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