int main(void) { /* Configuring the system clocks for EDMA. */ EDMAModuleClkConfig(); /* Configuring the system clocks for UART0 instance. */ UART0ModuleClkConfig(); /* Performing Pin Multiplexing for UART0 instance. */ UARTPinMuxSetup(0); /* Enabling IRQ in CPSR of ARM processor. */ IntMasterIRQEnable(); /* Initializing the ARM Interrupt Controller. */ IntAINTCInit(); /* Initializing the EDMA. */ EDMA3Initialize(); /* Initializing the UART0 instance for use. */ UARTInitialize(); /* ** Configuring the EDMA. */ /* Request DMA Channel and TCC for UART Transmit*/ EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_TX_CHA_NUM, EDMA3_UART_TX_CHA_NUM, EVT_QUEUE_NUM); /* Registering Callback Function for TX*/ cb_Fxn[EDMA3_UART_TX_CHA_NUM] = &callback; /* Request DMA Channel and TCC for UART Receive */ EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_RX_CHA_NUM, EDMA3_UART_RX_CHA_NUM, EVT_QUEUE_NUM); /* Registering Callback Function for RX*/ cb_Fxn[EDMA3_UART_RX_CHA_NUM] = &callback; /******************** Transmission of a string **************************/ /* Configuring EDMA PaRAM sets to transmit 'welcome' message. */ UartEDMATxConfTransfer(EDMA3_UART_TX_CHA_NUM, EDMA3_UART_TX_CHA_NUM, welcome, sizeof(welcome) - 1); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /******************** Transmission of a string **************************/ /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring EDMA PaRAM sets to transmit 'enter' message. */ UartEDMATxConfTransfer(EDMA3_UART_TX_CHA_NUM, EDMA3_UART_TX_CHA_NUM, enter, sizeof(enter) - 1); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /********************* Receiving Data from User *************************/ /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring the PaRAM set for reception. */ UartEDMARxConfTransfer(EDMA3_UART_RX_CHA_NUM, EDMA3_UART_RX_CHA_NUM, rxBuffer, sizeof(rxBuffer)); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /******************* Echoing received bytes *****************************/ /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring the PaRAM set to transmit the bytes that were received. */ UartEDMATxConfTransfer(EDMA3_UART_TX_CHA_NUM, EDMA3_UART_TX_CHA_NUM, rxBuffer, sizeof(rxBuffer)); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /******************* Freeing of allocated channels **********************/ /* Free EDMA3 Channels for TX and RX */ EDMA3FreeChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT, EDMA3_UART_TX_CHA_NUM, EVT_QUEUE_NUM); EDMA3FreeChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_RX_CHA_NUM, EDMA3_TRIG_MODE_EVENT, EDMA3_UART_RX_CHA_NUM, EVT_QUEUE_NUM); while(1); }
/* ** Main function. */ int main(void) { unsigned int numByteChunks = 0; unsigned char *pBuffer = NULL; unsigned int remainBytes = 0; /* Configure and enable the MMU. */ MMUConfigAndEnable(); /* Enable all levels of Cache. */ CacheEnable(CACHE_ALL); /* Configuring the system clocks for EDMA. */ EDMAModuleClkConfig(); /* Configuring the system clocks for UART0 instance. */ UART0ModuleClkConfig(); /* Performing Pin Multiplexing for UART0 instance. */ UARTPinMuxSetup(0); /* Enabling IRQ in CPSR of ARM processor. */ IntMasterIRQEnable(); /* Initializing the ARM Interrupt Controller. */ IntAINTCInit(); /* Initializing the EDMA. */ EDMA3Initialize(); /* Initializing the UART0 instance for use. */ UARTInitialize(); /* Select the console type based on compile time check */ ConsoleUtilsSetType(CONSOLE_UART); /* ** Configuring the EDMA. */ /* Request DMA Channel and TCC for UART Transmit*/ EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_TX_CHA_NUM, EDMA3_UART_TX_CHA_NUM, EVT_QUEUE_NUM); /* Registering Callback Function for TX*/ cb_Fxn[EDMA3_UART_TX_CHA_NUM] = &callback; /* Request DMA Channel and TCC for UART Receive */ EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_RX_CHA_NUM, EDMA3_UART_RX_CHA_NUM, EVT_QUEUE_NUM); /* Registering Callback Function for RX*/ cb_Fxn[EDMA3_UART_RX_CHA_NUM] = &callback; /******************** Transmission of a string **************************/ numByteChunks = (sizeof(welcome) - 1) / txBytesPerEvent; remainBytes = (sizeof(welcome) - 1) % txBytesPerEvent; /* Configuring EDMA PaRAM sets to transmit data. */ UARTTxEDMAPaRAMSetConfig(welcome, numByteChunks * txBytesPerEvent, EDMA3_UART_TX_CHA_NUM, EDMA3CC_OPT(DUMMY_CH_NUM), EDMA3_UART_TX_CHA_NUM); /* Configuring the PaRAM set for Dummy Transfer. */ TxDummyPaRAMConfEnable(); /* Enable EDMA Transfer */ EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /* Remaining bytes are transferred through polling method. */ if(0 != remainBytes) { pBuffer = welcome + (sizeof(welcome) - 1) - remainBytes; UARTPuts((char*)pBuffer, remainBytes); } /******************** Transmission of a string **************************/ numByteChunks = (sizeof(intent) - 1) / txBytesPerEvent; remainBytes = (sizeof(intent) - 1) % txBytesPerEvent; /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring EDMA PaRAM sets to transmit data. */ UARTTxEDMAPaRAMSetConfig(intent, numByteChunks * txBytesPerEvent, EDMA3_UART_TX_CHA_NUM, EDMA3CC_OPT(DUMMY_CH_NUM), EDMA3_UART_TX_CHA_NUM); /* Configuring the PaRAM set for Dummy Transfer. */ TxDummyPaRAMConfEnable(); /* Enable EDMA Transfer */ EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /* Remaining bytes are transferred through polling method. */ if(0 != remainBytes) { pBuffer = intent + (sizeof(intent) - 1) - remainBytes; UARTPuts((char*)pBuffer, remainBytes); } /******************** Transmission of a string **************************/ numByteChunks = (sizeof(enter) - 1) / txBytesPerEvent; remainBytes = (sizeof(enter) - 1) % txBytesPerEvent; /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring EDMA PaRAM sets to transmit data. */ UARTTxEDMAPaRAMSetConfig(enter, numByteChunks * txBytesPerEvent, EDMA3_UART_TX_CHA_NUM, EDMA3CC_OPT(DUMMY_CH_NUM), EDMA3_UART_TX_CHA_NUM); /* Configuring the PaRAM set for Dummy Transfer. */ TxDummyPaRAMConfEnable(); /* Enable EDMA Transfer */ EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /* Remaining bytes are transferred through polling method. */ if(0 != remainBytes) { pBuffer = enter + (sizeof(enter) - 1) - remainBytes; UARTPuts((char*)pBuffer, remainBytes); } /********************* Receiving Data from User *************************/ /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring the PaRAM set for reception. */ UARTRxEDMAPaRAMSetConfig(rxBuffer, NUM_RX_BYTES, EDMA3_UART_RX_CHA_NUM, 0xFFFF, EDMA3_UART_RX_CHA_NUM); /* Enable EDMA Transfer */ EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_RX_CHA_NUM, EDMA3_TRIG_MODE_EVENT); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /******************* Echoing received bytes *****************************/ numByteChunks = (NUM_RX_BYTES) / txBytesPerEvent; remainBytes = (NUM_RX_BYTES) % txBytesPerEvent; /* Enabling DMA Mode 1. */ UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE); /* Configuring EDMA PaRAM sets to transmit data. */ UARTTxEDMAPaRAMSetConfig(rxBuffer, numByteChunks * txBytesPerEvent, EDMA3_UART_TX_CHA_NUM, EDMA3CC_OPT(DUMMY_CH_NUM), EDMA3_UART_TX_CHA_NUM); /* Configuring the PaRAM set for Dummy Transfer. */ TxDummyPaRAMConfEnable(); /* Enable EDMA Transfer */ EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT); /* Wait for return from callback */ while(0 == clBackFlag); clBackFlag = 0; /* Remaining bytes are transferred through polling method. */ if(0 != remainBytes) { pBuffer = rxBuffer + NUM_RX_BYTES - remainBytes; UARTPuts((char*)pBuffer, remainBytes); } /******************* Freeing of allocated channels **********************/ /* Free EDMA3 Channels for TX and RX */ EDMA3FreeChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT, EDMA3_UART_TX_CHA_NUM, EVT_QUEUE_NUM); EDMA3FreeChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA, EDMA3_UART_RX_CHA_NUM, EDMA3_TRIG_MODE_EVENT, EDMA3_UART_RX_CHA_NUM, EVT_QUEUE_NUM); /* Support for Automation Testing. */ PRINT_STATUS(S_PASS); while(1); }
/* ** QDMA Application */ void EDMAAppQDMA3Test() { volatile unsigned int index = 0u; volatile unsigned int count = 0u; EDMA3CCPaRAMEntry paramSet; unsigned char data = 0u; unsigned int retVal = 0u; unsigned int isTestPassed = false; unsigned int numEnabled = 0u; unsigned int aCount = EDMAAPP_MAX_ACOUNT; unsigned int bCount = EDMAAPP_MAX_BCOUNT; unsigned int cCount = EDMAAPP_MAX_CCOUNT; unsigned int DstBuffAddr = 0u; volatile unsigned int opt = 0u; unsigned int paramId = 32u; /* Initalize source and destination buffers */ for(count = 0u; count < (aCount * bCount * cCount); count++) { SrcBuff[count] = data++; /* ** No need to initialize the destination buffer ** as it is being invalidated. */ } /* Request DMA channel and TCC */ retVal = EDMA3RequestChannel(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_TYPE, EDMAAPP_DMA_CH_NUM, EDMAAPP_DMA_TCC_NUM, EDMAAPP_DMA_EVTQ); EDMA3MapQdmaChToPaRAM(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_NUM, ¶mId); EDMA3SetQdmaTrigWord(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_NUM, EDMA3CC_PARAM_ENTRY_DST); /* Registering Callback Function */ EDMAAppCallbackFxn[EDMAAPP_DMA_TCC_NUM] = &EDMAAppCallback; if(TRUE == retVal) { /* Fill the PaRAM Set with transfer specific information */ paramSet.srcAddr = (unsigned int)(SrcBuff); paramSet.destAddr = (unsigned int)(DstBuff); paramSet.aCnt = (unsigned short)aCount; paramSet.bCnt = (unsigned short)bCount; paramSet.cCnt = (unsigned short)cCount; /* Setting up the SRC/DES Index */ paramSet.srcBIdx = (short)aCount; paramSet.destBIdx = (short)aCount; if(EDMA3_SYNC_A == EDMAAPP_DMA_SYNC_TYPE) { /* A Sync Transfer Mode */ paramSet.srcCIdx = (short)aCount; paramSet.destCIdx = (short)aCount; } else { /* AB Sync Transfer Mode */ paramSet.srcCIdx = ((short)aCount * (short)bCount); paramSet.destCIdx = ((short)aCount * (short)bCount); } /* Configure the paramset with NULL link */ paramSet.linkAddr = (unsigned short)0xFFFFu; paramSet.bCntReload = (unsigned short)0u; paramSet.opt = 0u; /* Src & Dest are in INCR modes */ paramSet.opt &= ~(EDMA3CC_OPT_SAM | EDMA3CC_OPT_DAM); /* Program the TCC */ paramSet.opt |= ((EDMAAPP_DMA_TCC_NUM << EDMA3CC_OPT_TCC_SHIFT) & EDMA3CC_OPT_TCC); /* Enable Intermediate & Final transfer completion interrupt */ paramSet.opt |= (1u << EDMA3CC_OPT_ITCINTEN_SHIFT); paramSet.opt |= (1u << EDMA3CC_OPT_TCINTEN_SHIFT); if(EDMA3_SYNC_A == EDMAAPP_DMA_SYNC_TYPE) { paramSet.opt &= ~EDMA3CC_OPT_SYNCDIM; } else { /* AB Sync Transfer Mode */ paramSet.opt |= (1u << EDMA3CC_OPT_SYNCDIM_SHIFT); } opt = paramSet.opt; /* Now, write the PaRAM Set. */ EDMA3QdmaSetPaRAM(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_NUM, paramId, ¶mSet); } retVal = EDMA3EnableTransfer(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_NUM, EDMAAPP_DMA_TRIG_MODE); /* ** Since the transfer is going to happen in Manual mode of EDMA3 ** operation, we have to 'Enable the Transfer' multiple times. ** Number of times depends upon the Mode (A/AB Sync) ** and the different counts. */ if(TRUE == retVal) { /* Need to activate next param */ if(EDMA3_SYNC_A == EDMAAPP_DMA_SYNC_TYPE) { numEnabled = bCount * cCount; } else { /* AB Sync Transfer Mode */ numEnabled = cCount; } for(index = 0u; index < numEnabled; index++) { IrqRaised = EDMAAPP_IRQ_STATUS_XFER_INPROG; if(index == (numEnabled - 1u)) { /** ** Since OPT.STATIC field should be SET for isolated QDMA ** transfers or for the final transfer in a linked list of QDMA ** transfers, do the needful for the last request. */ opt |= EDMA3CC_OPT_STATIC; EDMA3QdmaSetPaRAMEntry(EDMAAPP_EDMACC_BASE_ADDRESS, paramId, EDMA3CC_PARAM_ENTRY_OPT, opt); } opt |= EDMA3CC_OPT_FWID_8BIT; EDMA3QdmaSetPaRAMEntry(EDMAAPP_EDMACC_BASE_ADDRESS, paramId, EDMA3CC_PARAM_ENTRY_OPT, opt); /* ** Now trigger the QDMA channel by writing to the Trigger ** Word which is set as Destination Address. */ DstBuffAddr = (unsigned int)EDMA3QdmaGetPaRAMEntry( EDMAAPP_EDMACC_BASE_ADDRESS, paramId, EDMA3CC_PARAM_ENTRY_DST); EDMA3QdmaSetPaRAMEntry(EDMAAPP_EDMACC_BASE_ADDRESS, paramId, EDMA3CC_PARAM_ENTRY_DST, DstBuffAddr); /* Wait for the Completion ISR. */ while(EDMAAPP_IRQ_STATUS_XFER_INPROG == IrqRaised) { /* ** Wait for the Completion ISR on Master Channel. ** You can insert your code here to do something ** meaningful. */ } /* Check the status of the completed transfer */ if(IrqRaised < (int)EDMAAPP_IRQ_STATUS_XFER_INPROG) { /* Some error occured, break from the FOR loop. */ ConsoleUtilsPrintf("\r\nQDMA3Test: Event Miss Occured!!!\r\n"); /* Clear the error bits first */ EDMA3ClearErrorBits(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_NUM, EDMAAPP_DMA_EVTQ); break; } } } /* Match the Source and Destination Buffers. */ if(TRUE == retVal) { for(index = 0u; index < (aCount * bCount * cCount); index++) { if(SrcBuff[index] != DstBuff[index]) { isTestPassed = false; ConsoleUtilsPrintf("QDMA3Test: Data write-read matching FAILED.\r\n"); ConsoleUtilsPrintf("The mismatch happened at index : %d\r\n", ((int)index + 1u)); break; } } if(index == (aCount * bCount * cCount)) { isTestPassed = true; ConsoleUtilsPrintf("QDMA3Test: Data write-read matching PASSED.\r\n"); } /* Free the previously allocated channel. */ retVal = EDMA3FreeChannel(EDMAAPP_EDMACC_BASE_ADDRESS, EDMAAPP_DMA_CH_TYPE, EDMAAPP_DMA_CH_NUM, EDMAAPP_DMA_TRIG_MODE, EDMAAPP_DMA_TCC_NUM, EDMAAPP_DMA_EVTQ); /* Unregister Callback Function */ EDMAAppCallbackFxn[EDMAAPP_DMA_TCC_NUM] = NULL; if(TRUE != retVal) { ConsoleUtilsPrintf("QDMA3Test: EDMA3_DRV_freeChannel() FAILED.\r\n"); } } if(true == isTestPassed) { ConsoleUtilsPrintf("QDMA3Test PASSED.\r\n"); } else { ConsoleUtilsPrintf("QDMA3Test FAILED.\r\n"); } }