| 11 | #define DEFAULT_CBB_BLOCK_SIZE 1024 |
| 12 | |
| 13 | class CircularBlockBuffer { |
| 14 | public: |
| 15 | CircularBlockBuffer(); |
| 16 | explicit CircularBlockBuffer(int blockSize, int totalSize); |
| 17 | ~CircularBlockBuffer(); |
| 18 | |
| 19 | void set_buffer(uint8_t * buffer, int blockSize, int blockCount); |
| 20 | |
| 21 | void setSizes(int blockSize, int blockCount); |
| 22 | uint8_t * get_buffer(); |
| 23 | |
| 24 | size_t getTotalSize() const; |
| 25 | size_t getBlockSize() const; |
| 26 | size_t getBlockCount() const; |
| 27 | |
| 28 | void reset(); |
| 29 | void clear(); |
| 30 | |
| 31 | uint8_t * const getWritePointer(int n = 0); |
| 32 | uint8_t * const getReadPointer(int n = 0); |
| 33 | |
| 34 | int get_contiguous_read_blocks() const; |
| 35 | int get_contiguous_write_blocks() const; |
| 36 | |
| 37 | void incrementWritePointer(int n = 1, bool blocking = false); |
| 38 | void incrementReadPointer(int n = 1, bool blocking = false); |
| 39 | |
| 40 | int available_read() const; // Blocks available to read until underflow |
| 41 | int available_write() const; // Blocks available to write until overflow |
| 42 | |
| 43 | int get_num_underflow() const; |
| 44 | int get_num_overflow() const; |
| 45 | |
| 46 | private: |
| 47 | bool _external_buffer = false; |
| 48 | uint8_t* _buffer __attribute__((aligned (16))); |
| 49 | |
| 50 | size_t _blockCount{}; |
| 51 | size_t _blockSize{}; |
| 52 | int _totalSize{}; |
| 53 | |
| 54 | volatile int _readBlock{}; |
| 55 | volatile int _writeBlock{}; |
| 56 | |
| 57 | volatile int _reserve_write = 0; |
| 58 | volatile int _reserve_read = 0; |
| 59 | volatile int _reserve_write_total = 0; |
| 60 | volatile int _reserve_read_total = 0; |
| 61 | |
| 62 | volatile int _underflow_count = 0; |
| 63 | volatile int _overflow_count = 0; |
| 64 | |
| 65 | volatile int _buffer_fill = 0; |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | #endif //CIRCULAR_BLOCKBUFFER_H |
nothing calls this directly
no outgoing calls
no test coverage detected