http://mbed.org/cookbook/MODDMA

Dependencies:   MODDMA mbed

main.cpp

Committer:
avnisha
Date:
2013-09-04
Revision:
0:ad229870f727

File content as of revision 0:ad229870f727:

#ifdef OLD
#include "mbed.h"

DigitalOut myled(LED1);

int main() {
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}
#endif

#include "mbed.h"
#include "MODDMA.h"
 
DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
MODDMA dma;
 
int main() {
    pc.baud(115200);
    pc.printf("Hello World\r\n");
    
    // Create a source buffer we are going to move.
    char src[] = "TEST TEST TEST";
    
    // Create a buffer for the destination to copy to.
    char dst[sizeof(src)];
    
    // Create a MODDMA configuration object.
    MODDMA_Config *config = new MODDMA_Config;
    
    // Setup that configuration
    config
     ->channelNum    ( MODDMA::Channel_0 )
     ->srcMemAddr    ( (uint32_t) &src )
     ->dstMemAddr    ( (uint32_t) &dst )
     ->transferSize  ( sizeof(src) )
     ->transferType  ( MODDMA::m2m )     
    ; // config end
 
    // Pass the configuration to the controller
    dma.Setup( config );
    
    // Tell the controller to perform the DMA operation
    // defined by that configuration.
    dma.Enable ( config );
    
    wait(1);
    
    pc.printf("%s\r\n", dst);
    
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}