GSMA version

Dependencies:   FXOS8700CQ mbed

Fork of AvnetATT_shape_hackathon by Rick McConney

Committer:
elmkom
Date:
Mon Jan 09 18:23:37 2017 +0000
Revision:
46:733edf15f9e8
Parent:
0:9d5134074d84
tcp test code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:9d5134074d84 1 #pragma once
JMF 0:9d5134074d84 2
JMF 0:9d5134074d84 3 // This is a buffered serial reading class, using the serial interrupt introduced in mbed library version 18 on 17/11/09
JMF 0:9d5134074d84 4
JMF 0:9d5134074d84 5 // In the simplest case, construct it with a buffer size at least equal to the largest message you
JMF 0:9d5134074d84 6 // expect your program to receive in one go.
JMF 0:9d5134074d84 7
JMF 0:9d5134074d84 8 class SerialBuffered : public Serial
JMF 0:9d5134074d84 9 {
JMF 0:9d5134074d84 10 public:
JMF 0:9d5134074d84 11 SerialBuffered( PinName tx, PinName rx, size_t bufferSize );
JMF 0:9d5134074d84 12 virtual ~SerialBuffered();
JMF 0:9d5134074d84 13
JMF 0:9d5134074d84 14 int readable(); // returns 1 if there is a character available to read, 0 otherwise
JMF 0:9d5134074d84 15
JMF 0:9d5134074d84 16 void setTimeout( float seconds ); // maximum time in seconds that getc() should block
JMF 0:9d5134074d84 17 // while waiting for a character
JMF 0:9d5134074d84 18 // Pass -1 to disable the timeout.
JMF 0:9d5134074d84 19
JMF 0:9d5134074d84 20 size_t readBytes( uint8_t *bytes, size_t requested ); // read requested bytes into a buffer,
JMF 0:9d5134074d84 21 // return number actually read,
JMF 0:9d5134074d84 22 // which may be less than requested if there has been a timeout
JMF 0:9d5134074d84 23
JMF 0:9d5134074d84 24 void disable_flow_ctrl(void) { serial_set_flow_control(&_serial, FlowControlNone, NC, NC); }
JMF 0:9d5134074d84 25 // void suspend(bool enable) {
JMF 0:9d5134074d84 26 // if (enable) {
JMF 0:9d5134074d84 27 // serial_irq_set(&_serial, (SerialIrq)RxIrq, 0);
JMF 0:9d5134074d84 28 // serial_break_set(&_serial);
JMF 0:9d5134074d84 29 // _serial.uart->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
JMF 0:9d5134074d84 30 // } else {
JMF 0:9d5134074d84 31 // _serial.uart->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
JMF 0:9d5134074d84 32 // serial_break_clear(&_serial);
JMF 0:9d5134074d84 33 // _serial.uart->EVENTS_RXDRDY = 0;
JMF 0:9d5134074d84 34 // // dummy write needed or TXDRDY trails write rather than leads write.
JMF 0:9d5134074d84 35 // // pins are disconnected so nothing is physically transmitted on the wire
JMF 0:9d5134074d84 36 // _serial.uart->TXD = 0;
JMF 0:9d5134074d84 37 // serial_irq_set(&_serial, (SerialIrq)RxIrq, 1);
JMF 0:9d5134074d84 38 // }
JMF 0:9d5134074d84 39 // }
JMF 0:9d5134074d84 40
JMF 0:9d5134074d84 41 protected:
JMF 0:9d5134074d84 42 PinName _txpin;
JMF 0:9d5134074d84 43 PinName _rxpin;
JMF 0:9d5134074d84 44
JMF 0:9d5134074d84 45 protected:
JMF 0:9d5134074d84 46 virtual int _getc();
JMF 0:9d5134074d84 47 virtual int _putc(int c);
JMF 0:9d5134074d84 48
JMF 0:9d5134074d84 49 private:
JMF 0:9d5134074d84 50
JMF 0:9d5134074d84 51 void handleInterrupt();
JMF 0:9d5134074d84 52
JMF 0:9d5134074d84 53
JMF 0:9d5134074d84 54 uint8_t *m_buff; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
JMF 0:9d5134074d84 55 volatile uint16_t m_contentStart; // index of first bytes of content
JMF 0:9d5134074d84 56 volatile uint16_t m_contentEnd; // index of bytes after last byte of content
JMF 0:9d5134074d84 57 uint16_t m_buffSize;
JMF 0:9d5134074d84 58 float m_timeout;
JMF 0:9d5134074d84 59 Timer m_timer;
JMF 0:9d5134074d84 60
JMF 0:9d5134074d84 61 };