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

Last change on this file since 43 was 42, checked in by rosiere, 17 years ago

Modification des classes d'encapsulation des interfaces :

  • gère les signaux à écrire dans le vhdl
  • les traces pour le testbench
  • la génération des vhdl structurelles

-> test sur la Pattern History Table

File size: 7.1 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 "Include/ErrorMorpheo.h"
25#include "Include/ToBase2.h"
26#include "Include/ToString.h"
27#include "Include/Debug.h"
28
29using namespace std;
30
31namespace morpheo              {
32namespace behavioural          {
33
34  typedef enum {UNKNOW                     ,
35                BOOL                       ,
36                UINT8_T                    ,
37                UINT16_T                   ,
38                UINT32_T                   ,
39                UINT64_T                   } type_info_t;
40
41  typedef enum {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 string          _name         ;
56  private   : const direction_t     _direction    ;
57  private   : const uint32_t        _size         ;
58  private   : const presence_port_t _presence_port;
59
60  private   : Signal *              _signal       ;
61  private   : bool                  _is_allocate  ;
62  private   : void *                _sc_signal    ;
63  private   : bool                  _is_map       ;
64  private   : void *                _sc_signal_map;
65  private   : type_info_t           _type_info    ;
66
67#ifdef VHDL_TESTBENCH
68  private   : list<string>        * _list_value   ;
69#endif
70
71    // -----[ methods ]---------------------------------------------------
72  public    :                   Signal          (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    : string            get_name        (void);
80  public    : uint32_t          get_size        (void);
81  public    : Signal *          get_signal_link (void);
82
83  public    : bool              presence_vhdl      (void);
84  public    : bool              presence_testbench (void);
85
86  public    : void              mapping         (Signal * signal);
87  public    : void              link            (Signal * signal);
88
89#ifdef SYSTEMC         
90  public    :template <typename T>
91             T                  read (void)
92    {
93      switch (_direction)
94        {
95        case IN  : {return read_in  <T>();}
96        case OUT : {return read_out <T>();}
97        default  : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow."));
98        }
99    }
100
101  public    :template <typename T>
102             T                  read_in (void)
103    {
104      switch (_type_info)
105        {
106        case BOOL     : return (static_cast<sc_in  <bool    > *>(_sc_signal_map)->read()); 
107        case UINT8_T  : return (static_cast<sc_in  <uint8_t > *>(_sc_signal_map)->read()); 
108        case UINT16_T : return (static_cast<sc_in  <uint16_t> *>(_sc_signal_map)->read());
109        case UINT32_T : return (static_cast<sc_in  <uint32_t> *>(_sc_signal_map)->read()); 
110        case UINT64_T : return (static_cast<sc_in  <uint64_t> *>(_sc_signal_map)->read()); 
111        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
112        }
113    }
114
115  public    :template <typename T>
116             T                  read_out(void)
117    {
118      switch (_type_info)
119        {
120        case BOOL     : return (static_cast<sc_out <bool    > *>(_sc_signal_map)->read()); 
121        case UINT8_T  : return (static_cast<sc_out <uint8_t > *>(_sc_signal_map)->read()); 
122        case UINT16_T : return (static_cast<sc_out <uint16_t> *>(_sc_signal_map)->read());
123        case UINT32_T : return (static_cast<sc_out <uint32_t> *>(_sc_signal_map)->read()); 
124        case UINT64_T : return (static_cast<sc_out <uint64_t> *>(_sc_signal_map)->read()); 
125        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
126        }
127    }
128
129  public    : template <typename T>
130              void              alloc           (void * port)
131    {
132      if (_type_info != UNKNOW)
133        throw (ErrorMorpheo ("Signal \""+_name+"\" : already allocate."));
134
135      _is_allocate = true;
136      _sc_signal      = port;
137      _sc_signal_map  = port;
138
139      if (typeid(T) == typeid(bool    ))
140        _type_info = BOOL;
141      else
142      if (typeid(T) == typeid(uint8_t ))
143        _type_info = UINT8_T;
144      else
145      if (typeid(T) == typeid(uint16_t))
146        _type_info = UINT16_T;
147      else
148      if (typeid(T) == typeid(uint32_t))
149        _type_info = UINT32_T;
150      else
151      if (typeid(T) == typeid(uint64_t))
152        _type_info = UINT64_T;
153      else
154        _type_info = UNKNOW;
155    }
156#endif
157
158#ifdef VHDL
159  public    : void              set_port        (Vhdl * & vhdl);
160#  ifdef VHDL_TESTBENCH
161  public    : Signal *          get_clock       (void);
162  public    : Signal *          get_reset       (void);
163  public    : uint32_t          get_reset_cycle (bool active_low);
164
165  public    : void              set_signal      (Vhdl * & vhdl);
166  public    : void              get_name_vhdl   (list<string> * & list_signal);
167
168  public    : void              testbench        (void);
169  public    : void              testbench_body   (Vhdl           * & vhdl          ,
170                                                  string             counter_name  ,
171                                                  string             reset_name    );
172  public    : void              testbench_test_ok(Vhdl           * & vhdl          );
173#  endif
174#endif
175  public    : XML               toXML           (void);
176
177  public    : friend ostream&   operator<<      (ostream& output_stream,
178                                                 morpheo::behavioural::Signal & x);
179
180  };
181}; // end namespace behavioural         
182
183  template<>           inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x)
184  {
185    switch (x)
186      {
187      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_YES : return "Port  is in VHDL's model and TestBench's model" ; break;
188      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_NO  : return "Port  is in VHDL's model                      " ; break;
189      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_YES  : return "Port  is in                  TestBench's model" ; break;
190      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_NO   : return "Port  is in none model                        " ; break;
191      case morpheo::behavioural::CLOCK_VHDL_YES              : return "Clock is in VHDL's model                     " ; break;
192      case morpheo::behavioural::CLOCK_VHDL_NO               : return "Clock is not in VHDL's model                 " ; break;
193      case morpheo::behavioural::RESET_VHDL_YES              : return "Reset is in VHDL's model                     " ; break;
194      case morpheo::behavioural::RESET_VHDL_NO               : return "Reset is not in VHDL's model                 " ; break;
195      default                                                : return "";                                               break;
196      }
197  }
198
199}; // end namespace morpheo             
200
201#endif
Note: See TracBrowser for help on using the repository browser.