ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

beep.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS HAL
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            hal/halx86/generic/beep.c
00005  * PURPOSE:         Speaker support (beeping)
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 
00011 #include <hal.h>
00012 #define NDEBUG
00013 #include <debug.h>
00014 
00015 /* FUNCTIONS *****************************************************************/
00016 
00017 /*
00018  * @implemented
00019  */
00020 BOOLEAN
00021 NTAPI
00022 HalMakeBeep(IN ULONG Frequency)
00023 {
00024     SYSTEM_CONTROL_PORT_B_REGISTER SystemControl;
00025     TIMER_CONTROL_PORT_REGISTER TimerControl;
00026     ULONG Divider;
00027     BOOLEAN Result = FALSE;
00028 
00029     //
00030     // Acquire CMOS Lock
00031     //
00032     HalpAcquireCmosSpinLock();
00033 
00034     //
00035     // Turn the timer off by disconnecting its output pin and speaker gate
00036     //
00037     SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
00038     SystemControl.SpeakerDataEnable = FALSE;
00039     SystemControl.Timer2GateToSpeaker = FALSE;
00040     __outbyte(SYSTEM_CONTROL_PORT_B, SystemControl.Bits);
00041 
00042     //
00043     // Check if we have a frequency
00044     //
00045     if (Frequency)
00046     {
00047         //
00048         // Set the divider
00049         //
00050         Divider = PIT_FREQUENCY / Frequency;
00051 
00052         //
00053         // Check if it's too large
00054         //
00055         if (Divider <= 0x10000)
00056         {
00057             //
00058             // Program the PIT for binary mode
00059             //
00060             TimerControl.BcdMode = FALSE;
00061 
00062             //
00063             // Program the PIT to generate a square wave (Mode 3) on channel 2.
00064             // Channel 0 is used for the IRQ0 clock interval timer, and channel
00065             // 1 is used for DRAM refresh.
00066             //
00067             // Mode 2 gives much better accuracy, but generates an output signal
00068             // that drops to low for each input signal cycle at 0.8381 useconds.
00069             // This is too fast for the PC speaker to process and would result
00070             // in no sound being emitted.
00071             //
00072             // Mode 3 will generate a high pulse that is a bit longer and will
00073             // allow the PC speaker to notice. Additionally, take note that on
00074             // channel 2, when input goes low the counter will stop and output
00075             // will go to high.
00076             //
00077             TimerControl.OperatingMode = PitOperatingMode3;
00078             TimerControl.Channel = PitChannel2;
00079 
00080             //
00081             // Set the access mode that we'll use to program the reload value.
00082             //
00083             TimerControl.AccessMode = PitAccessModeLowHigh;
00084 
00085             //
00086             // Now write the programming bits
00087             //
00088             __outbyte(TIMER_CONTROL_PORT, TimerControl.Bits);
00089 
00090             //
00091             // Next we write the reload value for channel 2
00092             //
00093             __outbyte(TIMER_CHANNEL2_DATA_PORT, Divider & 0xFF);
00094             __outbyte(TIMER_CHANNEL2_DATA_PORT, (Divider >> 8) & 0xFF);
00095 
00096             //
00097             // Reconnect the speaker to the timer and re-enable the output pin
00098             //
00099             SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
00100             SystemControl.SpeakerDataEnable = TRUE;
00101             SystemControl.Timer2GateToSpeaker = TRUE;
00102             __outbyte(SYSTEM_CONTROL_PORT_B, SystemControl.Bits);
00103             Result = TRUE;
00104         }
00105     }
00106 
00107     //
00108     // Release CMOS lock
00109     //
00110     HalpReleaseCmosSpinLock();
00111 
00112     //
00113     // Return success
00114     //
00115     return Result;
00116 }

Generated on Wed May 23 2012 04:16:16 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.