Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beken-72xx] Fix deep_sleep time parameter overflow #232

Closed
wants to merge 1 commit into from

Conversation

daniel-dona
Copy link

Fix for #230

@kuba2k2 kuba2k2 changed the title Fix math for deep_sleep time param [beken-72xx] Fix deep_sleep time parameter overflow Jan 3, 2024
@@ -21,12 +21,12 @@ void lt_deep_sleep_unset_gpio(uint32_t gpio_index_map) {

void lt_deep_sleep_config_timer(uint32_t sleep_duration) {
deep_sleep_param.wake_up_way |= PS_DEEP_WAKEUP_RTC;
uint64_t duration_math = 32768 * sleep_duration;
if (duration_math / 1000 > 0xFFFFFFFF) {
uint32_t duration_math = (32768 * ((float) sleep_duration)/1000.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unnecessary casting, could you try 32.768 * sleep_duration? This way the division is avoided, and casting is implicit because the first operand is a float.

uint64_t duration_math = 32768 * sleep_duration;
if (duration_math / 1000 > 0xFFFFFFFF) {
uint32_t duration_math = (32768 * ((float) sleep_duration)/1000.0);
if (duration_math > 0xFFFFFFFF) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can never be larger than 0xFFFFFFFF now. Is that even needed?

@kuba2k2 kuba2k2 added bug Something isn't working BK7231 Beken BK72xx family labels Jan 3, 2024
cap9qd added a commit to cap9qd/libretiny that referenced this pull request Feb 1, 2024
cap9qd added a commit to cap9qd/libretiny that referenced this pull request Feb 21, 2024
cap9qd added a commit to cap9qd/libretiny that referenced this pull request Feb 21, 2024
cap9qd added a commit to cap9qd/libretiny that referenced this pull request Feb 21, 2024
cap9qd added a commit to cap9qd/libretiny that referenced this pull request Feb 21, 2024
cap9qd added a commit to cap9qd/libretiny that referenced this pull request Feb 21, 2024
@Cossid
Copy link
Collaborator

Cossid commented Mar 5, 2024

This can probably be closed as duplicate of the now-completed #253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BK7231 Beken BK72xx family bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants