123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- #ifndef MBED_UARTSERIAL_H
- #define MBED_UARTSERIAL_H
- #include "platform/platform.h"
- #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
- #include "FileHandle.h"
- #include "SerialBase.h"
- #include "InterruptIn.h"
- #include "PlatformMutex.h"
- #include "serial_api.h"
- #include "CircularBuffer.h"
- #include "platform/NonCopyable.h"
- #ifndef MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE
- #define MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE 256
- #endif
- #ifndef MBED_CONF_DRIVERS_UART_SERIAL_TXBUF_SIZE
- #define MBED_CONF_DRIVERS_UART_SERIAL_TXBUF_SIZE 256
- #endif
- namespace mbed {
- class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UARTSerial> {
- public:
-
- UARTSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
- virtual ~UARTSerial();
-
- virtual short poll(short events) const;
-
- using FileHandle::readable;
- using FileHandle::writable;
-
- virtual ssize_t write(const void *buffer, size_t length);
-
- virtual ssize_t read(void *buffer, size_t length);
-
- virtual int close();
-
- virtual int isatty();
-
- virtual off_t seek(off_t offset, int whence);
-
- virtual int sync();
-
- virtual int set_blocking(bool blocking)
- {
- _blocking = blocking;
- return 0;
- }
-
- virtual bool is_blocking() const
- {
- return _blocking;
- }
-
- virtual void sigio(Callback<void()> func);
-
- void set_data_carrier_detect(PinName dcd_pin, bool active_high = false);
-
- void set_baud(int baud);
-
- using SerialBase::Parity;
-
- using SerialBase::None;
- using SerialBase::Odd;
- using SerialBase::Even;
- using SerialBase::Forced1;
- using SerialBase::Forced0;
-
- void set_format(int bits = 8, Parity parity = UARTSerial::None, int stop_bits = 1);
- #if DEVICE_SERIAL_FC
-
-
- using SerialBase::Flow;
-
- using SerialBase::Disabled;
- using SerialBase::RTS;
- using SerialBase::CTS;
- using SerialBase::RTSCTS;
-
- void set_flow_control(Flow type, PinName flow1 = NC, PinName flow2 = NC);
- #endif
- private:
- void wait_ms(uint32_t millisec);
-
- virtual void lock(void);
-
- virtual void unlock(void);
-
- virtual void api_lock(void);
-
- virtual void api_unlock(void);
-
- CircularBuffer<char, MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE> _rxbuf;
- CircularBuffer<char, MBED_CONF_DRIVERS_UART_SERIAL_TXBUF_SIZE> _txbuf;
- PlatformMutex _mutex;
- Callback<void()> _sigio_cb;
- bool _blocking;
- bool _tx_irq_enabled;
- bool _rx_irq_enabled;
- InterruptIn *_dcd_irq;
-
- bool hup() const;
-
- void tx_irq(void);
- void rx_irq(void);
- void wake(void);
- void dcd_irq(void);
- };
- }
- #endif
- #endif
|