smckbpdd.cpp

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 2,209 行 · 第 1/5 页

CPP
2,209
字号
/*++
Copyright (c) 1995, 1996, 1997  Microsoft Corporation
Copyright 1997, 1998, 1999 Motorola.  All Rights Reserved.


@doc    EXTERNAL

@module smckbpdd.cpp |

    Sample implementation of the keyboard platform dependent device driver.  
    This driver is for the Sejin IR keyboard and Serial Receiver connected to
      either of the MPC821's SMC ports.


    NOTE:  This implementation uses internal buffers, (i.e. dpram), only.
           If external buffers are used, the developer should bear in mind
           that the function codes, as they are currently defined, cause
           the byte ordering to differ between internal and external memory.
--*/ 

//////////////////////////////////////////////////////////////////////////
// conditional code steering define/undef's

#undef SMC_KBD_BREAK_ON_ENTRY           // debugging-specific 
//#define SMC_KBD_BREAK_ON_ENTRY 

#ifdef SMC_KBD_DEBUG                    
// enable developer to set single breakpoint for debugging purposes
#define SMCKBD_DEBUG(smc, error_msg)    SmcKbd_Debug(smc, error_msg)
#else
#define SMCKBD_DEBUG(smc, error_msg)    ((void)0)
#endif



/////////////////////////////////////////////////////////////////////////
// UNAVAILABLE OAL FUNCTIONS

#undef OEM_DRIVER_PORT_PINS_AVAILABLE       // Get/set ext pin state


//////////////////////////////////////////////////////////////////////////
// includes

#include <memory.h>

#include <keybddr.h>
#include <windows.h>

#include <nkintr.h>
// #include <dispdrvr.h>

#include <mpc8xx.h>
//#include <platform.h>
#include <dd_serv.h>
//#include <oalintr.h>

#include <smc8xx.h>
#include <ir_kbd.h>
#include <keybdpdd.h>

#include "smc_kbd.h"

// Message enable defines 

#define ZONE_ERROR                  DEBUGZONE(0)
#define ZONE_SMC_BUFFER_INIT_DEBUG  DEBUGZONE(1)
#define ZONE_SMC_BD_INIT_DEBUG      DEBUGZONE(2)
#define ZONE_SMC_PROGRESS_DEBUG     DEBUGZONE(3)
#define ZONE_FUNCTION               DEBUGZONE(4)
#define ZONE_INIT                   DEBUGZONE(5)
#define ZONE_EVENT_HANDLER_DEBUG    DEBUGZONE(6)
#define ZONE_SMC_PUT_CHAR_DEBUG     DEBUGZONE(7)

extern "C" {
#include <windev.h>
};


#ifdef WINCEPROFILE
extern "C" void ProfileStart(DWORD,DWORD);
extern "C" void ProfileStop(void);
#endif


////////////////////////////////////////////////////////////////////////
// typedefs for volatile pointers

typedef volatile BYTE   *PVBYTE;




/////////////////////////////////////////////////////////////////////////////
// global variables
//
//    SMC channel data structure,
//
//    This structure contains various pointers to maintain a single SMC
//      channel receive and transmit functions. Similar to WinNT driver
//      extension.
//
//
//   This area contains:
//      - Buffer Descriptors,
//      - Function specific Parameter RAM (PRAM),
//      - General CPM and device-specific register values.

    static SMC_CHANNEL    KbdSmc;

//
// NOTE:
//
// The following variables should probably be added to the SMC_CHANNEL
//  structure.
//
//   Pointers (virtual/physical) to CPM DUAL PORT RAM area.
//
//   The physical address is required since the buffer addresses in the
//      BDs must be physical addresses used by the SDMA for transferring
//      data to/from buffers and CPM devices. Also, the "pointers" to the
//      BD Rings in the PRAM are 16-bit Physical offsets used by the CPM
//      to find the BDs.
//

    static PVBYTE        v_pDPRam;
    static PVBYTE        p_pDPRam;

#ifdef MOUSE_CURSOR_ON


// These variables are used for comparing the last mouse event with the current one.

    unsigned char Event_devIdLast = NULL;
    unsigned char last_x_data = NULL;
    unsigned char last_y_data = NULL;

// This is the current mouse ID received from the Keyboard

    unsigned char mouse_event_ID = NULL;

// Mouse parameters for mouse_event function    

    DWORD       
            dwFlagIr,
            dxIr, 
            dyIr;

#endif

    
#if (defined(MOTO_ADS) || defined(MOTO_FADS) || defined(SDB_RPXL) || defined(SDB_CLLF))
 
    //
    // These values point to the ADS Board CSR. The physical address
    //   of the registers can be read from the CPM registers and
    //   must be converted to an accessible virtual address via
    //   VirtualAlloc/VirtualCopy.
    //

    static HIOX_BCSR    *v_pBCSR;
    static HIOX_BCSR    *p_pBCSR;

