接下来我们来看看CSDIOControllerBase的继承类CSDIOController,实现在sdiocontroller.cpp.这个类的对象在SDH_Init中通过调用CreateSDIOController来创建其对象,这个函数也在sdiocontroller.cpp中实现:
CSDIOController实现了CSDIOControllerBase中定义的几个纯虚函数:
virtual BOOL InitializeHardware( BOOL bOnPowerUp = FALSE ) = 0;
virtual void DeinitializeHardware( BOOL bOnPowerDown = FALSE ) = 0;
virtual BOOL CustomSetup( LPCTSTR pszRegistryPath ) = 0;
virtual BOOL IsCardWriteProtected() = 0;
virtual BOOL IsCardPresent() = 0;
这些函数定义了与实际硬件平台相关的一些代码,当硬件发生变化时,只需要修改和硬件相关的代码就可以了.
1.CustomSetup
CustomSetup被基类的InterpretCapabilities函数调用,和InterpretCapabilities一样,CustomSetup主要工作也是从注册表中获取信息.如CardDetect,CardReadWrite的信息,比如是哪个GPIO寄存器,相应的掩码和具体的值等.这些信息被以下几个函数用到.
2.InitializeHardware
InitializeHardware被基类的Initialize函数调用.
根据具体的GPIO(读写检测m_chCardReadWriteGPIO,这里是GPH8,插入检测m_chCardDetectGPIO,这里是GPG10)来对相应的GPIO寄存器进行初始化(如GPACON或者GPBCON等).根据以下变量的值来进行设置,这些变量从注册表中获得(CustomSetup函数中进行).m_dwCardReadWriteControlMask,m_dwCardReadWriteControlFlag,m_dwCardDetectControlMask,m_dwCardDetectControlFlag
3.DeinitializeHardware
未做任何工作
4.IsCardWriteProtected
在SlotOptionHandler中被调用,给PSD_CARD_INTERFACE结构的WriteProtected成员赋值,判断SD卡是否写保护,通过判断对应的GPHDAT寄存器m_dwCardReadWriteMask位(GPH8)与m_dwCardReadWriteFlag进行比较判断.
5.IsCardPresent
判断SD卡是否存在,这个函数被基类的很多函数调用,如TransferIstThread等,很多操作都要先判断SD卡是否存在,然后在进行下面的操作.
通过判断GPG10状态来获得.
另外附上注册表sdhc_sc2410.reg的内容:
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/SDHC_SMDK2410]
"Order"=dword:21
"Dll"="sdhc_smdk2410.dll"
"Prefix"="SDH"
"DMAChannel"=dword:0 ; DMA channel to use. Set to 0xffffffff to disable DMA
"DMAIrq"=dword:11
"DMA_IST_Priority"=dword:96
"SDIOIrq"=dword:15
"SDIO_IST_Priority"=dword:97
"PollingTimeout"=dword:100 ; 100 ms
"CardDetect_Thread_Priority"=dword:98
"CardDetectGPIO"="G" ; card detect on GPG10
"CardDetectMask"=dword:400
"CardDetectFlag"=dword:0
"CardDetectControlMask"=dword:fffcffff
"CardDetectControlFlag"=dword:0
"CardDetectPullupMask"=dword:ffffffef
"CardDetectPullupFlag"=dword:10
"CardReadWriteGPIO"="H" ; card R/W on GPH8
"CardReadWriteMask"=dword:100
"CardReadWriteFlag"=dword:100
"CardReadWriteControlMask"=dword:ffcfffff
"CardReadWriteControlFlag"=dword:0
"CardReadWritePullupMask"=dword:ffffffbf
"CardReadWritePullupFlag"=dword:40
"HandleBusyFinishOnCommand38"=dword:1
"DmaTransferTimeoutFactor"=dword:8
"DmaTransferTimeoutConstant"=dword:3000