source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/src/test.cpp @ 50

Last change on this file since 50 was 50, checked in by rosiere, 17 years ago

Changement dans le répertoire "New_Component" afin que les composants nouvellement crées peuvent compiler

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