@@ -165,9 +165,9 @@ static void update_present_time(const ticker_data_t *const ticker)
165
165
}
166
166
167
167
/**
168
- * Given the absolute timestamp compute the hal tick timestamp.
168
+ * Given the absolute timestamp compute the hal tick timestamp rounded up .
169
169
*/
170
- static timestamp_t compute_tick (const ticker_data_t * const ticker , us_timestamp_t timestamp )
170
+ static timestamp_t compute_tick_round_up (const ticker_data_t * const ticker , us_timestamp_t timestamp )
171
171
{
172
172
ticker_event_queue_t * queue = ticker -> queue ;
173
173
us_timestamp_t delta_us = timestamp - queue -> present_time ;
@@ -186,14 +186,14 @@ static timestamp_t compute_tick(const ticker_data_t *const ticker, us_timestamp_
186
186
} else if (0 != queue -> frequency_shifts ) {
187
187
// Optimized frequencies divisible by 2
188
188
189
- delta = (delta_us << ticker -> queue -> frequency_shifts ) / 1000000 ;
189
+ delta = (( delta_us << ticker -> queue -> frequency_shifts ) + 1000000 - 1 ) / 1000000 ;
190
190
if (delta > ticker -> queue -> max_delta ) {
191
191
delta = ticker -> queue -> max_delta ;
192
192
}
193
193
} else {
194
194
// General case
195
195
196
- delta = delta_us * queue -> frequency / 1000000 ;
196
+ delta = ( delta_us * queue -> frequency + 1000000 - 1 ) / 1000000 ;
197
197
if (delta > ticker -> queue -> max_delta ) {
198
198
delta = ticker -> queue -> max_delta ;
199
199
}
@@ -249,14 +249,11 @@ static void schedule_interrupt(const ticker_data_t *const ticker)
249
249
return ;
250
250
}
251
251
252
- timestamp_t match_tick = compute_tick (ticker , match_time );
253
- // The time has been checked to be future, but it could still round
254
- // to the last tick as a result of us to ticks conversion
255
- if (match_tick == queue -> tick_last_read ) {
256
- // Match time has already expired so fire immediately
257
- ticker -> interface -> fire_interrupt ();
258
- return ;
259
- }
252
+ timestamp_t match_tick = compute_tick_round_up (ticker , match_time );
253
+
254
+ // The same tick should never occur since match_tick is rounded up.
255
+ // If the same tick is returned scheduling will not work correctly.
256
+ MBED_ASSERT (match_tick != queue -> tick_last_read );
260
257
261
258
ticker -> interface -> set_interrupt (match_tick );
262
259
timestamp_t cur_tick = ticker -> interface -> read ();
0 commit comments