Why need to delay some time to get the correct data after check the LPUART_DRV_EdmaGetReceiveStatus?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Why need to delay some time to get the correct data after check the LPUART_DRV_EdmaGetReceiveStatus?

1,146件の閲覧回数
hansonhe
NXP Employee
NXP Employee

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
}

ラベル(1)
0 件の賞賛
返信
2 返答(返信)

948件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Hanson He

Could you share the project from your customer, or at least the main.c file, I don't see where you start to receive data. I saw that you have:

void UartStartRecv(void)
{
LPUART_DRV_EdmaAbortReceivingData(LPUART2_IDX);
LPUART_DRV_EdmaReceiveData(LPUART2_IDX, s_aucRxBuf, 1024); // config buffer and size

}

but this function is inside the Lpuart2EdmaRx_callback, and this callback will be called when receive data register is full (this is set in LPUART_DRV_EdmaInit). So you aren't going to be able to received data until you call the function of receive data, and this is contradictory. I cannot prove this code in my side.

Waiting for your reply

Best Regards

Jorge Alcala

0 件の賞賛
返信

948件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Hanson He

Sorry for the late, How is your customer issue status? I'm working on this and I will inform you of anything that I find as soon as possible

Have a great day,
Jorge Alcala

0 件の賞賛
返信