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.
Fork of SPIRAM_23LC1024 by
example1.h
00001 #include "mbed.h" 00002 #include "MODDMA.h" 00003 #include "MODSERIAL.h" 00004 00005 DigitalOut led1(LED1); 00006 DigitalOut led2(LED2); 00007 DigitalOut led3(LED3); 00008 DigitalOut led4(LED4); 00009 MODDMA dma; 00010 MODSERIAL pc(USBTX, USBRX); 00011 00012 // Function prototypes for IRQ callbacks. 00013 // See definitions following main() below. 00014 void dmaTCCallback(void); 00015 void dmaERRCallback(void); 00016 void TC0_callback(void); 00017 void ERR0_callback(void); 00018 00019 int main() { 00020 char s[] = "**DMA** ABCDEFGHIJKLMNOPQRSTUVWXYZ **DMA**"; 00021 00022 pc.baud(PC_BAUD); 00023 00024 dma.attach_tc( &dmaTCCallback ); 00025 dma.attach_err( &dmaERRCallback ); 00026 00027 MODDMA_Config *config = new MODDMA_Config; 00028 config 00029 ->channelNum ( MODDMA::Channel_0 ) 00030 ->srcMemAddr ( (uint32_t) &s ) 00031 ->dstMemAddr ( 0 ) 00032 ->transferSize ( sizeof(s) ) 00033 ->transferType ( MODDMA::m2p ) 00034 ->transferWidth ( 0 ) 00035 ->srcConn ( 0 ) 00036 ->dstConn ( MODDMA::UART0_Tx ) 00037 ->dmaLLI ( 0 ) 00038 ->attach_tc ( &TC0_callback ) 00039 ->attach_err ( &ERR0_callback ) 00040 ; // config end 00041 00042 // Setup the configuration. 00043 dma.Setup(config); 00044 00045 //dma.Enable( MODDMA::Channel_0 ); 00046 //dma.Enable( config->channelNum() ); 00047 dma.Enable( config ); 00048 00049 while (1) { 00050 led1 = !led1; 00051 wait(0.25); 00052 } 00053 } 00054 00055 // Main controller TC IRQ callback 00056 void dmaTCCallback(void) { 00057 led2 = 1; 00058 } 00059 00060 // Main controller ERR IRQ callback 00061 void dmaERRCallback(void) { 00062 error("Oh no! My Mbed exploded! :( Only kidding, find the problem"); 00063 } 00064 00065 // Configuration callback on TC 00066 void TC0_callback(void) { 00067 MODDMA_Config *config = dma.getConfig(); 00068 dma.haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum()); 00069 dma.Disable( (MODDMA::CHANNELS)config->channelNum() ); 00070 00071 // Configurations have two IRQ callbacks for TC and Err so you 00072 // know which you are processing. However, if you want to use 00073 // a single callback function you can tell what type of IRQ 00074 // is being processed thus:- 00075 if (dma.irqType() == MODDMA::TcIrq) { 00076 led3 = 1; 00077 dma.clearTcIrq(); 00078 } 00079 if (dma.irqType() == MODDMA::ErrIrq) { 00080 led4 = 1; 00081 dma.clearErrIrq(); 00082 } 00083 } 00084 00085 // Configuration cakllback on Error 00086 void ERR0_callback(void) { 00087 error("Oh no! My Mbed exploded! :( Only kidding, find the problem"); 00088 } 00089
Generated on Wed Jul 13 2022 17:00:38 by
1.7.2
