123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
-
- #ifndef MBED_SERIALBASE_H
- #define MBED_SERIALBASE_H
-
- #include "platform.h"
-
- #if DEVICE_SERIAL
-
- #include "Stream.h"
- #include "FunctionPointer.h"
- #include "serial_api.h"
-
- #if DEVICE_SERIAL_ASYNCH
- #include "CThunk.h"
- #include "dma_api.h"
- #endif
-
- namespace mbed {
-
-
- class SerialBase {
-
- public:
-
-
- void baud(int baudrate);
-
- enum Parity {
- None = 0,
- Odd,
- Even,
- Forced1,
- Forced0
- };
-
- enum IrqType {
- RxIrq = 0,
- TxIrq
- };
-
- enum Flow {
- Disabled = 0,
- RTS,
- CTS,
- RTSCTS
- };
-
-
-
- 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) {
- if((mptr != NULL) && (tptr != NULL)) {
- _irq[type].attach(tptr, mptr);
- serial_irq_set(&_serial, (SerialIrq)type, 1);
- } else {
- serial_irq_set(&_serial, (SerialIrq)type, 0);
- }
- }
-
-
-
- void send_break();
-
- #if DEVICE_SERIAL_FC
-
-
- void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
- #endif
-
- static void _irq_handler(uint32_t id, SerialIrq irq_type);
-
- #if DEVICE_SERIAL_ASYNCH
-
-
-
- int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
-
-
-
- int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
-
-
-
- void abort_write();
-
-
-
- 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);
-
-
-
- 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);
-
-
-
- void abort_read();
-
-
-
- int set_dma_usage_tx(DMAUsage usage);
-
-
-
- int set_dma_usage_rx(DMAUsage usage);
-
- protected:
- void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
- void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
- void interrupt_handler_asynch(void);
- #endif
-
- protected:
- SerialBase(PinName tx, PinName rx);
- virtual ~SerialBase() {
- }
-
- int _base_getc();
- int _base_putc(int c);
-
- #if DEVICE_SERIAL_ASYNCH
- CThunk<SerialBase> _thunk_irq;
- event_callback_t _tx_callback;
- event_callback_t _rx_callback;
- DMAUsage _tx_usage;
- DMAUsage _rx_usage;
- #endif
-
- serial_t _serial;
- FunctionPointer _irq[2];
- int _baud;
-
- };
-
- }
-
- #endif
-
- #endif
|