[53] | 1 | /* |
---|
| 2 | * $Id: test.cpp 137 2010-02-16 12:35:48Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define NB_ITERATION 1 |
---|
| 10 | #define CYCLE_MAX (256*NB_ITERATION) |
---|
| 11 | |
---|
[82] | 12 | #include "Behavioural/Generic/RegisterFile/SelfTest/include/test.h" |
---|
| 13 | #include "Common/include/Test.h" |
---|
[53] | 14 | |
---|
| 15 | void test (string name, |
---|
| 16 | morpheo::behavioural::generic::registerfile::Parameters * _param) |
---|
| 17 | { |
---|
| 18 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 19 | |
---|
| 20 | #ifdef STATISTICS |
---|
[62] | 21 | morpheo::behavioural::Parameters_Statistics * _param_stat = new morpheo::behavioural::Parameters_Statistics(5,50); |
---|
[53] | 22 | #endif |
---|
[131] | 23 | |
---|
| 24 | _model.set_model(MODEL_SYSTEMC,true); |
---|
[53] | 25 | |
---|
[88] | 26 | Tusage_t _usage = USE_ALL; |
---|
| 27 | |
---|
[137] | 28 | _usage = usage_unset(_usage,USE_SYSTEMC ); |
---|
[88] | 29 | // _usage = usage_unset(_usage,USE_VHDL ); |
---|
| 30 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH ); |
---|
| 31 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT); |
---|
| 32 | // _usage = usage_unset(_usage,USE_POSITION ); |
---|
| 33 | // _usage = usage_unset(_usage,USE_STATISTICS ); |
---|
| 34 | // _usage = usage_unset(_usage,USE_INFORMATION ); |
---|
| 35 | |
---|
[62] | 36 | RegisterFile * _RegisterFile = new RegisterFile (name.c_str(), |
---|
| 37 | #ifdef STATISTICS |
---|
| 38 | _param_stat, |
---|
| 39 | #endif |
---|
[82] | 40 | _param, |
---|
[88] | 41 | _usage); |
---|
[62] | 42 | |
---|
[53] | 43 | #ifdef SYSTEMC |
---|
| 44 | /********************************************************************* |
---|
| 45 | * Déclarations des signaux |
---|
| 46 | *********************************************************************/ |
---|
| 47 | sc_clock * CLOCK; |
---|
| 48 | sc_signal<Tcontrol_t> * NRESET; |
---|
| 49 | |
---|
| 50 | sc_signal<Tcontrol_t> READ_VAL [_param->_nb_port_read]; |
---|
| 51 | sc_signal<Tcontrol_t> READ_ACK [_param->_nb_port_read]; |
---|
[81] | 52 | sc_signal<registerfile::Taddress_t> READ_ADDRESS [_param->_nb_port_read]; |
---|
[53] | 53 | sc_signal<Tdata_t> READ_DATA [_param->_nb_port_read]; |
---|
| 54 | |
---|
| 55 | sc_signal<Tcontrol_t> WRITE_VAL [_param->_nb_port_write]; |
---|
| 56 | sc_signal<Tcontrol_t> WRITE_ACK [_param->_nb_port_write]; |
---|
[81] | 57 | sc_signal<registerfile::Taddress_t> WRITE_ADDRESS [_param->_nb_port_write]; |
---|
[53] | 58 | sc_signal<Tdata_t> WRITE_DATA [_param->_nb_port_write]; |
---|
| 59 | |
---|
| 60 | string rename; |
---|
| 61 | |
---|
| 62 | CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
| 63 | NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
| 64 | |
---|
| 65 | /******************************************************** |
---|
| 66 | * Instanciation |
---|
| 67 | ********************************************************/ |
---|
| 68 | |
---|
| 69 | cout << "<" << name << "> Instanciation of _RegisterFile" << endl; |
---|
| 70 | |
---|
| 71 | (*(_RegisterFile->in_CLOCK)) (*(CLOCK)); |
---|
| 72 | (*(_RegisterFile->in_NRESET)) (*(NRESET)); |
---|
| 73 | |
---|
| 74 | for (uint32_t i=0; i<_param->_nb_port_read; i++) |
---|
| 75 | { |
---|
| 76 | (*(_RegisterFile-> in_READ_VAL [i])) (READ_VAL [i]); |
---|
| 77 | (*(_RegisterFile->out_READ_ACK [i])) (READ_ACK [i]); |
---|
[62] | 78 | if (_param->_have_port_address == true) |
---|
[53] | 79 | (*(_RegisterFile-> in_READ_ADDRESS [i])) (READ_ADDRESS [i]); |
---|
| 80 | (*(_RegisterFile->out_READ_DATA [i])) (READ_DATA [i]); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | for (uint32_t i=0; i<_param->_nb_port_write; i++) |
---|
| 84 | { |
---|
| 85 | (*(_RegisterFile-> in_WRITE_VAL [i])) (WRITE_VAL [i]); |
---|
| 86 | (*(_RegisterFile->out_WRITE_ACK [i])) (WRITE_ACK [i]); |
---|
[62] | 87 | if (_param->_have_port_address == true) |
---|
[53] | 88 | (*(_RegisterFile-> in_WRITE_ADDRESS [i])) (WRITE_ADDRESS [i]); |
---|
| 89 | (*(_RegisterFile-> in_WRITE_DATA [i])) (WRITE_DATA [i]); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 93 | Time * _time = new Time(); |
---|
| 94 | |
---|
| 95 | /******************************************************** |
---|
| 96 | * Simulation - Begin |
---|
| 97 | ********************************************************/ |
---|
| 98 | |
---|
| 99 | const bool simulate_read = true; |
---|
| 100 | const uint32_t nb_request = _param->_nb_word; |
---|
| 101 | // random init |
---|
| 102 | const uint32_t grain = 0; |
---|
| 103 | //const uint32_t grain = static_cast<uint32_t>(time(NULL)); |
---|
| 104 | |
---|
| 105 | srand(grain); |
---|
| 106 | |
---|
| 107 | // Initialisation |
---|
| 108 | |
---|
| 109 | SC_START(0); |
---|
| 110 | |
---|
| 111 | for (uint32_t i=0; i<_param->_nb_port_write; i++) |
---|
| 112 | WRITE_VAL [i] .write (0); |
---|
| 113 | |
---|
| 114 | for (uint32_t i=0; i<_param->_nb_port_read; i++) |
---|
| 115 | READ_VAL [i] .write (0); |
---|
| 116 | |
---|
| 117 | NRESET->write(0); |
---|
| 118 | |
---|
| 119 | SC_START(5); |
---|
| 120 | |
---|
| 121 | NRESET->write(1); |
---|
| 122 | |
---|
| 123 | for (uint32_t nb_iteration=0; nb_iteration < NB_ITERATION; nb_iteration ++) |
---|
| 124 | { |
---|
| 125 | cout << "<" << name << "> 1) Write the RegisterFile (no read)" << endl; |
---|
| 126 | |
---|
[81] | 127 | registerfile::Taddress_t nb_val = 0; |
---|
| 128 | registerfile::Taddress_t nb_ack = 0; |
---|
[53] | 129 | |
---|
| 130 | Tdata_t tab_data [_param->_nb_word]; |
---|
[81] | 131 | registerfile::Taddress_t tab_address [nb_request ]; |
---|
[53] | 132 | |
---|
| 133 | for (uint32_t i=0; i<_param->_nb_word; i++) |
---|
| 134 | tab_data [i]= rand()%(1<<(_param->_size_word-1)); |
---|
| 135 | for (uint32_t i=0; i<nb_request; i++) |
---|
| 136 | tab_address [i]= rand()%(1<<(_param->_size_address)); |
---|
| 137 | |
---|
| 138 | while (nb_ack < nb_request) |
---|
| 139 | { |
---|
[113] | 140 | cout << "cycle : " << static_cast<uint32_t> (simulation_cycle()) << endl; |
---|
[53] | 141 | |
---|
| 142 | for (uint32_t num_port=0; num_port < _param->_nb_port_write; num_port ++) |
---|
| 143 | { |
---|
| 144 | if ((nb_val < nb_request) and |
---|
| 145 | (WRITE_VAL [num_port].read() == 0)) |
---|
| 146 | { |
---|
| 147 | cout << "(" << num_port << ") [" << tab_address[nb_val] << "] <= " << tab_data[tab_address[nb_val]] << endl; |
---|
| 148 | |
---|
| 149 | WRITE_VAL [num_port] .write(1); |
---|
| 150 | WRITE_DATA [num_port] .write(tab_data[tab_address[nb_val]]); |
---|
| 151 | WRITE_ADDRESS [num_port] .write(tab_address[nb_val]); |
---|
| 152 | |
---|
| 153 | nb_val ++; |
---|
| 154 | |
---|
| 155 | // Address can be not a multiple of nb_port_write |
---|
| 156 | if (nb_val >= nb_request) |
---|
| 157 | break; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | SC_START(1); |
---|
| 162 | |
---|
| 163 | // reset write_val port |
---|
| 164 | for (uint32_t num_port=0; num_port < _param->_nb_port_write; num_port ++) |
---|
| 165 | { |
---|
| 166 | if ((WRITE_ACK [num_port].read() == 1) and |
---|
| 167 | (WRITE_VAL [num_port].read() == 1)) |
---|
| 168 | { |
---|
| 169 | WRITE_VAL [num_port] .write(0); |
---|
| 170 | nb_ack ++; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
[131] | 174 | // SC_START(0); |
---|
[53] | 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | if (simulate_read == true) |
---|
| 179 | { |
---|
| 180 | cout << "<" << name << "> 2) Read the RegisterFile (no write)" << endl; |
---|
| 181 | |
---|
| 182 | nb_val = 0; |
---|
| 183 | nb_ack = 0; |
---|
| 184 | Tdata_t read_address [_param->_nb_port_read]; |
---|
| 185 | |
---|
| 186 | while (nb_ack < nb_request) |
---|
| 187 | { |
---|
[113] | 188 | cout << "cycle : " << static_cast<uint32_t> (simulation_cycle()) << endl; |
---|
[53] | 189 | |
---|
| 190 | for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++) |
---|
| 191 | { |
---|
| 192 | if ((nb_val < nb_request) and |
---|
| 193 | (READ_VAL [num_port].read() == 0)) |
---|
| 194 | { |
---|
| 195 | read_address [num_port] = tab_address[nb_val]; |
---|
| 196 | READ_VAL [num_port].write(1); |
---|
| 197 | READ_ADDRESS [num_port].write(read_address [num_port]); |
---|
| 198 | |
---|
| 199 | nb_val ++; |
---|
| 200 | |
---|
| 201 | if (nb_val >= nb_request) |
---|
| 202 | break; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | SC_START(1); |
---|
| 207 | |
---|
| 208 | // reset write_val port |
---|
| 209 | for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++) |
---|
| 210 | { |
---|
| 211 | if ((READ_ACK [num_port].read() == 1) and |
---|
| 212 | (READ_VAL [num_port].read() == 1)) |
---|
| 213 | { |
---|
| 214 | READ_VAL [num_port] .write(0); |
---|
| 215 | |
---|
| 216 | cout << "(" << num_port << ") [" << read_address [num_port] << "] => " << READ_DATA [num_port].read() << endl; |
---|
| 217 | |
---|
| 218 | TEST(Tdata_t,READ_DATA [num_port].read(), tab_data[read_address [num_port]]); |
---|
| 219 | nb_ack ++; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
[131] | 223 | // SC_START(0); |
---|
[53] | 224 | } |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | /******************************************************** |
---|
| 229 | * Simulation - End |
---|
| 230 | ********************************************************/ |
---|
| 231 | |
---|
| 232 | TEST_OK ("End of Simulation"); |
---|
| 233 | delete _time; |
---|
| 234 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 235 | |
---|
| 236 | delete CLOCK; |
---|
| 237 | delete NRESET; |
---|
| 238 | #endif |
---|
| 239 | |
---|
| 240 | delete _RegisterFile; |
---|
| 241 | } |
---|