Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

DMA - Code example
[DMA - Direct Memory Access]

 #include <otSerial.h>
 #include <otTimer.h>
 #include <otPrintfLite.h>
 #include <otMalloc.h>
 #include <otDMA.h>

 #define LEN 65536U

 volatile bool done = false;
 U32 st, et;

 FAST_CODE_1 void dmaCallback()
 {
     et = TimerGetCounts(TIMER0);
     done = true;
 }

 void testDma(U32 *src, U32 *dst)
 {
     done = false;
     DmaSetInterruptService(DMA_CH_0, dmaCallback);
     st = TimerGetCounts(TIMER0);

     // LEN is a count of U32 elements. LEN=65536 is legal and is encoded
     // as X_COUNT=0 by the BF51x DMA hardware.
     if(!DmaMoveChecked(DMA_CH_0, src, dst, LEN, DMA_DWORD))
     {
         printf("DMA start failed\n");
         return;
     }

     while(!done)
     {
         if(DmaHasError(DMA_CH_0))
         {
             printf("DMA error\n");
             DmaStop(DMA_CH_0);
             return;
         }
     }

     printf("DMA transfer elapsed time: %lu us\n",
            (unsigned long)ElapsedTimeUs(st, et));
     DmaEnableInterrupt(DMA_CH_0, false);
     DmaStop(DMA_CH_0);
 }
footer
otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0