Xyris
0.5
spkr.cpp
Go to the documentation of this file.
1
/**
2
* @file spkr.cpp
3
* @author Keeton Feavel (
[email protected]
)
4
* @brief
5
* @version 0.3
6
* @date 2019-11-25
7
*
8
* @copyright Copyright the Xyris Contributors (c) 2019
9
*
10
*/
11
12
#include <
Arch/Arch.hpp
>
13
#include <
Devices/PCSpeaker/spkr.hpp
>
14
#include <
Arch/i686/timer.hpp
>
// TODO: Remove ASAP
15
16
static
void
spkr_tone(uint32_t freq) {
17
uint32_t div;
18
uint8_t tmp;
19
// Set the PIT to the desired frequency
20
div = 1193180 / freq;
21
writeByte
(0x43, 0xb6);
22
writeByte
(0x42, (uint8_t)(div));
23
writeByte
(0x42, (uint8_t)(div >> 8));
24
// And play the sound using the PC speaker
25
tmp =
readByte
(0x61);
26
if
(tmp != (tmp | 3)) {
27
writeByte
(0x61, tmp | 3);
28
}
29
}
30
31
static
void
spkr_stop() {
32
uint8_t tmp =
readByte
(0x61) & 0xFC;
33
writeByte
(0x61, tmp);
34
}
35
36
void
spkr_beep
(uint32_t freq, uint32_t ms) {
37
spkr_tone(freq);
38
// TODO: Change this to task sleep
39
sleep
(ms);
40
spkr_stop();
41
// set_PIT_2(old_frequency);
42
}
sleep
void sleep(uint32_t ms)
Sleeps for a certain length of time.
Definition:
timer.cpp:52
spkr.hpp
spkr_beep
void spkr_beep(uint32_t freq, uint32_t ms)
Plays a given frequency for the provided duration.
Definition:
spkr.cpp:36
timer.hpp
Arch.hpp
Architecture control and initialization.
writeByte
void writeByte(uint16_t port, uint8_t data)
Writes a byte (8 bits) to the CPU bus at a given port address.
Definition:
ports.cpp:19
readByte
uint8_t readByte(uint16_t port)
Reads a byte (8 bits) off the CPU bus at a given port address.
Definition:
ports.cpp:13
Kernel
Devices
PCSpeaker
spkr.cpp
Generated by
1.8.17