pw_chrono_zephyr: Resolve multiple issues SystemTimerZephyr

Adds a new system_timer_test.cc file, which runs fine on the native
simulator target. The test adds basic coverage for the functionality of
the system_timer.cc file, and also covers some specific edge cases where
bugs here found and fixed.

- When 64 bit timeouts were configured, the implementation computed a
  `time_until_deadline` that was a negative value, and was not clamped,
  causing a wait forever.
- With 64 bit timeouts, kMaxTimeout effectively was -2, and
  that value passed as a timeout would either result in an error or no
  wait.
- Using K_TICK_MAX in deriving kMaxTimeout proved to be problematic with
  64 bit timeouts on Zephyr, as it turned out there was an overflow in
  the kernel leading to effectively K_NO_WAIT. The max needed a small
  adjustment.
- If InvokeAt() or InvokeAfter() was called a second time to reschedule
  the wake-up, the k_work_schedule() function did not do anything as the
  wake-up was already scheduled. The fix was to call k_work_reschedule()
  instead, as this both schedules a new wake-up, or reschedules it if
  already scheduled.
- If 32 bit timeouts are used, the compiler complained about a downcast
  from a long (chrono duration) to an int for the call into the Zephyr
  API. A static cast is added to eliminate the warning.

Bug: b:512561694
Bug: b:512561066
Test: "./pw build pw_smoke_tests" (under zephyr-bazel)
Change-Id: Idba728d56e1ca0f01d69c326ca5a4044252acd7d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/418432
6 files changed
tree: 535edf318008bb10098395fe5853506db8ea404f
  1. .agents/
  2. .allstar/
  3. .gemini/
  4. .github/
  5. .vscode/
  6. build_overrides/
  7. docker/
  8. docs/
  9. kudzu/
  10. pw_alignment/
  11. pw_allocator/
  12. pw_allocator_zephyr/
  13. pw_analog/
  14. pw_android_toolchain/
  15. pw_arduino_build/
  16. pw_assert/
  17. pw_assert_basic/
  18. pw_assert_fuchsia/
  19. pw_assert_log/
  20. pw_assert_tokenized/
  21. pw_assert_trap/
  22. pw_assert_zephyr/
  23. pw_async/
  24. pw_async2/
  25. pw_async_basic/
  26. pw_async_fuchsia/
  27. pw_atomic/
  28. pw_base64/
  29. pw_bloat/
  30. pw_blob_store/
  31. pw_bluetooth/
  32. pw_bluetooth_hci/
  33. pw_bluetooth_profiles/
  34. pw_bluetooth_proxy/
  35. pw_bluetooth_sapphire/
  36. pw_boot/
  37. pw_boot_cortex_m/
  38. pw_build/
  39. pw_build_android/
  40. pw_build_info/
  41. pw_build_mcuxpresso/
  42. pw_bytes/
  43. pw_change/
  44. pw_channel/
  45. pw_checksum/
  46. pw_chre/
  47. pw_chrono/
  48. pw_chrono_embos/
  49. pw_chrono_freertos/
  50. pw_chrono_rp2040/
  51. pw_chrono_stl/
  52. pw_chrono_threadx/
  53. pw_chrono_zephyr/
  54. pw_cli/
  55. pw_cli_analytics/
  56. pw_clock_tree/
  57. pw_clock_tree_mcuxpresso/
  58. pw_compilation_testing/
  59. pw_config_loader/
  60. pw_console/
  61. pw_containers/
  62. pw_cpu_exception/
  63. pw_cpu_exception_cortex_m/
  64. pw_cpu_exception_risc_v/
  65. pw_crypto/
  66. pw_digital_io/
  67. pw_digital_io_linux/
  68. pw_digital_io_mcuxpresso/
  69. pw_digital_io_rp2040/
  70. pw_digital_io_zephyr/
  71. pw_display/
  72. pw_dma_mcuxpresso/
  73. pw_docgen/
  74. pw_doctor/
  75. pw_elf/
  76. pw_emu/
  77. pw_enum/
  78. pw_env_setup/
  79. pw_env_setup_zephyr/
  80. pw_file/
  81. pw_flatbuffers/
  82. pw_format/
  83. pw_function/
  84. pw_fuzzer/
  85. pw_grpc/
  86. pw_hdlc/
  87. pw_hex_dump/
  88. pw_i2c/
  89. pw_i2c_linux/
  90. pw_i2c_mcuxpresso/
  91. pw_i2c_rp2040/
  92. pw_i2c_zephyr/
  93. pw_ide/
  94. pw_interrupt/
  95. pw_interrupt_cortex_m/
  96. pw_interrupt_freertos/
  97. pw_interrupt_zephyr/
  98. pw_intrusive_ptr/
  99. pw_json/
  100. pw_kernel/
  101. pw_kvs/
  102. pw_libc/
  103. pw_libcxx/
  104. pw_log/
  105. pw_log_android/
  106. pw_log_basic/
  107. pw_log_fuchsia/
  108. pw_log_null/
  109. pw_log_rpc/
  110. pw_log_string/
  111. pw_log_tokenized/
  112. pw_log_zephyr/
  113. pw_malloc/
  114. pw_malloc_freelist/
  115. pw_malloc_freertos/
  116. pw_memory/
  117. pw_metric/
  118. pw_module/
  119. pw_multibuf/
  120. pw_multisink/
  121. pw_numeric/
  122. pw_package/
  123. pw_perf_test/
  124. pw_persistent_ram/
  125. pw_polyfill/
  126. pw_preprocessor/
  127. pw_presubmit/
  128. pw_protobuf/
  129. pw_protobuf_compiler/
  130. pw_random/
  131. pw_random_fuchsia/
  132. pw_result/
  133. pw_ring_buffer/
  134. pw_router/
  135. pw_rpc/
  136. pw_rpc_transport/
  137. pw_rust/
  138. pw_sensor/
  139. pw_snapshot/
  140. pw_software_update/
  141. pw_span/
  142. pw_spi/
  143. pw_spi_linux/
  144. pw_spi_mcuxpresso/
  145. pw_spi_rp2040/
  146. pw_spi_zephyr/
  147. pw_status/
  148. pw_stm32cube_build/
  149. pw_stream/
  150. pw_stream_uart_linux/
  151. pw_stream_uart_mcuxpresso/
  152. pw_string/
  153. pw_symbolizer/
  154. pw_sync/
  155. pw_sync_baremetal/
  156. pw_sync_embos/
  157. pw_sync_freertos/
  158. pw_sync_stl/
  159. pw_sync_threadx/
  160. pw_sync_zephyr/
  161. pw_sys_io/
  162. pw_sys_io_ambiq_sdk/
  163. pw_sys_io_arduino/
  164. pw_sys_io_baremetal_lm3s6965evb/
  165. pw_sys_io_baremetal_stm32f429/
  166. pw_sys_io_emcraft_sf2/
  167. pw_sys_io_mcuxpresso/
  168. pw_sys_io_rp2040/
  169. pw_sys_io_stdio/
  170. pw_sys_io_stm32cube/
  171. pw_sys_io_zephyr/
  172. pw_system/
  173. pw_target_runner/
  174. pw_thread/
  175. pw_thread_embos/
  176. pw_thread_freertos/
  177. pw_thread_stl/
  178. pw_thread_threadx/
  179. pw_thread_zephyr/
  180. pw_time/
  181. pw_tls_client/
  182. pw_tls_client_boringssl/
  183. pw_tls_client_mbedtls/
  184. pw_tokenizer/
  185. pw_toolchain/
  186. pw_trace/
  187. pw_trace_tokenized/
  188. pw_transfer/
  189. pw_uart/
  190. pw_uart_mcuxpresso/
  191. pw_unit_test/
  192. pw_uuid/
  193. pw_varint/
  194. pw_watch/
  195. pw_web/
  196. pw_work_queue/
  197. seed/
  198. targets/
  199. third_party/
  200. zephyr/
  201. .bazelignore
  202. .bazelrc
  203. .bazelversion
  204. .black.toml
  205. .clang-format
  206. .clang-tidy
  207. .git-blame-ignore-revs
  208. .gitattributes
  209. .gitignore
  210. .gn
  211. .mypy.ini
  212. .prettierignore
  213. .prettierrc.cjs
  214. .pw_ide.yaml
  215. .pylintrc
  216. .ruff.toml
  217. activate.bat
  218. Android.bp
  219. AUTHORS
  220. bootstrap.bat
  221. bootstrap.fish
  222. bootstrap.sh
  223. BUILD.bazel
  224. BUILD.gn
  225. BUILDCONFIG.gn
  226. CMakeLists.txt
  227. EXTENDED_OWNERS
  228. GEMINI.md
  229. go.mod
  230. go.sum
  231. Kconfig.zephyr
  232. LICENSE
  233. MODULE.bazel
  234. MODULE.bazel.lock
  235. modules.gni
  236. OWNERS
  237. package.json
  238. pigweed.json
  239. PIGWEED_MODULES
  240. pw
  241. README.md
  242. REPO.bazel
  243. rustfmt.toml
  244. tsconfig.json
  245. workflows.json
  246. WORKSPACE_OWNERS
README.md

Pigweed

Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.

For more information please see our website: https://pigweed.dev/.

Links