Skip to content

Commit

Permalink
Fix rollover in sleep functions
Browse files Browse the repository at this point in the history
per #232
  • Loading branch information
cap9qd committed Feb 21, 2024
1 parent 4cddc01 commit 67ea94f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cores/beken-72xx/base/api/lt_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ void lt_deep_sleep_unset_gpio(uint32_t gpio_index_map) {
deep_sleep_param.gpio_index_map &= (~gpio_index_map);
}

void lt_deep_sleep_config_timer(uint32_t sleep_duration) {
void lt_deep_sleep_config_timer(uint32_t sleep_duration_ms) {
deep_sleep_param.wake_up_way |= PS_DEEP_WAKEUP_RTC;
uint64_t duration_math = 32768 * sleep_duration;
if (duration_math / 1000 > 0xFFFFFFFF) {
// Sleep forever
deep_sleep_param.sleep_time = 0xFFFFFFFF;
uint64_t sleep_ticks = 32.768 * sleep_duration_ms;
if (sleep_ticks > 0xFFFFFFFF) {
deep_sleep_param.sleep_time = 0xFFFFFFFE;
} else {
deep_sleep_param.sleep_time = (duration_math / 1000) & 0xFFFFFFFF;
deep_sleep_param.sleep_time = sleep_ticks & 0xFFFFFFFF;
}
}

Expand Down

0 comments on commit 67ea94f

Please sign in to comment.