main.c
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 876 行 · 第 1/3 页
C
876 行
}
else {
if (EbootTFtpReceiver( &MyAddr, FrameBuffer, wDestPort, wSrcPort, pwUDPData, wUDPDataLen )) {
BootmeCnt = MAX_BOOTME_CNT;
}
}
break;
} // switch (dwIPState)
}
break;
default:
break;
} // switch (wFrameType)
}
if (dwLaunchAddr) {
EdbgOutputDebugString("Download successful! Jumping to image at %Xh...\r\n",dwLaunchAddr);
pBootArgs->dwLaunchAddr = dwLaunchAddr;
}
else if ( fGotJumpimg )
{
dwLaunchAddr = pBootArgs->dwLaunchAddr;
}
}
// Update address info in boot args area
memcpy(&pBootArgs->EdbgAddr,&MyAddr,sizeof(MyAddr));
memcpy(&pBootArgs->EshellHostAddr,&EshellHostAddr,sizeof(EDBG_ADDR));
pBootArgs->ucLoaderFlags = LDRFL_USE_EDBG | LDRFL_ADDR_VALID | LDRFL_JUMPIMG;
pBootArgs->DHCPLeaseTime = DHCPLeaseTime;
pBootArgs->EdbgFlags = EdbgFlags;
if (dwLaunchAddr == 0) {
EdbgOutputDebugString("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\r\n");
EdbgOutputDebugString("---------------------------------------------\r\n");
EdbgOutputDebugString(" Image Download Failed!\r\n");
EdbgOutputDebugString("---------------------------------------------\r\n");
EdbgOutputDebugString(" The Ethernet card seemed to be configured,\r\n");
EdbgOutputDebugString(" but the download didn't complete correctly.\r\n");
EdbgOutputDebugString("---------------------------------------------\r\n");
EdbgOutputDebugString("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n");
SpinForever();
}
EdbgOutputDebugString("\r\nJumping to image at %Xh...\r\n",dwLaunchAddr);
//
// If we have been configured by the host to clear RAM, do so now.
// The RAM addresses are hard coded and must match those in the
// config.bib file for the image. Note that the stack and the driver
// globals memory are not in this range, and this will not hang if we
// run off the end of the memory actually present.
//
if (pBootArgs->ucEshellFlags & EDBG_FL_CLEANBOOT) {
// Clear here if needed.
}
((PFN_LAUNCH)(dwLaunchAddr))();
}
//------------------------------------------------------------------------------
/* OEMEthGetFrame
*
* Check to see if a frame has been received, and if so copy to buffer. An optimization
* which may be performed in the Ethernet driver is to filter out all received broadcast
* packets except for ARPs. This is done in the SMC9000 driver.
*
* Return Value:
* Return TRUE if frame has been received, FALSE if not.
*/
//------------------------------------------------------------------------------
BOOL
OEMEthGetFrame(
BYTE *pData, // OUT - Receives frame data
UINT16 *pwLength) // IN - Length of Rx buffer
// OUT - Number of bytes received
{
return pfnEDbgGetFrame(pData, pwLength);
}
//------------------------------------------------------------------------------
/* OEMEthSendFrame
*
* Send Ethernet frame.
*
* Return Value:
* TRUE if frame successfully sent, FALSE otherwise.
*/
//------------------------------------------------------------------------------
BOOL
OEMEthSendFrame(
BYTE *pData, // IN - Data buffer
DWORD dwLength) // IN - Length of buffer
{
int retries = 0;
// Let's be persistant here
while (retries++ < 4) {
if (!pfnEDbgSendFrame(pData, dwLength))
return TRUE;
else
EdbgOutputDebugString("!OEMEthSendFrame failure, retry %u\n",retries);
}
return FALSE;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
VOID SC_WriteDebugLED(WORD wIndex, DWORD dwPattern) {
return;
}
//------------------------------------------------------------------------------
BYTE CMOS_Read( BYTE offset )
{
BYTE cAddr, cResult;
// Remember, we only change the low order 5 bits in address register
cAddr = _inp( CMOS_ADDR );
_outp( CMOS_ADDR, (cAddr & RTC_ADDR_MASK) | offset );
cResult = _inp( CMOS_DATA );
return (cResult);
}
BOOL IsTimeEqual(LPSYSTEMTIME lpst1, LPSYSTEMTIME lpst2)
{
if (lpst1->wYear != lpst2->wYear) return(FALSE);
if (lpst1->wMonth != lpst2->wMonth) return(FALSE);
if (lpst1->wDayOfWeek != lpst2->wDayOfWeek) return(FALSE);
if (lpst1->wDay != lpst2->wDay) return(FALSE);
if (lpst1->wHour != lpst2->wHour) return(FALSE);
if (lpst1->wMinute != lpst2->wMinute) return(FALSE);
if (lpst1->wSecond != lpst2->wSecond) return(FALSE);
return (TRUE);
}
// RTC routines from kernel\hal\x86\rtc.c
BOOL
Bare_GetRealTime(LPSYSTEMTIME lpst)
{
SYSTEMTIME st;
LPSYSTEMTIME lpst1 = &st, lpst2 = lpst, lptmp;
lpst1->wSecond = 61; // initialize to an invalid value
lpst2->wSecond = 62; // initialize to an invalid value
do {
// exchange lpst1 and lpst2
lptmp = lpst1;
lpst1 = lpst2;
lpst2 = lptmp;
// wait until not updating
while (CMOS_Read(RTC_STATUS_A) & RTC_SRA_UIP);
// Read all the values.
lpst1->wYear = CMOS_Read(RTC_YEAR);
lpst1->wMonth = CMOS_Read(RTC_MONTH);
lpst1->wDayOfWeek = CMOS_Read(RTC_DO_WEEK);
lpst1->wDay = CMOS_Read(RTC_DO_MONTH);
lpst1->wHour = CMOS_Read(RTC_HOUR);
lpst1->wMinute = CMOS_Read(RTC_MINUTE);
lpst1->wSecond = CMOS_Read(RTC_SECOND);
} while (!IsTimeEqual (lpst1, lpst2));
lpst->wMilliseconds = 0; // No easy way to read Milliseconds, returning 0 is safe
if (!(CMOS_Read (RTC_STATUS_B) & RTC_SRB_DM)) {
// Values returned in BCD.
lpst->wSecond = DECODE_BCD(lpst->wSecond);
lpst->wMinute = DECODE_BCD(lpst->wMinute);
lpst->wHour = DECODE_BCD(lpst->wHour);
lpst->wDay = DECODE_BCD(lpst->wDay);
lpst->wDayOfWeek = DECODE_BCD(lpst->wDayOfWeek);
lpst->wMonth = DECODE_BCD(lpst->wMonth);
lpst->wYear = DECODE_BCD(lpst->wYear);
}
// OK - PC RTC returns 1998 as 98.
lpst->wYear += (lpst->wYear > 70)? 1900 : 2000;
#ifdef NOTDEF
EdbgOutputDebugString("Real Time %d, %d, %d, %d, %d, %d, %d, %d\r\n",
lpst->wYear,
lpst->wMonth,
lpst->wDayOfWeek,
lpst->wDay,
lpst->wHour,
lpst->wMinute,
lpst->wSecond,
lpst->wMilliseconds );
#endif
return (TRUE);
}
//------------------------------------------------------------------------------
// OEMEthGetSecs
//
// Return a count of seconds from some arbitrary time (the absolute value
// is not important, so long as it increments appropriately).
//
//------------------------------------------------------------------------------
DWORD
OEMEthGetSecs()
{
SYSTEMTIME st;
Bare_GetRealTime( &st );
return ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
FindPCINetCard(
BYTE bIRQ
)
{
PCI_SLOT_NUMBER slotNumber;
PCI_COMMON_CONFIG pciConfig;
int bus, device, function;
int length;
DWORD dwBaseAddr = 0;
EdbgOutputDebugString("Searching for PCI NetCard @ IRQ %d...\r\n", bIRQ);
for (bus = 0; bus < PCI_MAX_BUS; bus++) {
for (device = 0; device < PCI_MAX_DEVICES; device++) {
slotNumber.u.bits.DeviceNumber = device;
for (function = 0; function < PCI_MAX_FUNCTION; function++) {
slotNumber.u.bits.FunctionNumber = function;
length = PCIGetBusDataByOffset(bus, slotNumber.u.AsULONG,
&pciConfig, 0, sizeof(pciConfig) -
sizeof(pciConfig.DeviceSpecific));
if (length == 0 || pciConfig.VendorID == 0xFFFF)
break;
if ((pciConfig.BaseClass == PCI_CLASS_NETWORK_CTLR) &&
(pciConfig.SubClass == PCI_SUBCLASS_NET_ETHERNET_CTLR)) {
// EdbgOutputDebugString("Found PCI Net card @ %d:%d:%d...\r\n", bus, device, function);
// EdbgOutputDebugString(" Base Address = 0x%04X\r\n", pciConfig.u.type0.BaseAddresses[0]);
// EdbgOutputDebugString(" IRQ = %d\r\n", pciConfig.u.type0.InterruptLine);
if (pciConfig.u.type0.InterruptLine == bIRQ) {
//
// It's an ethernet controller with the matching IRQ
// setting. The InterruptLine register must have been
// set by the PnP BIOS.
//
dwBaseAddr = pciConfig.u.type0.BaseAddresses[0] & 0xFFFC;
EdbgOutputDebugString("Found PCI Net card @ 0x%X, IRQ%d\r\n", dwBaseAddr, bIRQ);
break;
}
}
if (function == 0 && !(pciConfig.HeaderType & 0x80))
break;
}
if (dwBaseAddr || length == 0)
break;
}
if (dwBaseAddr || (length == 0 && device == 0))
break;
}
if (dwBaseAddr == 0) {
EdbgOutputDebugString("No PCI NetCard found @ IRQ %d...\r\n", bIRQ);
}
return (dwBaseAddr);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?