64 lines
2 KiB
C
64 lines
2 KiB
C
|
#pragma once
|
||
|
|
||
|
#include <systemc.h>
|
||
|
#include <tlm.h>
|
||
|
#include <tlm_utils/simple_initiator_socket.h>
|
||
|
#include <tlm_utils/simple_target_socket.h>
|
||
|
#include <queue>
|
||
|
#include <iostream>
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <iostream>
|
||
|
#include <cstdlib>
|
||
|
#include <cstdlib> // For rand()
|
||
|
#include <ctime> // For time()
|
||
|
|
||
|
#include "configuration.h"
|
||
|
#include "semaphore_manager.h"
|
||
|
|
||
|
using namespace sc_core;
|
||
|
|
||
|
// Router module with FIFOs, semaphores, and capacity control for receive FIFO
|
||
|
SC_MODULE(router) {
|
||
|
tlm_utils::simple_target_socket<router> sockets[CORE_NO]; // Sockets to receive data from cores
|
||
|
tlm_utils::simple_initiator_socket<router> core_sockets[CORE_NO]; // Sockets to send data to cores
|
||
|
sc_core::sc_fifo<my_payload*> in_fifo; // FIFO for incoming transactions from cores
|
||
|
sc_core::sc_fifo<my_payload*> out_fifo; // FIFO for transactions to be processed by the router
|
||
|
|
||
|
|
||
|
unsigned int current_router_id;
|
||
|
|
||
|
// Declare the semaphore for access control
|
||
|
sc_core::sc_semaphore sem;
|
||
|
int router_id;
|
||
|
const int D = 10; // Base delay for each router communication (in ns)
|
||
|
|
||
|
|
||
|
// Pointers to other routers' FIFOs and semaphores for inter-router communication
|
||
|
std::vector<sc_core::sc_fifo<my_payload*>*> other_out_fifos;
|
||
|
std::vector<sc_core::sc_semaphore*> other_sems;
|
||
|
|
||
|
// Add a pointer to the semaphore manager
|
||
|
semaphore_manager* sem_mgr;
|
||
|
|
||
|
SC_CTOR(router);
|
||
|
|
||
|
// Function to handle incoming transactions
|
||
|
tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload& trans, tlm::tlm_phase& phase, sc_time& delay);
|
||
|
|
||
|
// Thread to process core_fifo
|
||
|
void process_core_fifo();
|
||
|
|
||
|
// Thread to process router_receive_fifo and forward transactions to cores
|
||
|
void process_router_receive_fifo();
|
||
|
|
||
|
void log_info(std::string msg);
|
||
|
void log_error(std::string msg);
|
||
|
|
||
|
// Method to set the semaphore manager instance after creation
|
||
|
void set_semaphore_manager(semaphore_manager* manager) {
|
||
|
sem_mgr = manager;
|
||
|
}
|
||
|
};
|
||
|
|