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