source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/Select/Select_Priority_Fixed/SelfTest/src/test.cpp @ 15

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

Interface normalisé
Début du banc de registres multi niveaux

File size: 4.4 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION 512
10
11#include "Behavioural/Generic/Select/Select_Priority_Fixed/SelfTest/include/test.h"
12#include "Include/Test.h"
13
14void test (string name,
15           morpheo::behavioural::generic::select::select_priority_fixed::Parameters _param)
16{
17  cout << "<" << name << "> : Simulation SystemC" << endl;
18
19  Select_Priority_Fixed * _Select_Priority_Fixed = new Select_Priority_Fixed (name.c_str(),
20#ifdef STATISTICS
21                                             morpheo::behavioural::Parameters_Statistics(5,50),
22#endif
23                                             _param);
24 
25#ifdef SYSTEMC
26  /*********************************************************************
27   * Déclarations des signaux
28   *********************************************************************/
29  sc_clock                         * CLOCK ;
30  sc_signal<Tcontrol_t>            * NRESET;
31  sc_signal<Tcontrol_t>           ** VAL   ;
32  sc_signal<Tcontrol_t>           ** ACK   ;
33  sc_signal<Tentity_t >            * ENTITY;
34  sc_signal<Tcontrol_t>            * ENTITY_ACK;
35
36  string rename;
37
38  CLOCK        = new sc_clock ("clock", 1.0, 0.5);
39  NRESET       = new sc_signal<Tcontrol_t> ("NRESET");
40  VAL          = new sc_signal<Tcontrol_t> * [_param._nb_entity];
41  ACK          = new sc_signal<Tcontrol_t> * [_param._nb_entity];
42
43  for (uint32_t i=0; i<_param._nb_entity; i++)
44    {
45      rename = "VAL_"+toString(i);
46      VAL [i] = new sc_signal<Tcontrol_t> (rename.c_str());
47      rename = "ACK_"+toString(i);
48      ACK [i] = new sc_signal<Tcontrol_t> (rename.c_str());
49    }
50 
51  ENTITY       = new sc_signal<Tentity_t>  ("entity");
52  ENTITY_ACK   = new sc_signal<Tcontrol_t> ("entity_ack");
53 
54  /********************************************************
55   * Instanciation
56   ********************************************************/
57 
58  cout << "<" << name << "> Instanciation of _Select_Priority_Fixed" << endl;
59 
60  (*(_Select_Priority_Fixed->in_CLOCK ))       (*(CLOCK ));
61  (*(_Select_Priority_Fixed->in_NRESET))       (*(NRESET));
62
63    for (uint32_t i=0; i<_param._nb_entity; i++)
64      {
65        (*(_Select_Priority_Fixed-> in_VAL [i]))        (*(VAL [i]));
66        if (_param._encoding_one_hot)
67        (*(_Select_Priority_Fixed->out_ACK [i]))        (*(ACK [i]));
68      }
69    if (_param._encoding_compact)
70      {
71    (*(_Select_Priority_Fixed->out_ENTITY    ))        (*(ENTITY    ));
72    (*(_Select_Priority_Fixed->out_ENTITY_ACK))        (*(ENTITY_ACK));
73      }
74  /********************************************************
75   * Simulation - Begin
76   ********************************************************/
77
78  cout << "<" << name << "> Start Simulation ............" << endl;
79
80  if (_param._nb_entity > (8*sizeof (Tentity_t)))
81    throw ErrorMorpheo("No Selftest with nb_entity higher at "+toString(8*sizeof (Tentity_t)));
82
83  // Initialisation
84  const uint32_t seed = 0;
85//const uint32_t seed = static_cast<uint32_t>(time(NULL));
86
87  srand(seed);
88
89  Tentity_t entity;
90 
91  sc_start(0);
92//_Select_Priority_Fixed->vhdl_testbench_label("Initialisation");
93//cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
94
95  _Select_Priority_Fixed->vhdl_testbench_label("Loop of Test");
96  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl;
97
98  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
99    {
100      _Select_Priority_Fixed->vhdl_testbench_label("Iteration "+toString(iteration));
101
102      entity    = 0;
103      bool find = false;
104     
105      for (uint32_t i=0; i<_param._nb_entity; i++)
106        {
107          Tcontrol_t val = rand() % 2;
108
109          VAL [i]->write(val);
110         
111          if (not find and val)
112            {
113              find   = true;
114              entity = i;
115            }
116        }
117
118      sc_start(1);
119 
120      cout << "wait entity : " << entity << endl;
121   
122      entity = (find)?entity:0;
123
124      if (_param._encoding_one_hot)
125        TEST(Tcontrol_t, ACK   [entity]->read(), find  );
126      if (_param._encoding_compact)
127        {
128        TEST(Tentity_t , ENTITY        ->read(), entity); // burk
129        TEST(Tcontrol_t, ENTITY_ACK    ->read(), find  ); // burk
130        }
131    }
132
133  /********************************************************
134   * Simulation - End
135   ********************************************************/
136
137  cout << "<" << name << "> ............ Stop Simulation" << endl;
138
139  delete CLOCK;
140  delete NRESET;
141
142  for (uint32_t i=0; i<_param._nb_entity; i++)
143    {
144      delete VAL [i];
145      delete ACK [i];
146    }
147 
148  delete VAL       ;
149  delete ACK       ;
150  delete ENTITY    ;
151  delete ENTITY_ACK;
152#endif
153
154  delete _Select_Priority_Fixed;
155}
Note: See TracBrowser for help on using the repository browser.