VSOS has evolved quite a lot since 0.19
I wrote some totally untested code how to start a task to the end of this post.
Remember FreeTaskAndStack() after the SensorTask exits to avoid memory leak.
The priority is set same as main task and VSOS switches between tasks in few ticks. If priority was higher than main task, main task would starve if there wouldn't be Yield() calls and vice versa.
Keep the stack size moderate as VSOS needs to allocate memory with same address from X and Y memory.
Program called tasks can print you the max stack usage and that way it is possible to optimize the size.
And word of caution. Now you have one problem to solve. When solving the problem with task you have the problem to solve and all the concurrency problems.
To lock resources, you might be interested in mutex.h and maybe hwlocks.h
To use mutex functions the symbols must be imported to program in VSOS 3.40
See: VSOS_340_RootAndLibrariesSourceCode/solutions/ClassicPlayer/kernelmutex.h
Code: Select all
#include <taskandstack.h>
// Study exec.h, taskandstack.h and the implementation of the functions for greater understanding
TaskAndStack *tas;
void SensorTask(){
//Read input, process data etc...
while(1);
}
#define SENSOR_STACK_SIZE 0x100
#define SENSOR_TASK_PRIORITY 1
void SomewhereInInit(){
tas = CreateTaskAndStack(SensorTask, "Sensor task", SENSOR_STACK_SIZE, SENSOR_TASK_PRIORITY);
}