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

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 4.9 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 
45  sc_signal<Tcontrol_t>                    READ_ENABLE   [param._nb_port_read];
46  sc_signal<Taddress_t>                    READ_ADDRESS  [param._nb_port_read];
47  sc_signal<Tdata_t>                       READ_DATA     [param._nb_port_read];
48
49  sc_signal<Tcontrol_t>                    WRITE_ENABLE  [param._nb_port_write];
50  sc_signal<Taddress_t>                    WRITE_ADDRESS [param._nb_port_write];
51  sc_signal<Tdata_t>                       WRITE_DATA    [param._nb_port_write];
52
53  /********************************************************
54   * Instanciation
55   ********************************************************/
56 
57  cout << "<" << name << "> Instanciation of registerFile" << endl;
58 
59  (*(registerfile->in_CLOCK))        (CLOCK);
60
61  for (uint32_t i=0; i<param._nb_port_read; i++)
62    {
63      (*(registerfile-> in_READ_ENABLE   [i]))        (READ_ENABLE   [i]);
64      (*(registerfile-> in_READ_ADDRESS  [i]))        (READ_ADDRESS  [i]);
65      (*(registerfile->out_READ_DATA     [i]))        (READ_DATA     [i]);
66    }
67
68  for (uint32_t i=0; i<param._nb_port_write; i++)
69    {
70      (*(registerfile-> in_WRITE_ENABLE  [i]))        (WRITE_ENABLE  [i]);
71      (*(registerfile-> in_WRITE_ADDRESS [i]))        (WRITE_ADDRESS [i]);
72      (*(registerfile-> in_WRITE_DATA    [i]))        (WRITE_DATA    [i]);
73    }
74 
75  /********************************************************
76   * Simulation - Begin
77   ********************************************************/
78
79  cout << "<" << name << "> Start Simulation ............" << endl;
80  // Initialisation
81
82  sc_start(0);
83 
84  for (uint32_t i=0; i<param._nb_port_write; i++)
85    WRITE_ENABLE [i] .write (0);
86
87  for (uint32_t i=0; i<param._nb_port_read; i++)
88    READ_ENABLE  [i] .write (0);
89
90  sc_start(5);
91
92  cout << "<" << name << "> Write the RegisterFile (no read)" << endl;
93
94  uint32_t grain = 0;
95  //uint32_t grain = static_cast<uint32_t>(time(NULL));
96 
97  srand(grain);
98 
99  Tdata_t    data, data_wait;
100  Taddress_t address = 0;
101
102  while (address < param._nb_word)
103    {
104      uint32_t num_port = 0;
105     
106      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
107
108      while (num_port<param._nb_port_write)
109        {
110          data = rand()%(1<<(param._size_word-1));
111
112          cout << "(" << num_port << ") [" << address << "] <= " << data << endl;
113          WRITE_ENABLE  [num_port] .write(1);
114          WRITE_DATA    [num_port] .write(data);
115          WRITE_ADDRESS [num_port] .write(address);
116
117          address  ++;
118          num_port ++;
119          // Address can be not a multiple of nb_port_write
120          if (address >= param._nb_word)
121            break;
122        }
123
124      while (num_port<param._nb_port_write)
125        {
126          WRITE_ENABLE  [num_port] .write(0);
127          num_port ++;
128        }
129
130      sc_start(1);
131    }
132  cout << "<" << name << "> Read the RegisterFile (no write)" << endl;
133
134  srand(grain);
135
136  for (uint32_t i=0; i<param._nb_port_write; i++)
137    WRITE_ENABLE [i] .write (0);
138
139  sc_start(1);
140
141  address  = 0;
142  while (address < param._nb_word)
143    {
144      uint32_t num_port = 0;
145
146      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
147     
148      while (num_port<param._nb_port_read)
149        {
150          READ_ENABLE  [num_port] .write(1);
151          READ_ADDRESS [num_port] .write(address);
152
153          sc_start(0); // evaluation
154
155          data_wait = rand()%(1<<(param._size_word-1));
156          data      = READ_DATA    [num_port] .read();
157
158          cout << "(" << num_port << ") [" << address << "] => " << data << endl;
159
160          TEST(Tdata_t,data,data_wait);
161
162          address  ++;
163          num_port ++;
164          if (address >= param._nb_word)
165            break;
166        }
167
168      while (num_port<param._nb_port_read)
169        {
170          READ_ENABLE  [num_port] .write(0);
171          num_port ++;
172        }
173
174      sc_start(1);
175    }
176
177  for (uint32_t i=0; i<param._nb_port_read; i++)
178    READ_ENABLE  [i] .write (0);
179
180  sc_start(1);
181
182  /********************************************************
183   * Simulation - End
184   ********************************************************/
185
186  cout << "<" << name << "> ............ Stop Simulation" << endl;
187
188#endif
189
190  delete registerfile;
191}
Note: See TracBrowser for help on using the repository browser.