高通骁龙SM6225 sensor驱动架构(1)

sensor和sensor instance

Sensor & instance

(1) Sensor 用来产生 和/或 消费 异步数据。
(2) 每个sensor可实例化一次或多次sensor instances。其中:每个instance使用特殊配置来操作;发给sensor的任何request都会生成一个sensor instance 或者共享已经存在的instance。
(3) sensor instances 是请求式的创建,由sensor来终结。其中:sensors完全掌控他们匹配的instances的生命周期和配置信息,并且负责发送配置更新和初始状态events给他们的clients;Vendors强烈建议所有的clients提供及可能少的实例;stream data通过一个instance产生,并发送给所有激活的clients。
(4)一个单独的sensor instance 可以通过多个sensor来共享和配置。

Sensor:

(1)在初始化期间查找sensor硬件,并在硬件当前可用的情况publishes availability。
(2)publishes所有相关带有正常参数的attributes;
(3)获取所属的SUID。
(4)获取配置信息并从registry中获取calibration的数据。
(5)管理来自client的requests;
(6)当request进入时,根据不同信息来建立/更新/删除 instances。
(7)管理sensor硬件的用电;
(8)管理COM bus的用电;
(9)在析构过程中释放所有资源。

Instance:

(1)管理COM bus用电,
(2)根据request编程符合自身硬件的code。
(3)当硬件配置改变时Publishes 配置event。
(4)Publishes data event。
(5)Publishes 所有错误的events。
(6) 在析构过程中释放所有资源。

sns_sensor_instance

驱动中大量出现了这个sns_sensor_instance数据类型

typedef struct sns_sensor_instance
{
  /* Functions which call back into the framework; provided by the Framework */
  struct sns_sensor_instance_cb const *cb;

  /* Fixed-size memory allocation made by the Framework from the power
   * efficient heap appropriate for this Sensor.  Memory is for the sole use of
   * the Sensor Instance. Memory may be moved between Sensor registered function
   * calls. Therefore direct references should not be maintained.
   */
  struct sns_sensor_instance_state *state;

  /* Fixed-sized memory allocation made by the framework from the Non-Island,
   * high power memory heap.  May not be dereferenced unless Instance created
   * via sns_sensor_cb::create_instance_v2.
   *
   * Developer is responsible for invoking
   * sns_island_service::sensor_instance_island_exit before accessing.
   */
  struct sns_sensor_instance_state *state_ni;
} sns_sensor_instance;
cb: 指向回调函数的指针,通过这些回调函数,传感器实例可以与框架进行交互。
state: 指向由框架从适合该传感器的低功耗堆中分配的固定大小的内存。这块内存仅供传感器实例使用,并且可能在传感器注册的函数调用之间移动。因此,不应直接引用该内存。
state_ni: 指向由框架从非岛屿高功耗内存堆中分配的固定大小的内存。除非通过sns_sensor_cb::create_instance_v2创建实例,否则不能对其进行解引用操作。开发人员在访问之前需要负责调用sns_island_service::sensor_instance_island_exit。

这个结构体包含了与传感器实例相关的重要信息和回调函数,可用于管理和控制传感器实例的行为。

sns_sensor_instance_cb

/**
 * Accessor functions for Sensor Instance state managed by the Framework.
 */
