Scott Hoppe / MTS_SPI

Fork of MTS-Serial by Scott Hoppe

Committer:
Mike Fiore
Date:
Mon May 19 11:18:10 2014 -0500
Revision:
1:d34b566d6f47
Parent:
0:6585b7c8cd41
Child:
4:d348d001283b
add MTSBufferedIO, MTSSerial, and MTSSerialFlowControl

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:6585b7c8cd41 1 #ifndef MTSSERIALFLOWCONTROL_H
mfiore 0:6585b7c8cd41 2 #define MTSSERIALFLOWCONTROL_H
mfiore 0:6585b7c8cd41 3
Mike Fiore 1:d34b566d6f47 4 #include "mbed.h"
Mike Fiore 1:d34b566d6f47 5 #include "MTSSerial.h"
Mike Fiore 1:d34b566d6f47 6
Mike Fiore 1:d34b566d6f47 7
Mike Fiore 1:d34b566d6f47 8 namespace mts
Mike Fiore 1:d34b566d6f47 9 {
Mike Fiore 1:d34b566d6f47 10
Mike Fiore 1:d34b566d6f47 11 /** This class derives from MTSBufferedIO/MTSSerial and provides a buffered wrapper to the
Mike Fiore 1:d34b566d6f47 12 * standard mbed Serial class along with generic RTS/CTS HW flow control. Since it
Mike Fiore 1:d34b566d6f47 13 * depends only on the mbed Serial, DigitalOut and DigitalIn classes for accessing
Mike Fiore 1:d34b566d6f47 14 * the serial data, this class is inherently portable accross different mbed platforms
Mike Fiore 1:d34b566d6f47 15 * and provides HW flow control even when not natively supported by the processors
Mike Fiore 1:d34b566d6f47 16 * serial port. If HW flow control is not needed, use MTSSerial instead. It should also
Mike Fiore 1:d34b566d6f47 17 * be noted that the RTS/CTS functionality in this class is implemented as a DTE device.
Mike Fiore 1:d34b566d6f47 18 */
Mike Fiore 1:d34b566d6f47 19 class MTSSerialFlowControl : public MTSSerial
Mike Fiore 1:d34b566d6f47 20 {
Mike Fiore 1:d34b566d6f47 21 public:
Mike Fiore 1:d34b566d6f47 22 /** Creates a new MTSSerialFlowControl object that can be used to talk to an mbed serial
Mike Fiore 1:d34b566d6f47 23 * port through internal SW buffers. Note that this class also adds the ability to use
Mike Fiore 1:d34b566d6f47 24 * RTS/CTS HW Flow Conrtol through and standard mbed DigitalIn and DigitalOut pins.
Mike Fiore 1:d34b566d6f47 25 * The RTS and CTS functionality assumes this is a DTE device.
Mike Fiore 1:d34b566d6f47 26 *
Mike Fiore 1:d34b566d6f47 27 * @param TXD the transmit data pin on the desired mbed serial interface.
Mike Fiore 1:d34b566d6f47 28 * @param RXD the receive data pin on the desired mbed serial interface.
Mike Fiore 1:d34b566d6f47 29 * @param RTS the DigitalOut pin that RTS will be attached to. (DTE)
Mike Fiore 1:d34b566d6f47 30 * @param CTS the DigitalIn pin that CTS will be attached to. (DTE)
Mike Fiore 1:d34b566d6f47 31 * @param txBufferSize the size in bytes of the internal SW transmit buffer. The
Mike Fiore 1:d34b566d6f47 32 * default is 256 bytes.
Mike Fiore 1:d34b566d6f47 33 * @param rxBufferSize the size in bytes of the internal SW receive buffer. The
Mike Fiore 1:d34b566d6f47 34 * default is 256 bytes.
Mike Fiore 1:d34b566d6f47 35 */
Mike Fiore 1:d34b566d6f47 36 MTSSerialFlowControl(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize = 256, int rxBufSize = 256);
Mike Fiore 1:d34b566d6f47 37
Mike Fiore 1:d34b566d6f47 38 /** Destructs an MTSSerialFlowControl object and frees all related resources.
Mike Fiore 1:d34b566d6f47 39 */
Mike Fiore 1:d34b566d6f47 40 ~MTSSerialFlowControl();
Mike Fiore 1:d34b566d6f47 41
Mike Fiore 1:d34b566d6f47 42 //Overriden from MTSBufferedIO to support flow control correctly
Mike Fiore 1:d34b566d6f47 43 virtual void rxClear();
Mike Fiore 1:d34b566d6f47 44
Mike Fiore 1:d34b566d6f47 45 private:
Mike Fiore 1:d34b566d6f47 46 void notifyStartSending(); // Used to set cts start signal
Mike Fiore 1:d34b566d6f47 47 void notifyStopSending(); // Used to set cts stop signal
Mike Fiore 1:d34b566d6f47 48
Mike Fiore 1:d34b566d6f47 49 //This device acts as a DTE
Mike Fiore 1:d34b566d6f47 50 bool rxReadyFlag; //Tracks state change for rts signaling
Mike Fiore 1:d34b566d6f47 51 DigitalOut rts; // Used to tell DCE to send or not send data
Mike Fiore 1:d34b566d6f47 52 DigitalIn cts; // Used to check if DCE is ready for data
Mike Fiore 1:d34b566d6f47 53 int highThreshold; // High water mark for setting cts to stop
Mike Fiore 1:d34b566d6f47 54 int lowThreshold; // Low water mark for setting cts to start
Mike Fiore 1:d34b566d6f47 55
Mike Fiore 1:d34b566d6f47 56 virtual void handleRead(); // Method for handling data to be read
Mike Fiore 1:d34b566d6f47 57 virtual void handleWrite(); // Method for handling data to be written
Mike Fiore 1:d34b566d6f47 58 };
Mike Fiore 1:d34b566d6f47 59
Mike Fiore 1:d34b566d6f47 60 }
Mike Fiore 1:d34b566d6f47 61
Mike Fiore 1:d34b566d6f47 62 #endif /* MTSSERIALFLOWCONTROL */