17 #ifndef __AXI_T_MASTER_FROM_FILE__ 18 #define __AXI_T_MASTER_FROM_FILE__ 20 #include <nvhls_int.h> 22 #include <ac_reset_signal_is.h> 25 #include <axi/testbench/CSVFileReader.h> 26 #include <nvhls_connections.h> 27 #include <hls_globals.h> 34 #include <boost/assert.hpp> 57 template <
typename axiCfg,
bool enable_
interrupts = false>
class MasterFromFile :
public sc_module {
59 static const int kDebugLevel = 0;
62 typename axi4_::read::template master<> if_rd;
63 typename axi4_::write::template master<> if_wr;
65 sc_in<bool> reset_bar;
70 static const int bytesPerBeat = axi4_::DATA_WIDTH >> 3;
71 static const int bytesPerWord = axi4_::DATA_WIDTH >> 3;
74 std::queue< int > delay_q;
75 std::queue< int > req_q;
76 std::queue< typename axi4_::AddrPayload > raddr_q;
77 std::queue< typename axi4_::AddrPayload > waddr_q;
78 std::queue< typename axi4_::WritePayload > wdata_q;
79 std::queue<typename axi4_::Data> rresp_q;
91 MasterFromFile(sc_module_name name_, std::string filename=
"requests.csv")
92 : sc_module(name_), if_rd(
"if_rd"), if_wr(
"if_wr"), reset_bar(
"reset_bar"), clk(
"clk") {
94 CDCOUT(
"Reading file: " << filename << endl, kDebugLevel);
96 std::vector< std::vector<std::string> > dataList = reader.readCSV();
97 for (
unsigned int i=0; i < dataList.size(); i++) {
98 std::vector<std::string> vec = dataList[i];
100 delay_q.push(atoi(vec[0].c_str()));
103 std::stringstream ss;
104 sc_uint<axi4_::ADDR_WIDTH> addr;
107 addr_pld.addr =
static_cast<typename axi4_::Addr
>(addr);
109 raddr_q.push(addr_pld);
110 std::stringstream ss_data;
111 sc_biguint<axi4_::DATA_WIDTH> data;
112 ss_data << hex << vec[3];
114 rresp_q.push(TypeToNVUINT(data));
115 }
else if (vec[1] ==
"W") {
117 std::stringstream ss;
118 sc_uint<axi4_::ADDR_WIDTH> addr;
121 addr_pld.addr =
static_cast<typename axi4_::Addr
>(addr);
123 waddr_q.push(addr_pld);
124 std::stringstream ss_data;
125 sc_biguint<axi4_::DATA_WIDTH> data;
126 ss_data << hex << vec[3];
128 wr_data_pld.data = TypeToNVUINT(data);
129 wr_data_pld.wstrb = ~0;
130 wr_data_pld.last = 1;
131 wdata_q.push(wr_data_pld);
132 }
else if (vec[1] ==
"Q") {
133 NVHLS_ASSERT_MSG(enable_interrupts,
"Interrupt command read, but interrupts are not enabled");
141 sensitive << clk.pos();
142 async_reset_signal_is(reset_bar,
false);
155 while (!delay_q.empty()) {
156 int delay = delay_q.front();
157 if (delay > 0) wait(delay);
159 if (req_q.front() == 2) {
160 NVHLS_ASSERT_MSG(enable_interrupts,
"Interrupt command found, but interrupts are not enabled");
161 CDCOUT(sc_time_stamp() <<
" " << name() <<
" Beginning wait for interrupt" 162 << endl, kDebugLevel);
163 while (interrupt.read() == 0) wait();
164 CDCOUT(sc_time_stamp() <<
" " << name() <<
" Interrupt received" 165 << endl, kDebugLevel);
166 }
else if (req_q.front() == 1) {
167 addr_pld = waddr_q.front();
168 if_wr.aw.Push(addr_pld);
170 wr_data_pld = wdata_q.front();
171 if_wr.w.Push(wr_data_pld);
174 CDCOUT(sc_time_stamp() <<
" " << name() <<
" Sent write request:" 175 <<
" addr=[" << addr_pld <<
"]" 176 <<
" data=[" << wr_data_pld <<
"]" 177 << endl, kDebugLevel);
179 addr_pld = raddr_q.front();
180 if_rd.ar.Push(addr_pld);
182 CDCOUT(sc_time_stamp() <<
" " << name() <<
" Sent read request: " 184 << endl, kDebugLevel);
185 data_pld = if_rd.r.Pop();
186 CDCOUT(sc_time_stamp() <<
" " << name() <<
" Received read response: [" 188 << endl, kDebugLevel);
189 NVHLS_ASSERT_MSG(data_pld.data == rresp_q.front(),
"Read response did not match expected value");
A struct composed of the signals associated with an AXI write response.
A struct composed of the signals associated with AXI write data.
A struct composed of the signals associated with AXI read and write requests.
A struct composed of the signals associated with an AXI read response.
The base axi4 class parameterized according a valid config.
Compute Celing of log2 of a constant.
An AXI master that generates traffic according to a file for use in testbenches.
#define NVHLS_ASSERT_MSG(X, MSG)
A helper class to read CSV files.