]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/gpmc/test/src/main_gpmc_flash_test.c
gpmc-lld: add to PDK
[processor-sdk/pdk.git] / packages / ti / drv / gpmc / test / src / main_gpmc_flash_test.c
1 /**
2  *  \file   main_gpmc_flash_test.c
3  *
4  *  \brief  Test application main file. This application will write and read
5  *          the data to/from GPMC NOR/NAND flash through Board flash interface.
6  *
7  */
9 /*
10  * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the
22  * distribution.
23  *
24  * Neither the name of Texas Instruments Incorporated nor the names of
25  * its contributors may be used to endorse or promote products derived
26  * from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
42 #include <stdio.h>
43 #include <string.h>
45 /* XDCtools Header files */
46 #include <xdc/std.h>
47 #include <xdc/cfg/global.h>
48 #include <xdc/runtime/System.h>
50 /* BIOS Header files */
51 #include <ti/sysbios/BIOS.h>
53 /* GPMC Header files */
54 #include <ti/drv/gpmc/GPMC.h>
55 #include <ti/drv/gpmc/soc/GPMC_soc.h>
56 #include <ti/drv/gpmc/test/src/GPMC_board.h>
57 #include <ti/drv/gpmc/test/src/GPMC_log.h>
59 /* Board Header files */
60 #include <ti/board/board.h>
61 #include <ti/board/src/flash/include/board_flash.h>
63 /**********************************************************************
64  ************************** Macros ************************************
65  **********************************************************************/
67 /**********************************************************************
68  ************************** Internal functions ************************
69  **********************************************************************/
71 /* Function to generate known data */
72 static void GeneratePattern(uint8_t *txBuf, uint8_t *rxBuf, uint32_t length);
74 /* Data compare function */
75 bool VerifyData(uint8_t *expData,
76                 uint8_t *rxData,
77                 uint32_t length);
79 /**********************************************************************
80  ************************** Global Variables **************************
81  **********************************************************************/
83 /* Buffer containing the known data that needs to be written to flash */
84 uint8_t txBuf[TEST_DATA_LEN];
86 /* Buffer containing the received data */
87 uint8_t rxBuf[TEST_DATA_LEN];
89 /*
90  *  ======== test function ========
91  */
92 void gpmc_test(UArg arg0, UArg arg1)
93 {
94     Board_flashHandle boardHandle;
95     Board_FlashInfo *flashInfo;
96     uint32_t blockNum, pageNum;
97     bool testPassed = true;
99     /* Open the Board flash device with GPMC port instance
100        and use the default GPMC configurations */
101     boardHandle = Board_flashOpen(BOARD_FLASH_ID,
102                                   BOARD_GPMC_INSTANCE, NULL);
104     if (!boardHandle)
105     {
106         GPMC_log("\n Board_flashOpen failed. \n");
107         testPassed = false;
108         goto err;
109     }
110     else
111     {
112         flashInfo = (Board_FlashInfo *)boardHandle;
113         GPMC_log("\n GPMC flash device ID: 0x%x, manufacturer ID: 0x%x \n",
114                 flashInfo->device_id, flashInfo->manufacturer_id);
115     }
117     if (Board_flashOffsetToBlkPage(boardHandle, TEST_ADDR_OFFSET,
118                                    &blockNum, &pageNum))
119     {
120         GPMC_log("\n Board_flashOffsetToBlkPage failed. \n");
121         testPassed = false;
122         goto err;
123     }
125     /* Generate the data */
126     GeneratePattern(txBuf, rxBuf, TEST_DATA_LEN);
128 #ifdef TEST_GPMC_FLASH_WRITE
129     /* Erase block, to which data has to be written */
130     if (Board_flashEraseBlk(boardHandle, blockNum))
131     {
132         GPMC_log("\n Board_flashEraseBlk failed. \n");
133         testPassed = false;
134         goto err;
135     }
136     GPMC_log("\n GPMC flash block erase test passed. \n");
139     /* Write buffer to flash */
140     if (Board_flashWrite(boardHandle, TEST_ADDR_OFFSET, txBuf,
141                          TEST_DATA_LEN, NULL))
142     {
143         GPMC_log("\n Board_flashWrite failed. \n");
144         testPassed = false;
145         goto err;
146     }
147     GPMC_log("\n GPMC flash write test passed. \n");
148 #endif
150     /* Reset receive buffer */
151     if (Board_flashRead(boardHandle, TEST_ADDR_OFFSET, rxBuf,
152                         TEST_DATA_LEN, NULL))
153     {
154         GPMC_log("\n Board_flashRead failed. \n");
155         testPassed = false;
156         goto err;
157     }
158     GPMC_log("\n GPMC flash read test passed. \n");
160 #ifndef TEST_GPMC_FLASH_WRITE
161     /* if no write test, copy rxBuf to txBuf to pass the test */
162     memcpy(txBuf, rxBuf, TEST_DATA_LEN);
163 #endif
165     /* Verify Data */
166     if (VerifyData(txBuf, rxBuf, TEST_DATA_LEN) == false)
167     {
168         GPMC_log("\n Data mismatch. \n");
169         testPassed = false;
170     }
172 err:
173     if (boardHandle)
174     {
175         Board_flashClose(boardHandle);
176     }
178     if(true == testPassed)
179     {
180         GPMC_log("\n All tests have passed. \n");
181     }
182     else
183     {
184         GPMC_log("\n Some tests have failed. \n");
185     }
187     while(1);
190 void GPMC_initConfig(void)
192     GPMC_v1_HwAttrs gpmc_cfg;
194     /* Get the default UART init configurations */
195     GPMC_socGetInitCfg(BOARD_GPMC_INSTANCE, &gpmc_cfg);
197     /* Modify the default UART configurations if necessary */
199     /* Set the default UART init configurations */
200     GPMC_socSetInitCfg(BOARD_GPMC_INSTANCE, &gpmc_cfg);
203 /*
204  *  ======== main ========
205  */
206 int main(void)
208     /* Call board init functions */
209     Board_initCfg boardCfg;
211     boardCfg = BOARD_INIT_PINMUX_CONFIG |
212         BOARD_INIT_MODULE_CLOCK |
213         BOARD_INIT_UART_STDIO;
214     Board_init(boardCfg);
216     GPMC_initConfig();
218     /* Start BIOS */
219     BIOS_start();
220     return (0);
223 /*
224  *  ======== CompareData ========
225  */
226 bool VerifyData(uint8_t *expData,
227                 uint8_t *rxData,
228                 uint32_t length)
230     uint32_t idx = 0;
231     uint32_t match = 1;
232     bool retVal = false;
234     for(idx = 0; ((idx < length) && (match != 0)); idx++)
235     {
236         if(*expData != *rxData)
237         {
238             match = 0;
239         }
240         expData++;
241         rxData++;
242     }
244     if(match == 1)
245     {
246         retVal = true;
247     }
249     return retVal;
252 /*
253  *  ======== GeneratePattern ========
254  */
255 static void GeneratePattern(uint8_t *txBuf, uint8_t *rxBuf, uint32_t length)
257     volatile uint32_t idx;
258     volatile uint8_t *txPtr = txBuf;
259     volatile uint8_t *rxPtr = rxBuf;
261     for(idx = 0; idx < length; idx++)
262     {
263         *txPtr++ = (uint8_t)idx;
264         *rxPtr++ = (uint8_t)0U;
265     }