From 3af1373cac5893502605cd26de433046f00e1fc5 Mon Sep 17 00:00:00 2001 From: Jacek Maksymowicz Date: Thu, 26 Sep 2024 18:45:13 +0200 Subject: [PATCH] imxrt-multi: Allow UART_CONSOLE_USER to be defined empty JIRA: RTOS-754 --- multi/imxrt-multi/config.h | 35 +++++++++++++++++++++------------ multi/imxrt-multi/imxrt-multi.c | 9 ++++++--- multi/imxrt-multi/rtt.c | 2 +- multi/imxrt-multi/uart.c | 4 ++-- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/multi/imxrt-multi/config.h b/multi/imxrt-multi/config.h index 5f1c7f68..5296adaa 100644 --- a/multi/imxrt-multi/config.h +++ b/multi/imxrt-multi/config.h @@ -754,7 +754,7 @@ /* clang-format on */ -#if !defined(UART_CONSOLE) && !defined(RTT_CHANNEL_CONSOLE) +#ifndef UART_CONSOLE #if defined(__CPU_IMXRT105X) #define UART_CONSOLE 1 #elif defined(__CPU_IMXRT106X) @@ -766,14 +766,22 @@ #endif #endif -#if defined(UART_CONSOLE) -#if ISEMPTY(UART_CONSOLE) -#error "UART_CONSOLE must not be empty" -#elif UART_CONSOLE <= 0 +#if !ISEMPTY(UART_CONSOLE) +#if UART_CONSOLE <= 0 #error "Invalid value for UART_CONSOLE" #endif #endif +#if defined(UART_CONSOLE_USER) +#if !ISEMPTY(UART_CONSOLE_USER) +#if (UART_CONSOLE_USER <= 0) +#error "Invalid value for UART_CONSOLE_USER" +#endif +#endif +#else +#define UART_CONSOLE_USER UART_CONSOLE +#endif + /* RTT */ @@ -802,18 +810,19 @@ #endif -#if defined(UART_CONSOLE) && defined(RTT_CHANNEL_CONSOLE) -#error "Console on UART and RTT not supported" -#elif defined(RTT_CHANNEL_CONSOLE) -#if ISEMPTY(RTT_CHANNEL_CONSOLE) -#error "RTT_CHANNEL_CONSOLE must not be empty" -#elif RTT_CHANNEL_CONSOLE < 0 +#ifndef RTT_CHANNEL_CONSOLE +#define RTT_CHANNEL_CONSOLE +#elif !ISEMPTY(RTT_CHANNEL_CONSOLE) +#if RTT_CHANNEL_CONSOLE < 0 #error "Invalid value for RTT_CHANNEL_CONSOLE" #endif - -#define ONLY_RTT_CONSOLE #endif +#if !ISEMPTY(UART_CONSOLE_USER) && !ISEMPTY(RTT_CHANNEL_CONSOLE) +#error "Console on both UART and RTT not supported" +#elif ISEMPTY(UART_CONSOLE_USER) && ISEMPTY(RTT_CHANNEL_CONSOLE) +#error "Console must be either on UART or RTT" +#endif /* SPI */ diff --git a/multi/imxrt-multi/imxrt-multi.c b/multi/imxrt-multi/imxrt-multi.c index 3394290d..9744077c 100644 --- a/multi/imxrt-multi/imxrt-multi.c +++ b/multi/imxrt-multi/imxrt-multi.c @@ -169,10 +169,13 @@ static void uart_dispatchMsg(msg_t *msg) switch (id) { case id_console: -#ifdef ONLY_RTT_CONSOLE +#if !ISEMPTY(RTT_CHANNEL_CONSOLE) rtt_handleMsg(msg, RTT_CHANNEL_CONSOLE + id_rtt0); -#else +#elif !ISEMPTY(UART_CONSOLE_USER) uart_handleMsg(msg, UART_CONSOLE - 1 + id_uart1); +#else + /* TODO: Add support for no console */ + msg->o.err = -ENODEV; #endif break; @@ -608,7 +611,7 @@ int main(void) oid.id = id_console; create_dev(&oid, _PATH_CONSOLE); -#ifdef ONLY_RTT_CONSOLE +#if !ISEMPTY(RTT_CHANNEL_CONSOLE) libklog_init(rtt_klogCblk); #else libklog_init(uart_klogCblk); diff --git a/multi/imxrt-multi/rtt.c b/multi/imxrt-multi/rtt.c index 32f58897..3882a24b 100644 --- a/multi/imxrt-multi/rtt.c +++ b/multi/imxrt-multi/rtt.c @@ -255,7 +255,7 @@ int rtt_init(void) void rtt_klogCblk(const char *data, size_t size) { -#ifdef RTT_CHANNEL_CONSOLE +#if !ISEMPTY(RTT_CHANNEL_CONSOLE) libtty_write(&rtt_common.uarts[rttPos[RTT_CHANNEL_CONSOLE]].tty_common, data, size, 0); #endif } diff --git a/multi/imxrt-multi/uart.c b/multi/imxrt-multi/uart.c index c27b78f0..e5f237ee 100644 --- a/multi/imxrt-multi/uart.c +++ b/multi/imxrt-multi/uart.c @@ -772,8 +772,8 @@ static void uart_initPins(void) void uart_klogCblk(const char *data, size_t size) { -#ifdef UART_CONSOLE - libtty_write(&uart_common.uarts[uartPos[UART_CONSOLE - 1]].tty_common, data, size, 0); +#if !ISEMPTY(UART_CONSOLE_USER) + libtty_write(&uart_common.uarts[uartPos[UART_CONSOLE_USER - 1]].tty_common, data, size, 0); #endif }