First view the SD card-related schematics. SBC6000X is use AT91SAM9261S chip,the SD card used SDIO mode.the 10 and 11 goldfinger is the SD card socket.the 11 pin connection AT91SAM9261S chips PA22,when the SD card insert,the SD card connector of 10 and 11,this time PA22 pin is shorted to ground,if there is no SD card inserted,The PA22 pin is pull-up
resistor of 100K,that is the PA22 input high.SD card dirver inside the PA22 pin as interrupt pin to use,when a sd card inserted or unplugged,PA22 pin level change will be triggered interrupt, the interrupt processing thread to determine the pin PA22 level, for the low level indicated SD Card insert, for the high level indicated no SD card insert.

See the SBC6000X WinCE 6.0 BSP \SBC9261\SRC\DRIVERS\SDMEMORY\Loader\sdmem_loader.c
The SML_Init() function,which realize a SD card detection PA22 pin interrupt processing thread and loaded SD card in the boot.
First,we get the physical interrupt number PA22 pin:
dwPhyIntr= (LOGINTR_BASE_PIOA + 22);
Create disruptions:
m_hevInterrupt= CreateEvent(NULL,FALSE,FALSE,NULL);
Transfer KernelIoControl() function uses IOCONTROL yards
IOCTL_HAL_REQUEST_SYSINTR dynamic access to the dwPhyIntr logical interrupt number g_dwSysIntrToIrq
Transfer InterruptInitialize()function realize logical interrupt number g_dwSysIntrToIrq and bind interrupt events m_hevInterrupt Transfer CreateThread() function creat interrupt thread
Load SD card driver at boot time:
hDevice=ActivateDevice( TEXT("Drivers\\sdmem"), 0);
//! \fn BOOL WINAPI SML_Init()
//! \brief This function is the entry point of this pseudo-driver.
//It simply creates the thread that'll look for a change in the card detection status
BOOL WINAPI SML_Init()
{
DWORD dwPhyIntr;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
dwPhyIntr = (LOGINTR_BASE_PIOA + 22);
m_hevInterrupt = CreateEvent(NULL,FALSE,FALSE,NULL);
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr, sizeof(DWORD), &g_dwSysIntrToIrq, sizeof(DWORD), NULL))
{
RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr\r\n")));
g_dwSysIntrToIrq = SYSINTR_UNDEFINED;
return FALSE;
}
if (!InterruptInitialize(g_dwSysIntrToIrq, m_hevInterrupt, 0, 0))
{
RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! \r\n")));
}
gSDMMCDetectThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SDMMCDetectThread, NULL, 0, NULL);
hDevice=ActivateDevice( TEXT("Drivers\\sdmem"), 0);
if ( gSDMMCDetectThread == NULL )
{
RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread.\r\n")));
return (FALSE);
}
return TRUE;
}
Realize interrupt handling thread:
The use of an interrupt of the thread inside the WaitForSingleObject() function to wait for interrupt events m_hevInterrupt generation,after the interrupt event m_hevInterrupt happen,we use pio_get_value(AT91C_PIN_PA(22)) to determine the level of PA22 pin high or low,if it is low,indication there are SD card insert the SD card slot,load the SD card driver:hDevice=ActivateDevice( TEXT(“Drivers\\sdmemâ€), 0); if it is high,there is no SD card inserted,uninstall the SD card driver:DeactivateDevice( hDevice);
//! \fn void SDMMCDetectThread(void)
// This function is the main thread that looks for the card insertion event.
void SDMMCDetectThread(void)
{
static volatile int cardInserted;
BOOLEAN pollingMode = FALSE;
LONG result;
DWORD dwSize = sizeof(DWORD);
while(1)
{
result=WaitForSingleObject(m_hevInterrupt, INFINITE);
switch(result)
{
case WAIT_OBJECT_0:
//sd card removed
if (pio_get_value(AT91C_PIN_PA(22)))
{
DeactivateDevice( hDevice);
RETAILMSG(1, (TEXT("SD/MMC card removal detected\r\n")));
InterruptDone(g_dwSysIntrToIrq);
}
else // card inserted
{
hDevice = ActivateDevice( TEXT("Drivers\\sdmem"), 0);
RETAILMSG(1, (TEXT("SD/MMC card insertion detected\r\n")));
InterruptDone(g_dwSysIntrToIrq);
}
break;
default:
break;
}
}
}
More details can be found here.
http://armkits.com/Product/SBC9261-I.aspEmbest Info&Tech Co., LTD. (China HQ)
Room 509, Luohu Science Building
#85 Taining Rd., Shenzhen, Guangdong
China 518020
Tel: 0086-755-25635656, 25636285
Fax: 0086-755-25616057
Sales Email: market(at)embedinfo.com or embest1sale1(at)yahoo.com
Support Email: support(at)embedinfo.com or EmbestEmbest(at)yahoo.com
http://www.armkits.com