📄 socket.c
字号:
{
//
// TODO - Eventially I need to check to see if there is a failure from the PCCARD
// write.
//
PowerPCCardWrite
(
ucVcc,
ucVpp1
);
Sleep(100);
//
// Set the enable and reset lines.
//
*SMC_PCCONT |= PCCONT_PC1EN | PCCONT_PC1RST;
Sleep(20);
//
// Clear the reset line.
//
*SMC_PCCONT &= ~PCCONT_PC1RST;
Sleep(20);
//
// Allow the card 2 seconds to assert RDY
//
for (t = 0; t < PCMCIA_MAX_RDY_WAIT_TIME; t += PCMCIA_RDY_POLL_INT)
{
ulGPIOF = *GPIO_PFDR;
if (ulGPIOF & GPIOF_PCMCIA_IRQ)
{
DEBUGMSG
(
ZONE_PDD,
(
TEXT("PDCardSetSocket: Card in socket %d RDY after %dms\r\n"),
uSocket,
t
)
);
break;
}
Sleep(PCMCIA_RDY_POLL_INT);
}
if (t >= PCMCIA_MAX_RDY_WAIT_TIME)
{
DEBUGMSG
(
ZONE_PDD,
(
TEXT("PDCardSetSocket: CARD IN SOCKET %d NOT RDY AFTER %dms\r\n"),
uSocket,
t
)
);
}
}
*pPDDState = *pState;
pcss_exit:
DumpSocketRegisters();
LeaveCriticalSection(&g_PCIC_Crit);
return CERR_SUCCESS;
pcss_fail:
DEBUGMSG(ZONE_PDD, (TEXT("PDCardSetSocket(%d) returning %d\r\n"),
uSocket, ret));
return ret;
} // PDCardSetSocket
//****************************************************************************
// PDCardInquireAdapter
//****************************************************************************
// @func STATUS | PDCardInquireAdapter | Returns the socket controller's characteristics
// and capabilities.
// @rdesc Returns one of the CERR_* return codes in cardserv.h.
//
STATUS PDCardInquireAdapter
(
PPDCARD_ADAPTER_INFO pAdapterInfo // @parm Pointer to PDCARD_ADAPTER_INFO structure.
)
{
if (pAdapterInfo->uPowerEntries < NUM_POWER_ENTRIES)
{
pAdapterInfo->uPowerEntries = NUM_POWER_ENTRIES;
return CERR_BAD_ARG_LENGTH;
}
//
// Copy the adapter info
//
memcpy(pAdapterInfo, &v_AdapterInfo, sizeof(PDCARD_ADAPTER_INFO));
pAdapterInfo = (PPDCARD_ADAPTER_INFO)(((UINT)pAdapterInfo) + sizeof(PDCARD_ADAPTER_INFO));
//
// Copy the power entries at the end
//
memcpy(pAdapterInfo, &v_PowerEntries, sizeof(v_PowerEntries));
return CERR_SUCCESS;
}
//****************************************************************************
// InitSocket
//****************************************************************************
// Set up socket's initial window registers and interrupts
//
VOID InitSocket
(
UINT32 uSocket
)
{
PDCARD_WINDOW_STATE WinState;
PDCARD_SOCKET_STATE SockState;
//
// Set the socket to detect status change events
//
SockState = v_SockState[uSocket];
SockState.fInterruptEvents = EVENT_MASK_CARD_DETECT|
EVENT_MASK_CARD_LOCK|
EVENT_MASK_BATTERY_LOW|
EVENT_MASK_BATTERY_DEAD|
EVENT_MASK_WRITE_PROTECT;
//
// Configure the socket for memory and IO.
//
SockState.fInterfaceType = CFG_IFACE_MEMORY_IO;
SockState.fIREQRouting = 1;
SockState.fVcc = VCC_DEFAULT_INDEX;
PDCardSetSocket(uSocket, &SockState);
//
// Initially enable only the attribute and memory windows
// Lets not worry about the return codes since
// PDCardGetWindow/PDCardSetWindow only checks for
//
PDCardGetWindow( PCMCIA_MEMORY_WINDOW, &WinState);
PDCardSetWindow( PCMCIA_MEMORY_WINDOW, &WinState);
PDCardGetWindow( PCMCIA_ATTRIBUTE_WINDOW, &WinState);
PDCardSetWindow( PCMCIA_ATTRIBUTE_WINDOW, &WinState);
}
//****************************************************************************
// PDCardResetSocket
//****************************************************************************
// @func STATUS | PDCardResetSocket | Resets the specified socket.
// @rdesc Returns one of the CERR_* return codes in cardserv.h.
//
STATUS PDCardResetSocket
(
UINT32 uSocket // @parm Socket number (first socket is 0)
)
{
ULONG ulGPIOF;
UINT32 t;
DEBUGMSG(1, (TEXT("++PDCardResetSocket\r\n")));
if (uSocket >= NUM_SOCKETS)
{
return CERR_BAD_SOCKET;
}
EnterCriticalSection(&g_PCIC_Crit);
//
// Power off the socket
// TODO - Eventially I need to check to see if there is a failure from the PCCARD
// write.
//
// The card should be powered up at this point. So no need to power it up again.
//
// PowerPCCardWrite(0, 0);
ulGPIOF = *GPIO_PFDR ;
if (( ulGPIOF & (GPIOF_PCMCIA_CD1|GPIOF_PCMCIA_CD2)) ==
(GPIOF_PCMCIA_CD1|GPIOF_PCMCIA_CD2))
{
//
// Leave it powered off if no card in it.
//
// PowerPCCardWrite(0, 0);
LeaveCriticalSection(&g_PCIC_Crit);
return CERR_NO_CARD;
}
//
// Tri-state outputs for 310ms
//
Sleep(310);
//
// Set the enable and reset lines.
//
*SMC_PCCONT |= PCCONT_PC1EN | PCCONT_PC1RST | PCCONT_WEN1;;
Sleep(20);
//
// Clear the reset line.
//
*SMC_PCCONT &= ~PCCONT_PC1RST| PCCONT_WEN1;
Sleep(20);
//
// Allow the card 2 seconds to assert RDY
//
for (t = 0; t < PCMCIA_MAX_RDY_WAIT_TIME; t += PCMCIA_RDY_POLL_INT)
{
ulGPIOF = *GPIO_PFDR;
if (ulGPIOF & GPIOF_PCMCIA_IRQ)
{
DEBUGMSG
(
ZONE_PDD,
(
TEXT("PDCardResetSocket: Card in socket %d RDY after %dms\r\n"),
uSocket,
t
)
);
break;
}
Sleep(PCMCIA_RDY_POLL_INT);
}
if (t >= PCMCIA_MAX_RDY_WAIT_TIME)
{
DEBUGMSG
(
ZONE_PDD,
(
TEXT("PDCardResetSocket: CARD IN SOCKET %d NOT RDY AFTER %dms\r\n"),
uSocket,
t
)
);
}
InitSocket(uSocket);
// LKY 2001.12
Sleep(20);
//
// TODO - Enable Manage Interrupt
//
// PCICIndex(0, REG_INTERRUPT_AND_GENERAL_CONTROL);
// intctl = PCICDataRead();
// intctl |= INT_ENABLE_MANAGE_INT;
// PCICDataWrite(intctl);
LeaveCriticalSection(&g_PCIC_Crit);
DEBUGMSG(1, (TEXT("--PDCardResetSocket\r\n")));
return CERR_SUCCESS;
} // PDCardResetSocket
//****************************************************************************
// PDCardGetAdapter
//****************************************************************************
// @func STATUS | PDCardGetAdapter | Returns power save mode status and
// capabilities
// @rdesc Returns one of the CERR_* return codes in cardserv.h
//
STATUS PDCardGetAdapter
(
UINT32 uSocket,
PPDCARD_ADAPTER_STATE pState
)
{
DEBUGMSG
(
ZONE_PDD,
(
TEXT("^PCMCIA: PDCardGetAdapter(), socket[%u] "),
uSocket
)
);
if (uSocket >= NUM_SOCKETS)
{
return CERR_BAD_SOCKET;
}
if (pState == NULL)
{
return CERR_BAD_ARGS;
}
*pState = v_AdapterState[uSocket];
DEBUGMSG(ZONE_PDD, (TEXT("state: %x\r\n"), *pState));
return CERR_SUCCESS;
}
//****************************************************************************
// PDCardSetAdapter
//****************************************************************************
// @func STATUS | PDCardSetAdapter | Sets power save mode status and capabilities
// @rdesc Returns one of the CERR_* return codes in cardserv.h
//
STATUS
PDCardSetAdapter
(
UINT32 uSocket,
PPDCARD_ADAPTER_STATE pState
)
{
BOOL bUserMode;
ULONG ulGPIOF;
UINT8 fVcc;
if (uSocket >= NUM_SOCKETS)
{
return CERR_BAD_SOCKET;
}
if (pState == NULL)
{
return CERR_BAD_ARGS;
}
bUserMode = (*pState & ADP_STATE_KERNEL_MODE) ? FALSE : TRUE;
DEBUGMSG(bUserMode & ZONE_PDD, (TEXT("PDCardSetAdapter entered\r\n")));
if (bUserMode)
{
EnterCriticalSection(&g_PCIC_Crit);
}
//
// The socket controller will automatically power up when a card is inserted
//
if (*pState & ( ADP_STATE_POWERDOWN | ADP_STATE_POWEROFF))
{
//
// Set the voltage to zero.
//
v_SockState[uSocket].uVpp1 = VPP1_0V_INDEX;
v_SockState[uSocket].fVcc = VCC_0V_INDEX;
//
// Power down the socket
//
PowerPCCardWrite(0,0);
}
else
{
DEBUGMSG(ZONE_PDD, (TEXT("PDCardSetAdapter: Powering On Socket:\r\n")));
ulGPIOF = *GPIO_PFDR ;
switch(ulGPIOF & (GPIOF_PCMCIA_VS1 | GPIOF_PCMCIA_VS2))
{
case 0:
case GPIOF_PCMCIA_VS2:
fVcc = VCC_33V_INDEX;
break;
case (GPIOF_PCMCIA_VS1 | GPIOF_PCMCIA_VS2):
fVcc = VCC_50V_INDEX;
break;
case GPIOF_PCMCIA_VS1:
default:
fVcc = VCC_0V_INDEX;
break;
}
//
// Only set the voltage if needed.
//
if( v_SockState[uSocket].fVcc != fVcc)
{
//
// Update the value.
//
v_SockState[uSocket].fVcc = fVcc;
//
// Check to make sure that the battery voltage is correct.
//
if(v_SockState[uSocket].uVpp1 <= VPP1_120V_INDEX)
{
v_SockState[uSocket].uVpp1 = VPP1_0V_INDEX;
}
//
// Our pcmcia power supply can only handle voltages of
// vpp1 = vcc or 12v.
//
if(v_SockState[uSocket].uVpp1 != v_SockState[uSocket].fVcc &&
v_SockState[uSocket].uVpp1 !=VPP1_120V_INDEX)
{
v_SockState[uSocket].uVpp1 = VPP1_0V_INDEX;
}
PowerPCCardWrite
(
v_PowerEntries[v_SockState[uSocket].fVcc].uPowerLevel,
v_PowerEntries[v_SockState[uSocket].uVpp1].uPowerLevel
);
}
}
if (bUserMode)
{
LeaveCriticalSection(&g_PCIC_Crit);
}
DEBUGMSG(bUserMode & ZONE_PDD, (TEXT("PDCardSetAdapter done\r\n")));
return CERR_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -