#ifndef VasEBoot_SPEAKER_HEADER #define VasEBoot_SPEAKER_HEADER 1 #include #include /* The frequency of the PIT clock. */ #define VasEBoot_SPEAKER_PIT_FREQUENCY 0x1234dd static inline void VasEBoot_speaker_beep_off (void) { unsigned char status; status = VasEBoot_inb (VasEBoot_PIT_SPEAKER_PORT); VasEBoot_outb (status & ~(VasEBoot_PIT_SPK_TMR2 | VasEBoot_PIT_SPK_DATA), VasEBoot_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 = VasEBoot_SPEAKER_PIT_FREQUENCY / pitch; /* Program timer 2. */ VasEBoot_outb (VasEBoot_PIT_CTRL_SELECT_2 | VasEBoot_PIT_CTRL_READLOAD_WORD | VasEBoot_PIT_CTRL_SQUAREWAVE_GEN | VasEBoot_PIT_CTRL_COUNT_BINARY, VasEBoot_PIT_CTRL); VasEBoot_outb (counter & 0xff, VasEBoot_PIT_COUNTER_2); /* LSB */ VasEBoot_outb ((counter >> 8) & 0xff, VasEBoot_PIT_COUNTER_2); /* MSB */ /* Start speaker. */ status = VasEBoot_inb (VasEBoot_PIT_SPEAKER_PORT); VasEBoot_outb (status | VasEBoot_PIT_SPK_TMR2 | VasEBoot_PIT_SPK_DATA, VasEBoot_PIT_SPEAKER_PORT); } #endif