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

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