lpcware

DMA channel assignment: no error code?

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by jb111 on Tue Nov 24 21:47:32 MST 2015
I have started doing some work with the DMA and came across a potential problem in the LPCOpen driver.

Under the gpdma_18xx_43xx.h header there is the function Chip_GPDMA_GetFreeChannel().

If all channels have been assigned then it seems that there is a return of zero. But zero is legitimate channel. There is no way for the user to know if channel zero has been assigned or there are no free channels.



Here is a quick test I ran:


void dma_channel_test(){

int ch0 = -1;
int ch1 = -1;
int ch2 = -1;
int ch3 = -1;
int ch4 = -1;
int ch5 = -1;
int ch6 = -1;
int ch7 = -1;
int ch8 = -1;

ch0 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART0_Tx);
ch1 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART0_Rx);
ch2 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART2_Tx);
ch3 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART2_Rx);
ch4 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART3_Tx);
ch5 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART3_Rx);
ch6 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART1_Rx);
ch7 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_UART1_Tx);
ch8 = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_SSP1_Rx);


}


The results were:

ch0 = 0
ch1 = 1
ch2 = 2
ch3 = 3
ch4 = 4
ch5 = 5
ch6 = 6
ch7 = 7
ch8 = 0


I have not looked more indepth than that, just something I came across.


Here is the header and documentation:

/**
* @briefGet a free GPDMA channel for one DMA connection
* @parampGPDMA: The base of GPDMA on the chip
* @paramPeripheralConnection_ID: Some chip fix each peripheral DMA connection on a specified channel ( have not used in 17xx/40xx )
* @returnThe channel number which is selected
*/
uint8_t Chip_GPDMA_GetFreeChannel(LPC_GPDMA_T *pGPDMA,
  uint32_t PeripheralConnection_ID);




Here is the source :
/* Get a free GPDMA channel for one DMA connection */
uint8_t Chip_GPDMA_GetFreeChannel(LPC_GPDMA_T *pGPDMA,
  uint32_t PeripheralConnection_ID)
{
uint8_t temp = 0;
for (temp = 0; temp < GPDMA_NUMBER_CHANNELS; temp++) {
if (!Chip_GPDMA_IntGetStatus(pGPDMA, GPDMA_STAT_ENABLED_CH,
temp) && (ChannelHandlerArray[temp].ChannelStatus == DISABLE)) {
ChannelHandlerArray[temp].ChannelStatus = ENABLE;
return temp;
}
}
return 0;
}

Outcomes