Re: [PATCH] libmisc/shell: Support terminal size as env variables
On 23/11/22 12:44 am, Joel Sherrill wrote: > On Tue, Nov 22, 2022, 6:02 AM mailto:chr...@rtems.org>> > wrote: > From: Chris Johns mailto:chr...@rtems.org>> > > Closes #4763 > --- > cpukit/libmisc/shell/main_edit.c | 17 +- > cpukit/libmisc/shell/main_help.c | 94 > cpukit/libmisc/shell/shell.c | 83 +++- > 3 files changed, 154 insertions(+), 40 deletions(-) > > diff --git a/cpukit/libmisc/shell/main_edit.c > b/cpukit/libmisc/shell/main_edit.c > index 4cc742719a..16c44f2a11 100644 > --- a/cpukit/libmisc/shell/main_edit.c > +++ b/cpukit/libmisc/shell/main_edit.c > @@ -755,8 +755,21 @@ static void get_console_size(struct env *env) { > env->cols = ws.ws_col; > env->lines = ws.ws_row - 1; > #elif defined(__rtems__) > - env->cols = 80; > - env->lines = 25; > + char* e; > + e = getenv("LINES"); > + if (e != NULL) { > + int lines = strtol(e, 0, 10); > + if (lines > 0) { > + env->lines = lines - 1; > + } > + } > + e = getenv("COLUMNS"); > + if (e != NULL) { > + int cols = strtol(e, 0, 10); > + if (cols > 0) { > + env->cols = cols - 1; > + } > + } > > Does this lose the default values if the environment variables are not set? > Yes. I will add the defaults back and then push. Thanks for the review. Chris ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] libmisc/shell: Support terminal size as env variables
On Tue, Nov 22, 2022, 6:02 AM wrote: > From: Chris Johns > > Closes #4763 > --- > cpukit/libmisc/shell/main_edit.c | 17 +- > cpukit/libmisc/shell/main_help.c | 94 > cpukit/libmisc/shell/shell.c | 83 +++- > 3 files changed, 154 insertions(+), 40 deletions(-) > > diff --git a/cpukit/libmisc/shell/main_edit.c > b/cpukit/libmisc/shell/main_edit.c > index 4cc742719a..16c44f2a11 100644 > --- a/cpukit/libmisc/shell/main_edit.c > +++ b/cpukit/libmisc/shell/main_edit.c > @@ -755,8 +755,21 @@ static void get_console_size(struct env *env) { >env->cols = ws.ws_col; >env->lines = ws.ws_row - 1; > #elif defined(__rtems__) > - env->cols = 80; > - env->lines = 25; > + char* e; > + e = getenv("LINES"); > + if (e != NULL) { > +int lines = strtol(e, 0, 10); > +if (lines > 0) { > + env->lines = lines - 1; > +} > + } > + e = getenv("COLUMNS"); > + if (e != NULL) { > +int cols = strtol(e, 0, 10); > +if (cols > 0) { > + env->cols = cols - 1; > +} > + } > Does this lose the default values if the environment variables are not set? #else >struct term *term = gettib()->proc->term; >env->cols = term->cols; > diff --git a/cpukit/libmisc/shell/main_help.c > b/cpukit/libmisc/shell/main_help.c > index 564bc30a9c..e6d939d08f 100644 > --- a/cpukit/libmisc/shell/main_help.c > +++ b/cpukit/libmisc/shell/main_help.c > @@ -22,23 +22,34 @@ > #include "internal.h" > #include > > +static int rtems_shell_help_pause(int line, int lines) { > + if (lines && line >= lines - 1) { > +printf("\rPress any key to continue..."); > +(void) getchar(); > +printf("\r%*c\r", 29, ' '); > +line = 0; > + } > + return line; > +} > + > /* > * show the help for one command. > */ > static int rtems_shell_help_cmd( > - const rtems_shell_cmd_t *shell_cmd > + const rtems_shell_cmd_t *shell_cmd, int indent, int line, > + int cols, int lines > ) > { >const char * pc; > - intcol,line; > + intcol; > >if (!rtems_shell_can_see_cmd(shell_cmd)) { > return 0; >} > > - printf("%-12.12s - ",shell_cmd->name); > - col = 14; > - line = 1; > + printf("%-*s - ", indent, shell_cmd->name); > + indent += 3; > + col = indent; >if (shell_cmd->alias) { > printf("is an for command '%s'",shell_cmd->alias->name); >} else if (shell_cmd->usage) { > @@ -48,8 +59,10 @@ static int rtems_shell_help_cmd( > case '\r': >break; > case '\n': > - putchar('\n'); > - col = 0; > + if (*(pc + 1) != '\0') { > +putchar('\n'); > +col = 0; > + } >break; > default: >putchar(*pc); > @@ -57,19 +70,21 @@ static int rtems_shell_help_cmd( >break; >} >pc++; > - if (col>78) { /* What daring... 78?*/ > + if (col > (cols - 3)) { > if (*pc) { >putchar('\n'); >col = 0; > } >} > - if (!col && *pc) { > -printf(""); > -col = 12;line++; > + if (col == 0 && *pc) { > +line = rtems_shell_help_pause(line + 1, lines); > +printf("%*c", indent, ' '); > +col = indent; >} > } >} >puts(""); > + line = rtems_shell_help_pause(line + 1, lines); >return line; > } > > @@ -83,15 +98,27 @@ static int rtems_shell_help( >char * argv[] > ) > { > - int col,line,lines,arg; > - char* lines_env; > + int col,line,cols,lines,arg,indent; > + char *lines_env, *cols_env; >rtems_shell_topic_t *topic; > + rtems_shell_cmd_t *shell_cmd; > > + lines = 16; > + cols = 80; >lines_env = getenv("SHELL_LINES"); > - if (lines_env) > + if (lines_env) { > lines = strtol(lines_env, 0, 0); > - else > -lines = 16; > + } else { > +lines_env = getenv("LINES"); > +if (lines_env) { > + lines = strtol(lines_env, 0, 0); > +} > + } > + > + cols_env = getenv("COLUMNS"); > + if (cols_env) { > +cols = strtol(cols_env, 0, 0); > + } > >if (argc<2) { > printf("help: The topics are\n"); > @@ -101,7 +128,7 @@ static int rtems_shell_help( >if (!col){ > col = printf(" %s",topic->topic); >} else { > -if ((col+strlen(topic->topic)+2)>78){ > +if ((col+strlen(topic->topic)+2)>(cols - 2)){ >printf("\n"); >col = printf(" %s",topic->topic); > } else { > @@ -113,18 +140,19 @@ static int rtems_shell_help( > printf("\n"); > return 1; >} > + indent = 0; > + shell_cmd = rtems_shell_first_cmd; > + while (shell_cmd) { > +size_t len = strlen(shell_cmd->name); > +if (len > indent) { > + indent = len; > +} > +shell_cmd = shell_cmd->next; > + } >line = 0; >for (arg = 1;arg const char *cur = argv[arg]; > -rtems_shell_cmd_t *shell_cmd; > - > -if (lines && (line > lines)) { > - printf("Press any key to c
[PATCH] libmisc/shell: Support terminal size as env variables
From: Chris Johns Closes #4763 --- cpukit/libmisc/shell/main_edit.c | 17 +- cpukit/libmisc/shell/main_help.c | 94 cpukit/libmisc/shell/shell.c | 83 +++- 3 files changed, 154 insertions(+), 40 deletions(-) diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c index 4cc742719a..16c44f2a11 100644 --- a/cpukit/libmisc/shell/main_edit.c +++ b/cpukit/libmisc/shell/main_edit.c @@ -755,8 +755,21 @@ static void get_console_size(struct env *env) { env->cols = ws.ws_col; env->lines = ws.ws_row - 1; #elif defined(__rtems__) - env->cols = 80; - env->lines = 25; + char* e; + e = getenv("LINES"); + if (e != NULL) { +int lines = strtol(e, 0, 10); +if (lines > 0) { + env->lines = lines - 1; +} + } + e = getenv("COLUMNS"); + if (e != NULL) { +int cols = strtol(e, 0, 10); +if (cols > 0) { + env->cols = cols - 1; +} + } #else struct term *term = gettib()->proc->term; env->cols = term->cols; diff --git a/cpukit/libmisc/shell/main_help.c b/cpukit/libmisc/shell/main_help.c index 564bc30a9c..e6d939d08f 100644 --- a/cpukit/libmisc/shell/main_help.c +++ b/cpukit/libmisc/shell/main_help.c @@ -22,23 +22,34 @@ #include "internal.h" #include +static int rtems_shell_help_pause(int line, int lines) { + if (lines && line >= lines - 1) { +printf("\rPress any key to continue..."); +(void) getchar(); +printf("\r%*c\r", 29, ' '); +line = 0; + } + return line; +} + /* * show the help for one command. */ static int rtems_shell_help_cmd( - const rtems_shell_cmd_t *shell_cmd + const rtems_shell_cmd_t *shell_cmd, int indent, int line, + int cols, int lines ) { const char * pc; - intcol,line; + intcol; if (!rtems_shell_can_see_cmd(shell_cmd)) { return 0; } - printf("%-12.12s - ",shell_cmd->name); - col = 14; - line = 1; + printf("%-*s - ", indent, shell_cmd->name); + indent += 3; + col = indent; if (shell_cmd->alias) { printf("is an for command '%s'",shell_cmd->alias->name); } else if (shell_cmd->usage) { @@ -48,8 +59,10 @@ static int rtems_shell_help_cmd( case '\r': break; case '\n': - putchar('\n'); - col = 0; + if (*(pc + 1) != '\0') { +putchar('\n'); +col = 0; + } break; default: putchar(*pc); @@ -57,19 +70,21 @@ static int rtems_shell_help_cmd( break; } pc++; - if (col>78) { /* What daring... 78?*/ + if (col > (cols - 3)) { if (*pc) { putchar('\n'); col = 0; } } - if (!col && *pc) { -printf(""); -col = 12;line++; + if (col == 0 && *pc) { +line = rtems_shell_help_pause(line + 1, lines); +printf("%*c", indent, ' '); +col = indent; } } } puts(""); + line = rtems_shell_help_pause(line + 1, lines); return line; } @@ -83,15 +98,27 @@ static int rtems_shell_help( char * argv[] ) { - int col,line,lines,arg; - char* lines_env; + int col,line,cols,lines,arg,indent; + char *lines_env, *cols_env; rtems_shell_topic_t *topic; + rtems_shell_cmd_t *shell_cmd; + lines = 16; + cols = 80; lines_env = getenv("SHELL_LINES"); - if (lines_env) + if (lines_env) { lines = strtol(lines_env, 0, 0); - else -lines = 16; + } else { +lines_env = getenv("LINES"); +if (lines_env) { + lines = strtol(lines_env, 0, 0); +} + } + + cols_env = getenv("COLUMNS"); + if (cols_env) { +cols = strtol(cols_env, 0, 0); + } if (argc<2) { printf("help: The topics are\n"); @@ -101,7 +128,7 @@ static int rtems_shell_help( if (!col){ col = printf(" %s",topic->topic); } else { -if ((col+strlen(topic->topic)+2)>78){ +if ((col+strlen(topic->topic)+2)>(cols - 2)){ printf("\n"); col = printf(" %s",topic->topic); } else { @@ -113,18 +140,19 @@ static int rtems_shell_help( printf("\n"); return 1; } + indent = 0; + shell_cmd = rtems_shell_first_cmd; + while (shell_cmd) { +size_t len = strlen(shell_cmd->name); +if (len > indent) { + indent = len; +} +shell_cmd = shell_cmd->next; + } line = 0; for (arg = 1;arg lines)) { - printf("Press any key to continue..."); - (void) getchar(); /* we only want to know a character was pressed */ - printf("\n"); - line = 0; -} -topic = rtems_shell_lookup_topic(cur); +topic = rtems_shell_lookup_topic(cur); if (topic == NULL) { if ((shell_cmd = rtems_shell_lookup_cmd(cur)) == NULL) { if (strcmp(cur, "all") != 0) { @@ -132,11 +160,11 @@ static int rtems_shell_help( "help: topic or cmd '%s' not found. Try alone for a list\n", cur ); - line++; + line = rtems_shell_help_
[PATCH v2] aarch64/versal: Add UART interrupt support
From: Chris Johns --- .../dev/serial/versal-uart-polled.c | 37 -- .../xilinx-versal/dev/serial/versal-uart.c| 321 ++ .../include/dev/serial/versal-uart-regs.h | 1 - .../include/dev/serial/versal-uart.h | 4 +- spec/build/bsps/aarch64/xilinx-versal/grp.yml | 2 + spec/build/bsps/aarch64/xilinx-versal/obj.yml | 1 + .../bsps/aarch64/xilinx-versal/optconirq.yml | 15 + 7 files changed, 342 insertions(+), 39 deletions(-) create mode 100644 bsps/aarch64/xilinx-versal/dev/serial/versal-uart.c create mode 100644 spec/build/bsps/aarch64/xilinx-versal/optconirq.yml diff --git a/bsps/aarch64/xilinx-versal/dev/serial/versal-uart-polled.c b/bsps/aarch64/xilinx-versal/dev/serial/versal-uart-polled.c index 83493db909..9453dc248b 100644 --- a/bsps/aarch64/xilinx-versal/dev/serial/versal-uart-polled.c +++ b/bsps/aarch64/xilinx-versal/dev/serial/versal-uart-polled.c @@ -152,23 +152,6 @@ int versal_uart_initialize(rtems_termios_device_context *base) return 0; } -static bool versal_uart_first_open( - struct rtems_termios_tty *tty, - rtems_termios_device_context *base, - struct termios *term, - rtems_libio_open_close_args_t *args -) -{ - int rc = versal_uart_initialize(base); - if ( rc < 0 ) { -return false; - } - - rtems_termios_set_initial_baud(tty, VERSAL_UART_DEFAULT_BAUD); - - return true; -} - int versal_uart_read_polled(rtems_termios_device_context *base) { volatile versal_uart *regs = versal_uart_get_regs(base); @@ -209,23 +192,3 @@ void versal_uart_reset_tx_flush(rtems_termios_device_context *base) /* Wait for empty */ } } - -static void versal_uart_write_support( - rtems_termios_device_context *base, - const char *s, - size_t n -) -{ - size_t i; - - for (i = 0; i < n; i++) { -versal_uart_write_polled(base, s[i]); - } -} - -const rtems_termios_device_handler versal_uart_handler = { - .first_open = versal_uart_first_open, - .write = versal_uart_write_support, - .poll_read = versal_uart_read_polled, - .mode = TERMIOS_POLLED -}; diff --git a/bsps/aarch64/xilinx-versal/dev/serial/versal-uart.c b/bsps/aarch64/xilinx-versal/dev/serial/versal-uart.c new file mode 100644 index 00..b009f83c37 --- /dev/null +++ b/bsps/aarch64/xilinx-versal/dev/serial/versal-uart.c @@ -0,0 +1,321 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2022 Chris Johns + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +#ifdef VERSAL_CONSOLE_USE_INTERRUPTS +static uint32_t versal_uart_intr_all(void) +{ + return VERSAL_UARTI_OEI | +VERSAL_UARTI_BEI | +VERSAL_UARTI_PEI | +VERSAL_UARTI_FEI | +VERSAL_UARTI_RTI | +VERSAL_UARTI_TXI | +VERSAL_UARTI_RXI | +VERSAL_UARTI_DSRMI | +VERSAL_UARTI_DCDMI | +VERSAL_UARTI_CTSMI | +VERSAL_UARTI_RIMI; +} + +static void versal_uart_intr_clear(volatile versal_uart *regs, uint32_t ints) +{ + regs->uarticr = ints; +} + +static void versal_uart_intr_clearall(volatile versal_uart *regs) +{ + versal_uart_intr_clear(regs, versal_uart_intr_all()); +} + +static void versal_uart_intr_enable(volatile versal_uart *regs, uint32_t ints) +{ + regs->uartimsc |= ints; +} + +static void versal_uart_intr_disable(volatile versal_uart *regs, uint32_t ints) +{ + regs->uartimsc &= ~ints; +} + +static void versal_uart_intr_disableall(volatile versal_uart *regs) +{ + versal_uart_intr_disable(regs, versal_uart_intr_all()); +} + +static bool versal_uart_flags_clear(volatile versal_uart *regs, uint32_t flags) +{ + return (regs->uartfr & flags) == 0; +} + +static void versal_uart_interrupt(void *arg) +{ + rtems_termios_tty *tty = arg; + versal_uart_context *
Re: bsps/riscv: interrupt number mismatch
> On Mon, 2022-11-21 at 11:20 +0100, Sebastian Huber wrote: > > On 21/11/2022 11:17, padmarao.beg...@microchip.com wrote: > > > To which number would you map the software and timer interrupts? > > > > > The Software and Timer interrupts(numbers 0 & 1) are mapped by > > the Machine cause register (mcause) and enabled by the CLINT but > > not by > > the PLIC. > > Yes, this is the problem. We need an interrupt vector number for all > interrupts (PLIC and CLINT). > Fixed, by adding 2 with interrupt number in the bsp_fdt_map_intr() function. uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells) { (void) icells; return intr[0] + 2; } Regards Padmarao > -- > embedded brains GmbH > Herr Sebastian HUBER > Dornierstr. 4 > 82178 Puchheim > Germany > email: sebastian.hu...@embedded-brains.de > phone: +49-89-18 94 741 - 16 > fax: +49-89-18 94 741 - 08 > > Registergericht: Amtsgericht München > Registernummer: HRB 157899 > Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas > Dörfler > Unsere Datenschutzerklärung finden Sie hier: > https://embedded-brains.de/datenschutzerklaerung/ ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] aarch64/versal: Add UART interrupt support
On 22/11/22 6:01 pm, Sebastian Huber wrote: > Hello Chris, > > On 22/11/2022 03:03, chr...@rtems.org wrote: >> +static void versal_uart_write_support( >> + rtems_termios_device_context *base, >> + const char *buf, >> + size_t len >> +) >> +{ >> +#ifdef VERSAL_CONSOLE_USE_INTERRUPTS >> + versal_uart_context *ctx = (versal_uart_context *) base; >> + volatile versal_uart *regs = ctx->regs; >> + >> + if (len > 0) { >> + rtems_interrupt_lock_context lock_context; >> + size_t len_remaining = len; >> + const char *p = &buf[0]; >> + rtems_interrupt_lock_acquire(&ctx->interrupt_lock, &lock_context); > > you don't need an extra interrupt lock. The rtems_termios_device_context > already > contains an interrupt lock, see rtems_termios_device_lock_acquire(). This lock > is held while the write support handler is called. > Thanks for the review and I will remove. The driver took a while to isolate a possible issue in the hardware. I have raised this with Xilinx. The TX will not start with the single character write. I needed to write past the trigger point. I think this driver could be moved to shared as the hardware is based on the ARM IP for the PL011 UART. I wanted to get the chcanges in and used before considering moving it. Xilinx has changed the IP a little which is a shame. Chris ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel