Esempio n. 1
0
int putchar(int c)
{
    extern int32_t _the_console_fd;
    extern long xTaskGetSchedulerState( void );
    extern unsigned long getNesting( void );
    if ((intContext() == TRUE) || (_the_console_fd <= 0)
            || (getNesting() > 0)) //|| (xTaskGetSchedulerState() != 1))
    {
        /* 在终端中或调度器未运行时直接调用底层输出保证不使用taskDelay */
        if (c == '\n')
        {
            bsp_putchar('\r');
        }
        bsp_putchar((unsigned char)c);
    }
    else
    {
        if((c) == '\n')
        {
            char ch = '\r';
            dev_write(_the_console_fd, (uint8_t* )&ch, 1);
        }
        dev_write(_the_console_fd, (uint8_t* )&c, 1);
    }
    return 1;
}
Esempio n. 2
0
void bsp_put_string(char *string)
{
    while (*string != '\0')
    {
        bsp_putchar(*string);
        string++;
    }
}
Esempio n. 3
0
void bsp_printf(char * pcStr,...)
{
    char  *argP;

    vaStart(argP, pcStr);       /* point at the end of the format string */
    while (*pcStr)
    {                       /* this works because args are all ints */
        if (*pcStr == '%')
            pcStr = format_item(pcStr + 1, vaArg(argP, int));
        else
            bsp_putchar(*pcStr++);
    }
Esempio n. 4
0
int putchar(int c)
{
extern uint32_t consoleFd;
#if 1
    if((c) == '\n'){
        char ch = '\r';
        ttyWrite(consoleFd, (uint8_t* )&ch, 1);
        ttyWrite(consoleFd, (uint8_t* )&c, 1);
    }
    else
#endif
        ttyWrite(consoleFd, (uint8_t* )&c, 1);

#if 0
extern void bsp_putchar(char_t c);
    if (c == '\n')
    {
        bsp_putchar('\r');
    }

    bsp_putchar((unsigned char)c);
#endif
    return 1;
}
Esempio n. 5
0
static char *format_item(char *f, int a)
{
    char   c;
    int    fieldwidth = 0;
    int    leftjust = 0;
    int    radix = 0;
    char   fill = ' ';

    if (*f == '0')
        fill = '0';

    while ((c = *f++) != 0)
    {
        if (c >= '0' && c <= '9')
        {
            fieldwidth = (fieldwidth * 10) + (c - '0');
        }
        else
            switch (c)
            {
                case '\000':
                    return (--f);
                case '%':
                    bsp_putchar('%');
                    return (f);
                case '-':
                    leftjust = 1;
                    break;
                case 'c':
                    {
                        if (leftjust)
                            bsp_putchar(a & 0x7f);

                        if (fieldwidth > 0)
                            bsp_put_rep_char(fill, fieldwidth - 1);

                        if (!leftjust)
                            bsp_putchar(a & 0x7f);
                        return (f);
                    }
                case 's':
                    {
                        if (leftjust)
                            bsp_put_string((char *)a);

                        if (fieldwidth > strlen((char *)a))
                            bsp_put_rep_char(fill, fieldwidth - strlen((char *)a));

                        if (!leftjust)
                            bsp_put_string((char *)a);
                        return (f);
                    }
                case 'd':
                case 'i':
                    radix = -10;
                    break;
                case 'u':
                    radix = 10;
                    break;
                case 'x':
                    radix = 16;
                    break;
                case 'X':
                    radix = 16;
                    break;
                case 'o':
                    radix = 8;
                    break;
                default:
                    radix = 3;
                    break;      /* unknown switch! */
            }
        if (radix)
            break;
    }

    if (leftjust)
        fieldwidth = -fieldwidth;

    bsp_put_number(a, radix, fieldwidth, fill);

    return (f);
}
Esempio n. 6
0
static void put_string_reverse(char *s, int index)
{
    while ((index--) > 0)
        bsp_putchar(s[index]);
}
Esempio n. 7
0
static void bsp_put_rep_char(char c, int count)
{
    while (count--)
        bsp_putchar(c);
}