theCore C++ embedded framework
ecl::serial< PBus, buf_size > Class Template Reference

Serial driver interface. More...

#include </home/travis/build/forGGe/theCore/dev/bus/export/dev/serial.hpp>

Public Types

using platform_handle = PBus
 

Public Member Functions

 serial ()=delete
 
 serial (const serial &other)=delete
 
 serial (serial &&other)=delete
 
 ~serial ()=delete
 

Static Public Member Functions

static err init ()
 Initialize serial driver and underlying platform bus. More...
 
static err deinit ()
 Deinitialize serial driver and underlying platform bus. More...
 
static err nonblock (bool state=true)
 Sets or clears non-block mode of operation. More...
 
static err recv_byte (uint8_t &byte)
 Obtains a byte from serial device. More...
 
static err recv_buf (uint8_t *buf, size_t &sz)
 Gets buffer from serial device. More...
 
static err send_byte (uint8_t byte)
 Sends byte to a serial device. More...
 
static err send_buf (const uint8_t *buf, size_t &sz)
 Sends buffer to a serial stream. More...
 

Static Public Attributes

static constexpr auto buffer_size = buf_size
 

Detailed Description

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
PBusExclusively owned platform bus.
buf_sizeSize of internal rx and tx buffers.

Member Typedef Documentation

◆ platform_handle

template<class PBus , size_t buf_size = 128>
using ecl::serial< PBus, buf_size >::platform_handle = PBus

Constructor & Destructor Documentation

◆ serial() [1/3]

template<class PBus , size_t buf_size = 128>
ecl::serial< PBus, buf_size >::serial ( )
delete

◆ serial() [2/3]

template<class PBus , size_t buf_size = 128>
ecl::serial< PBus, buf_size >::serial ( const serial< PBus, buf_size > &  other)
delete

◆ serial() [3/3]

template<class PBus , size_t buf_size = 128>
ecl::serial< PBus, buf_size >::serial ( serial< PBus, buf_size > &&  other)
delete

◆ ~serial()

template<class PBus , size_t buf_size = 128>
ecl::serial< PBus, buf_size >::~serial ( )
delete

Member Function Documentation

◆ init()

template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::init ( )
static

Initialize serial driver and underlying platform bus.

Precondition
Driver is not initialized.
Returns
Operation status.
Here is the call graph for this function:

◆ deinit()

template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::deinit ( )
static

Deinitialize serial driver and underlying platform bus.

Precondition
Driver is initialized.
Returns
Operation status.

◆ nonblock()

template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::nonblock ( bool  state = true)
static

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
err::okIf state set without error.

◆ recv_byte()

template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::recv_byte ( uint8_t &  byte)
static

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]bytePlace for incoming byte. Will remain unchanged if error occurs.
Returns
Operation status.
Return values
err::wouldblockNon-blocking mode is set and read would block otherwise.

◆ 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]bufBuffer to fill with data.
[in,out]szSize 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
err::wouldblockNon-blocking mode is set and read would block otherwise.

◆ send_byte()

template<class PBus , size_t buf_size>
err ecl::serial< PBus, buf_size >::send_byte ( uint8_t  byte)
static

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
[in]byteByte to send.
Returns
Operation status.
Return values
err::wouldblockNon-blocking mode is set and send would block otherwise.

◆ 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]bufBuffer to send.
[in,out]szSize 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:againThe buffer was not consumed entirely.
err::wouldblockNon-blocking mode is set and send would block otherwise.
Here is the call graph for this function:

Field Documentation

◆ 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: