no-OS
no_os_timer.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef _NO_OS_SRC_TIMER_H_
41 #define _NO_OS_SRC_TIMER_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 
47 #include <stdint.h>
48 
49 /******************************************************************************/
50 /********************** Macros and Constants Definitions **********************/
51 /******************************************************************************/
52 
53 #define TIMER_MAX_TABLE 4
54 
55 /******************************************************************************/
56 /*************************** Types Declarations *******************************/
57 /******************************************************************************/
58 
65  void *mutex;
67  uint16_t id;
69  uint32_t freq_hz;
71  uint32_t ticks_count;
75  void *extra;
76 };
77 
84 
91  uint16_t id;
93  uint32_t freq_hz;
95  uint32_t ticks_count;
99  void *extra;
100 };
101 
109  int32_t (*init)(struct no_os_timer_desc **,
110  const struct no_os_timer_init_param *);
112  int32_t (*start)(struct no_os_timer_desc *);
114  int32_t (*stop)(struct no_os_timer_desc *);
116  int32_t (*counter_get)(struct no_os_timer_desc *, uint32_t *counter);
118  int32_t (*counter_set)(struct no_os_timer_desc *, uint32_t new_val);
120  int32_t (*count_clk_get)(struct no_os_timer_desc *, uint32_t *freq_hz);
122  int32_t (*count_clk_set)(struct no_os_timer_desc *, uint32_t freq_hz);
125  uint64_t *elapsed_time);
127  int32_t (*remove)(struct no_os_timer_desc *);
128 };
129 
130 /******************************************************************************/
131 /************************ Functions Declarations ******************************/
132 /******************************************************************************/
133 
134 /* Initialize hardware timer and the handler structure associated with it. */
135 int32_t no_os_timer_init(struct no_os_timer_desc **desc,
136  const struct no_os_timer_init_param *param);
137 
138 /* Free the memory allocated by timer_setup(). */
139 int32_t no_os_timer_remove(struct no_os_timer_desc *desc);
140 
141 /* Start a timer. */
142 int32_t no_os_timer_start(struct no_os_timer_desc *desc);
143 
144 /* Stop a timer from counting. */
145 int32_t no_os_timer_stop(struct no_os_timer_desc *desc);
146 
147 /* Get the value of the counter register for the timer. */
148 int32_t no_os_timer_counter_get(struct no_os_timer_desc *desc,
149  uint32_t *counter);
150 
151 /* Set the timer counter register value. */
152 int32_t no_os_timer_counter_set(struct no_os_timer_desc *desc,
153  uint32_t new_val);
154 
155 /* Get the timer clock frequency. */
156 int32_t no_os_timer_count_clk_get(struct no_os_timer_desc *desc,
157  uint32_t *freq_hz);
158 
159 /* Set the timer clock frequency. */
160 int32_t no_os_timer_count_clk_set(struct no_os_timer_desc *desc,
161  uint32_t freq_hz);
162 
163 /* Get the elapsed time in nsec for the timer. */
165  uint64_t *elapsed_time);
166 
167 #endif // _NO_OS_SRC_TIMER_H_
no_os_timer_platform_ops
Structure holding timer function pointers that point to the platform specific function.
Definition: no_os_timer.h:107
no_os_timer_init
int32_t no_os_timer_init(struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
Initialize hardware timer and the handler structure associated with it.
Definition: no_os_timer.c:63
no_os_timer_init_param::id
uint16_t id
Definition: no_os_timer.h:91
no_os_timer_platform_ops::count_clk_set
int32_t(* count_clk_set)(struct no_os_timer_desc *, uint32_t freq_hz)
Definition: no_os_timer.h:122
no_os_timer_desc::platform_ops
const struct no_os_timer_platform_ops * platform_ops
Definition: no_os_timer.h:73
no_os_timer_platform_ops::get_elapsed_time_nsec
int32_t(* get_elapsed_time_nsec)(struct no_os_timer_desc *, uint64_t *elapsed_time)
Definition: no_os_timer.h:124
no_os_timer_count_clk_set
int32_t no_os_timer_count_clk_set(struct no_os_timer_desc *desc, uint32_t freq_hz)
Set the timer clock frequency.
Definition: no_os_timer.c:197
no_os_timer_count_clk_get
int32_t no_os_timer_count_clk_get(struct no_os_timer_desc *desc, uint32_t *freq_hz)
Get the timer clock frequency.
Definition: no_os_timer.c:179
no_os_timer_platform_ops::count_clk_get
int32_t(* count_clk_get)(struct no_os_timer_desc *, uint32_t *freq_hz)
Definition: no_os_timer.h:120
no_os_timer_init_param::ticks_count
uint32_t ticks_count
Definition: no_os_timer.h:95
no_os_timer_platform_ops::counter_get
int32_t(* counter_get)(struct no_os_timer_desc *, uint32_t *counter)
Definition: no_os_timer.h:116
no_os_timer_init_param::freq_hz
uint32_t freq_hz
Definition: no_os_timer.h:93
no_os_timer_platform_ops::counter_set
int32_t(* counter_set)(struct no_os_timer_desc *, uint32_t new_val)
Definition: no_os_timer.h:118
no_os_timer_desc::ticks_count
uint32_t ticks_count
Definition: no_os_timer.h:71
no_os_timer_desc::id
uint16_t id
Definition: no_os_timer.h:67
no_os_timer_start
int32_t no_os_timer_start(struct no_os_timer_desc *desc)
Start a timer.
Definition: no_os_timer.c:110
no_os_timer_stop
int32_t no_os_timer_stop(struct no_os_timer_desc *desc)
Stop a timer from counting.
Definition: no_os_timer.c:126
no_os_timer_platform_ops::init
int32_t(* init)(struct no_os_timer_desc **, const struct no_os_timer_init_param *)
Definition: no_os_timer.h:109
no_os_timer_remove
int32_t no_os_timer_remove(struct no_os_timer_desc *desc)
Free the memory allocated by timer_init().
Definition: no_os_timer.c:91
no_os_timer_get_elapsed_time_nsec
int32_t no_os_timer_get_elapsed_time_nsec(struct no_os_timer_desc *desc, uint64_t *elapsed_time)
Get the elapsed time in nsec for the timer.
Definition: no_os_timer.c:215
no_os_timer_init_param::platform_ops
const struct no_os_timer_platform_ops * platform_ops
Definition: no_os_timer.h:97
no_os_timer_platform_ops::remove
int32_t(* remove)(struct no_os_timer_desc *)
Definition: no_os_timer.h:127
no_os_timer_counter_get
int32_t no_os_timer_counter_get(struct no_os_timer_desc *desc, uint32_t *counter)
Get the value of the counter register for the timer.
Definition: no_os_timer.c:144
no_os_timer_init_param
Structure holding the parameters for timer initialization.
Definition: no_os_timer.h:89
no_os_timer_platform_ops::start
int32_t(* start)(struct no_os_timer_desc *)
Definition: no_os_timer.h:112
no_os_timer_desc::freq_hz
uint32_t freq_hz
Definition: no_os_timer.h:69
no_os_timer_counter_set
int32_t no_os_timer_counter_set(struct no_os_timer_desc *desc, uint32_t new_val)
Set the timer counter register value.
Definition: no_os_timer.c:162
no_os_timer_desc::extra
void * extra
Definition: no_os_timer.h:75
no_os_timer_init_param::extra
void * extra
Definition: no_os_timer.h:99
no_os_timer_desc::mutex
void * mutex
Definition: no_os_timer.h:65
no_os_timer_desc
Structure holding timer descriptor.
Definition: no_os_timer.h:63
no_os_timer_platform_ops::stop
int32_t(* stop)(struct no_os_timer_desc *)
Definition: no_os_timer.h:114