pvtopv_swa.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _pvtopv_swa_cc_INC
00020 #define _pvtopv_swa_cc_INC
00021
00022 #include "pvtopv_swa.h"
00023
00024 PVToPV_swa::PVToPV_swa()
00025 {
00026
00027 }
00028
00029 PVToPV_swa::~PVToPV_swa()
00030 {
00031
00032 }
00033
00034 void
00035 PVToPV_swa::resize(uint port, uint ch)
00036 {
00037 PORTS = port;
00038 CHANNELS = ch;
00039 requested.resize(PORTS*CHANNELS);
00040 locked.resize(PORTS);
00041 done.resize(PORTS);
00042 last_port_winner.resize(PORTS);
00043 last_ch_winner.resize(PORTS);
00044 requesting_inputs.resize(PORTS*CHANNELS);
00045 last_winner.resize(PORTS);
00046 port_locked.resize(PORTS);
00047
00048 for ( uint i=0; i<(CHANNELS*PORTS); i++)
00049 {
00050 requested[i].resize(PORTS*CHANNELS);
00051 requesting_inputs[i].resize(PORTS*CHANNELS);
00052 }
00053
00054 for ( uint i=0; i<PORTS; i++)
00055 {
00056 done[i].resize(CHANNELS);
00057 locked[i].resize(CHANNELS);
00058 locked[i].resize(CHANNELS);
00059 last_port_winner[i].resize(CHANNELS);
00060 last_ch_winner[i].resize(CHANNELS);
00061 last_winner[i].resize(CHANNELS);
00062 port_locked[i] = false;
00063 }
00064
00065 for ( uint i=0; i<PORTS*CHANNELS; i++)
00066 for ( uint j=0; j<PORTS*CHANNELS; j++)
00067 {
00068 requested[i][j]=false;
00069 }
00070
00071 for ( uint i=0; i<PORTS; i++)
00072 for ( uint j=0; j<CHANNELS; j++)
00073 {
00074 locked[i][j] = false;
00075 done[i][j] = false;
00076 last_port_winner[i][j] = 0;
00077 last_ch_winner[i][j] = 0;
00078 }
00079 }
00080
00081 bool
00082 PVToPV_swa::is_requested( uint oport, uint och, uint inport, uint inch)
00083 {
00084
00085 return locked [oport][och];
00086 }
00087
00088 void
00089 PVToPV_swa::request(uint oport, uint och, uint inport, uint inch )
00090 {
00091 requested[oport*CHANNELS+och][inport*CHANNELS+inch] = true;
00092 done[oport][och] = false;
00093 requesting_inputs[CHANNELS*oport+och][CHANNELS*inport+inch].port = inport;
00094 requesting_inputs[CHANNELS*oport+och][CHANNELS*inport+inch].ch = inch;
00095
00096 return;
00097 }
00098
00099 SA_unit
00100 PVToPV_swa::pick_winner( uint oport, uint och)
00101 {
00102 if(!done[oport][och])
00103 {
00104 done[oport][och] = true;
00105 if(locked[oport][och] )
00106 return last_winner[oport][och];
00107
00108 else
00109 {
00110 locked[oport][och]= true;
00111
00112
00113
00114 bool winner_found = false;
00115 for( uint i=last_port_winner[oport][och]+1; i<(PORTS*CHANNELS); i++)
00116 if(requested[oport*CHANNELS+och][i])
00117 {
00118 last_port_winner[oport][och] = i;
00119 winner_found = true;
00120 last_winner[oport][och].port = requesting_inputs[oport*CHANNELS+och][i].port;
00121 last_winner[oport][och].ch = requesting_inputs[oport*CHANNELS+och][i].ch;
00122 return last_winner[oport][och];
00123 }
00124
00125 if(!winner_found)
00126 for( uint i=0; i<=last_port_winner[oport][och]; i++)
00127 {
00128 if(requested[oport*CHANNELS+och][i])
00129 {
00130 last_port_winner[oport][och] = i;
00131 winner_found = true;
00132 last_winner[oport][och].port = requesting_inputs[oport*CHANNELS+och][i].port;
00133 last_winner[oport][och].ch = requesting_inputs[oport*CHANNELS+och][i].ch;
00134 return last_winner[oport][och];
00135 }
00136 }
00137 if(!winner_found)
00138 {
00139 printf("ERROR: Cant find port winner" );
00140 exit(1);
00141 }
00142
00143 }
00144 }
00145
00146 return last_winner[oport][och];
00147 }
00148
00149 void
00150 PVToPV_swa::clear_winner( uint oport, uint och, uint inport, uint inch)
00151 {
00152 done[oport][och] = false;
00153 locked[oport][och] = false;
00154
00155 requested[oport*CHANNELS+och][inport*CHANNELS+inch] = false;
00156 return;
00157 }
00158
00159 bool
00160 PVToPV_swa::is_empty()
00161 {
00162
00163 for( uint i=0; i<PORTS*CHANNELS; i++)
00164 for( uint j=0; j<CHANNELS*PORTS; j++)
00165 if(requested[i][j] )
00166 {
00167 return false;
00168 }
00169 return true;
00170
00171 }
00172
00173 bool
00174 PVToPV_swa::is_empty_for_ch( uint ch)
00175 {
00176 for( uint i=0; i<requested[ch].size(); i++)
00177 if(requested[ch][i] )
00178 return true;
00179 return false;
00180 }
00181
00182 uint
00183 PVToPV_swa::no_requests_ch( uint ch)
00184 {
00185 uint count = 0;
00186 for( uint i=0; i<requested[ch].size(); i++)
00187 if(requested[ch][i] )
00188 {
00189 count++;
00190 }
00191 return count;
00192 }
00193
00194 string
00195 PVToPV_swa::toString() const
00196 {
00197 stringstream str;
00198 str << "PVToPV_swa: "
00199 << "\t requested_qu row_size: " << requested.size();
00200 if( requested.size())
00201 str << " col_size: " << requested[0].size()
00202 ;
00203 return str.str();
00204 }
00205 #endif