00001 00019 #ifndef _genericcrossbar_cc_INC 00020 #define _genericcrossbar_cc_INC 00021 00022 #include "genericCrossbar.h" 00023 00024 GenericCrossbar::GenericCrossbar () 00025 { 00026 input_ports = 0; 00027 output_ports = 0; 00028 } /* ----- end of method GenericCrossbar::GenericCrossbar ----- */ 00029 00030 GenericCrossbar::~GenericCrossbar () 00031 { 00032 return; 00033 } /* ----- end of method GenericCrossbar::~GenericCrossbar ----- */ 00034 00035 void 00036 GenericCrossbar::clear () 00037 { 00038 return ; 00039 } /* ----- end of method GenericCrossbar::clear ----- */ 00040 00041 uint 00042 GenericCrossbar::get_no_input_ports () 00043 { 00044 return input_ports; 00045 } /* ----- end of method GenericCrossbar::get_output_ports ----- */ 00046 00047 uint 00048 GenericCrossbar::get_no_output_ports () 00049 { 00050 return output_ports; 00051 } /* ----- end of method GenericCrossbar::get_output_ports ----- */ 00052 00053 void 00054 GenericCrossbar::setup (uint p, uint v) 00055 { 00056 vcs = v; 00057 input_ports =p; 00058 output_ports =p; 00059 00060 map.resize ( vcs ); 00061 busy.resize ( vcs ); 00062 00063 for ( uint i = 0; i < vcs ; i++) 00064 { 00065 map[i].resize( input_ports ); 00066 busy[i].resize( output_ports ); 00067 } 00068 00069 for ( uint i = 0; i < vcs ; i++) 00070 for ( uint j = 0; j < input_ports ; j++ ) 00071 { 00072 map[i][j] = 0; 00073 busy[i][j] = false; 00074 } 00075 00076 return ; 00077 } /* ----- end of method GenericCrossbar::set_no_channels ----- */ 00078 00079 uint 00080 GenericCrossbar::get_no_channels () 00081 { 00082 return map.size(); 00083 } /* ----- end of method GenericCrossbar::get_no_channels ----- */ 00084 00085 uint 00086 GenericCrossbar::get_map ( uint port, uint ch) 00087 { 00088 00089 if ( port >= input_ports ) 00090 { 00091 cout << "Tried to get the mapping from input port " << port << " but the crossbar only has " << input_ports << " input ports.\n"; 00092 cout << " Need to throw an invalid port exception " << endl; 00093 } 00094 return map[ch][port]; 00095 } /* ----- end of method GenericCrossbar::get_map ----- */ 00096 00097 void 00098 GenericCrossbar::configure_crossbar ( uint inport, uint outport, uint och ) 00099 { 00100 map[och][outport] = inport; 00101 busy[och][outport] = true; 00102 return ; 00103 } /* ----- end of method GenericCrossbar::configure_crossbar ----- */ 00104 00105 void 00106 GenericCrossbar::push ( uint outport, uint och) 00107 { 00108 busy[och][outport] = true; 00109 return ; 00110 } /* ----- end of method GenericCrossbar::push ----- */ 00111 00112 void 00113 GenericCrossbar::pull ( uint outport, uint och ) 00114 { 00115 busy[och][outport] = false; 00116 return ; 00117 } /* ----- end of method GenericCrossbar::pull ----- */ 00118 00119 bool 00120 GenericCrossbar::is_full ( uint inport, uint och ) 00121 { 00122 for ( uint i=0; i<busy.size(); i++) 00123 if ( map[och][i] == inport) 00124 return true; 00125 00126 return false; 00127 } /* ----- end of method GenericCrossbar::full ----- */ 00128 00129 bool 00130 GenericCrossbar::is_empty ( uint oport, uint ch ) 00131 { 00132 if( ch>= busy.size() ) 00133 cout << "Invalid channel " << endl; 00134 00135 if(oport >= busy[0].size()) 00136 cout << "Invalid output port" << busy[0].size() << endl; 00137 00138 return !busy[ch][oport]; 00139 } /* ----- end of method GenericCrossbar::is_port_empty ----- */ 00140 00141 string 00142 GenericCrossbar::toString () const 00143 { 00144 stringstream str; 00145 str << "GenericCrossbar" 00146 << "\t channels: " << map.size() 00147 << "\t ports: " << map[0].size() 00148 << "\t output_ports: " << output_ports 00149 << endl; 00150 return str.str(); 00151 } /* ----- end of function GenericCrossbar::toString ----- */ 00152 #endif /* ----- #ifndef _genericcrossbar_cc_INC ----- */ 00153