Skip to content

Commit 5c5b8ea

Browse files
committed
Documented methods
1 parent f362abb commit 5c5b8ea

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

RingBuf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ bool RingBuf<Type, MaxElements>::isEmpty()
5555
}
5656

5757
template <typename Type, uint16_t MaxElements>
58-
Type *RingBuf<Type, MaxElements>::peek(uint16_t index)
58+
Type *RingBuf<Type, MaxElements>::peek(uint16_t num)
5959
{
60-
if (index >= numElements)
60+
if (num >= numElements)
6161
return NULL;
6262

63-
return &_buf[(getTail() + index)%MaxElements];
63+
return &_buf[(getTail() + num)%MaxElements];
6464
}
6565

6666
template <typename Type, uint16_t MaxElements>

RingBuf.h

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#endif
3030

3131
#define RB_ATOMIC_START do { uint32_t _savedIS = xt_rsil(15) ;
32-
#define RB_ATOMIC_END xt_wsr_ps(_savedIS) ;} while(0);
32+
#define RB_ATOMIC_END xt_wsr_ps(_savedIS); } while(0);
3333

3434
#else
3535
#define RB_ATOMIC_START {
@@ -53,24 +53,50 @@ class RingBuf
5353

5454
RingBuf();
5555

56+
/**
57+
* Add element obj to the buffer
58+
* Return: true on success
59+
*/
5660
bool add(Type &obj);
5761

62+
/**
63+
* Remove last element from buffer, and copy it to dest
64+
* Return: true on success
65+
*/
5866
bool pull(Type *dest);
5967

68+
/**
69+
* Peek at num'th element in the buffer
70+
* Return: a pointer to the num'th element
71+
*/
72+
Type *peek(uint16_t num);
73+
74+
/**
75+
* Return: true if buffer is full
76+
*/
6077
bool isFull();
6178

79+
/**
80+
* Return: number of elements in buffer
81+
*/
6282
uint16_t numElements();
6383

84+
/**
85+
* Return: true if buffer is empty
86+
*/
6487
bool isEmpty();
6588

66-
Type *peek(uint16_t index);
67-
6889
protected:
90+
/**
91+
* Calculates the index in the array of the oldest element
92+
* Return: index in array of element
93+
*/
6994
uint16_t getTail();
7095

96+
// underlying array
7197
Type _buf[MaxElements];
72-
uint16_t _head;
7398

99+
uint16_t _head;
74100
uint16_t _numElements;
75101
private:
76102

0 commit comments

Comments
 (0)