|
| 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 |
0 commit comments