[41] | 1 | #ifdef VHDL_TESTBENCH |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * $Id$ |
---|
| 5 | * |
---|
| 6 | * [ Description ] |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "Behavioural/include/Interfaces.h" |
---|
| 11 | |
---|
| 12 | namespace morpheo { |
---|
| 13 | namespace behavioural { |
---|
| 14 | |
---|
| 15 | void Interfaces::testbench_generate_file (void) |
---|
| 16 | { |
---|
| 17 | log_printf(FUNC,Behavioural,"generate_file","Begin"); |
---|
| 18 | |
---|
| 19 | Vhdl * vhdl = new Vhdl(_name+"_Testbench"); |
---|
| 20 | string counter = "counter"; |
---|
[42] | 21 | Signal * clock = this->get_clock(); |
---|
| 22 | Signal * reset = this->get_reset(); |
---|
| 23 | string clock_name = clock->get_name(); |
---|
| 24 | string reset_name = reset->get_name(); |
---|
[41] | 25 | uint32_t cycle = this->get_cycle(); |
---|
| 26 | |
---|
[42] | 27 | vhdl->set_signal (clock_name, 1, 0); |
---|
| 28 | vhdl->set_signal (reset_name, 1, 0); |
---|
| 29 | vhdl->set_signal (counter, "natural"); |
---|
[41] | 30 | this->set_signal (vhdl); |
---|
| 31 | |
---|
| 32 | vhdl->set_body(""); |
---|
| 33 | vhdl->set_body("------------------------------------------------------"); |
---|
[42] | 34 | vhdl->set_body("-- Component - Intanciation"); |
---|
[41] | 35 | vhdl->set_body("------------------------------------------------------"); |
---|
| 36 | vhdl->set_body(""); |
---|
| 37 | |
---|
| 38 | list<string> * list_signal = new list<string>; |
---|
| 39 | this->get_signal (list_signal); |
---|
| 40 | |
---|
| 41 | vhdl->set_library_work (_name + "_Pack"); |
---|
| 42 | vhdl->set_body("instance_"+_name+" : "+_name); |
---|
| 43 | vhdl->set_body("port map ("); |
---|
| 44 | |
---|
| 45 | list<string>::iterator i = list_signal->begin(); |
---|
| 46 | if (i != list_signal->end()) |
---|
| 47 | { |
---|
| 48 | vhdl->set_body("\t "+*i+"\t=>\t"+*i); |
---|
| 49 | ++i; |
---|
| 50 | } |
---|
| 51 | while (i != list_signal->end()) |
---|
| 52 | { |
---|
| 53 | vhdl->set_body("\t,"+*i+"\t=>\t"+*i); |
---|
| 54 | ++i; |
---|
| 55 | } |
---|
| 56 | vhdl->set_body(" );"); |
---|
| 57 | |
---|
| 58 | delete list_signal; |
---|
| 59 | |
---|
[42] | 60 | string test_name = this->testbench_body(vhdl,counter, reset_name); |
---|
| 61 | |
---|
[41] | 62 | vhdl->set_body(""); |
---|
| 63 | vhdl->set_body("------------------------------------------------------"); |
---|
[42] | 64 | vhdl->set_body("-- reset"); |
---|
[41] | 65 | vhdl->set_body("------------------------------------------------------"); |
---|
| 66 | vhdl->set_body(""); |
---|
[42] | 67 | vhdl->set_body("-- if the systemC simulate have multiple reset, we make the last"); |
---|
| 68 | vhdl->set_body(reset_name+" <= '1' after 150 ns;"); |
---|
[41] | 69 | |
---|
| 70 | vhdl->set_body(""); |
---|
| 71 | vhdl->set_body("------------------------------------------------------"); |
---|
[42] | 72 | vhdl->set_body("-- process clock_name"); |
---|
[41] | 73 | vhdl->set_body("------------------------------------------------------"); |
---|
| 74 | vhdl->set_body(""); |
---|
[42] | 75 | vhdl->set_body(clock_name+" <= not "+clock_name+" after 50 ns;"); |
---|
[41] | 76 | vhdl->set_body(""); |
---|
[42] | 77 | vhdl->set_body("process ("+clock_name+")"); |
---|
[41] | 78 | vhdl->set_body("begin"); |
---|
[42] | 79 | vhdl->set_body("\tif ("+clock_name+"'event and "+clock_name+" = '1') then"); |
---|
[41] | 80 | vhdl->set_body(""); |
---|
[42] | 81 | vhdl->set_body("\t\tif ("+reset_name+" = '0') then"); |
---|
[41] | 82 | vhdl->set_body(""); |
---|
[42] | 83 | vhdl->set_body("\t\t\t"+counter+" <= "+toString(reset->get_reset_cycle(true))+";"); |
---|
| 84 | vhdl->set_body(""); |
---|
| 85 | vhdl->set_body("\t\telse"); |
---|
| 86 | vhdl->set_body(""); |
---|
| 87 | vhdl->set_body("\t\t\t"+counter+" <= "+counter+"+1;"); |
---|
| 88 | vhdl->set_body(""); |
---|
[44] | 89 | vhdl->set_body("\t\t\tassert not ("+counter+" >= "+toString(cycle)+") report \"Test OK\" severity FAILURE;"); |
---|
[42] | 90 | vhdl->set_body("\t\t\tassert not ("+test_name+" = '0') report \"Test KO\" severity FAILURE;"); |
---|
| 91 | |
---|
| 92 | #ifdef VHDL_TESTBENCH_ASSERT |
---|
| 93 | vhdl->set_body("\t\t\t-- Assert ..."); |
---|
| 94 | for (uint32_t cpt=0; cpt<=cycle; cpt++) |
---|
| 95 | vhdl->set_body("\t\t\tassert not ("+counter+" = "+toString(cpt)+") report \"===== Test number "+toString(cpt)+" =====\" severity NOTE;"); |
---|
| 96 | #endif |
---|
| 97 | |
---|
| 98 | vhdl->set_body(""); |
---|
| 99 | vhdl->set_body("\t\tend if;"); |
---|
[41] | 100 | vhdl->set_body("\tend if;"); |
---|
| 101 | vhdl->set_body("end process;"); |
---|
| 102 | |
---|
| 103 | |
---|
[42] | 104 | vhdl->generate_file(false,true); |
---|
| 105 | |
---|
[41] | 106 | delete vhdl; |
---|
| 107 | |
---|
| 108 | log_printf(FUNC,Behavioural,"generate_file","End"); |
---|
| 109 | }; |
---|
| 110 | |
---|
| 111 | }; // end namespace behavioural |
---|
| 112 | }; // end namespace morpheo |
---|
| 113 | |
---|
| 114 | #endif |
---|