[processor-sdk/performance-audio-sr.git] / pdk_k2g_1_0_1_0_eng / packages / ti / board / diag / mmcsd / src / mmcsd_main.c
1 /**
2 * \file mmcsd_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 #include <ti/board/board.h>
53 /* Example/Board Header files */
54 #if defined (IDK_AM572X)
55 #include <ti/board/src/idkAM572x/include/board_cfg.h>
56 #endif
57 #if defined (IDK_AM571X)
58 #include <ti/board/src/idkAM571x/include/board_cfg.h>
59 #endif
60 #if defined (EVM_AM572X)
61 #include <ti/board/src/evmAM572x/include/board_cfg.h>
62 #endif
64 /**********************************************************************
65 ************************** Macros ************************************
66 **********************************************************************/
68 /* Global data pointers */
69 #define HSMMCSD_DATA_SIZE 512
71 #define PAGE_OFFSET 0x0
72 #define MMCSTARTSECTOR 0x300000 //@1.5GB //100
73 #define MMCTESTSECTORS 0x20 //0x800 //0x5000 //10MB //512
75 #define DATA_PATTERN_00 0
76 #define DATA_PATTERN_FF 1
77 #define SDMMC_DATA_PATTERN_AA 2
78 #define SDMMC_DATA_PATTERN_55 3
79 #define SDMMC_DATA_PATTERN_INC 8
81 #define SECTORSIZE (512)
82 #define TESTSECTORS 16 //16 //1
84 /* Enable the below macro to have prints on the IO Console */
85 //#define IO_CONSOLE
87 #ifndef IO_CONSOLE
88 #define MMCSD_log UART_printf
89 #else
90 #define MMCSD_log printf
91 #endif
93 /* ========================================================================== */
94 /* Structures and Enums */
95 /* ========================================================================== */
97 typedef CSL_control_core_pad_ioRegs *CSL_padRegsOvly;
99 /**********************************************************************
100 ************************** Internal functions ************************
101 **********************************************************************/
103 static int32_t HSMMCSDReadWriteTest(MMCSD_Handle handle);
105 static int32_t fillMmcPageData(uint8_t *buf, int32_t length, uint8_t flag);
107 /* Delay function */
108 static void delay(unsigned int delayValue);
110 /**********************************************************************
111 ************************** Global Variables **************************
112 **********************************************************************/
114 MMCSD_Handle handle = NULL;
115 static uint8_t tx[SECTORSIZE*TESTSECTORS];
116 static uint8_t rx[SECTORSIZE*TESTSECTORS];
118 /* ========================================================================== */
119 /* Function Definitions */
120 /* ========================================================================== */
122 /*
123 * ======== main ========
124 */
125 int main(void)
126 {
127 /* Call board init functions */
128 Board_initCfg boardCfg;
129 boardCfg = BOARD_INIT_UART_STDIO;
130 Board_init(boardCfg);
131 UART_printf("\n*********************************************\n");
132 UART_printf ("* MMCSD Test *\n");
133 UART_printf ("*********************************************\n");
135 MMCSD_init();
137 MMCSD_open(0U, NULL, &handle);
139 return HSMMCSDReadWriteTest(handle);
140 }
142 int32_t fillMmcPageData(uint8_t *buf, int32_t length, uint8_t flag)
143 {
144 int32_t i;
145 uint32_t data = 0x00;
146 uint8_t incFlag = 0x00;
148 switch(flag)
149 {
150 case DATA_PATTERN_00:
151 data = 0;
152 break;
153 case DATA_PATTERN_FF:
154 data = 0xFF;
155 break;
156 case SDMMC_DATA_PATTERN_AA:
157 data = 0xAA;
158 //MMCSD_log("\nSD Read/Write pattern 0xAA ");
159 break;
160 case SDMMC_DATA_PATTERN_55:
161 data = 0x55;
162 //MMCSD_log("\nSD Read/Write pattern 0x55 ");
163 break;
164 case 4:
165 data = 0x00;
166 incFlag = 0x01;
167 //MMCSD_log("\nSD Read/Write incremental data");
168 break;
169 default:
170 return -1;
171 }
173 for(i =0; i < length; i++)
174 {
175 *(buf+i) = data;
176 if(incFlag)
177 data++;
178 }
182 return 0;
183 }
185 int32_t HSMMCSDReadWriteTest(MMCSD_Handle handle)
186 {
187 int32_t j, testIteration;
188 unsigned long int blockNum;
189 int32_t retVal = 0;
191 for(blockNum = MMCSTARTSECTOR; blockNum < (MMCTESTSECTORS+MMCSTARTSECTOR); blockNum+=TESTSECTORS)
192 {
193 testIteration = SDMMC_DATA_PATTERN_INC;
195 fillMmcPageData(&tx[0], (SECTORSIZE*TESTSECTORS), testIteration);
197 retVal = MMCSD_write(handle, &tx[0], blockNum, TESTSECTORS);
199 if(retVal != MMCSD_OK)
200 {
201 MMCSD_log("FAIL: Write failed on sector %d", blockNum);
202 return -1;
203 }
205 delay(100);
207 /* Clear receive buffer */
208 fillMmcPageData(&rx[0], (SECTORSIZE*TESTSECTORS), DATA_PATTERN_00);
210 /* Read a page */
211 retVal = MMCSD_read(handle, &rx[0], blockNum, TESTSECTORS);
213 if(retVal != MMCSD_OK)
214 {
215 MMCSD_log("FAIL: Read failed on sector %d", blockNum);
216 return -1;
217 }
219 /* Check the pattern */
220 for ( j = 0 ; j < (SECTORSIZE*TESTSECTORS) ; j++ )
221 {
222 /* Compare the data read against the expected */
223 if ( tx[j] != rx[j])
224 {
225 MMCSD_log ("FAIL: Data comparison failed @ ");
226 MMCSD_log("sector %d", blockNum);
227 MMCSD_log(" ,data %d", j);
228 MMCSD_log(" ,rx = %x", rx[j]);
229 MMCSD_log(" ,tx = %x", tx[j]);
230 return -1;
231 }
233 }
234 }
236 MMCSD_log ("\nPASS: Read/Write Success for this pattern\r\n");
238 return 0;
239 }
241 /*
242 * ======== Delay function ========
243 */
244 static void delay(unsigned int delayValue)
245 {
246 volatile uint32_t delay1 = delayValue*10000;
247 while (delay1--) ;
248 }