gem5  v20.1.0.0
speaker.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "dev/x86/speaker.hh"
30 
31 #include "base/bitunion.hh"
32 #include "base/trace.hh"
33 #include "debug/PcSpeaker.hh"
34 #include "dev/x86/i8254.hh"
35 #include "mem/packet.hh"
36 #include "mem/packet_access.hh"
37 
38 Tick
40 {
41  assert(pkt->getAddr() == pioAddr);
42  assert(pkt->getSize() == 1);
43  controlVal.timer = timer->outputHigh(2) ? 1 : 0;
44  DPRINTF(PcSpeaker,
45  "Reading from speaker device: gate %s, speaker %s, output %s.\n",
46  controlVal.gate ? "on" : "off",
47  controlVal.speaker ? "on" : "off",
48  controlVal.timer ? "on" : "off");
49  pkt->setLE((uint8_t)controlVal);
50  pkt->makeAtomicResponse();
51  return latency;
52 }
53 
54 Tick
56 {
57  assert(pkt->getAddr() == pioAddr);
58  assert(pkt->getSize() == 1);
59  SpeakerControl val = pkt->getLE<uint8_t>();
60  controlVal.gate = val.gate;
61  //Change the gate value in the timer.
62  if (!val.gate)
63  warn("The gate bit of the pc speaker isn't implemented and "
64  "is always on.\n");
65  //This would control whether the timer output is hooked up to a physical
66  //speaker. Since M5 can't make noise, it's value doesn't actually do
67  //anything.
68  controlVal.speaker = val.speaker;
69  DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n",
70  controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off");
71  pkt->makeAtomicResponse();
72  return latency;
73 }
74 
75 void
77 {
78  SERIALIZE_SCALAR(controlVal);
79 }
80 
81 void
83 {
84  UNSERIALIZE_SCALAR(controlVal);
85 }
86 
88 PcSpeakerParams::create()
89 {
90  return new X86ISA::Speaker(this);
91 }
Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1016
BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
warn
#define warn(...)
Definition: logging.hh:239
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
X86ISA::Speaker::latency
Tick latency
Definition: speaker.hh:44
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
speaker.hh
packet.hh
cp
Definition: cprintf.cc:40
X86ISA::Speaker::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: speaker.cc:39
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
bitunion.hh
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
packet_access.hh
Packet::getLE
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Definition: packet_access.hh:75
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
X86ISA::Speaker::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: speaker.cc:82
X86ISA::Speaker::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: speaker.cc:76
Packet::setLE
void setLE(T v)
Set the value in the data pointer to v as little endian.
Definition: packet_access.hh:105
X86ISA::Speaker
Definition: speaker.hh:41
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
X86ISA::Speaker::timer
Bitfield< 5 > timer
Definition: speaker.hh:49
trace.hh
CheckpointIn
Definition: serialize.hh:67
X86ISA::Speaker::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: speaker.cc:55
i8254.hh

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