Table of Contents
CHRE代码组成
EventLoopManager
platform相关类的实现
platform/slpi下的代码分为SMGR、SEE两类
SMGR实现
SEE实现
CHRE入口点
chre::init()
chreThreadEntry
sensor的data event事件是怎么发送到event loop的
chre_api
chre.h
re.h runtime environment
common.h
event.h
nanoapp.h
sensor
gnss/wifi/wwan
sensor chre_api的实现
SensorRequestManager的构造函数
chreSensorConfigure
chre_api是向nanoapp提供的接口,core、platform是实现chre的核心代码
EventLoopManager包含管理sensor等各种manager,通过EventLoopManger访问其他资源
//! Provide an alias to the EventLoopManager singleton.
typedef Singleton
类实例化,通过static等实现Singleton,EventLoopManagerSingleton::init()会创建对象
class EventLoopManager : public NonCopyable {
//---
private:
//! The audio request manager handles requests for all nanoapps and manages
//! the state of the audio subsystem that the runtime subscribes to.
AudioRequestManager mAudioRequestManager;
//! The event loop managed by this event loop manager.
EventLoop mEventLoop;
//! The GnssManager that handles requests for all nanoapps. This manages the
//! state of the GNSS subsystem that the runtime subscribes to.
GnssManager mGnssManager;
//! Handles communications with the host processor.
HostCommsManager mHostCommsManager;
//! The SensorRequestManager that handles requests for all nanoapps. This
//! manages the state of all sensors that runtime subscribes to.
SensorRequestManager mSensorRequestManager;
//! The WifiRequestManager that handles requests for nanoapps. This manages
//! the state of the wifi subsystem that the runtime subscribes to.
WifiRequestManager mWifiRequestManager;
//! The WwanRequestManager that handles requests for nanoapps. This manages
//! the state of the WWAN subsystem that the runtime subscribes to.
WwanRequestManager mWwanRequestManager;
//! The MemoryManager that handles malloc/free call from nanoapps and also
//! controls upper limits on the heap allocation amount.
MemoryManager mMemoryManager;
};
platform/include/chre/platform/platform_sensor.h 目录下有各种类的实现如PlatformSensor,但具体到不同platform有不同的实现方法,具体使用哪一个是通过编译选项控制的。
SLPI是高通sensor DSP,代码框架原来是SMGR,后来更新为SEE
Sensor manager (SMGR) – Master of all sensor device drivers (DD);
handles all scheduling and sensor-client interface
Sensors Execution Environment (SEE) – New generation of sensor management software on
Qualcomm All-Ways AwareTM Hub (AAH) introduced in SDM845 in 2017 and implemented in
subsequent chipsets
还有两个术语明确下:
µImage mode – Low Power mode – no double data rate (DDR)或者说静态memory不需要动态刷新
bigImage mode – DDR in use
SMGR的实现依赖slpi_proc的源码,如果源码没有使用smgr框架就没有对应的代码,如下面的Sensors路径
chre的入口点肯定包含 "chre::init()",以chre在slpi上的实现为例。CHRE host 通过 fastRPC 函数 chre_slpi_start_thread调用到slpi环境。
PlatformSensor中创建了SeeHelper并赋值了seeHelperCallback, 该callback的具体作用后面会看到;调用EventLoopMangerSingleton::init()创建对象EventLoopManger和其他manager对象
调用qurt函数设置thread属性创建线程后进入chreThreadEntry,最后进入整个控制流程EventLoop.run.
event的push/pop控制这整个代码的流程。
SeeHelper注册了SeeHelperCallback::onSensorDataEvent,该函数会调用postEvent,至于callback函数是怎么被调到的看上图
chre api都是为nanoapp服务的
bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle)
后面都依赖获得的handle
chreSensorxxx的实现在文件chre_api_sensor.cc中,//todo
从getSuidAndAttrs 可以看出和see通信的过程encodeSnsSuidReq (encode成pb格式),然后调用sendReq。这里维护一个全局变量mSensorRequests, 获得sensor infor等直接访问该变量。
注册当前的nanoapp接听该事件。