たけし みわ
/
y_CameraC1098_ES_01
CameraC1098/SerialBuffered.h@0:5bf7e3564c3b, 2012-06-17 (annotated)
- Committer:
- esmiwa
- Date:
- Sun Jun 17 01:15:35 2012 +0000
- Revision:
- 0:5bf7e3564c3b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
esmiwa | 0:5bf7e3564c3b | 1 | #ifndef _SERIAL_BUFFERED_H_ |
esmiwa | 0:5bf7e3564c3b | 2 | #define _SERIAL_BUFFERED_H_ |
esmiwa | 0:5bf7e3564c3b | 3 | |
esmiwa | 0:5bf7e3564c3b | 4 | /** |
esmiwa | 0:5bf7e3564c3b | 5 | * Buffered serial class. |
esmiwa | 0:5bf7e3564c3b | 6 | */ |
esmiwa | 0:5bf7e3564c3b | 7 | class SerialBuffered : public Serial { |
esmiwa | 0:5bf7e3564c3b | 8 | public: |
esmiwa | 0:5bf7e3564c3b | 9 | /** |
esmiwa | 0:5bf7e3564c3b | 10 | * Create a buffered serial class. |
esmiwa | 0:5bf7e3564c3b | 11 | * |
esmiwa | 0:5bf7e3564c3b | 12 | * @param tx A pin for transmit. |
esmiwa | 0:5bf7e3564c3b | 13 | * @param rx A pin for receive. |
esmiwa | 0:5bf7e3564c3b | 14 | */ |
esmiwa | 0:5bf7e3564c3b | 15 | SerialBuffered(PinName tx, PinName rx); |
esmiwa | 0:5bf7e3564c3b | 16 | |
esmiwa | 0:5bf7e3564c3b | 17 | /** |
esmiwa | 0:5bf7e3564c3b | 18 | * Destroy. |
esmiwa | 0:5bf7e3564c3b | 19 | */ |
esmiwa | 0:5bf7e3564c3b | 20 | virtual ~SerialBuffered(); |
esmiwa | 0:5bf7e3564c3b | 21 | |
esmiwa | 0:5bf7e3564c3b | 22 | /** |
esmiwa | 0:5bf7e3564c3b | 23 | * Get a character. |
esmiwa | 0:5bf7e3564c3b | 24 | * |
esmiwa | 0:5bf7e3564c3b | 25 | * @return A character. (-1:timeout) |
esmiwa | 0:5bf7e3564c3b | 26 | */ |
esmiwa | 0:5bf7e3564c3b | 27 | int getc(); |
esmiwa | 0:5bf7e3564c3b | 28 | |
esmiwa | 0:5bf7e3564c3b | 29 | /** |
esmiwa | 0:5bf7e3564c3b | 30 | * Returns 1 if there is a character available to read, 0 otherwise. |
esmiwa | 0:5bf7e3564c3b | 31 | */ |
esmiwa | 0:5bf7e3564c3b | 32 | int readable(); |
esmiwa | 0:5bf7e3564c3b | 33 | |
esmiwa | 0:5bf7e3564c3b | 34 | /** |
esmiwa | 0:5bf7e3564c3b | 35 | * Set timeout for getc(). |
esmiwa | 0:5bf7e3564c3b | 36 | * |
esmiwa | 0:5bf7e3564c3b | 37 | * @param ms milliseconds. (-1:Disable timeout) |
esmiwa | 0:5bf7e3564c3b | 38 | */ |
esmiwa | 0:5bf7e3564c3b | 39 | void setTimeout(int ms); |
esmiwa | 0:5bf7e3564c3b | 40 | |
esmiwa | 0:5bf7e3564c3b | 41 | /** |
esmiwa | 0:5bf7e3564c3b | 42 | * Read requested bytes. |
esmiwa | 0:5bf7e3564c3b | 43 | * |
esmiwa | 0:5bf7e3564c3b | 44 | * @param bytes A pointer to a buffer. |
esmiwa | 0:5bf7e3564c3b | 45 | * @param requested Length. |
esmiwa | 0:5bf7e3564c3b | 46 | * |
esmiwa | 0:5bf7e3564c3b | 47 | * @return Readed byte length. |
esmiwa | 0:5bf7e3564c3b | 48 | */ |
esmiwa | 0:5bf7e3564c3b | 49 | size_t readBytes(uint8_t *bytes, size_t requested); |
esmiwa | 0:5bf7e3564c3b | 50 | |
esmiwa | 0:5bf7e3564c3b | 51 | private: |
esmiwa | 0:5bf7e3564c3b | 52 | void handleInterrupt(); |
esmiwa | 0:5bf7e3564c3b | 53 | static const int BUFFERSIZE = 4096; |
esmiwa | 0:5bf7e3564c3b | 54 | uint8_t buffer[BUFFERSIZE]; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end |
esmiwa | 0:5bf7e3564c3b | 55 | uint16_t indexContentStart; // index of first bytes of content |
esmiwa | 0:5bf7e3564c3b | 56 | uint16_t indexContentEnd; // index of bytes after last byte of content |
esmiwa | 0:5bf7e3564c3b | 57 | int timeout; |
esmiwa | 0:5bf7e3564c3b | 58 | Timer timer; |
esmiwa | 0:5bf7e3564c3b | 59 | }; |
esmiwa | 0:5bf7e3564c3b | 60 | |
esmiwa | 0:5bf7e3564c3b | 61 | #endif |