[53] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
[57] | 9 | #define NB_ITERATION 1 |
---|
| 10 | #define CYCLE_MAX (10240*NB_ITERATION) |
---|
[53] | 11 | |
---|
| 12 | #include "Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/SelfTest/include/test.h" |
---|
| 13 | #include "Common/include/Test.h" |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #define LABEL(str) \ |
---|
| 17 | { \ |
---|
| 18 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} " << str << endl; \ |
---|
| 19 | } while(0) |
---|
| 20 | |
---|
| 21 | #define SC_START(cycle) \ |
---|
| 22 | do \ |
---|
| 23 | { \ |
---|
| 24 | if (static_cast<uint32_t>(sc_simulation_time()) > CYCLE_MAX) \ |
---|
| 25 | { \ |
---|
| 26 | TEST_KO("Maximal cycles Reached"); \ |
---|
| 27 | } \ |
---|
| 28 | sc_start(cycle); \ |
---|
| 29 | } while(0) |
---|
| 30 | |
---|
| 31 | void test (string name, |
---|
| 32 | morpheo::behavioural::generic::registerfile::registerfile_multi_banked::Parameters * _param) |
---|
| 33 | { |
---|
| 34 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 35 | |
---|
[57] | 36 | |
---|
| 37 | #ifdef STATISTICS |
---|
| 38 | morpheo::behavioural::Parameters_Statistics * _param_stat = new morpheo::behavioural::Parameters_Statistics(5,50); |
---|
| 39 | #endif |
---|
| 40 | |
---|
[53] | 41 | RegisterFile_Multi_Banked * _RegisterFile_Multi_Banked = new RegisterFile_Multi_Banked (name.c_str(), |
---|
| 42 | #ifdef STATISTICS |
---|
[57] | 43 | _param_stat, |
---|
[53] | 44 | #endif |
---|
[57] | 45 | _param); |
---|
[53] | 46 | |
---|
| 47 | #ifdef SYSTEMC |
---|
| 48 | /********************************************************************* |
---|
| 49 | * Déclarations des signaux |
---|
| 50 | *********************************************************************/ |
---|
| 51 | sc_clock * CLOCK; |
---|
| 52 | sc_signal<Tcontrol_t> * NRESET; |
---|
| 53 | |
---|
| 54 | sc_signal<Tcontrol_t> READ_VAL [_param->_nb_port_read]; |
---|
| 55 | sc_signal<Tcontrol_t> READ_ACK [_param->_nb_port_read]; |
---|
| 56 | sc_signal<Taddress_t> READ_ADDRESS [_param->_nb_port_read]; |
---|
| 57 | sc_signal<Tdata_t> READ_DATA [_param->_nb_port_read]; |
---|
| 58 | |
---|
| 59 | sc_signal<Tcontrol_t> WRITE_VAL [_param->_nb_port_write]; |
---|
| 60 | sc_signal<Tcontrol_t> WRITE_ACK [_param->_nb_port_write]; |
---|
| 61 | sc_signal<Taddress_t> WRITE_ADDRESS [_param->_nb_port_write]; |
---|
| 62 | sc_signal<Tdata_t> WRITE_DATA [_param->_nb_port_write]; |
---|
| 63 | |
---|
| 64 | string rename; |
---|
| 65 | |
---|
| 66 | CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
| 67 | NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
| 68 | |
---|
| 69 | /******************************************************** |
---|
| 70 | * Instanciation |
---|
| 71 | ********************************************************/ |
---|
| 72 | |
---|
| 73 | cout << "<" << name << "> Instanciation of _RegisterFile_Multi_Banked" << endl; |
---|
| 74 | |
---|
| 75 | (*(_RegisterFile_Multi_Banked->in_CLOCK)) (*(CLOCK)); |
---|
| 76 | (*(_RegisterFile_Multi_Banked->in_NRESET)) (*(NRESET)); |
---|
| 77 | |
---|
| 78 | for (uint32_t i=0; i<_param->_nb_port_read; i++) |
---|
| 79 | { |
---|
| 80 | (*(_RegisterFile_Multi_Banked-> in_READ_VAL [i])) (READ_VAL [i]); |
---|
| 81 | (*(_RegisterFile_Multi_Banked->out_READ_ACK [i])) (READ_ACK [i]); |
---|
[62] | 82 | if (_param->_have_port_address==true) |
---|
[53] | 83 | (*(_RegisterFile_Multi_Banked-> in_READ_ADDRESS [i])) (READ_ADDRESS [i]); |
---|
| 84 | (*(_RegisterFile_Multi_Banked->out_READ_DATA [i])) (READ_DATA [i]); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | for (uint32_t i=0; i<_param->_nb_port_write; i++) |
---|
| 88 | { |
---|
| 89 | (*(_RegisterFile_Multi_Banked-> in_WRITE_VAL [i])) (WRITE_VAL [i]); |
---|
| 90 | (*(_RegisterFile_Multi_Banked->out_WRITE_ACK [i])) (WRITE_ACK [i]); |
---|
[62] | 91 | if (_param->_have_port_address==true) |
---|
[53] | 92 | (*(_RegisterFile_Multi_Banked-> in_WRITE_ADDRESS [i])) (WRITE_ADDRESS [i]); |
---|
| 93 | (*(_RegisterFile_Multi_Banked-> in_WRITE_DATA [i])) (WRITE_DATA [i]); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 97 | Time * _time = new Time(); |
---|
| 98 | |
---|
| 99 | /******************************************************** |
---|
| 100 | * Simulation - Begin |
---|
| 101 | ********************************************************/ |
---|
| 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 | |
---|
[58] | 180 | { |
---|
| 181 | cout << "<" << name << "> 2) Read the RegisterFile (no write)" << endl; |
---|
| 182 | |
---|
| 183 | nb_val = 0; |
---|
| 184 | nb_ack = 0; |
---|
| 185 | Tdata_t read_address [_param->_nb_port_read]; |
---|
| 186 | |
---|
| 187 | while (nb_ack < nb_request) |
---|
| 188 | { |
---|
| 189 | cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl; |
---|
| 190 | |
---|
| 191 | for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++) |
---|
| 192 | { |
---|
| 193 | if ((nb_val < nb_request) and |
---|
| 194 | (READ_VAL [num_port].read() == 0)) |
---|
| 195 | { |
---|
| 196 | read_address [num_port] = tab_address[nb_val]; |
---|
| 197 | READ_VAL [num_port].write(1); |
---|
| 198 | READ_ADDRESS [num_port].write(read_address [num_port]); |
---|
| 199 | |
---|
| 200 | nb_val ++; |
---|
| 201 | |
---|
| 202 | if (nb_val >= nb_request) |
---|
| 203 | break; |
---|
| 204 | } |
---|
| 205 | } |
---|
[53] | 206 | |
---|
[58] | 207 | SC_START(1); |
---|
| 208 | |
---|
| 209 | // reset write_val port |
---|
| 210 | for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++) |
---|
| 211 | { |
---|
| 212 | if ((READ_ACK [num_port].read() == 1) and |
---|
| 213 | (READ_VAL [num_port].read() == 1)) |
---|
| 214 | { |
---|
| 215 | READ_VAL [num_port] .write(0); |
---|
| 216 | |
---|
| 217 | cout << "(" << num_port << ") [" << read_address [num_port] << "] => " << READ_DATA [num_port].read() << endl; |
---|
| 218 | |
---|
| 219 | TEST(Tdata_t,READ_DATA [num_port].read(), tab_data[read_address [num_port]]); |
---|
| 220 | nb_ack ++; |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | SC_START(0); |
---|
| 225 | } |
---|
| 226 | } |
---|
[53] | 227 | } |
---|
| 228 | |
---|
| 229 | /******************************************************** |
---|
| 230 | * Simulation - End |
---|
| 231 | ********************************************************/ |
---|
| 232 | |
---|
| 233 | TEST_OK("End of Simulation"); |
---|
| 234 | delete _time; |
---|
| 235 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 236 | |
---|
| 237 | delete CLOCK; |
---|
| 238 | delete NRESET; |
---|
| 239 | #endif |
---|
| 240 | |
---|
| 241 | delete _RegisterFile_Multi_Banked; |
---|
| 242 | } |
---|