LPUART RX outside interrupt context

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

LPUART RX outside interrupt context

650 Views
adria
Contributor I

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

Tags (1)
0 Kudos
1 Reply

500 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Adria, 

You mentioned that the problem you are facing is that you cannot receive the data properly. To give you more accurate support, could you please clarify a little bit more what do you mean by not receiving properly? For example, if you are sending the string "12345", what is the information that you are receiving in this case? 

Regards,

Victor 

0 Kudos