no-OS
timer.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef SRC_TIMER_H_
41 #define SRC_TIMER_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 
47 #include <stdint.h>
48 
49 /******************************************************************************/
50 /*************************** Types Declarations *******************************/
51 /******************************************************************************/
52 
57 struct timer_desc {
59  uint16_t id;
61  uint32_t freq_hz;
63  uint32_t load_value;
65  void *extra;
66 };
67 
74  uint16_t id;
76  uint32_t freq_hz;
78  uint32_t load_value;
80  void *extra;
81 };
82 
83 /******************************************************************************/
84 /************************ Functions Declarations ******************************/
85 /******************************************************************************/
86 
87 /* Initialize hardware timer and the handler structure associated with it. */
88 int32_t timer_init(struct timer_desc **desc,
89  struct timer_init_param *param);
90 
91 /* Free the memory allocated by timer_setup(). */
92 int32_t timer_remove(struct timer_desc *desc);
93 
94 /* Start a timer. */
95 int32_t timer_start(struct timer_desc *desc);
96 
97 /* Stop a timer from counting. */
98 int32_t timer_stop(struct timer_desc *desc);
99 
100 /* Get the value of the counter register for the timer. */
101 int32_t timer_counter_get(struct timer_desc *desc, uint32_t *counter);
102 
103 /* Set the timer counter register value. */
104 int32_t timer_counter_set(struct timer_desc *desc, uint32_t new_val);
105 
106 /* Get the timer clock frequency. */
107 int32_t timer_count_clk_get(struct timer_desc *desc, uint32_t *freq_hz);
108 
109 /* Set the timer clock frequency. */
110 int32_t timer_count_clk_set(struct timer_desc *desc, uint32_t freq_hz);
111 
112 #endif /* SRC_TIMER_H_ */
113 
timer_init
int32_t timer_init(struct timer_desc **desc, struct timer_init_param *param)
Initialize a instance of a timer.
Definition: timer.c:111
timer_desc::load_value
uint32_t load_value
Definition: timer.h:63
timer_init_param
Structure holding the parameters for timer initialization.
Definition: timer.h:72
timer_init_param::freq_hz
uint32_t freq_hz
Definition: timer.h:76
timer_desc::id
uint16_t id
Definition: timer.h:59
timer_start
int32_t timer_start(struct timer_desc *desc)
Enable counting in the timer instance.
Definition: timer.c:200
timer_count_clk_set
int32_t timer_count_clk_set(struct timer_desc *desc, uint32_t freq_hz)
Set the frequency the timer counts with.
Definition: timer.c:344
timer_remove
int32_t timer_remove(struct timer_desc *desc)
Remove a instance of a timer.
Definition: timer.c:163
timer_desc::extra
void * extra
Definition: timer.h:65
timer_count_clk_get
int32_t timer_count_clk_get(struct timer_desc *desc, uint32_t *freq_hz)
Get the frequency the timer counts with.
Definition: timer.c:327
timer_desc::freq_hz
uint32_t freq_hz
Definition: timer.h:61
timer_stop
int32_t timer_stop(struct timer_desc *desc)
Stop counting the timer instance.
Definition: timer.c:226
timer_counter_set
int32_t timer_counter_set(struct timer_desc *desc, uint32_t new_val)
Set a new value for the timer.
Definition: timer.c:307
timer_counter_get
int32_t timer_counter_get(struct timer_desc *desc, uint32_t *counter)
Get the value the timer is at.
Definition: timer.c:254
timer_init_param::id
uint16_t id
Definition: timer.h:74
timer_init_param::extra
void * extra
Definition: timer.h:80
timer_init_param::load_value
uint32_t load_value
Definition: timer.h:78
timer_desc
Structure holding timer descriptor.
Definition: timer.h:57