#pragma once #include #include #include #include #include #include #include #include #include #include #include // For rand() #include // 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 sockets[CORE_NO]; // Sockets to receive data from cores tlm_utils::simple_initiator_socket core_sockets[CORE_NO]; // Sockets to send data to cores sc_core::sc_fifo in_fifo; // FIFO for incoming transactions from cores sc_core::sc_fifo 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*> other_out_fifos; std::vector 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; } };