Skip to content

Commit

Permalink
Fix calculating system ticks in Ticker when sleep #bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceAngel committed Sep 25, 2022
1 parent 3d87339 commit 07e230c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Core/SystemTicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "config.h"


#include "Core/Hardware/RTC.h"

SystemTicker* SystemTicker::inst;
Expand All @@ -16,20 +15,27 @@ SystemTicker *SystemTicker::getInstance() {
}

void SystemTicker::tickWakedUp() {
if (this->ticks == USHRT_MAX) {
if (this->ticks > this->maxTicks) {
this->ticks = 0;
}
RTC::getInstance()->getCurrentDate();
this->ticks++;
}

void SystemTicker::tickSleep() {
this->ticks += (uint8_t)((SLEEPCYCLE_MS / 1000) * TICK_WAKEUP);
if (this->ticks == USHRT_MAX) {
this->ticks += (uint8_t)((SLEEPCYCLE_MS * CPU_FREQUENCY_LOW) / 1000);
if (this->ticks > this->maxTicks) {
this->ticks = 0;
}
}

bool SystemTicker::isTickFor(uint16_t tickCount) {
this->setMaxTicks(tickCount);
return (this->ticks % tickCount) == 0;
}

void SystemTicker::setMaxTicks(uint16_t maxTicks) {
if (this->maxTicks < maxTicks) {
this->maxTicks = maxTicks;
}
}
4 changes: 4 additions & 0 deletions src/Core/SystemTicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class SystemTicker {

uint16_t ticks = 0;

uint16_t maxTicks = 0;

void setMaxTicks(uint16_t maxTicks);

SystemTicker() {

}
Expand Down

0 comments on commit 07e230c

Please sign in to comment.