⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 LP1071 无线局域网卡WinCE驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:

        while (!(selection >= '0' && selection <= '7')  
              && selection != 'D' && selection != 'd'
              && selection != 'L' && selection != 'l'
              && selection != 'R' && selection != 'r')
        {
            selection = OEMReadDebugByte();
        }

        EdbgOutputDebugString ( "%c\r\n", selection);
        
        switch (selection) {
            case '0':
                SetMACAddr(g_MyAddr.wMAC);
                memcpy(pBootCfg->MACAddr, g_MyAddr.wMAC, 6);
                bConfigChanged = TRUE;
                break;
                
            case '1':
                if (SetIPAndSubnet(pBootCfg, TRUE))
                    bConfigChanged = TRUE;
                break;
                
            case '2':
                if (SetIPAndSubnet(pBootCfg, FALSE))
                    bConfigChanged = TRUE;
                break;
                
            case '3':
                ToggleDHCP(pBootCfg);
                bConfigChanged = TRUE;
                
                break;
            case '4':
                OALResetBootCFG(pBootCfg);
                bConfigChanged = TRUE;
                break;
                
            case '5':
                OALWriteBootCFG(pBootCfg);
                break;

            case '6':
                // Toggles autoboot enable and displays autoboot selection
                AutobootMenu(pBootCfg);
                bConfigChanged = TRUE;
                break;

#if NAND_BOOT_SUPPORT
            case '7':
                if (NandFlashMenu(pBootCfg, &bConfigChanged) == TRUE) {
                    bDownloadImage = FALSE;
                    goto MENU_DONE;
                }
                break;
#endif

            case 'D':
            case 'd':
                bDownloadImage = TRUE;     
                goto MENU_DONE;

            case 'L':
            case 'l':
                // Set Launch Address to Flash Address
                pBootCfg->LaunchAddress = FLASH_CVBASE + EBOOT_IMAGE_SIZE + 0x1000;
                bDownloadImage = FALSE;     
                goto MENU_DONE;

            case 'R':
            case 'r':                        
                bDownloadImage = FALSE;     
                goto MENU_DONE;                        

            default:
                break;
        }
    }

MENU_DONE:

    // If eboot settings were changed by user, save them to flash.
    if (bConfigChanged)
        OALWriteBootCFG(pBootCfg);

    return bDownloadImage;
}

