255 lines
7.3 KiB
C++
Executable file
255 lines
7.3 KiB
C++
Executable file
/*******************************************************************************
|
|
* Copyright (C) 2024 Juan Neyra
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
******************************************************************************/
|
|
#pragma once
|
|
|
|
#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
|
|
#define SC_INCLUDE_DYNAMIC_PROCESSES
|
|
#endif
|
|
|
|
#include "systemc.h"
|
|
#include "tlm.h"
|
|
#include <queue>
|
|
#include <algorithm>
|
|
#include <functional>
|
|
|
|
#include "ratatoskrUtils/utils/Structures.h"
|
|
#include "ratatoskrUtils/utils/TrafficTracer.h"
|
|
#include "ratatoskrUtils/container/PacketContainer.h"
|
|
#include "ratatoskrUtils/networkInterface/NetworkInterface.h"
|
|
|
|
#include "noc/noc.h"
|
|
#include "utils/memory_manager.h"
|
|
#include "utils/noc_logger.h"
|
|
|
|
|
|
using namespace tlm_utils;
|
|
|
|
class NetworkInterfaceTlm : public NetworkInterface {
|
|
public:
|
|
typedef simple_initiator_socket_tagged<NetworkInterfaceTlm> ni_init_socket;
|
|
typedef simple_target_socket_tagged<NetworkInterfaceTlm> ni_targ_socket;
|
|
|
|
std::queue<Packet*> packet_send_queue;
|
|
std::queue<Packet*> packet_recv_queue;
|
|
|
|
string ni_name;
|
|
// To PE
|
|
sc_in<bool> clk;
|
|
PacketPortContainer* packetPortContainer;
|
|
// To NoC
|
|
ni_init_socket initiator;
|
|
ni_targ_socket target;
|
|
tlm_utils::peq_with_cb_and_phase<NetworkInterfaceTlm> init_peq;
|
|
tlm_utils::peq_with_cb_and_phase<NetworkInterfaceTlm> target_peq;
|
|
tlm_gp* curr_req;
|
|
tlm_gp* end_req_pend;
|
|
tlm_gp* nxt_resp_pend;
|
|
tlm_gp* nxt_send_data_pend;
|
|
bool resp_in_progress;
|
|
bool send_data_in_progress;
|
|
int credit_counter;
|
|
Dir send_data_in_prog_dest;
|
|
MemoryManager m_mm;
|
|
uint8_t max_pos[3];
|
|
// To Circuit Switching NoC
|
|
ni_init_socket initiator_cs;
|
|
ni_targ_socket target_cs;
|
|
|
|
sc_event_or_list ev_msg_arrv;
|
|
|
|
SC_HAS_PROCESS(NetworkInterfaceTlm);
|
|
|
|
NetworkInterfaceTlm(sc_module_name nm, Node& node, uint8_t max_pos[3]);
|
|
|
|
~NetworkInterfaceTlm() override;
|
|
|
|
/**
|
|
* Not implemented, nothing to initialize, come from parent class
|
|
*/
|
|
void initialize() override;
|
|
|
|
/**
|
|
* Binds packet port container to Processing Element
|
|
*
|
|
* @param con connection struct
|
|
* @param sigContIn input signals for port
|
|
* @param sigContOut output signal for port
|
|
*/
|
|
void bind(Connection* conn, SignalContainer* sigContIn,
|
|
SignalContainer* sigContOut) override;
|
|
|
|
/**
|
|
* Main SC THREAD. Has logic to send and receive flits
|
|
*/
|
|
void thread() override;
|
|
|
|
/**
|
|
* Gets current flit to transmit and send it to the router in noc
|
|
*/
|
|
void send_data_to_noc();
|
|
|
|
/**
|
|
* Sends flit to noc
|
|
*
|
|
* @param p parent packet of the flit to send
|
|
* @param f flit to send
|
|
*/
|
|
void send_flit(Packet* p, Flit* f);
|
|
|
|
/**
|
|
* Build the transaction tp send. Called by send flit
|
|
*
|
|
* @param p parent packet of the flit to send
|
|
* @param f flit to send
|
|
*
|
|
* @return created transaction
|
|
*/
|
|
tlm_gp* build_transaction(Packet* p, Flit* f);
|
|
|
|
/**
|
|
* If message is init streaming, a router_cs needs to be
|
|
* configured
|
|
*
|
|
* @param trans TLM generic payload object
|
|
*/
|
|
bool check_cs_needed(tlm_gp& trans);
|
|
|
|
/**
|
|
* Sends configuration message to router_cs
|
|
*
|
|
* @param trans TLM generic payload object
|
|
*/
|
|
bool send_cs_rout_conf_msg(tlm_gp& trans);
|
|
|
|
|
|
/**
|
|
* Generates flits when a packet arrives
|
|
*/
|
|
void receivePacketFromPE() override;
|
|
|
|
/**
|
|
* Not implemented. TLM's target nb_transport_fw_cb callback
|
|
* used instead
|
|
*/
|
|
void receiveFlitFromRouter();
|
|
|
|
/**
|
|
* Used inside receivePacketFromPE to generate flits
|
|
*
|
|
* @param p packet from which to generate flits
|
|
*/
|
|
void generateFlitsForPacket(Packet *p);
|
|
|
|
/**
|
|
* Gets the node position and the destination of packet
|
|
* as strings
|
|
*
|
|
* @param p packet from which to extract destination
|
|
* @param pos stores the start (0) and end position (1)
|
|
*/
|
|
void get_start_end_pos_string(Packet* p, string pos[2]);
|
|
|
|
/**
|
|
* Checks transaction for errors, if no error found, log
|
|
* transaction and release transaction object. Called when
|
|
* transaction is completed
|
|
*
|
|
* @param trans TLM transaction object
|
|
*/
|
|
void check_transaction(tlm_gp& trans);
|
|
|
|
/**
|
|
* Logs the arrival of a flit. After processing, sends a response
|
|
*
|
|
* @param trans TLM transaction object
|
|
*/
|
|
void receive_and_process_flit(tlm_gp& trans);
|
|
|
|
/**
|
|
* Callback function for non blocking transport forward
|
|
*
|
|
* @param id active link
|
|
* @param trans TLM generic payload object
|
|
* @param phase TLM current phase
|
|
* @param delay TLM expected delay
|
|
*/
|
|
tlm::tlm_sync_enum nb_transport_fw_cb(int id, tlm_gp& trans,
|
|
tlm::tlm_phase& phase, sc_time& delay);
|
|
|
|
/**
|
|
* Callback function for non blocking transport backward
|
|
*
|
|
* @param id active link
|
|
* @param trans TLM generic payload object
|
|
* @param phase TLM current phase
|
|
* @param delay TLM expected delay
|
|
*/
|
|
tlm::tlm_sync_enum nb_transport_bw_cb(int id, tlm_gp& trans,
|
|
tlm::tlm_phase& phase, sc_time& delay);
|
|
|
|
/**
|
|
* Callback initiator Payload Event Queue (PEQ)
|
|
*
|
|
* @param trans TLM generic payload object
|
|
* @param phase TLM current phase
|
|
*/
|
|
void init_peq_cb(tlm_gp& trans, const tlm::tlm_phase& phase);
|
|
|
|
/**
|
|
* Callback target Payload Event Queue (PEQ)
|
|
*
|
|
* @param trans TLM generic payload object
|
|
* @param phase TLM current phase
|
|
*/
|
|
void target_peq_cb(tlm_gp& trans, const tlm::tlm_phase& phase);
|
|
|
|
/**
|
|
* Send end request
|
|
*
|
|
* @param trans TLM generic payload object
|
|
*/
|
|
tlm::tlm_sync_enum send_end_req(tlm_gp& trans);
|
|
|
|
/**
|
|
* Send begin response
|
|
*
|
|
* @param link active link
|
|
* @param trans TLM generic payload object
|
|
*/
|
|
void send_response(tlm_gp& trans);
|
|
|
|
|
|
/** Log info
|
|
* @param msg log message
|
|
*/
|
|
void log_info(string msg);
|
|
|
|
/** Log error
|
|
* @param msg log message
|
|
*/
|
|
void log_error(string msg);
|
|
|
|
/** Log fatal
|
|
* @param msg log message
|
|
*/
|
|
void log_fatal(string msg);
|
|
};
|