zephyr: Switch to interrupt-driven pull-style console.

While this console API improves handling on real hardware boards
(e.g. clipboard paste is much more reliable, as well as programmatic
communication), it vice-versa poses problems under QEMU, apparently
because it doesn't emulate UART interrupt handling faithfully. That
leads to inability to run the testsuite on QEMU at all. To work that
around, we have to suuport both old and new console routines, and use
the old ones under QEMU.
pull/1/head
Paul Sokolovsky 2017-10-07 17:09:53 +03:00
parent 71c1a05d88
commit 4514f073c1
5 changed files with 33 additions and 0 deletions

View File

@ -4,6 +4,12 @@ CONFIG_REBOOT=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_CONSOLE_HANDLER=y
CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y
CONFIG_CONSOLE_PULL=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_CONSOLE_GETCHAR_BUFSIZE=128
CONFIG_CONSOLE_PUTCHAR_BUFSIZE=128
CONFIG_NEWLIB_LIBC=y
CONFIG_FLOAT=y
CONFIG_MAIN_STACK_SIZE=4096

View File

@ -1,3 +1,7 @@
# Interrupt-driven UART console has emulation artifacts under QEMU,
# disable it
CONFIG_CONSOLE_PULL=n
# Networking drivers
# SLIP driver for QEMU
CONFIG_NET_SLIP_TAP=y

View File

@ -1,3 +1,7 @@
# Interrupt-driven UART console has emulation artifacts under QEMU,
# disable it
CONFIG_CONSOLE_PULL=n
# Networking drivers
# SLIP driver for QEMU
CONFIG_NET_SLIP_TAP=y

View File

@ -24,11 +24,16 @@
* THE SOFTWARE.
*/
#include <zephyr.h>
#include <console.h>
#include "zephyr_getchar.h"
int real_main(void);
void main(void) {
#ifdef CONFIG_CONSOLE_PULL
console_init();
#else
zephyr_getchar_init();
#endif
real_main();
}

View File

@ -28,6 +28,7 @@
#include "src/zephyr_getchar.h"
// Zephyr headers
#include <uart.h>
#include <console.h>
/*
* Core UART functions to implement for a port
@ -35,11 +36,23 @@
// Receive single character
int mp_hal_stdin_rx_chr(void) {
#ifdef CONFIG_CONSOLE_PULL
return console_getchar();
#else
return zephyr_getchar();
#endif
}
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
#ifdef CONFIG_CONSOLE_PULL
while (len--) {
char c = *str++;
while (console_putchar(c) == -1) {
k_sleep(1);
}
}
#else
static struct device *uart_console_dev;
if (uart_console_dev == NULL) {
uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);
@ -48,4 +61,5 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
while (len--) {
uart_poll_out(uart_console_dev, *str++);
}
#endif
}