Skip to content

Commit 67dfdde

Browse files
c1728p90xc0170
authored andcommitted
Add documentation for the HAL Ticker API
Add documentation and test header for the HAL Ticker API.
1 parent 1ae20c5 commit 67dfdde

File tree

5 files changed

+489
-10
lines changed

5 files changed

+489
-10
lines changed

TESTS/mbed_hal/lp_ticker_api_tests.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** \addtogroup hal_lp_ticker_tests
18+
* @{
19+
*/
20+
21+
#ifndef LP_TICKER_API_TESTS_H
22+
#define LP_TICKER_API_TESTS_H
23+
24+
#include "device.h"
25+
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
32+
/** Test that the ticker has the right frequency and number of bits
33+
*
34+
*/
35+
void lp_ticker_info_test(void);
36+
37+
/** Test that the ticker operates in deep sleep mode
38+
*
39+
*/
40+
void lp_ticker_deepsleep_test(void);
41+
42+
43+
/**@}*/
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif
50+
51+
/**@}*/

TESTS/mbed_hal/ticker_api_tests.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** \addtogroup hal_ticker_tests */
18+
/** @{*/
19+
20+
#ifndef TICKER_API_TESTS_H
21+
#define TICKER_API_TESTS_H
22+
23+
#include "device.h"
24+
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/** Test that ticker_init can be called multiple times
31+
*
32+
*/
33+
void ticker_init_test(void);
34+
35+
/** Test that ticker has a valid frequency and bitwidth
36+
*
37+
*/
38+
void ticker_info_test(void);
39+
40+
/** Test that the ticker increments by one on each tick
41+
*
42+
*/
43+
void ticker_increment_test(void);
44+
45+
/** Test that the interrupt fires at the right time
46+
*
47+
*/
48+
void ticker_interrupt_test(void);
49+
50+
/** Test that an interrupt is not triggered when ticker_set_interrupt is called with a time from the past
51+
*
52+
*/
53+
void ticker_past_test(void);
54+
55+
/** Test that a ticker can be rescheduled repeatedly before the handler has been called
56+
*
57+
*/
58+
void ticker_repeat_reschedule_test(void);
59+
60+
/** Test that ticker_fire_interrupt causes and interrupt to get fired immediately
61+
*
62+
*/
63+
void ticker_fire_now_test(void);
64+
65+
/** Test that common ticker functions complete with the required amount of time
66+
*
67+
* Ensure that ticker_read, ticker_clear_interrupt, ticker_set_interrupt
68+
* and ticker_fire_interrupt take less than 20us to complete.
69+
*
70+
*/
71+
void ticker_speed_test(void);
72+
73+
/** Test that the ticker correctly handles overflows
74+
*
75+
* This test verifies that rollover is properly handled and
76+
* that scheduling for a time after overflow works.
77+
*
78+
*/
79+
void ticker_overflow_test(void);
80+
81+
/** Test that rescheduling does not cause drift
82+
*
83+
* This test verifies that repeated rescheduling does not cause a
84+
* drift.
85+
*
86+
*/
87+
void ticker_reschedule_test(void);
88+
89+
/** Test that the ticker is operating at the frequency it specifies
90+
*
91+
*/
92+
void ticker_frequency_test(void);
93+
94+
95+
/**@}*/
96+
97+
#ifdef __cplusplus
98+
}
99+
#endif
100+
101+
#endif
102+
103+
/**@}*/

TESTS/mbed_hal/us_ticker_api_tests.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** \addtogroup hal_us_ticker_tests */
18+
/** @{*/
19+
20+
#ifndef US_TICKER_API_TESTS_H
21+
#define US_TICKER_API_TESTS_H
22+
23+
#include "device.h"
24+
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
31+
/** Test that the ticker has the right frequency and number of bits
32+
*
33+
*/
34+
void us_ticker_info_test(void);
35+
36+
37+
/**@}*/
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif
44+
45+
/**@}*/

hal/lp_ticker_api.h

Lines changed: 124 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,33 @@ extern "C" {
3030
#endif
3131

3232
/**
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+
*
3447
* @{
3548
*/
3649

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+
3760
typedef void (*ticker_irq_handler_type)(const ticker_data_t *const);
3861

3962
/** Set low power ticker IRQ handler
@@ -63,39 +86,135 @@ void lp_ticker_irq_handler(void);
6386

6487
/** Initialize the low power ticker
6588
*
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
66112
*/
67113
void lp_ticker_init(void);
68114

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
70122
*
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
72141
*/
73142
uint32_t lp_ticker_read(void);
74143

75144
/** Set interrupt for specified timestamp
76145
*
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
78164
*/
79165
void lp_ticker_set_interrupt(timestamp_t timestamp);
80166

81167
/** Disable low power ticker interrupt
82168
*
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
83177
*/
84178
void lp_ticker_disable_interrupt(void);
85179

86180
/** Clear the low power ticker interrupt
87181
*
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
88190
*/
89191
void lp_ticker_clear_interrupt(void);
90192

91193
/** Set pending interrupt that should be fired right away.
92194
*
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
94202
*/
95203
void lp_ticker_fire_interrupt(void);
96204

97205
/** Get frequency and counter bits of this ticker.
98206
*
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
99218
*/
100219
const ticker_info_t* lp_ticker_get_info(void);
101220

0 commit comments

Comments
 (0)