Linux中SPI

参考资料

https://www.cnblogs.com/aaronLinux/p/6219146.html

1.SPI
在这里插入图片描述
2.SPI传输
2.1传输示例

首先,CS0拉低选中的SPI Flash ,
然后在每个时钟周期,
DO输出对应的电平。
SPI FLASH会在每个时钟的上升沿读取D0的电平。

在这里插入图片描述
2.2SPI模式
根据SCK的电平以及数据在第一个跳变沿还是第二个跳变沿传输,SPI传输总共有四种模式。
在这里插入图片描述
在这里插入图片描述
3.SPI总线设备驱动模型

SPI系统中设涉及两类硬件:
SPI控制器
SPI设备

在这里插入图片描述
spi控制器有驱动程序,提供spi的传输能力。
spi设备也有自己的驱动程序,提供spi设备的访问能力。
4.spi设备驱动框架图

SPI驱动程序由spi_master及spi_device组成
spi_master是在设备树中定义的spi master及master
下边的device信息;当左边drive中的of_device_id和设备树中的compatible参数匹配的时候,会调用driver中的prboe函数,probe函数会生成master,还会生成spi_device。
spi设备左边包括一个spi驱动,当其中的of_device_id和spi_device匹配时,会调用左边driver中的probe函数。

在这里插入图片描述
4.1SPI控制器驱动程序
基于平台总线设备驱动模型实现。在probe函数中除了生成spi_master,还会创建spi_device结构体。
在这里插入图片描述
4.2SPI设备驱动程序

左边是spi_drive,里边有id_table表示能支持哪些SPI设备,有probe函数。
右边是spi_device,用来描述spi设备,可以来自设备树或者c文件

在这里插入图片描述

5.spi设备树处理过程
5.1spi_device

/*** struct spi_device - Master side proxy for an SPI slave device* @dev: Driver model representation of the device.* @master: SPI controller used with the device.* @max_speed_hz: Maximum clock rate to be used with this chip*	(on this board); may be changed by the device's driver.*	The spi_transfer.speed_hz can override this for each transfer.* @chip_select: Chipselect, distinguishing chips handled by @master.* @mode: The spi mode defines how data is clocked out and in.*	This may be changed by the device's driver.*	The "active low" default for chipselect mode can be overridden*	(by specifying SPI_CS_HIGH) as can the "MSB first" default for*	each word in a transfer (by specifying SPI_LSB_FIRST).* @bits_per_word: Data transfers involve one or more words; word sizes*	like eight or 12 bits are common.  In-memory wordsizes are*	powers of two bytes (e.g. 20 bit samples use 32 bits).*	This may be changed by the device's driver, or left at the*	default (0) indicating protocol words are eight bit bytes.*	The spi_transfer.bits_per_word can override this for each transfer.* @irq: Negative, or the number passed to request_irq() to receive*	interrupts from this device.* @controller_state: Controller's runtime state* @controller_data: Board-specific definitions for controller, such as*	FIFO initialization parameters; from board_info.controller_data* @modalias: Name of the driver to use with this device, or an alias*	for that name.  This appears in the sysfs "modalias" attribute*	for driver coldplugging, and in uevents used for hotplugging* @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when*	when not using a GPIO line)** @statistics: statistics for the spi_device** A @spi_device is used to interchange data between an SPI slave* (usually a discrete chip) and CPU memory.** In @dev, the platform_data is used to hold information about this* device that's meaningful to the device's protocol driver, but not* to its controller.  One example might be an identifier for a chip* variant with slightly different functionality; another might be* information about how this particular board wires the chip's pins.*/
struct spi_device {struct device		dev;struct spi_master	*master;u32			max_speed_hz;/* 该设备能支持的spi时钟最大值 */u8			chip_select;/* 是对应的spi_master下边的第几个设备 */u8			bits_per_word;/* 每个基本的spi传输涉及多少位 */u16			mode; /*spi_chpa  spi_cpol组合起来得到spi传输的四种模式 */
#define	SPI_CPHA	0x01			/* clock phase */
#define	SPI_CPOL	0x02			/* clock polarity */
#define	SPI_MODE_0	(0|0)			/* (original MicroWire) */
#define	SPI_MODE_1	(0|SPI_CPHA)
#define	SPI_MODE_2	(SPI_CPOL|0)
#define	SPI_MODE_3	(SPI_CPOL|SPI_CPHA)
#define	SPI_CS_HIGH	0x04			/* chipselect active high? */
#define	SPI_LSB_FIRST	0x08			/* per-word bits-on-wire */
#define	SPI_3WIRE	0x10			/* SI/SO signals shared */
#define	SPI_LOOP	0x20			/* loopback mode */
#define	SPI_NO_CS	0x40			/* 1 dev/bus, no chipselect */
#define	SPI_READY	0x80			/* slave pulls low to pause */
#define	SPI_TX_DUAL	0x100			/* transmit with 2 wires */
#define	SPI_TX_QUAD	0x200			/* transmit with 4 wires */
#define	SPI_RX_DUAL	0x400			/* receive with 2 wires */
#define	SPI_RX_QUAD	0x800			/* receive with 4 wires */int			irq;void			*controller_state;void			*controller_data;char			modalias[SPI_NAME_SIZE];int			cs_gpio;	/* chip select gpio *//* the statistics */struct spi_statistics	statistics;/** likely need more hooks for more protocol options affecting how* the controller talks to each chip, like:*  - memory packing (12 bit samples into low bits, others zeroed)*  - priority*  - drop chipselect after each word*  - chipselect delays*  - ...*/
};

