Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

SerialBase Class Reference

A base class for serial port implementations Can't be instantiated directly (use UnbufferedSerial or UARTSerial) More...

#include <SerialBase.h>

Inherits NonCopyable< SerialBase >.

Inherited by UARTSerial [private], and UnbufferedSerial [private].

Public Member Functions

void baud (int baudrate)
 Set the baud rate of the serial port.
void format (int bits=8, Parity parity=SerialBase::None, int stop_bits=1)
 Set the transmission format used by the serial port.
int readable ()
 Determine if there is a character available to read.
int writeable ()
 Determine if there is space available to write a character.
void attach (Callback< void()> func, IrqType type=RxIrq)
 Attach a function to call whenever a serial interrupt is generated.
template<typename T >
 MBED_DEPRECATED_SINCE ("mbed-os-5.1","The attach function does not support cv-qualifiers. Replaced by ""attach(callback(obj, method), type).") void attach(T *obj
 Attach a member function to call whenever a serial interrupt is generated.
void clear_break ()
 Clear a break condition on the serial line NOTE: Should be run at least one frame after set_break is called.
void send_break ()
 Generate a break condition on the serial line.
void enable_input (bool enable=true)
 Enable serial input.
void enable_output (bool enable=true)
 Enable serial output.
void set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC)
 Set the flow control type on the serial port.
void set_flow_control (Flow type, const serial_fc_pinmap_t &static_pinmap)
 Set the flow control type on the serial port.
