mirror of https://github.com/ARMmbed/mbed-os.git
fix for the case where there are multiple tickers firing at nearly the same time
parent
53ec8ba932
commit
de35d0c84e
|
@ -37,7 +37,7 @@ void us_ticker_irq_handler(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ((int)(head->timestamp - us_ticker_read()) <= 0) {
|
||||
if ((int64_t)(head->timestamp - us_ticker_read()) <= 0) {
|
||||
// This event was in the past:
|
||||
// point to the following one and execute its handler
|
||||
ticker_event_t *p = head;
|
||||
|
@ -70,7 +70,7 @@ void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t
|
|||
ticker_event_t *prev = NULL, *p = head;
|
||||
while (p != NULL) {
|
||||
/* check if we come before p */
|
||||
if ((int)(timestamp - p->timestamp) <= 0) {
|
||||
if ((int64_t)(timestamp - p->timestamp) < 0) {
|
||||
break;
|
||||
}
|
||||
/* go to the next element */
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t us_ticker_read()
|
|||
|
||||
timestamp_t value;
|
||||
app_timer_cnt_get(&value); /* This returns the RTC counter (which is fed by the 32khz crystal clock source) */
|
||||
return (uint32_t)((value * 1000000) / APP_TIMER_CLOCK_FREQ); /* Return a pseudo microsecond counter value.
|
||||
return ((value * 1000000) / (uint32_t)APP_TIMER_CLOCK_FREQ); /* Return a pseudo microsecond counter value.
|
||||
* This is only as precise as the 32khz low-freq
|
||||
* clock source, but could be adequate.*/
|
||||
}
|
||||
|
@ -78,15 +78,17 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
|||
uint32_t targetCounter = ((uint32_t)((timestamp * (uint64_t)APP_TIMER_CLOCK_FREQ) / 1000000) + 1) & MAX_RTC_COUNTER_VAL;
|
||||
uint32_t ticksToCount = (targetCounter >= currentCounter) ?
|
||||
(targetCounter - currentCounter) : (MAX_RTC_COUNTER_VAL + 1) - (currentCounter - targetCounter);
|
||||
if (ticksToCount > 0) {
|
||||
uint32_t rc;
|
||||
rc = app_timer_start(us_ticker_appTimerID, ticksToCount, NULL /*p_context*/);
|
||||
if (rc != NRF_SUCCESS) {
|
||||
/* placeholder to do something to recover from error */
|
||||
return;
|
||||
}
|
||||
us_ticker_appTimerRunning = true;
|
||||
if (ticksToCount < APP_TIMER_MIN_TIMEOUT_TICKS) { /* Honour the minimum value of the timeout_ticks parameter of app_timer_start() */
|
||||
ticksToCount = APP_TIMER_MIN_TIMEOUT_TICKS;
|
||||
}
|
||||
|
||||
uint32_t rc;
|
||||
rc = app_timer_start(us_ticker_appTimerID, ticksToCount, NULL /*p_context*/);
|
||||
if (rc != NRF_SUCCESS) {
|
||||
/* placeholder to do something to recover from error */
|
||||
return;
|
||||
}
|
||||
us_ticker_appTimerRunning = true;
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
|
|
Loading…
Reference in New Issue