Skip to content

Commit

Permalink
tty: add option to not register as a console
Browse files Browse the repository at this point in the history
JIRA: RTOS-998
  • Loading branch information
badochov committed Jan 29, 2025
1 parent f2679f4 commit 1f142a2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
24 changes: 17 additions & 7 deletions tty/pc-tty/ttypc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ static void ttypc_klogClbk(const char *data, size_t size)
}


int main(void)
int main(int argc, char **argv)
{
unsigned int i;
char path[12];
oid_t oid;
int err;

int isconsole = 1;
if ((argc == 2) && (strcmp(argv[1], "-n") == 0)) {
isconsole = 0;
}
else if (argc != 1) {
return -1;
}

/* Initialize driver */
memset(&ttypc_common, 0, sizeof(ttypc_t));

Expand Down Expand Up @@ -198,13 +206,15 @@ int main(void)

oid.port = ttypc_common.port;
oid.id = 0;
if (create_dev(&oid, _PATH_CONSOLE) < 0) {
fprintf(stderr, "pc-tty: failed to register device %s\n", _PATH_CONSOLE);
}
if (isconsole != 0) {
if (create_dev(&oid, _PATH_CONSOLE) < 0) {
fprintf(stderr, "pc-tty: failed to register device %s\n", _PATH_CONSOLE);
}

libklog_init(ttypc_klogClbk);
oid_t kmsgctrl = { .port = ttypc_common.port, .id = KMSG_CTRL_ID };
libklog_ctrlRegister(&kmsgctrl);
libklog_init(ttypc_klogClbk);
oid_t kmsgctrl = { .port = ttypc_common.port, .id = KMSG_CTRL_ID };
libklog_ctrlRegister(&kmsgctrl);
}

/* Register devices */
for (i = 0; i < NVTS; i++) {
Expand Down
3 changes: 3 additions & 0 deletions tty/uart16550/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ifeq ($(TARGET_FAMILY),riscv64)
LOCAL_SRCS += uarthw-riscv.c
else ifeq ($(TARGET_FAMILY),ia32)
LOCAL_SRCS += uarthw-pc.c
ifneq ($(CONSOLE),serial)
LOCAL_CFLAGS += -DNCONSOLE
endif
else ifeq ($(TARGET_SUBFAMILY),zynq7000)
LOCAL_SRCS += uarthw-zynq7000.c
endif
Expand Down
19 changes: 14 additions & 5 deletions tty/uart16550/uart16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <paths.h>
#include <string.h>

#include <sys/file.h>
#include <sys/interrupt.h>
Expand Down Expand Up @@ -269,23 +270,23 @@ static void uart_klogClbk(const char *data, size_t size)
}


static void _uart_mkDev(uint32_t port)
static void _uart_mkDev(uint32_t port, int isconsole)
{
char path[12];
unsigned int i;

for (i = 0; i < sizeof(uart_common.uarts) / sizeof(uart_common.uarts[0]); i++) {
if (uart_common.uarts[i].init == 1) {
uart_common.uarts[i].oid.port = port;
uart_common.uarts[i].oid.id = (i == UART16550_CONSOLE_USER) ? 0 : i + 1;
uart_common.uarts[i].oid.id = ((isconsole != 0) && (i == UART16550_CONSOLE_USER)) ? 0 : i + 1;
snprintf(path, sizeof(path), "/dev/ttyS%u", i);

if (create_dev(&uart_common.uarts[i].oid, path) < 0) {
fprintf(stderr, "uart16550: failed to register %s\n", path);
return;
}

if (i == UART16550_CONSOLE_USER) {
if ((isconsole != 0) && (i == UART16550_CONSOLE_USER)) {
libklog_init(uart_klogClbk);

if (create_dev(&uart_common.uarts[i].oid, _PATH_CONSOLE) < 0) {
Expand Down Expand Up @@ -350,12 +351,20 @@ static int _uart_init(uart_t *uart, unsigned int uartn, unsigned int speed)
}


int main(void)
int main(int argc, char **argv)
{
unsigned int i;
uint32_t port;
int err;

int isconsole = 1;
if ((argc == 2) && (strcmp(argv[1], "-n") == 0)) {
isconsole = 0;
}
else if (argc != 1) {
return -1;
}

portCreate(&port);

for (i = 0; i < sizeof(uart_common.uarts) / sizeof(uart_common.uarts[0]); i++) {
Expand All @@ -371,7 +380,7 @@ int main(void)
}

beginthread(poolthr, 4, uart_common.stack, sizeof(uart_common.stack), (void *)(uintptr_t)port);
_uart_mkDev(port);
_uart_mkDev(port, isconsole);
poolthr((void *)(uintptr_t)port);

return EXIT_SUCCESS;
Expand Down

0 comments on commit 1f142a2

Please sign in to comment.