1744d0dc995b505c3bac1bbe02ece0a410cca02f
1 /*
2 * main.c
3 *
4 * This file contains the test / demo code to demonstrate the EDMA3 driver
5 * functionality on DSP/BIOS 6.
6 *
7 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 */
40 #include <xdc/std.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <ti/sysbios/knl/Task.h>
44 #include <ti/sysbios/BIOS.h>
46 #include "sample.h"
47 extern const unsigned int numEdma3Instances;
49 /**
50 * DSP instance number on which the executable is running. Its value is
51 * determined by reading the processor specific register DNUM.
52 */
53 unsigned int dsp_num_tmp;
54 /* To find out the DSP# */
55 extern unsigned short determineProcId();
56 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
57 extern EDMA3_RM_InstanceInitConfig defInstInitConfig [][EDMA3_MAX_REGIONS];
58 /* External Global Configuration Structure */
59 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
61 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma);
62 extern void *AppSemHandle1;
63 extern void *AppSemHandle2;
65 /*
66 * Local References
67 */
68 static void tskHeartBit(void);
69 void echo(void);
71 void main()
72 {
73 Task_create((Task_FuncPtr)echo, NULL, NULL);
75 BIOS_start();
76 }
78 static void printWelcomeBanner(void)
79 {
80 /* Welcome Message */
81 printf("***************************************************************\n\r");
82 printf("* *\n\r");
83 printf("* **** *\n\r");
84 printf("* **** *\n\r");
85 printf("* ******o*** *\n\r");
86 printf("* ********_///_**** *\n\r");
87 printf("* ***** /_//_/ **** *\n\r");
88 printf("* ** ** (__/ **** *\n\r");
89 printf("* ********* *\n\r");
90 printf("* **** *\n\r");
91 printf("* *** *\n\r");
92 printf("* *\n\r");
93 printf("* TI EDMA3 LOW LEVEL DRIVER *\n\r");
94 printf("* Version: 0x%x *\n\r",EDMA3_DRV_getVersion());
95 printf("* %s *\n\r",EDMA3_DRV_getVersionStr());
96 printf("* *\n\r");
97 printf("* *\n\r");
98 printf("* For issues on TI EDMA3 LLD, contact TII PSP Team *\n\r");
99 printf("* *\n\r");
100 printf("* *\n\r");
101 printf("* *\n\r");
102 printf("***************************************************************\n\r");
103 printf("\r\n\r\n");
104 }
106 /**
107 * \brief This function determines if testing on a EDMA3 instance will be bypassed.
108 * When there are no EDMA channels allocated for the core from the given EDMA3
109 * instance, testing shall be bypassed.
110 *
111 * \return TRUE if bypass; FALSE if testing will done.
112 */
113 unsigned int bypassCore(unsigned int edmaInstNum)
114 {
115 unsigned int i, bypassFlag = 1;
117 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
118 EDMA3_DRV_InstanceInitConfig *instanceConfig = NULL;
119 #else
120 EDMA3_RM_InstanceInitConfig *rmInstInitCfg = NULL;
121 #endif
123 /* DSP instance number */
124 dsp_num_tmp = determineProcId();
126 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
127 /* configuration structure for the Driver */
128 instanceConfig = &sampleInstInitConfig[edmaInstNum][dsp_num_tmp];
129 for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
130 {
131 if(instanceConfig->ownDmaChannels[i])
132 bypassFlag = 0;
133 }
134 #else
135 /* configuration structure for the Driver */
136 rmInstInitCfg = &defInstInitConfig[edmaInstNum][dsp_num_tmp];
137 for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
138 {
139 if(rmInstInitCfg->ownDmaChannels[i])
140 bypassFlag = 0;
141 }
142 #endif
144 return (bypassFlag);
145 }
148 void echo()
149 {
150 EDMA3_DRV_Result edmaResult = EDMA3_DRV_SOK;
151 unsigned int i, bypass;
152 unsigned int count=0;
153 EDMA3_DRV_Handle hEdma[MAX_NUM_EDMA_INSTANCES];
154 Semaphore_Params semParams;
156 memset(hEdma,0,sizeof(hEdma));
158 /* Print the Welcome Message */
159 printWelcomeBanner();
161 Semaphore_Params_init(&semParams);
162 edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle1);
163 if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle1 == NULL))
164 {
165 printf("Error initializing the Application Semaphore handle\n");
166 return;
167 }
168 edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle2);
169 if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle2 == NULL))
170 {
171 printf("Error initializing the Application Semaphore handle\n");
172 return;
173 }
175 if(numEdma3Instances > MAX_NUM_EDMA_INSTANCES)
176 {
177 printf("Error numEdma3Instances:%d > MAX_NUM_EDMA_INSTANCES: %d\n", numEdma3Instances, MAX_NUM_EDMA_INSTANCES);
178 return;
179 }
181 for (i = 0; i < numEdma3Instances; i++)
182 {
183 bypass = bypassCore(i);
184 if(sampleEdma3GblCfgParams[i].numRegions > 1)
185 {
186 /* For multi core test init and de-init only once per test
187 * for a core.
188 */
189 if(bypass)
190 {
191 printf("Bypassing init for Core %d on EDMA3 instance %d\n", dsp_num_tmp, i);
192 continue;
193 }
195 hEdma[i] = edma3init(i, &edmaResult);
196 if (hEdma[i])
197 {
198 printf("edma3init() Passed\n");
199 }
200 else
201 {
202 printf("edma3init() Failed, error code: %d\n", edmaResult);
203 }
204 }
205 }
208 for (count=0; count<10; count++)
209 {
210 printf ("\nCount = %d\n",count);
212 for (i = 0; i < numEdma3Instances; i++)
213 {
215 bypass = bypassCore(i);
216 if(bypass)
217 {
218 printf("Bypass Core %d on EDMA3 instance %d\n", dsp_num_tmp, i);
219 }
220 else
221 {
222 if(sampleEdma3GblCfgParams[i].numRegions == 1)
223 {
224 /* Single Region Config Do Init and Deinit test for each iteration */
225 hEdma[i] = edma3init(i, &edmaResult);
226 if (hEdma[i])
227 {
228 printf("edma3init() Passed\n");
229 }
230 else
231 {
232 printf("edma3init() Failed, error code: %d\n", edmaResult);
233 }
234 }
237 if (edmaResult == EDMA3_DRV_SOK)
238 {
239 printf("\nStart -> EDMA3 Test memory to memory copy on Instance %d\n",i);
241 edmaResult = edma3MemToMemCpytest(hEdma[i]);
243 if (EDMA3_DRV_SOK != edmaResult)
244 {
245 /* Report EDMA Error */
246 printf("edma3MemToMemCpytest() FAILED!!!!!!!!!!!!!!!!\n");
247 return;
248 }
249 else
250 {
251 printf("edma3MemToMemCpytest() Passed\n");
252 }
254 printf("\nEnd -> EDMA3 Test memory to memory copy\n\n");
255 }
257 if(sampleEdma3GblCfgParams[i].numRegions == 1)
258 {
259 /* Single Region Config Do deinit */
260 /* De-init EDMA3 */
261 if (hEdma[i])
262 {
263 edmaResult = edma3deinit(i, hEdma[i]);
264 if (edmaResult != EDMA3_DRV_SOK)
265 {
266 printf("edma3deinit() Failed, error code: %d\n", edmaResult);
267 }
268 else
269 {
270 printf("edma3deinit() Passed\n");
271 }
272 }
273 }
274 }
276 }
277 }
279 /* Start the Heart Beat Print */
280 tskHeartBit();
282 for (i = 0; i < numEdma3Instances; i++)
283 {
284 if(sampleEdma3GblCfgParams[i].numRegions > 1)
285 {
286 if(bypass)
287 {
288 printf("Bypassing de-init for Core %d on EDMA3 instance %d\n", dsp_num_tmp, i);
289 continue;
290 }
292 /* Multi core Do deinit */
293 /* De-init EDMA3 */
294 if (hEdma[i])
295 {
296 edmaResult = edma3deinit(i, hEdma[i]);
297 if (edmaResult != EDMA3_DRV_SOK)
298 {
299 printf("edma3deinit() Failed, error code: %d\n", edmaResult);
300 }
301 else
302 {
303 printf("edma3deinit() Passed\n");
304 }
305 }
306 }
307 }
309 return;
310 }
313 /**
314 * \brief Main sample test case which will call other EDMA3 test cases.
315 * If one wants to call Edma3 test cases, include this main
316 * test case only.
317 *
318 * \return EDMA3_DRV_SOK or EDMA3_DRV Error Code
319 */
320 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma)
321 {
322 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
324 if (hEdma == NULL)
325 {
326 //result = EDMA3_DRV_E_INVALID_PARAM;
327 return result;
328 }
330 /* Edma test without linking, async, incr mode */
331 if (result == EDMA3_DRV_SOK)
332 {
333 result = edma3_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
335 if (result == EDMA3_DRV_SOK)
336 {
337 printf ("edma3_test (without linking) Passed\r\n");
338 }
339 else
340 {
341 printf ("edma3_test (without linking) Failed\r\n");
342 }
343 }
345 /* Edma test with linking, async, incr mode */
346 if (result == EDMA3_DRV_SOK)
347 {
348 result = edma3_test_with_link(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
350 if (result == EDMA3_DRV_SOK)
351 {
352 printf ("edma3_test_with_link Passed\r\n");
353 }
354 else
355 {
356 printf ("edma3_test_with_link Failed\r\n");
357 }
358 }
360 /* Qdma test, async, incr mode */
361 if (result == EDMA3_DRV_SOK)
362 {
363 result = qdma_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
365 if (result == EDMA3_DRV_SOK)
366 {
367 printf ("qdma_test Passed\r\n");
368 }
369 else
370 {
371 printf ("qdma_test Failed\r\n");
372 }
373 }
375 /* Qdma test with linking, async, incr mode */
376 if (result == EDMA3_DRV_SOK)
377 {
378 result = qdma_test_with_link (hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
380 if (result == EDMA3_DRV_SOK)
381 {
382 printf ("qdma_test_with_link Passed\r\n");
383 }
384 else
385 {
386 printf ("qdma_test_with_link Failed\r\n");
387 }
388 }
390 /* DMA channels with chaining test. */
391 if (result == EDMA3_DRV_SOK)
392 {
393 result = edma3_test_with_chaining(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
395 if (result == EDMA3_DRV_SOK)
396 {
397 printf ("edma3_test_with_chaining Passed\r\n");
398 }
399 else
400 {
401 printf ("edma3_test_with_chaining Failed\r\n");
402 }
403 }
405 /* DMA channels using Polling mode test. */
406 if (result == EDMA3_DRV_SOK)
407 {
408 result = edma3_test_poll_mode(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
410 if (result == EDMA3_DRV_SOK)
411 {
412 printf ("edma3_test_poll_mode Passed\r\n");
413 }
414 else
415 {
416 printf ("edma3_test_poll_mode Failed\r\n");
417 }
418 }
420 /* DMA channels in using ping-pong buffers test. */
421 if (result == EDMA3_DRV_SOK)
422 {
423 result = edma3_test_ping_pong_mode(hEdma);
425 if (result == EDMA3_DRV_SOK)
426 {
427 printf ("edma3_test_ping_pong_mode Passed\r\n");
428 }
429 else
430 {
431 printf ("edma3_test_ping_pong_mode Failed\r\n");
432 }
433 }
435 /* Misc tests. */
436 if (result == EDMA3_DRV_SOK)
437 {
438 result = edma3_misc_test(hEdma);
440 if (result == EDMA3_DRV_SOK)
441 {
442 printf ("edma3_misc_test Passed\r\n");
443 }
444 else
445 {
446 printf ("edma3_misc_test Failed\r\n");
447 }
448 }
450 return result;
451 }
454 void tskHeartBit()
455 {
456 static unsigned int counter = 0u;
458 while (counter < 0x1000000u)
459 {
460 printf("\r\n\r\n!!! EDMA3 LLD HrtBt %x", counter);
461 counter++;
462 }
463 }