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

📄 pollio.c

📁 FS4510开发板示例程序 demo5_pre----中断服务程序 串口驱动 演示的功能包括中断 定时器 串口 它提供了可以在 FS4510板子上运行的参考代码 文件说明 demo
💻 C
📖 第 1 页 / 共 3 页
字号:
    UCHAR rc;
    char line[80], *line_ptr, *seg_ptr;
    ULONG temp, ip_byte[4];
    int i;
    UCHAR *ptr;

    Print(string);
    switch (ptype)
    {
        case DECIMAL:
            Print(" [%d] ", *((ULONG *)parm_ptr));
            get_line();
            if (read_num(inp_buff, 10, &temp))
               *((ULONG *)parm_ptr) = temp;
            break;

        case HEX:
            Print(" [%X] ", *((ULONG *)parm_ptr));
            get_line();
            if (read_num(inp_buff, 16, &temp))
               *((ULONG *)parm_ptr) = temp;
            break;

        case FLAG:
            Print(" [%c] ", (*((UCHAR *)parm_ptr) ? 'Y' : 'N'));
            if ((rc = read_string(line)) != 0)
            {
                if (rc != 1)
                    Print("Invalid response\007\n");
                else if ((line[0] == 'Y') || (line[0] == 'y'))
                   *((UCHAR *)parm_ptr) = 1;
                else if ((line[0] == 'N') || (line[0] == 'n'))
                   *((UCHAR *)parm_ptr) = 0;
                else
                    Print("Invalid response\007\n");
            }
        break;

    case CHAR:
        Print(" [%c] ", *((UCHAR *)parm_ptr));
        if ((rc = read_string(line)) != 0)
        {
            if (rc != 1)
                Print("Invalid response\007\n");
            else
               *((UCHAR *)parm_ptr) = line[0];
            }
        break;

    case STRING:
        Print(" [%s] ", (UCHAR *)parm_ptr);
        if ((rc = read_string(line)) != 0)
            {
            line_ptr = line;
            ptr = (UCHAR *)parm_ptr;
            while ((*ptr++ = *line_ptr++) != 0);
            }
        break;

    case IP:
        Print(" [%I] ", *((ULONG *)parm_ptr));

        if ((rc = read_string(line)) != 0)
            {
            line_ptr = line;
            for (i = 3; i >= 0; i--)
                {
                seg_ptr = line_ptr;
                while ((*line_ptr) && (*line_ptr != '.'))
                    line_ptr++;
                if ((*line_ptr == '.') && (line_ptr[1]))
                   *line_ptr++ = 0;
                if (!read_num(seg_ptr, 10, &ip_byte[i]) || (ip_byte[i] > 255))
                    {
                    Print("Invalid IP address\n");
                    return;
                    }
                }
           *((ULONG *)parm_ptr) = (ip_byte[3] << 24)
                                  + (ip_byte[2] << 16)
                                  + (ip_byte[1] << 8)
                                  + ip_byte[0];
            }
        break;
    }
}

/***********************************************************************/
/*                                                                     */
/*   This subset of printf() supports the following conversion types:  */
/*                                                                     */
/*      %d, %i - output number as a signed decimal (this implementa-   */
/*               tion only uses the low 16 bits of the argument)       */
/*      %o - output number as an unsigned octal number                 */
/*      %x, %X - output number as unsigned hexadecimal                 */
/*      %c - output a single character                                 */
/*      %s - ouput a string                                            */
/*                                                                     */
/*   In addition, the normal width and precision specifiers may be     */
/*   used.                                                             */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/*        putb: Output a character                                     */
/*                                                                     */
/*      INPUTS: ch = character to output                               */
/*                                                                     */
/***********************************************************************/
static void putb(UCHAR ch)
{
    SerialPollConout(ch);
    if (ch == '\n')
        SerialPollConout('\r');
}

/***********************************************************************/
/*    isdigit: Determine whether a character is an ASCII decimal digit */
/*                                                                     */
/*      INPUTS: c = character to check                                 */
/*                                                                     */
/*     RETURNS: TRUE if "c" is a decimal digit                         */
/*                                                                     */
/***********************************************************************/
static UCHAR isdigit(char c)
{
    return (c >= '0') && (c <= '9');
}

/***********************************************************************/
/*     charout: Output a character                                     */
/*                                                                     */
/*      INPUTS: f_flags = ptr to format data structure                 */
/*              arg_pt = ptr to next argument in list                  */
/*                                                                     */
/***********************************************************************/
static void charout(FORMAT *f_flags, va_list *arg_pt)
{
    UCHAR cbuf[2];

    cbuf[0] = (UCHAR) va_arg((*arg_pt), ULONG);
    strout(f_flags, cbuf, 1);
}

/***********************************************************************/
/*      strlen: returns length of a string                             */
/*                                                                     */
/*      INPUTS: str = ptr to string being measured                     */
/*                                                                     */
/***********************************************************************/
static ULONG strlen(UCHAR *str)
{
    long i;

    for(i = 0; *str++; i++);

    return i;
}

/***********************************************************************/
/*   stringout: Output a string                                        */
/*                                                                     */
/*      INPUTS: f_flags = ptr to format data structure                 */
/*              arg_pt = ptr to next argument in list                  */
/*                                                                     */
/*        NOTE: Strings longer than 100 bytes are truncated!           */
/*                                                                     */
/***********************************************************************/
static void stringout(FORMAT *f_flags, va_list *arg_pt)
{
    UCHAR *str, str_buff[102];
    UCHAR *pt;
    ULONG str_len;
    
    pt = &str_buff[101];
    str = (UCHAR *)va_arg((*arg_pt), int);
    str_len = strlen(str);
    if (str_len > f_flags->precision && f_flags->precision != 0)
    str_len = f_flags->precision;
    if (str_len > 100) str_len = 100;
    
    *(pt) = '\0';
    pt = pt - str_len;
    copy(pt, str, str_len);
    
    strout(f_flags, pt, strlen(pt));
}

