IIO子系统(草稿)

简介

IIO子系统全称是Industrial I/O subsystem(工业 I/O 子系统),是专用于模数转换器(ADC)和数模转换器(DAC)的内核子系统,属于IIO的设备如下(参考ADI的WiKi):

  1. ADCs(模数转换器)
  2. 加速度传感器
  3. 陀螺仪
  4. IMUs(惯性测量单位)
  5. 电容-数字转换器(CDCs)
  6. 压力、温度和光线传感器

IIO模型基于设备和通道架构:

  • 设备代表芯片本身,它是层次结构的顶级。
  • 通道代表设备的单个采集线,设备可以具有一个或多个通道。例如,加速度计是具有 三个通道的装置,每个通道对应一个轴(X,Y和Z)。

IIO框架

设备节点

IIO芯片是物理和硬件传感器/转换器。它作为字符设备(当支持触发缓冲时)暴露给用户空间,以及包含一组文件的sysfs目录条目,其中一些文件代表通道。单个通道用单个sysfs文件条目表示。
下面是从用户空间与IIO驱动程序交互的两种方式:

  1. /sys/bus/iio/iio:deviceX: 表示传感器及其通道
  2. /dev/iio:deviceX: 表示导出设备事件和数据缓冲区的字符设备

框架图示

数据结构

IIO子系统关键对象有两个:设备、通道,以下进一步说明。

设备

设备对应数据结构为:

/**
 * struct iio_dev - industrial I/O device
 * @id:            [INTERN] used to identify device internally
 * @modes:        [DRIVER] operating modes supported by device
 * @currentmode:    [DRIVER] current operating mode
 * @dev:        [DRIVER] device structure, should be assigned a parent
 *            and owner
 * @event_interface:    [INTERN] event chrdevs associated with interrupt lines
 * @buffer:        [DRIVER] any buffer present
 * @buffer_list:    [INTERN] list of all buffers currently attached
 * @scan_bytes:        [INTERN] num bytes captured to be fed to buffer demux
 * @mlock:        [INTERN] lock used to prevent simultaneous device state
 *            changes
 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
 * @masklength:        [INTERN] the length of the mask established from
 *            channels
 * @active_scan_mask:    [INTERN] union of all scan masks requested by buffers
 * @scan_timestamp:    [INTERN] set if any buffers have requested timestamp
 * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
 * @trig:        [INTERN] current device trigger (buffer modes)
 * @pollfunc:        [DRIVER] function run on trigger being received
 * @channels:        [DRIVER] channel specification structure table
 * @num_channels:    [DRIVER] number of channels specified in @channels.
 * @channel_attr_list:    [INTERN] keep track of automatically created channel
 *            attributes
 * @chan_attr_group:    [INTERN] group for all attrs in base directory
 * @name:        [DRIVER] name of the device.
 * @info:        [DRIVER] callbacks and constant info from driver
 * @info_exist_lock:    [INTERN] lock to prevent use during removal
 * @setup_ops:        [DRIVER] callbacks to call before and after buffer
 *            enable/disable
 * @chrdev:        [INTERN] associated character device
 * @groups:        [INTERN] attribute groups
 * @groupcounter:    [INTERN] index of next attribute group
 * @flags:        [INTERN] file ops related flags including busy flag.
 * @debugfs_dentry:    [INTERN] device specific debugfs dentry.
 * @cached_reg_addr:    [INTERN] cached register address for debugfs reads.
 */
struct iio_dev {
    int                id;

    int                modes;
    int                currentmode;
    struct device            dev;

    struct iio_event_interface    *event_interface;

    struct iio_buffer        *buffer;
    struct list_head        buffer_list;
    int                scan_bytes;
    struct mutex            mlock;

    const unsigned long        *available_scan_masks;
    unsigned            masklength;
    const unsigned long        *active_scan_mask;
    bool                scan_timestamp;
    unsigned            scan_index_timestamp;
    struct iio_trigger        *trig;
    struct iio_poll_func        *pollfunc;

    struct iio_chan_spec const    *channels;
    int                num_channels;

    struct list_head        channel_attr_list;
    struct attribute_group        chan_attr_group;
    const char            *name;
    const struct iio_info        *info;
    struct mutex            info_exist_lock;
    const struct iio_buffer_setup_ops    *setup_ops;
    struct cdev            chrdev;
#define IIO_MAX_GROUPS 6
    const struct attribute_group    *groups[IIO_MAX_GROUPS + 1];
    int                groupcounter;

    unsigned long            flags;
#if defined(CONFIG_DEBUG_FS)
    struct dentry            *debugfs_dentry;
    unsigned            cached_reg_addr;
#endif
};
posted @ 2020-05-30 00:03  gaoyang3513  阅读(636)  评论(0编辑  收藏  举报