[29] | 1 | #ifndef morpheo_behavioural_Signal_h |
---|
| 2 | #define morpheo_behavioural_Signal_h |
---|
| 3 | |
---|
| 4 | /* |
---|
| 5 | * $Id: Signal.h 139 2010-07-30 14:47:27Z rosiere $ |
---|
| 6 | * |
---|
[113] | 7 | * [ Description ] |
---|
[29] | 8 | * |
---|
| 9 | */ |
---|
| 10 | |
---|
[38] | 11 | #ifdef SYSTEMC |
---|
| 12 | #include "systemc.h" |
---|
| 13 | #endif |
---|
| 14 | |
---|
[29] | 15 | #include <stdint.h> |
---|
| 16 | #include <iostream> |
---|
[38] | 17 | |
---|
[41] | 18 | #ifdef VHDL |
---|
| 19 | #include "Behavioural/include/Vhdl.h" |
---|
[38] | 20 | #endif |
---|
| 21 | |
---|
[81] | 22 | #include "Behavioural/include/Parameters.h" |
---|
[29] | 23 | #include "Behavioural/include/Direction.h" |
---|
| 24 | #include "Behavioural/include/XML.h" |
---|
[129] | 25 | #include "Behavioural/include/Debug_signal.h" |
---|
[44] | 26 | #include "Common/include/ErrorMorpheo.h" |
---|
| 27 | #include "Common/include/ToBase2.h" |
---|
| 28 | #include "Common/include/ToString.h" |
---|
| 29 | #include "Common/include/Debug.h" |
---|
[29] | 30 | |
---|
| 31 | namespace morpheo { |
---|
| 32 | namespace behavioural { |
---|
| 33 | |
---|
[38] | 34 | typedef enum {UNKNOW , |
---|
| 35 | BOOL , |
---|
| 36 | UINT8_T , |
---|
| 37 | UINT16_T , |
---|
| 38 | UINT32_T , |
---|
| 39 | UINT64_T } type_info_t; |
---|
| 40 | |
---|
[88] | 41 | typedef enum {PORT_SYSTEMC_NO , // also, vhdl_no and testbench_no |
---|
| 42 | PORT_VHDL_YES_TESTBENCH_YES, |
---|
[29] | 43 | PORT_VHDL_YES_TESTBENCH_NO , |
---|
| 44 | PORT_VHDL_NO_TESTBENCH_YES , |
---|
[41] | 45 | PORT_VHDL_NO_TESTBENCH_NO , |
---|
| 46 | CLOCK_VHDL_YES , |
---|
[42] | 47 | CLOCK_VHDL_NO , |
---|
| 48 | RESET_VHDL_YES , |
---|
| 49 | RESET_VHDL_NO } presence_port_t; |
---|
[29] | 50 | |
---|
| 51 | class Signal |
---|
| 52 | { |
---|
[31] | 53 | friend class Interface; |
---|
| 54 | |
---|
[29] | 55 | // -----[ fields ]---------------------------------------------------- |
---|
[78] | 56 | private : const std::string _name ; |
---|
[62] | 57 | private : const direction_t _direction ; |
---|
| 58 | private : const presence_port_t _presence_port ; |
---|
[65] | 59 | private : uint32_t _size ; |
---|
[29] | 60 | |
---|
[78] | 61 | 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 ...) |
---|
| 62 | private : Signal * _connect_from_signal ; // producter of signal. If NULL, then producteur is the current entity |
---|
| 63 | private : bool _is_allocate ; // Have allocate a sc_in or sc_out port |
---|
| 64 | private : void * _sc_signal ; // sc_in or sc_out associated at this signal |
---|
| 65 | private : void * _sc_signal_map ; // sc_out generated this signal |
---|
| 66 | private : bool _is_map_as_toplevel_dest ; |
---|
| 67 | private : bool _is_map_as_component_src ; |
---|
| 68 | private : bool _is_map_as_component_dest; |
---|
| 69 | private : type_info_t _type_info ; |
---|
[40] | 70 | |
---|
[42] | 71 | #ifdef VHDL_TESTBENCH |
---|
[75] | 72 | private : std::list<std::string> * _list_value ; |
---|
[38] | 73 | #endif |
---|
| 74 | |
---|
[29] | 75 | // -----[ methods ]--------------------------------------------------- |
---|
[88] | 76 | public : Signal (std::string name , |
---|
| 77 | direction_t direction , |
---|
| 78 | uint32_t size , |
---|
| 79 | presence_port_t presence_port = PORT_VHDL_YES_TESTBENCH_YES); |
---|
| 80 | public : Signal (const Signal &); |
---|
| 81 | public : ~Signal (); |
---|
[29] | 82 | |
---|
[82] | 83 | public : std::string get_name (void); |
---|
[62] | 84 | public : uint32_t get_size (void); |
---|
[65] | 85 | public : void set_size (uint32_t size); |
---|
| 86 | public : void set_size_max (uint32_t size); |
---|
| 87 | |
---|
[62] | 88 | public : Signal * get_connect_to_signal (void); |
---|
[44] | 89 | public : Signal * get_connect_from_signal (void); |
---|
[62] | 90 | public : direction_t get_direction (void); |
---|
| 91 | public : type_info_t get_type_info (void); |
---|
[42] | 92 | |
---|
[113] | 93 | public : void * get_sc_signal (void); |
---|
| 94 | |
---|
[62] | 95 | public : bool presence_vhdl (void); |
---|
| 96 | public : bool presence_testbench (void); |
---|
[42] | 97 | |
---|
[139] | 98 | public : bool test_map (std::string name_interface, |
---|
| 99 | bool top_level, |
---|
| 100 | bool is_behavioural); |
---|
[88] | 101 | //public : bool test_equi (uint32_t depth); |
---|
[42] | 102 | |
---|
[62] | 103 | public : void link (Signal * signal_dest, |
---|
| 104 | bool signal_dest_is_port); |
---|
| 105 | |
---|
| 106 | public : void connect (Signal * signal_dest); |
---|
| 107 | |
---|
[42] | 108 | #ifdef SYSTEMC |
---|
[40] | 109 | public :template <typename T> |
---|
| 110 | T read (void) |
---|
| 111 | { |
---|
| 112 | switch (_direction) |
---|
| 113 | { |
---|
| 114 | case IN : {return read_in <T>();} |
---|
| 115 | case OUT : {return read_out <T>();} |
---|
[88] | 116 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow.\n")); |
---|
[40] | 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | public :template <typename T> |
---|
| 121 | T read_in (void) |
---|
| 122 | { |
---|
| 123 | switch (_type_info) |
---|
| 124 | { |
---|
[42] | 125 | case BOOL : return (static_cast<sc_in <bool > *>(_sc_signal_map)->read()); |
---|
| 126 | case UINT8_T : return (static_cast<sc_in <uint8_t > *>(_sc_signal_map)->read()); |
---|
| 127 | case UINT16_T : return (static_cast<sc_in <uint16_t> *>(_sc_signal_map)->read()); |
---|
| 128 | case UINT32_T : return (static_cast<sc_in <uint32_t> *>(_sc_signal_map)->read()); |
---|
| 129 | case UINT64_T : return (static_cast<sc_in <uint64_t> *>(_sc_signal_map)->read()); |
---|
[88] | 130 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.\n")); |
---|
[40] | 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | public :template <typename T> |
---|
| 135 | T read_out(void) |
---|
| 136 | { |
---|
| 137 | switch (_type_info) |
---|
| 138 | { |
---|
[42] | 139 | case BOOL : return (static_cast<sc_out <bool > *>(_sc_signal_map)->read()); |
---|
| 140 | case UINT8_T : return (static_cast<sc_out <uint8_t > *>(_sc_signal_map)->read()); |
---|
| 141 | case UINT16_T : return (static_cast<sc_out <uint16_t> *>(_sc_signal_map)->read()); |
---|
| 142 | case UINT32_T : return (static_cast<sc_out <uint32_t> *>(_sc_signal_map)->read()); |
---|
| 143 | case UINT64_T : return (static_cast<sc_out <uint64_t> *>(_sc_signal_map)->read()); |
---|
[88] | 144 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.\n")); |
---|
[40] | 145 | } |
---|
| 146 | } |
---|
[138] | 147 | #endif |
---|
[40] | 148 | |
---|
[44] | 149 | #undef FUNCTION |
---|
| 150 | #define FUNCTION "Signal::alloc" |
---|
[38] | 151 | public : template <typename T> |
---|
[59] | 152 | void alloc (void * sc_signal) |
---|
[38] | 153 | { |
---|
[44] | 154 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 155 | |
---|
[38] | 156 | if (_type_info != UNKNOW) |
---|
[88] | 157 | throw (ErrorMorpheo (toString(_("Signal \"%s\" : already allocate.\n"),_name.c_str()))); |
---|
[38] | 158 | |
---|
[81] | 159 | if (test<T>(_size) == false) |
---|
[88] | 160 | throw (ErrorMorpheo (toString(_("Signal \"%s\" : size is too small (%d bits) to the associate type (%d bits).\n"),_name.c_str(),_size,8*sizeof(T)))); |
---|
[81] | 161 | |
---|
[44] | 162 | _is_allocate = true; |
---|
| 163 | _sc_signal = sc_signal; |
---|
| 164 | _sc_signal_map = sc_signal; |
---|
[38] | 165 | |
---|
[137] | 166 | DEBUG_SIGNAL_ADD(sc_signal,_name); |
---|
[129] | 167 | |
---|
[38] | 168 | if (typeid(T) == typeid(bool )) |
---|
| 169 | _type_info = BOOL; |
---|
| 170 | else |
---|
| 171 | if (typeid(T) == typeid(uint8_t )) |
---|
| 172 | _type_info = UINT8_T; |
---|
| 173 | else |
---|
| 174 | if (typeid(T) == typeid(uint16_t)) |
---|
| 175 | _type_info = UINT16_T; |
---|
| 176 | else |
---|
| 177 | if (typeid(T) == typeid(uint32_t)) |
---|
| 178 | _type_info = UINT32_T; |
---|
| 179 | else |
---|
| 180 | if (typeid(T) == typeid(uint64_t)) |
---|
| 181 | _type_info = UINT64_T; |
---|
| 182 | else |
---|
| 183 | _type_info = UNKNOW; |
---|
[113] | 184 | |
---|
[88] | 185 | log_printf(TRACE,Behavioural,FUNCTION, "Allocation of %s (%s, 0x%.8x)", _name.c_str(),toString(_type_info).c_str(), static_cast<uint32_t>(reinterpret_cast<uint64_t>(_sc_signal_map))); |
---|
| 186 | |
---|
[44] | 187 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
[38] | 188 | } |
---|
[41] | 189 | |
---|
[138] | 190 | |
---|
| 191 | #undef FUNCTION |
---|
| 192 | #define FUNCTION "Signal::alloc" |
---|
| 193 | void dealloc (void) |
---|
| 194 | { |
---|
| 195 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 196 | |
---|
| 197 | switch (_direction) |
---|
| 198 | { |
---|
| 199 | case INTERNAL : |
---|
| 200 | switch (_type_info) |
---|
| 201 | { |
---|
| 202 | case BOOL : delete (static_cast<sc_signal <bool > *>(_sc_signal_map)); break; |
---|
| 203 | case UINT8_T : delete (static_cast<sc_signal <uint8_t > *>(_sc_signal_map)); break; |
---|
| 204 | case UINT16_T : delete (static_cast<sc_signal <uint16_t> *>(_sc_signal_map)); break; |
---|
| 205 | case UINT32_T : delete (static_cast<sc_signal <uint32_t> *>(_sc_signal_map)); break; |
---|
| 206 | case UINT64_T : delete (static_cast<sc_signal <uint64_t> *>(_sc_signal_map)); break; |
---|
| 207 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.\n")); |
---|
| 208 | } |
---|
| 209 | default : throw (ErrorMorpheo ("Signal \""+_name+"\" : invalid direction.\n")); |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
| 215 | } |
---|
| 216 | |
---|
[41] | 217 | #ifdef VHDL |
---|
| 218 | public : void set_port (Vhdl * & vhdl); |
---|
| 219 | # ifdef VHDL_TESTBENCH |
---|
[42] | 220 | public : Signal * get_clock (void); |
---|
| 221 | public : Signal * get_reset (void); |
---|
| 222 | public : uint32_t get_reset_cycle (bool active_low); |
---|
| 223 | |
---|
[41] | 224 | public : void set_signal (Vhdl * & vhdl); |
---|
[75] | 225 | public : void get_name_vhdl (std::list<std::string> * & list_signal); |
---|
[42] | 226 | |
---|
| 227 | public : void testbench (void); |
---|
| 228 | public : void testbench_body (Vhdl * & vhdl , |
---|
[71] | 229 | std::string counter_name , |
---|
| 230 | std::string reset_name ); |
---|
[42] | 231 | public : void testbench_test_ok(Vhdl * & vhdl ); |
---|
[41] | 232 | # endif |
---|
| 233 | #endif |
---|
[29] | 234 | public : XML toXML (void); |
---|
| 235 | |
---|
[75] | 236 | public : friend std::ostream& operator<< (std::ostream& output_stream, |
---|
| 237 | morpheo::behavioural::Signal & x); |
---|
[29] | 238 | |
---|
| 239 | }; |
---|
| 240 | }; // end namespace behavioural |
---|
| 241 | |
---|
[88] | 242 | |
---|
| 243 | |
---|
| 244 | |
---|
[29] | 245 | template<> inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x) |
---|
| 246 | { |
---|
| 247 | switch (x) |
---|
| 248 | { |
---|
[42] | 249 | case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_YES : return "Port is in VHDL's model and TestBench's model" ; break; |
---|
| 250 | case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_NO : return "Port is in VHDL's model " ; break; |
---|
| 251 | case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_YES : return "Port is in TestBench's model" ; break; |
---|
| 252 | case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_NO : return "Port is in none model " ; break; |
---|
| 253 | case morpheo::behavioural::CLOCK_VHDL_YES : return "Clock is in VHDL's model " ; break; |
---|
| 254 | case morpheo::behavioural::CLOCK_VHDL_NO : return "Clock is not in VHDL's model " ; break; |
---|
| 255 | case morpheo::behavioural::RESET_VHDL_YES : return "Reset is in VHDL's model " ; break; |
---|
| 256 | case morpheo::behavioural::RESET_VHDL_NO : return "Reset is not in VHDL's model " ; break; |
---|
[29] | 257 | default : return ""; break; |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | |
---|
[88] | 261 | typedef enum {UNKNOW , |
---|
| 262 | BOOL , |
---|
| 263 | UINT8_T , |
---|
| 264 | UINT16_T , |
---|
| 265 | UINT32_T , |
---|
| 266 | UINT64_T } type_info_t; |
---|
| 267 | |
---|
| 268 | template<> inline std::string toString<morpheo::behavioural::type_info_t>(const morpheo::behavioural::type_info_t& x) |
---|
| 269 | { |
---|
| 270 | switch (x) |
---|
| 271 | { |
---|
| 272 | case morpheo::behavioural::BOOL : return "bool" ; break; |
---|
| 273 | case morpheo::behavioural::UINT8_T : return "uint8_t" ; break; |
---|
| 274 | case morpheo::behavioural::UINT16_T : return "uint16_t"; break; |
---|
| 275 | case morpheo::behavioural::UINT32_T : return "uint32_t"; break; |
---|
| 276 | case morpheo::behavioural::UINT64_T : return "uint64_t"; break; |
---|
| 277 | case morpheo::behavioural::UNKNOW : |
---|
| 278 | default : return "unknow" ; break; |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | |
---|
[29] | 282 | }; // end namespace morpheo |
---|
| 283 | |
---|
| 284 | #endif |
---|