Rtos API example
RawSerial Class Reference
[Drivers]
A serial port (UART) for communication with other serial devices This is a variation of the Serial class that doesn't use streams, thus making it safe to use in interrupt handlers with the RTOS. More...
#include <RawSerial.h>
Inherits mbed::SerialBase, and NonCopyable< RawSerial >.
Inherited by GreenteaSerial.
Public Member Functions | |
RawSerial (PinName tx, PinName rx, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) | |
Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. | |
int | putc (int c) |
Write a char to the serial port. | |
int | getc () |
Read a char from the serial port. | |
int | puts (const char *str) |
Write a string to the serial port. | |
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 | set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC) |
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. | |
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 serial port (UART) for communication with other serial devices This is a variation of the Serial class that doesn't use streams, thus making it safe to use in interrupt handlers with the RTOS.
Can be used for Full Duplex communication, or Simplex by specifying one pin as NC (Not Connected)
- Note:
- Synchronization level: Not protected
Example:
// Send a char to the PC #include "mbed.h" RawSerial pc(USBTX, USBRX); int main() { pc.putc('A'); }
Definition at line 53 of file RawSerial.h.
Constructor & Destructor Documentation
RawSerial | ( | PinName | tx, |
PinName | rx, | ||
int | baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE |
||
) |
Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
- Parameters:
-
tx Transmit pin rx Receive pin baud The 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 28 of file RawSerial.cpp.
Member Function Documentation
void abort_read | ( | void | ) | [inherited] |
Abort the on-going read transfer.
Definition at line 210 of file SerialBase.cpp.
void abort_write | ( | void | ) | [inherited] |
Abort the on-going write transfer.
Definition at line 200 of file SerialBase.cpp.
void attach | ( | Callback< void()> | func, |
IrqType | type = RxIrq |
||
) | [inherited] |
Attach a function to call whenever a serial interrupt is generated.
- Parameters:
-
func A pointer to a void function, or 0 to set as none type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
Definition at line 71 of file SerialBase.cpp.
void baud | ( | int | baudrate ) | [inherited] |
Set the baud rate of the serial port.
- Parameters:
-
baudrate The baudrate of the serial port (default = 9600).
Definition at line 43 of file SerialBase.cpp.
void format | ( | int | bits = 8 , |
Parity | parity = SerialBase::None , |
||
int | stop_bits = 1 |
||
) | [inherited] |
Set the transmission format used by the serial port.
- Parameters:
-
bits The number of bits in a word (5-8; default = 8) parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) stop_bits The number of stop bits (1 or 2; default = 1)
Definition at line 50 of file SerialBase.cpp.
int getc | ( | ) |
Read a char from the serial port.
- Returns:
- The char read from the serial port
Definition at line 32 of file RawSerial.cpp.
void lock | ( | void | ) | [protected, virtual] |
Acquire exclusive access to this serial port.
Reimplemented from SerialBase.
Definition at line 83 of file RawSerial.cpp.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.1" | , |
"The attach function does not support cv-qualifiers. Replaced by ""attach(callback(obj, method), type)." | |||
) | [inherited] |
Attach a member function to call whenever a serial interrupt is generated.
- Parameters:
-
obj pointer to the object to call the member function on method pointer to the member function to be called type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
int putc | ( | int | c ) |
Write a char to the serial port.
- Parameters:
-
c The char to write
- Returns:
- The written char or -1 if an error occured
Definition at line 39 of file RawSerial.cpp.
int puts | ( | const char * | str ) |
Write a string to the serial port.
- Parameters:
-
str The string to write
- Returns:
- 0 if the write succeeds, EOF for error
Definition at line 46 of file RawSerial.cpp.
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 |
||
) | [inherited] |
Begin asynchronous reading using 8bit buffer.
The completition invokes registred RX event callback.
This function locks the deep sleep until any event has occured
- Parameters:
-
buffer The buffer where received data will be stored length The buffer length in bytes callback The event callback function event The logical OR of RX events char_match The matching character
Definition at line 238 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 |
||
) | [inherited] |
Begin asynchronous reading using 16bit buffer.
The completition invokes registred RX event callback.
This function locks the deep sleep until any event has occured
- Parameters:
-
buffer The buffer where received data will be stored length The buffer length in bytes callback The event callback function event The logical OR of RX events char_match The matching character
Definition at line 248 of file SerialBase.cpp.
int readable | ( | ) | [inherited] |
Determine if there is a character available to read.
- Returns:
- 1 if there is a character available to read, 0 otherwise
Reimplemented in Serial.
Definition at line 56 of file SerialBase.cpp.
int set_dma_usage_rx | ( | DMAUsage | usage ) | [inherited] |
Configure DMA usage suggestion for non-blocking RX transfers.
- Parameters:
-
usage The usage DMA hint for peripheral
- Returns:
- Zero if the usage was set, -1 if a transaction is on-going
Definition at line 229 of file SerialBase.cpp.
int set_dma_usage_tx | ( | DMAUsage | usage ) | [inherited] |
Configure DMA usage suggestion for non-blocking TX transfers.
- Parameters:
-
usage The usage DMA hint for peripheral
- Returns:
- Zero if the usage was set, -1 if a transaction is on-going
Definition at line 220 of file SerialBase.cpp.
void set_flow_control | ( | Flow | type, |
PinName | flow1 = NC , |
||
PinName | flow2 = NC |
||
) | [inherited] |
Set the flow control type on the serial port.
- Parameters:
-
type the flow control type (Disabled, RTS, CTS, RTSCTS) flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) flow2 the second flow control pin (CTS for RTSCTS)
Reimplemented in UARTSerial.
Definition at line 147 of file SerialBase.cpp.
void unlock | ( | void | ) | [protected, virtual] |
Release exclusive access to this serial port.
Reimplemented from SerialBase.
Definition at line 89 of file RawSerial.cpp.
int write | ( | const uint16_t * | buffer, |
int | length, | ||
const event_callback_t & | callback, | ||
int | event = SERIAL_EVENT_TX_COMPLETE |
||
) | [inherited] |
Begin asynchronous write using 16bit buffer.
The completition invokes registered TX event callback
This function locks the deep sleep until any event has occured
- Parameters:
-
buffer The buffer where received data will be stored length The buffer length in bytes callback The event callback function event The logical OR of TX events
Definition at line 182 of file SerialBase.cpp.
int write | ( | const uint8_t * | buffer, |
int | length, | ||
const event_callback_t & | callback, | ||
int | event = SERIAL_EVENT_TX_COMPLETE |
||
) | [inherited] |
Begin asynchronous write using 8bit buffer.
The completition invokes registered TX event callback
This function locks the deep sleep until any event has occured
- Parameters:
-
buffer The buffer where received data will be stored length The buffer length in bytes callback The event callback function event The logical OR of TX events
Definition at line 173 of file SerialBase.cpp.
int writeable | ( | ) | [inherited] |
Determine if there is space available to write a character.
- Returns:
- 1 if there is space to write a character, 0 otherwise
Reimplemented in Serial.
Definition at line 64 of file SerialBase.cpp.
Generated on Sun Jul 17 2022 08:25:43 by 1.7.2