Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
scIGPfifo.h
Go to the documentation of this file.
1 
5  /* @author János Végh (jvegh)
6  * @bug No known bugs.
7  */
8 
9 #ifndef scIGPfifo_h
10 #define scIGPfifo_h
11 
12 #include <systemc>
13 //#include "BasicConfig.h"
14 using namespace std;
15 using namespace sc_core;
16 using namespace sc_dt;
17 
18 class scIGPwrite_if : virtual public sc_interface
19 {
20  public:
21  virtual void write(int32_t) = 0;
22  virtual void reset() = 0;
23 };
24 
25 class scIGPread_if : virtual public sc_interface
26 {
27  public:
28  virtual void read(int32_t &) = 0;
29  virtual int num_available() = 0;
30 };
31 
40 class scIGPfifo : public sc_channel, public scIGPwrite_if, public scIGPread_if
41 {
42  public:
43  scIGPfifo(sc_module_name name) : sc_channel(name), num_elements(0), first(0) {}
44 
45  void write(int32_t c) {
46  if (num_elements == max)
47  wait(scIGPread_event);
48 
49  data[(first + num_elements) % max] = c;
50  ++ num_elements;
51  scIGPwrite_event.notify();
52  }
53 
54  void read(int32_t &c){
55  if (num_elements == 0)
56  wait(scIGPwrite_event);
57 
58  c = data[first];
59  -- num_elements;
60  first = (first + 1) % max;
61  scIGPread_event.notify();
62  }
63 
64  void reset() { num_elements = first = 0; }
65 
66  int num_available() { return num_elements;}
67 
68  private:
69  enum e { max = 10 };
70  int32_t data[max];
71  uint16_t num_elements, first;
72  sc_event scIGPwrite_event, scIGPread_event;
73 };
74 
75 #endif //scIGPfifo_h
scIGPfifo
Definition: scIGPfifo.h:40