📄 sdcardddk.h
字号:
// Flags - bus request flags
// Output: pRequest - newly allocated request
// Return: SD API Status
// Notes:
// Must call free request in the completion callback
//
#define SDBusRequest(hDevice, \
Command, \
Argument, \
TransferClass, \
ResponseType, \
NumBlocks, \
BlockSize, \
pBuffer, \
pCallback, \
RequestParam,\
pRequest, \
Flags) \
g_SDClientApiFunctions.pSDBusRequest((hDevice),(Command),(Argument),(TransferClass), \
(ResponseType),(NumBlocks),(BlockSize), \
(pBuffer), (pCallback), (RequestParam), (pRequest), (Flags))
// SDCancelBusRequest - Cancel an outstanding bus request
// Input:
// pRequest - request to cancel,(returned from SDBusRequest)
// Output:
// Return: TRUE if request was cancelled , FALSE if the request is still pending
// Notes:
//
#define SDCancelBusRequest(pRequest) g_SDClientApiFunctions.pSDCancelBusRequest((pRequest))
// SDFreeBusRequest - free a bus request
// Input: pRequest
// Output:
// Return:
// Notes:
// this function should be called when the request has completed,
// typically in the completion callback
//
#define SDFreeBusRequest(pRequest) g_SDClientApiFunctions.pSDFreeBusRequest((pRequest))
// SDCardInfoQuery - Obtain Card information
// Input: hDevice - SD Device Handle
// InfoType - information to get
// StructureSize - size of info structure
// Output: pCardInfo - Information specific structure
// Return: SD_API_STATUS code
// Notes: pCardInfo must point to sufficient memory for the informtaion type
//
#define SDCardInfoQuery(hDevice, \
InfoType, \
pCardInfo, \
StructureSize) \
g_SDClientApiFunctions.pSDCardInfoQuery((hDevice), (InfoType), (pCardInfo), \
(StructureSize))
// SDReadWriteRegistersDirect - Read/Write I/O register(s) direct
// Input: hDevice - the device handle
// ReadWrite - read write flag
// Function - Function number
// Address - starting address
// ReadAfterWrite - flag to instruct card to read after write
// pBuffer - buffer to hold value of registers
// Length - number of bytes to read/write
//
// Output:
// Return: SD_API_STATUS code
// Notes:
// This function can be called to read or write multiple contiguous registers synchronously
// using the SDIO RW_DIRECT command. This function issues multiple commands to transfer
// to or from the user's buffer
// If ReadAfterWrite is set to 1, the operation will instruct the card
// to return the new value of the register in the response.
//
#define SDReadWriteRegistersDirect(hDevice, \
ReadWrite, \
Function, \
Address, \
ReadAfterWrite, \
pBuffer, \
Length) \
g_SDClientApiFunctions.pSDReadWriteRegistersDirect((hDevice), (ReadWrite), (Function), \
(Address), (ReadAfterWrite), (pBuffer), \
(Length))
// SDGetTuple - Get tuple data from CIS
// Input: hDevice - SD device handle
// TupleCode - Tuple code
// pBufferSize - size of buffer to store Tuple Data
// Output: pBuffer - Tuple data is copied here (optional)
// pBufferSize - if pBuffer is NULL, this will store the size of the
// CommonCIS - flag indicating common or function CIS
// Return: SD_API_STATUS code
//
// Notes: The caller should initially call this function with a NULL buffer
// to determine the size of the tuple. The variable pBufferSize points
// to the caller supplied storage for this result. If no bus errors occurs
// the function returns SD_API_STATUS_SUCCESS. The caller must check
// the value of the buffer size returned. If the value is non-zero, the
// tuple exists and can be fetched by calling this function again with a
// non-zero buffer.
//
#define SDGetTuple(hDevice, \
TupleCode, \
pBuffer, \
pBufferSize,\
CommonCIS) \
g_SDClientApiFunctions.pSDGetTuple((hDevice), (TupleCode), (pBuffer), (pBufferSize),(CommonCIS))
// SDIOConnectInterrupt - Associate an interrupt service routine for an SDIO
// peripheral interrupt
// Input: hDevice - SD device handle
// pIsrFunction - the Interrupt service routine
// Output:
// Return: SD_API_STATUS code
//
// Notes: This function is provided for an SDIO peripheral driver to
// register an interrupt routine for the device.
// The interrupt function has the form of PSD_INTERRUPT_CALLBACK.
// The caller should call SDIODisconnectInterrupt when cleaning up
// the device. The bus driver will enable the interrupt for the function in the
// card's CCCR area prior to returning from this function.
// The interrupt callback is called whenever the device function is
// interrupting. The bus driver will determine the interrupting function,
// disable the interrupt on the card and call the callback. Upon return
// from the callback the bus driver will reenable the interrupt in the
// card's CCCR.
//
#define SDIOConnectInterrupt(hDevice, \
pIsrFunction) \
g_SDClientApiFunctions.pSDIOConnectInterrupt((hDevice), (pIsrFunction))
// SDIODisconnectInterrupt - disconnect the interrupt
// Input: hDevice - SD device handle
// Output:
// Return:
//
// Notes: This function should be called to disconnect the interrupt
// from the device. The bus driver will disable the interrupt in the
// card's CCCR area
//
#define SDIODisconnectInterrupt(hDevice) \
g_SDClientApiFunctions.pSDIODisconnectInterrupt((hDevice))
// SDSetCardFeature - Set card feature
// Input: hDevice - SD Device Handle
// CardFeature - Card Feature to set
// StructureSize - size of card feature structure
// Output: pCardInfo - Information for the feature
// Return: SD_API_STATUS code
// Notes: This function is provided to set various card features
// in a thread safe manner. SDIO cards utilize shared register sets
// between functions. This requires that the
// register state be preserved between functions that can be
// controlled in separate thread contexts.
// This function can potentially block by issuing synchronous bus
// request. This function must not be called from a bus request callback
//
#define SDSetCardFeature(hDevice, \
CardFeature, \
pCardInfo, \
StructureSize) \
g_SDClientApiFunctions.pSDSetCardFeature((hDevice), (CardFeature), (pCardInfo), \
(StructureSize))
// SDPerformSafeCopy - perform a safe memory copy
// Input: pSource - source data
// Length - number of bytes to copy
// Output: pDestination - Destination of the copy
// Return: returns TRUE if the copy succeeded, FALSE if an exception occured
// Notes:
BOOLEAN SDPerformSafeCopy(PVOID pDestination, PVOID pSource, ULONG Length);
// SDProcessException - main SD exception handler
// Input:
// pException - exception record passed in from the kernel
// Output:
// Return:
// Notes:
DWORD SDProcessException(LPEXCEPTION_POINTERS pException);
// macro to set the process permissions to the specified access key
// caller must call RESTORE_PROC_PERMISSIONS in braces
#define SD_SET_PROC_PERMISSIONS(Permissions) \
{ \
DWORD oldPermissions; \
oldPermissions = SetProcPermissions((Permissions)); \
#define SD_RESTORE_PROC_PERMISSIONS() \
SetProcPermissions(oldPermissions); \
}
// macro to set the access permissions based on what was saved in the request
#define SD_SET_PROC_PERMISSIONS_FROM_REQUEST(pRequest) \
SD_SET_PROC_PERMISSIONS((pRequest)->CurrentPermissions)
// macro to set the process permissions to all access
// caller must call RESTORE_PROC_PERMISSIONS
#define SD_SET_PROC_PERMISSIONS_ALL_ACCESS() SD_SET_PROC_PERMISSIONS(~0U)
#ifndef SHIP_BUILD
// SDOutputBuffer - dump buffer to debugger
// Input:
// pBuffer - the buffer to dump
// BufferSize - size of buffer in bytes
// Output:
// Notes:
// This function prints the buffer to the debugger using
// 16 bytes per line and displays the ASCII character respresentation
// per line, if the character is not displayable, a '.' is used
//
VOID SDOutputBuffer(PVOID pBuffer, ULONG BufferSize);
#else
#define SDOutputBuffer(pBuffer, BufferSize)
#endif // !SHIP_BUILD
#ifdef __cplusplus
}
#endif //__cplusplus
#ifdef DEBUG
// register zones macro
// Input: hInstance - Dll hInstance
// pPath - registry path for ZoneMask override value
// get initial zone override value from register if one exists
// use this value to overide the initial zone value
#define SD_DEBUG_ZONE_REGISTER(hInstance, reserved) DEBUGREGISTER(hInstance)
// this macro instantiates the global debug variable
#define SD_DEBUG_INSTANTIATE_ZONES(ModuleName, InitialValue, Slot0, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7, Slot8, Slot9, Slot10) \
DBGPARAM dpCurSettings = \
{ \
ModuleName, \
{ \
Slot0, \
Slot1, \
Slot2, \
Slot3, \
Slot4, \
Slot5, \
Slot6, \
Slot7, \
Slot8, \
Slot9, \
Slot10, \
TEXT("Functions"), \
TEXT("Information"), \
TEXT("Init"), \
TEXT("Warnings"), \
TEXT("Errors"), \
}, \
(InitialValue) \
};
#define DbgPrintZo(m, s) \
((void)((m)?(SDCardDebugOutput s),1:0))
#else // no DEBUG
#define SD_DEBUG_ZONE_REGISTER(hInstance, reserved)
#define SD_DEBUG_INSTANTIATE_ZONES(ModuleName, InitialValue, Slot0, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7, Slot8, Slot9, Slot10)
#define DbgPrintZo(m, s)
#endif // DEBUG
#ifndef SHIP_BUILD
#define DbgPrintRetail(s) SDCardDebugOutput s
#else
#define DbgPrintRetail(s)
#endif
#if DEBUG
// will break into the debugger if the expression is false
// Input: an expression to test
// Output:
#define DEBUG_ASSERT(t) DEBUGCHK(t)
#define DEBUG_CHECK(t,s)\
if (!(t)) {\
DbgPrintZo(-1,s); \
DebugBreak();\
}
#else // DEBUG
#define DEBUG_ASSERT(t)
#define DEBUG_CHECK(t,s)
#endif // DEBUG
#define MAX_SD_DESCRIPTION_STRING (MAX_SDCARD_CLIENT_NAME*2)
// bus driver name
#define SDCARD_BUS_DRIVER_DEVICE_NAME TEXT("SDC1:")
// bus driver ioctls
// Note: 0 and 1 are reserved.
// Output: DWORD - number of slots in the system
//
#define IOCTL_SD_BUS_DRIVER_GET_SLOT_COUNT\
CTL_CODE(0, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
// Output: BUS_DRIVER_SLOT_INFO array
#define IOCTL_SD_BUS_DRIVER_GET_SLOT_INFO\
CTL_CODE(0, 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
// Output: DWORD, Upper 16 bits = Version Major, Lower 16 bits = Version Minor
#define IOCTL_SD_BUS_DRIVER_GET_VERSION\
CTL_CODE(0, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
// slot info structure (one per slot)
typedef struct _BUS_DRIVER_SLOT_INFO {
DWORD HostIndex; // host controller index
DWORD SlotIndex; // slot index in host controller
BOOL CardPresent; // card is present
SDCARD_DEVICE_TYPE DeviceType;
WCHAR Description[MAX_SD_DESCRIPTION_STRING]; // device description string
SD_CARD_INTERFACE CardInterface; // card interface
}BUS_DRIVER_SLOT_INFO, *PBUS_DRIVER_SLOT_INFO;
#ifndef dim
#define dim(x) (sizeof(x)/sizeof(x[0]))
#endif
#endif
// DO NOT REMOVE --- END EXTERNALLY DEVELOPED SOURCE CODE ID --- DO NOT REMOVE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -