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

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

时间:11-13 来源:互联网 点击:

static int io_open(struct inode* inode,struct file* file)
{
MOD_INC_USE_COUNT;
return 0;
}

static int io_release(struct inode* inode,struct file* file)
{
MOD_DEC_USE_COUNT;
return 0;
}

static ssize_t io_read(struct file * file ,char * buff,size_t count,loff_t * offp)
{
int i;
unsigned long temp,key_temp;
unsigned char key_data[4];
temp=AT91_SYS->PIOB_PDSR;
//printk("%d\n",temp);
key_temp=temp;
//temp=temp >>13;
key_data[0]=(unsigned char)(key_temp&0xfe);
temp=temp>>8;
key_temp=temp;
key_data[1]=(unsigned char)(key_temp& 0xff);
temp=temp>>8;
key_temp=temp;
key_data[2]=(unsigned char)(key_temp& 0x7);
temp=temp>>8;
key_temp=temp;
key_data[3]=(unsigned char)(key_temp& 0x30);
copy_to_user(buff,&key_data[0],4);
//printk("\nthe key data is \n");
//for(i=0;i<4;i++)
//printk("%4d",key_data[i]);
return 4;
//return 0;
}

ssize_t io_write(struct file* file, const char* ch, size_t count, loff_t* offp )
{
unsigned char led_data;
unsigned long temp;
copy_from_user(&led_data,ch,1);
temp=led_data;
temp=(temp<17);
temp=(temp &(AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22));
AT91_SYS->PIOA_ODSR= temp;
return 1;
}

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

网站地图

Top