📄 hif.c
字号:
if (SD_API_SUCCESS(pRequest->Status)) {
status = A_OK;
} else {
status = A_ERROR;
}
htcContext = (void *)dwParam;
htcCallbacks.rwCompletionHandler(htcContext, status);
AR_DEBUG_ASSERT(status == A_OK);
SDFreeBusRequest(pRequest);
return;
}
#ifdef CEPC
DWORD
hifIRQThread(LPVOID Context)
{
SD_DEVICE_HANDLE hDevice = Context;
A_STATUS status;
HIF_DEVICE *device;
if (hDevice == NULL) {
return SD_API_STATUS_UNSUCCESSFUL;
}
while (1) {
NdisWaitEvent(&hifIRQEvent, 0);
NdisResetEvent(&hifIRQEvent);
device = getHifDevice(hDevice);
status = htcCallbacks.dsrHandler(device);
AR_DEBUG_ASSERT(status == A_OK);
} // while
return SD_API_STATUS_SUCCESS;
}
#endif
SD_API_STATUS
hifIRQHandler(SD_DEVICE_HANDLE hDevice, PVOID notUsed)
{
#ifndef CEPC
A_STATUS status;
HIF_DEVICE *device;
A_BOOL callDSR;
#endif
HIF_DEBUG_PRINTF(ATH_LOG_TRC, "hifIRQHandler : Enter\n");
#ifndef CEPC
/* Disable device interrupts */
device = getHifDevice(hDevice);
status = htcCallbacks.deviceInterruptDisabler(device, &callDSR);
AR_DEBUG_ASSERT(status == A_OK);
/* Call the DSR Handler if it is not a Spurious Interrupt */
if (callDSR) {
status = htcCallbacks.dsrHandler(device);
AR_DEBUG_ASSERT(status == A_OK);
}
#else
NdisSetEvent(&hifIRQEvent);
#endif
HIF_DEBUG_PRINTF(ATH_LOG_TRC, "hifIRQHandler : Exit\n");
return SD_API_STATUS_SUCCESS;
}
BOOL
hifDeviceInserted(SD_DEVICE_HANDLE *handle)
{
HIF_DEVICE *device;
SD_API_STATUS sdStatus;
SDIO_CARD_INFO sdioInfo;
SD_HOST_BLOCK_CAPABILITY blockCap;
SD_CARD_RCA cardRCA;
A_UCHAR rgucTuple[SD_CISTPLE_MAX_BODY_SIZE];
PSD_CISTPL_FUNCE_FUNCTION pFunce = (PSD_CISTPL_FUNCE_FUNCTION) rgucTuple;
A_UINT32 ulLength = 0;
A_UCHAR ucRegVal;
A_BOOL blockMode;
SD_CARD_INTERFACE ci;
SD_IO_FUNCTION_ENABLE_INFO fData;
DWORD bData;
//SDCONFIG_FUNC_SLOT_CURRENT_DATA slotCurrent;
#ifdef CEPC
HANDLE hThread;
#endif //CEPC
device = addHifDevice(handle);
HIF_DEBUG_PRINTF(ATH_LOG_TRC, "hifDeviceInserted: Enter\n");
/* Enable SDIO [dragon] function */
fData.Interval = DEFAULT_SDIO_FUNCTION_RETRY_TIMEOUT;
fData.ReadyRetryCount = DEFAULT_SDIO_FUNCTION_RETRIES;
sdStatus = SDSetCardFeature (handle, SD_IO_FUNCTION_ENABLE,
&fData, sizeof(fData));
if (!SD_API_SUCCESS(sdStatus)) {
return FALSE;
}
/*
* Issue commands to get the manufacturer ID and stuff and compare it
* against the rev Id derived from the ID registered during the
* initialization process. Report the device only in the case there
* is a match.
*/
sdStatus = SDCardInfoQuery(handle, SD_INFO_SDIO,
&sdioInfo, sizeof(sdioInfo));
if (!SD_API_SUCCESS(sdStatus)) {
return FALSE;
}
funcNo = sdioInfo.FunctionNumber;
sdStatus = SDCardInfoQuery(handle, SD_INFO_REGISTER_RCA,
&cardRCA, sizeof(cardRCA));
HIF_DEBUG_PRINTF(ATH_LOG_INF, "Card RCA is 0x%x\n", cardRCA);
/* Configure the SDIO Bus Width */
memset(&ci, 0, sizeof(ci));
if (sdio1bitmode) {
ci.InterfaceMode = SD_INTERFACE_SD_MMC_1BIT;
} else {
ci.InterfaceMode = SD_INTERFACE_SD_4BIT;
}
if (sdiobusspeedlow) {
ci.ClockRate = SDIO_CLOCK_FREQUENCY_REDUCED;
} else {
ci.ClockRate = SDIO_CLOCK_FREQUENCY_DEFAULT;
}
sdStatus = SDSetCardFeature(handle, SD_SET_CARD_INTERFACE,
&ci, sizeof(ci));
if (!SD_API_SUCCESS(sdStatus)) {
return FALSE;
}
/* Check if the target supports block mode */
sdStatus = SDReadWriteRegistersDirect(handle, SD_IO_READ,
0, 0x08, FALSE, &ucRegVal, 1);
if (!SD_API_SUCCESS(sdStatus)) {
return FALSE;
}
blockMode = (ucRegVal & 0x2) >> 1; // SMB is bit 1
if (!blockMode) {
HIF_DEBUG_PRINTF(ATH_LOG_ERR, "Function does not support block mode\n");
return FALSE;
} else {
HIF_DEBUG_PRINTF(ATH_LOG_TRC, "Function supports block mode\n");
blockCap.ReadBlocks = blockCap.WriteBlocks = 8;
blockCap.ReadBlockSize = blockCap.WriteBlockSize = HIF_MBOX_BLOCK_SIZE;
sdStatus = SDCardInfoQuery(handle, SD_INFO_HOST_BLOCK_CAPABILITY,
&blockCap, sizeof(blockCap));
if (blockCap.ReadBlockSize < blockCap.WriteBlockSize) {
maxBlockSize = blockCap.ReadBlockSize;
} else {
maxBlockSize = blockCap.WriteBlockSize;
}
if (blockCap.ReadBlocks < blockCap.WriteBlocks) {
maxBlocks = blockCap.ReadBlocks;
} else {
maxBlocks = blockCap.WriteBlocks;
}
sdStatus = SDGetTuple(handle, SD_CISTPL_FUNCE, NULL, &ulLength, FALSE);
if ((!SD_API_SUCCESS(sdStatus)) || (ulLength > sizeof(rgucTuple)) ) {
return FALSE;
}
sdStatus = SDGetTuple(handle, SD_CISTPL_FUNCE, rgucTuple, &ulLength, FALSE);
if ((!SD_API_SUCCESS(sdStatus)) ||
(pFunce->bType != SD_CISTPL_FUNCE_FUNCTION_TYPE) ) {
return FALSE;
}
if (maxBlockSize > pFunce->wMaxBlkSize) {
maxBlockSize = pFunce->wMaxBlkSize;
}
bData = (DWORD)maxBlockSize;
sdStatus = SDSetCardFeature(handle,
SD_IO_FUNCTION_SET_BLOCK_SIZE,
&bData, sizeof(bData));
}
HIF_DEBUG_PRINTF(ATH_LOG_TRC,
"Bytes Per Block: %d bytes, Block Count:%d \n",
maxBlockSize, maxBlocks);
/* Allocate the slot current */
/* Kowsalya : commenting as there is no equivalent for this in WINCE */
/*
status = SDLIB_GetDefaultOpCurrent(handle, &slotCurrent.SlotCurrent);
if (SDIO_SUCCESS(status)) {
HIF_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("Allocating Slot current: %d mA\n",
slotCurrent.SlotCurrent));
status = SDLIB_IssueConfig(handle, SDCONFIG_FUNC_ALLOC_SLOT_CURRENT,
&slotCurrent, sizeof(slotCurrent));
if (!SDIO_SUCCESS(status)) {
HIF_DEBUG_PRINTF(ATH_DEBUG_ERROR,
("Failed to allocate slot current %d\n", status));
return FALSE;
}
}
*/
/* Inform HTC */
if ((htcCallbacks.deviceInsertedHandler(device)) != A_OK) {
HIF_DEBUG_PRINTF(ATH_LOG_TRC, "Device rejected\n");
return FALSE;
}
#ifdef CEPC
NdisInitializeEvent(&hifIRQEvent);
hThread = CreateThread(NULL, 0,
hifIRQThread, (LPVOID)handle, 0, NULL);
CeSetThreadPriority(hThread, 200);
CloseHandle(hThread);
#endif //CEPC
return TRUE;
}
void
HIFAckInterrupt(HIF_DEVICE *device)
{
#ifndef CEPC
htcCallbacks.deviceInterruptEnabler(device);
#endif
return;
}
void
HIFUnMaskInterrupt(HIF_DEVICE *device)
{
SD_API_STATUS sdStatus;
/* Register the IRQ Handler */
sdStatus = SDIOConnectInterrupt(device->handle, hifIRQHandler);
AR_DEBUG_ASSERT(SD_API_SUCCESS(sdStatus));
return;
}
void HIFMaskInterrupt(HIF_DEVICE *device)
{
SDIODisconnectInterrupt(device->handle);
return;
}
void
hifDeviceRemoved(SD_DEVICE_HANDLE *handle)
{
A_STATUS status;
HIF_DEVICE *device;
device = getHifDevice(handle);
status = htcCallbacks.deviceRemovedHandler(device);
delHifDevice(handle);
AR_DEBUG_ASSERT(status == A_OK);
return;
}
HIF_DEVICE *
addHifDevice(SD_DEVICE_HANDLE *handle)
{
hifDevice[0].handle = handle;
return &hifDevice[0];
}
HIF_DEVICE *
getHifDevice(SD_DEVICE_HANDLE *handle)
{
return &hifDevice[0];
}
void
delHifDevice(SD_DEVICE_HANDLE *handle)
{
hifDevice[0].handle = NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -