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