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

📄 menu.c

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    KITLOutputDebugString ( "\r\nEnter new IP address: ");

    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--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

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


//------------------------------------------------------------------------------
//
//  Function:  SetMask
//
//  Allows user to set a subnet mask using the boot loader menu.
//
//  Parameters:
//      eBootCFG 
//          [out] Points to bootloader configuration that will be updated with
//          the subnet mask entered by the user.
//
//  Returns:
//      None.
//
//------------------------------------------------------------------------------
static void SetMask(EBOOT_CFG *pEbootCFG)
{
    char szDottedD[16]; // The string used to collect the dotted masks
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    KITLOutputDebugString ( "\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--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

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



//------------------------------------------------------------------------------
//
//  Function:  SetBootMe
//
//  Allows user to set a BOOTME packet count using the boot loader menu.
//
//  Parameters:
//      eBootCFG 
//          [out] Points to bootloader configuration that will be updated with
//          the BOOTME packet count entered by the user.
//
//  Returns:
//      None.
//
//------------------------------------------------------------------------------
static void SetBootMe(EBOOT_CFG *pEbootCFG)
{
    char szCount[16];
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    KITLOutputDebugString ( "\r\nUse 0 for continuous boot me packets. \r\n");
    KITLOutputDebugString ( "Enter maximum number of boot me packets to send [0-255]: ");

    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 >= '0' && InChar <= '9'))
            {
                if (cwNumChars < 16)
                {
                    szCount[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)
            {
                if (cwNumChars > 0)
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    if (cwNumChars)
    {
        szCount[cwNumChars] = '\0';
        pEbootCFG->numBootMe = atoi(szCount);
        if (pEbootCFG->numBootMe > 255)
        {
            pEbootCFG->numBootMe = 255;
        }
        else if (pEbootCFG->numBootMe < 0)
        {
            pEbootCFG->numBootMe = 1;
        }
    }
}


//------------------------------------------------------------------------------
//
//  Function:  SetDelay
//
//  Allows user to set a boot delay using the boot loader menu.
//
//  Parameters:
//      eBootCFG 
//          [out] Points to bootloader configuration that will be updated with
//          the boot delay entered by the user.
//
//  Returns:
//      None.
//
//------------------------------------------------------------------------------
static void SetDelay(EBOOT_CFG *pEbootCFG)
{
    char szCount[16];
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    KITLOutputDebugString ( "\r\nEnter maximum number of seconds to delay [1-255]: ");

    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 >= '0' && InChar <= '9'))
            {
                if (cwNumChars < 16)
                {
                    szCount[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)
            {
                if (cwNumChars > 0)
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    if (cwNumChars)
    {
        szCount[cwNumChars] = '\0';
        pEbootCFG->delay = atoi(szCount);
        if (pEbootCFG->delay > 255)
        {
            pEbootCFG->delay = 255;
        }
        else if (pEbootCFG->delay < 1)
        {
            pEbootCFG->delay = 1;
        }
    }
}


//------------------------------------------------------------------------------
//
//  Function:  SetMAC
//
//  Allows user to set a MAC address using the boot loader menu.
//
//  Parameters:
//      eBootCFG 
//          [out] Points to bootloader configuration that will be updated with
//          the MAC address entered by the user.
//
//  Returns:
//      None.
//
//------------------------------------------------------------------------------
static void SetMAC(EBOOT_CFG *pEbootCfg)
{
    CHAR szDottedD[24];
    USHORT cwNumChars = 0;
    USHORT InChar = 0;

    memset(szDottedD, '0', 24);

    EdbgOutputDebugString ( "\r\nEnter new MAC address in hexadecimal (hh.hh.hh.hh.hh.hh): ");

    while(!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        InChar = tolower(InChar);
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
        {
            // If it's a hex number or a period, add it to the string.
            //
            if (InChar == '.' || (InChar >= '0' && InChar <= '9') || (InChar >= 'a' && InChar <= 'f')) 
            {
                if (cwNumChars < 17) 
                {
                    szDottedD[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            else if (InChar == 8)       // If it's a backspace, back up.
            {
                if (cwNumChars > 0) 
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    EdbgOutputDebugString ( "\r\n");

    // If it's a carriage return with an empty string, don't change anything.
    //
    if (cwNumChars) 
    {
        szDottedD[cwNumChars] = '\0';
        CvtMAC(pEbootCfg->mac, szDottedD);
        EdbgOutputDebugString("INFO: MAC address set to: %x:%x:%x:%x:%x:%x\r\n",
                  pEbootCfg->mac[0] & 0x00FF, pEbootCfg->mac[0] >> 8,
                  pEbootCfg->mac[1] & 0x00FF, pEbootCfg->mac[1] >> 8,
                  pEbootCfg->mac[2] & 0x00FF, pEbootCfg->mac[2] >> 8);
        return;
    }
    EdbgOutputDebugString("WARNING: SetCS8900MACAddress: Invalid MAC address.\r\n");
    
}


//------------------------------------------------------------------------------
//
//  Function:  bstrtoul
//
//  Provides boot loader implementation for strtoul.
//
//  Parameters:
//      pStr 
//          [in] Null-terminated string to convert.
//
//      nBase
//          [in] Number base to use for coversion.
//
//  Returns:
//      None.
//
//------------------------------------------------------------------------------
static ULONG bstrtoul(PUCHAR pStr, UCHAR nBase)
{
    UCHAR nPos=0;
    BYTE c;
    ULONG nVal = 0;
    UCHAR nCnt=0;
    ULONG n=0;

    // fulllibc doesn't implement isctype or iswctype, which are needed by
    // strtoul, rather than including coredll code, here's our own simple strtoul.

    if (pStr == NULL)
        return(0);

    for (nPos=0 ; nPos < strlen(pStr) ; nPos++)
    {
        c = tolower(*(pStr + strlen(pStr) - 1 - nPos));
        if (c >= '0' && c <= '9')
            c -= '0';
        else if (c >= 'a' && c <= 'f')
        {
            c -= 'a';
            c  = (0xa + c);
        }

        for (nCnt = 0, n = 1 ; nCnt < nPos ; nCnt++)
        {
            n *= nBase;
        }
        nVal += (n * c);
    }

    return(nVal);
}


//------------------------------------------------------------------------------
//
//  Function:  CvtMAC
//
//  Converts MAC address specified by the user in dotted string format
//  into 16-bit numeric array.
//
//  Parameters:
//      MacAddr 
//          [out] 16-bit numeric array for converted MAC address.
//
//      pszDottedD
//          [in] Points to string containing MAC address.
//
//  Returns:
//      None.
//
//------------------------------------------------------------------------------
static void CvtMAC(USHORT MacAddr[3], char *pszDottedD ) 
{
    DWORD cBytes;
    char *pszLastNum;
    int atoi (const char *s);
    int i=0;    
    BYTE *p = (BYTE *)MacAddr;

    // Replace the dots with NULL terminators
    pszLastNum = pszDottedD;
    for(cBytes = 0 ; cBytes < 6 ; cBytes++)
    {
        while(*pszDottedD != '.' && *pszDottedD != '\0')
        {
            pszDottedD++;
        }
        if (pszDottedD == '\0' && cBytes != 5)
        {
            // zero out the rest of MAC address
            while(i++ < 6)
            {
                *p++ = 0;
            }
            break;
        }
        *pszDottedD = '\0';
        *p++ = (BYTE)(bstrtoul(pszLastNum, 16) & 0xFF);
        i++;
        pszLastNum = ++pszDottedD;
    }
}

⌨️ 快捷键说明

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