Setting DMA controller as the flow controller.
The packet header contains the size of the packet which is 2 bytes. During initialization set up transfer size as 2 and then in DMA interrupt handler we set transfer size as the packet size. We are able to receive on test packet. However, is it the right method to receive unknown packet size. Is there more elegant method?
void Set_TransferSize(LPC_GPDMA_T *pGPDMA,uint8_t ch,uint8_t size)
{
GPDMA_CH_T *pDMAch;
uint32_t ctrlword;
// Get Channel pointer
pDMAch = (GPDMA_CH_T *) &(pGPDMA->CH[ch]);
//set transfer size
pDMAch->CONTROL = (pDMAch->CONTROL & 0xFFFFF000) | size;
Chip_GPDMA_ChannelCmd(pGPDMA, ch, ENABLE);
}
void DMA_IRQHandler(void)
{
uint8_t dmaChannelNum;
uint16_t count;
if (isDMATx) {
dmaChannelNum = dmaChannelNumTx;
}
else {
dmaChannelNum = dmaChannelNumRx;
}
if (first_flag == true)
{
if (Chip_GPDMA_Interrupt(LPC_GPDMA, dmaChannelNum) == SUCCESS) {
channelTC++;
//count = receiveBuffer[0];
count = (receiveBuffer[1] <<8) | receiveBuffer[0];
Set_TransferSize(LPC_GPDMA, dmaChannelNumRx,count);
//bns tried to set the new size this way , I do get interrupt but it is a lot of code in an interrupt route so tryign to dset just size
/*Chip_GPDMA_Transfer(LPC_GPDMA, dmaChannelNumRx,
_GPDMA_CONN_UART_Rx,
(uint32_t) &receiveBuffer[2],
GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA,
count);*/
}
else {
channelTCErr++;
}
first_flag = false;
}
else
{
if (Chip_GPDMA_Interrupt(LPC_GPDMA, dmaChannelNum) == SUCCESS) {
channelTC++;
count = receiveBuffer[0];
//count = (receiveBuffer[1] <<8) | receiveBuffer[0];
}
else {
channelTCErr++;
}
first_flag = true;
}
}