STM32LIB
reg_t.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "generate_mask_t.hpp"
4 #include <limits>
5 
32 template
33 <
34  typename mutability_policy_t,
35  unsigned address,
36  unsigned offset,
37  unsigned width
38 >
39 struct reg_t
40 {
41  static_assert(width > 0, "invalid field of zero width");
42  static_assert(width + offset <= std::numeric_limits<unsigned>::digits,
43  "register width overflow");
44 
49  static unsigned read()
50  {
51  return
52  mutability_policy_t::read(
53  reinterpret_cast<volatile unsigned *>(address),
54  offset,
56  );
57  }
58 
63  static void write(unsigned value)
64  {
65  mutability_policy_t::write(
66  reinterpret_cast<volatile unsigned *>(address),
67  offset,
69  value
70  );
71  }
72 
76  static void set()
77  {
78  mutability_policy_t::set(
79  reinterpret_cast<volatile unsigned *>(address),
81  );
82  }
83 
87  static void clear()
88  {
89  mutability_policy_t::clear(
90  reinterpret_cast<volatile unsigned *>(address),
92  );
93  }
94 };
static unsigned read()
Definition: reg_t.hpp:49
Definition: generate_mask_t.hpp:15
static void set()
Definition: reg_t.hpp:76
Definition: reg_t.hpp:39
static void write(unsigned value)
Definition: reg_t.hpp:63
static void clear()
Definition: reg_t.hpp:87