📄 kern.c~
字号:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
#include <asm/smplock.h>
#include <linux/coda.h>
#include <linux/config.h>
#include <linux/sched.h>
#include <linux/devfs_fs_kernel.h>
#define FPGA_SW_IOC 0xdc
#define FPGA_SWITCH _IOR(FPGA_SW_IOC,0,int)
#define FPGA_LED _IOW(FPGA_SW_IOC,1,int)
#define LED_ADDR (volatile unsigned short *)0x20000022
#define SW_ADDR (volatile unsigned short *)0x20000028
#define MAJOR_NUM 100
static int keyled_open(struct inode *inode ,struct file *file)
{
return 0;
}
static int keyled_release(struct inode *inode ,struct file *file)
{
return 0;
}
static int keyled_ioctl(struct inode *inode,struct file *file,unsigned int cmd ,unsigned long arg)
{
switch(cmd)
{ case FPGA_SWITCH_READ: *(int*) arg=*SW_ADDR;break;
case FPGA_LED: *LED_ADDR=arg;break;
default: break;
}
}
static struct file_operations fops=
{
open : keyled_open,
release: keyled_release,
ioctl: keyled_ioctl,
};
int init_module()
{
int value;
value=register_chrdev(MAJOR_NUM,keyled,&fops);
if(value<0)
{
printk("Failure,the number %d has already been registered!\n",value); return value;
}
printk("Success,you registered the number %d for your device 'keyled'\n",MAJOR_NUM);
return 0;
}
void cleanup_module()
{ unregister_chrdev(MAJOR_NUM,DEVICE_NAME);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -