From: Thomas Cort Date: Mon, 12 Aug 2013 17:33:13 +0000 (-0400) Subject: mmio: add 16-bit variants of read/write/set X-Git-Tag: v3.3.0~843 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/already%20found%20%2A/doxygen.log?a=commitdiff_plain;h=99e91dab2f13fddc42edbe0b50e89f737185d374;p=minix.git mmio: add 16-bit variants of read/write/set Change-Id: If4fb5585865768daa151bd4aa343ac5c84d2e9c3 --- diff --git a/include/minix/mmio.h b/include/minix/mmio.h index 8c23a3520..60a41c952 100644 --- a/include/minix/mmio.h +++ b/include/minix/mmio.h @@ -1,6 +1,7 @@ #ifndef __MMIO_H__ #define __MMIO_H__ +#define REG16(x)(*((volatile uint16_t *)(x))) #define REG(x)(*((volatile uint32_t *)(x))) #define BIT(x)(0x1 << x) @@ -30,4 +31,32 @@ set32(uint32_t address, uint32_t mask, uint32_t value) val |= (value & mask); write32(address, val); } + +/* Write a uint16_t value to a memory address. */ +static inline void +write16(uint32_t address, uint16_t value) +{ + REG16(address) = value; +} + +/* Read an uint16_t from a memory address */ +static inline uint16_t +read16(uint32_t address) +{ + return REG16(address); +} + +/* Set a 16 bits value depending on a mask */ +static inline void +set16(uint32_t address, uint16_t mask, uint16_t value) +{ + uint16_t val; + val = read16(address); + /* clear the bits */ + val &= ~(mask); + /* apply the value using the mask */ + val |= (value & mask); + write16(address, val); +} + #endif /* __MMIO_H__ */