首页 技术 正文
技术 2022年11月19日
0 收藏 460 点赞 4,216 浏览 1693 个字

ioctl经营无纸装置频繁使用的类型。同时这是一个非常实用的方法进程调试。

这里正在进行wdt该文章继续

static long at91_wdt_ioctl(struct file *file,

unsigned int cmd, unsigned long arg)

{

void __user *argp = (void __user *)arg;

int __user *p = argp;

int new_value;

switch (cmd) {

case WDIOC_GETSUPPORT:

return copy_to_user(argp, &at91_wdt_info,

sizeof(at91_wdt_info)) ? -EFAULT : 0;

case WDIOC_GETSTATUS:

case WDIOC_GETBOOTSTATUS:

return put_user(0, p);

case WDIOC_SETOPTIONS:

if (get_user(new_value, p))

return -EFAULT;

if (new_value & WDIOS_DISABLECARD)

at91_wdt_stop();

if (new_value & WDIOS_ENABLECARD)

at91_wdt_start();

return 0;

case WDIOC_KEEPALIVE:

at91_wdt_reload();
/* pat the watchdog */

return 0;

case WDIOC_SETTIMEOUT:

if (get_user(new_value, p))

return -EFAULT;

if (at91_wdt_settimeout(new_value))

return -EINVAL;

/* Enable new time value */

at91_wdt_start();

/* Return current value */

return put_user(wdt_time, p);

case WDIOC_GETTIMEOUT:

return put_user(wdt_time, p);

default:

return -ENOTTY;

}

}

这里先定义两个一个最底层的被调用接口。在这里面初始化了几个命令,这些命令就能够直接调用你自己的底层函数了

之后面临的就是怎么让这个ioctl被上层可一调用

这里有一个系统设置的结构体

static const struct file_operations at91wdt_fops = {

.owner
= THIS_MODULE,

.llseek
= no_llseek,

.unlocked_ioctl
= at91_wdt_ioctl,

.open = at91_wdt_open,

.release
= at91_wdt_close,

.write
= at91_wdt_write,

};

把ioctl赋给unlocked

再把这个结构体赋给miscdevice结构体   这里就能够看出来他是一个杂项设备  不是block  或者字符设备了

static struct miscdevice at91wdt_miscdev = {

.minor
= WATCHDOG_MINOR,

.name = "watchdog",

.fops = &at91wdt_fops,

};

这里再把它注冊给系统就好了

static int __devinit at91wdt_probe(struct platform_device *pdev)

{

int res;

if (at91wdt_miscdev.parent)

return -EBUSY;

at91wdt_miscdev.parent = &pdev->dev;

res = misc_register(&at91wdt_miscdev);

if (res)

return res;

printk(KERN_INFO "AT91 Watchdog Timer enabled (%d seconds%s)\n",

wdt_time, nowayout ?

", nowayout" : "");

return 0;

}

上面就是这个设备备注測时的调用   能够看到開始就把这个ioctl的父结构体赋给系统了

后面系上层系统将能够看到的功能    它可以通过驱动前来层

版权声明:本文博主原创文章,博客,未经同意不得转载。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918