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

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