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  sc_buffer_edge_reset.cpp -- Test sc_buffer<bool> edge events and reset
23
24  Original Author: Philipp A. Hartmann, OFFIS, 2013-10-12
25
26 -----------------------------------------------------------------------------
27
28 This test checks the functionality of the pos(), neg() event finders and
29 the async_reset_signal_is functionality, if the target port is bound to
30 an sc_buffer instead of an sc_signal.
31
32 *****************************************************************************/
33
34#define SC_INCLUDE_DYNAMIC_PROCESSES
35#include <systemc.h>
36#include <iomanip>
37
38SC_MODULE(print_edge)
39{
40  sc_in<bool> in;
41
42  SC_CTOR(print_edge)
43    : in("in")
44  {
45    spawn_trigger( "trigger_val", &in.value_changed() );
46    spawn_trigger( "trigger_pos", &in.pos() );
47    spawn_trigger( "trigger_neg", &in.neg() );
48    spawn_trigger( "trigger_rst", NULL );
49  }
50
51  void spawn_trigger( const char* name, sc_event_finder* ef )
52  {
53    sc_spawn_options opts;
54      opts.spawn_method();
55      opts.dont_initialize();
56    if( ef ) {
57      opts.set_sensitivity( ef );
58    } else {
59      opts.async_reset_signal_is( in, true );
60    }
61    sc_spawn( sc_bind(&print_edge::trigger,this)
62            , name, &opts);
63  }
64
65  void trigger()
66  {
67    std::cout << sc_get_current_process_handle().name()
68              << " @ " << std::setw(4) << sc_time_stamp()
69              << ": " << "in = " << in.read()
70              << std::endl;
71  }
72};
73
74int sc_main(int, char*[])
75{
76  sc_report_handler::set_actions( "disable() or dont_initialize() "
77            "called on process with no static sensitivity, it will be "
78            "orphaned", SC_DO_NOTHING );
79
80  sc_signal<int>  sig_int;
81
82  sc_buffer<bool> buf;
83  sc_signal<bool> sig;
84
85  print_edge sig_mod("sig_mod");
86    sig_mod.in(sig);
87
88  print_edge buf_mod("buf_mod");
89    buf_mod.in(buf);
90
91  for(int i=0; i<4; ++i) {
92    buf.write( !buf.read() );
93    sig.write( !sig.read() );
94    sc_start( 1, SC_NS );
95
96    buf.write( buf.read() );
97    sig.write( sig.read() );
98    sc_start( 1, SC_NS );
99  }
100
101  return 0;
102}
103