StuBS
|
Abstraction of the historical Programmable Interval Timer (PIT). More...
Enumerations | |
enum | AccessMode |
Access mode. | |
enum | OperatingMode { } |
Operating Mode. More... | |
enum | Format { } |
data format More... | |
Functions | |
bool | set (uint16_t us) |
Start timer. | |
uint16_t | get (void) |
Reads the current timer value. | |
bool | isActive (void) |
Check if the timer is running. | |
bool | waitForTimeout (void) |
(Active) waiting for timeout | |
bool | delay (uint16_t us) |
Set the timer and wait for timeout. | |
void | pcspeaker (uint32_t freq) |
Play a given frequency on the PC speaker. | |
void | disable (void) |
Deactivate the timer. | |
Abstraction of the historical Programmable Interval Timer (PIT).
Historically, PCs had a Timer component of type 8253 or 8254, modern systems come with a compatible chip. Each of these chips provides three 16-bit wide counters ("channel"), each running at a frequency of 1.19318 MHz. The timer's counting speed is thereby independent from the CPU frequency.
Traditionally, the first counter (channel 0) was used for triggering interrupts, the second one (channel 1) controlled the memory refresh, and the third counter (channel 2) was assigned to the PC speaker.
As the PIT's frequency is fixed to a constant value of 1.19318 MHz, the PIT can be used for calibration. For this purpose, we use channel 2 only.
enum PIT::Format |
enum PIT::OperatingMode |
bool PIT::delay | ( | uint16_t | us | ) |
Set the timer and wait for timeout.
us | Waiting time in us |
true
when waiting successfully terminated; false
on error (e.g., waiting time exceeds its limits) uint16_t PIT::get | ( | void | ) |
Reads the current timer value.
bool PIT::isActive | ( | void | ) |
Check if the timer is running.
true
if running, false
otherwise void PIT::pcspeaker | ( | uint32_t | freq | ) |
Play a given frequency on the PC speaker.
As the PC speaker is connected to PIT channel 2, the PIT can be used to play an acoustic signal. Playing sounds occupies the PIT, so it cannot be used for other purposes while playback.
-soundhw pcspk
. If you still cannot hear anything, try to set QEMU_AUDIO_DRV
to alsa
(by launching StuBS with QEMU_AUDIO_DRV=alsa make kvm
) freq | Frequency (in Hz) of the sound to be played, or 0 to deactivate playback. |
bool PIT::set | ( | uint16_t | us | ) |
Start timer.
Sets the channel 2 timer to the provided value and starts counting.
us | Waiting time in us |
true
if the counter is running; false
if the waiting time exceeds the limits. bool PIT::waitForTimeout | ( | void | ) |
(Active) waiting for timeout
true
when timeout was successfully hit, false
if the timer was not active prior to calling.