112841Sgabeblack@google.com/*
212841Sgabeblack@google.com * Copyright 2018 Google, Inc.
312841Sgabeblack@google.com *
412841Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512841Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612841Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812841Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012841Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112841Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212841Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312841Sgabeblack@google.com * this software without specific prior written permission.
1412841Sgabeblack@google.com *
1512841Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612841Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712841Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812841Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912841Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012841Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112841Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212841Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312841Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412841Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512841Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612841Sgabeblack@google.com *
2712841Sgabeblack@google.com * Authors: Gabe Black
2812841Sgabeblack@google.com */
2912841Sgabeblack@google.com
3012841Sgabeblack@google.com#ifndef __SYSTEMC_EXT_CHANNEL_SC_IN_HH__
3112841Sgabeblack@google.com#define __SYSTEMC_EXT_CHANNEL_SC_IN_HH__
3212841Sgabeblack@google.com
3312841Sgabeblack@google.com#include <string>
3412841Sgabeblack@google.com
3513054Sgabeblack@google.com#include "../core/sc_event.hh"
3613269Sgabeblack@google.com#include "../core/sc_main.hh"
3712841Sgabeblack@google.com#include "../core/sc_port.hh"
3813245Sgabeblack@google.com#include "../utils/sc_trace_file.hh"
3912841Sgabeblack@google.com#include "sc_signal_in_if.hh"
4012841Sgabeblack@google.com#include "sc_signal_inout_if.hh"
4112841Sgabeblack@google.com
4212841Sgabeblack@google.comnamespace sc_core
4312841Sgabeblack@google.com{
4412841Sgabeblack@google.com
4512841Sgabeblack@google.comclass sc_event;
4612841Sgabeblack@google.comclass sc_trace_file;
4712841Sgabeblack@google.com
4812841Sgabeblack@google.comtemplate <class T>
4912841Sgabeblack@google.comclass sc_in : public sc_port<sc_signal_in_if<T>, 1>
5012841Sgabeblack@google.com{
5112841Sgabeblack@google.com  public:
5213054Sgabeblack@google.com    sc_in() : sc_port<sc_signal_in_if<T>, 1>(),
5313054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
5413054Sgabeblack@google.com    {}
5513054Sgabeblack@google.com    explicit sc_in(const char *name) : sc_port<sc_signal_in_if<T>, 1>(name),
5613054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
5713054Sgabeblack@google.com    {}
5812841Sgabeblack@google.com    virtual ~sc_in() {}
5912841Sgabeblack@google.com
6012868Sgabeblack@google.com    // Deprecated binding constructors.
6112868Sgabeblack@google.com    explicit sc_in(const sc_signal_in_if<T> &interface) :
6213054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>(interface),
6313054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
6412868Sgabeblack@google.com    {}
6512868Sgabeblack@google.com    sc_in(const char *name, const sc_signal_in_if<T> &interface) :
6613054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>(name, interface),
6713054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
6812868Sgabeblack@google.com    {}
6912868Sgabeblack@google.com    explicit sc_in(sc_port_b<sc_signal_in_if<T> > &parent) :
7013054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>(parent),
7113054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
7212868Sgabeblack@google.com    {}
7312868Sgabeblack@google.com    sc_in(const char *name, sc_port_b<sc_signal_in_if<T> > &parent) :
7413054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>(name, parent),
7513054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
7612868Sgabeblack@google.com    {}
7712868Sgabeblack@google.com    explicit sc_in(sc_port<sc_signal_in_if<T>, 1> &parent) :
7813054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>(parent),
7913054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
8012868Sgabeblack@google.com    {}
8112868Sgabeblack@google.com    sc_in(const char *name, sc_port<sc_signal_in_if<T>, 1> &parent) :
8213054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>(name, parent),
8313054Sgabeblack@google.com        _valueChangedFinder(*this, &sc_signal_in_if<T>::value_changed_event)
8412868Sgabeblack@google.com    {}
8512868Sgabeblack@google.com
8613498Snikos.nikoleris@arm.com    using sc_port<sc_signal_in_if<T>, 1>::bind;
8712841Sgabeblack@google.com    virtual void
8813054Sgabeblack@google.com    bind(const sc_signal_in_if<T> &i)
8912841Sgabeblack@google.com    {
9013054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>::bind(
9113054Sgabeblack@google.com                const_cast<sc_signal_in_if<T> &>(i));
9213054Sgabeblack@google.com    }
9313054Sgabeblack@google.com    void operator () (const sc_signal_in_if<T> &i) { bind(i); }
9413054Sgabeblack@google.com
9513054Sgabeblack@google.com    virtual void
9613054Sgabeblack@google.com    bind(sc_port<sc_signal_in_if<T>, 1> &i)
9713054Sgabeblack@google.com    {
9813054Sgabeblack@google.com        sc_port<sc_signal_in_if<T>, 1>::bind(i);
9912841Sgabeblack@google.com    }
10012841Sgabeblack@google.com    void
10113054Sgabeblack@google.com    operator () (sc_port<sc_signal_in_if<T>, 1> &p)
10212841Sgabeblack@google.com    {
10313054Sgabeblack@google.com        bind(p);
10412841Sgabeblack@google.com    }
10512841Sgabeblack@google.com
10612841Sgabeblack@google.com    virtual void
10713054Sgabeblack@google.com    bind(sc_port<sc_signal_inout_if<T>, 1> &p)
10812841Sgabeblack@google.com    {
10913054Sgabeblack@google.com        sc_port_base::bind(p);
11012841Sgabeblack@google.com    }
11112841Sgabeblack@google.com    void
11213054Sgabeblack@google.com    operator () (sc_port<sc_signal_inout_if<T>, 1> &p)
11312841Sgabeblack@google.com    {
11413054Sgabeblack@google.com        bind(p);
11512841Sgabeblack@google.com    }
11612841Sgabeblack@google.com
11713245Sgabeblack@google.com    virtual void
11813245Sgabeblack@google.com    end_of_elaboration()
11913245Sgabeblack@google.com    {
12013245Sgabeblack@google.com        for (auto params: traceParamsVec)
12113245Sgabeblack@google.com            sc_trace(params->tf, (*this)->read(), params->name);
12213245Sgabeblack@google.com
12313245Sgabeblack@google.com        traceParamsVec.clear();
12413245Sgabeblack@google.com    }
12512841Sgabeblack@google.com
12613054Sgabeblack@google.com    const T &read() const { return (*this)->read(); }
12713054Sgabeblack@google.com    operator const T& () const { return (*this)->read(); }
12812841Sgabeblack@google.com
12913054Sgabeblack@google.com    const sc_event &default_event() const { return (*this)->default_event(); }
13012841Sgabeblack@google.com    const sc_event &
13112841Sgabeblack@google.com    value_changed_event() const
13212841Sgabeblack@google.com    {
13313054Sgabeblack@google.com        return (*this)->value_changed_event();
13412841Sgabeblack@google.com    }
13513054Sgabeblack@google.com    bool event() const { return (*this)->event(); }
13613054Sgabeblack@google.com    sc_event_finder &value_changed() const { return _valueChangedFinder; }
13712841Sgabeblack@google.com
13812841Sgabeblack@google.com    virtual const char *kind() const { return "sc_in"; }
13912841Sgabeblack@google.com
14013245Sgabeblack@google.com    void
14113245Sgabeblack@google.com    add_trace(sc_trace_file *tf, const std::string &name) const
14213245Sgabeblack@google.com    {
14313245Sgabeblack@google.com        traceParamsVec.push_back(new sc_trace_params(tf, name));
14413245Sgabeblack@google.com    }
14513245Sgabeblack@google.com
14612841Sgabeblack@google.com  private:
14713054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<T> > _valueChangedFinder;
14813054Sgabeblack@google.com
14913245Sgabeblack@google.com    mutable sc_trace_params_vec traceParamsVec;
15013245Sgabeblack@google.com
15112841Sgabeblack@google.com    // Disabled
15213054Sgabeblack@google.com    sc_in(const sc_in<T> &);
15313054Sgabeblack@google.com    sc_in<T> &operator = (const sc_in<T> &);
15412841Sgabeblack@google.com};
15512841Sgabeblack@google.com
15612841Sgabeblack@google.comtemplate <class T>
15712841Sgabeblack@google.cominline void
15813245Sgabeblack@google.comsc_trace(sc_trace_file *tf, const sc_in<T> &i, const std::string &name)
15912841Sgabeblack@google.com{
16013269Sgabeblack@google.com    if (::sc_core::sc_get_status() < ::sc_core::SC_START_OF_SIMULATION)
16113269Sgabeblack@google.com        i.add_trace(tf, name);
16213269Sgabeblack@google.com    else
16313245Sgabeblack@google.com        sc_trace(tf, i->read(), name);
16412841Sgabeblack@google.com}
16512841Sgabeblack@google.com
16612841Sgabeblack@google.comtemplate <>
16712841Sgabeblack@google.comclass sc_in<bool> : public sc_port<sc_signal_in_if<bool>, 1>
16812841Sgabeblack@google.com{
16912841Sgabeblack@google.com  public:
17013054Sgabeblack@google.com    sc_in() : sc_port<sc_signal_in_if<bool>, 1>(),
17113054Sgabeblack@google.com        _valueChangedFinder(*this,
17213054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
17313054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
17413054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
17513054Sgabeblack@google.com    {}
17612841Sgabeblack@google.com    explicit sc_in(const char *name) :
17713054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(name),
17813054Sgabeblack@google.com        _valueChangedFinder(*this,
17913054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
18013054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
18113054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
18213054Sgabeblack@google.com    {}
18312841Sgabeblack@google.com    virtual ~sc_in() {}
18412841Sgabeblack@google.com
18512868Sgabeblack@google.com    // Deprecated binding constructors.
18612868Sgabeblack@google.com    explicit sc_in(const sc_signal_in_if<bool> &interface) :
18713054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(interface),
18813054Sgabeblack@google.com        _valueChangedFinder(*this,
18913054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
19013054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
19113054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
19212868Sgabeblack@google.com    {}
19312868Sgabeblack@google.com    sc_in(const char *name, const sc_signal_in_if<bool> &interface) :
19413054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(name, interface),
19513054Sgabeblack@google.com        _valueChangedFinder(*this,
19613054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
19713054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
19813054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
19912868Sgabeblack@google.com    {}
20012868Sgabeblack@google.com    explicit sc_in(sc_port_b<sc_signal_in_if<bool> > &parent) :
20113054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(parent),
20213054Sgabeblack@google.com        _valueChangedFinder(*this,
20313054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
20413054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
20513054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
20612868Sgabeblack@google.com    {}
20712868Sgabeblack@google.com    sc_in(const char *name, sc_port_b<sc_signal_in_if<bool> > &parent) :
20813054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(name, parent),
20913054Sgabeblack@google.com        _valueChangedFinder(*this,
21013054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
21113054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
21213054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
21312868Sgabeblack@google.com    {}
21412868Sgabeblack@google.com    explicit sc_in(sc_port<sc_signal_in_if<bool>, 1> &parent) :
21513054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(parent),
21613054Sgabeblack@google.com        _valueChangedFinder(*this,
21713054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
21813054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
21913054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
22012868Sgabeblack@google.com    {}
22112868Sgabeblack@google.com    sc_in(const char *name, sc_port<sc_signal_in_if<bool>, 1> &parent) :
22213054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>(name, parent),
22313054Sgabeblack@google.com        _valueChangedFinder(*this,
22413054Sgabeblack@google.com                &sc_signal_in_if<bool>::value_changed_event),
22513054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<bool>::posedge_event),
22613054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<bool>::negedge_event)
22712868Sgabeblack@google.com    {}
22812868Sgabeblack@google.com
22913383Sgabeblack@google.com    using sc_port<sc_signal_in_if<bool>, 1>::bind;
23013383Sgabeblack@google.com
23112841Sgabeblack@google.com    virtual void
23213054Sgabeblack@google.com    bind(const sc_signal_in_if<bool> &i)
23312841Sgabeblack@google.com    {
23413054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>::bind(
23513054Sgabeblack@google.com                const_cast<sc_signal_in_if<bool> &>(i));
23613054Sgabeblack@google.com    }
23713054Sgabeblack@google.com    void operator () (const sc_signal_in_if<bool> &i) { bind(i); }
23813054Sgabeblack@google.com
23913054Sgabeblack@google.com    virtual void
24013054Sgabeblack@google.com    bind(sc_port<sc_signal_in_if<bool>, 1> &p)
24113054Sgabeblack@google.com    {
24213054Sgabeblack@google.com        sc_port<sc_signal_in_if<bool>, 1>::bind(p);
24312841Sgabeblack@google.com    }
24412841Sgabeblack@google.com    void
24513054Sgabeblack@google.com    operator () (sc_port<sc_signal_in_if<bool>, 1> &p)
24612841Sgabeblack@google.com    {
24713054Sgabeblack@google.com        bind(p);
24812841Sgabeblack@google.com    }
24912841Sgabeblack@google.com
25012841Sgabeblack@google.com    virtual void
25113054Sgabeblack@google.com    bind(sc_port<sc_signal_inout_if<bool>, 1> &p)
25212841Sgabeblack@google.com    {
25313054Sgabeblack@google.com        sc_port_base::bind(p);
25412841Sgabeblack@google.com    }
25512841Sgabeblack@google.com    void
25613054Sgabeblack@google.com    operator () (sc_port<sc_signal_inout_if<bool>, 1> &p)
25712841Sgabeblack@google.com    {
25813054Sgabeblack@google.com        bind(p);
25912841Sgabeblack@google.com    }
26012841Sgabeblack@google.com
26113245Sgabeblack@google.com    virtual void
26213245Sgabeblack@google.com    end_of_elaboration()
26313245Sgabeblack@google.com    {
26413245Sgabeblack@google.com        for (auto params: traceParamsVec)
26513245Sgabeblack@google.com            sc_trace(params->tf, (*this)->read(), params->name);
26613245Sgabeblack@google.com
26713245Sgabeblack@google.com        traceParamsVec.clear();
26813245Sgabeblack@google.com    }
26912841Sgabeblack@google.com
27013054Sgabeblack@google.com    const bool &read() const { return (*this)->read(); }
27113054Sgabeblack@google.com    operator const bool& () const { return (*this)->read(); }
27212841Sgabeblack@google.com
27313054Sgabeblack@google.com    const sc_event &default_event() const { return (*this)->default_event(); }
27412841Sgabeblack@google.com    const sc_event &
27512841Sgabeblack@google.com    value_changed_event() const
27612841Sgabeblack@google.com    {
27713054Sgabeblack@google.com        return (*this)->value_changed_event();
27812841Sgabeblack@google.com    }
27912841Sgabeblack@google.com    const sc_event &
28012841Sgabeblack@google.com    posedge_event() const
28112841Sgabeblack@google.com    {
28213054Sgabeblack@google.com        return (*this)->posedge_event();
28312841Sgabeblack@google.com    }
28412841Sgabeblack@google.com    const sc_event &
28512841Sgabeblack@google.com    negedge_event() const
28612841Sgabeblack@google.com    {
28713054Sgabeblack@google.com        return (*this)->negedge_event();
28812841Sgabeblack@google.com    }
28912841Sgabeblack@google.com
29013054Sgabeblack@google.com    bool event() const { return (*this)->event(); }
29113054Sgabeblack@google.com    bool posedge() const { return (*this)->posedge(); }
29213054Sgabeblack@google.com    bool negedge() const { return (*this)->negedge(); }
29312841Sgabeblack@google.com
29413054Sgabeblack@google.com    sc_event_finder &value_changed() const { return _valueChangedFinder; }
29513054Sgabeblack@google.com    sc_event_finder &pos() const { return _posFinder; }
29613054Sgabeblack@google.com    sc_event_finder &neg() const { return _negFinder; }
29712841Sgabeblack@google.com
29812841Sgabeblack@google.com    virtual const char *kind() const { return "sc_in"; }
29912841Sgabeblack@google.com
30013245Sgabeblack@google.com    void
30113245Sgabeblack@google.com    add_trace(sc_trace_file *tf, const std::string &name) const
30213245Sgabeblack@google.com    {
30313245Sgabeblack@google.com        traceParamsVec.push_back(new sc_trace_params(tf, name));
30413245Sgabeblack@google.com    }
30513245Sgabeblack@google.com
30612841Sgabeblack@google.com  private:
30713054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<bool> > _valueChangedFinder;
30813054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<bool> > _posFinder;
30913054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<bool> > _negFinder;
31013054Sgabeblack@google.com
31113245Sgabeblack@google.com    mutable sc_trace_params_vec traceParamsVec;
31213245Sgabeblack@google.com
31312841Sgabeblack@google.com    // Disabled
31413054Sgabeblack@google.com    sc_in(const sc_in<bool> &);
31513054Sgabeblack@google.com    sc_in<bool> &operator = (const sc_in<bool> &);
31612841Sgabeblack@google.com};
31712841Sgabeblack@google.com
31812841Sgabeblack@google.comtemplate <>
31912841Sgabeblack@google.cominline void
32013245Sgabeblack@google.comsc_trace<bool>(sc_trace_file *tf, const sc_in<bool> &i,
32113245Sgabeblack@google.com        const std::string &name)
32212841Sgabeblack@google.com{
32313269Sgabeblack@google.com    if (::sc_core::sc_get_status() < ::sc_core::SC_START_OF_SIMULATION)
32413269Sgabeblack@google.com        i.add_trace(tf, name);
32513269Sgabeblack@google.com    else
32613245Sgabeblack@google.com        sc_trace(tf, i->read(), name);
32712841Sgabeblack@google.com}
32812841Sgabeblack@google.com
32912841Sgabeblack@google.comtemplate <>
33012841Sgabeblack@google.comclass sc_in<sc_dt::sc_logic> :
33112841Sgabeblack@google.com    public sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>
33212841Sgabeblack@google.com{
33312841Sgabeblack@google.com  public:
33413054Sgabeblack@google.com    sc_in() : sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(),
33513054Sgabeblack@google.com        _valueChangedFinder(*this,
33613054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
33713054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
33813054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
33913054Sgabeblack@google.com    {}
34012841Sgabeblack@google.com    explicit sc_in(const char *name) :
34113054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(name),
34213054Sgabeblack@google.com        _valueChangedFinder(*this,
34313054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
34413054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
34513054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
34612841Sgabeblack@google.com    {}
34712841Sgabeblack@google.com    virtual ~sc_in() {}
34812841Sgabeblack@google.com
34912868Sgabeblack@google.com    // Deprecated binding constructors.
35012868Sgabeblack@google.com    explicit sc_in(const sc_signal_in_if<sc_dt::sc_logic> &interface) :
35113054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(interface),
35213054Sgabeblack@google.com        _valueChangedFinder(*this,
35313054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
35413054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
35513054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
35612868Sgabeblack@google.com    {}
35712868Sgabeblack@google.com    sc_in(const char *name,
35812868Sgabeblack@google.com            const sc_signal_in_if<sc_dt::sc_logic> &interface) :
35913054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(name, interface),
36013054Sgabeblack@google.com        _valueChangedFinder(*this,
36113054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
36213054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
36313054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
36412868Sgabeblack@google.com    {}
36512868Sgabeblack@google.com    explicit sc_in(sc_port_b<sc_signal_in_if<sc_dt::sc_logic> > &parent) :
36613054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(parent),
36713054Sgabeblack@google.com        _valueChangedFinder(*this,
36813054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
36913054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
37013054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
37112868Sgabeblack@google.com    {}
37212868Sgabeblack@google.com    sc_in(const char *name,
37312868Sgabeblack@google.com            sc_port_b<sc_signal_in_if<sc_dt::sc_logic> > &parent) :
37413054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(name, parent),
37513054Sgabeblack@google.com        _valueChangedFinder(*this,
37613054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
37713054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
37813054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
37912868Sgabeblack@google.com    {}
38012868Sgabeblack@google.com    explicit sc_in(sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &parent) :
38113054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(parent),
38213054Sgabeblack@google.com        _valueChangedFinder(*this,
38313054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
38413054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
38513054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
38612868Sgabeblack@google.com    {}
38712868Sgabeblack@google.com    sc_in(const char *name,
38812868Sgabeblack@google.com            sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &parent) :
38913054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>(name, parent),
39013054Sgabeblack@google.com        _valueChangedFinder(*this,
39113054Sgabeblack@google.com                &sc_signal_in_if<sc_dt::sc_logic>::value_changed_event),
39213054Sgabeblack@google.com        _posFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::posedge_event),
39313054Sgabeblack@google.com        _negFinder(*this, &sc_signal_in_if<sc_dt::sc_logic>::negedge_event)
39412868Sgabeblack@google.com    {}
39512868Sgabeblack@google.com
39613383Sgabeblack@google.com    using sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>::bind;
39713383Sgabeblack@google.com
39812841Sgabeblack@google.com    virtual void
39913054Sgabeblack@google.com    bind(const sc_signal_in_if<sc_dt::sc_logic> &i)
40012841Sgabeblack@google.com    {
40113054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>::bind(
40213054Sgabeblack@google.com                const_cast<sc_signal_in_if<sc_dt::sc_logic> &>(i));
40312841Sgabeblack@google.com    }
40412841Sgabeblack@google.com    void
40513054Sgabeblack@google.com    operator () (const sc_signal_in_if<sc_dt::sc_logic> &i) { bind(i); }
40613054Sgabeblack@google.com
40713054Sgabeblack@google.com    virtual void
40813054Sgabeblack@google.com    bind(sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &i)
40912841Sgabeblack@google.com    {
41013054Sgabeblack@google.com        sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1>::bind(i);
41113054Sgabeblack@google.com    }
41213054Sgabeblack@google.com    void
41313054Sgabeblack@google.com    operator () (sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &p)
41413054Sgabeblack@google.com    {
41513054Sgabeblack@google.com        bind(p);
41612841Sgabeblack@google.com    }
41712841Sgabeblack@google.com
41812841Sgabeblack@google.com    virtual void
41913054Sgabeblack@google.com    bind(sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &p)
42012841Sgabeblack@google.com    {
42113054Sgabeblack@google.com        sc_port_base::bind(p);
42212841Sgabeblack@google.com    }
42312841Sgabeblack@google.com    void
42413054Sgabeblack@google.com    operator () (sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &p)
42512841Sgabeblack@google.com    {
42613054Sgabeblack@google.com        bind(p);
42712841Sgabeblack@google.com    }
42812841Sgabeblack@google.com
42913245Sgabeblack@google.com    virtual void
43013245Sgabeblack@google.com    end_of_elaboration()
43113245Sgabeblack@google.com    {
43213245Sgabeblack@google.com        for (auto params: traceParamsVec)
43313245Sgabeblack@google.com            sc_trace(params->tf, (*this)->read(), params->name);
43413245Sgabeblack@google.com
43513245Sgabeblack@google.com        traceParamsVec.clear();
43613245Sgabeblack@google.com    }
43712841Sgabeblack@google.com
43813054Sgabeblack@google.com    const sc_dt::sc_logic &read() const { return (*this)->read(); }
43913054Sgabeblack@google.com    operator const sc_dt::sc_logic& () const { return (*this)->read(); }
44012841Sgabeblack@google.com
44113054Sgabeblack@google.com    const sc_event &default_event() const { return (*this)->default_event(); }
44212841Sgabeblack@google.com    const sc_event &
44312841Sgabeblack@google.com    value_changed_event() const
44412841Sgabeblack@google.com    {
44513054Sgabeblack@google.com        return (*this)->value_changed_event();
44612841Sgabeblack@google.com    }
44713054Sgabeblack@google.com    const sc_event &posedge_event() const { return (*this)->posedge_event(); }
44813054Sgabeblack@google.com    const sc_event &negedge_event() const { return (*this)->negedge_event(); }
44912841Sgabeblack@google.com
45013054Sgabeblack@google.com    bool event() const { return (*this)->event(); }
45113054Sgabeblack@google.com    bool posedge() const { return (*this)->posedge(); }
45213054Sgabeblack@google.com    bool negedge() const { return (*this)->negedge(); }
45312841Sgabeblack@google.com
45413054Sgabeblack@google.com    sc_event_finder &value_changed() const { return _valueChangedFinder; }
45513054Sgabeblack@google.com    sc_event_finder &pos() const { return _posFinder; }
45613054Sgabeblack@google.com    sc_event_finder &neg() const { return _negFinder; }
45712841Sgabeblack@google.com
45812841Sgabeblack@google.com    virtual const char *kind() const { return "sc_in"; }
45912841Sgabeblack@google.com
46013245Sgabeblack@google.com    void
46113245Sgabeblack@google.com    add_trace(sc_trace_file *tf, const std::string &name) const
46213245Sgabeblack@google.com    {
46313245Sgabeblack@google.com        traceParamsVec.push_back(new sc_trace_params(tf, name));
46413245Sgabeblack@google.com    }
46513245Sgabeblack@google.com
46612841Sgabeblack@google.com  private:
46713054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<sc_dt::sc_logic> >
46813054Sgabeblack@google.com        _valueChangedFinder;
46913054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<sc_dt::sc_logic> > _posFinder;
47013054Sgabeblack@google.com    mutable sc_event_finder_t<sc_signal_in_if<sc_dt::sc_logic> > _negFinder;
47113054Sgabeblack@google.com
47213245Sgabeblack@google.com    mutable sc_trace_params_vec traceParamsVec;
47313245Sgabeblack@google.com
47412841Sgabeblack@google.com    // Disabled
47513054Sgabeblack@google.com    sc_in(const sc_in<sc_dt::sc_logic> &);
47613054Sgabeblack@google.com    sc_in<sc_dt::sc_logic> &operator = (const sc_in<sc_dt::sc_logic> &);
47712841Sgabeblack@google.com};
47812841Sgabeblack@google.com
47912841Sgabeblack@google.comtemplate <>
48012841Sgabeblack@google.cominline void
48113245Sgabeblack@google.comsc_trace<sc_dt::sc_logic>(sc_trace_file *tf, const sc_in<sc_dt::sc_logic> &i,
48213245Sgabeblack@google.com        const std::string &name)
48312841Sgabeblack@google.com{
48413269Sgabeblack@google.com    if (::sc_core::sc_get_status() < ::sc_core::SC_START_OF_SIMULATION)
48513269Sgabeblack@google.com        i.add_trace(tf, name);
48613269Sgabeblack@google.com    else
48713245Sgabeblack@google.com        sc_trace(tf, i->read(), name);
48812841Sgabeblack@google.com}
48912841Sgabeblack@google.com
49012841Sgabeblack@google.com} // namespace sc_core
49112841Sgabeblack@google.com
49212841Sgabeblack@google.com#endif  //__SYSTEMC_EXT_CHANNEL_SC_IN_HH__
493