[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / board / diag / emmc / src / emmc_main.c
1 /**
2 * \file emmc_main.c
3 *
4 * \brief Test application main file. The test application demonstrates
5 * raw data write & read on a MMCSD device.
6 *
7 */
9 /*
10 * Copyright (C) 2014 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 */
43 /* TI-RTOS Header files */
44 #include <ti/csl/cslr_device.h>
45 #include <ti/drv/mmcsd/MMCSD.h>
47 /* UART Header files */
48 #include <ti/drv/uart/UART.h>
49 #include <ti/drv/uart/UART_stdio.h>
51 /* GPIO Header files */
52 #include <ti/drv/gpio/GPIO.h>
53 #ifdef SOC_K2G
54 #include <ti/drv/gpio/soc/GPIO_soc.h>
55 #else
56 #include <ti/drv/gpio/soc/GPIO_v1.h>
57 #endif
59 #include "board.h"
60 #include "board_cfg.h"
62 /* Example/Board Header files */
63 #if defined (IDK_AM572X)
64 #include <ti/board/src/idkAM572x/include/board_cfg.h>
65 #endif
66 #if defined (IDK_AM571X)
67 #include <ti/board/src/idkAM571x/include/board_cfg.h>
68 #endif
69 #if defined (EVM_AM572X)
70 #include <ti/board/src/evmAM572x/include/board_cfg.h>
71 #endif
73 /**********************************************************************
74 ************************** Macros ************************************
75 **********************************************************************/
77 /* Global data pointers */
78 #define HSMMCSD_DATA_SIZE 512
80 #define PAGE_OFFSET 0x0
81 #define MMCSTARTSECTOR 0x300000 //@1.5GB //100
82 #define MMCTESTSECTORS 0x20 //0x800 //0x5000 //10MB //512
84 #define DATA_PATTERN_00 0
85 #define DATA_PATTERN_FF 1
86 #define SDMMC_DATA_PATTERN_AA 2
87 #define SDMMC_DATA_PATTERN_55 3
88 #define SDMMC_DATA_PATTERN_INC 8
90 #define SECTORSIZE (512)
91 #define TESTSECTORS 16 //16 //1
93 /* GPIO pin value definitions */
94 #define GPIO_PIN_VAL_LOW (0U)
95 #define GPIO_PIN_VAL_HIGH (1U)
97 /* ON Board LED pins which are connected to GPIO pins. */
98 typedef enum GPIO_PIN {
99 GPIO_PIN_EMMC_RST = 0U,
100 GPIO_PIN_COUNT
101 }GPIO_PIN;
103 /* GPIO Driver board specific pin configuration structure */
104 GPIO_PinConfig gpioPinConfigs[] = {
105 /* Output pin : AM572X EMMC_RST */
106 GPIO_DEVICE_CONFIG(GPIO_EMMC_RST_PORT_NUM, GPIO_EMMC_RST_PIN_NUM) | GPIO_CFG_OUTPUT,
107 };
109 /* GPIO Driver call back functions */
110 GPIO_CallbackFxn gpioCallbackFunctions[] = {
111 NULL
112 };
114 #ifdef SOC_K2G
115 GPIO_v0_Config GPIO_v0_config = {
116 gpioPinConfigs,
117 gpioCallbackFunctions,
118 sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
119 sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
120 0,
121 };
122 #else
123 /* GPIO Driver configuration structure */
124 GPIO_v1_Config GPIO_v1_config = {
125 gpioPinConfigs,
126 gpioCallbackFunctions,
127 sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
128 sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
129 0,
130 };
131 #endif
133 /* Enable the below macro to have prints on the IO Console */
134 //#define IO_CONSOLE
136 #ifndef IO_CONSOLE
137 #define MMCSD_log UART_printf
138 #else
139 #define MMCSD_log printf
140 #endif
142 /* ========================================================================== */
143 /* Structures and Enums */
144 /* ========================================================================== */
146 #if !(defined (EVM_K2G))
147 typedef CSL_control_core_pad_ioRegs *CSL_padRegsOvly;
148 #endif
150 /**********************************************************************
151 ************************** Internal functions ************************
152 **********************************************************************/
154 static int32_t HSMMCSDReadWriteTest(MMCSD_Handle handle);
156 static int32_t fillMmcPageData(uint8_t *buf, int32_t length, uint8_t flag);
158 static void EmmcsReset(void);
160 /* Delay function */
161 void delay(unsigned int delayValue);
163 /**********************************************************************
164 ************************** Global Variables **************************
165 **********************************************************************/
167 MMCSD_Handle handle = NULL;
168 static uint8_t tx[SECTORSIZE*TESTSECTORS];
169 static uint8_t rx[SECTORSIZE*TESTSECTORS];
171 /* ========================================================================== */
172 /* Function Definitions */
173 /* ========================================================================== */
175 /*
176 * ======== main ========
177 */
178 int main(void)
179 {
180 /* Call board init functions */
181 Board_initCfg boardCfg;
182 boardCfg = BOARD_INIT_UART_STDIO;
183 Board_init(boardCfg);
185 UART_printf("\n*********************************************\n");
186 UART_printf ("* eMMC Test *\n");
187 UART_printf ("*********************************************\n");
189 GPIO_init();
191 EmmcsReset();
193 MMCSD_init();
195 MMCSD_open(1U, NULL, &handle);
197 return HSMMCSDReadWriteTest(handle);
198 }
200 int32_t fillMmcPageData(uint8_t *buf, int32_t length, uint8_t flag)
201 {
202 int32_t i;
203 uint32_t data = 0x00;
204 uint8_t incFlag = 0x00;
206 switch(flag)
207 {
208 case DATA_PATTERN_00:
209 data = 0;
210 break;
211 case DATA_PATTERN_FF:
212 data = 0xFF;
213 break;
214 case SDMMC_DATA_PATTERN_AA:
215 data = 0xAA;
216 //MMCSD_log("\nSD Read/Write pattern 0xAA ");
217 break;
218 case SDMMC_DATA_PATTERN_55:
219 data = 0x55;
220 //MMCSD_log("\nSD Read/Write pattern 0x55 ");
221 break;
222 case 4:
223 data = 0x00;
224 incFlag = 0x01;
225 //MMCSD_log("\nSD Read/Write incremental data");
226 break;
227 default:
228 return -1;
229 }
231 for(i =0; i < length; i++)
232 {
233 *(buf+i) = data;
234 if(incFlag)
235 data++;
236 }
240 return 0;
241 }
243 int32_t HSMMCSDReadWriteTest(MMCSD_Handle handle)
244 {
245 int32_t j, testIteration;
246 unsigned long int blockNum;
247 int32_t retVal = 0;
249 for(blockNum = MMCSTARTSECTOR; blockNum < (MMCTESTSECTORS+MMCSTARTSECTOR); blockNum+=TESTSECTORS)
250 {
251 testIteration = SDMMC_DATA_PATTERN_AA;
253 fillMmcPageData(&tx[0], (SECTORSIZE*TESTSECTORS), testIteration);
255 retVal = MMCSD_write(handle, &tx[0], blockNum, TESTSECTORS);
257 if(retVal != MMCSD_OK)
258 {
259 MMCSD_log("FAIL: Write failed on sector %d", blockNum);
260 return -1;
261 }
263 delay(100);
265 /* Clear receive buffer */
266 fillMmcPageData(&rx[0], (SECTORSIZE*TESTSECTORS), DATA_PATTERN_00);
268 /* Read a page */
269 retVal = MMCSD_read(handle, &rx[0], blockNum, TESTSECTORS);
271 if(retVal != MMCSD_OK)
272 {
273 MMCSD_log("FAIL: Read failed on sector %d", blockNum);
274 return -1;
275 }
277 /* Check the pattern */
278 for ( j = 0 ; j < (SECTORSIZE*TESTSECTORS) ; j++ )
279 {
280 /* Compare the data read against the expected */
281 if ( tx[j] != rx[j])
282 {
283 MMCSD_log ("FAIL: Data comparison failed @ ");
284 MMCSD_log("sector %d", blockNum);
285 MMCSD_log(" ,data %d", j);
286 MMCSD_log(" ,rx = %x", rx[j]);
287 MMCSD_log(" ,tx = %x", tx[j]);
288 return -1;
289 }
291 }
292 }
294 MMCSD_log ("\nPASS: Read/Write Success for this pattern\r\n");
296 return 0;
297 }
299 static void EmmcsReset(void)
300 {
301 /* EMMC reset */
302 GPIO_write(GPIO_PIN_EMMC_RST, GPIO_PIN_VAL_LOW);
303 delay(100);
304 GPIO_write(GPIO_PIN_EMMC_RST, GPIO_PIN_VAL_HIGH);
305 delay(100);
306 }
308 /*
309 * ======== Delay function ========
310 */
311 void delay(unsigned int delayValue)
312 {
313 volatile uint32_t delay1 = delayValue*10000;
314 while (delay1--) ;
315 }