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: SDFileSystem mbed
RingBuffer.cpp
00001 #include "RingBuffer.h" 00002 00003 void RingBuffer::initialize_buffer(){ 00004 start=0; 00005 end=0; 00006 } 00007 00008 int16_t RingBuffer::buffer_size(){ 00009 if(end >= start){ 00010 return end - start; 00011 } 00012 return RING_BUFFER_SIZE - (start - end); 00013 } 00014 00015 uint8_t RingBuffer::read_buffer_byte(){ 00016 uint8_t a; 00017 a=buffer[start]; 00018 start=(start+1)%RING_BUFFER_SIZE; 00019 return a; 00020 } 00021 00022 int16_t RingBuffer::read_buffer_short(){ 00023 int16_t a, b; 00024 a=buffer[start]; 00025 b=buffer[(start+1)%RING_BUFFER_SIZE]; 00026 start=(start+2)%RING_BUFFER_SIZE; 00027 return (a&0xff)|(b<<8); 00028 } 00029 00030 void RingBuffer::read_buffer(uint8_t buf[], int16_t offset, int16_t size){ 00031 int16_t i; 00032 uint8_t* p=buf+offset; 00033 00034 for(i=0; i<size; i++){ 00035 *(p++)=buffer[start]; 00036 start=(start+1)%RING_BUFFER_SIZE; 00037 } 00038 } 00039 00040 int16_t RingBuffer::buffer_capacity(){ 00041 if(end >= start){ 00042 return RING_BUFFER_SIZE-(end-start)-1; 00043 } 00044 return (start-end)-1; 00045 } 00046 00047 void RingBuffer::write_buffer_byte(uint8_t ch){ 00048 buffer[end]=ch; 00049 end=(end+1)%RING_BUFFER_SIZE; 00050 } 00051 00052 void RingBuffer::write_buffer(const uint8_t buf[], int16_t offset, int16_t size){ 00053 int16_t i; 00054 const uint8_t* p=buf+offset; 00055 for(i=0; i<size; i++){ 00056 buffer[end]=*(p++); 00057 end=(end+1)%RING_BUFFER_SIZE; 00058 } 00059 } 00060 00061 bool RingBuffer::is_buffer_empty(){ 00062 return (start==end); 00063 }
Generated on Tue Jul 12 2022 18:37:36 by
1.7.2