[2] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
[15] | 9 | #include "Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/include/test.h" |
---|
[44] | 10 | #include "Common/include/Test.h" |
---|
[2] | 11 | |
---|
| 12 | void test (string name, |
---|
[15] | 13 | morpheo::behavioural::generic::registerfile::registerfile_monolithic::Parameters param) |
---|
[2] | 14 | { |
---|
| 15 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 16 | |
---|
| 17 | try |
---|
| 18 | { |
---|
| 19 | cout << param.print(1); |
---|
| 20 | param.test(); |
---|
| 21 | } |
---|
| 22 | catch (morpheo::ErrorMorpheo & error) |
---|
| 23 | { |
---|
| 24 | cout << "<" << name << "> : " << error.what (); |
---|
| 25 | return; |
---|
| 26 | } |
---|
| 27 | catch (...) |
---|
| 28 | { |
---|
| 29 | cerr << "<" << name << "> : This test must generate a error" << endl; |
---|
| 30 | exit (EXIT_FAILURE); |
---|
| 31 | } |
---|
| 32 | |
---|
[15] | 33 | RegisterFile_Monolithic * registerfile = new RegisterFile_Monolithic (name.c_str(), |
---|
[2] | 34 | #ifdef STATISTICS |
---|
[15] | 35 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
[2] | 36 | #endif |
---|
[15] | 37 | param); |
---|
[2] | 38 | |
---|
| 39 | #ifdef SYSTEMC |
---|
| 40 | /********************************************************************* |
---|
| 41 | * Déclarations des signaux |
---|
| 42 | *********************************************************************/ |
---|
| 43 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
[6] | 44 | sc_signal<Tcontrol_t> NRESET; |
---|
[2] | 45 | |
---|
[6] | 46 | sc_signal<Tcontrol_t> READ_VAL [param._nb_port_read]; |
---|
| 47 | sc_signal<Tcontrol_t> READ_ACK [param._nb_port_read]; |
---|
[2] | 48 | sc_signal<Taddress_t> READ_ADDRESS [param._nb_port_read]; |
---|
| 49 | sc_signal<Tdata_t> READ_DATA [param._nb_port_read]; |
---|
| 50 | |
---|
[6] | 51 | sc_signal<Tcontrol_t> WRITE_VAL [param._nb_port_write]; |
---|
| 52 | sc_signal<Tcontrol_t> WRITE_ACK [param._nb_port_write]; |
---|
[2] | 53 | sc_signal<Taddress_t> WRITE_ADDRESS [param._nb_port_write]; |
---|
| 54 | sc_signal<Tdata_t> WRITE_DATA [param._nb_port_write]; |
---|
| 55 | |
---|
| 56 | /******************************************************** |
---|
| 57 | * Instanciation |
---|
| 58 | ********************************************************/ |
---|
| 59 | |
---|
[15] | 60 | cout << "<" << name << "> Instanciation of registerfile" << endl; |
---|
[2] | 61 | |
---|
| 62 | (*(registerfile->in_CLOCK)) (CLOCK); |
---|
[6] | 63 | (*(registerfile->in_NRESET)) (NRESET); |
---|
[2] | 64 | |
---|
| 65 | for (uint32_t i=0; i<param._nb_port_read; i++) |
---|
| 66 | { |
---|
[6] | 67 | (*(registerfile-> in_READ_VAL [i])) (READ_VAL [i]); |
---|
| 68 | (*(registerfile->out_READ_ACK [i])) (READ_ACK [i]); |
---|
[2] | 69 | (*(registerfile-> in_READ_ADDRESS [i])) (READ_ADDRESS [i]); |
---|
| 70 | (*(registerfile->out_READ_DATA [i])) (READ_DATA [i]); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | for (uint32_t i=0; i<param._nb_port_write; i++) |
---|
| 74 | { |
---|
[6] | 75 | (*(registerfile-> in_WRITE_VAL [i])) (WRITE_VAL [i]); |
---|
| 76 | (*(registerfile->out_WRITE_ACK [i])) (WRITE_ACK [i]); |
---|
[2] | 77 | (*(registerfile-> in_WRITE_ADDRESS [i])) (WRITE_ADDRESS [i]); |
---|
| 78 | (*(registerfile-> in_WRITE_DATA [i])) (WRITE_DATA [i]); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /******************************************************** |
---|
| 82 | * Simulation - Begin |
---|
| 83 | ********************************************************/ |
---|
| 84 | |
---|
| 85 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 86 | // Initialisation |
---|
| 87 | |
---|
| 88 | sc_start(0); |
---|
| 89 | |
---|
| 90 | for (uint32_t i=0; i<param._nb_port_write; i++) |
---|
[6] | 91 | WRITE_VAL [i] .write (0); |
---|
[2] | 92 | |
---|
| 93 | for (uint32_t i=0; i<param._nb_port_read; i++) |
---|
[6] | 94 | READ_VAL [i] .write (0); |
---|
[2] | 95 | |
---|
[42] | 96 | NRESET.write(0); |
---|
| 97 | |
---|
[2] | 98 | sc_start(5); |
---|
| 99 | |
---|
[42] | 100 | NRESET.write(1); |
---|
| 101 | |
---|
[2] | 102 | cout << "<" << name << "> Write the RegisterFile (no read)" << endl; |
---|
| 103 | |
---|
| 104 | uint32_t grain = 0; |
---|
| 105 | //uint32_t grain = static_cast<uint32_t>(time(NULL)); |
---|
| 106 | |
---|
| 107 | srand(grain); |
---|
| 108 | |
---|
| 109 | Tdata_t data, data_wait; |
---|
| 110 | Taddress_t address = 0; |
---|
| 111 | |
---|
| 112 | while (address < param._nb_word) |
---|
| 113 | { |
---|
| 114 | uint32_t num_port = 0; |
---|
| 115 | |
---|
| 116 | cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl; |
---|
| 117 | |
---|
| 118 | while (num_port<param._nb_port_write) |
---|
| 119 | { |
---|
| 120 | data = rand()%(1<<(param._size_word-1)); |
---|
| 121 | |
---|
| 122 | cout << "(" << num_port << ") [" << address << "] <= " << data << endl; |
---|
[6] | 123 | WRITE_VAL [num_port] .write(1); |
---|
[2] | 124 | WRITE_DATA [num_port] .write(data); |
---|
| 125 | WRITE_ADDRESS [num_port] .write(address); |
---|
| 126 | |
---|
| 127 | address ++; |
---|
| 128 | num_port ++; |
---|
| 129 | // Address can be not a multiple of nb_port_write |
---|
| 130 | if (address >= param._nb_word) |
---|
| 131 | break; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | while (num_port<param._nb_port_write) |
---|
| 135 | { |
---|
[6] | 136 | WRITE_VAL [num_port] .write(0); |
---|
[2] | 137 | num_port ++; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | sc_start(1); |
---|
| 141 | } |
---|
| 142 | cout << "<" << name << "> Read the RegisterFile (no write)" << endl; |
---|
| 143 | |
---|
| 144 | srand(grain); |
---|
| 145 | |
---|
| 146 | for (uint32_t i=0; i<param._nb_port_write; i++) |
---|
[6] | 147 | WRITE_VAL [i] .write (0); |
---|
[2] | 148 | |
---|
| 149 | sc_start(1); |
---|
| 150 | |
---|
| 151 | address = 0; |
---|
| 152 | while (address < param._nb_word) |
---|
| 153 | { |
---|
| 154 | uint32_t num_port = 0; |
---|
| 155 | |
---|
| 156 | cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl; |
---|
| 157 | |
---|
| 158 | while (num_port<param._nb_port_read) |
---|
| 159 | { |
---|
[6] | 160 | READ_VAL [num_port] .write(1); |
---|
[2] | 161 | READ_ADDRESS [num_port] .write(address); |
---|
| 162 | |
---|
| 163 | sc_start(0); // evaluation |
---|
| 164 | |
---|
| 165 | data_wait = rand()%(1<<(param._size_word-1)); |
---|
| 166 | data = READ_DATA [num_port] .read(); |
---|
| 167 | |
---|
| 168 | cout << "(" << num_port << ") [" << address << "] => " << data << endl; |
---|
| 169 | |
---|
| 170 | TEST(Tdata_t,data,data_wait); |
---|
| 171 | |
---|
| 172 | address ++; |
---|
| 173 | num_port ++; |
---|
| 174 | if (address >= param._nb_word) |
---|
| 175 | break; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | while (num_port<param._nb_port_read) |
---|
| 179 | { |
---|
[6] | 180 | READ_VAL [num_port] .write(0); |
---|
[2] | 181 | num_port ++; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | sc_start(1); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | for (uint32_t i=0; i<param._nb_port_read; i++) |
---|
[6] | 188 | READ_VAL [i] .write (0); |
---|
[2] | 189 | |
---|
| 190 | sc_start(1); |
---|
| 191 | |
---|
| 192 | /******************************************************** |
---|
| 193 | * Simulation - End |
---|
| 194 | ********************************************************/ |
---|
| 195 | |
---|
| 196 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 197 | |
---|
| 198 | #endif |
---|
| 199 | |
---|
| 200 | delete registerfile; |
---|
| 201 | } |
---|