mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-26 00:52:50 +00:00
Initial commit: SUB-OS 64-Bit Production Monolithic Operating System with LazyBox userland suite
This commit is contained in:
commit
cd9c786d14
88 files changed
+7132
No files matched your search
@@ -0,0 +1,30 @@
|
||||
#include <drivers/speaker.h>
|
||||
#include <arch/x86_64/pit.h>
|
||||
#include <arch/x86_64/io.h>
|
||||
|
||||
void speaker_on(uint32_t frequency) {
|
||||
if (frequency == 0) return;
|
||||
uint32_t divisor = 1193180 / frequency;
|
||||
|
||||
// Set PIT Channel 2
|
||||
outb(0x43, 0xB6);
|
||||
outb(0x42, (uint8_t)(divisor & 0xFF));
|
||||
outb(0x42, (uint8_t)((divisor >> 8) & 0xFF));
|
||||
|
||||
// Enable speaker via Port 0x61
|
||||
uint8_t tmp = inb(0x61);
|
||||
if (tmp != (tmp | 3)) {
|
||||
outb(0x61, tmp | 3);
|
||||
}
|
||||
}
|
||||
|
||||
void speaker_off(void) {
|
||||
uint8_t tmp = inb(0x61) & 0xFC;
|
||||
outb(0x61, tmp);
|
||||
}
|
||||
|
||||
void speaker_beep(uint32_t frequency, uint32_t duration_ms) {
|
||||
speaker_on(frequency);
|
||||
pit_sleep(duration_ms);
|
||||
speaker_off();
|
||||
}
|
||||
Reference in new issue
Block a user