URL
https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk
Only display areas with differences |
Details |
Blame |
View Log
Rev 2 |
Rev 4 |
/**
|
/**
|
* @file
|
* @file
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
* @brief FIFO implementation.
|
* @brief FIFO implementation.
|
*/
|
*/
|
|
|
#ifndef __DEBUGGER_FIFO_H__
|
#ifndef __DEBUGGER_FIFO_H__
|
#define __DEBUGGER_FIFO_H__
|
#define __DEBUGGER_FIFO_H__
|
|
|
#include <inttypes.h>
|
#include <inttypes.h>
|
|
|
namespace debugger {
|
namespace debugger {
|
|
|
template<class T> class TFifo {
|
template<class T> class TFifo {
|
public:
|
public:
|
TFifo(int sz) {
|
TFifo(int sz) {
|
arr_ = new T[size_ = sz];
|
arr_ = new T[size_ = sz];
|
prd_ = &arr_[0];
|
prd_ = &arr_[0];
|
pwr_ = &arr_[1];
|
pwr_ = &arr_[1];
|
}
|
}
|
~TFifo() {
|
~TFifo() {
|
delete [] arr_;
|
delete [] arr_;
|
}
|
}
|
bool isFull() {
|
bool isFull() {
|
return pwr_ == prd_;
|
return pwr_ == prd_;
|
}
|
}
|
bool isEmpty() {
|
bool isEmpty() {
|
if (pwr_ == (prd_ + 1)) {
|
if (pwr_ == (prd_ + 1)) {
|
return true;
|
return true;
|
}
|
}
|
if ((prd_ - pwr_ + 1) == size_) {
|
if ((prd_ - pwr_ + 1) == size_) {
|
return true;
|
return true;
|
}
|
}
|
return false;
|
return false;
|
}
|
}
|
void get(T *out) {
|
void get(T *out) {
|
if (isEmpty()) {
|
if (isEmpty()) {
|
return;
|
return;
|
}
|
}
|
if (prd_ >= &arr_[size_ - 1]) {
|
if (prd_ >= &arr_[size_ - 1]) {
|
*out = arr_[0];
|
*out = arr_[0];
|
prd_ = arr_;
|
prd_ = arr_;
|
} else {
|
} else {
|
*out = prd_[1];
|
*out = prd_[1];
|
prd_++;
|
prd_++;
|
}
|
}
|
}
|
}
|
void put(T *in) {
|
void put(T *in) {
|
if (isFull()) {
|
if (isFull()) {
|
return;
|
return;
|
}
|
}
|
*pwr_ = *in;
|
*pwr_ = *in;
|
if (pwr_ >= &arr_[size_ - 1]) {
|
if (pwr_ >= &arr_[size_ - 1]) {
|
pwr_ = arr_;
|
pwr_ = arr_;
|
} else {
|
} else {
|
pwr_++;
|
pwr_++;
|
}
|
}
|
}
|
}
|
private:
|
private:
|
T *arr_;
|
T *arr_;
|
T *prd_;
|
T *prd_;
|
T *pwr_;
|
T *pwr_;
|
int size_;
|
int size_;
|
};
|
};
|
|
|
} // namespace debugger
|
} // namespace debugger
|
|
|
#endif // __DEBUGGER_FIFO_H__
|
#endif // __DEBUGGER_FIFO_H__
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.