ioremap 函式對映操作已知的實體地址(暫存器、埠、IO)
阿新 • • 發佈:2019-01-05
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)))