khypervisor
v1
|
00001 #ifndef __TIMER_H__ 00002 #define __TIMER_H__ 00003 00004 #include "hvmm_types.h" 00005 #include "arch_types.h" 00006 00007 /* 00008 * Implements Timer functionality such as, 00009 * 00010 * - timer channel: periodic callback at a given time interval 00011 * - current time: time since boot-up 00012 * 00013 * ==Example Usage== 00014 * 00015 * Initialize the timer module 00016 * timer_init(timer_sched); 00017 * 00018 * Set interval 10 to timer_sched channel 00019 * timer_set_interval( timer_sched, 10 ); 00020 * 00021 * Set cb1 callback function to timer_scehd channel. 00022 * cb1 call after 10 interval. 00023 * timer_set_callback( timer_sched, &cb1 ); 00024 * 00025 * Start timer_sched channel. cb1 call after 10 interval. 00026 * timer_start( timer_sched ); 00027 */ 00028 00029 #define TIMER_MAX_CHANNEL_CALLBACKS 8 00030 00031 typedef enum{ 00032 timer_sched = 0, 00033 TIMER_NUM_MAX_CHANNELS 00034 } timer_channel_t; 00035 00036 typedef void(*timer_callback_t)(void *pdata); 00037 00038 struct timer_channel{ 00039 uint32_t interval_us; 00040 timer_callback_t callbacks[TIMER_MAX_CHANNEL_CALLBACKS]; 00041 }; 00042 00043 /* 00044 * Calling this function is required only once in the entire system prior to calls 00045 * to other functions of Timer module. 00046 */ 00047 hvmm_status_t timer_init(timer_channel_t channel); 00048 00049 /* 00050 * Starts the timer channel specified by 'channel'. The callback, 00051 * if set, will be periodically called until it's unset or the channel stops by 00052 * 'timer_stop(timer_channel)' 00053 */ 00054 hvmm_status_t timer_start(timer_channel_t channel); 00055 00056 /* 00057 * Stops the timer channel specified by 'channel' 00058 */ 00059 hvmm_status_t timer_stop(timer_channel_t channel); 00060 00061 /* 00062 * Sets time interval, in microseconds, for the timer channel. 00063 * If the channel has been started and a callback function is set, it will be called 00064 * in the next interval 00065 */ 00066 hvmm_status_t timer_set_interval(timer_channel_t channel, uint32_t interval_us); 00067 00068 /* 00069 * Returns the time interval for the timer channel if it was set previously. 00070 * Unknown value is returned otherwise. 00071 */ 00072 uint32_t timer_get_interval(timer_channel_t channel); 00073 00074 /* 00075 * Adds a callback function for the timer channel. 00076 */ 00077 hvmm_status_t timer_add_callback(timer_channel_t channel, timer_callback_t handler); 00078 00079 /* 00080 * Removes the callback function from the timer channel's registered callback function list 00081 * if it previously has been added. 00082 */ 00083 hvmm_status_t timer_remove_callback(timer_channel_t channel, timer_callback_t handler); 00084 00085 /* 00086 * Converts from microseconds to system counter. 00087 */ 00088 uint64_t timer_t2c(uint64_t time_us); 00089 00090 #endif