@@ -42,7 +42,7 @@ uint32_t us_ticker_read()
42
42
43
43
timestamp_t value ;
44
44
app_timer_cnt_get (& value ); /* This returns the RTC counter (which is fed by the 32khz crystal clock source) */
45
- return (uint32_t )(( value * 1000000 ) / APP_TIMER_CLOCK_FREQ ); /* Return a pseudo microsecond counter value.
45
+ return (( value * 1000000 ) / ( uint32_t ) APP_TIMER_CLOCK_FREQ ); /* Return a pseudo microsecond counter value.
46
46
* This is only as precise as the 32khz low-freq
47
47
* clock source, but could be adequate.*/
48
48
}
@@ -78,15 +78,17 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
78
78
uint32_t targetCounter = ((uint32_t )((timestamp * (uint64_t )APP_TIMER_CLOCK_FREQ ) / 1000000 ) + 1 ) & MAX_RTC_COUNTER_VAL ;
79
79
uint32_t ticksToCount = (targetCounter >= currentCounter ) ?
80
80
(targetCounter - currentCounter ) : (MAX_RTC_COUNTER_VAL + 1 ) - (currentCounter - targetCounter );
81
- if (ticksToCount > 0 ) {
82
- uint32_t rc ;
83
- rc = app_timer_start (us_ticker_appTimerID , ticksToCount , NULL /*p_context*/ );
84
- if (rc != NRF_SUCCESS ) {
85
- /* placeholder to do something to recover from error */
86
- return ;
87
- }
88
- us_ticker_appTimerRunning = true;
81
+ if (ticksToCount < APP_TIMER_MIN_TIMEOUT_TICKS ) { /* Honour the minimum value of the timeout_ticks parameter of app_timer_start() */
82
+ ticksToCount = APP_TIMER_MIN_TIMEOUT_TICKS ;
83
+ }
84
+
85
+ uint32_t rc ;
86
+ rc = app_timer_start (us_ticker_appTimerID , ticksToCount , NULL /*p_context*/ );
87
+ if (rc != NRF_SUCCESS ) {
88
+ /* placeholder to do something to recover from error */
89
+ return ;
89
90
}
91
+ us_ticker_appTimerRunning = true;
90
92
}
91
93
92
94
void us_ticker_disable_interrupt (void )
0 commit comments