GR712RC unit tests 1.0
Bare-metal C++ hardware tests for the PLATO DPU (IAA-CSIC, 2019)
Loading...
Searching...
No Matches
mcal_port.h
Go to the documentation of this file.
1
7
8#ifndef MCAL_PORT_2018_01_10_H_
9 #define MCAL_PORT_2018_01_10_H_
10
11 #include <mcal_reg_access.h>
12
13 namespace mcal
14 {
15 namespace port
16 {
17 typedef void config_type;
18 void init(const config_type*);
19
20 template<typename addr_type,
21 typename reg_type,
22 const addr_type port,
23 const reg_type bpos>
25 {
26 public:
28 {
29 // Set the port pin control bits.
30
31 // Set the port pin direction to digital output.
32 mcal::reg::access<addr_type,
33 reg_type,
34 port_direction_register,
35 static_cast<std::uint32_t>(UINT32_C(0x01) << (bpos))>::reg_or();
36
37 //Disable interrupts for that pin
38 mcal::reg::access<addr_type,
39 reg_type,
40 interrupt_mask_register,
41 ~static_cast<std::uint32_t>(UINT32_C(0x01) << (bpos))>::reg_and();
42
43 //Set output digital 0.
44 mcal::reg::access<addr_type,
45 reg_type,
46 output_data_register,
47 ~static_cast<std::uint32_t>(UINT32_C(0x01) << (bpos))>::reg_and();
48 }
49
50 static void set_direction_input()
51 {
52
53
54 //Disable interrupts for that pin
55 mcal::reg::access<addr_type,
56 reg_type,
57 interrupt_mask_register,
58 ~static_cast<std::uint32_t>(UINT32_C(0x01) << (bpos))>::reg_and();
59
60 //Set poert direction to input
61 mcal::reg::access<addr_type,
62 reg_type,
63 port_direction_register,
64 ~static_cast<std::uint32_t>(UINT32_C(0x01) << (bpos))>::reg_and();
65
66 /*
67 // Disable Output
68 mcal::reg::access<addr_type,
69 reg_type,
70 output_disable_register,
71 static_cast<std::uint32_t>(UINT32_C(0x01) << (bpos))>::reg_or(); */
72 }
73
74 static void set_pin_high()
75 {
76 // Set the port output value to high.
77 mcal::reg::access<addr_type,
78 reg_type,
79 output_data_register,
80 bpos>::bit_set();
81 }
82
83 static void set_pin_low()
84 {
85 // Set the port output value to low.
86 mcal::reg::access<addr_type,
87 reg_type,
88 output_data_register,
89 bpos>::bit_clr();
90 }
91
92 static bool read_input_value()
93 {
94 // Read the port input value.
95 return mcal::reg::access<addr_type,
96 reg_type,
97 input_data_register,
98 bpos>::bit_get();
99 }
100
101 static void toggle_pin()
102 {
103 // Toggle the port output value.
104 mcal::reg::access<addr_type,
105 reg_type,
106 output_data_register,
107 bpos>::bit_not();
108 }
109
110 private:
111 static constexpr addr_type input_data_register = addr_type(port + 0x00UL);
112 static constexpr addr_type output_data_register = addr_type(port + 0x04UL);
113 static constexpr addr_type port_direction_register = addr_type(port + 0x08UL);
114
115 static constexpr addr_type interrupt_mask_register = addr_type(port + 0x0CUL);
116 static constexpr addr_type interrupt_polarity_register = addr_type(port + 0x10UL);
117 static constexpr addr_type interrupt_edge_register = addr_type(port + 0x14UL);
118
119 };
120 }
121 }
122
123#endif // MCAL_PORT_2018_01_10_H_
static void set_direction_output()
Definition mcal_port.h:27
static void set_pin_high()
Definition mcal_port.h:74
static bool read_input_value()
Definition mcal_port.h:92
static void set_pin_low()
Definition mcal_port.h:83
static void set_direction_input()
Definition mcal_port.h:50
static void toggle_pin()
Definition mcal_port.h:101
void init(const config_type *)
Definition mcal_port.cpp:11
void config_type
Definition mcal_port.h:17