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