Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 3da9cb1 | 2019-04-23 10:53:45 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef __CONSOLE_H__ |
| 8 | #define __CONSOLE_H__ |
| 9 | |
| 10 | /* Returned by getc callbacks when receive FIFO is empty. */ |
| 11 | #define ERROR_NO_PENDING_CHAR -1 |
| 12 | /* Returned by console_xxx() if the registered console doesn't implement xxx. */ |
| 13 | #define ERROR_NO_VALID_CONSOLE (-128) |
| 14 | |
| 15 | #ifndef __ASSEMBLY__ |
| 16 | |
Ambroise Vincent | 602b7f5 | 2019-02-11 14:13:43 +0000 | [diff] [blame] | 17 | #include <stdint.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 18 | |
Antonio Nino Diaz | 3da9cb1 | 2019-04-23 10:53:45 +0100 | [diff] [blame] | 19 | /* |
| 20 | * Function to initialize the console without a C Runtime to print debug |
| 21 | * information. It saves the console base to the data section. Returns 1 on |
| 22 | * success, 0 on error. |
| 23 | */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 24 | int console_init(uintptr_t base_addr, |
| 25 | unsigned int uart_clk, unsigned int baud_rate); |
Antonio Nino Diaz | 3da9cb1 | 2019-04-23 10:53:45 +0100 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Function to output a character over the console. It returns the character |
| 29 | * printed on success or an error code. |
| 30 | */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 31 | int console_putc(int c); |
Antonio Nino Diaz | 3da9cb1 | 2019-04-23 10:53:45 +0100 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Function to get a character from the console. It returns the character |
| 35 | * grabbed on success or an error code on error. This function is blocking, it |
| 36 | * waits until there is an available character to return. Returns a character or |
| 37 | * error code. |
| 38 | */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 39 | int console_getc(void); |
Antonio Nino Diaz | 3da9cb1 | 2019-04-23 10:53:45 +0100 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Function to get a character from the console. It returns the character |
| 43 | * grabbed on success or an error code on error. This function is non-blocking, |
| 44 | * it returns immediately. |
| 45 | */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 46 | int console_try_getc(void); |
Antonio Nino Diaz | 3da9cb1 | 2019-04-23 10:53:45 +0100 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * Function to force a write of all buffered data that hasn't been output. It |
| 50 | * returns 0 upon successful completion, otherwise it returns an error code. |
| 51 | */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 52 | int console_flush(void); |
| 53 | |
| 54 | #endif /* __ASSEMBLY__ */ |
| 55 | |
| 56 | #endif /* __CONSOLE_H__ */ |