]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/src/tty.c
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / src / tty.c
index c47cc44fdaa4d637a08ff7a9f8a06686e3660312..3061924517617534112f960b23b08f19023a151f 100644 (file)
@@ -2,21 +2,35 @@
 /* SPDX-License-Identifier: Apache-2.0 */
 
 #include <metal/uart.h>
+#include <metal/tty.h>
 #include <metal/machine.h>
 
 #if defined(__METAL_DT_STDOUT_UART_HANDLE)
 /* This implementation serves as a small shim that interfaces with the first
  * UART on a system. */
-int metal_tty_putc(unsigned char c)
+int metal_tty_putc(int c)
 {
     if (c == '\n') {
-        int out = metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, '\r');
-        if (out != 0)
-            return out;
+        metal_tty_putc_raw( '\r' );
     }
+    return metal_tty_putc_raw( c );
+}
+
+int metal_tty_putc_raw(int c)
+{
     return metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, c);
 }
 
+int metal_tty_getc(int *c)
+{
+   do {
+        metal_uart_getc( __METAL_DT_STDOUT_UART_HANDLE, c );
+        /* -1 means no key pressed, getc waits */
+    } while( -1 == *c )
+        ;
+    return 0;
+}
+
 #ifndef __METAL_DT_STDOUT_UART_BAUD
 #define __METAL_DT_STDOUT_UART_BAUD 115200
 #endif
@@ -30,8 +44,8 @@ static void metal_tty_init(void)
 /* This implementation of putc doesn't actually do anything, it's just there to
  * provide a shim that eats all the characters so we can ensure that everything
  * can link to metal_tty_putc. */
-int nop_putc(unsigned char c) __attribute__((section(".text.metal.nop.putc")));
-int nop_putc(unsigned char c) { return -1; }
-int metal_tty_putc(unsigned char c) __attribute__((weak, alias("nop_putc")));
-#warning "There is no default output device, metal_tty_putc() will throw away all input."
+int nop_putc(int c) __attribute__((section(".text.metal.nop.putc")));
+int nop_putc(int c) { return -1; }
+int metal_tty_putc(int c) __attribute__((weak, alias("nop_putc")));
+#pragma message("There is no default output device, metal_tty_putc() will throw away all input.")
 #endif