gem5  v20.1.0.0
intpin.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __DEV_INTPIN_HH__
29 #define __DEV_INTPIN_HH__
30 
31 #include "sim/port.hh"
32 
33 class IntSourcePinBase;
34 
35 class IntSinkPinBase : public Port
36 {
37  protected:
39 
41 
42  int _number = 0;
43  bool _state = false;
44 
45  IntSinkPinBase(const std::string &_name, PortID _id, int num) :
46  Port(_name, _id), _number(num)
47  {}
48 
49  virtual void raiseOnDevice() = 0;
50  virtual void lowerOnDevice() = 0;
51 
52  void
53  raise()
54  {
55  _state = true;
56  raiseOnDevice();
57  }
58 
59  void
61  {
62  _state = false;
63  lowerOnDevice();
64  }
65 
66  public:
67  int number() { return _number; }
68  bool state() { return _state; }
69 
70  void bind(Port &peer) override;
71  void unbind() override;
72 };
73 
74 template <class Device>
75 class IntSinkPin : public IntSinkPinBase
76 {
77  private:
78  Device *device = nullptr;
79 
80  void raiseOnDevice() override { device->raiseInterruptPin(number()); }
81  void lowerOnDevice() override { device->lowerInterruptPin(number()); }
82 
83  public:
84  IntSinkPin(const std::string &_name, PortID _id, Device *dev, int num) :
85  IntSinkPinBase(_name, _id, num), device(dev) {}
86  IntSinkPin(const std::string &_name, PortID _id, Device *dev) :
87  IntSinkPin(_name, _id, dev, _id) {}
88 };
89 
90 class IntSourcePinBase : public Port
91 {
92  private:
93  IntSinkPinBase *sink = nullptr;
94  bool _state = false;
95 
96  public:
97  IntSourcePinBase(const std::string &_name, PortID _id, bool def_state) :
98  Port(_name, _id), _state(def_state)
99  {}
100 
101  void raise() { sink->raise(); }
102  void lower() { sink->lower(); }
103 
104  void bind(Port &peer) override;
105  void unbind() override;
106 };
107 
108 template <class Device>
110 {
111  public:
112  IntSourcePin(const std::string &_name, PortID _id, Device *owner,
113  bool def_state=false) :
114  IntSourcePinBase(_name, _id, def_state)
115  {}
116 };
117 
118 #endif //__DEV_INTPIN_HH__
IntSinkPinBase::_number
int _number
Definition: intpin.hh:42
IntSinkPinBase::IntSourcePinBase
friend IntSourcePinBase
Definition: intpin.hh:38
IntSinkPin::IntSinkPin
IntSinkPin(const std::string &_name, PortID _id, Device *dev, int num)
Definition: intpin.hh:84
IntSourcePinBase::lower
void lower()
Definition: intpin.hh:102
IntSinkPinBase::unbind
void unbind() override
Dettach from a peer port.
Definition: intpin.cc:42
IntSourcePin
Definition: intpin.hh:109
IntSinkPinBase::_state
bool _state
Definition: intpin.hh:43
IntSinkPinBase
Definition: intpin.hh:35
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
IntSourcePinBase::unbind
void unbind() override
Dettach from a peer port.
Definition: intpin.cc:63
IntSinkPin::lowerOnDevice
void lowerOnDevice() override
Definition: intpin.hh:81
IntSinkPinBase::number
int number()
Definition: intpin.hh:67
IntSinkPinBase::IntSinkPinBase
IntSinkPinBase(const std::string &_name, PortID _id, int num)
Definition: intpin.hh:45
IntSinkPin::raiseOnDevice
void raiseOnDevice() override
Definition: intpin.hh:80
IntSourcePinBase::sink
IntSinkPinBase * sink
Definition: intpin.hh:93
IntSinkPinBase::lower
void lower()
Definition: intpin.hh:60
IntSinkPinBase::source
IntSourcePinBase * source
Definition: intpin.hh:40
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
IntSinkPinBase::lowerOnDevice
virtual void lowerOnDevice()=0
IntSinkPin
Definition: intpin.hh:75
IntSinkPinBase::raiseOnDevice
virtual void raiseOnDevice()=0
port.hh
IntSourcePinBase::IntSourcePinBase
IntSourcePinBase(const std::string &_name, PortID _id, bool def_state)
Definition: intpin.hh:97
IntSinkPin::device
Device * device
Definition: intpin.hh:78
IntSourcePinBase::bind
void bind(Port &peer) override
Attach to a peer port.
Definition: intpin.cc:49
IntSourcePinBase::_state
bool _state
Definition: intpin.hh:94
IntSinkPinBase::raise
void raise()
Definition: intpin.hh:53
IntSourcePinBase
Definition: intpin.hh:90
IntSourcePin::IntSourcePin
IntSourcePin(const std::string &_name, PortID _id, Device *owner, bool def_state=false)
Definition: intpin.hh:112
IntSinkPin::IntSinkPin
IntSinkPin(const std::string &_name, PortID _id, Device *dev)
Definition: intpin.hh:86
IntSinkPinBase::bind
void bind(Port &peer) override
Attach to a peer port.
Definition: intpin.cc:33
IntSinkPinBase::state
bool state()
Definition: intpin.hh:68

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17