[2] | 1 | #ifdef VHDL |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * $Id: Vhdl_std_logic.cpp 81 2008-04-15 18:40:01Z rosiere $ |
---|
| 5 | * |
---|
| 6 | * [ Description ] |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include <math.h> |
---|
| 11 | #include "Behavioural/include/Vhdl.h" |
---|
| 12 | |
---|
| 13 | namespace morpheo { |
---|
| 14 | namespace behavioural { |
---|
| 15 | |
---|
[43] | 16 | #undef FUNCTION |
---|
| 17 | #define FUNCTION "Vhdl::std_logic" |
---|
[71] | 18 | std::string std_logic (uint32_t size) |
---|
[2] | 19 | { |
---|
[43] | 20 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 21 | |
---|
[71] | 22 | std::string type; |
---|
[2] | 23 | |
---|
| 24 | if (size == 1) |
---|
| 25 | type = "std_logic"; |
---|
| 26 | else |
---|
| 27 | type = "std_logic_vector(" + toString(size-1) + " downto 0)"; |
---|
| 28 | |
---|
[43] | 29 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 30 | |
---|
[2] | 31 | return type; |
---|
| 32 | }; |
---|
| 33 | |
---|
[43] | 34 | #undef FUNCTION |
---|
| 35 | #define FUNCTION "Vhdl::std_logic_conv" |
---|
[71] | 36 | std::string std_logic_conv (uint32_t size, std::string value) |
---|
[2] | 37 | { |
---|
[43] | 38 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 39 | |
---|
[71] | 40 | std::string conv; |
---|
[2] | 41 | |
---|
| 42 | if (size == 1) |
---|
| 43 | conv = "'"+toString(value)+"'"; |
---|
| 44 | else |
---|
| 45 | conv = "conv_std_logic_vector("+value+","+toString(size)+")"; |
---|
| 46 | |
---|
[43] | 47 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 48 | |
---|
[2] | 49 | return conv; |
---|
| 50 | }; |
---|
| 51 | |
---|
[71] | 52 | std::string std_logic_conv (uint32_t size, uint32_t value) |
---|
[2] | 53 | { |
---|
[43] | 54 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
[71] | 55 | std::string _return = std_logic_conv(size,toString(value)); |
---|
[43] | 56 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 57 | |
---|
| 58 | return _return; |
---|
[2] | 59 | }; |
---|
| 60 | |
---|
[43] | 61 | #undef FUNCTION |
---|
| 62 | #define FUNCTION "Vhdl::std_logic_range" |
---|
[71] | 63 | std::string std_logic_range (uint32_t size, uint32_t max, uint32_t min) |
---|
[67] | 64 | { |
---|
| 65 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
[71] | 66 | std::string type; |
---|
[67] | 67 | |
---|
| 68 | if (size < 2) |
---|
| 69 | type = ""; |
---|
| 70 | else |
---|
| 71 | if (max == min) |
---|
| 72 | type = "("+toString(max)+")"; |
---|
| 73 | else |
---|
| 74 | type = "("+toString(max)+" downto "+toString(min)+")"; |
---|
| 75 | |
---|
| 76 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 77 | |
---|
| 78 | return type; |
---|
| 79 | }; |
---|
| 80 | |
---|
[71] | 81 | std::string std_logic_range (uint32_t max, uint32_t min) |
---|
[2] | 82 | { |
---|
[43] | 83 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
[71] | 84 | std::string type; |
---|
[2] | 85 | |
---|
[57] | 86 | if (max == 0) |
---|
| 87 | type = ""; |
---|
[2] | 88 | else |
---|
[57] | 89 | if (max == min) |
---|
| 90 | type = "("+toString(max)+")"; |
---|
| 91 | else |
---|
| 92 | type = "("+toString(max)+" downto "+toString(min)+")"; |
---|
[2] | 93 | |
---|
[43] | 94 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 95 | |
---|
[2] | 96 | return type; |
---|
| 97 | }; |
---|
| 98 | |
---|
[71] | 99 | std::string std_logic_range (uint32_t size) |
---|
[2] | 100 | { |
---|
[43] | 101 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
[71] | 102 | std::string _return = std_logic_range(size-1,0); |
---|
[43] | 103 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 104 | |
---|
| 105 | return _return; |
---|
[2] | 106 | } |
---|
| 107 | |
---|
[43] | 108 | #undef FUNCTION |
---|
| 109 | #define FUNCTION "Vhdl::std_logic_others" |
---|
[71] | 110 | std::string std_logic_others (uint32_t size, uint32_t cst ) |
---|
[2] | 111 | { |
---|
[43] | 112 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 113 | |
---|
[71] | 114 | std::string _return; |
---|
[43] | 115 | |
---|
[2] | 116 | if (size < 2) |
---|
[43] | 117 | _return = "'"+toString(cst)+"'"; |
---|
[2] | 118 | else |
---|
[43] | 119 | _return = "(others => '"+toString(cst)+"')"; |
---|
| 120 | |
---|
| 121 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 122 | |
---|
| 123 | return _return; |
---|
[2] | 124 | } |
---|
[67] | 125 | |
---|
| 126 | |
---|
| 127 | |
---|
[2] | 128 | }; // end namespace behavioural |
---|
| 129 | }; // end namespace morpheo |
---|
| 130 | |
---|
| 131 | #endif |
---|