MQX - Protecting shared functions using lightweight semaphores

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

MQX - Protecting shared functions using lightweight semaphores

Jump to solution
688 Views
mikemorris
Contributor II

Hi,

I have a custom board (based on the twrk60n512) where I am using a number of tasks to perform various tasks. The application is configured to use priority based scheduling.

Two of the tasks in particular use the _io_write function to pass data to two individual uart channels,1 uart channel per task.

During testing I have found that the uart transmission (running at 115200 baud) from the lower priority task can have a delay of 15-20ms within the packet, this causes the field device (on customers side) to time out is it believes the transmission has ended. It is worth mentioning that no data is lost just an unexpected delay.

I believe that the lower priory task starts to transmit and is then blocked by the higher priory task which then also

To get around this I am using a lightweight semaphore, I wait for the semaphore before the _io_write and post the semaphore immediately after the fflush function.

_lwsem_wait(&ModbusSem);

write(modbusslave, uc_MSOut, length);

fflush(modbusslave);

_lwsem_post(&ModbusSem);

This seems to resolve the problem.

The question I have is there anything additional I should consider when using semaphores? Im new to MQX and am looking for some general advice.


Thanks in advance,

Mike

Tags (2)
0 Kudos
1 Solution
502 Views
DavidS
NXP Employee
NXP Employee

Hi Mike,

That solution looks correct.

FYI the TWR-K60N512 is the original K60 silicon Rev 1.x which is very old.  The Rev 2.x silicon is on the TWR-K60D100M.

Lots of low level RTOS examples are at : C:\Freescale\Freescale_MQX_4_2\mqx\examples

Specific example: C:\Freescale\Freescale_MQX_4_2\mqx\examples\lwsem

Regards,

David

View solution in original post

2 Replies
503 Views
DavidS
NXP Employee
NXP Employee

Hi Mike,

That solution looks correct.

FYI the TWR-K60N512 is the original K60 silicon Rev 1.x which is very old.  The Rev 2.x silicon is on the TWR-K60D100M.

Lots of low level RTOS examples are at : C:\Freescale\Freescale_MQX_4_2\mqx\examples

Specific example: C:\Freescale\Freescale_MQX_4_2\mqx\examples\lwsem

Regards,

David

502 Views
mikemorris
Contributor II

Hi David,

Thank your for your prompt response, just wanted to check I wasn't missing something obvious.

Regards

Mike

0 Kudos