1 /***************************************************************************//**
\r
3 * @brief Bitband Peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
34 #ifndef __SILICON_LABS_EM_BITBAND_H_
\r
35 #define __SILICON_LABS_EM_BITBAND_H_
\r
37 #include "em_device.h"
\r
42 /***************************************************************************//**
\r
43 * @addtogroup EM_Library
\r
45 ******************************************************************************/
\r
47 /***************************************************************************//**
\r
48 * @addtogroup BITBAND
\r
49 * @brief BITBAND Peripheral API
\r
51 ******************************************************************************/
\r
53 /***************************************************************************//**
\r
55 * Perform bit-band operation on peripheral memory location.
\r
58 * Bit-banding provides atomic read-modify-write cycle for single bit
\r
59 * modification. Please refer to the reference manual for further details
\r
60 * about bit-banding.
\r
63 * This function is only atomic on cores which fully support bitbanding.
\r
65 * @param[in] addr Peripheral address location to modify bit in.
\r
67 * @param[in] bit Bit position to modify, 0-31.
\r
69 * @param[in] val Value to set bit to, 0 or 1.
\r
70 ******************************************************************************/
\r
71 __STATIC_INLINE void BITBAND_Peripheral(volatile uint32_t *addr,
\r
75 #if defined(BITBAND_PER_BASE)
\r
77 BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4);
\r
79 *((volatile uint32_t *)tmp) = (uint32_t)val;
\r
81 uint32_t tmp = *addr;
\r
82 /* Make sure val is not more than 1, because we only want to set one bit. */
\r
84 *addr = (tmp & ~(1 << bit)) | (val << bit);
\r
85 #endif /* defined(BITBAND_PER_BASE) */
\r
89 /***************************************************************************//**
\r
91 * Perform a read operation on the peripheral bit-band memory location.
\r
94 * This function reads a single bit from the peripheral bit-band alias region.
\r
95 * Bit-banding provides atomic read-modify-write cycle for single bit
\r
96 * modification. Please refer to the reference manual for further details
\r
97 * about bit-banding.
\r
99 * @param[in] addr Peripheral address location to read.
\r
101 * @param[in] bit Bit position to read, 0-31.
\r
103 * @return Value of the requested bit.
\r
104 ******************************************************************************/
\r
105 __STATIC_INLINE uint32_t BITBAND_PeripheralRead(volatile uint32_t *addr,
\r
108 #if defined(BITBAND_PER_BASE)
\r
110 BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4);
\r
112 return *((volatile uint32_t *)tmp);
\r
114 return ((*addr) >> bit) & 1;
\r
115 #endif /* defined(BITBAND_PER_BASE) */
\r
119 /***************************************************************************//**
\r
121 * Perform bit-band operation on SRAM memory location.
\r
124 * Bit-banding provides atomic read-modify-write cycle for single bit
\r
125 * modification. Please refer to the reference manual for further details
\r
126 * about bit-banding.
\r
129 * This function is only atomic on cores which fully support bitbanding.
\r
131 * @param[in] addr SRAM address location to modify bit in.
\r
133 * @param[in] bit Bit position to modify, 0-31.
\r
135 * @param[in] val Value to set bit to, 0 or 1.
\r
136 ******************************************************************************/
\r
137 __STATIC_INLINE void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val)
\r
139 #if defined(BITBAND_RAM_BASE)
\r
141 BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) * 32) + (bit * 4);
\r
143 *((volatile uint32_t *)tmp) = (uint32_t)val;
\r
145 uint32_t tmp = *addr;
\r
146 /* Make sure val is not more than 1, because we only want to set one bit. */
\r
148 *addr = (tmp & ~(1 << bit)) | (val << bit);
\r
149 #endif /* defined(BITBAND_RAM_BASE) */
\r
153 /***************************************************************************//**
\r
155 * Read a single bit from the SRAM bit-band alias region.
\r
158 * This function reads a single bit from the SRAM bit-band alias region.
\r
159 * Bit-banding provides atomic read-modify-write cycle for single bit
\r
160 * modification. Please refer to the reference manual for further details
\r
161 * about bit-banding.
\r
163 * @param[in] addr SRAM address location to modify bit in.
\r
165 * @param[in] bit Bit position to modify, 0-31.
\r
167 * @return Value of the requested bit.
\r
168 ******************************************************************************/
\r
169 __STATIC_INLINE uint32_t BITBAND_SRAMRead(uint32_t *addr, uint32_t bit)
\r
171 #if defined(BITBAND_RAM_BASE)
\r
173 BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) * 32) + (bit * 4);
\r
175 return *((volatile uint32_t *)tmp);
\r
177 return ((*addr) >> bit) & 1;
\r
178 #endif /* defined(BITBAND_RAM_BASE) */
\r
181 /** @} (end addtogroup BITBAND) */
\r
182 /** @} (end addtogroup EM_Library) */
\r
188 #endif /* __SILICON_LABS_EM_BITBAND_H_ */
\r