Small fix to to_erl

Stefan Zegenhagen <[email protected]>
Newsgroups gmane.comp.lang.erlang.patches
Organization arcutronix GmbH
Message-ID <1369839043.3947.26.camel@ax-sze>
Dear all,

we've stumbled across a small problem.

One of our devices does not like 'to_erl' to be run over a serial port.
When to_erl is started, we see "Attaching to /tm<0xFF>" being printed
and the device then refuses to accept any input. Occasionally, we have
seen a linux kernel error message "serial8250: too much work for irq16"
simultaneously. After some debugging we found out that cause is a call
to tcsetattr() by to_erl, immediately preceeded by some printf().

The UART in our device doesn't like hardware parameters to be changed
while output is concurrently active. In fact, the GNU libc manual also
mentions that it might be dangerous to change UART hardware parameters
when a transmission is ongoing.

The patch attached to this e-mail changes the behaviour of to_erl to use
TCSADRAIN instead of TCSANOW when changing terminal parameters. This
makes the serial driver wait for the output queues to be empty before
applying the terminal parameter change.


Kind regards,

-- 
Dr. Stefan Zegenhagen

arcutronix GmbH
Garbsener Landstr. 10
30419 Hannover
Germany

Tel:   +49 511 277-2734
Fax:   +49 511 277-2709
Email: [email protected]
Web:   www.arcutronix.com

*Synchronize the Ethernet*

General Managers: Dipl. Ing. Juergen Schroeder, Dr. Josef Gfrerer -
Legal Form: GmbH, Registered office: Hannover, HRB 202442, Amtsgericht
Hannover; Ust-Id: DE257551767.

Please consider the environment before printing this message.

_______________________________________________
erlang-patches mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-patches
to_erl.patch (text/x-patch, 1.3 KB)
From 1f84b4ebd46da83e317cb15a37ef7d12206687df Mon Sep 17 00:00:00 2001
From: Stefan Zegenhagen <[email protected]>
Date: Wed, 29 May 2013 16:22:34 +0200
Subject: [PATCH] Fix changing terminal parameters in to_erl

to_erl is changing quite a number of terminal parameters that might
affect the underlying serial port hardware. The UART, however, may
dislike this parameter change when output is concurrently active, so use
TCSADRAIN instead of TCSANOW for changing the terminal parameters.
---
 erts/etc/unix/to_erl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/erts/etc/unix/to_erl.c b/erts/etc/unix/to_erl.c
index 754b349..e9dd255 100644
--- a/erts/etc/unix/to_erl.c
+++ b/erts/etc/unix/to_erl.c
@@ -339,7 +339,7 @@ int main(int argc, char **argv)
     tty_smode.c_cc[VTIME]     =0;/* Note that VTIME is the same as VEOL! */
     tty_smode.c_cc[VINTR]     =3;
     
-    tcsetattr(0, TCSANOW, &tty_smode);
+    tcsetattr(0, TCSADRAIN, &tty_smode);
     
 #ifdef DEBUG
     show_terminal_settings(&tty_smode);
@@ -484,7 +484,7 @@ int main(int argc, char **argv)
      * Reset terminal characterstics 
      * XXX
      */
-    tcsetattr(0, TCSANOW, &tty_rmode);
+    tcsetattr(0, TCSADRAIN, &tty_rmode);
     return 0;
 }
 
-- 
1.7.9.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.