Skip to content

add parity to uart verification component #1181

Open
rafaelnp wants to merge 5 commits intoVUnit:masterfrom
rafaelnp:feature/uart-parity
Open

add parity to uart verification component #1181
rafaelnp wants to merge 5 commits intoVUnit:masterfrom
rafaelnp:feature/uart-parity

Conversation

@rafaelnp
Copy link
Contributor

@rafaelnp rafaelnp commented Mar 15, 2026

Add parity support to uart verification component and extend the testbenches (VC and example) accordingly, and verified with the following simulators:

  • ghdl
  • nvc
  • questa

Copy link
Collaborator

@LarsAsplund LarsAsplund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed the updates to the examples. I will wait for the other comments to be sorted out.

type uart_master_t is record
p_actor : actor_t;
p_baud_rate : natural;
p_parity : natural;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an enumerated type parity_t for this.

uart_slave : uart_slave_t;
baud_rate : natural);

-- 0 = no parity, 1 = odd parity, 2 = even parity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are suitable names for the values of parity_t.

constant default_parity : natural := 0;

impure function new_uart_master(initial_baud_rate : natural := default_baud_rate;
initial_parity : natural := default_parity;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new parameters to the end to avoid breaking existing implementations.


constant uart_set_baud_rate_msg : msg_type_t := new_msg_type("uart set baud rate");

constant uart_set_parity_msg : msg_type_t := new_msg_type("uart set parity rate");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No "rate" in the message name.

constant default_baud_rate : natural := 115200;
constant default_idle_state : std_logic := '1';
constant default_data_length : positive := 8;
constant default_parity : natural := 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use the no_parity enum directly.

severity error;
end if;

push(msg, parity);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push parity_t'pos(parity)

baud_rate <= pop(msg);

elsif msg_type = uart_set_parity_msg then
parity <= pop(msg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you will have to convert the received value back to parity_t using the 'val attribute

wait for time_per_bit;
end loop;

if parity = 1 then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of the code in the if statement branches is identical and be placed outside of the if statement to reduce code duplication.

wait for 0 ns;

if parity_bit /= parity_calc then
report "odd parity mismatch"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A warning report will not cause a test case to fail by default. An error report will fail but is not testable (you need a test in tb_uart to verify that parity errors are detected). What you need is VUnit check procedures that can be mocked. Have a look at

elsif run("test failing check") then
for inspiration.

I would also add a pop procedure that returns both data and a parity error boolean such that the user can decide what to do with an error. This is not supported by the stream interface so the UART VC needs to support a "UART stream" interface as well. Have a look at how the AXI stream VCs supports both the basic stream interface and an AXI stream interface:

elsif msg_type = stream_pop_msg or msg_type = pop_axi_stream_msg or msg_type = check_axi_stream_msg then

test_baud_rate(2000);
test_baud_rate(7000);
test_baud_rate(200000);
elsif run("test_parity_odd") then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test case verifying parity error detection is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants