have to mention one thing, the code that I've seen about microcontroller threads are almost always hardcoded.
For a example simply suppose you have two while loops in main as seperate threads like,
Code: Select all
int main()
{
init();
while(){
check_adc();
check_button_pressed();
turn_on_led();
}
}
Then if you have two threads, I have seen they have exploited the '%' operators , if TMR0 is odd run the first
thread and if TMR0 is even then run the second. Like this.
Code: Select all
int main()
{
init();
while(true){
while(tmrofc%2){
// Thread 1 code //
}
while(!trmofc%2){
// thread 2 code //
}
}
}
Since it's completely hardcoded , you don't need to worry about deadlock issues or starvation issues at all.
Just only make sure that one loop code spends less than one overflow time. You could program to many
threads using a switch ,not my ideas just ideas that I've extracted through code reviewing[ that's why I always
tell code-reviewing is a good heaven thing

].
Code: Select all
while(true){
switch (tmrofc %n){
case 1:
//thread 1 code //
break;
case 2:
// thread 2 code //
break;
case 3:
// thread 3 code //
break;
//...
case n:
// thread n code//
break;
}
}
Simple code review will find you all this.
But if you really need to code a pure dynamic scheduler then THUMBS up you, I could hardly help you, I never done that
before for PIC like such small devices.