From 6212b63ac63d3de2bc8c5c5332add085fb16b551 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 23 Dec 2012 15:20:24 +0100 Subject: digital/ucoolib/ucoolib/hal/uart: implement uart module --- digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh') diff --git a/digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh b/digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh index d10d12d8..e807e9e9 100644 --- a/digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh +++ b/digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh @@ -24,28 +24,49 @@ // // }}} #include "ucoolib/intf/stream.hh" +#include "ucoolib/utils/fifo.hh" + +#include "config/hal/uart.hh" namespace ucoo { /// Universal asynchronous receiver transmitter (UART). +/// +/// When an error is detected on RX, error character is inserted in receive +/// FIFO. class Uart : public Stream { public: /// Parity setting. enum Parity { ODD, EVEN, NONE }; + /// Default error character. + static const char default_error_char = '~'; public: /// Initialise the Nth UART with given parameters. - Uart (int n, int speed, Parity parity, int stop_bits); + Uart (int n, int speed = 0, Parity parity = NONE, int stop_bits = 1); /// Shutdown UART. ~Uart (); - /// Change UART settings. - void setup (int speed, Parity parity, int stop_bits); + /// Change UART settings, use speed 0 to stop UART. + void setup (int speed, Parity parity = NONE, int stop_bits = 1); + /// Change the error character. + void set_error_char (char c); /// See Stream::read. int read (char *buf, int count); /// See Stream::write. int write (const char *buf, int count); /// See Stream::poll. int poll (); + /// Handle interrupts. + static void isr (int n); + private: + /// UART number. + int n_; + /// RX FIFO, filled by interrupt handler. + Fifo rx_fifo_; + /// TX FIFO, emptied by interrupt handler. + Fifo tx_fifo_; + /// Error character, inserted in case of error. + char error_char_; }; } // namespace ucoo -- cgit v1.2.3