diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 2cc09c51546e1..3731506ee63f5 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -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 diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index d434dfa5e02de..4398491748602 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -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) @@ -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 diff --git a/include/nuttx/serial/serial.h b/include/nuttx/serial/serial.h index 6c42f96334551..e4aa83a60b681 100644 --- a/include/nuttx/serial/serial.h +++ b/include/nuttx/serial/serial.h @@ -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 */