EFM32 Zero Gecko Software Documentation  efm32zg-doc-4.2.1
em_bus.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __SILICON_LABS_EM_BUS__
34 #define __SILICON_LABS_EM_BUS__
35 
36 #include "em_device.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /***************************************************************************/
47 /***************************************************************************/
53 /***************************************************************************/
73 __STATIC_INLINE void BUS_RamBitWrite(volatile uint32_t *addr,
74  unsigned int bit,
75  unsigned int val)
76 {
77 #if defined( BITBAND_RAM_BASE )
78  uint32_t aliasAddr =
79  BITBAND_RAM_BASE + (((uint32_t)addr - SRAM_BASE) * 32) + (bit * 4);
80 
81  *(volatile uint32_t *)aliasAddr = (uint32_t)val;
82 #else
83  uint32_t tmp = *addr;
84 
85  /* Make sure val is not more than 1, because we only want to set one bit. */
86  *addr = (tmp & ~(1 << bit)) | ((val & 1) << bit);
87 #endif
88 }
89 
90 
91 /***************************************************************************/
112 __STATIC_INLINE unsigned int BUS_RamBitRead(volatile const uint32_t *addr,
113  unsigned int bit)
114 {
115 #if defined( BITBAND_RAM_BASE )
116  uint32_t aliasAddr =
117  BITBAND_RAM_BASE + (((uint32_t)addr - SRAM_BASE) * 32) + (bit * 4);
118 
119  return *(volatile uint32_t *)aliasAddr;
120 #else
121  return ((*addr) >> bit) & 1;
122 #endif
123 }
124 
125 
126 /***************************************************************************/
146 __STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr,
147  unsigned int bit,
148  unsigned int val)
149 {
150 #if defined( BITBAND_PER_BASE )
151  uint32_t aliasAddr =
152  BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4);
153 
154  *(volatile uint32_t *)aliasAddr = (uint32_t)val;
155 #else
156  uint32_t tmp = *addr;
157 
158  /* Make sure val is not more than 1, because we only want to set one bit. */
159  *addr = (tmp & ~(1 << bit)) | ((val & 1) << bit);
160 #endif
161 }
162 
163 
164 /***************************************************************************/
185 __STATIC_INLINE unsigned int BUS_RegBitRead(volatile const uint32_t *addr,
186  unsigned int bit)
187 {
188 #if defined( BITBAND_PER_BASE )
189  uint32_t aliasAddr =
190  BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4);
191 
192  return *(volatile uint32_t *)aliasAddr;
193 #else
194  return ((*addr) >> bit) & 1;
195 #endif
196 }
197 
198 
199 /***************************************************************************/
219 __STATIC_INLINE void BUS_RegMaskedSet(volatile uint32_t *addr,
220  uint32_t mask)
221 {
222 #if defined( PER_BITSET_MEM_BASE )
223  uint32_t aliasAddr = PER_BITSET_MEM_BASE + ((uint32_t)addr - PER_MEM_BASE);
224  *(volatile uint32_t *)aliasAddr = mask;
225 #else
226  *addr |= mask;
227 #endif
228 }
229 
230 
231 /***************************************************************************/
251 __STATIC_INLINE void BUS_RegMaskedClear(volatile uint32_t *addr,
252  uint32_t mask)
253 {
254 #if defined( PER_BITCLR_MEM_BASE )
255  uint32_t aliasAddr = PER_BITCLR_MEM_BASE + ((uint32_t)addr - PER_MEM_BASE);
256  *(volatile uint32_t *)aliasAddr = mask;
257 #else
258  *addr &= ~mask;
259 #endif
260 }
261 
262 
263 /***************************************************************************/
283 __STATIC_INLINE void BUS_RegMaskedWrite(volatile uint32_t *addr,
284  uint32_t mask,
285  uint32_t val)
286 {
287 #if defined( PER_BITCLR_MEM_BASE )
288  BUS_RegMaskedClear(addr, mask);
289  BUS_RegMaskedSet(addr, val);
290 #else
291  *addr = (*addr & ~mask) | val;
292 #endif
293 }
294 
295 
296 /***************************************************************************/
313 __STATIC_INLINE uint32_t BUS_RegMaskedRead(volatile const uint32_t *addr,
314  uint32_t mask)
315 {
316  return *addr & mask;
317 }
318 
319 
323 #ifdef __cplusplus
324 }
325 #endif
326 
327 #endif /* __SILICON_LABS_EM_BUS__ */
__STATIC_INLINE void BUS_RamBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a 32-bit word in RAM.
Definition: em_bus.h:73
#define PER_MEM_BASE
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__STATIC_INLINE unsigned int BUS_RegBitRead(volatile const uint32_t *addr, unsigned int bit)
Perform a single-bit read operation on a peripheral register.
Definition: em_bus.h:185
#define SRAM_BASE
__STATIC_INLINE void BUS_RegMaskedSet(volatile uint32_t *addr, uint32_t mask)
Perform a masked set operation on peripheral register address.
Definition: em_bus.h:219
__STATIC_INLINE void BUS_RegMaskedClear(volatile uint32_t *addr, uint32_t mask)
Perform a masked clear operation on peripheral register address.
Definition: em_bus.h:251
__STATIC_INLINE uint32_t BUS_RegMaskedRead(volatile const uint32_t *addr, uint32_t mask)
Perform a peripheral register masked read.
Definition: em_bus.h:313
__STATIC_INLINE unsigned int BUS_RamBitRead(volatile const uint32_t *addr, unsigned int bit)
Perform a single-bit read operation on a 32-bit word in RAM.
Definition: em_bus.h:112
__STATIC_INLINE void BUS_RegMaskedWrite(volatile uint32_t *addr, uint32_t mask, uint32_t val)
Perform peripheral register masked clear and value write.
Definition: em_bus.h:283
__STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a peripheral register.
Definition: em_bus.h:146