]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/edma3_lld.git/blob - examples/edma3_driver/src/main.c
EDMA3 driver sample example made generic
[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 <ti/sysbios/knl/Task.h>
43 #include <ti/sysbios/BIOS.h>
45 #include "sample.h"
46 extern const unsigned int numEdma3Instances;
48 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma);
50 /*
51  * Local References
52  */
53 static void tskHeartBit(void);
54 void echo(void);
56 void main()
57 {
58     Task_create((Task_FuncPtr)echo, NULL, NULL);
60     BIOS_start();
61 }
63 static void printWelcomeBanner(void)
64     {
65     /* Welcome Message */
66     printf("***************************************************************\n\r");
67     printf("*                                                             *\n\r");
68     printf("*                            ****                             *\n\r");
69     printf("*                            ****                             *\n\r");
70     printf("*                            ******o***                       *\n\r");
71     printf("*                      ********_///_****                      *\n\r");
72     printf("*                      ***** /_//_/ ****                      *\n\r");
73     printf("*                       ** ** (__/ ****                       *\n\r");
74     printf("*                           *********                         *\n\r");
75     printf("*                            ****                             *\n\r");
76     printf("*                            ***                              *\n\r");
77     printf("*                                                             *\n\r");
78     printf("*                     TI EDMA3 LOW LEVEL DRIVER               *\n\r");
79     printf("*                                                             *\n\r");
80     printf("*                                                             *\n\r");
81     printf("*       For issues on TI EDMA3 LLD, contact TII PSP Team      *\n\r");
82     printf("*                                                             *\n\r");
83     printf("*                                                             *\n\r");
84     printf("*                                                             *\n\r");
85     printf("***************************************************************\n\r");
86     printf("\r\n\r\n");
87     }
90 void echo()
91     {
92     EDMA3_DRV_Result edmaResult = EDMA3_DRV_SOK;
93         unsigned int i;
94         unsigned int count=0;
95         EDMA3_DRV_Handle hEdma;
97     /* Print the Welcome Message */
98     printWelcomeBanner();
100         for (count=0; count<10; count++)
101                 {
102                 printf ("\nCount = %d\n",count);
104                 for (i = 0; i < numEdma3Instances; i++)
105                         {
106                     hEdma = edma3init(i, &edmaResult);
107                     if (hEdma)
108                         {
109                         printf("edma3init() Passed\n");
110                         }
111                     else
112                         {
113                         printf("edma3init() Failed, error code: %d\n", edmaResult);
114                         }
116                     if (edmaResult == EDMA3_DRV_SOK)
117                         {
118                                 printf("\nStart -> EDMA3 Test memory to memory copy on Instance %d\n",i);
120                             edmaResult = edma3MemToMemCpytest(hEdma);
122                         if (EDMA3_DRV_SOK != edmaResult)
123                            {
124                             /* Report EDMA Error */
125                             printf("edma3MemToMemCpytest() Failed\n");
126                            }
127                         else
128                            {
129                             printf("edma3MemToMemCpytest() Passed\n");
130                            }
132                         printf("\nEnd -> EDMA3 Test memory to memory copy\n\n");
133                         }
135                         /* De-init EDMA3 */
136                         if (hEdma)
137                                 {
138                                 edmaResult = edma3deinit(i, hEdma);
139                             if (edmaResult != EDMA3_DRV_SOK)
140                                 {
141                                 printf("edma3deinit() Failed, error code: %d\n", edmaResult);
142                                 }
143                             else
144                                 {
145                                 printf("edma3deinit() Passed\n");
146                                 }
147                                 }
148                         }
149                 }
151     /* Start the Heart Beat Print */
152     tskHeartBit();
154     return;
155     }
158 /**
159  *  \brief   Main sample test case which will call other EDMA3 test cases.
160  *              If one wants to call Edma3 test cases, include this main
161  *              test case only.
162  *
163  *  \return  EDMA3_DRV_SOK or EDMA3_DRV Error Code
164  */
165 EDMA3_DRV_Result edma3MemToMemCpytest (EDMA3_DRV_Handle hEdma)
167     EDMA3_DRV_Result result = EDMA3_DRV_SOK;
169     if (hEdma == NULL)
170         {
171         result = EDMA3_DRV_E_INVALID_PARAM;
172         }
174     /* Edma test without linking, async, incr mode */
175     if (result == EDMA3_DRV_SOK)
176         {
177         result = edma3_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
179             if (result == EDMA3_DRV_SOK)
180                 {
181                 printf ("edma3_test (without linking) Passed\r\n");
182                 }
183             else
184                 {
185                 printf ("edma3_test (without linking) Failed\r\n");
186                 }
187                 }
189         /* Edma test with linking, async, incr mode */
190     if (result == EDMA3_DRV_SOK)
191         {
192         result = edma3_test_with_link(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
194             if (result == EDMA3_DRV_SOK)
195                 {
196                 printf ("edma3_test_with_link Passed\r\n");
197                 }
198             else
199                 {
200                 printf ("edma3_test_with_link Failed\r\n");
201                 }
202                 }
204         /* Qdma test, async, incr mode */
205     if (result == EDMA3_DRV_SOK)
206         {
207         result = qdma_test(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
209             if (result == EDMA3_DRV_SOK)
210                 {
211                 printf ("qdma_test Passed\r\n");
212                 }
213             else
214                 {
215                 printf ("qdma_test Failed\r\n");
216                 }
217                 }
219         /* Qdma test with linking, async, incr mode */
220     if (result == EDMA3_DRV_SOK)
221         {
222         result = qdma_test_with_link (hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
224             if (result == EDMA3_DRV_SOK)
225                 {
226                 printf ("qdma_test_with_link Passed\r\n");
227                 }
228             else
229                 {
230                 printf ("qdma_test_with_link Failed\r\n");
231                 }
232                 }
234         /* DMA channels with chaining test. */
235     if (result == EDMA3_DRV_SOK)
236         {
237         result = edma3_test_with_chaining(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
239         if (result == EDMA3_DRV_SOK)
240             {
241             printf ("edma3_test_with_chaining Passed\r\n");
242             }
243         else
244             {
245             printf ("edma3_test_with_chaining Failed\r\n");
246             }
247         }
249         /* DMA channels using Polling mode test. */
250     if (result == EDMA3_DRV_SOK)
251         {
252         result = edma3_test_poll_mode(hEdma, MAX_ACOUNT, MAX_BCOUNT, MAX_CCOUNT, EDMA3_DRV_SYNC_A);
254         if (result == EDMA3_DRV_SOK)
255             {
256             printf ("edma3_test_poll_mode Passed\r\n");
257             }
258         else
259             {
260             printf ("edma3_test_poll_mode Failed\r\n");
261             }
262         }
264         /* DMA channels in using ping-pong buffers test. */
265     if (result == EDMA3_DRV_SOK)
266         {
267         result = edma3_test_ping_pong_mode(hEdma);
269         if (result == EDMA3_DRV_SOK)
270             {
271             printf ("edma3_test_ping_pong_mode Passed\r\n");
272             }
273         else
274             {
275             printf ("edma3_test_ping_pong_mode Failed\r\n");
276             }
277         }
279         /* Misc tests. */
280     if (result == EDMA3_DRV_SOK)
281         {
282             result = edma3_misc_test(hEdma);
284         if (result == EDMA3_DRV_SOK)
285             {
286             printf ("edma3_misc_test Passed\r\n");
287             }
288         else
289             {
290             printf ("edma3_misc_test Failed\r\n");
291             }
292         }
294     return result;
298 void tskHeartBit()
299     {
300     static unsigned int counter = 0u;
302     while (counter < 0x1000000u)
303         {
304         printf("\r\n\r\n!!! EDMA3 LLD HrtBt %x", counter);
305         counter++;
306         }
307     }