e658fd3b741e369805a85a4f928ed8020a58bd0b
[keystone-rtos/edma3_lld.git] / examples / edma3_driver / src / main.c
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 uint32_t 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 uint32_t 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 int main()
72 {
73     Task_create((Task_FuncPtr)echo, NULL, NULL);
75     BIOS_start();
77     return 0;
78 }
80 static void printWelcomeBanner(void)
81 {
82     /* Welcome Message */
83     printf("***************************************************************\n\r");
84     printf("*                                                             *\n\r");
85     printf("*                            ****                             *\n\r");
86     printf("*                            ****                             *\n\r");
87     printf("*                            ******o***                       *\n\r");
88     printf("*                      ********_///_****                      *\n\r");
89     printf("*                      ***** /_//_/ ****                      *\n\r");
90     printf("*                       ** ** (__/ ****                       *\n\r");
91     printf("*                           *********                         *\n\r");
92     printf("*                            ****                             *\n\r");
93     printf("*                            ***                              *\n\r");
94     printf("*                                                             *\n\r");
95     printf("*                     TI EDMA3 LOW LEVEL DRIVER               *\n\r");
96     printf("*                     Version: 0x%x                      *\n\r",(unsigned int)EDMA3_DRV_getVersion());
97     printf("*    %s     *\n\r",EDMA3_DRV_getVersionStr());
98     printf("*                                                             *\n\r");
99     printf("*                                                             *\n\r");
100     printf("*       For issues on TI EDMA3 LLD, contact TII PSP Team      *\n\r");
101     printf("*                                                             *\n\r");
102     printf("*                                                             *\n\r");
103     printf("*                                                             *\n\r");
104     printf("***************************************************************\n\r");
105     printf("\r\n\r\n");
108 /**
109 *  \brief   This function determines if testing on a EDMA3 instance will be bypassed.
110 *           When there are no EDMA channels allocated for the core from the given EDMA3 
111 *           instance, testing shall be bypassed.
113 *  \return  TRUE if bypass; FALSE if testing will done.
114 */
115 uint32_t bypassCore(uint32_t edmaInstNum)
117     uint32_t i, bypassFlag = 1;
119 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
120     EDMA3_DRV_InstanceInitConfig *instanceConfig = NULL;
121 #else
122     EDMA3_RM_InstanceInitConfig  *rmInstInitCfg = NULL;
123 #endif
125     /* DSP instance number */
126     dsp_num_tmp = determineProcId();
128 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
129     /* configuration structure for the Driver */
130     instanceConfig = &sampleInstInitConfig[edmaInstNum][dsp_num_tmp];
131     for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
132     {
133         if(instanceConfig->ownDmaChannels[i])
134             bypassFlag = 0;
135     }
136 #else
137     /* configuration structure for the Driver */
138     rmInstInitCfg = &defInstInitConfig[edmaInstNum][dsp_num_tmp];
139     for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
140     {
141         if(rmInstInitCfg->ownDmaChannels[i])
142             bypassFlag = 0;
143     }
144 #endif
146     return (bypassFlag);
150 void echo()
152     EDMA3_DRV_Result edmaResult = EDMA3_DRV_SOK;
153     uint32_t i, bypass;
154     uint32_t count=0;
155     EDMA3_DRV_Handle hEdma[MAX_NUM_EDMA_INSTANCES];
156     Semaphore_Params semParams;
158     memset(hEdma,0,sizeof(hEdma));
160     /* Print the Welcome Message */
161     printWelcomeBanner();
163     Semaphore_Params_init(&semParams);
164     edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle1);
165     if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle1 == NULL))
166     {
167         printf("Error initializing the Application Semaphore handle\n");
168         return;
169     }
170     edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle2);
171     if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle2 == NULL))
172     {
173         printf("Error initializing the Application Semaphore handle\n");
174         return;
175     }
177     if(numEdma3Instances > MAX_NUM_EDMA_INSTANCES)
178     {
179         printf("Error numEdma3Instances:%d > MAX_NUM_EDMA_INSTANCES: %d\n", (int)numEdma3Instances, MAX_NUM_EDMA_INSTANCES);
180         return;
181     }
183     for (i = 0; i < numEdma3Instances; i++)
184     {
185         bypass = bypassCore(i);
186         if(sampleEdma3GblCfgParams[i].numRegions > 1)
187         {
188             /* For multi core test init and de-init only once per test 
189             * for a core. 
190             */
191             if(bypass)
192             {
193                 printf("Bypassing init for Core %d on EDMA3 instance %d\n", (int)dsp_num_tmp, (int)i);
194                 continue;
195             }
197             hEdma[i] = edma3init(i, &edmaResult);
198             if (hEdma[i])
199             {
200                 printf("edma3init() Passed\n");
201             }
202             else
203             {
204                 printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
205             }
206         }
207     }
210     for (count=0; count<10; count++)
211     {
212         printf ("\nCount = %d\n",(int)count);
214         for (i = 0; i < numEdma3Instances; i++)
215         {
216             bypass = bypassCore(i);
217             if(bypass)
218             {
219                 printf("Bypass Core %d on EDMA3 instance %d\n", (int)dsp_num_tmp, (int)i);
220             }
221             else
222             {
223                 if(sampleEdma3GblCfgParams[i].numRegions == 1)
224                 {
225                     /* Single Region Config Do Init and Deinit test for each iteration */
226                     hEdma[i] = edma3init(i, &edmaResult);
227                     if (hEdma[i])
228                     {
229                         printf("edma3init() Passed\n");
230                     }
231                     else
232                     {
233                         printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
234                     }
235                 }
238                 if (edmaResult == EDMA3_DRV_SOK)
239                 {
240                     printf("\nStart -> EDMA3 Test memory to memory copy on Instance %d\n",(int)i);
242                     edmaResult = edma3MemToMemCpytest(hEdma[i]);
244                     if (EDMA3_DRV_SOK != edmaResult)
245                     {
246                         /* Report EDMA Error */
247                         printf("edma3MemToMemCpytest() FAILED!!!!!!!!!!!!!!!!\n");
248                         return;
249                     }
250                     else
251                     {
252                         printf("edma3MemToMemCpytest() Passed\n");
253                     }
255                     printf("\nEnd -> EDMA3 Test memory to memory copy\n\n");
256                 }
258                 if(sampleEdma3GblCfgParams[i].numRegions == 1)
259                 {
260                     /* Single Region Config Do deinit */
261                     /* De-init EDMA3 */
262                     if (hEdma[i])
263                     {
264                         edmaResult = edma3deinit(i, hEdma[i]);
265                         if (edmaResult != EDMA3_DRV_SOK)
266                         {
267                             printf("edma3deinit() Failed, error code: %d\n", (int)edmaResult);
268                         }
269                         else
270                         {
271                             printf("edma3deinit() Passed\n");
272                         }
273                     }
274                 }
275             }
276         }
277     }
279     for (i = 0; i < numEdma3Instances; i++)
280     {
281         if(sampleEdma3GblCfgParams[i].numRegions > 1)
282         {
283             /* Multi core Do deinit */
284             /* De-init EDMA3 */
285             if (hEdma[i])
286             {
287                 edmaResult = edma3deinit(i, hEdma[i]);
288                 if (edmaResult != EDMA3_DRV_SOK)
289                 {
290                     printf("edma3deinit() Failed, error code: %d\n", (int)edmaResult);
291                 }
292                 else
293                 {
294                     printf("edma3deinit() Passed\n");
295                 }
296             }
297         }
298     }
300     /* Start the Heart Beat Print */
301     tskHeartBit();
303     return;
307 /**
308 *  \brief   Main sample test case which will call other EDMA3 test cases.
309 *              If one wants to call Edma3 test cases, include this main
310 *              test case only.
312 *  \return  EDMA3_DRV_SOK or EDMA3_DRV Error Code
313 */
314 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma)
316     EDMA3_DRV_Result result = EDMA3_DRV_SOK;
318     if (hEdma == NULL)
319     {
320         //result = EDMA3_DRV_E_INVALID_PARAM;
321         return result;
322     }
324     /* Edma test without linking, async, incr mode */
325     if (result == EDMA3_DRV_SOK)
326     {
327         result = edma3_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
329         if (result == EDMA3_DRV_SOK)
330         {
331             printf ("edma3_test (without linking) Passed\r\n");
332         }
333         else
334         {
335             printf ("edma3_test (without linking) Failed\r\n");
336         }
337     }
339     /* Edma test with linking, async, incr mode */
340     if (result == EDMA3_DRV_SOK)
341     {
342         result = edma3_test_with_link(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
344         if (result == EDMA3_DRV_SOK)
345         {
346             printf ("edma3_test_with_link Passed\r\n");
347         }
348         else
349         {
350             printf ("edma3_test_with_link Failed\r\n");
351         }
352     }
354     /* Qdma test, async, incr mode */
355     if (result == EDMA3_DRV_SOK)
356     {
357         result = qdma_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
359         if (result == EDMA3_DRV_SOK)
360         {
361             printf ("qdma_test Passed\r\n");
362         }
363         else
364         {
365             printf ("qdma_test Failed\r\n");
366         }
367     }
369     /* Qdma test with linking, async, incr mode */
370     if (result == EDMA3_DRV_SOK)
371     {
372         result = qdma_test_with_link (hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
374         if (result == EDMA3_DRV_SOK)
375         {
376             printf ("qdma_test_with_link Passed\r\n");
377         }
378         else
379         {
380             printf ("qdma_test_with_link Failed\r\n");
381         }
382     }
384     /* DMA channels with chaining test. */
385     if (result == EDMA3_DRV_SOK)
386     {
387         result = edma3_test_with_chaining(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
389         if (result == EDMA3_DRV_SOK)
390         {
391             printf ("edma3_test_with_chaining Passed\r\n");
392         }
393         else
394         {
395             printf ("edma3_test_with_chaining Failed\r\n");
396         }
397     }
399     /* DMA channels using Polling mode test. */
400     if (result == EDMA3_DRV_SOK)
401     {
402         result = edma3_test_poll_mode(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
404         if (result == EDMA3_DRV_SOK)
405         {
406             printf ("edma3_test_poll_mode Passed\r\n");
407         }
408         else
409         {
410             printf ("edma3_test_poll_mode Failed\r\n");
411         }
412     }
414     /* DMA channels in using ping-pong buffers test. */
415     if (result == EDMA3_DRV_SOK)
416     {
417         result = edma3_test_ping_pong_mode(hEdma);
419         if (result == EDMA3_DRV_SOK)
420         {
421             printf ("edma3_test_ping_pong_mode Passed\r\n");
422         }
423         else
424         {
425             printf ("edma3_test_ping_pong_mode Failed\r\n");
426         }
427     }
429     /* Misc tests. */
430     if (result == EDMA3_DRV_SOK)
431     {
432         result = edma3_misc_test(hEdma);
434         if (result == EDMA3_DRV_SOK)
435         {
436             printf ("edma3_misc_test Passed\r\n");
437         }
438         else
439         {
440             printf ("edma3_misc_test Failed\r\n");
441         }
442     }
444     return result;
448 void tskHeartBit()
450     static uint32_t counter = 0u;
452     while (counter < 0x1000000u)
453     {
454         printf("\r\n\r\n!!! EDMA3 LLD HrtBt %x", (unsigned int)counter);
455         counter++;
456     }