Skip to content

Commit

Permalink
imxrt-multi: Allow UART_CONSOLE_USER to be defined empty
Browse files Browse the repository at this point in the history
Rename RTT_CHANNEL_* to RTT*

JIRA: RTOS-754
  • Loading branch information
jmaksymowicz committed Oct 16, 2024
1 parent ad38807 commit 733eeae
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 46 deletions.
69 changes: 39 additions & 30 deletions multi/imxrt-multi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 */

Expand Down
15 changes: 9 additions & 6 deletions multi/imxrt-multi/imxrt-multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions multi/imxrt-multi/rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]))
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions multi/imxrt-multi/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 733eeae

Please sign in to comment.