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

📄 sddevinf.cpp

📁 6410BSP3
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:  
    SDDevInfo.cpp
Abstract:
    SDBus Implementation.

Notes: 
--*/
#include <windows.h>
#include <types.h>
#include <safeint.hxx>

#include "../HSMMCCh1/s3c6410_hsmmc_lib/sdhcd.h"

#include "sdbus.hpp"
#include "sdslot.hpp"
#include "sdbusreq.hpp"
#include "sddevice.hpp"

BOOL  CSDDevice::IsHighCapacitySDMemory()
{
    if (m_DeviceType == Device_SD_Memory || m_DeviceType == Device_MMC || m_DeviceType == Device_SD_Combo ) {
        return ( (m_CachedRegisters.OCR[3] & 0x40)!=0) ; // OCR Bit 30 is Card Capacity Status bit.
    }
    else 
        return FALSE;
}

///////////////////////////////////////////////////////////////////////////////
//  SDGetTuple__X  - Get tuple data from CIS
//  Input:  hDevice     - SD bus device handle
//          TupleCode   - Tuple code
//          pBufferSize - size of buffer to store Tuple Data
//          CommonCIS   - flag indicating common or function CIS
//  Output: pBuffer     - Tuple data is copied here (optional)
//          pBufferSize - if pBuffer is NULL, this will store the size of the
//                        tuple
//  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.
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDDevice::SDGetTuple_I(UCHAR TupleCode,PUCHAR pBuffer,PULONG pBufferSize,BOOL CommonCIS)
{
    SD_API_STATUS status = SD_API_STATUS_SUCCESS;  // intermediate status
    UCHAR                  tCode;                  // tuple code we've read so far
    UCHAR                  tupleLink;              // tuple link offset
    ULONG                  currentOffset;          // current offset

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDCard: +SDGetTuple\n")));


    if (NULL == pBufferSize) {
        DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDGetTuple: NULL buffer size \n")));
        return SD_API_STATUS_INVALID_PARAMETER;
    }

    if (pBuffer == NULL) {
        // Initialize pBufferSize to zero to indicate that the tuple 
        // was not found
        *pBufferSize = 0; 
    }
    
    currentOffset = 0;
    // walk through the CIS
    while (TRUE) {

        // get 1 byte at the current position
        status = SDGetTupleBytes(currentOffset,  &tCode, 1, CommonCIS);

        if (!SD_API_SUCCESS(status)) {
            break;
        }
        // add the tCode
        currentOffset += 1;

        if(SD_CISTPL_END == tCode) {
            // this is the End of chain Tuple
            // break out of while loop
            break;

        } else  {

            // get the tuple link offset in the next byte, we always need this
            // value, so we fetch it before we compare the tuple code
            status = SDGetTupleBytes(currentOffset, &tupleLink, 1, CommonCIS);

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

            // add the link
            currentOffset += 1;

            // check for the end link flag, this is the alternative method to stop
            // tuple scanning
            if (SD_TUPLE_LINK_END == tupleLink) {
                // we reached an end of chain
                break;
            }
            // go back and check the tuple code
            if (tCode == TupleCode) {
                // found it

                // check to see if the caller is interested in the data
                if (NULL != pBuffer) {

                    // if the user passed a buffer, they must pass the buffer size, double check the length
                    if (*pBufferSize < tupleLink) {
                        DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDCard: SDGetTuple, caller supplied buffer of size: %d bytes but tuple body (code=0x%02X) reports size of %d bytes\n"),
                            *pBufferSize, tCode, tupleLink));    
                        status = SD_API_STATUS_INVALID_PARAMETER;
                        break;
                    }

                    // fetch the tuple body
                    status = SDGetTupleBytes(currentOffset, 
                        pBuffer, 
                        tupleLink, 
                        CommonCIS);

                } else {

                    // return the size of the tuple body we just found, no need to fetch
                    *pBufferSize = tupleLink;
                }
                // break out of the while loop 
                break;

            } else {

                // add the value of the link
                currentOffset += tupleLink;
            }

        } 

    }

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDCard: -SDGetTuple\n")));
    return status;
}
///////////////////////////////////////////////////////////////////////////////
//  SDGetTupleBytes - Gets tuple bytes at the current tuple offset
//  Input:  hDevice       - SD bus device handle
//          Offset        - offset from the CIS pointer
//          NumberOfBytes - number of bytes to fetch
//          CommonCIS     - flag indicating that this is fetched from the common CIS
//  Output: pBuffer       - Tuple data is copied here (optional)

