stipcores library
Collection of Software Drivers for Hardware IP Cores for the Panoradio SDR
Axis_FIFO.h
1 #ifndef AXIS_FIFO_H
2 #define AXIS_FIFO_H
3 
4 /*
5  -------------------------------------------------------
6  AXIS_FIFO.h
7  C++ class for the Xilinx AXIS FIFO
8  Stefan Scholl, DC9ST, TU Kaiserslautern, 2014
9  -------------------------------------------------------
10 */
11 
12 #include "IP_Driver.h"
13 #include <iostream>
14 
15 using namespace std;
16 
18 class AXIS_FIFO {
19 
20 private:
21 
23  void wait_ms(int t_ms) {
24 
25  volatile int a = 0;
26 
27  for (int j=0; j < t_ms; j++)
28  for (int i=0; i<50000; i++)
29  a += 1;
30  };
31 
32 
33  IP_Driver *axis_fifo_core_;
34 
35  int depth_; // FIFO depth
36  int empty_threshold_;
37  int full_threshold_;
38 
39 public:
45  AXIS_FIFO(int base_address, int size_in_k, int depth) {
46  axis_fifo_core_ = new IP_Driver(base_address, size_in_k);
47  depth_ = depth;
48  empty_threshold_ = 0;
49  full_threshold_ = depth;
50  }
51 
52 
55  delete axis_fifo_core_;
56  }
57 
58 
60  void reset() {
61  axis_fifo_core_ -> write(0x18,0xa5);
62  }
63 
64 
68  int read_single_data(int &data) {
69  if (get_fifo_occupancy() <= empty_threshold_) return -1;
70  data = axis_fifo_core_ -> read(0x20);
71  return 0;
72  }
73 
74 
79  int read_block_data(int data[], int size) {
80  if (get_fifo_occupancy() < (size + empty_threshold_)) return -1;
81 
82  for (int j=0; j< 50; j++)
83  data[j] = axis_fifo_core_ -> read(0x20);
84 
85  return 0;
86  }
87 
88 
92  return axis_fifo_core_ -> read(0x1C);
93  }
94 
95 
98  bool is_full() {
99  if (axis_fifo_core_ -> read(0x1C) >= full_threshold_)
100  return true;
101  else
102  return false;
103  }
104 
105 
108  bool is_empty() {
109  if (axis_fifo_core_ -> read(0x1C) <= empty_threshold_)
110  return true;
111  else
112  return false;
113  }
114 
115 };
116 
117 #endif /* AXIS_FIFO_H */
~AXIS_FIFO()
class deconstructor
Definition: Axis_FIFO.h:54
bool is_empty()
checks if FIFO is empty
Definition: Axis_FIFO.h:108
void reset()
resets the FIFO
Definition: Axis_FIFO.h:60
Generic IP Driver Class Class, that allows access to a AXI Lite IP core over the Zynq Memory Mapped I...
Definition: IP_Driver.h:14
int read_block_data(int data[], int size)
reads a block of data (32 bit/word) out of the FIFO
Definition: Axis_FIFO.h:79
int get_fifo_occupancy()
reads the number of available samples
Definition: Axis_FIFO.h:91
int read_single_data(int &data)
reads one data (1 sample, 32 bit) out of the FIFO
Definition: Axis_FIFO.h:68
Class for the.
Definition: Axis_FIFO.h:18
AXIS_FIFO(int base_address, int size_in_k, int depth)
class constructor
Definition: Axis_FIFO.h:45
bool is_full()
checks if FIFO is full
Definition: Axis_FIFO.h:98