kern.c
来自「读取frv实验系统上的按键值 并以此来控制frv实验板上的led 基于嵌入式」· C语言 代码 · 共 67 行
C
67 行
#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
#define DEVICE_NAME "keyled"
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,DEVICE_NAME,&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 + =
减小字号Ctrl + -
显示快捷键?