UART receive interrupt callback completing receive

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART receive interrupt callback completing receive

Jump to solution
1,698 Views
adyr
Contributor V

Hi,

 

I am using KSDK 1.2 and KDS 3.0 with the IAR compiler. I have added a UART component and ticked the box to install the receive interrupt.

What I want to do is terminate the blocking receive when a EOT is received (packet based reception). However the interrupt callback has now way to end the reception. The current loop in the UART_DRV_IRQHandler is as follows:

#if FSL_FEATURE_UART_HAS_FIFO
        /* Read out all data from RX FIFO */
        while(UART_HAL_GetRxDatawordCountInFifo(base))
        {
#endif
            /* Get data and put into receive buffer */
            UART_HAL_Getchar(base, uartState->rxBuff);

            /* Invoke callback if there is one */
            if (uartState->rxCallback != NULL)
            {
                uartState->rxCallback(instance, uartState);
            }
            else
            {
                ++uartState->rxBuff;
                --uartState->rxSize;

                /* Check and see if this was the last byte */
                if (uartState->rxSize == 0U)
                {
                    UART_DRV_CompleteReceiveData(instance);
                    #if FSL_FEATURE_UART_HAS_FIFO
                    break;
                    #endif
                }
            }
#if FSL_FEATURE_UART_HAS_FIFO
        }
#endif

 

If I change the inner part of loop to:

            /* Invoke callback if there is one */
            if (uartState->rxCallback != NULL)
            {
                uartState->rxCallback(instance, uartState);
            }
            else
            {
                ++uartState->rxBuff;
                --uartState->rxSize;
   }

   /* Check and see if this was the last byte */
   if (uartState->rxSize == 0U)
   {
    UART_DRV_CompleteReceiveData(instance);
    #if FSL_FEATURE_UART_HAS_FIFO
    break;
    #endif
   }

 

Then the user interrupt call back can terminate the reception by setting uartState->rxSize to 0.

 

I was wondering if Freescale would consider making this change to future KSDK versions so I don't have to modify the KSDK code?

 

Best regards,

Adrian.

Labels (1)
0 Kudos
1 Solution
620 Views
adyr
Contributor V

OK. More testing has found that my change breaks the nio_serial as that almost uses the fsl_uart_driver but it does not setup uartState->rxSize. It prefers to do it's own thing which is possibly why the Rx loop is different to the Tx loop.

If I change the:

if (uartState->rxSize == 0U)

to

if (uartState->isRxBlocking && (uartState->rxSize == 0U))

Then both are happy as nio_serial does not set the blocking flag either.

View solution in original post

2 Replies
621 Views
adyr
Contributor V

OK. More testing has found that my change breaks the nio_serial as that almost uses the fsl_uart_driver but it does not setup uartState->rxSize. It prefers to do it's own thing which is possibly why the Rx loop is different to the Tx loop.

If I change the:

if (uartState->rxSize == 0U)

to

if (uartState->isRxBlocking && (uartState->rxSize == 0U))

Then both are happy as nio_serial does not set the blocking flag either.

620 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Adrian Rockall:

Thank you for your feedback.

This issue has been reported internally (ticket KPSDK-5144).

The proper modifications could not make it into KSDK v1.3, but a change of the UART driver and callback scheme is planned to avoid these issues in the next version of KSDK.

Regards!

Jorge Gonzalez

0 Kudos