My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sw_timer.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact developer@sierraware.com.
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2010-2014 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 /*
24  * SW Timer declarations.
25  */
26 
27 #ifndef __TIMER_FRAME_WORK_
28 #define __TIMER_FRAME_WORK_
29 
30 #include <sw_types.h>
31 #include <sw_semaphores.h>
32 #include <sw_list.h>
33 
34 #define NSECS_PER_SEC 1000000000L
35 /*Seconds will be set to maximum value and the number of nanoseconds
36  * will be zero */
37 #define TIMEVAL_MAX (((s64)~((u64)1 << 63)) & (~((u64)0xFFFFFFFF)))
38 #define MAX_NUM_OF_TIMERS 2
39 
40  /*The timer event is Inactive*/
41 #define TIMER_STATE_INACTIVE 0x00
42  /* The timer event is active and is waiting for expiration*/
43 #define TIMER_STATE_ACTIVE 0x01
44  /*The timer is expired and is waiting on the callback list to be executed*/
45 #define TIMER_STATE_PENDING 0x02
46  /* The timer event is currently being executed */
47 #define TIMER_STATE_EXECUTING 0x04
48 
49 
55 typedef union {
56  s64 tval64;
57  struct {
58  s32 nsec, sec;
59  }tval;
60 }timeval_t;
61 
66  /* The handler function should be run in softirq*/
68  /* The handler function should be run in hardirq context itself*/
70  /* The handler function should be executed in hardirq and it should not
71  * restart the timer*/
73 };
74 
81 };
82 
88 
90  struct list active;
93 
94  int clock_id;
95  int shift;
96  unsigned long mult;
97 };
98 
104 
107  unsigned long num_events;
110 
111 };
112 
113 extern struct timer_cpu_info timer_cpu_info;
114 
118 struct timer_event {
119  struct list node;
121 
124  int (*handler)(void* );
125  int state;
127  void* data;
128 };
129 
130 typedef void (*sw_timer_event_handler) (struct timer_event*);
131 
141 
149 int timer_event_destroy(struct timer_event* tevent);
150 
157 void timer_event_start(struct timer_event *tevent, timeval_t *time);
158 
162 void __free_running_cntr_intr(void);
163 
169 void read_timestamp(timeval_t *val);
170 
174 void timer_interrupt(void);
175 
179 void init_sw_timer(void );
180 
189 int timeval_after(const timeval_t *value1, const timeval_t *value2);
190 
199 int timeval_after(const timeval_t *value1, const timeval_t *value2);
200 
206 u32 get_clock_period_us(void);
207 
220 int timeval_before(const timeval_t *value1, const timeval_t *value2);
221 
231 int is_timer_event_active(struct timer_event* tevent);
232 
243 
250 void timer_event_stop(struct timer_event* tevent);
251 
259 void wake_up_from_sleep(struct timer_event* tevent);
260 #endif
u32 get_clock_period_us(void)
This function retrieves the clock period in micro scale.
Definition: timer.c:83
struct list active
Definition: sw_timer.h:90
struct spinlock spin_lock
Definition: sw_timer.h:89
Structure to represent the time in High resolution format( Resolution in Nano seconds) ...
Definition: sw_timer.h:55
void timer_event_stop(struct timer_event *tevent)
Stops a timer_event.
Definition: sw_timer.c:648
int callback_mode
Definition: sw_timer.h:126
int is_timer_event_active(struct timer_event *tevent)
checks whether the timer event is active
Definition: sw_timer.c:611
struct timer_clock_info * clk_info
Definition: sw_timer.h:123
int clock_id
Definition: sw_timer.h:94
int free_run_clock_id
Definition: sw_timer.h:108
void __free_running_cntr_intr(void)
This function updates the timestamp This function is called only when the free running counter interr...
Definition: sw_timer.c:282
Definition: sw_timer.h:80
int timer_event_destroy(struct timer_event *tevent)
This function deletes the timer event structure After expiration of the timer ,the application can ch...
Definition: sw_timer.c:386
timer_callback_mode
Definition: sw_timer.h:65
s64 tval64
Definition: sw_timer.h:56
void timer_interrupt(void)
This is the function which is called on expiry of any timer event. This fn goes through the list of r...
Definition: sw_timer.c:549
int(* handler)(void *)
Definition: sw_timer.h:124
void(* sw_timer_event_handler)(struct timer_event *)
Definition: sw_timer.h:130
timeval_t expires_next
Definition: sw_timer.h:105
timeval_t clock_period
Definition: sw_timer.h:91
timer_cbfn_return_value
Definition: sw_timer.h:78
int state
Definition: sw_timer.h:125
void wake_up_from_sleep(struct timer_event *tevent)
This function wakes up the task which has called sleep.
Definition: sw_timer_functions.c:39
struct timer_cpu_info * cpu_info
Definition: sw_timer.h:87
Definition: sw_timer.h:86
timeval_t expires
Definition: sw_timer.h:122
struct timer_clock_info clock_info[MAX_NUM_OF_TIMERS]
Definition: sw_timer.h:103
s32 sec
Definition: sw_timer.h:58
Definition: sw_timer.h:118
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 ha...
Definition: sw_timer.c:486
#define MAX_NUM_OF_TIMERS
Definition: sw_timer.h:38
void * data
Definition: sw_timer.h:127
struct list pending_routines
Definition: sw_timer.h:106
void init_sw_timer(void)
This function initializes the Timer structure variables.
Definition: sw_timer.c:64
void read_timestamp(timeval_t *val)
It updates and returns the current timestamp value.
Definition: sw_timer.c:306
Definition: sw_timer.h:102
Definition: sw_timer.h:79
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...
Definition: sw_timer.c:346
Definition: sw_list.h:56
timeval_t timer_period
Definition: sw_timer.h:92
int is_timer_event_waiting_on_callback(struct timer_event *tevent)
checks whether the timer event is waiting in callback mode
Definition: sw_timer.c:631
int shift
Definition: sw_timer.h:95
struct list node
Definition: sw_timer.h:119
Definition: sw_timer.h:67
unsigned long mult
Definition: sw_timer.h:96
int tick_timer_id
Definition: sw_timer.h:109
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.
Definition: sw_timer.c:161
Definition: sw_semaphores.h:236
unsigned long num_events
Definition: sw_timer.h:107
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.
Definition: sw_timer.c:186
Definition: sw_timer.h:72
Definition: sw_timer.h:69
struct list callback_entry
Definition: sw_timer.h:120