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
Solved! Go to Solution.
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:
Regards,
David
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:
Regards,
David
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