1 | #ifndef morpheo_behavioural_Interface_h |
---|
2 | #define morpheo_behavioural_Interface_h |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id: Interface.h 139 2010-07-30 14:47:27Z rosiere $ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #ifdef SYSTEMC |
---|
12 | #include "systemc.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <stdint.h> |
---|
16 | #include <iostream> |
---|
17 | #include <list> |
---|
18 | #include "Behavioural/include/Signal.h" |
---|
19 | #include "Behavioural/include/Direction.h" |
---|
20 | #include "Behavioural/include/Localisation.h" |
---|
21 | #ifdef VHDL |
---|
22 | #include "Behavioural/include/Vhdl.h" |
---|
23 | #endif |
---|
24 | #include "Common/include/ChangeCase.h" |
---|
25 | #include "Common/include/ToString.h" |
---|
26 | #include "Common/include/ErrorMorpheo.h" |
---|
27 | #include "Common/include/Debug.h" |
---|
28 | #include "Behavioural/include/Usage.h" |
---|
29 | |
---|
30 | namespace morpheo { |
---|
31 | namespace behavioural { |
---|
32 | |
---|
33 | class Interface |
---|
34 | { |
---|
35 | // -----[ fields ]---------------------------------------------------- |
---|
36 | protected : const std::string _name ; |
---|
37 | #ifdef POSITION |
---|
38 | protected : const direction_t _direction ; |
---|
39 | protected : const localisation_t _localisation ; |
---|
40 | #endif |
---|
41 | protected : const Tusage_t _usage; |
---|
42 | |
---|
43 | #ifdef POSITION |
---|
44 | protected : std::string _comment ; |
---|
45 | #endif |
---|
46 | |
---|
47 | protected : std::list<Signal *> * _list_signal ; |
---|
48 | |
---|
49 | #ifdef POSITION |
---|
50 | protected : bool _is_map ; |
---|
51 | protected : void * _entity_map ; // Entity -> erreur cyclique |
---|
52 | protected : void * _interface_map; // pour être homogène avec _entity_map |
---|
53 | #endif |
---|
54 | |
---|
55 | #ifdef VHDL_TESTBENCH |
---|
56 | private : uint32_t _nb_cycle ; |
---|
57 | protected : bool _make_testbench; |
---|
58 | #endif |
---|
59 | |
---|
60 | // -----[ methods ]--------------------------------------------------- |
---|
61 | public : Interface (std::string name |
---|
62 | #ifdef POSITION |
---|
63 | ,direction_t direction |
---|
64 | ,localisation_t localisation |
---|
65 | #endif |
---|
66 | ,Tusage_t usage |
---|
67 | ); |
---|
68 | |
---|
69 | public : Interface (const Interface & interface); |
---|
70 | public : ~Interface (); |
---|
71 | |
---|
72 | public : std::string get_name (); |
---|
73 | |
---|
74 | #ifdef POSITION |
---|
75 | public : void set_comment (std::string comment); |
---|
76 | protected : std::string get_comment (void); |
---|
77 | #endif |
---|
78 | |
---|
79 | protected : std::string signal_name (std::string name_interface, |
---|
80 | std::string name_signal , |
---|
81 | direction_t direction ); |
---|
82 | |
---|
83 | public : Signal * find_signal (std::string name); |
---|
84 | public : bool find_signal (Signal * signal); |
---|
85 | |
---|
86 | protected : std::string get_signal (void); |
---|
87 | public : Signal * set_signal (std::string name , |
---|
88 | direction_t direction, |
---|
89 | uint32_t size , |
---|
90 | presence_port_t presence_port = PORT_VHDL_YES_TESTBENCH_YES); |
---|
91 | public : std::list<Signal *> * get_signal_list (void); |
---|
92 | |
---|
93 | #ifdef SYSTEMC |
---|
94 | |
---|
95 | #undef FUNCTION |
---|
96 | #define FUNCTION "Interface::set_signal_clk" |
---|
97 | public : sc_in_clk * set_signal_clk (std::string name , |
---|
98 | uint32_t size , |
---|
99 | presence_port_t presence_port=CLOCK_VHDL_YES) |
---|
100 | { |
---|
101 | log_begin(Behavioural,FUNCTION); |
---|
102 | |
---|
103 | if ((presence_port != CLOCK_VHDL_YES) and |
---|
104 | (presence_port != CLOCK_VHDL_NO )) |
---|
105 | throw ErrorMorpheo ("Signal \""+name+"\" is a clock, bad presence_port."); |
---|
106 | |
---|
107 | LowerCase(name); |
---|
108 | |
---|
109 | Signal * sig = set_signal (name, IN , size, presence_port); |
---|
110 | sc_in_clk * port; |
---|
111 | |
---|
112 | if (_usage & USE_SYSTEMC_INTERFACE) |
---|
113 | { |
---|
114 | port = new sc_in_clk (sig->_name.c_str()); |
---|
115 | sig->alloc<bool> (static_cast<void *>(port)); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | port = NULL; |
---|
120 | } |
---|
121 | |
---|
122 | log_end(Behavioural,FUNCTION); |
---|
123 | |
---|
124 | return port; |
---|
125 | }; |
---|
126 | |
---|
127 | #undef FUNCTION |
---|
128 | #define FUNCTION "Interface::set_signal_in" |
---|
129 | public : template <typename T> |
---|
130 | sc_in <T> * set_signal_in (std::string name , |
---|
131 | uint32_t size , |
---|
132 | presence_port_t presence_port=PORT_VHDL_YES_TESTBENCH_YES) |
---|
133 | { |
---|
134 | log_begin(Behavioural,FUNCTION); |
---|
135 | |
---|
136 | if ((presence_port == CLOCK_VHDL_YES) or |
---|
137 | (presence_port == CLOCK_VHDL_NO )) |
---|
138 | throw ErrorMorpheo ("Signal \""+name+"\" is not a clock, bad presence_port."); |
---|
139 | |
---|
140 | LowerCase(name); |
---|
141 | |
---|
142 | Signal * sig = set_signal (name, IN , size, presence_port); |
---|
143 | sc_in <T> * port; |
---|
144 | |
---|
145 | if (_usage & USE_SYSTEMC_INTERFACE) |
---|
146 | { |
---|
147 | port = new sc_in <T> (sig->_name.c_str()); |
---|
148 | sig->alloc<T> (static_cast<void *>(port)); |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | port = NULL; |
---|
153 | } |
---|
154 | |
---|
155 | log_end(Behavioural,FUNCTION); |
---|
156 | |
---|
157 | return port; |
---|
158 | }; |
---|
159 | |
---|
160 | #undef FUNCTION |
---|
161 | #define FUNCTION "Interface::set_signal_out" |
---|
162 | public : template <typename T> |
---|
163 | sc_out <T> * set_signal_out (std::string name , |
---|
164 | uint32_t size , |
---|
165 | presence_port_t presence_port=PORT_VHDL_YES_TESTBENCH_YES) |
---|
166 | { |
---|
167 | log_begin(Behavioural,FUNCTION); |
---|
168 | |
---|
169 | LowerCase(name); |
---|
170 | |
---|
171 | if ((presence_port == CLOCK_VHDL_YES) or |
---|
172 | (presence_port == CLOCK_VHDL_NO )) |
---|
173 | throw ErrorMorpheo ("Signal \""+name+"\" is not a clock, bad presence_port."); |
---|
174 | |
---|
175 | Signal * sig = set_signal (name, OUT , size, presence_port); |
---|
176 | sc_out <T> * port; |
---|
177 | |
---|
178 | if (_usage & USE_SYSTEMC_INTERFACE) |
---|
179 | { |
---|
180 | port = new sc_out <T> (sig->_name.c_str()); |
---|
181 | sig->alloc<T> (static_cast<void *>(port)); |
---|
182 | } |
---|
183 | else |
---|
184 | { |
---|
185 | port = NULL; |
---|
186 | } |
---|
187 | |
---|
188 | log_end(Behavioural,FUNCTION); |
---|
189 | |
---|
190 | return port; |
---|
191 | }; |
---|
192 | |
---|
193 | #undef FUNCTION |
---|
194 | #define FUNCTION "Interface::set_signal_internal" |
---|
195 | public : template <typename T> |
---|
196 | sc_signal <T> * set_signal_internal (std::string name, |
---|
197 | uint32_t size) |
---|
198 | { |
---|
199 | log_begin(Behavioural,FUNCTION); |
---|
200 | |
---|
201 | LowerCase(name); |
---|
202 | |
---|
203 | Signal * sig = set_signal (name, INTERNAL , size, PORT_VHDL_NO_TESTBENCH_NO); |
---|
204 | sc_signal <T> * port; |
---|
205 | |
---|
206 | if (_usage & USE_SYSTEMC_INTERFACE) |
---|
207 | { |
---|
208 | port = new sc_signal <T> (sig->_name.c_str()); |
---|
209 | sig->alloc<T> (static_cast<void *>(port)); |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | port = NULL; |
---|
214 | } |
---|
215 | |
---|
216 | log_end(Behavioural,FUNCTION); |
---|
217 | |
---|
218 | return port; |
---|
219 | }; |
---|
220 | |
---|
221 | #endif |
---|
222 | |
---|
223 | #ifdef VHDL |
---|
224 | public : void set_port (Vhdl * & vhdl); |
---|
225 | # ifdef VHDL_TESTBENCH |
---|
226 | public : void set_signal (Vhdl * & vhdl); |
---|
227 | public : void get_signal (std::list<std::string> * & list_signal); |
---|
228 | # endif |
---|
229 | #endif |
---|
230 | #ifdef VHDL_TESTBENCH |
---|
231 | public : uint32_t get_cycle (void); |
---|
232 | public : Signal * get_clock (void); |
---|
233 | public : Signal * get_reset (void); |
---|
234 | |
---|
235 | public : void make_testbench (bool value) {_make_testbench = value;} |
---|
236 | public : void testbench (void); |
---|
237 | public : void testbench_cycle (void); |
---|
238 | public : void testbench_body (Vhdl * & vhdl , |
---|
239 | std::string counter_name , |
---|
240 | std::string reset_name ); |
---|
241 | public : std::string testbench_test (Vhdl * & vhdl , |
---|
242 | std::string counter_name, |
---|
243 | std::string reset_name); |
---|
244 | public : std::string testbench_test_ok (Vhdl * & vhdl); |
---|
245 | protected : std::string testbench_test_name (Vhdl * & vhdl); |
---|
246 | protected : std::string testbench_test_ok_name (Vhdl * & vhdl); |
---|
247 | protected : std::string testbench_test_transaction_name (Vhdl * & vhdl); |
---|
248 | #endif |
---|
249 | |
---|
250 | public : bool test_map (std::string name_interfaces, |
---|
251 | bool top_level, |
---|
252 | bool is_behavioural); |
---|
253 | //public : bool test_equi (uint32_t depth); |
---|
254 | |
---|
255 | #ifdef POSITION |
---|
256 | public : void interface_map (void * entity, |
---|
257 | void * interface); |
---|
258 | public : XML toXML (void); |
---|
259 | public : XML toXML_mapping (void); |
---|
260 | #endif |
---|
261 | public : friend std::ostream& operator<< (std::ostream& output_stream, |
---|
262 | morpheo::behavioural::Interface & x); |
---|
263 | |
---|
264 | }; |
---|
265 | |
---|
266 | }; // end namespace behavioural |
---|
267 | }; // end namespace morpheo |
---|
268 | |
---|
269 | #endif |
---|