|
constexpr | SerialPort (UartLowLevel &uart, void *const readBuffer, const size_t readBufferSize, void *const writeBuffer, const size_t writeBufferSize) |
| SerialPort's constructor. More...
|
|
| ~SerialPort () override |
| SerialPort's destructor. More...
|
|
int | close () |
| Closes SerialPort. More...
|
|
int | open (uint32_t baudRate, uint8_t characterLength, UartParity parity, bool _2StopBits) |
| Opens SerialPort. More...
|
|
std::pair< int, size_t > | read (void *buffer, size_t size, size_t minSize=1, const TickClock::time_point *timePoint=nullptr) |
| Reads data from SerialPort. More...
|
|
std::pair< int, size_t > | tryReadFor (const TickClock::duration duration, void *const buffer, const size_t size, const size_t minSize=1) |
| Wrapper for read() with relative timeout. More...
|
|
template<typename Rep , typename Period > |
std::pair< int, size_t > | tryReadFor (const std::chrono::duration< Rep, Period > duration, void *const buffer, const size_t size, const size_t minSize=1) |
| Wrapper for read() with relative timeout. More...
|
|
std::pair< int, size_t > | tryReadUntil (const TickClock::time_point timePoint, void *const buffer, const size_t size, const size_t minSize=1) |
| Wrapper for read() with absolute timeout. More...
|
|
template<typename Duration > |
std::pair< int, size_t > | tryReadUntil (const std::chrono::time_point< TickClock, Duration > timePoint, void *const buffer, const size_t size, const size_t minSize=1) |
| Wrapper for read() with absolute timeout. More...
|
|
std::pair< int, size_t > | tryWriteFor (const TickClock::duration duration, const void *const buffer, const size_t size, const size_t minSize=SIZE_MAX) |
| Wrapper for write() with relative timeout. More...
|
|
template<typename Rep , typename Period > |
std::pair< int, size_t > | tryWriteFor (const std::chrono::duration< Rep, Period > duration, const void *const buffer, const size_t size, const size_t minSize=SIZE_MAX) |
| Wrapper for write() with relative timeout. More...
|
|
std::pair< int, size_t > | tryWriteUntil (const TickClock::time_point timePoint, const void *const buffer, const size_t size, const size_t minSize=SIZE_MAX) |
| Wrapper for write() with absolute timeout. More...
|
|
template<typename Duration > |
std::pair< int, size_t > | tryWriteUntil (const std::chrono::time_point< TickClock, Duration > timePoint, const void *const buffer, const size_t size, const size_t minSize=SIZE_MAX) |
| Wrapper for write() with absolute timeout. More...
|
|
std::pair< int, size_t > | write (const void *buffer, size_t size, size_t minSize=SIZE_MAX, const TickClock::time_point *timePoint=nullptr) |
| Writes data to SerialPort. More...
|
|
|
Mutex | readMutex_ |
| mutex used to serialize access to read(), close() and open() More...
|
|
Mutex | writeMutex_ |
| mutex used to serialize access to write(), close() and open() More...
|
|
CircularBuffer | readBuffer_ |
| internal instance of circular buffer for read operations More...
|
|
CircularBuffer | writeBuffer_ |
| internal instance of circular buffer for write operations More...
|
|
CircularBuffer *volatile | currentReadBuffer_ |
| pointer to current circular buffer for read operations, always valid More...
|
|
CircularBuffer *volatile | currentWriteBuffer_ |
| pointer to current circular buffer for write operations, always valid More...
|
|
CircularBuffer *volatile | nextReadBuffer_ |
| pointer to next circular buffer for read operations, used when currentReadBuffer_ becomes full More...
|
|
CircularBuffer *volatile | nextWriteBuffer_ |
| pointer to next circular buffer for write operations, used when currentWriteBuffer_ becomes empty More...
|
|
Semaphore *volatile | readSemaphore_ |
| pointer to semaphore used for "read complete" event notifications More...
|
|
Semaphore *volatile | transmitSemaphore_ |
| pointer to semaphore used for "transmit complete" event notifications More...
|
|
Semaphore *volatile | writeSemaphore_ |
| pointer to semaphore used for "write complete" event notifications More...
|
|
volatile size_t | readLimit_ |
| size limit of read operations, 0 if no limiting is needed, bytes More...
|
|
volatile size_t | writeLimit_ |
| size limit of write operations, 0 if no limiting is needed, bytes More...
|
|
UartLowLevel & | uart_ |
| reference to low-level implementation of UartLowLevel interface More...
|
|
uint32_t | baudRate_ |
| current baud rate, bps More...
|
|
uint8_t | characterLength_ |
| current character length, bits More...
|
|
UartParity | parity_ |
| current parity More...
|
|
bool | _2StopBits_ |
| current configuration of stop bits: 1 (false) or 2 (true) More...
|
|
uint8_t | openCount_ |
| number of times this device was opened but not yet closed More...
|
|
volatile bool | readInProgress_ |
| "read in progress" flag More...
|
|
volatile bool | transmitInProgress_ |
| "transmit in progress" flag More...
|
|
volatile bool | writeInProgress_ |
| "write in progress" flag More...
|
|
SerialPort class is a serial port with an interface similar to standard files
template<typename Rep , typename Period >
std::pair<int, size_t> distortos::devices::SerialPort::tryReadFor |
( |
const std::chrono::duration< Rep, Period > |
duration, |
|
|
void *const |
buffer, |
|
|
const size_t |
size, |
|
|
const size_t |
minSize = 1 |
|
) |
| |
|
inline |
Wrapper for read() with relative timeout.
Templated variant of tryReadFor(TickClock::duration, void*, size_t, size_t)
- Warning
- This function must not be called from interrupt context!
- Template Parameters
-
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
- Parameters
-
[in] | duration | is the duration after which the wait will be terminated without reading minSize |
[out] | buffer | is the buffer to which the data will be written |
[in] | size | is the size of buffer, bytes, must be even if selected character length is greater than 8 bits |
[in] | minSize | is the minimum size of read, bytes, default - 1 |
- Returns
- pair with return code (0 on success, error code otherwise) and number of read bytes (valid even when error code is returned); error codes:
- EAGAIN - no data can be read without blocking and non-blocking operation was requested (minSize is 0);
- EBADF - the device is not opened;
- EINTR - the wait was interrupted by an unmasked, caught signal;
- EINVAL - buffer and/or size are invalid;
- ETIMEDOUT - required amount of data could not be read before the specified timeout expired;
- error codes returned by UartLowLevel::startRead();
template<typename Rep , typename Period >
std::pair<int, size_t> distortos::devices::SerialPort::tryWriteFor |
( |
const std::chrono::duration< Rep, Period > |
duration, |
|
|
const void *const |
buffer, |
|
|
const size_t |
size, |
|
|
const size_t |
minSize = SIZE_MAX |
|
) |
| |
|
inline |
Wrapper for write() with relative timeout.
Template variant of tryWriteFor(TickClock::duration, const void*, size_t, size_t)
- Warning
- This function must not be called from interrupt context!
- Template Parameters
-
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
- Parameters
-
[in] | duration | is the duration after which the wait will be terminated without writing minSize |
[in] | buffer | is the buffer with data that will be transmitted |
[in] | size | is the size of buffer, bytes, must be even if selected character length is greater than 8 bits |
[in] | minSize | is the minimum size of write, bytes, default - SIZE_MAX |
- Returns
- pair with return code (0 on success, error code otherwise) and number of written bytes (valid even when error code is returned); error codes:
- EAGAIN - no data can be written without blocking and non-blocking operation was requested (minSize is 0);
- EBADF - the device is not opened;
- EINTR - the wait was interrupted by an unmasked, caught signal;
- EINVAL - buffer and/or size are invalid;
- ETIMEDOUT - required amount of data could not be written before the specified timeout expired;
- error codes returned by UartLowLevel::startWrite();
std::pair< int, size_t > distortos::devices::SerialPort::write |
( |
const void * |
buffer, |
|
|
size_t |
size, |
|
|
size_t |
minSize = SIZE_MAX , |
|
|
const TickClock::time_point * |
timePoint = nullptr |
|
) |
| |
Writes data to SerialPort.
Similar to POSIX write() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html#
This function will block until at least minSize bytes can be written (but no more than size). When minSize is greater than or equal to size - for example SIZE_MAX, which is the default value - the behavior of this function is similar to POSIX write() with O_NONBLOCK flag cleared. If minSize is 0, then the function will not block at all and only writes up to buffer's available free space - in this case it is similar to POSIX write() with O_NONBLOCK flag set.
- Warning
- This function must not be called from interrupt context!
- Parameters
-
[in] | buffer | is the buffer with data that will be transmitted |
[in] | size | is the size of buffer, bytes, must be even if selected character length is greater than 8 bits |
[in] | minSize | is the minimum size of write, bytes, default - SIZE_MAX |
[in] | timePoint | is a pointer to the time point at which the wait will be terminated without writing minSize, nullptr to wait indefinitely, default - nullptr |
- Returns
- pair with return code (0 on success, error code otherwise) and number of written bytes (valid even when error code is returned); error codes:
- EAGAIN - no data can be written without blocking and non-blocking operation was requested (minSize is 0);
- EBADF - the device is not opened;
- EINTR - the wait was interrupted by an unmasked, caught signal;
- EINVAL - buffer and/or size are invalid;
- ETIMEDOUT - required amount of data could not be written before the specified timeout expired;
- error codes returned by UartLowLevel::startWrite();