Skip to content

Commit

Permalink
imxrt-multi: add support for console over RTT
Browse files Browse the repository at this point in the history
JIRA: RTOS-754
  • Loading branch information
jmaksymowicz committed Sep 17, 2024
1 parent 518cbda commit 9dcc4ef
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 7 deletions.
9 changes: 7 additions & 2 deletions librtt/rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,17 @@ int rtt_initChannel(int isTx, unsigned int ch, unsigned char *buf, size_t sz)
}
}

ch += (isTx != 0) ? 0 : rtt->txChannels;
if (isTx != 0) {
librtt_common.lastRd[ch] = 0;
}
else {
ch += rtt->txChannels;
}

rtt->channel[ch].name = name;
rtt->channel[ch].ptr = buf;
rtt->channel[ch].sz = sz;
rtt->channel[ch].rd = 0;
librtt_common.lastRd[ch] = 0;
rtt->channel[ch].wr = 0;
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions multi/imxrt-multi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ NAME := imxrt-multi

LOCAL_PATH := $(call my-dir)

LOCAL_SRCS = imxrt-multi.c common.c uart.c gpio.c spi.c i2c.c fs.c posixsrv.c pct2075.c
LOCAL_SRCS = imxrt-multi.c common.c uart.c gpio.c spi.c i2c.c fs.c posixsrv.c pct2075.c rttuart.c
ifneq ($(TARGET_SUBFAMILY), imxrt117x)
LOCAL_SRCS += trng.c
else
LOCAL_SRCS += cm4.c
endif
DEP_LIBS := libtty libklog libpseudodev i2c-common
DEP_LIBS := libtty libklog libpseudodev i2c-common librtt
LIBS := libdummyfs libklog libpseudodev libposixsrv
LOCAL_HEADERS := imxrt-multi.h

Expand Down
50 changes: 49 additions & 1 deletion multi/imxrt-multi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@

/* clang-format on */

#ifndef UART_CONSOLE
#if !defined(UART_CONSOLE) && !defined(RTT_CHANNEL_CONSOLE)
#if defined(__CPU_IMXRT105X)
#define UART_CONSOLE 1
#elif defined(__CPU_IMXRT106X)
Expand All @@ -766,6 +766,54 @@
#endif
#endif

#if defined(UART_CONSOLE)
#if ISEMPTY(UART_CONSOLE)
#error "UART_CONSOLE must not be empty"
#elif UART_CONSOLE <= 0
#error "Invalid value for UART_CONSOLE"
#endif
#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"
#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"
#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"
#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"
#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"
#endif

#define ONLY_RTT_CONSOLE
#endif


/* SPI */

Expand Down
27 changes: 27 additions & 0 deletions multi/imxrt-multi/imxrt-multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "common.h"

#include "uart.h"
#include "rttuart.h"
#include "gpio.h"
#include "spi.h"
#include "i2c.h"
Expand Down Expand Up @@ -168,7 +169,11 @@ static void uart_dispatchMsg(msg_t *msg)

switch (id) {
case id_console:
#ifdef ONLY_RTT_CONSOLE
rttuart_handleMsg(msg, RTT_CHANNEL_CONSOLE + id_rttuart0);
#else
uart_handleMsg(msg, UART_CONSOLE - 1 + id_uart1);
#endif
break;

case id_uart1:
Expand All @@ -191,6 +196,11 @@ static void uart_dispatchMsg(msg_t *msg)
break;
#endif

case id_rttuart0:
case id_rttuart1:
rttuart_handleMsg(msg, id);
break;

default:
msg->o.err = -ENODEV;
break;
Expand Down Expand Up @@ -335,6 +345,18 @@ static int createDevFiles(void)
}
#endif

#endif

#if RTT_CHANNEL0
if (mkFile(&dir, id_rttuart0, "rttuart0", common.uart_port) < 0) {
return -1;
}
#endif

#if RTT_CHANNEL1
if (mkFile(&dir, id_rttuart1, "rttuart1", common.uart_port) < 0) {
return -1;
}
#endif

/* GPIOs */
Expand Down Expand Up @@ -577,6 +599,7 @@ int main(void)
#endif

uart_init();
rttuart_init();
gpio_init();
spi_init();
i2c_init();
Expand All @@ -585,7 +608,11 @@ int main(void)
oid.id = id_console;
create_dev(&oid, _PATH_CONSOLE);

#ifdef ONLY_RTT_CONSOLE
libklog_init(rttuart_klogCblk);
#else
libklog_init(uart_klogCblk);
#endif
oid_t kmsgctrl = { .port = common.uart_port, .id = id_kmsgctrl };
libklog_ctrlRegister(&kmsgctrl);

Expand Down
3 changes: 2 additions & 1 deletion multi/imxrt-multi/imxrt-multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ enum { id_console = 0, id_uart1, id_uart2, id_uart3, id_uart4, id_uart5, id_uart
id_i2c5, id_i2c6,
id_cm4_0, id_cm4_1, id_cm4_2, id_cm4_3,
#endif
id_trng, id_pseudoNull, id_pseudoZero, id_pseudoFull, id_pseudoRandom, id_kmsgctrl, id_temp1
id_trng, id_pseudoNull, id_pseudoZero, id_pseudoFull, id_pseudoRandom, id_kmsgctrl, id_temp1,
id_rttuart0, id_rttuart1,
};
/* clang-format on */

Expand Down
Loading

0 comments on commit 9dcc4ef

Please sign in to comment.