5.2设备树中的spi节点

    spi4 {compatible = "spi-gpio";/* 这个属性很关键,因为根据这个属性找到spi_master */pinctrl-names = "default";pinctrl-0 = <&pinctrl_spi4>;pinctrl-assert-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;status = "okay";gpio-sck = <&gpio5 11 0>;gpio-mosi = <&gpio5 10 0>;cs-gpios = <&gpio5 7 0>;num-chipselects = <1>;#address-cells = <1>;/* 这个SPI Master下的SPI设备,需要多少个cell来表述它的片选引脚 */#size-cells = <0>; /* 这个必须设置为0 *//* gpio_spi是spi_master 下边的device节点 */gpio_spi: gpio_spi@0 {compatible = "fairchild,74hc595";/* 根据它找到spi device驱动 */gpio-controller;#gpio-cells = <2>;reg = <0>;/* 使用哪个片选引脚 */registers-number = <1>;registers-default = /bits/ 8 <0x57>;spi-max-frequency = <10000>;/* 该设备支持的最大spi时钟 */};};

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/58683.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自旋锁--死锁

本文内容整理自B站视频教程 自旋锁定义 内核发生访问资源冲突的时候&#xff0c;可以有两种锁的解决方案选择&#xff1a;一个是原地等待&#xff0c;一个是挂起当前进程&#xff0c;调度其他进程执行(休眠)。 spinlock是内核中提供的一种比较常见的锁机制&#xff0c;自旋锁…

ICM20948 DMP代码详解(107)

接前一篇文章:ICM20948 DMP代码详解(106) 上一回开始解析inv_set_hw_smplrt_dmp_odrs函数中的以下代码片段: if (s->b2s_status != 0) {unsigned short lB2SMinDly = min(INV_ODR_DEFAULT_B2S, minDly_accel);lB2SMinDly = 1000/(get_multiple_56_rate(lB2SMinDly));dmp…

【C++】继承和多态常见的面试问题

文章目录 继承笔试面试题1. 什么是菱形继承&#xff1f;菱形继承的问题是什么&#xff1f;2. 什么是菱形虚拟继承&#xff1f;如何解决数据冗余和二义性&#xff1f;3. 继承和组合的区别&#xff1f;什么时候用继承&#xff1f;什么时候用组合&#xff1f; 选择题 多态概念考察…

Android gradle和maven国内镜像地址

在Android 开发中经常会出现gradle或者maven依赖下载过慢或者失败的情况&#xff0c;如果出现这种情况的话&#xff0c;那就需要使用国内镜像地址&#xff0c;本文章仅作记录&#xff0c;方便后续查取。 gradle国内镜像地址 这里提供的是腾讯的国内gradle镜像地址。 https://…

人工智能:机遇与挑战

人工智能&#xff08;AI&#xff09;作为当今世界科技发展的前沿领域&#xff0c;正在以前所未有的速度和规模影响着我们的生活和工作方式。AI技术的应用前景广阔&#xff0c;从医疗健康到金融服务&#xff0c;从教育到交通&#xff0c;再到娱乐和家庭生活&#xff0c;AI正在逐…

数字IC开发:布局布线

数字IC开发&#xff1a;布局布线 前端经过DFT&#xff0c;综合后输出网表文件给后端&#xff0c;由后端通过布局布线&#xff0c;将网表转换为GDSII文件&#xff1b;网表文件只包含单元器件及其连接等信息&#xff0c;GDS文件则包含其物理位置&#xff0c;具体的走线&#xff1…

Python爬虫的“京东大冒险”:揭秘商品类目信息

开篇&#xff1a;欢迎来到Python的奇幻森林 在这个数据驱动的时代&#xff0c;我们就像一群探险家&#xff0c;穿梭在数字的森林中&#xff0c;寻找着隐藏的宝藏——商品类目信息。今天&#xff0c;我们将带领你一起&#xff0c;用Python这把锋利的剑&#xff0c;深入京东的神…

Flutter 13 网络层框架架构设计,支持dio等框架。

在移动APP开发过程中&#xff0c;进行数据交互时&#xff0c;大多数情况下必须通过网络请求来实现。客户端与服务端常用的数据交互是通过HTTP请求完成。面对繁琐业务网络层&#xff0c;我们该如何通过网络层架构设计来有效解决这些问题&#xff0c;这便是网络层框架架构设计的初…

LLM大模型部署实战指南:部署简化流程

LLM大模型部署实战指南:Ollama简化流程,OpenLLM灵活部署,LocalAI本地优化,Dify赋能应用开发 1. Ollama 部署的本地模型(🔺) Ollama 是一个开源框架,专为在本地机器上便捷部署和运行大型语言模型(LLM)而设计。,这是 Ollama 的官网地址:https://ollama.com/ 以下是其…

Qt限制QGraphicsScene QGraphicsItem内部的移动范围

用过QGraphicsView的都知道&#xff0c;原点一般设定在view和item的中心&#xff0c;所以帮助文档和这个网友说的不一定跟我们对的上&#xff1a; 关于Qt限制QGraphicsScene内部Item的移动范围_qgraphicsitem限制移动范围-CSDN博客 首先&#xff0c;设定view的scenerect&…

电能表预付费系统-标准传输规范(STS)(27)

6.5.2.5 KeyRevisionNumber (KRN) Each SupplyGroup has one or more VendingKeys associated with it. A KRN uniquely identifies a VendingKey within the SupplyGroup. Together the SGC and KRN uniquely identify a VendingKey. 每个SupplyGroup都有一个或多个与之相关联…

git回滚间隔的提交

如果你需要回滚几个非连续的提交&#xff0c;可以使用 git revert 来选择性地撤销这些提交。这样做不会改变提交历史&#xff0c;只是会在当前分支上创建新的提交来反转指定的更改。 ### 使用 git revert 回滚间隔的提交 1. **查看提交历史**&#xff1a; 首先&#xff0c…

【数据结构-邻项消除】力扣2211. 统计道路上的碰撞次数

在一条无限长的公路上有 n 辆汽车正在行驶。汽车按从左到右的顺序按从 0 到 n - 1 编号&#xff0c;每辆车都在一个 独特的 位置。 给你一个下标从 0 开始的字符串 directions &#xff0c;长度为 n 。directions[i] 可以是 ‘L’、‘R’ 或 ‘S’ 分别表示第 i 辆车是向 左 、…

强网拟态的复现

web ez_picker 这题的考点 capoo Misc ezflag 这题涉及到kali的工具使用&#xff0c;binwalk或者formost 1.将压缩包拖进010&#xff0c;发现包含flag.zip文件&#xff0c;想到使用工具进行分离 命令&#xff1a;binwalk -e .... --run-asroot 分离流量包 得到一个文件&…

【Effective C++】阅读笔记2

1. 复制对象时要保证复制内容完整性 错误场景复现&#xff08;没有复制基类部分&#xff09; 如果一个类中包含多个成员变量或者继承了基类&#xff0c;那么在拷贝构造函数或者赋值运算符中&#xff0c;必须保证所有成员的基类部分被复制。 基类没有被复制&#xff0c;这样就都…

数组移除元素

目录 题目方法一&#xff1a;直接(暴力)求解法思路分析代码如下 方法二&#xff1a;双指针&#xff08;快慢指针&#xff09;思路分析代码如下 题目 这道题是来自于leetcode的一道算法题&#xff1a; 给你一个数组 nums 和一个值 val&#xff0c;你需要 原地 移除所有数值等于…

【Flask】二、Flask 路由机制

目录 什么是路由&#xff1f; Flask中的路由 基本路由 动态路由 路由中的HTTP方法 路由函数返回 在Web开发中&#xff0c;路由是将URL映射到相应的处理函数的过程。Flask是一个轻量级的Web应用框架&#xff0c;提供了简单而强大的路由机制&#xff0c;使得开发者能够轻松…

【IC验证_systemverilog】信号类型

IC验证_systemverilog 1.信号声明2.变量类型3.数据类型4.符号 1.信号声明 语法&#xff1a; 变量类型 信号类型 符号转换 位宽 信号名 深度&#xff1b;2.变量类型 &#xff08;1&#xff09;说明&#xff1a; systemverilog中的信号类型主要分为线网类型&#xff08;wire&a…

yt-dlp下载视频

插件官方下载地址 通过以下命令行使用 yt-dlp下载 (base) D:\tool\video>cd D:\tool\video (base) PS D:\tool\video> .\vdownlod.bat 此处输入链接或者(base) D:\tool\video>yt-dlp -f bv[extmp4]ba[extm4a] --cookies d:\Downloads\www.youtube.com_cookies.txt -…

《模拟电子技术基础》第六版PDF课后题答案详解

《模拟电子技术基础》第六版是在获首届全国优秀教材建设奖一等奖的第五版的基础上&#xff0c;总结6年来的教学实践经验修订而成的新形态教材。为满足国家人才培养的需求&#xff0c;适应新型教学模式&#xff0c;并考虑到大多数院校逐渐减少课程学时的现状&#xff0c;在不降低…