当前位置: 首页 > news >正文

邢台网站优化建设wordpress模块化布局

邢台网站优化建设,wordpress模块化布局,龙岩市建设部网站,深圳市福田区公司参考#xff1a;驱动程序开发#xff1a;SPI设备驱动_spi驱动_邓家文007的博客-CSDN博客 目录 一、SPI驱动简介 1.1 SPI架构概述 1.2 SPI适配器#xff08;控制器#xff09;数据结构 1.2 SPI设备数据结构 1.3 SIP设备驱动 1.4 接口函数 二、SPI驱动模板 一、SPI驱动…参考驱动程序开发SPI设备驱动_spi驱动_邓家文007的博客-CSDN博客 目录 一、SPI驱动简介 1.1 SPI架构概述 1.2 SPI适配器控制器数据结构 1.2 SPI设备数据结构 1.3 SIP设备驱动 1.4 接口函数 二、SPI驱动模板 一、SPI驱动简介 SPI驱动框架和I2C驱动框架是十分相似的不同的是因为SPI是通过片选引脚来选择从机设备的因此SPI不再需要像I2C那样先进行寻址操作查询从机地址后再进行对应寄存器的数据交互并且SPI是全双工通信通信速率要远高于I2C。 但是SPI显然占用的硬件资源也比I2C要多并且SPI没有了像I2C那样指定的流控制例如开始、停止信号和没有了像I2C应当机制导致无法确认数据是否接收到了。 1.1 SPI架构概述 Linux的SPI体系结构可以分为3个组成部分 spi核心SPI CoreSPI Core是Linux内核用来维护和管理spi的核心部分SPI Core提供操作接口函数允许一个spi masterspi driver和spi device初始化时在SPI Core中进行注册以及退出时进行注销。spi控制器驱动或适配器驱动SPI Master DriverSPI Master针对不同类型的spi控制器硬件实现spi总线的硬件访问操作。SPI Master 通过接口函数向SPI Core注册一个控制器。spi设备驱动SPI Device DriverSPI Driver是对应于spi设备端的驱动程序通过接口函数向SPI Core进行注册SPI Driver的作用是将spi设备挂接到spi总线上。 Linux的软件架构图如下图所示  1.2 SPI适配器控制器数据结构 参考内核文件include/linux/spi/spi.h Linux中使用spi_master结构体描述SPI控制器里面最重要的成员就是transfer函数指针 transfer 函数和 i2c_algorithm 中的 master_xfer 函数一样控制器数据传输函数。 transfer_one_message 函数也用于 SPI 数据发送用于发送一个 spi_messageSPI 的数据会打包成 spi_message然后以队列方式发送出去。 1.2 SPI设备数据结构 参考内核文件include/linux/spi/spi.h Linux中使用spi_device结构体描述SPI设备里面记录有设备的片选引脚、频率、挂在哪个SPI控制器下面 1.3 SIP设备驱动 参考内核文件include/linux/spi/spi.h Linux中使用spi_driver结构体描述SPI设备驱动 可以看出spi_driver 和 i2c_driver、 platform_driver 基本一样当 SPI 设备和驱动匹配成功以后 probe 函数就会执行。  比如spi1下面接有两个设备有两个片选信号我们就可以把设备放入子节点里面子节点将有内核解析后转换成一个spi_device与某一个spi_driver匹配后spi_driver里的probe函数就被调用我们在probe函数里就可以注册字符设备驱动程序。 1.4 接口函数 函数原形 简易函数 /*** SPI同步写* spi: 写哪个设备* buf: 数据buffer* len: 长度* 这个函数可以休眠** 返回值: 0-成功, 负数-失败码*/ static inline int spi_write(struct spi_device *spi, const void *buf, size_t len);/*** SPI同步读* spi: 读哪个设备* buf: 数据buffer* len: 长度* 这个函数可以休眠** 返回值: 0-成功, 负数-失败码*/ static inline int spi_read(struct spi_device *spi, void *buf, size_t len);/*** spi_write_then_read : 先写再读, 这是一个同步函数* spi: 读写哪个设备* txbuf: 发送buffer* n_tx: 发送多少字节* rxbuf: 接收buffer* n_rx: 接收多少字节* 这个函数可以休眠* * 这个函数执行的是半双工的操作: 先发送txbuf中的数据在读数据读到的数据存入rxbuf** 这个函数用来传输少量数据(建议不要操作32字节), 它的效率不高* 如果想进行高效的SPI传输请使用spi_{async,sync}(这些函数使用DMA buffer)** 返回值: 0-成功, 负数-失败码*/ extern int spi_write_then_read(struct spi_device *spi,const void *txbuf, unsigned n_tx,void *rxbuf, unsigned n_rx);/*** spi_w8r8 - 同步函数先写8位数据再读8位数据* spi: 读写哪个设备* cmd: 要写的数据* 这个函数可以休眠*** 返回值: 成功的话返回一个8位数据(unsigned), 负数表示失败码*/ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd);/*** spi_w8r16 - 同步函数先写8位数据再读16位数据* spi: 读写哪个设备* cmd: 要写的数据* 这个函数可以休眠** 读到的16位数据: * 低地址对应读到的第1个字节(MSB)高地址对应读到的第2个字节(LSB)* 这是一个big-endian的数据** 返回值: 成功的话返回一个16位数据(unsigned), 负数表示失败码*/ static inline ssize_t spi_w8r16(struct spi_device *spi, u8 cmd);/*** spi_w8r16be - 同步函数先写8位数据再读16位数据* 读到的16位数据被当做big-endian然后转换为CPU使用的字节序* spi: 读写哪个设备* cmd: 要写的数据* 这个函数可以休眠** 这个函数跟spi_w8r16类似差别在于它读到16位数据后会把它转换为native endianness** 返回值: 成功的话返回一个16位数据(unsigned, 被转换为本地字节序), 负数表示失败码*/ static inline ssize_t spi_w8r16be(struct spi_device *spi, u8 cmd); 复杂函数 /*** spi_async - 异步SPI传输函数简单地说就是这个函数即刻返回它返回后SPI传输不一定已经完成* spi: 读写哪个设备* message: 用来描述数据传输里面含有完成时的回调函数(completion callback)* 上下文: 任意上下文都可以使用中断中也可以使用** 这个函数不会休眠它可以在中断上下文使用(无法休眠的上下文)也可以在任务上下文使用(可以休眠的上下文) ** 完成SPI传输后回调函数被调用它是在无法休眠的上下文中被调用的所以回调函数里不能有休眠操作。* 在回调函数被调用前message-statuss是未定义的值没有意义。* 当回调函数被调用时就可以根据message-status判断结果: 0-成功,负数表示失败码* 当回调函数执行完后驱动程序要认为message等结构体已经被释放不能再使用它们。** 在传输过程中一旦发生错误整个message传输都会中止对spi设备的片选被取消。** 返回值: 0-成功(只是表示启动的异步传输并不表示已经传输成功), 负数-失败码*/ extern int spi_async(struct spi_device *spi, struct spi_message *message);/*** spi_sync - 同步的、阻塞的SPI传输函数简单地说就是这个函数返回时SPI传输要么成功要么失败* spi: 读写哪个设备* message: 用来描述数据传输里面含有完成时的回调函数(completion callback)* 上下文: 能休眠的上下文才可以使用这个函数** 这个函数的message参数中使用的buffer是DMA buffer** 返回值: 0-成功, 负数-失败码*/ extern int spi_sync(struct spi_device *spi, struct spi_message *message);/*** spi_sync_transfer - 同步的SPI传输函数* spi: 读写哪个设备* xfers: spi_transfers数组用来描述传输* num_xfers: 数组项个数* 上下文: 能休眠的上下文才可以使用这个函数** 返回值: 0-成功, 负数-失败码*/ static inline int spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers,unsigned int num_xfers); 二、SPI驱动模板 spi_drv.c #include linux/spi/spi.h #include linux/module.h #include linux/poll.h#include linux/fs.h #include linux/errno.h #include linux/miscdevice.h #include linux/kernel.h #include linux/major.h #include linux/mutex.h #include linux/proc_fs.h #include linux/seq_file.h #include linux/stat.h #include linux/init.h #include linux/device.h #include linux/tty.h #include linux/kmod.h #include linux/gfp.h #include linux/gpio/consumer.h #include linux/platform_device.h #include linux/of_gpio.h #include linux/of_irq.h #include linux/interrupt.h #include linux/irq.h #include linux/slab.h #include linux/fcntl.h #include linux/timer.h/* 主设备号 */ static int major 0; static struct class *my_spi_class;static struct spi_device *g_spi;static DECLARE_WAIT_QUEUE_HEAD(gpio_wait); struct fasync_struct *spi_fasync;/* 实现对应的open/read/write等函数填入file_operations结构体 */ static ssize_t spi_drv_read (struct file *file, char __user *buf, size_t size, loff_t *offset) {// int err;// struct spi_transfer msgs[2];/* 初始化 spi_transfer */// static inline int// spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers,// unsigned int num_xfers);/* copy_to_user */return 0; }static ssize_t spi_drv_write(struct file *file, const char __user *buf, size_t size, loff_t *offset) {//int err;/* copy_from_user */// struct spi_transfer msgs[2];/* 初始化 spi_transfer */// static inline int// spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers,// unsigned int num_xfers);return 0; }static unsigned int spi_drv_poll(struct file *fp, poll_table * wait) {//printk(%s %s line %d\n, __FILE__, __FUNCTION__, __LINE__);poll_wait(fp, gpio_wait, wait);//return is_key_buf_empty() ? 0 : POLLIN | POLLRDNORM;return 0; }static int spi_drv_fasync(int fd, struct file *file, int on) {if (fasync_helper(fd, file, on, spi_fasync) 0)return 0;elsereturn -EIO; }/* 定义自己的file_operations结构体 */ static struct file_operations spi_drv_fops {.owner THIS_MODULE,.read spi_drv_read,.write spi_drv_write,.poll spi_drv_poll,.fasync spi_drv_fasync, };static int spi_drv_probe(struct spi_device *spi) {// struct device_node *np client-dev.of_node;/* 记录spi_device */g_spi spi;/* 注册字符设备 *//* 注册file_operations */major register_chrdev(0, 100ask_spi, spi_drv_fops); /* /dev/gpio_desc */my_spi_class class_create(THIS_MODULE, 100ask_spi_class);if (IS_ERR(my_spi_class)) {printk(%s %s line %d\n, __FILE__, __FUNCTION__, __LINE__);unregister_chrdev(major, 100ask_spi);return PTR_ERR(my_spi_class);}device_create(my_spi_class, NULL, MKDEV(major, 0), NULL, myspi); /* /dev/myspi */return 0; }static int spi_drv_remove(struct spi_device *spi) {/* 反注册字符设备 */device_destroy(my_spi_class, MKDEV(major, 0));class_destroy(my_spi_class);unregister_chrdev(major, 100ask_spi);return 0; }static const struct of_device_id myspi_dt_match[] {{ .compatible 100ask,spidev },{}, }; static struct spi_driver my_spi_driver {.driver {.name 100ask_spi_drv,.owner THIS_MODULE,.of_match_table myspi_dt_match,},.probe spi_drv_probe,.remove spi_drv_remove, };static int __init spi_drv_init(void) {/* 注册spi_driver */return spi_register_driver(my_spi_driver); }static void __exit spi_drv_exit(void) {/* 反注册spi_driver */spi_unregister_driver(my_spi_driver); }/* 7. 其他完善提供设备信息自动创建设备节点 */module_init(spi_drv_init); module_exit(spi_drv_exit);MODULE_LICENSE(GPL);
http://www.dnsts.com.cn/news/123530.html

