The function of USART_RTOS_Receive can not receive data in sometimes

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

The function of USART_RTOS_Receive can not receive data in sometimes

994 次查看
HuangJames
Contributor I

    When the length of data received by the serial port is less than the third argument of the function,
the function of USART_RTOS_Receive will still receive data until the data received by the serial port is more than or equal to thevalue of length.

    For example, if the third argument of the function is set 4, the function of USART_RTOS_Receive will be still in the state of receiving data when the serial port receives only 2 data.

    Is this normal, please? Is there a way to solve this problem (except to set the third parameter lenth to 1)?

     Thanks very much!

标签 (1)
0 项奖励
1 回复

983 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, James,

As you know that the FreeRtos_uart example uses interrupt mechanism. Pls refer to the red color lines, in the usart ISR  USART_TransferHandleIRQ(), the handle->rxDataSize variable is the &n as you have defined.

 

USART_RTOS_Receive(&handle, recv_buffer, sizeof(recv_buffer), &n);

When the defined size of characters have been received, a callback function is called in the ISR, in the callback function,in the callback function, an event is triggered.

xResult = xEventGroupSetBitsFromISR(handle->rxEvent, RTOS_USART_COMPLETE, &xHigherPriorityTaskWoken);

In conclusion, the function error = USART_RTOS_Receive(&handle, recv_buffer, sizeof(recv_buffer), &n); is blocked with the line:

ev = xEventGroupWaitBits(handle->rxEvent, RTOS_USART_COMPLETE | RTOS_USART_RING_BUFFER_OVERRUN, pdTRUE, pdFALSE,
portMAX_DELAY);

until all the predefined size of characters have been received.

Hope it can help you

BR

XiangJun Rong

 

 

void USART_TransferHandleIRQ(USART_Type *base, usart_handle_t *handle)
{
/* Check arguments */
assert((NULL != base) && (NULL != handle));

bool receiveEnabled = ((handle->rxDataSize != 0U) || (handle->rxRingBuffer != NULL));
bool sendEnabled = (handle->txDataSize != 0U);
uint8_t rxdata;
size_t tmpsize;

/* If RX overrun. */
if ((base->FIFOSTAT & USART_FIFOSTAT_RXERR_MASK) != 0U)
{
/* Clear rx error state. */
base->FIFOSTAT |= USART_FIFOSTAT_RXERR_MASK;
/* clear rxFIFO */
base->FIFOCFG |= USART_FIFOCFG_EMPTYRX_MASK;
/* Trigger callback. */
if (handle->callback != NULL)
{
handle->callback(base, handle, kStatus_USART_RxError, handle->userData);
}
}
while ((receiveEnabled && ((base->FIFOSTAT & USART_FIFOSTAT_RXNOTEMPTY_MASK) != 0U)) ||
(sendEnabled && ((base->FIFOSTAT & USART_FIFOSTAT_TXNOTFULL_MASK) != 0U)))
{
/* Receive data */
if (receiveEnabled && ((base->FIFOSTAT & USART_FIFOSTAT_RXNOTEMPTY_MASK) != 0U))
{
/* Receive to app bufffer if app buffer is present */
if (handle->rxDataSize != 0U)
{
rxdata = (uint8_t)base->FIFORD;
*handle->rxData = rxdata;
handle->rxDataSize--;
handle->rxData++;
receiveEnabled = ((handle->rxDataSize != 0U) || (handle->rxRingBuffer != NULL));
if (0U == handle->rxDataSize)
{
if (NULL == handle->rxRingBuffer)
{
base->FIFOINTENCLR = USART_FIFOINTENCLR_RXLVL_MASK | USART_FIFOINTENSET_RXERR_MASK;
}
handle->rxState = (uint8_t)kUSART_RxIdle;
if (handle->callback != NULL)
{
handle->callback(base, handle, kStatus_USART_RxIdle, handle->userData);
}
}
}

0 项奖励