Skip to contentSkip to conversation

lib: utils/serial: Optimize semihosting_putc implementation

PATCH Superseded [email protected] 2 participants 2 messages Oct 17, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: utils/serial: Optimize semihosting_putc implementation

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

---
 lib/utils/serial/semihosting.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/utils/serial/semihosting.c +4 -1
index ce65887..9bbf2e2 100644
@@ -162,7 +162,10 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 static void semihosting_putc(char ch)
 {
-	semihosting_trap(SYSWRITEC, &ch);
+	if (semihosting_outfd < 0)
+		semihosting_trap(SYSWRITEC, &ch);
+	else
+		semihosting_write(semihosting_outfd, &ch, 1);
 }
 
 static unsigned long semihosting_puts(const char *str, unsigned long len)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 lib: utils/serial: Optimize semihosting_putc implementation

? 2023-10-17???? 19:53 +0800?cp0613 at linux.alibaba.com???

Quoted 19 lines

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

---
?lib/utils/serial/semihosting.c | 5 ++++-
?1 file changed, 4 insertions(+), 1 deletion(-)

lib/utils/serial/semihosting.c +0 -0
index ce65887..9bbf2e2 100644
@@ -162,7 +162,10 @@ static long semihosting_write(long fd, const void *memp, size_t len)

?
?static void semihosting_putc(char ch)
?{

lib/utils/serial/semihosting.c static long semihosting_write(long fd, const void *memp, size_t len) · line 168

Quoted 5 lines
lib/utils/serial/semihosting.c +4 -1
-	semihosting_trap(SYSWRITEC, &ch);
+	if (semihosting_outfd < 0)
+		semihosting_trap(SYSWRITEC, &ch);
+	else
+		semihosting_write(semihosting_outfd, &ch, 1);

The code can be simplified by calling semihosting_puts directly, otherwise look good to me.

Quoted 7 lines

?}
?
?static unsigned long semihosting_puts(const char *str, unsigned long len)

Signature · 1 line
2.25.1