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

Last change on this file since 88 was 88, checked in by rosiere, 16 years ago

Almost complete design
with Test and test platform

  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
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
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    : bool              presence_vhdl           (void);
93  public    : bool              presence_testbench      (void);
94
95  public    : bool              test_map                (uint32_t depth, bool top_level, bool is_behavioural);
96//public    : bool              test_equi               (uint32_t depth);
97
98  public    : void              link                    (Signal * signal_dest,
99                                                         bool     signal_dest_is_port);
100
101  public    : void              connect                 (Signal * signal_dest);
102
103#ifdef SYSTEMC         
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>();}
111        default  : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow.\n"));
112        }
113    }
114
115  public    :template <typename T>
116             T                  read_in (void)
117    {
118      switch (_type_info)
119        {
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()); 
125        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.\n"));
126        }
127    }
128
129  public    :template <typename T>
130             T                  read_out(void)
131    {
132      switch (_type_info)
133        {
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()); 
139        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow.\n"));
140        }
141    }
142
143#undef  FUNCTION
144#define FUNCTION "Signal::alloc"
145  public    : template <typename T>
146  void              alloc           (void * sc_signal)
147    {
148      log_printf(FUNC,Behavioural,FUNCTION,"Begin");
149
150      if (_type_info != UNKNOW)
151        throw (ErrorMorpheo (toString(_("Signal \"%s\" : already allocate.\n"),_name.c_str())));
152
153      if (test<T>(_size) == false)
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))));
155
156      _is_allocate    = true;
157      _sc_signal      = sc_signal;
158      _sc_signal_map  = sc_signal;
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;
176
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
179      log_printf(FUNC,Behavioural,FUNCTION,"End");
180    }
181#endif
182
183#ifdef VHDL
184  public    : void              set_port        (Vhdl * & vhdl);
185#  ifdef VHDL_TESTBENCH
186  public    : Signal *          get_clock       (void);
187  public    : Signal *          get_reset       (void);
188  public    : uint32_t          get_reset_cycle (bool active_low);
189
190  public    : void              set_signal      (Vhdl * & vhdl);
191  public    : void              get_name_vhdl   (std::list<std::string> * & list_signal);
192
193  public    : void              testbench        (void);
194  public    : void              testbench_body   (Vhdl           * & vhdl          ,
195                                                  std::string             counter_name  ,
196                                                  std::string             reset_name    );
197  public    : void              testbench_test_ok(Vhdl           * & vhdl          );
198#  endif
199#endif
200  public    : XML               toXML           (void);
201
202  public    : friend std::ostream&   operator<<      (std::ostream& output_stream,
203                                                      morpheo::behavioural::Signal & x);
204
205  };
206}; // end namespace behavioural         
207
208
209
210
211  template<>           inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x)
212  {
213    switch (x)
214      {
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;
223      default                                                : return "";                                               break;
224      }
225  }
226
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
248}; // end namespace morpheo             
249
250#endif
Note: See TracBrowser for help on using the repository browser.