码迷,mamicode.com
首页 > 其他好文 > 详细

ioremap 函数映射操作已知的物理地址(寄存器、端口、IO)

时间:2015-07-23 23:51:13      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:ioremap   物理地址   寄存器   

NAME
ioremap - map bus memory into CPU space
SYNOPSIS

  void __iomem * ioremap  (unsigned long  offset, unsigned long size);

ARGUMENTS

offset
bus address of the memory

size
size of the resource to map

DESCRIPTION

ioremap performs a platform specific sequence of operations to make bus memory CPU accessible via the readb/readw/readl/writeb/ writew/writel functions and the other mmio helpers. The returned address is not guaranteed to be usable directly as a virtual address.

ioremap 函数来映射到内核地址空间,然后修改虚拟地址空间达到控制寄存器的状态。
我用如下方法操作一个地址为0x56000020的端口
第一种:

unsigned long port_addr;
(void *)(port_addr) = ioremap(0x56000020,0x8);
*(volatile unsigned int *)(port_addr) |= 0x00008000;

编译时候出现警告warning,左值有问题,建议使用第二种。
第二种:

volatile unsigned int *port_addr = ioremap(0x56000020,0x8);
*port_addr |= 0x00008000;
#define rGPACON (*(volatile unsigned *)(ioremap(GPACON,0x8)))

版权声明:本文为博主原创文章,未经博主允许不得转载。

ioremap 函数映射操作已知的物理地址(寄存器、端口、IO)

标签:ioremap   物理地址   寄存器   

原文地址:http://blog.csdn.net/xy010902100449/article/details/47029679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!