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