linux驱动由浅入深系列:高通sensor架构实例分析之二(驱动代码结构)【转】

【自取】最近整理的,有需要可以领取学习:

这一系列导航:

[En]

This series of navigation:

linux驱动由浅入深系列:高通sensor架构实例分析之一(整体概览+AP侧代码分析)

linux驱动由浅入深系列:高通sensor架构实例分析之二(adsp驱动代码结构)
Linux驱动由浅入深系列:高通sensor架构实例分析之三(adsp上报数据详解、校准流程详解)

在上一篇文章中,我们了解了高通传感器的整体架构,并分析了AP端的代码。在本文中,我们详细分析了ADSP端的代码结构。

[En]

In the previous article, we understood the overall architecture of Qualcomm sensor and analyzed the code on the AP side. In this article, we analyzed the code structure on the aDSP side in detail.

sensor数据流关键代码概览

下图显示了传感器数据流的关键代码部分:

[En]

The following figure shows the key code parts of the sensor data flow:

实现传感器驱动程序最重要的结构

[En]

The most important structure to implement the sensor driver

结合前面的测试代码,我们可以清楚地看到高通传感器的数据处理流程。图中位置7表示每个基于ADSP架构的传感器都需要实现以下接口:

[En]

Combined with the previous test code, we can clearly see the data processing flow of Qualcomm sensor. The position 7 in figure indicates that each sensor based on ADSP architecture needs to implement the following interfaces:

