linux系統怎么用,linux中IIO子系統------IIO數據結構部分解析1

 2023-10-17 阅读 30 评论 0

摘要:一、kernel/include/linux/iio/iio.h 1.iio_dev結構體 struct iio_dev {int id;struct module *driver_module;int modes;//表示設備支持的不同操作模式int currentmode;//表示設備實際使用的模式struct device dev;//表示IIO設備所依賴的struct設備(根據Linux設備型號)struct

一、kernel/include/linux/iio/iio.h
1.iio_dev結構體

struct iio_dev {int				id;struct module			*driver_module;int				modes;//表示設備支持的不同操作模式int				currentmode;//表示設備實際使用的模式struct device			dev;//表示IIO設備所依賴的struct設備(根據Linux設備型號)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;//當前設備觸發器(支持緩沖模式時)bool				trig_readonly;struct iio_poll_func		*pollfunc;//在接收的觸發器上運行的函數struct iio_poll_func		*pollfunc_event;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;//來自驅動程序的回調和持續信息clockid_t			clock_id;struct mutex			info_exist_lock;const struct iio_buffer_setup_ops	*setup_ops;//啟用/禁用緩沖區之前和之后調用的回調函數集struct cdev			chrdev;//由IIO核心創建的關聯字符設備
#define IIO_MAX_GROUPS 6const 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
};
  • modes:支持的模式有
    INDIO_DIRECT_MODE表示設備提供的sysfs接口。
    INDIO_BUFFER_TRIGGERED表示設備支持硬件觸發器。 使用iio_triggered_buffer_setup()函數設置觸發緩沖區時,此模式會自動添加到設備中。
    INDIO_BUFFER_HARDWARE表示設備具有硬件緩沖區。
    INDIO_ALL_BUFFER_MODES是上述兩者的聯合
  • buffer:使用iio_triggered_buffer_setup函數啟用觸發緩沖區支持時,它會自動分配并與您的設備關聯
  • scan_bytes:當從用戶空間使用觸發緩沖區時,緩沖區應至少為indio->scan_bytes字節大
  • available_scan_masks:使用觸發緩沖器時,可以啟用通道捕獲并將其饋入IIO緩沖區,若不允許某些通道啟用,則僅使用允許的通道填充此數組
enum max3012_led_idx {MAX30102_LED_RED,MAX30102_LED_IR,MAX30105_LED_GREEN,
};
//可選
static const unsigned long max30102_scan_masks[] = {BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR),0
};
static const unsigned long max30105_scan_masks[] = {BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR),BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR) |BIT(MAX30105_LED_GREEN),0
};
indio_dev->available_scan_masks = max30105_scan_masks;
  • active_scan_mask:啟用通道的位掩碼。 只有來自這些通道的數據能被推入緩沖區。例如,對于8通道ADC轉換器,如果只啟用第一個(0),第三個(2)和最后一個(7)通道,則位掩碼將為0b10000101(0x85)。active_scan_mask將設置為0x85。然后,驅動程序可以使用for_each_set_bit宏遍歷每個設置位,根據通道獲取數據,并填充緩沖區
for_each_set_bit(bit, indio_dev->active_scan_mask,indio_dev->masklength) {ret = kmx61_read_measurement(data, base, bit);if (ret < 0) {mutex_unlock(&data->lock);goto err;}buffer[i++] = ret;}
  • scan_timestamp:是否將捕獲時間戳推入緩沖區。 如果為true,則將時間戳作為緩沖區的最后一個元素。時間戳大8字節(64位)

2.iio_info結構體

