📄 8253.c
字号:
/* joy_wudan 2007/12/12 */
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <asm/io.h>
/*functions*/
int init_module(void);
void cleanup_module(void);
static int device_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
static int device_release(struct inode *inode, struct file *file);
static int device_open(struct inode *inode, struct file *file);
static struct file_operations fops = {
ioctl : device_ioctl,
open: device_open,
release: device_release,
};
static int device_open(struct inode *inode, struct file *file)
{
return 0;
}
static int device_release(struct inode *inode, struct file *file)
{
Device_Open --; /* We're now ready for our next caller */
return 0;
}
static int device_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd)
{
case SET_MODE:
outb(0xb6,0x43);
break;
case SET_FREQ:
int count,count_low,count_high,clock=1190000;//PC机的时钟频率,它可以是一个全局变量;
count=clock/arg;//count为对应频率下应计数次数;
count_low=count & 0xFF;
count_high=count>>8;
outb(count_low,0x42);
outb(count_high,0x42);
break;
case START_BEEP:
outb(0x03,0x61);
break;
case STOP_BEEP:
outb(0x00,0x61);
break;
case READ_KEY:
(unsigned char*)arg=inb(0x60);
break;
case DELAY:
mdalay(arg);
break;
default:
break;
}
}
int init_module(void)
{
register_chrdev(Major, DEVICE_NAME, &fops);
return 0;
}
void cleanup_module(void)
{
unregister_chrdev(Major, DEVICE_NAME);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -