#ifndef VAS_EBOOT_SPEAKER_HEADER #define VAS_EBOOT_SPEAKER_HEADER 1 #include #include /* The frequency of the PIT clock. */ #define VAS_EBOOT_SPEAKER_PIT_FREQUENCY 0x1234dd static inline void VasEBoot_speaker_beep_off (void) { unsigned char status; status = VasEBoot_inb (VAS_EBOOT_PIT_SPEAKER_PORT); VasEBoot_outb (status & ~(VAS_EBOOT_PIT_SPK_TMR2 | VAS_EBOOT_PIT_SPK_DATA), VAS_EBOOT_PIT_SPEAKER_PORT); } static inline void VasEBoot_speaker_beep_on (VasEBoot_uint16_t pitch) { unsigned char status; unsigned int counter; if (pitch < 20) pitch = 20; else if (pitch > 20000) pitch = 20000; counter = VAS_EBOOT_SPEAKER_PIT_FREQUENCY / pitch; /* Program timer 2. */ VasEBoot_outb (VAS_EBOOT_PIT_CTRL_SELECT_2 | VAS_EBOOT_PIT_CTRL_READLOAD_WORD | VAS_EBOOT_PIT_CTRL_SQUAREWAVE_GEN | VAS_EBOOT_PIT_CTRL_COUNT_BINARY, VAS_EBOOT_PIT_CTRL); VasEBoot_outb (counter & 0xff, VAS_EBOOT_PIT_COUNTER_2); /* LSB */ VasEBoot_outb ((counter >> 8) & 0xff, VAS_EBOOT_PIT_COUNTER_2); /* MSB */ /* Start speaker. */ status = VasEBoot_inb (VAS_EBOOT_PIT_SPEAKER_PORT); VasEBoot_outb (status | VAS_EBOOT_PIT_SPK_TMR2 | VAS_EBOOT_PIT_SPK_DATA, VAS_EBOOT_PIT_SPEAKER_PORT); } #endif