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

Last change on this file since 131 was 131, checked in by rosiere, 15 years ago

1) add constant method
2) test with systemc 2.2.0

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1/*
2 * $Id: test.cpp 131 2009-07-08 18:40:08Z rosiere $
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
15void test (string name,
16           morpheo::behavioural::generic::registerfile::registerfile_multi_banked::Parameters * _param)
17{
18  cout << "<" << name << "> : Simulation SystemC" << endl;
19
20
21#ifdef STATISTICS
22  morpheo::behavioural::Parameters_Statistics * _param_stat = new morpheo::behavioural::Parameters_Statistics(5,50);
23#endif
24
25  _model.set_model(MODEL_SYSTEMC,true);
26
27  Tusage_t _usage = USE_ALL;
28
29//   _usage = usage_unset(_usage,USE_SYSTEMC              );
30//   _usage = usage_unset(_usage,USE_VHDL                 );
31//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH       );
32//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT);
33//   _usage = usage_unset(_usage,USE_POSITION             );
34//    _usage = usage_unset(_usage,USE_STATISTICS           );
35//   _usage = usage_unset(_usage,USE_INFORMATION          );
36
37  RegisterFile_Multi_Banked * _RegisterFile_Multi_Banked = new RegisterFile_Multi_Banked
38    (name.c_str(),
39#ifdef STATISTICS
40     _param_stat,
41#endif
42     _param,
43     _usage);
44 
45#ifdef SYSTEMC
46  /*********************************************************************
47   * Déclarations des signaux
48   *********************************************************************/
49  sc_clock                               * CLOCK;
50  sc_signal<Tcontrol_t>                  * NRESET;
51
52  sc_signal<Tcontrol_t>                    READ_VAL      [_param->_nb_port_read];
53  sc_signal<Tcontrol_t>                    READ_ACK      [_param->_nb_port_read];
54  sc_signal<Taddress_t>                    READ_ADDRESS  [_param->_nb_port_read];
55  sc_signal<Tdata_t>                       READ_DATA     [_param->_nb_port_read];
56
57  sc_signal<Tcontrol_t>                    WRITE_VAL     [_param->_nb_port_write];
58  sc_signal<Tcontrol_t>                    WRITE_ACK     [_param->_nb_port_write];
59  sc_signal<Taddress_t>                    WRITE_ADDRESS [_param->_nb_port_write];
60  sc_signal<Tdata_t>                       WRITE_DATA    [_param->_nb_port_write];
61
62  string rename;
63
64  CLOCK                                  = new sc_clock ("clock", 1.0, 0.5);
65  NRESET                                 = new sc_signal<Tcontrol_t> ("NRESET");
66 
67  /********************************************************
68   * Instanciation
69   ********************************************************/
70 
71  cout << "<" << name << "> Instanciation of _RegisterFile_Multi_Banked" << endl;
72 
73  (*(_RegisterFile_Multi_Banked->in_CLOCK))        (*(CLOCK));
74  (*(_RegisterFile_Multi_Banked->in_NRESET))       (*(NRESET));
75
76  for (uint32_t i=0; i<_param->_nb_port_read; i++)
77    {
78      (*(_RegisterFile_Multi_Banked-> in_READ_VAL      [i]))        (READ_VAL      [i]);
79      (*(_RegisterFile_Multi_Banked->out_READ_ACK      [i]))        (READ_ACK      [i]);
80      if (_param->_have_port_address==true)
81      (*(_RegisterFile_Multi_Banked-> in_READ_ADDRESS  [i]))        (READ_ADDRESS  [i]);
82      (*(_RegisterFile_Multi_Banked->out_READ_DATA     [i]))        (READ_DATA     [i]);
83    }
84
85  for (uint32_t i=0; i<_param->_nb_port_write; i++)
86    {
87      (*(_RegisterFile_Multi_Banked-> in_WRITE_VAL     [i]))        (WRITE_VAL     [i]);
88      (*(_RegisterFile_Multi_Banked->out_WRITE_ACK     [i]))        (WRITE_ACK     [i]);
89      if (_param->_have_port_address==true)
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> (simulation_cycle()) << 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> (simulation_cycle()) << 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.