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

Files at this revision

API Documentation at this revision

Comitter:
AjK
Date:
Tue Nov 23 15:33:30 2010 +0000
Parent:
3:f61c089ca882
Child:
5:c39b22fa0c60
Commit message:
1.1

Changed in this revision

ChangeLog.c Show annotated file Show diff for this revision Revisions of this file
MODDMA.h Show annotated file Show diff for this revision Revisions of this file
example1.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ChangeLog.c	Tue Nov 23 15:08:21 2010 +0000
+++ b/ChangeLog.c	Tue Nov 23 15:33:30 2010 +0000
@@ -1,6 +1,10 @@
 /* $Id:$
 
+1.1 - 23/10/2010
 
+    * Tidied up example1.cpp
+    * Removed some unneeded methoids that cause compiler errs.
+    
 1.0 - 23/11/2010
 
     * First release
--- a/MODDMA.h	Tue Nov 23 15:08:21 2010 +0000
+++ b/MODDMA.h	Tue Nov 23 15:33:30 2010 +0000
@@ -21,7 +21,7 @@
     
     @file          MODDMA.h 
     @purpose       Adds DMA controller and multiple transfer configurations
-    @version       1.0
+    @version       1.1
     @date          Nov 2010
     @author        Andy Kirkham    
 */
@@ -347,7 +347,7 @@
      * @param ChannelNumber Type uin32_t, the channel number to test
      * @return bool true if enabled, false otherwise.
      */
-    bool Enabled(uint32_t ChannelNumber) { Enabled((CHANNELS)(ChannelNumber & 0x7)); }
+    bool Enabled(uint32_t ChannelNumber) { return Enabled((CHANNELS)(ChannelNumber & 0x7)); }
     
     __INLINE uint32_t IntStat(uint32_t n)            { return (1UL << n) & 0xFF; }
     __INLINE uint32_t IntTCStat_Ch(uint32_t n)       { return (1UL << n) & 0xFF; }
@@ -417,13 +417,6 @@
     CHANNELS irqProcessingChannel(void) { return IrqProcessingChannel; }
     
     /**
-     * Gets which channel the ISR is currently servicing.
-     *
-     * @return uint32_t The current channel the ISR is servicing.
-     */
-    uint32_t irqProcessingChannel(void) { return (uint32_t)(IrqProcessingChannel & 0x7); }
-    
-    /**
      * Sets which type of IRQ the ISR is making a callback for.
      *
      * *** USED INTERNALLY. DO NOT CALL FROM USER PROGRAMS ***
--- a/example1.cpp	Tue Nov 23 15:08:21 2010 +0000
+++ b/example1.cpp	Tue Nov 23 15:33:30 2010 +0000
@@ -2,24 +2,78 @@
 
 #include "mbed.h"
 #include "MODDMA.h"
-#include "MODSERIAL.h"
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 MODDMA dma;
-MODSERIAL pc(USBTX, USBRX);
-//Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
+
+// Function prototypes for IRQ callbacks.
+// See definitions following main() below.
+void dmaTCCallback(void);
+void dmaERRCallback(void);
+void TC0_callback(void);
+void ERR0_callback(void);
 
-void dmaCallback(void) {
+int main() {
+    char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**";
+    
+    pc.baud(PC_BAUD);
+    
+    dma.isrIntTCStat.attach(&dmaTCCallback);
+    dma.isrIntErrStat.attach(&dmaERRCallback);
+    
+    MODDMA_Config *config = new MODDMA_Config;
+    config
+     ->channelNum    ( MODDMA::Channel_0 )
+     ->srcMemAddr    ( (uint32_t) &s )
+     ->dstMemAddr    ( 0 )
+     ->transferSize  ( sizeof(s) )
+     ->transferType  ( MODDMA::m2p )
+     ->transferWidth ( 0 )
+     ->srcConn       ( 0 )
+     ->dstConn       ( MODDMA::UART0_Tx )
+     ->dmaLLI        ( 0 )
+    ; // config end
+    
+    // Attach configuration callbacks if required.
+    config->isrIntTCStat->attach(&TC0_callback);
+    config->isrIntErrStat->attach(&ERR0_callback);
+    
+    // Setup the configuration.
+    dma.Setup(config);
+    
+    //dma.Enable( MODDMA::Channel_0 );
+    dma.Enable( config->channelNum() );
+    
+    while (1) {
+        led1 = !led1;
+        wait(0.25);        
+    }
+}
+
+// Main controller TC IRQ callback
+void dmaTCCallback(void) {
     led2 = 1;
 }
 
-void C0callback(void) {
+// Main controller ERR IRQ callback
+void dmaERRCallback(void) {
+    error("Oh no! My Mbed exploded! :( Only kidding, find the problem");
+}
+
+// Configuration callback on TC
+void TC0_callback(void) {
     MODDMA_Config *config = dma.getConfig();
     dma.haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum());
     dma.Disable( (MODDMA::CHANNELS)config->channelNum() );
+    
+    // Configurations have two IRQ callbacks for TC and Err so you 
+    // know which you are processing. However, if you want to use 
+    // a single callback function you can tell what type of IRQ 
+    // is being processed thus:-
     if (dma.irqType() == MODDMA::TcIrq)  {
         led3 = 1;
         dma.clearTcIrq();
@@ -30,42 +84,9 @@
     }
 }
 
-int main() {
-    char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**";
-    
-    pc.baud(115200);
-    
-    dma.isrIntTCStat.attach(&dmaCallback);
-    
-    MODDMA_Config *config = new MODDMA_Config;
-    config
-     ->channelNum    ( MODDMA::Channel_0 )
-     ->srcMemAddr    ( (uint32_t) &s )
-     //->dstMemAddr    ( 0 )
-     ->transferSize  ( sizeof(s) )
-     ->transferType  ( MODDMA::m2p )
-     //->transferWidth ( 0 )
-     //->srcConn       ( 0 )
-     ->dstConn       ( MODDMA::UART0_Tx )
-     //->dmaLLI        ( 0 )
-     ;//->isrIntTCStat->attach(&C0callback)
-    ; // config end
-   
-    dma.Setup(config);
-    
-    //dma.Enable( MODDMA::Channel_0 );
-    dma.Enable( config->channelNum() );
-    
-    pc.printf("123456789\r\n");
-    pc.printf("\r\nRESERVED9 = %p", &LPC_SC->RESERVED9);
-    pc.printf("\r\nOther = %p", &LPC_UART0->DMAREQSEL);
-    
-    while (1) {
-        led1 = !led1;
-        wait(0.2);
-        led1 = !led1;
-        wait(0.2);
-    }
+// Configuration cakllback on Error
+void ERR0_callback(void) {
+    error("Oh no! My Mbed exploded! :( Only kidding, find the problem");
 }
 
 #endif