Intel® Quark™ Microcontroller Software Interface 1.4.0 Intel® Quark™ Microcontroller BSP

- Main Page
- Modules
- Data Structures
- Files

- File List

qm_aon_counters.h
1 /*
2 * {% copyright %}
3 */
4
5 #ifndef __QM_AON_COUNTERS_H__
6 #define __QM_AON_COUNTERS_H__
7
8 #include "qm_common.h"
9 #include "qm_soc_regs.h"
10
11 /**
12 * Always-on Counters.
13 *
14 * @note The always on counters are in the 32kHz clock domain. Some register
15 * operations take a minimum of a 32kHz clock cycle to complete. If the Always
16 * on timer interrupt is not configured to be edge triggered, multiple
17 * interrupts will occur.
18 *
19 * @defgroup groupAONC Always-on Counters
20 * @{
21 */
22
23 /**
24 * Always on counter status.
25 */
26 typedef enum {
27 /**
28 * Default Timer Status
29 */
30 QM_AONPT_READY = 0,
31 /**
32 * Timer expired. Status must be cleared with qm_aonpt_clear().
33 */
34 QM_AONPT_EXPIRED,
35 } qm_aonpt_status_t;
36
37 /**
38 * QM Always-on Periodic Timer configuration type.
39 */
40 typedef struct {
41 uint32_t count; /**< Time to count down from in clock cycles.*/
42 bool int_en; /**< Enable/disable the interrupts. */
43
44 /**
45 * User callback.
46 *
47 * @param[in] data User defined data.
48 */
49 void (*callback)(void *data);
50 void *callback_data; /**< Callback data. */
51 } qm_aonpt_config_t;
52
53 /**
54 * Enable the Always-on Counter.
55 *
56 * @param[in] aonc Always-on counter to read.
57 *
58 * @return Standard errno return type for QMSI.
59 * @retval 0 on success.
60 * @retval Negative @ref errno for possible error codes.
61 */
62 int qm_aonc_enable(const qm_aonc_t aonc);
63
64 /**
65 * Disable the Always-on Counter.
66 *
67 * @param[in] aonc Always-on counter to read.
68 *
69 * @return Standard errno return type for QMSI.
70 * @retval 0 on success.
71 * @retval Negative @ref errno for possible error codes.
72 */
73 int qm_aonc_disable(const qm_aonc_t aonc);
74
75 /**
76 * Get the current value of the Always-on Counter.
77 *
78 * Returns a 32-bit value which represents the number of clock cycles
79 * since the counter was first enabled.
80 *
81 * @param[in] aonc Always-on counter to read.
82 * @param[out] val Value of the counter. This must not be NULL.
83 *
84 * @return Standard errno return type for QMSI.
85 * @retval 0 on success.
86 * @retval Negative @ref errno for possible error codes.
87 */
88 int qm_aonc_get_value(const qm_aonc_t aonc, uint32_t *const val);
89
90 /**
91 * Set the Always-on Periodic Timer configuration.
92 *
93 * This includes the initial value of the Always-on Periodic Timer,
94 * the interrupt enable and the callback function that will be run
95 * when the timer expiers and an interrupt is triggered.
96 * The Periodic Timer is disabled if the counter is set to 0.
97 *
98 * @param[in] aonc Always-on counter to read.
99 * @param[in] cfg New configuration for the Always-on Periodic Timer.
100 * This must not be NULL.
101 *
102 * @return Standard errno return type for QMSI.
103 * @retval 0 on success.
104 * @retval Negative @ref errno for possible error codes.
105 */
106 int qm_aonpt_set_config(const qm_aonc_t aonc,
107 const qm_aonpt_config_t *const cfg);
108
109 /**
110 * Get the current value of the Always-on Periodic Timer.
111 *
112 * Returns a 32-bit value which represents the number of clock cycles
113 * remaining before the timer fires.
114 * This is the initial configured number minus the number of cycles that have
115 * passed.
116 *
117 * @param[in] aonc Always-on counter to read.
118 * @param[out] val Value of the Always-on Periodic Timer.
119 * This must not be NULL.
120 *
121 * @return Standard errno return type for QMSI.
122 * @retval 0 on success.
123 * @retval Negative @ref errno for possible error codes.
124 */
125 int qm_aonpt_get_value(const qm_aonc_t aonc, uint32_t *const val);
126
127 /**
128 * Get the current status of an Always-on Periodic Timer.
129 *
130 * @param[in] aonc Always-on counter to read.
131 * @param[out] status Status of the Always-on Periodic Timer.
132 * This must not be NULL.
133 *
134 * @return Standard errno return type for QMSI.
135 * @retval 0 on success.
136 * @retval Negative @ref errno for possible error codes.
137 */
138 int qm_aonpt_get_status(const qm_aonc_t aonc, qm_aonpt_status_t *const status);
139
140 /**
141 * Clear the status of the Always-on Periodic Timer.
142 *
143 * The status must be clear before the Always-on Periodic Timer can trigger
144 * another interrupt.
145 *
146 * @param[in] aonc Always-on counter to read.
147 *
148 * @return Standard errno return type for QMSI.
149 * @retval 0 on success.
150 * @retval Negative @ref errno for possible error codes.
151 */
152 int qm_aonpt_clear(const qm_aonc_t aonc);
153
154 /**
155 * Reset the Always-on Periodic Timer back to the configured value.
156 *
157 * @param[in] aonc Always-on counter to read.
158 *
159 * @return Standard errno return type for QMSI.
160 * @retval 0 on success.
161 * @retval Negative @ref errno for possible error codes.
162 */
163 int qm_aonpt_reset(const qm_aonc_t aonc);
164
165 /**
166 * Save the Always-on Periodic Timer context.
167 *
168 * Save the configuration of the specified AONC peripheral
169 * before entering sleep.
170 *
171 * @param[in] aonc AONC index.
172 * @param[out] ctx AONC context structure. This must not be NULL.
173 *
174 * @return Standard errno return type for QMSI.
175 * @retval 0 on success.
176 * @retval Negative @ref errno for possible error codes.
177 */
178 int qm_aonpt_save_context(const qm_aonc_t aonc, qm_aonc_context_t *const ctx);
179
180 /**
181 * Restore the Always-on Periodic Timer context.
182 *
183 * Restore the configuration of the specified AONC peripheral
184 * after exiting sleep.
185 *
186 * @param[in] aonc AONC index.
187 * @param[in] ctx AONC context structure. This must not be NULL.
188 *
189 * @return Standard errno return type for QMSI.
190 * @retval 0 on success.
191 * @retval Negative @ref errno for possible error codes.
192 */
193 int qm_aonpt_restore_context(const qm_aonc_t aonc,
194 const qm_aonc_context_t *const ctx);
195
196 /**
197 * @}
198 */
199
200 #endif /* __QM_AON_COUNTERS_H__ */
qm_aonc_disable
int qm_aonc_disable(const qm_aonc_t aonc)
Disable the Always-on Counter.
Definition: qm_aon_counters.c:140
qm_aonpt_clear
int qm_aonpt_clear(const qm_aonc_t aonc)
Clear the status of the Always-on Periodic Timer.
Definition: qm_aon_counters.c:210
qm_aonpt_config_t::count
uint32_t count
Time to count down from in clock cycles.
Definition: qm_aon_counters.h:41
qm_aonpt_config_t::callback_data
void * callback_data
Callback data.
Definition: qm_aon_counters.h:50
qm_aonpt_status_t
qm_aonpt_status_t
Always on counter status.
Definition: qm_aon_counters.h:26
qm_aonc_enable
int qm_aonc_enable(const qm_aonc_t aonc)
Enable the Always-on Counter.
Definition: qm_aon_counters.c:130
qm_aonpt_get_status
int qm_aonpt_get_status(const qm_aonc_t aonc, qm_aonpt_status_t *const status)
Get the current status of an Always-on Periodic Timer.
Definition: qm_aon_counters.c:195
qm_aonc_get_value
int qm_aonc_get_value(const qm_aonc_t aonc, uint32_t *const val)
Get the current value of the Always-on Counter.
Definition: qm_aon_counters.c:150
qm_aonpt_save_context
int qm_aonpt_save_context(const qm_aonc_t aonc, qm_aonc_context_t *const ctx)
Save the Always-on Periodic Timer context.
Definition: qm_aon_counters.c:235
QM_AONPT_READY
Default Timer Status.
Definition: qm_aon_counters.h:30
qm_aonpt_get_value
int qm_aonpt_get_value(const qm_aonc_t aonc, uint32_t *const val)
Get the current value of the Always-on Periodic Timer.
Definition: qm_aon_counters.c:184
QM_AONPT_EXPIRED
Timer expired.
Definition: qm_aon_counters.h:34
qm_aonpt_config_t::int_en
bool int_en
Enable/disable the interrupts.
Definition: qm_aon_counters.h:42
qm_aonpt_config_t
QM Always-on Periodic Timer configuration type.
Definition: qm_aon_counters.h:40
qm_aonpt_reset
int qm_aonpt_reset(const qm_aonc_t aonc)
Reset the Always-on Periodic Timer back to the configured value.
Definition: qm_aon_counters.c:224
qm_aonpt_set_config
int qm_aonpt_set_config(const qm_aonc_t aonc, const qm_aonpt_config_t *const cfg)
Set the Always-on Periodic Timer configuration.
Definition: qm_aon_counters.c:160
qm_aonpt_restore_context
int qm_aonpt_restore_context(const qm_aonc_t aonc, const qm_aonc_context_t *const ctx)
Restore the Always-on Periodic Timer context.
Definition: qm_aon_counters.c:246
qm_aonc_t
qm_aonc_t
Number of Always-on counter controllers.
Definition: qm_soc_regs.h:255