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

📄 logging.c

📁 AT91所有开发板的资料 AT91所有开发板的资料
💻 C
📖 第 1 页 / 共 4 页
字号:
 *  Pre-conditions: none. * *    Params: *       Input: bit   - a 32 bit word with one bit set corresponding to *                      a LOG_xxx value from logging.h * *   Returns: char * name */char *log_adpname(int reason){    int j;    long r;        reason &= 0xffffff;    for(j = 0; log_adpnames[j].str != NULL; j++)    {        r = log_adpnames[j].reason;        if (reason == r)        {            return log_adpnames[j].str;        }    }    return "(none)";}/* *  Function: log_swiname *   Purpose: Return the name of the module which has adp reason 'reason'; *            note that this is the LOG_xxx value. * *  Pre-conditions: none. * *    Params: *       Input: bit   - a 32 bit word with one bit set corresponding to *                      a LOG_xxx value from logging.h * *   Returns: char * name */char *log_swiname(int reason){    if (reason < (int)((sizeof(swicalls) / sizeof(swicalls[0]))))        return swicalls[reason];    else        return "(unknown)";}void log_dump_buffer(WarnLevel lvl,                log_id mod,                unsigned int width,                char *buffer,                unsigned int length){    unsigned int i, j ;    char b[128] ;    char *p ;    Log_logmsginfo( log_file, __LINE__, mod);    if (length > 256)    {        log_log(lvl, "Buffer 0x%x, length %d (truncated to 256)\n",                buffer, length);        length = 256;    }    else    {        log_log(lvl, "Buffer 0x%x, length %d\n", buffer, length);    }    if (width == 4)    {        for (i = 0; i < length; i += 16)        {            p = b;            p += buf_itoh(p, (unsigned int)&buffer[i], 8, 1);            *p++ = ':';            *p++ = ' ';            for (j = 0; j < 16 && (i + j) < length; j += 4)            {            unsigned int *ptr ;                ptr = (unsigned int *)&buffer[i + j] ;                p += buf_itoh(p, *ptr, 8, 1);                *p++ = ' ';            }            for (; j < 16; j += 4)            {                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';            }            for (j = 0; j < 16 && (i + j) < length; j++)            {            unsigned char c = buffer[i + j];                *p++ = (c >= 0x20 && c < 0x7F) ? c : '.';            }            *p++ = '\0';            Log_logmsginfo( log_file, __LINE__, mod);            log_log(lvl, "%s\n", b);        }    }    else    {        /* Default width to 1 */        for (i = 0; i < length; i +=16)        {            p = b;            p += buf_itoh(p, i, 3, 1);            *p++ = ':';            *p++ = ' ';            for (j = 0; j < 16 && (i + j) < length; j++)            {                p += buf_itoh(p, buffer[i + j] & 0xff, 2, 1);                *p++ = ' ';            }            for (; j <= 16; j++)            {                *p++ = ' ';                *p++ = ' ';                *p++ = ' ';            }            for (j = 0; j < 16 && (i + j) < length; j++)            {            unsigned char c = buffer[i + j];                *p++ = (c >= 0x20 && c < 0x7F) ? c : '.';            }            *p++ = '\0';            Log_logmsginfo( log_file, __LINE__, mod);            log_log(lvl, "%s\n", b);        }    }}/* * Parse the initial segment of a printf % specifier, returning the * base code (d, x, s etc) to the caller and updating format to point * to that character in the source string. *format should point to the * initial %. * * width is the field width (the precision is not supported), padzero is * TRUE if field width began with a 0, longval is TRUE if (ld, lx etc) * was seen. * * A leading '-' on the field width (%-8s etc) is ignored. */char log_readformat(char **format, int *width, int *padzero, int *longval){    char fch = *(++(*format));    /*     * Check if the format has a width specified. NOTE: We do     * not use the "isdigit" function here, since it will     * require run-time support. The current ARM Ltd header     * defines "isdigit" as a macro, that uses a fixed     * character description table.     */    if (fch == '-')        fch = *(++(*format));   /* ignore right-adjust flag */    if ((fch >= '0') && (fch <= '9'))    {        if (fch == '0')        {            /* Leading zeroes padding */            *padzero = TRUE;            fch = *(++(*format));        }        while ((fch >= '0') && (fch <= '9'))        {            *width = (((*width) * 10) + (fch - '0'));            fch = *(++(*format));        }    }    if (fch == 'l')    {        /* skip 'l' in "%lx", etc. */        *longval = TRUE;        fch = *(++(*format));    }    return fch;}/* * Convert the long value ival to text, writing the result character * by character using the 'CHAROUT' macro in hexadecimal.  * * fch is used to specify one of the three variants used: 'p' for * the pointer type (0x00224AFDB etc) 'X' for hex numbers with leading * 0x and capital letter A-F, 'x' for hex numbers with no leading 0x * and lower-case a-f. * * width is the field width, which may be exceeded if representation * of the value demands, pad is TRUE if the value should be padded to * to the left up to the width * */static int log_itoh(char fch, unsigned long uval, int width, int padzero){    int count, loop;    int len = 0, mark = FALSE;    const char *hextab;    char buffer[12];  /* stack space used to hold number */    if (fch == 'X' || fch == 'p')    {        hextab = hextab1;        if (fch == 'p')            mark = TRUE;    }    else    {        hextab = hextab2;    }    /*     * Read each nibble from high to low; unless it's zero copy the     * hex character equivalent into the buffer. Note we start from     * bit (n-4) where (n) is the number of bits in the word, as     * loop is the base bit number (i.e. the nibble is from the bit     * at 'loop' to the bit at 'loop+3'.     */    count = 0;    for (loop = (sizeof(long) * 8) - 4; loop >= 0; loop -= 4)    {        int nibble = (uval >> loop) & 0xF;        if (nibble != 0 || count != 0)        {            buffer[count++] = hextab[nibble];        }    }    if (count == 0)        buffer[count++] = '0';    if (width != 0)      {        width -= count + (mark? 2: 0);        if (padzero)          {            if (mark)              {                CHAROUT('0');                CHAROUT('x');                len += 2;              }            for (; (width > 0); width--)              {                CHAROUT('0');                len++;              }          }        else          {            for (; (width > 0); width--)              {                CHAROUT(' ');                len++;              }            if (mark)              {                CHAROUT('0');                CHAROUT('x');                len += 2;              }          }      }    else if (mark)      {        CHAROUT('0');        CHAROUT('x');        len += 2;      }        for (loop = 0; loop < count; loop++)    {        CHAROUT(buffer[loop]);        len++;    }    return len;}/* * Convert the long value ival to text, writing the result character * by character using the 'CHAROUT' macro in hexadecimal.  * * fch is used to specify one of the three variants used: 'p' for * the pointer type (0x00224AFDB etc) 'X' for hex numbers with leading * 0x and capital letter A-F, 'x' for hex numbers with no leading 0x * and lower-case a-f. * * width is the field width, which may be exceeded if representation * of the value demands, pad is TRUE if the value should be padded to * to the left up to the width * */int buf_itoh(char *buf, unsigned long uval, int width, int padzero){    int count, loop;    int len = 0;    char buffer[12];  /* stack space used to hold number */    count = 0;    for (loop = (sizeof(long) * 8) - 4; loop >= 0; loop -= 4)    {        int nibble = (uval >> loop) & 0xF;        if (nibble != 0 || count != 0)        {            buffer[count++] = hextab2[nibble];        }    }    if (count == 0)        buffer[count++] = '0';    if (width != 0)    {        width -= count;                for (; (width > 0); width--)        {            *buf++ = (padzero)?'0':' ';            len++;        }    }        for (loop = 0; loop < count; loop++)    {        *buf++ = (buffer[loop]);        len++;    }    return len;}/* * Convert the long value ival to text, writing the result character * by character using the 'CHAROUT' macro in decimal.  * * width is the field width, which may be exceeded if representation * of the value demands, padzero is TRUE if the value should be padded to * to the left up to the width, sign is TRUE if the value should be * considered to be a signed number. * * note: the sign char is not counted in the field width [BUG] */static int log_itod(long ival, int width, int padzero, int sign){    int count;    int len = 0;    int writeminus = FALSE;    char buffer[12];  /* stack space used to hold number */    if (sign && (ival < 0))    {        ival = -ival;        writeminus = TRUE;    }    /*     * The simplest method of displaying numbers is to     * provide a small recursive routine. However, to reduce     * stack usage the following non-recursive solution is     * used.     */    /*     * Place the conversion into the buffer in     * reverse order:     */    count = 0;    while (ival != 0)    {        buffer[count++] = (char)('0' + ((unsigned long)ival % 10));        ival = ((unsigned long)ival / 10);    }    if (count == 0)        buffer[count++] = '0';    /*     * Check if we are placing the data in a fixed      * width field, and write the minus in the right     * place relative to the padding.     */    if (width != 0)    {        width -= count + (writeminus ? 1 : 0);        if (padzero)        {            if (writeminus)            {                    CHAROUT('-');                len++;            }            for (; (width > 0); width--)            {                CHAROUT('0');                len++;            }        }        else        {            for (; (width > 0); width--)            {                CHAROUT(' ');                len++;            }                            if (writeminus)            {                    CHAROUT('-');                len++;            }        }    }    else if (writeminus)    {            CHAROUT('-');        len++;    }

⌨️ 快捷键说明

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