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

📄 bspsdhc.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 C
📖 第 1 页 / 共 2 页
字号:
// BSP specific initialization
//
// Parameters:
//      ControllerIndex [in]		SDHC controller index 
//
// Returns:
//      TRUE if success 
//
//------------------------------------------------------------------------------
BOOL BSPSdhcInit(void) 
{
	return TRUE  ; 
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcIsCardPresent
//
// function to check card existence
//
// Parameters:
//      pSpecificContext [in]		pointer to the structure 
//
// Returns:
//      TRUE if success 
//
//------------------------------------------------------------------------------
BOOL BspSdhcIsCardPresent(PVOID pSpecificContext)
{

    BOOL card_exist = TRUE;
    PBSP_SDHC_CONTEXT pBspContext ; 
    PHYSICAL_ADDRESS phyAddr;
    CSP_PBC_REGS *pPBC;


    pBspContext = (PBSP_SDHC_CONTEXT)pSpecificContext ;

    phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;

    // Map PBC registers to virtual address space
    pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
    if (pPBC == NULL)
    {
        DEBUGMSG(1,
            (TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }

    if(pBspContext->dwControllerIndex == 1 )
    {
        // read from CPLD whether card exit,  1 = SD card is not Detected
        if (EXTREG16BF(&pPBC->BSTAT1, PBC_BSTAT1_SD1_DET) )
			card_exist = FALSE;
    }
    else if(pBspContext->dwControllerIndex == 2 )
    {
        //read from CPLD whether card exit
        if (EXTREG16BF(&pPBC->BSTAT1, PBC_BSTAT1_SD2_DET) )
		     card_exist = FALSE;
    }
    else if(pBspContext->dwControllerIndex == 3 )
    {
        //read from CPLD whether card exit
        if (EXTREG16BF(&pPBC->BSTAT1, PBC_BSTAT1_SD3_DET) )
		     card_exist = FALSE;
    }

     // free the virtual space allocated for PBC memory map
    MmUnmapIoSpace(pPBC, sizeof(CSP_PBC_REGS));
	
    return card_exist;

}
//------------------------------------------------------------------------------
//
// Function: BspSdhcCardDetectDeinitialize
//
// function to clean up preiously configured iomux, gpio 
//
// Parameters:
//      pSpecificContext [in]		pointer to the structure 
//
// Returns:
//
//------------------------------------------------------------------------------
void BspSdhcCardDetectDeinitialize(PVOID pSpecificContext)
{
    PBSP_SDHC_CONTEXT pBspContext ; 
    DDK_GPIO_CFG cfg,cfg2;
	
    pBspContext = (PBSP_SDHC_CONTEXT)pSpecificContext ; 

    if(pBspContext->dwControllerIndex == 1)
    {
        //disable the GPIO pins
        DDK_GPIO_SET_CONFIG(cfg, SDHC1);
        DDKGpioDisable(&cfg);
    }
    else if(pBspContext->dwControllerIndex == 2)
    {
        //disable the GPIO pins
        DDK_GPIO_SET_CONFIG(cfg, SDHC2);
        DDKGpioDisable(&cfg);
    }
    else if(pBspContext->dwControllerIndex == 3)
    {
        //disable the GPIO pins
        DDK_GPIO_SET_CONFIG(cfg, SDHC3);
        DDKGpioDisable(&cfg);
        DDK_GPIO_SET_CONFIG(cfg2, SDHC3_DA);
        DDKGpioDisable(&cfg2);
    }
}


//------------------------------------------------------------------------------
//
// Function: BspSdhcCardDetectInterruptType
//
// function to setup iomux, gpio 
//
// Parameters:
//      ControllerIndex [in]		SDHC controller index 
//      DetectType[in]                  TRUE:  Detect Card insert; FLASE: Detect Card Remove 
//
// Returns: pointer to the BSP context
//
//------------------------------------------------------------------------------
PVOID BspSdhcCardDetectInterruptType(DWORD ControllerIndex, BOOL  DetctType)
{
    PHYSICAL_ADDRESS phyAddr;
    CSP_PBC_REGS *pPBC;

    phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;

    // Map PBC registers to virtual address space
    pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
    if (pPBC == NULL)
    {
        DEBUGMSG(1,  (TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }

    if(DetctType)
    {   
        //Detect Card insert 
        if(ControllerIndex == 1)
        {
    		OUTREG16(&pPBC->INT_MASK_CLEAR,  CSP_BITFMASK(PBC_INT_MASK_SD1_R_EN));
			OUTREG16(&pPBC->INT_MASK_SET,  CSP_BITFMASK(PBC_INT_MASK_SD1_EN));
        }
        else if(ControllerIndex == 2)
        {
            OUTREG16(&pPBC->INT_MASK_CLEAR,  CSP_BITFMASK(PBC_INT_MASK_SD2_R_EN));
			OUTREG16(&pPBC->INT_MASK_SET,  CSP_BITFMASK(PBC_INT_MASK_SD2_EN));
        }
        else if(ControllerIndex == 3)
        {
    		OUTREG16(&pPBC->INT_MASK_CLEAR,  CSP_BITFMASK(PBC_INT_MASK_SD3_R_EN));
			OUTREG16(&pPBC->INT_MASK_SET,  CSP_BITFMASK(PBC_INT_MASK_SD3_EN));
        }
    }
    else
    {
       //Detect Card Remove
        if(ControllerIndex == 1)
        {
            OUTREG16(&pPBC->INT_MASK_CLEAR,  CSP_BITFMASK(PBC_INT_MASK_SD1_EN));
			OUTREG16(&pPBC->INT_MASK_SET,  CSP_BITFMASK(PBC_INT_MASK_SD1_R_EN));
        }
        else if(ControllerIndex == 2)
        {
            OUTREG16(&pPBC->INT_MASK_CLEAR,  CSP_BITFMASK(PBC_INT_MASK_SD2_EN));
			OUTREG16(&pPBC->INT_MASK_SET,  CSP_BITFMASK(PBC_INT_MASK_SD2_R_EN));
        }
        else if(ControllerIndex == 3)
        {
            OUTREG16(&pPBC->INT_MASK_CLEAR,  CSP_BITFMASK(PBC_INT_MASK_SD3_EN));
			OUTREG16(&pPBC->INT_MASK_SET,  CSP_BITFMASK(PBC_INT_MASK_SD3_R_EN));
        }
    }
    
     // free the virtual space allocated for PBC memory map
    MmUnmapIoSpace(pPBC, sizeof(CSP_PBC_REGS));

    return NULL;
	
}


//------------------------------------------------------------------------------
//
// Function: BspSdhcCardDetectInitialize
//
// function to setup iomux, gpio 
//
// Parameters:
//      ControllerIndex [in]		SDHC controller index 
//
// Returns: pointer to the BSP context
//
//------------------------------------------------------------------------------
PVOID BspSdhcCardDetectInitialize(DWORD ControllerIndex)
{
    PBSP_SDHC_CONTEXT pBspContext = NULL;    

    pBspContext = (PBSP_SDHC_CONTEXT)malloc( sizeof(BSP_SDHC_CONTEXT) );
    if( pBspContext == NULL )
    {
        DEBUGMSG(1 	, (TEXT("SDH: Failed to allocate extension\n")));
        return NULL;
    }
    memset( pBspContext, 0, sizeof(BSP_SDHC_CONTEXT) );

    //Enable SD Detect interrupt pin
    BspSdhcCardDetectInterruptType(ControllerIndex, TRUE);
	
    //Copy Controller Index number from hardware context to card detect context
    pBspContext->dwControllerIndex = ControllerIndex ; 
	
    return pBspContext;
}

//-----------------------------------------------------------------------------
//
// Function: BspSdhcSetGPIO
//
// This function configures IOMUX for successful operation of the SDHC.
//
// Parameters:
//      ControllerIndex [in]    SDHC controller index.
//
// Returns: None
//-----------------------------------------------------------------------------

void  BspSdhcSetGPIO(DWORD ControllerIndex)
{
    BOOL initState;
    DDK_GPIO_CFG cfg,cfg2;
	
    // Enable SDHC pins
    switch (ControllerIndex)
    {
        case 1:
        //config
            DDK_GPIO_SET_CONFIG(cfg, SDHC1);
            initState = DDKGpioEnable(&cfg);
            break;
        case 2:
            DDK_GPIO_SET_CONFIG(cfg, SDHC2);
            initState = DDKGpioEnable(&cfg);
            break;
        case 3:
             DDK_GPIO_SET_CONFIG(cfg, SDHC3);
             initState = DDKGpioEnable(&cfg);
             DDK_GPIO_SET_CONFIG(cfg2, SDHC3_DA);
             initState = DDKGpioEnable(&cfg2);
             break;
         default:
             break;
     }
}

//------------------------------------------------------------------------------
//
// Function: BSPSdhcIsCardWriteProtected
//
// This function is to check whether card is write protected. 
//
// Parameters:
//		 pSpecificContext [in]		pointer to the structure 
//
// Returns:
//      Return TRUE if card is write protected 
//			   FALSE if card is not write protected 
//
//------------------------------------------------------------------------------
BOOL BSPSdhcIsCardWriteProtected(PVOID pSpecificContext)
{
     PBSP_SDHC_CONTEXT pBspContext ; 
     PHYSICAL_ADDRESS phyAddr;
     CSP_PBC_REGS *pPBC;

     pBspContext = (PBSP_SDHC_CONTEXT)pSpecificContext ; 

     phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;

     // Map PBC registers to virtual address space
     pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
	
     if (pPBC == NULL)
     {
          DEBUGMSG(1,
               (TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
          return FALSE;
     }

     if(pBspContext->dwControllerIndex == 1 )
     {
          // read from CPLD whether card write protected ,1 = SD1 card is Write Protected 
          if (EXTREG16BF(&pPBC->BSTAT1, PBC_BSTAT1_SD1_WP) )
               pBspContext->bWriteProtected = TRUE ;
     }
     else if(pBspContext->dwControllerIndex == 2 )
     {
          //read from CPLD whether card write protected, 1 = SD2 card is Write Protected
          if (EXTREG16BF(&pPBC->BSTAT1, PBC_BSTAT1_SD2_WP) )
               pBspContext->bWriteProtected = TRUE ;
     }
     else if(pBspContext->dwControllerIndex == 3 )
     {
          //read from CPLD whether card write protected, 1 = SD3 card is Write Protected
          if (EXTREG16BF(&pPBC->BSTAT1, PBC_BSTAT1_SD3_WP) )
               pBspContext->bWriteProtected = TRUE ;
     }

     // free the virtual space allocated for PBC memory map
     MmUnmapIoSpace(pPBC, sizeof(CSP_PBC_REGS));

     return pBspContext->bWriteProtected;
}

//------------------------------------------------------------------------------
//
// Function: BspSdhcRegisterCardInterrupt
//
// This function is to register card detection interrupt 
//
// Parameters:
//		 pSpecificContext [in]		pointer to the structure 
//		 pSysIntrCardDetect [out]	system interrupt 
//
// Returns:
//      Return TRUE if card is write protected 
//			   FALSE if card is not write protected 
//
//------------------------------------------------------------------------------
HANDLE BspSdhcRegisterCardInterrupt(DWORD *pSysIntrCardDetect)
{
    HANDLE hCardInsertInterruptEvent;     // card insert/remove interrupt event
    DWORD dwCardIrq ; 
	
    // allocate the interrupt event for card insertion
    hCardInsertInterruptEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
    if(NULL == hCardInsertInterruptEvent)
    {
        ERRORMSG(1, (TEXT("SetupCardDetectIST: unable to create card detect event!\r\n")));
        return NULL;
    }

     dwCardIrq = BSP_SDHC_MS_IRQ ;

    // Translate IRQ to SYSINTR
    if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &(dwCardIrq), 
			sizeof(dwCardIrq), pSysIntrCardDetect, 
			sizeof(*pSysIntrCardDetect), NULL))
    {
        ERRORMSG(1,(TEXT("%s: Request SYSINTR failed\r\n"), __WFUNCTION__));
        return NULL;
    }
	
    // initialize the card insertion interrupt event
    if (!InterruptInitialize (*pSysIntrCardDetect, hCardInsertInterruptEvent, NULL, 0)) {
        ERRORMSG(1, (TEXT("SetupCardDetectIST: unable to init card detect interrupt!\r\n")));
        return NULL;
    }

	return hCardInsertInterruptEvent ; 
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcDeregisterCardInterrupt
//
// This function is to un-register card detection interrupt 
//
// Parameters:
//		 pSpecificContext [in]		pointer to the structure 
//
// Returns:
//      Return void
//
//------------------------------------------------------------------------------
void BspSdhcDeregisterCardInterrupt(PVOID pSpecificContext)
{
     PBSP_SDHC_CONTEXT pBspContext ; 
     pBspContext = (PBSP_SDHC_CONTEXT)pSpecificContext ; 

     //Disable interrupt
     InterruptDisable (pBspContext->dwSysIntrCardDetect);
	
     // close card interrupt event
     if (NULL != pBspContext->hCardInsertInterruptEvent) 
     {
          CloseHandle(pBspContext->hCardInsertInterruptEvent);
          pBspContext->hCardInsertInterruptEvent = NULL;
     }
}

⌨️ 快捷键说明

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