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

怎么跳转网站北京海淀区邮编

怎么跳转网站,北京海淀区邮编,wordpress查询数据库页面,营销网站建设评估与分析1.信号驱动IO框架图 分析: 信号驱动IO是一种异步IO方式。linux预留了一个信号SIGIO用于进行信号驱动IO。进程主程序注册一个SIGIO信号的信号处理函数,当硬件数据准备就绪后会发起一个硬件中断,在中断的处理函数中向当前进程发送一个SIGIO信号…

 1.信号驱动IO框架图

分析:

        信号驱动IO是一种异步IO方式。linux预留了一个信号SIGIO用于进行信号驱动IO。进程主程序注册一个SIGIO信号的信号处理函数,当硬件数据准备就绪后会发起一个硬件中断,在中断的处理函数中向当前进程发送一个SIGIO信号。进程收到SIGIO信号后执行信号处理函数,在信号处理函数中将数据读走即可。

应用层:1.打开设备文件,2注册SIGIO信号处理函数,3回调驱动中的fasync方法,4设置fd对应的驱动程序发送SIGIO信号只发送给当前进程

驱动层:完成异步对象的空间分配和初始化

硬件层:中断处理函数:发送SIGIO信号(用到异步对象的二级指针)

2.实现代码

---pro1.c---应用程序(信号驱动IO)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <signal.h>char buf[128] = {0};
int fd;void sigio_handler(int sig)
{read(fd, buf, sizeof(buf));printf("buf:%s\n", buf);
}int main(int argc, const char *argv[])
{// 1打开设备文件fd = open("/dev/mmyled0", O_RDWR);if (fd < 0){printf("自定义事件文件失败\n");exit(-1);}// 2注册SIGIO信号的处理函数signal(SIGIO, sigio_handler);// 3回调驱动中的fasync方法,完成发送信号之前的准备工作int flags = fcntl(fd,F_GETFL);  //获取文件描述符属性fcntl(fd,F_SETFL,flags|FASYNC);  //添加FASYNC属性就可以回调fasync操作方法// 4驱动发送信号只发送给当前进程fcntl(fd,F_SETOWN,getpid());while(1){printf("...等待信号驱动IO事件...\n");sleep(1);}close(fd);return 0;
}
---pro2.c---应用程序(模拟模拟硬件数据到达)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>int main(int argc, const char *argv[])
{char buf[128] = "hello world";int fd = open("/dev/mmyled0", O_RDWR);if (fd < 0){printf("打开设备文件失败\n");exit(-1);}write(fd, buf, sizeof(buf));close(fd);return 0;
}
---driceio.c---驱动程序
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
#include<linux/poll.h>char kbuf[128] = {0};
unsigned int major;
struct class *cls;
struct device *dev;
struct fasync_struct *fp;  //定义一个异步对象指针// 封装操作方法
int mycdev_open(struct inode *inode, struct file *file)
{printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}ssize_t mycdev_read(struct file *file, char *ubuf, size_t size, loff_t *lof)
{int ret;ret = copy_to_user(ubuf, kbuf, size);if (ret){printk("copy_to_ user err\n");return -EIO;}return 0;
}
ssize_t mycdev_write(struct file *file, const char *ubuf, size_t size, loff_t *lof)
{int ret;// 从用户拷贝数据,模拟硬件数据ret = copy_from_user(kbuf, ubuf, size);if (ret){printk("copy_from_user err\n");return -EIO;}//内核模块发送信号kill_fasync(&fp,SIGIO,POLL_IN);return 0;
}
int mycdev_fasync(int fd,struct file *file,int on)  //异步操作方法
{//完成发送信号之前的准备工作//异步对象空间的分配语言初始化fasync_helper(fd,file,on,&fp);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,.read = mycdev_read,.fasync = mycdev_fasync,.write = mycdev_write,.release = mycdev_close,
};// 入口函数
static int __init mycdev_init(void)
{major = register_chrdev(0, "myled", &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");// 向上提交设备节点信息int i;for (i = 0; i < 3; i++){dev = device_create(cls, NULL, MKDEV(major, i), NULL, "mmyled%d", i);if (IS_ERR(dev)){printk("向上提交设备节点信息失败\n");return -PTR_ERR(dev);}}printk("向上提交设备节点信息成功\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, "myled");
}// 声明
// 入口函数地址
module_init(mycdev_init);
// 出口函数地址
module_exit(mycdev_exit);
// 遵循的GPL协议
MODULE_LICENSE("GPL");

 

3.测试结果

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

相关文章:

  • 网站开发技术与应用课程设计三五互联网站管理登录地址
  • 公主坟网站建设wordpress更改注册
  • html5网站地址奉化网站建设
  • 备案的网站 ,能拿来做仿站吗wordpress用户角色权限
  • 自己做网站能赚钱么商务网站建设有哪几个步骤
  • 做社区网站用什么程序好百度站长资源管理
  • 网站目录访问php自己写框架做网站6
  • 小说网站建设目的爱牛网络
  • 上海手机网站建设哪家专业邢台微信群
  • 学做网站需要多久时间安徽建设工程信息网安全三类人员考试成绩查询
  • 用wordpress仿一个网站模板下载wordpress 询盘
  • 微网站注册海外短视频app怎么下载
  • 玉林网站推广旅游网站怎么设计
  • 网站 文件夹结构免费推广app软件下载
  • 务川县住房和城乡建设局网站恩施公司做网站
  • 黄骅市有火车站吗做网站刷QQ会员网站
  • 建设网站哪好阳泉市住房保障和城乡建设管理局网站
  • 工信部备案系统网站网站域名优势
  • 媒体网站网页设计站群推广
  • 过年做哪些网站能致富谷歌官方网站
  • 做国际网站有什么需要注意的工业设计公司怎么收费
  • 山东潍坊建设银行招聘网站城市建设理论研究官方网站
  • 全国拿货最便宜的网站网站被管理员权限
  • 旧网站如何优化新沂网站建设公司
  • 德州企业网站优化公司126企业邮箱入口
  • 网站业务建设是什么意思百度推广效果
  • 请问大连谁家做网站网站公司的好坏
  • 丰台网站建设公司网络营销的起源
  • 江苏做网站的企业做网站用什么软件
  • 安徽省造价信息网官网游戏优化大师官方下载