]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/edma3_lld.git/blob - examples/edma3_driver/src/dma_poll_test.c
Merge branch 'edma3_keystone2' of gitorious.design.ti.com:+edma3-lld-developers/edma3...
[keystone-rtos/edma3_lld.git] / examples / edma3_driver / src / dma_poll_test.c
1 /*
2 * dma_poll_test.c
3 *
4 * Test case demonstrating the poll mode scenario. User has requested a data 
5 * transfer without giving any callback function. After programming and 
6 * enabling the channel, he uses different APIs (meant to be used in poll mode)
7 * to check the status of ongoing transfer. Interrupt will NOT occur in this 
8 * case.
9 *
10 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 
11
12
13 *  Redistribution and use in source and binary forms, with or without 
14 *  modification, are permitted provided that the following conditions 
15 *  are met:
16 *
17 *    Redistributions of source code must retain the above copyright 
18 *    notice, this list of conditions and the following disclaimer.
19 *
20 *    Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the 
22 *    documentation and/or other materials provided with the   
23 *    distribution.
24 *
25 *    Neither the name of Texas Instruments Incorporated nor the names of
26 *    its contributors may be used to endorse or promote products derived
27 *    from this software without specific prior written permission.
28 *
29 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
30 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
31 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
33 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
34 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
35 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
38 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
39 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 */
43 #include "sample.h"
45 extern signed char   _srcBuff1[MAX_BUFFER_SIZE];
46 extern signed char   _dstBuff1[MAX_BUFFER_SIZE];
48 extern signed char *srcBuff1;
49 extern signed char *dstBuff1;
51 /**
52 *  \brief   EDMA3 mem-to-mem data copy test case, using a DMA channel.
53 *              This test case doesnot rely on the callback mechanism.
54 *              Instead, it Polls the IPR register to check the transfer
55 *              completion status.
56 *
57 *  \param  acnt        [IN]      Number of bytes in an array
58 *  \param  bcnt        [IN]      Number of arrays in a frame
59 *  \param  ccnt        [IN]      Number of frames in a block
60 *  \param  syncType    [IN]      Synchronization type (A/AB Sync)
61 *
62 *  \return  EDMA3_DRV_SOK or EDMA3_DRV Error Code
63 */
64 EDMA3_DRV_Result edma3_test_poll_mode(
65                                       EDMA3_DRV_Handle hEdma,
66                                       uint32_t acnt,
67                                       uint32_t bcnt,
68                                       uint32_t ccnt,
69                                       EDMA3_DRV_SyncType syncType)
70 {
71     EDMA3_DRV_Result result = EDMA3_DRV_SOK;
72     uint32_t chId = 0;
73     uint32_t tcc = 0;
74     int i;
75     uint32_t count;
76     uint32_t Istestpassed = 0u;
77     uint32_t numenabled = 0;
78     uint32_t BRCnt = 0;
79     int srcbidx = 0, desbidx = 0;
80     int srccidx = 0, descidx = 0;
83     srcBuff1 = (signed char*) GLOBAL_ADDR(_srcBuff1);
84     dstBuff1 = (signed char*) GLOBAL_ADDR(_dstBuff1);
86     /* Initalize source and destination buffers */
87     for (count = 0u; count < (acnt*bcnt*ccnt); count++)
88     {
89         srcBuff1[count] = (int)count+5;
90         /**
91         * No need to initialize the destination buffer as it is being invalidated.
92         dstBuff1[count] = initval;
93         */
94     }
97 #ifdef EDMA3_ENABLE_DCACHE
98     /*
99     * Note: These functions are required if the buffer is in DDR.
100     * For other cases, where buffer is NOT in DDR, user
101     * may or may not require the below functions.
102     */
103     /* Flush the Source Buffer */
104     if (result == EDMA3_DRV_SOK)
105     {
106         result = Edma3_CacheFlush((uint32_t)srcBuff1, (acnt*bcnt*ccnt));
107     }
109     /* Invalidate the Destination Buffer */
110     if (result == EDMA3_DRV_SOK)
111     {
112         result = Edma3_CacheInvalidate((uint32_t)dstBuff1, (acnt*bcnt*ccnt));
113     }
114 #endif  /* EDMA3_ENABLE_DCACHE */
117     /* Set B count reload as B count. */
118     BRCnt = bcnt;
120     /* Setting up the SRC/DES Index */
121     srcbidx = (int)acnt;
122     desbidx = (int)acnt;
124     if (syncType == EDMA3_DRV_SYNC_A)
125     {
126         /* A Sync Transfer Mode */
127         srccidx = (int)acnt;
128         descidx = (int)acnt;
129     }
130     else
131     {
132         /* AB Sync Transfer Mode */
133         srccidx = ((int)acnt * (int)bcnt);
134         descidx = ((int)acnt * (int)bcnt);
135     }
138     /* Setup for Channel 1*/
139     tcc = EDMA3_DRV_TCC_ANY;
140     chId = EDMA3_DRV_DMA_CHANNEL_ANY;
143     /* Request any DMA channel and any TCC */
144     if (result == EDMA3_DRV_SOK)
145     {
146         result = EDMA3_DRV_requestChannel (hEdma, &chId, &tcc,
147             (EDMA3_RM_EventQueue)0,
148             NULL, NULL);
149     }
151     if (result == EDMA3_DRV_SOK)
152     {
153         result = EDMA3_DRV_setSrcParams (hEdma, chId, (uint32_t)(srcBuff1),
154             EDMA3_DRV_ADDR_MODE_INCR,
155             EDMA3_DRV_W8BIT);
156     }
158     if (result == EDMA3_DRV_SOK)
159     {
160         result = EDMA3_DRV_setDestParams (hEdma, chId, (uint32_t)(dstBuff1),
161             EDMA3_DRV_ADDR_MODE_INCR,
162             EDMA3_DRV_W8BIT);
163     }
165     if (result == EDMA3_DRV_SOK)
166     {
167         result = EDMA3_DRV_setSrcIndex (hEdma, chId, srcbidx, srccidx);
168     }
170     if (result == EDMA3_DRV_SOK)
171     {
172         result =  EDMA3_DRV_setDestIndex (hEdma, chId, desbidx, descidx);
173     }
175     if (result == EDMA3_DRV_SOK)
176     {
177         if (syncType == EDMA3_DRV_SYNC_A)
178         {
179             result = EDMA3_DRV_setTransferParams (hEdma, chId, acnt, bcnt, ccnt,
180                 BRCnt, EDMA3_DRV_SYNC_A);
181         }
182         else
183         {
184             result = EDMA3_DRV_setTransferParams (hEdma, chId, acnt, bcnt, ccnt,
185                 BRCnt, EDMA3_DRV_SYNC_AB);
186         }
187     }
189     if (result == EDMA3_DRV_SOK)
190     {
191         result = EDMA3_DRV_setOptField (hEdma, chId,
192             EDMA3_DRV_OPT_FIELD_TCINTEN, 1u);
193     }
195     if (result == EDMA3_DRV_SOK)
196     {
197         result = EDMA3_DRV_setOptField (hEdma, chId,
198             EDMA3_DRV_OPT_FIELD_ITCINTEN, 1u);
199     }
201     /*
202     * Since the transfer is going to happen in Manual mode of EDMA3
203     * operation, we have to 'Enable the Transfer' multiple times.
204     * Number of times depends upon the Mode (A/AB Sync)
205     * and the different counts.
206     */
207     if (result == EDMA3_DRV_SOK)
208     {
209         /*Need to activate next param*/
210         if (syncType == EDMA3_DRV_SYNC_A)
211         {
212             numenabled = bcnt * ccnt;
213         }
214         else
215         {
216             /* AB Sync Transfer Mode */
217             numenabled = ccnt;
218         }
221         for (i = 0; i < numenabled; i++)
222         {
223             /*
224             * Now enable the transfer as many times as calculated above.
225             */
226             result = EDMA3_DRV_enableTransfer (hEdma, chId,
227                 EDMA3_DRV_TRIG_MODE_MANUAL);
228             if (result != EDMA3_DRV_SOK)
229             {
230 #ifdef EDMA3_DRV_DEBUG
231                 EDMA3_DRV_PRINTF ("edma3_test_poll_mode: EDMA3_DRV_enableTransfer " \
232                     "Failed, error code: %d\r\n", result);
233 #endif  /* EDMA3_DRV_DEBUG */
234                 break;
235             }
238             /* Wait for the Completion Bit to be SET in the IPR/IPRH register. */
239             result = EDMA3_DRV_waitAndClearTcc (hEdma, tcc);
240             if (result != EDMA3_DRV_SOK)
241             {
242 #ifdef EDMA3_DRV_DEBUG
243                 EDMA3_DRV_PRINTF ("edma3_test_poll_mode: EDMA3_DRV_waitAndClearTcc " \
244                     "Failed, error code: %d\r\n", result);
245 #endif  /* EDMA3_DRV_DEBUG */
246                 break;
247             }
248         }
249     }
252     /* Match the Source and Destination Buffers. */
253     if (EDMA3_DRV_SOK == result)
254     {
255         for (i = 0; i < (acnt*bcnt*ccnt); i++)
256         {
257             if (srcBuff1[i] != dstBuff1[i])
258             {
259                 Istestpassed = 0u;
260 #ifdef EDMA3_DRV_DEBUG
261                 EDMA3_DRV_PRINTF("edma3_test_poll_mode: Data write-read matching" \
262                     "FAILED at i = %d\r\n", i);
263 #endif  /* EDMA3_DRV_DEBUG */
264                 break;
265             }
266         }
267         if (i == (acnt*bcnt*ccnt))
268         {
269             Istestpassed = 1u;
270         }
273         /* Free the previously allocated channel. */
274         result = EDMA3_DRV_freeChannel (hEdma, chId);
275         if (result != EDMA3_DRV_SOK)
276         {
277 #ifdef EDMA3_DRV_DEBUG
278             EDMA3_DRV_PRINTF("edma3_test_poll_mode: EDMA3_DRV_freeChannel() FAILED, " \
279                 "error code: %d\r\n", result);
280 #endif  /* EDMA3_DRV_DEBUG */
281         }
282     }
285     if(Istestpassed == 1u)
286     {
287 #ifdef EDMA3_DRV_DEBUG
288         EDMA3_DRV_PRINTF("edma3_test_poll_mode PASSED\r\n");
289 #endif  /* EDMA3_DRV_DEBUG */
290     }
291     else
292     {
293 #ifdef EDMA3_DRV_DEBUG
294         EDMA3_DRV_PRINTF("edma3_test_poll_mode FAILED\r\n");
295 #endif  /* EDMA3_DRV_DEBUG */
296         result = ((EDMA3_DRV_SOK == result) ?
297                     EDMA3_DATA_MISMATCH_ERROR : result);
298     }
299     return result;