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

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