Пример #1
0
static int
console_rx_char(void *arg, uint8_t data)
{
    struct console_tty *ct = (struct console_tty *)arg;
    struct console_ring *tx = &ct->ct_tx;
    struct console_ring *rx = &ct->ct_rx;
    int tx_space;

    if (CONSOLE_HEAD_INC(&ct->ct_rx) == ct->ct_rx.cr_tail) {
        /*
         * RX queue full. Reader must drain this.
         */
        if (ct->ct_rx_cb) {
            ct->ct_rx_cb(0);
        }
        return -1;
    }

    tx_space = console_buf_space(tx);
    /* echo */
    switch (data) {
    case '\r':
    case '\n':
        /*
         * linefeed
         */
        if (tx_space < 3) {
            console_tx_flush(ct, 3);
        }
        console_add_char(tx, '\n');
        console_add_char(tx, '\r');
        console_add_char(rx, '\n');
        if (ct->ct_rx_cb) {
            ct->ct_rx_cb(1);
        }
        break;
    case '\b':
        /*
         * backspace
         */
        if (tx_space < 3) {
            console_tx_flush(ct, 3);
        }
        console_add_char(tx, '\b');
        console_add_char(tx, ' ');
        console_add_char(tx, '\b');
        console_pull_char_head(rx);
        break;
    default:
        if (tx_space < 1) {
            console_tx_flush(ct, 1);
        }
        console_add_char(tx, data);
        console_add_char(rx, data);
        break;
    }
    hal_uart_start_tx(CONSOLE_UART);
    return 0;
}
Пример #2
0
int do_printk(int msg_level, const char *fmt, ...)
{
	va_list args;
	int i;

	if (!console_log_level(msg_level))
		return 0;

#if CONFIG_SQUELCH_EARLY_SMP && defined(__PRE_RAM__)
	if (!boot_cpu())
		return 0;
#endif

	DISABLE_TRACE;
	spin_lock(&console_lock);

	va_start(args, fmt);
	i = vtxprintf(wrap_putchar, fmt, args, NULL);
	va_end(args);

	console_tx_flush();

	spin_unlock(&console_lock);
	ENABLE_TRACE;

	return i;
}
Пример #3
0
void
console_blocking_mode(void)
{
    struct console_tty *ct = &console_tty;
    int sr;

    OS_ENTER_CRITICAL(sr);
    ct->ct_write_char = console_blocking_tx;

    console_tx_flush(ct, CONSOLE_TX_BUF_SZ);
    OS_EXIT_CRITICAL(sr);
}
Пример #4
0
void
console_blocking_mode(void)
{
    struct console_tty *ct = &console_tty;
    int sr;

    OS_ENTER_CRITICAL(sr);
    if (ct->ct_write_char) {
        ct->ct_write_char = console_blocking_tx;

        console_tx_flush(ct, MYNEWT_VAL(CONSOLE_TX_BUF_SIZE));
    }
    OS_EXIT_CRITICAL(sr);
}
Пример #5
0
int do_printk(int msg_level, const char *fmt, ...)
{
	va_list args;
	int i;

	if (msg_level > console_loglevel) {
		return 0;
	}

	spin_lock(&console_lock);

	va_start(args, fmt);
	i = vtxprintf(console_tx_byte, fmt, args);
	va_end(args);

	console_tx_flush();

	spin_unlock(&console_lock);

	return i;
}
Пример #6
0
int do_printk(int msg_level, const char *fmt, ...)
{
    va_list args;
    int i;

    if (msg_level > console_loglevel) {
        return 0;
    }

#if CONFIG_SQUELCH_EARLY_SMP
    if (!boot_cpu())
        return 0;
#endif

    va_start(args, fmt);
    i = vtxprintf(console_tx_byte, fmt, args);
    va_end(args);

    console_tx_flush();

    return i;
}
Пример #7
0
void main(void)
{
	console_init();

	/* TODO: Follow Section 6.3 (FSBL) of the FU540 manual */

	/*
	 * Flush console before changing clock/UART divisor to prevent garbage
	 * being printed.
	 */
	console_tx_flush();

	clock_init();

	// re-initialize UART
	if (IS_ENABLED(CONFIG_CONSOLE_SERIAL))
		uart_init(CONFIG_UART_FOR_CONSOLE);

	sdram_init();

	cbmem_initialize_empty();

	run_ramstage();
}
Пример #8
0
static int
console_rx_char(void *arg, uint8_t data)
{
    struct console_tty *ct = (struct console_tty *)arg;
    struct console_ring *tx = &ct->ct_tx;
    struct console_ring *rx = &ct->ct_rx;
    int tx_space;
    int i;
    int tx_buf[3];

    if (CONSOLE_HEAD_INC(&ct->ct_rx) == ct->ct_rx.cr_tail) {
        /*
         * RX queue full. Reader must drain this.
         */
        if (ct->ct_rx_cb) {
            ct->ct_rx_cb();
        }
        return -1;
    }

    /* echo */
    switch (data) {
    case '\r':
    case '\n':
        /*
         * linefeed
         */
        tx_buf[0] = '\n';
        tx_buf[1] = '\r';
        tx_space = 2;
        console_add_char(rx, '\n');
        if (ct->ct_rx_cb) {
            ct->ct_rx_cb();
        }
        break;
    case CONSOLE_ESC:
        ct->ct_esc_seq = 1;
        goto out;
    case '[':
        if (ct->ct_esc_seq == 1) {
            ct->ct_esc_seq = 2;
            goto out;
        } else {
            goto queue_char;
        }
        break;
    case CONSOLE_LEFT:
        if (ct->ct_esc_seq == 2) {
            goto backspace;
        } else {
            goto queue_char;
        }
        break;
    case CONSOLE_UP:
    case CONSOLE_DOWN:
        if (ct->ct_esc_seq == 2) {
            /*
             * Do nothing.
             */
            ct->ct_esc_seq = 0;
            goto out;
        }
        goto queue_char;
    case CONSOLE_RIGHT:
        if (ct->ct_esc_seq == 2) {
            data = ' '; /* add space */
        }
        goto queue_char;
    case '\b':
    case CONSOLE_DEL:
backspace:
        /*
         * backspace
         */
        ct->ct_esc_seq = 0;
        if (console_pull_char_head(rx) == 0) {
            /*
             * Only wipe out char if we can pull stuff off from head.
             */
            tx_buf[0] = '\b';
            tx_buf[1] = ' ';
            tx_buf[2] = '\b';
            tx_space = 3;
        } else {
            goto out;
        }
        break;
    default:
queue_char:
        tx_buf[0] = data;
        tx_space = 1;
        ct->ct_esc_seq = 0;
        console_add_char(rx, data);
        break;
    }
    if (!ct->ct_echo_off) {
        if (console_buf_space(tx) < tx_space) {
            console_tx_flush(ct, tx_space);
        }
        for (i = 0; i < tx_space; i++) {
            console_add_char(tx, tx_buf[i]);
        }
        hal_uart_start_tx(CONSOLE_UART);
    }
out:
    return 0;
}
Пример #9
0
static int
console_rx_char(void *arg, uint8_t data)
{
    struct console_tty *ct = (struct console_tty *)arg;
    struct console_ring *tx = &ct->ct_tx;
    struct console_ring *rx = &ct->ct_rx;
    int tx_space = 0;
    int i;
#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
    uint8_t tx_buf[MYNEWT_VAL(CONSOLE_RX_BUF_SIZE)];
#else
    uint8_t tx_buf[3];
#endif

    if (CONSOLE_HEAD_INC(&ct->ct_rx) == ct->ct_rx.cr_tail) {
        /*
         * RX queue full. Reader must drain this.
         */
        if (ct->ct_rx_cb) {
            ct->ct_rx_cb();
        }
        return -1;
    }

    /* echo */
    switch (data) {
    case '\r':
    case '\n':
        /*
         * linefeed
         */
        tx_buf[0] = '\n';
        tx_buf[1] = '\r';
        tx_space = 2;
        console_add_char(rx, '\n');
#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
        console_hist_add(rx);
#endif
        if (ct->ct_rx_cb) {
            ct->ct_rx_cb();
        }
        break;
    case CONSOLE_ESC:
        ct->ct_esc_seq = 1;
        goto out;
    case '[':
        if (ct->ct_esc_seq == 1) {
            ct->ct_esc_seq = 2;
            goto out;
        } else {
            goto queue_char;
        }
        break;
    case CONSOLE_LEFT:
        if (ct->ct_esc_seq == 2) {
            goto backspace;
        } else {
            goto queue_char;
        }
        break;
    case CONSOLE_UP:
    case CONSOLE_DOWN:
        if (ct->ct_esc_seq != 2) {
            goto queue_char;
        }
#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
        tx_space = console_hist_move(rx, tx_buf, data);
        tx_buf[tx_space] = 0;
        ct->ct_esc_seq = 0;
        /*
         * when moving up, stop on oldest history entry
         * when moving down, let it delete input before leaving...
         */
        if (data == CONSOLE_UP && tx_space == 0) {
            goto out;
        }
        if (!ct->ct_echo_off) {
            /* HACK: clean line by backspacing up to maximum possible space */
            for (i = 0; i < MYNEWT_VAL(CONSOLE_TX_BUF_SIZE); i++) {
                if (console_buf_space(tx) < 3) {
                    console_tx_flush(ct, 3);
                }
                console_add_char(tx, '\b');
                console_add_char(tx, ' ');
                console_add_char(tx, '\b');
                uart_start_tx(ct->ct_dev);
            }
            if (tx_space == 0) {
                goto out;
            }
        } else {
            goto queue_char;
        }
        break;
#else
        ct->ct_esc_seq = 0;
        goto out;
#endif
    case CONSOLE_RIGHT:
        if (ct->ct_esc_seq == 2) {
            data = ' '; /* add space */
        }
        goto queue_char;
    case '\b':
    case CONSOLE_DEL:
backspace:
        /*
         * backspace
         */
        ct->ct_esc_seq = 0;
        if (console_pull_char_head(rx) == 0) {
            /*
             * Only wipe out char if we can pull stuff off from head.
             */
            tx_buf[0] = '\b';
            tx_buf[1] = ' ';
            tx_buf[2] = '\b';
            tx_space = 3;
        } else {
            goto out;
        }
        break;
    default:
queue_char:
        tx_buf[0] = data;
        tx_space = 1;
        ct->ct_esc_seq = 0;
        console_add_char(rx, data);
        break;
    }
    if (!ct->ct_echo_off) {
        if (console_buf_space(tx) < tx_space) {
            console_tx_flush(ct, tx_space);
        }
        for (i = 0; i < tx_space; i++) {
            console_add_char(tx, tx_buf[i]);
        }
        uart_start_tx(ct->ct_dev);
    }
out:
    return 0;
}
Пример #10
0
void do_vtxprintf(const char *fmt, va_list args)
{
	vtxprintf(wrap_putchar, fmt, args, NULL);
	console_tx_flush();
}