#endif // MOTO_ADS || MOTO_FADS || SDB_RPXL || SDB_CLLF

    
// Made global to deal with IR keyboard auto-repeat (100ms) -

    static UINT8             v_PrevKeyScanCode = 0;
    
// Made global to handle IR keyboard FN key operation

    UINT8         v_NumLockState = 0;    // make accessible to sctovk()

// Made global to track CAPS_LOCK/NUM_LOCK/SCROLL_LOCK LEDs on 
// IR Receiver module

    static UINT8         v_LEDstate = 0;


// This define must match the same define in SCToVK/sctovk.cpp

#define VK_SPECIAL    (0xFF)



////////////////////////////////////////////////////////////////////////////////
//
//  @doc EXTERNAL 
//
//  @func
//
//  Obtain Virtual Mappings for Resources 
//
//  @rdesc Return TRUE if keyboard memory addresses properly initialized;
//         Otherwise, return FALSE.
//
////////////////////////////////////////////////////////////////////////////////

BOOL
KeybdDriverInitializeAddresses(
    void
    )
{
    DEBUGMSG( ZONE_FUNCTION, 
      ( TEXT("KeybdDriverInitializeAddresses: Entry.\r\n") ) );

    //
    // Get IMMR value - need both virtual and physical representation
    //

    ADDRESSES immr_values; 
    BOOL ret_val;

    ret_val = KernelIoControl(
        (DWORD) OEM_IOCTL_GET_IMMR,
        NOTUSED,
        NOTUSED,
        (LPVOID)&immr_values,
        NOTUSED,
        NOTUSED
    );

    p_pDPRam = (PVBYTE)immr_values.PhysicalAddress;
    DEBUGMSG( ZONE_INIT, 
      ( TEXT("********** p_pDPRam = %8x *********\r\n"), p_pDPRam ) );

    if( p_pDPRam == NULL )
    {
        SMCKBD_DEBUG(&KbdSmc,  
            "KeybdDriverInitializeAddresses: OEM GET_IMMR failed!\r\n");

        DEBUGMSG( ZONE_ERROR, 
          ( TEXT("********** OEM_IOCTL_GET_IMMR FAILED !!! *********\r\n") ) );
        goto error_return;
    }

    //
    //  Map CPM Dual Port RAM base address
    //
    v_pDPRam =
        (PVBYTE)VirtualAlloc(
            0,
            sizeof(IMM),
            MEM_RESERVE,
            PAGE_NOACCESS
        );

    if( v_pDPRam == NULL )
    {
        SMCKBD_DEBUG( &KbdSmc,
    "KeybdDriverInitializeAddresses: DP RAM VirtualAlloc failed!\r\n" ); 

        DEBUGMSG( ZONE_ERROR, 
          ( TEXT("********** DP RAM VirtualAlloc() FAILED !!! *********\r\n")));
        goto error_return;
    }
    else
    {
        DEBUGMSG( ZONE_INIT, ( TEXT("v_pDPRam = %8x\r\n"), v_pDPRam ) );
    }

    DEBUGMSG( ZONE_INIT, ( TEXT("Physical IMMR address: %8x\r\n"), p_pDPRam) );
    DEBUGMSG( ZONE_INIT, 
      ( TEXT("VirtualCopy address: %8x\r\n"), 
        (UINT32)immr_values.VirtualAddress ) );

    if( !VirtualCopy(
              (PVOID)v_pDPRam,
              (PVOID)(immr_values.VirtualAddress),
              sizeof(IMM),
              PAGE_READWRITE | PAGE_NOCACHE ) )
    {
            SMCKBD_DEBUG( &KbdSmc,
    "KeybdDriverInitializeAddresses: DP RAM VirtualCopy failed!\r\n" );

        DEBUGMSG( ZONE_ERROR, 
          ( TEXT("********** DP RAM VirtualCopy() FAILED !!! *********\r\n")));
        goto error_return;
    }


#if (defined(MOTO_ADS) || defined(MOTO_FADS) || defined(SDB_RPXL) || defined(SDB_CLLF))

    //
    // Need to map ADS Board CSR space for turning on SMC transceiver
    //

    v_pBCSR =
        (HIOX_BCSR *)
        VirtualAlloc(
            0,
            sizeof(HIOX_BCSR),
            MEM_RESERVE,
            PAGE_NOACCESS
        );

    if( v_pBCSR == NULL )
    {
        SMCKBD_DEBUG( &KbdSmc,
    "KeybdDriverInitializeAddresses: BCSR VirtualAlloc failed!\r\n" );

        DEBUGMSG( ZONE_ERROR, 
         (TEXT("********** BCSR VirtualAlloc() FAILED !!! *********\r\n")));
        goto error_return;
    }
    else
    {
        DEBUGMSG( ZONE_INIT, ( TEXT("v_pBCSR = %8x\r\n"), v_pBCSR ) );
    }


#if defined(MOTO_ADS) || defined(MOTO_FADS)
    p_pBCSR =
        (BCSR *)((unsigned int)((IMM *)v_pDPRam)->memc_br1 & 0xffff8000);
#endif
#if defined(SDB_RPXL) || defined(SDB_CLLF)
    #if defined(SDB_HIOX)
    {
    PALL_SDB_BCSR Sdb_Bcsr =
        (PALL_SDB_BCSR)(((IMM *)v_pDPRam)->memc_br3 & 0xffff8000);
    p_pBCSR = &Sdb_Bcsr->Hiox_Bcsr;
    }
    #endif
#endif

     DEBUGMSG( ZONE_INIT, 
      ( TEXT("Physical BCSR address: %8x\r\n"), p_pBCSR) );

     DEBUGMSG( ZONE_INIT, 
      ( TEXT("VirtualCopy (PAGE_PHYSICAL) address: %8x\r\n"),
                                            (UINT32)p_pBCSR >> 8 ) );

    if( !VirtualCopy(
              (PVOID)v_pBCSR,
              (PVOID)((UINT32)p_pBCSR >> 8),
              sizeof(HIOX_BCSR),
              PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL ) )

    {
        SMCKBD_DEBUG( &KbdSmc,
    "KeybdDriverInitializeAddresses: ADS BCSR VirtualCopy failed!\r\n" );

        DEBUGMSG( ZONE_ERROR, 
          (TEXT("********** ADS BCSR VirtualCopy() FAILED !!! *********\r\n")));
        goto error_return;
    }

#endif // MOTO_ADS || MOTO_FADS || SDB_RPXL || SDB_CLLF

    DEBUGMSG( ZONE_FUNCTION, 
      ( TEXT("KeybdDriverInitializeAddresses: Exit.\r\n") ) );

    return TRUE;

    //
    // Handle error case
    //
error_return:

    //
    // Free Dual Port RAM mapping
    //
    if ( v_pDPRam )
    {
        VirtualFree((PVOID)v_pDPRam, 0, MEM_RELEASE);
    }

    v_pDPRam = 0;

#if (defined(MOTO_ADS) || defined(MOTO_FADS) || defined(SDB_RPXL) || defined(SDB_CLLF))

    //
    // Free ADS Board CSR mapping
    //

    if ( v_pBCSR )
    {
        VirtualFree((PVOID)v_pBCSR, 0, MEM_RELEASE);
    }

    v_pBCSR = 0;

#endif // MOTO_ADS || MOTO_FADS || SDB_RPXL || SDB_CLLF

    return FALSE;
}



