[10] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define NB_ITERATION 512 |
---|
| 10 | |
---|
[15] | 11 | #include "Behavioural/Generic/Select/Select_Priority_Fixed/SelfTest/include/test.h" |
---|
[44] | 12 | #include "Common/include/Test.h" |
---|
[10] | 13 | |
---|
| 14 | void test (string name, |
---|
[15] | 15 | morpheo::behavioural::generic::select::select_priority_fixed::Parameters _param) |
---|
[10] | 16 | { |
---|
| 17 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 18 | |
---|
[15] | 19 | Select_Priority_Fixed * _Select_Priority_Fixed = new Select_Priority_Fixed (name.c_str(), |
---|
[10] | 20 | #ifdef STATISTICS |
---|
[40] | 21 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
[10] | 22 | #endif |
---|
[40] | 23 | _param); |
---|
[10] | 24 | |
---|
| 25 | #ifdef SYSTEMC |
---|
| 26 | /********************************************************************* |
---|
| 27 | * Déclarations des signaux |
---|
| 28 | *********************************************************************/ |
---|
| 29 | sc_clock * CLOCK ; |
---|
[15] | 30 | sc_signal<Tcontrol_t> * NRESET; |
---|
[10] | 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); |
---|
[15] | 39 | NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
[10] | 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 | |
---|
[15] | 58 | cout << "<" << name << "> Instanciation of _Select_Priority_Fixed" << endl; |
---|
[10] | 59 | |
---|
[15] | 60 | (*(_Select_Priority_Fixed->in_CLOCK )) (*(CLOCK )); |
---|
| 61 | (*(_Select_Priority_Fixed->in_NRESET)) (*(NRESET)); |
---|
| 62 | |
---|
[10] | 63 | for (uint32_t i=0; i<_param._nb_entity; i++) |
---|
| 64 | { |
---|
[15] | 65 | (*(_Select_Priority_Fixed-> in_VAL [i])) (*(VAL [i])); |
---|
[10] | 66 | if (_param._encoding_one_hot) |
---|
[15] | 67 | (*(_Select_Priority_Fixed->out_ACK [i])) (*(ACK [i])); |
---|
[10] | 68 | } |
---|
| 69 | if (_param._encoding_compact) |
---|
| 70 | { |
---|
[15] | 71 | (*(_Select_Priority_Fixed->out_ENTITY )) (*(ENTITY )); |
---|
| 72 | (*(_Select_Priority_Fixed->out_ENTITY_ACK)) (*(ENTITY_ACK)); |
---|
[10] | 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 | //cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
| 93 | |
---|
| 94 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
| 95 | |
---|
| 96 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 97 | { |
---|
| 98 | entity = 0; |
---|
| 99 | bool find = false; |
---|
| 100 | |
---|
| 101 | for (uint32_t i=0; i<_param._nb_entity; i++) |
---|
| 102 | { |
---|
| 103 | Tcontrol_t val = rand() % 2; |
---|
| 104 | |
---|
| 105 | VAL [i]->write(val); |
---|
| 106 | |
---|
| 107 | if (not find and val) |
---|
| 108 | { |
---|
| 109 | find = true; |
---|
| 110 | entity = i; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | sc_start(1); |
---|
| 115 | |
---|
| 116 | cout << "wait entity : " << entity << endl; |
---|
| 117 | |
---|
| 118 | entity = (find)?entity:0; |
---|
| 119 | |
---|
| 120 | if (_param._encoding_one_hot) |
---|
| 121 | TEST(Tcontrol_t, ACK [entity]->read(), find ); |
---|
| 122 | if (_param._encoding_compact) |
---|
| 123 | { |
---|
| 124 | TEST(Tentity_t , ENTITY ->read(), entity); // burk |
---|
| 125 | TEST(Tcontrol_t, ENTITY_ACK ->read(), find ); // burk |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /******************************************************** |
---|
| 130 | * Simulation - End |
---|
| 131 | ********************************************************/ |
---|
| 132 | |
---|
| 133 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 134 | |
---|
[40] | 135 | delete CLOCK; |
---|
| 136 | delete NRESET; |
---|
| 137 | delete [] VAL ; |
---|
| 138 | delete [] ACK ; |
---|
| 139 | delete ENTITY ; |
---|
| 140 | delete ENTITY_ACK; |
---|
[10] | 141 | #endif |
---|
| 142 | |
---|
[15] | 143 | delete _Select_Priority_Fixed; |
---|
[10] | 144 | } |
---|