Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Socket lwip-sys lwip
Fork of AbitUSBModem by
serial/io/IOSerialStream.h@100:dbd92e9515ef, 2015-05-11 (annotated)
- Committer:
- phsfan
- Date:
- Mon May 11 14:07:07 2015 +0000
- Revision:
- 100:dbd92e9515ef
- Parent:
- 96:b50f5f795684
ports to APM-002 (Abit PHS Module)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| donatien | 0:3b2f052c333b | 1 | /* IOSerialStream.h */ |
| phsfan | 100:dbd92e9515ef | 2 | /* Modified by 2015 phsfan |
| phsfan | 100:dbd92e9515ef | 3 | * for ABIT SMA-01 |
| phsfan | 100:dbd92e9515ef | 4 | */ |
| donatien | 22:06fb2a93a1f6 | 5 | /* Copyright (C) 2012 mbed.org, MIT License |
| donatien | 22:06fb2a93a1f6 | 6 | * |
| donatien | 22:06fb2a93a1f6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| donatien | 22:06fb2a93a1f6 | 8 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| donatien | 22:06fb2a93a1f6 | 9 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| donatien | 22:06fb2a93a1f6 | 10 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| donatien | 22:06fb2a93a1f6 | 11 | * furnished to do so, subject to the following conditions: |
| donatien | 22:06fb2a93a1f6 | 12 | * |
| donatien | 22:06fb2a93a1f6 | 13 | * The above copyright notice and this permission notice shall be included in all copies or |
| donatien | 22:06fb2a93a1f6 | 14 | * substantial portions of the Software. |
| donatien | 22:06fb2a93a1f6 | 15 | * |
| donatien | 22:06fb2a93a1f6 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| donatien | 22:06fb2a93a1f6 | 17 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| donatien | 22:06fb2a93a1f6 | 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| donatien | 22:06fb2a93a1f6 | 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| donatien | 22:06fb2a93a1f6 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| donatien | 22:06fb2a93a1f6 | 21 | */ |
| donatien | 0:3b2f052c333b | 22 | #ifndef IOSERIALSTREAM_H_ |
| donatien | 0:3b2f052c333b | 23 | #define IOSERIALSTREAM_H_ |
| donatien | 0:3b2f052c333b | 24 | |
| donatien | 0:3b2f052c333b | 25 | #include "core/fwk.h" |
| donatien | 0:3b2f052c333b | 26 | |
| phsfan | 100:dbd92e9515ef | 27 | #include "RawSerial.h" |
| donatien | 0:3b2f052c333b | 28 | |
| donatien | 0:3b2f052c333b | 29 | #include "rtos.h" |
| phsfan | 96:b50f5f795684 | 30 | #include "MtxCircBuffer.h" |
| donatien | 0:3b2f052c333b | 31 | |
| donatien | 0:3b2f052c333b | 32 | /** Input Serial Stream for physical serial interfaces (UART...) |
| donatien | 0:3b2f052c333b | 33 | This class is not thread-safe, except for the *Abort() methods that can be called by any thread/ISR |
| donatien | 0:3b2f052c333b | 34 | */ |
| donatien | 0:3b2f052c333b | 35 | #define CIRCBUF_SIZE 255 |
| donatien | 0:3b2f052c333b | 36 | class IOSerialStream : public IOStream |
| donatien | 0:3b2f052c333b | 37 | { |
| donatien | 0:3b2f052c333b | 38 | public: |
| phsfan | 100:dbd92e9515ef | 39 | IOSerialStream(mbed::RawSerial& serial); |
| donatien | 0:3b2f052c333b | 40 | /*virtual*/ ~IOSerialStream(); |
| donatien | 0:3b2f052c333b | 41 | |
| donatien | 0:3b2f052c333b | 42 | //0 for non-blocking (returns immediately), osWaitForever for infinite blocking |
| donatien | 0:3b2f052c333b | 43 | virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever); |
| donatien | 0:3b2f052c333b | 44 | virtual size_t available(); |
| donatien | 0:3b2f052c333b | 45 | virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available |
| donatien | 0:3b2f052c333b | 46 | virtual int abortRead(); //Abort current reading (or waiting) operation |
| donatien | 0:3b2f052c333b | 47 | |
| donatien | 0:3b2f052c333b | 48 | |
| donatien | 0:3b2f052c333b | 49 | //0 for non-blocking (returns immediately), osWaitForever for infinite blocking |
| donatien | 0:3b2f052c333b | 50 | virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever); |
| donatien | 0:3b2f052c333b | 51 | virtual size_t space(); |
| donatien | 0:3b2f052c333b | 52 | virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available |
| donatien | 0:3b2f052c333b | 53 | virtual int abortWrite(); //Abort current writing (or waiting) operation |
| donatien | 0:3b2f052c333b | 54 | |
| donatien | 0:3b2f052c333b | 55 | private: |
| donatien | 0:3b2f052c333b | 56 | |
| phsfan | 100:dbd92e9515ef | 57 | mbed::RawSerial& m_serial; |
| donatien | 0:3b2f052c333b | 58 | volatile bool m_serialTxFifoEmpty; |
| donatien | 0:3b2f052c333b | 59 | |
| phsfan | 100:dbd92e9515ef | 60 | #if defined(TARGET_LPC176X) || defined(TARGET_LPC408X) || defined(TARGET_LPC2368) |
| phsfan | 100:dbd92e9515ef | 61 | LPC_UART1_TypeDef *_uart; |
| phsfan | 100:dbd92e9515ef | 62 | #elif defined(TARGET_LPC11UXX) |
| phsfan | 100:dbd92e9515ef | 63 | LPC_USART_Type *_uart; |
| phsfan | 100:dbd92e9515ef | 64 | #endif |
| phsfan | 100:dbd92e9515ef | 65 | |
| donatien | 0:3b2f052c333b | 66 | void setupReadableISR(bool en); |
| donatien | 0:3b2f052c333b | 67 | void readable(); //Callback from m_serial when new data is available |
| donatien | 0:3b2f052c333b | 68 | |
| donatien | 0:3b2f052c333b | 69 | Semaphore m_availableSphre; //Used for signalling |
| donatien | 0:3b2f052c333b | 70 | |
| donatien | 0:3b2f052c333b | 71 | void setupWriteableISR(bool en); |
| donatien | 0:3b2f052c333b | 72 | void writeable(); //Callback from m_serial when new space is available |
| donatien | 0:3b2f052c333b | 73 | |
| donatien | 0:3b2f052c333b | 74 | Semaphore m_spaceSphre; //Used for signalling |
| donatien | 0:3b2f052c333b | 75 | |
| donatien | 0:3b2f052c333b | 76 | MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf; |
| donatien | 0:3b2f052c333b | 77 | MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf; |
| donatien | 0:3b2f052c333b | 78 | |
| donatien | 0:3b2f052c333b | 79 | }; |
| donatien | 0:3b2f052c333b | 80 | |
| donatien | 0:3b2f052c333b | 81 | #endif /* IOSERIALSTREAM_H_ */ |
