2022-10-02 08:14:58 +02:00
|
|
|
|
2022-10-02 11:39:06 +02:00
|
|
|
#include "testbench.h"
|
2022-10-02 08:14:58 +02:00
|
|
|
#include <factory.h>
|
2022-10-02 11:39:06 +02:00
|
|
|
#include <tlm/scc/tlm_gp_shared.h>
|
2022-10-02 18:20:00 +02:00
|
|
|
#undef CHECK
|
2022-10-02 08:14:58 +02:00
|
|
|
#include <catch2/catch_all.hpp>
|
2022-10-02 18:20:00 +02:00
|
|
|
#include <unordered_map>
|
2022-10-02 08:14:58 +02:00
|
|
|
|
|
|
|
using namespace sc_core;
|
|
|
|
|
2022-10-02 11:39:06 +02:00
|
|
|
factory::add<testbench> tb;
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
bool is_equal(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload const& b) {
|
2022-10-02 11:39:06 +02:00
|
|
|
auto ret = true;
|
|
|
|
ret &= a.get_command() == b.get_command();
|
|
|
|
ret &= a.get_address() == b.get_address();
|
|
|
|
ret &= a.get_data_length() == b.get_data_length();
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto i = 0u; i < a.get_data_length(); ++i)
|
2022-10-02 11:39:06 +02:00
|
|
|
ret &= a.get_data_ptr()[i] == b.get_data_ptr()[i];
|
2022-10-02 18:20:00 +02:00
|
|
|
// if(a.get_byte_enable_ptr() && b.get_byte_enable_ptr()) {
|
|
|
|
// ret &= a.get_byte_enable_length() == b.get_byte_enable_length();
|
|
|
|
// for(auto i=0u; i<a.get_byte_enable_length(); ++i)
|
|
|
|
// ret &= a.get_byte_enable_ptr()[i] == b.get_byte_enable_ptr()[i];
|
|
|
|
// }
|
2022-10-02 11:39:06 +02:00
|
|
|
ret &= a.get_command() == b.get_command();
|
2023-12-22 20:42:21 +01:00
|
|
|
// if(!ret) SCCWARN()<<"Comparison failed: "<<a<<" and "<<b;
|
2022-10-02 11:39:06 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
template <typename bus_cfg>
|
2022-10-03 11:26:29 +02:00
|
|
|
tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned addr_incr, unsigned len, unsigned width, unsigned id) {
|
2022-10-02 08:14:58 +02:00
|
|
|
auto trans = tlm::scc::tlm_mm<>::get().allocate<axi::axi4_extension>(len);
|
|
|
|
trans->set_address(start_address);
|
|
|
|
tlm::scc::setId(*trans, id);
|
|
|
|
auto ext = trans->get_extension<axi::axi4_extension>();
|
|
|
|
trans->set_data_length(len);
|
|
|
|
trans->set_streaming_width(len);
|
2022-10-02 18:20:00 +02:00
|
|
|
ext->set_size(scc::ilog2(width));
|
2022-10-02 08:14:58 +02:00
|
|
|
sc_assert(len < (bus_cfg::BUSWIDTH / 8) || len % (bus_cfg::BUSWIDTH / 8) == 0);
|
2023-12-22 20:42:21 +01:00
|
|
|
auto length = (len * 8 - 1) / (8 * width);
|
|
|
|
if(width == (bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8))
|
2022-10-02 08:14:58 +02:00
|
|
|
length++;
|
|
|
|
ext->set_length(length);
|
|
|
|
// ext->set_burst(len * 8 > bus_cfg::buswidth ? axi::burst_e::INCR : axi::burst_e::FIXED);
|
|
|
|
ext->set_burst(axi::burst_e::INCR);
|
2022-10-02 18:20:00 +02:00
|
|
|
ext->set_id(id);
|
2022-10-02 08:14:58 +02:00
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void randomize(tlm::tlm_generic_payload& gp) {
|
2023-12-22 20:42:21 +01:00
|
|
|
static uint8_t req_cnt{0};
|
2022-10-02 08:14:58 +02:00
|
|
|
for(size_t i = 0; i < gp.get_data_length(); ++i) {
|
|
|
|
*(gp.get_data_ptr() + i) = i % 2 ? i : req_cnt;
|
|
|
|
}
|
|
|
|
req_cnt++;
|
|
|
|
}
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
template <typename STATE> unsigned run_scenario(STATE& state) {
|
2022-10-02 08:14:58 +02:00
|
|
|
auto& dut = factory::get<testbench>();
|
2022-10-02 11:39:06 +02:00
|
|
|
dut.tgt_pe.set_operation_cb([&state](axi::axi_protocol_types::tlm_payload_type& trans) -> unsigned {
|
2022-10-02 18:20:00 +02:00
|
|
|
auto id = axi::get_axi_id(trans);
|
|
|
|
if(trans.is_read()) {
|
|
|
|
for(size_t i = 0; i < trans.get_data_length(); ++i) {
|
2023-12-22 20:42:21 +01:00
|
|
|
*(trans.get_data_ptr() + i) = i % 2 ? i : (state.resp_cnt + 128);
|
2022-10-02 18:20:00 +02:00
|
|
|
}
|
|
|
|
state.read_tx[id].second.emplace_back(&trans);
|
2022-10-02 08:14:58 +02:00
|
|
|
}
|
2022-10-02 18:20:00 +02:00
|
|
|
if(trans.is_write())
|
|
|
|
state.write_tx[id].second.emplace_back(&trans);
|
2023-12-22 20:42:21 +01:00
|
|
|
SCCDEBUG(__FUNCTION__) << "RX: " << trans;
|
2022-10-02 11:39:06 +02:00
|
|
|
state.resp_cnt++;
|
2022-10-02 08:14:58 +02:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
dut.rst.write(false);
|
2023-12-22 20:42:21 +01:00
|
|
|
sc_start(state.ResetCycles * dut.clk.period());
|
2022-10-02 08:14:58 +02:00
|
|
|
dut.rst.write(true);
|
2022-10-02 18:20:00 +02:00
|
|
|
sc_start(dut.clk.period());
|
2022-10-02 08:14:58 +02:00
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
auto run1 = sc_spawn([&dut, &state]() {
|
2022-10-02 18:20:00 +02:00
|
|
|
unsigned int StartAddr{0x0};
|
2022-10-02 11:39:06 +02:00
|
|
|
for(int i = 0; i < state.NumberOfIterations; ++i) {
|
2023-12-22 20:42:21 +01:00
|
|
|
tlm::scc::tlm_gp_shared_ptr trans =
|
|
|
|
prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 1);
|
2022-10-03 11:26:29 +02:00
|
|
|
trans->set_command(tlm::TLM_READ_COMMAND);
|
2023-12-22 20:42:21 +01:00
|
|
|
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i << " TX: " << *trans;
|
2022-10-03 11:26:29 +02:00
|
|
|
dut.intor_pe.transport(*trans, false);
|
|
|
|
state.read_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
|
2022-10-02 18:20:00 +02:00
|
|
|
StartAddr += state.BurstSizeBytes;
|
2022-10-02 08:14:58 +02:00
|
|
|
}
|
|
|
|
});
|
2023-12-22 20:42:21 +01:00
|
|
|
auto run2 = sc_spawn([&dut, &state]() {
|
2022-10-03 11:26:29 +02:00
|
|
|
unsigned int StartAddr{0x2000};
|
|
|
|
for(int i = 0; i < state.NumberOfIterations; ++i) {
|
2023-12-22 20:42:21 +01:00
|
|
|
tlm::scc::tlm_gp_shared_ptr trans =
|
|
|
|
prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 2);
|
2022-10-03 11:26:29 +02:00
|
|
|
trans->set_command(tlm::TLM_WRITE_COMMAND);
|
|
|
|
randomize(*trans);
|
2023-12-22 20:42:21 +01:00
|
|
|
SCCDEBUG(__FUNCTION__) << "run2, iteration " << i << " TX: " << *trans;
|
2022-10-03 11:26:29 +02:00
|
|
|
dut.intor_pe.transport(*trans, false);
|
|
|
|
state.write_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
|
|
|
|
StartAddr += state.BurstSizeBytes;
|
|
|
|
}
|
|
|
|
});
|
2023-12-22 20:42:21 +01:00
|
|
|
auto run3 = sc_spawn([&dut, &state]() {
|
2022-10-02 18:20:00 +02:00
|
|
|
unsigned int StartAddr{0x1000};
|
2022-10-02 11:39:06 +02:00
|
|
|
for(int i = 0; i < state.NumberOfIterations; ++i) {
|
2023-12-22 20:42:21 +01:00
|
|
|
tlm::scc::tlm_gp_shared_ptr trans =
|
|
|
|
prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 3);
|
2022-10-03 11:26:29 +02:00
|
|
|
trans->set_command(tlm::TLM_READ_COMMAND);
|
2023-12-22 20:42:21 +01:00
|
|
|
SCCDEBUG(__FUNCTION__) << "run3, iteration " << i << " TX: " << *trans;
|
2022-10-03 11:26:29 +02:00
|
|
|
dut.intor_pe.transport(*trans, false);
|
|
|
|
state.read_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
|
|
|
|
StartAddr += state.BurstSizeBytes;
|
|
|
|
}
|
|
|
|
});
|
2023-12-22 20:42:21 +01:00
|
|
|
auto run4 = sc_spawn([&dut, &state]() {
|
2022-10-03 11:26:29 +02:00
|
|
|
unsigned int StartAddr{0x3000};
|
|
|
|
for(int i = 0; i < state.NumberOfIterations; ++i) {
|
2023-12-22 20:42:21 +01:00
|
|
|
tlm::scc::tlm_gp_shared_ptr trans =
|
|
|
|
prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 4);
|
2022-10-03 11:26:29 +02:00
|
|
|
trans->set_command(tlm::TLM_WRITE_COMMAND);
|
|
|
|
randomize(*trans);
|
2023-12-22 20:42:21 +01:00
|
|
|
SCCDEBUG(__FUNCTION__) << "run4, iteration " << i << " TX: " << *trans;
|
2022-10-03 11:26:29 +02:00
|
|
|
dut.intor_pe.transport(*trans, false);
|
|
|
|
state.write_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
|
2022-10-02 18:20:00 +02:00
|
|
|
StartAddr += state.BurstSizeBytes;
|
2022-10-02 08:14:58 +02:00
|
|
|
}
|
|
|
|
});
|
2022-10-03 11:08:39 +02:00
|
|
|
|
2022-10-03 11:26:29 +02:00
|
|
|
unsigned cycles{0};
|
2023-12-22 20:42:21 +01:00
|
|
|
while(cycles < 1000 && !(run1.terminated() && run2.terminated() && run3.terminated() && run4.terminated())) {
|
2022-10-03 11:26:29 +02:00
|
|
|
sc_start(10 * dut.clk.period());
|
2023-12-22 20:42:21 +01:00
|
|
|
cycles += 10;
|
2022-10-03 11:26:29 +02:00
|
|
|
}
|
|
|
|
return cycles;
|
2022-10-02 18:20:00 +02:00
|
|
|
}
|
|
|
|
|
2024-05-08 17:20:26 +02:00
|
|
|
void axi4_burst_alignment(bool pipelined_wrreq, bool write_bp) {
|
2022-10-03 11:08:39 +02:00
|
|
|
struct {
|
|
|
|
unsigned int ResetCycles{4};
|
|
|
|
unsigned int BurstLengthByte{16};
|
|
|
|
unsigned int BurstSizeBytes{8};
|
|
|
|
unsigned int NumberOfIterations{8};
|
|
|
|
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>> read_tx;
|
2023-12-22 20:42:21 +01:00
|
|
|
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>>
|
|
|
|
write_tx;
|
2022-10-03 11:08:39 +02:00
|
|
|
unsigned resp_cnt{0};
|
|
|
|
} state;
|
|
|
|
|
2024-05-08 17:20:26 +02:00
|
|
|
auto& dut = factory::get<testbench>();
|
|
|
|
dut.intor_bfm.pipelined_wrreq = pipelined_wrreq;
|
2024-12-11 11:03:49 +01:00
|
|
|
dut.tgt_pe.wr_data_accept_delay.set_value(write_bp ? 1 : 0);
|
2022-10-03 11:26:29 +02:00
|
|
|
auto cycles = run_scenario(state);
|
2022-10-03 11:08:39 +02:00
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
REQUIRE(cycles < 1000);
|
2022-10-03 11:08:39 +02:00
|
|
|
REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0);
|
|
|
|
REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0);
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
REQUIRE(state.resp_cnt == 4 * state.NumberOfIterations);
|
|
|
|
for(auto& e : state.write_tx) {
|
2022-10-03 11:08:39 +02:00
|
|
|
auto const& send_tx = e.second.first;
|
|
|
|
auto const& recv_tx = e.second.second;
|
|
|
|
REQUIRE(send_tx.size() == recv_tx.size());
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto i = 0; i < send_tx.size(); ++i) {
|
2022-10-03 11:26:29 +02:00
|
|
|
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
|
2023-12-22 20:42:21 +01:00
|
|
|
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
|
2022-10-03 11:26:29 +02:00
|
|
|
}
|
2022-10-03 11:08:39 +02:00
|
|
|
}
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto& e : state.read_tx) {
|
2022-10-03 11:08:39 +02:00
|
|
|
auto const& send_tx = e.second.first;
|
|
|
|
auto const& recv_tx = e.second.second;
|
|
|
|
REQUIRE(send_tx.size() == recv_tx.size());
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto i = 0; i < send_tx.size(); ++i) {
|
2022-10-03 11:26:29 +02:00
|
|
|
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
|
2023-12-22 20:42:21 +01:00
|
|
|
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
|
2022-10-03 11:26:29 +02:00
|
|
|
}
|
2022-10-03 11:08:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-08 17:20:26 +02:00
|
|
|
void axi4_narrow_burst(bool pipelined_wrreq, bool write_bp) {
|
2022-10-02 18:20:00 +02:00
|
|
|
struct {
|
|
|
|
unsigned int ResetCycles{4};
|
|
|
|
unsigned int BurstLengthByte{16};
|
|
|
|
unsigned int BurstSizeBytes{4};
|
|
|
|
unsigned int NumberOfIterations{8};
|
|
|
|
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>> read_tx;
|
2023-12-22 20:42:21 +01:00
|
|
|
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>>
|
|
|
|
write_tx;
|
2022-10-02 18:20:00 +02:00
|
|
|
unsigned resp_cnt{0};
|
|
|
|
} state;
|
|
|
|
|
2024-05-08 17:20:26 +02:00
|
|
|
auto& dut = factory::get<testbench>();
|
|
|
|
dut.intor_bfm.pipelined_wrreq = pipelined_wrreq;
|
2024-12-11 11:03:49 +01:00
|
|
|
dut.tgt_pe.wr_data_accept_delay.set_value(write_bp ? 1 : 0);
|
2022-10-03 11:26:29 +02:00
|
|
|
auto cycles = run_scenario(state);
|
2022-10-02 18:20:00 +02:00
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
REQUIRE(cycles < 1000);
|
2022-10-02 19:18:57 +02:00
|
|
|
REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0);
|
|
|
|
REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0);
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
REQUIRE(state.resp_cnt == 4 * state.NumberOfIterations);
|
|
|
|
for(auto& e : state.write_tx) {
|
2022-10-02 18:20:00 +02:00
|
|
|
auto const& send_tx = e.second.first;
|
|
|
|
auto const& recv_tx = e.second.second;
|
|
|
|
REQUIRE(send_tx.size() == recv_tx.size());
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto i = 0; i < send_tx.size(); ++i)
|
|
|
|
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
|
2022-10-02 18:20:00 +02:00
|
|
|
}
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto& e : state.read_tx) {
|
2022-10-02 18:20:00 +02:00
|
|
|
auto const& send_tx = e.second.first;
|
|
|
|
auto const& recv_tx = e.second.second;
|
|
|
|
REQUIRE(send_tx.size() == recv_tx.size());
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto i = 0; i < send_tx.size(); ++i)
|
|
|
|
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
|
2022-10-02 18:20:00 +02:00
|
|
|
}
|
2022-10-02 08:14:58 +02:00
|
|
|
}
|
2024-05-08 17:20:26 +02:00
|
|
|
|
|
|
|
TEST_CASE("axi4_burst_alignment", "[AXI][pin-level]") { axi4_burst_alignment(false, false); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_narrow_burst", "[AXI][pin-level]") { axi4_narrow_burst(false, false); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_burst_alignment_with_bp", "[AXI][pin-level]") { axi4_burst_alignment(false, true); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_narrow_burst_with_bp", "[AXI][pin-level]") { axi4_narrow_burst(false, true); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_burst_alignment_pipelined_write", "[AXI][pin-level]") { axi4_burst_alignment(true, false); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_narrow_burst_pipelined_write", "[AXI][pin-level]") { axi4_narrow_burst(true, false); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_burst_alignment_pipelined_write_with_bp", "[AXI][pin-level]") { axi4_burst_alignment(true, true); }
|
|
|
|
|
|
|
|
TEST_CASE("axi4_narrow_burst_pipelined_write_with_bp", "[AXI][pin-level]") { axi4_narrow_burst(true, true); }
|