embOS RTOS example application
The following example shows the ease of use of the embedded RTOS, embOS, for real-time applications.
Easy RTOS task scheduling
This sample application highlights basic RTOS scheduling. The two tasks are activated and execute until they run into the delay (a form of context switching in an RTOS), then suspend for the specified time and eventually continue execution.
You can write programs just as you always did, the only difference being that multiple programs run quasi-simultaneously as managed tasks. This demonstrates the core of task scheduling in RTOS.
#include "RTOS.h"
static OS_STACKPTR int StackHP[128], StackLP[128]; // Task stacks
static OS_TASK TCBHP, TCBLP; // Task-control-blocks
static void HPTask(void) {
while (1) {
OS_TASK_Delay(50);
}
}
static void LPTask(void) {
while (1) {
OS_TASK_Delay(200);
}
}
int main(void) {
OS_Init(); // Initialize OS
OS_InitHW(); // Initialize Hardware for OS
OS_TASK_CREATE(&TCBHP, "HP Task", 100, HPTask, StackHP);
OS_TASK_CREATE(&TCBLP, "LP Task", 50, LPTask, StackLP);
OS_Start(); // Start multitasking
return 0;
}