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

博罗营销网站制作做招聘网站要多久

博罗营销网站制作,做招聘网站要多久,厦门做模板网站的公司,优化内容1.应用程序发送指令控制LED亮灭 2.按键1 按下&#xff0c;led1电位反转 按键2按下&#xff0c;led2电位反转 按键3 按下&#xff0c;led3电位反转 驱动程序&#xff1a; #include <linux/init.h> #include <linux/module.h> #include<linux/of.h> #include…

1.应用程序发送指令控制LED亮灭

2.按键1 按下,led1电位反转 按键2按下,led2电位反转 按键3 按下,led3电位反转

驱动程序:

#include <linux/init.h>
#include <linux/module.h>
#include<linux/of.h>
#include<linux/of_irq.h>
#include<linux/interrupt.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>unsigned int major;
struct class *cls;
struct device *dev;struct device_node *dev_led;
struct device_node *dev_key;unsigned int irqno1;
unsigned int irqno2;
unsigned int irqno3;struct gpio_desc *gpiono1;
struct gpio_desc *gpiono2;
struct gpio_desc *gpiono3;//功能码
#define LED_ON _IOW('l', 1, int)
#define LED_OFF _IOW('l', 0, int)//中断处理函数
irqreturn_t my_handler1(int irq, void *dev) //key1
{//灯状态取反gpiod_set_value(gpiono1, !gpiod_get_value(gpiono1));return IRQ_HANDLED;
}irqreturn_t my_handler2(int irq, void *dev) //key2
{//灯状态取反gpiod_set_value(gpiono2, !gpiod_get_value(gpiono2));return IRQ_HANDLED;
}irqreturn_t my_handler3(int irq, void *dev) //key3
{//灯状态取反gpiod_set_value(gpiono3, !gpiod_get_value(gpiono3));return IRQ_HANDLED;
}// 封装操作方法
int mycdev_open(struct inode *inode, struct file *file)
{printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}long mycdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{switch (cmd){case LED_ON:switch (arg){case 1:                           // LED1gpiod_set_value(gpiono1, 1); // LED1开灯break;case 2:                           // LED2gpiod_set_value(gpiono2, 1); // LED2开灯break;case 3:                          // LED3gpiod_set_value(gpiono3, 1); // LED3开灯break;}break;case LED_OFF:switch (arg){case 1:gpiod_set_value(gpiono1, 0);break;case 2:gpiod_set_value(gpiono2, 0);break;case 3:gpiod_set_value(gpiono3, 0);break;}}return 0;
}int mycdev_close(struct inode *inode, struct file *file)
{printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}//定义操作方法结构体变量并赋值
struct file_operations fops = {.open = mycdev_open,.unlocked_ioctl = mycdev_ioctl,.release = mycdev_close,
};static int __init mycdev_init(void)
{int ret;int i;//***************字符设备***************//// 字符设备驱动注册major = register_chrdev(0, "mychrdev", &fops);if (major < 0){printk("字符设备驱动注册失败\n");return major;}printk("字符设备驱动注册成功:major=%d\n", major);//向上提交目录cls = class_create(THIS_MODULE, "myled");if (IS_ERR(cls)){printk("向上提交目录失败\n");return -PTR_ERR(cls);}printk("向上提交目录成功\n");//向上提交设备节点信息for (i = 0; i < 3; i++){dev = device_create(cls, NULL, MKDEV(major, i), NULL, "myled%d", i);if (IS_ERR(dev)){printk("向上提交设备节点信息失败\n");return -PTR_ERR(dev);}}printk("向上提交设备节点成功\n");//*************LED**************//// 根据设备树节点的路径解析设备树信息dev_led = of_find_node_by_path("/leds");if (dev_led == NULL){printk("解析设备树节点失败\n");return -EFAULT;}printk("解析设备树节点成功\n");// 根据解析得到的设备树节点指针解析出LED1的gpio编号gpiono1 = gpiod_get_from_of_node(dev_led, "led1-gpios", 0, GPIOD_OUT_LOW, NULL);if (IS_ERR(gpiono1)){printk("解析gpio编号失败\n");return -PTR_ERR(gpiono1);}gpiono2 = gpiod_get_from_of_node(dev_led, "led2-gpios", 0, GPIOD_OUT_LOW, NULL);if (IS_ERR(gpiono2)){printk("解析gpio编号失败\n");return -PTR_ERR(gpiono2);}gpiono3 = gpiod_get_from_of_node(dev_led, "led3-gpios", 0, GPIOD_OUT_LOW, NULL);if (IS_ERR(gpiono3)){printk("解析gpio编号失败\n");return -PTR_ERR(gpiono3);}//*************KEY**************//// 根据设备树节点的路径解析设备树信息dev_key = of_find_node_by_path("/myirq");if (dev_key == NULL){printk("解析设备树节点失败\n");return -EFAULT;}printk("解析设备树节点成功\n");//*****KEY1*******////根据设备树节点,解析软中断号irqno1 = irq_of_parse_and_map(dev_key, 0); //按键1索引号为 0if(!irqno1){printk("解析软中断号失败\n");return -ENXIO;}printk("解析软中断号成功 irqno1=%d\n", irqno1);//注册中断ret = request_irq(irqno1, my_handler1, IRQF_TRIGGER_FALLING, "key1", NULL);if(ret){printk("注册中断失败\n");return -EFAULT;}printk("KEY1注册中断成功\n");//*****KEY2*******////根据设备树节点,解析软中断号irqno2 = irq_of_parse_and_map(dev_key, 1); //按键2索引号为 1if(!irqno2){printk("解析软中断号失败\n");return -ENXIO;}printk("解析软中断号成功 irqno2=%d\n", irqno2);//注册中断ret = request_irq(irqno2, my_handler2, IRQF_TRIGGER_FALLING, "key2", NULL);if(ret){printk("注册中断失败\n");return -EFAULT;}printk("KEY2注册中断成功\n");//*****KEY3*******////根据设备树节点,解析软中断号irqno3 = irq_of_parse_and_map(dev_key, 2); //按键3索引号为 2if(!irqno3){printk("解析软中断号失败\n");return -ENXIO;}printk("解析软中断号成功 irqno3=%d\n", irqno3);//注册中断ret = request_irq(irqno3, my_handler3, IRQF_TRIGGER_FALLING, "key3", NULL);if(ret){printk("注册中断失败\n");return -EFAULT;}printk("KEY3注册中断成功\n");return 0;
}static void __exit mycdev_exit(void)
{//销毁节点信息int i;for (i = 0; i < 3; i++){device_destroy(cls, MKDEV(major, i));}//销毁目录信息class_destroy(cls);// 注销字符设备驱动unregister_chrdev(major, "mychrdev");//注销中断free_irq(irqno1, NULL);free_irq(irqno2, NULL);free_irq(irqno3, NULL);// 灭灯gpiod_set_value(gpiono1, 0);gpiod_set_value(gpiono2, 0);gpiod_set_value(gpiono3, 0);// 释放gpio编号gpiod_put(gpiono1);gpiod_put(gpiono2);gpiod_put(gpiono3);}module_init(mycdev_init);
module_exit(mycdev_exit);
MODULE_LICENSE("GPL");

应用层程序:

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
//功能码
#define LED_ON _IOW('l', 1, int)
#define LED_OFF _IOW('l', 0, int)int main(int argc, char const *argv[])
{int a, b;int fd = open("/dev/myled0", O_RDWR);if (fd < 0){printf("打开设备文件失败\n");exit(-1);}while (1){printf("请输入指令\n");printf("0(关灯) 1(开灯)\n");printf("请输入:");scanf("%d", &a);printf("请输入要控制的灯 1(LED1) 2(LED2) 3(LED3):");scanf("%d", &b);switch (a){case 1:ioctl(fd, LED_ON, b); //开灯break;case 0:ioctl(fd, LED_OFF, b); //关灯break;default:printf("输入错误\n");break;}}close(fd);return 0;
}

http://www.yayakq.cn/news/408154/

相关文章:

  • 做网站设计的电脑需要什么配置运营的三个核心要素
  • 杭州网站商场开发国外网站视频播放器
  • 做网站有er图购物网站开发简介
  • 途牛电子商务网站建设建设学风建设专题网站
  • 网页设计怎么创建站点百度输入法下载
  • 网站空间换了 使用原有域名网站换网址了怎么找
  • 中国建设移动门户网站网站 域名解析出错
  • 网站开发有哪些软件北京牌楼设计制作
  • 拖拽网站开发申请网站一年多少钱
  • 写一个网站ppt模板免费下载 素材百度网盘
  • 做网站没什么用啊老师别人强remix做歌网站
  • 企业官方网站建设如何免费ppt模板300套
  • python可以做的网站论文如何查询网站备案号
  • 17做网店这个网站好不好做百度推广需要有网站吗
  • 网站关键词百度排名在下降网站如何添加友情链接
  • 昆明市网站备案可口可乐公司的企业网站建设
  • 电商网站平台网站做提示框
  • 智能营销型网站制作电子商务网站策划
  • 石家庄建设集团南京做网站优化的企业排名
  • 界面简洁的网站网站做等保二级收费多少
  • 佛山网站建设咨询可以免费视频的软件哪个最好
  • 搜索引擎是如何判断网站的结构免费网站推广怎么做
  • 萧山网站建设争锋网络建设商务网站作用
  • 做搜狗网站排名做网站赚钱好难
  • 木藕设计网站大全wordpress 开通json
  • 腾讯云wed服务器做网站湖北专业的网瘾戒除学校哪里好
  • 可以做很多个网站然后哭推广深圳在建工程查询
  • 西安网站维护兼职wordpress使用百度云cdn
  • 深圳的知名网站设计有哪些可以自己设计图案的软件
  • 收费网站怎么做封面制作网站