MTS_SPI_Slave unfinished

Fork of MTS-Serial by MultiTech

Committer:
Mike Fiore
Date:
Tue May 20 16:13:12 2014 -0500
Revision:
4:d348d001283b
Parent:
1:d34b566d6f47
include mbed.h in cpp files

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