Skip to content

Commit

Permalink
Updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
edualvss committed Jan 25, 2017
2 parents 2d8a046 + 1c48125 commit ddfa544
Show file tree
Hide file tree
Showing 16 changed files with 843 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Routing/Routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class IOrthogonal2DRouting : public IRouting {
unsigned char REQ_S;
unsigned char REQ_W;
unsigned char REQ_NONE;
unsigned char INDEX_N;
unsigned char INDEX_E;
unsigned char INDEX_S;
unsigned char INDEX_W;

unsigned short XID,YID;
public:
Expand Down Expand Up @@ -138,6 +142,10 @@ class IOrthogonal2DRouting : public IRouting {
REQ_W = (unsigned char) pow(2,(useNorth+useEast+useSouth+useWest));
}
}
INDEX_N = log2(REQ_N);
INDEX_E = log2(REQ_E);
INDEX_S = log2(REQ_S);
INDEX_W = log2(REQ_W);
}

INoC::TopologyType supportedTopology() const { return INoC::TT_Orthogonal2D; }
Expand Down
172 changes: 172 additions & 0 deletions Routing_NF/Routing_NF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#include "Routing_NF.h"

//#define DEBUG_ROUTING

/*!
* \brief Routing_NF::Routing_NF Negative-First routing for Mesh topology constructor
* \param mn Module name
* \param nPorts Number of ports to route - number of requests to generate
* \param ROUTER_ID Router identifier in the network
*/
Routing_NF::Routing_NF(sc_module_name mn,
unsigned short nPorts,
unsigned short ROUTER_ID)
: IOrthogonal2DRouting(mn,nPorts,ROUTER_ID)
{
SC_METHOD(p_REQUEST);
sensitive << i_READ_OK << i_DATA;
}

/*!
* \brief Routing_NF::p_REQUEST Process that generate the requests
*/
void Routing_NF::p_REQUEST() {
UIntVar v_DATA; // Used to extract fields from data
UIntVar v_XDEST(0,RIB_WIDTH/2); // x-coordinate
UIntVar v_YDEST(0,RIB_WIDTH/2); // y-coordinate
bool v_BOP; // packet framing bit: begin of packet
bool v_HEADER_PRESENT; // A header is in the FIFO's output
UIntVar v_REQUEST(0,numPorts); // Encoded request
short int v_X_offset, v_Y_offset; // Aux. variables used for routing

Flit f = i_DATA.read();
v_DATA = f.data;

// It extracts the RIB fields and the framing bits
v_XDEST = v_DATA.range(RIB_WIDTH-1, RIB_WIDTH/2);
v_YDEST = v_DATA.range(RIB_WIDTH/2-1,0);
v_BOP = v_DATA[FLIT_WIDTH-2];

// It determines if a header is present
if ((v_BOP==1) && (i_READ_OK.read()==1)) {
v_HEADER_PRESENT = 1;
} else {
v_HEADER_PRESENT = 0;
}

// It runs the routing algorithm
if (v_HEADER_PRESENT) {
v_X_offset = (int) v_XDEST.to_int() - (int) XID;
v_Y_offset = (int) v_YDEST.to_int() - (int) YID;
if ((v_X_offset < 0) || (v_Y_offset < 0)) {
if (v_X_offset < 0) {
if( REQ_W == 0 ) {
std::cout << "\n\t[Routing_NF] ERROR: Requesting an nonexistent port WEST on Router: "
<< ROUTER_ID << " - (" << XID << "," << YID << ") - with destination: ("
<< v_XDEST << "," << v_YDEST << ")." << std::endl
<< " Aborting simulation..." << std::endl;
sc_stop();
}
v_REQUEST = REQ_W;
} else {
if( REQ_S == 0 ) {
std::cout << "\n\t[Routing_NF] ERROR: Requesting an nonexistent port SOUTH on Router: "
<< ROUTER_ID << " - (" << XID << "," << YID << ") - with destination: ("
<< v_XDEST << "," << v_YDEST << ")." << std::endl
<< " Aborting simulation..." << std::endl;
sc_stop();
}
v_REQUEST = REQ_S;
}
} else if ((v_X_offset > 0) || (v_Y_offset > 0)) {
if (v_X_offset == 0) {
if( REQ_N == 0 ) {
std::cout << "\n\t[Routing_NF] ERROR: Requesting an nonexistent port NORTH on Router: "
<< ROUTER_ID << " - (" << XID << "," << YID << ") - with destination: ("
<< v_XDEST << "," << v_YDEST << ")." << std::endl
<< " Aborting simulation..." << std::endl;
sc_stop();
}
v_REQUEST = REQ_N;
} else if (v_Y_offset == 0) {
if( REQ_E == 0 ) {
std::cout << "\n\t[Routing_NF] ERROR: Requesting an nonexistent port EAST on Router: "
<< ROUTER_ID << " - (" << XID << "," << YID << ") - with destination: ("
<< v_XDEST << "," << v_YDEST << ")." << std::endl
<< " Aborting simulation..." << std::endl;
sc_stop();
}
v_REQUEST = REQ_E;
} else {
if( REQ_N == 0 ) {
std::cout << "\n\t[Routing_NF] ERROR: Requesting an nonexistent port NORTH on Router: "
<< ROUTER_ID << " - (" << XID << "," << YID << ") - with destination: ("
<< v_XDEST << "," << v_YDEST << ")." << std::endl
<< " Aborting simulation..." << std::endl;
sc_stop();
}
if ( i_IDLE[INDEX_N].read() ) {
v_REQUEST = REQ_N;
} else {
if( REQ_E == 0 ) {
std::cout << "\n\t[Routing_NF] ERROR: Requesting an nonexistent port EAST on Router: "
<< ROUTER_ID << " - (" << XID << "," << YID << ") - with destination: ("
<< v_XDEST << "," << v_YDEST << ")." << std::endl
<< " Aborting simulation..." << std::endl;
sc_stop();
}
if ( i_IDLE[INDEX_E].read() ){
v_REQUEST = REQ_E;
} else {
// NOTE if requested port is busy, prefer NORTH
v_REQUEST = REQ_N;
//std::cout << "\t\t\tNone @ " << sc_time_stamp() << std::endl;
}
}
}
} else { // X == Y == 0
v_REQUEST = REQ_L;
}
#ifdef DEBUG_ROUTING
std::cout << "\n[Routing_NF]"
<< " Local(" << XID << "," << YID
<< ") - Dest(" << v_XDEST << "," << v_YDEST << ") "
<< ", Req: ";
if(v_REQUEST == REQ_L) {
std::cout << "LOCAL";
} else if(v_REQUEST == REQ_N) {
std::cout << "NORTH";
} else if(v_REQUEST == REQ_E) {
std::cout << "EAST";
} else if(v_REQUEST == REQ_S) {
std::cout << "SOUTH";
} else if(v_REQUEST == REQ_W) {
std::cout << "WEST";
} else if(v_REQUEST == 0) {
std::cout << "NONE";
}
std::cout << " @ " << sc_time_stamp() << " , ID: " << f << std::endl;
#endif

} else {
v_REQUEST = REQ_NONE;
}

// Outputs
for( unsigned short i = 0; i < numPorts; i++ ) {
o_REQUEST[i].write( v_REQUEST[i] );
}
}

