GR712RC unit tests 1.0
Bare-metal C++ hardware tests for the PLATO DPU (IAA-CSIC, 2019)
Loading...
Searching...
No Matches
mcal_reg_access_template.h
Go to the documentation of this file.
1
2// Copyright Christopher Kormanyos 2007 - 2013.
3// Distributed under the Boost Software License,
4// Version 1.0. (See accompanying file LICENSE_1_0.txt
5// or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7
8#ifndef _MCAL_REG_ACCESS_TEMPLATE_2010_12_01_H_
9 #define _MCAL_REG_ACCESS_TEMPLATE_2010_12_01_H_
10
11 namespace mcal
12 {
13 namespace reg
14 {
15 template<typename register_address_type,
16 typename register_value_type,
17 const register_address_type address,
18 const register_value_type value = static_cast<register_value_type>(0)>
19 struct access
20 {
21 static void reg_set() { *reinterpret_cast<volatile register_value_type*>(address) = value; }
22 static void reg_and() { *reinterpret_cast<volatile register_value_type*>(address) &= value; }
23 static void reg_or () { *reinterpret_cast<volatile register_value_type*>(address) |= value; }
24 static void reg_not() { *reinterpret_cast<volatile register_value_type*>(address) &= register_value_type(~value); }
25 static register_value_type reg_get() { return *reinterpret_cast<volatile register_value_type*>(address); }
26
27 template<const register_value_type mask_value>
28 static void reg_msk()
29 {
30 *reinterpret_cast<volatile register_value_type*>(address) = register_value_type(register_value_type(reg_get() & register_value_type(~mask_value)) | register_value_type(value & mask_value));
31 }
32
33 static void bit_set() { *reinterpret_cast<volatile register_value_type*>(address) |= static_cast<register_value_type>(1UL << value); }
34 static void bit_clr() { *reinterpret_cast<volatile register_value_type*>(address) &= static_cast<register_value_type>(~static_cast<register_value_type>(1UL << value)); }
35 static void bit_not() { *reinterpret_cast<volatile register_value_type*>(address) ^= static_cast<register_value_type>(1UL << value); }
36 static bool bit_get() { return (static_cast<volatile register_value_type>(reg_get() & static_cast<register_value_type>(1UL << value)) != static_cast<register_value_type>(0U)); }
37 };
38 }
39 }
40
41#endif // _MCAL_REG_ACCESS_TEMPLATE_2010_12_01_H_
static register_value_type reg_get()