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