42#define HF_UART_ERR_LIST(X) \
44 X(UART_SUCCESS, 0, "Success") \
46 X(UART_ERR_FAILURE, 1, "General failure") \
47 X(UART_ERR_NOT_INITIALIZED, 2, "Not initialized") \
48 X(UART_ERR_ALREADY_INITIALIZED, 3, "Already initialized") \
49 X(UART_ERR_INVALID_PARAMETER, 4, "Invalid parameter") \
50 X(UART_ERR_NULL_POINTER, 5, "Null pointer") \
51 X(UART_ERR_OUT_OF_MEMORY, 6, "Out of memory") \
53 X(UART_ERR_TIMEOUT, 7, "Operation timeout") \
54 X(UART_ERR_BUFFER_FULL, 8, "Buffer full") \
55 X(UART_ERR_BUFFER_EMPTY, 9, "Buffer empty") \
56 X(UART_ERR_TRANSMISSION_FAILED, 10, "Transmission failed") \
57 X(UART_ERR_RECEPTION_FAILED, 11, "Reception failed") \
59 X(UART_ERR_FRAME_ERROR, 12, "Frame error") \
60 X(UART_ERR_PARITY_ERROR, 13, "Parity error") \
61 X(UART_ERR_OVERRUN_ERROR, 14, "Overrun error") \
62 X(UART_ERR_NOISE_ERROR, 15, "Noise error") \
63 X(UART_ERR_BREAK_DETECTED, 16, "Break condition detected") \
65 X(UART_ERR_HARDWARE_FAULT, 17, "Hardware fault") \
66 X(UART_ERR_COMMUNICATION_FAILURE, 18, "Communication failure") \
67 X(UART_ERR_DEVICE_NOT_RESPONDING, 19, "Device not responding") \
68 X(UART_ERR_VOLTAGE_OUT_OF_RANGE, 20, "Voltage out of range") \
70 X(UART_ERR_INVALID_CONFIGURATION, 21, "Invalid configuration") \
71 X(UART_ERR_UNSUPPORTED_OPERATION, 22, "Unsupported operation") \
72 X(UART_ERR_INVALID_BAUD_RATE, 23, "Invalid baud rate") \
73 X(UART_ERR_INVALID_DATA_BITS, 24, "Invalid data bits") \
74 X(UART_ERR_INVALID_PARITY, 25, "Invalid parity") \
75 X(UART_ERR_INVALID_STOP_BITS, 26, "Invalid stop bits") \
76 X(UART_ERR_PIN_CONFIGURATION_ERROR, 27, "Pin configuration error") \
77 X(UART_ERR_FLOW_CONTROL_ERROR, 28, "Flow control error") \
79 X(UART_ERR_SYSTEM_ERROR, 29, "System error") \
80 X(UART_ERR_PERMISSION_DENIED, 30, "Permission denied") \
81 X(UART_ERR_OPERATION_ABORTED, 31, "Operation aborted") \
82 X(UART_ERR_UNKNOWN, 32, "Unknown error")
85#define X(NAME, VALUE, DESC) NAME = VALUE,
97#define X(NAME, VALUE, DESC) \
98 case hf_uart_err_t::NAME: \
266 hf_u32_t timeout_ms = 0) noexcept = 0;
301 virtual
int Printf(const
char* format, ...) noexcept = 0;
hf_uart_err_t
Definition BaseUart.h:84
@ UART_ERR_UNSUPPORTED_OPERATION
#define X(NAME, VALUE, DESC)
Definition BaseUart.h:85
constexpr std::string_view HfUartErrToString(hf_uart_err_t err) noexcept
Convert hf_uart_err_t to human-readable string.
Definition BaseUart.h:95
Platform-agnostic hardware type definitions for the HardFOC system.
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
hf_u32_t hf_port_num_t
Platform-agnostic port/controller identifier type.
Definition HardwareTypes.h:120
uint64_t hf_u64_t
Platform-agnostic 64-bit unsigned integer type.
Definition HardwareTypes.h:58
uint16_t hf_u16_t
Platform-agnostic 16-bit unsigned integer type.
Definition HardwareTypes.h:46
Abstract base class for UART driver implementations.
Definition BaseUart.h:191
bool EnsureDeinitialized() noexcept
Ensures that the UART is deinitialized (lazy deinitialization).
Definition BaseUart.h:219
virtual hf_uart_err_t FlushRx() noexcept=0
Flush the receive buffer.
hf_uart_statistics_t statistics_
UART operation statistics.
Definition BaseUart.h:404
bool EnsureInitialized() noexcept
Ensures that the UART is initialized (lazy initialization).
Definition BaseUart.h:208
virtual hf_uart_err_t Write(const hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept=0
Write data to the UART.
virtual hf_uart_err_t GetStatistics(hf_uart_statistics_t &statistics) const noexcept
Get UART operation statistics.
Definition BaseUart.h:379
virtual bool Deinitialize() noexcept=0
Deinitialize the UART driver.
virtual hf_uart_err_t GetDiagnostics(hf_uart_diagnostics_t &diagnostics) const noexcept
Get UART diagnostic information.
Definition BaseUart.h:389
virtual bool Open() noexcept
Open the UART (alias for Initialize).
Definition BaseUart.h:311
bool initialized_
Initialization status.
Definition BaseUart.h:403
virtual hf_u16_t BytesAvailable() noexcept=0
Get the number of bytes available to read.
virtual hf_uart_err_t FlushTx() noexcept=0
Flush the transmit buffer.
virtual bool WriteByte(hf_u8_t byte) noexcept
Write a single byte to the UART.
Definition BaseUart.h:344
virtual int Printf(const char *format,...) noexcept=0
Printf-style formatted output.
virtual hf_uart_err_t Read(hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept=0
Read data from the UART.
bool IsInitialized() const noexcept
Checks if the driver is initialized.
Definition BaseUart.h:230
virtual hf_uart_err_t ResetStatistics() noexcept
Reset UART operation statistics.
Definition BaseUart.h:359
virtual bool WriteString(const char *str) noexcept
Write a string to the UART.
Definition BaseUart.h:332
hf_port_num_t port_
UART port number.
Definition BaseUart.h:402
virtual hf_uart_err_t ResetDiagnostics() noexcept
Reset UART diagnostic information.
Definition BaseUart.h:369
hf_port_num_t GetPort() const noexcept
Get the UART port number.
Definition BaseUart.h:238
virtual bool Initialize() noexcept=0
Initialize the UART driver.
virtual ~BaseUart() noexcept=default
Virtual destructor ensures proper cleanup in derived classes.
virtual bool Close() noexcept
Close the UART (alias for Deinitialize).
Definition BaseUart.h:319
hf_uart_diagnostics_t diagnostics_
UART diagnostic information.
Definition BaseUart.h:405
BaseUart(hf_port_num_t port) noexcept
Protected constructor with port.
Definition BaseUart.h:399
#define HF_UART_ERR_LIST(X)
HardFOC UART error codes.
Definition BaseUart.h:42
UART diagnostic information.
Definition BaseUart.h:140
hf_u32_t rx_buffer_usage
RX buffer usage percentage.
Definition BaseUart.h:152
bool flow_control_active
Flow control status.
Definition BaseUart.h:148
hf_u64_t last_error_timestamp
Timestamp of last error (microseconds)
Definition BaseUart.h:144
hf_u32_t tx_buffer_usage
TX buffer usage percentage.
Definition BaseUart.h:151
bool is_initialized
Initialization status.
Definition BaseUart.h:145
hf_u32_t error_reset_count
Number of times error state was reset.
Definition BaseUart.h:143
hf_uart_diagnostics_t() noexcept
Definition BaseUart.h:155
hf_uart_err_t last_error
Last error that occurred.
Definition BaseUart.h:141
bool pattern_detection_active
Pattern detection status.
Definition BaseUart.h:149
hf_u32_t consecutive_errors
Number of consecutive errors.
Definition BaseUart.h:142
bool is_receiving
Reception status.
Definition BaseUart.h:147
bool wakeup_enabled
Wakeup status.
Definition BaseUart.h:150
hf_u32_t event_queue_usage
Event queue usage percentage.
Definition BaseUart.h:153
bool is_transmitting
Transmission status.
Definition BaseUart.h:146
UART operation statistics.
Definition BaseUart.h:114
hf_u32_t break_count
Break condition count.
Definition BaseUart.h:123
hf_u64_t last_activity_timestamp
Last activity timestamp (microseconds)
Definition BaseUart.h:127
hf_u32_t rx_byte_count
Total bytes received.
Definition BaseUart.h:116
hf_u64_t initialization_timestamp
Initialization timestamp (microseconds)
Definition BaseUart.h:128
hf_u32_t tx_error_count
Transmission error count.
Definition BaseUart.h:117
hf_u32_t timeout_count
Timeout occurrence count.
Definition BaseUart.h:124
hf_u32_t wakeup_count
Wakeup event count.
Definition BaseUart.h:126
hf_u32_t frame_error_count
Frame error count.
Definition BaseUart.h:119
hf_u32_t tx_byte_count
Total bytes transmitted.
Definition BaseUart.h:115
hf_u32_t rx_error_count
Reception error count.
Definition BaseUart.h:118
hf_u32_t parity_error_count
Parity error count.
Definition BaseUart.h:120
hf_u32_t pattern_detect_count
Pattern detection count.
Definition BaseUart.h:125
hf_u32_t noise_error_count
Noise error count.
Definition BaseUart.h:122
hf_uart_statistics_t() noexcept
Definition BaseUart.h:130
hf_u32_t overrun_error_count
Overrun error count.
Definition BaseUart.h:121