pw_sync_threadx: allow a custom pw::chrono::SystemClock backend

Modifies the GN implementation for pw_sync_threadx to allow a
custom backend for pw::chrono::SystemClock which is not
pw_chrono_threadx:system_clock in case the TX time capability is
not enabled in a ThreadX configuration.

Change-Id: I1a4191425b4d2679472a86a388085c0ab64bedbe
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/28560
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_sync/backend.gni b/pw_sync/backend.gni
index 9e43ae6..59d8b48 100644
--- a/pw_sync/backend.gni
+++ b/pw_sync/backend.gni
@@ -24,4 +24,9 @@
 
   # Backend for the pw_sync module's spin lock.
   pw_sync_SPIN_LOCK_BACKEND = ""
+
+  # Whether the GN asserts should be silenced in ensuring that a compatible
+  # backend for pw_chrono_SYSTEM_CLOCK_BACKEND is chosen.
+  # Set to true to disable the asserts.
+  pw_sync_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK = false
 }
diff --git a/pw_sync_threadx/BUILD.gn b/pw_sync_threadx/BUILD.gn
index dc82a5a..0b6e478 100644
--- a/pw_sync_threadx/BUILD.gn
+++ b/pw_sync_threadx/BUILD.gn
@@ -17,6 +17,7 @@
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_chrono/backend.gni")
 import("$dir_pw_docgen/docs.gni")
+import("$dir_pw_sync/backend.gni")
 
 config("public_include_path") {
   include_dirs = [ "public" ]
@@ -28,94 +29,97 @@
   visibility = [ ":*" ]
 }
 
