embos: fix for_at_least contract to add one tick

Fixes the embOS backends for pw::sync::Mutex,
pw::sync::BinarySemaphore, pw::sync::CountingSemaphore, and
pw::this_thread::sleep_for to add one tick when invoking the native
API to comply with the for_at_least contract as we do not know how
far we are into the current tick.

Note this is not observable without the use of an independent clock.

This also adds explicit downcasting from int64_t to OS_TIME ticks
when invoking native APIs.

Change-Id: I113cbdfc1a88795df87223117e65a763ae050772
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/37280
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
8 files changed
tree: fa21015b578d974d3f6838e061391f4eda838526
  1. build_overrides/
  2. docker/
  3. docs/
  4. pw_allocator/
  5. pw_arduino_build/
  6. pw_assert/
  7. pw_assert_basic/
  8. pw_assert_log/
  9. pw_base64/
  10. pw_bloat/
  11. pw_blob_store/
  12. pw_boot_armv7m/
  13. pw_build/
  14. pw_bytes/
  15. pw_checksum/
  16. pw_chrono/
  17. pw_chrono_embos/
  18. pw_chrono_freertos/
  19. pw_chrono_stl/
  20. pw_chrono_threadx/
  21. pw_cli/
  22. pw_containers/
  23. pw_cpu_exception/
  24. pw_cpu_exception_cortex_m/
  25. pw_docgen/
  26. pw_doctor/
  27. pw_env_setup/
  28. pw_fuzzer/
  29. pw_hdlc/
  30. pw_hex_dump/
  31. pw_i2c/
  32. pw_interrupt/
  33. pw_interrupt_cortex_m/
  34. pw_kvs/
  35. pw_log/
  36. pw_log_basic/
  37. pw_log_multisink/
  38. pw_log_null/
  39. pw_log_rpc/
  40. pw_log_sink/
  41. pw_log_tokenized/
  42. pw_malloc/
  43. pw_malloc_freelist/
  44. pw_metric/
  45. pw_minimal_cpp_stdlib/
  46. pw_module/
  47. pw_package/
  48. pw_polyfill/
  49. pw_preprocessor/
  50. pw_presubmit/
  51. pw_protobuf/
  52. pw_protobuf_compiler/
  53. pw_random/
  54. pw_result/
  55. pw_ring_buffer/
  56. pw_router/
  57. pw_rpc/
  58. pw_span/
  59. pw_status/
  60. pw_stream/
  61. pw_string/
  62. pw_sync/
  63. pw_sync_baremetal/
  64. pw_sync_embos/
  65. pw_sync_freertos/
  66. pw_sync_stl/
  67. pw_sync_threadx/
  68. pw_sys_io/
  69. pw_sys_io_arduino/
  70. pw_sys_io_baremetal_lm3s6965evb/
  71. pw_sys_io_baremetal_stm32f429/
  72. pw_sys_io_stdio/
  73. pw_target_runner/
  74. pw_thread/
  75. pw_thread_embos/
  76. pw_thread_freertos/
  77. pw_thread_stl/
  78. pw_thread_threadx/
  79. pw_tokenizer/
  80. pw_tool/
  81. pw_toolchain/
  82. pw_trace/
  83. pw_trace_tokenized/
  84. pw_unit_test/
  85. pw_varint/
  86. pw_watch/
  87. pw_web_ui/
  88. targets/
  89. third_party/
  90. .bazelignore
  91. .bazelrc
  92. .clang-format
  93. .eslintrc.json
  94. .gitattributes
  95. .gitignore
  96. .gn
  97. .prettierrc.js
  98. .pylintrc
  99. activate.bat
  100. AUTHORS
  101. bootstrap.bat
  102. bootstrap.sh
  103. BUILD
  104. BUILD.gn
  106. CMakeLists.txt
  109. LICENSE
  110. modules.gni
  111. OWNERS
  112. package.json
  114. README.md
  115. tsconfig.json
  117. yarn.lock


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.

Pigweed is in the early stages of development, and should be considered experimental. We’re continuing to evolve the platform and add new modules. We value developer feedback along the way.

Quick links

Get the code: git clone https://pigweed.googlesource.com/pigweed/pigweed

Getting Started

If you'd like to get set up with Pigweed, please visit the getting started guide.

What does Pigweed offer?

There are many modules in Pigweed, and this section only showcases a small selection that happen to produce visual output. For more information about the different Pigweed module offerings, refer to “Module Guides” section in the full documentation.

pw_watch - Build, flash, run, & test on save

In the web development space, file system watchers are prevalent. These watchers trigger a web server reload on source change, making development much faster. In the embedded space, file system watchers are less prevalent; however, they are no less useful! The Pigweed watcher module makes it easy to instantly compile, flash, and run tests upon save. Combined with the GN-based build which expresses the full dependency tree, only the exact tests affected by a file change are run on saves.

The demo below shows pw_watch building for a STMicroelectronics STM32F429I-DISC1 development board, flashing the board with the affected test, and verifying the test runs as expected. Once this is set up, you can attach multiple devices to run tests in a distributed manner to reduce the time it takes to run tests.

pw watch running on-device tests

pw_presubmit - Vacuum code lint on every commit

Presubmit checks are essential tools, but they take work to set up, and projects don’t always get around to it. The pw_presubmit module provides tools for setting up high quality presubmit checks for any project. We use this framework to run Pigweed’s presubmit on our workstations and in our automated building tools.

The pw_presubmit module includes pw format command, a tool that provides a unified interface for automatically formatting code in a variety of languages. With pw format, you can format C, C++, Python, GN, and Go code according to configurations defined by your project. pw format leverages existing tools like clang-format, and it’s simple to add support for new languages.

pw presubmit demo

pw_env_setup - Cross platform embedded compiler setup

A classic problem in the embedded space is reducing the time from git clone to having a binary executing on a device. The issue is that an entire suite of tools is needed for non-trivial production embedded projects. For example:

  • A C++ compiler for your target device, and also for your host
  • A build system or three; for example, GN, Ninja, CMake, Bazel
  • A code formatting program like clang-format
  • A debugger like OpenOCD to flash and debug your embedded device
  • A known Python version with known modules installed for scripting
  • A Go compiler for the Go-based command line tools
  • ... and so on

In the server space, container solutions like Docker or Podman solve this; however, in our experience container solutions are a mixed bag for embedded systems development where one frequently needs access to native system resources like USB devices, or must operate on Windows.

pw_env_setup is our compromise solution for this problem that works on Mac, Windows, and Linux. It leverages the Chrome packaging system CIPD to bootstrap a Python installation, which in turn inflates a virtual environment. The tooling is installed into your workspace, and makes no changes to your system. This tooling is designed to be reused by any project.