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:
Tue Nov 23 15:33:30 2010 +0000
Revision:
4:67f327b9278e
Parent:
0:c409efd8df78
Child:
5:c39b22fa0c60
1.1

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 0:c409efd8df78 5
AjK 0:c409efd8df78 6 DigitalOut led1(LED1);
AjK 0:c409efd8df78 7 DigitalOut led2(LED2);
AjK 0:c409efd8df78 8 DigitalOut led3(LED3);
AjK 0:c409efd8df78 9 DigitalOut led4(LED4);
AjK 0:c409efd8df78 10 MODDMA dma;
AjK 4:67f327b9278e 11 Serial pc(USBTX, USBRX);
AjK 4:67f327b9278e 12
AjK 4:67f327b9278e 13 // Function prototypes for IRQ callbacks.
AjK 4:67f327b9278e 14 // See definitions following main() below.
AjK 4:67f327b9278e 15 void dmaTCCallback(void);
AjK 4:67f327b9278e 16 void dmaERRCallback(void);
AjK 4:67f327b9278e 17 void TC0_callback(void);
AjK 4:67f327b9278e 18 void ERR0_callback(void);
AjK 0:c409efd8df78 19
AjK 4:67f327b9278e 20 int main() {
AjK 4:67f327b9278e 21 char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**";
AjK 4:67f327b9278e 22
AjK 4:67f327b9278e 23 pc.baud(PC_BAUD);
AjK 4:67f327b9278e 24
AjK 4:67f327b9278e 25 dma.isrIntTCStat.attach(&dmaTCCallback);
AjK 4:67f327b9278e 26 dma.isrIntErrStat.attach(&dmaERRCallback);
AjK 4:67f327b9278e 27
AjK 4:67f327b9278e 28 MODDMA_Config *config = new MODDMA_Config;
AjK 4:67f327b9278e 29 config
AjK 4:67f327b9278e 30 ->channelNum ( MODDMA::Channel_0 )
AjK 4:67f327b9278e 31 ->srcMemAddr ( (uint32_t) &s )
AjK 4:67f327b9278e 32 ->dstMemAddr ( 0 )
AjK 4:67f327b9278e 33 ->transferSize ( sizeof(s) )
AjK 4:67f327b9278e 34 ->transferType ( MODDMA::m2p )
AjK 4:67f327b9278e 35 ->transferWidth ( 0 )
AjK 4:67f327b9278e 36 ->srcConn ( 0 )
AjK 4:67f327b9278e 37 ->dstConn ( MODDMA::UART0_Tx )
AjK 4:67f327b9278e 38 ->dmaLLI ( 0 )
AjK 4:67f327b9278e 39 ; // config end
AjK 4:67f327b9278e 40
AjK 4:67f327b9278e 41 // Attach configuration callbacks if required.
AjK 4:67f327b9278e 42 config->isrIntTCStat->attach(&TC0_callback);
AjK 4:67f327b9278e 43 config->isrIntErrStat->attach(&ERR0_callback);
AjK 4:67f327b9278e 44
AjK 4:67f327b9278e 45 // Setup the configuration.
AjK 4:67f327b9278e 46 dma.Setup(config);
AjK 4:67f327b9278e 47
AjK 4:67f327b9278e 48 //dma.Enable( MODDMA::Channel_0 );
AjK 4:67f327b9278e 49 dma.Enable( config->channelNum() );
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