2001-08-21 20:18:27 +00:00
|
|
|
/*
|
2006-11-14 18:17:33 +00:00
|
|
|
* PROJECT: ReactOS HAL
|
2010-01-08 04:31:19 +00:00
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
2006-11-29 08:28:20 +00:00
|
|
|
* FILE: hal/halx86/generic/beep.c
|
2006-11-16 17:30:52 +00:00
|
|
|
* PURPOSE: Speaker support (beeping)
|
2010-01-08 04:31:19 +00:00
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
2006-11-14 18:17:33 +00:00
|
|
|
*/
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:34:57 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2005-06-18 14:29:31 +00:00
|
|
|
#include <hal.h>
|
2005-06-19 22:53:49 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2001-08-21 20:18:27 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2006-11-16 17:30:52 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-08-21 20:18:27 +00:00
|
|
|
BOOLEAN
|
2006-11-13 04:34:57 +00:00
|
|
|
NTAPI
|
|
|
|
HalMakeBeep(IN ULONG Frequency)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2010-01-08 04:31:19 +00:00
|
|
|
SYSTEM_CONTROL_PORT_B_REGISTER SystemControl;
|
|
|
|
TIMER_CONTROL_PORT_REGISTER TimerControl;
|
2006-11-13 04:34:57 +00:00
|
|
|
ULONG Divider;
|
2010-01-08 04:31:19 +00:00
|
|
|
BOOLEAN Result = FALSE;
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Acquire CMOS Lock
|
|
|
|
//
|
2011-09-07 10:14:48 +00:00
|
|
|
HalpAcquireCmosSpinLock();
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Turn the timer off by disconnecting its output pin and speaker gate
|
|
|
|
//
|
|
|
|
SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
|
|
|
|
SystemControl.SpeakerDataEnable = FALSE;
|
|
|
|
SystemControl.Timer2GateToSpeaker = FALSE;
|
|
|
|
__outbyte(SYSTEM_CONTROL_PORT_B, SystemControl.Bits);
|
2006-11-13 04:34:57 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Check if we have a frequency
|
|
|
|
//
|
2001-08-21 20:18:27 +00:00
|
|
|
if (Frequency)
|
|
|
|
{
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Set the divider
|
|
|
|
//
|
|
|
|
Divider = PIT_FREQUENCY / Frequency;
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Check if it's too large
|
|
|
|
//
|
|
|
|
if (Divider <= 0x10000)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Program the PIT for binary mode
|
|
|
|
//
|
|
|
|
TimerControl.BcdMode = FALSE;
|
2011-09-07 10:14:48 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Program the PIT to generate a square wave (Mode 3) on channel 2.
|
|
|
|
// Channel 0 is used for the IRQ0 clock interval timer, and channel
|
|
|
|
// 1 is used for DRAM refresh.
|
|
|
|
//
|
|
|
|
// Mode 2 gives much better accuracy, but generates an output signal
|
|
|
|
// that drops to low for each input signal cycle at 0.8381 useconds.
|
|
|
|
// This is too fast for the PC speaker to process and would result
|
|
|
|
// in no sound being emitted.
|
|
|
|
//
|
|
|
|
// Mode 3 will generate a high pulse that is a bit longer and will
|
|
|
|
// allow the PC speaker to notice. Additionally, take note that on
|
|
|
|
// channel 2, when input goes low the counter will stop and output
|
|
|
|
// will go to high.
|
|
|
|
//
|
|
|
|
TimerControl.OperatingMode = PitOperatingMode3;
|
|
|
|
TimerControl.Channel = PitChannel2;
|
2011-09-07 10:14:48 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Set the access mode that we'll use to program the reload value.
|
|
|
|
//
|
|
|
|
TimerControl.AccessMode = PitAccessModeLowHigh;
|
2011-09-07 10:14:48 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Now write the programming bits
|
|
|
|
//
|
|
|
|
__outbyte(TIMER_CONTROL_PORT, TimerControl.Bits);
|
2011-09-07 10:14:48 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Next we write the reload value for channel 2
|
|
|
|
//
|
|
|
|
__outbyte(TIMER_CHANNEL2_DATA_PORT, Divider & 0xFF);
|
2011-11-21 12:04:16 +00:00
|
|
|
__outbyte(TIMER_CHANNEL2_DATA_PORT, (Divider >> 8) & 0xFF);
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Reconnect the speaker to the timer and re-enable the output pin
|
|
|
|
//
|
|
|
|
SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
|
|
|
|
SystemControl.SpeakerDataEnable = TRUE;
|
|
|
|
SystemControl.Timer2GateToSpeaker = TRUE;
|
|
|
|
__outbyte(SYSTEM_CONTROL_PORT_B, SystemControl.Bits);
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2001-08-21 20:18:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Release CMOS lock
|
|
|
|
//
|
2009-10-29 19:58:41 +00:00
|
|
|
HalpReleaseCmosSpinLock();
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2010-01-08 04:31:19 +00:00
|
|
|
//
|
|
|
|
// Return success
|
|
|
|
//
|
|
|
|
return Result;
|
2001-08-21 20:18:27 +00:00
|
|
|
}
|