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
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION 32
10
11#include "Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/include/test.h"
12#include "Common/include/Test.h"
13
14void test (string name,
15           morpheo::behavioural::generic::registerfile::registerfile_monolithic::Parameters param)
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
35  RegisterFile_Monolithic * registerfile = new RegisterFile_Monolithic (name.c_str()
36#ifdef STATISTICS
37                                                                        ,morpheo::behavioural::Parameters_Statistics(5,1000)
38#endif
39                                                                        ,param);
40 
41#ifdef SYSTEMC
42  /*********************************************************************
43   * Déclarations des signaux
44   *********************************************************************/
45  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
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  /********************************************************
59   * Instanciation
60   ********************************************************/
61 
62  cout << "<" << name << "> Instanciation of registerfile" << endl;
63 
64  (*(registerfile->in_CLOCK))        (CLOCK);
65  (*(registerfile->in_NRESET))       (NRESET);
66
67  for (uint32_t i=0; i<param._nb_port_read; i++)
68    {
69      (*(registerfile-> in_READ_VAL      [i]))        (READ_VAL      [i]);
70      (*(registerfile->out_READ_ACK      [i]))        (READ_ACK      [i]);
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    {
77      (*(registerfile-> in_WRITE_VAL     [i]))        (WRITE_VAL     [i]);
78      (*(registerfile->out_WRITE_ACK     [i]))        (WRITE_ACK     [i]);
79      (*(registerfile-> in_WRITE_ADDRESS [i]))        (WRITE_ADDRESS [i]);
80      (*(registerfile-> in_WRITE_DATA    [i]))        (WRITE_DATA    [i]);
81    }
82 
83  cout << "<" << name << "> Start Simulation ............" << endl;
84  Time * _time = new Time();
85
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++)
95    WRITE_VAL [i] .write (0);
96
97  for (uint32_t i=0; i<param._nb_port_read; i++)
98    READ_VAL  [i] .write (0);
99
100  NRESET.write(0);
101
102  sc_start(5);
103
104  NRESET.write(1);
105
106
107  for (uint32_t nb_iteration=0; nb_iteration < NB_ITERATION; nb_iteration ++)
108    {
109      cout << "<" << name << "> 1) Write the RegisterFile (no read)" << endl;
110
111      // random init
112      uint32_t grain = 0;
113      //uint32_t grain = static_cast<uint32_t>(time(NULL));
114     
115      srand(grain);
116
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)
126        {
127          cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
128
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);
147
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            }
158
159          sc_start(0);
160        }
161     
162      address_next = 0;
163      nb_ack       = 0;
164
165      cout << "<" << name << "> 2) Read the RegisterFile (no write)" << endl;
166     
167      Tdata_t read_address [param._nb_port_read];
168
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++;
179
180                  READ_VAL     [num_port].write(1);
181                  READ_ADDRESS [num_port].write(read_address [num_port]);
182
183                  if (address_next >= param._nb_word)
184                    break;
185                }
186            }
187
188          sc_start(1);
189
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);
197
198                  cout << "(" << num_port << ") [" << read_address [num_port] << "] => " << READ_DATA [num_port].read() << endl;
199
200                  TEST(Tdata_t,READ_DATA [num_port].read(), tab[read_address [num_port]]);
201                  nb_ack ++;
202                }
203            }
204
205          sc_start(0);
206        }
207    }
208
209  /********************************************************
210   * Simulation - End
211   ********************************************************/
212
213  TEST_STR(bool,true,true, "End of Simulation");
214  delete _time;
215  cout << "<" << name << "> ............ Stop Simulation" << endl;
216
217#endif
218
219  delete registerfile;
220}
Note: See TracBrowser for help on using the repository browser.