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

📄 iodriver.c

📁 IO测试
💻 C
字号:
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
//#define _POSIX_SOURCE 
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/modversions.h>
#include <linux/version.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/hardware.h>
#include <asm/arch/io.h>
#include <asm/arch/irq.h>
#include <asm/arch/hardware.h>
#include <asm/arch/AT91RM9200_SYS.h>
#include <asm/arch/AT91RM9200.h>
//#include <asm/arch/AT91RM9200new.h>
//#include <asm/arch/AT91RM9200_PIO.h>
#include <asm/arch/pio.h>
int my_major=0;			/*设备端口号*/
/*unsigned long r_PIOA_PER;
unsigned long r_PIOA_PDR;
unsigned long r_PIOA_OER;
unsigned long r_PIOA_ODR;
unsigned long r_PIOA_PUDR;
unsigned long r_PIOA_PUER;
unsigned long r_PIOA_OWER;
unsigned long r_PIOA_OWDR;
unsigned long r_PIOA_SODR;
unsigned long r_PIOA_CODR;
#define rPIOA_PER (*(volatile unsigned long *)r_PIOA_PER)
#define rPIOA_PDR (*(volatile unsigned long *)r_PIOA_PDR)
#define rPIOA_OER (*(volatile unsigned long *)r_PIOA_OER)
#define rPIOA_ODR (*(volatile unsigned long *)r_PIOA_ODR)
#define rPIOA_PUDR (*(volatile unsigned long *)r_PIOA_PUDR)
#define rPIOA_PUER (*(volatile unsigned long *)r_PIOA_PUER)
#define rPIOA_OWER (*(volatile unsigned long *)r_PIOA_OWER)
#define rPIOA_OWDR (*(volatile unsigned long *)r_PIOA_OWDR)
#define rPIOA_SODR (*(volatile unsigned long *)r_PIOA_SODR)
#define rPIOA_CODR (*(volatile unsigned long *)r_PIOA_CODR)
//#define PIOA_PDR 0xFFFFF404
//#define PIOA_OER 0xFFFFF410
//#define PIOA_ODR 0xFFFFF414
//#define PIOA_PUDR 0xFFFFF460
//#define PIOA_PUER 0xFFFFF464
//#define PIOA_OWER 0xFFFFF4A0
//#define PIOA_OWDR 0xFFFFF4A4
//#define PIOA_SODR 0xFFFFF430
//#define PIOA_CODR 0xFFFFF434
int address_map(void)
{
r_PIOA_PER=ioremap(0xfffff400,4);
r_PIOA_PDR=ioremap(0xfffff404,4);
r_PIOA_OER=ioremap(0xfffff410,4);
r_PIOA_ODR=ioremap(0xfffff414,4);
r_PIOA_PUDR=ioremap(0xfffff460,4);
r_PIOA_PUER=ioremap(0xfffff464,4);
r_PIOA_OWER=ioremap(0xfffff4A0,4);
r_PIOA_OWDR=ioremap(0xfffff4A4,4);
r_PIOA_SODR=ioremap(0xfffff430,4);
r_PIOA_CODR=ioremap(0xfffff434,4);
return 0;
}*/
/***************************************************************************************/
/*                                    驱动读操作                                       */
/***************************************************************************************/
ssize_t IO_read(struct file *filp,char *buf,size_t count,loff_t *f_ops)
{
	return count;
}
/***************************************************************************************/
/*                                    驱动写操作                                       */
/***************************************************************************************/
ssize_t IO_write(struct file *filp,const char *buf,size_t count,loff_t *f_ops)
{
	return count;
}
/***************************************************************************************/
/*                                    驱动其它操作                                     */
/***************************************************************************************/
ssize_t IO_ioctl(struct inode *inode,struct file *filp,unsigned int out)
{	printk("IO_ioctl is called,parament is %d.\n",out);
	switch(out)
		{case 0:
			AT91_SYS->PIOA_CODR|=0x1;
			break;
		 case 1:
			AT91_SYS->PIOA_SODR|=0x1;
			break;
		 default:
			printk("error command is inputed.\n");
		}
}
/***************************************************************************************/
/*                                    驱动打开操作                                     */
/***************************************************************************************/
ssize_t IO_open(struct inode *inode,struct file *filp)
{
	int j,i,out;
	AT91_SYS->PIOA_PER|=AT91C_PA0_PCK3;
	AT91_SYS->PIOA_OER|=0x1;
	AT91_SYS->PIOA_OWER|=0x1;
	AT91_SYS->PIOA_PPUER|=0x1;
	return 0; 
}
/***************************************************************************************/
/*                                    驱动关闭操作                                     */
/***************************************************************************************/
ssize_t IO_release(struct inode *inode,struct file *filp)
{
	return 0;	
}
//设备向系统注册用的OPS结构,里面是对应的操作
struct file_operations IO_ops={
	open:		IO_open,
	read:		IO_read,
	write:		IO_write,
	ioctl:		IO_ioctl,
	release:	IO_release,
};
int init_module()
{
	int ret;
		ret=register_chrdev (my_major,"IOdriver",&IO_ops);
		if(ret<0){
			printk("ATRM9200: init_module faiIO with %d\n",ret);
			return ret;
		}
		else{if(my_major==0)
			my_major=ret;
			printk(KERN_INFO"ATRM9200 init_module success!!!\n");
			printk("major-number=%d\n",ret);
			return 0;
		    }
	return ret;}
void cleanup_module()
{
	printk("cleanup_module success!!!\n");
	unregister_chrdev(my_major,"IOdriver");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -