00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00041 #ifndef _SCHEDULER_H_
00042 #define _SCHEDULER_H_
00043
00044 #include <aversive.h>
00045
00046 #ifdef CONFIG_MODULE_SCHEDULER_USE_TIMERS
00047 #include <timer.h>
00048 #endif
00049
00050 #include <scheduler_config.h>
00051
00052 #ifdef CONFIG_MODULE_SCHEDULER_USE_TIMERS
00053 #if SCHEDULER_TIMER_NUM == 0
00054 #define SCHEDULER_TIMER_REGISTER() timer0_register_OV_intr(scheduler_interrupt)
00055 #define SCHEDULER_CLOCK_PRESCALER timer0_get_prescaler_div()
00056 #ifdef TCNT0H
00057 #define SCHEDULER_TIMER_BITS 16
00058 #else
00059 #define SCHEDULER_TIMER_BITS 8
00060 #endif
00061
00062 #elif SCHEDULER_TIMER_NUM == 1
00063 #define SCHEDULER_TIMER_REGISTER() timer1_register_OV_intr(scheduler_interrupt)
00064 #define SCHEDULER_CLOCK_PRESCALER timer1_get_prescaler_div()
00065 #ifdef TCNT1H
00066 #define SCHEDULER_TIMER_BITS 16
00067 #else
00068 #define SCHEDULER_TIMER_BITS 8
00069 #endif
00070
00071 #elif SCHEDULER_TIMER_NUM == 2
00072 #define SCHEDULER_TIMER_REGISTER() timer2_register_OV_intr(scheduler_interrupt)
00073 #define SCHEDULER_CLOCK_PRESCALER timer2_get_prescaler_div()
00074 #ifdef TCNT2H
00075 #define SCHEDULER_TIMER_BITS 16
00076 #else
00077 #define SCHEDULER_TIMER_BITS 8
00078 #endif
00079
00080 #elif SCHEDULER_TIMER_NUM == 3
00081 #define SCHEDULER_TIMER_REGISTER() timer3_register_OV_intr(scheduler_interrupt)
00082 #define SCHEDULER_CLOCK_PRESCALER timer3_get_prescaler_div()
00083 #ifdef TCNT3H
00084 #define SCHEDULER_TIMER_BITS 16
00085 #else
00086 #define SCHEDULER_TIMER_BITS 8
00087 #endif
00088
00089 #else
00090 #error "Bad SCHEDULER_TIMER_NUM value in config file"
00091 #endif
00092
00093 #endif
00094
00095 #ifdef CONFIG_MODULE_SCHEDULER_TIMER0
00096 #define SCHEDULER_TIMER_BITS 8
00097 #endif
00098
00099 #ifndef CONFIG_MODULE_SCHEDULER_MANUAL
00100
00103 #if SCHEDULER_TIMER_BITS == 8
00104 #define TIMER_UNIT_FLOAT ( 256000000.0 / (double)(CONFIG_QUARTZ) )
00105 #else
00106 #define TIMER_UNIT_FLOAT ( 65536000000.0 / (double)(CONFIG_QUARTZ) )
00107 #endif
00108
00114 #define SCHEDULER_UNIT_FLOAT ( TIMER_UNIT_FLOAT * (double)SCHEDULER_CLOCK_PRESCALER )
00115 #define SCHEDULER_UNIT ( (unsigned long) SCHEDULER_UNIT_FLOAT )
00116
00117 #endif
00118
00119
00120
00121 #define SCHEDULER_PERIODICAL 0
00122 #define SCHEDULER_SINGLE 1
00123
00124 #define SCHEDULER_DEFAULT_PRIORITY 128
00125
00126
00128 void scheduler_init(void);
00129
00135 int8_t scheduler_add_event(uint8_t unicity, void (*f)(void *), void * data, uint16_t period, uint8_t priority);
00136
00137
00141 static inline int8_t scheduler_add_single_event_priority(void (*f)(void *), void * data, uint16_t period, uint8_t priority)
00142 {
00143 return scheduler_add_event(SCHEDULER_SINGLE, f, data, period, priority);
00144 }
00145
00149 static inline int8_t scheduler_add_periodical_event_priority(void (*f)(void *), void * data, uint16_t period, uint8_t priority)
00150 {
00151 return scheduler_add_event(SCHEDULER_PERIODICAL, f, data, period, priority);
00152 }
00153
00157 static inline int8_t scheduler_add_single_event(void (*f)(void *), void * data, uint16_t period)
00158 {
00159 return scheduler_add_event(SCHEDULER_SINGLE, f, data, period, SCHEDULER_DEFAULT_PRIORITY);
00160 }
00161
00165 static inline int8_t scheduler_add_periodical_event(void (*f)(void *), void * data, uint16_t period)
00166 {
00167 return scheduler_add_event(SCHEDULER_PERIODICAL, f, data, period, SCHEDULER_DEFAULT_PRIORITY);
00168 }
00169
00174 int8_t scheduler_del_event(int8_t num);
00175
00180 void scheduler_interrupt(void);
00181
00186 uint8_t scheduler_disable_save(void);
00187
00191 void scheduler_enable_restore(uint8_t old_prio);
00192
00193 #endif