📄 timerk.c
字号:
#include<linux/fs.h>#include<linux/kernel.h>#include<linux/module.h>#include<linux/configfs.h>#include<linux/init.h>#include<linux/types.h>#include<linux/ioctl.h>#include<asm/io.h>#include<asm/uaccess.h>#define TIMER_IOC_LL 0xdc#define TIMER_OPEN _IOW(TIMER_IOC_LL,0,int)#define TIMER _IOW(TIMER_IOC_LL,1,int)#define TIMER_CLOSE _IOW(TIMER_IOC_LL,2,int)#define TIMER_GET _IOW(TIMER_IOC_LL,4,int)#define MAJOR_MINOR 252
#define DEVICE_NAME "lltimer"int timer_open(struct inode *node,struct file *fop){ outb_p(0x80,0x63); return 0;}int timer_close(struct inode *node,struct file *fop){ return 0;}static int timer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ unsigned char data; switch(cmd) { case TIMER_OPEN: outb_p(0x03,0x61); outb_p(0xbe,0x43); break; case TIMER: data=arg&0xff; outb_p(data,0x42); data=(arg>>8)&0xff; outb_p(data,0x42); break; case TIMER_CLOSE: outb_p(0x00,0x61); break; case TIMER_GET: outb_p(0x60,arg); //inb_p(0x60,arg); break; default: break; } return 0;}struct file_operations fop={ open: timer_open, release: timer_close, ioctl: timer_ioctl,};int init_module(){ register_chrdev(MAJOR_MINOR,DEVICE_NAME,&fop); return 0;}void cleanup_module(){ unregister_chrdev(MAJOR_MINOR,DEVICE_NAME);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -