1 | #ifdef VHDL |
---|
2 | |
---|
3 | /* |
---|
4 | * $Id: Vhdl_std_logic.cpp 97 2008-12-19 15:34:00Z rosiere $ |
---|
5 | * |
---|
6 | * [ Description ] |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | #include <math.h> |
---|
11 | #include "Behavioural/include/Vhdl.h" |
---|
12 | #include "Common/include/ToBase2.h" |
---|
13 | |
---|
14 | namespace morpheo { |
---|
15 | namespace behavioural { |
---|
16 | |
---|
17 | #undef FUNCTION |
---|
18 | #define FUNCTION "Vhdl::std_logic" |
---|
19 | std::string std_logic (uint32_t size) |
---|
20 | { |
---|
21 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
22 | |
---|
23 | std::string type; |
---|
24 | |
---|
25 | if (size == 1) |
---|
26 | type = "std_logic"; |
---|
27 | else |
---|
28 | type = "std_logic_vector(" + toString(size-1) + " downto 0)"; |
---|
29 | |
---|
30 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
31 | |
---|
32 | return type; |
---|
33 | }; |
---|
34 | |
---|
35 | #undef FUNCTION |
---|
36 | #define FUNCTION "Vhdl::std_logic_conv" |
---|
37 | std::string std_logic_conv (uint32_t size, std::string value) |
---|
38 | { |
---|
39 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
40 | |
---|
41 | std::string conv; |
---|
42 | |
---|
43 | if (size == 1) |
---|
44 | conv = "'"+toString(value)+"'"; |
---|
45 | else |
---|
46 | conv = "conv_std_logic_vector("+value+","+toString(size)+")"; |
---|
47 | |
---|
48 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
49 | |
---|
50 | return conv; |
---|
51 | }; |
---|
52 | |
---|
53 | std::string std_logic_conv (uint32_t size, uint32_t value) |
---|
54 | { |
---|
55 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
56 | std::string _return = std_logic_conv(size,toString(value)); |
---|
57 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
58 | |
---|
59 | return _return; |
---|
60 | }; |
---|
61 | |
---|
62 | #undef FUNCTION |
---|
63 | #define FUNCTION "Vhdl::std_logic_cst" |
---|
64 | std::string std_logic_cst (uint32_t size, uint32_t value) |
---|
65 | { |
---|
66 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
67 | |
---|
68 | std::string conv; |
---|
69 | |
---|
70 | if (size == 1) |
---|
71 | conv = "'"+toString(value&1)+"'"; |
---|
72 | else |
---|
73 | conv = "\""+toBase2<uint32_t>(value,size)+"\""; |
---|
74 | |
---|
75 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
76 | |
---|
77 | return conv; |
---|
78 | }; |
---|
79 | |
---|
80 | #undef FUNCTION |
---|
81 | #define FUNCTION "Vhdl::std_logic_range" |
---|
82 | std::string std_logic_range (uint32_t size, uint32_t max, uint32_t min) |
---|
83 | { |
---|
84 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
85 | std::string type; |
---|
86 | |
---|
87 | { |
---|
88 | if (size < 2) |
---|
89 | type = ""; |
---|
90 | else |
---|
91 | { |
---|
92 | if (max == min) |
---|
93 | { |
---|
94 | type = "("+toString(max)+")"; |
---|
95 | } |
---|
96 | else |
---|
97 | { |
---|
98 | type = "("+toString(max)+" downto "+toString(min)+")"; |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
104 | |
---|
105 | return type; |
---|
106 | }; |
---|
107 | |
---|
108 | std::string std_logic_range (uint32_t max, uint32_t min) |
---|
109 | { |
---|
110 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
111 | std::string type; |
---|
112 | |
---|
113 | { |
---|
114 | if (max == min) |
---|
115 | { |
---|
116 | type = "("+toString(max)+")"; |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | if (max == 0) |
---|
121 | type = ""; |
---|
122 | else |
---|
123 | type = "("+toString(max)+" downto "+toString(min)+")"; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
128 | |
---|
129 | return type; |
---|
130 | }; |
---|
131 | |
---|
132 | std::string std_logic_range (uint32_t size) |
---|
133 | { |
---|
134 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
135 | std::string _return = std_logic_range(size,size-1,0); |
---|
136 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
137 | |
---|
138 | return _return; |
---|
139 | } |
---|
140 | |
---|
141 | #undef FUNCTION |
---|
142 | #define FUNCTION "Vhdl::_std_logic_range" |
---|
143 | std::string _std_logic_range (uint32_t size, uint32_t max, uint32_t min) |
---|
144 | { |
---|
145 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
146 | std::string type=_std_logic_range(max,min); |
---|
147 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
148 | |
---|
149 | return type; |
---|
150 | }; |
---|
151 | |
---|
152 | std::string _std_logic_range (uint32_t max, uint32_t min) |
---|
153 | { |
---|
154 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
155 | std::string type = "("+toString(max)+" downto "+toString(min)+")"; |
---|
156 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
157 | |
---|
158 | return type; |
---|
159 | }; |
---|
160 | |
---|
161 | std::string _std_logic_range (uint32_t size) |
---|
162 | { |
---|
163 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
164 | std::string _return = _std_logic_range(size,size-1,0); |
---|
165 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
166 | |
---|
167 | return _return; |
---|
168 | } |
---|
169 | |
---|
170 | #undef FUNCTION |
---|
171 | #define FUNCTION "Vhdl::std_logic_others" |
---|
172 | std::string std_logic_others (uint32_t size, bool cst ) |
---|
173 | { |
---|
174 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
175 | |
---|
176 | std::string _return; |
---|
177 | |
---|
178 | if (size < 2) |
---|
179 | _return = "'"+toString(cst)+"'"; |
---|
180 | else |
---|
181 | _return = "(others => '"+toString(cst)+"')"; |
---|
182 | |
---|
183 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
184 | |
---|
185 | return _return; |
---|
186 | } |
---|
187 | |
---|
188 | }; // end namespace behavioural |
---|
189 | }; // end namespace morpheo |
---|
190 | |
---|
191 | #endif |
---|