13 #ifndef _SMING_CORE_DATA_BUFFER_SERIAL_BUFFER_H_ 14 #define _SMING_CORE_DATA_BUFFER_SERIAL_BUFFER_H_ 16 #include <user_config.h> 40 int ret = writePos - readPos;
52 if(buffer ==
nullptr) {
55 int ret = readPos - writePos - 1;
62 __forceinline
bool isEmpty()
64 return (buffer ==
nullptr) || (writePos == readPos);
67 __forceinline
bool isFull()
77 return isEmpty() ? -1 : buffer[readPos];
83 __forceinline
int peekLastChar()
85 return isEmpty() ? -1 : buffer[getPrevPos(writePos)];
88 __forceinline
int readChar()
94 uint8_t c = buffer[readPos];
95 readPos = getNextPos(readPos);
99 __forceinline
size_t writeChar(uint8_t c)
101 size_t nextPos = getNextPos(writePos);
102 if(nextPos == readPos) {
106 buffer[writePos] = c;
118 size_t resize(
size_t newSize);
122 readPos = writePos = 0;
131 data = buffer + readPos;
133 return (wp < readPos) ? size - readPos : wp - readPos;
143 if(readPos == size) {
150 __forceinline
size_t getNextPos(
size_t pos)
153 return (n == size) ? 0 : n;
157 __forceinline
size_t getPrevPos(
size_t pos)
159 return (pos != 0 ? pos : size) - 1;
166 char* buffer =
nullptr;
169 #endif // _SMING_CORE_DATA_BUFFER_SERIAL_BUFFER_H_ int find(uint8_t c)
find a character in the buffer
__forceinline int peekChar()
see if there's anything in the buffer
Definition: SerialBuffer.h:75
__forceinline size_t available()
get number of bytes stored in the buffer
Definition: SerialBuffer.h:38
FIFO buffer used for both receive and transmit data.
Definition: SerialBuffer.h:23
__forceinline void skipRead(size_t length)
Skip a number of chars starting at the given read position.
Definition: SerialBuffer.h:140
__forceinline size_t getReadData(void *&data)
Access data directly within buffer.
Definition: SerialBuffer.h:129
__forceinline size_t getFreeSpace()
get number of bytes of space available in this buffer
Definition: SerialBuffer.h:50