GPDMA (Direct Memory Access) and LLI (Link List Item) test see: http://mbed.org/users/okini3939/notebook/dma_jp/
MODDMA/example1.h@1:1a77fa863282, 2013-09-13 (annotated)
- Committer:
- okini3939
- Date:
- Fri Sep 13 15:19:09 2013 +0000
- Revision:
- 1:1a77fa863282
- Parent:
- 0:de79d4a48e63
fix more lli
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:de79d4a48e63 | 1 | #include "mbed.h" |
okini3939 | 0:de79d4a48e63 | 2 | #include "MODDMA.h" |
okini3939 | 0:de79d4a48e63 | 3 | #include "MODSERIAL.h" |
okini3939 | 0:de79d4a48e63 | 4 | |
okini3939 | 0:de79d4a48e63 | 5 | DigitalOut led1(LED1); |
okini3939 | 0:de79d4a48e63 | 6 | DigitalOut led2(LED2); |
okini3939 | 0:de79d4a48e63 | 7 | DigitalOut led3(LED3); |
okini3939 | 0:de79d4a48e63 | 8 | DigitalOut led4(LED4); |
okini3939 | 0:de79d4a48e63 | 9 | MODDMA dma; |
okini3939 | 0:de79d4a48e63 | 10 | MODSERIAL pc(USBTX, USBRX); |
okini3939 | 0:de79d4a48e63 | 11 | |
okini3939 | 0:de79d4a48e63 | 12 | // Function prototypes for IRQ callbacks. |
okini3939 | 0:de79d4a48e63 | 13 | // See definitions following main() below. |
okini3939 | 0:de79d4a48e63 | 14 | void dmaTCCallback(void); |
okini3939 | 0:de79d4a48e63 | 15 | void dmaERRCallback(void); |
okini3939 | 0:de79d4a48e63 | 16 | void TC0_callback(void); |
okini3939 | 0:de79d4a48e63 | 17 | void ERR0_callback(void); |
okini3939 | 0:de79d4a48e63 | 18 | |
okini3939 | 0:de79d4a48e63 | 19 | int main() { |
okini3939 | 0:de79d4a48e63 | 20 | char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**"; |
okini3939 | 0:de79d4a48e63 | 21 | |
okini3939 | 0:de79d4a48e63 | 22 | pc.baud(PC_BAUD); |
okini3939 | 0:de79d4a48e63 | 23 | |
okini3939 | 0:de79d4a48e63 | 24 | dma.attach_tc( &dmaTCCallback ); |
okini3939 | 0:de79d4a48e63 | 25 | dma.attach_err( &dmaERRCallback ); |
okini3939 | 0:de79d4a48e63 | 26 | |
okini3939 | 0:de79d4a48e63 | 27 | MODDMA_Config *config = new MODDMA_Config; |
okini3939 | 0:de79d4a48e63 | 28 | config |
okini3939 | 0:de79d4a48e63 | 29 | ->channelNum ( MODDMA::Channel_0 ) |
okini3939 | 0:de79d4a48e63 | 30 | ->srcMemAddr ( (uint32_t) &s ) |
okini3939 | 0:de79d4a48e63 | 31 | ->dstMemAddr ( 0 ) |
okini3939 | 0:de79d4a48e63 | 32 | ->transferSize ( sizeof(s) ) |
okini3939 | 0:de79d4a48e63 | 33 | ->transferType ( MODDMA::m2p ) |
okini3939 | 0:de79d4a48e63 | 34 | ->transferWidth ( 0 ) |
okini3939 | 0:de79d4a48e63 | 35 | ->srcConn ( 0 ) |
okini3939 | 0:de79d4a48e63 | 36 | ->dstConn ( MODDMA::UART0_Tx ) |
okini3939 | 0:de79d4a48e63 | 37 | ->dmaLLI ( 0 ) |
okini3939 | 0:de79d4a48e63 | 38 | ->attach_tc ( &TC0_callback ) |
okini3939 | 0:de79d4a48e63 | 39 | ->attach_err ( &ERR0_callback ) |
okini3939 | 0:de79d4a48e63 | 40 | ; // config end |
okini3939 | 0:de79d4a48e63 | 41 | |
okini3939 | 0:de79d4a48e63 | 42 | // Setup the configuration. |
okini3939 | 0:de79d4a48e63 | 43 | dma.Setup(config); |
okini3939 | 0:de79d4a48e63 | 44 | |
okini3939 | 0:de79d4a48e63 | 45 | //dma.Enable( MODDMA::Channel_0 ); |
okini3939 | 0:de79d4a48e63 | 46 | //dma.Enable( config->channelNum() ); |
okini3939 | 0:de79d4a48e63 | 47 | dma.Enable( config ); |
okini3939 | 0:de79d4a48e63 | 48 | |
okini3939 | 0:de79d4a48e63 | 49 | while (1) { |
okini3939 | 0:de79d4a48e63 | 50 | led1 = !led1; |
okini3939 | 0:de79d4a48e63 | 51 | wait(0.25); |
okini3939 | 0:de79d4a48e63 | 52 | } |
okini3939 | 0:de79d4a48e63 | 53 | } |
okini3939 | 0:de79d4a48e63 | 54 | |
okini3939 | 0:de79d4a48e63 | 55 | // Main controller TC IRQ callback |
okini3939 | 0:de79d4a48e63 | 56 | void dmaTCCallback(void) { |
okini3939 | 0:de79d4a48e63 | 57 | led2 = 1; |
okini3939 | 0:de79d4a48e63 | 58 | } |
okini3939 | 0:de79d4a48e63 | 59 | |
okini3939 | 0:de79d4a48e63 | 60 | // Main controller ERR IRQ callback |
okini3939 | 0:de79d4a48e63 | 61 | void dmaERRCallback(void) { |
okini3939 | 0:de79d4a48e63 | 62 | error("Oh no! My Mbed exploded! :( Only kidding, find the problem"); |
okini3939 | 0:de79d4a48e63 | 63 | } |
okini3939 | 0:de79d4a48e63 | 64 | |
okini3939 | 0:de79d4a48e63 | 65 | // Configuration callback on TC |
okini3939 | 0:de79d4a48e63 | 66 | void TC0_callback(void) { |
okini3939 | 0:de79d4a48e63 | 67 | MODDMA_Config *config = dma.getConfig(); |
okini3939 | 0:de79d4a48e63 | 68 | dma.haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum()); |
okini3939 | 0:de79d4a48e63 | 69 | dma.Disable( (MODDMA::CHANNELS)config->channelNum() ); |
okini3939 | 0:de79d4a48e63 | 70 | |
okini3939 | 0:de79d4a48e63 | 71 | // Configurations have two IRQ callbacks for TC and Err so you |
okini3939 | 0:de79d4a48e63 | 72 | // know which you are processing. However, if you want to use |
okini3939 | 0:de79d4a48e63 | 73 | // a single callback function you can tell what type of IRQ |
okini3939 | 0:de79d4a48e63 | 74 | // is being processed thus:- |
okini3939 | 0:de79d4a48e63 | 75 | if (dma.irqType() == MODDMA::TcIrq) { |
okini3939 | 0:de79d4a48e63 | 76 | led3 = 1; |
okini3939 | 0:de79d4a48e63 | 77 | dma.clearTcIrq(); |
okini3939 | 0:de79d4a48e63 | 78 | } |
okini3939 | 0:de79d4a48e63 | 79 | if (dma.irqType() == MODDMA::ErrIrq) { |
okini3939 | 0:de79d4a48e63 | 80 | led4 = 1; |
okini3939 | 0:de79d4a48e63 | 81 | dma.clearErrIrq(); |
okini3939 | 0:de79d4a48e63 | 82 | } |
okini3939 | 0:de79d4a48e63 | 83 | } |
okini3939 | 0:de79d4a48e63 | 84 | |
okini3939 | 0:de79d4a48e63 | 85 | // Configuration cakllback on Error |
okini3939 | 0:de79d4a48e63 | 86 | void ERR0_callback(void) { |
okini3939 | 0:de79d4a48e63 | 87 | error("Oh no! My Mbed exploded! :( Only kidding, find the problem"); |
okini3939 | 0:de79d4a48e63 | 88 | } |
okini3939 | 0:de79d4a48e63 | 89 |