1be466a6b4316c6cda44aceabbc998e53a495c5e
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);
64 /*
65 * Local References
66 */
67 static void tskHeartBit(void);
68 void echo(void);
70 void main()
71 {
72 Task_create((Task_FuncPtr)echo, NULL, NULL);
74 BIOS_start();
75 }
77 static void printWelcomeBanner(void)
78 {
79 /* Welcome Message */
80 printf("***************************************************************\n\r");
81 printf("* *\n\r");
82 printf("* **** *\n\r");
83 printf("* **** *\n\r");
84 printf("* ******o*** *\n\r");
85 printf("* ********_///_**** *\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("* TI EDMA3 LOW LEVEL DRIVER *\n\r");
93 printf("* Version: 0x%x *\n\r",EDMA3_DRV_getVersion());
94 printf("* %s *\n\r",EDMA3_DRV_getVersionStr());
95 printf("* *\n\r");
96 printf("* *\n\r");
97 printf("* For issues on TI EDMA3 LLD, contact TII PSP Team *\n\r");
98 printf("* *\n\r");
99 printf("* *\n\r");
100 printf("* *\n\r");
101 printf("***************************************************************\n\r");
102 printf("\r\n\r\n");
103 }
105 /**
106 * \brief This function determines if testing on a EDMA3 instance will be bypassed.
107 * When there are no EDMA channels allocated for the core from the given EDMA3
108 * instance, testing shall be bypassed.
109 *
110 * \return TRUE if bypass; FALSE if testing will done.
111 */
112 unsigned int bypassCore(unsigned int edmaInstNum)
113 {
114 unsigned int i, bypassFlag = 1;
116 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
117 EDMA3_DRV_InstanceInitConfig *instanceConfig = NULL;
118 #else
119 EDMA3_RM_InstanceInitConfig *rmInstInitCfg = NULL;
120 #endif
122 /* DSP instance number */
123 dsp_num_tmp = determineProcId();
125 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
126 /* configuration structure for the Driver */
127 instanceConfig = &sampleInstInitConfig[edmaInstNum][dsp_num_tmp];
128 for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
129 {
130 if(instanceConfig->ownDmaChannels[i])
131 bypassFlag = 0;
132 }
133 #else
134 /* configuration structure for the Driver */
135 rmInstInitCfg = &defInstInitConfig[edmaInstNum][dsp_num_tmp];
136 for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
137 {
138 if(rmInstInitCfg->ownDmaChannels[i])
139 bypassFlag = 0;
140 }
141 #endif
143 return (bypassFlag);
144 }
147 void echo()
148 {
149 EDMA3_DRV_Result edmaResult = EDMA3_DRV_SOK;
150 unsigned int i, bypass;
151 unsigned int count=0;
152 EDMA3_DRV_Handle hEdma[MAX_NUM_EDMA_INSTANCES];
154 memset(hEdma,0,sizeof(hEdma));
156 /* Print the Welcome Message */
157 printWelcomeBanner();
159 if(numEdma3Instances > MAX_NUM_EDMA_INSTANCES)
160 {
161 printf("Error numEdma3Instances:%d > MAX_NUM_EDMA_INSTANCES: %d\n", numEdma3Instances, MAX_NUM_EDMA_INSTANCES);
162 return;
163 }
165 for (i = 0; i < numEdma3Instances; i++)
166 {
167 bypass = bypassCore(i);
168 if(sampleEdma3GblCfgParams[i].numRegions > 1)
169 {
170 /* For multi core test init and de-init only once per test
171 * for a core.
172 */
173 if(bypass)
174 {
175 printf("Bypassing init for Core %d on EDMA3 instance %d\n", dsp_num_tmp, i);
176 continue;
177 }
179 hEdma[i] = edma3init(i, &edmaResult);
180 if (hEdma[i])
181 {
182 printf("edma3init() Passed\n");
183 }
184 else
185 {
186 printf("edma3init() Failed, error code: %d\n", edmaResult);
187 }
188 }
189 }
192 for (count=0; count<10; count++)
193 {
194 printf ("\nCount = %d\n",count);
196 for (i = 0; i < numEdma3Instances; i++)
197 {
199 bypass = bypassCore(i);
200 if(bypass)
201 {
202 printf("Bypass Core %d on EDMA3 instance %d\n", dsp_num_tmp, i);
203 }
204 else
205 {
206 if(sampleEdma3GblCfgParams[i].numRegions == 1)
207 {
208 /* Single Region Config Do Init and Deinit test for each iteration */
209 hEdma[i] = edma3init(i, &edmaResult);
210 if (hEdma[i])
211 {
212 printf("edma3init() Passed\n");
213 }
214 else
215 {
216 printf("edma3init() Failed, error code: %d\n", edmaResult);
217 }
218 }
221 if (edmaResult == EDMA3_DRV_SOK)
222 {
223 printf("\nStart -> EDMA3 Test memory to memory copy on Instance %d\n",i);
225 edmaResult = edma3MemToMemCpytest(hEdma[i]);
227 if (EDMA3_DRV_SOK != edmaResult)
228 {
229 /* Report EDMA Error */
230 printf("edma3MemToMemCpytest() FAILED!!!!!!!!!!!!!!!!\n");
231 return;
232 }
233 else
234 {
235 printf("edma3MemToMemCpytest() Passed\n");
236 }
238 printf("\nEnd -> EDMA3 Test memory to memory copy\n\n");
239 }
241 if(sampleEdma3GblCfgParams[i].numRegions == 1)
242 {
243 /* Single Region Config Do deinit */
244 /* De-init EDMA3 */
245 if (hEdma[i])
246 {
247 edmaResult = edma3deinit(i, hEdma[i]);
248 if (edmaResult != EDMA3_DRV_SOK)
249 {
250 printf("edma3deinit() Failed, error code: %d\n", edmaResult);
251 }
252 else
253 {
254 printf("edma3deinit() Passed\n");
255 }
256 }
257 }
258 }
260 }
261 }
263 /* Start the Heart Beat Print */
264 tskHeartBit();
266 for (i = 0; i < numEdma3Instances; i++)
267 {
268 if(sampleEdma3GblCfgParams[i].numRegions > 1)
269 {
270 if(bypass)
271 {
272 printf("Bypassing de-init for Core %d on EDMA3 instance %d\n", dsp_num_tmp, i);
273 continue;
274 }
276 /* Multi core Do deinit */
277 /* De-init EDMA3 */
278 if (hEdma[i])
279 {
280 edmaResult = edma3deinit(i, hEdma[i]);
281 if (edmaResult != EDMA3_DRV_SOK)
282 {
283 printf("edma3deinit() Failed, error code: %d\n", edmaResult);
284 }
285 else
286 {
287 printf("edma3deinit() Passed\n");
288 }
289 }
290 }
291 }
293 return;
294 }
297 /**
298 * \brief Main sample test case which will call other EDMA3 test cases.
299 * If one wants to call Edma3 test cases, include this main
300 * test case only.
301 *
302 * \return EDMA3_DRV_SOK or EDMA3_DRV Error Code
303 */
304 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma)
305 {
306 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
308 if (hEdma == NULL)
309 {
310 //result = EDMA3_DRV_E_INVALID_PARAM;
311 return result;
312 }
314 /* Edma test without linking, async, incr mode */
315 if (result == EDMA3_DRV_SOK)
316 {
317 result = edma3_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
319 if (result == EDMA3_DRV_SOK)
320 {
321 printf ("edma3_test (without linking) Passed\r\n");
322 }
323 else
324 {
325 printf ("edma3_test (without linking) Failed\r\n");
326 }
327 }
329 /* Edma test with linking, async, incr mode */
330 if (result == EDMA3_DRV_SOK)
331 {
332 result = edma3_test_with_link(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
334 if (result == EDMA3_DRV_SOK)
335 {
336 printf ("edma3_test_with_link Passed\r\n");
337 }
338 else
339 {
340 printf ("edma3_test_with_link Failed\r\n");
341 }
342 }
344 /* Qdma test, async, incr mode */
345 if (result == EDMA3_DRV_SOK)
346 {
347 result = qdma_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
349 if (result == EDMA3_DRV_SOK)
350 {
351 printf ("qdma_test Passed\r\n");
352 }
353 else
354 {
355 printf ("qdma_test Failed\r\n");
356 }
357 }
359 /* Qdma test with linking, async, incr mode */
360 if (result == EDMA3_DRV_SOK)
361 {
362 result = qdma_test_with_link (hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
364 if (result == EDMA3_DRV_SOK)
365 {
366 printf ("qdma_test_with_link Passed\r\n");
367 }
368 else
369 {
370 printf ("qdma_test_with_link Failed\r\n");
371 }
372 }
374 /* DMA channels with chaining test. */
375 if (result == EDMA3_DRV_SOK)
376 {
377 result = edma3_test_with_chaining(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
379 if (result == EDMA3_DRV_SOK)
380 {
381 printf ("edma3_test_with_chaining Passed\r\n");
382 }
383 else
384 {
385 printf ("edma3_test_with_chaining Failed\r\n");
386 }
387 }
389 /* DMA channels using Polling mode test. */
390 if (result == EDMA3_DRV_SOK)
391 {
392 result = edma3_test_poll_mode(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
394 if (result == EDMA3_DRV_SOK)
395 {
396 printf ("edma3_test_poll_mode Passed\r\n");
397 }
398 else
399 {
400 printf ("edma3_test_poll_mode Failed\r\n");
401 }
402 }
404 /* DMA channels in using ping-pong buffers test. */
405 if (result == EDMA3_DRV_SOK)
406 {
407 result = edma3_test_ping_pong_mode(hEdma);
409 if (result == EDMA3_DRV_SOK)
410 {
411 printf ("edma3_test_ping_pong_mode Passed\r\n");
412 }
413 else
414 {
415 printf ("edma3_test_ping_pong_mode Failed\r\n");
416 }
417 }
419 /* Misc tests. */
420 if (result == EDMA3_DRV_SOK)
421 {
422 result = edma3_misc_test(hEdma);
424 if (result == EDMA3_DRV_SOK)
425 {
426 printf ("edma3_misc_test Passed\r\n");
427 }
428 else
429 {
430 printf ("edma3_misc_test Failed\r\n");
431 }
432 }
434 return result;
435 }
438 void tskHeartBit()
439 {
440 static unsigned int counter = 0u;
442 while (counter < 0x1000000u)
443 {
444 printf("\r\n\r\n!!! EDMA3 LLD HrtBt %x", counter);
445 counter++;
446 }
447 }