APM:Libraries
bitband.h
Go to the documentation of this file.
1 /******************************************************************************
2  * The MIT License
3  *
4  * Copyright (c) 2011 LeafLabs, LLC.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use, copy,
10  * modify, merge, publish, distribute, sublicense, and/or sell copies
11  * of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  *****************************************************************************/
26 
32 #ifndef _BITBAND_H_
33 #define _BITBAND_H_
34 
35 #include "hal_types.h"
36 
37 #ifdef __cplusplus
38  extern "C" {
39 #endif
40 
41 
42 static inline volatile uint32_t* __bb_addr(volatile void*,
43  uint32_t,
44  uint32_t,
45  uint32_t);
46 
53 static inline volatile uint32_t* bb_sramp(volatile void *address, uint32_t bit) {
54  return __bb_addr(address, bit, SRAM1_BB_BASE, SRAM_BASE);
55 }
56 
63 static inline uint8_t bb_sram_get_bit(volatile void *address, uint32_t bit) {
64  return *bb_sramp(address, bit);
65 }
66 
73 static inline void bb_sram_set_bit(volatile void *address,
74  uint32_t bit,
75  uint8_t val) {
76  *bb_sramp(address, bit) = val;
77 }
78 
85 static inline volatile uint32_t* bb_perip(volatile void *address, uint32_t bit) {
86  return __bb_addr(address, bit, PERIPH_BB_BASE, PERIPH_BASE);
87 }
88 
95 static inline uint8_t bb_peri_get_bit(volatile void *address, uint32_t bit) {
96  return *bb_perip(address, bit);
97 }
98 
105 static inline void bb_peri_set_bit(volatile void *address,
106  uint32_t bit,
107  uint8_t val) {
108  *bb_perip(address, bit) = val;
109 }
110 
111 static inline volatile uint32_t* __bb_addr(volatile void *address,
112  uint32_t bit,
113  uint32_t bb_base,
114  uint32_t bb_ref) {
115  return (volatile uint32_t*)(bb_base + ((uint32_t)address - bb_ref) * 32 +
116  bit * 4);
117 }
118 
119 #ifdef __cplusplus
120  }
121 #endif
122 
123 
124 #endif /* _BITBAND_H_ */
static uint8_t bb_sram_get_bit(volatile void *address, uint32_t bit)
Get a bit from an address in the SRAM bit-band region.
Definition: bitband.h:63
static volatile uint32_t * bb_sramp(volatile void *address, uint32_t bit)
Obtain a pointer to the bit-band address corresponding to a bit in a volatile SRAM address...
Definition: bitband.h:53
static volatile uint32_t * __bb_addr(volatile void *, uint32_t, uint32_t, uint32_t)
Definition: bitband.h:111
static void bb_peri_set_bit(volatile void *address, uint32_t bit, uint8_t val)
Set a bit in an address in the peripheral bit-band region.
Definition: bitband.h:105
static uint8_t bb_peri_get_bit(volatile void *address, uint32_t bit)
Get a bit from an address in the peripheral bit-band region.
Definition: bitband.h:95
static volatile uint32_t * bb_perip(volatile void *address, uint32_t bit)
Obtain a pointer to the bit-band address corresponding to a bit in a peripheral address.
Definition: bitband.h:85
static void bb_sram_set_bit(volatile void *address, uint32_t bit, uint8_t val)
Set a bit in an address in the SRAM bit-band region.
Definition: bitband.h:73