Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
io/MTSSerialFlowControl.h@77:d7b14688a704, 2013-12-26 (annotated)
- Committer:
- jengbrecht
- Date:
- Thu Dec 26 21:54:19 2013 +0000
- Revision:
- 77:d7b14688a704
- Parent:
- 51:d22d3d87391f
- Child:
- 78:ef3ee53cf5df
Fixed Several RTS/CTS Issues
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jengbrecht | 0:563b70517320 | 1 | #ifndef MTSSERIALFLOWCONTROL_H |
| jengbrecht | 0:563b70517320 | 2 | #define MTSSERIALFLOWCONTROL_H |
| jengbrecht | 0:563b70517320 | 3 | |
| jengbrecht | 0:563b70517320 | 4 | #include "mbed.h" |
| jengbrecht | 0:563b70517320 | 5 | #include "MTSBufferedIO.h" |
| mfiore | 2:8d3ea0dfce39 | 6 | |
| jengbrecht | 77:d7b14688a704 | 7 | namespace mts |
| jengbrecht | 77:d7b14688a704 | 8 | { |
| mfiore | 39:6e94520a3217 | 9 | |
| jengbrecht | 45:40745c2036cf | 10 | /** This class derives from MTSBufferedIO and provides a buffered wrapper to the |
| jengbrecht | 45:40745c2036cf | 11 | * standard mbed Serial class along with generic RTS/CTS HW flow control. Since it |
| jengbrecht | 45:40745c2036cf | 12 | * depends only on the mbed Serial, DigitalOut and InterruptIn classes for accessing |
| jengbrecht | 45:40745c2036cf | 13 | * the serial data, this class is inherently portable accross different mbed platforms |
| jengbrecht | 45:40745c2036cf | 14 | * and provides HW flow control even when not natively supported by the processors |
| jengbrecht | 45:40745c2036cf | 15 | * serial port. If HW flow control is not needed, use MTSSerial instead. |
| jengbrecht | 45:40745c2036cf | 16 | */ |
| jengbrecht | 0:563b70517320 | 17 | class MTSSerialFlowControl : public MTSBufferedIO |
| jengbrecht | 0:563b70517320 | 18 | { |
| jengbrecht | 0:563b70517320 | 19 | public: |
| jengbrecht | 45:40745c2036cf | 20 | /** Creates a new MTSSerialFlowControl object that can be used to talk to an mbed serial |
| jengbrecht | 36:bb6b293c7495 | 21 | * port through internal SW buffers. Note that this class also adds the ability to use |
| jengbrecht | 45:40745c2036cf | 22 | * RTS/CTS HW Flow Conrtol through and standard mbed InterruptIn and DigitalOut pins. |
| jengbrecht | 36:bb6b293c7495 | 23 | * |
| jengbrecht | 45:40745c2036cf | 24 | * @param TXD the transmit data pin on the desired mbed serial interface. |
| jengbrecht | 45:40745c2036cf | 25 | * @param RXD the receive data pin on the desired mbed serial interface. |
| jengbrecht | 45:40745c2036cf | 26 | * @param RTS the InterruptIn pin that RTS will be attached to. |
| jengbrecht | 36:bb6b293c7495 | 27 | * @param CTS the DigitalOut pin that CTS will be attached to. |
| jengbrecht | 36:bb6b293c7495 | 28 | * @param txBufferSize the size in bytes of the internal SW transmit buffer. The |
| jengbrecht | 36:bb6b293c7495 | 29 | * default is 64 bytes. |
| jengbrecht | 36:bb6b293c7495 | 30 | * @param rxBufferSize the size in bytes of the internal SW receive buffer. The |
| jengbrecht | 36:bb6b293c7495 | 31 | * default is 64 bytes. |
| jengbrecht | 36:bb6b293c7495 | 32 | * @param name an optional name for the serial port. The default is blank. |
| jengbrecht | 36:bb6b293c7495 | 33 | */ |
| mfiore | 10:2bd727a4b329 | 34 | MTSSerialFlowControl(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize = 64, int rxBufSize = 64, char* name = ""); |
| jengbrecht | 36:bb6b293c7495 | 35 | |
| jengbrecht | 36:bb6b293c7495 | 36 | /** Destructs an MTSSerialFlowControl object and frees all related resources, |
| jengbrecht | 36:bb6b293c7495 | 37 | * including internal buffers. |
| jengbrecht | 36:bb6b293c7495 | 38 | */ |
| jengbrecht | 0:563b70517320 | 39 | ~MTSSerialFlowControl(); |
| jengbrecht | 36:bb6b293c7495 | 40 | |
| jengbrecht | 36:bb6b293c7495 | 41 | /** This method is used to the set the baud rate of the serial port. |
| jengbrecht | 36:bb6b293c7495 | 42 | * |
| jengbrecht | 36:bb6b293c7495 | 43 | * @param baudrate the baudrate in bps as an int. The internal interface |
| jengbrecht | 36:bb6b293c7495 | 44 | * default is 9600 bps. |
| jengbrecht | 36:bb6b293c7495 | 45 | */ |
| mfiore | 10:2bd727a4b329 | 46 | void baud(int baudrate); |
| jengbrecht | 36:bb6b293c7495 | 47 | |
| jengbrecht | 45:40745c2036cf | 48 | /** This method sets the transmission format used by the serial port. |
| jengbrecht | 45:40745c2036cf | 49 | * |
| jengbrecht | 45:40745c2036cf | 50 | * @param bits the number of bits in a word (5-8; default = 8) |
| jengbrecht | 45:40745c2036cf | 51 | * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, |
| jengbrecht | 45:40745c2036cf | 52 | * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) |
| jengbrecht | 45:40745c2036cf | 53 | * @param stop the number of stop bits (1 or 2; default = 1) |
| jengbrecht | 45:40745c2036cf | 54 | */ |
| mfiore | 51:d22d3d87391f | 55 | void format(int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1); |
| jengbrecht | 0:563b70517320 | 56 | |
| jengbrecht | 0:563b70517320 | 57 | private: |
| jengbrecht | 77:d7b14688a704 | 58 | void startSending(); // Used to process rts start signal |
| jengbrecht | 77:d7b14688a704 | 59 | void stopSending(); // Used to process rts stop signal |
| jengbrecht | 77:d7b14688a704 | 60 | void notifyStartSending(); // Used to set cts start signal |
| jengbrecht | 77:d7b14688a704 | 61 | void notifyStopSending(); // Used to set cts stop signal |
| jengbrecht | 36:bb6b293c7495 | 62 | InterruptIn* rts; // Used to monitor the RTS line |
| jengbrecht | 36:bb6b293c7495 | 63 | DigitalOut* cts; // Used to control the CTS line |
| jengbrecht | 36:bb6b293c7495 | 64 | Serial* serial; // Internal Mbed Serial object |
| jengbrecht | 77:d7b14688a704 | 65 | volatile bool clearToSend; // Flag determining if the CTS line is valid |
| jengbrecht | 45:40745c2036cf | 66 | int highThreshold; // High water mark for setting cts to stop |
| jengbrecht | 45:40745c2036cf | 67 | int lowThreshold; // Low water mark for setting cts to start |
| jengbrecht | 45:40745c2036cf | 68 | char* if_name; // Internal variable for interface name |
| jengbrecht | 36:bb6b293c7495 | 69 | |
| jengbrecht | 77:d7b14688a704 | 70 | |
| mfiore | 2:8d3ea0dfce39 | 71 | |
| jengbrecht | 45:40745c2036cf | 72 | virtual void handleRead(); // Method for handling data to be read |
| jengbrecht | 45:40745c2036cf | 73 | virtual void handleWrite(); // Method for handling data to be written |
| jengbrecht | 0:563b70517320 | 74 | }; |
| mfiore | 2:8d3ea0dfce39 | 75 | |
| mfiore | 39:6e94520a3217 | 76 | } |
| mfiore | 39:6e94520a3217 | 77 | |
| jengbrecht | 0:563b70517320 | 78 | #endif /* MTSSERIALFLOWCONTROL */ |
uIP Socket Modem Shield (Outdated - see below)