00001 /*! \file kernel/speaker.c 00002 * \brief System speaker driver. 00003 * \author Andrea Righi <drizzt@inwind.it> 00004 * \date Last update: 2003-11-02 00005 * \note Copyright (©) 2003 Andrea Righi 00006 */ 00007 00008 #include <const.h> 00009 00010 #include <arch/i386.h> 00011 00012 #include <kernel/clock.h> 00013 00014 #include <kernel/speaker.h> 00015 00016 //! \brief Start a sound using the speaker. 00017 //! \param frequency The frequency of the sound. 00018 void sound(uint32_t frequency) 00019 { 00020 dword x, IF; 00021 00022 if ((frequency<19) || (frequency>22000)) return; 00023 00024 x = TIMER_FREQ / frequency; 00025 00026 IF = GET_IF(); 00027 SET_IF(0); 00028 00029 outportb(0x61, inportb(0x61) | 3); 00030 outportb(0x43, 0xB6); 00031 outportb(0x42, x & 0xFF); 00032 outportb(0x42, x >> 8); 00033 00034 SET_IF(IF); 00035 } 00036 00037 //! \brief Turn off the speaker. 00038 void nosound() 00039 { 00040 dword IF; 00041 00042 IF = GET_IF(); 00043 SET_IF(0); 00044 00045 outportb(0x61, inportb(0x61) & 0xFC); 00046 00047 SET_IF(IF); 00048 } 00049 00050 //! \brief Play a system beep. 00051 void beep() 00052 { 00053 sound(SYSTEM_BEEP_FREQ); 00054 delay(SYSTEM_BEEP_TIME); 00055 nosound(); 00056 }