diff --git a/hw/top_chip/rtl/top_chip_system.sv b/hw/top_chip/rtl/top_chip_system.sv index 984da567e..b723de35d 100644 --- a/hw/top_chip/rtl/top_chip_system.sv +++ b/hw/top_chip/rtl/top_chip_system.sv @@ -806,8 +806,8 @@ module top_chip_system #( .intr_gpio_o (gpio_interrupts) ); - // Instantiate our UART block. - uart u_uart ( + // Instantiate UART 16550 block. + uart16550 u_uart ( .clk_i (clkmgr_clocks.clk_io_infra), .rst_ni (rstmgr_resets.rst_io_n[rstmgr_pkg::DomainMainSel]), diff --git a/hw/top_chip/top_chip_system.core b/hw/top_chip/top_chip_system.core index be36cab28..c29d074c0 100644 --- a/hw/top_chip/top_chip_system.core +++ b/hw/top_chip/top_chip_system.core @@ -9,7 +9,7 @@ filesets: files_rtl: depend: - lowrisc:ip:i2c - - lowrisc:ip:uart + - lowrisc:ip:uart16550 - lowrisc:ip:rv_timer - lowrisc:ip:spi_device - lowrisc:ip:spi_host diff --git a/hw/vendor/REUSE.toml b/hw/vendor/REUSE.toml index 716e201cb..ae3917acd 100644 --- a/hw/vendor/REUSE.toml +++ b/hw/vendor/REUSE.toml @@ -86,6 +86,11 @@ path = ["axi_riscv_atomics/**"] SPDX-License-Identifier = "SHL-0.51" SPDX-FileCopyrightText = ["2018 ETH Zurich and University of Bologna."] +[[annotations]] +path = ["uart_16550/**"] +SPDX-License-Identifier = "Apache-2.0" +SPDX-FileCopyrightText = ["lowRISC and contributors (COSMIC project)."] + [[annotations]] path = ["patches/**"] SPDX-License-Identifier = "Apache-2.0" diff --git a/hw/vendor/uart_16550.lock.hjson b/hw/vendor/uart_16550.lock.hjson new file mode 100644 index 000000000..706cc36c2 --- /dev/null +++ b/hw/vendor/uart_16550.lock.hjson @@ -0,0 +1,14 @@ +// Copyright lowRISC contributors (OpenTitan project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +// This file is generated by the util/vendor script. Please do not modify it +// manually. + +{ + upstream: + { + url: https://github.com/lowRISC/uart-16550 + rev: da7b3330525dcab9545c247430ac5e0c71a97a38 + } +} diff --git a/hw/vendor/uart_16550.vendor.hjson b/hw/vendor/uart_16550.vendor.hjson new file mode 100644 index 000000000..87f7ad523 --- /dev/null +++ b/hw/vendor/uart_16550.vendor.hjson @@ -0,0 +1,17 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +{ + name: "uart_16550", + target_dir: "uart_16550", + + upstream: { + url: "https://github.com/lowRISC/uart-16550" + rev: "mocha-fixes" + } + + mapping: [ + // UART 16550 wrapper. + {from: "hw/ip/uart16550", to: "hw/ip/uart16550"}, + ], +} diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/README.md b/hw/vendor/uart_16550/hw/ip/uart16550/README.md new file mode 100644 index 000000000..76a843445 --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/README.md @@ -0,0 +1,36 @@ +# UART 16550 Hardware IP Block + +The UART 16550 IP block is a wrapper around the [OpenTitan UART IP][opentitan-uart], which allows it to be used with the standard 16550 register map. + +> [!IMPORTANT] +> The design for this IP is incomplete and the RTL will change significantly. This IP is also not well verified. + +## Register functionality + +As the OpenTitan UART IP and the [16550 specification][16550-spec] have different feature sets, this wrapper only provides features supported by both implementations. The differences in register functionality are further described in the [register documentation](doc/registers.md). + +## Functional differences + +Additional functional differences from the [16550 specification][16550-spec] are listed below: + +- Receive FIFO size is 64 bytes +- Transmit FIFO size is 32 bytes +- Received characters with framing error or parity error are not pushed into the RCVR FIFO. + +## Interrupts + +This wrapper provides the same set of interrupt outputs as the OpenTitan UART IP. The following interrupt outputs will however always be inactive as they are never enabled by the wrapper: + +- tx_watermark +- tx_done +- rx_timeout + +## Features not yet implemented + +- TL-UL host request integrity check, integrity errors will be ignored +- TL-UL host `PutPartialData` opcode, which will behave as `PutFullData` +- TL-UL host request size other than 2, which will be treated as 2 +- RACL, all registers will always be accessible + +[opentitan-uart]: https://github.com/lowRISC/opentitan/tree/master/hw/ip/uart +[16550-spec]: https://web.archive.org/web/20180826215135/http://www.ti.com/lit/ds/symlink/pc16550d.pdf diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550.hjson b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550.hjson new file mode 100644 index 000000000..17e3a9dc8 --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550.hjson @@ -0,0 +1,156 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +{ + name: "uart16550" + human_name: "UART 16550" + one_line_desc: "Wrapper around the OpenTitan UART core, which provides the standard 16550 register map." + one_paragraph_desc: ''' + Universal Asynchronous Receiver/Transmitter (UART) provides industry standard serial communication with external devices via two wires at a programmable baud rate. + The UART 16550 wrapper translates 16550 register accesses to the OpenTitan UART memory map, allowing the OpenTitan UART core to be used with built-in drivers from rich Operating Systems such as Linux. + ''' + // Unique comportable IP identifier defined under KNOWN_CIP_IDS in the regtool. + cip_id: "49" + design_spec: "../doc" + version: "0.0.1" + life_stage: "L1" + design_stage: "D0" + verification_stage: "V0" + + clocking: [ + { clock: "clk_i", reset: "rst_ni", primary: true } + ] + + bus_interfaces: [ + { protocol: "tlul", direction: "device", racl_support: false } + ] + + available_input_list: [ + { name: "rx", desc: "Serial receive bit" } + ] + available_output_list: [ + { name: "tx", desc: "Serial transmit bit" } + ] + + interrupt_list: [ + { name: "tx_watermark", + type: "status", + default: "1", + desc: "raised if the transmit FIFO is past the high-water mark."} + { name: "rx_watermark", + type: "status", + desc: "raised if the receive FIFO is past the high-water mark."} + { name: "tx_done", + desc: "raised if the transmit FIFO has emptied and no transmit is ongoing."} + { name: "rx_overflow", + desc: "raised if the receive FIFO has overflowed."} + { name: "rx_frame_err", + desc: "raised if a framing error has been detected on receive."} + { name: "rx_break_err", + desc: "raised if break condition has been detected on receive."} + { name: "rx_timeout", + desc: ''' + raised if RX FIFO has characters remaining in the FIFO without being + retrieved for the programmed time period. + ''' + } + { name: "rx_parity_err", + desc: "raised if the receiver has detected a parity error."} + { name: "tx_empty", + type: "status", + default: "1", + desc: "raised if the transmit FIFO is empty."} + ] + + alert_list: [ + { name: "fatal_fault", + desc: ''' + This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. + ''' + } + ] + + features: [ + { name: "UART.PARITY", + desc: ''' + The UART can be configured to so that it sends (or expects) a parity bit after each 8 data bits. + In receive mode, the UART sends the rx_parity_err interrupt if it receives a parity bit of the wrong polarity. + The parity mode is configurable (ensuring words are even or odd). + ''' + } + { name: "UART.SYSTEM_LOOPBACK", + desc: ''' + The UART can be configured so that outgoing bits are registered as having been received on the RX side. + ''' + } + { name: "UART.FIFO_INTERRUPTS", + desc: ''' + The UART can be configured to send an "watermark" interrupt when RX or TX FIFO is nearly full/empty, respectively. + It sends an rx_overflow interrupt if it sees an extra character when the RX FIFO is full. + ''' + } + ] + + inter_signal_list: [ + { struct: "logic" + type: "uni" + name: "lsio_trigger" + desc: ''' + Self-clearing status trigger for the DMA. + Set when RX or TX FIFOs are past their configured watermarks matching watermark interrupt behaviour. + ''' + act: "req" + } + { struct: "racl_policy_vec", + type: "uni", + name: "racl_policies", + act: "rcv", + package: "top_racl_pkg", + desc: ''' + Incoming RACL policy vector from a racl_ctrl instance. + The policy selection vector (parameter) selects the policy for each register. + ''' + } + { struct: "racl_error_log", + type: "uni", + name: "racl_error", + act: "req", + width: "1" + package: "top_racl_pkg", + desc: ''' + RACL error log information of this module. + ''' + } + ] + + countermeasures: [ + // No countermeasure implemented yet + ] + + param_list: [ + // Note that the watermark CSRs further below need to be adjusted when + // making changes to these FIFO depths. The RTL and DV are written in + // a parametric way and will adjust automatically. + { name: "RxFifoDepth", + desc: "Number of bytes in the RX FIFO.", + type: "int", + default: "64", + local: "true", + } + { name: "TxFifoDepth", + desc: "Number of bytes in the TX FIFO.", + type: "int", + default: "32", + local: "true", + } + ] + + regwidth: "32", + registers: [ + // Registers are specified in the following HJSON files as the interrupt and alert lists cause + // related CSRs, which do not exist on 16550, to be inserted at the start of the address map. + // - uart16550_main.hjson - Main address map with DLAB=0 and excluding write-only registers + // - uart16550_wo.hjson - Write-only registers with DLAB=0 + // - uart16550_dl.hjson - Divisor latch registers with DLAB=1 + ] +} diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_dl.hjson b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_dl.hjson new file mode 100644 index 000000000..c213cec0b --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_dl.hjson @@ -0,0 +1,50 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +{ + name: "uart16550_dl" + human_name: "UART 16550 divisor latch address map" + // Unique comportable IP identifier defined under KNOWN_CIP_IDS in the regtool. + cip_id: "49" + design_spec: "../doc" + version: "0.0.1" + life_stage: "L1" + design_stage: "D0" + verification_stage: "V0" + + clocking: [ + { clock: "clk_i", reset: "rst_ni", primary: true } + ] + + bus_interfaces: [ + { protocol: "tlul", direction: "device", racl_support: false } + ] + + regwidth: "32", + registers: [ + { name: "DLL", + desc: '''Divisor latch register (least significant byte). + One write to the divisor latch is needed to enable Tx and Rx. + ''', + swaccess: "rw", + hwaccess: "hro", + fields: [ + { bits: "7:0", + resval: "0x00" + } + ] + } + { name: "DLM", + desc: '''Divisor latch register (most significant byte). + One write to the divisor latch is needed to enable Tx and Rx. + ''', + swaccess: "rw", + hwaccess: "hro", + fields: [ + { bits: "7:0", + resval: "0x00" + } + ] + } + ] +} diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_main.hjson b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_main.hjson new file mode 100644 index 000000000..dcf565cdf --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_main.hjson @@ -0,0 +1,299 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +{ + name: "uart16550_main" + human_name: "UART 16550 main address map" + // Unique comportable IP identifier defined under KNOWN_CIP_IDS in the regtool. + cip_id: "49" + design_spec: "../doc" + version: "0.0.1" + life_stage: "L1" + design_stage: "D0" + verification_stage: "V0" + + clocking: [ + { clock: "clk_i", reset: "rst_ni", primary: true } + ] + + bus_interfaces: [ + { protocol: "tlul", direction: "device", racl_support: false } + ] + + regwidth: "32", + registers: [ + { name: "RBR", + desc: "Receive buffer register.", + swaccess: "ro", + hwaccess: "hrw", + hwext: "true", + hwre: "true", + fields: [ + { bits: "7:0", + resval: "0x00" + } + ] + } + { name: "IER", + desc: "Interrupt enable register.", + swaccess: "rw", + hwaccess: "hro", + fields: [ + { bits: "0", + name: "ERBFI", + desc: "Enable received data available interrupt.", + resval: "0" + } + { bits: "1", + name: "ETBEI", + desc: "Enable transmitter holding register empty interrupt.", + resval: "0", + tags: [// Do not write to ETBEI, this causes THRE interrupt to be indicated + // with an empty transmitter and affects the value in IIR. + "excl:CsrNonInitTests:CsrExclWrite"] + } + { bits: "2", + name: "ELSI", + desc: "Enable receiver line status interrupt.", + resval: "0" + } + { bits: "3", + name: "EDSSI", + desc: "Enable MODEM status interrupt.", + resval: "0" + } + ] + } + { name: "IIR", + desc: "Interrupt identification register.", + swaccess: "ro", + hwaccess: "hrw", + fields: [ + { bits: "0", + name: "INTR_PENDING", + desc: "Interrupt pending, active low.", + resval: "1" + } + { bits: "3:1", + name: "INTR_ID", + desc: '''Interrupt ID for the highest priority pending interrupt. + Encoding: + 0b011: Receiver line status interrupt + 0b010: Received data available interrupt + 0b110: Character timeout indication + 0b001: Transmitter holding register empty + 0b000: MODEM status interrupt or no pending interrupt + ''', + resval: "0x0" + } + { bits: "7:6", + name: "FIFO_EN", + desc: "FIFO enable, replicated across the width of this field.", + resval: "0x0" + } + ] + } + { name: "LCR", + desc: "Line control register.", + swaccess: "rw", + hwaccess: "hro", + fields: [ + { bits: "1:0", + name: "WLS", + desc: "Word length select, tied to 0x3 to indicate 8-bit word length.", + swaccess: "ro", + resval: "0x3" + } + { bits: "2", + name: "STB", + desc: "Number of stop bits, tied to 0 to indicate 1 stop bit.", + swaccess: "ro", + resval: "0" + } + { bits: "3", + name: "PEN", + desc: "Parity enable.", + resval: "0" + } + { bits: "4", + name: "EPS", + desc: "Even parity select.", + resval: "1" + } + { bits: "5", + name: "STICK_PARITY", + desc: "Stick parity, tied to 0 to indicate that it is always disabled.", + swaccess: "ro", + resval: "0" + } + { bits: "6", + name: "BREAK_CTRL", + desc: '''Break control bit. + When set to 1, the UART serial output is forced to spacing (logic 0) state. + This has no effect on the transmitter logic. + ''', + resval: "0", + tags: [// Do not write to BREAK_CTRL, writing 1 forces the Tx output to 0 and causes + // UART protocol violation. + "excl:CsrAllTests:CsrExclWrite"] + } + { bits: "7", + name: "DLAB", + desc: '''Divisor latch access bit. + This bit must be set high to access the DLL and DLM registers. + This bit must be set low to access the RBR, THR and IER registers. + ''', + resval: "0", + tags: [// Do not write to DLAB, this affects which registers are accessible + // at address offsets 0x0 and 0x4. + "excl:CsrNonInitTests:CsrExclWrite"] + } + ] + } + { name: "MCR", + desc: "MODEM control register.", + swaccess: "rw", + hwaccess: "hro", + fields: [ + { bits: "0", + name: "DTR", + desc: "Data terminal ready. This field has no effect on external pins.", + resval: "0" + } + { bits: "1", + name: "RTS", + desc: "Request to send. This field has no effect on external pins.", + resval: "0" + } + { bits: "3:2", + name: "OUT", + desc: "User-designated output. This field has no effect on external pins.", + resval: "0" + } + { bits: "4", + name: "LOOP", + desc: '''System loopback enable. + When set to 1: + 1. The serial output is set to the marking (logic 1) state. + 2. The serial input is disconnected. + 3. The transmitter shift register output is looped back to the + receiver shift register input. + 4. The MODEM control outouts (DTR, RTS, OUT1, OUT2) are internally + connected to the MODEM control inputs. + ''', + resval: "0", + tags: [// Do not write to LOOP, this affects the value in MSR. + "excl:CsrNonInitTests:CsrExclWrite"] + } + ] + } + { name: "LSR", + desc: "Line status register.", + swaccess: "ro", + hwaccess: "hrw", + fields: [ + { bits: "0", + name: "DR", + desc: "Data ready.", + resval: "0" + } + { bits: "1", + name: "OE", + desc: "Overrun error. Indicated on reception.", + swaccess: "rc", + resval: "0" + } + { bits: "2", + name: "PE", + desc: "Parity error. Indicated on reception.", + swaccess: "rc", + resval: "0" + } + { bits: "3", + name: "FE", + desc: "Framing error. Indicated on reception.", + swaccess: "rc", + resval: "0" + } + { bits: "4", + name: "BI", + desc: "Break interrupt. Indicated on reception.", + swaccess: "rc", + resval: "0" + } + { bits: "5", + name: "THRE", + desc: "Transmitter holding register empty.", + resval: "1" + } + { bits: "6", + name: "TEMT", + desc: "Transmitter empty.", + resval: "1" + } + { bits: "7", + name: "RCVR_FIFO_ERROR", + desc: "Error in receiver FIFO. Equivalent to the or reduction of PE, FE and BI.", + resval: "0" + } + ] + } + { name: "MSR", + desc: "MODEM status register.", + swaccess: "ro", + hwaccess: "hwo", + fields: [ + { bits: "0", + name: "DCTS", + desc: "Delta clear to send. Tied to 0.", + resval: "0" + } + { bits: "1", + name: "DDSR", + desc: "Delta data set ready. Tied to 0.", + resval: "0" + } + { bits: "2", + name: "TERI", + desc: "Trailing edge ring indicator. Tied to 0.", + resval: "0" + } + { bits: "3", + name: "DDCD", + desc: "Delta data carrier detect. Tied to 0.", + resval: "0" + } + { bits: "4", + name: "CTS", + desc: "Clear to send. Tied to 0 when loopback is disabled.", + resval: "0" + } + { bits: "5", + name: "DSR", + desc: "Data set ready. Tied to 0 when loopback is disabled.", + resval: "0" + } + { bits: "6", + name: "RI", + desc: "Ring indicator. Tied to 0 when loopback is disabled.", + resval: "0" + } + { bits: "7", + name: "DCD", + desc: "Data carrier detect. Tied to 0 when loopback is disabled.", + resval: "0" + } + ] + } + { name: "SCR", + desc: "Scratch register.", + swaccess: "rw", + hwaccess: "none", + fields: [ + { bits: "7:0", + resval: "0x00" + } + ] + } + ] +} diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_wo.hjson b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_wo.hjson new file mode 100644 index 000000000..45a908a99 --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/data/uart16550_wo.hjson @@ -0,0 +1,85 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +{ + name: "uart16550_wo" + human_name: "UART 16550 write-only address map" + // Unique comportable IP identifier defined under KNOWN_CIP_IDS in the regtool. + cip_id: "49" + design_spec: "../doc" + version: "0.0.1" + life_stage: "L1" + design_stage: "D0" + verification_stage: "V0" + + clocking: [ + { clock: "clk_i", reset: "rst_ni", primary: true } + ] + + bus_interfaces: [ + { protocol: "tlul", direction: "device", racl_support: false } + ] + + regwidth: "32", + registers: [ + { name: "THR", + desc: "Transmitter holding register.", + swaccess: "wo", + hwaccess: "hro", + hwext: "true", + hwqe: "true", + fields: [ + { bits: "7:0" } + ] + tags: [// Do not write to THR, this affects the values in IIR and LSR. + "excl:CsrNonInitTests:CsrExclWrite"] + } + { skipto: "0x8" } + { name: "FCR", + desc: "FIFO control register.", + swaccess: "wo", + hwaccess: "hrw", + hwqe: "true", + fields: [ + { bits: "0", + name: "FIFO_EN", + desc: "FIFO enable.", + resval: "0", + tags: [// Do not write to FIFO_EN, this affects the value of IIR[7:6] + // which aliases this bit. + "excl:CsrNonInitTests:CsrExclWrite"] + } + { bits: "1", + name: "RCVR_FIFO_RESET", + desc: '''Receiver FIFO reset. + Writing 1 to this field resets the receiver FIFO, the write is self-clearing. + ''', + resval: "0" + } + { bits: "2", + name: "XMIT_FIFO_RESET", + desc: '''Transmitter FIFO reset. + Writing 1 to this field resets the transmitter FIFO, the write is self-clearing. + ''', + resval: "0" + } + { bits: "3", + name: "DMA_MODE_SEL", + desc: "DMA mode select. This field has no effect.", + resval: "0" + } + { bits: "7:6", + name: "RCVR_TRIGGER", + desc: '''Trigger level for the RCVR FIFO interrupt. + Encoding: + 0b00: 1 byte + 0b01: 4 bytes + 0b10: 8 bytes + 0b11: 16 bytes + ''', + resval: "0x0" + } + ] + } + ] +} diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/doc/registers.md b/hw/vendor/uart_16550/hw/ip/uart16550/doc/registers.md new file mode 100644 index 000000000..dc4b4c22e --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/doc/registers.md @@ -0,0 +1,24 @@ +# UART 16550 registers + +All standard 16550 registers are implemented and accessible at the least significant byte of consecutive 4-byte words. Writes to the more significant 3 bytes are ignored and reads from these 3 bytes return 0. +The register map has a size of 32 bytes and wraps every 32 bytes. +Accesses with a non-zero `a_address[1:0]` return an error. + +The difference in functionality between the [16550 specification][16550-spec] and the UART 16550 wrapper is provided in the table below. + +| Register | Address offset (bytes) | Access | Difference from the specification | +|-|-|-|-| +| RBR | 0x0 (DLAB=0) | RO | Reads from an empty RCVR FIFO returns 0. | +| THR | 0x0 (DLAB=0) | WO | Writes to a full XMIT FIFO are dropped. | +| IER | 0x4 (DLAB=0) | RW | Values written to EDSSI are kept, but will have no other effect as MODEM status interrupts are never raised. | +| IIR | 0x8 | RO | Bit 3 is set when FIFO is enabled and there is an RCVR FIFO overflow interrupt. FIFO mode timeout interrupts are aliased to received data available interrupts, and are raised immediately when the trigger level is reached without a timeout. Software must set a RCVR FIFO trigger level of 1 byte. THRE interrupt will not be cleared by reading IIR. A fix for bit 3 and FIFO mode timeout interrupt are tracked in [#9](https://github.com/lowRISC/uart-16550/issues/9). | +| FCR | 0x8 | WO | 16450 mode is not supported. Values written to FIFO enable are kept, but will have no other effect as the OpenTitan UART always uses a FIFO. Changing FIFO enable does not clear the FIFOs. All bits of FCR are writable regardless of the value of FIFO enable. Writes to bits 3-5 have no effect. Writing `0b11` to the RCVR FIFO trigger level will set a trigger level of 16 bytes. | +| LCR | 0xC | RW | WLS writes are ignored and reads return `0b11` to indicate 8-bit word length. STB writes are ignored and reads return `0b0` to indicate 1 stop bit. EPS resets to `0b1` to indicate it is enabled by default. Writes to stick parity are ignored and reads return `0b0` to indicate that stick parity is always disabled. | +| MCR | 0x10 | RW | Values written to DTR, RTS and OUT are kept but have no effect on external pins. | +| LSR | 0x14 | RO | Break interrupt is indicated when the Rx pin has been continuously low for 1 bit time less than 2 character times. The first all-zero character of a break sets FE. PE, FE and BI are indicated on reception, with `LSR[7]` being the or reduction of these bits. Writes are ignored and do not return an error. | +| MSR | 0x18 | RO | Reads to DCTS, DDSR, TERI and DDCD always return 0. Reads to CTS, DSR, RI and DCD return 0 when loopback is disabled. Writes are ignored and do not return an error. | +| SCR | 0x1C | RW | - | +| DLL | 0x0 (DLAB=1) | RW | Values written are kept, but will always set CTRL.NCO to 20972, corresponding to 1 Mbaud at 50 MHz clock. One write to DLL/DLM is needed to enable Tx and Rx. | +| DLM | 0x4 (DLAB=1) | RW | Same as DLL. | + +[16550-spec]: https://web.archive.org/web/20180826215135/http://www.ti.com/lit/ds/symlink/pc16550d.pdf diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/pre_dv/uart16550_tb.core b/hw/vendor/uart_16550/hw/ip/uart16550/pre_dv/uart16550_tb.core new file mode 100644 index 000000000..fc0fe349d --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/pre_dv/uart16550_tb.core @@ -0,0 +1,46 @@ +CAPI=2: +# Copyright lowRISC contributors (OpenTitan project). +# Copyright lowRISC and contributors (COSMIC project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +name: "lowrisc:dv:uart16550_tb:0.1" +description: "uart16550 pre_dv sim target" +filesets: + files_rtl: + depend: + - lowrisc:ip:uart16550 + + files_dv: + files: + - uart16550_tb.sv + file_type: systemVerilogSource + +targets: + default: &default_target + filesets: + - files_rtl + - files_dv + + sim: + <<: *default_target + default_tool: verilator + toplevel: uart16550_tb + tools: + verilator: + mode: binary + verilator_options: + # Disabling tracing reduces compile times but doesn't have a + # huge influence on runtime performance. + - '--trace' + - '--trace-fst' # this requires -DVM_TRACE_FMT_FST in CFLAGS below! + - '--trace-structs' + - '--trace-params' + - '--trace-max-array 1024' + - '--assert' + # Enable all warnings + - '-Wall' + # Enable timing support + - '--timing' + # Default timescale + - '--timescale 1ns/1ps' diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/pre_dv/uart16550_tb.sv b/hw/vendor/uart_16550/hw/ip/uart16550/pre_dv/uart16550_tb.sv new file mode 100644 index 000000000..0a6e3513a --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/pre_dv/uart16550_tb.sv @@ -0,0 +1,240 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +module uart16550_tb; + +// Clock and reset signals +logic clk; +logic rst_n; + +// Waveform trace set up +initial begin + $dumpfile("tb.fst"); + $dumpvars(); +end + +// CLock set up +initial begin + clk = 0; + forever #10 clk = ~clk; // Clock is at 100 MHz +end + +// DUT signals +tlul_pkg::tl_h2d_t tl_i; +tlul_pkg::tl_d2h_t tl_o; + +// Test variables +bit has_assert_fail; + +// DUT instantiation +uart16550 u_dut ( + .clk_i (clk), + .rst_ni (rst_n), + + // Bus Interface + .tl_i (tl_i), + .tl_o (tl_o), + + // Alerts + .alert_rx_i (prim_alert_pkg::ALERT_RX_DEFAULT), + .alert_tx_o ( ), + + // RACL interface + .racl_policies_i (top_racl_pkg::RACL_POLICY_VEC_DEFAULT), + .racl_error_o ( ), + + .lsio_trigger_o ( ), + + .cio_rx_i (1'b0), + .cio_tx_o ( ), + .cio_tx_en_o ( ), + + // Interrupts + .intr_tx_watermark_o ( ), + .intr_tx_empty_o ( ), + .intr_rx_watermark_o ( ), + .intr_tx_done_o ( ), + .intr_rx_overflow_o ( ), + .intr_rx_frame_err_o ( ), + .intr_rx_break_err_o ( ), + .intr_rx_timeout_o ( ), + .intr_rx_parity_err_o ( ) +); + +// Test sequence +initial begin + // Initial signals + rst_n = 0; + tl_i = tlul_pkg::TL_H2D_DEFAULT; + tl_i.d_ready = 0; + has_assert_fail = 0; + + // Deassert reset + repeat(10) @(posedge clk); + rst_n <= 1; + + repeat(2) @(posedge clk); + + + // Fixed register tests + uart_req(.is_wr(1), .a(0), .data_in(32'hFE45AB01), .exp_data_out(32'hFFFFFFFF)); // Reg 0 wr FE45AB01 + uart_req(.is_wr(0), .a(0), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 0 rd + uart_req(.is_wr(0), .a(1), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 1 rd + uart_req(.is_wr(1), .a(1), .data_in(32'hFE120005), .exp_data_out(32'hFFFFFFFF)); // Reg 1 wr FE120005 + uart_req(.is_wr(0), .a(1), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000005)); // Reg 1 rd + uart_req(.is_wr(1), .a(1), .data_in(32'h44EEFF0A), .exp_data_out(32'hFFFFFFFF)); // Reg 1 wr 44EEFF0A + uart_req(.is_wr(0), .a(1), .data_in(32'hFFFFEEEE), .exp_data_out(32'h0000000A)); // Reg 1 rd + uart_req(.is_wr(1), .a(1), .data_in(32'h00000000), .exp_data_out(32'hFFFFFFFF)); // Reg 1 wr 00000000 + uart_req(.is_wr(0), .a(2), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000001)); // Reg 2 rd + uart_req(.is_wr(1), .a(2), .data_in(32'hFFFF0087), .exp_data_out(32'hFFFFFFFF)); // Reg 2 wr FFFF0087 + uart_req(.is_wr(0), .a(2), .data_in(32'hFFFFEEEE), .exp_data_out(32'h000000C1)); // Reg 2 rd + uart_req(.is_wr(0), .a(3), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000013)); // Reg 3 rd + uart_req(.is_wr(1), .a(3), .data_in(32'hFFFF00FC), .exp_data_out(32'hFFFFFFFF)); // Reg 3 wr FFFF00FC + uart_req(.is_wr(0), .a(3), .data_in(32'hFFFFEEEE), .exp_data_out(32'h000000DB)); // Reg 3 rd + uart_req(.is_wr(1), .a(3), .data_in(32'h00000000), .exp_data_out(32'hFFFFFFFF)); // Reg 3 wr 00000000 + uart_req(.is_wr(0), .a(3), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000003)); // Reg 3 rd + uart_req(.is_wr(0), .a(4), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 4 rd + uart_req(.is_wr(1), .a(4), .data_in(32'hDDDDDD5A), .exp_data_out(32'hFFFFFFFF)); // Reg 4 wr DDDDDD5A + uart_req(.is_wr(0), .a(4), .data_in(32'hFFFFEEEE), .exp_data_out(32'h0000001A)); // Reg 4 rd + uart_req(.is_wr(1), .a(4), .data_in(32'hBBBBBBA5), .exp_data_out(32'hFFFFFFFF)); // Reg 4 wr BBBBBBA5 + uart_req(.is_wr(0), .a(4), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000005)); // Reg 4 rd + uart_req(.is_wr(1), .a(5), .data_in(32'hFFFFAA55), .exp_data_out(32'hFFFFFFFF)); // Reg 5 wr FFFFAA55 + uart_req(.is_wr(0), .a(5), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000060)); // Reg 5 rd + uart_req(.is_wr(0), .a(6), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 6 rd + uart_req(.is_wr(1), .a(4), .data_in(32'hFFFF0015), .exp_data_out(32'hFFFFFFFF)); // Reg 4 wr FFFF0015 + uart_req(.is_wr(0), .a(6), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000060)); // Reg 6 rd + uart_req(.is_wr(1), .a(4), .data_in(32'hFFFF001B), .exp_data_out(32'hFFFFFFFF)); // Reg 4 wr FFFF001B + uart_req(.is_wr(0), .a(6), .data_in(32'hFFFFEEEE), .exp_data_out(32'h000000B0)); // Reg 6 rd + uart_req(.is_wr(1), .a(4), .data_in(32'hFFFF000F), .exp_data_out(32'hFFFFFFFF)); // Reg 4 wr FFFF000F + uart_req(.is_wr(0), .a(6), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 6 rd + uart_req(.is_wr(0), .a(7), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 7 rd + uart_req(.is_wr(1), .a(7), .data_in(32'hABCDEF5A), .exp_data_out(32'hFFFFFFFF)); // Reg 7 wr ABCDEF5A + uart_req(.is_wr(0), .a(7), .data_in(32'hFFFFEEEE), .exp_data_out(32'h0000005A)); // Reg 7 rd + uart_req(.is_wr(1), .a(7), .data_in(32'hFC5612A5), .exp_data_out(32'hFFFFFFFF)); // Reg 7 wr FC5612A5 + uart_req(.is_wr(0), .a(7), .data_in(32'hFFFFEEEE), .exp_data_out(32'h000000A5)); // Reg 7 rd + uart_req(.is_wr(1), .a(1), .data_in(32'h44EEFF0A), .exp_data_out(32'hFFFFFFFF)); // Reg 1 wr 44EEFF0A + uart_req(.is_wr(1), .a(3), .data_in(32'h00000080), .exp_data_out(32'hFFFFFFFF)); // Reg 3 wr 00000080 + uart_req(.is_wr(0), .a(0), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 0 rd + uart_req(.is_wr(0), .a(1), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 1 rd + uart_req(.is_wr(1), .a(0), .data_in(32'h9AB5EEAB), .exp_data_out(32'hFFFFFFFF)); // Reg 0 wr 9AB5EEAB + uart_req(.is_wr(1), .a(1), .data_in(32'h3CBE0191), .exp_data_out(32'hFFFFFFFF)); // Reg 1 wr 3CBE0191 + uart_req(.is_wr(0), .a(0), .data_in(32'hFFFFEEEE), .exp_data_out(32'h000000AB)); // Reg 0 rd + uart_req(.is_wr(0), .a(1), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000091)); // Reg 1 rd + uart_req(.is_wr(1), .a(3), .data_in(32'h00000000), .exp_data_out(32'hFFFFFFFF)); // Reg 3 wr 00000000 + uart_req(.is_wr(0), .a(0), .data_in(32'hFFFFEEEE), .exp_data_out(32'h00000000)); // Reg 0 rd + uart_req(.is_wr(0), .a(1), .data_in(32'hFFFFEEEE), .exp_data_out(32'h0000000A)); // Reg 1 rd + + + repeat(10) @(posedge clk); + + if (has_assert_fail) + $display("Test failed!"); + else + $display("Test passed!"); + + $finish(); +end + +// Task to make TL-UL access to uart16550 +task uart_req( + input logic is_wr, + input logic [3-1:0] a, + input logic [top_pkg::TL_DW-1:0] data_in, + input logic [top_pkg::TL_DW-1:0] exp_data_out +); + +tlul_pkg::tl_h2d_t req_tl_h2d; +tlul_pkg::tl_d_op_e exp_d_opcode; +logic [top_pkg::TL_AIW-1:0] exp_d_source; + +begin + // Set expected device opcode + if (is_wr) begin + exp_d_opcode = tlul_pkg::AccessAck; + end else begin + exp_d_opcode = tlul_pkg::AccessAckData; + end + + // Set expected source + exp_d_source = top_pkg::TL_AIW'($urandom()); + + // Send request + @(posedge clk); + req_tl_h2d.a_valid = 1; + if (is_wr) begin + req_tl_h2d.a_opcode = tlul_pkg::PutFullData; + end else begin + req_tl_h2d.a_opcode = tlul_pkg::Get; + end + req_tl_h2d.a_param = '0; + req_tl_h2d.a_size = 2; + req_tl_h2d.a_source = exp_d_source; + req_tl_h2d.a_address = $urandom(); // Unused address bits are randomised + req_tl_h2d.a_address[0 +: $clog2(top_pkg::TL_DBW)] = '0; // Address is word aligned + req_tl_h2d.a_address[$clog2(top_pkg::TL_DBW) +: 3] = a; // Register ID + req_tl_h2d.a_mask = 4'hF; + req_tl_h2d.a_data = data_in; + req_tl_h2d.a_user = '{ + rsvd: '0, + instr_type: prim_mubi_pkg::MuBi4False, + cmd_intg: tlul_pkg::get_cmd_intg(.tl(req_tl_h2d)), + data_intg: tlul_pkg::get_data_intg(.data(req_tl_h2d.a_data)) + }; + req_tl_h2d.d_ready = 1'b0; // Not ready for a response by default + + tl_i <= req_tl_h2d; + do @(posedge clk); while (!tl_o.a_ready); + + // Clear a_valid and wait for response + req_tl_h2d = tlul_pkg::TL_H2D_DEFAULT; + if ($urandom_range(1) == 1) begin + // Assert d_ready immediately + tl_i <= req_tl_h2d; + end else begin + // Assert d_ready after some delay + req_tl_h2d.d_ready = 1'b0; + tl_i <= req_tl_h2d; + + repeat($urandom_range(1, 10)) @(posedge clk); + tl_i.d_ready <= 1; + end + + while (!tl_o.d_valid) @(posedge clk); + assert(tl_o.d_error == 0) else begin + $warning("[t=%0t] d_error test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_opcode == exp_d_opcode) else begin + $warning("[t=%0t] d_opcode test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_param == '0) else begin + $warning("[t=%0t] d_param test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_size == 2) else begin + $warning("[t=%0t] d_size test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_source == exp_d_source) else begin + $warning("[t=%0t] d_source test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_data == exp_data_out) else begin + $warning("[t=%0t] d_data test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_user.data_intg == tlul_pkg::get_data_intg(.data(tl_o.d_data))) else begin + $warning("[t=%0t] d_user.data_intg test failed!", $time()); + has_assert_fail = 1; + end + assert(tl_o.d_user.rsp_intg == tlul_pkg::get_rsp_intg(.tl(tl_o))) else begin + $warning("[t=%0t] d_user.rsp_intg test failed!", $time()); + has_assert_fail = 1; + end +end + +endtask + +endmodule diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_dl.rdl b/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_dl.rdl new file mode 100644 index 000000000..f29c53ded --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_dl.rdl @@ -0,0 +1,16 @@ +addrmap uart16550_dl { + addrmap { + reg { + field { + sw = rw; + hw = r; + } DLL[7:0] = 0x0; + } DLL @ 0x0; + reg { + field { + sw = rw; + hw = r; + } DLM[7:0] = 0x0; + } DLM @ 0x4; + } none @ 0x0; +}; \ No newline at end of file diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_main.rdl b/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_main.rdl new file mode 100644 index 000000000..a67d0326a --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_main.rdl @@ -0,0 +1,220 @@ +addrmap uart16550_main { + addrmap { + reg { + hwre = true; + field { + sw = r; + hw = rw; + } RBR[7:0] = 0x0; + } external RBR @ 0x0; + reg { + field { + sw = rw; + hw = r; + desc = "Enable received data available interrupt."; + } ERBFI[0:0] = 0x0; + field { + sw = rw; + hw = r; + desc = "Enable transmitter holding register empty interrupt."; + } ETBEI[1:1] = 0x0; + field { + sw = rw; + hw = r; + desc = "Enable receiver line status interrupt."; + } ELSI[2:2] = 0x0; + field { + sw = rw; + hw = r; + desc = "Enable MODEM status interrupt."; + } EDSSI[3:3] = 0x0; + } IER @ 0x4; + reg { + field { + sw = r; + hw = rw; + desc = "Interrupt pending, active low."; + } INTR_PENDING[0:0] = 0x1; + field { + sw = r; + hw = rw; + desc = "Interrupt ID for the highest priority pending interrupt. + Encoding: + 0b011: Receiver line status interrupt + 0b010: Received data available interrupt + 0b110: Character timeout indication + 0b001: Transmitter holding register empty + 0b000: MODEM status interrupt or no pending interrupt"; + } INTR_ID[3:1] = 0x0; + field { + sw = r; + hw = rw; + desc = "FIFO enable, replicated across the width of this field."; + } FIFO_EN[7:6] = 0x0; + } IIR @ 0x8; + reg { + field { + sw = r; + hw = r; + desc = "Word length select, tied to 0x3 to indicate 8-bit word length."; + } WLS[1:0] = 0x3; + field { + sw = r; + hw = r; + desc = "Number of stop bits, tied to 0 to indicate 1 stop bit."; + } STB[2:2] = 0x0; + field { + sw = rw; + hw = r; + desc = "Parity enable."; + } PEN[3:3] = 0x0; + field { + sw = rw; + hw = r; + desc = "Even parity select."; + } EPS[4:4] = 0x1; + field { + sw = r; + hw = r; + desc = "Stick parity, tied to 0 to indicate that it is always disabled."; + } STICK_PARITY[5:5] = 0x0; + field { + sw = rw; + hw = r; + desc = "Break control bit. + When set to 1, the UART serial output is forced to spacing (logic 0) state. + This has no effect on the transmitter logic."; + } BREAK_CTRL[6:6] = 0x0; + field { + sw = rw; + hw = r; + desc = "Divisor latch access bit. + This bit must be set high to access the DLL and DLM registers. + This bit must be set low to access the RBR, THR and IER registers."; + } DLAB[7:7] = 0x0; + } LCR @ 0xC; + reg { + field { + sw = rw; + hw = r; + desc = "Data terminal ready. This field has no effect on external pins."; + } DTR[0:0] = 0x0; + field { + sw = rw; + hw = r; + desc = "Request to send. This field has no effect on external pins."; + } RTS[1:1] = 0x0; + field { + sw = rw; + hw = r; + desc = "User-designated output. This field has no effect on external pins."; + } OUT[3:2] = 0x0; + field { + sw = rw; + hw = r; + desc = "System loopback enable. + When set to 1: + 1. The serial output is set to the marking (logic 1) state. + 2. The serial input is disconnected. + 3. The transmitter shift register output is looped back to the + receiver shift register input. + 4. The MODEM control outouts (DTR, RTS, OUT1, OUT2) are internally + connected to the MODEM control inputs."; + } LOOP[4:4] = 0x0; + } MCR @ 0x10; + reg { + field { + sw = r; + hw = rw; + desc = "Data ready."; + } DR[0:0] = 0x0; + field { + sw = rw; + onread = rclr; + hw = rw; + desc = "Overrun error. Indicated on reception."; + } OE[1:1] = 0x0; + field { + sw = rw; + onread = rclr; + hw = rw; + desc = "Parity error. Indicated on reception."; + } PE[2:2] = 0x0; + field { + sw = rw; + onread = rclr; + hw = rw; + desc = "Framing error. Indicated on reception."; + } FE[3:3] = 0x0; + field { + sw = rw; + onread = rclr; + hw = rw; + desc = "Break interrupt. Indicated on reception."; + } BI[4:4] = 0x0; + field { + sw = r; + hw = rw; + desc = "Transmitter holding register empty."; + } THRE[5:5] = 0x1; + field { + sw = r; + hw = rw; + desc = "Transmitter empty."; + } TEMT[6:6] = 0x1; + field { + sw = r; + hw = rw; + desc = "Error in receiver FIFO. Equivalent to the or reduction of PE, FE and BI."; + } RCVR_FIFO_ERROR[7:7] = 0x0; + } LSR @ 0x14; + reg { + field { + sw = r; + hw = w; + desc = "Delta clear to send. Tied to 0."; + } DCTS[0:0] = 0x0; + field { + sw = r; + hw = w; + desc = "Delta data set ready. Tied to 0."; + } DDSR[1:1] = 0x0; + field { + sw = r; + hw = w; + desc = "Trailing edge ring indicator. Tied to 0."; + } TERI[2:2] = 0x0; + field { + sw = r; + hw = w; + desc = "Delta data carrier detect. Tied to 0."; + } DDCD[3:3] = 0x0; + field { + sw = r; + hw = w; + desc = "Clear to send. Tied to 0 when loopback is disabled."; + } CTS[4:4] = 0x0; + field { + sw = r; + hw = w; + desc = "Data set ready. Tied to 0 when loopback is disabled."; + } DSR[5:5] = 0x0; + field { + sw = r; + hw = w; + desc = "Ring indicator. Tied to 0 when loopback is disabled."; + } RI[6:6] = 0x0; + field { + sw = r; + hw = w; + desc = "Data carrier detect. Tied to 0 when loopback is disabled."; + } DCD[7:7] = 0x0; + } MSR @ 0x18; + reg { + field { + sw = rw; + hw = na; + } SCR[7:0] = 0x0; + } SCR @ 0x1C; + } none @ 0x0; +}; \ No newline at end of file diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_wo.rdl b/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_wo.rdl new file mode 100644 index 000000000..adc393779 --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_wo.rdl @@ -0,0 +1,50 @@ +addrmap uart16550_wo { + addrmap { + reg { + field { + sw = w; + hw = r; + swmod = true; + } THR[7:0]; + } external THR @ 0x0; + reg { + field { + sw = w; + hw = rw; + swmod = true; + desc = "FIFO enable."; + } FIFO_EN[0:0] = 0x0; + field { + sw = w; + hw = rw; + swmod = true; + desc = "Receiver FIFO reset. + Writing 1 to this field resets the receiver FIFO, the write is self-clearing."; + } RCVR_FIFO_RESET[1:1] = 0x0; + field { + sw = w; + hw = rw; + swmod = true; + desc = "Transmitter FIFO reset. + Writing 1 to this field resets the transmitter FIFO, the write is self-clearing."; + } XMIT_FIFO_RESET[2:2] = 0x0; + field { + sw = w; + hw = rw; + swmod = true; + desc = "DMA mode select. This field has no effect."; + } DMA_MODE_SEL[3:3] = 0x0; + field { + sw = w; + hw = rw; + swmod = true; + desc = "Trigger level for the RCVR FIFO interrupt. + Encoding: + 0b00: 1 byte + 0b01: 4 bytes + 0b10: 8 bytes + 0b11: 16 bytes"; + } RCVR_TRIGGER[7:6] = 0x0; + } FCR @ 0x8; + } none @ 0x0; +}; \ No newline at end of file diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/rtl/uart16550.sv b/hw/vendor/uart_16550/hw/ip/uart16550/rtl/uart16550.sv new file mode 100644 index 000000000..4591123fb --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/rtl/uart16550.sv @@ -0,0 +1,95 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +module uart16550 + import uart_reg_pkg::*; +#( + parameter logic [NumAlerts-1:0] AlertAsyncOn = {NumAlerts{1'b1}}, + // Number of cycles a differential skew is tolerated on the alert signal + parameter int unsigned AlertSkewCycles = 1, + parameter bit EnableRacl = 1'b0, + parameter bit RaclErrorRsp = EnableRacl, + parameter top_racl_pkg::racl_policy_sel_t RaclPolicySelVec[NumRegs] = '{NumRegs{0}} +) ( + input clk_i, + input rst_ni, + + // Bus Interface + input tlul_pkg::tl_h2d_t tl_i, + output tlul_pkg::tl_d2h_t tl_o, + + // Alerts + input prim_alert_pkg::alert_rx_t [NumAlerts-1:0] alert_rx_i, + output prim_alert_pkg::alert_tx_t [NumAlerts-1:0] alert_tx_o, + + // RACL interface + input top_racl_pkg::racl_policy_vec_t racl_policies_i, + output top_racl_pkg::racl_error_log_t racl_error_o, + + output logic lsio_trigger_o, + + // Generic IO + input cio_rx_i, + output logic cio_tx_o, + output logic cio_tx_en_o, + + // Interrupts + output logic intr_tx_watermark_o, + output logic intr_tx_empty_o, + output logic intr_rx_watermark_o, + output logic intr_tx_done_o, + output logic intr_rx_overflow_o, + output logic intr_rx_frame_err_o, + output logic intr_rx_break_err_o, + output logic intr_rx_timeout_o, + output logic intr_rx_parity_err_o +); + + // TileLink signals. + // Translated requests to the OpenTitan UART core + tlul_pkg::tl_h2d_t tl_translated_h2d; + tlul_pkg::tl_d2h_t tl_translated_d2h; + + // Register translation block + uart16550_translate u_reg_translate( + .clk_i (clk_i), + .rst_ni (rst_ni), + .host_tl_i (tl_i), + .host_tl_o (tl_o), + .uart_tl_o (tl_translated_h2d), + .uart_tl_i (tl_translated_d2h) + ); + + // OpenTitan UART core instance + uart #( + .AlertAsyncOn ( AlertAsyncOn ), + .AlertSkewCycles ( AlertSkewCycles ), + .EnableRacl ( EnableRacl ), + .RaclErrorRsp ( RaclErrorRsp ), + .RaclPolicySelVec ( RaclPolicySelVec ) + ) u_uart_core( + .clk_i (clk_i), + .rst_ni (rst_ni), + .tl_i (tl_translated_h2d), + .tl_o (tl_translated_d2h), + .alert_rx_i (alert_rx_i), + .alert_tx_o (alert_tx_o), + .racl_policies_i (racl_policies_i), + .racl_error_o (racl_error_o), + .lsio_trigger_o (lsio_trigger_o), + .cio_rx_i (cio_rx_i), + .cio_tx_o (cio_tx_o), + .cio_tx_en_o (cio_tx_en_o), + .intr_tx_watermark_o (intr_tx_watermark_o), + .intr_tx_empty_o (intr_tx_empty_o), + .intr_rx_watermark_o (intr_rx_watermark_o), + .intr_tx_done_o (intr_tx_done_o), + .intr_rx_overflow_o (intr_rx_overflow_o), + .intr_rx_frame_err_o (intr_rx_frame_err_o), + .intr_rx_break_err_o (intr_rx_break_err_o), + .intr_rx_timeout_o (intr_rx_timeout_o), + .intr_rx_parity_err_o (intr_rx_parity_err_o) + ); + +endmodule diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/rtl/uart16550_translate.sv b/hw/vendor/uart_16550/hw/ip/uart16550/rtl/uart16550_translate.sv new file mode 100644 index 000000000..9deabab9d --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/rtl/uart16550_translate.sv @@ -0,0 +1,951 @@ +// Copyright lowRISC and contributors (COSMIC project). +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +module uart16550_translate( + // Clock and reset + input logic clk_i, + input logic rst_ni, + + // TL-UL interface to the host + input tlul_pkg::tl_h2d_t host_tl_i, + output tlul_pkg::tl_d2h_t host_tl_o, + + // TL-UL interface to the UART core + output tlul_pkg::tl_h2d_t uart_tl_o, + input tlul_pkg::tl_d2h_t uart_tl_i +); + + // Unused signals + logic unused_sig; + assign unused_sig = |{host_tl_i, uart_tl_i}; + + // TL-UL host D2H without integrity + tlul_pkg::tl_d2h_t host_tl_d2h_pre; + + // TL-UL UART H2D without integrity + tlul_pkg::tl_h2d_t uart_tl_h2d_pre; + + // TODO: incoming host req intg verify + // TODO: inocoming uart resp intg verify + // TODO: error resp from UART should prevent any 16550/OT state modification? + // TODO: PutPartialData or size != 2 handling + // TODO: unused fields in TL struct + // TODO: RACL + // TODO: NCO solving from div + + /////////////////// + // Control logic // + /////////////////// + + // TODO state enc + localparam int StateWidth = 10; + typedef enum logic [StateWidth-1:0] { + IdleSt = 10'b1110001010, + FifoReqSt = 10'b1001000001, + FifoReqWaitSt = 10'b0010101101, + FifoRespSt = 10'b1101101100, + IERReqSt = 10'b0111110000, + IERReqWaitSt = 10'b1000110110, + IERRespSt = 10'b1011111011, + IIRReqSt = 10'b0101011111, + IIRReqWaitSt = 10'b0011000110, + IIRRespSt = 10'b0000011000, + FCRReqSt = 10'h0, + FCRReqWaitSt = 10'h1, + FCRRespSt = 10'h2, + LCRReqSt = 10'h3, + LCRReqWaitSt = 10'h4, + LCRRespSt = 10'h5, + MCRReqSt = 10'h6, + MCRReqWaitSt = 10'h7, + MCRRespSt = 10'h8, + LSRReqSt = 10'h9, + LSRReqWaitSt = 10'hA, + LSRRespSt = 10'hB, + MSRRespSt = 10'hC, + SCRRespSt = 10'hD, + DLReqSt = 10'hE, + DLReqWaitSt = 10'hF, + DLRespSt = 10'h10, + ErrorRespSt = 10'b0100100011 + } state_e; + + state_e state_d, state_q; + + // Latched request parameters + tlul_pkg::tl_a_op_e req_opcode_d; + tlul_pkg::tl_a_op_e req_opcode_q; + logic [top_pkg::TL_DW-1:0] req_data_d; + logic [top_pkg::TL_DW-1:0] req_data_q; + logic [top_pkg::TL_SZW-1:0] req_size_d; + logic [top_pkg::TL_SZW-1:0] req_size_q; + logic [top_pkg::TL_DBW-1:0] req_mask_d; + logic [top_pkg::TL_DBW-1:0] req_mask_q; + logic [top_pkg::TL_AIW-1:0] req_source_d; + logic [top_pkg::TL_AIW-1:0] req_source_q; + + // Latched response parameters + tlul_pkg::tl_d_op_e resp_opcode_d; + tlul_pkg::tl_d_op_e resp_opcode_q; + logic [top_pkg::TL_DW-1:0] resp_data_d; + logic [top_pkg::TL_DW-1:0] resp_data_q; + logic resp_error_d; + logic resp_error_q; + + // Additional request control registers + logic [1:0] req_step_d; + logic [1:0] req_step_q; + + // 16550 state registers + logic edssi_d; + logic edssi_q; + logic fifo_en_d; + logic fifo_en_q; + logic dma_mode_d; + logic dma_mode_q; + logic pen_d; + logic pen_q; + logic eps_d; + logic eps_q; + logic break_d; + logic break_q; + logic dlab_d; + logic dlab_q; + logic loop_d; + logic loop_q; + logic dtr_d; + logic dtr_q; + logic rts_d; + logic rts_q; + logic out1_d; + logic out1_q; + logic out2_d; + logic out2_q; + logic [7:0] scr_d; + logic [7:0] scr_q; + logic [7:0] dll_d; + logic [7:0] dll_q; + logic [7:0] dlm_d; + logic [7:0] dlm_q; + + // OT state registers + logic txrx_en_d; + logic txrx_en_q; + + always_comb begin : p_fsm + // Default + state_d = state_q; + host_tl_d2h_pre = tlul_pkg::TL_D2H_DEFAULT; + host_tl_d2h_pre.a_ready = 1'b0; // Not ready for a new request by default + host_tl_d2h_pre.d_size = req_size_q; // Return size of the request + host_tl_d2h_pre.d_source = req_source_q; // Return source of the request + uart_tl_h2d_pre = tlul_pkg::TL_H2D_DEFAULT; + uart_tl_h2d_pre.a_size = 2; + uart_tl_h2d_pre.a_mask = '1; + uart_tl_h2d_pre.a_user.instr_type = prim_mubi_pkg::MuBi4False; + + req_opcode_d = req_opcode_q; + req_data_d = req_data_q; + req_size_d = req_size_q; + req_mask_d = req_mask_q; + req_source_d = req_source_q; + resp_opcode_d = resp_opcode_q; + resp_data_d = resp_data_q; + resp_error_d = resp_error_q; + + req_step_d = req_step_q; + + edssi_d = edssi_q; + fifo_en_d = fifo_en_q; + dma_mode_d = dma_mode_q; + pen_d = pen_q; + eps_d = eps_q; + break_d = break_q; + dlab_d = dlab_q; + loop_d = loop_q; + dtr_d = dtr_q; + rts_d = rts_q; + out1_d = out1_q; + out2_d = out2_q; + scr_d = scr_q; + txrx_en_d = txrx_en_q; + dll_d = dll_q; + dlm_d = dlm_q; + + unique case (state_q) + // Wait for new host request + IdleSt: begin + // Ready to accept a new request from the host + host_tl_d2h_pre.a_ready = 1'b1; + + // Clear latched response data + resp_data_d = '0; + + if (host_tl_i.a_valid) begin + // Request param latching + req_opcode_d = host_tl_i.a_opcode; + req_data_d = host_tl_i.a_data; + req_size_d = host_tl_i.a_size; + req_mask_d = host_tl_i.a_mask; + req_source_d = host_tl_i.a_source; + + req_step_d = 2'h0; + + // Decode request + unique case (host_tl_i.a_address[4:0]) + 'h0: begin + if (!dlab_q) begin + state_d = FifoReqSt; + end else begin + // Override step to 0, this identifies access to DLL + req_step_d = 2'h0; + + if (host_tl_i.a_opcode == tlul_pkg::Get) begin + // DLL/DLM reads do not require a request to the UART core + state_d = DLRespSt; + end else begin + state_d = DLReqSt; + end + end + end + 'h4: begin + if (!dlab_q) begin + state_d = IERReqSt; + end else begin + // Override step to 1, this identifies access to DLM + req_step_d = 2'h1; + + if (host_tl_i.a_opcode == tlul_pkg::Get) begin + // DLL/DLM reads do not require a request to the UART core + state_d = DLRespSt; + end else begin + state_d = DLReqSt; + end + end + end + 'h8: begin + if (host_tl_i.a_opcode == tlul_pkg::Get) begin + state_d = IIRReqSt; + end else begin + state_d = FCRReqSt; + end + end + 'hC: begin + if (host_tl_i.a_opcode == tlul_pkg::Get) begin + // LCR reads do not require a request to the UART core + state_d = LCRRespSt; + end else begin + state_d = LCRReqSt; + end + end + 'h10: begin + if (host_tl_i.a_opcode == tlul_pkg::Get) begin + // MCR reads do not require a request to the UART core + state_d = MCRRespSt; + end else begin + state_d = MCRReqSt; + end + end + 'h14: begin + if (host_tl_i.a_opcode == tlul_pkg::Get) begin + state_d = LSRReqSt; + end else begin + // LSR writes are ignored + state_d = LSRRespSt; + end + end + 'h18: begin + // MSR accesses do not require a request to the UART core + state_d = MSRRespSt; + end + 'h1C: begin + // SCR accesses do not require a request to the UART core + state_d = SCRRespSt; + end + default: state_d = ErrorRespSt; // Unsupported address + endcase + end + end + // Passthrough request to R/W FIFO + FifoReqSt: begin + uart_tl_h2d_pre.a_valid = 1; + if (req_opcode_q == tlul_pkg::Get) begin + uart_tl_h2d_pre.a_opcode = tlul_pkg::Get; + uart_tl_h2d_pre.a_address = 'h18; // RDATA reg + end else begin + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + uart_tl_h2d_pre.a_address = 'h1c; // WDATA reg + end + uart_tl_h2d_pre.a_data = req_data_q; + + if (uart_tl_i.a_ready) begin + state_d = FifoReqWaitSt; + end + end + // Wait for FIFO response from UART + FifoReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + resp_data_d = uart_tl_i.d_data; + resp_error_d = uart_tl_i.d_error; + + state_d = FifoRespSt; + end + end + // Send FIFO response to host + FifoRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + host_tl_d2h_pre.d_opcode = resp_opcode_q; + host_tl_d2h_pre.d_data = resp_data_q; + host_tl_d2h_pre.d_error = resp_error_q; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // IER access: send request to UART + IERReqSt: begin + // Write to INTR_ENABLE + // No need for RMW as no other interrupt can be enabled + uart_tl_h2d_pre.a_valid = 1; + if (req_opcode_q == tlul_pkg::Get) begin + uart_tl_h2d_pre.a_opcode = tlul_pkg::Get; + end else begin + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + end + uart_tl_h2d_pre.a_address = 'h4; // INTR_ENABLE reg + uart_tl_h2d_pre.a_data = '0; + // 16550 to OT mapping + uart_tl_h2d_pre.a_data[1] = req_data_q[0]; // rx_watermark = ERBFI + uart_tl_h2d_pre.a_data[8] = req_data_q[1]; // tx_empty = ETBEI + uart_tl_h2d_pre.a_data[3] = req_data_q[2]; // rx_overflow = ELSI + uart_tl_h2d_pre.a_data[4] = req_data_q[2]; // rx_frame_err = ELSI + uart_tl_h2d_pre.a_data[5] = req_data_q[2]; // rx_break_err = ELSI + uart_tl_h2d_pre.a_data[7] = req_data_q[2]; // rx_parity_err = ELSI + + // EDSSI write logic + // This register has no effect but the value is kept + if (req_opcode_q != tlul_pkg::Get) begin + edssi_d = req_data_q[3]; + end + + if (uart_tl_i.a_ready) begin + state_d = IERReqWaitSt; + end + end + // IER access: wait for response from UART + IERReqWaitSt: begin // TODO duplicate states + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + resp_data_d = uart_tl_i.d_data; + resp_error_d = uart_tl_i.d_error; + + state_d = IERRespSt; + end + end + // IER access: send response to host + IERRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + host_tl_d2h_pre.d_opcode = resp_opcode_q; + if (req_opcode_q == tlul_pkg::Get) begin + // OT to 16550 mapping + host_tl_d2h_pre.d_data = '0; + host_tl_d2h_pre.d_data[0] = resp_data_q[1]; // ERBFI = rx_watermark + host_tl_d2h_pre.d_data[1] = resp_data_q[8]; // ETBEI = tx_empty + host_tl_d2h_pre.d_data[2] = (resp_data_q[3] & // ELSI = rx_overflow & + resp_data_q[4] & // rx_frame_err & + resp_data_q[5] & // rx_break_err & + resp_data_q[7]); // rx_parity_err + host_tl_d2h_pre.d_data[3] = edssi_q; // EDSSI read back + end else begin + host_tl_d2h_pre.d_data = '1; + end + host_tl_d2h_pre.d_error = resp_error_q; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // IIR read: send request to UART + IIRReqSt: begin + // Read INTR_STATE / INTR_ENABLE + uart_tl_h2d_pre.a_valid = 1; + uart_tl_h2d_pre.a_opcode = tlul_pkg::Get; + if (req_step_q == 0) begin + uart_tl_h2d_pre.a_address = 'h0; // INTR_STATE reg + end else begin + uart_tl_h2d_pre.a_address = 'h4; // INTR_ENABLE reg + end + uart_tl_h2d_pre.a_data = '0; + + if (uart_tl_i.a_ready) begin + state_d = IIRReqWaitSt; + end + end + // IIR read: wait for response from UART + IIRReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + if (req_step_q == 0) begin + resp_data_d = uart_tl_i.d_data; + resp_error_d = uart_tl_i.d_error; + end else begin + resp_data_d = resp_data_q & uart_tl_i.d_data; + resp_error_d = resp_error_q | uart_tl_i.d_error; + end + + if (req_step_q == 0) begin + // Next step, read another register + req_step_d = 1; + state_d = IIRReqSt; + end else begin + // UART reads done + state_d = IIRRespSt; + end + end + end + // IIR read: send response to host + IIRRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + host_tl_d2h_pre.d_opcode = resp_opcode_q; + // OT to 16550 mapping + host_tl_d2h_pre.d_data = '0; + // Interrupt pending, active low + host_tl_d2h_pre.d_data[0] = ~(resp_data_q[1] | + resp_data_q[3] | + resp_data_q[4] | + resp_data_q[5] | + resp_data_q[7] | + resp_data_q[8]); + if (resp_data_q[3] || resp_data_q[4] || resp_data_q[5] || resp_data_q[7]) begin + // Receiver line status has highest priority + host_tl_d2h_pre.d_data[2:1] = 2'b11; + end else if (resp_data_q[1]) begin + // Received data available has highest priority + host_tl_d2h_pre.d_data[2:1] = 2'b10; + end else if (resp_data_q[8]) begin + // Transmitter holding register empty has highest priority + host_tl_d2h_pre.d_data[2:1] = 2'b01; + end else begin + // MODEM status has highest priority or no pending interrupt + host_tl_d2h_pre.d_data[2:1] = 2'b00; + end + // Bit 3 = FIFO enable AND timeout error + host_tl_d2h_pre.d_data[3] = fifo_en_q & resp_data_q[3]; + // Bit 6,7 = FIFO enable + host_tl_d2h_pre.d_data[6] = fifo_en_q; + host_tl_d2h_pre.d_data[7] = fifo_en_q; + host_tl_d2h_pre.d_error = resp_error_q; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // FCR write: send request to UART + FCRReqSt: begin + // Write FIFO_CTRL + uart_tl_h2d_pre.a_valid = 1; + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + uart_tl_h2d_pre.a_address = 'h20; // FIFO_CTRL reg + // 16550 to OT mapping + uart_tl_h2d_pre.a_data = '0; + uart_tl_h2d_pre.a_data[0] = req_data_q[1]; // RXRST = RCVR FIFO reset + uart_tl_h2d_pre.a_data[1] = req_data_q[2]; // TXRST = XMIT FIFO reset + // RXILVL mapped from RCVR trigger + unique case (req_data_q[7:6]) + 2'b00: uart_tl_h2d_pre.a_data[4:2] = 3'h0; // 1 char == 1 byte + 2'b01: uart_tl_h2d_pre.a_data[4:2] = 3'h2; // 4 char == 4 bytes + 2'b10: uart_tl_h2d_pre.a_data[4:2] = 3'h3; // 8 char == 8 bytes + 2'b11: uart_tl_h2d_pre.a_data[4:2] = 3'h4; // 16 char ~= 14 bytes + default: ; + endcase + + // FIFO enable write + fifo_en_d = req_data_q[0]; + + // DMA mode write + dma_mode_d = req_data_q[3]; + + if (uart_tl_i.a_ready) begin + state_d = FCRReqWaitSt; + end + end + // FCR write: wait for response from UART + FCRReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + resp_data_d = uart_tl_i.d_data; + resp_error_d = uart_tl_i.d_error; + + state_d = FCRRespSt; + end + end + // FCR write: send response to host + FCRRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + host_tl_d2h_pre.d_opcode = resp_opcode_q; + host_tl_d2h_pre.d_data = '1; + host_tl_d2h_pre.d_error = resp_error_q; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // LCR write: send request to UART + LCRReqSt: begin + // Write CTRL / OVRD + uart_tl_h2d_pre.a_valid = 1; + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + if (req_step_q == 0) begin + uart_tl_h2d_pre.a_address = 'h10; // CTRL reg + end else begin + uart_tl_h2d_pre.a_address = 'h28; // OVRD reg + end + // 16550 to OT mapping + if (req_step_q == 0) begin + pen_d = req_data_q[3]; + eps_d = req_data_q[4]; + uart_tl_h2d_pre.a_data = '0; + uart_tl_h2d_pre.a_data[0] = txrx_en_q; // TX = txrx_en + uart_tl_h2d_pre.a_data[1] = txrx_en_q; // RX = txrx_en + uart_tl_h2d_pre.a_data[4] = loop_q; // SLPBK = loop + uart_tl_h2d_pre.a_data[6] = pen_d; // PARITY_EN = PEN + uart_tl_h2d_pre.a_data[7] = ~eps_d; // PARITY_ODD = !EPS + uart_tl_h2d_pre.a_data[31:16] = 16'd20972; // NCO default value + end else begin + break_d = req_data_q[6]; + uart_tl_h2d_pre.a_data = '0; + uart_tl_h2d_pre.a_data[0] = break_d; // TXEN = break + uart_tl_h2d_pre.a_data[1] = 1'b0; // TXVAL = 0 + end + + // DLAB write + dlab_d = req_data_q[7]; + + if (uart_tl_i.a_ready) begin + state_d = LCRReqWaitSt; + end + end + // LCR write: wait for response from UART + LCRReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + // No need to latch response data + if (req_step_q == 0) begin + resp_error_d = uart_tl_i.d_error; + end else begin + resp_error_d = resp_error_q | uart_tl_i.d_error; + end + + if (req_step_q == 0) begin + // Next step, write another register + req_step_d = 1; + state_d = LCRReqSt; + end else begin + // UART writes done + state_d = LCRRespSt; + end + end + end + // LCR access: send response to host + LCRRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAckData; + end else begin + host_tl_d2h_pre.d_opcode = resp_opcode_q; + end + if (req_opcode_q == tlul_pkg::Get) begin + // OT to 16550 mapping + host_tl_d2h_pre.d_data = '0; + host_tl_d2h_pre.d_data[1:0] = 2'b11; // WLS = 8 bits (non-adjustable) + host_tl_d2h_pre.d_data[2] = 1'b0; // STB = 1 stop bit (non-adjustable) + host_tl_d2h_pre.d_data[3] = pen_q; // PEN + host_tl_d2h_pre.d_data[4] = eps_q; // EPS + host_tl_d2h_pre.d_data[5] = 1'b0; // Stick parity not supported + host_tl_d2h_pre.d_data[6] = break_q; // Set break + host_tl_d2h_pre.d_data[7] = dlab_q; // DLAB + end else begin + host_tl_d2h_pre.d_data = '1; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_error = 1'b0; + end else begin + host_tl_d2h_pre.d_error = resp_error_q; + end + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // MCR write: send request to UART + MCRReqSt: begin + // Write CTRL + uart_tl_h2d_pre.a_valid = 1; + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + uart_tl_h2d_pre.a_address = 'h10; // CTRL reg + // 16550 to OT mapping + loop_d = req_data_q[4]; // loop + uart_tl_h2d_pre.a_data = '0; + uart_tl_h2d_pre.a_data[0] = txrx_en_q; // TX = txrx_en + uart_tl_h2d_pre.a_data[1] = txrx_en_q; // RX = txrx_en + uart_tl_h2d_pre.a_data[4] = loop_d; // SLPBK = loop + uart_tl_h2d_pre.a_data[6] = pen_q; // PARITY_EN = PEN + uart_tl_h2d_pre.a_data[7] = ~eps_q; // PARITY_ODD = !EPS + uart_tl_h2d_pre.a_data[31:16] = 16'd20972; // NCO default value + + // MODEM control reg writes + dtr_d = req_data_q[0]; + rts_d = req_data_q[1]; + out1_d = req_data_q[2]; + out2_d = req_data_q[3]; + + if (uart_tl_i.a_ready) begin + state_d = MCRReqWaitSt; + end + end + // MCR write: wait for response from UART + MCRReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + resp_data_d = uart_tl_i.d_data; + resp_error_d = uart_tl_i.d_error; + + state_d = MCRRespSt; + end + end + // MCR access: send response to host + MCRRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAckData; + end else begin + host_tl_d2h_pre.d_opcode = resp_opcode_q; + end + if (req_opcode_q == tlul_pkg::Get) begin + // OT to 16550 mapping + host_tl_d2h_pre.d_data = '0; + host_tl_d2h_pre.d_data[0] = dtr_q; // DTR + host_tl_d2h_pre.d_data[1] = rts_q; // RTS + host_tl_d2h_pre.d_data[2] = out1_q; // OUT1 + host_tl_d2h_pre.d_data[3] = out2_q; // OUT2 + host_tl_d2h_pre.d_data[4] = loop_q; // loop + end else begin + host_tl_d2h_pre.d_data = '1; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_error = 1'b0; + end else begin + host_tl_d2h_pre.d_error = resp_error_q; + end + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // LSR read: send request to UART + LSRReqSt: begin + // Read STATUS / INTR_STATE / write INTR_STATE + uart_tl_h2d_pre.a_valid = 1; + if (req_step_q != 2) begin + uart_tl_h2d_pre.a_opcode = tlul_pkg::Get; + end else begin + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + end + if (req_step_q == 0) begin + uart_tl_h2d_pre.a_address = 'h14; // STATUS reg + end else begin + uart_tl_h2d_pre.a_address = 'h0; // INTR_STATE reg + end + // Clear interrupts that were raised if this is a write to INTR_STATE + // Reuse resp_data_q[4:1] set in LSRReqWaitSt when req_step_q == 1 + uart_tl_h2d_pre.a_data = '0; + uart_tl_h2d_pre.a_data[3] = resp_data_q[1]; // Clear rx_overflow if it was set + uart_tl_h2d_pre.a_data[4] = resp_data_q[3]; // Clear rx_frame_err if it was set + uart_tl_h2d_pre.a_data[5] = resp_data_q[4]; // Clear rx_break_err if it was set + uart_tl_h2d_pre.a_data[7] = resp_data_q[2]; // Clear rx_parity_err if it was set + + if (uart_tl_i.a_ready) begin + state_d = LSRReqWaitSt; + end + end + // LSR read: wait for response from UART + LSRReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + // Latch specific bits + if (req_step_q == 0) begin + resp_data_d[0] = ~uart_tl_i.d_data[5]; // DR = !STATUS.RXEMPTY + resp_data_d[5] = uart_tl_i.d_data[2]; // THRE = STATUS.TXEMPTY + resp_data_d[6] = uart_tl_i.d_data[3]; // TEMT = STATUS.TXIDLE + resp_error_d = uart_tl_i.d_error; + end else if (req_step_q == 1) begin + resp_data_d[1] = uart_tl_i.d_data[3]; // OE = INTR_STATE.rx_overflow + resp_data_d[2] = uart_tl_i.d_data[7]; // PE = INTR_STATE.rx_parity_err + resp_data_d[3] = uart_tl_i.d_data[4]; // FE = INTR_STATE.rx_frame_err + resp_data_d[4] = uart_tl_i.d_data[5]; // BI = INTR_STATE.rx_break_err + resp_data_d[7] = |resp_data_d[4:2]; // Error in RCVR FIFO = INTR_STATE.(rx_parity_err | rx_frame_err | rx_break_err) + resp_error_d = resp_error_q | uart_tl_i.d_error; + end else begin + resp_error_d = resp_error_q | uart_tl_i.d_error; + end + + if (req_step_q != 2) begin + // Next step, read/write another register + req_step_d = req_step_q + 1; + state_d = LSRReqSt; + end else begin + // UART accesses done + state_d = LSRRespSt; + end + end + end + // LSR access: send response to host + LSRRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAckData; + end else begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAck; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_data = resp_data_d; + end else begin + host_tl_d2h_pre.d_data = '1; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_error = resp_error_q; + end else begin + host_tl_d2h_pre.d_error = 1'b0; + end + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // MSR access: send response to host + MSRRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAckData; + end else begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAck; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_data = '0; + // OT to 16550 mapping + host_tl_d2h_pre.d_data[0] = 1'b0; // DCTS = 0 + host_tl_d2h_pre.d_data[1] = 1'b0; // DDSR = 0 + host_tl_d2h_pre.d_data[2] = 1'b0; // TERI = 0 + host_tl_d2h_pre.d_data[3] = 1'b0; // DDCD = 0 + host_tl_d2h_pre.d_data[4] = loop_q & rts_q; // CTS = if loop RTS else 0 + host_tl_d2h_pre.d_data[5] = loop_q & dtr_q; // DSR = if loop DTR else 0 + host_tl_d2h_pre.d_data[6] = loop_q & out1_q; // RI = if loop OUT1 else 0 + host_tl_d2h_pre.d_data[7] = loop_q & out2_q; // DCD = if loop OUT2 else 0 + end else begin + host_tl_d2h_pre.d_data = '1; + end + host_tl_d2h_pre.d_error = 1'b0; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // MSR access: send response to host + SCRRespSt: begin + // SCR write logic + if (req_opcode_q != tlul_pkg::Get) begin + scr_d = req_data_q[7:0]; + end + + // Send host response + host_tl_d2h_pre.d_valid = 1'b1; + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAckData; + end else begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAck; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_data = '0; + host_tl_d2h_pre.d_data[7:0] = scr_q; + end else begin + host_tl_d2h_pre.d_data = '1; + end + host_tl_d2h_pre.d_error = 1'b0; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // DL write: send request to UART + DLReqSt: begin + // Enable Tx and Rx + txrx_en_d = 1'b1; + + // Write CTRL + uart_tl_h2d_pre.a_valid = 1; + uart_tl_h2d_pre.a_opcode = tlul_pkg::PutFullData; + uart_tl_h2d_pre.a_address = 'h10; // CTRL reg + // 16550 to OT mapping + uart_tl_h2d_pre.a_data = '0; + uart_tl_h2d_pre.a_data[0] = txrx_en_d; // TX = new txrx_en + uart_tl_h2d_pre.a_data[1] = txrx_en_d; // RX = new txrx_en + uart_tl_h2d_pre.a_data[4] = loop_q; // SLPBK = loop + uart_tl_h2d_pre.a_data[6] = pen_q; // PARITY_EN = PEN + uart_tl_h2d_pre.a_data[7] = ~eps_q; // PARITY_ODD = !EPS + uart_tl_h2d_pre.a_data[31:16] = 16'd20972; // NCO default value + + // DLL and DLM write + if (req_step_q == 0) begin + dll_d = req_data_q[7:0]; + end else begin + dlm_d = req_data_q[7:0]; + end + + if (uart_tl_i.a_ready) begin + state_d = DLReqWaitSt; + end + end + // DL write: wait for response from UART + DLReqWaitSt: begin + if (uart_tl_i.d_valid) begin + resp_opcode_d = uart_tl_i.d_opcode; + resp_data_d = uart_tl_i.d_data; + resp_error_d = uart_tl_i.d_error; + + state_d = DLRespSt; + end + end + // DL access: send response to host + DLRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAckData; + end else begin + host_tl_d2h_pre.d_opcode = resp_opcode_q; + end + if (req_opcode_q == tlul_pkg::Get) begin + // 16550 mapping + host_tl_d2h_pre.d_data = '0; + if (req_step_q == 0) begin + host_tl_d2h_pre.d_data[7:0] = dll_q; + end else begin + host_tl_d2h_pre.d_data[7:0] = dlm_q; + end + end else begin + host_tl_d2h_pre.d_data = '1; + end + if (req_opcode_q == tlul_pkg::Get) begin + host_tl_d2h_pre.d_error = 1'b0; + end else begin + host_tl_d2h_pre.d_error = resp_error_q; + end + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + // Send error response to host + ErrorRespSt: begin + host_tl_d2h_pre.d_valid = 1'b1; + host_tl_d2h_pre.d_opcode = tlul_pkg::AccessAck; + host_tl_d2h_pre.d_data = '1; + host_tl_d2h_pre.d_error = 1'b1; + + if (host_tl_i.d_ready) begin + state_d = IdleSt; + end + end + default: begin + state_d = IdleSt; + end + endcase + end + + //////////////////////////////// + // TL-UL integrity generation // + //////////////////////////////// + + // Host D2H integrity generation + tlul_rsp_intg_gen u_host_d2h_intg_gen ( + .tl_i (host_tl_d2h_pre), + .tl_o (host_tl_o) + ); + + // UART H2D integrity generation + tlul_cmd_intg_gen u_uart_h2d_intg_gen ( + .tl_i (uart_tl_h2d_pre), + .tl_o (uart_tl_o) + ); + + ////////// + // Regs // + ////////// + + // State register + prim_sparse_fsm_flop #( + .StateEnumT(state_e), + .Width($bits(state_e)), + .ResetValue(IdleSt), + .EnableAlertTriggerSVA(0) + ) u_state_regs ( + .clk_i ( clk_i ), + .rst_ni ( rst_ni ), + .state_i ( state_d ), + .state_o ( state_q ) + ); + + always_ff @(posedge clk_i) begin + req_opcode_q <= req_opcode_d; + req_data_q <= req_data_d; + req_mask_q <= req_mask_d; + resp_opcode_q <= resp_opcode_d; + resp_data_q <= resp_data_d; + resp_error_q <= resp_error_d; + req_step_q <= req_step_d; + end + + always_ff @(posedge clk_i or negedge rst_ni) begin + if (!rst_ni) begin + edssi_q <= 1'b0; + fifo_en_q <= 1'b0; + dma_mode_q <= 1'b0; + pen_q <= 1'b0; + eps_q <= 1'b1; // Even parity on by default + break_q <= 1'b0; + dlab_q <= 1'b0; + loop_q <= 1'b0; + dtr_q <= 1'b0; + rts_q <= 1'b0; + out1_q <= 1'b0; + out2_q <= 1'b0; + scr_q <= '0; + txrx_en_q <= 1'b0; + dll_q <= '0; + dlm_q <= '0; + req_size_q <= '0; + req_source_q <= '0; + end else begin + edssi_q <= edssi_d; + fifo_en_q <= fifo_en_d; + dma_mode_q <= dma_mode_d; + pen_q <= pen_d; + eps_q <= eps_d; + break_q <= break_d; + dlab_q <= dlab_d; + loop_q <= loop_d; + dtr_q <= dtr_d; + rts_q <= rts_d; + out1_q <= out1_d; + out2_q <= out2_d; + scr_q <= scr_d; + txrx_en_q <= txrx_en_d; + dll_q <= dll_d; + dlm_q <= dlm_d; + req_size_q <= req_size_d; + req_source_q <= req_source_d; + end + end + +endmodule diff --git a/hw/vendor/uart_16550/hw/ip/uart16550/uart16550.core b/hw/vendor/uart_16550/hw/ip/uart16550/uart16550.core new file mode 100644 index 000000000..b785c8016 --- /dev/null +++ b/hw/vendor/uart_16550/hw/ip/uart16550/uart16550.core @@ -0,0 +1,40 @@ +CAPI=2: +# Copyright lowRISC and contributors (COSMIC project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +name: "lowrisc:ip:uart16550:0.1" +description: "UART IP wrapper with 16550 registrer map" +filesets: + files_rtl: + depend: + - lowrisc:virtual_constants:top_pkg + - lowrisc:virtual_constants:top_racl_pkg + - lowrisc:prim:sparse_fsm + - lowrisc:tlul:trans_intg + - lowrisc:ip:uart + files: + - rtl/uart16550_translate.sv + - rtl/uart16550.sv + file_type: systemVerilogSource + +parameters: + SYNTHESIS: + datatype: bool + paramtype: vlogdefine + +targets: + default: &default_target + filesets: + - files_rtl + toplevel: uart16550 + + lint: + <<: *default_target + default_tool: verilator + parameters: + - SYNTHESIS=true + tools: + verilator: + mode: lint-only + verilator_options: + - "-Wall" diff --git a/rdl/mocha.rdl b/rdl/mocha.rdl index 46f439601..197b6adb5 100644 --- a/rdl/mocha.rdl +++ b/rdl/mocha.rdl @@ -14,7 +14,7 @@ `include "ip/rv_timer.rdl" `include "ip/spi_device.rdl" `include "ip/spi_host.rdl" -`include "ip/uart.rdl" +`include "../hw/vendor/uart_16550/hw/ip/uart16550/rdl/uart16550_main.rdl" `include "ip/udp.rdl" addrmap reserved { external mem {mementries = 0x10000; memwidth=8;}dummy_space;}; @@ -48,7 +48,7 @@ addrmap top_mocha { entropy_src ENTROPY_SRC[1] @ 0x4006_0000 += 0x10000; - uart UART[1] @ 0x4100_0000 += 0x10000; + uart16550_main UART[1] @ 0x4100_0000 += 0x10000; i2c I2C[1] @ 0x4200_0000 += 0x10000; diff --git a/sw/device/devicetree/mocha.S b/sw/device/devicetree/mocha.S index 34374687f..722401e1b 100644 --- a/sw/device/devicetree/mocha.S +++ b/sw/device/devicetree/mocha.S @@ -896,36 +896,19 @@ gpio_end: .byte 0x00 .byte 0x00 .byte 0x00 - .byte 0x1a + .byte 0x09 .byte 0x00 .byte 0x00 .byte 0x00 .byte 0x1b - .byte 0x6c - .byte 0x6f - .byte 0x77 - .byte 0x72 - .byte 0x69 - .byte 0x73 - .byte 0x63 - .byte 0x2c - .byte 0x6f - .byte 0x70 - .byte 0x65 .byte 0x6e - .byte 0x74 - .byte 0x69 - .byte 0x74 - .byte 0x61 - .byte 0x6e - .byte 0x2d - .byte 0x75 + .byte 0x73 + .byte 0x31 + .byte 0x36 + .byte 0x35 + .byte 0x35 + .byte 0x30 .byte 0x61 - .byte 0x72 - .byte 0x74 - .byte 0x2d - .byte 0x76 - .byte 0x32 .byte 0x0 .balign 4, 0 /* FDT_PROP */ @@ -956,7 +939,25 @@ gpio_end: .byte 0x00 .byte 0x00 .byte 0x00 - .byte 0x30 + .byte 0x1c + .balign 4, 0 + /* FDT_PROP */ + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x03 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x04 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0xc9 + .byte 0x02 + .byte 0xfa + .byte 0xf0 + .byte 0x80 .balign 4, 0 /* FDT_PROP */ .byte 0x00 @@ -1222,7 +1223,7 @@ gpio_end: .byte 0x00 .byte 0x00 .byte 0x00 - .byte 0xc9 + .byte 0xd9 .byte 0x00 .byte 0x00 .byte 0x01 @@ -1240,7 +1241,7 @@ gpio_end: .byte 0x00 .byte 0x00 .byte 0x00 - .byte 0xd7 + .byte 0xe7 .byte 0x00 .byte 0x00 .byte 0x01 @@ -1258,7 +1259,7 @@ gpio_end: .byte 0x00 .byte 0x00 .byte 0x00 - .byte 0xe5 + .byte 0xf5 .byte 0x00 .byte 0x00 .byte 0x00 @@ -1354,7 +1355,7 @@ gpio_end: .byte 0x00 .byte 0x00 .byte 0x00 - .byte 0xec + .byte 0xfc .byte 0x02 .byte 0xfa .byte 0xf0 @@ -1555,8 +1556,8 @@ plic: .byte 0x04 .byte 0x00 .byte 0x00 - .byte 0x00 - .byte 0xfe + .byte 0x01 + .byte 0x0e .byte 0x00 .byte 0x00 .byte 0x00 @@ -1782,6 +1783,7 @@ _dt_strings_start: .asciz "interrupts-extended" .asciz "gpio-controller" .asciz "ngpios" + .asciz "clock-frequency" .asciz "tx-fifo-depth" .asciz "rx-fifo-depth" .asciz "num-cs" diff --git a/sw/device/devicetree/mocha.dts b/sw/device/devicetree/mocha.dts index ba680775b..b7151e1d7 100644 --- a/sw/device/devicetree/mocha.dts +++ b/sw/device/devicetree/mocha.dts @@ -56,8 +56,9 @@ }; serial@41000000 { - compatible = "lowrisc,opentitan-uart-v2"; - reg = <0x0 0x41000000 0x0 0x30>; + compatible = "ns16550a"; + reg = <0x0 0x41000000 0x0 0x1c>; + clock-frequency = <50000000>; interrupts-extended = <&plic 8>; // UART is PLIC interrupt source 8 }; diff --git a/sw/device/lib/hal/autogen/uart.h b/sw/device/lib/hal/autogen/uart.h index a446f0a20..6cf9d9b3a 100644 --- a/sw/device/lib/hal/autogen/uart.h +++ b/sw/device/lib/hal/autogen/uart.h @@ -8,177 +8,131 @@ #include #include -typedef enum [[clang::flag_enum]] uart_intr : uint32_t { - uart_intr_none = 0, - uart_intr_tx_watermark = (1u << 0), - uart_intr_rx_watermark = (1u << 1), - uart_intr_tx_done = (1u << 2), - uart_intr_rx_overflow = (1u << 3), - uart_intr_rx_frame_err = (1u << 4), - uart_intr_rx_break_err = (1u << 5), - uart_intr_rx_timeout = (1u << 6), - uart_intr_rx_parity_err = (1u << 7), - uart_intr_tx_empty = (1u << 8), -} uart_intr; - -typedef struct [[gnu::aligned(4)]] { - uint32_t fatal_fault : 1; - uint32_t : 31; -} uart_alert_test; - typedef struct [[gnu::aligned(4)]] { - uint32_t tx : 1; - uint32_t rx : 1; - uint32_t nf : 1; - uint32_t : 1; - uint32_t slpbk : 1; - uint32_t llpbk : 1; - uint32_t parity_en : 1; - uint32_t parity_odd : 1; - uint32_t rxblvl : 2; - uint32_t : 6; - uint32_t nco : 16; -} uart_ctrl; - -typedef enum [[clang::flag_enum]] uart_status : uint32_t { - uart_status_none = 0, - uart_status_txfull = (1u << 0), - uart_status_rxfull = (1u << 1), - uart_status_txempty = (1u << 2), - uart_status_txidle = (1u << 3), - uart_status_rxidle = (1u << 4), - uart_status_rxempty = (1u << 5), -} uart_status; - -typedef struct [[gnu::aligned(4)]] { - uint32_t rdata : 8; + uint32_t rbr : 8; uint32_t : 24; -} uart_rdata; +} uart_rbr; -typedef struct [[gnu::aligned(4)]] { - uint32_t wdata : 8; - uint32_t : 24; -} uart_wdata; +typedef enum [[clang::flag_enum]] uart_ier : uint32_t { + uart_ier_none = 0, + uart_ier_erbfi = (1u << 0), + uart_ier_etbei = (1u << 1), + uart_ier_elsi = (1u << 2), + uart_ier_edssi = (1u << 3), +} uart_ier; typedef struct [[gnu::aligned(4)]] { - uint32_t rxrst : 1; - uint32_t txrst : 1; - uint32_t rxilvl : 3; - uint32_t txilvl : 3; + uint32_t intr_pending : 1; + uint32_t intr_id : 3; + uint32_t : 2; + uint32_t fifo_en : 2; uint32_t : 24; -} uart_fifo_ctrl; +} uart_iir; typedef struct [[gnu::aligned(4)]] { - uint32_t txlvl : 8; - uint32_t : 8; - uint32_t rxlvl : 8; - uint32_t : 8; -} uart_fifo_status; - -typedef enum [[clang::flag_enum]] uart_ovrd : uint32_t { - uart_ovrd_none = 0, - uart_ovrd_txen = (1u << 0), - uart_ovrd_txval = (1u << 1), -} uart_ovrd; + uint32_t wls : 2; + uint32_t stb : 1; + uint32_t pen : 1; + uint32_t eps : 1; + uint32_t stick_parity : 1; + uint32_t break_ctrl : 1; + uint32_t dlab : 1; + uint32_t : 24; +} uart_lcr; typedef struct [[gnu::aligned(4)]] { - uint32_t rx : 16; - uint32_t : 16; -} uart_val; + uint32_t dtr : 1; + uint32_t rts : 1; + uint32_t out : 2; + uint32_t loop : 1; + uint32_t : 27; +} uart_mcr; + +typedef enum [[clang::flag_enum]] uart_lsr : uint32_t { + uart_lsr_none = 0, + uart_lsr_dr = (1u << 0), + uart_lsr_oe = (1u << 1), + uart_lsr_pe = (1u << 2), + uart_lsr_fe = (1u << 3), + uart_lsr_bi = (1u << 4), + uart_lsr_thre = (1u << 5), + uart_lsr_temt = (1u << 6), + uart_lsr_rcvr_fifo_error = (1u << 7), +} uart_lsr; + +typedef enum [[clang::flag_enum]] uart_msr : uint32_t { + uart_msr_none = 0, + uart_msr_dcts = (1u << 0), + uart_msr_ddsr = (1u << 1), + uart_msr_teri = (1u << 2), + uart_msr_ddcd = (1u << 3), + uart_msr_cts = (1u << 4), + uart_msr_dsr = (1u << 5), + uart_msr_ri = (1u << 6), + uart_msr_dcd = (1u << 7), +} uart_msr; typedef struct [[gnu::aligned(4)]] { - uint32_t val : 24; - uint32_t : 7; - uint32_t en : 1; -} uart_timeout_ctrl; + uint32_t scr : 8; + uint32_t : 24; +} uart_scr; typedef volatile struct [[gnu::aligned(4)]] uart_memory_layout { - /* uart.intr_state (0x0) */ - uart_intr intr_state; - - /* uart.intr_enable (0x4) */ - uart_intr intr_enable; - - /* uart.intr_test (0x8) */ - uart_intr intr_test; - - /* uart.alert_test (0xc) */ - uart_alert_test alert_test; - - /* uart.ctrl (0x10) */ - uart_ctrl ctrl; - - /* uart.status (0x14) */ - const uart_status status; + /* uart.rbr (0x0) */ + const uart_rbr rbr; - /* uart.rdata (0x18) */ - const uart_rdata rdata; + /* uart.ier (0x4) */ + uart_ier ier; - /* uart.wdata (0x1c) */ - uart_wdata wdata; + /* uart.iir (0x8) */ + const uart_iir iir; - /* uart.fifo_ctrl (0x20) */ - uart_fifo_ctrl fifo_ctrl; + /* uart.lcr (0xc) */ + uart_lcr lcr; - /* uart.fifo_status (0x24) */ - const uart_fifo_status fifo_status; + /* uart.mcr (0x10) */ + uart_mcr mcr; - /* uart.ovrd (0x28) */ - uart_ovrd ovrd; + /* uart.lsr (0x14) */ + uart_lsr lsr; - /* uart.val (0x2c) */ - const uart_val val; + /* uart.msr (0x18) */ + const uart_msr msr; - /* uart.timeout_ctrl (0x30) */ - uart_timeout_ctrl timeout_ctrl; + /* uart.scr (0x1c) */ + uart_scr scr; } *uart_t; -_Static_assert(__builtin_offsetof(struct uart_memory_layout, intr_state) == 0x0ul, - "incorrect register intr_state offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, intr_enable) == 0x4ul, - "incorrect register intr_enable offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, intr_test) == 0x8ul, - "incorrect register intr_test offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, alert_test) == 0xcul, - "incorrect register alert_test offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, ctrl) == 0x10ul, - "incorrect register ctrl offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, status) == 0x14ul, - "incorrect register status offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, rdata) == 0x18ul, - "incorrect register rdata offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, wdata) == 0x1cul, - "incorrect register wdata offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, fifo_ctrl) == 0x20ul, - "incorrect register fifo_ctrl offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, fifo_status) == 0x24ul, - "incorrect register fifo_status offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, ovrd) == 0x28ul, - "incorrect register ovrd offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, val) == 0x2cul, - "incorrect register val offset"); -_Static_assert(__builtin_offsetof(struct uart_memory_layout, timeout_ctrl) == 0x30ul, - "incorrect register timeout_ctrl offset"); - -_Static_assert(sizeof(uart_intr) == sizeof(uint32_t), - "register type uart_intr is not register sized"); -_Static_assert(sizeof(uart_alert_test) == sizeof(uint32_t), - "register type uart_alert_test is not register sized"); -_Static_assert(sizeof(uart_ctrl) == sizeof(uint32_t), - "register type uart_ctrl is not register sized"); -_Static_assert(sizeof(uart_status) == sizeof(uint32_t), - "register type uart_status is not register sized"); -_Static_assert(sizeof(uart_rdata) == sizeof(uint32_t), - "register type uart_rdata is not register sized"); -_Static_assert(sizeof(uart_wdata) == sizeof(uint32_t), - "register type uart_wdata is not register sized"); -_Static_assert(sizeof(uart_fifo_ctrl) == sizeof(uint32_t), - "register type uart_fifo_ctrl is not register sized"); -_Static_assert(sizeof(uart_fifo_status) == sizeof(uint32_t), - "register type uart_fifo_status is not register sized"); -_Static_assert(sizeof(uart_ovrd) == sizeof(uint32_t), - "register type uart_ovrd is not register sized"); -_Static_assert(sizeof(uart_val) == sizeof(uint32_t), - "register type uart_val is not register sized"); -_Static_assert(sizeof(uart_timeout_ctrl) == sizeof(uint32_t), - "register type uart_timeout_ctrl is not register sized"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, rbr) == 0x0ul, + "incorrect register rbr offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, ier) == 0x4ul, + "incorrect register ier offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, iir) == 0x8ul, + "incorrect register iir offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, lcr) == 0xcul, + "incorrect register lcr offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, mcr) == 0x10ul, + "incorrect register mcr offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, lsr) == 0x14ul, + "incorrect register lsr offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, msr) == 0x18ul, + "incorrect register msr offset"); +_Static_assert(__builtin_offsetof(struct uart_memory_layout, scr) == 0x1cul, + "incorrect register scr offset"); + +_Static_assert(sizeof(uart_rbr) == sizeof(uint32_t), + "register type uart_rbr is not register sized"); +_Static_assert(sizeof(uart_ier) == sizeof(uint32_t), + "register type uart_ier is not register sized"); +_Static_assert(sizeof(uart_iir) == sizeof(uint32_t), + "register type uart_iir is not register sized"); +_Static_assert(sizeof(uart_lcr) == sizeof(uint32_t), + "register type uart_lcr is not register sized"); +_Static_assert(sizeof(uart_mcr) == sizeof(uint32_t), + "register type uart_mcr is not register sized"); +_Static_assert(sizeof(uart_lsr) == sizeof(uint32_t), + "register type uart_lsr is not register sized"); +_Static_assert(sizeof(uart_msr) == sizeof(uint32_t), + "register type uart_msr is not register sized"); +_Static_assert(sizeof(uart_scr) == sizeof(uint32_t), + "register type uart_scr is not register sized"); diff --git a/sw/device/lib/hal/uart.c b/sw/device/lib/hal/uart.c index a3d2b374a..7ffdb8687 100644 --- a/sw/device/lib/hal/uart.c +++ b/sw/device/lib/hal/uart.c @@ -9,97 +9,102 @@ void uart_init(uart_t uart) { - uart_ctrl ctrl = VOLATILE_READ(uart->ctrl); - ctrl.tx = true; - ctrl.rx = true; - ctrl.nco = (((uint64_t)BAUD_RATE << 20) / system_clock_frequency); - VOLATILE_WRITE(uart->ctrl, ctrl); -} - -uart_intr uart_interrupt_enable_read(uart_t uart) -{ - return VOLATILE_READ(uart->intr_enable); -} + // Enable divisor latch access + uart_lcr lcr = VOLATILE_READ(uart->lcr); + lcr.dlab = 1; + VOLATILE_WRITE(uart->lcr, lcr); + + // Write divisor latch + uart_dl_t uart_dl = (uart_dl_t)uart; + uint16_t dl = system_clock_frequency / ((uint64_t)BAUD_RATE << 4); + uart_dll dll = { + .dll = dl & 0xFF, + }; + VOLATILE_WRITE(uart_dl->dll, dll); + uart_dlm dlm = { + .dlm = dl >> 8, + }; + VOLATILE_WRITE(uart_dl->dlm, dlm); -void uart_interrupt_enable_write(uart_t uart, uart_intr intrs) -{ - VOLATILE_WRITE(uart->intr_enable, intrs); + // Disable divisor latch access + lcr.dlab = 0; + VOLATILE_WRITE(uart->lcr, lcr); } -void uart_interrupt_enable_set(uart_t uart, uart_intr intrs) +uart_ier uart_interrupt_enable_read(uart_t uart) { - uart_intr intr_enable = VOLATILE_READ(uart->intr_enable); - intr_enable |= intrs; - VOLATILE_WRITE(uart->intr_enable, intr_enable); + return VOLATILE_READ(uart->ier); } -void uart_interrupt_enable_clear(uart_t uart, uart_intr intrs) +void uart_interrupt_enable_write(uart_t uart, uart_ier intrs) { - uart_intr intr_enable = VOLATILE_READ(uart->intr_enable); - intr_enable &= ~intrs; - VOLATILE_WRITE(uart->intr_enable, intr_enable); + VOLATILE_WRITE(uart->ier, intrs); } -void uart_interrupt_force(uart_t uart, uart_intr intrs) +void uart_interrupt_enable_set(uart_t uart, uart_ier intrs) { - VOLATILE_WRITE(uart->intr_test, intrs); + uart_ier ier = VOLATILE_READ(uart->ier); + ier |= intrs; + VOLATILE_WRITE(uart->ier, ier); } -void uart_interrupt_clear(uart_t uart, uart_intr intrs) +void uart_interrupt_enable_clear(uart_t uart, uart_ier intrs) { - VOLATILE_WRITE(uart->intr_state, intrs); + uart_ier ier = VOLATILE_READ(uart->ier); + ier &= ~intrs; + VOLATILE_WRITE(uart->ier, ier); } -bool uart_interrupt_all_pending(uart_t uart, uart_intr intrs) +bool uart_interrupt_is_pending(uart_t uart) { - return (VOLATILE_READ(uart->intr_state) & intrs) == intrs; + uart_iir iir = VOLATILE_READ(uart->iir); + return !iir.intr_pending; } -bool uart_interrupt_any_pending(uart_t uart, uart_intr intrs) +uart_intr_id uart_pending_interrupt_read(uart_t uart) { - return (VOLATILE_READ(uart->intr_state) & intrs) != 0u; + uart_iir iir = VOLATILE_READ(uart->iir); + return (uart_intr_id)iir.intr_id; } -bool uart_status_any(uart_t uart, uart_status status) +bool uart_line_status_any(uart_t uart, uart_lsr lsr) { - return (VOLATILE_READ(uart->status) & status) != 0u; + // This will clear any receive error in the LSR as a side effect + return (VOLATILE_READ(uart->lsr) & lsr) != 0u; } -bool uart_status_all(uart_t uart, uart_status status) +bool uart_line_status_all(uart_t uart, uart_lsr lsr) { - return (VOLATILE_READ(uart->status) & status) == status; + // This will clear any receive error in the LSR as a side effect + return (VOLATILE_READ(uart->lsr) & lsr) == lsr; } -void uart_loopback_set(uart_t uart, bool system_enable, bool line_enable) +void uart_loopback_set(uart_t uart, bool system_enable) { - uart_ctrl ctrl = VOLATILE_READ(uart->ctrl); - ctrl.slpbk = system_enable; - ctrl.llpbk = line_enable; - VOLATILE_WRITE(uart->ctrl, ctrl); + uart_mcr mcr = VOLATILE_READ(uart->mcr); + mcr.loop = system_enable; + VOLATILE_WRITE(uart->mcr, mcr); } char uart_in(uart_t uart) { - uart_status status; - do { - status = VOLATILE_READ(uart->status); - } while (status & uart_status_rxempty); + // Wait until there is received data + uart_wait_for(uart, uart_lsr_dr); - uart_rdata rdata = VOLATILE_READ(uart->rdata); - return (char)(rdata.rdata); + // Read from Rx FIFO + uart_rbr rbr = VOLATILE_READ(uart->rbr); + return (char)(rbr.rbr); } void uart_out(uart_t uart, char ch) { - uart_status status; - do { - status = VOLATILE_READ(uart->status); - } while (status & uart_status_txfull); + // Wait until THR is empty + uart_wait_for(uart, uart_lsr_thre); - uart_wdata wdata = { - .wdata = ch, - }; - VOLATILE_WRITE(uart->wdata, wdata); + // Push to Tx FIFO + uart_wo_t uart_wo = (uart_wo_t)uart; + uart_thr thr = { .thr = ch }; + VOLATILE_WRITE(uart_wo->thr, thr); } void uart_putchar(uart_t uart, char ch) diff --git a/sw/device/lib/hal/uart.h b/sw/device/lib/hal/uart.h index 0ab8df56d..7e6452393 100644 --- a/sw/device/lib/hal/uart.h +++ b/sw/device/lib/hal/uart.h @@ -10,28 +10,88 @@ #define BAUD_RATE (1000000u) + +/* Interrupt ID enum from IIR */ +typedef enum uart_intr_id : uint32_t { + uart_intr_id_receiver_line_status = 0b011, + uart_intr_id_received_data_available = 0b010, + uart_intr_id_character_timeout_indication = 0b110, + uart_intr_id_transmitter_holding_register_empty = 0b001, + uart_intr_id_modem_status = 0b000, +} uart_intr_id; + + +/* Write-only register types */ +typedef struct [[gnu::aligned(4)]] { + uint32_t thr : 8; + uint32_t : 24; +} uart_thr; + +typedef struct [[gnu::aligned(4)]] { + uint32_t fifo_en : 1; + uint32_t rcvr_fifo_reset : 1; + uint32_t xmit_fifo_reset : 1; + uint32_t dma_mode_sel : 1; + uint32_t : 2; + uint32_t uart_rcvr_trigger : 2; + uint32_t : 24; +} uart_fcr; + + +/* Divisor latch register types */ +typedef struct [[gnu::aligned(4)]] { + uint32_t dll : 8; + uint32_t : 24; +} uart_dll; + +typedef struct [[gnu::aligned(4)]] { + uint32_t dlm : 8; + uint32_t : 24; +} uart_dlm; + + +/* Write-only memory layout with DLAB=0 */ +typedef volatile struct [[gnu::aligned(4)]] uart_wo_memory_layout { + /* uart.thr (0x0) */ + uart_thr thr; + + const uint8_t __reserved1[0x8 - 0x4]; + + /* uart.fcr (0x8) */ + uart_fcr fcr; +} *uart_wo_t; + + +/* Divisor latch memory layout with DLAB=1 */ +typedef volatile struct [[gnu::aligned(4)]] uart_dl_memory_layout { + /* uart.dll (0x0) */ + uart_dll dll; + + /* uart.dlm (0x4) */ + uart_dlm dlm; +} *uart_dl_t; + + /* initialisation */ void uart_init(uart_t uart); /* interrupts */ -uart_intr uart_interrupt_enable_read(uart_t uart); -void uart_interrupt_enable_write(uart_t uart, uart_intr intrs); -void uart_interrupt_enable_set(uart_t uart, uart_intr intrs); -void uart_interrupt_enable_clear(uart_t uart, uart_intr intrs); -void uart_interrupt_force(uart_t uart, uart_intr intrs); -void uart_interrupt_clear(uart_t uart, uart_intr intrs); -bool uart_interrupt_all_pending(uart_t uart, uart_intr intrs); -bool uart_interrupt_any_pending(uart_t uart, uart_intr intrs); -bool uart_status_any(uart_t uart, uart_status status); -bool uart_status_all(uart_t uart, uart_status status); - -static inline void uart_wait_for(uart_t uart, uart_status status) +uart_ier uart_interrupt_enable_read(uart_t uart); +void uart_interrupt_enable_write(uart_t uart, uart_ier intrs); +void uart_interrupt_enable_set(uart_t uart, uart_ier intrs); +void uart_interrupt_enable_clear(uart_t uart, uart_ier intrs); +bool uart_interrupt_is_pending(uart_t uart); +uart_intr_id uart_pending_interrupt_read(uart_t uart); +bool uart_line_status_any(uart_t uart, uart_lsr lsr); +bool uart_line_status_all(uart_t uart, uart_lsr lsr); + +static inline void uart_wait_for(uart_t uart, uart_lsr lsr) { - while (!uart_status_any(uart, status)) { + while (!uart_line_status_all(uart, lsr)) { }; } -void uart_loopback_set(uart_t uart, bool system_enable, bool line_enable); +void uart_loopback_set(uart_t uart, bool system_enable); char uart_in(uart_t uart); void uart_out(uart_t uart, char ch); void uart_putchar(uart_t uart, char ch); diff --git a/sw/device/lib/test_framework/main.c b/sw/device/lib/test_framework/main.c index 02722669f..b9307e6fa 100644 --- a/sw/device/lib/test_framework/main.c +++ b/sw/device/lib/test_framework/main.c @@ -74,13 +74,13 @@ test_exception_handler(struct trap_registers *registers, struct trap_context *co uart_init(console); // Flush the uart - uart_wait_for(console, uart_status_txidle); + uart_wait_for(console, uart_lsr_temt); DEV_WRITE(&dv_window->test_status, dv_test_status_in_test); bool result = test_main(console); // Flush the uart - uart_wait_for(console, uart_status_txidle); + uart_wait_for(console, uart_lsr_temt); test_exit(result); } diff --git a/sw/device/tests/plic/smoketest.c b/sw/device/tests/plic/smoketest.c index 42c5d1ed8..2277a8dfb 100644 --- a/sw/device/tests/plic/smoketest.c +++ b/sw/device/tests/plic/smoketest.c @@ -6,7 +6,7 @@ #include "hal/mocha.h" #include "hal/mocha_irq.h" #include "hal/plic.h" -#include "hal/uart.h" +#include "hal/spi_device.h" #include #include @@ -46,24 +46,25 @@ bool reg_test(plic_t plic) return true; } -bool uart_machine_irq_test(plic_t plic, uart_t uart) +bool spi_device_machine_irq_test(plic_t plic, spi_device_t spi_device) { uint32_t intr_id; plic_init(plic); - plic_interrupt_priority_write(plic, mocha_system_irq_uart, 3); + plic_interrupt_priority_write(plic, mocha_system_irq_spi_device, 3); plic_machine_priority_threshold_write(plic, 0); - uart_interrupt_enable_write(uart, uart_intr_rx_frame_err); + spi_device_interrupt_disable_all(spi_device); + spi_device_interrupt_enable(spi_device, SPI_DEVICE_INTR_TPM_RDFIFO_DROP); - plic_machine_interrupt_enable_set(plic, mocha_system_irq_uart); + plic_machine_interrupt_enable_set(plic, mocha_system_irq_spi_device); // Check that mip MEIP is clear if (hart_interrupt_any_pending(interrupt_machine_external)) { return false; } - uart_interrupt_force(uart, uart_intr_rx_frame_err); + spi_device_interrupt_trigger(spi_device, SPI_DEVICE_INTR_TPM_RDFIFO_DROP); // Check that mip MEIP is set following the triggered interrupt for (size_t i = 0; i < mip_read_retry_count; i++) { @@ -77,7 +78,7 @@ bool uart_machine_irq_test(plic_t plic, uart_t uart) } intr_id = plic_machine_interrupt_claim(plic); - uart_interrupt_clear(uart, uart_intr_rx_frame_err); + spi_device_interrupt_clear(spi_device, SPI_DEVICE_INTR_TPM_RDFIFO_DROP); plic_machine_interrupt_complete(plic, intr_id); // Check that mip MEIP is clear @@ -88,24 +89,25 @@ bool uart_machine_irq_test(plic_t plic, uart_t uart) return true; } -bool uart_supervisor_irq_test(plic_t plic, uart_t uart) +bool spi_device_supervisor_irq_test(plic_t plic, spi_device_t spi_device) { uint32_t intr_id; plic_init(plic); - plic_interrupt_priority_write(plic, mocha_system_irq_uart, 3); + plic_interrupt_priority_write(plic, mocha_system_irq_spi_device, 3); plic_supervisor_priority_threshold_write(plic, 0); - uart_interrupt_enable_write(uart, uart_intr_rx_timeout); + spi_device_interrupt_disable_all(spi_device); + spi_device_interrupt_enable(spi_device, SPI_DEVICE_INTR_UPLOAD_PAYLOAD_OVERFLOW); - plic_supervisor_interrupt_enable_set(plic, mocha_system_irq_uart); + plic_supervisor_interrupt_enable_set(plic, mocha_system_irq_spi_device); // Check that mip SEIP is clear if (hart_interrupt_any_pending(interrupt_supervisor_external)) { return false; } - uart_interrupt_force(uart, uart_intr_rx_timeout); + spi_device_interrupt_trigger(spi_device, SPI_DEVICE_INTR_UPLOAD_PAYLOAD_OVERFLOW); // Check for mip SEIP is set following the triggered interrupt for (size_t i = 0; i < mip_read_retry_count; i++) { @@ -119,7 +121,7 @@ bool uart_supervisor_irq_test(plic_t plic, uart_t uart) } intr_id = plic_supervisor_interrupt_claim(plic); - uart_interrupt_clear(uart, uart_intr_rx_timeout); + spi_device_interrupt_clear(spi_device, SPI_DEVICE_INTR_UPLOAD_PAYLOAD_OVERFLOW); plic_supervisor_interrupt_complete(plic, intr_id); // Check that mip SEIP is clear @@ -130,10 +132,11 @@ bool uart_supervisor_irq_test(plic_t plic, uart_t uart) return true; } -bool test_main(uart_t console) +bool test_main() { plic_t plic = mocha_system_plic(); + spi_device_t spi_device = mocha_system_spi_device(); - return reg_test(plic) && uart_machine_irq_test(plic, console) && - uart_supervisor_irq_test(plic, console); + return reg_test(plic) && spi_device_machine_irq_test(plic, spi_device) && + spi_device_supervisor_irq_test(plic, spi_device); } diff --git a/sw/device/tests/uart/smoketest.c b/sw/device/tests/uart/smoketest.c index 2e45c4e3c..545a460e1 100644 --- a/sw/device/tests/uart/smoketest.c +++ b/sw/device/tests/uart/smoketest.c @@ -12,20 +12,19 @@ const static char uart_loopback_test_string[] = "Test String"; static bool loopback_test(uart_t uart) { // Flush the uart - uart_wait_for(uart, uart_status_txidle); + uart_wait_for(uart, uart_lsr_temt); - uart_loopback_set(uart, true, true); + uart_loopback_set(uart, true); for (uint32_t idx = 0; idx < sizeof(uart_loopback_test_string); idx++) { uart_out(uart, uart_loopback_test_string[idx]); } // Wait for the transmission to finish - uart_wait_for(uart, uart_status_txidle); - uart_loopback_set(uart, false, false); + uart_wait_for(uart, uart_lsr_temt); + uart_loopback_set(uart, false); bool res = true; for (uint32_t idx = 0; idx < sizeof(uart_loopback_test_string); idx++) { - while (uart_status_any(uart, uart_status_rxempty)) { - }; + uart_wait_for(uart, uart_lsr_dr); char rx = uart_in(uart); if (rx != uart_loopback_test_string[idx]) { uprintf(uart, "Expected: %c, got: %c\n", rx, uart_loopback_test_string[idx]); diff --git a/util/artefacts.py b/util/artefacts.py index d92202b01..80de9bfa1 100755 --- a/util/artefacts.py +++ b/util/artefacts.py @@ -143,14 +143,17 @@ # vendored hardware dependencies ["util/vendor.py", "hw/vendor/axi_riscv_atomics.vendor.hjson"], ["util/vendor.py", "hw/vendor/cva6_cheri.vendor.hjson"], + ["util/vendor.py", "hw/vendor/cvfpu.vendor.hjson"], ["util/vendor.py", "hw/vendor/hpdcache.vendor.hjson"], ["util/vendor.py", "hw/vendor/ethernet.vendor.hjson"], + ["util/vendor.py", "hw/vendor/fpu_div_sqrt_mvp.vendor.hjson"], ["util/vendor.py", "hw/vendor/pulp_axi.vendor.hjson"], ["util/vendor.py", "hw/vendor/pulp_axi_llc.vendor.hjson"], ["util/vendor.py", "hw/vendor/pulp_register_interface.vendor.hjson"], ["util/vendor.py", "hw/vendor/pulp_riscv_dbg.vendor.hjson"], ["util/vendor.py", "hw/vendor/sonata_system.vendor.hjson"], ["util/vendor.py", "hw/vendor/tagctrl.vendor.hjson"], + ["util/vendor.py", "hw/vendor/uart_16550.vendor.hjson"], ]