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

Last change on this file since 81 was 81, checked in by rosiere, 16 years ago
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1#ifndef morpheo_behavioural_Signal_h
2#define morpheo_behavioural_Signal_h
3
4/*
5 * $Id: Signal.h 81 2008-04-15 18:40: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 "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);
95
96  public    : void              link                    (Signal * signal_dest,
97                                                         bool     signal_dest_is_port);
98
99  public    : void              connect                 (Signal * signal_dest);
100
101#ifdef SYSTEMC         
102  public    :template <typename T>
103             T                  read (void)
104    {
105      switch (_direction)
106        {
107        case IN  : {return read_in  <T>();}
108        case OUT : {return read_out <T>();}
109        default  : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow."));
110        }
111    }
112
113  public    :template <typename T>
114             T                  read_in (void)
115    {
116      switch (_type_info)
117        {
118        case BOOL     : return (static_cast<sc_in  <bool    > *>(_sc_signal_map)->read()); 
119        case UINT8_T  : return (static_cast<sc_in  <uint8_t > *>(_sc_signal_map)->read()); 
120        case UINT16_T : return (static_cast<sc_in  <uint16_t> *>(_sc_signal_map)->read());
121        case UINT32_T : return (static_cast<sc_in  <uint32_t> *>(_sc_signal_map)->read()); 
122        case UINT64_T : return (static_cast<sc_in  <uint64_t> *>(_sc_signal_map)->read()); 
123        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
124        }
125    }
126
127  public    :template <typename T>
128             T                  read_out(void)
129    {
130      switch (_type_info)
131        {
132        case BOOL     : return (static_cast<sc_out <bool    > *>(_sc_signal_map)->read()); 
133        case UINT8_T  : return (static_cast<sc_out <uint8_t > *>(_sc_signal_map)->read()); 
134        case UINT16_T : return (static_cast<sc_out <uint16_t> *>(_sc_signal_map)->read());
135        case UINT32_T : return (static_cast<sc_out <uint32_t> *>(_sc_signal_map)->read()); 
136        case UINT64_T : return (static_cast<sc_out <uint64_t> *>(_sc_signal_map)->read()); 
137        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
138        }
139    }
140
141#undef  FUNCTION
142#define FUNCTION "Signal::alloc"
143  public    : template <typename T>
144  void              alloc           (void * sc_signal)
145    {
146      log_printf(FUNC,Behavioural,FUNCTION,"Begin");
147
148      if (_type_info != UNKNOW)
149        throw (ErrorMorpheo ("Signal \""+_name+"\" : already allocate."));
150
151      if (test<T>(_size) == false)
152        throw (ErrorMorpheo ("Signal \""+_name+"\" : size is too small to the associate type."));
153
154      _is_allocate    = true;
155      _sc_signal      = sc_signal;
156      _sc_signal_map  = sc_signal;
157
158      log_printf(TRACE,Behavioural,FUNCTION, "Allocation of %s - %.8x", _name.c_str(), (uint32_t)(_sc_signal_map));
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(FUNC,Behavioural,FUNCTION,"End");
178    }
179#endif
180
181#ifdef VHDL
182  public    : void              set_port        (Vhdl * & vhdl);
183#  ifdef VHDL_TESTBENCH
184  public    : Signal *          get_clock       (void);
185  public    : Signal *          get_reset       (void);
186  public    : uint32_t          get_reset_cycle (bool active_low);
187
188  public    : void              set_signal      (Vhdl * & vhdl);
189  public    : void              get_name_vhdl   (std::list<std::string> * & list_signal);
190
191  public    : void              testbench        (void);
192  public    : void              testbench_body   (Vhdl           * & vhdl          ,
193                                                  std::string             counter_name  ,
194                                                  std::string             reset_name    );
195  public    : void              testbench_test_ok(Vhdl           * & vhdl          );
196#  endif
197#endif
198  public    : XML               toXML           (void);
199
200  public    : friend std::ostream&   operator<<      (std::ostream& output_stream,
201                                                      morpheo::behavioural::Signal & x);
202
203  };
204}; // end namespace behavioural         
205
206  template<>           inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x)
207  {
208    switch (x)
209      {
210      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_YES : return "Port  is in VHDL's model and TestBench's model" ; break;
211      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_NO  : return "Port  is in VHDL's model                      " ; break;
212      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_YES  : return "Port  is in                  TestBench's model" ; break;
213      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_NO   : return "Port  is in none model                        " ; break;
214      case morpheo::behavioural::CLOCK_VHDL_YES              : return "Clock is in VHDL's model                     " ; break;
215      case morpheo::behavioural::CLOCK_VHDL_NO               : return "Clock is not in VHDL's model                 " ; break;
216      case morpheo::behavioural::RESET_VHDL_YES              : return "Reset is in VHDL's model                     " ; break;
217      case morpheo::behavioural::RESET_VHDL_NO               : return "Reset is not in VHDL's model                 " ; break;
218      default                                                : return "";                                               break;
219      }
220  }
221
222}; // end namespace morpheo             
223
224#endif
Note: See TracBrowser for help on using the repository browser.