Skip to content

Commit

Permalink
drivers/serial: support force panic only when repeat the panic char
Browse files Browse the repository at this point in the history
We can increase the panic repeat count to avoid abnormal crashes
caused by serial port interference.

Signed-off-by: Bowen Wang <[email protected]>
  • Loading branch information
CV-Bowen authored and anjiahao1 committed Oct 8, 2024
1 parent c0a7ed9 commit ecc5f04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions drivers/serial/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ config TTY_FORCE_PANIC_CHAR
---help---
Use Ctrl-? 0x1F inputs to determine whether panic system

config TTY_FORCE_PANIC_REPEAT_COUNT
int "TTY force crash repeat count"
default 1
depends on TTY_FORCE_PANIC
---help---
Repeat how many times the panic char to determine whether panic system

config TTY_SIGINT
bool "Support SIGINT"
default n
Expand Down
14 changes: 13 additions & 1 deletion drivers/serial/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,10 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev)
dev->pid = INVALID_PROCESS_ID;
#endif

#ifdef CONFIG_TTY_FORCE_PANIC
dev->panic_count = 0;
#endif

/* If this UART is a serial console */

if (dev->isconsole)
Expand Down Expand Up @@ -2218,9 +2222,17 @@ int uart_check_special(FAR uart_dev_t *dev, FAR const char *buf, size_t size)
#ifdef CONFIG_TTY_FORCE_PANIC
if (buf[i] == CONFIG_TTY_FORCE_PANIC_CHAR)
{
PANIC_WITH_REGS("Force panic by user.", NULL);
if (++dev->panic_count >= CONFIG_TTY_FORCE_PANIC_REPEAT_COUNT)
{
PANIC_WITH_REGS("Force panic by user.", NULL);
}

return 0;
}
else
{
dev->panic_count = 0;
}
#endif

#ifdef CONFIG_TTY_LAUNCH
Expand Down
4 changes: 4 additions & 0 deletions include/nuttx/serial/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ struct uart_dev_s
pid_t pid; /* Thread PID to receive signals (-1 if none) */
#endif

#ifdef CONFIG_TTY_FORCE_PANIC
int panic_count;
#endif

/* Terminal control flags */

tcflag_t tc_iflag; /* Input modes */
Expand Down

0 comments on commit ecc5f04

Please sign in to comment.