Hi all
This is actually a generic ChibiOS question but I thought that I'd put it here so the SPC56x forum didn't look so lonely
How can one set the rate at which a thread is executed?
Example; In my code (using µC/OS-II) I have a 200Hz (highest priority), 100Hz (middle priority), and 10Hz (lowest priority) task. These threads need to execute at precisely these frequencies.
How would this be done in ChibiOS?
Kevin
Setting thread execution rate
- Giovanni
- Site Admin
- Posts: 14461
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Setting thread execution rate
Hi,
Assign tasks their priorities then use one of the methods described in this article: http://www.chibios.org/dokuwiki/doku.ph ... :kb:timing
This forum will not be lonely for long so don't worry and use the correct one next time
Giovanni
Assign tasks their priorities then use one of the methods described in this article: http://www.chibios.org/dokuwiki/doku.ph ... :kb:timing
This forum will not be lonely for long so don't worry and use the correct one next time
Giovanni
Re: Setting thread execution rate
Thanks for the response.
I'm still working my way through the documentation.
Let me describe how I set thread execution rate now and perhaps you can tell me if something similar is possible in ChibiOS.
Assume that the system tick rate is set at 200Hz.
At the start of every task I acquire a semaphore for that task, Sem200Hz, for example, for the 200Hz task.
In µC/OS-II there is a function that is user modifiable and called at every system tick.
Works well in my application. Would this be possible in ChibiOS?
Kevin
I'm still working my way through the documentation.
Let me describe how I set thread execution rate now and perhaps you can tell me if something similar is possible in ChibiOS.
Assume that the system tick rate is set at 200Hz.
At the start of every task I acquire a semaphore for that task, Sem200Hz, for example, for the 200Hz task.
In µC/OS-II there is a function that is user modifiable and called at every system tick.
Code: Select all
void OSTimeTickHook (void)
{
OSSemPost(Sem200Hz); //release semaphore
if(!(TickCount % 2))
{
OSSemPost(Sem100Hz); //release semaphore
}
if(!(TickCount % 20))
{
OSSemPost(Sem10Hz); //release semaphore
}
}
Works well in my application. Would this be possible in ChibiOS?
Kevin
- Giovanni
- Site Admin
- Posts: 14461
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Setting thread execution rate
Hi,
Look into chconf.h in the hooks section: SYSTEM_TICK_EVENT_HOOK(). The counter can be read using chTimeNow().
Remember that you are in ISR context so you need to call I-Class functions from there inside locks:
It is advisable to enable the debug options in chconf.h during development, the system state checker (CH_DBG_SYSTEM_STATE_CHECK) will catch call protocol errors.
Giovanni
Look into chconf.h in the hooks section: SYSTEM_TICK_EVENT_HOOK(). The counter can be read using chTimeNow().
Remember that you are in ISR context so you need to call I-Class functions from there inside locks:
Code: Select all
chSysLockFromIsr();
if (!(chTimeNow()) % 2)
chSemResetI(&sem1, 0);
...
chSysUnlockFromIsr();
It is advisable to enable the debug options in chconf.h during development, the system state checker (CH_DBG_SYSTEM_STATE_CHECK) will catch call protocol errors.
Giovanni
Re: Setting thread execution rate
Thanks, looks like just what I was looking for.
I have the ST dev board for the SPC564A and will be trying out the SPC5 Studio example. Once I get that running I'll try the code you suggested and report back here on my results.
I have the ST dev board for the SPC564A and will be trying out the SPC5 Studio example. Once I get that running I'll try the code you suggested and report back here on my results.
Who is online
Users browsing this forum: No registered users and 1 guest