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

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