fix for the case where there are multiple tickers firing at nearly the same time

pull/583/head
Rohit Grover 2014-10-20 09:49:22 +01:00
parent 53ec8ba932
commit de35d0c84e
2 changed files with 13 additions and 11 deletions

View File

@ -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 */

View File

@ -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)