LINUX下读写寄存器Word格式文档下载.docx
- 文档编号:20534250
- 上传时间:2023-01-23
- 格式:DOCX
- 页数:10
- 大小:16.19KB
LINUX下读写寄存器Word格式文档下载.docx
《LINUX下读写寄存器Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《LINUX下读写寄存器Word格式文档下载.docx(10页珍藏版)》请在冰豆网上搜索。
linux/slab.h>
/*kmalloc()*/
linux/fs.h>
/*everything...*/
linux/errno.h>
/*errorcodes*/
linux/types.h>
/*size_t*/
linux/proc_fs.h>
linux/fcntl.h>
/*O_ACCMODE*/
linux/seq_file.h>
linux/cdev.h>
linux/ioport.h>
mach/regs-gpio.h>
asm/system.h>
/*cli(),*_flags*/
asm/uaccess.h>
/*copy_*_user*/
asm/io.h>
#defineLED_NUM4
structled_dev
{
structcdevdev;
unsignedport;
unsignedlongoffset;
};
structled_devled[4];
dev_tdev=0;
staticstructresource*led_resource;
intled_open(structinode*inode,structfile*filp)
structled_dev*led;
/*deviceinformation*/
led=container_of(inode->
i_cdev,structled_dev,dev);
filp->
private_data=led;
/*forothermethods*/
return0;
/*success*/
}
intled_release(structinode*inode,structfile*filp)
ssize_tled_read(structfile*filp,char__user*buf,size_tcount,loff_t*f_pos)
ssize_tled_write(structfile*filp,constchar__user*buf,size_tcount,loff_t*f_pos)
chardata;
u32value;
printk(KERN_INFO"
debugbybaikal:
leddevwrite\n"
);
led=(structled_dev*)filp->
private_data;
copy_from_user(&
data,buf,count);
if(data=='
0'
)
ledoff\n"
value=inl((unsigned)(S3C2410_GPBDAT));
outl(value|1<
<
led->
offset,(unsigned)(S3C2410_GPBDAT));
//value=ioread32(led->
base);
//iowrite32(value|1<
offset,led->
else
ledon\n"
outl(value&
~(1<
offset),(unsigned)(S3C2410_GPBDAT));
//iowrite32(value&
offset),led->
structfile_operationsled_fops={
.owner=THIS_MODULE,
.read=led_read,
.write=led_write,
//.ioctl=led_ioctl,
.open=led_open,
.release=led_release,
staticintled_init(void)
intresult,i;
result=alloc_chrdev_region(&
dev,0,LED_NUM,"
LED"
if(result<
0){
printk(KERN_WARNING"
LED:
can'
tgetmajor%d\n"
MAJOR(dev));
returnresult;
led_resource=request_region(0x56000014,0x4,"
led"
if(led_resource==NULL)
printk(KERN_ERR"
UnabletoregisterLEDI/Oaddresses\n"
return-1;
for(i=0;
i<
LED_NUM;
i++)
cdev_init(&
led[i].dev,&
led_fops);
//led[i].port=ioport_map(0x56000014,0x4);
//led[i].base=ioremap(0x56000014,0x4);
led[i].offset=i+5;
//ledsGPB5\6\7\8
led[i].dev.owner=THIS_MODULE;
led[i].dev.ops=&
led_fops;
result=cdev_add(&
led[i].dev,MKDEV(MAJOR(dev),i),1);
if(result<
0)
taddled%d\n"
i);
staticvoidled_exit(void)
inti;
release_region(0x56000014,0x4);
for(i=0;
//iounmap(led[i].base);
cdev_del(&
led[i].dev);
unregister_chrdev_region(dev,LED_NUM);
module_init(led_init);
module_exit(led_exit);
MODULE_AUTHOR("
Baikal"
MODULE_LICENSE("
GPL"
MODULE_DESCRIPTION("
SimpleLEDDriver"
2.利用IOMem的方式:
void__iomem*base;
value=ioread32(led->
iowrite32(value|1<
iowrite32(value&
request_mem_region(0x56000014,0x4,"
led[i].base=ioremap(0x56000014,0x4);
release_mem_region(0x56000014,0x4);
iounmap(led[i].base);
目前,对于具体体系上的linux在移植过程中如何实现这两种方式的方法还不清楚,现在只是会用。
等以后有机会了再慢慢理清楚。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- LINUX 读写 寄存器
![提示](https://static.bdocx.com/images/bang_tan.gif)