From 79c1563e03feb9dd18ccb390b2379a2d48e102a6 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Wed, 6 Sep 2023 17:46:51 +0200 Subject: [PATCH] drivers,uart: add uart_reboot() function The UART reboot functionality looks for '+++' character string input received via UART and calls reboot() when detected. Signed-off-by: Pawel Wieczorkiewicz --- drivers/serial.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/serial.c b/drivers/serial.c index 31cf0f28..a2380346 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -221,6 +221,19 @@ int serial_write(io_port_t port, const char *buf, size_t len) { return rc; } +#define NUM_PLUS 3 +static inline void uart_reboot(char c) { + static volatile uint8_t break_cmd = NUM_PLUS; + + if (c != '+') { + break_cmd = NUM_PLUS; + return; + } + + if (--break_cmd == 0) + reboot(); +} + void uart_interrupt_handler(void) { for (unsigned int i = 0; i < ARRAY_SIZE(com_ports); ++i) { com_port_t com_port = com_ports[i]; @@ -238,6 +251,7 @@ void uart_interrupt_handler(void) { input_state.curr = (input_state.curr + 1) % sizeof(input_state.buf); printk("%c", input); + uart_reboot(input); } }