File tree Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,12 @@ bool RingBuf<Type, MaxElements>::isEmpty()
5555}
5656
5757template <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
6666template <typename Type, uint16_t MaxElements>
Original file line number Diff line number Diff line change 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
5454RingBuf ();
5555
56+ /* *
57+ * Add element obj to the buffer
58+ * Return: true on success
59+ */
5660bool add (Type &obj);
5761
62+ /* *
63+ * Remove last element from buffer, and copy it to dest
64+ * Return: true on success
65+ */
5866bool 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+ */
6077bool isFull ();
6178
79+ /* *
80+ * Return: number of elements in buffer
81+ */
6282uint16_t numElements ();
6383
84+ /* *
85+ * Return: true if buffer is empty
86+ */
6487bool isEmpty ();
6588
66- Type *peek (uint16_t index);
67-
6889protected:
90+ /* *
91+ * Calculates the index in the array of the oldest element
92+ * Return: index in array of element
93+ */
6994uint16_t getTail ();
7095
96+ // underlying array
7197Type _buf[MaxElements];
72- uint16_t _head;
7398
99+ uint16_t _head;
74100uint16_t _numElements;
75101private:
76102
You can’t perform that action at this time.
0 commit comments