typedef struct
{
/**
* @brief Initializes the driver and sets up devices.

*
* Allocates a handle to a driver instance, opens a communication port to
* associated devices, configures the driver and devices, and places
* the devices in the default power state. Returns the instance handle along
* with a list of supported sensors. This function will be called at init
* time.

*
* @param[out] dd_handle_ptr Pointer that this function must malloc and
* populate. This is a handle to the driver
* instance that will be passed in to all other
* functions. NB: Do not use @a memhandler to
* allocate this memory.

  • @param[in] smgr_handle Handle used to identify this driver when it
  • calls into Sensors Manager functions.

  • @param[in] nv_params NV parameters retrieved for the driver.

  • @param[in] device_info Access info for physical devices controlled by

  • this driver. Used to configure the bus
  • and talk to the devices.

  • @param[in] num_devices Number of elements in @a device_info.

  • @param[in] memhandler Memory handler used to dynamically allocate

  • output parameters, if applicable. NB: Do not
  • use memhandler to allocate memory for
  • @a dd_handle_ptr.

  • @param[in/out] sensors List of supported sensors, allocated,

  • populated, and returned by this function.

  • @param[in/out] num_sensors Number of elements in @a sensors.

*
* @return Success if @a dd_handle_ptr was allocated and the driver was
* configured properly. Otherwise a specific error code is returned.

/
sns_ddf_status_e (
init)(
sns_ddf_handle_t dd_handle_ptr,
sns_ddf_handle_t smgr_handle,
sns_ddf_nv_params_s
nv_params,
sns_ddf_device_access_s device_info[],
uint32_t num_devices,
sns_ddf_memhandler_s memhandler,
sns_ddf_sensor_e
sensors,
uint32_t
num_sensors);

/**
* @brief Retrieves a single set of sensor data.

*
* Requests a single sample of sensor data from each of the specified
* sensors. Data is returned in one of two ways: (1) immediately after being
* read from the sensor, in which case data is populated in the same order
* it was requested, or (2) in cases where the sensor requires several steps
* to be read, this function will return with the status SNS_DDF_PENDING,
* and provide the data asynchronously via @a sns_ddf_smgr_data_notify()
* when it is ready. Note that @a sns_ddf_smgr_data_notify() must be called
* even in the event of an error in order to report a failed status. An
* asynchronous notification is also expected in the case of mixed data
* (i.e. synchronous and asynchronous).

*
* @note In the case where multiple sensors are requested, the driver must
* attempt to collect data from all requested sensors, meaning that
* the time it takes to execute this function will be determined by
* the number of sensors sampled, and their various delays. Drivers
* must never return partial responses. If a sensor has failed or
* isn’t available, @a sns_ddf_sensor_data_s.status must be used to
* reflect this status.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] sensors List of sensors for which data is requested.

  • @param[in] num_sensors Number of elements in @a sensors.

  • @param[in] memhandler Memory handler used to dynamically allocate

  • output parameters, if applicable.

  • @param[out] data Sampled sensor data. The number of elements must

  • match @a num_sensors.

*
* @return SNS_DDF_SUCCESS if data was populated successfully. If any of the
* sensors queried are to be read asynchronously SNS_DDF_PENDING is
* returned and data is via @a sns_ddf_smgr_data_notify() when
* available. Otherwise a specific error code is returned.

*
@see sns_ddf_data_notify()
/
sns_ddf_status_e (get_data)(
sns_ddf_handle_t dd_handle,
sns_ddf_sensor_e sensors[],
uint32_t num_sensors,
sns_ddf_memhandler_s
memhandler,
sns_ddf_sensor_data_s** data);

/**
* @brief Sets a sensor attribute to a specific value.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] sensor Sensor for which this attribute is to be set. When
  • addressing an attribute that refers to the driver
  • this value is set to SNS_DDF_SENSOR__ALL.

  • @param[in] attrib Attribute to be set.

  • @param[in] value Value to set this attribute.

*
* @return Success if the value of the attribute was set properly. Otherwise
* a specific error code is returned.

/
sns_ddf_status_e (
set_attrib)(
sns_ddf_handle_t dd_handle,
sns_ddf_sensor_e sensor,
sns_ddf_attribute_e attrib,
void* value);

/**
* @brief Retrieves the value of an attribute for a sensor.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] sensor Sensor whose attribute is to be retrieved. When
  • addressing an attribute that refers to the driver
  • this value is set to SNS_DDF_SENSOR__ALL.

  • @param[in] attrib Attribute to be retrieved.

  • @param[in] memhandler Memory handler used to dynamically allocate

  • output parameters, if applicable.

  • @param[out] value Pointer that this function will allocate or set

  • to the attribute’s value.

  • @param[out] num_elems Number of elements in @a value.

*
* @return Success if the attribute was retrieved and the buffer was
* populated. Otherwise a specific error code is returned.

/
sns_ddf_status_e (
get_attrib)(
sns_ddf_handle_t dd_handle,
sns_ddf_sensor_e sensor,
sns_ddf_attribute_e attrib,
sns_ddf_memhandler_s memhandler,
void
value,
uint32_t
num_elems);

/**
* @brief Called when the timer set by this driver has expired. This must be
* the callback function submitted when initializing a timer.

*
* @note This will be called within the context of the Sensors Manager task.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] arg The argument submitted when the timer was set.

*
@see sns_ddf_set_timer()
/
void (handle_timer)(sns_ddf_handle_t dd_handle, void arg);

/**
* @brief Called in response to an interrupt for this driver.

*
@note This function will be called within the context of the SMGR task,
*
not* the ISR.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] gpio_num GPIO number that triggered this interrupt.

  • @param[in] timestamp Time at which interrupt happened.

/
void (
handle_irq)(
sns_ddf_handle_t dd_handle,
uint32_t gpio_num,
sns_ddf_time_t timestamp);

/**
* @brief Resets the driver and device so they return to the state they were
* in after init() was called.

*
* @param[in] dd_handle Handle to a driver instance.

*
* @return Success if the driver was able to reset its state and the device.

  • Otherwise a specific error code is returned.

/
sns_ddf_status_e (
reset)(sns_ddf_handle_t dd_handle);

/**
* @brief Runs a factory test case.

*
* Tests may include embedded hardware tests in cases where the sensor
* supports it, as well as driver based sensor tests. This is generally run
* in a factory setting and must not be called while a device is streaming
* data.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] sensor Sensor on which to run the test.

  • @param[in] test Test case to run.

  • @param[out] err Optional driver-specific error code.

*
* @return One of the following error codes:
* SNS_DDF_SUCCESS – Test passed.

  • SNS_DDF_PENDING – Test result will be sent as an event.

  • SNS_DDF_EDEVICE_BUSY – Device is busy streaming, cannot run test.

  • SNS_DDF_EINVALID_TEST – Test is not defined for this sensor.

  • SNS_DDF_EINVALID_PARAM – One of the parameters is invalid.

  • SNS_DDF_EFAIL – Unknown error occurred.

/
sns_ddf_status_e (
run_test)(
sns_ddf_handle_t dd_handle,
sns_ddf_sensor_e sensor,
sns_ddf_test_e test,
uint32_t* err);

/**
* @brief Begins device-scheduled sampling and enables notification via Data
* Ready Interrupts (DRI).

*
* The driver commands the device to begin sampling at the configured
* ODR (@a SNS_DDF_ATTRIB_ODR) and enables DRI. When data is ready, the
* driver’s handle_irq() function is called and the driver notifies
* SMGR of the event via @a sns_ddf_smgr_notify_event() and @a
* SNS_DDF_EVENT_DATAREADY.

*
* @param[in] handle Handle to the driver’s instance.

  • @param[in] sensor Sensor to be sampled.

  • @param[in] enable True to enable or false to disable data stream.

*
* @return SNS_DDF_SUCCESS if sensor was successfully configured and
* internal sampling has commenced or ceased. Otherwise an
* appropriate error code.

/
sns_ddf_status_e (
enable_sched_data)(
sns_ddf_handle_t handle,
sns_ddf_sensor_e sensor,
bool enable);

/**
* @brief Probes for the device with a given configuration.

*
* This commands the driver to look for the device with the specified
* configuration (ie, I2C address/bus defined in the sns_ddf_device_access_s
* struct.

*
* @param[in] dev_info Access info for physical devices controlled by
* this driver. Used to determine if the device is
* physically present.

  • @param[in] memhandler Memory handler used to dynamically allocate
  • output parameters, if applicable.

  • @param[out] num_sensors Number of sensors supported. 0 if none.

  • @param[out] sensor_type Array of sensor types supported, with num_sensor

  • elements. Allocated by this function.

*
* @return SNS_DDF_SUCCESS if the part was probed function completed, even
* if no device was found (in which case num_sensors will be set to
* 0).

/
sns_ddf_status_e(
probe)(
sns_ddf_device_access_s device_info,
sns_ddf_memhandler_s
memhandler,
uint32_t num_sensors,
sns_ddf_sensor_e
* sensors );

/*
* @brief Retrieves a set of sensor data. Asynchronous API
*
Requests sample of sensor data from the specified sensor.

*
* @note If a sensor has failed or
* isn’t available, @a sns_ddf_sensor_data_s.status must be used to
* reflect this status.

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] sensor sensor for which data is requested.

*
* @param[in] num_samples number of samples to retrieve as available. Drain the FIFO if value is set to Zero.

  • @param[in] trigger now trigger notify fifo data now or
  • later when trigger_now is set to true.

*
*
* @return SNS_DDF_SUCCESS if data was populated successfully.

  • via sns_ddf_smgr_data_notify() or if trigger_now is
  • set to false; Otherwise a specific error code is
  • returned.

*
* @see sns_ddf_data_notify_data() as this will be used to report the data.

/
sns_ddf_status_e (
trigger_fifo_data)(
sns_ddf_handle_t dd_handle,
sns_ddf_sensor_e sensor,
uint16_t num_samples,
bool trigger_now);

/**
* @brief Delivers a Driver Access Framework message to the driver.

  • Asynchronous/Synchronous API.

*
@detail
*
@param[in] dd_handle Handle to a driver instance.

  • @param[in] req_id Request identifier.

  • @param[in] req_msg Request message in the opaque payload. If no

  • payload is supplied, then this pointer will be
  • null.

  • @param[in] req_size Number of bytes in @req_msg. If req_msg is empty,

  • this value must be 0.

  • @param[in] memhandler Memory handler used to dynamically allocate

  • output parameters, if applicable.

  • @param[out] resp_msg Pointer to the output message pointer. The output

  • message must be allocated first using @memhandler.

  • @param[out] resp_size Pointer to number of bytes in @resp_msg. If there

  • is no DAF response message for the request, then
  • this must be 0 to show that the DAF response is
  • not present. Response messages are limited in
  • size to @SNS_SMGR_MAX_DAF_MESSAGE_SIZE_V01 bytes.

  • Any response message larger than

  • @SNS_SMGR_MAX_DAF_MESSAGE_SIZE_V01 bytes will be
  • truncated.

  • @param[in] trans_id_ptr Pointer to the optional transaction identifier.

This will be null if a transaction ID was not
provided.

  • @param[in] conn_handle The connection handle for the request message.

  • This value must be saved if the particular request

  • is expected to generate indications. Upon
  • notifying the SMGR of an indication, this value
  • must be provided to the SMGR.

*
* @return Success if the message was retrieved and the buffer was correctly
* populated. Otherwise a specific error code is returned.

/
sns_ddf_status_e (
process_daf_req)(
sns_ddf_handle_t dd_handle,
uint32_t req_id,
const void req_msg,
uint32_t req_size,
sns_ddf_memhandler_s
memhandler,
void resp_msg,
uint32_t
resp_size,
const uint8_t
trans_id_ptr,
void* conn_handle);

/**
* @brief Cancels all of the driver’s current Driver Access Framework
* asynchronous transactions for the provided connection handle.

*
* @note This does not have to cancel a response message in the process of
* being created.

  • This function does not have to be implemented for drivers that do
  • not support or implement any asynchronous messages (these messages
  • require the usage of sns_ddf_smgr_notify_daf_ind).

*
* @param[in] dd_handle Handle to a driver instance.

  • @param[in] conn_handle The connection handle for the client that is
  • cancelling the Driver Access Framework
  • transaction.

/
void (
cancel_daf_trans)(
sns_ddf_handle_t dd_handle,
void* conn_handle);

} sns_ddf_driver_if_s;

aDSP初始化流程

aDSP的初始化工作从[Sns_init_dsps.c]文件中的 sns_init()函数开始,其中调用 -> sns_init_once(); -> SNS_INIT_FUNCTIONS存在一个各个模块的初始化函数指针列表,依次调用各个模块的初始化函数init_ptrsi -> 其中我们关注传感器相关的[sns_smgr_main_uimg.c]sns_smgr_init() -> 创建了 [sns_smgr_main.c]sns_smgr_task() 进程 ->sns_smgr_hw_init(); ->sns_smgr_process_msg(); ->sns_smgr_process_reg_resp_msg(); ->sns_smgr_process_reg_data() ->sns_smgr_process_reg_devinfo() ->sns_smgr_parse_reg_devinfo_resp() -> 通过drv_fn_ptr->probe()指针,调用相应传感器实现的probe函数。如果某传感器没有实现probe函数,则调用sns_smgr_populate_cfg_from_devinfo()。

aDSP上报传感器数据

Sensor上报数据的三种方式:

1, (Polling)0x00调用一次get_data后启动timer,等到timer到时间后调用sns_ddf_driver_if_s中指定的handle_timer()函数上报一组传感器数据

2, (DRI)0x80调用enable_sched_data()启用DRI(Data ReadyInterrupt,数据完成中断),按照set_cycle_time指定的ODR(Output Data Rate,数据输出速率)进行数据采集,采集完成后调用sns_ddf_driver_if_s中指定的handle_irq()函数上报传感器数据。

3, (FIFO)0xD0调用trigger_fifo_data()函数启动FIFO模式,当数据量到达指定的阈值,触发sns_ddf_smgr_data_notify()函数上报一批数据。

有关数据报告流程的更多详细信息,请参阅下一篇博客:Linux驱动程序由浅入深系列:高通传感器架构案例分析第3部分(ADSP报告数据的详细解释)

[En]

For more details on the data reporting process, see the next blog: Linux driver from shallow to deep series: Qualcomm sensor architecture case analysis part 3 (detailed explanation of adsp reporting data)

Original: https://www.cnblogs.com/zzb-Dream-90Time/p/10963728.html
Author: 请给我倒杯茶
Title: linux驱动由浅入深系列:高通sensor架构实例分析之二(驱动代码结构)【转】

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/7103/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Linux01:常用的基本命令及概述及环境搭建(狂神说)

    Linux学习 一、入门概述 我们为什么要学Linux Linux诞生了这么多年,以前还喊着如何能取代windows系统,现在这个口号已经小多了,任何事物发展都有其局限性都有其天花…

    Linux 2022年9月10日
    0220
  • linux内核学习—Linux内核程序调试工具Crash的安装

    客户机操作系统已禁用 CPU,请关闭或重置虚拟机 本人在研究SDN中,需要经常修改OVS源码实现自己的功能,因此大部分工作需要修改openvswitch.ko内核模块,而内核程序的…

    2022年8月11日
    0630
  • linux shell数据重定向(输入重定向与输出重定向)详细分析

    linux shell数据重定向(输入重定向与输出重定向)详细分析 一个奔跑的程序员 Original: https://www.cnblogs.com/jingzhishen/p…

    Linux 2022年8月11日
    0290
  • linux 修改时间

    实例:设置时间伟2008年8月8号12:00 date -s “2008-08-08 12:00:00” 修改完后,记得执行clock -w,把系统时间写入…

    Linux 2022年8月20日
    0220
  • 致远 OA 组合 getshell

    测试版本为: 致远 A8-V5 协同管理软件 V6.1SP2 1.获取cookie信息 2….

    Linux 2022年9月14日
    0170
  • (原)通过clash在ubuntu下做旁路由

    (本文假设阅读者已经熟练使用clash for windows。) 目的: 把一台闲置ubuntu,搞成旁路由(下文里的”旁路由”或”ubunt…

    Linux 2022年8月26日
    0650
  • 使用ssh连接到centos7中docker容器

    任务: 使用ssh连接到centos7中docker容器 实验步骤: 如图,首先用真机ping容器(容器事先安装了常用的软件,具体步骤请看上一篇) 然后用容器ping真机以及外网,…

    Linux 2022年9月10日
    0420
  • .gitignore == git添加忽略不生效解决方案

    把某些目录或文件加入忽略规则,发现并未生效,原因是.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的…

    Linux 2022年8月30日
    0330
  • linux练习题

    观察系统当前进程的运行情况的命令是( ):A、freeB、dmesgC、topD、last Linux系统通过( )命令给其他用户发消息?A.lessB.mesg yC.write…

    Linux 2022年8月11日
    0380
  • linux diff对比文件

    diff 是 Unix 系统的一个命令,用来比较两个文本文件的差异。一般用法: $diff file1 file2 具体参数可以查询 man diff diff 有三种输出格式 正…

    Linux 2022年8月8日
    0940
  • linux 命令行中常用的快捷键

    001、 ctrl + a:回到行首 ctrl + e:回到行末 ctrl + u:剪切行首到光标处的位置 ctrl + k:剪切光标所在位置到末尾的内容 ctrl + y:粘贴最…

    Linux 2022年8月11日
    0620
  • Linux文件名乱码无法删除文件

    现象: 如图所示,使用ls查看目录下文件,发现文件名有乱码和奇怪的符号,通过rm命令无法删除; 解决方案: 此时可通过文件的inode删除文件 操作过程: 使用ls -il查看文件…

    Linux 2022年8月26日
    0270
  • Linux:A start job is running for /etc/rc.local compatibility解决办法

    面对问题首先:Linux系统无法启动CentOS启动的时候读条已经读满,但是没有反应,按下任意键(我按的是方向键)跳出启动列表,最后一条信息:A start job is runn…

    Linux 2022年8月24日
    0250
  • ArchLinux安装-2022-01-12

    这篇教程,是我基于B站up住theCW的视频教程整理的,其中添加了一些我在安装n次之后的经验(虽然失败过几次,但我现在安装不会再出差错,所以请放心的看此教程) 当然,我认为theC…

    Linux 2022年9月10日
    0260
  • linux查找命令

    基本格式:find path expression 1.按照文件名查找 (1)find / -name httpd.conf #在根目录下查找文件httpd.conf,表示在整个硬…

    Linux 2022年8月20日
    0320
  • Linux部署Net Core网站,三种自定义绑定端口号的方法(UseUrls,UseKestrel,手动指定)

    一、应用场景 现在随着.Net Core的发展,Asp.Net的网站也可以开始跨平台发布了,.Net Core网站有两种形式,一种就是传统Windows自带的IIS服务器发布,还有…

    2022年8月26日
    0250
  • 灵感来袭,基于Redis的分布式延迟队列

    延迟队列 延迟队列,也就是一定时间之后将消息体放入队列,然后消费者才能正常消费。比如1分钟之后发送短信,发送邮件,检测数据状态等。 [En] Delay queue, that i…

    Linux 2022年9月14日
    0230
  • Ubuntu20.04 体验和美化

    Ubuntu20.04美化和体验 windows用久了,换下系统也挺好的。ubuntu20.04优化后,用起来蛮舒服的。 系统配置 1.修改软件源 Ubuntu默认是国外的软件源,…

    Linux 2022年8月26日
    0250
  • redis实战

    转载于:https://blog.csdn.net/piaoslowly/article/details/81563579 redis简介 Redis 是一个开源的 使用 ANSI…

    Linux 2022年9月14日
    0200
  • thinkphp5简单使用redis缓存

    csharp;gutter:true; connect("127.0.0.1","6379");</p> <pre>…

    Linux 2022年9月14日
    0230
  • Linux sort命令详解:字符串排序

    sort 是 Linux 的排序命令,而且可以依据不同的数据类型来进行排序。sort 将文件的每一行作为一个单位,相互比较。比较原则是从首字符向后,依次按 ASCII 码值进行比较…

    2022年8月20日
    0370
  • MAC安装redis

    一、安装命令使用mac的包管理工具brew一行命令搞定安装。若未安装brew,命令行先输入以下命令安装brew。 /usr/bin/ruby -e “$(curl -f…

    Linux 2022年9月14日
    0460
  • 如何在 Visual Studio 中使用 Git 同步代码到 CodePlex

    开源社区不管在国内还是国外都很火热,微软也曾因为没有开源而倍受指责,但是随着 .Net framework、ASP.Net MVC等框架的逐渐开源,也让大家看到了微软开源的步伐。C…

    2022年8月30日
    0230
  • 在原生CSS中使用变量

    一直以来,CSS作为一种申明式的样式标记语言,很难像如 javascript等命令式编程语言一样通过定义和使用变量的方式来维护和追踪某些状态。后来随着 scss, less等CSS…

    Linux 2022年8月30日
    0450
  • Linux、apache 无法使用PHP创建目录和文件

    因为项目的需要,这几天搭建了虚拟机,环境是centos7+lamp,可是搭建好网站后,即使把权限放开了(777),我试了改父文件夹权限;重新创建文件夹,改权限再移动文件;更换文件夹…

    Linux 2022年8月24日
    0250
  • Linux内核镜像格式

    1 Linux内核镜像格式Linux内核有多种格式的镜像,包括vmlinux、vmlinuz,Image、zImage、bzImage、uImage、xipImage、bootpI…

    2022年8月13日
    0390

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部