My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions | Variables
sw_timer.c File Reference
#include <sw_types.h>
#include <sw_list.h>
#include <sw_timer.h>
#include <global.h>
#include <task.h>
#include <sw_buddy.h>
#include <sw_debug.h>
#include <sw_mem_functions.h>

Classes

struct  sw_tmr_info
 The elements of this structure are useful for implementing the sw_timer.
 

Macros

#define SW_FREE_RUNNING_CNTR   timer_cpu_info.free_run_clock_id
 
#define SW_TICKTIMER   timer_cpu_info.tick_timer_id
 

Functions

void init_sw_timer (void)
 This function initializes the Timer structure variables. More...
 
int timeval_after (const timeval_t *value1, const timeval_t *value2)
 Checks whether value 1 comes after value2 If yes returns 1 else returns 0. More...
 
int timeval_before (const timeval_t *value1, const timeval_t *value2)
 Checks whether value 1 comes before value2 If yes returns 1 else returns 0. More...
 
void __free_running_cntr_intr (void)
 This function updates the timestamp This function is called only when the free running counter interrupt is generated.(When free running counter reaches zero this interrupt arises and after that the counter reload itself to the max value(mostly 0xFFFFFFFF) and continue to count down) More...
 
void read_timestamp (timeval_t *val)
 It updates and returns the current timestamp value. More...
 
struct timer_eventtimer_event_create (sw_timer_event_handler handler, void *priv_data)
 This function is called to create a new timer event. It allocates the memory for timer event struct, initializes the elements and returns the structure. If it cannot allocate the memory then it returns NULL. More...
 
int timer_event_destroy (struct timer_event *tevent)
 This function deletes the timer event structure After expiration of the timer ,the application can choose to keep and reuse the same structure again or delete it.If it decides to delete the structure then this function is called. This function frees the memory. More...
 
void timer_event_start (struct timer_event *tevent, timeval_t *time)
 It starts the timer event by calling the appropriate functions The time interval is written to the hardwire timer and the event is added to the list of events to be handled on timer expiry. More...
 
void timer_interrupt (void)
 This is the function which is called on expiry of any timer event. This fn goes through the list of registered timer events. If the expiry time of the event is already in the past then the corresponding handler function is called. As the list is already sorted according to their time of expiration, the function returns either when it encounters the first event whose expiry time is in the future or when the list becomes empty. More...
 
int is_timer_event_active (struct timer_event *tevent)
 checks whether the timer event is active More...
 
int is_timer_event_waiting_on_callback (struct timer_event *tevent)
 checks whether the timer event is waiting in callback mode More...
 
void timer_event_stop (struct timer_event *tevent)
 Stops a timer_event. More...
 

Variables

struct timer_cpu_info timer_cpu_info
 

Macro Definition Documentation

#define SW_FREE_RUNNING_CNTR   timer_cpu_info.free_run_clock_id
#define SW_TICKTIMER   timer_cpu_info.tick_timer_id

Function Documentation

void __free_running_cntr_intr ( void  )

This function updates the timestamp This function is called only when the free running counter interrupt is generated.(When free running counter reaches zero this interrupt arises and after that the counter reload itself to the max value(mostly 0xFFFFFFFF) and continue to count down)

Otherwise the timestamp is updated by read_timestamp function

void init_sw_timer ( void  )

This function initializes the Timer structure variables.

int is_timer_event_active ( struct timer_event tevent)

checks whether the timer event is active

Parameters
teventThe timer event whose state need to be checked
Returns
1 - If active 0 - If not active
int is_timer_event_waiting_on_callback ( struct timer_event tevent)

checks whether the timer event is waiting in callback mode

Parameters
teventThe timer event whose state need to be checked
Returns
1 - If it is waiting on callback 0 - If it is not waiting on callback
void read_timestamp ( timeval_t val)

It updates and returns the current timestamp value.

Returns
The current timestamp value
struct timer_event* timer_event_create ( sw_timer_event_handler  handler,
void *  priv_data 
)

This function is called to create a new timer event. It allocates the memory for timer event struct, initializes the elements and returns the structure. If it cannot allocate the memory then it returns NULL.

Parameters
handlerThe handler which will be called on the expiration of the timer
priv_dataThe data which may be needed by the handler
Returns
-The timer_event structure allocated and initialized -NULL if it fails to allocate the structure
int timer_event_destroy ( struct timer_event tevent)

This function deletes the timer event structure After expiration of the timer ,the application can choose to keep and reuse the same structure again or delete it.If it decides to delete the structure then this function is called. This function frees the memory.

Parameters
teventThe structure which needs to be deleted
Returns
0 on success -1 on failure
void timer_event_start ( struct timer_event tevent,
timeval_t time 
)

It starts the timer event by calling the appropriate functions The time interval is written to the hardwire timer and the event is added to the list of events to be handled on timer expiry.

Parameters
teventThe timer event which needed to be started
timeThe time duration after which the event need to be expire
void timer_event_stop ( struct timer_event tevent)

Stops a timer_event.

Parameters
tevent
void timer_interrupt ( void  )

This is the function which is called on expiry of any timer event. This fn goes through the list of registered timer events. If the expiry time of the event is already in the past then the corresponding handler function is called. As the list is already sorted according to their time of expiration, the function returns either when it encounters the first event whose expiry time is in the future or when the list becomes empty.

int timeval_after ( const timeval_t value1,
const timeval_t value2 
)

Checks whether value 1 comes after value2 If yes returns 1 else returns 0.

Parameters
value1Time value1
value2Time value 2
Returns
1 - If value1 comes after value2 0 - If value2 comes after value1
int timeval_before ( const timeval_t value1,
const timeval_t value2 
)

Checks whether value 1 comes before value2 If yes returns 1 else returns 0.

Parameters
value1Time value 1
value2Time value 2
Returns
1 - If value1 comes before value2 0 - If value2 comes before value1

Variable Documentation