[2] | 1 | /* |
---|
| 2 | * $Id: top_test.cpp 113 2009-04-14 18:39:12Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
[113] | 9 | #include "Behavioural/Generic/Counter/SelfTest/include/top.h" |
---|
[2] | 10 | |
---|
[113] | 11 | void top::test (void) |
---|
[2] | 12 | { |
---|
| 13 | #ifdef SYSTEMC |
---|
[112] | 14 | Time * _time = new Time(); |
---|
| 15 | |
---|
[2] | 16 | /******************************************************** |
---|
| 17 | * Simulation - Begin |
---|
| 18 | ********************************************************/ |
---|
| 19 | |
---|
| 20 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 21 | // Initialisation |
---|
| 22 | |
---|
| 23 | srand(0); |
---|
| 24 | //srand(TIME(NULL)); |
---|
| 25 | |
---|
[113] | 26 | Tdata_t data_in [param->_nb_port]; |
---|
| 27 | Tdata_t data_out [param->_nb_port]; |
---|
| 28 | Tcontrol_t addsub [param->_nb_port]; |
---|
[2] | 29 | |
---|
[113] | 30 | SC_CYCLE(0); |
---|
[42] | 31 | |
---|
[113] | 32 | in_NRESET->write(1); |
---|
[42] | 33 | |
---|
[113] | 34 | LABEL("Initialisation"); |
---|
[2] | 35 | |
---|
[113] | 36 | LABEL("Loop of Test"); |
---|
[2] | 37 | |
---|
| 38 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 39 | { |
---|
[113] | 40 | LABEL("Iteration %d",iteration); |
---|
| 41 | |
---|
| 42 | for (uint32_t i=0; i<param->_nb_port; i++) |
---|
[2] | 43 | { |
---|
[113] | 44 | Tdata_t data = rand()%param->_data_max; |
---|
[2] | 45 | data_in [i] = data; |
---|
| 46 | addsub [i] = (rand()%2)==1; |
---|
| 47 | |
---|
[113] | 48 | LABEL("in_COUNTER_DATA [%d] = %d",i,data ); |
---|
| 49 | LABEL("in_COUNTER_ADDSUB [%d] = %d" ,i,addsub [i]); |
---|
[2] | 50 | |
---|
[113] | 51 | in_COUNTER_DATA [i]->write(data ); |
---|
| 52 | in_COUNTER_ADDSUB [i]->write(addsub [i]); |
---|
| 53 | |
---|
| 54 | data_out [i] = (addsub[i]==1)?((data<param->_data_max)?data+1:data):((data>0)?data-1:data); |
---|
[2] | 55 | } |
---|
| 56 | |
---|
[113] | 57 | SC_CYCLE(0); |
---|
| 58 | |
---|
| 59 | for (uint32_t i=0; i<param->_nb_port; i++) |
---|
[2] | 60 | { |
---|
[113] | 61 | string op = (addsub[i] == 1)?"++":"--"; |
---|
| 62 | LABEL("0x%d %s = 0x%d",i,op.c_str(),out_COUNTER_DATA [i]->read()); |
---|
[2] | 63 | |
---|
[113] | 64 | TEST(Tdata_t,out_COUNTER_DATA [i]->read(),data_out [i]); |
---|
[2] | 65 | } |
---|
| 66 | |
---|
[113] | 67 | SC_CYCLE(1); |
---|
[2] | 68 | } |
---|
| 69 | |
---|
[113] | 70 | SC_CYCLE(1); |
---|
[2] | 71 | |
---|
| 72 | /******************************************************** |
---|
| 73 | * Simulation - End |
---|
| 74 | ********************************************************/ |
---|
| 75 | |
---|
[113] | 76 | sc_stop(); |
---|
| 77 | |
---|
[112] | 78 | delete _time; |
---|
| 79 | |
---|
[2] | 80 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 81 | #endif |
---|
| 82 | } |
---|