]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/src/tty.c
Rename the RISC-V_RV32_SiFive_Hifive1_GCC folder to RISC-V_RV32_SiFive_HiFive1_Freedo...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / src / tty.c
1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
3
4 #include <metal/uart.h>
5 #include <metal/machine.h>
6
7 #if defined(__METAL_DT_STDOUT_UART_HANDLE)
8 /* This implementation serves as a small shim that interfaces with the first
9  * UART on a system. */
10 int metal_tty_putc(unsigned char c)
11 {
12     if (c == '\n') {
13         int out = metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, '\r');
14         if (out != 0)
15             return out;
16     }
17     return metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, c);
18 }
19
20 #ifndef __METAL_DT_STDOUT_UART_BAUD
21 #define __METAL_DT_STDOUT_UART_BAUD 115200
22 #endif
23
24 static void metal_tty_init(void) __attribute__((constructor));
25 static void metal_tty_init(void)
26 {
27     metal_uart_init(__METAL_DT_STDOUT_UART_HANDLE, __METAL_DT_STDOUT_UART_BAUD);
28 }
29 #else
30 /* This implementation of putc doesn't actually do anything, it's just there to
31  * provide a shim that eats all the characters so we can ensure that everything
32  * can link to metal_tty_putc. */
33 int nop_putc(unsigned char c) __attribute__((section(".text.metal.nop.putc")));
34 int nop_putc(unsigned char c) { return -1; }
35 int metal_tty_putc(unsigned char c) __attribute__((weak, alias("nop_putc")));
36 #warning "There is no default output device, metal_tty_putc() will throw away all input."
37 #endif