⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdbusdriver.cpp

📁 2443 wince5.0 bsp, source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        ReleaseLock();
        return 0;   
    }

    // get the slot array
    slotInfoArray = (PBUS_DRIVER_SLOT_INFO)pBuffer;

    // reset index
    slotArrayIndex = 0;
    // reset the head
    pListEntry = m_HostControllerListHead.Flink;

    // loop through the host controllers and get the slot information
    while (pListEntry != &m_HostControllerListHead) {

        // get the context
        pHCContext = CONTAINING_RECORD(pListEntry, SDBUS_HC_CONTEXT, ListEntry);

        // for each slot on this HC, check for a device
        for (slotIndex = 0; slotIndex < pHCContext->NumberOfSlots; slotIndex++) {

            // get the slot
            pSlot = SDHCGetSlotContext(pHCContext, slotIndex);

            // 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) {
                    // build the description
                    wcsncpy(description, SDDCGetClientName(pDevice), dim(description));
                    description[dim(description) - 1] = 0; // NULL-terminate
                } else {
                    wsprintf(description, TEXT("Driver not loaded"));
                }

            } else {
                wsprintf(description, TEXT("Empty Slot"));
            }

            __try {
                // set the index
                slotInfoArray[slotArrayIndex].HostIndex = pSlot->pHostController->dwHCNumber;
                slotInfoArray[slotArrayIndex].SlotIndex = slotIndex;

                if (pDevice != NULL) {
                    // copy the card interface 
                    memcpy(&slotInfoArray[slotArrayIndex].CardInterface, 
                        &pDevice->CardInterface, sizeof(pDevice->CardInterface));
                    slotInfoArray[slotArrayIndex].CardPresent = TRUE;
                    slotInfoArray[slotArrayIndex].DeviceType = pDevice->DeviceType;
                }
                // copy the description string
                wcscpy(slotInfoArray[slotArrayIndex].Description, description);

            } __except (SDProcessException(GetExceptionInformation())) {

                ReleaseLock();
                return 0;
            }

            // move the index along
            slotArrayIndex++;
        }

        // move to the next one
        pListEntry = pListEntry->Flink;
    }


    ReleaseLock();

    return slotCount;
}



///////////////////////////////////////////////////////////////////////////////
//  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 + -