- Make HalMakeBeep a bit nicer by making the PUCHAR typedef part of the TIMER constants.

svn path=/trunk/; revision=24742
This commit is contained in:
Alex Ionescu 2006-11-13 04:34:57 +00:00
parent 30c16d9652
commit abe724dba9

View file

@ -1,77 +1,68 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS HAL
* PROJECT: ReactOS kernel * LICENSE: GPL - See COPYING in the top level directory
* FILE: ntoskrnl/hal/x86/beep.c * FILE: ntoskrnl/hal/x86/beep.c
* PURPOSE: Speaker function (it's only one) * PURPOSE: Speak support (beeping)
* PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
* UPDATE HISTORY: * Eric Kohl (ekohl@abo.rhein-zeitung.de)
* Created 31/01/99 */
*/
/* INCLUDES *****************************************************************/ /* INCLUDES ******************************************************************/
#include <hal.h> #include <hal.h>
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
/* CONSTANTS *****************************************************************/ /* CONSTANTS *****************************************************************/
#define TIMER2 0x42 #define TIMER2 (PUCHAR)0x42
#define TIMER3 0x43 #define TIMER3 (PUCHAR)0x43
#define PORT_B 0x61 #define PORT_B (PUCHAR)0x61
#define CLOCKFREQ 1193167 #define CLOCKFREQ 1193167
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/*
* FUNCTION: Beeps the speaker.
* ARGUMENTS:
* Frequency = If 0, the speaker will be switched off, otherwise
* the speaker beeps with the specified frequency.
*/
BOOLEAN BOOLEAN
STDCALL NTAPI
HalMakeBeep ( HalMakeBeep(IN ULONG Frequency)
ULONG Frequency
)
{ {
UCHAR b; UCHAR Data;
ULONG flags; ULONG Divider;
BOOLEAN Result = TRUE;
/* save flags and disable interrupts */ /* FIXME: Acquire CMOS Lock */
Ki386SaveFlags(flags);
Ki386DisableInterrupts();
/* speaker off */ /* Turn the register off */
b = READ_PORT_UCHAR((PUCHAR)PORT_B); Data = READ_PORT_UCHAR(PORT_B);
WRITE_PORT_UCHAR((PUCHAR)PORT_B, (UCHAR)(b & 0xFC)); WRITE_PORT_UCHAR(PORT_B, Data & 0xFC);
/* Check if we have a frequency */
if (Frequency) if (Frequency)
{ {
ULONG Divider = CLOCKFREQ / Frequency; /* Set the divider */
Divider = CLOCKFREQ / Frequency;
/* Check if it's too large */
if (Divider > 0x10000) if (Divider > 0x10000)
{ {
/* restore flags */ /* Fail */
Ki386RestoreFlags(flags); Result = FALSE;
goto Cleanup;
return FALSE;
} }
/* set timer divider */ /* Set timer divider */
WRITE_PORT_UCHAR((PUCHAR)TIMER3, 0xB6); WRITE_PORT_UCHAR(TIMER3, 0xB6);
WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)(Divider & 0xFF)); WRITE_PORT_UCHAR(TIMER2, (UCHAR)(Divider & 0xFF));
WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)((Divider>>8) & 0xFF)); WRITE_PORT_UCHAR(TIMER2, (UCHAR)((Divider>>8) & 0xFF));
/* speaker on */ /* Turn speaker on */
WRITE_PORT_UCHAR((PUCHAR)PORT_B, (UCHAR)(READ_PORT_UCHAR((PUCHAR)PORT_B) | 0x03)); WRITE_PORT_UCHAR(PORT_B, READ_PORT_UCHAR(PORT_B) | 0x03);
} }
/* restore flags */ Cleanup:
Ki386RestoreFlags(flags); /* FIXME: Release hardware lock */
return TRUE; /* Return result */
return Result;
} }