void DMA_IRQHandler (void) { // check GPDMA interrupt on channel 0 TRANSMISION if (GPDMA_IntGetStatus(GPDMA_STAT_INT, 0)){ //check interrupt status on channel 0 // Check counter terminal status if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0)){ // Clear terminate counter Interrupt pending GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0); Channel0_TC++; } // Check error terminal status if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0)){ // Clear error counter Interrupt pending GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0); Channel0_Err++; } } } |
#define BUFFER_SIZE 1024 uint8_t Channel0_TC = 0; uint8_t Channel0_Err = 0; uint8_t buff_tx[BUFFER_SIZE]; uin8_t *I2STXBuffer = buff_tx; void DMA_Config(void) { GPDMA_Init(); LPC_GPDMA->DMACConfig = 0x01; /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* * Configure GPDMA channel 0 ------------------------------------------------------------- * Used for I2S Transmit */ // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = I2STXBuffer; // Destination memory GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = BUFFER_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = GPDMA_CONN_I2S_Channel_0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; GPDMA_ChannelCmd(0, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); I2S_DMAStruct.DMAIndex = I2S_DMA_1; I2S_DMAStruct.depth = 1; I2S_DMAConfig(LPC_I2S, &I2S_DMAStruct, I2S_TX_MODE); } |
I2S_DMACmd(LPC_I2S, I2S_DMA_1, I2S_TX_MODE, ENABLE); while (1) { } |
DMA_LLI_Struct.SrcAddr = (uint32_t)I2STXBuffer; //buffer DMA_LLI_Struct.DstAddr = (uint32_t)0; //peripheral DMA_LLI_Struct.NextLLI = (uint32_t)&DMA_LLI_Struct; DMA_LLI_Struct.Control = (BUFFER_SIZE) | (2<<18) //source width 32 bit | (2<<21) //dest. width 32 bit | (1<<26) //source increment | (1<<27) ; |
I2S_DMACmd(LPC_I2S, I2S_DMA_1, I2S_TX_MODE, ENABLE); |
NVIC_EnableIRQ (DMA_IRQn); |