Alex Borisevich
/
OpenBCI
OpenBCI 32bit board variation with STM32L476 mircocontroller and mbed support
SerialBuffered.h@1:4683702d7ad8, 2017-01-22 (annotated)
- Committer:
- akpc806a
- Date:
- Sun Jan 22 04:10:11 2017 +0000
- Revision:
- 1:4683702d7ad8
OpenBCI 32bit board variation with STM32L476 mircocontroller and mbed support. Version V2 of firmware, forked from the same official version for the PIC32 board.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akpc806a | 1:4683702d7ad8 | 1 | #pragma once |
akpc806a | 1:4683702d7ad8 | 2 | |
akpc806a | 1:4683702d7ad8 | 3 | // This is a buffered serial reading class, using the serial interrupt introduced in mbed library version 18 on 17/11/09 |
akpc806a | 1:4683702d7ad8 | 4 | |
akpc806a | 1:4683702d7ad8 | 5 | // In the simplest case, construct it with a buffer size at least equal to the largest message you |
akpc806a | 1:4683702d7ad8 | 6 | // expect your program to receive in one go. |
akpc806a | 1:4683702d7ad8 | 7 | |
akpc806a | 1:4683702d7ad8 | 8 | class SerialBuffered : public RawSerial |
akpc806a | 1:4683702d7ad8 | 9 | { |
akpc806a | 1:4683702d7ad8 | 10 | public: |
akpc806a | 1:4683702d7ad8 | 11 | SerialBuffered( size_t bufferSize, PinName tx, PinName rx, int baud ); |
akpc806a | 1:4683702d7ad8 | 12 | virtual ~SerialBuffered(); |
akpc806a | 1:4683702d7ad8 | 13 | |
akpc806a | 1:4683702d7ad8 | 14 | int getc(); // will block till the next character turns up, or return -1 if there is a timeout |
akpc806a | 1:4683702d7ad8 | 15 | |
akpc806a | 1:4683702d7ad8 | 16 | int readable(); // returns 1 if there is a character available to read, 0 otherwise |
akpc806a | 1:4683702d7ad8 | 17 | |
akpc806a | 1:4683702d7ad8 | 18 | void setTimeout( float seconds ); // maximum time in seconds that getc() should block |
akpc806a | 1:4683702d7ad8 | 19 | // while waiting for a character |
akpc806a | 1:4683702d7ad8 | 20 | // Pass -1 to disable the timeout. |
akpc806a | 1:4683702d7ad8 | 21 | |
akpc806a | 1:4683702d7ad8 | 22 | size_t readBytes( uint8_t *bytes, size_t requested ); // read requested bytes into a buffer, |
akpc806a | 1:4683702d7ad8 | 23 | // return number actually read, |
akpc806a | 1:4683702d7ad8 | 24 | // which may be less than requested if there has been a timeout |
akpc806a | 1:4683702d7ad8 | 25 | |
akpc806a | 1:4683702d7ad8 | 26 | |
akpc806a | 1:4683702d7ad8 | 27 | private: |
akpc806a | 1:4683702d7ad8 | 28 | |
akpc806a | 1:4683702d7ad8 | 29 | void handleInterrupt(); |
akpc806a | 1:4683702d7ad8 | 30 | |
akpc806a | 1:4683702d7ad8 | 31 | |
akpc806a | 1:4683702d7ad8 | 32 | 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 |
akpc806a | 1:4683702d7ad8 | 33 | uint16_t m_contentStart; // index of first bytes of content |
akpc806a | 1:4683702d7ad8 | 34 | uint16_t m_contentEnd; // index of bytes after last byte of content |
akpc806a | 1:4683702d7ad8 | 35 | uint16_t m_buffSize; |
akpc806a | 1:4683702d7ad8 | 36 | float m_timeout; |
akpc806a | 1:4683702d7ad8 | 37 | Timer m_timer; |
akpc806a | 1:4683702d7ad8 | 38 | |
akpc806a | 1:4683702d7ad8 | 39 | }; |