00001 #ifndef KAL_TIMER_WHEEL_H_
00002 #define KAL_TIMER_WHEEL_H_
00003
00004 #include <linux/time.h>
00005 #ifdef QOS_KS
00006 # include <linux/timer.h>
00007 # include <linux/jiffies.h>
00008 #endif
00009
00010 #include "kal_time.h"
00011 #include <linux/aquosa/qos_types.h>
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023
00024
00025
00026 #include "kal_arg.h"
00027 typedef void (*linux_timer_cb)(unsigned long cb_data);
00028 typedef void (*kal_timer_cb)(kal_arg_t cb_data);
00029
00030 typedef struct {
00031 struct timer_list timer;
00032 kal_timer_cb timer_cb;
00033 kal_arg_t timer_cb_data;
00034 char handler_running;
00035 } kal_timer_t;
00036
00037 #if defined(QOS_KS)
00038 static inline void set_timer_expires(kal_timer_t* p_timer, unsigned long expires) {
00039 p_timer->expires = expires;
00040 }
00041
00042 static inline unsigned long get_timer_expires(kal_timer_t* p_timer) {
00043 return p_timer->expires;
00044 }
00045
00046 #else
00047 void setup_timer(void* p_timer, void* p_call_back, kal_arg_t cb_data);
00048 void add_timer(void* p_timer);
00049 void del_timer(void* p_timer);
00050 void set_timer_expires(void* p_timer, unsigned long expires);
00051 unsigned long get_timer_expires(void* p_timer);
00052 int timer_pending(void* p_timer);
00053 static inline void del_timer_sync (void* p_timer) { del_timer(p_timer);}
00054
00055 struct timer_list {
00056
00057
00058 void* timer;
00059 };
00060
00061 #endif
00062
00063 void timer_callback(unsigned long cb_data) {
00064 kal_timer_t p_timer = (kal_timer_t *) cb_data;
00065 p_timer->handler_running = 1;
00066 p_timer->timer_cb(p_timer->
00067 }
00068
00069 static inline void kal_timer_init(kal_timer_t * p_timer, kal_timer_cb cb, kal_arg_t cb_data) {
00070 setup_timer(p_timer, (linux_timer_cb) cb, (unsigned long) cb_data);
00071 }
00072
00073 static inline void kal_timer_init_now(kal_timer_t * p_timer, kal_timer_cb cb, kal_arg_t cb_data) {
00074 unsigned long expires = get_jiffies();
00075 kal_timer_init(p_timer, cb, cb_data);
00076
00077 set_timer_expires(p_timer, expires);
00078 }
00079
00080 static inline void kal_timer_set(kal_timer_t * p_timer, kal_time_t t) {
00081 unsigned long expires = kal_time2jiffies(t);
00082
00083 del_timer(p_timer);
00084 set_timer_expires(p_timer, expires);
00085 add_timer(p_timer);
00086 }
00087
00088 static inline void kal_timer_del(kal_timer_t * p_timer) {
00089 del_timer_sync(p_timer);
00090 }
00091
00092 static inline void kal_timer_forward(kal_timer_t * p_timer, kal_time_t t) {
00093 unsigned long expires = get_timer_expires(p_timer) + kal_time2jiffies(t);
00094
00095
00096 kal_timer_del(p_timer);
00097 set_timer_expires(p_timer, expires);
00098 add_timer(p_timer);
00099 }
00100
00101 static inline int kal_timer_pending(kal_timer_t *p_timer) {
00102 return timer_pending(p_timer);
00103 }
00104
00105 #endif