基于AT91RM9200的I/O驱动程序(linux)
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;
}
AT91RM9200IO驱动linu 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)