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

最方便建立网站centos7系统做网站

最方便建立网站,centos7系统做网站,邳州网站,公司网站建设 阿里本人linux驱动小白#xff0c;文章基于B站up主 李Sir______ 视频内容记录#xff0c;做笔记用。如有错误欢迎指正。本文将以开发板第40引脚GPIO3_B4作为LED灯珠的控制引脚#xff0c;高电平灯亮#xff0c;低电平灯灭。 杂话 在linux内核中#xff0c;芯片厂商已经把所有… 本人linux驱动小白文章基于B站up主 李Sir______ 视频内容记录做笔记用。如有错误欢迎指正。本文将以开发板第40引脚GPIO3_B4作为LED灯珠的控制引脚高电平灯亮低电平灯灭。 杂话 在linux内核中芯片厂商已经把所有控制器的设备树编写好了。硬件层与子系统的API也都适配好无需使用者关心。我们编写驱动只需要将自己所需要的硬件资源与厂商定义好的设备树匹配在驱动程序中调用相应子系统API函数即可写出一份自己的GPIO驱动程序。相比传统无官方库支持的单片机需操作寄存器来操作底层程序可移植性大大提高。 内核子系统三层概念 user 逻辑代码—————————————————————————————————————————————设备驱动层(今天的驱动在这一层) 通过各个子系统 完成对硬件的操作 并向上层提供接口 驱动工程师______________________________________________________________________________ kernel核心层(内核维护者) 屏蔽底层细节 向上层提供接口 各类子系统api 内核工程师———————————————————————————————————————厂商驱动层(瑞芯微) 各个厂商针对不同硬件的操作 包括内存映射 厂商————————————————————————————————————————————— HARDWAREmotor led lcd ...厂商的设备树文件 厂商已经把所有的控制器设备树信息都提供了下面是与gpio相关的一些文件所在位置。 path:kenel\arch\arm64\boot\dts\rockchip\rk3568.dtsi ... gpio3: gpiofe760000 {//节点名compatible rockchip,gpio-bank; //厂商名 设备名reg 0x0 0xfe760000 0x0 0x100; //地址 0x0 0xfe760000控制器地址 0x0 0x100地址范围interrupts GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH;//中断clocks cru PCLK_GPIO3, cru DBCLK_GPIO3;//时钟gpio-controller;//标识#gpio-cells 2;//描述子节点个数gpio-ranges pinctrl 0 96 32; //引脚范围 pinctrl 引用pinctrl节点 0 96 GPIO起始序号 32引脚范围interrupt-controller;#interrupt-cells 2;//描述子节点个数 }; ... //一些宏厂商也已经做出定义 pathkernel\include\dt-binding\pinctrl\rockchip.h pathkernel\include\dt-binding\pinctrl\pinctrl-amd.h pathkernel\include\dt-binding\gpio\gpio.hgpio设备树书写规则 [names]-gpios控制器地址 引脚编号 高/低电平;设备树中添加我们的设备 仿照设备树中的节点添加一个我们自己的节点位置在根节点处 path:kenel\arch\arm64\boot\dts\tspi-rk3566-user-v10-linux.dts .............. / {model lckfb tspi V10 Board;compatible lckfb,tspi-v10, rockchip,rk3566;//自己新建的led灯的设备树 image_led{compatible image,led;status okay;led_gpiogpio3 RK_PB4 GPIO_ACTIVE_LOW;}; rk_headset: rk-headset {compatible rockchip_headset;headset_gpio gpio0 RK_PC5 GPIO_ACTIVE_HIGH;pinctrl-names ............编译内核,将boot.img文件烧录到开发板 ./build.sh kernel查看添加的设备树节点是否存在 rootRK356X:/tmp# ls /proc/device-tree...........iepfdef0000 serialfe6c0000image_led serialfe6d0000interrupt-controllerfd400000 sfcfe300000..........GPIO相关的API static inline int of_get_named_gpio(struct device_node *np, const char *propname, int index) 功能获取gpio编号 参数np 结构体指针propname 属性名index 编号 返回值成功 返回gpio编号失败 返回错误码static inline int gpio_request(unsigned gpio, const char *label) 功能申请gpio 参数gpio GPIO编号label 标签 NULL 返回值成功 返回0失败 返回错误码 static inline int gpio_direction_input(unsigned gpio) 功能设置gpio为输入 参数gpio GPIO编号 返回值成功 返回0失败 返回错误码static inline int gpio_direction_output(unsigned gpio, int value) 功能设置gpio为输出 参数gpio GPIO编号value 输出电平 1高电平 0是低电平 返回值成功 返回0失败 返回错误码static inline void gpio_set_value(unsigned int gpio, int value) 功能设置gpio输出电平 参数gpio GPIO编号value 输出电平 1高电平 0是低电平 返回值成功 返回0失败 返回错误码static inline int gpio_get_value(unsigned int gpio) 功能获取gpio电平状态 参数gpio GPIO编号 返回值1 是高电平0 是低电平static inline void gpio_free(unsigned gpio) 功能释放gpio 参数gpio GPIO编号 返回值无解析设备树相关API device_node 结构体讲解 struct device_node {const char *name; //节点名#const char *type; //节点类型#phandle phandle; //唯一标识const char *full_name; //节点全名#struct fwnode_handle fwnode; //用于支持不同设备struct property *properties; //设备数属性键值对的链表#struct property *deadprops; /* removed properties */ 链表头struct device_node *parent; //父节点struct device_node *child; //子节点struct device_node *sibling; //兄弟节点 #if defined(CONFIG_OF_KOBJ)#struct kobject kobj;//内核对象 #endif#unsigned long _flags;//状态标志#void *data;//节点相关的私有数据 #if defined(CONFIG_SPARC)#const char *path_component_name;//表示设备节点路径的一部分#unsigned int unique_id;//唯一ID#struct of_irq_controller *irq_trans;//中断控制器结构体指针 #endif };property结构体 struct property {char *name;//键的名字int length; //值长度void *value; //值 注意 强转struct property *next; //下一个键值对的property结构体指针 };static inline struct device_node *of_find_node_by_path(const char *path) 功能通过路径获取节点 参数path 路径 /image_led 返回值成功 返回结构体首地址失败 返回NULLstatic inline struct device_node *of_find_node_by_name(struct device_node *from,const char *name)功能通过节点名获取节点 参数from 填NULL 从根节点搜索name 节点名 返回值成功 返回结构体首地址失败 返回NULLstatic inline struct device_node *of_find_compatible_node(struct device_node *fromconst char *type,const char *compat) 功能通过compatible获取节点 参数from 填NULL 从根节点搜索type 填NULcompat 厂商名 设备名 返回值成功 返回结构体首地址失败 返回NULL获取属性相关的API static inline struct property *of_find_property(const struct device_node *np,const char *name,int *lenp) 功能获取键值对 参数np device_node结构体首地址name 键的名字lenp 值的长度 单位字节 返回值成功 返回结构体首地址失败 返回NULLstatic inline int of_property_read_u8_array(const struct device_node *np,const char *propname, u8 *out_values, size_t sz) 功能获取单字节数据数组 参数np device_node结构体首地址propname 键的名字out_values 获取到的数据sz 值的个数 返回值成功 返回0失败 返回错误码static inline int of_property_read_u32_index(const struct device_node *np,const char *propname, u32 index, u32 *out_value) 功能获取32位数值 参数np device_node结构体首地址propname 键的名字index 索引号 下标out_values 获取到的数据 返回值成功 返回0失败 返回错误码static inline int of_property_read_string(const struct device_node *np, const char *propname, const char **out_string) 功能获取字符串 参数np device_node结构体首地址propname 键的名字index 索引号 下标out_string 获取到的字符串 返回值成功 返回0失败 返回错误码编写的驱动文件 #include linux/init.h #include linux/module.h #include linux/fs.h #include linux/io.h #include linux/uaccess.h #include linux/device.h #include linux/of.h #include linux/gpio.h #include linux/of_gpio.h//字符设备名 sys/class 描述名称 #define CDEV_NAME image_led //设备树中 自定义led节点路径 #define LED_NODE_PATH /image_led //自定义设备树节点中 led引脚名称 #define LED_NODE_PROPERTY led_gpioint major -1; int gpionum -1; struct class *cls NULL; struct device *dev NULL; struct device_node *led_node NULL; //设备树节点结构体 char kbuf[128] {0};int my_led_open(struct inode *inode, struct file *file) {printk(device:image_led is open\r\n);return 0; }ssize_t my_led_read (struct file *file, char __user *ubuf, size_t size, loff_t *offset) {char level 0;if(size 1){size 1;}level gpio_get_value(gpionum);if(copy_to_user(ubuf, level, size)){printk(copy data from user failed!\n);return -EINVAL;}printk(device:image_led cur level is %d\r\n,level);return size; } ssize_t my_led_write (struct file *file, const char __user *ubuf, size_t size, loff_t *offset) {size size sizeof(kbuf) ? sizeof(kbuf) : size;if(copy_from_user(kbuf, ubuf, size)){printk(copy data from user failed!\n);return -EINVAL;}if(kbuf[0] 1){gpio_set_value(gpionum,1); //设置高电平printk(device:image_led set level is %d\r\n,kbuf[0]);}else{gpio_set_value(gpionum,0); //设置低电平printk(device:image_led set level is %d\r\n,kbuf[0]);}return size; } int my_led_close (struct inode *inode, struct file *file) {printk(device:image_led is close\r\n);return 0; }struct file_operations fops {.open my_led_open,.read my_led_read,.write my_led_write,.release my_led_close };int led_gpio_init(void) {//读取设备树上节点路径获取节点数据led_node of_find_node_by_path(LED_NODE_PATH);if(led_node NULL){printk(find node %s failed!\n,LED_NODE_PATH );return -ENODEV;}//通过节点数据中的名称获取gpio编号gpionum of_get_named_gpio(led_node, LED_NODE_PROPERTY, 0);if(gpionum 0){printk(get property %s failed!\n,LED_NODE_PROPERTY );return -EINVAL;}//申请GPIO 防止占用冲突if(gpio_request(gpionum,NULL)){printk(request gpio failed!\n);return -EINVAL;}//设置GPIO为输出if(gpio_direction_output(gpionum, 0)){printk(set gpio direction failed!\n);return -EINVAL;}return 0; } void led_gpio_deinit(void) {gpio_set_value(gpionum,0);gpio_free(gpionum); } static int __init image_led_init(void) {//注册字符设备major register_chrdev(0,CDEV_NAME,fops);if(major 0){printk(register chardev failed! \n);return -1;}//自动创建设备节点//提交目录信息cls class_create(THIS_MODULE,CDEV_NAME);if(IS_ERR(cls)){printk(auto create node failed! \n);goto del_cdev; //}//提交设备信息dev device_create(cls,NULL,MKDEV(major,0),NULL,image_led0);if(IS_ERR(dev)){printk(device create failed! \n);goto destroy_class;}if(led_gpio_init()0){goto free_gpio;}return 0;free_gpio:led_gpio_deinit(); destroy_class:class_destroy(cls); del_cdev:unregister_chrdev(major,CDEV_NAME); return -EIO; }static void __exit image_led_exit(void) {led_gpio_deinit();device_destroy(cls, MKDEV(major,0));class_destroy(cls);unregister_chrdev(major,CDEV_NAME); }module_init(image_led_init); module_exit(image_led_exit); MODULE_LICENSE(GPL);APP测试文件 #include sys/types.h #include sys/stat.h #include fcntl.h #include unistd.h #include stdio.h #include string.h #define MY_CHRDEV_NAME /dev/image_led0int fd 0; int main(void) {char light_cmd 1;char off_cmd 0;char count 0;char read_buf[1] {0};fd open(MY_CHRDEV_NAME,O_RDWR);if(fd 0){printf(open %s is failed fd:%d\r\n,MY_CHRDEV_NAME,fd);return -1;}for(count0;count10;count){write(fd,light_cmd,1);printf(cmd:%c\r\n,light_cmd);usleep(500*1000);read(fd,read_buf,1);printf(read gpio level is %d\r\n,read_buf[0]);write(fd,off_cmd,1);printf(cmd:%c\r\n,off_cmd);usleep(500*1000);read(fd,read_buf,1);printf(read gpio level is %d\r\n,read_buf[0]);}close(fd);return 0; }Makefile文件 PWD ? $(shell pwd) KERNELDIR:/home/image/work/tspi/sdk/kernel CROSS_COMPILE ? /home/image/work/tspi/sdk/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- obj-m demo.o CC : $(CROSS_COMPILE)gcc module:make -C $(KERNELDIR) M$(PWD) ARCHarm64 modules$(CC) test_app.c -o test_app clean:make -C $(KERNELDIR) M$(PWD) ARCHarm64 cleanrm test_appAPP执行效果 rootRK356X:/tmp# ./test_app cmd:1 read gpio level is 1 cmd:0 read gpio level is 0 cmd:1 read gpio level is 1 cmd:0 read gpio level is 0 cmd:1 read gpio level is 1 cmd:0 read gpio level is 0 cmd:1 ..............开发板打印调试信息 rootRK356X:/tmp# dmesg [ 6757.176165] device:image_led is open [ 6757.176265] device:image_led set level is 49 [ 6757.676878] device:image_led cur level is 1 [ 6757.677111] device:image_led set level is 48 [ 6758.177583] device:image_led cur level is 0 [ 6758.177804] device:image_led set level is 49 [ 6758.678220] device:image_led cur level is 1 [ 6758.678423] device:image_led set level is 48 [ 6759.178801] device:image_led cur level is 0 [ 6759.178988] device:image_led set level is 49 [ 6759.679358] device:image_led cur level is 1 [ 6759.679582] device:image_led set level is 48 [ 6760.179943] device:image_led cur level is 0 [ 6760.180143] device:image_led set level is 49 [ 6760.680495] device:image_led cur level is 1 [ 6760.680716] device:image_led set level is 48 [ 6761.181149] device:image_led cur level is 0 [ 6761.181349] device:image_led set level is 49 [ 6761.681747] device:image_led cur level .................. //48 49为ASCII码的0 和 1这里打印没处理好开发板运行效果 开发板运行效果
文章转载自:
http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn
http://www.morning.bsjxh.cn.gov.cn.bsjxh.cn
http://www.morning.rgrdd.cn.gov.cn.rgrdd.cn
http://www.morning.kzhxy.cn.gov.cn.kzhxy.cn
http://www.morning.zbgqt.cn.gov.cn.zbgqt.cn
http://www.morning.pzrrq.cn.gov.cn.pzrrq.cn
http://www.morning.mqwnp.cn.gov.cn.mqwnp.cn
http://www.morning.lsqmb.cn.gov.cn.lsqmb.cn
http://www.morning.tfrmx.cn.gov.cn.tfrmx.cn
http://www.morning.jhxtm.cn.gov.cn.jhxtm.cn
http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn
http://www.morning.rbkl.cn.gov.cn.rbkl.cn
http://www.morning.ylyzk.cn.gov.cn.ylyzk.cn
http://www.morning.qwbtr.cn.gov.cn.qwbtr.cn
http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn
http://www.morning.ywpwq.cn.gov.cn.ywpwq.cn
http://www.morning.rnzbr.cn.gov.cn.rnzbr.cn
http://www.morning.dblgm.cn.gov.cn.dblgm.cn
http://www.morning.wjlbb.cn.gov.cn.wjlbb.cn
http://www.morning.yktwr.cn.gov.cn.yktwr.cn
http://www.morning.gczzm.cn.gov.cn.gczzm.cn
http://www.morning.lcxzg.cn.gov.cn.lcxzg.cn
http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn
http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn
http://www.morning.fbdtd.cn.gov.cn.fbdtd.cn
http://www.morning.pamdeer.com.gov.cn.pamdeer.com
http://www.morning.lqlfj.cn.gov.cn.lqlfj.cn
http://www.morning.nkkr.cn.gov.cn.nkkr.cn
http://www.morning.tssmk.cn.gov.cn.tssmk.cn
http://www.morning.rlxg.cn.gov.cn.rlxg.cn
http://www.morning.qncqd.cn.gov.cn.qncqd.cn
http://www.morning.tbqdm.cn.gov.cn.tbqdm.cn
http://www.morning.hyxwh.cn.gov.cn.hyxwh.cn
http://www.morning.kybpj.cn.gov.cn.kybpj.cn
http://www.morning.dskmq.cn.gov.cn.dskmq.cn
http://www.morning.wwdlg.cn.gov.cn.wwdlg.cn
http://www.morning.swsrb.cn.gov.cn.swsrb.cn
http://www.morning.gcjhh.cn.gov.cn.gcjhh.cn
http://www.morning.hsflq.cn.gov.cn.hsflq.cn
http://www.morning.krjyq.cn.gov.cn.krjyq.cn
http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn
http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn
http://www.morning.ryjl.cn.gov.cn.ryjl.cn
http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn
http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn
http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn
http://www.morning.ffydh.cn.gov.cn.ffydh.cn
http://www.morning.qhkdt.cn.gov.cn.qhkdt.cn
http://www.morning.lsnnc.cn.gov.cn.lsnnc.cn
http://www.morning.sknbb.cn.gov.cn.sknbb.cn
http://www.morning.mqlsf.cn.gov.cn.mqlsf.cn
http://www.morning.brps.cn.gov.cn.brps.cn
http://www.morning.wklmj.cn.gov.cn.wklmj.cn
http://www.morning.wqmpd.cn.gov.cn.wqmpd.cn
http://www.morning.wpxfk.cn.gov.cn.wpxfk.cn
http://www.morning.njnqn.cn.gov.cn.njnqn.cn
http://www.morning.qwbls.cn.gov.cn.qwbls.cn
http://www.morning.rqkzh.cn.gov.cn.rqkzh.cn
http://www.morning.syznh.cn.gov.cn.syznh.cn
http://www.morning.lxqkt.cn.gov.cn.lxqkt.cn
http://www.morning.ngcw.cn.gov.cn.ngcw.cn
http://www.morning.dfltx.cn.gov.cn.dfltx.cn
http://www.morning.grpfj.cn.gov.cn.grpfj.cn
http://www.morning.jyzqn.cn.gov.cn.jyzqn.cn
http://www.morning.hmfxl.cn.gov.cn.hmfxl.cn
http://www.morning.nkwgy.cn.gov.cn.nkwgy.cn
http://www.morning.clyhq.cn.gov.cn.clyhq.cn
http://www.morning.tpnxr.cn.gov.cn.tpnxr.cn
http://www.morning.yltyz.cn.gov.cn.yltyz.cn
http://www.morning.jqtb.cn.gov.cn.jqtb.cn
http://www.morning.ztqyj.cn.gov.cn.ztqyj.cn
http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn
http://www.morning.jlgjn.cn.gov.cn.jlgjn.cn
http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn
http://www.morning.qsy41.cn.gov.cn.qsy41.cn
http://www.morning.mnbgx.cn.gov.cn.mnbgx.cn
http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn
http://www.morning.fthcn.cn.gov.cn.fthcn.cn
http://www.morning.scrnt.cn.gov.cn.scrnt.cn
http://www.morning.fypgl.cn.gov.cn.fypgl.cn
http://www.tj-hxxt.cn/news/255750.html

