Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos_forked_resit
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s2-alsaloumi
Pintos_forked_resit
Commits
8c542409
Commit
8c542409
authored
1 year ago
by
h2-addad
Browse files
Options
Downloads
Patches
Plain Diff
Update
parent
6b221e35
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/devices/speaker.c
+68
-0
68 additions, 0 deletions
src/devices/speaker.c
with
68 additions
and
0 deletions
src/devices/speaker.c
0 → 100644
+
68
−
0
View file @
8c542409
#include
"devices/speaker.h"
#include
"devices/pit.h"
#include
"threads/io.h"
#include
"threads/interrupt.h"
#include
"devices/timer.h"
/* Speaker port enable I/O register. */
#define SPEAKER_PORT_GATE 0x61
/* Speaker port enable bits. */
#define SPEAKER_GATE_ENABLE 0x03
/* Sets the PC speaker to emit a tone at the given FREQUENCY, in
Hz. */
void
speaker_on
(
int
frequency
)
{
if
(
frequency
>=
20
&&
frequency
<=
20000
)
{
/* Set the timer channel that's connected to the speaker to
output a square wave at the given FREQUENCY, then
connect the timer channel output to the speaker. */
enum
intr_level
old_level
=
intr_disable
();
pit_configure_channel
(
2
,
3
,
frequency
);
outb
(
SPEAKER_PORT_GATE
,
inb
(
SPEAKER_PORT_GATE
)
|
SPEAKER_GATE_ENABLE
);
intr_set_level
(
old_level
);
}
else
{
/* FREQUENCY is outside the range of normal human hearing.
Just turn off the speaker. */
speaker_off
();
}
}
/* Turn off the PC speaker, by disconnecting the timer channel's
output from the speaker. */
void
speaker_off
(
void
)
{
enum
intr_level
old_level
=
intr_disable
();
outb
(
SPEAKER_PORT_GATE
,
inb
(
SPEAKER_PORT_GATE
)
&
~
SPEAKER_GATE_ENABLE
);
intr_set_level
(
old_level
);
}
/* Briefly beep the PC speaker. */
void
speaker_beep
(
void
)
{
/* Only attempt to beep the speaker if interrupts are enabled,
because we don't want to freeze the machine during the beep.
We could add a hook to the timer interrupt to avoid that
problem, but then we'd risk failing to ever stop the beep if
Pintos crashes for some unrelated reason. There's nothing
more annoying than a machine whose beeping you can't stop
without a power cycle.
We can't just enable interrupts while we sleep. For one
thing, we get called (indirectly) from printf, which should
always work, even during boot before we're ready to enable
interrupts. */
if
(
intr_get_level
()
==
INTR_ON
)
{
speaker_on
(
440
);
timer_msleep
(
250
);
speaker_off
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment