PFN_KEYBD_PDD_POWER_HANDLER (Compact 2013)
3/26/2014
This function handles system power state changes. It is called by the upper layer.
Syntax
typedef void (*PFN_KEYBD_PDD_POWER_HANDLER)(
UINT uiPddId,
BOOL fTurnOff
);
Parameters
- uiPddId
[in] Index of the PDD.
- fTurnOff
[in] TRUE indicates that the system is powering down. FALSE indicates that the system is powering up.
Return Value
None.
Remarks
This function runs in kernel context and assumes that interrupts are disabled because it works directly with microprocessor registers. It does not make any system calls or cause tasks to be rescheduled. This function is restricted to reading and writing to pre-allocated memory. Any subroutines called from this function must follow this restriction.
On receiving a power-down event, the sample driver empties the 8042-keyboard controller's data buffer. The following code example shows an implementation of the PFN_KEYBD_PDD_POWER_HANDLER function to actually control the power of the keyboard device; this function works in conjunction with PFN_KEYBD_DRIVER_POWER_HANDLER.
Important
For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.
void
WINAPI
KeybdPdd_PowerHandler(
BOOL bOff
)
{
extern DWORD gdwIoBase;
if ( bOff )
{
if ( KeyStateFlags == KeyStateDownFlag )
{
UCHAR ucKbdStatus, ucKbdData;
// Because this function is invoked right after a key is pressed, the output buffer of
// the keyboard must be cleaned until the corresponding key is released. Otherwise the
// data in that buffer will prevent subsequent keystrokes from generating interrupts,
// which might cause the keyboard to stop responding.
if(gdwIoBase != 0) {
do
{
ucKbdData = READ_PORT_UCHAR((PUCHAR)(gdwIoBase + 0x00));
} while ( !(ucKbdData & scKeyUpMask) );
}
KeyStateFlags = 0;
if(gdwIoBase != 0) {
ucKbdStatus = READ_PORT_UCHAR((PUCHAR)(gdwIoBase + 0x04));
while ( (ucKbdStatus & 0x21) == 0x01 )
{
ucKbdData = READ_PORT_UCHAR((PUCHAR)(gdwIoBase + 0x00));
ucKbdStatus = READ_PORT_UCHAR((PUCHAR)(gdwIoBase + 0x04));
}
}
}
}
return;
}
Requirements
Header |
keybdpdd.h |
See Also
Reference
Keyboard Driver PDD Functions
PFN_KEYBD_DRIVER_POWER_HANDLER