GPDMA (Direct Memory Access) and LLI (Link List Item) test see: http://mbed.org/users/okini3939/notebook/dma_jp/

Dependencies:   mbed

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?

UserRevisionLine numberNew contents of line
okini3939 0:de79d4a48e63 1 #include "mbed.h"
okini3939 0:de79d4a48e63 2 #include "MODDMA.h"
okini3939 0:de79d4a48e63 3
okini3939 1:1a77fa863282 4 #define LLI_NUM 5
okini3939 0:de79d4a48e63 5
okini3939 0:de79d4a48e63 6 Serial pc(USBTX, USBRX);
okini3939 1:1a77fa863282 7 DigitalOut myled(LED1), errled(LED4);
okini3939 0:de79d4a48e63 8
okini3939 0:de79d4a48e63 9 MODDMA dma;
okini3939 0:de79d4a48e63 10 MODDMA_Config *dmacfg;
okini3939 0:de79d4a48e63 11 MODDMA_LLI *lli[LLI_NUM];
okini3939 0:de79d4a48e63 12 MODDMA::GPDMA_CONNECTION dmacon;
okini3939 0:de79d4a48e63 13 volatile int dmacount = 0;
okini3939 0:de79d4a48e63 14 char dmadata[LLI_NUM][40];
okini3939 0:de79d4a48e63 15 char text[] = "* count, dmadata[*] abcdefg\r\n";
okini3939 0:de79d4a48e63 16
okini3939 0:de79d4a48e63 17 void tc_callback () {
okini3939 0:de79d4a48e63 18 int i;
okini3939 0:de79d4a48e63 19 MODDMA_Config *config = dma.getConfig();
okini3939 0:de79d4a48e63 20
okini3939 1:1a77fa863282 21 myled = ! myled;
okini3939 1:1a77fa863282 22
okini3939 0:de79d4a48e63 23 for (i = 0; i < LLI_NUM; i ++) {
okini3939 0:de79d4a48e63 24 dmadata[i][0] = '0' + dmacount;
okini3939 0:de79d4a48e63 25 }
okini3939 1:1a77fa863282 26
okini3939 0:de79d4a48e63 27 dmacount ++;
okini3939 1:1a77fa863282 28 if (dmacount > 10) {
okini3939 1:1a77fa863282 29 lli[LLI_NUM - 1]->Control = NULL;
okini3939 0:de79d4a48e63 30 }
okini3939 1:1a77fa863282 31
okini3939 0:de79d4a48e63 32 // Clear DMA IRQ flags.
okini3939 0:de79d4a48e63 33 if (dma.irqType() == MODDMA::TcIrq) dma.clearTcIrq();
okini3939 0:de79d4a48e63 34 if (dma.irqType() == MODDMA::ErrIrq) dma.clearErrIrq();
okini3939 0:de79d4a48e63 35 }
okini3939 0:de79d4a48e63 36
okini3939 0:de79d4a48e63 37 void err_callback () {
okini3939 1:1a77fa863282 38 MODDMA_Config *config = dma.getConfig();
okini3939 1:1a77fa863282 39
okini3939 1:1a77fa863282 40 errled = 1;
okini3939 1:1a77fa863282 41 dma.Disable( (MODDMA::CHANNELS)config->channelNum() );
okini3939 0:de79d4a48e63 42 }
okini3939 0:de79d4a48e63 43
okini3939 0:de79d4a48e63 44
okini3939 0:de79d4a48e63 45 int main() {
okini3939 0:de79d4a48e63 46 int i, len;
okini3939 0:de79d4a48e63 47
okini3939 0:de79d4a48e63 48 pc.printf("MODDMA LLI test\r\n");
okini3939 0:de79d4a48e63 49
okini3939 0:de79d4a48e63 50 dmacfg = new MODDMA_Config;
okini3939 0:de79d4a48e63 51 dmacon = MODDMA::UART0_Tx;
okini3939 0:de79d4a48e63 52
okini3939 0:de79d4a48e63 53 len = strlen(text);
okini3939 0:de79d4a48e63 54 for (i = 0; i < LLI_NUM; i ++) {
okini3939 0:de79d4a48e63 55 strcpy(dmadata[i], text);
okini3939 0:de79d4a48e63 56 dmadata[i][17] = '0' + i;
okini3939 0:de79d4a48e63 57
okini3939 0:de79d4a48e63 58 lli[i] = new MODDMA_LLI;
okini3939 0:de79d4a48e63 59 }
okini3939 0:de79d4a48e63 60
okini3939 0:de79d4a48e63 61 dmacfg
okini3939 0:de79d4a48e63 62 ->channelNum ( MODDMA::Channel_0 )
okini3939 0:de79d4a48e63 63 ->srcMemAddr ( (uint32_t)dmadata[0] )
okini3939 0:de79d4a48e63 64 ->dstConn ( dmacon )
okini3939 0:de79d4a48e63 65 ->transferSize ( len )
okini3939 0:de79d4a48e63 66 ->transferType ( MODDMA::m2p )
okini3939 0:de79d4a48e63 67 ->dmaLLI ( (uint32_t)lli[1] )
okini3939 0:de79d4a48e63 68 ->attach_tc ( tc_callback )
okini3939 0:de79d4a48e63 69 ->attach_err ( err_callback )
okini3939 0:de79d4a48e63 70 ; // config end
okini3939 0:de79d4a48e63 71 lli[0]->SrcAddr = (uint32_t)dmadata[0];
okini3939 0:de79d4a48e63 72 lli[0]->DstAddr = (uint32_t)dma.LUTPerAddr(dmacon);
okini3939 0:de79d4a48e63 73 lli[0]->NextLLI = (uint32_t)lli[1];
okini3939 0:de79d4a48e63 74 lli[0]->Control = dma.CxControl_TransferSize((uint32_t)len)
okini3939 0:de79d4a48e63 75 | dma.CxControl_SBSize((uint32_t)dma.LUTPerBurst(dmacon))
okini3939 0:de79d4a48e63 76 | dma.CxControl_DBSize((uint32_t)dma.LUTPerBurst(dmacon))
okini3939 0:de79d4a48e63 77 | dma.CxControl_SWidth((uint32_t)dma.LUTPerWid(dmacon))
okini3939 0:de79d4a48e63 78 | dma.CxControl_DWidth((uint32_t)dma.LUTPerWid(dmacon))
okini3939 0:de79d4a48e63 79 | dma.CxControl_SI()
okini3939 0:de79d4a48e63 80 | dma.CxControl_I();
okini3939 0:de79d4a48e63 81 for (i = 1; i < LLI_NUM; i ++) {
okini3939 0:de79d4a48e63 82 lli[i]->SrcAddr = (uint32_t)dmadata[i];
okini3939 0:de79d4a48e63 83 lli[i]->DstAddr = lli[0]->DstAddr;
okini3939 0:de79d4a48e63 84 lli[i]->NextLLI = (uint32_t)lli[i < LLI_NUM - 1 ? i + 1 : 0];
okini3939 0:de79d4a48e63 85 lli[i]->Control = lli[0]->Control;
okini3939 0:de79d4a48e63 86 }
okini3939 0:de79d4a48e63 87
okini3939 0:de79d4a48e63 88 if (dma.Setup( dmacfg )) {
okini3939 0:de79d4a48e63 89 // _ssp->FCR = (1<<3); // DMA Mode
okini3939 0:de79d4a48e63 90 dma.Enable( dmacfg );
okini3939 0:de79d4a48e63 91 }
okini3939 0:de79d4a48e63 92
okini3939 0:de79d4a48e63 93 wait(3);
okini3939 0:de79d4a48e63 94 pc.printf("end\r\n");
okini3939 0:de79d4a48e63 95
okini3939 0:de79d4a48e63 96 return 0;
okini3939 0:de79d4a48e63 97 }