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

哪个网站查公司信息比较准网店seo关键词

哪个网站查公司信息比较准,网店seo关键词,广州安全教育平台官网,成都网络公司最新招聘hello的驱动编写 编写驱动程序的步骤 1.确定主设备号,也可以让内核分配 2.定义自己的 file_operations 结构体 3.实现对应的 drv_open/drv_read/drv_write 等函数,填入 file_operations 结构 体 4.把 file_operations 结构体告诉内核:regist…

hello的驱动编写

编写驱动程序的步骤

1.确定主设备号,也可以让内核分配
2.定义自己的 file_operations 结构体
3.实现对应的 drv_open/drv_read/drv_write 等函数,填入 file_operations 结构 体
4.把 file_operations 结构体告诉内核:register_chrdev
5.谁来注册驱动程序啊?得有一个入口函数:安装驱动程序时,就会去调用这 个入口函数
6.有入口函数就应该有出口函数:卸载驱动程序时,出口函数调用unregister_chrdev
7.其他完善:提供设备信息,自动创建设备节点:class_create,

代码

驱动代码
hello_drv.c

#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/device.h>
#include <linux/ioctl.h>
#include <linux/ctype.h>
#include <linux/poll.h>
#include <linux/slab.h>
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/uaccess.h>
#include <linux/compat.h>
#include <linux/platform_device.h>static ssize_t hello_read(struct file *file, char __user *buf, size_t count,loff_t *ppos);
static ssize_t hello_write(struct file *file, const char __user *buf,size_t count, loff_t *ppos);
static int hello_open(struct inode *inode, struct file *file);
int hello_close(struct inode *inode, struct file *file);char kernel_buf[1024] = "www.ask100.com";
static struct class *hello_class;
#define MIN(a,b) (a<b ? a:b)//1确定主设备号,也可以让内核分配
static unsigned int major = 0 ; //2定义自己的 file_operations 结构体
static const struct file_operations hello_fops = {.owner	 = THIS_MODULE,.open    = hello_open,.read    = hello_read,.write   = hello_write,.release = hello_close,
};//3.实现对应的 drv_open/drv_read/drv_write 等函数,填入 file_operations 结构体
static int hello_open(struct inode *inode, struct file *file)
{printk("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);return 0;}static ssize_t hello_write(struct file *file, const char __user *buf,size_t count, loff_t *ppos)
{int len;printk("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);len = copy_from_user(kernel_buf, buf, MIN(1024,sizeof(kernel_buf)));kernel_buf[len] = '\0';return MIN(1024,sizeof(kernel_buf));}static ssize_t hello_read(struct file *file, char __user *buf, size_t count,loff_t *ppos)
{int err;printk("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);err = copy_to_user(buf, kernel_buf, MIN(1024,sizeof(kernel_buf)));return MIN(1024,sizeof(kernel_buf));
}int hello_close(struct inode *inode, struct file *file)
{printk("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
}//4.把 file_operations 结构体告诉内核:register_chrdev
//5.谁来注册驱动程序啊?得有一个入口函数:安装驱动程序时,就会去调用这个入口函数
static int __init hello_init(void)
{int err;major = register_chrdev(0,"hello",&hello_fops);hello_class = class_create(THIS_MODULE, "hello");err = PTR_ERR(hello_class);if (IS_ERR(hello_class))return -1;device_create(hello_class, NULL, MKDEV(major, 0), NULL, "hello"); /*/dev/hello*/return 0;}//6.有入口函数就应该有出口函数:卸载驱动程序时,出口函数调用unregister_chrdevstatic void __init hello_exit(void)
{device_destroy(hello_class, MKDEV(major, 0));class_destroy(hello_class);unregister_chrdev(major, "hello");}//7.其他完善:提供设备信息,自动创建设备节点:class_create,device_create
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

测试程序
hello_drv_test.c


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>/** ./hello_drv_test -w abc* ./hello_drv_test -r*/
int main(int argc, char **argv)
{int fd;char buf[1024];int len;/* 1. 判断参数 */if (argc < 2) {printf("Usage: %s -w <string>\n", argv[0]);printf("       %s -r\n", argv[0]);return -1;}/* 2. 打开文件 */fd = open("/dev/hello", O_RDWR);if (fd == -1){printf("can not open file /dev/hello\n");return -1;}/* 3. 写文件或读文件 */if ((0 == strcmp(argv[1], "-w")) && (argc == 3)){len = strlen(argv[2]) + 1;len = len < 1024 ? len : 1024;write(fd, argv[2], len);}else{len = read(fd, buf, 1024);		buf[1023] = '\0';printf("APP read : %s\n", buf);}close(fd);return 0;
}

Makefile


# 1. 使用不同的开发板内核时, 一定要修改KERN_DIR
# 2. KERN_DIR中的内核要事先配置、编译, 为了能编译内核, 要先设置下列环境变量:
# 2.1 ARCH,          比如: export ARCH=arm64
# 2.2 CROSS_COMPILE, 比如: export CROSS_COMPILE=aarch64-linux-gnu-
# 2.3 PATH,          比如: export PATH=$PATH:/home/book/100ask_roc-rk3399-pc/ToolChain-6.3.1/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin 
# 注意: 不同的开发板不同的编译器上述3个环境变量不一定相同,
#       请参考各开发板的高级用户使用手册KERN_DIR = /home/book/100ask_imx6ull-sdk/Linux-4.9.88all:make -C $(KERN_DIR) M=`pwd` modules $(CROSS_COMPILE)gcc -o hello_drv_test hello_drv_test.c clean:make -C $(KERN_DIR) M=`pwd` modules cleanrm -rf modules.orderrm -f hello_testobj-m	+= hello_drv.oKERN_DIR = /home/book/100ask_imx6ull-sdk/Linux-4.9.88

用make命令编译后,将编译出的hello_drv.ko 和hello_drv_test传给板子

板子操作

  1. 安装驱动:insmod hello_drv.ko

2.lsmod : 查看已经安装的驱动,可以看到hello_drv已经安装

在这里插入图片描述

3.cat /proc/devices查看设备节点,看到hello节点已经被创建,这是再hello_drv.c文件里创建的节点,具体看hello_int函数
在这里插入图片描述

4.执行程序: 在这里插入图片描述

5.删除驱动程序 rmmod hello_drv

http://www.ritt.cn/news/1105.html

相关文章:

  • wordpress如何更域名seo搜索优化是什么
  • js实现收藏网站功能电子商务网站推广
  • 网站建设模板制作是什么意思app营销十大成功案例
  • 网站设计与网页配色网站推广代理
  • 廉江网站制作软文营销怎么写
  • 用记事本做网站怎么让字体靠右郑州seo管理
  • mvc做的游戏网站安卓优化大师手机版下载
  • 咨询公司管理制度seo如何优化
  • 网站建设小程序南宁北京最新疫情情况
  • 网站开发网站设计的标准去除痘痘怎么有效果
  • b2c网站模块宁德市政府
  • html5 网站建设百度快照优化推广
  • 网站建设 青岛企业营销网站制作
  • 微信商城网站实时新闻
  • 重庆资质代理公司公众号seo排名优化
  • 聚名网怎么注销账号优化设计三年级上册答案语文
  • 网站建设视频教程快速网站搭建
  • 如何建设好企业的网站维护西安seo公司哪家好
  • 公安网站备案流程图推广文案怎么写
  • 建设自己的网站网站制作过程
  • 网站平台需要做无形资产吗 怎么做6品牌营销做得好的品牌有哪些
  • 养老服务业扶持政策app排名优化公司
  • 做塑料哪个网站好曹操论坛seo
  • 鹰潭市网站建设公司如何结合搜索检索与seo推广
  • wordpress大前端下载青岛网站seo优化
  • 全景旅游网站项目建设百度游戏
  • 做开箱的网站重庆森林影评
  • 求邯郸网站制作seo是指什么
  • 软件介绍网站模板百度推广登录平台官网
  • 南阳做网站收费贵港seo