13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- #include <stdio.h>
16
+ #include <stdio.h>
17
17
#include <stddef.h>
18
18
#include "hal/ticker_api.h"
19
19
#include "platform/mbed_critical.h"
@@ -26,7 +26,8 @@ static void update_current_timestamp(const ticker_data_t *const ticker);
26
26
/*
27
27
* Initialize a ticker instance.
28
28
*/
29
- static void initialize (const ticker_data_t * ticker ) {
29
+ static void initialize (const ticker_data_t * ticker )
30
+ {
30
31
// return if the queue has already been initialized, in that case the
31
32
// interface used by the queue is already initialized.
32
33
if (ticker -> queue -> initialized ) {
@@ -47,7 +48,8 @@ static void initialize(const ticker_data_t *ticker) {
47
48
/**
48
49
* Set the event handler function of a ticker instance.
49
50
*/
50
- static void set_handler (const ticker_data_t * const ticker , ticker_event_handler handler ) {
51
+ static void set_handler (const ticker_data_t * const ticker , ticker_event_handler handler )
52
+ {
51
53
ticker -> queue -> event_handler = handler ;
52
54
}
53
55
@@ -63,7 +65,8 @@ static void set_handler(const ticker_data_t *const ticker, ticker_event_handler
63
65
* @param ref: The timestamp of reference.
64
66
* @param relative_timestamp: The timestamp to convert.
65
67
*/
66
- static us_timestamp_t convert_relative_timestamp (us_timestamp_t ref , timestamp_t relative_timestamp ) {
68
+ static us_timestamp_t convert_relative_timestamp (us_timestamp_t ref , timestamp_t relative_timestamp )
69
+ {
67
70
bool overflow = relative_timestamp < ((timestamp_t ) ref ) ? true : false;
68
71
69
72
us_timestamp_t result = (ref & ~((us_timestamp_t )UINT32_MAX )) | relative_timestamp ;
@@ -77,7 +80,8 @@ static us_timestamp_t convert_relative_timestamp(us_timestamp_t ref, timestamp_t
77
80
/**
78
81
* update the current timestamp value of a ticker.
79
82
*/
80
- static void update_current_timestamp (const ticker_data_t * const ticker ) {
83
+ static void update_current_timestamp (const ticker_data_t * const ticker )
84
+ {
81
85
ticker -> queue -> timestamp = convert_relative_timestamp (
82
86
ticker -> queue -> timestamp ,
83
87
ticker -> interface -> read ()
@@ -91,7 +95,8 @@ static void update_current_timestamp(const ticker_data_t *const ticker) {
91
95
* interrupt will be set to MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA us from now.
92
96
* Otherwise the interrupt will be set to head->timestamp - queue->timestamp us.
93
97
*/
94
- static void update_interrupt (const ticker_data_t * const ticker ) {
98
+ static void update_interrupt (const ticker_data_t * const ticker )
99
+ {
95
100
update_current_timestamp (ticker );
96
101
uint32_t diff = MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA ;
97
102
@@ -107,12 +112,14 @@ static void update_interrupt(const ticker_data_t *const ticker) {
107
112
);
108
113
}
109
114
110
- void ticker_set_handler (const ticker_data_t * const ticker , ticker_event_handler handler ) {
115
+ void ticker_set_handler (const ticker_data_t * const ticker , ticker_event_handler handler )
116
+ {
111
117
initialize (ticker );
112
118
set_handler (ticker , handler );
113
119
}
114
120
115
- void ticker_irq_handler (const ticker_data_t * const ticker ) {
121
+ void ticker_irq_handler (const ticker_data_t * const ticker )
122
+ {
116
123
ticker -> interface -> clear_interrupt ();
117
124
118
125
/* Go through all the pending TimerEvents */
@@ -142,7 +149,8 @@ void ticker_irq_handler(const ticker_data_t *const ticker) {
142
149
update_interrupt (ticker );
143
150
}
144
151
145
- void ticker_insert_event (const ticker_data_t * const ticker , ticker_event_t * obj , timestamp_t timestamp , uint32_t id ) {
152
+ void ticker_insert_event (const ticker_data_t * const ticker , ticker_event_t * obj , timestamp_t timestamp , uint32_t id )
153
+ {
146
154
/* disable interrupts for the duration of the function */
147
155
core_util_critical_section_enter ();
148
156
@@ -161,7 +169,8 @@ void ticker_insert_event(const ticker_data_t *const ticker, ticker_event_t *obj,
161
169
);
162
170
}
163
171
164
- void ticker_insert_event_us (const ticker_data_t * const ticker , ticker_event_t * obj , us_timestamp_t timestamp , uint32_t id ) {
172
+ void ticker_insert_event_us (const ticker_data_t * const ticker , ticker_event_t * obj , us_timestamp_t timestamp , uint32_t id )
173
+ {
165
174
/* disable interrupts for the duration of the function */
166
175
core_util_critical_section_enter ();
167
176
@@ -207,7 +216,8 @@ void ticker_insert_event_us(const ticker_data_t *const ticker, ticker_event_t *o
207
216
core_util_critical_section_exit ();
208
217
}
209
218
210
- void ticker_remove_event (const ticker_data_t * const ticker , ticker_event_t * obj ) {
219
+ void ticker_remove_event (const ticker_data_t * const ticker , ticker_event_t * obj )
220
+ {
211
221
core_util_critical_section_enter ();
212
222
213
223
// remove this object from the list
@@ -230,11 +240,13 @@ void ticker_remove_event(const ticker_data_t *const ticker, ticker_event_t *obj)
230
240
core_util_critical_section_exit ();
231
241
}
232
242
233
- timestamp_t ticker_read (const ticker_data_t * const ticker ) {
243
+ timestamp_t ticker_read (const ticker_data_t * const ticker )
244
+ {
234
245
return ticker_read_us (ticker );
235
246
}
236
247
237
- us_timestamp_t ticker_read_us (const ticker_data_t * const ticker ) {
248
+ us_timestamp_t ticker_read_us (const ticker_data_t * const ticker )
249
+ {
238
250
update_current_timestamp (ticker );
239
251
return ticker -> queue -> timestamp ;
240
252
}
0 commit comments