00001 /*! \file scheduler.h \brief Simple Task Scheduler. */ 00002 //***************************************************************************** 00003 // 00004 // File Name : 'scheduler.h' 00005 // Title : Simple Task Scheduler 00006 // Author : Pascal Stang - Copyright (C) 2006 00007 // Created : 2006.05.24 00008 // Revised : 2006.05.26 00009 // Version : 0.1 00010 // Target MCU : Atmel AVR Series 00011 // Editor Tabs : 4 00012 // 00013 // NOTE: This code is currently below version 1.0, and therefore is considered 00014 // to be lacking in some functionality or documentation, or may not be fully 00015 // tested. Nonetheless, you can expect most functions to work. 00016 // 00017 // This code is distributed under the GNU Public License 00018 // which can be found at http://www.gnu.org/licenses/gpl.txt 00019 // 00020 //***************************************************************************** 00021 00022 #ifndef SCHEDULER_H 00023 #define SCHEDULER_H 00024 00025 #include "global.h" 00026 00027 // structures and typedefs 00028 typedef void (*taskfuncptr)(int htask, int systime); 00029 typedef void (*voidFuncPtr)(void); 00030 00031 struct task 00032 { 00033 int runtime; 00034 int nrepeat; 00035 int interval; 00036 taskfuncptr funcptr; 00037 }; 00038 00039 #ifndef TASKLIST_SIZE 00040 #define TASKLIST_SIZE 10 00041 #endif 00042 00043 // functions 00044 00045 // initialize scheduler 00046 void schedulerInit(void); 00047 00048 // run scheduler 00049 // this function should be called at the system clock tick rate 00050 // the system time must be passed in systime 00051 void schedulerRun(int systime); 00052 00053 // schedule a task 00054 // returns a handle to the task (or -1 for failure) 00055 int schedulerAddTask(int runtime, int nrepeat, int interval, taskfuncptr taskfunc); 00056 00057 // remove a scheduled task by handle 00058 int schedulerRemoveTask(int taskhandle); 00059 00060 // remove a scheduled task(s) by function reference 00061 // NOTE: this will remove ALL tasks referencing the specified function 00062 int schedulerRemoveTaskFunc(taskfuncptr funcptr); 00063 00064 #endif