相关文章:

  • 中国建设银行网站密码忘了怎么办内部网站开发
  • 买衣服网站排名网站建设对企业的帮助
  • wordpress 压缩网站网络公司取什么名字好
  • 哪些行业需要网站有哪些内容彬县网新闻最新消息
  • 网站建设万户微信的网站怎么做
  • 一般网站做哪些端口映射网站代码规范
  • 网站制作什么品牌好赵公口网站建设
  • 租二级目录做网站wordpress 设置评论
  • 怎么用服务器做局域网网站香精论坛
  • 网站用什么开发东莞金融网站建设
  • wordpress做网站教程互联网公司市值
  • 校园网站建设 方案论证h5做网站用什么框架
  • 网站改标题关键词描述系统优化的例子
  • 家居企业网站建设平台池州市建设工程质量安全监督局网站
  • 手机怎么网站模板wordpress文章模板
  • 织梦视频网站源码能免费做微信群推广的网站
  • 网站建设公司电话咨询关键词优化收费标准
  • jquery网站开发实例哪里教做网站的
  • 电子商务网站建设课设网站网页开发用到的技术
  • 网站登录界面源码深圳建网站价格
  • 百度站长反馈中心微信自己开发小程序
  • uc官方网站开发者中心苏州木渎做网站
  • 如何做好网站需求分析房地产企业网站建设
  • 嘉兴市住房和城乡建设局网站pc端网页设计模板
  • 高性能网站建设进阶...国家建设部标准官方网站
  • 镇江市建设工程质量监督局网站如何编写一个软件
  • 模板建网站多少钱南宁区建设银行招聘网站
  • 网页制作免费的素材网站免费的网页模版
  • 微网站开发需求承接各类网站建设
  • 福州网站建设哪家公司好哪些公司的网站做的漂亮