local fork
Dependencies: Socket USBHostWANDongle_bleedingedge lwip-sys lwip
Fork of VodafoneUSBModem_bleedingedge by
serial/io/IOSerialStream.h@22:06fb2a93a1f6, 2012-08-17 (annotated)
- Committer:
- donatien
- Date:
- Fri Aug 17 14:31:27 2012 +0000
- Revision:
- 22:06fb2a93a1f6
- Parent:
- 8:04b6a042595f
Fork with names/headers changes to prepare for pre-built version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:3b2f052c333b | 1 | /* IOSerialStream.h */ |
donatien | 22:06fb2a93a1f6 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
donatien | 22:06fb2a93a1f6 | 3 | * |
donatien | 22:06fb2a93a1f6 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 22:06fb2a93a1f6 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
donatien | 22:06fb2a93a1f6 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
donatien | 22:06fb2a93a1f6 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
donatien | 22:06fb2a93a1f6 | 8 | * furnished to do so, subject to the following conditions: |
donatien | 22:06fb2a93a1f6 | 9 | * |
donatien | 22:06fb2a93a1f6 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 22:06fb2a93a1f6 | 11 | * substantial portions of the Software. |
donatien | 22:06fb2a93a1f6 | 12 | * |
donatien | 22:06fb2a93a1f6 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 22:06fb2a93a1f6 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 22:06fb2a93a1f6 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 22:06fb2a93a1f6 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 22:06fb2a93a1f6 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 22:06fb2a93a1f6 | 18 | */ |
donatien | 0:3b2f052c333b | 19 | #ifndef IOSERIALSTREAM_H_ |
donatien | 0:3b2f052c333b | 20 | #define IOSERIALSTREAM_H_ |
donatien | 0:3b2f052c333b | 21 | |
donatien | 0:3b2f052c333b | 22 | #include "core/fwk.h" |
donatien | 0:3b2f052c333b | 23 | |
donatien | 0:3b2f052c333b | 24 | #include "Serial.h" |
donatien | 0:3b2f052c333b | 25 | |
donatien | 0:3b2f052c333b | 26 | #include "rtos.h" |
donatien | 0:3b2f052c333b | 27 | #include "core/MtxCircBuffer.h" |
donatien | 0:3b2f052c333b | 28 | |
donatien | 0:3b2f052c333b | 29 | /** Input Serial Stream for physical serial interfaces (UART...) |
donatien | 0:3b2f052c333b | 30 | This class is not thread-safe, except for the *Abort() methods that can be called by any thread/ISR |
donatien | 0:3b2f052c333b | 31 | */ |
donatien | 0:3b2f052c333b | 32 | #define CIRCBUF_SIZE 255 |
donatien | 0:3b2f052c333b | 33 | class IOSerialStream : public IOStream |
donatien | 0:3b2f052c333b | 34 | { |
donatien | 0:3b2f052c333b | 35 | public: |
donatien | 0:3b2f052c333b | 36 | IOSerialStream(mbed::Serial& serial); |
donatien | 0:3b2f052c333b | 37 | /*virtual*/ ~IOSerialStream(); |
donatien | 0:3b2f052c333b | 38 | |
donatien | 0:3b2f052c333b | 39 | //0 for non-blocking (returns immediately), osWaitForever for infinite blocking |
donatien | 0:3b2f052c333b | 40 | virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever); |
donatien | 0:3b2f052c333b | 41 | virtual size_t available(); |
donatien | 0:3b2f052c333b | 42 | virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available |
donatien | 0:3b2f052c333b | 43 | virtual int abortRead(); //Abort current reading (or waiting) operation |
donatien | 0:3b2f052c333b | 44 | |
donatien | 0:3b2f052c333b | 45 | |
donatien | 0:3b2f052c333b | 46 | //0 for non-blocking (returns immediately), osWaitForever for infinite blocking |
donatien | 0:3b2f052c333b | 47 | virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever); |
donatien | 0:3b2f052c333b | 48 | virtual size_t space(); |
donatien | 0:3b2f052c333b | 49 | virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available |
donatien | 0:3b2f052c333b | 50 | virtual int abortWrite(); //Abort current writing (or waiting) operation |
donatien | 0:3b2f052c333b | 51 | |
donatien | 0:3b2f052c333b | 52 | private: |
donatien | 0:3b2f052c333b | 53 | |
donatien | 0:3b2f052c333b | 54 | mbed::Serial& m_serial; |
donatien | 0:3b2f052c333b | 55 | volatile bool m_serialTxFifoEmpty; |
donatien | 0:3b2f052c333b | 56 | |
donatien | 0:3b2f052c333b | 57 | void setupReadableISR(bool en); |
donatien | 0:3b2f052c333b | 58 | void readable(); //Callback from m_serial when new data is available |
donatien | 0:3b2f052c333b | 59 | |
donatien | 0:3b2f052c333b | 60 | Semaphore m_availableSphre; //Used for signalling |
donatien | 0:3b2f052c333b | 61 | |
donatien | 0:3b2f052c333b | 62 | void setupWriteableISR(bool en); |
donatien | 0:3b2f052c333b | 63 | void writeable(); //Callback from m_serial when new space is available |
donatien | 0:3b2f052c333b | 64 | |
donatien | 0:3b2f052c333b | 65 | Semaphore m_spaceSphre; //Used for signalling |
donatien | 0:3b2f052c333b | 66 | |
donatien | 0:3b2f052c333b | 67 | MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf; |
donatien | 0:3b2f052c333b | 68 | MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf; |
donatien | 0:3b2f052c333b | 69 | |
donatien | 0:3b2f052c333b | 70 | }; |
donatien | 0:3b2f052c333b | 71 | |
donatien | 0:3b2f052c333b | 72 | #endif /* IOSERIALSTREAM_H_ */ |