Customer use K81, KSDK1.3 version, and have below question,
Why need to delay some time to get the new data after check the LPUART_DRV_EdmaGetReceiveStatus?
Below is the question description:
LPUART_DRV_EdmaGetReceiveStatus(LPUART2_IDX, &uiCnt);
// We check uiCnt whether have new data,
// When UART have new data, we check from LPUART_DRV_EdmaGetReceiveStatus function, then read the DMA buffer data, the data is not latest data, we need to delay some time to get the buffer data after check the LPUART_DRV_EdmaGetReceiveStatus function. If we delay 100us to read, we could got the latest correct data from s_aucRxBuf.
// Resource using is as below:
//1. LPUART2 receive use DMA function
//2. DMA BUF is 1024, it receive 200 bytes at one time
// DMA Init
int EdmaInit(void)
{
// Init eDMA modules.
edmaUserConfig.chnArbitration = kEDMAChnArbitrationRoundrobin;
edmaUserConfig.notHaltOnError = false;
EDMA_DRV_Init(&edmaState, &edmaUserConfig);
return 0;
}
// LPUART2 receive DMA init
int Lpuart2eDmaInit(void)
{
unsigned char uartchn;
lpuart_edma_user_config_t uartConfig;
uartConfig.clockSource = BOARD_LPUART_CLOCK_SOURCE;
uartConfig.baudRate = 115200;
uartConfig.bitCountPerChar = kLpuart8BitsPerChar;
uartConfig.parityMode = kLpuartParityDisabled;
uartConfig.stopBitCount = kLpuartOneStopBit;
LPUART_DRV_EdmaInit(LPUART2_IDX, &uartEdmaState, &uartConfig);
uartchn = LPUART2_IDX;
EDMA_DRV_InstallCallback(&uartEdmaState.edmaLpuartRx, Lpuart2EdmaRx_callback, &uartchn);
return 0;
}
// UART receive DMA config
void UartStartRecv(void)
{
LPUART_DRV_EdmaAbortReceivingData(LPUART2_IDX);
LPUART_DRV_EdmaReceiveData(LPUART2_IDX, s_aucRxBuf, 1024); // config buffer and size
}
void Lpuart2EdmaRx_callback(void *parameter, edma_chn_status_t status)
{
/* Stop DMA channel. */
EDMA_DRV_StopChannel(&lpuartEdmaState.edmaLpuartRx);
/* Signal the synchronous completion object. */
if (lpuartEdmaState.isRxBlocking)
{
OSA_SemaPost(&lpuartEdmaState.rxIrqSync);
}
/* Update the information of the module driver state */
lpuartEdmaState.isRxBusy = false;
UartStartRecv();
}
// UART receive function
u16 UartRxData(u8 *pDataBuf, u16 usLen)
{
u32 ulAvailLen = 0;
u32 ulBufWritePt;
unsigned int uiRC;
unsigned int uiCnt;
unsigned short usNowBufSaveLen;
LPUART_DRV_EdmaGetReceiveStatus(LPUART2_IDX, &uiCnt);
// We check uiCnt whether have new data
// If got the new data, we read the DMA buffer data, the data is not the latest data, we need to delay some time to get
// the buffer data. If we delay some time to read, such as 100us, we could got the correct data from s_aucRxBuf.
}
unsigned char Buf[1024];
void main()
{
EdmaInit();
configure_lpuart_pins(LPUART2_IDX); // LPUART2 pin init
Lpuart2eDmaInit();
while(1)
{
UartRxData(Buf, 256); //Why this interface function have delay when read data
}