Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
example1.h
00001 #include "mbed.h" 00002 #include "MODDMA.h" 00003 00004 DigitalOut led1(LED1); 00005 DigitalOut led2(LED2); 00006 DigitalOut led3(LED3); 00007 DigitalOut led4(LED4); 00008 MODDMA dma; 00009 00010 // Function prototypes for IRQ callbacks. 00011 // See definitions following main() below. 00012 void dmaTCCallback(void); 00013 void dmaERRCallback(void); 00014 void TC0_callback(void); 00015 void ERR0_callback(void); 00016 00017 /** 00018 * @brief 00019 * @note 00020 * @param 00021 * @retval 00022 */ 00023 int main() 00024 { 00025 char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**"; 00026 00027 printf("\r\nStarting\r\n"); 00028 00029 dma.attach_tc(&dmaTCCallback); 00030 dma.attach_err(&dmaERRCallback); 00031 00032 MODDMA_Config* config = new MODDMA_Config; 00033 00034 config->channelNum(MODDMA::Channel_0); 00035 config->srcMemAddr((uint32_t) & s); 00036 config->dstMemAddr(0); 00037 config->transferSize(sizeof(s)); 00038 config->transferType(MODDMA::m2p); 00039 config->transferWidth(0); 00040 config->srcConn(0); 00041 config->dstConn(MODDMA::UART0_Tx); 00042 config->dmaLLI(0)->attach_tc(&TC0_callback); 00043 config->attach_err(&ERR0_callback); 00044 00045 // Setup the configuration. 00046 dma.Setup(config); 00047 00048 //dma.Enable( MODDMA::Channel_0 ); 00049 //dma.Enable( config->channelNum() ); 00050 dma.Enable(config); 00051 00052 while (1) { 00053 led1 = !led1; 00054 ThisThread::sleep_for(250ms); 00055 } 00056 } 00057 00058 // Main controller TC IRQ callback 00059 void dmaTCCallback(void) 00060 { 00061 led2 = 1; 00062 } 00063 00064 // Main controller ERR IRQ callback 00065 void dmaERRCallback(void) 00066 { 00067 printf("Oh no! My Mbed exploded! :( Only kidding, find the problem"); 00068 } 00069 00070 // Configuration callback on TC 00071 void TC0_callback(void) 00072 { 00073 MODDMA_Config* config = dma.getConfig(); 00074 00075 dma.haltAndWaitChannelComplete((MODDMA::CHANNELS) config->channelNum()); 00076 dma.Disable((MODDMA::CHANNELS) config->channelNum()); 00077 00078 // Configurations have two IRQ callbacks for TC and Err so you 00079 // know which you are processing. However, if you want to use 00080 // a single callback function you can tell what type of IRQ 00081 // is being processed thus:- 00082 if (dma.irqType() == MODDMA::TcIrq) { 00083 led3 = 1; 00084 dma.clearTcIrq(); 00085 } 00086 00087 if (dma.irqType() == MODDMA::ErrIrq) { 00088 led4 = 1; 00089 dma.clearErrIrq(); 00090 } 00091 } 00092 00093 // Configuration cakllback on Error 00094 void ERR0_callback(void) 00095 { 00096 printf("Oh no! My Mbed exploded! :( Only kidding, find the problem"); 00097 }
Generated on Mon Dec 12 2022 15:08:43 by
1.7.2