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

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

1) Add modelsim simulation systemC
2) Modelsim cosimulation systemC / VHDL is not finish !!!! (cf execute_queue and write_unit)
3) Add multi architecture
5) Add template for comparator, multiplier and divider
6) Change Message
Warning) Various test macro have change, many selftest can't compile

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