-
Notifications
You must be signed in to change notification settings - Fork 26
Timer API
Implements Timer functionality such as,
- timer channel: periodic callback at a given time interval
- current time: time since boot-up
typedef enum{
timer_sched = 0;
} timer_channel_t;
Represents a channel where 'time interval' and a callback function can be specified.
struct timeval{
uint64_t tv_sec;
uint64_t tv_usec;
};
Represents time in seconds and microseconds.
- tv_sec : seconds
- tv_usec : microseconds
typedef void(*timer_callback_t)(void);
/* Initialize the timer module
* This is required only once in the entire system prior to calls to other functions of Timer module.
*/
timer_init(timer_sched);
/* Set interval 10 to timer_sched channel */
timer_set_interval( timer_sched, 10 );
/* Set cb1 callback function to timer_scehd channel. */
/* cb1 call after 10 interval. */
timer_set_callback( timer_sched, &cb1 );
/* Start timer_sched channel. cb1 call after 10 interval. */
timer_start( timer_sched );
...
/* Remove the call back */
timer_remove_callback(timer_sched, &cb1);
...
void cb1(...) {
/* the call back function body */
}
hvmm_status_t timer_init(timer_channel_t channel);
Calling this function is required only once in the entire system prior to calls to other functions of Timer module.
hvmm_status_t timer_start(timer_channel_t channel);
Starts the timer channel specified by 'channel'. The callback, if set, will be periodically called until it's unset or the channel stops by 'timer_stop(timer_channel)'
hvmm_status_t timer_stop(timer_channel_t channel);
Stops the timer channel specified by 'channel'
hvmm_status_t timer_set_interval(timer_channel_t channel, uint32_t interval);
Sets time interval, in (TBD)seconds, for the timer channel. If the channel has been started and a callback function is set, it will be called in the next interval
hvmm_status_t timer_get_interval(timer_channel_t channel);
Returns the time interval for the timer channel if it was set previously. Unknown value is returned otherwise.
hvmm_status_t timer_add_callback(timer_channel_t channel, timer_callback_t handler);
Adds a callback function for the timer channel.
hvmm_status_t timer_remove_callback(timer_channel_t channel, timer_callback_t handler);
Removes the callback function from the timer channel's registered callback function list if it previously has been added.
- channel: The timer channel
- handler: callback function pointer
void timer_get_time(struct timeval* timeval);
Returns current time since boot-up
uint64_t timer_c2t(uint64_t count);
Converts from system counter to milliseconds.
uint64_t timer_t2c(uint64_t time);
Converts from milliseconds to system counter.