
August 24th, 2012, 11:42 PM
|
 |
Contributed User
|
|
|
|
Well in an RTOS (or any OS for that matter), tasks are not responsible for switching between themselves.
Here, spawn() creates a separate stack, and the named function is an entry point.
The schedule() function is then called to start the first task, and thereafter periodically switch between tasks.
Note: These are both imaginary functions - you can't just write this and expect it to work, without providing a lot of implementation.
Code:
void task1(void);
void task2(void);
void main()
{
spawn(task1);
spawn(task2);
schedule();
}
void task1()
{
static unsigned int i=0;
while(1)
{
NOP();
i++;
}
}
void task2()
{
static unsigned int j=0;
while(1)
{
NOP();
j++;
}
}
If you want a reasonable simulation without a lot of effort on your part, then look at threads.
|