⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kern.c~

📁 读取frv实验系统上的按键值 并以此来控制frv实验板上的led 基于嵌入式linux
💻 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 + -