xref: /aosp_15_r20/system/chre/chpp/QUICKSTART.md (revision 84e339476a462649f82315436d70fd732297a399)
1*84e33947SAndroid Build Coastguard Worker# CHPP Integration
2*84e33947SAndroid Build Coastguard Worker
3*84e33947SAndroid Build Coastguard WorkerThis guide focuses on integrating and porting CHPP to your desired platform. For implementation details please refer to the included README.md instead. The minimum typical steps are provided.
4*84e33947SAndroid Build Coastguard Worker
5*84e33947SAndroid Build Coastguard Worker## CHPP Transport Layer Integration
6*84e33947SAndroid Build Coastguard Worker
7*84e33947SAndroid Build Coastguard Worker### Platform-specific functionality
8*84e33947SAndroid Build Coastguard Worker
9*84e33947SAndroid Build Coastguard WorkerImplement the platform-specific functionality utilized by CHPP. These can be found in chpp/platform and include:
10*84e33947SAndroid Build Coastguard Worker
11*84e33947SAndroid Build Coastguard Worker1. Memory allocation and deallocation
12*84e33947SAndroid Build Coastguard Worker1. Thread notification mechanisms and thread signalling
13*84e33947SAndroid Build Coastguard Worker1. Mutexes (or other resource sharing mechanism)
14*84e33947SAndroid Build Coastguard Worker1. Condition variables
15*84e33947SAndroid Build Coastguard Worker1. Logging (including defining CHPP_LOGx, CHPP_LOG_OOM, PRIuSIZE)
16*84e33947SAndroid Build Coastguard Worker1. CRC32 (a half-byte algorithm is provided in platform/shared, but it is recommended to use a platform-optimized / hardware algorithm when available)
17*84e33947SAndroid Build Coastguard Worker
18*84e33947SAndroid Build Coastguard WorkerSample Linux implementations are provided.
19*84e33947SAndroid Build Coastguard Worker
20*84e33947SAndroid Build Coastguard Worker### Link-Layer APIs
21*84e33947SAndroid Build Coastguard Worker
22*84e33947SAndroid Build Coastguard WorkerYou need to create a `ChppLinkApi` API struct and a `ChppLinkConfiguration` configuration struct for your link layer.
23*84e33947SAndroid Build Coastguard WorkerSee details in link.h.
24*84e33947SAndroid Build Coastguard Worker
25*84e33947SAndroid Build Coastguard Worker### Initialization
26*84e33947SAndroid Build Coastguard Worker
27*84e33947SAndroid Build Coastguard WorkerIn order to initialize CHPP, it is necessary to:
28*84e33947SAndroid Build Coastguard Worker
29*84e33947SAndroid Build Coastguard Worker1. Allocate the linkContext, transportContext, and appContext structs that hold the state for each instance of the application, transport, and link layers (in any order)
30*84e33947SAndroid Build Coastguard Worker1. Call the layers’ initialization functions, chppTransportInit and chppAppInit (in any order)
31*84e33947SAndroid Build Coastguard Worker1. Call chppWorkThreadStart to start the main thread for CHPP's Transport Layer
32*84e33947SAndroid Build Coastguard Worker
33*84e33947SAndroid Build Coastguard Worker### Testing
34*84e33947SAndroid Build Coastguard Worker
35*84e33947SAndroid Build Coastguard WorkerSeveral unit tests are provided in transport_test.c. In addition, loopback functionality is already implemented in CHPP, and can be used for testing. For details on crafting a loopback datagram, please refer to README.md and the transport layer unit tests (transport_test.c).
36*84e33947SAndroid Build Coastguard Worker
37*84e33947SAndroid Build Coastguard Worker### Termination
38*84e33947SAndroid Build Coastguard Worker
39*84e33947SAndroid Build Coastguard WorkerIn order to terminate CHPP's main transport layer thread, it is necessary to:
40*84e33947SAndroid Build Coastguard Worker
41*84e33947SAndroid Build Coastguard Worker1. Call chppWorkThreadStop() to stop the main worker thread.
42*84e33947SAndroid Build Coastguard Worker1. Call the layers’ deinitialization functions, chppTransportDeinit and chppAppDeinit (in any order)
43*84e33947SAndroid Build Coastguard Worker1. Deallocate the transportContext, appContext, and the linkContext structs
44*84e33947SAndroid Build Coastguard Worker
45*84e33947SAndroid Build Coastguard Worker### Single-threaded systems
46*84e33947SAndroid Build Coastguard Worker
47*84e33947SAndroid Build Coastguard WorkerIf the system does not support multi-threading, the chppWorkThreadHandleSignal method can be used to directly handle signals without using chppWorkThreadStart.
48*84e33947SAndroid Build Coastguard Worker
49*84e33947SAndroid Build Coastguard WorkerNote that the system MUST replicate the high-level behavior of chppWorkThreadStart exactly in this case. More details in the documentation of chppWorkThreadHandleSignal.
50*84e33947SAndroid Build Coastguard Worker
51*84e33947SAndroid Build Coastguard WorkerFor such systems, chppTransportGetTimeUntilNextDoWorkNs() can be used to replicate the functionality of chppNotifierTimedWait(). chppTransportGetTimeUntilNextDoWorkNs() returns the time until chppTransportDoWork() must be called again.
52*84e33947SAndroid Build Coastguard Worker
53*84e33947SAndroid Build Coastguard Worker## CHPP Services Integration
54*84e33947SAndroid Build Coastguard Worker
55*84e33947SAndroid Build Coastguard WorkerCHPP provides several predefined services (including Loopback Test, Service Discovery), as well as three standard services that follow the CHRE PAL API to simplify integration and testing. CHPP allows for custom services as well, as described in README.md. The standard services included in CHPP are:
56*84e33947SAndroid Build Coastguard Worker
57*84e33947SAndroid Build Coastguard Worker1. WWAN
58*84e33947SAndroid Build Coastguard Worker1. WiFi
59*84e33947SAndroid Build Coastguard Worker1. GNSS
60*84e33947SAndroid Build Coastguard Worker
61*84e33947SAndroid Build Coastguard WorkerIn order to integrate the standard services using the CHRE PAL API, please refer to each service's interface as provided in include/chre/pal/
62