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

Last change on this file since 113 was 113, checked in by rosiere, 15 years ago

1) Add modelsim simulation systemC
2) Modelsim cosimulation systemC / VHDL is not finish !!!! (cf execute_queue and write_unit)
3) Add multi architecture
5) Add template for comparator, multiplier and divider
6) Change Message
Warning) Various test macro have change, many selftest can't compile

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