MODDMA GPDMA Controller New features: transfer pins to memory buffer under periodic timer control and send double buffers to DAC

Dependents:   FirstTest WaveSim IO-dma-memmem DACDMAfuncgenlib ... more

Committer:
AjK
Date:
Wed Nov 24 00:32:49 2010 +0000
Revision:
7:347110c7aefc
Parent:
6:40d38be4bb59
Child:
8:cb4d323ce6fd
1.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:c409efd8df78 1 #ifdef COMPILE_EXAMPLE_CODE_MODDMA
AjK 0:c409efd8df78 2
AjK 0:c409efd8df78 3 #include "mbed.h"
AjK 0:c409efd8df78 4 #include "MODDMA.h"
AjK 6:40d38be4bb59 5 #include "MODSERIAL.h"
AjK 0:c409efd8df78 6
AjK 0:c409efd8df78 7 DigitalOut led1(LED1);
AjK 0:c409efd8df78 8 DigitalOut led2(LED2);
AjK 0:c409efd8df78 9 DigitalOut led3(LED3);
AjK 0:c409efd8df78 10 DigitalOut led4(LED4);
AjK 0:c409efd8df78 11 MODDMA dma;
AjK 6:40d38be4bb59 12 MODSERIAL pc(USBTX, USBRX);
AjK 4:67f327b9278e 13
AjK 4:67f327b9278e 14 // Function prototypes for IRQ callbacks.
AjK 4:67f327b9278e 15 // See definitions following main() below.
AjK 4:67f327b9278e 16 void dmaTCCallback(void);
AjK 4:67f327b9278e 17 void dmaERRCallback(void);
AjK 4:67f327b9278e 18 void TC0_callback(void);
AjK 4:67f327b9278e 19 void ERR0_callback(void);
AjK 0:c409efd8df78 20
AjK 4:67f327b9278e 21 int main() {
AjK 4:67f327b9278e 22 char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**";
AjK 4:67f327b9278e 23
AjK 4:67f327b9278e 24 pc.baud(PC_BAUD);
AjK 4:67f327b9278e 25
AjK 5:c39b22fa0c60 26 dma.attach_tc( &dmaTCCallback );
AjK 5:c39b22fa0c60 27 dma.attach_err( &dmaERRCallback );
AjK 4:67f327b9278e 28
AjK 4:67f327b9278e 29 MODDMA_Config *config = new MODDMA_Config;
AjK 4:67f327b9278e 30 config
AjK 4:67f327b9278e 31 ->channelNum ( MODDMA::Channel_0 )
AjK 4:67f327b9278e 32 ->srcMemAddr ( (uint32_t) &s )
AjK 4:67f327b9278e 33 ->dstMemAddr ( 0 )
AjK 4:67f327b9278e 34 ->transferSize ( sizeof(s) )
AjK 4:67f327b9278e 35 ->transferType ( MODDMA::m2p )
AjK 4:67f327b9278e 36 ->transferWidth ( 0 )
AjK 4:67f327b9278e 37 ->srcConn ( 0 )
AjK 4:67f327b9278e 38 ->dstConn ( MODDMA::UART0_Tx )
AjK 4:67f327b9278e 39 ->dmaLLI ( 0 )
AjK 5:c39b22fa0c60 40 ->attach_tc ( &TC0_callback )
AjK 5:c39b22fa0c60 41 ->attach_err ( &ERR0_callback )
AjK 4:67f327b9278e 42 ; // config end
AjK 4:67f327b9278e 43
AjK 4:67f327b9278e 44 // Setup the configuration.
AjK 4:67f327b9278e 45 dma.Setup(config);
AjK 4:67f327b9278e 46
AjK 4:67f327b9278e 47 //dma.Enable( MODDMA::Channel_0 );
AjK 7:347110c7aefc 48 //dma.Enable( config->channelNum() );
AjK 7:347110c7aefc 49 dma.Enable( config );
AjK 4:67f327b9278e 50
AjK 4:67f327b9278e 51 while (1) {
AjK 4:67f327b9278e 52 led1 = !led1;
AjK 4:67f327b9278e 53 wait(0.25);
AjK 4:67f327b9278e 54 }
AjK 4:67f327b9278e 55 }
AjK 4:67f327b9278e 56
AjK 4:67f327b9278e 57 // Main controller TC IRQ callback
AjK 4:67f327b9278e 58 void dmaTCCallback(void) {
AjK 0:c409efd8df78 59 led2 = 1;
AjK 0:c409efd8df78 60 }
AjK 0:c409efd8df78 61
AjK 4:67f327b9278e 62 // Main controller ERR IRQ callback
AjK 4:67f327b9278e 63 void dmaERRCallback(void) {
AjK 4:67f327b9278e 64 error("Oh no! My Mbed exploded! :( Only kidding, find the problem");
AjK 4:67f327b9278e 65 }
AjK 4:67f327b9278e 66
AjK 4:67f327b9278e 67 // Configuration callback on TC
AjK 4:67f327b9278e 68 void TC0_callback(void) {
AjK 0:c409efd8df78 69 MODDMA_Config *config = dma.getConfig();
AjK 0:c409efd8df78 70 dma.haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum());
AjK 0:c409efd8df78 71 dma.Disable( (MODDMA::CHANNELS)config->channelNum() );
AjK 4:67f327b9278e 72
AjK 4:67f327b9278e 73 // Configurations have two IRQ callbacks for TC and Err so you
AjK 4:67f327b9278e 74 // know which you are processing. However, if you want to use
AjK 4:67f327b9278e 75 // a single callback function you can tell what type of IRQ
AjK 4:67f327b9278e 76 // is being processed thus:-
AjK 0:c409efd8df78 77 if (dma.irqType() == MODDMA::TcIrq) {
AjK 0:c409efd8df78 78 led3 = 1;
AjK 0:c409efd8df78 79 dma.clearTcIrq();
AjK 0:c409efd8df78 80 }
AjK 0:c409efd8df78 81 if (dma.irqType() == MODDMA::ErrIrq) {
AjK 0:c409efd8df78 82 led4 = 1;
AjK 0:c409efd8df78 83 dma.clearErrIrq();
AjK 0:c409efd8df78 84 }
AjK 0:c409efd8df78 85 }
AjK 0:c409efd8df78 86
AjK 4:67f327b9278e 87 // Configuration cakllback on Error
AjK 4:67f327b9278e 88 void ERR0_callback(void) {
AjK 4:67f327b9278e 89 error("Oh no! My Mbed exploded! :( Only kidding, find the problem");
AjK 0:c409efd8df78 90 }
AjK 0:c409efd8df78 91
AjK 0:c409efd8df78 92 #endif