Tiny Threads - Tiny Multitasking Threads for Microcontrollers
by: Regulus Berdin
- Idea based on http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html.
- Only 1 byte RAM needed per thread.
- Very small overhead context switching.
- Maximum 254 lines per thread.
- Thread context switching will not work within a switch block.
TT_DEF(1)
{
TT_BEGIN(1);
while (1)
{
...
TT_SWITCH(1);
...
...
TT_WAIT_UNTIL(1,keypress);
}
TT_END(1);
}
TT_DEF(LED_TASK)
{
TT_BEGIN(LED_TASK);
while (1)
{
LedOn();
delay=DELAY_1_SECOND;
TT_WAIT_UNTIL(LED_TASK,delay==0);
LedOff();
delay=DELAY_1_SECOND;
TT_WAIT_UNTIL(LED_TASK,delay==0);
}
TT_END(LED_TASK);
}
void main(void)
{
...
...
while(1)
{
TT_SCHED(1);
TT_SCHED(LED_TASK);
}
}
Visit Site
0 Comments:
Post a Comment
<< Home