2 * Copyright 2019 Google, Inc.
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.
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.
28 #ifndef __DEV_INTPIN_HH__
29 #define __DEV_INTPIN_HH__
31 #include "sim/port.hh"
33 class IntSourcePinBase;
35 class IntSinkPinBase : public Port
38 friend IntSourcePinBase;
40 IntSourcePinBase *source = nullptr;
45 IntSinkPinBase(const std::string &_name, PortID _id, int num) :
46 Port(_name, _id), _number(num)
49 virtual void raiseOnDevice() = 0;
50 virtual void lowerOnDevice() = 0;
67 int number() { return _number; }
68 bool state() { return _state; }
70 void bind(Port &peer) override;
71 void unbind() override;
74 template <class Device>
75 class IntSinkPin : public IntSinkPinBase
78 Device *device = nullptr;
80 void raiseOnDevice() override { device->raiseInterruptPin(number()); }
81 void lowerOnDevice() override { device->lowerInterruptPin(number()); }
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) {}
90 class IntSourcePinBase : public Port
93 IntSinkPinBase *sink = nullptr;
97 IntSourcePinBase(const std::string &_name, PortID _id, bool def_state) :
98 Port(_name, _id), _state(def_state)
101 void raise() { sink->raise(); }
102 void lower() { sink->lower(); }
104 void bind(Port &peer) override;
105 void unbind() override;
108 template <class Device>
109 class IntSourcePin : public IntSourcePinBase
112 IntSourcePin(const std::string &_name, PortID _id, Device *owner,
113 bool def_state=false) :
114 IntSourcePinBase(_name, _id, def_state)
118 #endif //__DEV_INTPIN_HH__