Multiple tasks using single UART0 device not working S32K144

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

Multiple tasks using single UART0 device not working S32K144

1,511 Views
mrajanna
Contributor V

Hi,

I have 2 tasks scheduled in freeRTOS. Both of them using same uart 0 device for transmit and receive.

Code snippet:

xTaskCreate( Task1, "X", configMINIMAL_STACK_SIZE, NULL, TASK_PRIORITY, NULL );
xTaskCreate( Task2, "Y", configMINIMAL_STACK_SIZE, NULL, TASK_PRIORITY, NULL );

/*Task1 receives the request from processor ABC and sends the response back from S32K144 over UART0*/

Task1() 

{

   while(1)

   {

      LPUART_DRV_ReceiveData(UART0, &buffer[count], 1);
      while(LPUART_DRV_GetReceiveStatus(UART0, &bytesRemain) != STATUS_SUCCESS);

      -

      -

      -

      LPUART_DRV_SendData(UART0, buffer, count);
      while(LPUART_DRV_GetTransmitStatus(UART0, &bytesRemain) != STATUS_SUCCESS);

   }

}

/*Task2 sends the event from S32K144 over UART0 to processor ABC and waits for the aknowledgement*/

Task2()

{

   while(1)

   {

      Send some event over UART0.

      -

      -

      -

       LPUART_DRV_ReceiveData(UART0, &buffer[count], 1);
      while(LPUART_DRV_GetReceiveStatus(UART0, &bytesRemain) != STATUS_SUCCESS)  

   }

}

When I run single task, receive and transmit works properly.

However when I run both the tasks, Task2 is never receiving the ackowledgement.

Any suggestion please?

Thanks

Mohan

Labels (1)
Tags (1)
5 Replies

1,028 Views
jiri_kral
NXP Employee
NXP Employee

Hi Mohan, 

you are using blocking functions inside task - while(LPUART_DRV_GetReceiveStatus(UART0, &bytesRemain) != STATUS_SUCCESS); - that's first thing. 

Also sharing one HW device between tasks is - let's say - very unusual construction. It's better idea share data - no device. 

I still can't figure out what you are trying to do - but for the simple communication between S32K144 and other generic MCU (what I get from your other questions) you don't need FreeRTOS at all - it is only complicating whole thing. 

 

Better idea is to have nonblocking "uart_data_hadling_task" if you need a FreeRTOS task for it. And best idea is to have callback function for receive event - LPUART_DRV_InstallRxCallback and throw away FreeRTOS. 

Jiri  

 

 

1,028 Views
mrajanna
Contributor V

Hi Jiri,

I got your point of not sharing hardware device between the tasks.

The reason I choosed freeRTOS is in future we have plan of adding couple of more tasks and also task scheduling, synchronization between tasks..... everything is provided by freeRTOS which we don't have to rewrite.

Is there any way to break from LPUART_DRV_GetReceiveStatus(UART0, &bytesRemain) != STATUS_SUCCESS);

blocking call ?

My requirement is :

a. one task for handling request and response between processor(ABC) to S32K144.

b. One task for sending events dynamically on certain conditions from S32K144 to processor(ABC) and get acknowledgement.

Idea is to use same UART device for both the requirements.

Can you tell me more on LPUART_DRV_InstallRxCallback() please.

Thanks

Mohan

0 Kudos

1,028 Views
jiri_kral
NXP Employee
NXP Employee

Hi Mohan, 

i did some research for another question - and the callback function needs to perform all the stuff related to IRQ handling and data copy from UART registers. So - for your case it is better use only  LPUART_DRV_ReceiveData(...) function and check the status by non-blocking way - something like:

if (status==STATUS_SUCCESS)

{

   do something with data;

}

else

{

   do something different;

}

Jiri

1,028 Views
mrajanna
Contributor V

Thanks Jiri for the ideas.

I could solve it with my weird kind of logic.

0 Kudos

1,028 Views
jiri_kral
NXP Employee
NXP Employee

If you install callback function - every time when you got data on UART - your callback function will be called. For example: 

volatile unsigned char data[64];

void ThisIsMyRXCallback()

{

    LPUART_DRV_ReceiveData(INST_LPUART1, data, 1UL);

   printf("We got: %s\n",data);

}

You can install RX callback by calling LPUART_DRV_InstallRxCallback(INST_LPUART1,ThisIsMyRXCallback,NULL);

Jiri