![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
http://mbed.org/cookbook/MODDMA
main.cpp@0:ad229870f727, 2013-09-04 (annotated)
- Committer:
- avnisha
- Date:
- Wed Sep 04 19:44:37 2013 +0000
- Revision:
- 0:ad229870f727
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avnisha | 0:ad229870f727 | 1 | #ifdef OLD |
avnisha | 0:ad229870f727 | 2 | #include "mbed.h" |
avnisha | 0:ad229870f727 | 3 | |
avnisha | 0:ad229870f727 | 4 | DigitalOut myled(LED1); |
avnisha | 0:ad229870f727 | 5 | |
avnisha | 0:ad229870f727 | 6 | int main() { |
avnisha | 0:ad229870f727 | 7 | while(1) { |
avnisha | 0:ad229870f727 | 8 | myled = 1; |
avnisha | 0:ad229870f727 | 9 | wait(0.2); |
avnisha | 0:ad229870f727 | 10 | myled = 0; |
avnisha | 0:ad229870f727 | 11 | wait(0.2); |
avnisha | 0:ad229870f727 | 12 | } |
avnisha | 0:ad229870f727 | 13 | } |
avnisha | 0:ad229870f727 | 14 | #endif |
avnisha | 0:ad229870f727 | 15 | |
avnisha | 0:ad229870f727 | 16 | #include "mbed.h" |
avnisha | 0:ad229870f727 | 17 | #include "MODDMA.h" |
avnisha | 0:ad229870f727 | 18 | |
avnisha | 0:ad229870f727 | 19 | DigitalOut myled(LED1); |
avnisha | 0:ad229870f727 | 20 | Serial pc(USBTX, USBRX); |
avnisha | 0:ad229870f727 | 21 | MODDMA dma; |
avnisha | 0:ad229870f727 | 22 | |
avnisha | 0:ad229870f727 | 23 | int main() { |
avnisha | 0:ad229870f727 | 24 | pc.baud(115200); |
avnisha | 0:ad229870f727 | 25 | pc.printf("Hello World\r\n"); |
avnisha | 0:ad229870f727 | 26 | |
avnisha | 0:ad229870f727 | 27 | // Create a source buffer we are going to move. |
avnisha | 0:ad229870f727 | 28 | char src[] = "TEST TEST TEST"; |
avnisha | 0:ad229870f727 | 29 | |
avnisha | 0:ad229870f727 | 30 | // Create a buffer for the destination to copy to. |
avnisha | 0:ad229870f727 | 31 | char dst[sizeof(src)]; |
avnisha | 0:ad229870f727 | 32 | |
avnisha | 0:ad229870f727 | 33 | // Create a MODDMA configuration object. |
avnisha | 0:ad229870f727 | 34 | MODDMA_Config *config = new MODDMA_Config; |
avnisha | 0:ad229870f727 | 35 | |
avnisha | 0:ad229870f727 | 36 | // Setup that configuration |
avnisha | 0:ad229870f727 | 37 | config |
avnisha | 0:ad229870f727 | 38 | ->channelNum ( MODDMA::Channel_0 ) |
avnisha | 0:ad229870f727 | 39 | ->srcMemAddr ( (uint32_t) &src ) |
avnisha | 0:ad229870f727 | 40 | ->dstMemAddr ( (uint32_t) &dst ) |
avnisha | 0:ad229870f727 | 41 | ->transferSize ( sizeof(src) ) |
avnisha | 0:ad229870f727 | 42 | ->transferType ( MODDMA::m2m ) |
avnisha | 0:ad229870f727 | 43 | ; // config end |
avnisha | 0:ad229870f727 | 44 | |
avnisha | 0:ad229870f727 | 45 | // Pass the configuration to the controller |
avnisha | 0:ad229870f727 | 46 | dma.Setup( config ); |
avnisha | 0:ad229870f727 | 47 | |
avnisha | 0:ad229870f727 | 48 | // Tell the controller to perform the DMA operation |
avnisha | 0:ad229870f727 | 49 | // defined by that configuration. |
avnisha | 0:ad229870f727 | 50 | dma.Enable ( config ); |
avnisha | 0:ad229870f727 | 51 | |
avnisha | 0:ad229870f727 | 52 | wait(1); |
avnisha | 0:ad229870f727 | 53 | |
avnisha | 0:ad229870f727 | 54 | pc.printf("%s\r\n", dst); |
avnisha | 0:ad229870f727 | 55 | |
avnisha | 0:ad229870f727 | 56 | while(1) { |
avnisha | 0:ad229870f727 | 57 | myled = 1; |
avnisha | 0:ad229870f727 | 58 | wait(0.2); |
avnisha | 0:ad229870f727 | 59 | myled = 0; |
avnisha | 0:ad229870f727 | 60 | wait(0.2); |
avnisha | 0:ad229870f727 | 61 | } |
avnisha | 0:ad229870f727 | 62 | } |