//kernel/include/linux/iio/iio.h
struct iio_info {const struct attribute_group	*event_attrs;const struct attribute_group	*attrs;//表示設備屬性//用戶讀取設備sysfs文件屬性時的回調運行int (*read_raw)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask);int (*read_raw_multi)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int max_len,int *vals,int *val_len,long mask);int (*read_avail)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,const int **vals,int *type,int *length,long mask);//用于將值寫入設備的回調int (*write_raw)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int val,int val2,long mask);int (*write_raw_get_fmt)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,long mask);int (*read_event_config)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir);int (*write_event_config)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir,int state);int (*read_event_value)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir,enum iio_event_info info, int *val, int *val2);int (*write_event_value)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir,enum iio_event_info info, int val, int val2);int (*validate_trigger)(struct iio_dev *indio_dev,struct iio_trigger *trig);int (*update_scan_mode)(struct iio_dev *indio_dev,const unsigned long *scan_mask);int (*debugfs_reg_access)(struct iio_dev *indio_dev,unsigned reg, unsigned writeval,unsigned *readval);int (*of_xlate)(struct iio_dev *indio_dev,const struct of_phandle_args *iiospec);int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned val);int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev,unsigned count);
};
//示例
static const struct iio_info kmx61_acc_info = {.read_raw		= kmx61_read_raw,.write_raw		= kmx61_write_raw,.attrs			= &kmx61_acc_attribute_group,.read_event_value	= kmx61_read_event,.write_event_value	= kmx61_write_event,.read_event_config	= kmx61_read_event_config,.write_event_config	= kmx61_write_event_config,.validate_trigger	= kmx61_acc_validate_trigger,
};
indio_dev->info = &kmx61_acc_info;

3.iio_chan_spec結構體

//通道代表單條采集線
struct iio_chan_spec {enum iio_chan_type	type;//指定了通道的測量類型int			channel;//指定.indexed設置為1時的通道索引int			channel2;//指定.modified設置為1時的通道修飾unsigned long		address;
//scan_index and scan_type: 當使用緩沖區觸發器時,這些字段用于標識緩沖區中的元素int			scan_index;//設置緩沖區內捕獲的通道的位置,.scan_index=-1將阻止通道緩沖捕獲struct {char	sign; //'s' or 'u'描述有符號和無符號u8	realbits;//有效位數u8	storagebits;//Realbits + paddingu8	shift;u8	repeat;enum iio_endian endianness; //little or big endian,字節序} scan_type;long			info_mask_separate;//將屬性標記為特定于此通道long			info_mask_separate_available;long			info_mask_shared_by_type;//將該屬性標記為由相同類型的所有通道共享long			info_mask_shared_by_type_available;long			info_mask_shared_by_dir;//將屬性標記為由同一方向的所有通道共享long			info_mask_shared_by_dir_available;long			info_mask_shared_by_all;//將屬性標記為所有通道共享long			info_mask_shared_by_all_available;const struct iio_event_spec *event_spec;unsigned int		num_event_specs;const struct iio_chan_spec_ext_info *ext_info;//描述一個channel擴展屬性相關的信息,包括屬性名稱、讀寫接口等const char		*extend_name;const char		*datasheet_name;unsigned		modified:1;//指定是否將修飾符應用于此通道屬性名稱,飾符設置在.channel2中unsigned		indexed:1;//指定通道屬性名稱是否具有索引,若是,在.channel字段中指定索引unsigned		output:1;  //channel是輸出unsigned		differential:1;
};
  • type: 指定了通道的測量類型。 在電壓測量的情況下,它應該是IIO_VOLTAGE。 對于光傳感器,它是IIO_LIGHT。對于加速度計,使用IIO_ACCEL。 所有可用類型都在include / uapi / linux / iio /types.h中定義,如enum iio_chan_type。 要為給定轉換器編寫驅動程序,請查看該文件以查看每個通道所屬的類型
//type對應的通道類型根據iio_chan_type_name_spec
static const char * const iio_chan_type_name_spec[] = {[IIO_VOLTAGE] = "voltage",[IIO_CURRENT] = "current",[IIO_POWER] = "power",[IIO_ACCEL] = "accel",
};
//channel2字段根據modifier=1時iio_modifier_names
static const char * const iio_modifier_names[] = {[IIO_MOD_X] = "x",[IIO_MOD_Y] = "y",[IIO_MOD_Z] = "z",[IIO_MOD_X_AND_Y] = "x&y",
};
//info_mask取決于char數組iio_chan_info_postfix中的通道信息掩碼
static const char * const iio_chan_info_postfix[] = {[IIO_CHAN_INFO_RAW] = "raw",[IIO_CHAN_INFO_PROCESSED] = "input",[IIO_CHAN_INFO_SCALE] = "scale",[IIO_CHAN_INFO_OFFSET] = "offset",
};

參考鏈接請點擊而此處
IIO子系統概述請點擊此處
在學習中進步,如有錯誤,請多多批評指正

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/148405.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息