From c3767ac0c6bcb9a1aed1e7b666061f829a371e1f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 4 May 2018 00:16:36 +0200 Subject: Start own HAL implementation based on MCC's generated files Other changes: - Undo conversion of MCC files to C++ - Delete old Led implementation --- hal/uart.hpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 hal/uart.hpp (limited to 'hal/uart.hpp') diff --git a/hal/uart.hpp b/hal/uart.hpp new file mode 100644 index 0000000..179dd4a --- /dev/null +++ b/hal/uart.hpp @@ -0,0 +1,87 @@ +/* + * File: uart.hpp + * Author: naopross + * + * Created on May 2, 2018, 7:04 PM + */ + +#ifndef UART_HPP +#define UART_HPP + +#include +#include +#include + +extern "C" { +void usart_1_isr(); +void usart_2_isr(); +void usart_3_isr(); +void usart_4_isr(); +} + +namespace uart +{ + const unsigned devices_count = 4; + + enum class status : unsigned int + { + rx_data_available = 1<<0, + rx_overrun_error = 1<<1, + framing_error = 1<<2, + parity_error = 1<<3, + receiver_ide = 1<<4, + tx_complete = 1<<8, + tx_full = 1<<9, + }; + + enum class transfer_status : unsigned int + { + rx_full = 1<<0, + rx_data_present = 1<<1, + rx_empty = 1<<2, + tx_full = 1<<3, + tx_empty = 1<<4, + }; + + std::string rx_buffer[devices_count]; + std::string tx_buffer[devices_count]; + + template + void initialize(); + + template + uint8_t peek(uint16_t offset); + + template + uint8_t read(void); + + template + unsigned read(uint8_t *buffer, const unsigned numbytes); + + template + void write(const uint8_t byte); + + template + unsigned write(const uint8_t *buffer, const unsigned numbytes); + + template + status status(); + + template + transfer_status tranfer_status(); + + template + unsigned rx_buffer_size(); + + template + unsigned tx_buffer_size(); + + template + bool rx_buffer_empty(); + + template + bool tx_buffer_full(); +} + +#endif /* UART_HPP */ + -- cgit v1.2.1