A simple Round Robin Task scheduler (a sub minimalistic Operating System) with no inter Task communication implemented (semaphores, mailboxes etc) nor task local varibales can be used. They have to be global (static). But, it's the first step up to an OS.

Dependencies:   mbed

Committer:
Stanislaus
Date:
Fri Jun 11 20:52:03 2010 +0000
Revision:
0:9ce7c170cb66

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Stanislaus 0:9ce7c170cb66 1 /*! \file scheduler.h \brief Simple Task Scheduler. */
Stanislaus 0:9ce7c170cb66 2 //*****************************************************************************
Stanislaus 0:9ce7c170cb66 3 //
Stanislaus 0:9ce7c170cb66 4 // File Name : 'scheduler.h'
Stanislaus 0:9ce7c170cb66 5 // Title : Simple Task Scheduler
Stanislaus 0:9ce7c170cb66 6 // Author : Pascal Stang - Copyright (C) 2006
Stanislaus 0:9ce7c170cb66 7 // Created : 2006.05.24
Stanislaus 0:9ce7c170cb66 8 // Revised : 2006.05.26
Stanislaus 0:9ce7c170cb66 9 // Version : 0.2
Stanislaus 0:9ce7c170cb66 10 // Target MCU : NXP Cortex M3 LPC17xx and LPC13xx
Stanislaus 0:9ce7c170cb66 11 // Editor Tabs : 4
Stanislaus 0:9ce7c170cb66 12 //
Stanislaus 0:9ce7c170cb66 13 // NOTE: This code is currently below version 1.0, and therefore is considered
Stanislaus 0:9ce7c170cb66 14 // to be lacking in some functionality or documentation, or may not be fully
Stanislaus 0:9ce7c170cb66 15 // tested. Nonetheless, you can expect most functions to work.
Stanislaus 0:9ce7c170cb66 16 //
Stanislaus 0:9ce7c170cb66 17 // This code is distributed under the GNU Public License
Stanislaus 0:9ce7c170cb66 18 // which can be found at http://www.gnu.org/licenses/gpl.txt
Stanislaus 0:9ce7c170cb66 19 //
Stanislaus 0:9ce7c170cb66 20 //*****************************************************************************
Stanislaus 0:9ce7c170cb66 21
Stanislaus 0:9ce7c170cb66 22 #ifndef SCHEDULER_H
Stanislaus 0:9ce7c170cb66 23 #define SCHEDULER_H
Stanislaus 0:9ce7c170cb66 24
Stanislaus 0:9ce7c170cb66 25 // structures and typedefs
Stanislaus 0:9ce7c170cb66 26 typedef void (*taskfuncptr)(int htask, int systime);
Stanislaus 0:9ce7c170cb66 27 typedef void (*voidFuncPtr)(void);
Stanislaus 0:9ce7c170cb66 28
Stanislaus 0:9ce7c170cb66 29 struct task
Stanislaus 0:9ce7c170cb66 30 {
Stanislaus 0:9ce7c170cb66 31 int runtime;
Stanislaus 0:9ce7c170cb66 32 int nrepeat;
Stanislaus 0:9ce7c170cb66 33 int interval;
Stanislaus 0:9ce7c170cb66 34 taskfuncptr funcptr;
Stanislaus 0:9ce7c170cb66 35 };
Stanislaus 0:9ce7c170cb66 36
Stanislaus 0:9ce7c170cb66 37 #ifndef TASKLIST_SIZE
Stanislaus 0:9ce7c170cb66 38 #define TASKLIST_SIZE 10
Stanislaus 0:9ce7c170cb66 39 #endif
Stanislaus 0:9ce7c170cb66 40
Stanislaus 0:9ce7c170cb66 41 // functions
Stanislaus 0:9ce7c170cb66 42
Stanislaus 0:9ce7c170cb66 43 // initialize scheduler
Stanislaus 0:9ce7c170cb66 44 void schedulerInit(void);
Stanislaus 0:9ce7c170cb66 45
Stanislaus 0:9ce7c170cb66 46 // run scheduler
Stanislaus 0:9ce7c170cb66 47 // this function should be called at the system clock tick rate
Stanislaus 0:9ce7c170cb66 48 // the system time must be passed in systime
Stanislaus 0:9ce7c170cb66 49 void schedulerRun(int systime);
Stanislaus 0:9ce7c170cb66 50
Stanislaus 0:9ce7c170cb66 51 // schedule a task
Stanislaus 0:9ce7c170cb66 52 // returns a handle to the task (or -1 for failure)
Stanislaus 0:9ce7c170cb66 53 int schedulerAddTask(int runtime, int nrepeat, int interval, taskfuncptr taskfunc);
Stanislaus 0:9ce7c170cb66 54
Stanislaus 0:9ce7c170cb66 55 // remove a scheduled task by handle
Stanislaus 0:9ce7c170cb66 56 int schedulerRemoveTask(int taskhandle);
Stanislaus 0:9ce7c170cb66 57
Stanislaus 0:9ce7c170cb66 58 // remove a scheduled task(s) by function reference
Stanislaus 0:9ce7c170cb66 59 // NOTE: this will remove ALL tasks referencing the specified function
Stanislaus 0:9ce7c170cb66 60 int schedulerRemoveTaskFunc(taskfuncptr funcptr);
Stanislaus 0:9ce7c170cb66 61
Stanislaus 0:9ce7c170cb66 62 #endif