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

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

Update all component (except front_end) to :

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