📄 main.cpp
字号:
//---------------------------------------------------------------------------
//
// Copyright (C) 2003-2004, MOTOROLA, INC. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// MOTOROLA, INC.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2006,2007 Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------
//
// File: drivers/sdhc/main.cpp
// Purpose: Entry points for SDHC driver
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include <Devload.h>
#include "csp.h"
#include "sdhc.h"
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
_T("SDHC"),
{
_T("Init"), _T("DeInit"), _T("Ioctl"), _T(""),
_T(""), _T(""), _T(""), _T(""),
_T(""),_T("DMA"),_T("Interrupt"),_T("Command"),
_T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
},
(ZONEMASK_ERROR | ZONEMASK_WARN)
};
#endif
/*******************************************************************************
GLOBAL OR STATIC VARIABLES
*******************************************************************************/
/*******************************************************************************
STATIC FUNCTION PROTOTYPES
*******************************************************************************/
static BOOL LoadRegistrySettings(HKEY hKeyDevice, PSDH_HARDWARE_CONTEXT pController);
/*******************************************************************************
EXPORTED FUNCTIONS
*******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
// CardDllEntry - the main dll entry point
// Input: hInstance - the instance that is attaching
// Reason - the reason for attaching
// pReserved -
// Output:
// Return: TRUE
// Notes: this is only used to initialize the zones
///////////////////////////////////////////////////////////////////////////////
BOOL WINAPI DllEntry(HINSTANCE hInstance,
ULONG Reason,
LPVOID pReserved)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("SDH: +DllEntry\n")));
if ( Reason == DLL_PROCESS_ATTACH )
{
DEBUGMSG(ZONE_INFO, (TEXT("DLL_PROCESS_ATTACH\n")));
DEBUGREGISTER((HMODULE) hInstance); //register debug zones
DisableThreadLibraryCalls( (HMODULE) hInstance );
if( !SDInitializeCardLib() )
{
return FALSE;
}
else if( !SD_API_SUCCESS( SDHCDInitializeHCLib() ) )
{
SDDeinitializeCardLib();
return FALSE;
}
}
if ( Reason == DLL_PROCESS_DETACH )
{
DEBUGMSG(ZONE_INFO, (TEXT("DLL_PROCESS_DETACH\n")));
SDHCDDeinitializeHCLib();
SDDeinitializeCardLib();
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("SDH: -DllEntry\n")));
return(TRUE);
}
///////////////////////////////////////////////////////////////////////////////
// SDH_Deinit - the deinit entry point
// Input: hDeviceContext - the context returned from SDH_Init
// Output:
// Return: always returns TRUE
// Notes:
///////////////////////////////////////////////////////////////////////////////
BOOL SDH_Deinit(DWORD hDeviceContext)
{
PSDCARD_HC_CONTEXT pHostContext;
DEBUGMSG(ZONE_FUNCTION, (TEXT("SDH: +SDH_Deinit\n")));
pHostContext = (PSDCARD_HC_CONTEXT)hDeviceContext;
// deregister the host controller
SDHCDDeregisterHostController(pHostContext);
if( pHostContext && pHostContext->pHCSpecificContext )
{
free( pHostContext->pHCSpecificContext );
}
// cleanup the context
SDHCDDeleteContext((PSDCARD_HC_CONTEXT)hDeviceContext);
DEBUGMSG(ZONE_FUNCTION , (TEXT("SDH: -SDH_Deinit\n")));
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// SDH_Init - the init entry point
// Input: dwContext - the context for this init
// Output:
// Return: returns instance context
// Notes:
///////////////////////////////////////////////////////////////////////////////
DWORD SDH_Init(DWORD dwContext)
{
PSDCARD_HC_CONTEXT pHostContext; // new HC context
SD_API_STATUS status; // SD status
PSDH_HARDWARE_CONTEXT pController; // new instance
HKEY hKeyDevice = NULL;
LPCTSTR pszActiveKey;
DEBUGMSG(ZONE_FUNCTION, (TEXT("SDH: +SDH_Init\n")));
DEBUGMSG(ZONE_INFO, (TEXT("SDH: Active RegPath: %s \n"),(PTSTR)dwContext));
pController = NULL;
// allocate the context
status = SDHCDAllocateContext(SDH_SLOTS, &pHostContext);
if (!SD_API_SUCCESS(status))
{
DEBUGMSG(ZONE_ERROR, (TEXT("SDH: Failed to allocate context : 0x%08X \n"), status));
RETAILMSG(ZONE_ERROR, (TEXT("SDH: Failed to allocate contextt\n")));
goto _errExit;
}
// create our extension
pController = (PSDH_HARDWARE_CONTEXT)malloc( sizeof(SDH_HARDWARE_CONTEXT) );
if( pController == NULL )
{
DEBUGMSG(ZONE_ERROR, (TEXT("SDH: Failed to allocate extension\n")));
RETAILMSG(ZONE_ERROR, (TEXT("SDH: Failed to allocate extension\n")));
goto _errExit;
}
memset( pController, 0, sizeof(SDH_HARDWARE_CONTEXT) );
// Set our extension
pHostContext->pHCSpecificContext = pController;
pController = GetExtensionFromHCDContext(PSDH_HARDWARE_CONTEXT, pHostContext);
pszActiveKey = (LPCTSTR) dwContext;
hKeyDevice = OpenDeviceKey(pszActiveKey);
if (!hKeyDevice || !LoadRegistrySettings(hKeyDevice, pController) )
{
DEBUGMSG(ZONE_ERROR, (TEXT("SDH: Failed load the registry settings\n")));
RETAILMSG(ZONE_ERROR, (TEXT("SDH: Failed load the registry settings\n")));
goto _errExit;
}
RegCloseKey( hKeyDevice );
// save off the host context
pController->pHCContext = pHostContext;
//Set a unique name for each host controller
if (pController->ControllerIndex == 1)
{
SDHCDSetHCName(pHostContext, TEXT("MX27_1"));
}
else if (pController->ControllerIndex == 2)
{
SDHCDSetHCName(pHostContext, TEXT("MX27_2"));
}
else if (pController->ControllerIndex == 3)
{
SDHCDSetHCName(pHostContext, TEXT("MX27_3"));
}
// set init handler
SDHCDSetControllerInitHandler(pHostContext,SDInitialize);
// set deinit handler
SDHCDSetControllerDeinitHandler(pHostContext, SDDeinitialize);
// set the bus request handler
SDHCDSetBusRequestHandler(pHostContext,SDHBusRequestHandler);
// set the cancel I/O handler
SDHCDSetCancelIOHandler(pHostContext, SDHCancelIoHandler);
// set the slot option handler
SDHCDSetSlotOptionHandler(pHostContext, SDHSlotOptionHandler);
// now register the host controller
status = SDHCDRegisterHostController(pHostContext);
if (!SD_API_SUCCESS(status))
{
DEBUGMSG(ZONE_ERROR, (TEXT("SDH: Failed to register host controller: %0x08X \n"),status));
RETAILMSG(ZONE_ERROR, (TEXT("SDH: Failed to register host controller\n")));
goto _errExit;
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("SDH: -SDH_Init\n")));
// return the Host Controller context
return (DWORD)pHostContext;
_errExit:
if(pHostContext)
SDHCDDeleteContext(pHostContext);
if(pController){
free(pController);
}
if(hKeyDevice)
RegCloseKey(hKeyDevice);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// SDH_IOControl - the I/O control entry point
// Input: hOpenContext - the context returned from SDH_Open
// dwCode - the ioctl code
// pBufIn - the input buffer from the user
// dwLenIn - the length of the input buffer
// pBufOut - the output buffer from the user
// dwLenOut - the length of the output buffer
// pdwActualOut - the size of the transfer
// Output:
// Return: FALSE
// Notes: Not used
///////////////////////////////////////////////////////////////////////////////
BOOL SDH_IOControl(DWORD hOpenContext,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -