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

更新时间:2023-07-10 01:48:08 阅读: 评论:0

linux驱动由浅⼊深系列:⾼通nsor架构实例分析之⼆(驱动
代码结构)
上⼀篇⽂章中我们了解了⾼通nsor的整体架构及对AP侧的代码进⾏了分析,这篇⽂章我们详细分析⼀下aDSP侧的代码结构。
nsor数据流关键代码概览
下图是nsor数据流程中的关键代码部分:
实现nsor驱动最重要的⼀个结构体
结合上⼀篇的测试代码,可以清楚的看到⾼通nsor的数据处理流程。图中7位置指⽰了每个基于ADSP架构的传感器需要实现的接⼝如下:
1. typedef struct
2. {
3. /**磨芋烧鸭
4. * @brief Initializes the driver and ts up devices.
5. *
6. * Allocates a handle to a driver instance, opens a communication port to
7. * associated devices, configures the driver and devices, and places
8. * the devices in the default power state. Returns the instance handle along
9. * with a list of supported nsors. This function will be called at init
0. * time.
1. *
2. * @param[out] dd_handle_ptr Pointer that this function must malloc and
3. * populate. This is a handle to the driver
4. * instance that will be pasd in to all other
5. * functions. NB: Do not u @a memhandler to
6. * allocate this memory.
7. * @param[in] smgr_handle Handle ud to identify this driver when it
8. * calls into Sensors Manager functions.
9. * @param[in] nv_params NV parameters retrieved for the driver.
0. * @param[in] device_info Access info for physical devices controlled by
1. * this driver. Ud to configure the bus
2. * and talk to the devices.
3. * @param[in] num_devices Number of elements in @a device_info.
4. * @param[in] memhandler Memory handler ud to dynamically allocate
红豆糯米饼5. * output parameters, if applicable. NB: Do not
6. * u memhandler to allocate memory for
7. * @a dd_handle_ptr.
8. * @param[in/out] nsors List of supported nsors, allocated,
9. * populated, and returned by this function.
0. * @param[in/out] num_nsors Number of elements in @a nsors.
1. *
2. * @return Success if @a dd_handle_ptr was allocated and the driver was
3. * configured properly. Otherwi a specific error code is returned.
隋朝灭亡的原因
4. */
5. sns_ddf_status_e (*init)(
6. sns_ddf_handle_t* dd_handle_ptr,
7. sns_ddf_handle_t smgr_handle,
8. sns_ddf_nv_params_s* nv_params,
9. sns_ddf_device_access_s device_info[],
0. uint32_t num_devices,
1. sns_ddf_memhandler_s* memhandler,
2. sns_ddf_nsor_e** nsors,
3. uint32_t* num_nsors);
44.
5. /**
6. * @brief Retrieves a single t of nsor data.
7. *
8. * Requests a single sample of nsor data from each of the specified
9. * nsors. Data is returned in one of two ways: (1) immediately after being
0. * read from the nsor, in which ca data is populated in the same order
1. * it was requested, or (2) in cas where the nsor requires veral steps
2. * to be read, this function will return with the status SNS_DDF_PENDING,
3. * and provide the data asynchronously via @a sns_ddf_smgr_data_notify()
4. * when it is ready. Note that @a sns_ddf_smgr_data_notify() must be called
5. * even in the event of an error in order to report a failed status. An
6. * asynchronous notification is also expected in the ca of mixed data
7. * (i.e. synchronous and asynchronous).
8. *
9. * @note In the ca where multiple nsors are requested, the driver must
0. * attempt to collect data from all requested nsors, meaning that
1. * the time it takes to execute this function will be determined by
2. * the number of nsors sampled, and their various delays. Drivers
3. * must never return partial respons. If a nsor has failed or
4. * isn't available, @a sns_ddf_nsor_data_s.status must be ud to
5. * reflect this status.
6. *
7. * @param[in] dd_handle Handle to a driver instance.
8. * @param[in] nsors List of nsors for which data is requested.
9. * @param[in] num_nsors Number of elements in @a nsors.
0. * @param[in] memhandler Memory handler ud to dynamically allocate
1. * output parameters, if applicable.
2. * @param[out] data Sampled nsor data. The number of elements must
3. * match @a num_nsors.
4. *
5. * @return SNS_DDF_SUCCESS if data was populated successfully. If any of the
6. * nsors queried are to be read asynchronously SNS_DDF_PENDING is
7. * returned and data is via @a sns_ddf_smgr_data_notify() when
8. * available. Otherwi a specific error code is returned.
9. *
0. * @e sns_ddf_data_notify()
1. */
2. sns_ddf_status_e (*get_data)(
3. sns_ddf_handle_t dd_handle,
4. sns_ddf_nsor_e nsors[],
5. uint32_t num_nsors,
6. sns_ddf_memhandler_s* memhandler,
7. sns_ddf_nsor_data_s** data);
88.
9. /**
0. * @brief Sets a nsor attribute to a specific value.
1. *
2. * @param[in] dd_handle Handle to a driver instance.
3. * @param[in] nsor Sensor for which this attribute is to be t. When
4. * addressing an attribute that refers to the driver
5. * this value is t to SNS_DDF_SENSOR__ALL.
6. * @param[in] attrib Attribute to be t.
7. * @param[in] value Value to t this attribute.
8. *
9. * @return Success if the value of the attribute was t properly. Otherwi
0. * a specific error code is returned.
水龙头1. */雷声轰隆隆
2. sns_ddf_status_e (*t_attrib)(
3. sns_ddf_handle_t dd_handle,
4. sns_ddf_nsor_e nsor,
5. sns_ddf_attribute_e attrib,
6. void* value);
107.
8. /**
9. * @brief Retrieves the value of an attribute for a nsor.
0. *
1. * @param[in] dd_handle Handle to a driver instance.
2. * @param[in] nsor Sensor who attribute is to be retrieved. When
3. * addressing an attribute that refers to the driver
4. * this value is t to SNS_DDF_SENSOR__ALL.
5. * @param[in] attrib Attribute to be retrieved.
6. * @param[in] memhandler Memory handler ud to dynamically allocate
7. * output parameters, if applicable.
8. * @param[out] value Pointer that this function will allocate or t
9. * to the attribute's value.
0. * @param[out] num_elems Number of elements in @a value.
1. *
2. * @return Success if the attribute was retrieved and the buffer was
3. * populated. Otherwi a specific error code is returned.
4. */
5. sns_ddf_status_e (*get_attrib)(
6. sns_ddf_handle_t dd_handle,
7. sns_ddf_nsor_e nsor,
8. sns_ddf_attribute_e attrib,
9. sns_ddf_memhandler_s* memhandler,
0. void** value,
1. uint32_t* num_elems);
132.
3. /**
4. * @brief Called when the timer t by this driver has expired. This must be
5. * the callback function submitted when initializing a timer.
6. *
7. * @note This will be called within the context of the Sensors Manager task.
8. *
9. * @param[in] dd_handle Handle to a driver instance.高中英语必修三单词表
0. * @param[in] arg The argument submitted when the timer was t.
1. *
2. * @e sns_ddf_t_timer()
大区经理
3. */
4. void (*handle_timer)(sns_ddf_handle_t dd_handle, void* arg);
145.狼行拂晓
6. /**
7. * @brief Called in respon to an interrupt for this driver.
8. *
9. * @note This function will be called within the context of the SMGR task,
0. * *not* the ISR.
1. *
2. * @param[in] dd_handle Handle to a driver instance.
3. * @param[in] gpio_num GPIO number that triggered this interrupt.
4. * @param[in] timestamp Time at which interrupt happened.
5. */

本文发布于:2023-07-10 01:48:08,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1088311.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:代码   架构   关键
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图