lib: utils/serial: Optimize semihosting_putc implementation
authorChen Pei <cp0613@linux.alibaba.com>
Wed, 18 Oct 2023 02:42:05 +0000 (10:42 +0800)
committerAnup Patel <anup@brainfault.org>
Thu, 16 Nov 2023 06:06:44 +0000 (11:36 +0530)
For some debuggers that do not implement SYSWRITEC and SYSREADC
operations, we can use SYSWRITE and SYSREAD instead like the
implementation of semihosting_getc().

Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/utils/serial/semihosting.c

index ce65887dd72d1c8da59f1e94e74002a46d8eea92..a27c69eed81721cf57f0597cd9d5a2f5f2cf1c24 100644 (file)
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-       semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
        char ch;
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
        return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+       semihosting_puts(&ch, 1);
+}
+
 static int semihosting_getc(void)
 {
        char ch = 0;