How to create a cyclic task in MQX

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

How to create a cyclic task in MQX

跳至解决方案
1,333 次查看
hbouch
Contributor III

Hi,

Is there a simple way of creating a cyclic task in MQX?

The _time_delay(xx) function isn't really what I'm looking for since it doesn't take into account the execution time of the task. So, with this delay function, if I want a 5 ms cyclic task for example and this task takes 1 ms to execute, my task would be executed every 6 ms and not 5.

If we take the same example above, what I would like is that 4 ms after execution of the task (which last 1 ms), the task would become ready again. I could just call _time_delay(4) but the execution time of the task isn't constant.

I though about creating a task queue and a lwtimer event queue with a lwtimer that calls a callback function when it expires. This callback would simply call _taskq_resume(). At the end of the task execution the task would call _taskq_suspend().

It seems complicated just to do something that should be very simple. Is there another way and simpler way of doing this?

Thanks

标记 (2)
0 项奖励
回复
1 解答
749 次查看
DavidS
NXP Employee
NXP Employee

Hi Hugo,

It has been long time since I implemented something like this so please refer to the following PDF:

C:\Freescale\Freescale_MQX_4_1_1\doc\mqx\MQX_Reference_Manual.pdf

Search for "_timer_start_" for various implementations.

Your implementation might want to use:

source\kernel\timer.c

#include <timer.h>

_timer_id _timer_start_oneshot_after(

TIMER_NOTIFICATION_TIME_FPTR notification_function,

void *notification_data_ptr,

_mqx_uint mode,

uint32_t milliseconds)

My example is from MQX3.8 so check that it matches current PDF:

ScreenHunter_163 Jun. 30 10.19.gif

Regards,

David

在原帖中查看解决方案

0 项奖励
回复
2 回复数
750 次查看
DavidS
NXP Employee
NXP Employee

Hi Hugo,

It has been long time since I implemented something like this so please refer to the following PDF:

C:\Freescale\Freescale_MQX_4_1_1\doc\mqx\MQX_Reference_Manual.pdf

Search for "_timer_start_" for various implementations.

Your implementation might want to use:

source\kernel\timer.c

#include <timer.h>

_timer_id _timer_start_oneshot_after(

TIMER_NOTIFICATION_TIME_FPTR notification_function,

void *notification_data_ptr,

_mqx_uint mode,

uint32_t milliseconds)

My example is from MQX3.8 so check that it matches current PDF:

ScreenHunter_163 Jun. 30 10.19.gif

Regards,

David

0 项奖励
回复
749 次查看
hbouch
Contributor III

Hi David,

You're right, "_timer_start_" seems simpler. I looked at MQX reference manual and I think using "_timer_start_periodic_every" would be best suited for me. I could also use "_task_ready" as notification function and task descriptor pointer as pointer to the data that MQX passes to the notification function. At the end of my tasks I would need to use "_task_block".

I will try that thanks!

Regards,

Hugo

0 项奖励
回复