Serial driver interface.
More...
#include </home/travis/build/forGGe/theCore/dev/bus/export/dev/serial.hpp>
template<class PBus, size_t buf_size = 128>
class ecl::serial< PBus, buf_size >
Serial driver interface.
The serial allows to abstract async, interrupt-driven nature of platform-level drivers and provide synchronus, buffered data management interface.
- Template Parameters
-
PBus | Exclusively owned platform bus. |
buf_size | Size of internal rx and tx buffers. |
◆ platform_handle
template<class PBus , size_t buf_size = 128>
◆ serial() [1/3]
template<class PBus , size_t buf_size = 128>
◆ serial() [2/3]
template<class PBus , size_t buf_size = 128>
◆ serial() [3/3]
template<class PBus , size_t buf_size = 128>
◆ ~serial()
template<class PBus , size_t buf_size = 128>
◆ init()
template<class PBus , size_t buf_size>
Initialize serial driver and underlying platform bus.
- Precondition
- Driver is not initialized.
- Returns
- Operation status.
◆ deinit()
template<class PBus , size_t buf_size>
Deinitialize serial driver and underlying platform bus.
- Precondition
- Driver is initialized.
- Returns
- Operation status.
◆ nonblock()
template<class PBus , size_t buf_size>
Sets or clears non-block mode of operation.
- Precondition
- Driver is initialized.
Setting nonblock mode will prevent recv and send functions from blocking. Special error code will be returned to notify user about possible blocking.
- Parameters
-
[in] | state | 'true' to enable non-blocking mode. |
- Return values
-
◆ recv_byte()
template<class PBus , size_t buf_size>
Obtains a byte from serial device.
- Precondition
- Driver is initialized.
If there is no data to return call with block in blocking mode, and return immediately in non-blocking mode. Otherwise data will be stored in the given argument and method will return.
- Parameters
-
[out] | byte | Place for incoming byte. Will remain unchanged if error occurs. |
- Returns
- Operation status.
- Return values
-
◆ recv_buf()
template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::recv_buf |
( |
uint8_t * |
buf, |
|
|
size_t & |
sz |
|
) |
| |
|
static |
Gets buffer from serial device.
- Precondition
- Driver is initialized.
Call will block if there is no data to return in blocking mode. In non-blocking mode special code is returned. Otherwise, buffer will be populated with avaliable data and method will return.
- Parameters
-
[out] | buf | Buffer to fill with data. |
[in,out] | sz | Size of buffer. Will be updated with amount of bytes written to the buffer. In case of error, size will be updated with bytes successfully stored in the buffer before error occurred. |
- Returns
- Operation status.
- Return values
-
◆ send_byte()
template<class PBus , size_t buf_size>
Sends byte to a serial device.
- Precondition
- Driver is initialized.
It may not block if internal buffering is applied. It may also block if platform device is not yet ready to send data. In non-blocking mode special code is returned instead of blocking.
- Parameters
-
- Returns
- Operation status.
- Return values
-
◆ send_buf()
template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::send_buf |
( |
const uint8_t * |
buf, |
|
|
size_t & |
sz |
|
) |
| |
|
static |
Sends buffer to a serial stream.
- Precondition
- Driver is initialized.
It may not block if internal buffering is applied. It may also block if platform device is not yet ready to send data. In non-blocking mode special code is returned instead of blocking.
- Parameters
-
[in] | buf | Buffer to send. |
[in,out] | sz | Size of buffer. Will be updated with amount of bytes sent In case of error, size will be updated with amount of bytes successfully sent before error occur. |
- Returns
- Operation status.
- Return values
-
err:again | The buffer was not consumed entirely. |
err::wouldblock | Non-blocking mode is set and send would block otherwise. |
◆ buffer_size
template<class PBus , size_t buf_size = 128>
constexpr auto ecl::serial< PBus, buf_size >::buffer_size = buf_size |
|
static |
The documentation for this class was generated from the following file: