OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [socsim_plugin/] [fifo.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief          FIFO implementation.
6
 */
7
 
8
#ifndef __DEBUGGER_FIFO_H__
9
#define __DEBUGGER_FIFO_H__
10
 
11
#include <inttypes.h>
12
 
13
namespace debugger {
14
 
15
template<class T> class TFifo {
16
public:
17
    TFifo(int sz) {
18
        arr_ = new T[size_ = sz];
19
        prd_ = &arr_[0];
20
        pwr_ = &arr_[1];
21
    }
22
    ~TFifo() {
23
        delete [] arr_;
24
    }
25
    bool isFull() {
26
        return pwr_ == prd_;
27
    }
28
    bool isEmpty() {
29
        if (pwr_ == (prd_ + 1)) {
30
            return true;
31
        }
32
        if ((prd_ - pwr_ + 1) == size_) {
33
            return true;
34
        }
35
        return false;
36
    }
37
    void get(T *out) {
38
        if (isEmpty()) {
39
            return;
40
        }
41
        if (prd_ >= &arr_[size_ - 1]) {
42
            *out = arr_[0];
43
            prd_ = arr_;
44
        } else {
45
            *out = prd_[1];
46
            prd_++;
47
        }
48
    }
49
    void put(T *in) {
50
        if (isFull()) {
51
            return;
52
        }
53
        *pwr_ = *in;
54
        if (pwr_ >= &arr_[size_ - 1]) {
55
            pwr_ = arr_;
56
        } else {
57
            pwr_++;
58
        }
59
    }
60
private:
61
    T *arr_;
62
    T *prd_;
63
    T *pwr_;
64
    int size_;
65
};
66
 
67
}  // namespace debugger
68
 
69
#endif  // __DEBUGGER_FIFO_H__

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.