1 | #ifndef morpheo_behavioural_Signal_h |
---|
2 | #define morpheo_behavioural_Signal_h |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #ifdef SYSTEMC |
---|
12 | #include "systemc.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <stdint.h> |
---|
16 | #include <iostream> |
---|
17 | |
---|
18 | #ifdef VHDL |
---|
19 | #include "Behavioural/include/Vhdl.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include "Behavioural/include/Direction.h" |
---|
23 | #include "Behavioural/include/XML.h" |
---|
24 | #include "Common/include/ErrorMorpheo.h" |
---|
25 | #include "Common/include/ToBase2.h" |
---|
26 | #include "Common/include/ToString.h" |
---|
27 | #include "Common/include/Debug.h" |
---|
28 | |
---|
29 | using namespace std; |
---|
30 | |
---|
31 | namespace morpheo { |
---|
32 | namespace behavioural { |
---|
33 | |
---|
34 | typedef enum {UNKNOW , |
---|
35 | BOOL , |
---|
36 | UINT8_T , |
---|
37 | UINT16_T , |
---|
38 | UINT32_T , |
---|
39 | UINT64_T } type_info_t; |
---|
40 | |
---|
41 | typedef enum {PORT_VHDL_YES_TESTBENCH_YES, |
---|
42 | PORT_VHDL_YES_TESTBENCH_NO , |
---|
43 | PORT_VHDL_NO_TESTBENCH_YES , |
---|
44 | PORT_VHDL_NO_TESTBENCH_NO , |
---|
45 | CLOCK_VHDL_YES , |
---|
46 | CLOCK_VHDL_NO , |
---|
47 | RESET_VHDL_YES , |
---|
48 | RESET_VHDL_NO } presence_port_t; |
---|
49 | |
---|
50 | class Signal |
---|
51 | { |
---|
52 | friend class Interface; |
---|
53 | |
---|
54 | // -----[ fields ]---------------------------------------------------- |
---|
55 | private : const string _name ; |
---|
56 | private : const direction_t _direction ; |
---|
57 | private : const uint32_t _size ; |
---|
58 | private : const presence_port_t _presence_port; |
---|
59 | |
---|
60 | private : Signal * _connect_to_signal; // the actual implementaion, this signal link with one signal (but if signal is an output, it can be connect with many signal ...) |
---|
61 | private : Signal * _connect_from_signal; // producter of signal. If NULL, then producteur is the current entity |
---|
62 | private : bool _is_allocate ; // Have allocate a sc_in or sc_out port |
---|
63 | private : void * _sc_signal ; // sc_in or sc_out associated at this signal |
---|
64 | private : bool _is_map ; |
---|
65 | private : void * _sc_signal_map; // sc_out generated this signal |
---|
66 | private : type_info_t _type_info ; |
---|
67 | |
---|
68 | #ifdef VHDL_TESTBENCH |
---|
69 | private : list<string> * _list_value ; |
---|
70 | #endif |
---|
71 | |
---|
72 | // -----[ methods ]--------------------------------------------------- |
---|
73 | public : Signal (string name , |
---|
74 | direction_t direction , |
---|
75 | uint32_t size , |
---|
76 | presence_port_t presence_port = PORT_VHDL_YES_TESTBENCH_YES); |
---|
77 | public : Signal (const Signal &); |
---|
78 | public : ~Signal (); |
---|
79 | |
---|
80 | public : string get_name (void); |
---|
81 | public : uint32_t get_size (void); |
---|
82 | public : bool get_is_map (void); |
---|
83 | public : Signal * get_connect_to_signal (void); |
---|
84 | public : Signal * get_connect_from_signal (void); |
---|
85 | public : direction_t get_direction (void); |
---|
86 | |
---|
87 | public : bool presence_vhdl (void); |
---|
88 | public : bool presence_testbench (void); |
---|
89 | |
---|
90 | // public : void mapping (Signal * signal); |
---|
91 | public : void link (Signal * signal , |
---|
92 | bool is_port_component); |
---|
93 | |
---|
94 | #ifdef SYSTEMC |
---|
95 | public :template <typename T> |
---|
96 | T read (void) |
---|
97 | { |
---|
98 | switch (_direction) |
---|
99 | { |
---|
100 | case IN : {return read_in <T>();} |
---|
101 | case OUT : {return read_out <T>();} |
---|
102 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow.")); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | public :template <typename T> |
---|
107 | T read_in (void) |
---|
108 | { |
---|
109 | switch (_type_info) |
---|
110 | { |
---|
111 | case BOOL : return (static_cast<sc_in <bool > *>(_sc_signal_map)->read()); |
---|
112 | case UINT8_T : return (static_cast<sc_in <uint8_t > *>(_sc_signal_map)->read()); |
---|
113 | case UINT16_T : return (static_cast<sc_in <uint16_t> *>(_sc_signal_map)->read()); |
---|
114 | case UINT32_T : return (static_cast<sc_in <uint32_t> *>(_sc_signal_map)->read()); |
---|
115 | case UINT64_T : return (static_cast<sc_in <uint64_t> *>(_sc_signal_map)->read()); |
---|
116 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.")); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | public :template <typename T> |
---|
121 | T read_out(void) |
---|
122 | { |
---|
123 | switch (_type_info) |
---|
124 | { |
---|
125 | case BOOL : return (static_cast<sc_out <bool > *>(_sc_signal_map)->read()); |
---|
126 | case UINT8_T : return (static_cast<sc_out <uint8_t > *>(_sc_signal_map)->read()); |
---|
127 | case UINT16_T : return (static_cast<sc_out <uint16_t> *>(_sc_signal_map)->read()); |
---|
128 | case UINT32_T : return (static_cast<sc_out <uint32_t> *>(_sc_signal_map)->read()); |
---|
129 | case UINT64_T : return (static_cast<sc_out <uint64_t> *>(_sc_signal_map)->read()); |
---|
130 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.")); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | #undef FUNCTION |
---|
135 | #define FUNCTION "Signal::alloc" |
---|
136 | public : template <typename T> |
---|
137 | void alloc (void * sc_signal) |
---|
138 | { |
---|
139 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
140 | |
---|
141 | if (_type_info != UNKNOW) |
---|
142 | throw (ErrorMorpheo ("Signal \""+_name+"\" : already allocate.")); |
---|
143 | |
---|
144 | _is_allocate = true; |
---|
145 | _sc_signal = sc_signal; |
---|
146 | _sc_signal_map = sc_signal; |
---|
147 | |
---|
148 | log_printf(TRACE,Behavioural,FUNCTION, "Allocation of %s - %.8x", _name.c_str(), (uint32_t)(_sc_signal_map)); |
---|
149 | |
---|
150 | if (typeid(T) == typeid(bool )) |
---|
151 | _type_info = BOOL; |
---|
152 | else |
---|
153 | if (typeid(T) == typeid(uint8_t )) |
---|
154 | _type_info = UINT8_T; |
---|
155 | else |
---|
156 | if (typeid(T) == typeid(uint16_t)) |
---|
157 | _type_info = UINT16_T; |
---|
158 | else |
---|
159 | if (typeid(T) == typeid(uint32_t)) |
---|
160 | _type_info = UINT32_T; |
---|
161 | else |
---|
162 | if (typeid(T) == typeid(uint64_t)) |
---|
163 | _type_info = UINT64_T; |
---|
164 | else |
---|
165 | _type_info = UNKNOW; |
---|
166 | |
---|
167 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
168 | } |
---|
169 | #endif |
---|
170 | |
---|
171 | #ifdef VHDL |
---|
172 | public : void set_port (Vhdl * & vhdl); |
---|
173 | # ifdef VHDL_TESTBENCH |
---|
174 | public : Signal * get_clock (void); |
---|
175 | public : Signal * get_reset (void); |
---|
176 | public : uint32_t get_reset_cycle (bool active_low); |
---|
177 | |
---|
178 | public : void set_signal (Vhdl * & vhdl); |
---|
179 | public : void get_name_vhdl (list<string> * & list_signal); |
---|
180 | |
---|
181 | public : void testbench (void); |
---|
182 | public : void testbench_body (Vhdl * & vhdl , |
---|
183 | string counter_name , |
---|
184 | string reset_name ); |
---|
185 | public : void testbench_test_ok(Vhdl * & vhdl ); |
---|
186 | # endif |
---|
187 | #endif |
---|
188 | public : XML toXML (void); |
---|
189 | |
---|
190 | public : friend ostream& operator<< (ostream& output_stream, |
---|
191 | morpheo::behavioural::Signal & x); |
---|
192 | |
---|
193 | }; |
---|
194 | }; // end namespace behavioural |
---|
195 | |
---|
196 | template<> inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x) |
---|
197 | { |
---|
198 | switch (x) |
---|
199 | { |
---|
200 | case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_YES : return "Port is in VHDL's model and TestBench's model" ; break; |
---|
201 | case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_NO : return "Port is in VHDL's model " ; break; |
---|
202 | case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_YES : return "Port is in TestBench's model" ; break; |
---|
203 | case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_NO : return "Port is in none model " ; break; |
---|
204 | case morpheo::behavioural::CLOCK_VHDL_YES : return "Clock is in VHDL's model " ; break; |
---|
205 | case morpheo::behavioural::CLOCK_VHDL_NO : return "Clock is not in VHDL's model " ; break; |
---|
206 | case morpheo::behavioural::RESET_VHDL_YES : return "Reset is in VHDL's model " ; break; |
---|
207 | case morpheo::behavioural::RESET_VHDL_NO : return "Reset is not in VHDL's model " ; break; |
---|
208 | default : return ""; break; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | }; // end namespace morpheo |
---|
213 | |
---|
214 | #endif |
---|