1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_chre: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker======= 4*61c4878aSAndroid Build Coastguard Workerpw_chre 5*61c4878aSAndroid Build Coastguard Worker======= 6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module:: 7*61c4878aSAndroid Build Coastguard Worker :name: pw_chre 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard WorkerThe `Context Hub Runtime Environment <https://source.android.com/docs/core/interaction/contexthub>`_ 10*61c4878aSAndroid Build Coastguard Worker(CHRE) is Android's platform for developing always-on applications called 11*61c4878aSAndroid Build Coastguard Workernanoapps. These nanoapps run on a vendor-specific processor which is more power 12*61c4878aSAndroid Build Coastguard Workerefficient. Nanoapps use the CHRE API, which is standardized across platforms, 13*61c4878aSAndroid Build Coastguard Workerallowing them to be code-compatible across devices. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard WorkerThis module implements a Pigweed backend to CHRE. In order to use this module, 16*61c4878aSAndroid Build Coastguard Worker``dir_pw_third_party_chre`` must point to the directory to the CHRE library. 17*61c4878aSAndroid Build Coastguard Worker 18*61c4878aSAndroid Build Coastguard Worker----------- 19*61c4878aSAndroid Build Coastguard WorkerGet started 20*61c4878aSAndroid Build Coastguard Worker----------- 21*61c4878aSAndroid Build Coastguard Worker 22*61c4878aSAndroid Build Coastguard WorkerTo integrate ``pw_chre`` with your project: 23*61c4878aSAndroid Build Coastguard Worker 24*61c4878aSAndroid Build Coastguard Worker- Call the initialization functions and start the event loop. 25*61c4878aSAndroid Build Coastguard Worker- Handle messages from the application processor and connect them through to 26*61c4878aSAndroid Build Coastguard Worker the CHRE runtime. 27*61c4878aSAndroid Build Coastguard Worker- Implement the functions in ``pw_chre/host_link``. This is how CHRE sends 28*61c4878aSAndroid Build Coastguard Worker messages to the application processor. 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard Worker 31*61c4878aSAndroid Build Coastguard Worker``$pw_chre:chre_example`` runs the CHRE environment using ``pw_system``. 32*61c4878aSAndroid Build Coastguard WorkerThis also loads several static example nanoapps from the CHRE codebase by 33*61c4878aSAndroid Build Coastguard Workercompiling them into the executable. This can be a helpful reference. 34*61c4878aSAndroid Build Coastguard Worker 35*61c4878aSAndroid Build Coastguard WorkerCHRE is implemented using the following Pigweed modules for functionality: 36*61c4878aSAndroid Build Coastguard Worker 37*61c4878aSAndroid Build Coastguard Worker- ``pw_chrono:system_timer``: implements getting monotonic time 38*61c4878aSAndroid Build Coastguard Worker- ``pw_log``: implements logging to the application processor 39*61c4878aSAndroid Build Coastguard Worker- ``pw_assert``: implements crash handling 40*61c4878aSAndroid Build Coastguard Worker- ``pw_sync``: implements mutual exclusion primitives 41*61c4878aSAndroid Build Coastguard Worker- ``malloc/free``: implements virtual memory allocation 42*61c4878aSAndroid Build Coastguard Worker (This may be eventually replaced with a pigweed module) 43*61c4878aSAndroid Build Coastguard Worker 44*61c4878aSAndroid Build Coastguard Worker---------------------- 45*61c4878aSAndroid Build Coastguard WorkerCurrent implementation 46*61c4878aSAndroid Build Coastguard Worker---------------------- 47*61c4878aSAndroid Build Coastguard Worker 48*61c4878aSAndroid Build Coastguard WorkerAs mentioned at the top of this document, ``pw_chre`` is extremely experimental. 49*61c4878aSAndroid Build Coastguard WorkerOnly a few parts of CHRE have been tested. There are likely to be bugs and 50*61c4878aSAndroid Build Coastguard Workerunimplemented behavior. The lists below track the current state and will 51*61c4878aSAndroid Build Coastguard Workerbe updated as things change. 52*61c4878aSAndroid Build Coastguard Worker 53*61c4878aSAndroid Build Coastguard WorkerSupported and tested behavior: 54*61c4878aSAndroid Build Coastguard Worker 55*61c4878aSAndroid Build Coastguard Worker- Loading static nanoapps. 56*61c4878aSAndroid Build Coastguard Worker- The following sample nanoapps have been run: 57*61c4878aSAndroid Build Coastguard Worker - hello_world 58*61c4878aSAndroid Build Coastguard Worker - debug_dump_world 59*61c4878aSAndroid Build Coastguard Worker - timer_world 60*61c4878aSAndroid Build Coastguard Worker - unload_tester 61*61c4878aSAndroid Build Coastguard Worker - message_world 62*61c4878aSAndroid Build Coastguard Worker - spammer 63*61c4878aSAndroid Build Coastguard Worker- Logging from a nanoapp. 64*61c4878aSAndroid Build Coastguard Worker- Allocating memory (although it uses malloc/free). 65*61c4878aSAndroid Build Coastguard Worker- Sending messages to/from the AP. 66*61c4878aSAndroid Build Coastguard Worker 67*61c4878aSAndroid Build Coastguard WorkerFeatures not implemented, but likely to be implemented in the future: 68*61c4878aSAndroid Build Coastguard Worker 69*61c4878aSAndroid Build Coastguard Worker- Context Hub Qualification Test Suite (CHQTS). 70*61c4878aSAndroid Build Coastguard Worker- Some simulated PALS for testing (based off of CHRE's linux simulated PALs). 71*61c4878aSAndroid Build Coastguard Worker- Power Management APIs, e.g: waking the host AP and flushing messages. 72*61c4878aSAndroid Build Coastguard Worker- Instructions around implementing a PAL. 73*61c4878aSAndroid Build Coastguard Worker- Instructions around building and testing a nanoapp. 74*61c4878aSAndroid Build Coastguard Worker- Dynamically loading nanoapps. 75*61c4878aSAndroid Build Coastguard Worker 76*61c4878aSAndroid Build Coastguard WorkerFeatures that would be nice to have: 77*61c4878aSAndroid Build Coastguard Worker 78*61c4878aSAndroid Build Coastguard Worker- A plug-and-play implementation of AP <-> MCU flatbuffer message communication. 79*61c4878aSAndroid Build Coastguard Worker- Pigweed defined facades for each PAL. 80*61c4878aSAndroid Build Coastguard Worker- PAL implementations using Pigweed functionality (i.e: implementing bluetooth 81*61c4878aSAndroid Build Coastguard Worker via ``pw_bluetooth``). 82*61c4878aSAndroid Build Coastguard Worker- Pigweed defined facades for core CHRE functionality, such as clock selection, 83*61c4878aSAndroid Build Coastguard Worker memory management, cache management. 84*61c4878aSAndroid Build Coastguard Worker- A protobuf implementation of CHRE's flatbuffer API. 85*61c4878aSAndroid Build Coastguard Worker- Cmake and Bazel build system integration. 86*61c4878aSAndroid Build Coastguard Worker 87*61c4878aSAndroid Build Coastguard Worker------------- 88*61c4878aSAndroid Build Coastguard WorkerAPI reference 89*61c4878aSAndroid Build Coastguard Worker------------- 90*61c4878aSAndroid Build Coastguard Worker.. doxygennamespace:: pw::chre 91*61c4878aSAndroid Build Coastguard Worker :members: 92*61c4878aSAndroid Build Coastguard Worker 93*61c4878aSAndroid Build Coastguard Worker------------- 94*61c4878aSAndroid Build Coastguard WorkerPorting Guide 95*61c4878aSAndroid Build Coastguard Worker------------- 96*61c4878aSAndroid Build Coastguard WorkerThe ``pw_chre`` module has completed the steps outlined for `creating a new CHRE platform`_ . 97*61c4878aSAndroid Build Coastguard Worker 98*61c4878aSAndroid Build Coastguard Worker.. _Creating a new CHRE platform: https://android.googlesource.com/platform/system/chre/+/refs/heads/main/doc/porting_guide.md#recommended-steps-for-porting-chre 99*61c4878aSAndroid Build Coastguard Worker 100*61c4878aSAndroid Build Coastguard WorkerThe ``pw_chre`` module still needs to be configured correctly on a new platform. 101*61c4878aSAndroid Build Coastguard WorkerYou ``pw_chre`` user is responsible for: 102*61c4878aSAndroid Build Coastguard Worker 103*61c4878aSAndroid Build Coastguard Worker- Starting a thread for CHRE's event loop and calling the correct APIs. 104*61c4878aSAndroid Build Coastguard Worker- Forwarding messages to/from the Application Processor (AP). 105*61c4878aSAndroid Build Coastguard Worker 106*61c4878aSAndroid Build Coastguard Worker----------------------------- 107*61c4878aSAndroid Build Coastguard WorkerAdding Optional Feature Areas 108*61c4878aSAndroid Build Coastguard Worker----------------------------- 109*61c4878aSAndroid Build Coastguard WorkerHowever, ``pw_chre`` users will likely want to implement their own 110*61c4878aSAndroid Build Coastguard WorkerPlatform Abstraction Layers (PALs). For more information see this 111*61c4878aSAndroid Build Coastguard Worker`implementation guide <https://android.googlesource.com/platform/system/chre/+/refs/heads/main/doc/porting_guide.md#implementing-optional-feature-areas-e_g_pals>`_. 112*61c4878aSAndroid Build Coastguard Worker 113*61c4878aSAndroid Build Coastguard Worker.. list-table:: List of PALs 114*61c4878aSAndroid Build Coastguard Worker :widths: 1 1 115*61c4878aSAndroid Build Coastguard Worker :header-rows: 1 116*61c4878aSAndroid Build Coastguard Worker 117*61c4878aSAndroid Build Coastguard Worker * - PAL Name 118*61c4878aSAndroid Build Coastguard Worker - Pigweed implementation available 119*61c4878aSAndroid Build Coastguard Worker * - Audio 120*61c4878aSAndroid Build Coastguard Worker - ❌ 121*61c4878aSAndroid Build Coastguard Worker * - Bluetooth 122*61c4878aSAndroid Build Coastguard Worker - ❌ 123*61c4878aSAndroid Build Coastguard Worker * - GNSS 124*61c4878aSAndroid Build Coastguard Worker - ❌ 125*61c4878aSAndroid Build Coastguard Worker * - Sensor 126*61c4878aSAndroid Build Coastguard Worker - ❌ 127*61c4878aSAndroid Build Coastguard Worker * - Wifi 128*61c4878aSAndroid Build Coastguard Worker - ❌ 129*61c4878aSAndroid Build Coastguard Worker * - WWAN 130*61c4878aSAndroid Build Coastguard Worker - ❌ 131*61c4878aSAndroid Build Coastguard Worker 132*61c4878aSAndroid Build Coastguard Worker 133*61c4878aSAndroid Build Coastguard WorkerFor more information on a specific PAL see 134*61c4878aSAndroid Build Coastguard Worker`the PAL headers <https://cs.android.com/android/platform/superproject/+/main:system/chre/pal/include/chre/pal/>`_ 135*61c4878aSAndroid Build Coastguard Workeror the `Linux reference PAL implementations <https://cs.android.com/android/platform/superproject/+/main:system/chre/platform/linux/>`_. 136