微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于AT91RM9200的I/O驱动程序(linux)

基于AT91RM9200的I/O驱动程序(linux)

时间:11-13 来源:互联网 点击:
#include linux/config.h>

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include /* get ioctl stuff for gpio */
//#include "at91_gpio.h"

#defineDRIVER_NAME"key_led" //device name
#defineDRIVER_VERSION"1.00" //driver version
#defineDRIVER_MAJOR33

static devfs_handle_t devfs_handle, devfs_keyled_dir;
static ssize_t io_read(struct file*, char*, size_t, loff_t* );
static ssize_t io_write(struct file*, const char*, size_t, loff_t* );
//static int can0_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
static int io_open(struct inode*,struct file*);
static int io_release(struct inode*,struct file*);
struct file_operations io_fops = {
//owner: THIS_MODULE,
//ioctl: gpio_ioctl,
write:io_write,
read: io_read,
open: io_open,
release: io_release,
};

void delay(int count)
{
int temp,i;
for(i=0;ifor(temp=0;temp<10000;temp++)
{
;
}
}

void io_int(void)
{
unsigned char temp;
AT91_SYS->PIOA_PER =AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//enable the peripheral control
AT91_SYS->PIOA_OER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//output enable
AT91_SYS->PIOA_IFDR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
AT91_SYS->PIOA_CODR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
AT91_SYS->PIOA_IDR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//disable the interrupt
AT91_SYS->PIOA_MDER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
AT91_SYS->PIOA_PPUER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
AT91_SYS->PIOA_OWER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//enable write the PIO_ODSR for PA22
for(temp=0;temp<5;temp++)
{
AT91_SYS->PIOA_ODSR=0;//PA22 should goto low now
delay(1000);
AT91_SYS->PIOA_ODSR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//PA22 should be high now
delay(1000);
}
printk("Init the LED over,and begine to init the key\n");
//////////////////////////init the led over,begine to init the KEY
AT91_SYS->PMC_PCER=0xffffffff;
AT91_SYS->PIOB_PER=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//enable the peripheral control
AT91_SYS->PIOB_ODR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the output
AT91_SYS->PIOB_IFER=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//enable the filter
AT91_SYS->PIOB_CODR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//clean the output reg
AT91_SYS->PIOB_IDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the interrupt
AT91_SYS->PIOB_MDDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//enable the multidriver
AT91_SYS->PIOB_PPUDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the pullup
AT91_SYS->PIOB_OWDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the output write

}
void keyled_init(void)
{
if(register_chrdev(DRIVER_MAJOR,DRIVER_NAME,&io_fops))
{printk("Can not register keyled driver as major device 33\n");
return;
}
else
printk("\nRegisterd the keyled driver as major device 33 success\n");
//devfs_keyled_dir = devfs_mk_dir(NULL, DRIVER_NAME, NULL);
devfs_handle = devfs_register(devfs_keyled_dir, DRIVER_NAME,
DEVFS_FL_DEFAULT,
DRIVER_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR,
&io_fops, NULL);

io_int();
printk("\nKeyled driver V0.1 write by Simon Liu\n");
return;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top