Skip to content

Commit 59d39f5

Browse files
authored
Merge pull request #65 from ChinYikMing/fix/termios-control-mode
Enable ISIG control mode of termios after exit
2 parents 333254e + 58598a8 commit 59d39f5

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

uart.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
#include "riscv.h"
1111
#include "riscv_private.h"
1212

13+
/*
14+
* The control mode flag for keyboard.
15+
*
16+
* ICANON: Enable canonical mode.
17+
* ECHO: Echo input characters.
18+
* ISIG: When any of the characters INTR, QUIT,
19+
* SUSP, or DSUSP are received, generate the
20+
* corresponding signal.
21+
*
22+
* It is essential to re-enable ISIG upon exit.
23+
* Otherwise, the default signal handler will
24+
* not catch the signal. E.g., SIGINT generated by
25+
* CTRL + c.
26+
*
27+
*/
28+
#define TERMIOS_C_CFLAG (ICANON | ECHO | ISIG)
29+
1330
/* Emulate 8250 (plain, without loopback mode support) */
1431

1532
#define U8250_INT_THRE 1
@@ -19,7 +36,7 @@ static void reset_keyboard_input()
1936
/* Re-enable echo, etc. on keyboard. */
2037
struct termios term;
2138
tcgetattr(0, &term);
22-
term.c_lflag |= ICANON | ECHO;
39+
term.c_lflag |= TERMIOS_C_CFLAG;
2340
tcsetattr(0, TCSANOW, &term);
2441
}
2542

@@ -31,7 +48,7 @@ void capture_keyboard_input()
3148

3249
struct termios term;
3350
tcgetattr(0, &term);
34-
term.c_lflag &= ~(ICANON | ECHO | ISIG); /* Disable echo as well */
51+
term.c_lflag &= ~TERMIOS_C_CFLAG; /* Disable echo as well */
3552
tcsetattr(0, TCSANOW, &term);
3653
}
3754

0 commit comments

Comments
 (0)