[prev in list] [next in list] [prev in thread] [next in thread]
List: uclinux-dev
Subject: Re: [uClinux-dev] how to recognise the ESC sequence and single ESC key
From: "Robert Nodder" <robert.nodder () zen ! co ! uk>
Date: 2003-08-31 21:36:06
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I also had the same problems.
Basically the terminal program is sending the ^[A (where ^ is escape) faster than the \
ISR can handle the input, i.e. the first char (^) is received, the serial interrupt \
handler is called but before it can return the second char ([) is sent. The last \
char (A or whatever) is then sent and triggers another interrupt. (This might be \
slightly different depending on the architecture, you might get the second char not \
the third, or get the third char twice).
There are 3 solutions (that I know of):
1. Use a lower baud rate so that the incoming character is slower than the time taken \
to handle the interrupt (or increase processor clock rate) 2. Use a hardware FIFO on \
the UART (eg a 16550 has a 16-byte buffer) 3. Configure the terminal program to have \
a delay between each character.
Rgds,
Rob
----- Original Message -----
From: bonze2000@21cn.com
To: uclinux-dev@uclinux.org
Sent: Sunday, August 31, 2003 6:56 PM
Subject: [uClinux-dev] how to recognise the ESC sequence and single ESC key
Hi all,
I met a strange thing. I write a program to handle user input from console.
-------------------------------------------------------
char getch ()
{
while (read (STDIN_FILENO, &c, 1) != 1)
;
if (c != VT_ESC)
return c;
t.tv_sec = 0;
t.tv_usec = 500;
FD_ZERO (&rfd);
FD_SET (STDIN_FILENO, &rfd);
n = select (STDIN_FILENO+1, &rfd, NULL, NULL, &t);
if (n == 0)
return VT_ESC;
if (n < 0)
return -1;
while (read (STDIN_FILENO, &c, 1) != 1)
;
if (c != VT_BRACKET)
return c;
while (read (STDIN_FILENO, &c, 1) != 1)
;
switch (c)
{
case VT_A:
return 0xe0;
case VT_B:
return 0xe1;
case VT_C:
return 0xe2;
case VT_D:
return 0xe3;
}
return -1;
}
------------------------------------------------------------
when console's baudrate is 57600, I can got correctly single ESC key,
arrow key and others. but after changing the baudrate to 115200,
arrow key (ESC sequence) could not be get; often get some deformity
sequence. who knows why it is? any suggestions would be appreciated!
Thanks,
Peng Hill.
------------------------------------------------------------------------------
_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 5.50.4930.1700" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I also had the same problems.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Basically the terminal program is sending the ^[A
(where ^ is escape) faster than the ISR can handle the input, i.e. the first
char (^) is received, the serial interrupt handler is called but before it can
return the second char ([) is sent. The last char (A or whatever) is then
sent and triggers another interrupt. (This might be slightly different depending
on the architecture, you might get the second char not the third, or get the
third char twice).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>There are 3 solutions (that I know
of):</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>1. Use a lower baud rate so that the incoming
character is slower than the time taken to handle the interrupt (or increase
processor clock rate)</FONT></DIV>
<DIV><FONT face=Arial size=2>2. Use a hardware FIFO on the UART (eg a 16550 has
a 16-byte buffer)</FONT></DIV>
<DIV><FONT face=Arial size=2>3. Configure the terminal program to have a delay
between each character.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Rgds,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Rob</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 \
2px solid; MARGIN-RIGHT: 0px"> <DIV style="FONT: 10pt arial">----- Original Message \
----- </DIV> <DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=bonze2000@21cn.com
href="mailto:bonze2000@21cn.com">bonze2000@21cn.com</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=uclinux-dev@uclinux.org
href="mailto:uclinux-dev@uclinux.org">uclinux-dev@uclinux.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, August 31, 2003 6:56
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [uClinux-dev] how to recognise
the ESC sequence and single ESC key</DIV>
<DIV><BR></DIV>
<DIV><FONT size=2>Hi all,</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>I met a strange thing. I write a program to handle
</FONT><FONT size=2>user input from console. </FONT></DIV>
<DIV><FONT
size=2>-------------------------------------------------------</FONT></DIV>
<DIV><FONT size=2>char getch ()</FONT></DIV>
<DIV><FONT size=2>{</FONT></DIV>
<DIV><FONT size=2>while (read (STDIN_FILENO, &c, 1) !=
1)<BR> \
;</FONT></DIV>
<DIV><FONT size=2>if (c != VT_ESC)<BR> return
c;</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>t.tv_sec = 0;<BR>t.tv_usec = 500;<BR>FD_ZERO
(&rfd);<BR>FD_SET (STDIN_FILENO, &rfd);<BR>n = select (STDIN_FILENO+1,
&rfd, NULL, NULL, &t);<BR>if (n == 0)<BR>
return VT_ESC;</FONT></DIV>
<DIV><FONT size=2>if (n < 0)<BR> return
-1;<BR></FONT><FONT size=2></FONT></DIV>
<DIV><FONT size=2>while (read (STDIN_FILENO, &c, 1) !=
1)<BR>
;<BR></FONT><FONT size=2>if (c != VT_BRACKET)<BR>
return c;<BR>while (read (STDIN_FILENO, &c, 1) !=
1)<BR>
;<BR></FONT><FONT size=2>switch
(c)<BR>{<BR> case
VT_A:<BR> \
return 0xe0;<BR> case
VT_B:<BR> \
return 0xe1;<BR> case
VT_C:<BR> \
return 0xe2;<BR> case
VT_D:<BR> \
return 0xe3;<BR>}<BR>return -1;</FONT></DIV>
<DIV><FONT
size=2>}<BR>------------------------------------------------------------</FONT></DIV>
<DIV><FONT size=2>when console's baudrate is </FONT><FONT size=2>57600, I can
got correctly single ESC key, </FONT></DIV>
<DIV><FONT size=2>arrow key and others. but after changing the baudrate to
115200, </FONT></DIV>
<DIV><FONT size=2>arrow key (ESC sequence) </FONT><FONT size=2>could not be
get; often get some deformity </FONT></DIV>
<DIV><FONT size=2>sequence. who knows why it is? </FONT><FONT size=2>any
suggestions would be appreciated!</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Thanks,</FONT></DIV>
<DIV><FONT size=2>Peng Hill.</FONT></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>uClinux-dev mailing
list<BR>uClinux-dev@uclinux.org<BR>http://mailman.uclinux.org/mailman/listinfo/uclinux-dev<BR>This \
message was resent by uclinux-dev@uclinux.org</BLOCKQUOTE></BODY></HTML>
_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic