Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/mbed/common/us_ticker_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
}
Expand Down Expand Up @@ -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)
Expand Down