pw_spin_delay: Have Micros() return 64-bit value.
A 32-bit value is only 71 minutes, so users would need to add
logic to detect a value wrap. 64-bit values wrap every 500K years.
All implementations already call into API functions which
return 64-bit values, or they use a 32-bit millisecond
api/counter and can cast before multiplying by 1000.
| Platform | API | Value Type |
| ---------- | --------------------- | ----------------- |
| Arduino | micros() | unsigned long |
| Host | std::chrono::duration | long long |
| MCUxpresso | msec counter | uint32_t |
| rp2040 | to_us_since_boot() | uint64_t |
| stm32cube | HAL_GetTick() | uint32_t in msec. |
Note: This function is currently unused.
Change-Id: I1cc67de17b7e3e7b2a21f6024079e1edf5b3ed05
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/experimental/+/126110
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Chris Mumford <cmumford@google.com>
diff --git a/pw_spin_delay_mcuxpresso/delay.cc b/pw_spin_delay_mcuxpresso/delay.cc
index de78ee6..f1a579a 100644
--- a/pw_spin_delay_mcuxpresso/delay.cc
+++ b/pw_spin_delay_mcuxpresso/delay.cc
@@ -29,11 +29,7 @@
bool s_initialized = false;
volatile uint32_t s_msec_count = 0;
-void UTickCallback(void) {
- // clang-format off
- s_msec_count++;
- // clang-format on
-}
+void UTickCallback(void) { s_msec_count++; }
void InitTickTimer() {
s_initialized = true;
@@ -54,11 +50,11 @@
return s_msec_count;
}
-uint32_t Micros() {
+uint64_t Micros() {
if (!s_initialized) {
InitTickTimer();
}
- return s_msec_count * 1000;
+ return static_cast<uint64_t>(s_msec_count) * 1000;
}
} // namespace pw::spin_delay