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

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

Vhdl : RegisterFile_Multi_Banked - "full crossbar"
Correction d'un bug pour le "partial crossbar"

File size: 7.6 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 uint32_t nb_request    = _param->_nb_word;
101  // random init
102  const uint32_t grain         = 0;
103  //const uint32_t grain = static_cast<uint32_t>(time(NULL));
104 
105  srand(grain);
106
107  // Initialisation
108
109  SC_START(0);
110 
111  for (uint32_t i=0; i<_param->_nb_port_write; i++)
112    WRITE_VAL [i] .write (0);
113
114  for (uint32_t i=0; i<_param->_nb_port_read; i++)
115    READ_VAL  [i] .write (0);
116
117  NRESET->write(0);
118
119  SC_START(5);
120
121  NRESET->write(1);
122
123  for (uint32_t nb_iteration=0; nb_iteration < NB_ITERATION; nb_iteration ++)
124    {
125      cout << "<" << name << "> 1) Write the RegisterFile (no read)" << endl;
126
127      Taddress_t nb_val            = 0;
128      Taddress_t nb_ack            = 0;
129     
130      Tdata_t    tab_data    [_param->_nb_word];
131      Taddress_t tab_address [nb_request      ];
132 
133      for (uint32_t i=0; i<_param->_nb_word; i++)
134        tab_data    [i]= rand()%(1<<(_param->_size_word-1));
135      for (uint32_t i=0; i<nb_request; i++)
136        tab_address [i]= rand()%(1<<(_param->_size_address));
137
138      while (nb_ack < nb_request)
139        {
140          cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
141
142          for (uint32_t num_port=0; num_port < _param->_nb_port_write; num_port ++)
143            {
144              if ((nb_val            < nb_request) and
145                  (WRITE_VAL [num_port].read() == 0))
146                {
147                  cout << "(" << num_port << ") [" << tab_address[nb_val] << "] <= " << tab_data[tab_address[nb_val]] << endl;
148                 
149                  WRITE_VAL     [num_port] .write(1);
150                  WRITE_DATA    [num_port] .write(tab_data[tab_address[nb_val]]);
151                  WRITE_ADDRESS [num_port] .write(tab_address[nb_val]);
152
153                  nb_val ++;
154
155                  // Address can be not a multiple of nb_port_write
156                  if (nb_val >= nb_request)
157                    break;
158                }
159            }
160         
161          SC_START(1);
162
163          // reset write_val port
164          for (uint32_t num_port=0; num_port < _param->_nb_port_write; num_port ++)
165            {
166              if ((WRITE_ACK [num_port].read() == 1) and
167                  (WRITE_VAL [num_port].read() == 1))
168                {
169                  WRITE_VAL  [num_port] .write(0);
170                  nb_ack ++;
171                }
172            }
173
174          SC_START(0);
175        }
176     
177
178      {
179        cout << "<" << name << "> 2) Read the RegisterFile (no write)" << endl;
180       
181        nb_val = 0;
182        nb_ack = 0;
183        Tdata_t read_address [_param->_nb_port_read];
184       
185        while (nb_ack < nb_request)
186          {
187            cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
188           
189            for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++)
190              {
191                if ((nb_val < nb_request) and
192                    (READ_VAL [num_port].read() == 0))
193                  {
194                    read_address [num_port] = tab_address[nb_val];
195                    READ_VAL     [num_port].write(1);
196                    READ_ADDRESS [num_port].write(read_address [num_port]);
197                   
198                    nb_val ++;
199                   
200                    if (nb_val >= nb_request)
201                      break;
202                  }
203              }
204             
205            SC_START(1);
206           
207            // reset write_val port
208            for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++)
209              {
210                if ((READ_ACK [num_port].read() == 1) and
211                    (READ_VAL [num_port].read() == 1))
212                  {
213                    READ_VAL  [num_port] .write(0);
214                   
215                    cout << "(" << num_port << ") [" << read_address [num_port] << "] => " << READ_DATA [num_port].read() << endl;
216                   
217                    TEST(Tdata_t,READ_DATA [num_port].read(), tab_data[read_address [num_port]]);
218                    nb_ack ++;
219                  }
220              }
221           
222            SC_START(0);
223          }
224      }
225    }
226 
227  /********************************************************
228   * Simulation - End
229   ********************************************************/
230
231  TEST_OK("End of Simulation");
232  delete _time;
233  cout << "<" << name << "> ............ Stop Simulation" << endl;
234
235  delete CLOCK;
236  delete NRESET;
237#endif
238
239  delete _RegisterFile_Multi_Banked;
240}
Note: See TracBrowser for help on using the repository browser.