/***********************************************************************/
/*      decout: Output a value as a decimal number                     */
/*                                                                     */
/*      INPUTS: f_flags = ptr to format data structure                 */
/*              arg_pt = ptr to next argument in list                  */
/*                                                                     */
/***********************************************************************/
static void decout(FORMAT *f_flags, va_list *arg_pt)
{
    UCHAR dec_buff[20], *pt, neg;
    long val, s_length;
    ULONG t_count;

    t_count = 0;
    pt = &dec_buff[19];
    neg = FALSE;

    /*---------------------------------------------------------------------*/
    /* Get the value to output from the argument list.                     */
    /*---------------------------------------------------------------------*/
    if (f_flags->mod == 'h')
        val = (short) va_arg((*arg_pt), long);
    else
        val = (long) va_arg((*arg_pt), long);
    
    /*---------------------------------------------------------------------*/
    /* Null terminate the output string.  Not included in output count.    */
    /*---------------------------------------------------------------------*/
    *(pt--) = '\0';

    /*---------------------------------------------------------------------*/
    /* If val is negative, set the true flag and multiply by -1.           */
    /*---------------------------------------------------------------------*/
    if (val < 0)
    {
        neg = LTRUE;
        val = -val;
    }

    /*---------------------------------------------------------------------*/
    /* While val is greater than zero, output characters to the string     */
    /* from right to left.                                                 */
    /*---------------------------------------------------------------------*/
    do
    {
        long i, tmp;

        /*-----------------------------------------------------------------*/
        /* The next two statements cause problems on the 68000, since that */
        /* processor does not have a 32-bit divide instruction.  They are  */
        /* replaced by functionally equivalent routines.                   */
        /*-----------------------------------------------------------------*/

        /*  *(pt--) = val % 10 + '0';  */
        tmp = val;
        
        
        while (tmp >= 10000) tmp -= 10000;
        while (tmp >= 1000) tmp -= 1000;
        while (tmp >= 100) tmp -= 100;
        
        while ((tmp -= 10) >= 10);
        if (tmp < 0) tmp += 10;
        *(pt--) = (UCHAR)(tmp + '0');
        
        /*   val /= (short)10;        */
        if (val >= 10)
        {
            for (i = 0; val >= 100000; i += 10000) val -= 100000;
            for (     ; val >=  10000; i +=  1000) val -= 10000;
            for (     ; val >=   1000; i +=   100) val -= 1000;
            for (     ; val >=    100; i +=    10) val -= 100;
            for (     ; val >=     10; i++) val -= 10;
            val = i;
        }
        else
            val = 0;

        t_count++;
    } while (val != 0);

    while (t_count < f_flags->precision)
    {
        *(pt--) = '0';
        t_count++;
    }

    /*---------------------------------------------------------------------*/
    /* Next check to see if the 0 flag was used in the format and if the   */
    /* current count is less than the specified field width.  If TRUE then */
    /* fill in the leading zeros.  Temporarily leave room in the field for */
    /* an optional plus or minus sign.                                     */
    /*---------------------------------------------------------------------*/
    pt++;
    if (f_flags->zero)
    {
        s_length = strlen(pt);
        while (f_flags->width > s_length + 1)
        {
           *(--pt) = '0';
            s_length += 1;
        }
    }

    /*---------------------------------------------------------------------*/
    /* Add leading plus or minus sign, and/or leading zero if needed.      */
    /*---------------------------------------------------------------------*/
    if (neg)
       *(--pt) = '-';
    else if (f_flags->plus)
       *(--pt) = '+';
    else if (f_flags->space)
        *(--pt) = ' ';
    else if ((f_flags->zero) && (f_flags->width > s_length))
       *(--pt) = '0';
    f_flags->precision = DEFAULT;
    strout(f_flags, pt, strlen(pt));
}

/***********************************************************************/
/*      hexout: Output a value as a hexadecimal number                 */
/*                                                                     */
/*      INPUTS: f_flags = ptr to format data structure                 */
/*              arg_pt = ptr to next argument in list                  */
/*                                                                     */
/***********************************************************************/
static void hexout(FORMAT *f_flags, va_list *arg_pt)
{
    UCHAR c, *pt, d[16], hexbuff[16];
    ULONG val, t_count;
    long s_length;
    USHORT i;

    t_count = 0;
    
    /*---------------------------------------------------------------------*/
    /* Set up the array of hex digits used in conversion.                  */
    /*---------------------------------------------------------------------*/
    for (i = 0; i <= 9; i++)
        d[i] = '0' + i;
    c = (f_flags->type == 'X') ? 'A' : 'a';
    for (i = 10; i <= 15; i++)
        d[i] = c++;
    
    /*---------------------------------------------------------------------*/
    /* Obtain the value to be output.                                      */
    /*---------------------------------------------------------------------*/
    if (f_flags->mod == 'h')
        val = (USHORT) va_arg((*arg_pt), ULONG);
    else
        val = (ULONG) va_arg((*arg_pt), ULONG);
    
    /*---------------------------------------------------------------------*/
    /* Null terminate string then process the value.                       */
    /*---------------------------------------------------------------------*/
    pt = &hexbuff[15];
    *(pt--) = '\0';

    /*---------------------------------------------------------------------*/
    /* Process the value                                                   */
    /*---------------------------------------------------------------------*/
    do
    {
        *(pt--) = d[val & 0xf];
        t_count++;

⌨️ 快捷键说明

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