相关文章:

  • 网站建设视频教程最新成都协会网站建设
  • 做网站需要用到技术国家信息企业信用信息公示系统
  • 滁州网站建设费用尚石设计深圳有限公司
  • 廊坊高端网站建设东莞网站建设关键词
  • 怎么在建设银行网站留言网站型与商城型有什么区别吗
  • 网站网站怎么优化关键词排名房地产类型的网站建设
  • 长沙网站seo费用广州网站建设乐云seo模板中心
  • 网站左侧固定广告代码wordpress首页是什么意思
  • 网站建设与管理ppt模板下载python编程是干嘛的
  • 杭州网站建设官网蓝韵网络广州餐饮管理有限公司
  • 深圳电信网站备案注册深圳公司
  • 行政审批网站开发文档wordpress苏醒主题grace
  • 网站建设所出现的问题网站PC关键词怎么做
  • 微信小程序与微网站韩国网站never官网
  • 那个企业建网站好wordpress 星 评分
  • 亳州建设局网站公司网站 域名 cn com
  • 注册一个公司的所有流程单页网站seo优化
  • 海南茶叶网站建设货源之家
  • 基于阿里云的电商网站建设wordpress 粉丝
  • 网站建设介绍的ppt网站建设套模
  • 做网站 百度推广桐乡哪里有做网站的
  • 做网站需要什么域名优秀的国内企业网站
  • 百度抓取不到网站电信开放81端口怎样做网站
  • 数据线厂家东莞网站建设软文营销的写作技巧有哪些
  • 免费的设计网站有哪些广州新闻最新消息今天
  • 网站建设属于硬件还是软件学校网站建设电话
  • 做设备推广的网站phpcms仿站
  • 流浪动物网站开发网站建设公众号
  • 双语网站模板下载怎么优化整站
  • 长沙本土网站建设公司做网站接电话一般要会什么问题