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

Last change on this file since 82 was 82, checked in by rosiere, 16 years ago
  • support locale (now must "just" translate)
  • update all component with new test format
  • update all component with usage
  • New component : decod queue and prediction_unit
  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
1#ifndef morpheo_behavioural_Signal_h
2#define morpheo_behavioural_Signal_h
3
4/*
5 * $Id: Signal.h 82 2008-05-01 16:48:45Z 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_VHDL_YES_TESTBENCH_YES,
41                PORT_VHDL_YES_TESTBENCH_NO ,
42                PORT_VHDL_NO_TESTBENCH_YES ,
43                PORT_VHDL_NO_TESTBENCH_NO  ,
44                CLOCK_VHDL_YES             ,
45                CLOCK_VHDL_NO              ,
46                RESET_VHDL_YES             ,
47                RESET_VHDL_NO              } presence_port_t;
48
49  class Signal
50  {
51    friend class Interface;
52
53    // -----[ fields ]----------------------------------------------------
54  private   : const std::string     _name          ;
55  private   : const direction_t     _direction     ;
56  private   : const presence_port_t _presence_port ;
57  private   :       uint32_t        _size          ;
58
59  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 ...)
60  private   : Signal *              _connect_from_signal     ; // producter of signal. If NULL, then producteur is the current entity
61  private   : bool                  _is_allocate             ; // Have allocate a sc_in or sc_out port
62  private   : void *                _sc_signal               ; // sc_in or sc_out associated at this signal
63  private   : void *                _sc_signal_map           ; // sc_out generated this signal
64  private   : bool                  _is_map_as_toplevel_dest ; 
65  private   : bool                  _is_map_as_component_src ; 
66  private   : bool                  _is_map_as_component_dest;
67  private   : type_info_t           _type_info               ;
68
69#ifdef VHDL_TESTBENCH
70  private   : std::list<std::string> * _list_value    ;
71#endif
72
73    // -----[ methods ]---------------------------------------------------
74  public    :                   Signal          (std::string          name          ,
75                                                 direction_t     direction     ,
76                                                 uint32_t        size          ,
77                                                 presence_port_t presence_port = PORT_VHDL_YES_TESTBENCH_YES);
78  public    :                   Signal          (const Signal &);
79  public    :                   ~Signal         ();
80
81  public    : std::string       get_name                (void);
82  public    : uint32_t          get_size                (void);
83  public    : void              set_size                (uint32_t size);
84  public    : void              set_size_max            (uint32_t size);
85
86  public    : Signal *          get_connect_to_signal   (void);
87  public    : Signal *          get_connect_from_signal (void);
88  public    : direction_t       get_direction           (void);
89  public    : type_info_t       get_type_info           (void);
90
91  public    : bool              presence_vhdl           (void);
92  public    : bool              presence_testbench      (void);
93
94  public    : bool              test_map                (uint32_t depth, bool top_level, bool is_behavioural);
95//   public    : bool              test_equi               (uint32_t depth);
96
97  public    : void              link                    (Signal * signal_dest,
98                                                         bool     signal_dest_is_port);
99
100  public    : void              connect                 (Signal * signal_dest);
101
102#ifdef SYSTEMC         
103  public    :template <typename T>
104             T                  read (void)
105    {
106      switch (_direction)
107        {
108        case IN  : {return read_in  <T>();}
109        case OUT : {return read_out <T>();}
110        default  : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow."));
111        }
112    }
113
114  public    :template <typename T>
115             T                  read_in (void)
116    {
117      switch (_type_info)
118        {
119        case BOOL     : return (static_cast<sc_in  <bool    > *>(_sc_signal_map)->read()); 
120        case UINT8_T  : return (static_cast<sc_in  <uint8_t > *>(_sc_signal_map)->read()); 
121        case UINT16_T : return (static_cast<sc_in  <uint16_t> *>(_sc_signal_map)->read());
122        case UINT32_T : return (static_cast<sc_in  <uint32_t> *>(_sc_signal_map)->read()); 
123        case UINT64_T : return (static_cast<sc_in  <uint64_t> *>(_sc_signal_map)->read()); 
124        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
125        }
126    }
127
128  public    :template <typename T>
129             T                  read_out(void)
130    {
131      switch (_type_info)
132        {
133        case BOOL     : return (static_cast<sc_out <bool    > *>(_sc_signal_map)->read()); 
134        case UINT8_T  : return (static_cast<sc_out <uint8_t > *>(_sc_signal_map)->read()); 
135        case UINT16_T : return (static_cast<sc_out <uint16_t> *>(_sc_signal_map)->read());
136        case UINT32_T : return (static_cast<sc_out <uint32_t> *>(_sc_signal_map)->read()); 
137        case UINT64_T : return (static_cast<sc_out <uint64_t> *>(_sc_signal_map)->read()); 
138        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
139        }
140    }
141
142#undef  FUNCTION
143#define FUNCTION "Signal::alloc"
144  public    : template <typename T>
145  void              alloc           (void * sc_signal)
146    {
147      log_printf(FUNC,Behavioural,FUNCTION,"Begin");
148
149      if (_type_info != UNKNOW)
150        throw (ErrorMorpheo ("Signal \""+_name+"\" : already allocate."));
151
152      if (test<T>(_size) == false)
153        throw (ErrorMorpheo ("Signal \""+_name+"\" : size is too small to the associate type."));
154
155      _is_allocate    = true;
156      _sc_signal      = sc_signal;
157      _sc_signal_map  = sc_signal;
158
159      log_printf(TRACE,Behavioural,FUNCTION, "Allocation of %s - %.8x", _name.c_str(), (uint32_t)(_sc_signal_map));
160
161      if (typeid(T) == typeid(bool    ))
162        _type_info = BOOL;
163      else
164      if (typeid(T) == typeid(uint8_t ))
165        _type_info = UINT8_T;
166      else
167      if (typeid(T) == typeid(uint16_t))
168        _type_info = UINT16_T;
169      else
170      if (typeid(T) == typeid(uint32_t))
171        _type_info = UINT32_T;
172      else
173      if (typeid(T) == typeid(uint64_t))
174        _type_info = UINT64_T;
175      else
176        _type_info = UNKNOW;
177
178      log_printf(FUNC,Behavioural,FUNCTION,"End");
179    }
180#endif
181
182#ifdef VHDL
183  public    : void              set_port        (Vhdl * & vhdl);
184#  ifdef VHDL_TESTBENCH
185  public    : Signal *          get_clock       (void);
186  public    : Signal *          get_reset       (void);
187  public    : uint32_t          get_reset_cycle (bool active_low);
188
189  public    : void              set_signal      (Vhdl * & vhdl);
190  public    : void              get_name_vhdl   (std::list<std::string> * & list_signal);
191
192  public    : void              testbench        (void);
193  public    : void              testbench_body   (Vhdl           * & vhdl          ,
194                                                  std::string             counter_name  ,
195                                                  std::string             reset_name    );
196  public    : void              testbench_test_ok(Vhdl           * & vhdl          );
197#  endif
198#endif
199  public    : XML               toXML           (void);
200
201  public    : friend std::ostream&   operator<<      (std::ostream& output_stream,
202                                                      morpheo::behavioural::Signal & x);
203
204  };
205}; // end namespace behavioural         
206
207  template<>           inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x)
208  {
209    switch (x)
210      {
211      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_YES : return "Port  is in VHDL's model and TestBench's model" ; break;
212      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_NO  : return "Port  is in VHDL's model                      " ; break;
213      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_YES  : return "Port  is in                  TestBench's model" ; break;
214      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_NO   : return "Port  is in none model                        " ; break;
215      case morpheo::behavioural::CLOCK_VHDL_YES              : return "Clock is in VHDL's model                     " ; break;
216      case morpheo::behavioural::CLOCK_VHDL_NO               : return "Clock is not in VHDL's model                 " ; break;
217      case morpheo::behavioural::RESET_VHDL_YES              : return "Reset is in VHDL's model                     " ; break;
218      case morpheo::behavioural::RESET_VHDL_NO               : return "Reset is not in VHDL's model                 " ; break;
219      default                                                : return "";                                               break;
220      }
221  }
222
223}; // end namespace morpheo             
224
225#endif
Note: See TracBrowser for help on using the repository browser.