GR712RC unit tests 1.0
Bare-metal C++ hardware tests for the PLATO DPU (IAA-CSIC, 2019)
Loading...
Searching...
No Matches
mcal_uart.h
Go to the documentation of this file.
1
11
12#ifndef _MCAL_UART_GR712_EMBEDDED_2018_
13#define _MCAL_UART_GR712_EMBEDDED_2018_
14
15
16#include <cstdint>
17#include <mcal_cpu.h>
18#include <mcal_reg_access.h>
19#include <algorithm>
20
21
22//extern "C" void __vector_uart1_rx_tx_handler() __attribute__((used, noinline));
23
24namespace mcal
25{
26 namespace uart
27 {
28 typedef void config_type;
29
30 void init(const config_type*);
31
32 template <typename port_type,// std::uint32_t
33 typename bval_type,// std::uint8_t
34 port_type port>
36 {
37 public:
38 typedef std::uint32_t addr_type;
39 typedef std::uint32_t reg_type;
40
41 uart_communication() : send_is_active(false)
42 {
43
44 // Set baudrate: Scaler_Reload_value (12bit) = fpck/(8*baud_rate) -1 => 650 = 0x28A
47 baud_rate_gen_register,
48 static_cast<std::uint32_t>(UINT32_C(0x0000028A))>::reg_set();
49
50 // Enable Rx and Tx
51 // Transmision 8n1: 8bit, No parity, 1StopBit
54 uart_ctrl_register,
55 static_cast<std::uint32_t>(UINT32_C(0x00000003))>::reg_set();
56
57 // Set interrupts
58 /*
59 mcal::reg::access<addr_type,
60 reg_type,
61 interrupt_enable_register,
62 static_cast<std::uint32_t>(UINT32_C(0x00000000))>::reg_or();
63 */
64 }
65
66 bool send(const bval_type byte_to_send)
67 {
68
69 if ( send_is_active )
70 {
71 return false;
72 }
73 else{
74 send_is_active = true;
76 reg_type>::reg_set(output_data_register, static_cast<bval_type>(byte_to_send));
77 send_is_active = false;
78 }
79 return true;
80 }
81
82 template<typename send_iterator_type>
83 bool send_n(send_iterator_type first,
84 send_iterator_type last)
85 {
86 bool send_result = true;
87
88 while(first != last)
89 {
90 typedef typename
91 std::iterator_traits<send_iterator_type>::value_type
92 send_value_type;
93
94 const send_value_type value(*first);
95
96 send_result &= send(std::uint8_t(value));
97
98 for (int i=0; i < 1000; ++i)
99 for (int j=0; j< 100; ++j)
100 {
102 }
103
104 ++first;
105 }
106
107 return send_result;
108 }
109
110 bool recv(bval_type &byte_to_recv)
111 {
112 byte_to_recv = mcal::reg::access<addr_type,
113 reg_type,
114 input_data_register>::reg_get();
115
116 return true;
117 }
118
119 //Checks if there is data to receive.
121 {
123 reg_type,
124 uart_status_register>::reg_get();
125 return (uart_status & (0x1 << 0));
126 }
127
128 private:
129 volatile bool send_is_active;
130
131 static constexpr addr_type uart_ctrl_register = addr_type(port + 0x08UL);
132 static constexpr addr_type uart_status_register = addr_type(port + 0x04UL);
133 static constexpr addr_type baud_rate_gen_register = addr_type(port + 0x0CUL);
134
135 static constexpr addr_type output_data_register = addr_type(port + 0x00UL);
136 static constexpr addr_type input_data_register = addr_type(port + 0x00UL);
137
138 static constexpr addr_type uart_fifo_register = addr_type(port + 0x10UL);
139
140 // friend void __vector_uart1_rx_tx_irq();
141
142 };
143
144}
145
146}
147
148#endif //_MCAL_UART_GR712_EMBEDDED_2018_
bool send_n(send_iterator_type first, send_iterator_type last)
Definition mcal_uart.h:83
bool recv(bval_type &byte_to_recv)
Definition mcal_uart.h:110
bool send(const bval_type byte_to_send)
Definition mcal_uart.h:66
Microcontroller abstraction layer for SAM4S ARM Cortex M CPU.
void nop()
Definition mcal_cpu.h:24
void config_type
Definition mcal_uart.h:28
void init(const config_type *)
Definition mcal_uart.cpp:16