summaryrefslogtreecommitdiff
path: root/digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh
diff options
context:
space:
mode:
Diffstat (limited to 'digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh')
-rw-r--r--digital/ucoolib/ucoolib/hal/uart/uart.stm32.hh27
1 files changed, 24 insertions, 3 deletions
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<char, UCOO_CONFIG_HAL_UART_RX_BUFFER> rx_fifo_;
+ /// TX FIFO, emptied by interrupt handler.
+ Fifo<char, UCOO_CONFIG_HAL_UART_TX_BUFFER> tx_fifo_;
+ /// Error character, inserted in case of error.
+ char error_char_;
};
} // namespace ucoo