pw_thread_freertos: add FreeRTOS backends pw::this_thread

Adds id, yield, and sleep backends for pw::this_thread for use on
FreeRTOS.

Change-Id: I374f671880f060d195868fd05e94b0e592b0faad
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/30521
Commit-Queue: Ewout van Bekkum <ewout@google.com>
Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_thread_freertos/BUILD.gn b/pw_thread_freertos/BUILD.gn
new file mode 100644
index 0000000..24bb882
--- /dev/null
+++ b/pw_thread_freertos/BUILD.gn
@@ -0,0 +1,98 @@
+# Copyright 2020 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_build/target_types.gni")
+import("$dir_pw_chrono/backend.gni")
+import("$dir_pw_docgen/docs.gni")
+
+config("public_include_path") {
+  include_dirs = [ "public" ]
+  visibility = [ ":*" ]
+}
+
+config("backend_config") {
+  include_dirs = [ "public_overrides" ]
+  visibility = [ ":*" ]
+}
+
+# This target provides the backend for pw::thread::Id & pw::this_thread::get_id.
+pw_source_set("id") {
+  public_configs = [
+    ":public_include_path",
+    ":backend_config",
+  ]
+  public_deps = [
+    "$dir_pw_interrupt:context",
+    "$dir_pw_third_party/freertos",
+  ]
+  public = [
+    "public/pw_thread_freertos/id_inline.h",
+    "public/pw_thread_freertos/id_native.h",
+    "public_overrides/pw_thread_backend/id_inline.h",
+    "public_overrides/pw_thread_backend/id_native.h",
+  ]
+  deps = [ "$dir_pw_thread:id.facade" ]
+}
+
+# This target provides the backend for pw::this_thread::sleep_{for,until}.
+pw_source_set("sleep") {
+  public_configs = [
+    ":public_include_path",
+    ":backend_config",
+  ]
+  public = [
+    "public/pw_thread_freertos/sleep_inline.h",
+    "public_overrides/pw_thread_backend/sleep_inline.h",
+  ]
+  public_deps = [ "$dir_pw_chrono:system_clock" ]
+  sources = [ "sleep.cc" ]
+  deps = [
+    "$dir_pw_assert",
+    "$dir_pw_chrono_freertos:system_clock",
+    "$dir_pw_third_party/freertos",
+    "$dir_pw_thread:id",
+    "$dir_pw_thread:sleep.facade",
+  ]
+  assert(pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
+             pw_chrono_SYSTEM_CLOCK_BACKEND ==
+                 "$dir_pw_chrono_freertos:system_clock",
+         "The FreeRTOS pw::this_thread::sleep_{for,until} backend only works " +
+             "with the FreeRTOS pw::chrono::SystemClock backend " +
+             "(pw_chrono_SYSTEM_CLOCK_BACKEND = " +
+             "\"$dir_pw_chrono_freertos:system_clock\")")
+}
+
+# This target provides the backend for pw::this_thread::yield.
+pw_source_set("yield") {
+  public_configs = [
+    ":public_include_path",
+    ":backend_config",
+  ]
+  public = [
+    "public/pw_thread_freertos/yield_inline.h",
+    "public_overrides/pw_thread_backend/yield_inline.h",
+  ]
+  public_deps = [
+    "$dir_pw_assert",
+    "$dir_pw_third_party/freertos",
+    "$dir_pw_thread:id",
+  ]
+  deps = [ "$dir_pw_thread:yield.facade" ]
+}
+
+pw_doc_group("docs") {
+  sources = [ "docs.rst" ]
+}