//  Return: SD_API_STATUS code
//          
//  Notes:
//         If the Buffer pointer is NULL, the function does not fetch the bytes
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDDevice::SDGetTupleBytes(DWORD Offset,PUCHAR pBuffer,ULONG NumberOfBytes,BOOL CommonCIS)
{
    SD_API_STATUS          status;          // intermediate status
    DWORD                  tupleAddress;    // calculated tuple address


    status = SD_API_STATUS_INVALID_PARAMETER;

    if (m_DeviceType == Device_SD_IO || m_DeviceType == Device_SD_Combo ) {
        if (CommonCIS) {
            if (m_FuncionIndex!=0) {
                CSDDevice * psdDevice0 = m_sdSlot.GetFunctionDevice(0);
                if (psdDevice0) {
                    status = psdDevice0->SDGetTupleBytes(Offset,pBuffer,NumberOfBytes, CommonCIS);
                    psdDevice0->DeRef();
                }
                return status;
            }
            else {
                DEBUGCHK(NULL != m_SDCardInfo.SDIOInformation.pCommonInformation);
                DEBUGCHK(0 != m_SDCardInfo.SDIOInformation.pCommonInformation->CommonCISPointer);
                // the tuple starting address is at the common CIS pointer
                tupleAddress = m_SDCardInfo.SDIOInformation.pCommonInformation->CommonCISPointer;
            }
        } else { 
            DEBUGCHK(0 != m_SDCardInfo.SDIOInformation.CISPointer);
            // the tuple starting address is at the function CIS pointer
            tupleAddress = m_SDCardInfo.SDIOInformation.CISPointer;
        }

        // add the desired offset
        tupleAddress += Offset;

        if (NULL != pBuffer) {
            CSDDevice * psdDevice0 = m_sdSlot.GetFunctionDevice(0);
            if (psdDevice0) {
                status = psdDevice0->SDReadWriteRegistersDirect_I( SD_IO_READ,tupleAddress,FALSE,pBuffer,NumberOfBytes); 
                psdDevice0->DeRef();
            }

        }
    }
    ASSERT(SD_API_SUCCESS(status));
    return status;
}

//Structure definiton of SDIO Version 1.0 term
typedef struct _SDIO_TPLFID_FUNC17_V10 {
    UCHAR   ExtendedDataType;
    UCHAR   FunctionInfo;
    UCHAR   StandardRev;
    USHORT  CardPSN;
    USHORT  CSASize;
    UCHAR   CSAProperty;
    USHORT  MaxBlockSize;
    USHORT  OCR;
    UCHAR   OpMinPwr;
    UCHAR   OpAvgPwr;
    UCHAR   OpMaxPwr;
    UCHAR   StbyMinPwr;
    UCHAR   StbyAvgPwr;
    UCHAR   StbyMaxPwr;
    USHORT  MinBandwidth;
    USHORT  OptimalBandwidth;
}SDIO_TPLFID_FUNC17_V10, *P_SDIO_TPLFID_FUNC17_V10;

//Structure definiton of SDIO Version 1.10 added term
typedef struct _SDIO_TPLFID_FUNC17_V11 {
    USHORT  EnableTimoutVal;
    USHORT  SpAvePwr33V;
    USHORT  SpMaxPwr33V;
    USHORT  HpAvePwr33V;
    USHORT  HpMaxPwr33V;
    USHORT  LpAvePwr33V;
    USHORT  LpMaxPwr33V;
}SDIO_TPLFID_FUNC17_V11, *P_SDIO_TPLFID_FUNC17_V11;

