Skip to content

Commit

Permalink
samples: bluetooth: Fix iso time sync sample timestamp u32 overflow
Browse files Browse the repository at this point in the history
We didn't handle the corner case where the new timestamp
was above the uint32_t overflow and the current timestamp was below.

Signed-off-by: Rubin Gerritsen <[email protected]>
  • Loading branch information
rugeGerritsen authored and rlubos committed Jul 17, 2024
1 parent 156e1c1 commit 18dc97d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion samples/bluetooth/iso_time_sync/src/timed_led_toggle.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ void timed_led_toggle_trigger_at(uint8_t value, uint32_t timestamp_us)
const uint64_t current_time_us = controller_time_us_get();
const uint64_t current_time_most_significant_word = current_time_us & 0xFFFFFFFF00000000UL;

const uint64_t full_timestamp_us = current_time_most_significant_word | timestamp_us;
uint64_t full_timestamp_us = current_time_most_significant_word | timestamp_us;

if (timestamp_us < (current_time_us & UINT32_MAX)) {
/* Trigger time is after UINT32 wrap */
full_timestamp_us += 0x100000000UL;
}

controller_time_trigger_set(full_timestamp_us);

Expand Down

0 comments on commit 18dc97d

Please sign in to comment.