-# This target provides the backend for pw::sync::BinarySemaphore.
-pw_source_set("binary_semaphore") {
-  public_configs = [
-    ":public_include_path",
-    ":backend_config",
-  ]
-  public = [
-    "public/pw_sync_threadx/binary_semaphore_inline.h",
-    "public/pw_sync_threadx/binary_semaphore_native.h",
-    "public_overrides/pw_sync_backend/binary_semaphore_inline.h",
-    "public_overrides/pw_sync_backend/binary_semaphore_native.h",
-  ]
-  public_deps = [
-    "$dir_pw_assert",
-    "$dir_pw_chrono:system_clock",
-    "$dir_pw_interrupt:context",
-    "$dir_pw_third_party/threadx",
-  ]
-  sources = [ "binary_semaphore.cc" ]
-  deps = [
-    "$dir_pw_chrono_threadx:system_clock",
-    "$dir_pw_sync:binary_semaphore.facade",
-  ]
-  assert(pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
-             pw_chrono_SYSTEM_CLOCK_BACKEND ==
-                 "$dir_pw_chrono_threadx:system_clock",
-         "The ThreadX pw::sync::BinarySemaphore backend only works with the " +
-             "ThreadX pw::chrono::SystemClock backend.")
-}
+if (pw_chrono_SYSTEM_CLOCK_BACKEND != "") {
+  # This target provides the backend for pw::sync::BinarySemaphore.
+  pw_source_set("binary_semaphore") {
+    public_configs = [
+      ":public_include_path",
+      ":backend_config",
+    ]
+    public = [
+      "public/pw_sync_threadx/binary_semaphore_inline.h",
+      "public/pw_sync_threadx/binary_semaphore_native.h",
+      "public_overrides/pw_sync_backend/binary_semaphore_inline.h",
+      "public_overrides/pw_sync_backend/binary_semaphore_native.h",
+    ]
+    public_deps = [
+      "$dir_pw_assert",
+      "$dir_pw_chrono:system_clock",
+      "$dir_pw_interrupt:context",
+      "$dir_pw_third_party/threadx",
+    ]
+    sources = [ "binary_semaphore.cc" ]
+    deps = [
+      "$dir_pw_sync:binary_semaphore.facade",
+      pw_chrono_SYSTEM_CLOCK_BACKEND,
+    ]
+    assert(
+        pw_sync_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK ||
+            pw_chrono_SYSTEM_CLOCK_BACKEND ==
+                "$dir_pw_chrono_threadx:system_clock",
+        "The ThreadX pw::sync::BinarySemaphore backend only works with the " +
+            "ThreadX pw::chrono::SystemClock backend.")
+  }
 
-# This target provides the backend for pw::sync::CountingSemaphore.
-pw_source_set("counting_semaphore") {
-  public_configs = [
-    ":public_include_path",
-    ":backend_config",
-  ]
-  public = [
-    "public/pw_sync_threadx/counting_semaphore_inline.h",
-    "public/pw_sync_threadx/counting_semaphore_native.h",
-    "public_overrides/pw_sync_backend/counting_semaphore_inline.h",
-    "public_overrides/pw_sync_backend/counting_semaphore_native.h",
-  ]
-  public_deps = [
-    "$dir_pw_assert",
-    "$dir_pw_chrono:system_clock",
-    "$dir_pw_interrupt:context",
-    "$dir_pw_third_party/threadx",
-  ]
-  sources = [ "counting_semaphore.cc" ]
-  deps = [
-    "$dir_pw_chrono_threadx:system_clock",
-    "$dir_pw_sync:counting_semaphore.facade",
-  ]
-  assert(pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
-             pw_chrono_SYSTEM_CLOCK_BACKEND ==
-                 "$dir_pw_chrono_threadx:system_clock",
-         "The ThreadX pw::sync::CountingSemaphore backend only works with " +
-             "the ThreadX pw::chrono::SystemClock backend.")
-}
+  # This target provides the backend for pw::sync::CountingSemaphore.
+  pw_source_set("counting_semaphore") {
+    public_configs = [
+      ":public_include_path",
+      ":backend_config",
+    ]
+    public = [
+      "public/pw_sync_threadx/counting_semaphore_inline.h",
+      "public/pw_sync_threadx/counting_semaphore_native.h",
+      "public_overrides/pw_sync_backend/counting_semaphore_inline.h",
+      "public_overrides/pw_sync_backend/counting_semaphore_native.h",
+    ]
+    public_deps = [
+      "$dir_pw_assert",
+      "$dir_pw_chrono:system_clock",
+      "$dir_pw_interrupt:context",
+      "$dir_pw_third_party/threadx",
+    ]
+    sources = [ "counting_semaphore.cc" ]
+    deps = [
+      "$dir_pw_sync:counting_semaphore.facade",
+      pw_chrono_SYSTEM_CLOCK_BACKEND,
+    ]
+    assert(pw_sync_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK ||
+               pw_chrono_SYSTEM_CLOCK_BACKEND ==
+                   "$dir_pw_chrono_threadx:system_clock",
+           "The ThreadX pw::sync::CountingSemaphore backend only works with " +
+               "the ThreadX pw::chrono::SystemClock backend.")
+  }
 
-# This target provides the backend for pw::sync::Mutex.
-pw_source_set("mutex") {
-  public_configs = [
-    ":public_include_path",
-    ":backend_config",
-  ]
-  public = [
-    "public/pw_sync_threadx/mutex_inline.h",
-    "public/pw_sync_threadx/mutex_native.h",
-    "public_overrides/pw_sync_backend/mutex_inline.h",
-    "public_overrides/pw_sync_backend/mutex_native.h",
-  ]
-  public_deps = [
-    "$dir_pw_assert",
-    "$dir_pw_chrono:system_clock",
-    "$dir_pw_interrupt:context",
-    "$dir_pw_third_party/threadx",
-  ]
-  sources = [ "mutex.cc" ]
-  deps = [
-    "$dir_pw_chrono_threadx:system_clock",
-    "$dir_pw_sync:mutex.facade",
-  ]
-  assert(pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
-             pw_chrono_SYSTEM_CLOCK_BACKEND ==
-                 "$dir_pw_chrono_threadx:system_clock",
-         "The ThreadX pw::sync::Mutex backend only works with the ThreadX " +
-             "pw::chrono::SystemClock backend.")
+  # This target provides the backend for pw::sync::Mutex.
+  pw_source_set("mutex") {
+    public_configs = [
+      ":public_include_path",
+      ":backend_config",
+    ]
+    public = [
+      "public/pw_sync_threadx/mutex_inline.h",
+      "public/pw_sync_threadx/mutex_native.h",
+      "public_overrides/pw_sync_backend/mutex_inline.h",
+      "public_overrides/pw_sync_backend/mutex_native.h",
+    ]
+    public_deps = [
+      "$dir_pw_assert",
+      "$dir_pw_chrono:system_clock",
+      "$dir_pw_interrupt:context",
+      "$dir_pw_third_party/threadx",
+    ]
+    sources = [ "mutex.cc" ]
+    deps = [
+      "$dir_pw_sync:mutex.facade",
+      pw_chrono_SYSTEM_CLOCK_BACKEND,
+    ]
+    assert(pw_sync_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK ||
+               pw_chrono_SYSTEM_CLOCK_BACKEND ==
+                   "$dir_pw_chrono_threadx:system_clock",
+           "The ThreadX pw::sync::Mutex backend only works with the ThreadX " +
+               "pw::chrono::SystemClock backend.")
+  }
 }
 
 # This target provides the backend for pw::sync::SpinLock, note that this
diff --git a/pw_sync_threadx/docs.rst b/pw_sync_threadx/docs.rst
index f7b0eaa..b6fac08 100644
--- a/pw_sync_threadx/docs.rst
+++ b/pw_sync_threadx/docs.rst
@@ -6,3 +6,8 @@
 This is a set of backends for pw_sync based on ThreadX. It is not ready for use,
 and is under construction.
 
+It is possible, if necessary, to use pw_sync_threadx without using the Pigweed
+provided pw_chrono_threadx in case the ThreadX time API (``tx_time_get()``)) is
+not available (i.e. ``TX_NO_TIMER`` is set). You are responsible for ensuring
+that the chrono backend provided has counts which match the ThreadX tick based
+API.