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

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

Modification des classes d'encapsulation des interfaces.
Stable sur tous les composants actuels

File size: 5.4 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#include "Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/include/test.h"
10#include "Common/include/Test.h"
11
12void test (string name,
13           morpheo::behavioural::generic::registerfile::registerfile_monolithic::Parameters param)
14{
15  cout << "<" << name << "> : Simulation SystemC" << endl;
16
17  try 
18    {
19      cout << param.print(1);
20      param.test();
21    }
22  catch (morpheo::ErrorMorpheo & error)
23    {
24      cout << "<" << name << "> : " <<  error.what ();
25      return;
26    }
27  catch (...)
28    {
29      cerr << "<" << name << "> : This test must generate a error" << endl;
30      exit (EXIT_FAILURE);
31    }
32
33  RegisterFile_Monolithic * registerfile = new RegisterFile_Monolithic (name.c_str(),
34#ifdef STATISTICS
35                                                                        morpheo::behavioural::Parameters_Statistics(5,50),
36#endif
37                                                                        param);
38 
39#ifdef SYSTEMC
40  /*********************************************************************
41   * Déclarations des signaux
42   *********************************************************************/
43  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
44  sc_signal<Tcontrol_t>                    NRESET;
45 
46  sc_signal<Tcontrol_t>                    READ_VAL      [param._nb_port_read];
47  sc_signal<Tcontrol_t>                    READ_ACK      [param._nb_port_read];
48  sc_signal<Taddress_t>                    READ_ADDRESS  [param._nb_port_read];
49  sc_signal<Tdata_t>                       READ_DATA     [param._nb_port_read];
50
51  sc_signal<Tcontrol_t>                    WRITE_VAL     [param._nb_port_write];
52  sc_signal<Tcontrol_t>                    WRITE_ACK     [param._nb_port_write];
53  sc_signal<Taddress_t>                    WRITE_ADDRESS [param._nb_port_write];
54  sc_signal<Tdata_t>                       WRITE_DATA    [param._nb_port_write];
55
56  /********************************************************
57   * Instanciation
58   ********************************************************/
59 
60  cout << "<" << name << "> Instanciation of registerfile" << endl;
61 
62  (*(registerfile->in_CLOCK))        (CLOCK);
63  (*(registerfile->in_NRESET))       (NRESET);
64
65  for (uint32_t i=0; i<param._nb_port_read; i++)
66    {
67      (*(registerfile-> in_READ_VAL      [i]))        (READ_VAL      [i]);
68      (*(registerfile->out_READ_ACK      [i]))        (READ_ACK      [i]);
69      (*(registerfile-> in_READ_ADDRESS  [i]))        (READ_ADDRESS  [i]);
70      (*(registerfile->out_READ_DATA     [i]))        (READ_DATA     [i]);
71    }
72
73  for (uint32_t i=0; i<param._nb_port_write; i++)
74    {
75      (*(registerfile-> in_WRITE_VAL     [i]))        (WRITE_VAL     [i]);
76      (*(registerfile->out_WRITE_ACK     [i]))        (WRITE_ACK     [i]);
77      (*(registerfile-> in_WRITE_ADDRESS [i]))        (WRITE_ADDRESS [i]);
78      (*(registerfile-> in_WRITE_DATA    [i]))        (WRITE_DATA    [i]);
79    }
80 
81  /********************************************************
82   * Simulation - Begin
83   ********************************************************/
84
85  cout << "<" << name << "> Start Simulation ............" << endl;
86  // Initialisation
87
88  sc_start(0);
89 
90  for (uint32_t i=0; i<param._nb_port_write; i++)
91    WRITE_VAL [i] .write (0);
92
93  for (uint32_t i=0; i<param._nb_port_read; i++)
94    READ_VAL  [i] .write (0);
95
96  NRESET.write(0);
97
98  sc_start(5);
99
100  NRESET.write(1);
101
102  cout << "<" << name << "> Write the RegisterFile (no read)" << endl;
103
104  uint32_t grain = 0;
105  //uint32_t grain = static_cast<uint32_t>(time(NULL));
106 
107  srand(grain);
108 
109  Tdata_t    data, data_wait;
110  Taddress_t address = 0;
111
112  while (address < param._nb_word)
113    {
114      uint32_t num_port = 0;
115     
116      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
117
118      while (num_port<param._nb_port_write)
119        {
120          data = rand()%(1<<(param._size_word-1));
121
122          cout << "(" << num_port << ") [" << address << "] <= " << data << endl;
123          WRITE_VAL  [num_port] .write(1);
124          WRITE_DATA    [num_port] .write(data);
125          WRITE_ADDRESS [num_port] .write(address);
126
127          address  ++;
128          num_port ++;
129          // Address can be not a multiple of nb_port_write
130          if (address >= param._nb_word)
131            break;
132        }
133
134      while (num_port<param._nb_port_write)
135        {
136          WRITE_VAL  [num_port] .write(0);
137          num_port ++;
138        }
139
140      sc_start(1);
141    }
142  cout << "<" << name << "> Read the RegisterFile (no write)" << endl;
143
144  srand(grain);
145
146  for (uint32_t i=0; i<param._nb_port_write; i++)
147    WRITE_VAL [i] .write (0);
148
149  sc_start(1);
150
151  address  = 0;
152  while (address < param._nb_word)
153    {
154      uint32_t num_port = 0;
155
156      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
157     
158      while (num_port<param._nb_port_read)
159        {
160          READ_VAL  [num_port] .write(1);
161          READ_ADDRESS [num_port] .write(address);
162
163          sc_start(0); // evaluation
164
165          data_wait = rand()%(1<<(param._size_word-1));
166          data      = READ_DATA    [num_port] .read();
167
168          cout << "(" << num_port << ") [" << address << "] => " << data << endl;
169
170          TEST(Tdata_t,data,data_wait);
171
172          address  ++;
173          num_port ++;
174          if (address >= param._nb_word)
175            break;
176        }
177
178      while (num_port<param._nb_port_read)
179        {
180          READ_VAL  [num_port] .write(0);
181          num_port ++;
182        }
183
184      sc_start(1);
185    }
186
187  for (uint32_t i=0; i<param._nb_port_read; i++)
188    READ_VAL  [i] .write (0);
189
190  sc_start(1);
191
192  /********************************************************
193   * Simulation - End
194   ********************************************************/
195
196  cout << "<" << name << "> ............ Stop Simulation" << endl;
197
198#endif
199
200  delete registerfile;
201}
Note: See TracBrowser for help on using the repository browser.