////////////////////////////////////////////////////////////////////////////////
//
//  @doc EXTERNAL
//
//  @func
//
//  On entry from the model device driver, the keyboard hardware is initialized.
//
//  @parm   The callback into the input system.
//
//  @rdesc  Return TRUE if keyboard hardware properly initialized.
//          Otherwise, return FALSE.
//
////////////////////////////////////////////////////////////////////////////////

BOOL WINAPI
KeybdPdd_InitializeDriver(
    PFN_KEYBD_EVENT_CALLBACK    pfnKeybdEventCallback
    )
{
#ifdef DEBUG
/* dpCurSettings is declared in KeybdIST.cpp.
   This is the first PDD function called.
   Update dpCurSettings here.
 */

    DBGPARAM dpCurSettings = {
    TEXT("Keyboard"), { 
    TEXT("Error"),TEXT("Buffer_Init"),TEXT("BD_Init"),TEXT("Progress"),
    TEXT("Function"),TEXT("Init"),TEXT("EventHandler"),TEXT("PutChar"),
    TEXT(""),TEXT(""),TEXT(""),TEXT(""),
    TEXT(""),TEXT(""),TEXT(""),TEXT("") },
    //0x0029  /* 0x0029 turns on 3 zones:  ERROR, PROGRESS and INIT */
    0xffff
};

#endif

    DEBUGMSG(ZONE_FUNCTION, (TEXT("KeybdPdd_InitializeDriver: Entry\r\n")));

    //
    // Breakpoint for determining mapping of driver.
    //

#if defined( SMC_KBD_BREAK_ON_ENTRY )
    DebugBreak();
#endif

    //
    // Initialize mappings for driver resources
    //

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?