OpenMPTL - ARM Cortex (common)
C++ Microprocessor Template Library
bitband.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef ARM_CORTEX_COMMON_BITBAND_HPP_INCLUDED
22 #define ARM_CORTEX_COMMON_BITBAND_HPP_INCLUDED
23 
24 #include <register_type.hpp>
25 
26 namespace mptl {
27 
29 {
30  static constexpr reg_addr_t region_start = 0x40000000;
31  static constexpr reg_addr_t region_end = 0x40100000;
32  static constexpr reg_addr_t alias_base = 0x42000000;
33 
34  using value_type = uint32_t;
35 
36  static constexpr bool covered(reg_addr_t addr) {
37  return (addr >= region_start) && (addr < region_end);
38  }
39 
40  template<reg_addr_t addr, unsigned bit_no>
41  static __always_inline void bitset(void) {
42  // static_assert(covered(addr), "addr is not covered by the bit-band region");
43  static constexpr reg_addr_t addr_bb = alias_base + ((addr - region_start) * 32) + (bit_no * 4);
44  *reinterpret_cast<volatile value_type *>(addr_bb) = 1;
45  }
46 
47  template<reg_addr_t addr, unsigned bit_no>
48  static __always_inline void bitclear(void) {
49  // static_assert(covered(addr), "addr is not covered by the bit-band region");
50  static constexpr reg_addr_t addr_bb = alias_base + ((addr - region_start) * 32) + (bit_no * 4);
51  *reinterpret_cast<volatile value_type *>(addr_bb) = 0;
52  }
53 
54  template<reg_addr_t addr, unsigned bit_no>
55  static __always_inline bool bittest(void) {
56  // static_assert(covered(addr), "addr is not covered by the bit-band region");
57  static constexpr reg_addr_t addr_bb = alias_base + ((addr - region_start) * 32) + (bit_no * 4);
58  return *reinterpret_cast<volatile value_type *>(addr_bb);
59  }
60 };
61 
62 
63 
64 } // namespace mptl
65 
66 #endif // ARM_CORTEX_COMMON_BITBAND_HPP_INCLUDED
static constexpr bool covered(reg_addr_t addr)
Definition: bitband.hpp:36
static constexpr reg_addr_t region_end
Definition: bitband.hpp:31
static __always_inline void bitclear(void)
Definition: bitband.hpp:48
static constexpr reg_addr_t region_start
Definition: bitband.hpp:30
static __always_inline void bitset(void)
Definition: bitband.hpp:41
uintptr_t reg_addr_t
#define __always_inline
Definition: bitband.hpp:28
static __always_inline bool bittest(void)
Definition: bitband.hpp:55
static constexpr reg_addr_t alias_base
Definition: bitband.hpp:32
uint32_t value_type
Definition: bitband.hpp:34