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