aboutsummaryrefslogtreecommitdiff
path: root/core/include/io.h
diff options
context:
space:
mode:
authorVictor Chong <victor.chong@linaro.org>2016-07-05 12:19:05 +0900
committerJoakim Bech <joakim.bech@linaro.org>2016-07-05 12:20:23 +0200
commit14ed32748f7d915493e31dbf01664c119fad91c6 (patch)
treec50634168bea957fb4f8cdd1afbc4f74a4af9fd5 /core/include/io.h
parent5e7638a863f42f6b400e0707fcb790057916451f (diff)
io.h: add io_mask{8,16,32} functions
When writing peripheral drivers, there's very often a need to read a register value, set/clear some bits and then write the new value back. Instead of having to 'manually' call read, do bit manipulations and write every single time, add this helper function for convenience. Signed-off-by: Victor Chong <victor.chong@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Diffstat (limited to 'core/include/io.h')
-rw-r--r--core/include/io.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/include/io.h b/core/include/io.h
index b0702130..510bf33d 100644
--- a/core/include/io.h
+++ b/core/include/io.h
@@ -66,4 +66,19 @@ static inline uint32_t read32(vaddr_t addr)
return *(volatile uint32_t *)addr;
}
+static inline void io_mask8(vaddr_t addr, uint8_t val, uint8_t mask)
+{
+ write8((read8(addr) & ~mask) | (val & mask), addr);
+}
+
+static inline void io_mask16(vaddr_t addr, uint16_t val, uint16_t mask)
+{
+ write16((read16(addr) & ~mask) | (val & mask), addr);
+}
+
+static inline void io_mask32(vaddr_t addr, uint32_t val, uint32_t mask)
+{
+ write32((read32(addr) & ~mask) | (val & mask), addr);
+}
+
#endif /*IO_H*/