int write (const uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
 Begin asynchronous write using 8bit buffer.
int write (const uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
 Begin asynchronous write using 16bit buffer.
void abort_write ()
 Abort the on-going write transfer.
int read (uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH)
 Begin asynchronous reading using 8bit buffer.
int read (uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH)
 Begin asynchronous reading using 16bit buffer.
void abort_read ()
 Abort the on-going read transfer.
int set_dma_usage_tx (DMAUsage usage)
 Configure DMA usage suggestion for non-blocking TX transfers.
int set_dma_usage_rx (DMAUsage usage)
 Configure DMA usage suggestion for non-blocking RX transfers.

Protected Member Functions

virtual void lock (void)
 Acquire exclusive access to this serial port.
virtual void unlock (void)
 Release exclusive access to this serial port.
void _init ()
 Initialize serial port.
void _deinit ()
 Deinitialize serial port.

Private Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Detailed Description

A base class for serial port implementations Can't be instantiated directly (use UnbufferedSerial or UARTSerial)

Note:
Synchronization level: Set by subclass

Definition at line 46 of file SerialBase.h.


Member Function Documentation

void _deinit (  ) [protected]

Deinitialize serial port.

Definition at line 174 of file SerialBase.cpp.

void _init ( void   ) [protected]

Initialize serial port.

Definition at line 150 of file SerialBase.cpp.

void abort_read ( void   )

Abort the on-going read transfer.

It is safe to call abort_read() when there is no on-going transaction.

Definition at line 401 of file SerialBase.cpp.

void abort_write ( void   )

Abort the on-going write transfer.

It is safe to call abort_write() when there is no on-going transaction.

Definition at line 387 of file SerialBase.cpp.

void attach ( Callback< void()>  func,
IrqType  type = RxIrq 
)

Attach a function to call whenever a serial interrupt is generated.

Parameters:
funcA pointer to a void function, or 0 to set as none
typeWhich serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)

Definition at line 99 of file SerialBase.cpp.

void baud ( int  baudrate )

Set the baud rate of the serial port.

Parameters:
baudrateThe baudrate of the serial port (default = 9600).

Definition at line 67 of file SerialBase.cpp.

void clear_break (  )

Clear a break condition on the serial line NOTE: Should be run at least one frame after set_break is called.

Definition at line 260 of file SerialBase.cpp.

void enable_input ( bool  enable = true )

Enable serial input.

If both serial input and serial output are disabled, the peripheral is freed. If either serial input or serial output is re-enabled, the peripheral is reinitialized.

On re-initialization rx interrupts will be enabled if a rx handler is attached. The rx handler is called once during re-initialization.

Reimplemented in UARTSerial.

Definition at line 179 of file SerialBase.cpp.

void enable_output ( bool  enable = true )

Enable serial output.

If both serial input and serial output are disabled, the peripheral is freed. If either serial input or serial output is re-enabled, the peripheral is reinitialized.

On re-initialization tx interrupts will be enabled if a tx handler is attached. The tx handler is called once during re-initialization.

Reimplemented in UARTSerial.

Definition at line 216 of file SerialBase.cpp.

void format ( int  bits = 8,
Parity  parity = SerialBase::None,
int  stop_bits = 1 
)

Set the transmission format used by the serial port.

Parameters:
bitsThe number of bits in a word (5-8; default = 8)
parityThe parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
stop_bitsThe number of stop bits (1 or 2; default = 1)

Definition at line 75 of file SerialBase.cpp.

void lock ( void   ) [protected, virtual]

Acquire exclusive access to this serial port.

Definition at line 284 of file SerialBase.cpp.

MBED_DEPRECATED_SINCE ( "mbed-os-5.1"  ,
"The attach function does not support cv-qualifiers. Replaced by ""attach(callback(obj, method), type)."   
)

Attach a member function to call whenever a serial interrupt is generated.

Parameters:
objpointer to the object to call the member function on
methodpointer to the member function to be called
typeWhich serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
int read ( uint8_t *  buffer,
int  length,
const event_callback_t &  callback,
int  event = SERIAL_EVENT_RX_COMPLETE,
unsigned char  char_match = SERIAL_RESERVED_CHAR_MATCH 
)

Begin asynchronous reading using 8bit buffer.

The read operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_read() when no events are enabled. This function locks the deep sleep until any event has occurred.

Parameters:
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of RX events that should end operation
char_matchThe matching character
Returns:
Zero if new transaction was started, -1 if transaction is already on-going

Definition at line 433 of file SerialBase.cpp.

int read ( uint16_t *  buffer,
int  length,
const event_callback_t &  callback,
int  event = SERIAL_EVENT_RX_COMPLETE,
unsigned char  char_match = SERIAL_RESERVED_CHAR_MATCH 
)

Begin asynchronous reading using 16bit buffer.

The read operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_read() when no events are enabled. This function locks the deep sleep until any event has occurred.

Parameters:
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of RX events that should end operation
char_matchThe matching character
Returns:
Zero if new transaction was started, -1 if transaction is already on-going

Definition at line 447 of file SerialBase.cpp.

int readable (  )

Determine if there is a character available to read.

Returns:
1 if there is a character available to read, 0 otherwise

Definition at line 82 of file SerialBase.cpp.

void send_break (  )

Generate a break condition on the serial line.

Definition at line 267 of file SerialBase.cpp.

int set_dma_usage_rx ( DMAUsage  usage )

Configure DMA usage suggestion for non-blocking RX transfers.

Parameters:
usageThe usage DMA hint for peripheral
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 424 of file SerialBase.cpp.

int set_dma_usage_tx ( DMAUsage  usage )

Configure DMA usage suggestion for non-blocking TX transfers.

Parameters:
usageThe usage DMA hint for peripheral
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 415 of file SerialBase.cpp.

void set_flow_control ( Flow  type,
const serial_fc_pinmap_t &  static_pinmap 
)

Set the flow control type on the serial port.

Parameters:
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
pinmapreference to structure which holds static pinmap

Definition at line 336 of file SerialBase.cpp.

void set_flow_control ( Flow  type,
PinName  flow1 = NC,
PinName  flow2 = NC 
)

Set the flow control type on the serial port.

Parameters:
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
flow1the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
flow2the second flow control pin (CTS for RTSCTS)

Reimplemented in UARTSerial, and UnbufferedSerial.

Definition at line 305 of file SerialBase.cpp.

void unlock ( void   ) [protected, virtual]

Release exclusive access to this serial port.

Definition at line 289 of file SerialBase.cpp.

int write ( const uint8_t *  buffer,
int  length,
const event_callback_t &  callback,
int  event = SERIAL_EVENT_TX_COMPLETE 
)

Begin asynchronous write using 8bit buffer.

The write operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_write() when no events are enabled. This function locks the deep sleep until any event has occurred.

Parameters:
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of TX events that should end operation
Returns:
Zero if new transaction was started, -1 if transaction is already on-going

Definition at line 351 of file SerialBase.cpp.

int write ( const uint16_t *  buffer,
int  length,
const event_callback_t &  callback,
int  event = SERIAL_EVENT_TX_COMPLETE 
)

Begin asynchronous write using 16bit buffer.

The write operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_write() when no events are enabled. This function locks the deep sleep until any event has occurred.

Parameters:
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of TX events that should end operation
Returns:
Zero if new transaction was started, -1 if transaction is already on-going

Definition at line 364 of file SerialBase.cpp.

int writeable (  )

Determine if there is space available to write a character.

Returns:
1 if there is space to write a character, 0 otherwise

Definition at line 91 of file SerialBase.cpp.