Skip to content

Commit

Permalink
Prevent timer underflow caused by very short wait periods
Browse files Browse the repository at this point in the history
  - Introduce minimum timer period
  (from Joe)
  • Loading branch information
mmoskal committed Feb 1, 2020
1 parent a505046 commit 7e459b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 9 additions & 0 deletions inc/core/CodalConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ DEALINGS IN THE SOFTWARE.
#define CODAL_TIMESTAMP uint32_t
#endif

//
// Defines the default minimum period (in uS) a hardware timer can measure without
// risk of a race condition. Can be overridden in a target config.json.
//
#ifndef CODAL_TIMER_MINIMUM_PERIOD
#define CODAL_TIMER_MINIMUM_PERIOD 10
#endif


//
// Fiber scheduler configuration
//
Expand Down
5 changes: 1 addition & 4 deletions source/driver-models/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ void Timer::trigger(bool isFallback)
if (nextTimerEvent) {
// this may possibly happen if a new timer event was added to the queue while
// we were running - it might be already in the past
if (currentTimeUs < nextTimerEvent->timestamp)
triggerIn(nextTimerEvent->timestamp - currentTimeUs);
else
triggerIn(1);
triggerIn(max(nextTimerEvent->timestamp - currentTimeUs, CODAL_TIMER_MINIMUM_PERIOD));
}
}

Expand Down

0 comments on commit 7e459b8

Please sign in to comment.