AnsweredAssumed Answered

LPUART RX outside interrupt context

Question asked by Adria Perez on Oct 16, 2019
Latest reply on Oct 23, 2019 by Victor Jimenez

Hi,

 

I am working with s32K146 together with FreeRTOS. The system clock is configured at 48 MHz.

I have checked the "lpuart_echo_s32K146" example code because I want to work with LPUART.

In the example, the bytes are being processed in interrupt context. In this example, process only means check if rx buffer overflows and also if end of line ASCII byte received.

I want to do this process in a task, outside of interrupt context. So in the interrupt ISR, in case of RX event I just give a binary semaphore and a task is sleeping taking the semaphore. And when it wakes up thanks to the ISR semaphore give then I want to process the rx data.

The problem I am facing is that I cannot receive properly if I process rx outside ISR. Basically what I am doing is:

 

uint8_t rx_buf[255]

 

RxISR() {

   if (rx_full_event) {

      semaphore_give_from_ISR()

   }

}

 

proc_rx() {

    /* Necessary protections for buffer overflow... and then */

   rx_buf_id++

   LPUART_DRV_SetRxBuffer(&(rx_buf[rx_buf_id]), 1)

}

 

Task() {

   LPUART_DRV_Init()

   INT_SYS_SetPriority(uart_int_id, 1)

   LPUART_DRV_InstallRxCallback(RxISR)

   LPUART_DRV_ReceiveData(rx_buf, 1)

   for (;;) {

      semaphore_take()

      proc_rx()

   }

}

 

I don't want to work on interrupt context because of 2 reasons:

1. To avoid monopolizing the context so any other interruption can be handled without delay.

2. When another task wants to read the buffer, then this buffer and its index need to be protected with a mutex, in case I modify them in the ISR then I need to use a mutex in the ISR. As I am never going to do that, I would use critical sections in the API to get the buffer data. But this critical section could make me miss rx bytes from the UART.

 

Is there anything I am doing wrong? Does anyone have any idea of how to do that?

 

Best regards,

 

Adria

Outcomes