2020-07-14 10:49:06 +02:00
|
|
|
/*
|
|
|
|
* blocks.cpp
|
|
|
|
*
|
|
|
|
* Created on: 04.05.2020
|
|
|
|
* Author: eyck
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pkt_sender.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include <scc/report.h>
|
2021-06-01 18:21:49 +02:00
|
|
|
#include <tlm/scc/tlm_mm.h>
|
2020-07-14 10:49:06 +02:00
|
|
|
|
|
|
|
using namespace sc_core;
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
pkt_sender::pkt_sender(const sc_core::sc_module_name& nm, unsigned dim, unsigned pos_x, unsigned pos_y, unsigned count)
|
2020-07-14 10:49:06 +02:00
|
|
|
: sc_module(nm)
|
|
|
|
, bw_peq("bw_peq")
|
|
|
|
, fw_peq("fw_peq")
|
2023-12-22 20:42:21 +01:00
|
|
|
, my_pos{pos_x, pos_y}
|
2020-07-14 10:49:06 +02:00
|
|
|
, dim{dim}
|
2023-12-22 20:42:21 +01:00
|
|
|
, count{count} {
|
|
|
|
SCCDEBUG(SCMOD) << "instantiating sender " << pos_x << "/" << pos_y;
|
2020-07-14 10:49:06 +02:00
|
|
|
SC_HAS_PROCESS(pkt_sender);
|
2023-12-22 20:42:21 +01:00
|
|
|
isck.register_nb_transport_bw([this](tlm::tlm_generic_payload& gp, tlm::tlm_phase& phase,
|
|
|
|
sc_core::sc_time& delay) -> tlm::tlm_sync_enum { return this->nb_bw(gp, phase, delay); });
|
|
|
|
tsck.register_nb_transport_fw([this](tlm::tlm_generic_payload& gp, tlm::tlm_phase& phase,
|
|
|
|
sc_core::sc_time& delay) -> tlm::tlm_sync_enum { return this->nb_fw(gp, phase, delay); });
|
2020-07-14 10:49:06 +02:00
|
|
|
SC_METHOD(received);
|
2023-12-22 20:42:21 +01:00
|
|
|
sensitive << fw_peq.get_event();
|
2020-07-14 10:49:06 +02:00
|
|
|
dont_initialize();
|
|
|
|
SC_THREAD(run);
|
|
|
|
}
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
void pkt_sender::gen_routing(std::vector<uint8_t>& route_vec) {
|
|
|
|
if(std::get<0>(my_pos) == 0) {
|
|
|
|
for(auto i = 0; i < dim; ++i)
|
2020-07-14 10:49:06 +02:00
|
|
|
route_vec.push_back(RIGHT);
|
2023-12-22 20:42:21 +01:00
|
|
|
} else if(std::get<0>(my_pos) == dim + 1) {
|
|
|
|
for(auto i = 0; i < dim; ++i)
|
2020-07-14 10:49:06 +02:00
|
|
|
route_vec.push_back(LEFT);
|
2023-12-22 20:42:21 +01:00
|
|
|
} else if(std::get<1>(my_pos) == 0) {
|
|
|
|
for(auto i = 0; i < dim; ++i)
|
2020-07-14 10:49:06 +02:00
|
|
|
route_vec.push_back(BOTTOM);
|
2023-12-22 20:42:21 +01:00
|
|
|
} else if(std::get<1>(my_pos) == dim + 1) {
|
|
|
|
for(auto i = 0; i < dim; ++i)
|
2020-07-14 10:49:06 +02:00
|
|
|
route_vec.push_back(TOP);
|
|
|
|
} else
|
2023-12-22 20:42:21 +01:00
|
|
|
SCCERR(SCMOD) << "WTF!?!";
|
2020-07-14 10:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void pkt_sender::run() {
|
|
|
|
wait(clk_i.posedge_event());
|
2023-12-22 20:42:21 +01:00
|
|
|
for(auto i = 0U; i < count; i++) {
|
2021-06-01 18:21:49 +02:00
|
|
|
tlm::tlm_generic_payload* gp = tlm::scc::tlm_mm<>::get().allocate<packet_ext>();
|
2020-07-14 10:49:06 +02:00
|
|
|
gen_routing(gp->get_extension<packet_ext>()->routing);
|
|
|
|
tlm::tlm_phase phase{tlm::BEGIN_REQ};
|
|
|
|
sc_time delay;
|
|
|
|
gp->acquire();
|
|
|
|
auto sync = isck->nb_transport_fw(*gp, phase, delay);
|
2023-12-22 20:42:21 +01:00
|
|
|
sc_assert(sync == tlm::TLM_UPDATED && phase == tlm::END_REQ);
|
2020-07-14 10:49:06 +02:00
|
|
|
tlm::tlm_generic_payload* ret{nullptr};
|
2023-12-22 20:42:21 +01:00
|
|
|
while(!(ret = bw_peq.get_next_transaction())) {
|
2020-07-14 10:49:06 +02:00
|
|
|
wait(bw_peq.get_event());
|
|
|
|
}
|
2023-12-22 20:42:21 +01:00
|
|
|
sc_assert(gp == ret);
|
2020-07-14 10:49:06 +02:00
|
|
|
ret->release();
|
|
|
|
}
|
|
|
|
finish_evt.notify(SC_ZERO_TIME);
|
|
|
|
}
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
tlm::tlm_sync_enum pkt_sender::nb_bw(tlm::tlm_generic_payload& gp, tlm::tlm_phase& phase, sc_core::sc_time& delay) {
|
|
|
|
sc_assert(phase == tlm::BEGIN_RESP);
|
2020-07-14 10:49:06 +02:00
|
|
|
bw_peq.notify(gp, delay);
|
2023-12-22 20:42:21 +01:00
|
|
|
phase = tlm::END_RESP;
|
2020-07-14 10:49:06 +02:00
|
|
|
return tlm::TLM_COMPLETED;
|
|
|
|
}
|
|
|
|
|
2023-12-22 20:42:21 +01:00
|
|
|
tlm::tlm_sync_enum pkt_sender::nb_fw(tlm::tlm_generic_payload& gp, tlm::tlm_phase& phase, sc_core::sc_time& delay) {
|
|
|
|
sc_assert(phase == tlm::BEGIN_REQ);
|
2020-07-14 10:49:06 +02:00
|
|
|
auto ext = gp.get_extension<packet_ext>();
|
2023-12-22 20:42:21 +01:00
|
|
|
sc_assert(ext->routing.size() == 0);
|
2020-07-14 10:49:06 +02:00
|
|
|
gp.acquire();
|
|
|
|
fw_peq.notify(gp, delay);
|
2023-12-22 20:42:21 +01:00
|
|
|
phase = tlm::END_REQ;
|
2020-07-14 10:49:06 +02:00
|
|
|
return tlm::TLM_UPDATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pkt_sender::received() {
|
2023-12-22 20:42:21 +01:00
|
|
|
if(auto gp = fw_peq.get_next_transaction()) {
|
2020-07-14 10:49:06 +02:00
|
|
|
tlm::tlm_phase phase{tlm::BEGIN_RESP};
|
|
|
|
sc_time delay;
|
|
|
|
auto sync = tsck->nb_transport_bw(*gp, phase, delay);
|
2023-12-22 20:42:21 +01:00
|
|
|
sc_assert(sync == tlm::TLM_COMPLETED && phase == tlm::END_RESP);
|
2020-07-14 10:49:06 +02:00
|
|
|
gp->release();
|
|
|
|
}
|
|
|
|
}
|