@@ -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
@@ -63,39 +86,135 @@ void lp_ticker_irq_handler(void);
63
86
64
87
/** Initialize the low power ticker
65
88
*
89
+ * Initialize or re-initialize the ticker. This resets all the
90
+ * clocking and prescaler registers, along with disabling
91
+ * the compare interrupt.
92
+ *
93
+ * Pseudo Code:
94
+ * @code
95
+ * void lp_ticker_init()
96
+ * {
97
+ * // Enable clock gate so processor can read LPTMR registers
98
+ * POWER_CTRL |= POWER_CTRL_LPTMR_Msk;
99
+ *
100
+ * // Disable the timer and ensure it is powered down
101
+ * LPTMR_CTRL &= ~(LPTMR_CTRL_ENABLE_Msk | LPTMR_CTRL_COMPARE_ENABLE_Msk);
102
+ *
103
+ * // Configure divisors - no division necessary
104
+ * LPTMR_PRESCALE = 0;
105
+ * LPTMR_CTRL |= LPTMR_CTRL_ENABLE_Msk;
106
+ *
107
+ * // Install the interrupt handler
108
+ * NVIC_SetVector(LPTMR_IRQn, (uint32_t)lp_ticker_irq_handler);
109
+ * NVIC_EnableIRQ(LPTMR_IRQn);
110
+ * }
111
+ * @endcode
66
112
*/
67
113
void lp_ticker_init (void );
68
114
69
- /** Read the current counter
115
+ /** Read the current tick
116
+ *
117
+ * If no rollover has occurred, the seconds passed since ::lp_ticker_init
118
+ * was called can be found by dividing the ticks returned by this function
119
+ * by the frequency returned by ::lp_ticker_get_info.
120
+ *
121
+ * @return The current timer's counter value in ticks
70
122
*
71
- * @return The current timer's counter value in microseconds
123
+ * Pseudo Code:
124
+ * @code
125
+ * uint32_t lp_ticker_read()
126
+ * {
127
+ * uint16_t count;
128
+ * uint16_t last_count;
129
+ *
130
+ * // Loop until the same tick is read twice since this
131
+ * // is ripple counter on a different clock domain.
132
+ * count = LPTMR_COUNT;
133
+ * do {
134
+ * last_count = count;
135
+ * count = LPTMR_COUNT;
136
+ * } while (last_count != count);
137
+ *
138
+ * return count;
139
+ * }
140
+ * @endcode
72
141
*/
73
142
uint32_t lp_ticker_read (void );
74
143
75
144
/** Set interrupt for specified timestamp
76
145
*
77
- * @param timestamp The time in microseconds to be set
146
+ * @param timestamp The time in ticks to be set
147
+ *
148
+ * @note no special handling needs to be done for times in the past
149
+ * as the common timer code will detect this and call
150
+ * ::lp_ticker_fire_interrupt if this is the case
151
+ *
152
+ * @note calling this function with timestamp of more than the supported
153
+ * number of bits returned by ::lp_ticker_get_info results in undefined
154
+ * behavior.
155
+ *
156
+ * Pseudo Code:
157
+ * @code
158
+ * void lp_ticker_set_interrupt(timestamp_t timestamp)
159
+ * {
160
+ * LPTMR_COMPARE = timestamp;
161
+ * LPTMR_CTRL |= LPTMR_CTRL_COMPARE_ENABLE_Msk;
162
+ * }
163
+ * @endcode
78
164
*/
79
165
void lp_ticker_set_interrupt (timestamp_t timestamp );
80
166
81
167
/** Disable low power ticker interrupt
82
168
*
169
+ * Pseudo Code:
170
+ * @code
171
+ * void lp_ticker_disable_interrupt(void)
172
+ * {
173
+ * // Disable the compare interrupt
174
+ * LPTMR_CTRL &= ~LPTMR_CTRL_COMPARE_ENABLE_Msk;
175
+ * }
176
+ * @endcode
83
177
*/
84
178
void lp_ticker_disable_interrupt (void );
85
179
86
180
/** Clear the low power ticker interrupt
87
181
*
182
+ * Pseudo Code:
183
+ * @code
184
+ * void lp_ticker_clear_interrupt(void)
185
+ * {
186
+ * // Write to the ICR (interrupt clear register) of the LPTMR
187
+ * LPTMR_ICR = LPTMR_ICR_COMPARE_Msk;
188
+ * }
189
+ * @endcode
88
190
*/
89
191
void lp_ticker_clear_interrupt (void );
90
192
91
193
/** Set pending interrupt that should be fired right away.
92
194
*
93
- * The ticker should be initialized prior calling this function.
195
+ * Pseudo Code:
196
+ * @code
197
+ * void lp_ticker_fire_interrupt(void)
198
+ * {
199
+ * NVIC_SetPendingIRQ(LPTMR_IRQn);
200
+ * }
201
+ * @endcode
94
202
*/
95
203
void lp_ticker_fire_interrupt (void );
96
204
97
205
/** Get frequency and counter bits of this ticker.
98
206
*
207
+ * Pseudo Code:
208
+ * @code
209
+ * const ticker_info_t* lp_ticker_get_info()
210
+ * {
211
+ * static const ticker_info_t info = {
212
+ * 32768, // 32KHz
213
+ * 16 // 16 bit counter
214
+ * };
215
+ * return &info;
216
+ * }
217
+ * @endcode
99
218
*/
100
219
const ticker_info_t * lp_ticker_get_info (void );
101
220
0 commit comments