Skip to contentSkip to conversation

tools: termios_linux.h: Fix tcsendbreak() implementation

PATCH In review Pali Rohár 2 participants 3 messages Oct 6, 2021 – Oct 21, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: termios_linux.h: Fix tcsendbreak() implementation

There are two Linux ioctls which implements tcsendbreak() functionality:
TCSBRK and TCSBRKP

TCSBRK with non-zero parameter implements tcdrain() and with zero parameter implements tcsendbreak() for duration of 0.25s.

TCSBRKP with zero parameter is same as TCSBRK and with non-zero parameter implements tcsendbreak() for duration in deciseconds specified by parameter. TCSBRKP does not have to be provided by older toolchain versions.

So tcsendbreak() has to either use TCSBRK with zero parameter or TCSBRKP with any parameter.

Fix code to use TCSBRKP and fallback to TCSBRK with 0.

---
 tools/termios_linux.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/termios_linux.h +5 -1
index d73989b625a2..e100c8e4eb5f 100644
@@ -90,7 +90,11 @@ static inline int tcflush(int fd, int q)
 
 static inline int tcsendbreak(int fd, int d)
 {
-	return ioctl(fd, TCSBRK, d);
+#ifdef TCSBRKP
+	return ioctl(fd, TCSBRKP, d);
+#else
+	return ioctl(fd, TCSBRK, 0);
+#endif
 }
 
 static inline int tcflow(int fd, int a)
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Pali Rohár

There are two Linux ioctls which implements tcsendbreak() functionality:
TCSBRK and TCSBRKP

TCSBRK with non-zero parameter implements tcdrain() and with zero parameter implements tcsendbreak() for duration of 0.25s.

TCSBRKP with zero parameter is same as TCSBRK and with non-zero parameter implements tcsendbreak() for duration in deciseconds specified by parameter. TCSBRKP does not have to be provided by older toolchain versions.

Quoted 6 lines

So tcsendbreak() has to either use TCSBRK with zero parameter or TCSBRKP with any parameter.

Fix code to use TCSBRKP and fallback to TCSBRK with 0.

Thanks,
Stefan

Quoted 12 lines
---
  tools/termios_linux.h | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
tools/termios_linux.h +0 -0
index d73989b625a2..e100c8e4eb5f 100644
@@ -90,7 +90,11 @@ static inline int tcflush(int fd, int q)
 
  static inline int tcsendbreak(int fd, int d)

tools/termios_linux.h static inline int tcflush(int fd, int q) · line 100

Quoted 10 lines
tools/termios_linux.h +5 -1
  {
-	return ioctl(fd, TCSBRK, d);
+#ifdef TCSBRKP
+	return ioctl(fd, TCSBRKP, d);
+#else
+	return ioctl(fd, TCSBRK, 0);
+#endif
  }
 
  static inline int tcflow(int fd, int a)

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#2 lore raw
Quoted 12 lines · Stefan Roese
Quoted 11 lines · Pali Rohár

There are two Linux ioctls which implements tcsendbreak() functionality:
TCSBRK and TCSBRKP

TCSBRK with non-zero parameter implements tcdrain() and with zero parameter implements tcsendbreak() for duration of 0.25s.

TCSBRKP with zero parameter is same as TCSBRK and with non-zero parameter implements tcsendbreak() for duration in deciseconds specified by parameter. TCSBRKP does not have to be provided by older toolchain versions.

Quoted 8 lines
Quoted 6 lines

So tcsendbreak() has to either use TCSBRK with zero parameter or TCSBRKP with any parameter.

Fix code to use TCSBRKP and fallback to TCSBRK with 0.

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 19 lines

Thanks,
Stefan

Quoted 16 lines

---
  tools/termios_linux.h | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
tools/termios_linux.h +4 -1
index d73989b625a2..e100c8e4eb5f 100644
@@ -90,7 +90,11 @@ static inline int tcflush(int fd, int q)
   static inline int tcsendbreak(int fd, int d)
   {
-    return ioctl(fd, TCSBRK, d);
+#ifdef TCSBRKP
+    return ioctl(fd, TCSBRKP, d);
+#else
+    return ioctl(fd, TCSBRK, 0);
Quoted 9 lines

tools/termios_linux.h static inline int tcflush(int fd, int q)

Quoted 4 lines
tools/termios_linux.h +1 -0
+#endif
   }
   static inline int tcflow(int fd, int a)
 

Viele Grüße,
Stefan

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]