[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, |
---|
[57] | 15 | morpheo::behavioural::generic::select::select_priority_fixed::Parameters * _param) |
---|
[10] | 16 | { |
---|
| 17 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 18 | |
---|
[57] | 19 | |
---|
| 20 | #ifdef STATISTICS |
---|
| 21 | morpheo::behavioural::Parameters_Statistics * _param_stat = new morpheo::behavioural::Parameters_Statistics (5,50); |
---|
| 22 | #endif |
---|
[15] | 23 | Select_Priority_Fixed * _Select_Priority_Fixed = new Select_Priority_Fixed (name.c_str(), |
---|
[10] | 24 | #ifdef STATISTICS |
---|
[57] | 25 | _param_stat, |
---|
[10] | 26 | #endif |
---|
[40] | 27 | _param); |
---|
[10] | 28 | |
---|
| 29 | #ifdef SYSTEMC |
---|
| 30 | /********************************************************************* |
---|
| 31 | * Déclarations des signaux |
---|
| 32 | *********************************************************************/ |
---|
| 33 | sc_clock * CLOCK ; |
---|
[15] | 34 | sc_signal<Tcontrol_t> * NRESET; |
---|
[10] | 35 | sc_signal<Tcontrol_t> ** VAL ; |
---|
| 36 | sc_signal<Tcontrol_t> ** ACK ; |
---|
| 37 | sc_signal<Tentity_t > * ENTITY; |
---|
| 38 | sc_signal<Tcontrol_t> * ENTITY_ACK; |
---|
| 39 | |
---|
| 40 | string rename; |
---|
| 41 | |
---|
| 42 | CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
[15] | 43 | NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
[57] | 44 | VAL = new sc_signal<Tcontrol_t> * [_param->_nb_entity]; |
---|
| 45 | ACK = new sc_signal<Tcontrol_t> * [_param->_nb_entity]; |
---|
[10] | 46 | |
---|
[57] | 47 | for (uint32_t i=0; i<_param->_nb_entity; i++) |
---|
[10] | 48 | { |
---|
| 49 | rename = "VAL_"+toString(i); |
---|
| 50 | VAL [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
| 51 | rename = "ACK_"+toString(i); |
---|
| 52 | ACK [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | ENTITY = new sc_signal<Tentity_t> ("entity"); |
---|
| 56 | ENTITY_ACK = new sc_signal<Tcontrol_t> ("entity_ack"); |
---|
| 57 | |
---|
| 58 | /******************************************************** |
---|
| 59 | * Instanciation |
---|
| 60 | ********************************************************/ |
---|
| 61 | |
---|
[15] | 62 | cout << "<" << name << "> Instanciation of _Select_Priority_Fixed" << endl; |
---|
[10] | 63 | |
---|
[15] | 64 | (*(_Select_Priority_Fixed->in_CLOCK )) (*(CLOCK )); |
---|
| 65 | (*(_Select_Priority_Fixed->in_NRESET)) (*(NRESET)); |
---|
| 66 | |
---|
[57] | 67 | for (uint32_t i=0; i<_param->_nb_entity; i++) |
---|
[10] | 68 | { |
---|
[15] | 69 | (*(_Select_Priority_Fixed-> in_VAL [i])) (*(VAL [i])); |
---|
[57] | 70 | if (_param->_encoding_one_hot) |
---|
[15] | 71 | (*(_Select_Priority_Fixed->out_ACK [i])) (*(ACK [i])); |
---|
[10] | 72 | } |
---|
[57] | 73 | if (_param->_encoding_compact) |
---|
[10] | 74 | { |
---|
[15] | 75 | (*(_Select_Priority_Fixed->out_ENTITY )) (*(ENTITY )); |
---|
| 76 | (*(_Select_Priority_Fixed->out_ENTITY_ACK)) (*(ENTITY_ACK)); |
---|
[10] | 77 | } |
---|
| 78 | /******************************************************** |
---|
| 79 | * Simulation - Begin |
---|
| 80 | ********************************************************/ |
---|
| 81 | |
---|
| 82 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 83 | |
---|
[57] | 84 | if (_param->_nb_entity > (8*sizeof (Tentity_t))) |
---|
[10] | 85 | throw ErrorMorpheo("No Selftest with nb_entity higher at "+toString(8*sizeof (Tentity_t))); |
---|
| 86 | |
---|
| 87 | // Initialisation |
---|
| 88 | const uint32_t seed = 0; |
---|
| 89 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
| 90 | |
---|
| 91 | srand(seed); |
---|
| 92 | |
---|
| 93 | Tentity_t entity; |
---|
| 94 | |
---|
| 95 | sc_start(0); |
---|
| 96 | //cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
| 97 | |
---|
| 98 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
| 99 | |
---|
| 100 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 101 | { |
---|
| 102 | entity = 0; |
---|
| 103 | bool find = false; |
---|
| 104 | |
---|
[57] | 105 | for (uint32_t i=0; i<_param->_nb_entity; i++) |
---|
[10] | 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 | |
---|
[57] | 124 | if (_param->_encoding_one_hot) |
---|
[10] | 125 | TEST(Tcontrol_t, ACK [entity]->read(), find ); |
---|
[57] | 126 | if (_param->_encoding_compact) |
---|
[10] | 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 | |
---|
[40] | 139 | delete CLOCK; |
---|
| 140 | delete NRESET; |
---|
| 141 | delete [] VAL ; |
---|
| 142 | delete [] ACK ; |
---|
| 143 | delete ENTITY ; |
---|
| 144 | delete ENTITY_ACK; |
---|
[10] | 145 | #endif |
---|
| 146 | |
---|
[15] | 147 | delete _Select_Priority_Fixed; |
---|
[10] | 148 | } |
---|