From 733eeaee46ef250d89866b3d5c0e4535923a5a48 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 Rename RTT_CHANNEL_* to RTT* JIRA: RTOS-754 --- multi/imxrt-multi/config.h | 69 +++++++++++++++++++-------------- multi/imxrt-multi/imxrt-multi.c | 15 ++++--- multi/imxrt-multi/rtt.c | 16 ++++---- multi/imxrt-multi/uart.c | 4 +- 4 files changed, 58 insertions(+), 46 deletions(-) diff --git a/multi/imxrt-multi/config.h b/multi/imxrt-multi/config.h index 5f1c7f68..5eb5ceb3 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,54 +766,63 @@ #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 */ -#ifndef RTT_CHANNEL0 -#define RTT_CHANNEL0 0 -#elif !ISBOOLEAN(RTT_CHANNEL0) -#error "RTT_CHANNEL0 must have a value of 0, 1, or be undefined" +#ifndef RTT0 +#define RTT0 0 +#elif !ISBOOLEAN(RTT0) +#error "RTT0 must have a value of 0, 1, or be undefined" #endif -#ifndef RTT_CHANNEL1 -#define RTT_CHANNEL1 0 -#elif !ISBOOLEAN(RTT_CHANNEL1) -#error "RTT_CHANNEL1 must have a value of 0, 1, or be undefined" +#ifndef RTT1 +#define RTT1 0 +#elif !ISBOOLEAN(RTT1) +#error "RTT1 must have a value of 0, 1, or be undefined" #endif -#ifndef RTT_CHANNEL0_BLOCKING -#define RTT_CHANNEL0_BLOCKING 0 -#elif !ISBOOLEAN(RTT_CHANNEL0_BLOCKING) -#error "RTT_CHANNEL0_BLOCKING must have a value of 0, 1, or be undefined" +#ifndef RTT0_BLOCKING +#define RTT0_BLOCKING 0 +#elif !ISBOOLEAN(RTT0_BLOCKING) +#error "RTT0_BLOCKING must have a value of 0, 1, or be undefined" #endif -#ifndef RTT_CHANNEL1_BLOCKING -#define RTT_CHANNEL1_BLOCKING 0 -#elif !ISBOOLEAN(RTT_CHANNEL1_BLOCKING) -#error "RTT_CHANNEL1_BLOCKING must have a value of 0, 1, or be undefined" +#ifndef RTT1_BLOCKING +#define RTT1_BLOCKING 0 +#elif !ISBOOLEAN(RTT1_BLOCKING) +#error "RTT1_BLOCKING must have a value of 0, 1, or be undefined" #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 -#error "Invalid value for RTT_CHANNEL_CONSOLE" +#ifndef RTT_CONSOLE_USER +#define RTT_CONSOLE_USER +#elif !ISEMPTY(RTT_CONSOLE_USER) +#if RTT_CONSOLE_USER < 0 +#error "Invalid value for RTT_CONSOLE_USER" #endif - -#define ONLY_RTT_CONSOLE #endif +#if !ISEMPTY(UART_CONSOLE_USER) && !ISEMPTY(RTT_CONSOLE_USER) +#error "Console on both UART and RTT not supported" +#elif ISEMPTY(UART_CONSOLE_USER) && ISEMPTY(RTT_CONSOLE_USER) +#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..75a58671 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 - rtt_handleMsg(msg, RTT_CHANNEL_CONSOLE + id_rtt0); +#if !ISEMPTY(RTT_CONSOLE_USER) + rtt_handleMsg(msg, RTT_CONSOLE_USER + id_rtt0); +#elif !ISEMPTY(UART_CONSOLE_USER) + uart_handleMsg(msg, UART_CONSOLE_USER - 1 + id_uart1); #else - uart_handleMsg(msg, UART_CONSOLE - 1 + id_uart1); + /* TODO: Add support for no console */ + msg->o.err = -ENODEV; #endif break; @@ -347,13 +350,13 @@ static int createDevFiles(void) #endif -#if RTT_CHANNEL0 +#if RTT0 if (mkFile(&dir, id_rtt0, "rtt0", common.uart_port) < 0) { return -1; } #endif -#if RTT_CHANNEL1 +#if RTT1 if (mkFile(&dir, id_rtt1, "rtt1", common.uart_port) < 0) { return -1; } @@ -608,7 +611,7 @@ int main(void) oid.id = id_console; create_dev(&oid, _PATH_CONSOLE); -#ifdef ONLY_RTT_CONSOLE +#if !ISEMPTY(RTT_CONSOLE_USER) 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..dd6c49fe 100644 --- a/multi/imxrt-multi/rtt.c +++ b/multi/imxrt-multi/rtt.c @@ -40,9 +40,9 @@ /* Doesn't need to be large, data will mostly be stored in RTT buffers */ #define TTY_BUF_SIZE 64 -#define RTT_CHANNEL0_POS 0 -#define RTT_CHANNEL1_POS (RTT_CHANNEL0_POS + RTT_CHANNEL0) -#define RTT_ACTIVE_CNT (RTT_CHANNEL0 + RTT_CHANNEL1) +#define RTT0_POS 0 +#define RTT1_POS (RTT0_POS + RTT0) +#define RTT_ACTIVE_CNT (RTT0 + RTT1) typedef struct rtt_s { int chn; @@ -57,13 +57,13 @@ static struct { } rtt_common; -static const int rttConfig[] = { RTT_CHANNEL0, RTT_CHANNEL1 }; +static const int rttConfig[] = { RTT0, RTT1 }; -static const int rttBlocking[] = { RTT_CHANNEL0_BLOCKING, RTT_CHANNEL1_BLOCKING }; +static const int rttBlocking[] = { RTT0_BLOCKING, RTT1_BLOCKING }; -static const int rttPos[] = { RTT_CHANNEL0_POS, RTT_CHANNEL1_POS }; +static const int rttPos[] = { RTT0_POS, RTT1_POS }; #define RTT_CHANNEL_CNT (sizeof(rttConfig) / sizeof(rttConfig[0])) @@ -255,8 +255,8 @@ int rtt_init(void) void rtt_klogCblk(const char *data, size_t size) { -#ifdef RTT_CHANNEL_CONSOLE - libtty_write(&rtt_common.uarts[rttPos[RTT_CHANNEL_CONSOLE]].tty_common, data, size, 0); +#if !ISEMPTY(RTT_CONSOLE_USER) + libtty_write(&rtt_common.uarts[rttPos[RTT_CONSOLE_USER]].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 }