mbed-drivers
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
mbed::SerialBase Class Reference

#include <SerialBase.h>

Inheritance diagram for mbed::SerialBase:
mbed::RawSerial mbed::Serial

Public Types

enum  Parity {
  None = 0, Odd, Even, Forced1,
  Forced0
}
 
enum  IrqType { RxIrq = 0, TxIrq }
 
enum  Flow { Disabled = 0, RTS, CTS, RTSCTS }
 
typedef mbed::util::FunctionPointer2< void, Buffer, int > event_callback_t
 

Public Member Functions

void baud (int baudrate)
 
void format (int bits=8, Parity parity=SerialBase::None, int stop_bits=1)
 
int readable ()
 
int writeable ()
 
void attach (void(*fptr)(void), IrqType type=RxIrq)
 
template<typename T >
void attach (T *tptr, void(T::*mptr)(void), IrqType type=RxIrq)
 
void send_break ()
 
void set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC)
 
int write (void *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
 
int write (const Buffer &buf, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
 
void abort_write ()
 
int read (void *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH)
 
int read (const Buffer &buffer, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH)
 
void abort_read ()
 
int set_dma_usage_tx (DMAUsage usage)
 
int set_dma_usage_rx (DMAUsage usage)
 

Static Public Member Functions

static void _irq_handler (uint32_t id, SerialIrq irq_type)
 

Protected Types

typedef OneWayTransaction< event_callback_ttransaction_data_t
 
typedef Transaction< SerialBase, transaction_data_ttransaction_t
 

Protected Member Functions

void start_read (const Buffer &buffer, char buffer_width, const event_callback_t &callback, int event, unsigned char char_match)
 
void start_write (const Buffer &buffer, char buffer_width, const event_callback_t &callback, int event)
 
void interrupt_handler_asynch (void)
 
 SerialBase (PinName tx, PinName rx)
 
int _base_getc ()
 
int _base_putc (int c)
 

Protected Attributes

CThunk< SerialBase_thunk_irq
 
transaction_data_t _current_tx_transaction
 
transaction_data_t _current_rx_transaction
 
DMAUsage _tx_usage
 
DMAUsage _rx_usage
 
serial_t _serial
 
mbed::util::FunctionPointer _irq [2]
 
int _baud
 

Detailed Description

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

Member Typedef Documentation

typedef mbed::util::FunctionPointer2<void, Buffer, int> mbed::SerialBase::event_callback_t

Serial transfer callback

Parameters
Bufferthe transfer buffer
intthe event that triggered the calback

Member Function Documentation

void mbed::SerialBase::abort_read ( void  )

Abort the on-going read transfer

void mbed::SerialBase::abort_write ( void  )

Abort the on-going write transfer

void mbed::SerialBase::attach ( void(*)(void)  fptr,
IrqType  type = RxIrq 
)

Attach a function to call whenever a serial interrupt is generated

Parameters
fptrA pointer to a void function, or 0 to set as none
typeWhich serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
template<typename T >
void mbed::SerialBase::attach ( T *  tptr,
void(T::*)(void)  mptr,
IrqType  type = RxIrq 
)
inline

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

Parameters
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called
typeWhich serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
void mbed::SerialBase::baud ( int  baudrate)

Set the baud rate of the serial port

Parameters
baudrateThe baudrate of the serial port (default = 9600).
void mbed::SerialBase::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)
stopThe number of stop bits (1 or 2; default = 1)
int mbed::SerialBase::read ( void *  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 completition invokes registred RX event callback.

Parameters
bufferThe buffer where received data will be stored
lengthThe buffer length
callbackThe event callback function
eventThe logical OR of RX events
char_matchThe matching character
int mbed::SerialBase::read ( const Buffer buffer,
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 completition invokes registred RX event callback.

Parameters
bufferThe buffer where received data will be stored
callbackThe event callback function
eventThe logical OR of RX events
char_matchThe matching character
int mbed::SerialBase::readable ( )

Determine if there is a character available to read

typedef FunctionPointer3<void, Buffer, int, void*> event_callback_t; typedef OneWayTransaction<event_callback_t> transaction_data_t; typedef Transaction<SerialBase, transaction_data_t> transaction_t;

Returns
1 if there is a character available to read, 0 otherwise
void mbed::SerialBase::send_break ( )

Generate a break condition on the serial line

int mbed::SerialBase::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
int mbed::SerialBase::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
void mbed::SerialBase::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)
int mbed::SerialBase::write ( void *  buffer,
int  length,
const event_callback_t callback,
int  event = SERIAL_EVENT_TX_COMPLETE 
)

Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback

Parameters
bufferThe buffer where received data will be stored
lengthThe buffer length
callbackThe event callback function
eventThe logical OR of TX events
int mbed::SerialBase::write ( const Buffer buf,
const event_callback_t callback,
int  event = SERIAL_EVENT_TX_COMPLETE 
)

Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback

Parameters
bufferThe buffer where received data will be stored
callbackThe event callback function
eventThe logical OR of TX events
int mbed::SerialBase::writeable ( )

Determine if there is space available to write a character

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

The documentation for this class was generated from the following files: