blob: 4c22a997d595a819a9992fa444ea50a09909fdc2 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +01002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
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 Vincent602b7f52019-02-11 14:13:43 +000017#include <stdint.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010019/*
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 Bailleux3cd87d72018-10-09 11:12:55 +020024int console_init(uintptr_t base_addr,
25 unsigned int uart_clk, unsigned int baud_rate);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010026
27/*
28 * Function to output a character over the console. It returns the character
29 * printed on success or an error code.
30 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020031int console_putc(int c);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010032
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 Bailleux3cd87d72018-10-09 11:12:55 +020039int console_getc(void);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010040
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 Bailleux3cd87d72018-10-09 11:12:55 +020046int console_try_getc(void);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010047
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 Bailleux3cd87d72018-10-09 11:12:55 +020052int console_flush(void);
53
54#endif /* __ASSEMBLY__ */
55
56#endif /* __CONSOLE_H__ */