no-OS
no_os_timer.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef _NO_OS_SRC_TIMER_H_
35 #define _NO_OS_SRC_TIMER_H_
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 
41 #include <stdint.h>
42 
43 /******************************************************************************/
44 /********************** Macros and Constants Definitions **********************/
45 /******************************************************************************/
46 
47 #define TIMER_MAX_TABLE 4
48 
49 /******************************************************************************/
50 /*************************** Types Declarations *******************************/
51 /******************************************************************************/
52 
59  void *mutex;
61  uint16_t id;
63  uint32_t freq_hz;
65  uint32_t ticks_count;
69  void *extra;
70 };
71 
78 
85  uint16_t id;
87  uint32_t freq_hz;
89  uint32_t ticks_count;
93  void *extra;
94 };
95 
103  int32_t (*init)(struct no_os_timer_desc **,
104  const struct no_os_timer_init_param *);
106  int32_t (*start)(struct no_os_timer_desc *);
108  int32_t (*stop)(struct no_os_timer_desc *);
110  int32_t (*counter_get)(struct no_os_timer_desc *, uint32_t *counter);
112  int32_t (*counter_set)(struct no_os_timer_desc *, uint32_t new_val);
114  int32_t (*count_clk_get)(struct no_os_timer_desc *, uint32_t *freq_hz);
116  int32_t (*count_clk_set)(struct no_os_timer_desc *, uint32_t freq_hz);
119  uint64_t *elapsed_time);
121  int32_t (*remove)(struct no_os_timer_desc *);
122 };
123 
124 /******************************************************************************/
125 /************************ Functions Declarations ******************************/
126 /******************************************************************************/
127 
128 /* Initialize hardware timer and the handler structure associated with it. */
129 int32_t no_os_timer_init(struct no_os_timer_desc **desc,
130  const struct no_os_timer_init_param *param);
131 
132 /* Free the memory allocated by timer_setup(). */
133 int32_t no_os_timer_remove(struct no_os_timer_desc *desc);
134 
135 /* Start a timer. */
136 int32_t no_os_timer_start(struct no_os_timer_desc *desc);
137 
138 /* Stop a timer from counting. */
139 int32_t no_os_timer_stop(struct no_os_timer_desc *desc);
140 
141 /* Get the value of the counter register for the timer. */
142 int32_t no_os_timer_counter_get(struct no_os_timer_desc *desc,
143  uint32_t *counter);
144 
145 /* Set the timer counter register value. */
146 int32_t no_os_timer_counter_set(struct no_os_timer_desc *desc,
147  uint32_t new_val);
148 
149 /* Get the timer clock frequency. */
150 int32_t no_os_timer_count_clk_get(struct no_os_timer_desc *desc,
151  uint32_t *freq_hz);
152 
153 /* Set the timer clock frequency. */
154 int32_t no_os_timer_count_clk_set(struct no_os_timer_desc *desc,
155  uint32_t freq_hz);
156 
157 /* Get the elapsed time in nsec for the timer. */
159  uint64_t *elapsed_time);
160 
161 #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:101
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:57
no_os_timer_init_param::id
uint16_t id
Definition: no_os_timer.h:85
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:116
no_os_timer_desc::platform_ops
const struct no_os_timer_platform_ops * platform_ops
Definition: no_os_timer.h:67
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:118
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:191
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:173
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:114
no_os_timer_init_param::ticks_count
uint32_t ticks_count
Definition: no_os_timer.h:89
no_os_timer_platform_ops::counter_get
int32_t(* counter_get)(struct no_os_timer_desc *, uint32_t *counter)
Definition: no_os_timer.h:110
no_os_timer_init_param::freq_hz
uint32_t freq_hz
Definition: no_os_timer.h:87
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:112
no_os_timer_desc::ticks_count
uint32_t ticks_count
Definition: no_os_timer.h:65
no_os_timer_desc::id
uint16_t id
Definition: no_os_timer.h:61
no_os_timer_start
int32_t no_os_timer_start(struct no_os_timer_desc *desc)
Start a timer.
Definition: no_os_timer.c:104
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:120
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:103
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:85
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:209
no_os_timer_init_param::platform_ops
const struct no_os_timer_platform_ops * platform_ops
Definition: no_os_timer.h:91
no_os_timer_platform_ops::remove
int32_t(* remove)(struct no_os_timer_desc *)
Definition: no_os_timer.h:121
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:138
no_os_timer_init_param
Structure holding the parameters for timer initialization.
Definition: no_os_timer.h:83
no_os_timer_platform_ops::start
int32_t(* start)(struct no_os_timer_desc *)
Definition: no_os_timer.h:106
no_os_timer_desc::freq_hz
uint32_t freq_hz
Definition: no_os_timer.h:63
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:156
no_os_timer_desc::extra
void * extra
Definition: no_os_timer.h:69
no_os_timer_init_param::extra
void * extra
Definition: no_os_timer.h:93
no_os_timer_desc::mutex
void * mutex
Definition: no_os_timer.h:59
no_os_timer_desc
Structure holding timer descriptor.
Definition: no_os_timer.h:57
no_os_timer_platform_ops::stop
int32_t(* stop)(struct no_os_timer_desc *)
Definition: no_os_timer.h:108