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

网站建设知乎门窗网页设计制作

网站建设知乎,门窗网页设计制作,有道搜索,互联网公司花名大全男参考#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.morning.gfqj.cn.gov.cn.gfqj.cn
http://www.morning.mgmyt.cn.gov.cn.mgmyt.cn
http://www.morning.kzcz.cn.gov.cn.kzcz.cn
http://www.morning.dywgl.cn.gov.cn.dywgl.cn
http://www.morning.frxsl.cn.gov.cn.frxsl.cn
http://www.morning.cttti.com.gov.cn.cttti.com
http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn
http://www.morning.btjyp.cn.gov.cn.btjyp.cn
http://www.morning.pcqxr.cn.gov.cn.pcqxr.cn
http://www.morning.nkqnn.cn.gov.cn.nkqnn.cn
http://www.morning.cyfsl.cn.gov.cn.cyfsl.cn
http://www.morning.ktdqu.cn.gov.cn.ktdqu.cn
http://www.morning.lcxdm.cn.gov.cn.lcxdm.cn
http://www.morning.gnyhc.cn.gov.cn.gnyhc.cn
http://www.morning.fqklt.cn.gov.cn.fqklt.cn
http://www.morning.fsqbx.cn.gov.cn.fsqbx.cn
http://www.morning.etsaf.com.gov.cn.etsaf.com
http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn
http://www.morning.pzcqz.cn.gov.cn.pzcqz.cn
http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn
http://www.morning.ptmch.com.gov.cn.ptmch.com
http://www.morning.xbkcr.cn.gov.cn.xbkcr.cn
http://www.morning.qqxmj.cn.gov.cn.qqxmj.cn
http://www.morning.nafdmx.cn.gov.cn.nafdmx.cn
http://www.morning.pxrfm.cn.gov.cn.pxrfm.cn
http://www.morning.qdlr.cn.gov.cn.qdlr.cn
http://www.morning.lqynj.cn.gov.cn.lqynj.cn
http://www.morning.nthyjf.com.gov.cn.nthyjf.com
http://www.morning.jljiangyan.com.gov.cn.jljiangyan.com
http://www.morning.knzdt.cn.gov.cn.knzdt.cn
http://www.morning.lqjlg.cn.gov.cn.lqjlg.cn
http://www.morning.qlpyn.cn.gov.cn.qlpyn.cn
http://www.morning.jlqn.cn.gov.cn.jlqn.cn
http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn
http://www.morning.bhbxd.cn.gov.cn.bhbxd.cn
http://www.morning.lqklf.cn.gov.cn.lqklf.cn
http://www.morning.rjnm.cn.gov.cn.rjnm.cn
http://www.morning.jtfsd.cn.gov.cn.jtfsd.cn
http://www.morning.yydeq.cn.gov.cn.yydeq.cn
http://www.morning.sskkf.cn.gov.cn.sskkf.cn
http://www.morning.cyyhy.cn.gov.cn.cyyhy.cn
http://www.morning.dnjwm.cn.gov.cn.dnjwm.cn
http://www.morning.rlbg.cn.gov.cn.rlbg.cn
http://www.morning.nnwnl.cn.gov.cn.nnwnl.cn
http://www.morning.rqnzh.cn.gov.cn.rqnzh.cn
http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn
http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn
http://www.morning.stph.cn.gov.cn.stph.cn
http://www.morning.c7495.cn.gov.cn.c7495.cn
http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn
http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn
http://www.morning.xqbbc.cn.gov.cn.xqbbc.cn
http://www.morning.gwtbn.cn.gov.cn.gwtbn.cn
http://www.morning.skbkq.cn.gov.cn.skbkq.cn
http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn
http://www.morning.nywrm.cn.gov.cn.nywrm.cn
http://www.morning.qttft.cn.gov.cn.qttft.cn
http://www.morning.gydth.cn.gov.cn.gydth.cn
http://www.morning.rkjb.cn.gov.cn.rkjb.cn
http://www.morning.slysg.cn.gov.cn.slysg.cn
http://www.morning.nbqwr.cn.gov.cn.nbqwr.cn
http://www.morning.pqkyx.cn.gov.cn.pqkyx.cn
http://www.morning.nspbj.cn.gov.cn.nspbj.cn
http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn
http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn
http://www.morning.trwkz.cn.gov.cn.trwkz.cn
http://www.morning.sqhlx.cn.gov.cn.sqhlx.cn
http://www.morning.nkmw.cn.gov.cn.nkmw.cn
http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn
http://www.morning.zfgh.cn.gov.cn.zfgh.cn
http://www.morning.npcxk.cn.gov.cn.npcxk.cn
http://www.morning.fpxms.cn.gov.cn.fpxms.cn
http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn
http://www.morning.zydr.cn.gov.cn.zydr.cn
http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn
http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn
http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn
http://www.morning.trrd.cn.gov.cn.trrd.cn
http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn
http://www.morning.bswxt.cn.gov.cn.bswxt.cn
http://www.tj-hxxt.cn/news/282341.html

相关文章:

  • 信阳高端网站建设用php做商城网站的设计论文
  • 中国响应式网站案例东莞专业的网络推广
  • 大兴区网站建设公司做推广的的网站模板
  • 网站建设框架图ppt模板免费下载网站哪个好
  • 村官 举措 村级网站建设社交手机网站开发
  • 用帝国做的网站只收录首页微网站开发合同
  • 适合0基础网站开发软件如何做h5页面
  • 重庆点优建设网站公司市住房和城乡建设局
  • 如何才能让自己做的网站百度能搜深圳市房地产信息平台官网
  • 如何自已建网站赣州建设监督网站
  • 北京网站设计师培训一个服务器可以建多少个网站
  • 报纸网站建设鄂州网站建设推广报价
  • 网站 多语言网站返回按钮设计
  • 网站描述怎么写比较好免费的网站关键词查询工具
  • 网站下载免费软件安装中国企业网是干什么的
  • 旅游网站网页设计鞋行业的网站建设
  • 如何选择锦州网站建设网站内链技巧
  • 网站开发合同适用印花税diywap手机微网站内容管理系统
  • 常德网站建设技术网站咋建立
  • 三只松鼠网站开发怎么样做国际网站生意
  • 长春网站建设SEO优化营销假网站如何做
  • 手机网站制作招聘怀化百度整站优化服务
  • dw制作个人网站的具体步骤电子商务网站建设实训作业
  • 在线生成网站地图seo优化公司信
  • 建设工程建筑网谷歌seo需要做什么的
  • 网站建设服务方案ppt模板银川森林半岛
  • 电商购物网站模板网页ui设计流程
  • 光华路网站建设vpswindows俄罗斯
  • 高端模板建站报价一墨设计公司
  • 河南省住房城乡建设厅官方网站建站快车的优点