SEGGER - Jobs
emWin upgrade     Trade-In program     Web shop

embOS sample application

The following is a printout of the example application OS_Start_2Tasks.c. It shows how simple it is to use embOS. It is a good starting point for your application.

#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 (50);
  }
}

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


/*********************************************************************
*
*       main()
*/
int main(void) {
  OS_IncDI();                      /* Initially disable interrupts  */
  OS_InitKern();                   /* Initialize OS                 */
  OS_InitHW();                     /* Initialize Hardware for OS    */
  OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
  OS_CREATETASK(&TCBLP, "LP Task", LPTask,  50, StackLP);
  OS_Start();                      /* Start multitasking            */
  return 0;
}

What happens is easy to see:

After initialization of embOS; two tasks are created and started.
The two tasks are activated and execute until they run into the delay, then suspend for the specified time and continue execution.

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

 


 

This sample application shows how to signal a task from an interrupt:

#include "RTOS.h"

#define EVENT_MASK 0x01

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

static void UartIntHandler(void) {      
  OS_EnterInterrupt();         
  OS_SignalEvent(EVENT_MASK, &TCBHP);  /* Signal the task that a new character was received */         
  OS_LeaveInterrupt();   
}        

static void HPTask(void) {      
  while (1) {        
    OS_WaitEvent(EVENT_MASK);  /* Suspend the task until next character is received */   
  } 
}  

/********************************************************************* 
* 
*      main() 
*/ 
int main(void) {
  OS_IncDI();                      /* Initially disable interrupts  */
  OS_InitKern();                   /* Initialize OS                 */
  OS_InitHW();                     /* Initialize Hardware for OS    */
  OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
  OS_Start();                      /* Start multitasking            */
  return 0;
}