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)Visit Site
{
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);
}
}
1 Comments:
Hello,
You published this code and a interrupt driven routine for serial on the http://www.microchipc.com website. Can you tell me how the later functions? I want to adapt it so I can use it for SPI. The round FIFO idea is great, but, for me, it hangs at the while conditions. Can you tell me what is the logic behind it?
Thank you.
Post a Comment
<< Home