My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Enumerations | Functions | Variables
sw_timer.h File Reference
#include <sw_types.h>
#include <sw_semaphores.h>
#include <sw_list.h>

Go to the source code of this file.

Classes

union  timeval_t
 Structure to represent the time in High resolution format( Resolution in Nano seconds) More...
 
struct  timer_clock_info
 
struct  timer_cpu_info
 
struct  timer_event
 

Macros

#define NSECS_PER_SEC   1000000000L
 
#define TIMEVAL_MAX   (((s64)~((u64)1 << 63)) & (~((u64)0xFFFFFFFF)))
 
#define MAX_NUM_OF_TIMERS   2
 
#define TIMER_STATE_INACTIVE   0x00
 
#define TIMER_STATE_ACTIVE   0x01
 
#define TIMER_STATE_PENDING   0x02
 
#define TIMER_STATE_EXECUTING   0x04
 

Typedefs

typedef void(* sw_timer_event_handler )(struct timer_event *)
 

Enumerations

enum  timer_callback_mode { TIMER_CALLBACK_SOFTIRQ, TIMER_CALLBACK_HARDIRQ, TIMER_CALLBACK_HARDIRQ_NORESTART }
 
enum  timer_cbfn_return_value { TIMER_RESTART, TIMER_NORESTART }
 

Functions

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 __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...
 
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...
 
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...
 
u32 get_clock_period_us (void)
 This function retrieves the clock period in micro scale. 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...
 
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...
 
void wake_up_from_sleep (struct timer_event *tevent)
 This function wakes up the task which has called sleep. More...
 

Variables

struct timer_cpu_info timer_cpu_info
 

Macro Definition Documentation

#define MAX_NUM_OF_TIMERS   2
#define NSECS_PER_SEC   1000000000L
#define TIMER_STATE_ACTIVE   0x01
#define TIMER_STATE_EXECUTING   0x04
#define TIMER_STATE_INACTIVE   0x00
#define TIMER_STATE_PENDING   0x02
#define TIMEVAL_MAX   (((s64)~((u64)1 << 63)) & (~((u64)0xFFFFFFFF)))

Typedef Documentation

typedef void(* sw_timer_event_handler)(struct timer_event *)

Enumeration Type Documentation

Enumerator
TIMER_CALLBACK_SOFTIRQ 
TIMER_CALLBACK_HARDIRQ 
TIMER_CALLBACK_HARDIRQ_NORESTART 
Enumerator
TIMER_RESTART 
TIMER_NORESTART 

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

u32 get_clock_period_us ( void  )

This function retrieves the clock period in micro scale.

Returns
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
handler
priv_data
Returns
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
tevent
Returns
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
tevent
time
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
value1
value2
Returns
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
void wake_up_from_sleep ( struct timer_event tevent)

This function wakes up the task which has called sleep.

Parameters
teventThe timer_event structure used for putting this function to sleep

Variable Documentation