new_prop1.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  new_prop1.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#include "systemc.h"
39
40static int (*print_func)(const char*, ...);
41
42struct new_prop : sc_module {
43    sc_in<bool> i[16];
44
45    void my_print(const char*);
46
47    void async0() { my_print("async0"); }
48    void async1() { my_print("async1"); }
49    void async2() { my_print("async2"); }
50    void async3() { my_print("async3"); }
51
52    void aproc0() { wait(); while (1) { my_print("aproc0"); wait(); } }
53    void aproc1() { wait(); while (1) { my_print("aproc1"); wait(); } }
54    void aproc2() { wait(); while (1) { my_print("aproc2"); wait(); } }
55    void aproc3() { wait(); while (1) { my_print("aproc3"); wait(); } }
56
57    SC_CTOR(new_prop) {
58        SC_METHOD(async0);
59        sensitive << i[4].neg();
60        sensitive << i[12].neg();
61        sensitive << i[13].neg();
62        sensitive << i[14].neg();
63        sensitive << i[15].neg();
64
65        SC_METHOD(async1);
66        sensitive << i[1].pos();
67        sensitive << i[5].pos();
68        sensitive << i[7].pos();
69        sensitive << i[9].pos();
70
71        SC_METHOD(async2);
72        sensitive << i[5].neg();
73        sensitive << i[6].neg();
74        sensitive << i[13].pos();
75        sensitive << i[15].pos();
76
77        SC_METHOD(async3);
78        sensitive << i[3].pos();
79        sensitive << i[5].neg();
80        sensitive << i[7].neg();
81        sensitive << i[11].pos();
82
83        SC_THREAD(aproc0);
84        sensitive << i[2].pos();
85
86        SC_THREAD(aproc1);
87        sensitive << i[3].pos();
88        sensitive << i[12].neg();
89        sensitive << i[13].neg();
90        sensitive << i[14].neg();
91        sensitive << i[15].neg();
92
93        SC_THREAD(aproc2);
94        sensitive << i[8].neg();
95        sensitive << i[9].neg();
96        sensitive << i[10].neg();
97        sensitive << i[11].neg();
98
99        SC_THREAD(aproc3);
100        sensitive << i[6].pos();
101        sensitive << i[7].pos();
102        sensitive << i[10].pos();
103        sensitive << i[11].pos();
104        sensitive << i[14].pos();
105        sensitive << i[15].pos();
106    }
107};
108
109void
110new_prop::my_print(const char* p)
111{
112    (*print_func)("%s executed on:\n", p);
113    for (int j = 0; j < 16; ++j) {
114        if (i[j].posedge()) {
115            (*print_func)("\tposedge i[%d]\n", j);
116        }
117        if (i[j].negedge()) {
118            (*print_func)("\tnegedge i[%d]\n", j);
119        }
120    }
121}
122
123static int
124dont_print(const char* fmt, ...)
125{
126    return 0;
127}
128
129int
130sc_main(int,char**)
131{
132    sc_signal<bool> i[16];
133
134    new_prop np("np");
135
136    for( int j = 0; j < 16; ++ j ) {
137        np.i[j]( i[j] );
138    }
139
140    for (int j = 0; j < 16; ++j) {
141        i[j] = 0;
142    }
143
144    print_func = &dont_print;
145    sc_start(0, SC_NS);
146
147    print_func = &printf;
148
149    for (int k = 0; k < 16; ++k) {
150        i[k] = ! i[k].read();
151        sc_start(1, SC_NS);
152        i[k] = ! i[k].read();
153        sc_start(1, SC_NS);
154    }
155
156    fflush( stdout );
157
158    return 0;
159}
160