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_api是向nanoapp提供的接口,core、platform是實現chre的核心代碼

EventLoopManager

EventLoopManager包含管理sensor等各種manager,通過EventLoopManger訪問其他資源

//! Provide an alias to the EventLoopManager singleton.
typedef Singleton<EventLoopManager> 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路徑

 

SEE實現

 

CHRE入口點

chre的入口點肯定包含 "chre::init()",以chre在slpi上的實現爲例。CHRE host 通過 fastRPC 函數 chre_slpi_start_thread調用到slpi環境。

chre::init()

PlatformSensor中創建了SeeHelper並賦值了seeHelperCallback, 該callback的具體作用後面會看到;調用EventLoopMangerSingleton::init()創建對象EventLoopManger和其他manager對象

 chreThreadEntry

調用qurt函數設置thread屬性創建線程後進入chreThreadEntry,最後進入整個控制流程EventLoop.run.

event的push/pop控制這整個代碼的流程。

sensor的data event事件是怎麼發送到event loop的

SeeHelper註冊了SeeHelperCallback::onSensorDataEvent,該函數會調用postEvent,至於callback函數是怎麼被調到的看上圖

chre_api

 chre.h

chre api都是爲nanoapp服務的

re.h runtime environment

 common.h

 event.h

 nanoapp.h

 sensor

gnss/wifi/wwan

 

sensor chre_api的實現

bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle)
後面都依賴獲得的handle

chreSensorxxx的實現在文件chre_api_sensor.cc中,//todo

SensorRequestManager的構造函數

從getSuidAndAttrs 可以看出和see通信的過程encodeSnsSuidReq (encode成pb格式),然後調用sendReq。這裏維護一個全局變量mSensorRequests, 獲得sensor infor等直接訪問該變量。

chreSensorConfigure

 

註冊當前的nanoapp接聽該事件。 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章