Xtensa port: Added support for Xtensa simulator console driver.

Change-Id: I58effa98fd6ff53bcfd21cb8de2fcd89651dc1d9
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
This commit is contained in:
Mazen NEIFER 2017-01-24 22:03:19 +01:00 committed by Andrew Boie
commit b0669a04b3
4 changed files with 105 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#
# Copyright (c) 2014-2015 Wind River Systems, Inc.
# Copyright (c) 2016 Cadence Design Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -164,6 +165,22 @@ config UART_PIPE_ON_DEV_NAME
This option specifies the name of UART device to be used
for pipe UART.
source "drivers/console/Kconfig.telnet"
config XTENSA_SIM_CONSOLE
bool
prompt "Use Xtensa simulator console"
depends on SIMULATOR_XTENSA
select CONSOLE_HAS_DRIVER
default y
help
Use simulator console to print messages.
config XTENSA_CONSOLE_INIT_PRIORITY
int
prompt "Init priority"
default 60
depends on XTENSA_SIM_CONSOLE
help
Device driver initialization priority.
source "drivers/console/Kconfig.telnet"
endif

View file

@ -5,3 +5,4 @@ obj-$(CONFIG_IPM_CONSOLE_RECEIVER) += ipm_console_receiver.o
obj-$(CONFIG_IPM_CONSOLE_SENDER) += ipm_console_sender.o
obj-$(CONFIG_UART_PIPE) += uart_pipe.o
obj-$(CONFIG_TELNET_CONSOLE) += telnet_console.o
obj-$(CONFIG_XTENSA_SIM_CONSOLE) += xtensa_sim_console.o

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2016 Cadence Design Systems, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
#include <xtensa/simcall.h>
#include <device.h>
#include <init.h>
#if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
/**
* @brief Output one character to SIMULATOR console
* @param c Character to output
* @return The character passed as input.
*/
static int console_out(int c)
{
char buf[16];
register int a2 __asm__ ("a2") = SYS_write;
register int a3 __asm__ ("a3") = 1;
register char *a4 __asm__ ("a4") = buf;
register int a5 __asm__ ("a5") = 1;
register int ret_val __asm__ ("a2");
register int ret_err __asm__ ("a3");
buf[0] = (char)c;
__asm__ ("simcall"
: "=a" (ret_val), "=a" (ret_err)
: "a" (a2), "a" (a3), "a" (a4), "a" (a5));
return c;
}
#endif
#if defined(CONFIG_STDOUT_CONSOLE)
extern void __stdout_hook_install(int (*hook)(int));
#else
#define __stdout_hook_install(x) \
do {/* nothing */ \
} while ((0))
#endif
#if defined(CONFIG_PRINTK)
extern void __printk_hook_install(int (*fn)(int));
#else
#define __printk_hook_install(x) \
do {/* nothing */ \
} while ((0))
#endif
/**
*
* @brief Install printk/stdout hook for Xtensa Simulator console output
* @return N/A
*/
void xt_sim_console_hook_install(void)
{
__stdout_hook_install(console_out);
__printk_hook_install(console_out);
}
/**
*
* @brief Initialize the console/debug port
* @return 0 if successful, otherwise failed.
*/
static int xt_sim_console_init(struct device *arg)
{
ARG_UNUSED(arg);
xt_sim_console_hook_install();
return 0;
}
/* UART consloe initializes after the UART device itself */
SYS_INIT(xt_sim_console_init,
#if defined(CONFIG_EARLY_CONSOLE)
PRIMARY,
#else
SECONDARY,
#endif
CONFIG_XTENSA_CONSOLE_INIT_PRIORITY);

View file

@ -2,6 +2,7 @@
#
# Copyright (c) 2014-2015 Wind River Systems, Inc.
# Copyright (c) 2016 Cadence Design Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#