[sw] Remove all references to uart_init()
Signed-off-by: Miguel Young de la Sota <mcyoung@google.com>
diff --git a/sw/device/benchmarks/coremark/meson.build b/sw/device/benchmarks/coremark/meson.build
index 694d2e0..6101d07 100644
--- a/sw/device/benchmarks/coremark/meson.build
+++ b/sw/device/benchmarks/coremark/meson.build
@@ -18,7 +18,7 @@
],
name_suffix: 'elf',
dependencies: [
- sw_lib_uart,
+ sw_lib_dif_uart,
sw_lib_mem,
riscv_crt,
sw_lib_irq_handlers,
diff --git a/sw/device/benchmarks/coremark/top_earlgrey/core_portme.c b/sw/device/benchmarks/coremark/top_earlgrey/core_portme.c
index 3437fec..2d264f7 100644
--- a/sw/device/benchmarks/coremark/top_earlgrey/core_portme.c
+++ b/sw/device/benchmarks/coremark/top_earlgrey/core_portme.c
@@ -9,9 +9,13 @@
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/stdasm.h"
+#include "sw/device/lib/dif/dif_uart.h"
+#include "sw/device/lib/runtime/check.h"
#include "sw/device/lib/testing/test_status.h"
#include "sw/vendor/eembc_coremark/coremark.h"
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
+
#if VALIDATION_RUN
volatile ee_s32 seed1_volatile = 0x3415;
volatile ee_s32 seed2_volatile = 0x3415;
@@ -103,12 +107,27 @@
ee_u32 default_num_contexts = 1;
+static dif_uart_t uart;
+
/* Function : portable_init
Target specific initialization code
Test for some common mistakes.
*/
void portable_init(core_portable *p, int *argc, char *argv[]) {
- uart_init(kUartBaudrate);
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart) == kDifUartOk,
+ "failed to init UART");
+ CHECK(dif_uart_configure(&uart,
+ (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk,
+ "failed to configure UART");
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) {
ee_printf(
diff --git a/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c b/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c
index a1cc426..b010cbd 100644
--- a/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c
+++ b/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c
@@ -33,6 +33,8 @@
*/
#include <stdarg.h>
+
+#include "sw/device/lib/runtime/print.h"
#include "sw/vendor/eembc_coremark/coremark.h"
#define ZEROPAD (1 << 0) /* Pad with zero */
@@ -654,23 +656,12 @@
}
int ee_printf(const char *fmt, ...) {
- char buf[256], *p;
+ char buf[256];
va_list args;
- int n = 0;
va_start(args, fmt);
ee_vsprintf(buf, fmt, args);
va_end(args);
- p = buf;
- while (*p) {
- if (*p == '\n') {
- uart_send_char('\r');
- }
- uart_send_char(*p);
- n++;
- p++;
- }
-
- return n;
+ return base_printf("%s", buf);
}
diff --git a/sw/device/boot_rom/boot_rom.c b/sw/device/boot_rom/boot_rom.c
index 8250041..dfff4b9 100644
--- a/sw/device/boot_rom/boot_rom.c
+++ b/sw/device/boot_rom/boot_rom.c
@@ -8,11 +8,14 @@
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/common.h"
#include "sw/device/lib/dif/dif_gpio.h"
+#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/pinmux.h"
+#include "sw/device/lib/runtime/check.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_status.h"
-#include "sw/device/lib/uart.h"
+
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
/**
* This symbol is defined in sw/device/boot_rom/rom_link.ld,
@@ -24,11 +27,27 @@
*/
extern struct { void (*entry)(void); } _flash_header;
+static dif_uart_t uart0;
+
void _boot_start(void) {
test_status_set(kTestStatusInBootRom);
pinmux_init();
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart0) == kDifUartOk,
+ "failed to init UART");
+ CHECK(dif_uart_configure(&uart0,
+ (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk,
+ "failed to configure UART");
+ base_uart_stdout(&uart0);
LOG_INFO("%s", chip_info);
diff --git a/sw/device/boot_rom/meson.build b/sw/device/boot_rom/meson.build
index d48f42d..8011f70 100644
--- a/sw/device/boot_rom/meson.build
+++ b/sw/device/boot_rom/meson.build
@@ -50,8 +50,8 @@
sw_lib_dif_spi_device,
sw_lib_hmac,
sw_lib_mmio,
- sw_lib_uart,
sw_lib_runtime_log,
+ sw_lib_dif_uart,
top_earlgrey,
device_lib,
sw_lib_testing_test_status,
diff --git a/sw/device/examples/hello_usbdev/hello_usbdev.c b/sw/device/examples/hello_usbdev/hello_usbdev.c
index 49f3543..c8bd0fc 100644
--- a/sw/device/examples/hello_usbdev/hello_usbdev.c
+++ b/sw/device/examples/hello_usbdev/hello_usbdev.c
@@ -10,15 +10,18 @@
#include "sw/device/lib/common.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_spi_device.h"
+#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/pinmux.h"
#include "sw/device/lib/runtime/check.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"
-#include "sw/device/lib/uart.h"
+#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/usb_controlep.h"
#include "sw/device/lib/usb_simpleserial.h"
#include "sw/device/lib/usbdev.h"
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
+
// These just for the '/' printout
#define USBDEV_BASE_ADDR 0x40150000
#include "usbdev_regs.h" // Generated.
@@ -61,27 +64,38 @@
static const size_t kExpectedUsbCharsRecved = 6;
static size_t usb_chars_recved_total;
+static dif_gpio_t gpio;
+static dif_spi_device_t spi;
+static dif_uart_t uart;
+
/**
* Callbacks for processing USB reciept. The latter increments the
* recieved character by one, to make them distinct.
*/
static void usb_receipt_callback_0(uint8_t c) {
c = make_printable(c, '?');
- uart_send_char(c);
+ CHECK(dif_uart_byte_send_polled(&uart, c) == kDifUartOk);
++usb_chars_recved_total;
}
static void usb_receipt_callback_1(uint8_t c) {
c = make_printable(c + 1, '?');
- uart_send_char(c);
+ CHECK(dif_uart_byte_send_polled(&uart, c) == kDifUartOk);
++usb_chars_recved_total;
}
-static dif_gpio_t gpio;
-static dif_spi_device_t spi;
-
int main(int argc, char **argv) {
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart) == kDifUartOk);
+ CHECK(dif_uart_configure(&uart, (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk);
+ base_uart_stdout(&uart);
pinmux_init();
@@ -133,9 +147,17 @@
gpio_state = demo_gpio_to_log_echo(&gpio, gpio_state);
demo_spi_to_log_echo(&spi);
- char rcv_char;
- while (uart_rcv_char(&rcv_char) != -1) {
- uart_send_char(rcv_char);
+ while (true) {
+ size_t chars_available;
+ if (dif_uart_rx_bytes_available(&uart, &chars_available) != kDifUartOk ||
+ chars_available == 0) {
+ break;
+ }
+
+ uint8_t rcv_char;
+ CHECK(dif_uart_bytes_receive(&uart, 1, &rcv_char, NULL) == kDifUartOk);
+ CHECK(dif_uart_byte_send_polled(&uart, rcv_char) == kDifUartOk);
+
CHECK(dif_gpio_write_all(&gpio, rcv_char << 8) == kDifGpioOk);
if (rcv_char == '/') {
@@ -150,12 +172,10 @@
// Signal that the simulation succeeded.
if (usb_chars_recved_total >= kExpectedUsbCharsRecved && !pass_signaled) {
- uart_send_str("\r\n");
- uart_send_str("PASS!\r\n");
+ LOG_INFO("PASS!");
pass_signaled = true;
}
}
- uart_send_str("\r\n");
LOG_INFO("USB recieved %d characters.", usb_chars_recved_total);
}
diff --git a/sw/device/examples/hello_usbdev/meson.build b/sw/device/examples/hello_usbdev/meson.build
index 98b369e..3b470cf 100644
--- a/sw/device/examples/hello_usbdev/meson.build
+++ b/sw/device/examples/hello_usbdev/meson.build
@@ -17,8 +17,8 @@
sw_lib_dif_gpio,
sw_lib_irq,
sw_lib_dif_spi_device,
- sw_lib_uart,
sw_lib_runtime_log,
+ sw_lib_dif_uart,
sw_lib_usb,
riscv_crt,
sw_lib_irq_handlers,
diff --git a/sw/device/examples/hello_world/hello_world.c b/sw/device/examples/hello_world/hello_world.c
index ab1fa81..052ce8e 100644
--- a/sw/device/examples/hello_world/hello_world.c
+++ b/sw/device/examples/hello_world/hello_world.c
@@ -6,19 +6,33 @@
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_spi_device.h"
+#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/pinmux.h"
#include "sw/device/lib/runtime/check.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"
+#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_status.h"
-#include "sw/device/lib/uart.h"
+
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
static dif_gpio_t gpio;
static dif_spi_device_t spi;
+static dif_uart_t uart;
int main(int argc, char **argv) {
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart) == kDifUartOk);
+ CHECK(dif_uart_configure(&uart, (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk);
+ base_uart_stdout(&uart);
pinmux_init();
diff --git a/sw/device/examples/hello_world/meson.build b/sw/device/examples/hello_world/meson.build
index 2589350..25c1466 100644
--- a/sw/device/examples/hello_world/meson.build
+++ b/sw/device/examples/hello_world/meson.build
@@ -16,7 +16,7 @@
sw_lib_dif_gpio,
sw_lib_irq,
sw_lib_dif_spi_device,
- sw_lib_uart,
+ sw_lib_dif_uart,
riscv_crt,
sw_lib_irq_handlers,
device_lib,
diff --git a/sw/device/lib/testing/meson.build b/sw/device/lib/testing/meson.build
index a1628ed..0a61bd5 100644
--- a/sw/device/lib/testing/meson.build
+++ b/sw/device/lib/testing/meson.build
@@ -54,8 +54,9 @@
'test_main_ot',
sources: ['test_main.c'],
dependencies: [
- sw_lib_uart,
sw_lib_runtime_log,
+ sw_lib_runtime_print,
+ sw_lib_dif_uart,
sw_lib_testing_test_status,
sw_lib_testing_test_coverage,
],
diff --git a/sw/device/lib/testing/test_main.c b/sw/device/lib/testing/test_main.c
index 75b76c9..71bd354 100644
--- a/sw/device/lib/testing/test_main.c
+++ b/sw/device/lib/testing/test_main.c
@@ -5,19 +5,40 @@
#include "sw/device/lib/testing/test_main.h"
#include "sw/device/lib/arch/device.h"
+#include "sw/device/lib/dif/dif_uart.h"
+#include "sw/device/lib/runtime/check.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_coverage.h"
#include "sw/device/lib/testing/test_status.h"
-#include "sw/device/lib/uart.h"
+
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
+
+static dif_uart_t uart0;
+static void init_uart(void) {
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart0) == kDifUartOk,
+ "failed to init UART");
+ CHECK(dif_uart_configure(&uart0,
+ (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk,
+ "failed to configure UART");
+ base_uart_stdout(&uart0);
+}
int main(int argc, char **argv) {
test_status_set(kTestStatusInTest);
// Initialize the UART to enable logging for non-DV simulation platforms.
if (kDeviceType != kDeviceSimDV) {
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+ init_uart();
}
// Run the SW test which is fully contained within `test_main()`.
@@ -25,7 +46,7 @@
// Must happen before any debug output.
if (kTestConfig.can_clobber_uart) {
- uart_init(kUartBaudrate);
+ init_uart();
}
test_coverage_send_buffer();
diff --git a/sw/device/riscv_compliance_support/support.c b/sw/device/riscv_compliance_support/support.c
index a199987..e31337a 100644
--- a/sw/device/riscv_compliance_support/support.c
+++ b/sw/device/riscv_compliance_support/support.c
@@ -5,16 +5,34 @@
#include <stddef.h>
#include "sw/device/lib/arch/device.h"
-#include "sw/device/lib/uart.h"
+#include "sw/device/lib/runtime/check.h"
+#include "sw/device/lib/runtime/print.h"
+
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
// These symbopls are provided by the riscv-compliance libraries.
extern void run_rvc_test(void);
extern volatile uint32_t begin_signature[];
extern volatile uint32_t end_signature[];
+static dif_uart_t uart0;
+
int opentitan_compliance_main(int argc, char **argv) {
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart0) == kDifUartOk,
+ "failed to init UART");
+ CHECK(dif_uart_configure(&uart0,
+ (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk,
+ "failed to configure UART");
+ base_uart_stdout(&uart0);
run_rvc_test();
diff --git a/sw/device/sca/aes_serial/aes_serial.c b/sw/device/sca/aes_serial/aes_serial.c
index 1c712fa..3706480 100644
--- a/sw/device/sca/aes_serial/aes_serial.c
+++ b/sw/device/sca/aes_serial/aes_serial.c
@@ -6,12 +6,13 @@
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_rv_timer.h"
+#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/handler.h"
#include "sw/device/lib/irq.h"
#include "sw/device/lib/pinmux.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"
-#include "sw/device/lib/uart.h"
+#include "sw/device/lib/runtime/print.h"
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
@@ -22,6 +23,7 @@
static dif_gpio_t gpio;
static dif_rv_timer_t timer;
+static dif_uart_t uart;
// UART input maximum buffer sizes
static const uint32_t kMaxInputLengthText = 128;
@@ -128,15 +130,11 @@
*/
static void print_cmd_response(const char cmd_tag, const char *data,
size_t data_len) {
- static const char b2a_hex_values[16] = "0123456789ABCDEF";
-
- // TODO: Switch to sw/device/lib/runtime/print.h
- uart_send_char(cmd_tag);
+ base_printf("%c", cmd_tag);
for (int i = 0; i < data_len; ++i) {
- uart_send_char(b2a_hex_values[data[i] >> 4]);
- uart_send_char(b2a_hex_values[data[i] & 0xF]);
+ base_printf("%x", (uint32_t)data[i]);
}
- uart_send_char('\n');
+ base_printf("\n");
}
/**
@@ -268,8 +266,19 @@
}
int main(int argc, char **argv) {
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart) == kDifUartOk);
+ CHECK(dif_uart_configure(&uart, (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk);
+ base_uart_stdout(&uart);
+
pinmux_init();
irq_global_ctrl(true);
@@ -303,7 +312,9 @@
char text[128] = {0};
size_t pos = 0;
while (true) {
- if (uart_rcv_char(&text[pos]) == -1) {
+ size_t chars_available;
+ if (dif_uart_rx_bytes_available(&uart, &chars_available) != kDifUartOk ||
+ chars_available == 0) {
usleep(50);
continue;
}
diff --git a/sw/device/sca/aes_serial/meson.build b/sw/device/sca/aes_serial/meson.build
index 4032acf..e558f5f 100644
--- a/sw/device/sca/aes_serial/meson.build
+++ b/sw/device/sca/aes_serial/meson.build
@@ -19,7 +19,7 @@
sw_lib_mmio,
sw_lib_pinmux,
sw_lib_runtime_hart,
- sw_lib_uart,
+ sw_lib_dif_uart,
],
)
diff --git a/sw/device/tests/crt_test.c b/sw/device/tests/crt_test.c
index 36e167f..7164130 100644
--- a/sw/device/tests/crt_test.c
+++ b/sw/device/tests/crt_test.c
@@ -7,11 +7,13 @@
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/stdasm.h"
+#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/runtime/check.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_status.h"
-#include "sw/device/lib/uart.h"
+
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
// Symbols defined in sw/device/exts/common/flash_link.ld, which we use to
// check that the CRT did what it was supposed to.
@@ -33,6 +35,25 @@
volatile char ensure_data_exists = 42;
volatile char ensure_bss_exists;
+static dif_uart_t uart0;
+static void init_uart(void) {
+ CHECK(dif_uart_init(
+ (dif_uart_params_t){
+ .base_addr = mmio_region_from_addr(TOP_EARLGREY_UART_BASE_ADDR),
+ },
+ &uart0) == kDifUartOk,
+ "failed to init UART");
+ CHECK(dif_uart_configure(&uart0,
+ (dif_uart_config_t){
+ .baudrate = kUartBaudrate,
+ .clk_freq_hz = kClockFreqPeripheralHz,
+ .parity_enable = kDifUartToggleDisabled,
+ .parity = kDifUartParityEven,
+ }) == kDifUartConfigOk,
+ "failed to configure UART");
+ base_uart_stdout(&uart0);
+}
+
int main(int argc, char **argv) {
// NOTE: we cannot call any external functions until all checks of post-CRT
// state are complete; this is to ensure that our checks are not tainted by
@@ -85,8 +106,7 @@
test_status_set(kTestStatusInTest);
// Initialize the UART to enable logging for non-DV simulation platforms.
if (kDeviceType != kDeviceSimDV) {
- uart_init(kUartBaudrate);
- base_set_stdout(uart_stdout);
+ init_uart();
}
CHECK(bss_start_addr % sizeof(uint32_t) == 0,
diff --git a/sw/device/tests/meson.build b/sw/device/tests/meson.build
index c23b0a0..df6a89c 100644
--- a/sw/device/tests/meson.build
+++ b/sw/device/tests/meson.build
@@ -153,6 +153,9 @@
device_lib,
sw_lib_irq_handlers,
sw_lib_testing_test_status,
+ sw_lib_runtime_print,
+ sw_lib_runtime_log,
+ sw_lib_dif_uart,
# Explicitly do not pull in the test main; we need to run right after
# the CRT is done executing.
# sw_lib_testing_test_main,