typedef struct sns_sensor_instance_cb
{
  uint32_t struct_len;

  /**
   * Get a reference to the Service Manager.  With this object, a reference
   * to any other utility service can be obtained.
   *
   * @param[i] this Sensor Instance reference
   *
   * @return Service Manager reference
   */
  struct sns_service_manager* (*get_service_manager)(
    sns_sensor_instance *this);

  /**
   * Return the next client request associated with this Sensor Instance and
   * SUID.
   *
   * Each Sensor Instance has a list of client requests per SUID which it is
   * servicing.  Entries are added via calls to add_client_request; removed
   * via remove_client_request.
   *
   * Each call to this function iterates over the list, and returns the next
   * entry.  NULL is returned at the end of the list, or if the list is empty.
   *
   * @note An Instance may be handling client requests for multiple
   * (related) Sensors; must use SUID parameter to filter.
   *
   * @param[i] this Sensor Instance reference
   * @param[i] suid Sensor associated with this Instance
   * @param[i] first Return the first request; reset the internal iterator
   *                 Must be called first to initialize iteration
   *
   * SNS_RC_NOT_AVAILABLE - The Framework is not aware of SUID
   * SNS_RC_SUCCESS
   */
   struct sns_request const* (*get_client_request)(
    sns_sensor_instance *this,
    sns_sensor_uid const *suid,
    bool first);

   /**
    * Remove a client request from this Sensor Instance
    *
    * @param[i] this Sensor Instance reference
    * @param[i] request Client request to be removed
    */
   void (*remove_client_request)(
    sns_sensor_instance *this,
    struct sns_request const *request);

  /**
   * Assign this Sensor Instance to service the client request.  Replaces any
   * existing request from the same client.
   *
   * @note The SUID of the recepient Sensor will be noted upon addition;
   * this SUID must be used within get_client_request.
   *
   * @param[i] this Sensor Instance reference
   * @param[i] request Client request to be added
   */
   void (*add_client_request)(
    sns_sensor_instance *this,
    struct sns_request const *request);
} sns_sensor_instance_cb;
struct_len: 结构体的长度。
get_service_manager: 获取服务管理器的引用。通过这个对象可以获取到任何其他实用服务的引用。
get_client_request: 返回与该传感器和SUID关联的下一个客户端请求。每个传感器都有一个与之相关的SUID的客户端请求列表,可以通过调用add_client_request方法添加请求并通过调用remove_client_request方法删除请求。每次调用此函数时,会迭代列表并返回下一个条目。如果列表为空或者已经到达列表末尾,则返回NULL。
remove_client_request: 从该传感器实例中删除一个客户端请求。
add_client_request: 将一个客户端请求分配给该传感器实例来处理。如果已存在来自同一客户端的请求,则将其替换。

这些访问函数可以帮助管理传感器的状态和处理与其相关的客户端请求。

sns_sensor_instance_state

/**
 * State specifically allocated for the Sensor Instance, to be used by the
 * Sensor developer as needed.  May be relocated; no pointers into this buffer
 * may be saved.
 */
typedef struct sns_sensor_instance_state
{
  uint32_t state_len;
  uint64_t state[1];
} sns_sensor_instance_state;
state_len: 状态缓冲区的长度。
state[1]: 状态缓冲区,以64位无符号整数数组的形式表示。具体的大小可以根据需要进行调整,但是至少有一个元素。

这个结构体允许传感器开发人员在传感器实例中存储自定义的状态数据。它的长度可以根据需要进行扩展,并且可以在必要时重新定位。然而,需要注意的是,不应该保存指向该缓冲区的指针,因为它可能会被移动。

以icm42607为例

sns_icm4x6xx_sensor_island.c

部分API
主要是把sensor中这些API放到sns_<drv_name>_sensor_island.c中实现处理请求、获取imu信息等等

sns_icm4x6xx_sensor_instance_island.c

部分API
把sensor instance中这些API放到sns_<drv_name>_sensor_instance_island.c

sns_icm4x6xx_hal_island.c

部分API

把所有sensor & sensor instance island中调用的函数放到sns_<drv_name>_hal_island.c中实现,主要是对寄存器的各种读写

Normal情况哪些API放在哪些文件中呢?
(1) 把sensor中这些API放到sns_<drv_name>sensor.c中实现
在这里插入图片描述
(2) 把sensor instance中这些API放到sns
<drv_name>_sensor_instance.c中实现
在这里插入图片描述
主要是一些初始化还有测试API

(3)所有sensor & sensor instance 非island中调用的函数放到sns_<drv_name>_hal.c中实现。
在这里插入图片描述
参考链接:https://blog.csdn.net/mjfh095215/article/details/113931708

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凉山有客不自赏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值