28#ifndef CMSIS_PLUS_POSIX_DRIVER_DEVICE_SERIAL_BUFFERED_H_
29#define CMSIS_PLUS_POSIX_DRIVER_DEVICE_SERIAL_BUFFERED_H_
31#if defined(__cplusplus)
37#include <cmsis-plus/posix-io/device-char.h>
54#pragma GCC diagnostic push
55#pragma GCC diagnostic ignored "-Wpadded"
131 do_vopen (
const char* path,
int oflag, std::va_list args)
override;
137 do_read (
void* buf, std::size_t nbyte)
override;
140 do_write (
const void* buf, std::size_t nbyte)
override;
144 do_writev (
const struct iovec* iov,
int iovcnt)
override;
147 do_vioctl (
int request, std::va_list args)
override;
150 do_vfcntl (
int cmd, va_list args)
override;
183 std::size_t rx_count_ = 0;
184 bool volatile tx_busy_ =
false;
185 bool volatile is_connected_ =
false;
186 bool volatile is_opened_ =
false;
195#pragma GCC diagnostic pop
208 template<
typename CS>
210 const char* device_name,
214 device_char (device_name),
219 trace::printf (
"%s(\"%s\",%p,%p,%p) %p\n", __func__, device_name,
220 driver, rx_buf, tx_buf,
this);
222 assert (rx_buf !=
nullptr);
226 driver_->register_callback (
230 template<
typename CS>
236 is_connected_ =
false;
242#pragma GCC diagnostic push
243#pragma GCC diagnostic ignored "-Wunused-parameter"
245 template<
typename CS>
271 if (tx_buf_ !=
nullptr)
278 result = driver_->configure (
309 capa = driver_->get_capabilities ();
319 status = driver_->get_modem_status ();
331 std::size_t nbyte = rx_buf_->back_contiguous_buffer (&pbuf);
333 result = driver_->receive (pbuf, nbyte);
340 is_connected_ =
true;
346 template<
typename CS>
353 template<
typename CS>
357 return is_connected_;
360 template<
typename CS>
369 if (tx_buf_ !=
nullptr)
373 if (tx_buf_->empty ())
401 is_connected_ =
false;
407 template<
typename CS>
420 count = rx_buf_->pop_front (
static_cast<uint8_t*
> (buf), nbyte);
438 template<
typename CS>
444 if (tx_buf_ !=
nullptr)
451 if (tx_buf_->below_high_water_mark ())
454 count = tx_buf_->push_back (
455 static_cast<const uint8_t*
> (buf), nbyte);
466#pragma GCC diagnostic push
467#pragma GCC diagnostic ignored "-Waggregate-return"
468 status = driver_->get_status ();
469#pragma GCC diagnostic pop
481 nb = tx_buf_->front_contiguous_buffer (&pbuf);
526 n = tx_buf_->push_back (
527 static_cast<const uint8_t*
> (buf) + count,
547 status = driver_->get_status ();
565 status = driver_->get_status ();
572 count = driver_->get_tx_count ();
586 template<
typename CS>
594 template<
typename CS>
596 device_serial_buffered<CS>::do_vioctl (
int request, std::va_list args)
602 template<
typename CS>
604 device_serial_buffered<CS>::do_vfcntl (
int cmd, std::va_list args)
613 template<
typename CS>
618 if (!object->is_opened_)
629 std::size_t tmpCount =
object->driver_->get_rx_count ();
630 std::size_t count = tmpCount -
object->rx_count_;
631 object->rx_count_ = tmpCount;
632 std::size_t adjust =
object->rx_buf_->advance_back (count);
633 assert (count == adjust);
638 std::size_t nbyte =
object->rx_buf_->back_contiguous_buffer (
644 object->rx_buf_->retreat_back ();
645 nbyte =
object->rx_buf_->back_contiguous_buffer (&pbuf);
651 status =
object->driver_->receive (pbuf, nbyte);
655 object->rx_count_ = 0;
660 object->rx_sem_.post ();
665 if (object->tx_buf_ !=
nullptr)
667 std::size_t count =
object->driver_->get_tx_count ();
668 std::size_t adjust =
object->tx_buf_->advance_front (count);
669 assert (count == adjust);
672 std::size_t nbyte =
object->tx_buf_->front_contiguous_buffer (
677 status =
object->driver_->send (pbuf, nbyte);
683 object->tx_busy_ =
false;
685 if (object->tx_buf_->below_low_water_mark ())
688 object->tx_sem_.post ();
694 object->tx_sem_.post ();
700 status =
object->driver_->get_modem_status ();
703 object->is_connected_ = is_dcd_active;
707 object->open_sem_.post ();
712 object->rx_sem_.post ();
715 object->tx_sem_.post ();
728#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.