@@ -30,10 +30,33 @@ extern "C" {
30
30
#endif
31
31
32
32
/**
33
- * \defgroup hal_LpTicker Low Power Ticker Functions
33
+ * \defgroup hal_lp_ticker Low Power Ticker
34
+ * Low level interface to the low power ticker of a target
35
+ *
36
+ * # Defined behavior
37
+ * * Has a reported frequency between 8KHz and 64KHz - verified by lp_ticker_info_test
38
+ * * Has a counter that is at least 12 bits wide - verified by lp_ticker_info_test
39
+ * * Continues operating in deep sleep mode - verified by lp_ticker_sleep_test
40
+ * * All behavior defined by the @ref hal_ticker_shared "ticker specification"
41
+ *
42
+ * # Undefined behavior
43
+ * * See the @ref hal_ticker_shared "ticker specification"
44
+ *
45
+ * @see hal_lp_ticker_tests
46
+ *
34
47
* @{
35
48
*/
36
49
50
+ /**
51
+ * \defgroup hal_lp_ticker_tests Low Power Ticker tests
52
+ * Tests to validate the proper implementation of the low power ticker
53
+ *
54
+ * To run the low power ticker hal tests use the command:
55
+ *
56
+ * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-us_lp_ticker*,tests-mbed_hal-lp_ticker*
57
+ *
58
+ */
59
+
37
60
typedef void (* ticker_irq_handler_type )(const ticker_data_t * const );
38
61
39
62
/** Set low power ticker IRQ handler
@@ -62,39 +85,135 @@ void lp_ticker_irq_handler(void);
62
85
63
86
/** Initialize the low power ticker
64
87
*
88
+ * Initialize or re-initialize the ticker. This resets all the
89
+ * clocking and prescaler registers, along with disabling
90
+ * the compare interrupt.
91
+ *
92
+ * Pseudo Code:
93
+ * @code
94
+ * void lp_ticker_init()
95
+ * {
96
+ * // Enable clock gate so processor can read LPTMR registers
97
+ * POWER_CTRL |= POWER_CTRL_LPTMR_Msk;
98
+ *
99
+ * // Disable the timer and ensure it is powered down
100
+ * LPTMR_CTRL &= ~(LPTMR_CTRL_ENABLE_Msk | LPTMR_CTRL_COMPARE_ENABLE_Msk);
101
+ *
102
+ * // Configure divisors - no division necessary
103
+ * LPTMR_PRESCALE = 0;
104
+ * LPTMR_CTRL |= LPTMR_CTRL_ENABLE_Msk;
105
+ *
106
+ * // Install the interrupt handler
107
+ * NVIC_SetVector(LPTMR_IRQn, (uint32_t)lp_ticker_irq_handler);
108
+ * NVIC_EnableIRQ(LPTMR_IRQn);
109
+ * }
110
+ * @endcode
65
111
*/
66
112
void lp_ticker_init (void );
67
113
68
- /** Read the current counter
114
+ /** Read the current tick
115
+ *
116
+ * If no rollover has occurred, the seconds passed since ::lp_ticker_init
117
+ * was called can be found by dividing the ticks returned by this function
118
+ * by the frequency returned by ::lp_ticker_get_info.
119
+ *
120
+ * @return The current timer's counter value in ticks
69
121
*
70
- * @return The current timer's counter value in microseconds
122
+ * Pseudo Code:
123
+ * @code
124
+ * uint32_t lp_ticker_read()
125
+ * {
126
+ * uint16_t count;
127
+ * uint16_t last_count;
128
+ *
129
+ * // Loop until the same tick is read twice since this
130
+ * // is ripple counter on a different clock domain.
131
+ * count = LPTMR_COUNT;
132
+ * do {
133
+ * last_count = count;
134
+ * count = LPTMR_COUNT;
135
+ * } while (last_count != count);
136
+ *
137
+ * return count;
138
+ * }
139
+ * @endcode
71
140
*/
72
141
uint32_t lp_ticker_read (void );
73
142
74
143
/** Set interrupt for specified timestamp
75
144
*
76
- * @param timestamp The time in microseconds to be set
145
+ * @param timestamp The time in ticks to be set
146
+ *
147
+ * @note no special handling needs to be done for times in the past
148
+ * as the common timer code will detect this and call
149
+ * ::lp_ticker_fire_interrupt if this is the case
150
+ *
151
+ * @note calling this function with timestamp of more than the supported
152
+ * number of bits returned by ::lp_ticker_get_info results in undefined
153
+ * behavior.
154
+ *
155
+ * Pseudo Code:
156
+ * @code
157
+ * void lp_ticker_set_interrupt(timestamp_t timestamp)
158
+ * {
159
+ * LPTMR_COMPARE = timestamp;
160
+ * LPTMR_CTRL |= LPTMR_CTRL_COMPARE_ENABLE_Msk;
161
+ * }
162
+ * @endcode
77
163
*/
78
164
void lp_ticker_set_interrupt (timestamp_t timestamp );
79
165
80
166
/** Disable low power ticker interrupt
81
167
*
168
+ * Pseudo Code:
169
+ * @code
170
+ * void lp_ticker_disable_interrupt(void)
171
+ * {
172
+ * // Disable the compare interrupt
173
+ * LPTMR_CTRL &= ~LPTMR_CTRL_COMPARE_ENABLE_Msk;
174
+ * }
175
+ * @endcode
82
176
*/
83
177
void lp_ticker_disable_interrupt (void );
84
178
85
179
/** Clear the low power ticker interrupt
86
180
*
181
+ * Pseudo Code:
182
+ * @code
183
+ * void lp_ticker_clear_interrupt(void)
184
+ * {
185
+ * // Write to the ICR (interrupt clear register) of the LPTMR
186
+ * LPTMR_ICR = LPTMR_ICR_COMPARE_Msk;
187
+ * }
188
+ * @endcode
87
189
*/
88
190
void lp_ticker_clear_interrupt (void );
89
191
90
192
/** Set pending interrupt that should be fired right away.
91
193
*
92
- * The ticker should be initialized prior calling this function.
194
+ * Pseudo Code:
195
+ * @code
196
+ * void lp_ticker_fire_interrupt(void)
197
+ * {
198
+ * NVIC_SetPendingIRQ(LPTMR_IRQn);
199
+ * }
200
+ * @endcode
93
201
*/
94
202
void lp_ticker_fire_interrupt (void );
95
203
96
204
/** Get frequency and counter bits of this ticker.
97
205
*
206
+ * Pseudo Code:
207
+ * @code
208
+ * const ticker_info_t* lp_ticker_get_info()
209
+ * {
210
+ * static const ticker_info_t info = {
211
+ * 32768, // 32KHz
212
+ * 16 // 16 bit counter
213
+ * };
214
+ * return &info;
215
+ * }
216
+ * @endcode
98
217
*/
99
218
const ticker_info_t * lp_ticker_get_info (void );
100
219
0 commit comments