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

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

Banc de registres

  • ajout de 2 ports additionnels inutiles (reset et ack) mais nécessaire pour uniformisé les différentes version du banc de registres
File size: 5.3 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#include "Behavioural/Generic/RegisterFile/SelfTest/include/test.h"
10#include "Include/Test.h"
11
12void test (string name,
13           morpheo::behavioural::generic::registerfile::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 * registerfile = new RegisterFile (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  sc_start(5);
97
98  cout << "<" << name << "> Write the RegisterFile (no read)" << endl;
99
100  uint32_t grain = 0;
101  //uint32_t grain = static_cast<uint32_t>(time(NULL));
102 
103  srand(grain);
104 
105  Tdata_t    data, data_wait;
106  Taddress_t address = 0;
107
108  while (address < param._nb_word)
109    {
110      uint32_t num_port = 0;
111     
112      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
113
114      while (num_port<param._nb_port_write)
115        {
116          data = rand()%(1<<(param._size_word-1));
117
118          cout << "(" << num_port << ") [" << address << "] <= " << data << endl;
119          WRITE_VAL  [num_port] .write(1);
120          WRITE_DATA    [num_port] .write(data);
121          WRITE_ADDRESS [num_port] .write(address);
122
123          address  ++;
124          num_port ++;
125          // Address can be not a multiple of nb_port_write
126          if (address >= param._nb_word)
127            break;
128        }
129
130      while (num_port<param._nb_port_write)
131        {
132          WRITE_VAL  [num_port] .write(0);
133          num_port ++;
134        }
135
136      sc_start(1);
137    }
138  cout << "<" << name << "> Read the RegisterFile (no write)" << endl;
139
140  srand(grain);
141
142  for (uint32_t i=0; i<param._nb_port_write; i++)
143    WRITE_VAL [i] .write (0);
144
145  sc_start(1);
146
147  address  = 0;
148  while (address < param._nb_word)
149    {
150      uint32_t num_port = 0;
151
152      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
153     
154      while (num_port<param._nb_port_read)
155        {
156          READ_VAL  [num_port] .write(1);
157          READ_ADDRESS [num_port] .write(address);
158
159          sc_start(0); // evaluation
160
161          data_wait = rand()%(1<<(param._size_word-1));
162          data      = READ_DATA    [num_port] .read();
163
164          cout << "(" << num_port << ") [" << address << "] => " << data << endl;
165
166          TEST(Tdata_t,data,data_wait);
167
168          address  ++;
169          num_port ++;
170          if (address >= param._nb_word)
171            break;
172        }
173
174      while (num_port<param._nb_port_read)
175        {
176          READ_VAL  [num_port] .write(0);
177          num_port ++;
178        }
179
180      sc_start(1);
181    }
182
183  for (uint32_t i=0; i<param._nb_port_read; i++)
184    READ_VAL  [i] .write (0);
185
186  sc_start(1);
187
188  /********************************************************
189   * Simulation - End
190   ********************************************************/
191
192  cout << "<" << name << "> ............ Stop Simulation" << endl;
193
194#endif
195
196  delete registerfile;
197}
Note: See TracBrowser for help on using the repository browser.