13#ifndef CMSIS_PLUS_POSIX_DRIVER_DEVICE_SERIAL_BUFFERED_H_
14#define CMSIS_PLUS_POSIX_DRIVER_DEVICE_SERIAL_BUFFERED_H_
16#if defined(__cplusplus)
22#include <cmsis-plus/posix-io/device-char.h>
39#pragma GCC diagnostic push
41#pragma clang diagnostic ignored "-Wpadded"
42#elif defined(__GNUC__)
43#pragma GCC diagnostic ignored "-Wpadded"
120 do_vopen (
const char* path,
int oflag, std::va_list args)
override;
126 do_read (
void* buf, std::size_t nbyte)
override;
129 do_write (
const void* buf, std::size_t nbyte)
override;
133 do_writev (
const struct iovec* iov,
int iovcnt)
override;
136 do_vioctl (
int request, std::va_list args)
override;
139 do_vfcntl (
int cmd, va_list args)
override;
172 std::size_t rx_count_ = 0;
173 bool volatile tx_busy_ =
false;
174 bool volatile is_connected_ =
false;
175 bool volatile is_opened_ =
false;
184#pragma GCC diagnostic pop
197 template<
typename CS>
199 const char* device_name,
203 device_char (device_name),
208 trace::printf (
"%s(\"%s\",%p,%p,%p) %p\n", __func__, device_name,
209 driver, rx_buf, tx_buf,
this);
211 assert (rx_buf !=
nullptr);
215 driver_->register_callback (
219 template<
typename CS>
225 is_connected_ =
false;
231#pragma GCC diagnostic push
232#if defined(__clang__)
233#elif defined(__GNUC__)
234#pragma GCC diagnostic ignored "-Wunused-parameter"
237 template<
typename CS>
263 if (tx_buf_ !=
nullptr)
270 result = driver_->configure (
301 capa = driver_->get_capabilities ();
311 status = driver_->get_modem_status ();
323 std::size_t nbyte = rx_buf_->back_contiguous_buffer (&pbuf);
325 result = driver_->receive (pbuf, nbyte);
332 is_connected_ =
true;
338 template<
typename CS>
345 template<
typename CS>
349 return is_connected_;
352 template<
typename CS>
361 if (tx_buf_ !=
nullptr)
365 if (tx_buf_->empty ())
393 is_connected_ =
false;
399 template<
typename CS>
412 count = rx_buf_->pop_front (
static_cast<uint8_t*
> (buf), nbyte);
430 template<
typename CS>
436 if (tx_buf_ !=
nullptr)
443 if (tx_buf_->below_high_water_mark ())
446 count = tx_buf_->push_back (
447 static_cast<const uint8_t*
> (buf), nbyte);
458#pragma GCC diagnostic push
459#if defined(__clang__)
460#elif defined(__GNUC__)
461#pragma GCC diagnostic ignored "-Waggregate-return"
463 status = driver_->get_status ();
464#pragma GCC diagnostic pop
476 nb = tx_buf_->front_contiguous_buffer (&pbuf);
521 n = tx_buf_->push_back (
522 static_cast<const uint8_t*
> (buf) + count,
542 status = driver_->get_status ();
560 status = driver_->get_status ();
567 count = driver_->get_tx_count ();
581 template<
typename CS>
589 template<
typename CS>
591 device_serial_buffered<CS>::do_vioctl (
int request, std::va_list args)
597 template<
typename CS>
599 device_serial_buffered<CS>::do_vfcntl (
int cmd, std::va_list args)
608 template<
typename CS>
613 if (!object->is_opened_)
624 std::size_t tmpCount =
object->driver_->get_rx_count ();
625 std::size_t count = tmpCount -
object->rx_count_;
626 object->rx_count_ = tmpCount;
627 std::size_t adjust =
object->rx_buf_->advance_back (count);
628 assert (count == adjust);
633 std::size_t nbyte =
object->rx_buf_->back_contiguous_buffer (
639 object->rx_buf_->retreat_back ();
640 nbyte =
object->rx_buf_->back_contiguous_buffer (&pbuf);
646 status =
object->driver_->receive (pbuf, nbyte);
650 object->rx_count_ = 0;
655 object->rx_sem_.post ();
660 if (object->tx_buf_ !=
nullptr)
662 std::size_t count =
object->driver_->get_tx_count ();
663 std::size_t adjust =
object->tx_buf_->advance_front (count);
664 assert (count == adjust);
667 std::size_t nbyte =
object->tx_buf_->front_contiguous_buffer (
672 status =
object->driver_->send (pbuf, nbyte);
678 object->tx_busy_ =
false;
680 if (object->tx_buf_->below_low_water_mark ())
683 object->tx_sem_.post ();
689 object->tx_sem_.post ();
695 status =
object->driver_->get_modem_status ();
698 object->is_connected_ = is_dcd_active;
702 object->open_sem_.post ();
707 object->rx_sem_.post ();
710 object->tx_sem_.post ();
723#pragma GCC diagnostic pop
Serial device driver capabilities.
bool dcd
RI Line: false=not available, true=available.
bool tx_busy
< Transmitter busy flag
Circular buffer class template.
Buffered serial driver class template.
static void signal_event(device_serial_buffered *object, uint32_t event)
virtual ssize_t do_read(void *buf, std::size_t nbyte) override
virtual int do_close(void) override
virtual bool do_is_connected(void) override
virtual ~device_serial_buffered()
device_serial_buffered(const char *device_name, os::driver::Serial *driver, os::posix::circular_buffer_bytes *rx_buf, os::posix::circular_buffer_bytes *tx_buf)
virtual bool do_is_opened(void) override
virtual int do_vopen(const char *path, int oflag, std::va_list args) override
virtual ssize_t do_write(const void *buf, std::size_t nbyte) override
POSIX compliant binary semaphore.
int printf(const char *format,...)
Write a formatted string to the trace device.
constexpr config_t PARITY_NONE
Even Parity.
constexpr config_t DATA_BITS_8
9 Data bits
constexpr config_t STOP_BITS_1
2 Stop bits
constexpr config_t MODE_ASYNCHRONOUS
< UART = (Asynchronous);; arg = Baudrate
constexpr config_t FLOW_CONTROL_NONE
RTS Flow Control.
@ abort_receive
Abort Serial::transfer()
@ abort_send
Abort Serial::receive()
@ disable_tx
Disable Receiver.
@ enable_tx
Enable Transmitter.
@ enable_rx
Enable Continuous Break transmission.
@ disable_rx
Disable Continuous Break transmission;.
@ cts
DSR state changed (optional)
@ rx_framing_error
Parity error detected on receive.
@ dsr
DCD state changed (optional)
@ dcd
RI state changed (optional)
@ rx_timeout
Break detected on receive.
@ receive_complete
Transfer completed.
@ tx_complete
Transmit data not available (Synchronous Slave)
constexpr return_t RETURN_OK
< Operation succeeded
void(* signal_event_t)(const void *object, event_t event)
Single file µOS++ RTOS definitions.