📄 sdbusdriver.cpp
字号:
if(NULL == pSlot)
{
return SD_API_STATUS_NO_SUCH_DEVICE;
}
memset(pFPCdata, 0, sizeof(FUNCTION_POWER_DATA));
status = CheckSlotReady(pSlot);
if(!SD_API_SUCCESS(status)) {
return status;
}
// Start from parent device
pCurrentDevice = SDDCGetClientDeviceFromHandle(pSlot->hDevice);
if ( pCurrentDevice == NULL ) {
return SD_API_STATUS_UNSUCCESSFUL;
}
// Find the function wanted
while (pCurrentDevice != NULL) {
if(pCurrentDevice->SDCardInfo.SDIOInformation.Function == FunctionIndexWanted) {
break;
}
pCurrentDevice = pCurrentDevice->pNext;
}
if(pCurrentDevice != NULL)
{
// we found the function, now fill in the data
_tcsncpy(pFPCdata->ClientName, pCurrentDevice->ClientName, MAX_SDCARD_CLIENT_NAME);
status = GetFunctionPowerState(pCurrentDevice, &pFPCdata->PowerState);
if(!SD_API_SUCCESS(status)) {
return status;
}
pFPCdata->PowerTuples = pCurrentDevice->SDCardInfo.SDIOInformation.PowerDrawData;
}
return SD_API_STATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
// SetSlotPowerControl - set if a slot will enable power control on card insertion
// Input: slotIndexWanted - index of slot
// fEnablePowerControl - flag set if power control is to be enabled or not
//
// Output:
// Notes:
// returns SD Api Error
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDBusDriver::SetSlotPowerControl(DWORD slotIndexWanted,
BOOL fEnablePowerControl)
{
PSDBUS_HC_SLOT_CONTEXT pSlot; // slot context
pSlot = GetSlotContext(slotIndexWanted);
if(NULL == pSlot)
{
return SD_API_STATUS_NO_SUCH_DEVICE;
}
//Set flag that is checked on initalization of power control
SDHCDSetSlotEnablePowerControl(pSlot->pHostController, slotIndexWanted, fEnablePowerControl);
return SD_API_STATUS_SUCCESS;
}
#ifdef ENABLE_SDIO_V1_1_SUPPORT
///////////////////////////////////////////////////////////////////////////////
// SlotCardSelectDeselect - Select/Deselect the card in teh slot
// Input: SlotIndexWanted - index of slot
// Event - SlotDeselectRequest/SlotSelectRequest/SlotResetRequest
// Output:
// Notes:
///////////////////////////////////////////////////////////////////////////////
BOOL CSDBusDriver::SlotCardSelectDeselect(DWORD SlotIndexWanted,
SD_SLOT_EVENT Event)
{
PSDBUS_HC_SLOT_CONTEXT pSlot; // slot context
PSDCARD_DEVICE_CONTEXT pDevice; // the device in the slot
SD_API_STATUS status; // intermediate SD status
BOOL retStatus; // return status
SD_SET_FEATURE_TYPE CardFeature; // card feature code
pSlot = GetSlotContext(SlotIndexWanted);
if(NULL == pSlot) {
return FALSE;
}
// get the device in the slot if any
pDevice = SDDCGetClientDeviceFromHandle(pSlot->hDevice);
if (NULL != pDevice) {
// check for a ready device in the slot
if (pSlot->SlotState == Ready) {
switch ( Event ) {
case SlotDeselectRequest:
CardFeature = SD_CARD_DESELECT_REQUEST;
break;
case SlotSelectRequest:
CardFeature = SD_CARD_SELECT_REQUEST;
break;
case SlotResetRequest:
CardFeature = SD_CARD_FORCE_RESET;
break;
default:
DEBUG_CHECK(FALSE, (TEXT("SDBusDriver: Unknown Slot Event : %d \n"),
Event));
return FALSE;
}
// Call API to request the card to be deselected
status = SDSetCardFeature__X( (SD_DEVICE_HANDLE) pDevice,
CardFeature,
NULL,
0);
retStatus = TRUE;
if(!SD_API_SUCCESS(status)) {
DbgPrintZo(SDCARD_ZONE_ERROR,(TEXT("SDBusDriver: Failed to request the card to be deselected\r\n")));
retStatus = FALSE;
}
} else {
retStatus = FALSE;
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("Driver not loaded")));
}
} else {
retStatus = FALSE;
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("Empty Slot")));
}
return retStatus;
}
#endif //ENABLE_SDIO_V1_1_SUPPORT
///////////////////////////////////////////////////////////////////////////////
// RegisterHostController - Register a host controller with the bus driver
// Input: pHCContext - host controller context
// Output:
// Notes:
// returns api status error
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDBusDriver::RegisterHostController(PSDBUS_HC_CONTEXT pHCContext)
{
// insert the host controller into the list
InsertTailList(&m_HostControllerListHead, &pHCContext->ListEntry);
return SD_API_STATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
// DeregisterHostController - De register a host controller with the bus driver
// Input: pHCContext - host controller context
// Output:
// Notes:
// returns api status error
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDBusDriver::DeregisterHostController(PSDBUS_HC_CONTEXT pHCContext)
{
PSDBUS_HC_SLOT_CONTEXT pSlotContext; // the slot context
PREFAST_DEBUGCHK(pHCContext->ListEntry.Flink != NULL);
PREFAST_DEBUGCHK(pHCContext->ListEntry.Blink != NULL);
// cut the context out of the list
RemoveEntryList(&pHCContext->ListEntry);
// flush the slot queue of any pending slot events
for (ULONG ii = 0; ii < pHCContext->NumberOfSlots; ii++) {
// get the slot context for this slot number and host controller
pSlotContext = SDHCGetSlotContext(pHCContext, ii);
// cleanup work items
if (NULL != pSlotContext->pWorkItem) {
delete (CSDWorkItem *)pSlotContext->pWorkItem;
pSlotContext->pWorkItem = NULL;
}
}
return SD_API_STATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
// PowerUp - Power up notification for the bus driver
// Input: pSlot - slot
// Output:
// Notes: This function is called from an interrupt context from the
// SDHCDPowerUpDown() API
//
// Currently there is nothing to do.
///////////////////////////////////////////////////////////////////////////////
VOID CSDBusDriver::PowerUp(PSDBUS_HC_SLOT_CONTEXT pSlot)
{
// Nothing to do
}
///////////////////////////////////////////////////////////////////////////////
// PowerDown -Power down notificiation for the bus driver
// Input: pSlot - slot
// KeepPower - the slot keeps power
// Output:
// Notes: This function is called from an interrupt contextfrom the
// SDHCDPowerUpDown() API
//
///////////////////////////////////////////////////////////////////////////////
VOID CSDBusDriver::PowerDown(PSDBUS_HC_SLOT_CONTEXT pSlot, BOOL KeepPower)
{
if (!KeepPower) {
// mark slot as device ejected to prevent drivers from submitting
// requests while we are cleaning up from powerup
pSlot->SlotState = SlotDeviceEjected;
}
}
///////////////////////////////////////////////////////////////////////////////
// PostSlotEvent - Post a slot event
// Input: Event - event
// pSlotContext - the slot
// Output:
// Notes:
//
///////////////////////////////////////////////////////////////////////////////
VOID CSDBusDriver::PostSlotEvent(SD_SLOT_EVENT Event,
PSDBUS_HC_SLOT_CONTEXT pSlotContext,
CSDWorkItem *pWorkItem)
{
PSDCARD_HC_SLOT_EVENT pSlotEvent; // slot event packet
PWORK_ITEM_MESSAGE_BLOCK pMessage; // message block
// allocate a message
pMessage = pWorkItem->AllocateMessage();
if (NULL == pMessage ) {
DEBUG_CHECK(FALSE, (TEXT("SDHCDIndicateSlotStateChange, no more slot events \n")));
return;
}
pSlotEvent = GetMessageBlock(PSDCARD_HC_SLOT_EVENT, pMessage);
// fill in the message block
pSlotEvent->pSlotContext = pSlotContext;
pSlotEvent->SlotEvent = Event;
// post the message to the dispatcher
pWorkItem->PostMessage(pMessage);
}
///////////////////////////////////////////////////////////////////////////////
// BusRequestCompleteDispatch - bus request complete dispatcher
// Input: pWorkItem - the work item
// pBusDriver - the bus driver instance
// Output:
// Notes:
//
///////////////////////////////////////////////////////////////////////////////
VOID CSDBusDriver::BusRequestCompleteDispatch(CSDWorkItem *pWorkItem, CSDBusDriver *pBusDriver)
{
SD_API_STATUS status; // intermediate status
DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: BusRequestCompleteDispatch Work Item Starting Up \n")));
while(1) {
// wait for an event
status = pWorkItem->WaitWakeUp();
if (!SD_API_SUCCESS(status)) {
if (status == SD_API_STATUS_SHUT_DOWN) {
DEBUGMSG(SDBUS_ZONE_DISPATCHER, (TEXT("SDBusDriver: Event Dispatcher shutting down\n")));
}
return;
}
// handle the bus request completion
pBusDriver->HandleBusRequestComplete();
}
}
// DO NOT REMOVE --- END EXTERNALLY DEVELOPED SOURCE CODE ID --- DO NOT REMOVE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -