Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

UnbufferedSerial Class Reference

Class implementation for unbuffered I/O for an interrupt driven application or one that needs to have more control. More...

#include <UnbufferedSerial.h>

Inherits mbed::SerialBase, mbed::FileHandle, and NonCopyable< UnbufferedSerial >.

Public Member Functions

 UnbufferedSerial (PinName tx, PinName rx, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
 Create a serial port instance connected to the specified transmit and receive pins, with the specified baud rate.
 UnbufferedSerial (const serial_pinmap_t &static_pinmap, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
 Create a UnbufferedSerial port, connected to the specified transmit and receive pins, with a particular baud rate.
virtual ssize_t write (const void *buffer, size_t size)
 Write the contents of a buffer to a file.
virtual ssize_t read (void *buffer, size_t size)
 Read the contents of a file into a buffer.
virtual off_t seek (off_t offset, int whence=SEEK_SET)
 Move the file position to a given offset from from a given location.
virtual off_t size ()
 Get the size of the file.
virtual int isatty ()
 Check if the file in an interactive terminal device.
virtual int close ()
 Close a file.
virtual short poll (short events) const
 Check for poll event flags Check the events listed in events to see if data can be read or written without blocking.
void set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC)
 Set the flow control type on the serial port.
virtual int sync ()
 Flush any buffers associated with the file.
virtual off_t tell ()
 Get the file position of the file.
virtual void rewind ()
 Rewind the file position to the beginning of the file.
virtual int truncate (off_t length)
 Truncate or extend a file.
 MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::seek") virtual off_t lseek(off_t offset
 Move the file position to a given offset from a given location.
 MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::sync") virtual int fsync()
 Flush any buffers associated with the FileHandle, ensuring it is up to date on disk.
 MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::size") virtual off_t flen()
 Find the length of the file.
virtual int set_blocking (bool blocking)
 Set blocking or nonblocking mode of the file operation like read/write.
virtual bool is_blocking () const
 Check current blocking or nonblocking mode for file operations.
virtual int enable_input (bool enabled)
 Enable or disable input.
virtual int enable_output (bool enabled)
 Enable or disable output.
bool writable () const
 Definition depends on the subclass implementing FileHandle.
bool readable () const
 Definition depends on the subclass implementing FileHandle.
virtual void sigio (Callback< void()> func)
 Register a callback on state change of the file.

Protected 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.

Private 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.
virtual void lock (void)
 Acquire exclusive access to this serial port.
virtual void unlock (void)
 Release exclusive access to this 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.
void _init ()
 Initialize serial port.
void _deinit ()
 Deinitialize serial port.
 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

Class implementation for unbuffered I/O for an interrupt driven application or one that needs to have more control.

Definition at line 44 of file UnbufferedSerial.h.


Constructor & Destructor Documentation

UnbufferedSerial ( PinName  tx,
PinName  rx,
int  baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 
)

Create a serial port instance connected to the specified transmit and receive pins, with the specified baud rate.

Parameters:
txTransmit pin
rxReceive pin
baudThe baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
Note:
Either tx or rx may be specified as NC if unused

Definition at line 26 of file UnbufferedSerial.cpp.


Member Function Documentation

virtual int enable_input ( bool  enabled ) [virtual, inherited]

Enable or disable input.

Control enabling of device for input. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow input to be temporarily disabled to permit power saving without losing device state.

Parameters:
enabledtrue to enable input, false to disable.
Returns:
0 on success
Negative error code on failure

Reimplemented in UARTSerial.

Definition at line 236 of file FileHandle.h.

virtual int enable_output ( bool  enabled ) [virtual, inherited]

Enable or disable output.

Control enabling of device for output. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow output to be temporarily disabled to permit power saving without losing device state.

Parameters:
enabledtrue to enable output, false to disable.
Returns:
0 on success
Negative error code on failure

Reimplemented in UARTSerial.

Definition at line 254 of file FileHandle.h.

virtual bool is_blocking (  ) const [virtual, inherited]

Check current blocking or nonblocking mode for file operations.

Returns:
true for blocking mode, false for nonblocking mode.

Reimplemented in UARTSerial.

Definition at line 218 of file FileHandle.h.

MBED_DEPRECATED ( "Invalid copy construction of a NonCopyable< FileHandle > resource."   ) const [protected, inherited]

NonCopyable copy constructor.

A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.

If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.

Definition at line 191 of file NonCopyable.h.

MBED_DEPRECATED ( "Invalid copy assignment of a NonCopyable< FileHandle > resource."   ) [protected, inherited]

NonCopyable copy assignment operator.

A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.

If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.

MBED_DEPRECATED_SINCE ( "mbed-os-5.4"  ,
"Replaced by FileHandle::size"   
) [inherited]

Find the length of the file.

Returns:
Length of the file

Definition at line 194 of file FileHandle.h.

MBED_DEPRECATED_SINCE ( "mbed-os-5.4"  ,
"Replaced by FileHandle::seek"   
) [inherited]

Move the file position to a given offset from a given location.

Parameters:
offsetThe offset from whence to move to
whenceSEEK_SET for the start of the file, SEEK_CUR for the current file position, or SEEK_END for the end of the file.
Returns:
new file position on success, -1 on failure or unsupported
MBED_DEPRECATED_SINCE ( "mbed-os-5.4"  ,
"Replaced by FileHandle::sync"   
) [inherited]

Flush any buffers associated with the FileHandle, ensuring it is up to date on disk.

Returns:
0 on success or un-needed, -1 on error

Definition at line 182 of file FileHandle.h.

bool readable (  ) const [inherited]

Definition depends on the subclass implementing FileHandle.

For example, if the FileHandle is of type Stream, readable() could return true when there is something available to read.

Returns:
true when there is something available to read.

Definition at line 292 of file FileHandle.h.

virtual void rewind (  ) [virtual, inherited]

Rewind the file position to the beginning of the file.

Note:
This is equivalent to seek(0, SEEK_SET)

Reimplemented in File, and Stream.

Definition at line 130 of file FileHandle.h.

virtual int set_blocking ( bool  blocking ) [virtual, inherited]

Set blocking or nonblocking mode of the file operation like read/write.

Definition depends on the subclass implementing FileHandle. The default is blocking.

Parameters:
blockingtrue for blocking mode, false for nonblocking mode.
Returns:
0 on success
Negative error code on failure

Reimplemented in UARTSerial.

Definition at line 209 of file FileHandle.h.

virtual void sigio ( Callback< void()>  func ) [virtual, inherited]

Register a callback on state change of the file.

The specified callback will be called on state changes such as when the file can be written to or read from.

The callback may be called in an interrupt context and should not perform expensive operations.

Note! This is not intended as an attach-like asynchronous API, but rather as a building block for constructing such functionality.

The exact timing of when the registered function is called is not guaranteed and is susceptible to change. It should be used as a cue to make read/write/poll calls to find the current state.

Parameters:
funcFunction to call on state change

Reimplemented in UARTSerial.

Definition at line 314 of file FileHandle.h.

virtual int sync (  ) [virtual, inherited]

Flush any buffers associated with the file.

Returns:
0 on success, negative error code on failure

Reimplemented in UARTSerial, File, and Stream.

Definition at line 99 of file FileHandle.h.

virtual off_t tell (  ) [virtual, inherited]

Get the file position of the file.

Note:
This is equivalent to seek(0, SEEK_CUR)
Returns:
The current offset in the file, negative error code on failure

Reimplemented in File, and Stream.

Definition at line 121 of file FileHandle.h.

virtual int truncate ( off_t  length ) [virtual, inherited]

Truncate or extend a file.

The file's length is set to the specified value. The seek pointer is not changed. If the file is extended, the extended area appears as if it were zero-filled.

Parameters:
lengthThe requested new length for the file
Returns:
Zero on success, negative error code on failure

Reimplemented in File.

Definition at line 151 of file FileHandle.h.

bool writable (  ) const [inherited]

Definition depends on the subclass implementing FileHandle.

For example, if the FileHandle is of type Stream, writable() could return true when there is ample buffer space available for write() calls.

Returns:
true if the FileHandle is writable.

Definition at line 281 of file FileHandle.h.