Board logo

标题: arm内部寄存器读写函数(1) [打印本页]

作者: yuyang911220    时间: 2014-7-29 16:37     标题: arm内部寄存器读写函数(1)

1.在arch\parisc\include\asm\io.h中定义了如下函数:

以下函数用于内存映射
static inline void __iomem * ioremap(unsigned long offset, unsigned long size)
{

return __ioremap(offset, size, _PAGE_NO_CACHE);
}
#define ioremap_nocache(off, sz)
ioremap((off), (sz))

extern void iounmap(const volatile void __iomem *addr);



以下函数用于读写寄存器的值(数据寄存器,控制寄存器,配置寄存器...)
static inline unsigned char __raw_readb(const volatile void __iomem *addr)
{

return (*(volatile unsigned char __force *) (addr));
}
static inline unsigned short __raw_readw(const volatile void __iomem *addr)
{

return *(volatile unsigned short __force *) addr;
}
static inline unsigned int __raw_readl(const volatile void __iomem *addr)
{

return *(volatile unsigned int __force *) addr;
}
static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
{

return *(volatile unsigned long long __force *) addr;
}

static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
{

*(volatile unsigned char __force *) addr = b;
}
static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
{

*(volatile unsigned short __force *) addr = b;
}
static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
{

*(volatile unsigned int __force *) addr = b;
}
static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
{

*(volatile unsigned long long __force *) addr = b;
}

static inline unsigned char readb(const volatile void __iomem *addr)
{

return __raw_readb(addr);
}
static inline unsigned short readw(const volatile void __iomem *addr)
{

return le16_to_cpu(__raw_readw(addr));
}
static inline unsigned int readl(const volatile void __iomem *addr)
{

return le32_to_cpu(__raw_readl(addr));
}
static inline unsigned long long readq(const volatile void __iomem *addr)
{

return le64_to_cpu(__raw_readq(addr));
}

static inline void writeb(unsigned char b, volatile void __iomem *addr)
{

__raw_writeb(b, addr);
}
static inline void writew(unsigned short w, volatile void __iomem *addr)
{

__raw_writew(cpu_to_le16(w), addr);
}
static inline void writel(unsigned int l, volatile void __iomem *addr)
{

__raw_writel(cpu_to_le32(l), addr);
}
static inline void writeq(unsigned long long q, volatile void __iomem *addr)
{

__raw_writeq(cpu_to_le64(q), addr);

2.samsung.h中对串口对应寄存器的读写控制具体实现:
#define portaddr(port, reg) ((port)->membase + (reg))
#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))

struct uart_port {

spinlock_t
lock;
/* port lock */

unsigned long
iobase;
/* in/out[bwl] */

unsigned char __iomem
*membase;
/* read/write[bwl] */

unsigned int
(*serial_in)(struct uart_port *, int);

void
(*serial_out)(struct uart_port *, int, int);

unsigned int
irq;
/* irq number */

unsigned long
irqflags;
/* irq flags  */

unsigned int
uartclk;
/* base uart clock */

unsigned int
fifosize;
/* tx fifo size */

unsigned char
x_char;
/* xon/xoff char */

unsigned char
regshift;
/* reg offset shift */

unsigned char
iotype;
/* io access style */

unsigned char
unused1;




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0