aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-10-26 22:55:27 -0600
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2021-12-17 00:09:32 +0000
commitb8f3ad2db9ad0f08970d62af3910f91ee5389e12 (patch)
tree75f9676f73cd9db2a2f01744d500d65e1a9788d8
parent6f6b6a12665eaac4854c6399e919736a9e32778c (diff)
downloadpigweed-b8f3ad2db9ad0f08970d62af3910f91ee5389e12.tar.gz
Zephyr implementation of pw_rpc and dependencies
Provide a Zephyr implementation of the pigweed modules and facades required for using pw_rpc in a Zephyr application. Change-Id: I6f148e7d85b338fcb7045460912d228f1785576c Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/67186 Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Paul Fagerburg <pfagerburg@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com> Pigweed-Auto-Submit: Yuval Peress <peress@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
-rw-r--r--CMakeLists.txt17
-rw-r--r--Kconfig.zephyr43
-rw-r--r--docs/BUILD.gn5
-rw-r--r--modules.gni5
-rw-r--r--pw_assert_zephyr/BUILD.gn21
-rw-r--r--pw_assert_zephyr/CMakeLists.txt27
-rw-r--r--pw_assert_zephyr/Kconfig17
-rw-r--r--pw_assert_zephyr/assert_zephyr.cc23
-rw-r--r--pw_assert_zephyr/docs.rst17
-rw-r--r--pw_assert_zephyr/public/pw_assert_zephyr/assert_zephyr.h48
-rw-r--r--pw_assert_zephyr/public_overrides/pw_assert_backend/assert_backend.h20
-rw-r--r--pw_build/CMakeLists.txt13
-rw-r--r--pw_bytes/CMakeLists.txt3
-rw-r--r--pw_bytes/Kconfig20
-rw-r--r--pw_bytes/docs.rst5
-rw-r--r--pw_checksum/CMakeLists.txt3
-rw-r--r--pw_checksum/Kconfig18
-rw-r--r--pw_checksum/docs.rst5
-rw-r--r--pw_chrono_zephyr/BUILD.gn21
-rw-r--r--pw_chrono_zephyr/CMakeLists.txt27
-rw-r--r--pw_chrono_zephyr/Kconfig25
-rw-r--r--pw_chrono_zephyr/docs.rst16
-rw-r--r--pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_config.h41
-rw-r--r--pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_constants.h27
-rw-r--r--pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_inline.h24
-rw-r--r--pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_inline.h26
-rw-r--r--pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_native.h39
-rw-r--r--pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_config.h19
-rw-r--r--pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_inline.h16
-rw-r--r--pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_inline.h19
-rw-r--r--pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_native.h19
-rw-r--r--pw_chrono_zephyr/system_timer.cc93
-rw-r--r--pw_containers/CMakeLists.txt3
-rw-r--r--pw_containers/Kconfig18
-rw-r--r--pw_containers/docs.rst5
-rw-r--r--pw_function/CMakeLists.txt4
-rw-r--r--pw_function/Kconfig18
-rw-r--r--pw_function/docs.rst5
-rw-r--r--pw_hdlc/CMakeLists.txt4
-rw-r--r--pw_hdlc/Kconfig26
-rw-r--r--pw_hdlc/docs.rst5
-rw-r--r--pw_interrupt/CMakeLists.txt17
-rw-r--r--pw_interrupt_zephyr/BUILD.gn21
-rw-r--r--pw_interrupt_zephyr/CMakeLists.txt27
-rw-r--r--pw_interrupt_zephyr/Kconfig16
-rw-r--r--pw_interrupt_zephyr/docs.rst11
-rw-r--r--pw_interrupt_zephyr/public/pw_interrupt_zephyr/context_inline.h22
-rw-r--r--pw_interrupt_zephyr/public_overrides/pw_interrupt_backend/context_inline.h19
-rw-r--r--pw_log_zephyr/CMakeLists.txt30
-rw-r--r--pw_log_zephyr/Kconfig28
-rw-r--r--pw_log_zephyr/docs.rst39
-rw-r--r--pw_log_zephyr/log_zephyr.cc23
-rw-r--r--pw_log_zephyr/public/pw_log_zephyr/config.h16
-rw-r--r--pw_log_zephyr/public/pw_log_zephyr/log_zephyr.h72
-rw-r--r--pw_log_zephyr/public_overrides/pw_log_backend/log_backend.h16
-rw-r--r--pw_polyfill/CMakeLists.txt6
-rw-r--r--pw_polyfill/Kconfig20
-rw-r--r--pw_polyfill/docs.rst6
-rw-r--r--pw_preprocessor/CMakeLists.txt4
-rw-r--r--pw_preprocessor/Kconfig16
-rw-r--r--pw_preprocessor/docs.rst5
-rwxr-xr-xpw_presubmit/py/pw_presubmit/pigweed_presubmit.py3
-rw-r--r--pw_result/CMakeLists.txt4
-rw-r--r--pw_result/Kconfig18
-rw-r--r--pw_result/docs.rst5
-rw-r--r--pw_router/CMakeLists.txt12
-rw-r--r--pw_router/Kconfig40
-rw-r--r--pw_router/docs.rst14
-rw-r--r--pw_rpc/CMakeLists.txt15
-rw-r--r--pw_rpc/Kconfig53
-rw-r--r--pw_rpc/docs.rst13
-rw-r--r--pw_rpc/nanopb/CMakeLists.txt15
-rw-r--r--pw_rpc/nanopb/Kconfig53
-rw-r--r--pw_rpc/nanopb/docs.rst17
-rw-r--r--pw_span/CMakeLists.txt4
-rw-r--r--pw_span/Kconfig17
-rw-r--r--pw_span/docs.rst5
-rw-r--r--pw_status/CMakeLists.txt4
-rw-r--r--pw_status/Kconfig16
-rw-r--r--pw_status/docs.rst5
-rw-r--r--pw_stream/CMakeLists.txt3
-rw-r--r--pw_stream/Kconfig21
-rw-r--r--pw_stream/docs.rst5
-rw-r--r--pw_string/CMakeLists.txt3
-rw-r--r--pw_string/Kconfig21
-rw-r--r--pw_string/docs.rst5
-rw-r--r--pw_sync/CMakeLists.txt8
-rw-r--r--pw_sync_zephyr/BUILD.gn21
-rw-r--r--pw_sync_zephyr/CMakeLists.txt37
-rw-r--r--pw_sync_zephyr/Kconfig31
-rw-r--r--pw_sync_zephyr/binary_semaphore.cc42
-rw-r--r--pw_sync_zephyr/docs.rst16
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h57
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h25
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/mutex_inline.h50
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/mutex_native.h23
-rw-r--r--pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_inline.h16
-rw-r--r--pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_native.h16
-rw-r--r--pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_inline.h16
-rw-r--r--pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_native.h16
-rw-r--r--pw_sys_io_zephyr/BUILD.gn21
-rw-r--r--pw_sys_io_zephyr/CMakeLists.txt28
-rw-r--r--pw_sys_io_zephyr/Kconfig18
-rw-r--r--pw_sys_io_zephyr/docs.rst11
-rw-r--r--pw_sys_io_zephyr/sys_io.cc47
-rw-r--r--pw_varint/CMakeLists.txt3
-rw-r--r--pw_varint/Kconfig18
-rw-r--r--pw_varint/docs.rst5
-rw-r--r--zephyr/module.yml18
109 files changed, 2130 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9500926b3..6499f02b9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,7 @@ cmake_minimum_required(VERSION 3.16)
# Regardless of whether it's set or not the following include will ensure it is.
include(pw_build/pigweed.cmake)
+add_subdirectory(pw_assert_zephyr EXCLUDE_FROM_ALL)
add_subdirectory(pw_assert EXCLUDE_FROM_ALL)
add_subdirectory(pw_assert_basic EXCLUDE_FROM_ALL)
add_subdirectory(pw_assert_log EXCLUDE_FROM_ALL)
@@ -28,6 +29,7 @@ add_subdirectory(pw_blob_store EXCLUDE_FROM_ALL)
add_subdirectory(pw_build EXCLUDE_FROM_ALL)
add_subdirectory(pw_bytes EXCLUDE_FROM_ALL)
add_subdirectory(pw_checksum EXCLUDE_FROM_ALL)
+add_subdirectory(pw_chrono_zephyr EXCLUDE_FROM_ALL)
add_subdirectory(pw_chrono EXCLUDE_FROM_ALL)
add_subdirectory(pw_chrono_stl EXCLUDE_FROM_ALL)
add_subdirectory(pw_containers EXCLUDE_FROM_ALL)
@@ -36,7 +38,10 @@ add_subdirectory(pw_cpu_exception_cortex_m EXCLUDE_FROM_ALL)
add_subdirectory(pw_file EXCLUDE_FROM_ALL)
add_subdirectory(pw_function EXCLUDE_FROM_ALL)
add_subdirectory(pw_hdlc EXCLUDE_FROM_ALL)
+add_subdirectory(pw_interrupt_zephyr EXCLUDE_FROM_ALL)
+add_subdirectory(pw_interrupt EXCLUDE_FROM_ALL)
add_subdirectory(pw_kvs EXCLUDE_FROM_ALL)
+add_subdirectory(pw_log_zephyr EXCLUDE_FROM_ALL)
add_subdirectory(pw_log EXCLUDE_FROM_ALL)
add_subdirectory(pw_log_basic EXCLUDE_FROM_ALL)
add_subdirectory(pw_log_null EXCLUDE_FROM_ALL)
@@ -55,8 +60,10 @@ add_subdirectory(pw_span EXCLUDE_FROM_ALL)
add_subdirectory(pw_status EXCLUDE_FROM_ALL)
add_subdirectory(pw_stream EXCLUDE_FROM_ALL)
add_subdirectory(pw_string EXCLUDE_FROM_ALL)
+add_subdirectory(pw_sync_zephyr EXCLUDE_FROM_ALL)
add_subdirectory(pw_sync EXCLUDE_FROM_ALL)
add_subdirectory(pw_sync_stl EXCLUDE_FROM_ALL)
+add_subdirectory(pw_sys_io_zephyr EXCLUDE_FROM_ALL)
add_subdirectory(pw_sys_io EXCLUDE_FROM_ALL)
add_subdirectory(pw_sys_io_stdio EXCLUDE_FROM_ALL)
add_subdirectory(pw_system EXCLUDE_FROM_ALL)
@@ -67,9 +74,11 @@ add_subdirectory(pw_transfer EXCLUDE_FROM_ALL)
add_subdirectory(pw_unit_test EXCLUDE_FROM_ALL)
add_subdirectory(pw_varint EXCLUDE_FROM_ALL)
-add_subdirectory(targets/host EXCLUDE_FROM_ALL)
-
add_subdirectory(third_party/nanopb EXCLUDE_FROM_ALL)
-add_custom_target(pw_apps)
-add_dependencies(pw_apps pw_hdlc.rpc_example)
+if(NOT ZEPHYR_PIGWEED_MODULE_DIR)
+ add_subdirectory(targets/host EXCLUDE_FROM_ALL)
+
+ add_custom_target(pw_apps)
+ add_dependencies(pw_apps pw_hdlc.rpc_example)
+endif()
diff --git a/Kconfig.zephyr b/Kconfig.zephyr
new file mode 100644
index 000000000..d0c43d020
--- /dev/null
+++ b/Kconfig.zephyr
@@ -0,0 +1,43 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config ZEPHYR_PIGWEED_MODULE
+ select LIB_CPLUSPLUS
+ depends on STD_CPP17 || STD_CPP2A || STD_CPP20 || STD_CPP2B
+
+if ZEPHYR_PIGWEED_MODULE
+
+rsource "pw_assert_zephyr/Kconfig"
+rsource "pw_bytes/Kconfig"
+rsource "pw_checksum/Kconfig"
+rsource "pw_chrono_zephyr/Kconfig"
+rsource "pw_containers/Kconfig"
+rsource "pw_function/Kconfig"
+rsource "pw_hdlc/Kconfig"
+rsource "pw_interrupt_zephyr/Kconfig"
+rsource "pw_log_zephyr/Kconfig"
+rsource "pw_polyfill/Kconfig"
+rsource "pw_preprocessor/Kconfig"
+rsource "pw_result/Kconfig"
+rsource "pw_router/Kconfig"
+rsource "pw_rpc/Kconfig"
+rsource "pw_span/Kconfig"
+rsource "pw_status/Kconfig"
+rsource "pw_stream/Kconfig"
+rsource "pw_string/Kconfig"
+rsource "pw_sync_zephyr/Kconfig"
+rsource "pw_sys_io_zephyr/Kconfig"
+rsource "pw_varint/Kconfig"
+
+endif # ZEPHYR_PIGWEED_MODULE
diff --git a/docs/BUILD.gn b/docs/BUILD.gn
index e54489b80..ef0f5bd65 100644
--- a/docs/BUILD.gn
+++ b/docs/BUILD.gn
@@ -68,6 +68,7 @@ group("module_docs") {
"$dir_pw_assert:docs",
"$dir_pw_assert_basic:docs",
"$dir_pw_assert_log:docs",
+ "$dir_pw_assert_zephyr:docs",
"$dir_pw_base64:docs",
"$dir_pw_bloat:docs",
"$dir_pw_blob_store:docs",
@@ -84,6 +85,7 @@ group("module_docs") {
"$dir_pw_chrono_freertos:docs",
"$dir_pw_chrono_stl:docs",
"$dir_pw_chrono_threadx:docs",
+ "$dir_pw_chrono_zephyr:docs",
"$dir_pw_cli:docs",
"$dir_pw_console:docs",
"$dir_pw_containers:docs",
@@ -101,6 +103,7 @@ group("module_docs") {
"$dir_pw_i2c:docs",
"$dir_pw_interrupt:docs",
"$dir_pw_interrupt_cortex_m:docs",
+ "$dir_pw_interrupt_zephyr:docs",
"$dir_pw_kvs:docs",
"$dir_pw_libc:docs",
"$dir_pw_log:docs",
@@ -141,11 +144,13 @@ group("module_docs") {
"$dir_pw_sync_freertos:docs",
"$dir_pw_sync_stl:docs",
"$dir_pw_sync_threadx:docs",
+ "$dir_pw_sync_zephyr:docs",
"$dir_pw_sys_io:docs",
"$dir_pw_sys_io_arduino:docs",
"$dir_pw_sys_io_baremetal_stm32f429:docs",
"$dir_pw_sys_io_mcuxpresso:docs",
"$dir_pw_sys_io_stdio:docs",
+ "$dir_pw_sys_io_zephyr:docs",
"$dir_pw_system:docs",
"$dir_pw_target_runner:docs",
"$dir_pw_thread:docs",
diff --git a/modules.gni b/modules.gni
index 3789ac8d7..b78953ec8 100644
--- a/modules.gni
+++ b/modules.gni
@@ -24,6 +24,7 @@ declare_args() {
dir_pw_assert = get_path_info("pw_assert", "abspath")
dir_pw_assert_basic = get_path_info("pw_assert_basic", "abspath")
dir_pw_assert_log = get_path_info("pw_assert_log", "abspath")
+ dir_pw_assert_zephyr = get_path_info("pw_assert_zephyr", "abspath")
dir_pw_base64 = get_path_info("pw_base64", "abspath")
dir_pw_bloat = get_path_info("pw_bloat", "abspath")
dir_pw_blob_store = get_path_info("pw_blob_store", "abspath")
@@ -39,6 +40,7 @@ declare_args() {
dir_pw_chrono_freertos = get_path_info("pw_chrono_freertos", "abspath")
dir_pw_chrono_stl = get_path_info("pw_chrono_stl", "abspath")
dir_pw_chrono_threadx = get_path_info("pw_chrono_threadx", "abspath")
+ dir_pw_chrono_zephyr = get_path_info("pw_chrono_zephyr", "abspath")
dir_pw_cli = get_path_info("pw_cli", "abspath")
dir_pw_console = get_path_info("pw_console", "abspath")
dir_pw_containers = get_path_info("pw_containers", "abspath")
@@ -58,6 +60,7 @@ declare_args() {
dir_pw_i2c = get_path_info("pw_i2c", "abspath")
dir_pw_interrupt = get_path_info("pw_interrupt", "abspath")
dir_pw_interrupt_cortex_m = get_path_info("pw_interrupt_cortex_m", "abspath")
+ dir_pw_interrupt_zephyr = get_path_info("pw_interrupt_zephyr", "abspath")
dir_pw_kvs = get_path_info("pw_kvs", "abspath")
dir_pw_libc = get_path_info("pw_libc", "abspath")
dir_pw_log = get_path_info("pw_log", "abspath")
@@ -98,6 +101,7 @@ declare_args() {
dir_pw_sync_baremetal = get_path_info("pw_sync_baremetal", "abspath")
dir_pw_sync_stl = get_path_info("pw_sync_stl", "abspath")
dir_pw_sync_threadx = get_path_info("pw_sync_threadx", "abspath")
+ dir_pw_sync_zephyr = get_path_info("pw_sync_zephyr", "abspath")
dir_pw_sys_io = get_path_info("pw_sys_io", "abspath")
dir_pw_sys_io_baremetal_lm3s6965evb =
get_path_info("pw_sys_io_baremetal_lm3s6965evb", "abspath")
@@ -107,6 +111,7 @@ declare_args() {
dir_pw_sys_io_mcuxpresso = get_path_info("pw_sys_io_mcuxpresso", "abspath")
dir_pw_sys_io_stdio = get_path_info("pw_sys_io_stdio", "abspath")
dir_pw_sys_io_stm32cube = get_path_info("pw_sys_io_stm32cube", "abspath")
+ dir_pw_sys_io_zephyr = get_path_info("pw_sys_io_zephyr", "abspath")
dir_pw_system = get_path_info("pw_system", "abspath")
dir_pw_target_runner = get_path_info("pw_target_runner", "abspath")
dir_pw_thread = get_path_info("pw_thread", "abspath")
diff --git a/pw_assert_zephyr/BUILD.gn b/pw_assert_zephyr/BUILD.gn
new file mode 100644
index 000000000..9a6699a8e
--- /dev/null
+++ b/pw_assert_zephyr/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_docgen/docs.gni")
+
+pw_doc_group("docs") {
+ sources = [ "docs.rst" ]
+}
diff --git a/pw_assert_zephyr/CMakeLists.txt b/pw_assert_zephyr/CMakeLists.txt
new file mode 100644
index 000000000..1d55f658d
--- /dev/null
+++ b/pw_assert_zephyr/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+if(NOT CONFIG_PIGWEED_ASSERT)
+ return()
+endif()
+
+pw_auto_add_simple_module(pw_assert_zephyr
+ IMPLEMENTS_FACADE
+ pw_assert
+)
+pw_set_backend(pw_assert pw_assert_zephyr)
+target_link_libraries(pw_assert_zephyr PUBLIC zephyr_interface)
+zephyr_link_libraries(pw_assert_zephyr)
diff --git a/pw_assert_zephyr/Kconfig b/pw_assert_zephyr/Kconfig
new file mode 100644
index 000000000..de2290cdc
--- /dev/null
+++ b/pw_assert_zephyr/Kconfig
@@ -0,0 +1,17 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_ASSERT
+ bool "Enable Pigweed assert library (pw_assert)"
+ select PIGWEED_PREPROCESSOR
diff --git a/pw_assert_zephyr/assert_zephyr.cc b/pw_assert_zephyr/assert_zephyr.cc
new file mode 100644
index 000000000..1deae5d11
--- /dev/null
+++ b/pw_assert_zephyr/assert_zephyr.cc
@@ -0,0 +1,23 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include <kernel.h>
+
+#include "pw_assert/assert.h"
+#include "pw_preprocessor/compiler.h"
+
+extern "C" void pw_assert_HandleFailure(void) {
+ k_panic();
+ PW_UNREACHABLE;
+}
diff --git a/pw_assert_zephyr/docs.rst b/pw_assert_zephyr/docs.rst
new file mode 100644
index 000000000..a9313fd2b
--- /dev/null
+++ b/pw_assert_zephyr/docs.rst
@@ -0,0 +1,17 @@
+.. _module-pw_assert_zephyr:
+
+================
+pw_assert_zephyr
+================
+
+--------
+Overview
+--------
+This assert backend implements the ``pw_assert`` facade, by routing the assert
+message to the Zephyr assert subsystem. Failed asserts will call ``k_panic()``.
+To enable the assert module, set ``CONFIG_PIGWEED_ASSERT=y``. After that,
+Zephyr's assert configs can be used to control the behavior via CONFIG_ASSERT_
+and CONFIG_ASSERT_LEVEL_.
+
+.. _CONFIG_ASSERT: https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_ASSERT.html#std-kconfig-CONFIG_ASSERT
+.. _CONFIG_ASSERT_LEVEL: https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_ASSERT_LEVEL.html#std-kconfig-CONFIG_ASSERT_LEVEL \ No newline at end of file
diff --git a/pw_assert_zephyr/public/pw_assert_zephyr/assert_zephyr.h b/pw_assert_zephyr/public/pw_assert_zephyr/assert_zephyr.h
new file mode 100644
index 000000000..40c4e16ff
--- /dev/null
+++ b/pw_assert_zephyr/public/pw_assert_zephyr/assert_zephyr.h
@@ -0,0 +1,48 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// This override header merely points to the true backend, in this case the
+// basic one. The reason to redirect is to permit the use of multiple backends
+// (though only pw_assert/check.h can only point to 1 backend).
+#pragma once
+
+#include <sys/__assert.h>
+
+#include "pw_assert/assert.h"
+
+#define PW_HANDLE_CRASH(...) \
+ { \
+ __ASSERT_MSG_INFO(__VA_ARGS__); \
+ pw_assert_HandleFailure(); \
+ }
+
+#define PW_HANDLE_ASSERT_FAILURE(condition_string, ...) \
+ { \
+ __ASSERT_MSG_INFO("Check failed: " condition_string ". " __VA_ARGS__); \
+ __ASSERT_POST_ACTION(); \
+ }
+
+#define PW_HANDLE_ASSERT_BINARY_COMPARE_FAILURE(arg_a_str, \
+ arg_a_val, \
+ comparison_op_str, \
+ arg_b_str, \
+ arg_b_val, \
+ type_fmt, \
+ message, \
+ ...) \
+ PW_HANDLE_ASSERT_FAILURE(arg_a_str " (=" type_fmt ") " comparison_op_str \
+ " " arg_b_str " (=" type_fmt ")", \
+ message, \
+ arg_a_val, \
+ arg_b_val PW_COMMA_ARGS(__VA_ARGS__))
diff --git a/pw_assert_zephyr/public_overrides/pw_assert_backend/assert_backend.h b/pw_assert_zephyr/public_overrides/pw_assert_backend/assert_backend.h
new file mode 100644
index 000000000..63e5ab07b
--- /dev/null
+++ b/pw_assert_zephyr/public_overrides/pw_assert_backend/assert_backend.h
@@ -0,0 +1,20 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// This override header merely points to the true backend, in this case the
+// basic one. The reason to redirect is to permit the use of multiple backends
+// (though only pw_assert/check.h can only point to 1 backend).
+#pragma once
+
+#include "pw_assert_zephyr/assert_zephyr.h"
diff --git a/pw_build/CMakeLists.txt b/pw_build/CMakeLists.txt
index 602dd4a66..d4ad2c331 100644
--- a/pw_build/CMakeLists.txt
+++ b/pw_build/CMakeLists.txt
@@ -49,13 +49,16 @@ target_compile_options(pw_build.reduced_size
)
add_library(pw_build.strict_warnings INTERFACE)
+if(NOT ZEPHYR_PIGWEED_MODULE_DIR)
+ # Only include these flags if we're not building with Zephyr.
+ set(strict_warnings_cond "-Wcast-qual" "-Wundef")
+endif()
target_compile_options(pw_build.strict_warnings
INTERFACE
"-Wall"
"-Wextra"
"-Wimplicit-fallthrough"
- "-Wcast-qual"
- "-Wundef"
+ ${strict_warnings_cond}
"-Wpointer-arith"
# Make all warnings errors, except for the exemptions below.
@@ -67,10 +70,14 @@ target_compile_options(pw_build.strict_warnings
)
add_library(pw_build.extra_strict_warnings INTERFACE)
+if(NOT ZEPHYR_PIGWEED_MODULE_DIR)
+ # Only include these flags if we're not building with Zephyr.
+ set(extra_strict_warnings_cond "-Wredundant-decls")
+endif()
target_compile_options(pw_build.extra_strict_warnings
INTERFACE
"-Wshadow"
- "-Wredundant-decls"
+ ${extra_strict_warnings_cond}
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
)
diff --git a/pw_bytes/CMakeLists.txt b/pw_bytes/CMakeLists.txt
index 33f48b748..3bfc6bd96 100644
--- a/pw_bytes/CMakeLists.txt
+++ b/pw_bytes/CMakeLists.txt
@@ -21,3 +21,6 @@ pw_auto_add_simple_module(pw_bytes
pw_span
pw_status
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_BYTES)
+ zephyr_link_libraries(pw_bytes)
+endif()
diff --git a/pw_bytes/Kconfig b/pw_bytes/Kconfig
new file mode 100644
index 000000000..482ef21b2
--- /dev/null
+++ b/pw_bytes/Kconfig
@@ -0,0 +1,20 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_BYTES
+ bool "Enable the Pigweed bytes library (pw_bytes)"
+ select PIGWEED_POLYFILL_OVERRIDES
+ select PIGWEED_PREPROCESSOR
+ select PIGWEED_SPAN
+ select PIGWEED_STATUS
diff --git a/pw_bytes/docs.rst b/pw_bytes/docs.rst
index d2ef9ffa0..c2868b470 100644
--- a/pw_bytes/docs.rst
+++ b/pw_bytes/docs.rst
@@ -66,3 +66,8 @@ In order to use these you must use a using namespace directive, for example:
using namespace pw::bytes::unit_literals;
constexpr size_t kRandomBufferSizeBytes = 1_MiB + 42_KiB;
+
+Zephyr
+======
+To enable ``pw_bytes`` for Zephyr add ``CONFIG_PIGWEED_BYTES=y`` to the
+project's configuration.
diff --git a/pw_checksum/CMakeLists.txt b/pw_checksum/CMakeLists.txt
index 94fe37154..2c437a992 100644
--- a/pw_checksum/CMakeLists.txt
+++ b/pw_checksum/CMakeLists.txt
@@ -20,3 +20,6 @@ pw_auto_add_simple_module(pw_checksum
PRIVATE_DEPS
pw_bytes
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_CHECKSUM)
+ zephyr_link_libraries(pw_checksum)
+endif()
diff --git a/pw_checksum/Kconfig b/pw_checksum/Kconfig
new file mode 100644
index 000000000..91a44d495
--- /dev/null
+++ b/pw_checksum/Kconfig
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_CHECKSUM
+ bool "Enable Pigweed checksum library (pw_checksum)"
+ select PIGWEED_SPAN
+ select PIGWEED_BYTES
diff --git a/pw_checksum/docs.rst b/pw_checksum/docs.rst
index 3006ab0f2..456e08038 100644
--- a/pw_checksum/docs.rst
+++ b/pw_checksum/docs.rst
@@ -62,3 +62,8 @@ Compatibility
Dependencies
============
* ``pw_span``
+
+Zephyr
+======
+To enable ``pw_checksum`` for Zephyr add ``CONFIG_PIGWEED_CHECKSUM=y`` to the
+project's configuration.
diff --git a/pw_chrono_zephyr/BUILD.gn b/pw_chrono_zephyr/BUILD.gn
new file mode 100644
index 000000000..9a6699a8e
--- /dev/null
+++ b/pw_chrono_zephyr/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_docgen/docs.gni")
+
+pw_doc_group("docs") {
+ sources = [ "docs.rst" ]
+}
diff --git a/pw_chrono_zephyr/CMakeLists.txt b/pw_chrono_zephyr/CMakeLists.txt
new file mode 100644
index 000000000..ad979c9eb
--- /dev/null
+++ b/pw_chrono_zephyr/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_CHRONO_SYSTEM_CLOCK)
+ pw_add_module_library(pw_chrono_zephyr.system_clock
+ IMPLEMENTS_FACADES
+ pw_chrono.system_clock
+ PUBLIC_DEPS
+ pw_function
+ )
+ pw_set_backend(pw_chrono.system_clock pw_chrono_zephyr.system_clock)
+ zephyr_link_interface(pw_chrono_zephyr.system_clock)
+ zephyr_link_libraries(pw_chrono_zephyr.system_clock)
+endif() \ No newline at end of file
diff --git a/pw_chrono_zephyr/Kconfig b/pw_chrono_zephyr/Kconfig
new file mode 100644
index 000000000..c6eacaca5
--- /dev/null
+++ b/pw_chrono_zephyr/Kconfig
@@ -0,0 +1,25 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+menuconfig PIGWEED_CHRONO
+ bool "Enable the Pigweed chrono facade (pw_chrono)"
+ select PIGWEED_PREPROCESSOR
+
+if PIGWEED_CHRONO
+
+config PIGWEED_CHRONO_SYSTEM_CLOCK
+ bool "Enabled the Pigweed chrono system clock library (pw_chrono.system_clock)"
+ select PIGWEED_FUNCTION
+
+endif # PIGWEED_CHRONO
diff --git a/pw_chrono_zephyr/docs.rst b/pw_chrono_zephyr/docs.rst
new file mode 100644
index 000000000..06760fd66
--- /dev/null
+++ b/pw_chrono_zephyr/docs.rst
@@ -0,0 +1,16 @@
+.. _module-pw_chrono_zephyr:
+
+================
+pw_chrono_zephyr
+================
+
+--------
+Overview
+--------
+This chrono backend implements the ``pw_chrono`` facades. To enable, set
+``CONFIG_PIGWEED_CHRONO=y``.
+
+pw_chrono.system_clock
+----------------------
+To enable the ``system_clock`` facade, it is also required to add
+``CONFIG_PIGWEED_CHRONO_SYSTEM_CLOCK=y``. \ No newline at end of file
diff --git a/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_config.h b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_config.h
new file mode 100644
index 000000000..55bfda5e6
--- /dev/null
+++ b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_config.h
@@ -0,0 +1,41 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+// Use the Zephyr config's tick rate.
+#define PW_CHRONO_SYSTEM_CLOCK_PERIOD_SECONDS_NUMERATOR 1
+#define PW_CHRONO_SYSTEM_CLOCK_PERIOD_SECONDS_DENOMINATOR \
+ CONFIG_SYS_CLOCK_TICKS_PER_SEC
+
+#ifdef __cplusplus
+
+#include "pw_chrono/epoch.h"
+
+namespace pw::chrono::backend {
+
+// The Zephyr clock starts at zero during initialization, approximately the
+// time since boot.
+inline constexpr Epoch kSystemClockEpoch = pw::chrono::Epoch::kTimeSinceBoot;
+
+// The current backend implementation is not NMI safe.
+inline constexpr bool kSystemClockNmiSafe = false;
+
+// The Zephyr clock never halts.
+inline constexpr bool kSystemClockFreeRunning = false;
+
+} // namespace pw::chrono::backend
+
+#endif // __cplusplus
diff --git a/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_constants.h b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_constants.h
new file mode 100644
index 000000000..4013b5c38
--- /dev/null
+++ b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_constants.h
@@ -0,0 +1,27 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+#include "pw_chrono/system_clock.h"
+
+namespace pw::chrono::zephyr {
+
+// Max timeout to be used by users of the Zephyr pw::chrono::SystemClock
+// backend provided by this module.
+inline constexpr SystemClock::duration kMaxTimeout =
+ SystemClock::duration(K_FOREVER.ticks - 1);
+
+} // namespace pw::chrono::zephyr
diff --git a/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_inline.h b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_inline.h
new file mode 100644
index 000000000..9ea227811
--- /dev/null
+++ b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_clock_inline.h
@@ -0,0 +1,24 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+#include "pw_chrono/system_clock.h"
+
+namespace pw::chrono::backend {
+
+inline int64_t GetSystemClockTickCount() { return k_uptime_ticks(); }
+
+} // namespace pw::chrono::backend
diff --git a/pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_inline.h b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_inline.h
new file mode 100644
index 000000000..f65246769
--- /dev/null
+++ b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_inline.h
@@ -0,0 +1,26 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+#include "pw_chrono/system_timer.h"
+
+namespace pw::chrono {
+
+inline void SystemTimer::InvokeAfter(SystemClock::duration delay) {
+ InvokeAt(SystemClock::TimePointAfterAtLeast(delay));
+}
+
+} // namespace pw::chrono
diff --git a/pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_native.h b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_native.h
new file mode 100644
index 000000000..9aa1a6583
--- /dev/null
+++ b/pw_chrono_zephyr/public/pw_chrono_zephyr/system_timer_native.h
@@ -0,0 +1,39 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+#include <sys/mutex.h>
+
+#include "pw_chrono/system_clock.h"
+#include "pw_function/function.h"
+
+namespace pw::chrono::backend {
+
+struct NativeSystemTimer;
+
+struct ZephyrWorkWrapper {
+ k_work_delayable work;
+ NativeSystemTimer* owner;
+};
+
+struct NativeSystemTimer {
+ ZephyrWorkWrapper work_wrapper;
+ sys_mutex mutex;
+ SystemClock::time_point expiry_deadline;
+ Function<void(SystemClock::time_point expired_deadline)> user_callback;
+};
+using NativeSystemTimerHandle = NativeSystemTimer&;
+
+} // namespace pw::chrono::backend
diff --git a/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_config.h b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_config.h
new file mode 100644
index 000000000..7dfe01944
--- /dev/null
+++ b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_config.h
@@ -0,0 +1,19 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// This override header includes the main tokenized logging header and defines
+// the PW_LOG macro as the tokenized logging macro.
+#pragma once
+
+#include "pw_chrono_zephyr/system_clock_config.h"
diff --git a/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_inline.h b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_inline.h
new file mode 100644
index 000000000..ea2e8e254
--- /dev/null
+++ b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_clock_inline.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "pw_chrono_zephyr/system_clock_inline.h"
diff --git a/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_inline.h b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_inline.h
new file mode 100644
index 000000000..18566e4b6
--- /dev/null
+++ b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_inline.h
@@ -0,0 +1,19 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// This override header includes the main tokenized logging header and defines
+// the PW_LOG macro as the tokenized logging macro.
+#pragma once
+
+#include "pw_chrono_zephyr/system_timer_inline.h"
diff --git a/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_native.h b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_native.h
new file mode 100644
index 000000000..7bcb1ace7
--- /dev/null
+++ b/pw_chrono_zephyr/public_overrides/pw_chrono_backend/system_timer_native.h
@@ -0,0 +1,19 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// This override header includes the main tokenized logging header and defines
+// the PW_LOG macro as the tokenized logging macro.
+#pragma once
+
+#include "pw_chrono_zephyr/system_timer_native.h"
diff --git a/pw_chrono_zephyr/system_timer.cc b/pw_chrono_zephyr/system_timer.cc
new file mode 100644
index 000000000..abb7423c8
--- /dev/null
+++ b/pw_chrono_zephyr/system_timer.cc
@@ -0,0 +1,93 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include "pw_chrono/system_timer.h"
+
+#include <kernel.h>
+#include <sys/mutex.h>
+
+#include <algorithm>
+
+#include "pw_chrono_zephyr/system_clock_constants.h"
+#include "pw_chrono_zephyr/system_timer_native.h"
+
+namespace pw::chrono {
+namespace {
+
+constexpr SystemClock::duration kMinTimerPeriod = SystemClock::duration(1);
+// Work synchronization objects must be in cache-coherent memory, which excludes
+// stacks on some architectures.
+static k_work_sync work_sync;
+
+} // namespace
+
+void HandleTimerWork(k_work* item) {
+ k_work_delayable* delayable_item = k_work_delayable_from_work(item);
+ backend::NativeSystemTimer* native_type =
+ CONTAINER_OF(delayable_item, backend::ZephyrWorkWrapper, work)->owner;
+
+ sys_mutex_lock(&native_type->mutex, K_FOREVER);
+#ifdef CONFIG_TIMEOUT_64BIT
+ native_type->user_callback(native_type->expiry_deadline);
+#else
+ const SystemClock::duration time_until_deadline =
+ native_type->expiry_deadline - SystemClock::now();
+ if (time_until_deadline <= SystemClock::duration::zero()) {
+ native_type->user_callback(native_type->expiry_deadline);
+ } else {
+ // We haven't met the deadline yet, reschedule as far out as possible.
+ const SystemClock::duration period =
+ std::min(pw::chrono::zephyr::kMaxTimeout, time_until_deadline);
+ k_work_schedule(&native_type->work_wrapper.work, K_TICKS(period.count()));
+ }
+#endif // CONFIG_TIMEOUT_64BIT
+ sys_mutex_unlock(&native_type->mutex);
+}
+
+SystemTimer::SystemTimer(ExpiryCallback callback)
+ : native_type_{.work_wrapper =
+ {
+ .work = {},
+ .owner = nullptr,
+ },
+ .mutex = {},
+ .expiry_deadline = SystemClock::time_point(),
+ .user_callback = std::move(callback)} {
+ k_work_init_delayable(&native_type_.work_wrapper.work, HandleTimerWork);
+ sys_mutex_init(&native_type_.mutex);
+ native_type_.work_wrapper.owner = &native_type_;
+}
+
+SystemTimer::~SystemTimer() {
+ k_work_cancel_sync(&native_type_.work_wrapper.work, &work_sync);
+}
+
+void SystemTimer::InvokeAt(SystemClock::time_point timestamp) {
+ sys_mutex_lock(&native_type_.mutex, K_FOREVER);
+ native_type_.expiry_deadline = timestamp;
+
+ const SystemClock::duration time_until_deadline =
+ timestamp - SystemClock::now();
+ const SystemClock::duration period =
+ IS_ENABLED(CONFIG_TIMEOUT_64BIT)
+ ? time_until_deadline
+ : std::clamp(kMinTimerPeriod,
+ time_until_deadline,
+ pw::chrono::zephyr::kMaxTimeout);
+
+ k_work_schedule(&native_type_.work_wrapper.work, K_TICKS(period.count()));
+ sys_mutex_unlock(&native_type_.mutex);
+}
+
+} // namespace pw::chrono
diff --git a/pw_containers/CMakeLists.txt b/pw_containers/CMakeLists.txt
index 393624926..06d173c00 100644
--- a/pw_containers/CMakeLists.txt
+++ b/pw_containers/CMakeLists.txt
@@ -19,3 +19,6 @@ pw_auto_add_simple_module(pw_containers
pw_assert
pw_status
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_CONTAINERS)
+ zephyr_link_libraries(pw_containers)
+endif()
diff --git a/pw_containers/Kconfig b/pw_containers/Kconfig
new file mode 100644
index 000000000..4b83c360f
--- /dev/null
+++ b/pw_containers/Kconfig
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_CONTAINERS
+ bool "Enable the Pigweed containers library (pw_containers)"
+ select PIGWEED_ASSERT
+ select PIGWEED_STATUS
diff --git a/pw_containers/docs.rst b/pw_containers/docs.rst
index aa3d6e764..297763a3a 100644
--- a/pw_containers/docs.rst
+++ b/pw_containers/docs.rst
@@ -171,3 +171,8 @@ Compatibility
Dependencies
============
* ``pw_span``
+
+Zephyr
+======
+To enable ``pw_containers`` for Zephyr add ``CONFIG_PIGWEED_CONTAINERS=y`` to
+the project's configuration.
diff --git a/pw_function/CMakeLists.txt b/pw_function/CMakeLists.txt
index 6f6e27567..752ae96f9 100644
--- a/pw_function/CMakeLists.txt
+++ b/pw_function/CMakeLists.txt
@@ -19,3 +19,7 @@ pw_auto_add_simple_module(pw_function
pw_assert
pw_preprocessor
)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_FUNCTION)
+ zephyr_link_libraries(pw_function)
+endif()
diff --git a/pw_function/Kconfig b/pw_function/Kconfig
new file mode 100644
index 000000000..e9ff1ef3e
--- /dev/null
+++ b/pw_function/Kconfig
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_FUNCTION
+ bool "Enable the Pigweed function library (pw_function)"
+ select PIGWEED_ASSERT
+ select PIGWEED_PREPROCESSOR
diff --git a/pw_function/docs.rst b/pw_function/docs.rst
index dbd4b8895..14ce90608 100644
--- a/pw_function/docs.rst
+++ b/pw_function/docs.rst
@@ -246,3 +246,8 @@ Functions are movable, but not copyable. This allows them to store and manage
callables without having to perform bookkeeping such as reference counting, and
avoids any reliance on dynamic memory management. The result is a simpler
implementation which is easy to conceptualize and use in an embedded context.
+
+Zephyr
+======
+To enable ``pw_function` for Zephyr add ``CONFIG_PIGWEED_FUNCTION=y`` to the
+project's configuration.
diff --git a/pw_hdlc/CMakeLists.txt b/pw_hdlc/CMakeLists.txt
index 5f48d55b0..97626c2ef 100644
--- a/pw_hdlc/CMakeLists.txt
+++ b/pw_hdlc/CMakeLists.txt
@@ -30,3 +30,7 @@ pw_auto_add_simple_module(pw_hdlc
)
add_subdirectory(rpc_example)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_HDLC)
+ zephyr_link_libraries(pw_hdlc)
+endif()
diff --git a/pw_hdlc/Kconfig b/pw_hdlc/Kconfig
new file mode 100644
index 000000000..de042ed90
--- /dev/null
+++ b/pw_hdlc/Kconfig
@@ -0,0 +1,26 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_HDLC
+ bool "Enable Pigweed HDLC library (pw_hdlc)"
+ select PIGWEED_ASSERT
+ select PIGWEED_BYTES
+ select PIGWEED_CHECKSUM
+ select PIGWEED_RESULT
+ select PIGWEED_ROUTER_PACKET_PARSER
+ select PIGWEED_RPC_COMMON
+ select PIGWEED_STATUS
+ select PIGWEED_STREAM
+ select PIGWEED_SYS_IO
+ select PIGWEED_LOG
diff --git a/pw_hdlc/docs.rst b/pw_hdlc/docs.rst
index ac7683ba8..3004891a3 100644
--- a/pw_hdlc/docs.rst
+++ b/pw_hdlc/docs.rst
@@ -268,3 +268,8 @@ Roadmap
Compatibility
=============
C++17
+
+Zephyr
+======
+To enable ``pw_hdlc`` for Zephyr add ``CONFIG_PIGWEED_HDLC=y`` to the project's
+configuration.
diff --git a/pw_interrupt/CMakeLists.txt b/pw_interrupt/CMakeLists.txt
new file mode 100644
index 000000000..87536f0d0
--- /dev/null
+++ b/pw_interrupt/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+pw_add_facade(pw_interrupt)
diff --git a/pw_interrupt_zephyr/BUILD.gn b/pw_interrupt_zephyr/BUILD.gn
new file mode 100644
index 000000000..9a6699a8e
--- /dev/null
+++ b/pw_interrupt_zephyr/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_docgen/docs.gni")
+
+pw_doc_group("docs") {
+ sources = [ "docs.rst" ]
+}
diff --git a/pw_interrupt_zephyr/CMakeLists.txt b/pw_interrupt_zephyr/CMakeLists.txt
new file mode 100644
index 000000000..9563dba34
--- /dev/null
+++ b/pw_interrupt_zephyr/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+if(NOT CONFIG_PIGWEED_INTERRUPT)
+ return()
+endif()
+
+pw_add_module_library(pw_interrupt_zephyr
+ IMPLEMENTS_FACADES
+ pw_interrupt
+)
+pw_set_backend(pw_interrupt pw_interrupt_zephyr)
+zephyr_link_interface(pw_interrupt_zephyr)
+zephyr_link_libraries(pw_interrupt_zephyr)
diff --git a/pw_interrupt_zephyr/Kconfig b/pw_interrupt_zephyr/Kconfig
new file mode 100644
index 000000000..44626a939
--- /dev/null
+++ b/pw_interrupt_zephyr/Kconfig
@@ -0,0 +1,16 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_INTERRUPT
+ bool "Enable the Pigweed interrupt library (pw_interrupt)"
diff --git a/pw_interrupt_zephyr/docs.rst b/pw_interrupt_zephyr/docs.rst
new file mode 100644
index 000000000..bfa397775
--- /dev/null
+++ b/pw_interrupt_zephyr/docs.rst
@@ -0,0 +1,11 @@
+.. _module-pw_interrupt_zephyr:
+
+===================
+pw_interrupt_zephyr
+===================
+
+--------
+Overview
+--------
+This interrupt backend implements the ``pw_interrupt`` facade. To enable, set
+``CONFIG_PIGWEED_INTERRUPT=y``.
diff --git a/pw_interrupt_zephyr/public/pw_interrupt_zephyr/context_inline.h b/pw_interrupt_zephyr/public/pw_interrupt_zephyr/context_inline.h
new file mode 100644
index 000000000..cf8fb7860
--- /dev/null
+++ b/pw_interrupt_zephyr/public/pw_interrupt_zephyr/context_inline.h
@@ -0,0 +1,22 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+namespace pw::interrupt {
+
+inline bool InInterruptContext() { return k_is_in_isr(); }
+
+} // namespace pw::interrupt
diff --git a/pw_interrupt_zephyr/public_overrides/pw_interrupt_backend/context_inline.h b/pw_interrupt_zephyr/public_overrides/pw_interrupt_backend/context_inline.h
new file mode 100644
index 000000000..b6d96e412
--- /dev/null
+++ b/pw_interrupt_zephyr/public_overrides/pw_interrupt_backend/context_inline.h
@@ -0,0 +1,19 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// This override header includes the main tokenized logging header and defines
+// the PW_LOG macro as the tokenized logging macro.
+#pragma once
+
+#include "pw_interrupt_zephyr/context_inline.h"
diff --git a/pw_log_zephyr/CMakeLists.txt b/pw_log_zephyr/CMakeLists.txt
new file mode 100644
index 000000000..c4c71789e
--- /dev/null
+++ b/pw_log_zephyr/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+if(NOT CONFIG_PIGWEED_LOG)
+ return()
+endif()
+
+pw_auto_add_simple_module(pw_log_zephyr
+ IMPLEMENTS_FACADE
+ pw_log
+ PUBLIC_DEPS
+ zephyr_interface
+ PRIVATE_DEPS
+ pw_preprocessor
+)
+pw_set_backend(pw_log pw_log_zephyr)
+zephyr_link_libraries(pw_log_zephyr)
diff --git a/pw_log_zephyr/Kconfig b/pw_log_zephyr/Kconfig
new file mode 100644
index 000000000..472b54c64
--- /dev/null
+++ b/pw_log_zephyr/Kconfig
@@ -0,0 +1,28 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+menuconfig PIGWEED_LOG
+ bool "Enable Pigweed logging library (pw_log)"
+ select PIGWEED_PREPROCESSOR
+ help
+ Once the Pigweed logging is enabled, all Pigweed logs via PW_LOG_*() will
+ go to the "pigweed" Zephyr logging module.
+
+if PIGWEED_LOG
+
+module = PIGWEED
+module-str = "pigweed"
+source "subsys/logging/Kconfig.template.log_config"
+
+endif # PIGWEED_LOG
diff --git a/pw_log_zephyr/docs.rst b/pw_log_zephyr/docs.rst
new file mode 100644
index 000000000..84b8db9ac
--- /dev/null
+++ b/pw_log_zephyr/docs.rst
@@ -0,0 +1,39 @@
+.. _module-pw_log_zephyr:
+
+================
+pw_log_zephyr
+================
+
+--------
+Overview
+--------
+This interrupt backend implements the ``pw_log`` facade. To enable, set
+``CONFIG_PIGWEED_LOG=y``. After that, logging can be controlled via the standard
+`Kconfig options <https://docs.zephyrproject.org/latest/reference/logging/index.html#global-kconfig-options>`_.
+All logs made through `PW_LOG_*` are logged to the Zephyr logging module
+``pigweed``.
+
+Setting the log level
+---------------------
+In order to remain compatible with existing Pigweed code, the logging backend
+respects ``PW_LOG_LEVEL``. If set, the backend will translate the Pigweed log
+levels to their closest Zephyr counterparts:
+
++---------------------------+-------------------+
+| Pigweed | Zephyr |
++===========================+===================+
+| ``PW_LOG_LEVEL_DEBUG`` | ``LOG_LEVEL_DBG`` |
++---------------------------+-------------------+
+| ``PW_LOG_LEVEL_INFO`` | ``LOG_LEVEL_INF`` |
++---------------------------+-------------------+
+| ``PW_LOG_LEVEL_WARN`` | ``LOG_LEVEL_WRN`` |
++---------------------------+-------------------+
+| ``PW_LOG_LEVEL_ERROR`` | ``LOG_LEVEL_ERR`` |
+| | |
+| ``PW_LOG_LEVEL_CRITICAL`` | |
+| | |
+| ``PW_LOG_LEVEL_FATAL`` | |
++---------------------------+-------------------+
+
+Alternatively, it is also possible to set the Zephyr logging level directly via
+``CONFIG_PIGWEED_LOG_LEVEL``.
diff --git a/pw_log_zephyr/log_zephyr.cc b/pw_log_zephyr/log_zephyr.cc
new file mode 100644
index 000000000..053bf5403
--- /dev/null
+++ b/pw_log_zephyr/log_zephyr.cc
@@ -0,0 +1,23 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include <logging/log.h>
+
+#include "pw_log_zephyr/config.h"
+
+// Register the Zephyr logging module.
+// This must be done exactly ONCE. The header provided in public_overrides
+// provides the call to LOG_MODULE_DECLARE for each consumer of this backend
+// which will allow the use of this module.
+LOG_MODULE_REGISTER(PW_LOG_ZEPHYR_MODULE_NAME);
diff --git a/pw_log_zephyr/public/pw_log_zephyr/config.h b/pw_log_zephyr/public/pw_log_zephyr/config.h
new file mode 100644
index 000000000..027aaf639
--- /dev/null
+++ b/pw_log_zephyr/public/pw_log_zephyr/config.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#define PW_LOG_ZEPHYR_MODULE_NAME pigweed
diff --git a/pw_log_zephyr/public/pw_log_zephyr/log_zephyr.h b/pw_log_zephyr/public/pw_log_zephyr/log_zephyr.h
new file mode 100644
index 000000000..5f0b88e7f
--- /dev/null
+++ b/pw_log_zephyr/public/pw_log_zephyr/log_zephyr.h
@@ -0,0 +1,72 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <logging/log.h>
+#include <logging/log_ctrl.h>
+
+#include "pw_log_zephyr/config.h"
+
+#ifndef PW_LOG_MODULE_NAME
+#define PW_LOG_MODULE_NAME ""
+#endif
+
+// If the consumer defined PW_LOG_LEVEL use it, otherwise fallback to the global
+// CONFIG_PIGWEED_LOG_LEVEL set by Kconfig.
+#ifdef PW_LOG_LEVEL
+#if PW_LOG_LEVEL == PW_LOG_LEVEL_DEBUG
+// Map PW_LOG_LEVEL_DEBUG to LOG_LEVEL_DBG
+#define LOG_LEVEL LOG_LEVEL_DBG
+#elif PW_LOG_LEVEL == PW_LOG_LEVEL_INFO
+// Map PW_LOG_LEVEL_INFO to LOG_LEVEL_INF
+#define LOG_LEVEL LOG_LEVEL_INF
+#elif PW_LOG_LEVEL == PW_LOG_LEVEL_WARN
+// Map PW_LOG_LEVEL_WARN to LOG_LEVEL_WRN
+#define LOG_LEVEL LOG_LEVEL_WRN
+#elif (PW_LOG_LEVEL == PW_LOG_LEVEL_ERROR) || \
+ (PW_LOG_LEVEL == PW_LOG_LEVEL_CRITICAL) || \
+ (PW_LOG_LEVEL == PW_LOG_LEVEL_FATAL)
+// Map PW_LOG_LEVEL_(ERROR|CRITICAL|FATAL) to LOG_LEVEL_ERR
+#define LOG_LEVEL LOG_LEVEL_ERR
+#endif
+#else
+// Default to the Kconfig value
+#define LOG_LEVEL CONFIG_PIGWEED_LOG_LEVEL
+#endif
+
+LOG_MODULE_DECLARE(PW_LOG_ZEPHYR_MODULE_NAME, LOG_LEVEL);
+
+#define PW_HANDLE_LOG(level, flags, ...) \
+ do { \
+ switch (level) { \
+ case PW_LOG_LEVEL_INFO: \
+ LOG_INF(PW_LOG_MODULE_NAME " " __VA_ARGS__); \
+ break; \
+ case PW_LOG_LEVEL_WARN: \
+ LOG_WRN(PW_LOG_MODULE_NAME " " __VA_ARGS__); \
+ break; \
+ case PW_LOG_LEVEL_ERROR: \
+ case PW_LOG_LEVEL_CRITICAL: \
+ LOG_ERR(PW_LOG_MODULE_NAME " " __VA_ARGS__); \
+ break; \
+ case PW_LOG_LEVEL_FATAL: \
+ LOG_ERR(PW_LOG_MODULE_NAME " " __VA_ARGS__); \
+ LOG_PANIC(); \
+ break; \
+ case PW_LOG_LEVEL_DEBUG: \
+ default: \
+ LOG_DBG(PW_LOG_MODULE_NAME " " __VA_ARGS__); \
+ break; \
+ } \
+ } while (0)
diff --git a/pw_log_zephyr/public_overrides/pw_log_backend/log_backend.h b/pw_log_zephyr/public_overrides/pw_log_backend/log_backend.h
new file mode 100644
index 000000000..a6d363b94
--- /dev/null
+++ b/pw_log_zephyr/public_overrides/pw_log_backend/log_backend.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "pw_log_zephyr/log_zephyr.h"
diff --git a/pw_polyfill/CMakeLists.txt b/pw_polyfill/CMakeLists.txt
index 0914577a5..621271ad2 100644
--- a/pw_polyfill/CMakeLists.txt
+++ b/pw_polyfill/CMakeLists.txt
@@ -14,6 +14,9 @@
add_library(pw_polyfill INTERFACE)
target_include_directories(pw_polyfill INTERFACE public standard_library_public)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_POLYFILL)
+ zephyr_link_libraries(pw_polyfill)
+endif()
add_library(pw_polyfill.overrides INTERFACE)
target_link_libraries(pw_polyfill.overrides INTERFACE pw_polyfill)
@@ -22,3 +25,6 @@ target_include_directories(pw_polyfill.overrides
public_overrides
standard_library_public
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_POLYFILL_OVERRIDES)
+ zephyr_link_libraries(pw_polyfill.overrides)
+endif()
diff --git a/pw_polyfill/Kconfig b/pw_polyfill/Kconfig
new file mode 100644
index 000000000..c575dd8fb
--- /dev/null
+++ b/pw_polyfill/Kconfig
@@ -0,0 +1,20 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_POLYFILL
+ bool "Enable the Pigweed polyfill library (pw_polyfill)"
+
+config PIGWEED_POLYFILL_OVERRIDES
+ bool "Enable the Pigweed polyfill overrides library (pw_polyfill.overrides)"
+ depends on PIGWEED_POLYFILL
diff --git a/pw_polyfill/docs.rst b/pw_polyfill/docs.rst
index 095557833..bcf160ada 100644
--- a/pw_polyfill/docs.rst
+++ b/pw_polyfill/docs.rst
@@ -71,3 +71,9 @@ systems, add ``pw_polyfill/standard_library_public`` and
Compatibility
-------------
C++14
+
+Zephyr
+======
+To enable ``pw_polyfill`` for Zephyr add ``CONFIG_PIGWEED_POLYFILL=y`` to the
+project's configuration. Similarly, to enable ``pw_polyfill.overrides``, add
+``CONFIG_PIGWEED_POLYFILL_OVERRIDES=y`` to the project's configuration.
diff --git a/pw_preprocessor/CMakeLists.txt b/pw_preprocessor/CMakeLists.txt
index 3e893a020..b2f6f50ad 100644
--- a/pw_preprocessor/CMakeLists.txt
+++ b/pw_preprocessor/CMakeLists.txt
@@ -15,3 +15,7 @@
include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
pw_auto_add_simple_module(pw_preprocessor)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_PREPROCESSOR)
+ zephyr_link_libraries(pw_preprocessor)
+endif()
diff --git a/pw_preprocessor/Kconfig b/pw_preprocessor/Kconfig
new file mode 100644
index 000000000..ec5bc9213
--- /dev/null
+++ b/pw_preprocessor/Kconfig
@@ -0,0 +1,16 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_PREPROCESSOR
+ bool "Enable Pigweed preprocessor library (pw_preprocessor)"
diff --git a/pw_preprocessor/docs.rst b/pw_preprocessor/docs.rst
index 16abdfb17..ac6fd9991 100644
--- a/pw_preprocessor/docs.rst
+++ b/pw_preprocessor/docs.rst
@@ -256,3 +256,8 @@ General purpose, useful macros.
nothing in C
* ``PW_EXTERN_C_START`` / ``PW_EXTERN_C_END`` -- declares an ``extern "C" { }``
block in C++; expands to nothing in C
+
+Zephyr
+======
+To enable ``pw_preprocessor`` for Zephyr add ``CONFIG_PIGWEED_PREPROCESSOR=y``
+to the project's configuration.
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index 95aea37a2..a8dbe933c 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -611,7 +611,8 @@ _GN_SOURCES_IN_BUILD = ('setup.cfg', '.toml', '.rst', '.py',
*_BAZEL_SOURCES_IN_BUILD)
-@filter_paths(endswith=(*_GN_SOURCES_IN_BUILD, 'BUILD', '.bzl', '.gn', '.gni'))
+@filter_paths(endswith=(*_GN_SOURCES_IN_BUILD, 'BUILD', '.bzl', '.gn', '.gni'),
+ exclude=['zephyr.*/'])
def source_is_in_build_files(ctx: PresubmitContext):
"""Checks that source files are in the GN and Bazel builds."""
missing = build.check_builds_for_files(
diff --git a/pw_result/CMakeLists.txt b/pw_result/CMakeLists.txt
index 20b5db030..9e110256f 100644
--- a/pw_result/CMakeLists.txt
+++ b/pw_result/CMakeLists.txt
@@ -19,3 +19,7 @@ pw_auto_add_simple_module(pw_result
pw_assert
pw_status
)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RESULT)
+ zephyr_link_libraries(pw_result)
+endif()
diff --git a/pw_result/Kconfig b/pw_result/Kconfig
new file mode 100644
index 000000000..76e3b2197
--- /dev/null
+++ b/pw_result/Kconfig
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_RESULT
+ bool "Enable Pigweed result library (pw_result)"
+ select PIGWEED_ASSERT
+ select PIGWEED_STATUS
diff --git a/pw_result/docs.rst b/pw_result/docs.rst
index 57d161083..223e6b2c8 100644
--- a/pw_result/docs.rst
+++ b/pw_result/docs.rst
@@ -91,3 +91,8 @@ usage of Result in real code. Make sure to always run your own size reports to
check if Result is suitable for you.
.. include:: result_size
+
+Zephyr
+======
+To enable ``pw_result`` for Zephyr add ``CONFIG_PIGWEED_RESULT=y`` to the
+project's configuration.
diff --git a/pw_router/CMakeLists.txt b/pw_router/CMakeLists.txt
index cf80e79dd..a971d5765 100644
--- a/pw_router/CMakeLists.txt
+++ b/pw_router/CMakeLists.txt
@@ -25,21 +25,33 @@ pw_add_module_library(pw_router.static_router
PRIVATE_DEPS
pw_log
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_ROUTER_STATIC_ROUTER)
+ zephyr_link_libraries(pw_router.static_router)
+endif()
pw_add_module_library(pw_router.egress
PUBLIC_DEPS
pw_bytes
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_ROUTER_EGRESS)
+ zephyr_link_libraries(pw_router.egress)
+endif()
pw_add_module_library(pw_router.packet_parser
PUBLIC_DEPS
pw_bytes
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_ROUTER_PACKET_PARSER)
+ zephyr_link_libraries(pw_router.packet_parser)
+endif()
pw_add_module_library(pw_router.egress_function
PUBLIC_DEPS
pw_rpc.egress
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_ROUTER_EGRESS_FUNCTION)
+ zephyr_link_libraries(pw_router.egress_function)
+endif()
pw_auto_add_module_tests(pw_router
PRIVATE_DEPS
diff --git a/pw_router/Kconfig b/pw_router/Kconfig
new file mode 100644
index 000000000..090e34e24
--- /dev/null
+++ b/pw_router/Kconfig
@@ -0,0 +1,40 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+menuconfig PIGWEED_ROUTER
+ bool "Enable the Pigweed router library (pw_router)"
+
+if PIGWEED_ROUTER
+
+config PIGWEED_ROUTER_STATIC_ROUTER
+ bool "Enable the Pigweed static router library (pw_router.static_router)"
+ select PIGWEED_METRIC
+ select PIGWEED_ROUTER_EGRESS
+ select PIGWEED_ROUTER_PACKET_PARSER
+ select PIGWEED_SYNC_MUTEX
+ select PIGWEED_LOG
+
+config PIGWEED_ROUTER_EGRESS
+ bool "Enable the Pigweed router egress library (pw_router.egress)"
+ select PIGWEED_BYTES
+
+config PIGWEED_ROUTER_PACKET_PARSER
+ bool "Enable the Pigweed router packet parser library (pw_router.packet_parser)"
+ select PIGWEED_BYTES
+
+config PIGWEED_ROUTER_EGRESS_FUNCTION
+ bool "Enable the Pigweed router egress function library (pw_router.egress_function)"
+ select PIGWEED_RPC_EGRESS
+
+endif # PIGWEED_ROUTER
diff --git a/pw_router/docs.rst b/pw_router/docs.rst
index 8788826b1..3ce051c9a 100644
--- a/pw_router/docs.rst
+++ b/pw_router/docs.rst
@@ -68,3 +68,17 @@ Usage example
.. ``PacketParser`` implementation and a single route using an ``EgressFunction``.
.. .. include:: static_router_size
+
+Zephyr
+======
+To enable ``pw_router.*`` for Zephyr add ``CONFIG_PIGWEED_ROUTER=y`` to the
+project's configuration. This will enable the Kconfig menu for the following:
+
+* ``pw_router.static_router`` which can be enabled via
+ ``CONFIG_PIGWEED_ROUTER_STATIC_ROUTER=y``.
+* ``pw_router.egress`` which can be enabled via
+ ``CONFIG_PIGWEED_ROUTER_EGRESS=y``.
+* ``pw_router.packet_parser`` which can be enabled via
+ ``CONFIG_PIGWEED_ROUTER_PACKET_PARSER=y``.
+* ``pw_router.egress_function`` which can be enabled via
+ ``CONFIG_PIGWEED_ROUTER_EGRESS_FUNCTION=y``. \ No newline at end of file
diff --git a/pw_rpc/CMakeLists.txt b/pw_rpc/CMakeLists.txt
index e7093db1f..f8bc41417 100644
--- a/pw_rpc/CMakeLists.txt
+++ b/pw_rpc/CMakeLists.txt
@@ -34,6 +34,9 @@ pw_add_module_library(pw_rpc.server
PRIVATE_DEPS
pw_log
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_SERVER)
+ zephyr_link_libraries(pw_rpc.server)
+endif()
pw_add_module_library(pw_rpc.client
SOURCES
@@ -45,6 +48,9 @@ pw_add_module_library(pw_rpc.client
PRIVATE_DEPS
pw_log
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_CLIENT)
+ zephyr_link_libraries(pw_rpc.client)
+endif()
pw_add_module_library(pw_rpc.client_server
SOURCES
@@ -53,6 +59,9 @@ pw_add_module_library(pw_rpc.client_server
pw_rpc.client
pw_rpc.server
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_CLIENT_SERVER)
+ zephyr_link_libraries(pw_rpc.client_server)
+endif()
pw_add_module_library(pw_rpc.common
SOURCES
@@ -70,6 +79,9 @@ pw_add_module_library(pw_rpc.common
PRIVATE_DEPS
pw_log
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_COMMON)
+ zephyr_link_libraries(pw_rpc.common)
+endif()
if (NOT "${pw_sync.mutex_BACKEND}" STREQUAL "pw_sync.mutex.NO_BACKEND_SET" AND
NOT "${pw_sync.mutex_BACKEND}" STREQUAL "")
@@ -81,6 +93,9 @@ pw_add_module_library(pw_rpc.synchronized_channel_output
pw_rpc.common
pw_sync.mutex
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_SYNCHRONIZED_CHANNEL_OUTPUT)
+ zephyr_link_libraries(pw_rpc.synchronized_channel_output)
+endif()
pw_add_module_library(pw_rpc.test_utils
SOURCES
diff --git a/pw_rpc/Kconfig b/pw_rpc/Kconfig
new file mode 100644
index 000000000..66b2a61b3
--- /dev/null
+++ b/pw_rpc/Kconfig
@@ -0,0 +1,53 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+menuconfig PIGWEED_RPC
+ bool "Pigweed RPC submodule"
+
+if PIGWEED_RPC
+
+rsource "nanopb/Kconfig"
+
+config PIGWEED_RPC_SERVER
+ bool "Enable Pigweed RPC server library (pw_rpc.server)"
+ select PIGWEED_RPC_COMMON
+ select PIGWEED_LOG
+
+config PIGWEED_RPC_CLIENT
+ bool "Enable Pigweed RPC client library (pw_rpc.client)"
+ select PIGWEED_RPC_COMMON
+ select PIGWEED_RESULT
+ select PIGWEED_LOG
+
+config PIGWEED_RPC_CLIENT_SERVER
+ bool "Enable Pigweed RPC client-server library (pw_rpc.client_server)"
+ select PIGWEED_RPC_CLIENT
+ select PIGWEED_RPC_SERVER
+
+config PIGWEED_RPC_COMMON
+ bool "Enable Pigweed RPC common library (pw_rpc.common)"
+ select PIGWEED_ASSERT
+ select PIGWEED_BYTES
+ select PIGWEED_CONTAINERS
+ select PIGWEED_FUNCTION
+ select PIGWEED_SPAN
+ select PIGWEED_STATUS
+ select PIGWEED_LOG
+
+config PIGWEED_RPC_SYNCHRONIZED_CHANNEL_OUTPUT
+ bool "Enable Pigweed RPC synchronized channel output library (pw_rpc.synchronized_channel_output)"
+ select PIGWEED_RPC_COMMON
+ select PIGWEED_SYNC_MUTEX
+
+endif # PIGWEED_RPC
diff --git a/pw_rpc/docs.rst b/pw_rpc/docs.rst
index 072ffcf6a..b8af1a0aa 100644
--- a/pw_rpc/docs.rst
+++ b/pw_rpc/docs.rst
@@ -1038,3 +1038,16 @@ streaming RPC call object (``ClientWriter`` or ``ClientReaderWriter``) can be
used as a ``pw::rpc::Writer&``. On the server side, a server or bidirectional
streaming RPC call object (``ServerWriter`` or ``ServerReaderWriter``) can be
used as a ``pw::rpc::Writer&``.
+
+Zephyr
+======
+To enable ``pw_rpc.*`` for Zephyr add ``CONFIG_PIGWEED_RPC=y`` to the project's
+configuration. This will enable the Kconfig menu for the following:
+
+* ``pw_rpc.server`` which can be enabled via ``CONFIG_PIGWEED_RPC_SERVER=y``.
+* ``pw_rpc.client`` which can be enabled via ``CONFIG_PIGWEED_RPC_CLIENT=y``.
+* ``pw_rpc.client_server`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_CLIENT_SERVER=y``.
+* ``pw_rpc.common` which can be enabled via ``CONFIG_PIGWEED_RPC_COMMON=y``.
+* ``pw_rpc.synchronized_channel_output`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_SYNCHRONIZED_CHANNEL_OUTPUT=y``.
diff --git a/pw_rpc/nanopb/CMakeLists.txt b/pw_rpc/nanopb/CMakeLists.txt
index 5ae28f5b4..2b5d36cf7 100644
--- a/pw_rpc/nanopb/CMakeLists.txt
+++ b/pw_rpc/nanopb/CMakeLists.txt
@@ -24,6 +24,9 @@ pw_add_module_library(pw_rpc.nanopb.method
PRIVATE_DEPS
pw_log
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_NANOPB_METHOD)
+ zephyr_link_libraries(pw_rpc.nanopb.method)
+endif()
pw_add_module_library(pw_rpc.nanopb.method_union
PUBLIC_DEPS
@@ -33,6 +36,9 @@ pw_add_module_library(pw_rpc.nanopb.method_union
PRIVATE_DEPS
pw_log
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_NANOPB_METHOD_UNION)
+ zephyr_link_libraries(pw_rpc.nanopb.method_union)
+endif()
pw_add_module_library(pw_rpc.nanopb.client
PUBLIC_DEPS
@@ -40,6 +46,9 @@ pw_add_module_library(pw_rpc.nanopb.client
pw_rpc.nanopb.common
pw_rpc.common
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_NANOPB_CLIENT)
+ zephyr_link_libraries(pw_rpc.nanopb.client)
+endif()
pw_add_module_library(pw_rpc.nanopb.common
SOURCES
@@ -50,11 +59,17 @@ pw_add_module_library(pw_rpc.nanopb.common
pw_rpc.common
pw_third_party.nanopb
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_NANOPB_COMMON)
+ zephyr_link_libraries(pw_rpc.nanopb.common)
+endif()
pw_add_module_library(pw_rpc.nanopb.echo_service
PUBLIC_DEPS
pw_rpc.protos.nanopb_rpc
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_RPC_NANOPB_ECHO_SERVICE)
+ zephyr_link_libraries(pw_rpc.nanopb.echo_service)
+endif()
pw_auto_add_module_tests(pw_rpc.nanopb
PRIVATE_DEPS
diff --git a/pw_rpc/nanopb/Kconfig b/pw_rpc/nanopb/Kconfig
new file mode 100644
index 000000000..649707fbb
--- /dev/null
+++ b/pw_rpc/nanopb/Kconfig
@@ -0,0 +1,53 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+menuconfig PIGWEED_RPC_NANOPB
+ bool "Pigweed RPC nanobp"
+
+if PIGWEED_RPC_NANOPB
+
+config PIGWEED_RPC_NANOPB_DIR
+ string "Optional 3rd party directory for nanopb"
+ help
+ The directory for the custom nanopb build rules to integrate with pigweed.
+
+config PIGWEED_RPC_NANOPB_METHOD
+ bool "Enable Pigweed RPC/Nanopb method library (pw_rpc.nanopb.method)"
+ select PIGWEED_RPC_NANOPB_COMMON
+ select PIGWEED_RPC_SERVER
+ select PIGWEED_LOG
+
+config PIGWEED_RPC_NANOPB_METHOD_UNION
+ bool "Enable Pigweed RPC/Nanopb method union library (pw_rpc.nanopb.method_union)"
+ select PIGWEED_RPC_NANOPB_METHOD
+ select PIGWEED_RPC_RAW
+ select PIGWEED_RPC_SERVER
+ select PIGWEED_LOG
+
+config PIGWEED_RPC_NANOPB_CLIENT
+ bool "Enable Pigweed RPC/Nanopb client library (pw_rpc.nanopb.client)"
+ select PIGWEED_FUNCTION
+ select PIGWEED_RPC_NANOPB_COMMON
+ select PIGWEED_RPC_COMMON
+
+config PIGWEED_RPC_NANOPB_COMMON
+ bool "Enable Pigweed RPC/Nanopb common library (pw_rpc.nanopb.common)"
+ select PIGWEED_BYTES
+ select PIGWEED_LOG
+ select PIGWEED_RPC_COMMON
+
+config PIGWEED_RPC_NANOPB_ECHO_SERVICE
+ bool "Enable Pigweed RPC/Nanopb echo service library (pw_rpc.nanopb.echo_service)"
+
+endif # PIGWEED_RPC_NANOPB \ No newline at end of file
diff --git a/pw_rpc/nanopb/docs.rst b/pw_rpc/nanopb/docs.rst
index c72c56f0e..5ed7010f1 100644
--- a/pw_rpc/nanopb/docs.rst
+++ b/pw_rpc/nanopb/docs.rst
@@ -262,3 +262,20 @@ service client and receive the response.
// Do other stuff now that we have the room information.
}
+
+Zephyr
+======
+To enable ``pw_rpc.nanopb.*`` for Zephyr add ``CONFIG_PIGWEED_RPC_NANOPB=y`` to
+the project's configuration. This will enable the Kconfig menu for the
+following:
+
+* ``pw_rpc.nanopb.method`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_NANOPB_METHOD=y``.
+* ``pw_rpc.nanopb.method_union`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_NANOPB_METHOD_UNION=y``.
+* ``pw_rpc.nanopb.client`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_NANOPB_CLIENT=y``.
+* ``pw_rpc.nanopb.common`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_NANOPB_COMMON=y``.
+* ``pw_rpc.nanopb.echo_service`` which can be enabled via
+ ``CONFIG_PIGWEED_RPC_NANOPB_ECHO_SERVICE=y``.
diff --git a/pw_span/CMakeLists.txt b/pw_span/CMakeLists.txt
index 9b229501f..a0a3b0d27 100644
--- a/pw_span/CMakeLists.txt
+++ b/pw_span/CMakeLists.txt
@@ -16,3 +16,7 @@ include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
pw_auto_add_simple_module(pw_span PUBLIC_DEPS pw_polyfill)
target_include_directories(pw_span PUBLIC public_overrides)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_SPAN)
+ zephyr_link_libraries(pw_span)
+endif()
diff --git a/pw_span/Kconfig b/pw_span/Kconfig
new file mode 100644
index 000000000..34ef65837
--- /dev/null
+++ b/pw_span/Kconfig
@@ -0,0 +1,17 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_SPAN
+ bool "Enable the Pigweed span library (pw_span)"
+ select PIGWEED_POLYFILL
diff --git a/pw_span/docs.rst b/pw_span/docs.rst
index c1bfcd0bc..63d44ba76 100644
--- a/pw_span/docs.rst
+++ b/pw_span/docs.rst
@@ -69,3 +69,8 @@ Pointer and size arguments can be replaced with a ``std::span``:
Compatibility
=============
Works with C++14, but some features require C++17.
+
+Zephyr
+======
+To enable ``pw_span`` for Zephyr add ``CONFIG_PIGWEED_SPAN=y`` to the project's
+configuration.
diff --git a/pw_status/CMakeLists.txt b/pw_status/CMakeLists.txt
index 3c5a0f043..2b8194d84 100644
--- a/pw_status/CMakeLists.txt
+++ b/pw_status/CMakeLists.txt
@@ -15,3 +15,7 @@
include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
pw_auto_add_simple_module(pw_status)
+
+if(Zephyr_FOUND AND CONFIG_PIGWEED_STATUS)
+ zephyr_link_libraries(pw_status)
+endif()
diff --git a/pw_status/Kconfig b/pw_status/Kconfig
new file mode 100644
index 000000000..9fd180af4
--- /dev/null
+++ b/pw_status/Kconfig
@@ -0,0 +1,16 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_STATUS
+ bool "Enable the Pigweed status library (pw_status)"
diff --git a/pw_status/docs.rst b/pw_status/docs.rst
index 3830d7a60..b4a89b6a1 100644
--- a/pw_status/docs.rst
+++ b/pw_status/docs.rst
@@ -293,3 +293,8 @@ the size from the StatusWithSize on ok.
Compatibility
=============
C++14
+
+Zephyr
+======
+To enable ``pw_status`` for Zephyr add ``CONFIG_PIGWEED_STATUS=y`` to the
+project's configuration.
diff --git a/pw_stream/CMakeLists.txt b/pw_stream/CMakeLists.txt
index f3af22211..430dd4b4d 100644
--- a/pw_stream/CMakeLists.txt
+++ b/pw_stream/CMakeLists.txt
@@ -24,6 +24,9 @@ pw_add_module_library(pw_stream
pw_span
pw_status
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_STREAM)
+ zephyr_link_libraries(pw_stream)
+endif()
pw_add_module_library(pw_stream.socket_stream
SOURCES
diff --git a/pw_stream/Kconfig b/pw_stream/Kconfig
new file mode 100644
index 000000000..8b8bb235c
--- /dev/null
+++ b/pw_stream/Kconfig
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_STREAM
+ bool "Enable Pigweed stream library (pw_stream)"
+ select PIGWEED_ASSERT
+ select PIGWEED_BYTES
+ select PIGWEED_RESULT
+ select PIGWEED_SPAN
+ select PIGWEED_STATUS
diff --git a/pw_stream/docs.rst b/pw_stream/docs.rst
index 1a435b54d..951e9d456 100644
--- a/pw_stream/docs.rst
+++ b/pw_stream/docs.rst
@@ -643,3 +643,8 @@ Dependencies
* :ref:`module-pw_span`
.. cpp:namespace-pop::
+
+Zephyr
+======
+To enable ``pw_stream`` for Zephyr add ``CONFIG_PIGWEED_STREAM=y`` to the
+project's configuration.
diff --git a/pw_string/CMakeLists.txt b/pw_string/CMakeLists.txt
index a4d12d304..eef5a93b2 100644
--- a/pw_string/CMakeLists.txt
+++ b/pw_string/CMakeLists.txt
@@ -22,3 +22,6 @@ pw_auto_add_simple_module(pw_string
pw_span
pw_status
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_STRING)
+ zephyr_link_libraries(pw_string)
+endif()
diff --git a/pw_string/Kconfig b/pw_string/Kconfig
new file mode 100644
index 000000000..fffa12a9c
--- /dev/null
+++ b/pw_string/Kconfig
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_STRING
+ bool "Enable Pigweed string library (pw_string)"
+ select PIGWEED_ASSERT
+ select PIGWEED_PREPROCESSOR
+ select PIGWEED_RESULT
+ select PIGWEED_SPAN
+ select PIGWEED_STATUS
diff --git a/pw_string/docs.rst b/pw_string/docs.rst
index c89f4ab6a..c44f5801b 100644
--- a/pw_string/docs.rst
+++ b/pw_string/docs.rst
@@ -187,3 +187,8 @@ Future work
* StringBuilder's fixed size cost can be dramatically reduced by limiting
support for 64-bit integers.
* Consider integrating with the tokenizer module.
+
+Zephyr
+======
+To enable ``pw_string`` for Zephyr add ``CONFIG_PIGWEED_STRING=y`` to the
+project's configuration.
diff --git a/pw_sync/CMakeLists.txt b/pw_sync/CMakeLists.txt
index c0c9ce00d..0be2f281d 100644
--- a/pw_sync/CMakeLists.txt
+++ b/pw_sync/CMakeLists.txt
@@ -23,6 +23,14 @@ pw_add_facade(pw_sync.mutex
pw_preprocessor
)
+pw_add_facade(pw_sync.binary_semaphore
+ SOURCES
+ binary_semaphore.cc
+ PUBLIC_DEPS
+ pw_chrono.system_clock
+ pw_preprocessor
+)
+
pw_add_module_library(pw_sync.lock_annotations
PUBLIC_DEPS
pw_preprocessor
diff --git a/pw_sync_zephyr/BUILD.gn b/pw_sync_zephyr/BUILD.gn
new file mode 100644
index 000000000..9a6699a8e
--- /dev/null
+++ b/pw_sync_zephyr/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_docgen/docs.gni")
+
+pw_doc_group("docs") {
+ sources = [ "docs.rst" ]
+}
diff --git a/pw_sync_zephyr/CMakeLists.txt b/pw_sync_zephyr/CMakeLists.txt
new file mode 100644
index 000000000..b035dc52b
--- /dev/null
+++ b/pw_sync_zephyr/CMakeLists.txt
@@ -0,0 +1,37 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+if(CONFIG_PIGWEED_SYNC_MUTEX)
+ pw_add_module_library(pw_sync_zephyr.mutex_backend
+ IMPLEMENTS_FACADES
+ pw_sync.mutex
+ )
+ pw_set_backend(pw_sync.mutex pw_sync_zephyr.mutex_backend)
+ zephyr_link_libraries(pw_sync_zephyr.mutex_backend)
+ zephyr_link_interface(pw_sync_zephyr.mutex_backend)
+endif()
+
+if(CONFIG_PIGWEED_SYNC_BINARY_SEMAPHORE)
+ pw_add_module_library(pw_sync_zephyr.binary_semaphore_backend
+ IMPLEMENTS_FACADES
+ pw_sync.binary_semaphore
+ SOURCES
+ binary_semaphore.cc
+ )
+ pw_set_backend(pw_sync.binary_semaphore pw_sync_zephyr.binary_semaphore_backend)
+ zephyr_link_libraries(pw_sync_zephyr.binary_semaphore_backend)
+ zephyr_link_interface(pw_sync_zephyr.binary_semaphore_backend)
+endif()
diff --git a/pw_sync_zephyr/Kconfig b/pw_sync_zephyr/Kconfig
new file mode 100644
index 000000000..2ca2e7dec
--- /dev/null
+++ b/pw_sync_zephyr/Kconfig
@@ -0,0 +1,31 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+menuconfig PIGWEED_SYNC
+ bool "Enable Pigweed's sync module (pw_sync)"
+
+if PIGWEED_SYNC
+
+config PIGWEED_SYNC_MUTEX
+ bool "Enable Pigweed mutex library (pw_sync.mutex)"
+ select PIGWEED_CHRONO_SYSTEM_CLOCK
+ select PIGWEED_POLYFILL
+ select PIGWEED_PREPROCESSOR
+
+config PIGWEED_SYNC_BINARY_SEMAPHORE
+ bool "Enable Pigweed binary semaphore library (pw_sync.binary_semaphore)"
+ select PIGWEED_CHRONO_SYSTEM_CLOCK
+ select PIGWEED_PREPROCESSOR
+
+endif # PIGWEED_SYNC
diff --git a/pw_sync_zephyr/binary_semaphore.cc b/pw_sync_zephyr/binary_semaphore.cc
new file mode 100644
index 000000000..082813769
--- /dev/null
+++ b/pw_sync_zephyr/binary_semaphore.cc
@@ -0,0 +1,42 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include "pw_sync/binary_semaphore.h"
+
+#include <kernel.h>
+
+namespace pw::sync {
+
+bool BinarySemaphore::try_acquire_for(chrono::SystemClock::duration timeout) {
+ // Use non-blocking try_acquire for negative and zero length durations.
+ if (timeout <= chrono::SystemClock::duration::zero()) {
+ return try_acquire();
+ }
+
+#ifndef CONFIG_TIMEOUT_64BIT
+ constexpr chrono::SystemClock::duration kMaxTimeoutMinusOne =
+ chrono::SystemClock::duration(K_FOREVER.ticks - 1);
+
+ while (timeout > kMaxTimeoutMinusOne) {
+ if (k_sem_take(&native_type_, K_TICKS(kMaxTimeoutMinusOne.count())) == 0) {
+ return true;
+ }
+ timeout -= kMaxTimeoutMinusOne;
+ }
+#endif // CONFIG_TIMEOUT_64BIT
+
+ return k_sem_take(&native_type_, K_TICKS(timeout.count())) == 0;
+}
+
+} // namespace pw::sync
diff --git a/pw_sync_zephyr/docs.rst b/pw_sync_zephyr/docs.rst
new file mode 100644
index 000000000..705c144f7
--- /dev/null
+++ b/pw_sync_zephyr/docs.rst
@@ -0,0 +1,16 @@
+.. _module-pw_sync_zephyr:
+
+================
+pw_sync_zephyr
+================
+
+--------
+Overview
+--------
+This sync backend implements the ``pw_sync`` facade. To enable, set
+``CONFIG_PIGWEED_SYNC=y``. After that, specific submodules can be enabled via
+the Kconfig menu.
+
+* ``pw_sync.mutex`` can be enabled via ``CONFIG_PIGWEED_SYNC_MUTEX``.
+* ``pw_sync.binary_semaphore`` can be enabled via
+ ``CONFIG_PIGWEED_SYNC_BINARY_SEMAPHORE``.
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h
new file mode 100644
index 000000000..9afe7ceb1
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h
@@ -0,0 +1,57 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+#include "pw_assert/assert.h"
+#include "pw_chrono/system_clock.h"
+#include "pw_interrupt/context.h"
+#include "pw_sync/binary_semaphore.h"
+
+namespace pw::sync {
+
+inline BinarySemaphore::BinarySemaphore() : native_type_() {
+ constexpr unsigned int kInitialCount = 0;
+ k_sem_init(&native_type_, kInitialCount, backend::kBinarySemaphoreMaxValue);
+}
+
+inline BinarySemaphore::~BinarySemaphore() = default;
+
+inline void BinarySemaphore::release() {
+ PW_DASSERT(!interrupt::InInterruptContext());
+ k_sem_give(&native_type_);
+}
+
+inline void BinarySemaphore::acquire() {
+ PW_DASSERT(!interrupt::InInterruptContext());
+ PW_ASSERT(k_sem_take(&native_type_, K_FOREVER) == 0);
+}
+
+inline bool BinarySemaphore::try_acquire() noexcept {
+ return k_sem_take(&native_type_, K_NO_WAIT) == 0;
+}
+
+inline bool BinarySemaphore::try_acquire_until(
+ chrono::SystemClock::time_point deadline) {
+ // Note that if this deadline is in the future, it will get rounded up by
+ // one whole tick due to how try_acquire_for is implemented.
+ return try_acquire_for(deadline - chrono::SystemClock::now());
+}
+
+inline BinarySemaphore::native_handle_type BinarySemaphore::native_handle() {
+ return native_type_;
+}
+
+} // namespace pw::sync
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h
new file mode 100644
index 000000000..946a93433
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h
@@ -0,0 +1,25 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+namespace pw::sync::backend {
+
+using NativeBinarySemaphore = struct k_sem;
+using NativeBinarySemaphoreHandle = NativeBinarySemaphore&;
+
+inline constexpr ptrdiff_t kBinarySemaphoreMaxValue = 1;
+
+} // namespace pw::sync::backend
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/mutex_inline.h b/pw_sync_zephyr/public/pw_sync_zephyr/mutex_inline.h
new file mode 100644
index 000000000..cbc9772f9
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/mutex_inline.h
@@ -0,0 +1,50 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+#include "pw_assert/assert.h"
+#include "pw_interrupt/context.h"
+#include "pw_sync/mutex.h"
+
+namespace pw::sync {
+
+inline Mutex::Mutex() : native_type_() { k_mutex_init(&native_type_); }
+
+inline Mutex::~Mutex() = default;
+
+inline void Mutex::lock() {
+ PW_DASSERT(!interrupt::InInterruptContext());
+ k_mutex_lock(&native_type_, K_FOREVER);
+ PW_DASSERT(native_type_.lock_count == 1);
+}
+
+inline bool Mutex::try_lock() {
+ PW_DASSERT(!interrupt::InInterruptContext());
+
+ bool result = k_mutex_lock(&native_type_, K_NO_WAIT) == 0;
+ PW_DASSERT(native_type_.lock_count <= 1);
+
+ return result;
+}
+
+inline void Mutex::unlock() {
+ PW_DASSERT(!interrupt::InInterruptContext());
+ PW_ASSERT(k_mutex_unlock(&native_type_) == 0);
+}
+
+inline Mutex::native_handle_type Mutex::native_handle() { return native_type_; }
+
+} // namespace pw::sync
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/mutex_native.h b/pw_sync_zephyr/public/pw_sync_zephyr/mutex_native.h
new file mode 100644
index 000000000..e1099e94c
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/mutex_native.h
@@ -0,0 +1,23 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include <kernel.h>
+
+namespace pw::sync::backend {
+
+using NativeMutex = struct k_mutex;
+using NativeMutexHandle = NativeMutex&;
+
+} // namespace pw::sync::backend
diff --git a/pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_inline.h b/pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_inline.h
new file mode 100644
index 000000000..73cd1945a
--- /dev/null
+++ b/pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_inline.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "pw_sync_zephyr/binary_semaphore_inline.h"
diff --git a/pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_native.h b/pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_native.h
new file mode 100644
index 000000000..8cf9cbde6
--- /dev/null
+++ b/pw_sync_zephyr/public_overrides/pw_sync_backend/binary_semaphore_native.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "pw_sync_zephyr/binary_semaphore_native.h"
diff --git a/pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_inline.h b/pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_inline.h
new file mode 100644
index 000000000..1bcdb2aac
--- /dev/null
+++ b/pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_inline.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "pw_sync_zephyr/mutex_inline.h"
diff --git a/pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_native.h b/pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_native.h
new file mode 100644
index 000000000..f02bbb73c
--- /dev/null
+++ b/pw_sync_zephyr/public_overrides/pw_sync_backend/mutex_native.h
@@ -0,0 +1,16 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "pw_sync_zephyr/mutex_native.h"
diff --git a/pw_sys_io_zephyr/BUILD.gn b/pw_sys_io_zephyr/BUILD.gn
new file mode 100644
index 000000000..9a6699a8e
--- /dev/null
+++ b/pw_sys_io_zephyr/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_docgen/docs.gni")
+
+pw_doc_group("docs") {
+ sources = [ "docs.rst" ]
+}
diff --git a/pw_sys_io_zephyr/CMakeLists.txt b/pw_sys_io_zephyr/CMakeLists.txt
new file mode 100644
index 000000000..4d1955f67
--- /dev/null
+++ b/pw_sys_io_zephyr/CMakeLists.txt
@@ -0,0 +1,28 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+if(NOT CONFIG_PIGWEED_SYS_IO)
+ return()
+endif()
+
+pw_auto_add_simple_module(pw_sys_io_zephyr
+ IMPLEMENTS_FACADE
+ pw_sys_io
+ PUBLIC_DEPS
+ zephyr_interface
+)
+pw_set_backend(pw_sys_io pw_sys_io_zephyr)
+zephyr_link_libraries(pw_sys_io_zephyr)
diff --git a/pw_sys_io_zephyr/Kconfig b/pw_sys_io_zephyr/Kconfig
new file mode 100644
index 000000000..efda27052
--- /dev/null
+++ b/pw_sys_io_zephyr/Kconfig
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_SYS_IO
+ bool "Enable the Zephyr system IO module"
+ select PIGWEED_SPAN
+ select PIGWEED_STATUS
diff --git a/pw_sys_io_zephyr/docs.rst b/pw_sys_io_zephyr/docs.rst
new file mode 100644
index 000000000..b9820ea70
--- /dev/null
+++ b/pw_sys_io_zephyr/docs.rst
@@ -0,0 +1,11 @@
+.. _module-pw_sys_io_zephyr:
+
+================
+pw_sys_io_zephyr
+================
+
+--------
+Overview
+--------
+This sys IO backend implements the ``pw_sys_io`` facade. To enable, set
+``CONFIG_PIGWEED_SYS_IO=y``.
diff --git a/pw_sys_io_zephyr/sys_io.cc b/pw_sys_io_zephyr/sys_io.cc
new file mode 100644
index 000000000..fe0faf57e
--- /dev/null
+++ b/pw_sys_io_zephyr/sys_io.cc
@@ -0,0 +1,47 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include "pw_sys_io/sys_io.h"
+
+#include <sys/printk.h>
+
+namespace pw::sys_io {
+
+Status ReadByte(std::byte*) { return Status::Unimplemented(); }
+
+Status TryReadByte(std::byte*) { return Status::Unimplemented(); }
+
+Status WriteByte(std::byte b) {
+ printk("%c", static_cast<char>(b));
+ return OkStatus();
+}
+
+StatusWithSize WriteLine(const std::string_view& s) {
+ size_t chars_written = 0;
+ StatusWithSize size_result = WriteBytes(std::as_bytes(std::span(s)));
+ if (!size_result.ok()) {
+ return size_result;
+ }
+ chars_written += size_result.size();
+
+ // Write trailing newline character.
+ Status result = WriteByte(static_cast<std::byte>('\n'));
+ if (result.ok()) {
+ chars_written++;
+ }
+
+ return StatusWithSize(result, chars_written);
+}
+
+} // namespace pw::sys_io
diff --git a/pw_varint/CMakeLists.txt b/pw_varint/CMakeLists.txt
index e7c4dc314..0092387e2 100644
--- a/pw_varint/CMakeLists.txt
+++ b/pw_varint/CMakeLists.txt
@@ -21,3 +21,6 @@ pw_auto_add_simple_module(pw_varint
pw_status
pw_stream
)
+if(Zephyr_FOUND AND CONFIG_PIGWEED_VARINT)
+ zephyr_link_libraries(pw_varint)
+endif()
diff --git a/pw_varint/Kconfig b/pw_varint/Kconfig
new file mode 100644
index 000000000..b43114dd1
--- /dev/null
+++ b/pw_varint/Kconfig
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_VARINT
+ bool "Enable Pigweed variable length int library (pw_varint)"
+ select PIGWEED_PREPROCESSOR
+ select PIGWEED_SPAN
diff --git a/pw_varint/docs.rst b/pw_varint/docs.rst
index db6c8f4d2..1d87fe61b 100644
--- a/pw_varint/docs.rst
+++ b/pw_varint/docs.rst
@@ -52,3 +52,8 @@ Reads a maximum of 10 bytes.
Dependencies
============
* ``pw_span``
+
+Zephyr
+======
+To enable ``pw_varint`` for Zephyr add ``CONFIG_PIGWEED_VARINT=y`` to the
+project's configuration.
diff --git a/zephyr/module.yml b/zephyr/module.yml
new file mode 100644
index 000000000..a9f574482
--- /dev/null
+++ b/zephyr/module.yml
@@ -0,0 +1,18 @@
+# Copyright 2021 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+name: pigweed
+build:
+ cmake: .
+ kconfig: Kconfig.zephyr