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