PRSDK-927: additional fix to ensure the far qualifier only applies for C66x compilation
[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 #if defined(_TMS320C6X)
48 extern far const uint32_t numEdma3Instances;
49 #else
50 extern const uint32_t numEdma3Instances;
51 #endif
53 /**
54 * DSP instance number on which the executable is running. Its value is
55 * determined by reading the processor specific register DNUM.
56 */
57 uint32_t dsp_num_tmp;
58 /* To find out the DSP# */
59 extern unsigned short determineProcId();
60 extern EDMA3_DRV_InstanceInitConfig sampleInstInitConfig[][EDMA3_MAX_REGIONS];
61 extern EDMA3_RM_InstanceInitConfig defInstInitConfig [][EDMA3_MAX_REGIONS];
62 /* External Global Configuration Structure */
63 extern EDMA3_DRV_GblConfigParams sampleEdma3GblCfgParams[];
65 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma);
66 extern void *AppSemHandle1;
67 extern void *AppSemHandle2;
69 /*
70 * Local References
71 */
72 static void tskHeartBit(void);
73 void echo(void);
75 int main()
76 {
77     Task_create((Task_FuncPtr)echo, NULL, NULL);
79     BIOS_start();
81     return 0;
82 }
84 static void printWelcomeBanner(void)
85 {
86     /* Welcome Message */
87     printf("***************************************************************\n\r");
88     printf("*                                                             *\n\r");
89     printf("*                            ****                             *\n\r");
90     printf("*                            ****                             *\n\r");
91     printf("*                            ******o***                       *\n\r");
92     printf("*                      ********_///_****                      *\n\r");
93     printf("*                      ***** /_//_/ ****                      *\n\r");
94     printf("*                       ** ** (__/ ****                       *\n\r");
95     printf("*                           *********                         *\n\r");
96     printf("*                            ****                             *\n\r");
97     printf("*                            ***                              *\n\r");
98     printf("*                                                             *\n\r");
99     printf("*                     TI EDMA3 LOW LEVEL DRIVER               *\n\r");
100     printf("*                     Version: 0x%x                      *\n\r",(unsigned int)EDMA3_DRV_getVersion());
101     printf("*    %s     *\n\r",EDMA3_DRV_getVersionStr());
102     printf("*                                                             *\n\r");
103     printf("*                                                             *\n\r");
104     printf("*       For issues on TI EDMA3 LLD, contact TII PSP Team      *\n\r");
105     printf("*                                                             *\n\r");
106     printf("*                                                             *\n\r");
107     printf("*                                                             *\n\r");
108     printf("***************************************************************\n\r");
109     printf("\r\n\r\n");
112 /**
113 *  \brief   This function determines if testing on a EDMA3 instance will be bypassed.
114 *           When there are no EDMA channels allocated for the core from the given EDMA3 
115 *           instance, testing shall be bypassed.
117 *  \return  TRUE if bypass; FALSE if testing will done.
118 */
119 uint32_t bypassCore(uint32_t edmaInstNum)
121     uint32_t i, bypassFlag = 1;
123 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
124     EDMA3_DRV_InstanceInitConfig *instanceConfig = NULL;
125 #else
126     EDMA3_RM_InstanceInitConfig  *rmInstInitCfg = NULL;
127 #endif
129     /* DSP instance number */
130     dsp_num_tmp = determineProcId();
132 #ifndef EDMA3_DRV_USE_DEF_RM_CFG
133     /* configuration structure for the Driver */
134     instanceConfig = &sampleInstInitConfig[edmaInstNum][dsp_num_tmp];
135     for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
136     {
137         if(instanceConfig->ownDmaChannels[i])
138             bypassFlag = 0;
139     }
140 #else
141     /* configuration structure for the Driver */
142     rmInstInitCfg = &defInstInitConfig[edmaInstNum][dsp_num_tmp];
143     for (i = 0; i < EDMA3_MAX_DMA_CHAN_DWRDS; i++)
144     {
145         if(rmInstInitCfg->ownDmaChannels[i])
146             bypassFlag = 0;
147     }
148 #endif
150     return (bypassFlag);
154 void echo()
156     EDMA3_DRV_Result edmaResult = EDMA3_DRV_SOK;
157     uint32_t i, bypass;
158     uint32_t count=0;
159     EDMA3_DRV_Handle hEdma[MAX_NUM_EDMA_INSTANCES];
160     Semaphore_Params semParams;
162     memset(hEdma,0,sizeof(hEdma));
164     /* Print the Welcome Message */
165     printWelcomeBanner();
167     Semaphore_Params_init(&semParams);
168     edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle1);
169     if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle1 == NULL))
170     {
171         printf("Error initializing the Application Semaphore handle\n");
172         return;
173     }
174     edmaResult = edma3OsSemCreate(0, &semParams, &AppSemHandle2);
175     if((edmaResult != EDMA3_DRV_SOK) || (AppSemHandle2 == NULL))
176     {
177         printf("Error initializing the Application Semaphore handle\n");
178         return;
179     }
181     if(numEdma3Instances > MAX_NUM_EDMA_INSTANCES)
182     {
183         printf("Error numEdma3Instances:%d > MAX_NUM_EDMA_INSTANCES: %d\n", (int)numEdma3Instances, MAX_NUM_EDMA_INSTANCES);
184         return;
185     }
187     for (i = 0; i < numEdma3Instances; i++)
188     {
189         bypass = bypassCore(i);
190         if(sampleEdma3GblCfgParams[i].numRegions > 1)
191         {
192             /* For multi core test init and de-init only once per test 
193             * for a core. 
194             */
195             if(bypass)
196             {
197                 printf("Bypassing init for Core %d on EDMA3 instance %d\n", (int)dsp_num_tmp, (int)i);
198                 continue;
199             }
201             hEdma[i] = edma3init(i, &edmaResult);
202             if (hEdma[i])
203             {
204                 printf("edma3init() Passed\n");
205             }
206             else
207             {
208                 printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
209             }
210         }
211     }
214     for (count=0; count<10; count++)
215     {
216         printf ("\nCount = %d\n",(int)count);
218         for (i = 0; i < numEdma3Instances; i++)
219         {
220             bypass = bypassCore(i);
221             if(bypass)
222             {
223                 printf("Bypass Core %d on EDMA3 instance %d\n", (int)dsp_num_tmp, (int)i);
224             }
225             else
226             {
227                 if(sampleEdma3GblCfgParams[i].numRegions == 1)
228                 {
229                     /* Single Region Config Do Init and Deinit test for each iteration */
230                     hEdma[i] = edma3init(i, &edmaResult);
231                     if (hEdma[i])
232                     {
233                         printf("edma3init() Passed\n");
234                     }
235                     else
236                     {
237                         printf("edma3init() Failed, error code: %d\n", (int)edmaResult);
238                     }
239                 }
242                 if (edmaResult == EDMA3_DRV_SOK)
243                 {
244                     printf("\nStart -> EDMA3 Test memory to memory copy on Instance %d\n",(int)i);
246                     edmaResult = edma3MemToMemCpytest(hEdma[i]);
248                     if (EDMA3_DRV_SOK != edmaResult)
249                     {
250                         /* Report EDMA Error */
251                         printf("edma3MemToMemCpytest() FAILED!!!!!!!!!!!!!!!!\n");
252                         return;
253                     }
254                     else
255                     {
256                         printf("edma3MemToMemCpytest() Passed\n");
257                     }
259                     printf("\nEnd -> EDMA3 Test memory to memory copy\n\n");
260                 }
262                 if(sampleEdma3GblCfgParams[i].numRegions == 1)
263                 {
264                     /* Single Region Config Do deinit */
265                     /* De-init EDMA3 */
266                     if (hEdma[i])
267                     {
268                         edmaResult = edma3deinit(i, hEdma[i]);
269                         if (edmaResult != EDMA3_DRV_SOK)
270                         {
271                             printf("edma3deinit() Failed, error code: %d\n", (int)edmaResult);
272                         }
273                         else
274                         {
275                             printf("edma3deinit() Passed\n");
276                         }
277                     }
278                 }
279             }
280         }
281     }
283     for (i = 0; i < numEdma3Instances; i++)
284     {
285         if(sampleEdma3GblCfgParams[i].numRegions > 1)
286         {
287             /* Multi core Do deinit */
288             /* De-init EDMA3 */
289             if (hEdma[i])
290             {
291                 edmaResult = edma3deinit(i, hEdma[i]);
292                 if (edmaResult != EDMA3_DRV_SOK)
293                 {
294                     printf("edma3deinit() Failed, error code: %d\n", (int)edmaResult);
295                 }
296                 else
297                 {
298                     printf("edma3deinit() Passed\n");
299                 }
300             }
301         }
302     }
304     /* Start the Heart Beat Print */
305     tskHeartBit();
307     return;
311 /**
312 *  \brief   Main sample test case which will call other EDMA3 test cases.
313 *              If one wants to call Edma3 test cases, include this main
314 *              test case only.
316 *  \return  EDMA3_DRV_SOK or EDMA3_DRV Error Code
317 */
318 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma)
320     EDMA3_DRV_Result result = EDMA3_DRV_SOK;
322     if (hEdma == NULL)
323     {
324         //result = EDMA3_DRV_E_INVALID_PARAM;
325         return result;
326     }
328     /* Edma test without linking, async, incr mode */
329     if (result == EDMA3_DRV_SOK)
330     {
331         result = edma3_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
333         if (result == EDMA3_DRV_SOK)
334         {
335             printf ("edma3_test (without linking) Passed\r\n");
336         }
337         else
338         {
339             printf ("edma3_test (without linking) Failed\r\n");
340         }
341     }
343     /* Edma test with linking, async, incr mode */
344     if (result == EDMA3_DRV_SOK)
345     {
346         result = edma3_test_with_link(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
348         if (result == EDMA3_DRV_SOK)
349         {
350             printf ("edma3_test_with_link Passed\r\n");
351         }
352         else
353         {
354             printf ("edma3_test_with_link Failed\r\n");
355         }
356     }
358     /* Qdma test, async, incr mode */
359     if (result == EDMA3_DRV_SOK)
360     {
361         result = qdma_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
363         if (result == EDMA3_DRV_SOK)
364         {
365             printf ("qdma_test Passed\r\n");
366         }
367         else
368         {
369             printf ("qdma_test Failed\r\n");
370         }
371     }
373     /* Qdma test with linking, async, incr mode */
374     if (result == EDMA3_DRV_SOK)
375     {
376         result = qdma_test_with_link (hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
378         if (result == EDMA3_DRV_SOK)
379         {
380             printf ("qdma_test_with_link Passed\r\n");
381         }
382         else
383         {
384             printf ("qdma_test_with_link Failed\r\n");
385         }
386     }
388     /* DMA channels with chaining test. */
389     if (result == EDMA3_DRV_SOK)
390     {
391         result = edma3_test_with_chaining(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
393         if (result == EDMA3_DRV_SOK)
394         {
395             printf ("edma3_test_with_chaining Passed\r\n");
396         }
397         else
398         {
399             printf ("edma3_test_with_chaining Failed\r\n");
400         }
401     }
403     /* DMA channels using Polling mode test. */
404     if (result == EDMA3_DRV_SOK)
405     {
406         result = edma3_test_poll_mode(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
408         if (result == EDMA3_DRV_SOK)
409         {
410             printf ("edma3_test_poll_mode Passed\r\n");
411         }
412         else
413         {
414             printf ("edma3_test_poll_mode Failed\r\n");
415         }
416     }
418     /* DMA channels in using ping-pong buffers test. */
419     if (result == EDMA3_DRV_SOK)
420     {
421         result = edma3_test_ping_pong_mode(hEdma);
423         if (result == EDMA3_DRV_SOK)
424         {
425             printf ("edma3_test_ping_pong_mode Passed\r\n");
426         }
427         else
428         {
429             printf ("edma3_test_ping_pong_mode Failed\r\n");
430         }
431     }
433     /* Misc tests. */
434     if (result == EDMA3_DRV_SOK)
435     {
436         result = edma3_misc_test(hEdma);
438         if (result == EDMA3_DRV_SOK)
439         {
440             printf ("edma3_misc_test Passed\r\n");
441         }
442         else
443         {
444             printf ("edma3_misc_test Failed\r\n");
445         }
446     }
448     return result;
452 void tskHeartBit()
454     static uint32_t counter = 0u;
456     while (counter < 0x1000000u)
457     {
458         printf("\r\n\r\n!!! EDMA3 LLD HrtBt %x", (unsigned int)counter);
459         counter++;
460     }