embOS frame program

This sample frame program needs to be compiled and linked with the library for the selected memory model to build a simple multi-task program. It is part of every embOS distribution.

----------------------------------------------------------------------
File : Main.c
Purpose : Skeleton program for OS
-------- END-OF-HEADER ---------------------------------------------
*/

#include "RTOS.h"

OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */
OS_TASK TCBHP, TCBLP; /* Task-control-blocks */

static void HPTask(void) {
while (1) {
OS_Delay (10);
}
}

static void LPTask(void) {
while (1) {
OS_Delay (50);
}
}

/*********************************************************************
*
* main
*
*********************************************************************/

int main(void) {
OS_IncDI(); /* Initially disable interrupts */
OS_InitKern(); /* initialize OS */
OS_InitHW(); /* initialize Hardware for OS */
/* You need to create at least one task here ! */
OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP);
OS_Start(); /* Start multitasking */
return 0;
}

This program can then be loaded into your emulator and checked out. Just as with a single task program, you can set breakpoints and step through any part of the program including the OS.
Check out how fast the task switch is executed ...
Expand the functionality and adopt the program to your target hardware ...

This way it is very easy to get started.
You can write programs just as you always did, where the only difference is that multiple programs run quasi-simultaneously. You already reduce the power consumption this way since the OS automatically puts the CPU in power-saving mode when no task is active. As you can also see, timing is made very easy.

Other features

you can use later as you feel comfortable with the system :

  • Software timers to control timing and simple "jobs" that need to be done regularly
  • Mailboxes for task / task and task / interrupt communications instead of global variables
  • Resource semaphores to make sure that resources are not used by multiple task simultaneously