//------------------------------------------------------------------------------
//
// Function: SetIPAndSubnet
//
// This function is used to implement the IP/subnet change menu.
//
// Parameters:        
//      pBootCfg
//          [in/out] ptr to bootloader configuration structure
//
// Returns:        
//      TRUE if new IP/Subnet Mask is entered. FALSE otherwise
//
//------------------------------------------------------------------------------
static BOOL SetIPAndSubnet(BOOT_CFG *pBootCfg, BOOL bSetIP)
{
    CHAR szDottedD[16];    // The string used to collect the dotted decimal IP address
    WORD cwNumChars = 0;
    UINT16 InChar = 0;
    BOOL bChanged = FALSE;

    if (bSetIP)
        EdbgOutputDebugString ( "\r\nEnter new IP address: ");
    else
        EdbgOutputDebugString ( "\r\nEnter new subnet mask: ");
        
    while (!((InChar == 0x0d) || (InChar == 0x0a))) {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) {
            // If it's a number or a period, add it to the string
            if (InChar == '.' || (InChar >= '0' && InChar <= '9')) {
                if (cwNumChars < 16) {
                    szDottedD[cwNumChars++] = (CHAR)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)  {
                if (cwNumChars > 0) {
                    cwNumChars--;
                    DELETE_CHAR;
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    if (cwNumChars) {
        szDottedD[cwNumChars] = '\0';
        if (bSetIP)
            pBootCfg->IPAddr = inet_addr(szDottedD);            
        else
            pBootCfg->SubnetMask = inet_addr(szDottedD);

        bChanged = TRUE;
    }

    if (bSetIP)
        ClearPromiscuousIP();
    
    return bChanged;
}

//------------------------------------------------------------------------------
//
// Function: SetMACAddr
//
// This function implements the MAC Address change menu.
//
// Parameters:        
//      pMacAddress
//          [in/out] - MAC address
//
// Returns:        
//      None.
//
//------------------------------------------------------------------------------
static void SetMACAddr(UINT16 *pMacAddress)
{
    UINT8 szLocalMAC[6];    // Store new MAC Address
    WORD cwNumChars = 0;
    CHAR InChar = 0;
    BOOL bValid = TRUE;
    UINT8 cHiByte;

    EdbgOutputDebugString ( "\r\nEnter New MAC Address [Format: XX:XX:XX:XX:XX]: ");

    while (1) {
        InChar = OEMReadDebugByte();
        if ((InChar == 0x0d) || (InChar == 0x0a)) break;
        
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) {
            if (InChar == 0x08 && cwNumChars > 0) {
                // it's backspace
                if((cwNumChars < 12) && ((cwNumChars % 2) == 0)) {
                    // bypass ':' the separator
                    DELETE_CHAR;                    
                }
                DELETE_CHAR;
                cwNumChars--;
                
            } else if(cwNumChars < 12) {

                bValid=TRUE;
                
                if (InChar >= '0' && InChar <= '9') {
                    OEMWriteDebugByte((BYTE)InChar);
                    InChar -= 0x30;
                } else if (InChar >= 'A' && InChar <= 'F') {
                    OEMWriteDebugByte((BYTE)InChar);
                    InChar -= 0x37;
                } else if (InChar >= 'a' && InChar <= 'f') {
                    OEMWriteDebugByte((BYTE)InChar);
                    InChar -= 0x57;
                } else {
                    bValid = FALSE;
                }

                if (bValid) {
                    // it's valid input
                    if (((cwNumChars + 1) % 2) == 0) {
                        szLocalMAC[cwNumChars / 2] = cHiByte + InChar;
                        if( (cwNumChars + 1) < 12) {
                            // Also write the byte separator field
                            OEMWriteDebugByte((BYTE)':');
                        }
                    } else {
                        cHiByte = InChar << 4;
                        szLocalMAC[cwNumChars/2] = cHiByte;
                    }
                    cwNumChars++;                    
                }
            }
        }
    }

    // Only store a valid MAC Address
    if (cwNumChars == 12) // only valid MAC Address, we save it 
        // Return New MAC Address
        memcpy(pMacAddress,szLocalMAC,sizeof(szLocalMAC));
}

//------------------------------------------------------------------------------
//
// Function: ToggleDHCP
//
// Implements the enable/disable DHCP menu.
//
// Parameters:        
//      pBootCfg
//          [in/out] ptr to bootloader configuration structure
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
static void ToggleDHCP(BOOT_CFG *pBootCfg)
{
    if ((pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP))
        pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_DHCP;
    else
        pBootCfg->ConfigFlags |= CONFIG_FLAGS_DHCP;
}

//------------------------------------------------------------------------------
//
// Function: AutobootMenu
//
// Implements the autoboot feature menu. Toggles autoboot enable and displays 
// selected autoboot option when autoboot is enabled.
//
// Parameters:        
//      pBootCfg
//          [in/out] ptr to bootloader configuration structure
//
// Returns:
//      None.
//                     
//------------------------------------------------------------------------------
static void AutobootMenu(BOOT_CFG *pBootCfg)
{
    BOOL bExitMenu;
    char selection;

    if ((pBootCfg->ConfigFlags & CONFIG_FLAGS_AUTOBOOT)) {
        // Clear all autoboot flags
        pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_AUTOBOOT;
    } else {
        // Set autoboot flag
        pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_AUTOBOOT;

        bExitMenu = FALSE;
        
        do {
            EdbgOutputDebugString("\r\nAutoboot Selection Menu\r\n");
            EdbgOutputDebugString("1) Autoboot from NOR\r\n");
            EdbgOutputDebugString("2) Autoboot from NAND\r\n");
            EdbgOutputDebugString("Enter your selection: ");
            while (1) {
                selection = OEMReadDebugByte();
                if ((selection >= '1' && selection <= '2'))
                    break;
            }

            EdbgOutputDebugString ("%c\r\n\r\n", selection);

            switch (selection) {
                case '1':
                    pBootCfg->ConfigFlags |= CONFIG_FLAGS_AUTOBOOT;
                    pBootCfg->BootDevice = CONFIG_AUTOBOOT_DEVICE_NOR;
                    // Return To Main Menu.
                    bExitMenu = TRUE;
                    break;
                    
                case '2':
                    pBootCfg->ConfigFlags |= CONFIG_FLAGS_AUTOBOOT;
                    pBootCfg->BootDevice = CONFIG_AUTOBOOT_DEVICE_NAND;
                    // Return To Main Menu.
                    bExitMenu = TRUE;
                    break;
                    
                default:
                    break;
            }
        } while(bExitMenu == FALSE);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -