yangsong8-a1 opened a new pull request, #21839:
URL: https://github.com/apache/nuttx/pull/21839

   ## Summary
   
   serial.c and pty.c each have their own copy of the c_iflag/c_oflag
   translation and of the INTR/SUSP scan. This adds 
drivers/serial/serial_termios.c
   with `uart_termios_*` helpers and `struct uart_termios_s`, and converts 
serial
   and pty to them:
   
   - The helpers keep c_cc[VINTR] and c_cc[VSUSP], so the runtime INTR/SUSP
     characters stay as they are now: tcsetattr() can change them or disable 
them
     with `_POSIX_VDISABLE`, TCGETS reports them, and the characters that send a
     signal are still dropped.
   - A pty keeps its settings in the slave (also when set through the master), 
as
     before.
   
   ## Impact
   
   Output and input translation now follow POSIX (Linux gives the same results):
   
   - ONLRET no longer inserts a CR before NL: `x\ny` is written as `x\ny`, not
     `x\r\ny` (ONLRET means NL already does the CR function).
   - With ONLCR and OCRNL, a CR is mapped to NL only: `\r` goes out as `\n`, not
     `\r\n`.
   - With IGNCR and ICRNL, a received CR is ignored (IGNCR wins) instead of 
being
     mapped to NL.
   - With INLCR and IGNCR, a received NL is mapped to CR and kept; before, it
     was mapped to CR and then dropped. IGNCR now only drops a CR that was
     received as CR.
   
   These changes apply to the console and to a pty. ONLCR, OCRNL, ICRNL, IGNCR
   and INLCR each used alone, ECHO, ICANON, OPOST off, Ctrl-C/Ctrl-Z, c_cc and
   the pty settings behave as before.
   `struct uart_dev_s` changes 
(`tc_iflag`/`tc_oflag`/`tc_lflag`/`tc_vintr`/`tc_vsusp`
   become `termios`); nothing outside drivers/serial uses these fields.
   
   ## Testing
   
   Ubuntu 22.04, gcc 13.1, aarch64-none-elf-gcc 13.2, arm-none-eabi-gcc 10.3.
   
   Builds with no warnings (each commit builds sim:nsh and the sim configuration
   below with TTY_LAUNCH and TTY_FORCE_PANIC): sim:nsh, sim:rpproxy,
   qemu-armv8a:nsh, qemu-intel64:nsh, mps3-an547:nsh, and sim:nsh with
   SERIAL_TERMIOS, TTY_SIGINT, TTY_SIGTSTP, SIG_DEFAULT, PSEUDOTERM,
   PSEUDOTERM_SUSV1 (SIM_UART_DMA=y and =n, with and without
   TTY_LAUNCH/TTY_FORCE_PANIC, and PSEUDOTERM without TTY_SIGINT/TTY_SIGTSTP).
   
   Run on sim (console and a posix_openpt() pty) with a test program that sets
   the modes with tcsetattr(), sends bytes, and prints what is read and which
   signals arrived. The results are the same with SIM_UART_DMA=y and =n.
   
   | Test | master | this PR |
   |---|---|---|
   | TCGETS c_cc: VINTR, VSUSP, VERASE, VMIN; `fpathconf(_PC_VDISABLE)` | 03 1a 
7f 01; 0 | same |
   | console: `a ^C b` with ISIG | reads `a b`, SIGINT | same |
   | console: VINTR=^X, send `a ^C ^X b` | reads `a ^C b`, SIGINT, reads back 
^X | same |
   | console: VINTR=`_POSIX_VDISABLE`, send `a ^C NUL b` | reads all, no signal 
| same |
   | console: `a ^Z b`; VSUSP=^Y | reads `a b`, SIGTSTP | same |
   | console: -ISIG, `a ^C ^Z b` | reads all, no signal | same |
   | nsh: Ctrl-C stops `hello spin 5` | stopped | same |
   | nsh: VINTR=^X, then Ctrl-C / Ctrl-X | not stopped / stopped | same |
   | nsh: VINTR=0, then Ctrl-C | not stopped | same |
   | pty: TCGETS on master and slave | slave settings, c_cc as above | same |
   | pty: VINTR=^X set through the master, master writes `^C ^X` | slave reads 
`^C`, SIGINT | same |
   | pty: VINTR=0 / slave -ISIG / default VSUSP | no signal / no signal / 
SIGTSTP | same |
   | console input ICRNL, IGNCR, INLCR, none (`a\rb\nc`) | `a\nb\nc`, `ab\nc`, 
`a\rb\rc`, `a\rb\nc` | same |
   | console input IGNCR + ICRNL | `a\nb\nc` | `ab\nc` |
   | console input INLCR + IGNCR; INLCR + IGNCR + ICRNL | `abc`; `a\nbc` | 
`ab\rc`; `ab\rc` |
   | pty input INLCR + IGNCR, with and without ICRNL (master writes `a\rb\nc`, 
the master's OCRNL makes it `a\nb\nc`) | `abc` | `a\rb\rc` |
   | output ONLCR, -OPOST, OCRNL (`x\ny\rz`, console and pty) | `x\r\ny\rz`, 
`x\ny\rz`, `x\ny\nz` | same |
   | console output ONLCR + OCRNL | `x\r\ny\r\nz` | `x\r\ny\nz` |
   | output ONLRET (console and pty) | `x\r\ny\rz` | `x\ny\rz` |
   | console ECHO on/off and ICANON line read; pty input translation, echo and 
master flags | as expected | same |
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to