📄 sdmmc_load.c
字号:
v_pClockRegs = (volatile CLKMAN_REGS *) VirtualAllocCopy(0x400,(char *)TEXT("aclink Alloc 4 clock"),
(PVOID)CLK_BASE_U_VIRTUAL);
}
if (v_pIndCtrlReg == NULL ||
v_pClockRegs == NULL)
{
SDMMC_FreeAddresses();
return(FALSE);
}
else
return(TRUE);
}
/************************************************************************************************************
* Function: SML_PowerHandler
*
* Purpose: Power Handler for the loader. Currently we dont need to do anything here, so these are just stubs.
*
* Returns: void
*
************************************************************************************************************/
void WINAPI SML_PowerHandler(
BOOL bOff // @parm TRUE, the system is powering off; FALSE, the system is powering up.
)
{
if (bOff)
{
SML_PowerDown();
}
else
{
SML_PowerUp();
}
}
void ResetRegistry()
{
BYTE i;
WCHAR *szActive = L"Drivers\\Active";
WCHAR *szKey;
LONG nErr;
TCHAR Temp[MAX_PATH];
DWORD Type, Size;
HANDLE hDevice = NULL;
HKEY hKey;
szKey = (WCHAR*)malloc(100);
if(NULL == szKey)
return;
for(i = 1; i < 100; i++)
{
swprintf(szKey, L"%s\\%02d", szActive, i);
nErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szKey, 0, 0, &hKey);
if (nErr == ERROR_SUCCESS)
{
nErr = RegQueryValueEx(hKey, L"Key", NULL, &Type, (LPBYTE)Temp, &Size);
if(nErr == ERROR_SUCCESS && Type == REG_SZ)
{
if ( 0 == wcscmp(Temp, L"Drivers\\BuiltIn\\sdmmc") )
{
nErr = RegQueryValueEx(hKey, L"Hnd", NULL, &Type, (LPBYTE)&hDevice, &Size);
if(nErr == ERROR_SUCCESS && Type == REG_DWORD && NULL != hDevice)
{
DeactivateDevice( hDevice);
DoDeleteHandleValue(szRegKey);
}
//RegDeleteKey( HKEY_LOCAL_MACHINE, szKey);
}
}
RegCloseKey( hKey );
}
}
}
/************************************************************************************************************
* Function: SDMMCDetectThread
*
* Purpose: This function is the main thread that looks for the card insertion interrupt from the FPGA. It runs
* indefinately and is responsible for loading the driver when it sees the interrupt and unloads the
* driver when it sees the card removal. Currently we are polling for the levels because of the inherent
* problem in the FPGA not able to deliver a card removal interrupt. This code will change when this
* issue is resolved.
*
* Returns: void
*
************************************************************************************************************/
void SDMMCDetectThread(void)
{
HANDLE hDevice = NULL;
// volatile P_XLLP_GPIO_T v_pGPIOReg = NULL;
// v_pGPIOReg = (volatile P_XLLP_GPIO_T)GPIO_BASE_U_VIRTUAL;
SDMMC_InitializeAddresses();
gSDMMCIntrEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("SDMMC"));
if(NULL == gSDMMCIntrEvent)
{
gSDMMCIntrEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("SDMMC"));
if(NULL == gSDMMCIntrEvent)
{
RETAILMSG(1, (TEXT("SDMMC CreateEvent Failed = %d\r\n"), GetLastError()));
return;
}
if (!(InterruptInitialize(SYSINTR_SDMMC, gSDMMCIntrEvent, NULL, 0)))
{
RETAILMSG(1, (TEXT("SDMMC IntrInit Failed = %d\r\n"), GetLastError()));
//return;
}
}
Sleep(200);
ResetRegistry();
//deal with card insertion even before the board is brought up
if(IsCardOnSite())
{
RETAILMSG(1, (TEXT("SD Card On Site\r\n")));
DoRegSetup(szRegKey);
hDevice = ActivateDevice( szRegKey, 0);
DoSetHandleValue( szRegKey, hDevice);
SDMMC_DETECT = 1;
}
v_pIndCtrlReg->control &= ~(0x1u<<12); //SD_EN signal
while(1)
{
Sleep(200);
if(IsCardOnSite())
{
if(SDMMC_DETECT == 0)
{
RETAILMSG(1, (TEXT("SD Card On Site\r\n")));
DoRegSetup(szRegKey);
hDevice = ActivateDevice( szRegKey, 0);
if ( NULL != hDevice )
DoSetHandleValue( szRegKey, hDevice);
SDMMC_DETECT = 1;
}
}
else
{
if(SDMMC_DETECT == 1)
{
RETAILMSG(1, (TEXT("SD Card Off Site\r\n")));
if ( NULL != hDevice )
{
DeactivateDevice( hDevice);
DoDeleteHandleValue(szRegKey);
}
v_pClockRegs->cken &= ~(0x1 << 12);
SDMMC_DETECT = 0;
}
}
//PowerDown
if(v_pDrvGlob->ac97.SDDetect == 1)
{
RETAILMSG(1, (TEXT("SD Card PowerDown\r\n")));
if ( NULL != hDevice )
{
DeactivateDevice( hDevice);
DoDeleteHandleValue(szRegKey);
}
v_pClockRegs->cken &= ~(0x1 << 12);
SDMMC_DETECT = 1;
v_pDrvGlob->ac97.SDDetect = 0;
}
}
}
/************************************************************************************************************
* Function: SML_Init
*
* Purpose: performs some initialisation. spawns the main loader thread.
*
* Returns: void
*
************************************************************************************************************/
BOOL WINAPI SML_Init()
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
gSDMMCDetectThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SDMMCDetectThread, NULL, 0, NULL);
if ( gSDMMCDetectThread == NULL )
{
return (FALSE);
}
else
{
ThreadInfo TI;
TI.ThreadHandle = gSDMMCDetectThread;
strcpy((char *)TI.ThreadName, "SDMMC SDMMCDetectThread");
KernelIoControl(IOCTL_SET_THREAD, (LPVOID)&TI, sizeof(ThreadInfo), NULL, 0, NULL);
}
return TRUE;
}
BOOL WINAPI SML_DllEntry( HANDLE hInstDll,
DWORD dwReason,
LPVOID lpvReserved
)
{
switch ( dwReason )
{
case DLL_PROCESS_ATTACH:
DEBUGREGISTER((HINSTANCE) hInstDll);
// RETAILMSG(1, (TEXT("SDMMCLoader : DLL_PROCESS_ATTACH\r\n")));
break;
case DLL_PROCESS_DETACH:
// should be signaling thread here
// RETAILMSG(1, (TEXT("SDMMCLoader : DLL_PROCESS_DETACH\r\n")));
break;
}
return (TRUE);
}
// The following functions are all stubbed out. They are not required but are provided for the sake
// of code completion.
DWORD SML_Open (DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
return (4);
}
BOOL SML_Close(DWORD dwData)
{
SDMMC_FreeAddresses();
return (TRUE);
}
DWORD SML_Read (DWORD dwData, LPVOID pBuf, DWORD Len)
{
return (0);
}
DWORD SML_Write(DWORD dwData, LPCVOID pBuf, DWORD Len)
{
return (0);
}
DWORD SML_Seek (DWORD dwData, long pos, DWORD type)
{
return (DWORD)-1;
}
VOID SML_PowerUp (VOID)
{
SDMMC_DETECT = 0;
}
BOOL SML_PowerDown(VOID)
{
return (TRUE);
}
BOOL SML_Deinit(DWORD dwData)
{
return (TRUE);
}
BOOL SML_IOControl(DWORD p1, DWORD p2, PBYTE p3, DWORD p4, PBYTE p5,
DWORD p6, PDWORD p7)
{
return (TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -