Software APIs
uart_testutils.h
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_UART_TESTUTILS_H_
6#define OPENTITAN_SW_DEVICE_LIB_TESTING_UART_TESTUTILS_H_
7
8#include <stdint.h>
9
10#include "hw/top/dt/dt_uart.h"
11#include "sw/device/lib/base/status.h"
14
15/**
16 * Define the available platforms which uart is mapped
17 */
18typedef enum uart_pinmux_platform_id {
19 kUartPinmuxPlatformIdFpgaCw310 = 0,
20 kUartPinmuxPlatformIdDvsim,
21 kUartPinmuxPlatformIdSilicon,
22 kUartPinmuxPlatformIdCount,
23} uart_pinmux_platform_id_t;
24
25/**
26 * Define the available external channels that a UART could be connected to.
27 */
28typedef enum uart_pinmux_channel {
29 kUartPinmuxChannelConsole,
30 kUartPinmuxChannelDut,
31 kUartPinmuxChannelCount,
32} uart_pinmux_channel_t;
33
34/**
35 * Connect the uart pins to mio pins via pinmux based on the platform the test
36 * is running.
37 *
38 * @param pimmux A pinmux handler.
39 * @param uart_idx The index of the UART to configure.
40 * @param platform The platform which the test is running.
41 * @return The result of the operation.
42 */
44status_t uart_testutils_select_pinmux(const dif_pinmux_t *pinmux,
45 uint8_t uart_idx,
46 uart_pinmux_channel_t channel);
47
48/**
49 * Disconnect the uart input pins from mio pads and wire it to zero.
50 *
51 * @param pimmux A pinmux handler.
52 * @param uart_id The index of the UART to configure.
53 * @return The result of the operation.
54 */
56status_t uart_testutils_detach_pinmux(const dif_pinmux_t *pinmux,
57 uint8_t uart_idx);
58
59#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_UART_TESTUTILS_H_