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

📄 sdcardio.cpp

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                FALSE,
                &regValue,   // reg
                1);         // one byte
            if (!SD_API_SUCCESS(status)) {
                break;
            }

            // see if it is ready
            if (regValue & (1 << pDevice->SDCardInfo.SDIOInformation.Function)) {
                DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDEnableDisableFunction: Card Function %d is now ready \n"),
                    pDevice->SDCardInfo.SDIOInformation.Function));
                break;
            }
            // decrement the count
            retryCount--; 
            DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDEnableDisableFunction: Card Function %d, Not Ready, re-checking (%d) \n"),
                pDevice->SDCardInfo.SDIOInformation.Function, retryCount));
        }

        if (0 == retryCount) {
            DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDEnableDisableFunction: Card Function %d, Not ready , exceeded retry count\n"),
                pDevice->SDCardInfo.SDIOInformation.Function));
            status = SD_API_STATUS_DEVICE_NOT_RESPONDING;
        }
    }

    return status;
} 


///////////////////////////////////////////////////////////////////////////////
//  SDFunctionSelectPower  - switch device function to High or Low power state
//  Input:  pDevice   - the device 
//          fLowPower - High or Low Power state
//  Output: 
//  Return: SD_API_STATUS code
//          
//  Notes: 
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDFunctionSelectPower(PSDCARD_DEVICE_CONTEXT      pDevice,
                                    BOOL                        fLowPower)
{
    PSDCARD_DEVICE_CONTEXT      pParentDevice;  // parent device
    UCHAR                       regValue;       // temp register value
    SD_API_STATUS               status;         // intermediate status
    FUNCTION_POWER_STATE        PowerState;     // The function's power state
    PSD_CHANGE_CARD_POWER       pPowerChangeHandler;   
    DWORD                       FBROffset;      // calculated FBR offset
    CSDBusDriver                *pBusDriver;    // Pointer to the bus driver class


        // get the parent device
    pParentDevice = pDevice->pParentDevice;
    
    if (NULL == pParentDevice) {
        DEBUG_ASSERT(FALSE);
        return SD_API_STATUS_INVALID_PARAMETER;
    }

    DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDFunctionSelectPower: SDIO Device Function %d Power Select\n"),
                                        pDevice->SDCardInfo.SDIOInformation.Function));

    		// Get a pointer to the bus driver calss
	pBusDriver = SDDCGetBusDriver(pDevice);
    
        // Get the functions power state
    status = pBusDriver->GetFunctionPowerState(pDevice, &PowerState);

    if (!SD_API_SUCCESS(status)) {
        return status;
    }

        //check if power selection is supported
    if((!PowerState.fPowerControlSupport) ||
       (!PowerState.fSupportsPowerSelect))
    {
        DEBUGMSG(SDCARD_ZONE_ERROR, 
                    (TEXT("SDFunctionSelectPower: Card or Function does not support Power Select.\n")));
        return SD_API_STATUS_INVALID_DEVICE_REQUEST;
    }

        // Check if states already match
    if (PowerState.fLowPower == fLowPower)
    {
        if (fLowPower) { 
            DEBUGMSG(SDCARD_ZONE_WARN, 
                    (TEXT("SDFunctionSelectPower: Attempting to select low power state when that is already enabled \n")));
        }
        else
        {
            DEBUGMSG(SDCARD_ZONE_WARN, 
                    (TEXT("SDFunctionSelectPower: Attempting to select high power state when that is already enabled \n")));
        }

        return SD_API_STATUS_SUCCESS;
    }
        
        // Attempt to change card's power draw
    pPowerChangeHandler = SDHCDGetChangePowerHandler(pDevice->pSlot->pHostController);
    status = pPowerChangeHandler(pDevice->pSlot->pHostController, pDevice->pSlot->SlotIndex, PowerState.SelectDelta);

    if (!SD_API_SUCCESS(status)) {
        return status;
    }

        //update the power used at the slot
    {
        INT SlotPower = (INT)SDHCDGetSlotPower(pDevice->pSlot->pHostController, pDevice->pSlot->SlotIndex);

        SlotPower += PowerState.SelectDelta;

        if(SlotPower >= 0)
        {
            SDHCDSetSlotPower(pDevice->pSlot->pHostController, pDevice->pSlot->SlotIndex, (USHORT)SlotPower);
        }
        else
        {
            SDHCDSetSlotPower(pDevice->pSlot->pHostController, pDevice->pSlot->SlotIndex, 0);
        }
    }

        // select the function's power state
    FBROffset = SD_IO_FBR_1_OFFSET + (pDevice->SDCardInfo.SDIOInformation.Function - 1) * SD_IO_FBR_LENGTH;

    status = SDReadWriteRegistersDirect__X((SD_DEVICE_HANDLE)pDevice,
                                        SD_IO_READ,          
                                        0,          // all from function 0
                                        FBROffset + SD_IO_FBR_POWER_SELECT,
                                        FALSE,
                                        &regValue,
                                        1); 

    if (!SD_API_SUCCESS(status)) {
        return status;
    }

    if(fLowPower)
    {
        regValue |= SD_IO_FUNCTION_POWER_SELECT_STATE;
    }
    else
    {
        regValue &= ~SD_IO_FUNCTION_POWER_SELECT_STATE;
    }

    status = SDReadWriteRegistersDirect__X((SD_DEVICE_HANDLE)pDevice,
                                        SD_IO_WRITE,
                                        0,           // function 0
                                        FBROffset + SD_IO_FBR_POWER_SELECT,
                                        FALSE,        
                                        &regValue,
                                        1);

    return status;
} 


