MQX - Protecting shared functions using lightweight semaphores

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MQX - Protecting shared functions using lightweight semaphores

跳至解决方案
775 次查看
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

标记 (2)
0 项奖励
回复
1 解答
589 次查看
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

在原帖中查看解决方案

2 回复数
590 次查看
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

589 次查看
mikemorris
Contributor II

Hi David,

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

Regards

Mike

0 项奖励
回复