From 379907a42c6f3a5452ea7569c64d1970b7fb46c1 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Sun, 27 Apr 2014 12:13:09 +0200 Subject: [PATCH] adf_os_io.h: add some ios Signed-off-by: Oleksij Rempel --- .../magpie_fw_dev/target/inc/adf_os_io.h | 91 +++++++++++++++---- 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/target_firmware/magpie_fw_dev/target/inc/adf_os_io.h b/target_firmware/magpie_fw_dev/target/inc/adf_os_io.h index 7924288..cc2f246 100755 --- a/target_firmware/magpie_fw_dev/target/inc/adf_os_io.h +++ b/target_firmware/magpie_fw_dev/target/inc/adf_os_io.h @@ -43,34 +43,89 @@ #include -/** - * @brief Read a 32-bit register value - * - * @param[in] addr register addr - * - * @return A 32-bit register value. - */ -static inline a_uint32_t ioread32(a_uint32_t addr) +static inline uint8_t ioread8(const volatile uint32_t addr) { - return *(const volatile a_uint32_t *) addr; + return *(const volatile uint8_t *) addr; } -#define ioread32_mac(addr) ioread32(WLAN_BASE_ADDRESS + (addr)) +static inline uint16_t ioread16(const volatile uint32_t addr) +{ + return *(const volatile uint16_t *) addr; +} -/** - * @brief Write a 32-bit value into register - * - * @param[in] addr register addr - * @param[in] b the 32-bit value to be written - */ +static inline uint32_t ioread32(const volatile uint32_t addr) +{ + return *(const volatile uint32_t *) addr; +} + +static inline void iowrite8(volatile uint32_t addr, const uint8_t b) +{ + *(volatile uint8_t *) addr = b; +} + +static inline void iowrite16(volatile uint32_t addr, const uint16_t b) +{ + *(volatile uint16_t *) addr = b; +} + +static inline void iowrite32(volatile uint32_t addr, const uint32_t b) +{ + *(volatile uint32_t *) addr = b; +} + +static inline void io8_rmw(volatile uint32_t addr, + const uint8_t set, const uint8_t clr) +{ + uint8_t val; + + val = ioread8(addr); + val &= ~clr; + val |= set; + iowrite8(addr, val); +} -static inline void iowrite32(volatile a_uint32_t addr, a_uint32_t b) +static inline void io32_rmw(volatile uint32_t addr, + const uint32_t set, const uint32_t clr) { - *(volatile a_uint32_t *) addr = b; + uint32_t val; + + val = ioread32(addr); + val &= ~clr; + val |= set; + iowrite32(addr, val); } +/* generic functions */ +#define io8_set(addr, s) io8_rmw((addr), (s), 0) +#define io8_clr(addr, c) io8_rmw((addr), 0, (c)) +#define io32_set(addr, s) io32_rmw((addr), (s), 0) +#define io32_clr(addr, c) io32_rmw((addr), 0, (c)) + +/* mac specific functions */ +#define ioread32_mac(addr) ioread32(WLAN_BASE_ADDRESS + (addr)) #define iowrite32_mac(addr, b) iowrite32(WLAN_BASE_ADDRESS + (addr), (b)) +/* usb specific functions */ +#define ioread8_usb(addr) ioread8(USB_CTRL_BASE_ADDRESS | (addr)^3) +#define ioread16_usb(addr) ioread16(USB_CTRL_BASE_ADDRESS | (addr)) +#define ioread32_usb(addr) ioread32(USB_CTRL_BASE_ADDRESS | (addr)) + +#define iowrite8_usb(addr, b) iowrite8(USB_CTRL_BASE_ADDRESS | (addr)^3, (b)) +#define iowrite16_usb(addr, b) iowrite16(USB_CTRL_BASE_ADDRESS | (addr), (b)) +#define iowrite32_usb(addr, b) iowrite32(USB_CTRL_BASE_ADDRESS | (addr), (b)) + +#define io8_rmw_usb(addr, s, c) \ + io8_rmw(USB_CTRL_BASE_ADDRESS | (addr)^3, (s), (c)) +#define io8_set_usb(addr, s) \ + io8_rmw(USB_CTRL_BASE_ADDRESS | (addr)^3, (s), 0) +#define io8_clr_usb(addr, c) \ + io8_rmw(USB_CTRL_BASE_ADDRESS | (addr)^3, 0, (c)) + +#define io32_rmw_usb(addr, s, c) \ + io32_rmw(USB_CTRL_BASE_ADDRESS | (addr), (s), (c)) +#define io32_set_usb(addr, s) io32_rmw(USB_CTRL_BASE_ADDRESS | (addr), (s), 0) +#define io32_clr_usb(addr, c) io32_rmw(USB_CTRL_BASE_ADDRESS | (addr), 0, (c)) + /** * @brief Convert a 16-bit value from network byte order to host byte order */ -- 2.25.1