]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/edma3_lld.git/blob - examples/edma3_driver/src/main.c
fixed build warning
[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-2018 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 #if defined(_TMS320C6X)
48 extern far const uint32_t numEdma3Instances;
49 #else
50 extern const uint32_t numEdma3Instances;
51 #endif
53 #ifdef SOC_AM335x
54 #define WR_MEM_32(addr, data) *(unsigned int*)(addr) = (unsigned int)(data)
56 #define PRCM_BASE_ADDR       (0x44E00000)
57 #define CM_PER_TPTC0_CLKCTRL (PRCM_BASE_ADDR +0x0024)
58 #define CM_PER_TPCC_CLKCTRL  (PRCM_BASE_ADDR +0x00BC)
59 #define CM_PER_TPTC1_CLKCTRL (PRCM_BASE_ADDR +0x00FC)
60 #define CM_PER_TPTC2_CLKCTRL (PRCM_BASE_ADDR +0x0100)
62 /*To enable EDMA3 Clock Module */
63 static void edma3PRCMEnable();
64 #endif
66 /**
67 * DSP instance number on which the executable is running. Its value is
68 * determined by reading the processor specific register DNUM.
69 */
70 uint32_t dsp_num_tmp;
71 /* To find out the DSP# */
72 extern unsigned short determineProcId();
73 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
74 extern EDMA3_RM_InstanceInitConfig defInstInitConfig [][EDMA3_MAX_REGIONS];
75 /* External Global Configuration Structure */
76 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
78 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma);
79 extern void *AppSemHandle1;
80 extern void *AppSemHandle2;
82 /*
83 * Local References
84 */
85 static void tskHeartBit(void);
86 void echo(void);
88 int main()
89 {
90     Task_create((Task_FuncPtr)echo, NULL, NULL);
92     BIOS_start();
94     return 0;
95 }
97 static void printWelcomeBanner(void)
98 {
99     /* Welcome Message */
100     printf("***************************************************************\n\r");
101     printf("*                                                             *\n\r");
102     printf("*                            ****                             *\n\r");
103     printf("*                            ****                             *\n\r");
104     printf("*                            ******o***                       *\n\r");
105     printf("*                      ********_///_****                      *\n\r");
106     printf("*                      ***** /_//_/ ****                      *\n\r");
107     printf("*                       ** ** (__/ ****                       *\n\r");
108     printf("*                           *********                         *\n\r");
109     printf("*                            ****                             *\n\r");
110     printf("*                            ***                              *\n\r");
111     printf("*                                                             *\n\r");
112     printf("*                     TI EDMA3 LOW LEVEL DRIVER               *\n\r");
113     printf("*                     Version: 0x%x                      *\n\r",(unsigned int)EDMA3_DRV_getVersion());
114     printf("*    %s     *\n\r",EDMA3_DRV_getVersionStr());
115     printf("*                                                             *\n\r");
116     printf("*                                                             *\n\r");
117     printf("*       For issues on TI EDMA3 LLD, contact TII PSP Team      *\n\r");
118     printf("*                                                             *\n\r");
119     printf("*                                                             *\n\r");
120     printf("*                                                             *\n\r");
121     printf("***************************************************************\n\r");
122     printf("\r\n\r\n");
125 /**
126 *  \brief   This function determines if testing on a EDMA3 instance will be bypassed.
127 *           When there are no EDMA channels allocated for the core from the given EDMA3 
128 *           instance, testing shall be bypassed.
130 *  \return  TRUE if bypass; FALSE if testing will done.
131 */
132 uint32_t bypassCore(uint32_t edmaInstNum)
134     uint32_t i, bypassFlag = 1;
136 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
137     EDMA3_DRV_InstanceInitConfig *instanceConfig = NULL;
138 #else
139     EDMA3_RM_InstanceInitConfig  *rmInstInitCfg = NULL;
140 #endif
142     /* DSP instance number */
143     dsp_num_tmp = determineProcId();
145 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
146     /* configuration structure for the Driver */
147     instanceConfig = &sampleInstInitConfig[edmaInstNum][dsp_num_tmp];
148     for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
149     {
150         if(instanceConfig->ownDmaChannels[i])
151             bypassFlag = 0;
152     }
153 #else
154     /* configuration structure for the Driver */
155     rmInstInitCfg = &defInstInitConfig[edmaInstNum][dsp_num_tmp];
156     for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
157     {
158         if(rmInstInitCfg->ownDmaChannels[i])
159             bypassFlag = 0;
160     }
161 #endif
163     return (bypassFlag);
167 void echo()
169     EDMA3_DRV_Result edmaResult = EDMA3_DRV_SOK;
170     uint32_t i, bypass;
171     uint32_t count=0;
172     uint32_t edmaInstance = 0;
173     EDMA3_DRV_Handle hEdma[MAX_NUM_EDMA_INSTANCES];
174     EDMA3_DRV_Handle hndEdma = NULL;
175     Semaphore_Params semParams;
177     memset(hEdma,0,sizeof(hEdma));
179 #ifdef SOC_AM335x
180     edma3PRCMEnable();
181 #endif
183     /* Print the Welcome Message */
184     printWelcomeBanner();
186     Semaphore_Params_init(&semParams);
187     edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle1);
188     if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle1 == NULL))
189     {
190         printf("Error initializing the Application Semaphore handle\n");
191         return;
192     }
193     edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle2);
194     if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle2 == NULL))
195     {
196         printf("Error initializing the Application Semaphore handle\n");
197         return;
198     }
200     if(numEdma3Instances > MAX_NUM_EDMA_INSTANCES)
201     {
202         printf("Error numEdma3Instances:%d > MAX_NUM_EDMA_INSTANCES: %d\n", (int)numEdma3Instances, MAX_NUM_EDMA_INSTANCES);
203         return;
204     }
206     for (i = 0; i < numEdma3Instances; i++)
207     {
208         bypass = bypassCore(i);
209         if(sampleEdma3GblCfgParams[i].numRegions > 1)
210         {
211             /* For multi core test init and de-init only once per test 
212             * for a core. 
213             */
214             if(bypass)
215             {
216                 printf("Bypassing init for Core %d on EDMA3 instance %d\n", (int)dsp_num_tmp, (int)i);
217                 continue;
218             }
220             hEdma[i] = edma3init(i, &edmaResult);
221             if (hEdma[i])
222             {
223                 printf("edma3init() Passed\n");
224             }
225             else
226             {
227                 printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
228             }
229         }
230     }
233     for (count=0; count<10; count++)
234     {
235         printf ("\nCount = %d\n",(int)count);
237         for (i = 0; i < numEdma3Instances; i++)
238         {
239             bypass = bypassCore(i);
240             if(bypass)
241             {
242                 printf("Bypass Core %d on EDMA3 instance %d\n", (int)dsp_num_tmp, (int)i);
243             }
244             else
245             {
246                 if(sampleEdma3GblCfgParams[i].numRegions == 1)
247                 {
248                     /* Single Region Config Do Init and Deinit test for each iteration */
249                     hEdma[i] = edma3init(i, &edmaResult);
250                     if (hEdma[i])
251                     {
252                         printf("edma3init() Passed\n");
253                     }
254                     else
255                     {
256                         printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
257                     }
258                 }
261                 if (edmaResult == EDMA3_DRV_SOK)
262                 {
263                     printf("\nStart -> EDMA3 Test memory to memory copy on Instance %d\n",(int)i);
265                     edmaResult = edma3MemToMemCpytest(hEdma[i]);
267                     if (EDMA3_DRV_SOK != edmaResult)
268                     {
269                         /* Report EDMA Error */
270                         printf("edma3MemToMemCpytest() FAILED!!!!!!!!!!!!!!!!\n");
271                         return;
272                     }
273                     else
274                     {
275                         printf("edma3MemToMemCpytest() Passed\n");
276                     }
278                     printf("\nEnd -> EDMA3 Test memory to memory copy\n\n");
279                 }
281                 if(sampleEdma3GblCfgParams[i].numRegions == 1)
282                 {
283                     /* Single Region Config 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             }
299         }
300     }
302     for (i = 0; i < numEdma3Instances; i++)
303     {
304         if(sampleEdma3GblCfgParams[i].numRegions > 1)
305         {
306             /* Multi core Do deinit */
307             /* De-init EDMA3 */
308             if (hEdma[i])
309             {
310                 edmaResult = edma3deinit(i, hEdma[i]);
311                 if (edmaResult != EDMA3_DRV_SOK)
312                 {
313                     printf("edma3deinit() Failed, error code: %d\n", (int)edmaResult);
314                 }
315                 else
316                 {
317                     printf("edma3deinit() Passed\n");
318                 }
319             }
320         }
321     }
323     /* Mapping DMA channels to corresponding paRAM Id. The user can request for 
324      * any DAM channel to map with the paRAM Id as same as the channel number
325      */
326     for (count = 0u; count < EDMA3_MAX_DMA_CH; count++)
327     {
328         sampleEdma3GblCfgParams[edmaInstance].dmaChannelPaRAMMap[count] = count;
329     }
331     /*EDMA3 Initialization*/
332     hndEdma = edma3init(edmaInstance, &edmaResult);
333     if (hndEdma)
334     {
335         printf("edma3init() Passed\n");
337         /* User request PaRAMId test */
338         if (edmaResult == EDMA3_DRV_SOK)
339         {
340             edmaResult = edma3_test_user_req_paRAMId(hndEdma, edmaInstance,
341                       MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
342         }
344         if (edmaResult == EDMA3_DRV_SOK)
345         {
346             printf ("edma3_test_user_req_paRAMId Passed\r\n");
347         }
348         else
349         {
350             printf ("edma3_test_user_req_paRAMId Failed\r\n");
351         }
353         /*EDMA3 deinitialization */
354         edmaResult = edma3deinit(edmaInstance, hndEdma);
355         if (edmaResult != EDMA3_DRV_SOK)
356         {
357             printf("edma3deinit() Failed, error code: %d\n", (int)edmaResult);
358         }
359         else
360         {
361             printf("edma3deinit() Passed\n");
362         }
363     }
364     else
365     {
366         printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
367     }
369     /* Start the Heart Beat Print */
370     tskHeartBit();
372     return;
376 /**
377 *  \brief   Main sample test case which will call other EDMA3 test cases.
378 *              If one wants to call Edma3 test cases, include this main
379 *              test case only.
381 *  \return  EDMA3_DRV_SOK or EDMA3_DRV Error Code
382 */
383 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma)
385     EDMA3_DRV_Result result = EDMA3_DRV_SOK;
387     if (hEdma == NULL)
388     {
389         //result = EDMA3_DRV_E_INVALID_PARAM;
390         return result;
391     }
393     /* Edma test without linking, async, incr mode */
394     if (result == EDMA3_DRV_SOK)
395     {
396         result = edma3_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
398         if (result == EDMA3_DRV_SOK)
399         {
400             printf ("edma3_test (without linking) Passed\r\n");
401         }
402         else
403         {
404             printf ("edma3_test (without linking) Failed\r\n");
405         }
406     }
408     /* Edma test with linking, async, incr mode */
409     if (result == EDMA3_DRV_SOK)
410     {
411         result = edma3_test_with_link(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
413         if (result == EDMA3_DRV_SOK)
414         {
415             printf ("edma3_test_with_link Passed\r\n");
416         }
417         else
418         {
419             printf ("edma3_test_with_link Failed\r\n");
420         }
421     }
423     /* Qdma test, async, incr mode */
424     if (result == EDMA3_DRV_SOK)
425     {
426         result = qdma_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
428         if (result == EDMA3_DRV_SOK)
429         {
430             printf ("qdma_test Passed\r\n");
431         }
432         else
433         {
434             printf ("qdma_test Failed\r\n");
435         }
436     }
438     /* Qdma test with linking, async, incr mode */
439     if (result == EDMA3_DRV_SOK)
440     {
441         result = qdma_test_with_link (hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
443         if (result == EDMA3_DRV_SOK)
444         {
445             printf ("qdma_test_with_link Passed\r\n");
446         }
447         else
448         {
449             printf ("qdma_test_with_link Failed\r\n");
450         }
451     }
453     /* DMA channels with chaining test. */
454     if (result == EDMA3_DRV_SOK)
455     {
456         result = edma3_test_with_chaining(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
458         if (result == EDMA3_DRV_SOK)
459         {
460             printf ("edma3_test_with_chaining Passed\r\n");
461         }
462         else
463         {
464             printf ("edma3_test_with_chaining Failed\r\n");
465         }
466     }
468     /* DMA channels using Polling mode test. */
469     if (result == EDMA3_DRV_SOK)
470     {
471         result = edma3_test_poll_mode(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
473         if (result == EDMA3_DRV_SOK)
474         {
475             printf ("edma3_test_poll_mode Passed\r\n");
476         }
477         else
478         {
479             printf ("edma3_test_poll_mode Failed\r\n");
480         }
481     }
483     /* DMA channels in using ping-pong buffers test. */
484     if (result == EDMA3_DRV_SOK)
485     {
486         result = edma3_test_ping_pong_mode(hEdma);
488         if (result == EDMA3_DRV_SOK)
489         {
490             printf ("edma3_test_ping_pong_mode Passed\r\n");
491         }
492         else
493         {
494             printf ("edma3_test_ping_pong_mode Failed\r\n");
495         }
496     }
498     /* Misc tests. */
499     if (result == EDMA3_DRV_SOK)
500     {
501         result = edma3_misc_test(hEdma);
503         if (result == EDMA3_DRV_SOK)
504         {
505             printf ("edma3_misc_test Passed\r\n");
506         }
507         else
508         {
509             printf ("edma3_misc_test Failed\r\n");
510         }
511     }
513     return result;
517 void tskHeartBit()
519     static uint32_t counter = 0u;
521     while (counter < 0x1000000u)
522     {
523         printf("\r\n\r\n!!! EDMA3 LLD HrtBt %x", (unsigned int)counter);
524         counter++;
525     }
528 #ifdef SOC_AM335x
529 /*To enable EDMA3 Clock Module of AM335x*/
530 static void edma3PRCMEnable()
532     WR_MEM_32(CM_PER_TPCC_CLKCTRL, 2);
533     WR_MEM_32(CM_PER_TPTC0_CLKCTRL ,   2);
534     WR_MEM_32(CM_PER_TPTC1_CLKCTRL ,   2);
535     WR_MEM_32(CM_PER_TPTC2_CLKCTRL ,   2);
537 #endif