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

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

Vhdl_Testbench : Modification du testbench. Maintenant complétement encapsuler dans la classe "Interfaces".
Suppression de la class Vhdl_Testbench dans un avenir proche :D
Suppression du répertoire Configuration.old

File size: 5.6 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              } presence_port_t;
47
48  class Signal
49  {
50    friend class Interface;
51
52    // -----[ fields ]----------------------------------------------------
53  private   : const string          _name         ;
54  private   : const direction_t     _direction    ;
55  private   : const uint32_t        _size         ;
56  private   : const presence_port_t _presence_port;
57
58#ifdef VHDL_TESTBENCH
59  private   : void *                _signal       ;
60  private   : type_info_t           _type_info    ;
61
62  private   : list<string>        * _list_value   ;
63#endif
64
65    // -----[ methods ]---------------------------------------------------
66  public    :                   Signal          (string          name          ,
67                                                 direction_t     direction     ,
68                                                 uint32_t        size          ,
69                                                 presence_port_t presence_port = PORT_VHDL_YES_TESTBENCH_YES);
70  public    :                   Signal          (const Signal &);
71  public    :                   ~Signal         ();
72
73#ifdef VHDL_TESTBENCH
74  public    :template <typename T>
75             T                  read (void)
76    {
77      switch (_direction)
78        {
79        case IN  : {return read_in  <T>();}
80        case OUT : {return read_out <T>();}
81        default  : throw (ErrorMorpheo ("Signal \""+_name+"\" : direction unknow."));
82        }
83    }
84
85  public    :template <typename T>
86             T                  read_in (void)
87    {
88      switch (_type_info)
89        {
90        case BOOL     : return (static_cast<sc_in  <bool    > *>(_signal)->read()); 
91        case UINT8_T  : return (static_cast<sc_in  <uint8_t > *>(_signal)->read()); 
92        case UINT16_T : return (static_cast<sc_in  <uint16_t> *>(_signal)->read());
93        case UINT32_T : return (static_cast<sc_in  <uint32_t> *>(_signal)->read()); 
94        case UINT64_T : return (static_cast<sc_in  <uint64_t> *>(_signal)->read()); 
95        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
96        }
97    }
98
99  public    :template <typename T>
100             T                  read_out(void)
101    {
102      switch (_type_info)
103        {
104        case BOOL     : return (static_cast<sc_out <bool    > *>(_signal)->read()); 
105        case UINT8_T  : return (static_cast<sc_out <uint8_t > *>(_signal)->read()); 
106        case UINT16_T : return (static_cast<sc_out <uint16_t> *>(_signal)->read());
107        case UINT32_T : return (static_cast<sc_out <uint32_t> *>(_signal)->read()); 
108        case UINT64_T : return (static_cast<sc_out <uint64_t> *>(_signal)->read()); 
109        default       : throw (ErrorMorpheo ("Signal \""+_name+"\" : type unknow."));
110        }
111    }
112
113  public    : template <typename T>
114              void              alloc           (void * port)
115    {
116      if (_type_info != UNKNOW)
117        throw (ErrorMorpheo ("Signal \""+_name+"\" : already allocate."));
118
119      _signal    = port;
120
121      if (typeid(T) == typeid(bool    ))
122        _type_info = BOOL;
123      else
124      if (typeid(T) == typeid(uint8_t ))
125        _type_info = UINT8_T;
126      else
127      if (typeid(T) == typeid(uint16_t))
128        _type_info = UINT16_T;
129      else
130      if (typeid(T) == typeid(uint32_t))
131        _type_info = UINT32_T;
132      else
133      if (typeid(T) == typeid(uint64_t))
134        _type_info = UINT64_T;
135      else
136        _type_info = UNKNOW;
137    }
138
139  public    : void              testbench        (void);
140  public    : void              testbench_body   (Vhdl           * & vhdl          ,
141                                                  string             counter_name  );
142  public    : void              testbench_test_ok(Vhdl           * & vhdl          );
143#endif
144#ifdef VHDL
145  public    : void              set_port        (Vhdl * & vhdl);
146#  ifdef VHDL_TESTBENCH
147  public    : string            get_clock       (void);
148  public    : void              set_signal      (Vhdl * & vhdl);
149  public    : void              get_name_vhdl   (list<string> * & list_signal);
150#  endif
151#endif
152  public    : XML               toXML           (void);
153
154  public    : friend ostream&   operator<<      (ostream& output_stream,
155                                                 morpheo::behavioural::Signal & x);
156
157  };
158}; // end namespace behavioural         
159
160  template<>           inline std::string toString<morpheo::behavioural::presence_port_t>(const morpheo::behavioural::presence_port_t& x)
161  {
162    switch (x)
163      {
164      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_YES : return "Port is in VHDL's model and TestBench's model" ; break;
165      case morpheo::behavioural::PORT_VHDL_YES_TESTBENCH_NO  : return "Port is in VHDL's model                      " ; break;
166      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_YES  : return "Port is in                  TestBench's model" ; break;
167      case morpheo::behavioural::PORT_VHDL_NO_TESTBENCH_NO   : return "Port is in none model                        " ; break;
168      default                                                : return "";                                               break;
169      }
170  }
171
172}; // end namespace morpheo             
173
174#endif
Note: See TracBrowser for help on using the repository browser.