From effd2fd66f3f67e42a3fc8c0e3c7a82f30dc2e44 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 21 Mar 2011 04:21:12 -0400 Subject: More convenient bit-banding interface --- libmaple/bitband.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/libmaple/bitband.h b/libmaple/bitband.h index b817f73..3e02702 100644 --- a/libmaple/bitband.h +++ b/libmaple/bitband.h @@ -47,6 +47,26 @@ static inline __io uint32* bb_sramp(__io void *address, uint32 bit) { return __bb_addr(address, bit, BB_SRAM_BASE, BB_SRAM_REF); } +/** + * @brief Get a bit from an address in the SRAM bit-band region. + * @param address Address in the SRAM bit-band region to read from + * @param bit Bit in address to read + * @return bit's value in address. + */ +static inline uint8 bb_sram_get_bit(__io void *address, uint32 bit) { + return *bb_sramp(address, bit); +} + +/** + * @brief Set a bit in an address in the SRAM bit-band region. + * @param address Address in the SRAM bit-band region to write to + * @param bit Bit in address to write to + * @param val Value to write for bit, either 0 or 1. + */ +static inline void bb_sram_set_bit(__io void *address, uint32 bit, uint8 val) { + *bb_sramp(address, bit) = val; +} + /** * @brief Obtain a pointer to the bit-band address corresponding to a * bit in a peripheral address. @@ -57,6 +77,26 @@ static inline __io uint32* bb_perip(__io void *address, uint32 bit) { return __bb_addr(address, bit, BB_PERI_BASE, BB_PERI_REF); } +/** + * @brief Get a bit from an address in the peripheral bit-band region. + * @param address Address in the peripheral bit-band region to read from + * @param bit Bit in address to read + * @return bit's value in address. + */ +static inline uint8 bb_peri_get_bit(__io void *address, uint32 bit) { + return *bb_perip(address, bit); +} + +/** + * @brief Set a bit in an address in the peripheral bit-band region. + * @param address Address in the peripheral bit-band region to write to + * @param bit Bit in address to write to + * @param val Value to write for bit, either 0 or 1. + */ +static inline void bb_peri_set_bit(__io void *address, uint32 bit, uint8 val) { + *bb_perip(address, bit) = val; +} + static inline __io uint32* __bb_addr(__io void *address, uint32 bit, uint32 bb_base, -- cgit v1.2.3