REGISTER should be ready for tests
This commit is contained in:
+16
-4
@@ -21,6 +21,8 @@
|
||||
#ifndef _FIFO_H_
|
||||
#define _FIFO_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
template <class T, int N>
|
||||
class Fifo
|
||||
{
|
||||
@@ -40,13 +42,18 @@ class Fifo
|
||||
|
||||
void push(T element)
|
||||
{
|
||||
uint32_t next = (widx+1) & (N-1);
|
||||
uint32_t next = nextIndex(widx);
|
||||
if (next != ridx) {
|
||||
fifo[widx] = element;
|
||||
widx = next;
|
||||
}
|
||||
}
|
||||
|
||||
void skip()
|
||||
{
|
||||
ridx = nextIndex(ridx);
|
||||
}
|
||||
|
||||
bool pop(T & element)
|
||||
{
|
||||
if (isEmpty()) {
|
||||
@@ -54,7 +61,7 @@ class Fifo
|
||||
}
|
||||
else {
|
||||
element = fifo[ridx];
|
||||
ridx = (ridx+1) & (N-1);
|
||||
ridx = nextIndex(ridx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -66,7 +73,7 @@ class Fifo
|
||||
|
||||
bool isFull()
|
||||
{
|
||||
uint32_t next = (widx+1) & (N-1);
|
||||
uint32_t next = nextIndex(widx);
|
||||
return (next == ridx);
|
||||
}
|
||||
|
||||
@@ -77,7 +84,7 @@ class Fifo
|
||||
|
||||
uint32_t size() const
|
||||
{
|
||||
return (N + widx - ridx) & (N-1);
|
||||
return (N + widx - ridx) & (N - 1);
|
||||
}
|
||||
|
||||
uint32_t hasSpace(uint32_t n) const
|
||||
@@ -100,6 +107,11 @@ class Fifo
|
||||
T fifo[N];
|
||||
volatile uint32_t widx;
|
||||
volatile uint32_t ridx;
|
||||
|
||||
inline uint32_t nextIndex(uint32_t idx)
|
||||
{
|
||||
return (idx + 1) & (N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _FIFO_H_
|
||||
|
||||
Reference in New Issue
Block a user