Skip to content

Commit

Permalink
Merge pull request sysprog21#65 from ChinYikMing/fix/termios-control-…
Browse files Browse the repository at this point in the history
…mode

Enable ISIG control mode of termios after exit
  • Loading branch information
jserv authored Dec 10, 2024
2 parents 333254e + 58598a8 commit 59d39f5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
#include "riscv.h"
#include "riscv_private.h"

/*
* The control mode flag for keyboard.
*
* ICANON: Enable canonical mode.
* ECHO: Echo input characters.
* ISIG: When any of the characters INTR, QUIT,
* SUSP, or DSUSP are received, generate the
* corresponding signal.
*
* It is essential to re-enable ISIG upon exit.
* Otherwise, the default signal handler will
* not catch the signal. E.g., SIGINT generated by
* CTRL + c.
*
*/
#define TERMIOS_C_CFLAG (ICANON | ECHO | ISIG)

/* Emulate 8250 (plain, without loopback mode support) */

#define U8250_INT_THRE 1
Expand All @@ -19,7 +36,7 @@ static void reset_keyboard_input()
/* Re-enable echo, etc. on keyboard. */
struct termios term;
tcgetattr(0, &term);
term.c_lflag |= ICANON | ECHO;
term.c_lflag |= TERMIOS_C_CFLAG;
tcsetattr(0, TCSANOW, &term);
}

Expand All @@ -31,7 +48,7 @@ void capture_keyboard_input()

struct termios term;
tcgetattr(0, &term);
term.c_lflag &= ~(ICANON | ECHO | ISIG); /* Disable echo as well */
term.c_lflag &= ~TERMIOS_C_CFLAG; /* Disable echo as well */
tcsetattr(0, TCSANOW, &term);
}

Expand Down

0 comments on commit 59d39f5

Please sign in to comment.