www.pudn.com > noc.rar > switch.cpp
/*
* TU Eindhoven
* Eindhoven, The Netherlands
*
* Name : switch.cpp
*
* Author : A.S.Slusarczyk@tue.nl
*
* Date : 13-09-2003
*
* Function : Crossbar switch with e-cube router
*
*/
#include "switch.h"
// data multiplexing
void CROSSBAR3x3::crossbar_process()
{
bool c00, c01, c02, c10, c11, c12, c20, c21, c22;
sc_uint<2> g0 = grant0.read(), g1 = grant1.read(), g2 = grant2.read();
sc_bv zero(0);
c00 = (g0==1);
c01 = (g1==1);
c02 = (g2==1);
c10 = (g0==2);
c11 = (g1==2);
c12 = (g2==2);
c20 = (g0==3);
c21 = (g1==3);
c22 = (g2==3);
// data and req flow from requester to requested
data_out_0.write(c00 ? data_in_0.read() : (c10 ? data_in_1.read() : ( c20 ? data_in_2.read() : zero)));
data_out_1.write(c01 ? data_in_0.read() : (c11 ? data_in_1.read() : ( c21 ? data_in_2.read() : zero)));
data_out_2.write(c02 ? data_in_0.read() : (c12 ? data_in_1.read() : ( c22 ? data_in_2.read() : zero)));
req_out_0.write(c00 ? req_in_0.read() : (c10 ? req_in_1.read() : ( c20 ? req_in_2.read() : 0)));
req_out_1.write(c01 ? req_in_0.read() : (c11 ? req_in_1.read() : ( c21 ? req_in_2.read() : 0)));
req_out_2.write(c02 ? req_in_0.read() : (c12 ? req_in_1.read() : ( c22 ? req_in_2.read() : 0)));
// ack flows from requested to requester
ack_out_0.write(c00 ? ack_in_0.read() : (c01 ? ack_in_1.read() : ( c02 ? ack_in_2.read() : 0)));
ack_out_1.write(c10 ? ack_in_0.read() : (c11 ? ack_in_1.read() : ( c12 ? ack_in_2.read() : 0)));
ack_out_2.write(c20 ? ack_in_0.read() : (c21 ? ack_in_1.read() : ( c22 ? ack_in_2.read() : 0)));
}
// arbitration
void CROSSBAR3x3::arbiter_process()
{
bool c00, c01, c02, c10, c11, c12, c20, c21, c22, c0, c1, c2;
sc_uint<2> a0=addr_0.read(), a1=addr_1.read(), a2=addr_2.read();
sc_uint<2> g0 = grant0.read(), g1 = grant1.read(), g2 = grant2.read();
sc_uint<2> rr = round_robin.read();
bool rrinc = false;
// who wants what?
c0 = (conn_0.read()==true);
c1 = (conn_1.read()==true);
c2 = (conn_2.read()==true);
c00 = c0 && (a0==1);
c01 = c0 && (a0==2);
c02 = c0 && (a0==3);
c10 = c1 && (a1==1);
c11 = c1 && (a1==2);
c12 = c1 && (a1==3);
c20 = c2 && (a2==1);
c21 = c2 && (a2==2);
c22 = c2 && (a2==3);
if( g0 != 0 ){
// output is busy - wait for the holder to release conn_x
if( ((g0 == 1) && !c0) || ((g0 == 2) && !c1) || ((g0 == 3) && !c2) )
g0 = 0;
}
else { // output if free - grant to requester with number equal to round_robin, or lowest number
if( c00 && rr==0 ){
rrinc = true; g0 = 1;
}
else if( c10 && rr==1 ){
rrinc = true; g0 = 2;
}
else if( c20 && rr==2 ){
rrinc = true; g0 = 3;
}
else
g0 = ( c00 ? 1 : (c10 ? 2 : (c20 ? 3 : 0)) );
}
if( g1 != 0 ){
if( ((g1 == 1) && !c0) || ((g1 == 2) && !c1) || ((g1 == 3) && !c2) )
g1 = 0;
}
else {
if( c01 && rr==0 ){
rrinc = true; g1 = 1;
}
else if( c11 && rr==1 ){
rrinc = true; g1 = 2;
}
else if( c21 && rr==2 ){
rrinc = true; g1 = 3;
}
else
g1 = ( c01 ? 1 : (c11 ? 2 : (c21 ? 3 : 0)) );
}
if( g2 != 0 ){
if( ((g2 == 1) && !c0) || ((g2 == 2) && !c1) || ((g2 == 3) && !c2) )
g2 = 0;
}
else {
if( c02 && rr==0 ){
rrinc = true; g2 = 1;
}
else if( c12 && rr==1 ){
rrinc = true; g2 = 2;
}
else if( c22 && rr==2 ){
rrinc = true; g2 = 3;
}
else
g2 = ( c02 ? 1 : (c12 ? 2 : (c22 ? 3 : 0)) );
}
grant0.write(g0);
grant1.write(g1);
grant2.write(g2);
rr_inc.write(rrinc);
}
void CROSSBAR3x3::round_robin_process()
{
if( rr_inc.read() ){
round_robin.write( round_robin.read()+1 );
}
}