///////////////////////////////////////////////////////////////////////////////
//  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
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDSetCardFeature__X(SD_DEVICE_HANDLE     hDevice,
                                  SD_SET_FEATURE_TYPE  CardFeature,
                                  PVOID                pCardInfo,
                                  ULONG                StructureSize)
{
    SD_API_STATUS               status = SD_API_STATUS_SUCCESS;  // intermediate status
    PSD_DATA_TRANSFER_CLOCKS    pClocks;                         // data transfer clocks variable  

    PSDCARD_DEVICE_CONTEXT pDevice = (PSDCARD_DEVICE_CONTEXT) hDevice;
    if (!ValidateClientHandle(pDevice)) {
        return SD_API_STATUS_INVALID_HANDLE;
    }

    if (NULL == pDevice) {
        DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device handle is NULL \n")));
        return SD_API_STATUS_INVALID_PARAMETER;
    }

    switch (CardFeature) {

        case SD_IO_FUNCTION_ENABLE:
            if ((sizeof(SD_IO_FUNCTION_ENABLE_INFO) != StructureSize) || 
                (NULL == pCardInfo)) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_IO_FUNCTION_ENABLE - Invalid params \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                if (Device_SD_IO != pDevice->DeviceType) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                status = SDEnableDisableFunction(pDevice, (PSD_IO_FUNCTION_ENABLE_INFO)pCardInfo, TRUE);

                break;

        case SD_IO_FUNCTION_DISABLE:
            if (Device_SD_IO != pDevice->DeviceType) {
                DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
                return SD_API_STATUS_INVALID_PARAMETER;
            }

            status = SDEnableDisableFunction(pDevice, NULL, FALSE);

            break;

		case SD_IO_FUNCTION_HIGH_POWER:         
            if (Device_SD_IO != pDevice->DeviceType) {
                DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
                return SD_API_STATUS_INVALID_PARAMETER;
            }

            status = SDFunctionSelectPower(pDevice, FALSE);
            break;

        case SD_IO_FUNCTION_LOW_POWER:
            if (Device_SD_IO != pDevice->DeviceType) {
                DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
                return SD_API_STATUS_INVALID_PARAMETER;
            }

            status = SDFunctionSelectPower(pDevice, TRUE);
            break;

        case SD_INFO_POWER_CONTROL_STATE:
            {
                CSDBusDriver                *pBusDriver;    // Pointer to the bus driver class

                if ((sizeof(FUNCTION_POWER_STATE) != StructureSize) || 
                    (NULL == pCardInfo)) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, 
                        (TEXT("SDSetCardFeature: SD_INFO_POWER_CONTROL_STATE - Invalid params \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                if (Device_SD_IO != pDevice->DeviceType) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                		// Get a pointer to the bus driver calss
            	pBusDriver = SDDCGetBusDriver(pDevice);

                status = pBusDriver->GetFunctionPowerState(pDevice, (PFUNCTION_POWER_STATE)pCardInfo);
            }
            break;

        case SD_IO_FUNCTION_SET_BLOCK_SIZE:
            if ((sizeof(DWORD) != StructureSize) || 
                (NULL == pCardInfo)) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_IO_FUNCTION_SET_BLOCK_SIZE - Invalid params \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                if (Device_SD_IO != pDevice->DeviceType) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                status = SDSetFunctionBlockSize(pDevice, *((DWORD *)pCardInfo));
                break;

        case SD_SET_DATA_TRANSFER_CLOCKS:
            if ((sizeof(SD_DATA_TRANSFER_CLOCKS) != StructureSize) || 
                (NULL == pCardInfo)) {
                    DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_SET_DATA_TRANSFER_CLOCKS - Invalid params \n")));
                    return SD_API_STATUS_INVALID_PARAMETER;
                }

                pClocks = (PSD_DATA_TRANSFER_CLOCKS)pCardInfo;
                pDevice->SDCardInfo.SDMMCInformation.DataAccessReadClocks = pClocks->ReadClocks;
                pDevice->SDCardInfo.SDMMCInformation.DataAccessWriteClocks = pClocks->WriteClocks;

                status = SD_API_STATUS_SUCCESS;
                break;

⌨️ 快捷键说明

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