rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2008-2014 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <stdarg.h> |
| 24 | #include <reg.h> |
| 25 | #include <stdio.h> |
| 26 | #include <kernel/thread.h> |
| 27 | #include <dev/uart.h> |
| 28 | #include <platform/debug.h> |
| 29 | #include <platform/qemu-virt.h> |
| 30 | #include <target/debugconfig.h> |
| 31 | #include <reg.h> |
| 32 | |
| 33 | /* DEBUG_UART must be defined to 0 or 1 */ |
| 34 | #if defined(DEBUG_UART) && DEBUG_UART == 0 |
| 35 | #define DEBUG_UART_BASE UART0_BASE |
| 36 | #elif defined(DEBUG_UART) && DEBUG_UART == 1 |
| 37 | #define DEBUG_UART_BASE UART1_BASE |
| 38 | #else |
| 39 | #error define DEBUG_UART to something valid |
| 40 | #endif |
| 41 | |
| 42 | void platform_dputc(char c) |
| 43 | { |
| 44 | if (c == '\n') |
| 45 | uart_putc(DEBUG_UART, '\r'); |
| 46 | uart_putc(DEBUG_UART, c); |
| 47 | } |
| 48 | |
| 49 | int platform_dgetc(char *c, bool wait) |
| 50 | { |
| 51 | int ret = uart_getc(DEBUG_UART, wait); |
| 52 | if (ret == -1) |
| 53 | return -1; |
| 54 | *c = ret; |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | void platform_pputc(char c) |
| 59 | { |
| 60 | if (c == '\n') |
| 61 | uart_pputc(DEBUG_UART, '\r'); |
| 62 | uart_pputc(DEBUG_UART, c); |
| 63 | } |
| 64 | |
| 65 | int platform_pgetc(char *c, bool wait) |
| 66 | { |
| 67 | int ret = uart_pgetc(DEBUG_UART); |
| 68 | if (ret < 0) |
| 69 | return ret; |
| 70 | *c = ret; |
| 71 | return 0; |
| 72 | } |
| 73 | |