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 "sw/device/lib/base/status.h"
13 
14 /**
15  * Define the available platforms which uart is mapped
16  */
17 typedef enum uart_pinmux_platform_id {
18  kUartPinmuxPlatformIdFpgaCw310 = 0,
19  kUartPinmuxPlatformIdDvsim,
20  kUartPinmuxPlatformIdSilicon,
21  kUartPinmuxPlatformIdCount,
22 } uart_pinmux_platform_id_t;
23 
24 /**
25  * Define the available external channels that a UART could be connected to.
26  */
27 typedef enum uart_pinmux_channel {
28  kUartPinmuxChannelConsole,
29  kUartPinmuxChannelDut,
30  kUartPinmuxChannelCount,
31 } uart_pinmux_channel_t;
32 
33 typedef struct uart_cfg_params {
34  uint32_t base_addr;
35  uint32_t peripheral_id;
36  uint32_t irq_tx_watermark_id;
37  uint32_t irq_tx_empty_id;
38  uint32_t irq_rx_watermark_id;
39  uint32_t irq_tx_done_id;
40  uint32_t irq_rx_overflow_id;
41  uint32_t irq_rx_frame_err_id;
42  uint32_t irq_rx_break_err_id;
43  uint32_t irq_rx_timeout_id;
44  uint32_t irq_rx_parity_err_id;
46 
47 /**
48  * Connect the uart pins to mio pins via pinmux based on the platform the test
49  * is running.
50  *
51  * @param pimmux A pinmux handler.
52  * @param uart_idx The index of the UART to configure.
53  * @param platform The platform which the test is running.
54  * @return The result of the operation.
55  */
57 status_t uart_testutils_select_pinmux(const dif_pinmux_t *pinmux,
58  uint8_t uart_idx,
59  uart_pinmux_channel_t channel);
60 
61 /**
62  * Disconnect the uart input pins from mio pads and wire it to zero.
63  *
64  * @param pimmux A pinmux handler.
65  * @param uart_id The index of the UART to configure.
66  * @return The result of the operation.
67  */
69 status_t uart_testutils_detach_pinmux(const dif_pinmux_t *pinmux,
70  uint8_t uart_idx);
71 
72 /**
73  * Look up the configuration parameters for a given UART instance.
74  *
75  * @param uart_idx The index of the UART being configured.
76  * @param[out] params Pointer to the struct to write the parameters to.
77  * @return The result of the operation.
78  */
80 status_t uart_testutils_cfg_params(uint8_t uart_idx, uart_cfg_params_t *params);
81 
82 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_UART_TESTUTILS_H_