1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_third_party_freertos: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker======== 4*61c4878aSAndroid Build Coastguard WorkerFreeRTOS 5*61c4878aSAndroid Build Coastguard Worker======== 6*61c4878aSAndroid Build Coastguard Worker 7*61c4878aSAndroid Build Coastguard WorkerThe ``$dir_pw_third_party/freertos/`` module contains various helpers to use 8*61c4878aSAndroid Build Coastguard WorkerFreeRTOS, including Pigweed backend modules which depend on FreeRTOS. 9*61c4878aSAndroid Build Coastguard Worker 10*61c4878aSAndroid Build Coastguard Worker------------- 11*61c4878aSAndroid Build Coastguard WorkerBuild Support 12*61c4878aSAndroid Build Coastguard Worker------------- 13*61c4878aSAndroid Build Coastguard WorkerThis module provides support to compile FreeRTOS with GN, CMake, and Bazel. 14*61c4878aSAndroid Build Coastguard WorkerThis is required when compiling backends modules for FreeRTOS. 15*61c4878aSAndroid Build Coastguard Worker 16*61c4878aSAndroid Build Coastguard WorkerGN 17*61c4878aSAndroid Build Coastguard Worker== 18*61c4878aSAndroid Build Coastguard WorkerIn order to use this you are expected to configure the following variables from 19*61c4878aSAndroid Build Coastguard Worker``$dir_pw_third_party/freertos:freertos.gni``: 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard Worker#. Set the GN ``dir_pw_third_party_freertos`` to the path of the FreeRTOS 22*61c4878aSAndroid Build Coastguard Worker installation. 23*61c4878aSAndroid Build Coastguard Worker#. Set ``pw_third_party_freertos_CONFIG`` to a ``pw_source_set`` which provides 24*61c4878aSAndroid Build Coastguard Worker the FreeRTOS config header. 25*61c4878aSAndroid Build Coastguard Worker#. Set ``pw_third_party_freertos_PORT`` to a ``pw_source_set`` which provides 26*61c4878aSAndroid Build Coastguard Worker the FreeRTOS port specific includes and sources. 27*61c4878aSAndroid Build Coastguard Worker 28*61c4878aSAndroid Build Coastguard WorkerAfter this is done a ``pw_source_set`` for the FreeRTOS library is created at 29*61c4878aSAndroid Build Coastguard Worker``$dir_pw_third_party/freertos``. 30*61c4878aSAndroid Build Coastguard Worker 31*61c4878aSAndroid Build Coastguard WorkerCMake 32*61c4878aSAndroid Build Coastguard Worker===== 33*61c4878aSAndroid Build Coastguard WorkerIn order to use this you are expected to set the following variables from 34*61c4878aSAndroid Build Coastguard Worker``third_party/freertos/CMakeLists.txt``: 35*61c4878aSAndroid Build Coastguard Worker 36*61c4878aSAndroid Build Coastguard Worker#. Set ``dir_pw_third_party_freertos`` to the path of the FreeRTOS installation. 37*61c4878aSAndroid Build Coastguard Worker#. Set ``pw_third_party_freertos_CONFIG`` to a library target which provides 38*61c4878aSAndroid Build Coastguard Worker the FreeRTOS config header. 39*61c4878aSAndroid Build Coastguard Worker#. Set ``pw_third_party_freertos_PORT`` to a library target which provides 40*61c4878aSAndroid Build Coastguard Worker the FreeRTOS port specific includes and sources. 41*61c4878aSAndroid Build Coastguard Worker 42*61c4878aSAndroid Build Coastguard WorkerBazel 43*61c4878aSAndroid Build Coastguard Worker===== 44*61c4878aSAndroid Build Coastguard WorkerPigweed provides its own BUILD.bazel file for FreeRTOS, at 45*61c4878aSAndroid Build Coastguard Worker``third_party/freertos/freertos.BUILD.bazel``. You can use it directly in 46*61c4878aSAndroid Build Coastguard Workeryour ``WORKSPACE``, like so: 47*61c4878aSAndroid Build Coastguard Worker 48*61c4878aSAndroid Build Coastguard Worker.. code-block:: python 49*61c4878aSAndroid Build Coastguard Worker 50*61c4878aSAndroid Build Coastguard Worker http_archive( 51*61c4878aSAndroid Build Coastguard Worker name = "freertos", 52*61c4878aSAndroid Build Coastguard Worker build_file = "@pigweed//third_party/freertos:freertos.BUILD.bazel", 53*61c4878aSAndroid Build Coastguard Worker sha256 = "89af32b7568c504624f712c21fe97f7311c55fccb7ae6163cda7adde1cde7f62", 54*61c4878aSAndroid Build Coastguard Worker strip_prefix = "FreeRTOS-Kernel-10.5.1", 55*61c4878aSAndroid Build Coastguard Worker urls = ["https://github.com/FreeRTOS/FreeRTOS-Kernel/archive/refs/tags/V10.5.1.tar.gz"], 56*61c4878aSAndroid Build Coastguard Worker ) 57*61c4878aSAndroid Build Coastguard Worker 58*61c4878aSAndroid Build Coastguard WorkerThe FreeRTOS build is configured through `constraint_settings 59*61c4878aSAndroid Build Coastguard Worker<https://bazel.build/reference/be/platforms-and-toolchains#constraint_setting>`_. 60*61c4878aSAndroid Build Coastguard WorkerThe `platform <https://bazel.build/extending/platforms>`_ you are building for 61*61c4878aSAndroid Build Coastguard Workermust specify values for the following settings: 62*61c4878aSAndroid Build Coastguard Worker 63*61c4878aSAndroid Build Coastguard Worker* ``@freertos//:port``, to set which FreeRTOS port to use. You can 64*61c4878aSAndroid Build Coastguard Worker select a value from those defined in 65*61c4878aSAndroid Build Coastguard Worker ``third_party/freertos/freertos.BUILD.bazel`` (for example, 66*61c4878aSAndroid Build Coastguard Worker ``@freertos//:port_ARM_CM4F``). 67*61c4878aSAndroid Build Coastguard Worker* ``@freertos//:malloc``, to set which FreeRTOS malloc implementation to use. 68*61c4878aSAndroid Build Coastguard Worker You can select a value from those defined in 69*61c4878aSAndroid Build Coastguard Worker ``third_party/freertos/BUILD.bazel`` (for example, 70*61c4878aSAndroid Build Coastguard Worker ``@freertos//:malloc_heap_1``). 71*61c4878aSAndroid Build Coastguard Worker* ``@freertos//:disable_task_statics_setting``, to determine whether statics 72*61c4878aSAndroid Build Coastguard Worker should be disabled during compilation of the tasks.c source file (see next 73*61c4878aSAndroid Build Coastguard Worker section). This setting has only two possible values, also defined in 74*61c4878aSAndroid Build Coastguard Worker ``third_party/freertos/BUILD.bazel``: ``@freertos//:disable_task_statics`` 75*61c4878aSAndroid Build Coastguard Worker and ``@freertos//:no_disable_task_statics``. 76*61c4878aSAndroid Build Coastguard Worker 77*61c4878aSAndroid Build Coastguard WorkerIn addition, you need to set the ``@freertos//:freertos_config`` label flag to 78*61c4878aSAndroid Build Coastguard Workerpoint to the library target providing the FreeRTOS config header. See 79*61c4878aSAndroid Build Coastguard Worker:ref:`docs-build_system-bazel_configuration` for a discussion of how to work 80*61c4878aSAndroid Build Coastguard Workerwith our label flags. 81*61c4878aSAndroid Build Coastguard Worker 82*61c4878aSAndroid Build Coastguard Worker 83*61c4878aSAndroid Build Coastguard Worker.. _third_party-freertos_disable_task_statics: 84*61c4878aSAndroid Build Coastguard Worker 85*61c4878aSAndroid Build Coastguard WorkerLinking against FreeRTOS kernel's static internals 86*61c4878aSAndroid Build Coastguard Worker================================================== 87*61c4878aSAndroid Build Coastguard WorkerIn order to link against internal kernel data structures through the use of 88*61c4878aSAndroid Build Coastguard Workerextern "C", statics can be optionally disabled for the tasks.c source file 89*61c4878aSAndroid Build Coastguard Workerto enable use of things like pw_thread_freertos/util.h's ``ForEachThread``. 90*61c4878aSAndroid Build Coastguard Worker 91*61c4878aSAndroid Build Coastguard WorkerTo facilitate this, Pigweed offers an opt-in option which can be enabled, 92*61c4878aSAndroid Build Coastguard Worker 93*61c4878aSAndroid Build Coastguard Worker* in GN through ``pw_third_party_freertos_DISABLE_TASKS_STATICS = true``, 94*61c4878aSAndroid Build Coastguard Worker* in CMake through ``set(pw_third_party_freertos_DISABLE_TASKS_STATICS ON 95*61c4878aSAndroid Build Coastguard Worker CACHE BOOL "" FORCE)``, 96*61c4878aSAndroid Build Coastguard Worker* in Bazel through ``@freertos//:disable_task_statics``. 97*61c4878aSAndroid Build Coastguard Worker 98*61c4878aSAndroid Build Coastguard WorkerThis redefines ``static`` to nothing for the ``Source/tasks.c`` FreeRTOS source 99*61c4878aSAndroid Build Coastguard Workerfile when building through ``$dir_pw_third_party/freertos`` in GN and through 100*61c4878aSAndroid Build Coastguard Worker``pw_third_party.freertos`` in CMake. 101*61c4878aSAndroid Build Coastguard Worker 102*61c4878aSAndroid Build Coastguard Worker.. attention:: If you use this, make sure that your FreeRTOSConfig.h and port 103*61c4878aSAndroid Build Coastguard Worker does not rely on any statics inside of tasks.c. For example, you cannot use 104*61c4878aSAndroid Build Coastguard Worker ``PW_CHECK`` for ``configASSERT`` when this is enabled. 105*61c4878aSAndroid Build Coastguard Worker 106*61c4878aSAndroid Build Coastguard WorkerAs a helper ``PW_THIRD_PARTY_FREERTOS_NO_STATICS=1`` is defined when statics are 107*61c4878aSAndroid Build Coastguard Workerdisabled to help manage conditional configuration. 108*61c4878aSAndroid Build Coastguard Worker 109*61c4878aSAndroid Build Coastguard WorkerWe highly recommend :ref:`our configASSERT wrapper 110*61c4878aSAndroid Build Coastguard Worker<third_party-freertos_config_assert>` when using this configuration, which 111*61c4878aSAndroid Build Coastguard Workercorrectly sets ``configASSERT`` to use ``PW_CHECK`` and ``PW_ASSERT`` for you. 112*61c4878aSAndroid Build Coastguard Worker 113*61c4878aSAndroid Build Coastguard Worker----------------------------- 114*61c4878aSAndroid Build Coastguard WorkerOS Abstraction Layers Support 115*61c4878aSAndroid Build Coastguard Worker----------------------------- 116*61c4878aSAndroid Build Coastguard WorkerSupport for Pigweed's :ref:`docs-os` are provided for FreeRTOS via the following 117*61c4878aSAndroid Build Coastguard Workermodules: 118*61c4878aSAndroid Build Coastguard Worker 119*61c4878aSAndroid Build Coastguard Worker* :ref:`module-pw_chrono_freertos` 120*61c4878aSAndroid Build Coastguard Worker* :ref:`module-pw_sync_freertos` 121*61c4878aSAndroid Build Coastguard Worker* :ref:`module-pw_thread_freertos` 122*61c4878aSAndroid Build Coastguard Worker 123*61c4878aSAndroid Build Coastguard WorkerBackend group 124*61c4878aSAndroid Build Coastguard Worker============= 125*61c4878aSAndroid Build Coastguard WorkerIn GN, import ``pw_targets_FREERTOS_BACKEND_GROUP`` to set backends for 126*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_chrono`, :ref:`module-pw_sync`, and :ref:`module-pw_thread` for 127*61c4878aSAndroid Build Coastguard WorkerFreeRTOS. The backends can be overridden individually if needed. 128*61c4878aSAndroid Build Coastguard Worker 129*61c4878aSAndroid Build Coastguard Worker.. code-block:: none 130*61c4878aSAndroid Build Coastguard Worker 131*61c4878aSAndroid Build Coastguard Worker # Toolchain configuration 132*61c4878aSAndroid Build Coastguard Worker import("$dir_pigweed/targets/common/freertos.gni") 133*61c4878aSAndroid Build Coastguard Worker 134*61c4878aSAndroid Build Coastguard Worker _backend_setting_example = { 135*61c4878aSAndroid Build Coastguard Worker # Since this target is using FreeRTOS, adopt FreeRTOS backends by default. 136*61c4878aSAndroid Build Coastguard Worker forward_variables_from(pw_targets_FREERTOS_BACKEND_GROUP, "*") 137*61c4878aSAndroid Build Coastguard Worker 138*61c4878aSAndroid Build Coastguard Worker # Set other backends or override the default FreeRTOS selections if needed. 139*61c4878aSAndroid Build Coastguard Worker ... 140*61c4878aSAndroid Build Coastguard Worker } 141*61c4878aSAndroid Build Coastguard Worker 142*61c4878aSAndroid Build Coastguard Worker.. _third_party-freertos_config_assert: 143*61c4878aSAndroid Build Coastguard Worker 144*61c4878aSAndroid Build Coastguard Worker-------------------------- 145*61c4878aSAndroid Build Coastguard WorkerconfigASSERT and pw_assert 146*61c4878aSAndroid Build Coastguard Worker-------------------------- 147*61c4878aSAndroid Build Coastguard WorkerTo make it easier to use :ref:`module-pw_assert` with FreeRTOS a helper header 148*61c4878aSAndroid Build Coastguard Workeris provided under ``pw_third_party/freertos/config_assert.h`` which defines 149*61c4878aSAndroid Build Coastguard Worker``configASSERT`` for you using Pigweed's assert system for your 150*61c4878aSAndroid Build Coastguard Worker``FreeRTOSConfig.h`` if you chose to use it. 151*61c4878aSAndroid Build Coastguard Worker 152*61c4878aSAndroid Build Coastguard Worker.. code-block:: cpp 153*61c4878aSAndroid Build Coastguard Worker 154*61c4878aSAndroid Build Coastguard Worker // Instead of defining configASSERT, simply include this header in its place. 155*61c4878aSAndroid Build Coastguard Worker #include "pw_third_party/freertos/config_assert.h" 156*61c4878aSAndroid Build Coastguard Worker 157*61c4878aSAndroid Build Coastguard Worker--------------------------------------------- 158*61c4878aSAndroid Build Coastguard WorkerFreeRTOS application function implementations 159*61c4878aSAndroid Build Coastguard Worker--------------------------------------------- 160*61c4878aSAndroid Build Coastguard Worker.. doxygengroup:: FreeRTOS_application_functions 161