source: trunk/IPs/systemC/processor/Morpheo/Behavioural/include/Signal.h @ 138

Last change on this file since 138 was 138, checked in by rosiere, 14 years ago

1) add counters_t type for interface
2) fix in check load in load_store_unit
3) add parameters (but not yet implemented)
4) change environment and add script (distcc_env.sh ...)
5) add warning if an unser change rename flag with l.mtspr instruction
6) ...

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