File: main.cpp

package info (click to toggle)
systemc 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,768 kB
  • sloc: cpp: 181,958; sh: 4,925; asm: 2,700; perl: 1,980; ansic: 1,931; makefile: 1,761; fortran: 492; python: 482; awk: 157; csh: 50
file content (156 lines) | stat: -rw-r--r-- 4,539 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*****************************************************************************

  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
  more contributor license agreements.  See the NOTICE file distributed
  with this work for additional information regarding copyright ownership.
  Accellera licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  implied.  See the License for the specific language governing
  permissions and limitations under the License.

 *****************************************************************************/

/*****************************************************************************

  main.cpp -- This example shows the use of the sc_export class.

  Original Author: 

 *****************************************************************************/

/*****************************************************************************

  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
  changes you are making here.

      Name, Affiliation, Date:
  Description of Modification:

 *****************************************************************************/

/*
In this example, module D contains a channel of type C which
implements an interface C_if. D makes the interface C visible to the
outside by an interface-port named "IFP". Module E contains an
instance of D and also contains another instance of C. E exports both
interfaces as interface-ports IFP1 and IFP2. Both IFP1 and IFP2 are
bound to ports P1 and P2 of module X.

              +-------------+             +------------------+
              |     X       |             |    E    +----+   |
              |             |P1       IFP1|         | C  |   |
              |            [ ]------------O---------@    |   |
              |             |             |         |    |   |
              |             |             |         +----+   |
              |             |             |                  |
              |             |             |     +----------+ |
              |             |             |     | D        | |
              |             |             |     |   +----+ | |
              |             |P2       IFP2|  IFP|   | C  | | |
              |            [ ]------------O-----O---@    | | |
              |             |             |     |   |    | | |
              |             |             |     |   +----+ | |
              |             |             |     |          | |
              |             |             |     +----------+ |
              +-------------+             +------------------+

 Legend:
   [ ]   port
    O    interface-port
    @    interface

*/

#include "systemc.h"

// Interface
class C_if : virtual public sc_interface
{ 
public:
    virtual void run() = 0;
};

// Channel
class C : public C_if, public sc_channel
{ 
public:
    SC_CTOR(C) { }
    virtual void run() 
    { 
        cout << sc_time_stamp() << " In Channel run() " << endl; 
    }
};

// --- D: export channel C through IFP --------
SC_MODULE( D )
{
    sc_export<C_if> IFP;

    SC_CTOR( D ) 
	: IFP("IFP"),   // explicit name
	  m_C("C")
    {                
	IFP( m_C );     // bind sc_export->interface by name
    }
 private:
    C m_C;            // channel
};

// --- E: module with two interface-ports ---
SC_MODULE( E )
{
 private:
    C m_C;
    D m_D;

 public:
    sc_export<C_if> IFP1;
    sc_export<C_if> IFP2;
				 
    SC_CTOR( E ) 		 
	: m_C("C"),
	  m_D("D"),
	  IFP1("IFP1") 		
    {				 
        IFP1( m_C );
	IFP2( m_D.IFP );          // bind sc_export->sc_export by name
        IFP1.get_interface();     // just to see whether it compiles
    }
};

// Module X connected to the channels through E
SC_MODULE( X )
{
    sc_port<C_if> P1;
    sc_port<C_if> P2;
    SC_CTOR(X) {
        SC_THREAD(run);
    }
    void run() {
        wait(10, SC_NS);
	P1->run();
	wait(10, SC_NS);
	P2->run();
    }
};

int sc_main(int , char** ) {
  E the_E("E");
  X the_X("X");
  // port->IFP
  the_X.P1( the_E.IFP1 );
  the_X.P2( the_E.IFP2 );

  sc_start(17, SC_NS);
  the_E.IFP1->run();  // testing the operator-> of sc_export
  sc_start(50, SC_NS);

  return 0;
}