OpenSwarm  0.16.1.2
An operating system for miniature robots
Files
Process Management

Functions to create, switch, block, yield, and terminate processes and start critical sections. More...

Files

file  process_Management_HDI.c
 Hardware dependent implementations to manage processes (e.g. task swichting)
 
file  process_Management_HDI.h
 Hardware dependent implementations to manage processes (e.g. task swichting)
 
file  system_Timer_HDI.c
 Hardware dependent implementations to initialise, configure and run the system Timer.
 
file  system_Timer_HDI.h
 Hardware dependent implementations to initialise, configure and run the system Timer.
 
file  data.c
 It defines functions to manage process lists and related structs.
 
file  data.h
 It declares functions to manage process lists and related structs.
 
file  process_Management.c
 It defines functions to manage processes (e.g. task creation, switching, termination)
 
file  process_Management.h
 It declares functions to manage processes (e.g. task creation, switching, termination)
 
file  scheduler.c
 It defines functions to specify a scheduling algorithm.
 
file  scheduler.h
 It declares functions to specify a scheduling algorithm.
 
file  system_Timer.c
 It defines functions to initialise, configure and run the system Timer.
 
file  system_Timer.h
 It declares functions to initialise, configure and run the system Timer.
 

Detailed Description

Functions to create, switch, block, yield, and terminate processes and start critical sections.

Author
Stefan M. Trenkwalder s.tre.nosp@m.nkwa.nosp@m.lder@.nosp@m.open.nosp@m.swarm.nosp@m..org

A process is a basic form to execute functions in OpenSwarm. Due to target device architecture, OpenSwarm does not provide functions to separate memory in pages or segments. Therefore, all processes are executed in the same memory area. Consequently, Each process can be seen as a single thread where all threads share the same memory space. A thread is represented by a function with no arguments and no return value. One function can be executed multiple times as individual threads.

OpenSwarm organises processes in four lists (pid sorted):

  1. running list: includes only one element—the process that is executed at that time.
  2. ready list: includes all processes are ready to be executed and will be scheduled according to the scheduling algorithm.
  3. blocked list: includes all processes that are waiting for events to occur.
  4. Zombie list: includes all processes that are about to be terminated but not deleted yet.

Usage

The process management is initialised with Sys_Init_Process_Management(void), which generated the System Thread (pid: 0) and initialises all data structures. After initialising, the following functions are available.

User code:

  1. Processes are started and terminated with Sys_Start_Process(pFunction function) and Sys_Kill_Process(uint) respectively.
  2. A Process can be yield with Sys_Yield(void) and remains in the ready list. The process can be rescheduled by the scheduler.
  3. A thread/process can be suspended while waiting for arriving events with Sys_Wait_For_Event(uint) and Sys_Wait_For_Condition(uint, pConditionFunction). Processes that are suspended are on the block list and are not rescheduled whilst in it.

Internal function (shouldn't be used by the user)

Scheduling (functions to decide which process is executed at which time)

Scheduling-related functions can be found in scheduler.h and process_Management.h.

System Timer (timer to start the scheduling, found in system_Timer.h):

  1. The System Timer needs to be initialised and started by Sys_Init_SystemTimer(pFunction) and Sys_Start_SystemTimer(void) respectively (these functions are used when the process Management is initialised and started).
  2. It can be stopped, continued, and reset by Sys_Stop_SystemTimer(), Sys_Continue_SystemTimer(), and Sys_Reset_SystemTimer() respectively.
  3. The timer interrupt can be disabled and enabled by Sys_Disable_TimerInterrupt(void) and Sys_Enable_TimerInterrupt(void).
  4. To force a system timer and therefore the scheduling process, Sys_Force_TimerInterrupt() will be executed.

Process Event handling (functions to store/process events with it's subscribed process and add/remove subscriptions) \ref events

Example

#include "os/system.h"
#define WAIT_FOR_ME 0x0F
void thread(void){//thread definition
while(true){
//do something as a thread
sys_event_data * data = Sys_Wait_For_Event(WAIT_FOR_ME);//blocking
}
}
int main(void){
//initialise some global or local variables
int variable;
Sys_Register_Event(WAIT_FOR_ME);
Sys_Start_Kernel();//OpenSwarm is running now
while(1){
if( ... ){//under a certain condition
Sys_Send_Event(WAIT_FOR_ME, &variable, sizeof(int));
//alternatively, you could use Sys_Send_IntEvent(WAIT_FOR_ME, variable);
}
//do something
}
}

License

LICENSE: adapted FreeBSD License (see http://openswarm.org/license)
Copyright (c) 2015, Stefan M. Trenkwalder
All rights reserved.