Skip to content

Commit 833d6d4

Browse files
[dv] Switch to new & improved top-level UART tests
Switch from the initial hacky top-level UART test programs to the ones ported from OpenTitan for increased randomisation. Also introduce a new test that randomises baud rate and a new `uart` regression test group.
1 parent a6e9673 commit 833d6d4

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright lowRISC contributors (Sunburst project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
`define CALC_NCO(baud_rate, nco_width, clk_freq_khz) \
6+
(baud_rate == BaudRate1p5Mbps && clk_freq_khz == 24_000) ? 16'hffff : \
7+
(longint'(baud_rate) * (2**(nco_width+4))) / (clk_freq_khz * 1000)
8+
9+
class top_chip_dv_uart_rand_baudrate_vseq extends top_chip_dv_uart_tx_rx_vseq;
10+
// import top_chip_system_pkg::PeriClkFreq;
11+
`uvm_object_utils(top_chip_dv_uart_rand_baudrate_vseq)
12+
`uvm_object_new
13+
14+
localparam NCO_WIDTH = 16;
15+
16+
int uart_clk_freq_khz; // Use khz to avoid fractional value.
17+
18+
rand baud_rate_e baud_rate;
19+
20+
constraint baud_rate_c {
21+
// constrain nco not over nco width
22+
`CALC_NCO(baud_rate, NCO_WIDTH, uart_clk_freq_khz) < (1 << NCO_WIDTH);
23+
// only test 4 other speeds, <= 115k is slow which may take a few hours to complete the test
24+
baud_rate > BaudRate115200;
25+
}
26+
27+
function void pre_randomize();
28+
super.pre_randomize();
29+
30+
// if (cfg.chip_clock_source != ChipClockSourceInternal) begin
31+
// // Uart bus clock is in div4 domain
32+
// uart_clk_freq_khz = cfg.chip_clock_source * 1000 / 4; // div4
33+
// if (cfg.chip_clock_source == ChipClockSourceExternal48Mhz) begin
34+
// uart_clk_freq_khz = uart_clk_freq_khz * 2; // div2
35+
// end
36+
// end else begin
37+
// internal uart clock
38+
uart_clk_freq_khz = top_chip_system_pkg::PeriClkFreq / 1000;
39+
// end
40+
endfunction
41+
42+
function void post_randomize();
43+
super.post_randomize();
44+
uart_baud_rate = baud_rate;
45+
endfunction
46+
47+
virtual task body();
48+
// sw_symbol_backdoor_overwrite takes an array as the input
49+
bit [7:0] uart_freq_arr[8] = {<<byte{uart_baud_rate}};
50+
51+
sw_symbol_backdoor_overwrite("kUartBaudrate", uart_freq_arr);
52+
`uvm_info(`gfn, $sformatf(
53+
"Backdoor_overwrite: configure uart core clk %0d khz, baud_rate: %s",
54+
uart_clk_freq_khz,
55+
baud_rate.name
56+
), UVM_LOW)
57+
58+
// if (cfg.chip_clock_source != ChipClockSourceInternal) begin
59+
// bit [7:0] use_extclk_arr[] = {cfg.chip_clock_source != ChipClockSourceInternal};
60+
// bit [7:0] low_speed_sel_arr[] = {cfg.chip_clock_source == ChipClockSourceExternal48Mhz};
61+
// bit [7:0] uart_clk_freq_arr[8] = {<<byte{uart_clk_freq_khz * 1000}};
62+
63+
// sw_symbol_backdoor_overwrite("kUseExtClk", use_extclk_arr);
64+
// sw_symbol_backdoor_overwrite("kUseLowSpeedSel", low_speed_sel_arr);
65+
// sw_symbol_backdoor_overwrite("kClockFreqPeripheralHz", uart_clk_freq_arr);
66+
// end
67+
68+
super.body();
69+
endtask
70+
71+
// // When uart starts to send RX data, check if AST is using extclk if extclk is selected.
72+
// virtual task send_uart_rx_data(int instance_num, int size = -1, bit random = 0);
73+
// if (cfg.chip_clock_source != ChipClockSourceInternal) begin
74+
// `DV_CHECK(cfg.ast_ext_clk_vif.is_ext_clk_in_use(),
75+
// "expected the external clock to be used for io");
76+
// end
77+
// super.send_uart_rx_data(instance_num, size, random);
78+
// endtask
79+
80+
endclass : top_chip_dv_uart_rand_baudrate_vseq
81+
`undef CALC_NCO

hw/top_chip/dv/env/seq_lib/top_chip_dv_vseq_list.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
`include "top_chip_dv_pattgen_vseq.sv"
88
`include "top_chip_dv_uart_base_vseq.sv"
99
`include "top_chip_dv_uart_tx_rx_vseq.sv"
10+
`include "top_chip_dv_uart_rand_baudrate_vseq.sv"

hw/top_chip/dv/env/top_chip_dv_env.core

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ filesets:
3030
- seq_lib/top_chip_dv_pattgen_vseq.sv: {is_include_file: true}
3131
- seq_lib/top_chip_dv_uart_base_vseq.sv: {is_include_file: true}
3232
- seq_lib/top_chip_dv_uart_tx_rx_vseq.sv: {is_include_file: true}
33+
- seq_lib/top_chip_dv_uart_rand_baudrate_vseq.sv: {is_include_file: true}
3334
file_type: systemVerilogSource
3435

3536
targets:

hw/top_chip/dv/top_chip_sim_cfg.hjson

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,19 @@
5959
run_opts: ["+ChipMemSRAM_image_file={proj_root}/sw/device/build/tests/pattgen_ios_test.vmem"]
6060
}
6161
{
62-
name: top_uart_smoke
63-
uvm_test_seq: top_chip_dv_base_vseq
64-
run_opts: ["+ChipMemSRAM_image_file={proj_root}/scratch_sw/bare_metal/build/checks/uart_smoke_check.vmem"]
62+
name: uart_baud_rate_test
63+
uvm_test_seq: top_chip_dv_uart_rand_baudrate_vseq
64+
run_opts: ["+ChipMemSRAM_image_file={proj_root}/sw/device/build/tests/uart_tx_rx_test.vmem"]
6565
}
6666
{
67-
name: top_uart_tx_rx
68-
uvm_test_seq: top_chip_dv_uart_tx_rx_vseq
69-
run_opts: ["+ChipMemSRAM_image_file={proj_root}/scratch_sw/bare_metal/build/checks/uart_tx_rx_check.vmem",
70-
"+uart_idx=0"]
67+
name: uart_smoketest
68+
uvm_test_seq: top_chip_dv_base_vseq
69+
run_opts: ["+ChipMemSRAM_image_file={proj_root}/sw/device/build/tests/uart_smoketest.vmem"]
7170
}
7271
{
73-
name: top_usbdev_smoke
74-
uvm_test_seq: top_chip_dv_base_vseq
75-
run_opts: ["+ChipMemSRAM_image_file={proj_root}/scratch_sw/bare_metal/build/checks/usbdev_check.vmem"]
72+
name: uart_tx_rx_test
73+
uvm_test_seq: top_chip_dv_uart_tx_rx_vseq
74+
run_opts: ["+ChipMemSRAM_image_file={proj_root}/sw/device/build/tests/uart_tx_rx_test.vmem"]
7675
}
7776
{
7877
name: usbdev_config_host_test
@@ -135,7 +134,11 @@
135134
regressions: [
136135
{
137136
name: smoke
138-
tests: ["top_chip_smoke", "pattgen_ios_test", "top_uart_smoke", "top_usbdev_smoke"]
137+
tests: ["top_chip_smoke", "pattgen_ios_test", "uart_smoketest", "top_usbdev_smoke"]
138+
}
139+
{
140+
name: uart
141+
tests: ["uart_baud_rate_test", "uart_smoketest", "uart_tx_rx_test"]
139142
}
140143
]
141144
}

0 commit comments

Comments
 (0)