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

📄 sdbus.cpp

📁 S3C2450BSP开发包,里面有很多资料。可以提供大家参考下。有什么需要解决问题。可以联系我QQ:314661
💻 CPP
📖 第 1 页 / 共 5 页
字号:
VOID CSDHostContainer::SDHCDPowerUpDown__X(PSDCARD_HC_CONTEXT  pExternalHCContext, 
                         BOOL                PowerUp, 
                         BOOL                SlotKeepPower,
                         DWORD               SlotIndex)
{
    
    CSDHost * psdHost  = GetSDHost((CSDHost *)pExternalHCContext) ;
    if (psdHost ) {
        CSDSlot * psdSlot = psdHost->GetSlot(SlotIndex) ;
        if (psdHost->IsAttached() && psdSlot) {
            if (PowerUp){
                psdSlot->PowerUp();        
            } else {
                psdSlot->PowerDown(SlotKeepPower);
            }
        }
        psdHost->DeRef();
    }
    else {
        RETAILMSG(1, (TEXT("SDBusDriver: Passed invalid SDCARD_HC_CONTEXT \n")));
        DEBUGCHK(FALSE);
        return;
    }
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDIndicateBusRequestComplete - indicate to the bus driver that
//                                   the request is complete
// Input:   pExternalHCContext - host controller context
//          pRequest   - the request to indicate
//          Status     - the ending status of the request
// Output:
// Return:  
// Notes:       
//
//      
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDIndicateBusRequestComplete__X(PSDCARD_HC_CONTEXT pExternalHCContext,
                                        PSD_BUS_REQUEST    pRequest,
                                        SD_API_STATUS      Status)
{
    CSDBusRequest * pBusRequest = (CSDBusRequest *) pRequest;
    DWORD   dwSDHCIndex = MAXDWORD;
    DWORD   dwSlotIndex = MAXDWORD;
    BOOL    fResult = FALSE;
    if (pBusRequest) {
        __try {
            dwSDHCIndex = pBusRequest->GetDevice().GetSlot().GetHost().GetIndex();
            dwSlotIndex = pBusRequest->GetDevice().GetSlot().GetSlotIndex();
        }
        __except(EXCEPTION_EXECUTE_HANDLER)  {
        }
    }
    CSDHost * psdHost  = GetSDHost( dwSDHCIndex ) ;
    if (psdHost && (PSDCARD_HC_CONTEXT)psdHost == pExternalHCContext) {
        CSDSlot * psdSlot = psdHost->GetSlot(dwSlotIndex) ;
        if (psdSlot) {
            fResult = psdSlot->CompleteRequestFromHC(pBusRequest, Status);
        }
    }
    ASSERT(fResult);
    if (psdHost ) {
        psdHost->DeRef();
    }
    
    
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDGetAndLockCurrentRequest - get the current request in the host controller
//                                 slot and lock it to keep it from being cancelable
// Input:   pExternalHCContext - host controller context   
//          SlotIndex  - the slot number 
// Output:
// Return: current bus request       
// Notes:
//          This function retrieves the current request and marks the
//          request as NON-cancelable.  To return the request back to the
//          cancelable state the caller must call SDHCDUnlockRequest()     
//          This function returns the current request which can be NULL if 
//          the request was previously marked cancelable and the host controller's
//          cancelIo Handler completed the request 
///////////////////////////////////////////////////////////////////////////////
PSD_BUS_REQUEST CSDHostContainer::SDHCDGetAndLockCurrentRequest__X(PSDCARD_HC_CONTEXT pExternalHCContext, DWORD SlotIndex)
{
    DWORD   dwSDHCIndex = MAXDWORD;
    CSDBusRequest * pBusRequest = NULL;
    if (pExternalHCContext) {
        __try {
            dwSDHCIndex =( (CSDHost *) pExternalHCContext)->GetIndex();
        }
        __except(EXCEPTION_EXECUTE_HANDLER)  {
        }
    }
    CSDHost * psdHost  = GetSDHost( dwSDHCIndex ) ;
    if (psdHost && (PSDCARD_HC_CONTEXT)psdHost == pExternalHCContext) {
        CSDSlot * psdSlot = psdHost->GetSlot(SlotIndex) ;
        if (psdSlot) {
            pBusRequest = psdSlot->SDHCGetAndLockCurrentRequest_I();
        }
    }
    //ASSERT(pBusRequest);
    if (psdHost ) {
        psdHost->DeRef();
    }
    return (pBusRequest!=NULL? (PSD_BUS_REQUEST)pBusRequest: NULL);
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDUnlockRequest - Unlock a request that was previous locked
//                             
// Input:   pHCContext - host controller context   
//          pRequest  - the request to lock
// Output:
// Return:      
// Notes:   This function unlocks the request that was returned from the
//          function SDHCDGetAndLockCurrentRequest()
//          
//          This request can now be cancelled from any thread context
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDUnlockRequest__X(PSDCARD_HC_CONTEXT  pExternalHCContext,PSD_BUS_REQUEST pRequest)
{
    DWORD   dwSDHCIndex = MAXDWORD;
    DWORD   dwSlotIndex = MAXDWORD;
    BOOL    fSuccess = FALSE;
    if (pExternalHCContext) {
        __try {
            dwSDHCIndex =( (CSDHost *) pExternalHCContext)->GetIndex();
            dwSlotIndex = ((CSDBusRequest *)pRequest)->GetDevice().GetSlot().GetSlotIndex();
        }
        __except(EXCEPTION_EXECUTE_HANDLER)  {
        }
    }
    CSDHost * psdHost  = GetSDHost( dwSDHCIndex ) ;
    if (psdHost && (PSDCARD_HC_CONTEXT)psdHost == pExternalHCContext) {
        CSDSlot * psdSlot = psdHost->GetSlot(dwSlotIndex) ;
        if (psdSlot) {
            psdSlot->SDHCDUnlockRequest_I(pRequest) ;
            fSuccess = TRUE;
        }
    }
    if (psdHost ) {
        psdHost->DeRef();
    }
    ASSERT(fSuccess);
}



///////////////////////////////////////////////////////////////////////////////
//  SDRegisterClient__X - register a client device
//  Input:  hDevice         - device handle
//          pDeviceContext  - device specific context allocated by driver
//          pInfo           - registration information
//          
//  Output: 
//  Notes:  
//      returns SD_API_STATUS_SUCCESS
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDRegisterClient__X(HANDLE  hDevice,PVOID pDeviceContext, PSDCARD_CLIENT_REGISTRATION_INFO pInfo)
{
    SD_API_STATUS   status = SD_API_STATUS_INVALID_PARAMETER;  // intermediate status
    CSDDevice *     pDevice  = CSDHostContainer::GetDeviceByDevice(hDevice);
    if (pDevice) {
        __try {
            status = pDevice->RegisterClient(NULL,pDeviceContext, pInfo);
        }
        __except (SDProcessException(GetExceptionInformation())) {
            status = SD_API_STATUS_ACCESS_VIOLATION;
        }
        pDevice->DeRef();
    }
    DEBUGMSG(SDCARD_ZONE_ERROR && !SD_API_SUCCESS(status), (TEXT("SDRegisterClient: Failed to register client 0x%08X \n"),status));
    return status;
}
///////////////////////////////////////////////////////////////////////////////
//  SDSynchronousBusRequest__X - send an SD Bus request synchronously
//  Input:  hDevice -  device handle
//          Command - command to send
//          Argument - argument for command
//          TransferClass - Command only, or associated with read/write data
//          ResponseType - expected response
//          pResponse - buffer to hold response (OPTIONAL)
//          NumBlocks   - number of blocks
//          BlockSize   - block size
//          pBuffer     - block buffer
//          Flags       - bus request flags
//          
//  Output: pResponse - caller allocated storage for the return response 
//  Return: SD_API_STATUS
//  Notes:  
//        This function provides a synchronous (blocking) call to perform a 
//        bus request.  
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDSynchronousBusRequest__X(SD_DEVICE_HANDLE       hDevice, 
                                         UCHAR                  Command,
                                         DWORD                  Argument,
                                         SD_TRANSFER_CLASS      TransferClass,
                                         SD_RESPONSE_TYPE       ResponseType,
                                         PSD_COMMAND_RESPONSE   pResponse,
                                         ULONG                  NumBlocks,
                                         ULONG                  BlockSize,
                                         PUCHAR                 pBuffer,
                                         DWORD                  Flags)
{
    SD_API_STATUS   status = SD_API_STATUS_INVALID_PARAMETER;  // intermediate status
    CSDDevice *     pDevice = CSDHostContainer::GetDeviceByDevice((HANDLE)hDevice);
    if (pDevice) {
        __try {
        
#ifdef FOR_MOVI_NAND
/*************************************************************************/
/****** Date : 07.05.28                                         	******/
/****** Developer : HS.JANG											******/
/****** Description : If moviNAND use Multi block r/w, we must use	******/
/******               pre-define. Open-end can cause wrong operation******/
/*************************************************************************/
        	if ( Flags == SD_MOVINAND_PRE_DEFINE )
        	{
        		SD_COMMAND_RESPONSE ResponseValue = {ResponseR1,{0}};
	        	status = pDevice->SDSynchronousBusRequest_I(MMC_CMD_SET_BLOCK_LENGTH,NumBlocks,SD_COMMAND,ResponseR1,&ResponseValue,0,0,NULL,0);
			}
/*************************************************************************/    
#endif        
      	
            status = pDevice->SDSynchronousBusRequest_I(Command,Argument,TransferClass,ResponseType,pResponse,NumBlocks,BlockSize,pBuffer,Flags);
        }
        __except (SDProcessException(GetExceptionInformation())) {
            status = SD_API_STATUS_ACCESS_VIOLATION;
        }
        pDevice->DeRef();
    }
    DEBUGMSG(SDCARD_ZONE_ERROR && !SD_API_SUCCESS(status), (TEXT("SDSynchronousBusRequest__X: Failed status 0x%08X \n"),status));
    return status;
}
///////////////////////////////////////////////////////////////////////////////
//  SDBusRequest__I - send command over SD bus
//  Input:  pHandle       - SD bus device structure
//          Command       - SD command to send over bus
//          Argument      - 32 bit argument specific to the command
//          TransferClass - Command only, or associated with read/write data
//          ResponseType  - Response Type for the command
//          NumBlocks     - Number of data blocks in pBlockArray, can be zero
//                          if transfer class is not read or write
//          BlockSize     - Size of data blocks in pBlockArray. All blocks
//                          must be same size.
//          pBuffer       - Pointer to buffer containing BlockSize*NumBlocks bytes
//          pCallback     - completion callback
//          RequestParam    - optional driver specific parameter for this request
//          Flags         - bus request flags
//          fExtern       - True for calling from external.
//  Output: ppRequest     - newly allocated request
//  Return: SD_API_STATUS
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDBusRequest__X(SD_DEVICE_HANDLE         hDevice,
                              UCHAR                    Command,
                              DWORD                    Argument,
                              SD_TRANSFER_CLASS        TransferClass,
                              SD_RESPONSE_TYPE         ResponseType,
                              ULONG                    NumBlocks,
                              ULONG                    BlockSize,
                              PUCHAR                   pBuffer,
                              PSD_BUS_REQUEST_CALLBACK pCallback,
                              DWORD                    RequestParam,
                              HANDLE                   * phRequest,
                              DWORD                    Flags)
{
    SD_API_STATUS   status = SD_API_STATUS_INVALID_PARAMETER;  // intermediate status
    CSDDevice *     pDevice = CSDHostContainer::GetDeviceByDevice((HANDLE)hDevice);
    if (pDevice) {
        __try {
            status = pDevice->SDBusRequest_I(Command,Argument,TransferClass,ResponseType,NumBlocks,BlockSize,pBuffer,
                    pCallback,RequestParam,phRequest,Flags);
        }
        __except (SDProcessException(GetExceptionInformation())) {
            status = SD_API_STATUS_ACCESS_VIOLATION;
        }
        pDevice->DeRef();
    }
    DEBUGMSG(SDCARD_ZONE_ERROR && !SD_API_SUCCESS(status), (TEXT("SDBusRequest__X: Failed status 0x%08X \n"),status));
    return status;
}
///////////////////////////////////////////////////////////////////////////////
//  SDFreeBusRequest__X - free this request
//  Input:  pRequest  - the request to free     
//  Output: 
//  Return: 
//  Notes:
//          this function returns the bus request back to the memory look aside 
//          list
///////////////////////////////////////////////////////////////////////////////
VOID SDFreeBusRequest__X(HANDLE  hRequest)
{
    CSDDevice *     pDevice = CSDHostContainer::GetDeviceByRequest((HANDLE)hRequest);
    if (pDevice) {
        pDevice->SDFreeBusRequest_I((HANDLE)hRequest);
        pDevice->DeRef();
    }
    else
        DEBUGMSG(SDCARD_ZONE_ERROR , (TEXT("SDFreeBusRequest__X: Failed:wrong Handle 0x%08X \n"),hRequest));
}
///////////////////////////////////////////////////////////////////////////////
//  SDCardInfoQuery__X - Obtain Card information
//  Input:  hHandle        - SD Device Handle
//          InfoType       - information to get
//          StructureSize  - size of info

⌨️ 快捷键说明

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