CHRE:代码框架

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代码组成

CHRE:代码框架_第1张图片

chre_api是向nanoapp提供的接口,core、platform是实现chre的核心代码

EventLoopManager

EventLoopManager包含管理sensor等各种manager,通过EventLoopManger访问其他资源

//! Provide an alias to the EventLoopManager singleton.
typedef Singleton EventLoopManagerSingleton;

类实例化,通过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相关类的实现

platform/include/chre/platform/platform_sensor.h 目录下有各种类的实现如PlatformSensor,但具体到不同platform有不同的实现方法,具体使用哪一个是通过编译选项控制的。

 

 platform/slpi下的代码分为SMGR、SEE两类

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实现

SMGR的实现依赖slpi_proc的源码,如果源码没有使用smgr框架就没有对应的代码,如下面的Sensors路径

CHRE:代码框架_第2张图片

 

SEE实现

CHRE:代码框架_第3张图片

 

CHRE:代码框架_第4张图片

CHRE入口点

CHRE:代码框架_第5张图片

chre的入口点肯定包含 "chre::init()",以chre在slpi上的实现为例。CHRE host 通过 fastRPC 函数 chre_slpi_start_thread调用到slpi环境。

chre::init()

CHRE:代码框架_第6张图片

PlatformSensor中创建了SeeHelper并赋值了seeHelperCallback, 该callback的具体作用后面会看到;调用EventLoopMangerSingleton::init()创建对象EventLoopManger和其他manager对象

 chreThreadEntry

调用qurt函数设置thread属性创建线程后进入chreThreadEntry,最后进入整个控制流程EventLoop.run.

event的push/pop控制这整个代码的流程。

sensor的data event事件是怎么发送到event loop的

CHRE:代码框架_第7张图片

SeeHelper注册了SeeHelperCallback::onSensorDataEvent,该函数会调用postEvent,至于callback函数是怎么被调到的看上图

chre_api

CHRE:代码框架_第8张图片

 chre.h

chre api都是为nanoapp服务的

CHRE:代码框架_第9张图片

re.h runtime environment

CHRE:代码框架_第10张图片

 common.h

CHRE:代码框架_第11张图片

 event.h

CHRE:代码框架_第12张图片

 nanoapp.h

 sensor

CHRE:代码框架_第13张图片

gnss/wifi/wwan

CHRE:代码框架_第14张图片 

sensor chre_api的实现

bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle)
后面都依赖获得的handle

CHRE:代码框架_第15张图片

chreSensorxxx的实现在文件chre_api_sensor.cc中,//todo

SensorRequestManager的构造函数

CHRE:代码框架_第16张图片

从getSuidAndAttrs 可以看出和see通信的过程encodeSnsSuidReq (encode成pb格式),然后调用sendReq。这里维护一个全局变量mSensorRequests, 获得sensor infor等直接访问该变量。

CHRE:代码框架_第17张图片

chreSensorConfigure

 

注册当前的nanoapp接听该事件。 

你可能感兴趣的:(人工智能)