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
If UART_CONSOLE_USER is empty, there will be no console output.

JIRA: RTOS-754
  • Loading branch information
jmaksymowicz committed Sep 27, 2024
1 parent a2bd786 commit 543908c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
26 changes: 18 additions & 8 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 @@ -774,6 +774,16 @@
#endif
#endif

#if defined(UART_CONSOLE_USER)
#if !ISEMPTY(UART_CONSOLE_USER)
#if (UART_CONSOLE_USER <= 0)
#error "Invalid value for UART_CONSOLE"
#endif
#endif
#else
#define UART_CONSOLE_USER UART_CONSOLE
#endif


/* RTT */

Expand Down Expand Up @@ -802,16 +812,16 @@
#endif


#if defined(UART_CONSOLE) && defined(RTT_CHANNEL_CONSOLE)
#ifndef RTT_CHANNEL_CONSOLE
#define RTT_CHANNEL_CONSOLE
#endif

#if !ISEMPTY(UART_CONSOLE_USER) && !ISEMPTY(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
#elif !ISEMPTY(RTT_CHANNEL_CONSOLE)
#if RTT_CHANNEL_CONSOLE < 0
#error "Invalid value for RTT_CHANNEL_CONSOLE"
#endif

#define ONLY_RTT_CONSOLE
#endif


Expand Down
8 changes: 5 additions & 3 deletions multi/imxrt-multi/imxrt-multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ 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
dummyuart_handleMsg(msg);
#endif
break;

Expand Down Expand Up @@ -608,7 +610,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);
Expand Down
2 changes: 1 addition & 1 deletion multi/imxrt-multi/rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,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
}
Expand Down
61 changes: 59 additions & 2 deletions multi/imxrt-multi/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ typedef struct uart_s {

struct {
uart_t uarts[UART_CNT];
#if ISEMPTY(UART_CONSOLE_USER)
libtty_common_t dummy_tty;
#endif
} uart_common;


Expand Down Expand Up @@ -291,6 +294,49 @@ static void set_baudrate(void *_uart, speed_t baud)
}


#if ISEMPTY(UART_CONSOLE_USER)
int dummyuart_handleMsg(msg_t *msg)
{
unsigned long request;
const void *in_data, *out_data = NULL;
pid_t pid;
int err;

switch (msg->type) {
case mtWrite:
msg->o.err = msg->i.size;
break;

case mtRead:
msg->o.err = 0;
break;

case mtGetAttr:
if (msg->i.attr.type != atPollStatus) {
msg->o.err = -ENOSYS;
break;
}
msg->o.attr.val = libtty_poll_status(&uart_common.dummy_tty);
msg->o.err = EOK;
break;

case mtDevCtl:
in_data = ioctl_unpack(msg, &request, NULL);
pid = ioctl_getSenderPid(msg);
err = libtty_ioctl(&uart_common.dummy_tty, pid, request, in_data, &out_data);
ioctl_setResponse(msg, request, err, out_data);
break;

default:
msg->o.err = -ENOSYS;
break;
}

return EOK;
}
#endif


int uart_handleMsg(msg_t *msg, int dev)
{
unsigned long request;
Expand Down Expand Up @@ -772,8 +818,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 Expand Up @@ -806,6 +852,17 @@ int uart_init(void)

memset(&uart_common, 0, sizeof(uart_common));

#if ISEMPTY(UART_CONSOLE_USER)
callbacks.arg = NULL;
callbacks.set_baudrate = NULL;
callbacks.set_cflag = NULL;
callbacks.signal_txready = NULL;

if (libtty_init(&uart_common.dummy_tty, &callbacks, 4, B115200) < 0) {
return -1;
}
#endif

uart_initPins();

const uint32_t default_baud[] = { UART_BAUDRATES };
Expand Down
3 changes: 3 additions & 0 deletions multi/imxrt-multi/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
int uart_handleMsg(msg_t *msg, int dev);


int dummyuart_handleMsg(msg_t *msg);


void uart_klogCblk(const char *data, size_t size);


Expand Down

0 comments on commit 543908c

Please sign in to comment.