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