Skip to content

Commit 7710084

Browse files
mark9064JF002
authored andcommitted
Replace rounded div macro
1 parent f032847 commit 7710084

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/displayapp/DisplayApp.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ void DisplayApp::InitHw() {
159159
TickType_t DisplayApp::CalculateSleepTime() {
160160
TickType_t ticksElapsed = xTaskGetTickCount() - alwaysOnStartTime;
161161
// Divide both the numerator and denominator by 8 to increase the number of ticks (frames) before the overflow tick is reached
162-
TickType_t elapsedTarget = ROUNDED_DIV((configTICK_RATE_HZ / 8) * alwaysOnTickCount * alwaysOnRefreshPeriod, 1000 / 8);
163-
// ROUNDED_DIV overflows when numerator + (denominator floordiv 2) > uint32 max
162+
auto RoundedDiv = [](uint32_t a, uint32_t b) {
163+
return ((a + (b / 2)) / b);
164+
};
165+
TickType_t elapsedTarget = RoundedDiv((configTICK_RATE_HZ / 8) * alwaysOnTickCount * alwaysOnRefreshPeriod, 1000 / 8);
166+
// RoundedDiv overflows when numerator + (denominator floordiv 2) > uint32 max
164167
// in this case around 9 hours
165168
constexpr TickType_t overflowTick = (UINT32_MAX - (1000 / 16)) / ((configTICK_RATE_HZ / 8) * alwaysOnRefreshPeriod);
166169

0 commit comments

Comments
 (0)