/////////////////////////////////////////////////////////////////////////////////////////////

extern "C" {
SS_EXP IRouting* new_Routing(sc_simcontext* simcontext,
sc_module_name moduleName,
unsigned short int nPorts,
unsigned short int ROUTER_ID) {
// Simcontext is needed because in shared library a
// new and different simcontext will be created if
// the main application simcontext is not passed to
// this shared library.
// IMPORTANT: The simcontext assignment shall be
// done before component instantiation.
sc_curr_simcontext = simcontext;
sc_default_global_context = simcontext;

return new Routing_NF(moduleName,nPorts,ROUTER_ID);
}
SS_EXP void delete_Routing(IRouting* routing) {
delete routing;
}
}
45 changes: 45 additions & 0 deletions Routing_NF/Routing_NF.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
--------------------------------------------------------------------------------
PROJECT: SoCIN Simulator
MODULE : Routing_NF
FILE : Routing_NF.h
--------------------------------------------------------------------------------
DESCRIPTION: Implements the NF routing algorithm. It takes as parameters the
router's coordinates and compares them with the destination router's coordi-
specified on the header's RIB field.
--------------------------------------------------------------------------------
AUTHORS: Laboratory of Embedded and Distributed Systems (LEDS - UNIVALI)
CONTACT: Prof. Cesar Zeferino ([email protected])
-------------------------------- Reviews ---------------------------------------
| Date - Version - Author | Description
--------------------------------------------------------------------------------
| 01/12/2016 - 1.0 - Sérgio Vargas Júnior | Reuse from ParIS
--------------------------------------------------------------------------------
*/
#ifndef __ROUTING_NF_H__
#define __ROUTING_NF_H__

#include "../Routing/Routing.h"

/*!
* \brief The Routing_NF class implements the Negative-First routing algorithm
* for Mesh 2D topology.
*
* Implements the Negative-First routing algorithm. It takes as parameters the
* router's coordinates and compares them with the destination
* router's coordinate-specified on the header's RIB field.
*/
class Routing_NF : public IOrthogonal2DRouting {
public:
// Module's process
void p_REQUEST();

SC_HAS_PROCESS(Routing_NF);
Routing_NF(sc_module_name mn,
unsigned short nPorts,
unsigned short ROUTER_ID);

const char* moduleName() const { return "Routing_NF"; }
};

#endif // __ROUTING_NF_H__
10 changes: 10 additions & 0 deletions Routing_NF/Routing_NF.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include(../Routing/Routing.pro)
include(../plugin.pri)

TARGET = routing_nf

SOURCES += \
Routing_NF.cpp

HEADERS += \
Routing_NF.h
Loading

0 comments on commit ddfa544

Please sign in to comment.