///////////////////////////////////////////////////////////////////////////////
//  SDGetFunctionPowerControlTuples - Get SDIO Power control Tuples for an SDIO device function
//  Input:  pDevice         - the device context
//  Output: pPowerDrawData  - Data about function's power draw
//  Return: SD_API_STATUS code
//  Notes:  
//         This function collects pwer draw data for a SD function 
//         via the tuple CITPL_FUNCE (extended 0x01).
//         
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDDevice::SDGetFunctionPowerControlTuples() 
{
    SD_API_STATUS               status;             // intermediate status
    ULONG                       length;             // tuple length
    UCHAR                       buffer[SD_CISTPLE_MAX_BODY_SIZE]; //tupple info
    P_SDIO_TPLFID_FUNC17_V10    pV1FunctionTuple;   // SDIO V1.0 Function Tuple
    P_SDIO_TPLFID_FUNC17_V11    pV11FunctionTupleExt;// SDIO V1.1 Extentions to Function Tuple
    PSD_FUNCTION_POWER_DRAW     pPowerDrawData = &m_SDCardInfo.SDIOInformation.PowerDrawData;

    length = 0;

        // get the FUNCE tuple
    status = SDGetTuple_I( SD_CISTPL_FUNCE, NULL, &length, FALSE);

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

    if (0 == length) {
        DbgPrintZo(SDCARD_ZONE_ERROR, 
            (TEXT("SDBusDriver: Card does not have FUNCE tuple! \n")));
           return SD_API_STATUS_DEVICE_UNSUPPORTED;
    } else {

        if (length < sizeof(SDIO_TPLFID_FUNC17_V10)) {
             DbgPrintZo(SDCARD_ZONE_ERROR, 
                (TEXT("SDBusDriver: Function tuple reports size of %d , expecting %d or greater\n"),
                length, sizeof(SDIO_TPLFID_FUNC17_V10)));
            return SD_API_STATUS_DEVICE_UNSUPPORTED;   
        }

            // get the tplIDfunction tuple 
        status = SDGetTuple_I(SD_CISTPL_FUNCE,(PUCHAR)buffer,&length,FALSE);

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

        if (buffer[0] != 0x01) {
             DbgPrintZo(SDCARD_ZONE_ERROR, 
                (TEXT("SDBusDriver: Tuple is not Extended Data type: %d \n"),
                buffer[0]));
            return SD_API_STATUS_DEVICE_UNSUPPORTED;   
        }

        pV1FunctionTuple = (P_SDIO_TPLFID_FUNC17_V10)buffer;

        pPowerDrawData->OpMinPower = pV1FunctionTuple->OpMinPwr;
        pPowerDrawData->OpAvePower = pV1FunctionTuple->OpAvgPwr;
        pPowerDrawData->OpMaxPower = pV1FunctionTuple->OpMaxPwr;


        if (length < (sizeof(SDIO_TPLFID_FUNC17_V10) + sizeof(SDIO_TPLFID_FUNC17_V11))) {
            pPowerDrawData->SpAvePower33 = 0;
            pPowerDrawData->SpMaxPower33 = 0;

            pPowerDrawData->HpAvePower33 = 0;
            pPowerDrawData->HpMaxPower33 = 0;

            pPowerDrawData->LpAvePower33 = 0;
            pPowerDrawData->LpMaxPower33 = 0;
        }
        else
        {
            pV11FunctionTupleExt = (P_SDIO_TPLFID_FUNC17_V11)(&buffer[sizeof(SDIO_TPLFID_FUNC17_V10)]);

            pPowerDrawData->SpAvePower33 = pV11FunctionTupleExt->SpAvePwr33V;
            pPowerDrawData->SpMaxPower33 = pV11FunctionTupleExt->SpMaxPwr33V;

⌨️ 快捷键说明

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