Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Weiyet_RTLStructLib/source/Doubly_Linked_List/src/doubly_linked_list.sv +458 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/src/rtl_list.f +1 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/cocotb/Makefile +41 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/cocotb/tb.py +480 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/sv/Makefile +38 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/sv/tb.sv +744 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/vip/pyuvm/Makefile +61 -0
- Weiyet_RTLStructLib/source/Doubly_Linked_List/vip/uvm/README.md +242 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/agent/__init__.py +9 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/agent/fifo_vip_driver.py +100 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/agent/fifo_vip_sequencer.py +16 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/__init__.py +8 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/fifo_vip_config.py +39 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/fifo_vip_seq_item.py +63 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/fifo_vip_types.py +20 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/env/__init__.py +7 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/env/fifo_vip_env.py +68 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/env/fifo_vip_scoreboard.py +73 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/__init__.py +8 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/fifo_vip_base_seq.py +13 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/fifo_vip_read_req_seq.py +28 -0
- Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/fifo_vip_write_req_seq.py +28 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_agent.sv +45 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_driver.sv +89 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_monitor.sv +77 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_sequencer.sv +19 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/common/fifo_vip_config.sv +38 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/common/fifo_vip_pkg.sv +42 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/common/fifo_vip_seq_item.sv +50 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/env/fifo_vip_env.sv +64 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/env/fifo_vip_scoreboard.sv +58 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/interface/fifo_vip_if.sv +38 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/sequences/fifo_vip_base_seq.sv +26 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/sequences/fifo_vip_read_req_seq.sv +37 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/sequences/fifo_vip_write_req_seq.sv +38 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/sim/tb_top.sv +70 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/sim/tests/fifo_vip_base_test.sv +42 -0
- Weiyet_RTLStructLib/source/FIFO/vip/uvm/sim/tests/fifo_vip_simple_test.sv +40 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/agent/__init__.py +9 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/agent/ht_vip_agent.py +28 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/agent/ht_vip_driver.py +48 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/__init__.py +14 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/ht_vip_config.py +37 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/ht_vip_seq_item.py +62 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/ht_vip_types.py +16 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/env/__init__.py +4 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/env/ht_vip_env.py +28 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/env/ht_vip_scoreboard.py +42 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/sequences/__init__.py +6 -0
- Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/sequences/ht_vip_base_seq.py +14 -0
Weiyet_RTLStructLib/source/Doubly_Linked_List/src/doubly_linked_list.sv
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
`timescale 1ns / 1ps
|
| 2 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 3 |
+
// Create Date: 09/10/2024 08:46:52 PM
|
| 4 |
+
// Last Update: 02/20/2025 10:17 PM
|
| 5 |
+
// Module Name: doubly_linked_list
|
| 6 |
+
// Description: Supported Operation
|
| 7 |
+
// 0. Read_Addr(addr_in) -> data_out
|
| 8 |
+
// 1. Insert_Addr(addr_in, data_in)
|
| 9 |
+
// 5. Insert_Index(addr_in, data_in)
|
| 10 |
+
// 2. Delete_Value(data_in)
|
| 11 |
+
// 3. Delete_Addr(addr_in)
|
| 12 |
+
// 7. Delete_Index(addr_in)
|
| 13 |
+
// Additional Comments: .
|
| 14 |
+
//
|
| 15 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
module doubly_linked_list #(
|
| 19 |
+
parameter DATA_WIDTH = 8, // Data Width
|
| 20 |
+
parameter MAX_NODE = 8 // Maximum number of nodes stored
|
| 21 |
+
)(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
input [DATA_WIDTH-1:0] data_in,
|
| 25 |
+
input [ADDR_WIDTH-1:0] addr_in, // index of element
|
| 26 |
+
input [2:0] op, // 0: Read(addr_in); 1: Delete_value(data_in); 2: Push_back(data_in); 3: Push_front(data_in)
|
| 27 |
+
input op_start,
|
| 28 |
+
output reg op_done,
|
| 29 |
+
output reg [DATA_WIDTH-1:0] data_out,
|
| 30 |
+
output reg [ADDR_WIDTH-1:0] pre_node_addr, // Addr of pre node
|
| 31 |
+
output reg [ADDR_WIDTH-1:0] next_node_addr, // Addr of next node
|
| 32 |
+
// status
|
| 33 |
+
output reg [ADDR_WIDTH-1:0] length,
|
| 34 |
+
output reg [ADDR_WIDTH-1:0] head, // Addr of head
|
| 35 |
+
output reg [ADDR_WIDTH-1:0] tail, // Addr of tail
|
| 36 |
+
output wire full,
|
| 37 |
+
output wire empty,
|
| 38 |
+
output reg fault
|
| 39 |
+
);
|
| 40 |
+
|
| 41 |
+
localparam ADDR_WIDTH = $clog2(MAX_NODE+1); // Reserve {ADDR_WIDTH(1'b1)} as NULL/INVALID ADDR.
|
| 42 |
+
localparam NODE_WIDTH = $clog2(MAX_NODE);
|
| 43 |
+
localparam ADDR_NULL = (MAX_NODE);
|
| 44 |
+
|
| 45 |
+
// yosys does not support sv typedef
|
| 46 |
+
// typedef struct {
|
| 47 |
+
// reg [DATA_WIDTH-1:0] data; // RAM
|
| 48 |
+
// reg [ADDR_WIDTH-1:0] next_node_addr; // RAM
|
| 49 |
+
// reg [ADDR_WIDTH-1:0] pre_node_addr; // RAM
|
| 50 |
+
// reg valid; // Register
|
| 51 |
+
// } node_st;
|
| 52 |
+
|
| 53 |
+
//node_st node [0:MAX_NODE-1];
|
| 54 |
+
reg [DATA_WIDTH-1:0] node_data [0:MAX_NODE-1]; // RAM
|
| 55 |
+
reg [ADDR_WIDTH-1:0] node_next_node_addr [0:MAX_NODE-1]; // RAM
|
| 56 |
+
reg [ADDR_WIDTH-1:0] node_pre_node_addr [0:MAX_NODE-1]; // RAM
|
| 57 |
+
reg node_valid [0:MAX_NODE-1]; // Register
|
| 58 |
+
|
| 59 |
+
wire [MAX_NODE-1:0] valid_bits;
|
| 60 |
+
wire op_is_read;
|
| 61 |
+
wire op_is_insert_at_addr;
|
| 62 |
+
wire op_is_insert_at_index;
|
| 63 |
+
wire op_is_delete_by_addr;
|
| 64 |
+
wire op_is_delete_by_index;
|
| 65 |
+
wire op_is_delete_by_value;
|
| 66 |
+
// wire addr_match;
|
| 67 |
+
wire ascending;
|
| 68 |
+
wire [ADDR_WIDTH-1:0] head_idx_sel;
|
| 69 |
+
wire [ADDR_WIDTH-1:0] tail_idx_sel;
|
| 70 |
+
wire addr_overflow;
|
| 71 |
+
reg [NODE_WIDTH-1:0] index;
|
| 72 |
+
reg [ADDR_WIDTH-1:0] cur_ptr;
|
| 73 |
+
reg [ADDR_WIDTH-1:0] pre_ptr;
|
| 74 |
+
//reg [ADDR_WIDTH-1:0] head; // Addr of head
|
| 75 |
+
//reg [ADDR_WIDTH-1:0] tail; // Addr of tail
|
| 76 |
+
reg [2:0] state;
|
| 77 |
+
reg [2:0] next_state;
|
| 78 |
+
reg wr_req;
|
| 79 |
+
reg rd_req;
|
| 80 |
+
reg valid_rd_buf;
|
| 81 |
+
reg valid_wr;
|
| 82 |
+
reg [ADDR_WIDTH-1:0] next_addr_rd_buf;
|
| 83 |
+
reg [ADDR_WIDTH-1:0] pre_addr_rd_buf;
|
| 84 |
+
reg [DATA_WIDTH-1:0] data_rd_buf;
|
| 85 |
+
reg [ADDR_WIDTH-1:0] target_idx;
|
| 86 |
+
reg [ADDR_WIDTH-1:0] next_node_addr_idx;
|
| 87 |
+
reg [ADDR_WIDTH-1:0] next_node_addr_in;
|
| 88 |
+
reg [ADDR_WIDTH-1:0] pre_node_addr_idx;
|
| 89 |
+
reg [ADDR_WIDTH-1:0] pre_node_addr_in;
|
| 90 |
+
|
| 91 |
+
integer i;
|
| 92 |
+
|
| 93 |
+
localparam IDLE = 3'b000;
|
| 94 |
+
localparam FIND_ADDR = 3'b001;
|
| 95 |
+
localparam FIND_VALUE = 3'b010;
|
| 96 |
+
localparam FIND_INDEX = 3'b110;
|
| 97 |
+
localparam INSERT_STG1 = 3'b011;
|
| 98 |
+
localparam FAULT = 3'b101;
|
| 99 |
+
localparam EXECUTE = 3'b100;
|
| 100 |
+
|
| 101 |
+
assign op_is_read = op[2:0] == 3'd0 & op_start;
|
| 102 |
+
assign op_is_insert_at_index = op[2:0] == 3'd5 & op_start;
|
| 103 |
+
assign op_is_insert_at_addr = op[2:0] == 3'd1 & op_start;
|
| 104 |
+
assign op_is_delete_by_value = op[2:0] == 3'd2 & op_start;
|
| 105 |
+
assign op_is_delete_by_index = op[2:0] == 3'd7 & op_start;
|
| 106 |
+
assign op_is_delete_by_addr = op[2:0] == 3'd3 & op_start;
|
| 107 |
+
|
| 108 |
+
always @ (posedge clk or posedge rst) begin
|
| 109 |
+
if (rst) begin
|
| 110 |
+
for (i = 0; i < MAX_NODE; i = i+1) begin
|
| 111 |
+
node_data[i] <= {DATA_WIDTH{1'b0}};
|
| 112 |
+
node_valid[i] <= 1'b0;
|
| 113 |
+
end
|
| 114 |
+
end else if (wr_req & state != INSERT_STG1 & target_idx != ADDR_NULL) begin
|
| 115 |
+
node_data[target_idx[NODE_WIDTH-1:0]] <= data_in;
|
| 116 |
+
node_valid[target_idx[NODE_WIDTH-1:0]] <= valid_wr;
|
| 117 |
+
end
|
| 118 |
+
end
|
| 119 |
+
|
| 120 |
+
always @ (posedge clk or posedge rst) begin
|
| 121 |
+
if (rst) begin
|
| 122 |
+
for (i = 0; i < MAX_NODE; i = i+1) begin
|
| 123 |
+
node_next_node_addr[i] <= ADDR_NULL;
|
| 124 |
+
end
|
| 125 |
+
end else if (wr_req & next_node_addr_idx != ADDR_NULL) begin
|
| 126 |
+
node_next_node_addr[next_node_addr_idx[NODE_WIDTH-1:0]] <= next_node_addr_in;
|
| 127 |
+
end
|
| 128 |
+
end
|
| 129 |
+
|
| 130 |
+
always @ (posedge clk or posedge rst) begin
|
| 131 |
+
if (rst) begin
|
| 132 |
+
for (i = 0; i < MAX_NODE; i = i+1) begin
|
| 133 |
+
node_pre_node_addr[i] <= ADDR_NULL;
|
| 134 |
+
end
|
| 135 |
+
end else if (wr_req & pre_node_addr_idx != ADDR_NULL) begin
|
| 136 |
+
node_pre_node_addr[pre_node_addr_idx[NODE_WIDTH-1:0]] <= pre_node_addr_in;
|
| 137 |
+
end
|
| 138 |
+
end
|
| 139 |
+
|
| 140 |
+
assign head_idx_sel = op[2] ? 0 : head;
|
| 141 |
+
assign tail_idx_sel = op[2] ? (length-1) : tail;
|
| 142 |
+
assign addr_overflow = (op[2] & (addr_in >= length)) | (addr_in >= ADDR_NULL);
|
| 143 |
+
assign ascending = (addr_in < (length << 2));
|
| 144 |
+
|
| 145 |
+
always @ (posedge clk or posedge rst) begin
|
| 146 |
+
if (rst) begin
|
| 147 |
+
state <= 3'b0;
|
| 148 |
+
end else begin
|
| 149 |
+
state <= next_state;
|
| 150 |
+
end
|
| 151 |
+
end
|
| 152 |
+
|
| 153 |
+
// op_done
|
| 154 |
+
always @ (*) begin
|
| 155 |
+
op_done <= 1'b0;
|
| 156 |
+
rd_req <= 1'b0;
|
| 157 |
+
wr_req <= 1'b0;
|
| 158 |
+
target_idx <= ADDR_NULL;
|
| 159 |
+
valid_wr <= 1'b0;
|
| 160 |
+
next_node_addr_idx <= ADDR_NULL;
|
| 161 |
+
next_node_addr_in <= ADDR_NULL;
|
| 162 |
+
pre_node_addr_idx <= ADDR_NULL;
|
| 163 |
+
pre_node_addr_in <= ADDR_NULL;
|
| 164 |
+
fault <= 1'b0;
|
| 165 |
+
next_state <= IDLE;
|
| 166 |
+
case(state)
|
| 167 |
+
IDLE: begin
|
| 168 |
+
if (op_is_insert_at_addr | op_is_insert_at_index) begin
|
| 169 |
+
if (full) begin
|
| 170 |
+
next_state <= FAULT;
|
| 171 |
+
end else if (addr_in == head_idx_sel) begin // push_front
|
| 172 |
+
// Add new node
|
| 173 |
+
// Next node addr of new node point to head
|
| 174 |
+
wr_req <= 1'b1;
|
| 175 |
+
target_idx <= find_next_ptr(valid_bits);
|
| 176 |
+
valid_wr <= 1'b1;
|
| 177 |
+
next_node_addr_idx <= find_next_ptr(valid_bits);
|
| 178 |
+
next_node_addr_in <= head;
|
| 179 |
+
pre_node_addr_idx <= head;
|
| 180 |
+
pre_node_addr_in <= find_next_ptr(valid_bits);
|
| 181 |
+
next_state <= EXECUTE;
|
| 182 |
+
end else if (addr_overflow) begin // push_back
|
| 183 |
+
// Add new node
|
| 184 |
+
// Next node addr of tail point to new node
|
| 185 |
+
wr_req <= 1'b1;
|
| 186 |
+
target_idx <= find_next_ptr(valid_bits);
|
| 187 |
+
valid_wr <= 1'b1;
|
| 188 |
+
next_node_addr_idx <= tail;
|
| 189 |
+
next_node_addr_in <= find_next_ptr(valid_bits);
|
| 190 |
+
pre_node_addr_idx <= find_next_ptr(valid_bits);
|
| 191 |
+
pre_node_addr_in <= tail;
|
| 192 |
+
next_state <= EXECUTE;
|
| 193 |
+
end else begin
|
| 194 |
+
rd_req <= 1'b1;
|
| 195 |
+
target_idx <= op[2]? (ascending ? head : tail) : addr_in;
|
| 196 |
+
next_state <= op[2]? FIND_INDEX : FIND_ADDR;
|
| 197 |
+
end
|
| 198 |
+
end else if (op_is_read) begin
|
| 199 |
+
if(empty | addr_overflow) begin
|
| 200 |
+
next_state <= FAULT;
|
| 201 |
+
end else begin
|
| 202 |
+
rd_req <= 1'b1;
|
| 203 |
+
target_idx <= addr_in;
|
| 204 |
+
next_state <= EXECUTE;
|
| 205 |
+
end
|
| 206 |
+
end else if (op_is_delete_by_value) begin
|
| 207 |
+
if(empty) begin
|
| 208 |
+
next_state <= FAULT;
|
| 209 |
+
end else begin
|
| 210 |
+
rd_req <= 1'b1;
|
| 211 |
+
target_idx <= head;
|
| 212 |
+
next_state <= FIND_VALUE;
|
| 213 |
+
end
|
| 214 |
+
end else if (op_is_delete_by_addr | op_is_delete_by_index) begin
|
| 215 |
+
if(empty | addr_overflow) begin
|
| 216 |
+
next_state <= FAULT;
|
| 217 |
+
end else begin
|
| 218 |
+
rd_req <= 1'b1;
|
| 219 |
+
target_idx <= op[2] ? (ascending ? head : tail) : addr_in;
|
| 220 |
+
next_state <= op[2] ? FIND_INDEX : FIND_ADDR;
|
| 221 |
+
end
|
| 222 |
+
end else if(op_start)begin
|
| 223 |
+
next_state <= FAULT; // Invalid operation
|
| 224 |
+
end else begin
|
| 225 |
+
next_state <= IDLE;
|
| 226 |
+
end
|
| 227 |
+
end
|
| 228 |
+
FIND_ADDR: begin // to get pre pos (pre_ptr)
|
| 229 |
+
if (!valid_rd_buf) begin
|
| 230 |
+
next_state <= FAULT;
|
| 231 |
+
end else begin
|
| 232 |
+
if(op_is_delete_by_addr) begin
|
| 233 |
+
// update curr pos to invalid
|
| 234 |
+
wr_req <= 1'b1;
|
| 235 |
+
target_idx <= cur_ptr;
|
| 236 |
+
valid_wr <= 1'b0;
|
| 237 |
+
// update next_node_addr of pre pos to next pos
|
| 238 |
+
next_node_addr_idx <= pre_addr_rd_buf;
|
| 239 |
+
next_node_addr_in <= next_addr_rd_buf;
|
| 240 |
+
// update pre_node_addr of next post to pre pos
|
| 241 |
+
pre_node_addr_idx <= next_addr_rd_buf;
|
| 242 |
+
pre_node_addr_in <= pre_addr_rd_buf;
|
| 243 |
+
next_state <= EXECUTE;
|
| 244 |
+
end else if (op_is_insert_at_addr) begin
|
| 245 |
+
// insert new pos
|
| 246 |
+
wr_req <= 1'b1;
|
| 247 |
+
target_idx <= find_next_ptr(valid_bits);
|
| 248 |
+
valid_wr <= 1'b1;
|
| 249 |
+
// update next_node_addr of curr pos to new pos
|
| 250 |
+
next_node_addr_idx <= pre_addr_rd_buf;
|
| 251 |
+
next_node_addr_in <= find_next_ptr(valid_bits);
|
| 252 |
+
// update next_node_addr of next pos to neew pos
|
| 253 |
+
pre_node_addr_idx <= find_next_ptr(valid_bits);
|
| 254 |
+
pre_node_addr_in <= pre_addr_rd_buf;
|
| 255 |
+
next_state <= INSERT_STG1;
|
| 256 |
+
end
|
| 257 |
+
end
|
| 258 |
+
end
|
| 259 |
+
FIND_INDEX: begin
|
| 260 |
+
if (!valid_rd_buf) begin
|
| 261 |
+
next_state <= FAULT;
|
| 262 |
+
end else if (addr_in == index) begin
|
| 263 |
+
if(op_is_delete_by_index) begin
|
| 264 |
+
// update cur pos to invalid
|
| 265 |
+
wr_req <= 1'b1;
|
| 266 |
+
target_idx <= cur_ptr;
|
| 267 |
+
valid_wr <= 1'b0;
|
| 268 |
+
// update next_node_addr of pre pos to next pos
|
| 269 |
+
next_node_addr_idx <= pre_addr_rd_buf;
|
| 270 |
+
next_node_addr_in <= next_addr_rd_buf;
|
| 271 |
+
// update pre_node_addr of next post to pre pos
|
| 272 |
+
pre_node_addr_idx <= next_addr_rd_buf;
|
| 273 |
+
pre_node_addr_in <= pre_addr_rd_buf;
|
| 274 |
+
next_state <= EXECUTE;
|
| 275 |
+
end else if (op_is_insert_at_index) begin
|
| 276 |
+
// insert new pos
|
| 277 |
+
wr_req <= 1'b1;
|
| 278 |
+
target_idx <= find_next_ptr(valid_bits);
|
| 279 |
+
valid_wr <= 1'b1;
|
| 280 |
+
// update next_node_addr of curr pos to new pos
|
| 281 |
+
next_node_addr_idx <= pre_addr_rd_buf;
|
| 282 |
+
next_node_addr_in <= find_next_ptr(valid_bits);
|
| 283 |
+
// update next_node_addr of next pos to neew pos
|
| 284 |
+
pre_node_addr_idx <= find_next_ptr(valid_bits);
|
| 285 |
+
pre_node_addr_in <= pre_addr_rd_buf;
|
| 286 |
+
next_state <= INSERT_STG1;
|
| 287 |
+
end
|
| 288 |
+
end else if ((ascending & index >= (length - 1)) | (!ascending & index == 0)) begin
|
| 289 |
+
next_state <= FAULT;
|
| 290 |
+
end else begin
|
| 291 |
+
rd_req <= 1'b1;
|
| 292 |
+
target_idx <= ascending ? next_addr_rd_buf : pre_addr_rd_buf;
|
| 293 |
+
next_state <= FIND_INDEX;
|
| 294 |
+
end
|
| 295 |
+
end
|
| 296 |
+
FIND_VALUE: begin
|
| 297 |
+
if(data_rd_buf == data_in) begin
|
| 298 |
+
// update curr pos to invalid
|
| 299 |
+
wr_req <= 1'b1;
|
| 300 |
+
target_idx <= cur_ptr;
|
| 301 |
+
valid_wr <= 1'b0;
|
| 302 |
+
// update next_node_addr of pre pos to next pos
|
| 303 |
+
next_node_addr_idx <= pre_ptr;
|
| 304 |
+
next_node_addr_in <= next_addr_rd_buf;
|
| 305 |
+
// update pre_node_addr of next pos to pre pos
|
| 306 |
+
pre_node_addr_idx <= next_addr_rd_buf;
|
| 307 |
+
pre_node_addr_in <= pre_ptr;
|
| 308 |
+
next_state <= EXECUTE;
|
| 309 |
+
end else if (index >= (length - 1)) begin
|
| 310 |
+
next_state <= FAULT;
|
| 311 |
+
end else begin
|
| 312 |
+
rd_req <= 1'b1;
|
| 313 |
+
target_idx <= next_addr_rd_buf;
|
| 314 |
+
next_state <= FIND_VALUE;
|
| 315 |
+
end
|
| 316 |
+
end
|
| 317 |
+
INSERT_STG1: begin
|
| 318 |
+
wr_req <= 1'b1;
|
| 319 |
+
next_node_addr_idx <= cur_ptr; //new inserted node
|
| 320 |
+
next_node_addr_in <= pre_ptr;
|
| 321 |
+
pre_node_addr_idx <= pre_ptr;
|
| 322 |
+
pre_node_addr_in <= cur_ptr;
|
| 323 |
+
next_state <= EXECUTE;
|
| 324 |
+
end
|
| 325 |
+
EXECUTE: begin
|
| 326 |
+
op_done <= 1'b1;
|
| 327 |
+
fault <= op_is_read & !valid_rd_buf;
|
| 328 |
+
next_state <= IDLE;
|
| 329 |
+
end
|
| 330 |
+
FAULT: begin
|
| 331 |
+
fault <= 1'b1;
|
| 332 |
+
op_done <= 1'b1;
|
| 333 |
+
next_state <= IDLE;
|
| 334 |
+
end
|
| 335 |
+
default: begin
|
| 336 |
+
next_state <= IDLE;
|
| 337 |
+
end
|
| 338 |
+
endcase
|
| 339 |
+
end
|
| 340 |
+
|
| 341 |
+
always @ (posedge clk, posedge rst) begin
|
| 342 |
+
if (rst) begin
|
| 343 |
+
index <= 0;
|
| 344 |
+
end else if (state == FIND_VALUE) begin
|
| 345 |
+
index <= index + 1;
|
| 346 |
+
end else if (state == FIND_INDEX) begin
|
| 347 |
+
index <= ascending ? (index + 1) : (index - 1);
|
| 348 |
+
end else if (!ascending & next_state == FIND_INDEX) begin
|
| 349 |
+
index <= length - 1;
|
| 350 |
+
end else begin
|
| 351 |
+
index <= 0;
|
| 352 |
+
end
|
| 353 |
+
end
|
| 354 |
+
|
| 355 |
+
always @ (posedge clk, posedge rst) begin
|
| 356 |
+
if (rst) begin
|
| 357 |
+
data_rd_buf <= {DATA_WIDTH{1'b0}};
|
| 358 |
+
valid_rd_buf <= 1'b0;
|
| 359 |
+
next_addr_rd_buf <= {ADDR_WIDTH{1'b0}};
|
| 360 |
+
pre_addr_rd_buf <= {ADDR_WIDTH{1'b0}};
|
| 361 |
+
end else if (rd_req) begin
|
| 362 |
+
data_rd_buf <= node_data[target_idx];
|
| 363 |
+
valid_rd_buf <= node_valid[target_idx];
|
| 364 |
+
next_addr_rd_buf <= node_next_node_addr[target_idx];
|
| 365 |
+
pre_addr_rd_buf <= node_pre_node_addr[target_idx];
|
| 366 |
+
end
|
| 367 |
+
end
|
| 368 |
+
|
| 369 |
+
always @ (posedge clk, posedge rst) begin
|
| 370 |
+
if (rst) begin
|
| 371 |
+
data_out <= {DATA_WIDTH{1'b0}};
|
| 372 |
+
next_node_addr <= ADDR_NULL;
|
| 373 |
+
pre_node_addr <= ADDR_NULL;
|
| 374 |
+
end else if (op_is_read & (next_state == EXECUTE)) begin
|
| 375 |
+
data_out <= node_data[target_idx];
|
| 376 |
+
next_node_addr <= (addr_in == tail) ? ADDR_NULL : node_next_node_addr[target_idx];
|
| 377 |
+
pre_node_addr <= (addr_in == head) ? ADDR_NULL : node_pre_node_addr[target_idx];
|
| 378 |
+
end
|
| 379 |
+
end
|
| 380 |
+
|
| 381 |
+
always @ (posedge clk, posedge rst) begin
|
| 382 |
+
if (rst) begin
|
| 383 |
+
cur_ptr <= ADDR_NULL;
|
| 384 |
+
pre_ptr <= ADDR_NULL;
|
| 385 |
+
end else if(next_state == IDLE) begin
|
| 386 |
+
cur_ptr <= ADDR_NULL;
|
| 387 |
+
pre_ptr <= ADDR_NULL;
|
| 388 |
+
end
|
| 389 |
+
else if (rd_req | wr_req) begin
|
| 390 |
+
cur_ptr <= target_idx;
|
| 391 |
+
pre_ptr <= cur_ptr;
|
| 392 |
+
end
|
| 393 |
+
end
|
| 394 |
+
|
| 395 |
+
genvar j;
|
| 396 |
+
// Status
|
| 397 |
+
generate
|
| 398 |
+
for (j = 0; j < MAX_NODE; j = j+1) begin
|
| 399 |
+
assign valid_bits[j] = node_valid[j];
|
| 400 |
+
end
|
| 401 |
+
endgenerate
|
| 402 |
+
|
| 403 |
+
assign full = & valid_bits;
|
| 404 |
+
assign empty = ~(| valid_bits);
|
| 405 |
+
|
| 406 |
+
always @ (posedge clk or posedge rst) begin
|
| 407 |
+
if (rst) begin
|
| 408 |
+
head <= ADDR_NULL;
|
| 409 |
+
end else if ((op_is_insert_at_addr | op_is_insert_at_index) & ((addr_in == head_idx_sel) | empty) & (next_state == EXECUTE)) begin //INVALID addr
|
| 410 |
+
head <= find_next_ptr(valid_bits);
|
| 411 |
+
end else if ((op_is_delete_by_value | op_is_delete_by_addr | op_is_delete_by_index) & (next_state == EXECUTE) & (length == 1)) begin
|
| 412 |
+
head <= ADDR_NULL;
|
| 413 |
+
end else if ((op_is_delete_by_addr | op_is_delete_by_index) & (addr_in == head_idx_sel) & (next_state == EXECUTE)) begin
|
| 414 |
+
head <= next_addr_rd_buf;
|
| 415 |
+
end else if (op_is_delete_by_value & (cur_ptr == head) & (next_state == EXECUTE)) begin
|
| 416 |
+
head <= next_addr_rd_buf;
|
| 417 |
+
end
|
| 418 |
+
end
|
| 419 |
+
|
| 420 |
+
always @ (posedge clk or posedge rst) begin
|
| 421 |
+
if (rst) begin
|
| 422 |
+
tail <= ADDR_NULL;
|
| 423 |
+
end else if ((op_is_insert_at_addr | op_is_insert_at_index) & (addr_overflow | empty) & (next_state == EXECUTE)) begin
|
| 424 |
+
tail <= find_next_ptr(valid_bits);
|
| 425 |
+
end else if ((op_is_delete_by_value | op_is_delete_by_addr | op_is_delete_by_index) & (next_state == EXECUTE) & (length == 1)) begin
|
| 426 |
+
tail <= ADDR_NULL;
|
| 427 |
+
end else if ((op_is_delete_by_addr | op_is_delete_by_index) & (addr_in == tail_idx_sel) & (next_state == EXECUTE)) begin
|
| 428 |
+
tail <= pre_ptr;
|
| 429 |
+
end else if (op_is_delete_by_value & (cur_ptr == tail) & (next_state == EXECUTE)) begin
|
| 430 |
+
tail <= pre_ptr;
|
| 431 |
+
end
|
| 432 |
+
end
|
| 433 |
+
|
| 434 |
+
always @ (posedge clk or posedge rst) begin
|
| 435 |
+
if (rst) begin
|
| 436 |
+
length <= 0;
|
| 437 |
+
end else if ((op_is_insert_at_addr | op_is_insert_at_index) & (next_state == EXECUTE)) begin
|
| 438 |
+
length <= length + 1;
|
| 439 |
+
end else if ((op_is_delete_by_addr | op_is_delete_by_index)& (next_state == EXECUTE)) begin
|
| 440 |
+
length <= length - 1;
|
| 441 |
+
end else if (op_is_delete_by_value & (next_state == EXECUTE)) begin
|
| 442 |
+
length <= length - 1;
|
| 443 |
+
end
|
| 444 |
+
end
|
| 445 |
+
|
| 446 |
+
function integer find_next_ptr(input integer valid_bits);
|
| 447 |
+
integer done;
|
| 448 |
+
done = 0;
|
| 449 |
+
find_next_ptr = 0;
|
| 450 |
+
for (i = 0; i < MAX_NODE ; i = i+1) begin
|
| 451 |
+
if(valid_bits[i] == 0 & done == 0) begin
|
| 452 |
+
find_next_ptr = i;
|
| 453 |
+
done = 1;
|
| 454 |
+
end
|
| 455 |
+
end
|
| 456 |
+
endfunction
|
| 457 |
+
|
| 458 |
+
endmodule
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/src/rtl_list.f
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
doubly_linked_list.sv
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/cocotb/Makefile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SIM ?= icarus
|
| 2 |
+
TOPLEVEL_LANG ?= verilog
|
| 3 |
+
WAVES ?= 1 #set 1 to enable waveform dump.
|
| 4 |
+
|
| 5 |
+
PWD=$(shell pwd)
|
| 6 |
+
|
| 7 |
+
#export PYTHONPATH := $(PWD)/../model:$(PYTHONPATH)
|
| 8 |
+
|
| 9 |
+
VERILOG_SOURCES = $(PWD)/../../src/doubly_linked_list.sv
|
| 10 |
+
|
| 11 |
+
# DUT Top
|
| 12 |
+
TOPLEVEL = doubly_linked_list
|
| 13 |
+
# top python file name
|
| 14 |
+
MODULE = tb
|
| 15 |
+
|
| 16 |
+
#use , separtor to run multiple TESTCASE, by default all @cocotb.test will be run
|
| 17 |
+
#TESTCASE = index_op_test , addr_op_test
|
| 18 |
+
|
| 19 |
+
COMPILE_ARGS = -Ptable_top.DATA_WIDTH=8 # DUT parameter #"-p" (parameter) iverilog command flags
|
| 20 |
+
COMPILE_ARGS += -Ptable_top.MAX_NODE=8 # DUT parameter #"-p" (parameter) iverilog command flags
|
| 21 |
+
#run make clean before running with new parameter.
|
| 22 |
+
|
| 23 |
+
#Set RANDOM_SEED number
|
| 24 |
+
#PLUSARGS = +seed=1716033254
|
| 25 |
+
COCOTB_HDL_TIMEUNIT = 1ns
|
| 26 |
+
COCOTB_HDL_TIMEPRECISION = 1ps
|
| 27 |
+
|
| 28 |
+
ifeq ($(SIM), icarus)
|
| 29 |
+
$(shell echo 'module iverilog_dump();' > iverilog_dump.v)
|
| 30 |
+
$(shell echo 'initial begin' >> iverilog_dump.v)
|
| 31 |
+
$(shell echo ' $$dumpfile("$(TOPLEVEL).vcd");' >> iverilog_dump.v)
|
| 32 |
+
$(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
|
| 33 |
+
$(shell echo 'end' >> iverilog_dump.v)
|
| 34 |
+
$(shell echo 'endmodule' >> iverilog_dump.v)
|
| 35 |
+
VERILOG_SOURCES += $(PWD)/iverilog_dump.v
|
| 36 |
+
COMPILE_ARGS += -s iverilog_dump
|
| 37 |
+
endif
|
| 38 |
+
|
| 39 |
+
include $(shell cocotb-config --makefiles)/Makefile.sim
|
| 40 |
+
|
| 41 |
+
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/cocotb/tb.py
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
#import asyncio
|
| 3 |
+
import math
|
| 4 |
+
import cocotb
|
| 5 |
+
import cocotb.result
|
| 6 |
+
from cocotb.triggers import Timer, RisingEdge, ReadOnly
|
| 7 |
+
from cocotb.clock import Clock
|
| 8 |
+
from cocotb_bus.drivers import BusDriver
|
| 9 |
+
from cocotb_bus.monitors import BusMonitor
|
| 10 |
+
from cocotb.binary import BinaryValue
|
| 11 |
+
|
| 12 |
+
#BIN string
|
| 13 |
+
#BinaryValue(dut.data_wr.value, n_bits=8) ; BinaryValue.integar ; BinaryValue.hex ; BinaryValue.binstr; BinaryValue.signed_integer ; can represent x,z
|
| 14 |
+
|
| 15 |
+
DATA_WIDTH = 8 # DUT paramter
|
| 16 |
+
MAX_NODE = 8 # DUT paramter
|
| 17 |
+
|
| 18 |
+
ADDR_NULL = MAX_NODE + 1
|
| 19 |
+
MAX_DATA = 2**DATA_WIDTH - 1
|
| 20 |
+
|
| 21 |
+
OP_Read = 0b000
|
| 22 |
+
OP_Insert_At_Addr = 0b001
|
| 23 |
+
OP_Insert_At_Index = 0b101
|
| 24 |
+
OP_Delete_Value = 0b010
|
| 25 |
+
OP_Delete_At_Addr = 0b011
|
| 26 |
+
OP_Delete_At_Index = 0b111;
|
| 27 |
+
|
| 28 |
+
TB_CLK_PERIOD = 30 # TB clk generator
|
| 29 |
+
TB_SIM_TIMEOUT = 30 # TB sim timeout 30ms
|
| 30 |
+
TB_TEST_WEIGHT = 1
|
| 31 |
+
err_cnt = 0
|
| 32 |
+
|
| 33 |
+
# doubly_linked_list #(.DATA_WIDTH(DUT_DATA_WIDTH),.MAX_NODE(DUT_MAX_NODE)) DUT
|
| 34 |
+
# ( /*input*/ .rst(rst),
|
| 35 |
+
# /*input*/ .clk(clk),
|
| 36 |
+
# /*input [DATA_WIDTH-1:0]*/ .data_in(data_in),
|
| 37 |
+
# /*input [ADDR_WIDTH-1:0]*/ .addr_in(addr_in),
|
| 38 |
+
# /*input [1:0]*/ .op(op), // 0: Read(addr_in); 1: Delete_Value(data_in); 2: Push_Back(data_in); 3: Push_front(data_in)
|
| 39 |
+
# /*input*/ .op_start(op_start),
|
| 40 |
+
# /*output reg [DATA_WIDTH-1:0]*/ .data_out(data_out),
|
| 41 |
+
# /*output reg*/ .op_done(op_done),
|
| 42 |
+
# /*output wire [ADDR_WIDTH-1:0]*/ .pre_node_addr(pre_node_addr),// Addr of pre node
|
| 43 |
+
# /*output wire [ADDR_WIDTH-1:0]*/ .next_node_addr(next_node_addr), // Addr of next node
|
| 44 |
+
# // status
|
| 45 |
+
# /*output reg [ADDR_WIDTH-1:0]*/ .length(length),
|
| 46 |
+
# /*output wire*/ .full(full),
|
| 47 |
+
# /*output reg [ADDR_WIDTH-1:0]*/ .head(head), // Addr of head
|
| 48 |
+
# /*output reg [ADDR_WIDTH-1:0]*/ .tail(tail), // Addr of head
|
| 49 |
+
# /*output wire*/ .empty(empty),
|
| 50 |
+
# /*output reg*/ .fault(fault) // Invalid Errors
|
| 51 |
+
# );
|
| 52 |
+
|
| 53 |
+
# Actual Python linked_list class: https://www.datacamp.com/tutorial/python-linked-lists
|
| 54 |
+
# To mimic harware linked_list, we need to keep track of the address of each node, model in below way also for our ease of debug.
|
| 55 |
+
class doubly_linked_list:
|
| 56 |
+
def __init__(self, dut):
|
| 57 |
+
self.dut = dut
|
| 58 |
+
self.linked_list_value = []
|
| 59 |
+
self.linked_list_addr = []
|
| 60 |
+
|
| 61 |
+
def remove(self, index):
|
| 62 |
+
self.linked_list_value.pop(index)
|
| 63 |
+
self.linked_list_addr.pop(index)
|
| 64 |
+
|
| 65 |
+
def find_next_addr(self):
|
| 66 |
+
for i in range(len(self.linked_list_addr)+2):
|
| 67 |
+
if i not in self.linked_list_addr:
|
| 68 |
+
return i
|
| 69 |
+
|
| 70 |
+
def insert_by_addr(self, addr, data):
|
| 71 |
+
if(addr == -1):
|
| 72 |
+
self.linked_list_value.append(data)
|
| 73 |
+
self.linked_list_addr.append(self.find_next_addr())
|
| 74 |
+
else:
|
| 75 |
+
self.linked_list_value.insert(self.linked_list_addr.index(addr), data)
|
| 76 |
+
self.linked_list_addr.insert(self.linked_list_addr.index(addr), self.find_next_addr())
|
| 77 |
+
|
| 78 |
+
def insert_by_index(self, index, data):
|
| 79 |
+
if(index == -1):
|
| 80 |
+
self.linked_list_value.append(data)
|
| 81 |
+
self.linked_list_addr.append(self.find_next_addr())
|
| 82 |
+
else:
|
| 83 |
+
self.linked_list_value.insert(index, data)
|
| 84 |
+
self.linked_list_addr.insert(index, self.find_next_addr())
|
| 85 |
+
|
| 86 |
+
def delete_by_value(self, data):
|
| 87 |
+
self.linked_list_addr.remove(self.linked_list_value.index(data))
|
| 88 |
+
self.linked_list_value.remove(data)
|
| 89 |
+
|
| 90 |
+
def delete_by_addr(self, addr):
|
| 91 |
+
self.linked_list_value.pop(self.linked_list_addr.index(addr))
|
| 92 |
+
self.linked_list_addr.pop(self.linked_list_addr.index(addr))
|
| 93 |
+
|
| 94 |
+
def read_by_addr(self, addr):
|
| 95 |
+
return self.linked_list_value[self.linked_list_addr.index(addr)]
|
| 96 |
+
|
| 97 |
+
def print_content(self):
|
| 98 |
+
cocotb.log.info(f"Linked List Content: value = {self.linked_list_value}, addr = {self.linked_list_addr}")
|
| 99 |
+
|
| 100 |
+
async def read_n_front(dut, list_exp, n):
|
| 101 |
+
global err_cnt
|
| 102 |
+
cocotb.log.info("OP_Read %0d values", n)
|
| 103 |
+
i = 0
|
| 104 |
+
await RisingEdge(dut.clk)
|
| 105 |
+
await Timer (1, units = 'ns')
|
| 106 |
+
dut.op.value = OP_Read
|
| 107 |
+
dut.op_start.value = 1
|
| 108 |
+
dut.addr_in.value = dut.head.value
|
| 109 |
+
i = i + 1
|
| 110 |
+
while (i <= n):
|
| 111 |
+
await RisingEdge(dut.clk)
|
| 112 |
+
await Timer (1, units = 'ns')
|
| 113 |
+
if (dut.op_done.value == 1):
|
| 114 |
+
if( (i-1) >= len(list_exp.linked_list_addr)):
|
| 115 |
+
if(dut.fault.value == 1):
|
| 116 |
+
cocotb.log.info("Data read out of bound, fault flag is asserted correctly")
|
| 117 |
+
else:
|
| 118 |
+
cocotb.log.error("Data read out of bound, fault flag is not asserted")
|
| 119 |
+
err_cnt += 1
|
| 120 |
+
elif (list_exp.linked_list_value[i-1] == dut.data_out.value):
|
| 121 |
+
cocotb.log.info("Data read : %0d at Index %0d", dut.data_out.value, i-1)
|
| 122 |
+
else:
|
| 123 |
+
cocotb.log.error("Data read at Index %0d is Correct, ACT: %0d, EXP: %0d", i-1, dut.data_out.value, list_exp.linked_list_value[i-1])
|
| 124 |
+
err_cnt += 1
|
| 125 |
+
if(i==n):
|
| 126 |
+
dut.op_start.value = 0
|
| 127 |
+
dut.addr_in.value = dut.next_node_addr.value
|
| 128 |
+
i = i + 1
|
| 129 |
+
list_exp.print_content()
|
| 130 |
+
|
| 131 |
+
async def read_n_back(dut, list_exp, n):
|
| 132 |
+
global err_cnt
|
| 133 |
+
cocotb.log.info("OP_Read %0d values", n)
|
| 134 |
+
i = 0
|
| 135 |
+
await RisingEdge(dut.clk)
|
| 136 |
+
await Timer (1, units = 'ns')
|
| 137 |
+
dut.op.value = OP_Read
|
| 138 |
+
dut.op_start.value = 1
|
| 139 |
+
dut.addr_in.value = dut.tail.value
|
| 140 |
+
i = i + 1
|
| 141 |
+
while (i <= n):
|
| 142 |
+
await RisingEdge(dut.clk)
|
| 143 |
+
await Timer (1, units = 'ns')
|
| 144 |
+
if (dut.op_done.value == 1):
|
| 145 |
+
if( (i-1) >= len(list_exp.linked_list_addr)):
|
| 146 |
+
if(dut.fault.value == 1):
|
| 147 |
+
cocotb.log.info("Data read out of bound, fault flag is asserted correctly")
|
| 148 |
+
else:
|
| 149 |
+
cocotb.log.error("Data read out of bound, fault flag is not asserted")
|
| 150 |
+
err_cnt += 1
|
| 151 |
+
elif (list_exp.linked_list_value[-i] == dut.data_out.value):
|
| 152 |
+
cocotb.log.info("Data read : %0d at Index %0d", dut.data_out.value, len(list_exp.linked_list_addr)-1-(i-1))
|
| 153 |
+
else:
|
| 154 |
+
cocotb.log.error("Data read at Index %0d is Correct, ACT: %0d, EXP: %0d", i-1, dut.data_out.value, list_exp.linked_list_value[-i])
|
| 155 |
+
err_cnt += 1
|
| 156 |
+
if(i==n):
|
| 157 |
+
dut.op_start.value = 0
|
| 158 |
+
dut.addr_in.value = dut.pre_node_addr.value
|
| 159 |
+
i = i + 1
|
| 160 |
+
list_exp.print_content()
|
| 161 |
+
|
| 162 |
+
async def delete_value(dut, list_exp, value):
|
| 163 |
+
global err_cnt
|
| 164 |
+
cocotb.log.info("OP_Delete_Value %0d value", value)
|
| 165 |
+
i = 0
|
| 166 |
+
found = 0
|
| 167 |
+
await RisingEdge(dut.clk)
|
| 168 |
+
await Timer (1, units = 'ns')
|
| 169 |
+
dut.op.value = OP_Delete_Value
|
| 170 |
+
dut.data_in.value = value
|
| 171 |
+
dut.op_start.value = 1
|
| 172 |
+
await RisingEdge(dut.op_done)
|
| 173 |
+
await Timer (1, units = 'ns')
|
| 174 |
+
for i in range(len(list_exp.linked_list_addr)):
|
| 175 |
+
if list_exp.linked_list_value[i] == value:
|
| 176 |
+
cocotb.log.info("Data %0d at Index %0d is Deleted_by_Value", value, i)
|
| 177 |
+
list_exp.remove(i)
|
| 178 |
+
found = 1
|
| 179 |
+
break
|
| 180 |
+
if found == 0:
|
| 181 |
+
if(dut.fault.value == 1):
|
| 182 |
+
cocotb.log.info("Data delete out of bound, fault flag is asserted correctly")
|
| 183 |
+
else:
|
| 184 |
+
cocotb.log.error("Data delete out of bound, fault flag is not asserted")
|
| 185 |
+
err_cnt += 1
|
| 186 |
+
else:
|
| 187 |
+
if(dut.fault.value == 1):
|
| 188 |
+
cocotb.log.error("Data delete in bound, fault flag is asserted incorrectly")
|
| 189 |
+
err_cnt += 1
|
| 190 |
+
dut.op_start.value = 0
|
| 191 |
+
list_exp.print_content()
|
| 192 |
+
|
| 193 |
+
async def delete_at_index(dut, list_exp, index):
|
| 194 |
+
global err_cnt
|
| 195 |
+
cocotb.log.info("OP_Delete_At_Index %0d index", index)
|
| 196 |
+
await RisingEdge(dut.clk)
|
| 197 |
+
await Timer (1, units = 'ns')
|
| 198 |
+
dut.op.value = OP_Delete_At_Index
|
| 199 |
+
dut.addr_in.value = index
|
| 200 |
+
dut.op_start.value = 1
|
| 201 |
+
await RisingEdge(dut.op_done)
|
| 202 |
+
await Timer (1, units = 'ns')
|
| 203 |
+
if (index >= len(list_exp.linked_list_addr)):
|
| 204 |
+
if(dut.fault.value == 1):
|
| 205 |
+
cocotb.log.info("Data delete out of bound, fault flag is asserted correctly")
|
| 206 |
+
else:
|
| 207 |
+
cocotb.log.error("Data delete out of bound, fault flag is not asserted")
|
| 208 |
+
err_cnt += 1
|
| 209 |
+
elif (index == 0):
|
| 210 |
+
if(dut.fault.value == 1):
|
| 211 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 212 |
+
err_cnt += 1
|
| 213 |
+
cocotb.log.info("Data %0d at Front is Deleted_by_Index", list_exp.linked_list_value[0])
|
| 214 |
+
list_exp.remove(0)
|
| 215 |
+
else:
|
| 216 |
+
if(dut.fault.value == 1):
|
| 217 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 218 |
+
err_cnt += 1
|
| 219 |
+
cocotb.log.info("Data %0d at Index %0d is Deleted_by_Index", list_exp.linked_list_value[index], index)
|
| 220 |
+
list_exp.remove(index)
|
| 221 |
+
dut.op_start.value = 0
|
| 222 |
+
list_exp.print_content()
|
| 223 |
+
|
| 224 |
+
async def insert_at_index(dut, list_exp, index, data):
|
| 225 |
+
global err_cnt
|
| 226 |
+
cocotb.log.info("OP_Insert_At_Index %0d index, %0d data", index, data)
|
| 227 |
+
await RisingEdge(dut.clk)
|
| 228 |
+
await Timer (1, units = 'ns')
|
| 229 |
+
dut.op.value = OP_Insert_At_Index
|
| 230 |
+
dut.addr_in.value = index
|
| 231 |
+
dut.data_in.value = data
|
| 232 |
+
dut.op_start.value = 1
|
| 233 |
+
await RisingEdge(dut.op_done)
|
| 234 |
+
await Timer (1, units = 'ns')
|
| 235 |
+
if (len(list_exp.linked_list_value) >= MAX_NODE):
|
| 236 |
+
if(dut.fault.value == 1):
|
| 237 |
+
cocotb.log.info("Data insert out of bound, fault flag is asserted correctly")
|
| 238 |
+
else:
|
| 239 |
+
cocotb.log.error("Data insert out of bound, fault flag is not asserted")
|
| 240 |
+
err_cnt += 1
|
| 241 |
+
elif (index == 0):
|
| 242 |
+
if(dut.fault.value == 1):
|
| 243 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 244 |
+
err_cnt += 1
|
| 245 |
+
list_exp.insert_by_index(0, data)
|
| 246 |
+
cocotb.log.info("Data %0d at Front is Inserted_by_Index", data)
|
| 247 |
+
elif (index >= len(list_exp.linked_list_value)):
|
| 248 |
+
if(dut.fault.value == 1):
|
| 249 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 250 |
+
err_cnt += 1
|
| 251 |
+
list_exp.insert_by_index(-1, data)
|
| 252 |
+
cocotb.log.info("Data %0d at End is Inserted_by_Index", data)
|
| 253 |
+
else:
|
| 254 |
+
if(dut.fault.value == 1):
|
| 255 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 256 |
+
err_cnt += 1
|
| 257 |
+
list_exp.insert_by_index(index, data)
|
| 258 |
+
cocotb.log.info("Data %0d at Index %0d is Inserted_by_Index", data, index)
|
| 259 |
+
if(len(list_exp.linked_list_value) >= MAX_NODE):
|
| 260 |
+
if(dut.full.value == 1):
|
| 261 |
+
cocotb.log.info("Full flag is asserted correctly")
|
| 262 |
+
else:
|
| 263 |
+
cocotb.log.error("Full flag is not asserted")
|
| 264 |
+
err_cnt += 1
|
| 265 |
+
elif (dut.full.value == 1):
|
| 266 |
+
cocotb.log.error("Full flag is asserted incorrectly")
|
| 267 |
+
err_cnt += 1
|
| 268 |
+
dut.op_start.value = 0
|
| 269 |
+
list_exp.print_content()
|
| 270 |
+
|
| 271 |
+
async def delete_at_addr (dut, list_exp, addr):
|
| 272 |
+
global err_cnt
|
| 273 |
+
cocotb.log.info("OP_Delete_At_Addr %0d addr", addr)
|
| 274 |
+
await RisingEdge(dut.clk)
|
| 275 |
+
await Timer (1, units = 'ns')
|
| 276 |
+
dut.op.value = OP_Delete_At_Addr
|
| 277 |
+
dut.addr_in.value = addr
|
| 278 |
+
dut.op_start.value = 1
|
| 279 |
+
pre_head = int(dut.head.value)
|
| 280 |
+
pre_tail = int(dut.tail.value)
|
| 281 |
+
|
| 282 |
+
await RisingEdge(dut.op_done)
|
| 283 |
+
await Timer (1, units = 'ns')
|
| 284 |
+
if (addr >= ADDR_NULL):
|
| 285 |
+
if(dut.fault.value == 1):
|
| 286 |
+
cocotb.log.info("Data delete out of bound, fault flag is asserted correctly")
|
| 287 |
+
else:
|
| 288 |
+
cocotb.log.error("Data delete out of bound, fault flag is not asserted")
|
| 289 |
+
err_cnt += 1
|
| 290 |
+
elif (addr == pre_head):
|
| 291 |
+
if(dut.fault.value == 1):
|
| 292 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 293 |
+
err_cnt += 1
|
| 294 |
+
cocotb.log.info("Data %0d at Front is Deleted_by_Addr", list_exp.linked_list_value[0])
|
| 295 |
+
list_exp.remove(0)
|
| 296 |
+
elif (addr == pre_tail):
|
| 297 |
+
if(dut.fault.value == 1):
|
| 298 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 299 |
+
err_cnt += 1
|
| 300 |
+
cocotb.log.info("Data %0d at Back is Deleted_by_Addr", list_exp.linked_list_value[0])
|
| 301 |
+
list_exp.remove(-1)
|
| 302 |
+
else:
|
| 303 |
+
if(addr not in list_exp.linked_list_addr):
|
| 304 |
+
if(dut.fault.value == 0):
|
| 305 |
+
cocotb.log.error("Fault flag is not asserted")
|
| 306 |
+
err_cnt += 1
|
| 307 |
+
else:
|
| 308 |
+
if(dut.fault.value == 1):
|
| 309 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 310 |
+
err_cnt += 1
|
| 311 |
+
cocotb.log.info("Data %0d at Addr %0d is Inserted_by_Addr", list_exp.linked_list_value[list_exp.linked_list_addr.index(addr)], addr)
|
| 312 |
+
list_exp.delete_by_addr(addr)
|
| 313 |
+
if(len(list_exp.linked_list_value) == 0):
|
| 314 |
+
if(dut.empty.value == 1):
|
| 315 |
+
cocotb.log.info("Full flag is asserted correctly")
|
| 316 |
+
else:
|
| 317 |
+
cocotb.log.error("Full flag is not asserted")
|
| 318 |
+
err_cnt += 1
|
| 319 |
+
elif (dut.empty.value == 1):
|
| 320 |
+
cocotb.log.error("Full flag is asserted incorrectly")
|
| 321 |
+
err_cnt += 1
|
| 322 |
+
dut.op_start.value = 0
|
| 323 |
+
list_exp.print_content()
|
| 324 |
+
|
| 325 |
+
async def insert_at_addr(dut, list_exp, addr, data):
|
| 326 |
+
global err_cnt
|
| 327 |
+
cocotb.log.info("OP_Insert_At_Addr %0d addr, %0d data", addr, data)
|
| 328 |
+
await RisingEdge(dut.clk)
|
| 329 |
+
await Timer (1, units = 'ns')
|
| 330 |
+
dut.op.value = OP_Insert_At_Addr
|
| 331 |
+
dut.addr_in.value = addr
|
| 332 |
+
dut.data_in.value = data
|
| 333 |
+
dut.op_start.value = 1
|
| 334 |
+
pre_head = int(dut.head.value)
|
| 335 |
+
pre_tail = int(dut.tail.value)
|
| 336 |
+
|
| 337 |
+
await RisingEdge(dut.op_done)
|
| 338 |
+
await Timer (1, units = 'ns')
|
| 339 |
+
if (len(list_exp.linked_list_value) >= MAX_NODE):
|
| 340 |
+
if(dut.fault.value == 1):
|
| 341 |
+
cocotb.log.info("Data insert out of bound, fault flag is asserted correctly")
|
| 342 |
+
else:
|
| 343 |
+
cocotb.log.error("Data insert out of bound, fault flag is not asserted")
|
| 344 |
+
err_cnt += 1
|
| 345 |
+
elif (addr >= ADDR_NULL):
|
| 346 |
+
if(dut.fault.value == 1):
|
| 347 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 348 |
+
err_cnt += 1
|
| 349 |
+
list_exp.insert_by_addr(-1, data)
|
| 350 |
+
cocotb.log.info("Data %0d at End is Inserted_by_Addr", data)
|
| 351 |
+
elif (addr == pre_head):
|
| 352 |
+
if(dut.fault.value == 1):
|
| 353 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 354 |
+
err_cnt += 1
|
| 355 |
+
list_exp.insert_by_addr(addr, data)
|
| 356 |
+
cocotb.log.info("Data %0d at Front is Inserted_by_Addr", data)
|
| 357 |
+
elif (addr == pre_tail):
|
| 358 |
+
if(dut.fault.value == 1):
|
| 359 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 360 |
+
err_cnt += 1
|
| 361 |
+
list_exp.insert_by_index(len(list_exp.linked_list_value)-1, data)
|
| 362 |
+
cocotb.log.info("Data %0d at End is Inserted_by_Addr", data)
|
| 363 |
+
else:
|
| 364 |
+
if(addr not in list_exp.linked_list_addr):
|
| 365 |
+
if(dut.fault.value == 0):
|
| 366 |
+
cocotb.log.error("Fault flag is not asserted")
|
| 367 |
+
err_cnt += 1
|
| 368 |
+
else:
|
| 369 |
+
if(dut.fault.value == 1):
|
| 370 |
+
cocotb.log.error("Fault flag is asserted incorrectly")
|
| 371 |
+
err_cnt += 1
|
| 372 |
+
list_exp.insert_by_addr(addr, data)
|
| 373 |
+
cocotb.log.info("Data %0d at Addr %0d is Inserted_by_Addr", data, addr)
|
| 374 |
+
if(len(list_exp.linked_list_value) >= MAX_NODE):
|
| 375 |
+
if(dut.full.value == 1):
|
| 376 |
+
cocotb.log.info("Full flag is asserted correctly")
|
| 377 |
+
else:
|
| 378 |
+
cocotb.log.error("Full flag is not asserted")
|
| 379 |
+
err_cnt += 1
|
| 380 |
+
elif (dut.full.value == 1):
|
| 381 |
+
cocotb.log.error("Full flag is asserted incorrectly")
|
| 382 |
+
err_cnt += 1
|
| 383 |
+
dut.op_start.value = 0
|
| 384 |
+
list_exp.print_content()
|
| 385 |
+
|
| 386 |
+
async def dut_init(dut):
|
| 387 |
+
global DATA_WIDTH # DUT paramter
|
| 388 |
+
global MAX_NODE # DUT paramter
|
| 389 |
+
global ADDR_NULL
|
| 390 |
+
global MAX_DATA
|
| 391 |
+
DATA_WIDTH = dut.DATA_WIDTH.value
|
| 392 |
+
MAX_NODE = dut.MAX_NODE.value
|
| 393 |
+
ADDR_NULL = MAX_NODE
|
| 394 |
+
MAX_DATA = 2**DATA_WIDTH - 1
|
| 395 |
+
await cocotb.start(Clock(dut.clk, TB_CLK_PERIOD, units="ns").start())
|
| 396 |
+
dut.data_in.value = 0
|
| 397 |
+
dut.addr_in.value = 0
|
| 398 |
+
dut.op.value = 0
|
| 399 |
+
dut.op_start.value = 0
|
| 400 |
+
dut.rst.value = 1
|
| 401 |
+
await(Timer(100,'ns'))
|
| 402 |
+
dut.rst.value = 0
|
| 403 |
+
await(Timer(100,'ns'))
|
| 404 |
+
|
| 405 |
+
@cocotb.test()
|
| 406 |
+
async def index_op_test(dut):
|
| 407 |
+
await dut_init(dut)
|
| 408 |
+
list_exp = doubly_linked_list(dut)
|
| 409 |
+
cocotb.log.info("SEED NUMBER = %d",cocotb.RANDOM_SEED)
|
| 410 |
+
await insert_at_index(dut,list_exp,0,3)
|
| 411 |
+
await insert_at_index(dut,list_exp,0,0)
|
| 412 |
+
await Timer(200, units = 'ns')
|
| 413 |
+
await insert_at_index(dut,list_exp,4,5)
|
| 414 |
+
await insert_at_index(dut,list_exp,0,6)
|
| 415 |
+
await insert_at_index(dut,list_exp,0,7)
|
| 416 |
+
await insert_at_index(dut,list_exp,1,3)
|
| 417 |
+
await insert_at_index(dut,list_exp,2,4)
|
| 418 |
+
await insert_at_index(dut,list_exp,ADDR_NULL,3)
|
| 419 |
+
await insert_at_index(dut,list_exp,ADDR_NULL,4)
|
| 420 |
+
await insert_at_index(dut,list_exp,ADDR_NULL,1)
|
| 421 |
+
await insert_at_index(dut,list_exp,0,3)
|
| 422 |
+
await Timer(200, units = 'ns')
|
| 423 |
+
await read_n_front(dut,list_exp,len(list_exp.linked_list_value))
|
| 424 |
+
await read_n_back(dut,list_exp,len(list_exp.linked_list_value))
|
| 425 |
+
await Timer(200, units = 'ns')
|
| 426 |
+
await delete_value(dut,list_exp,7)
|
| 427 |
+
await delete_at_index(dut,list_exp,0)
|
| 428 |
+
await delete_at_index(dut,list_exp,0)
|
| 429 |
+
await delete_value(dut,list_exp,2)
|
| 430 |
+
await delete_value(dut,list_exp,4)
|
| 431 |
+
await delete_at_index(dut,list_exp,0)
|
| 432 |
+
await delete_at_index(dut,list_exp,7)
|
| 433 |
+
await delete_at_index(dut,list_exp,dut.length.value-1)
|
| 434 |
+
await delete_at_index(dut,list_exp,dut.length.value-1)
|
| 435 |
+
await delete_at_index(dut,list_exp,0)
|
| 436 |
+
await delete_at_index(dut,list_exp,0)
|
| 437 |
+
await delete_at_index(dut,list_exp,0)
|
| 438 |
+
await Timer(200, units = 'ns')
|
| 439 |
+
|
| 440 |
+
if (err_cnt > 0):
|
| 441 |
+
cocotb.log.error("Errors count = %d",err_cnt)
|
| 442 |
+
cocotb.result.TestFailure() #FIX ME
|
| 443 |
+
|
| 444 |
+
@cocotb.test()
|
| 445 |
+
async def addr_op_test(dut):
|
| 446 |
+
await dut_init(dut)
|
| 447 |
+
list_exp = doubly_linked_list(dut)
|
| 448 |
+
cocotb.log.info("SEED NUMBER = %d",cocotb.RANDOM_SEED)
|
| 449 |
+
await insert_at_addr(dut, list_exp, int(dut.head.value), 3)
|
| 450 |
+
await insert_at_addr(dut, list_exp, int(dut.head.value), 0)
|
| 451 |
+
await Timer(100, units='ns')
|
| 452 |
+
await insert_at_addr(dut, list_exp, int(dut.head.value), 5)
|
| 453 |
+
await insert_at_addr(dut, list_exp, int(dut.head.value), 6)
|
| 454 |
+
await insert_at_addr(dut, list_exp, list_exp.linked_list_addr[2], 7)
|
| 455 |
+
await insert_at_addr(dut, list_exp, 0, 3)
|
| 456 |
+
await insert_at_addr(dut, list_exp, int(dut.head.value), 4)
|
| 457 |
+
await insert_at_addr(dut, list_exp, int(dut.tail.value), 3)
|
| 458 |
+
await insert_at_addr(dut, list_exp, ADDR_NULL, 4)
|
| 459 |
+
await insert_at_addr(dut, list_exp, ADDR_NULL, 1)
|
| 460 |
+
await insert_at_addr(dut, list_exp, 0, 3)
|
| 461 |
+
await Timer(200, units='ns')
|
| 462 |
+
await read_n_front(dut, list_exp, len(list_exp.linked_list_value))
|
| 463 |
+
await read_n_back(dut, list_exp, len(list_exp.linked_list_value))
|
| 464 |
+
await Timer(500, units='ns')
|
| 465 |
+
await delete_value(dut, list_exp, 7)
|
| 466 |
+
await delete_at_addr(dut, list_exp, 0)
|
| 467 |
+
await delete_at_addr(dut, list_exp, 0)
|
| 468 |
+
await delete_value(dut, list_exp, 2)
|
| 469 |
+
await read_n_front(dut, list_exp, len(list_exp.linked_list_value))
|
| 470 |
+
await delete_value(dut, list_exp, 4)
|
| 471 |
+
await delete_at_addr(dut, list_exp, 0)
|
| 472 |
+
await delete_at_addr(dut, list_exp, 7)
|
| 473 |
+
await delete_at_addr(dut, list_exp, int(dut.head.value))
|
| 474 |
+
await delete_at_addr(dut, list_exp, int(dut.tail.value)-1)
|
| 475 |
+
await delete_at_addr(dut, list_exp, 0)
|
| 476 |
+
await Timer(500, units='ns')
|
| 477 |
+
|
| 478 |
+
if (err_cnt > 0):
|
| 479 |
+
cocotb.log.error("Errors count = %d",err_cnt)
|
| 480 |
+
cocotb.result.TestError() #FIX ME
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/sv/Makefile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
DUT ?= doubly_linked_list
|
| 3 |
+
SIM_OPTS ?= ../../src/doubly_linked_list.sv
|
| 4 |
+
SEED ?= $$(shuf -i 1-10000 -n 1)
|
| 5 |
+
|
| 6 |
+
# DUT parameter #"-p" iverilog command flags
|
| 7 |
+
# COMPILE_ARGS = -P tb.DUT_DATA_WIDTH=8
|
| 8 |
+
# COMPILE_ARGS += -P tb.DUT_MAX_NODE=8
|
| 9 |
+
# COMPILE_ARGS += -P tb.TB_CLK_PERIOD=25
|
| 10 |
+
# COMPILE_ARGS += -P tb.TB_TEST_WEIGHT=1
|
| 11 |
+
# COMPILE_ARGS += -P tb.TB_CLK_PERIOD=100
|
| 12 |
+
# COMPILE_ARGS += -P tb.SIM_TIMEOUT=500000
|
| 13 |
+
|
| 14 |
+
XILINX_LIB_URL ?= https://github.com/Xilinx/XilinxUnisimLibrary.git
|
| 15 |
+
XILINX_LIB_DIR ?= XilinxUnisimLibrary/verilog/src
|
| 16 |
+
|
| 17 |
+
sim: gen_sim
|
| 18 |
+
./${DUT}.sim +VCDFILE=sim.vcd +VCDLEVEL=0 +SEED=${SEED} | tee sim.log
|
| 19 |
+
|
| 20 |
+
gen_sim: tb.sv ${SIM_OPTS} # to generate executable file by using iverilator
|
| 21 |
+
iverilog -g2012 -s tb ${COMPILE_ARGS} -o ${DUT}.sim $^
|
| 22 |
+
|
| 23 |
+
synth: ${SIM_OPTS}
|
| 24 |
+
yosys -p synth_xilinx ${SIM_OPTS} -L synth.log -o ${DUT}.netlist.v
|
| 25 |
+
#timeout
|
| 26 |
+
|
| 27 |
+
netlist_sim: gen_netlist_sim
|
| 28 |
+
./${DUT}.netlist.sim +VCDFILE=netlist_sim.vcd +VCDLEVEL=0 +SEED=${SEED} | tee netlist_sim.log
|
| 29 |
+
|
| 30 |
+
gen_netlist_sim: tb.sv ${DUT}.netlist.v | ${XILINX_LIBS_DIR}/.got
|
| 31 |
+
iverilog -g2012 -s tb -y ${XILINX_LIB_DIR} -y ${XILINX_LIB_DIR}/unisims -DXILINX_GLS ${COMPILE_ARGS} -o ${DUT}.netlist.sim $^
|
| 32 |
+
|
| 33 |
+
${XILINX_LIBS_DIR}/.git:
|
| 34 |
+
git clone ${XILINX_LIB_URL}
|
| 35 |
+
|
| 36 |
+
clean:
|
| 37 |
+
rm -f ${DUT}_sim sim.log sim.vcd
|
| 38 |
+
rm -f ${DUT}.netlist.v synth.log
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/tb/sv/tb.sv
ADDED
|
@@ -0,0 +1,744 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
`timescale 1ns / 1ps
|
| 2 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 3 |
+
// Create Date: 09/22/2024 01:42:52 PM
|
| 4 |
+
// Module Name: tb
|
| 5 |
+
// Description: Supported Operation
|
| 6 |
+
// 0. Read_Addr(addr_in) -> data_out
|
| 7 |
+
// 1. Insert_At_Addr(addr_in, data_in)
|
| 8 |
+
// 5. Insert_At_Index(addr_in, data_in)
|
| 9 |
+
// 2. Delete_Value(data_in)
|
| 10 |
+
// 3. Delete_At_Addr(addr_in)
|
| 11 |
+
// 7. Delete_At_Index(addr_in)
|
| 12 |
+
// Additional Comments:
|
| 13 |
+
//
|
| 14 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
module tb(
|
| 18 |
+
);
|
| 19 |
+
// DUT parameter
|
| 20 |
+
localparam DUT_DATA_WIDTH = 8;
|
| 21 |
+
localparam DUT_MAX_NODE = 8;
|
| 22 |
+
// TB parameter
|
| 23 |
+
localparam TB_CLK_PERIOD = 25;
|
| 24 |
+
localparam ADDR_WIDTH = $clog2(DUT_MAX_NODE+1); // Reserve {ADDR_WIDTH(1'b1)} as NULL/INVALID ADDR
|
| 25 |
+
localparam MAX_DATA = 2**DUT_DATA_WIDTH - 1;
|
| 26 |
+
localparam TB_TEST_WEIGHT = 1;
|
| 27 |
+
localparam SIM_TIMEOUT = 500000;
|
| 28 |
+
|
| 29 |
+
localparam ADDR_NULL = (DUT_MAX_NODE);
|
| 30 |
+
|
| 31 |
+
localparam OP_Read = 3'b000;
|
| 32 |
+
localparam OP_Insert_At_Addr = 3'b001;
|
| 33 |
+
localparam OP_Insert_At_Index = 3'b101;
|
| 34 |
+
localparam OP_Delete_Value = 3'b010;
|
| 35 |
+
localparam OP_Delete_At_Addr = 3'b011;
|
| 36 |
+
localparam OP_Delete_At_Index = 3'b111;
|
| 37 |
+
|
| 38 |
+
integer err_cnt = 0;
|
| 39 |
+
|
| 40 |
+
// input
|
| 41 |
+
reg clk = 0;
|
| 42 |
+
reg rst = 0;
|
| 43 |
+
reg [DUT_DATA_WIDTH-1:0] data_in = 0;
|
| 44 |
+
reg [ADDR_WIDTH-1:0] addr_in = 0;
|
| 45 |
+
reg [2:0] op = 0;
|
| 46 |
+
reg op_start = 0;
|
| 47 |
+
// output
|
| 48 |
+
wire [DUT_DATA_WIDTH-1:0] data_out;
|
| 49 |
+
wire op_done;
|
| 50 |
+
wire [ADDR_WIDTH-1:0] pre_node_addr;
|
| 51 |
+
wire [ADDR_WIDTH-1:0] next_node_addr;
|
| 52 |
+
wire [ADDR_WIDTH-1:0] length;
|
| 53 |
+
wire [ADDR_WIDTH-1:0] head; // Addr of head
|
| 54 |
+
reg [ADDR_WIDTH-1:0] pre_head;
|
| 55 |
+
wire [ADDR_WIDTH-1:0] tail; // Addr of tail
|
| 56 |
+
reg [ADDR_WIDTH-1:0] pre_tail; // Addr of tail
|
| 57 |
+
wire full;
|
| 58 |
+
wire empty;
|
| 59 |
+
wire fault;
|
| 60 |
+
|
| 61 |
+
`ifdef XILINX_GLS
|
| 62 |
+
// for xilinx gate sim
|
| 63 |
+
glbl glbl();
|
| 64 |
+
`endif
|
| 65 |
+
|
| 66 |
+
doubly_linked_list #(.DATA_WIDTH(DUT_DATA_WIDTH),.MAX_NODE(DUT_MAX_NODE)) DUT
|
| 67 |
+
( /*input*/ .rst(rst),
|
| 68 |
+
/*input*/ .clk(clk),
|
| 69 |
+
/*input [DATA_WIDTH-1:0]*/ .data_in(data_in),
|
| 70 |
+
/*input [ADDR_WIDTH-1:0]*/ .addr_in(addr_in),
|
| 71 |
+
/*input [1:0]*/ .op(op), // 0: Read(addr_in); 1: Delete_Value(data_in); 2: Push_Back(data_in); 3: Push_front(data_in)
|
| 72 |
+
/*input*/ .op_start(op_start),
|
| 73 |
+
/*output reg [DATA_WIDTH-1:0]*/ .data_out(data_out),
|
| 74 |
+
/*output reg*/ .op_done(op_done),
|
| 75 |
+
/*output wire [ADDR_WIDTH-1:0]*/ .pre_node_addr(pre_node_addr),// Addr of pre node
|
| 76 |
+
/*output wire [ADDR_WIDTH-1:0]*/ .next_node_addr(next_node_addr), // Addr of next node
|
| 77 |
+
// status
|
| 78 |
+
/*output reg [ADDR_WIDTH-1:0]*/ .length(length),
|
| 79 |
+
/*output wire*/ .full(full),
|
| 80 |
+
/*output reg [ADDR_WIDTH-1:0]*/ .head(head), // Addr of head
|
| 81 |
+
/*output reg [ADDR_WIDTH-1:0]*/ .tail(tail), // Addr of head
|
| 82 |
+
/*output wire*/ .empty(empty),
|
| 83 |
+
/*output reg*/ .fault(fault) // Invalid Errors
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
always #(TB_CLK_PERIOD/2) clk = ~clk;
|
| 87 |
+
|
| 88 |
+
integer linked_list_exp[$];
|
| 89 |
+
integer linked_list_addr[$]; // corresponding to linked_list_exp.
|
| 90 |
+
integer data_wr[$];
|
| 91 |
+
integer i = 0;
|
| 92 |
+
integer next;
|
| 93 |
+
int dummy[$];
|
| 94 |
+
int temp[$];
|
| 95 |
+
integer temp2;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
task list_print_contents();
|
| 99 |
+
$write("%0t linked_list_exp = ", $realtime);
|
| 100 |
+
for (int i = 0; i < linked_list_exp.size(); i = i + 1) begin
|
| 101 |
+
$write("%0d ", linked_list_exp[i]);
|
| 102 |
+
end
|
| 103 |
+
$write("\n%0t linked_list_addr = ", $realtime);
|
| 104 |
+
for (int i = 0; i < linked_list_addr.size(); i = i + 1) begin
|
| 105 |
+
$write("%0d ", linked_list_addr[i]);
|
| 106 |
+
end
|
| 107 |
+
$write("\n");
|
| 108 |
+
endtask
|
| 109 |
+
|
| 110 |
+
task find_first_index (input integer addr); // input integer list[$], ref integer addr[$]); icarus does not support ref.
|
| 111 |
+
begin
|
| 112 |
+
temp = {};
|
| 113 |
+
for (integer i = 0; i < linked_list_addr.size(); i = i + 1) begin
|
| 114 |
+
if(addr == linked_list_addr[i]) begin
|
| 115 |
+
temp.push_back(i);
|
| 116 |
+
$display("%0t Addr %0d found at Index %0d", $realtime, addr, i);
|
| 117 |
+
end
|
| 118 |
+
end
|
| 119 |
+
end
|
| 120 |
+
endtask
|
| 121 |
+
|
| 122 |
+
task find_first_index2 (input integer addr); //avoid temp output conflict
|
| 123 |
+
begin
|
| 124 |
+
dummy = {};
|
| 125 |
+
for (integer i = 0; i < linked_list_addr.size(); i = i + 1) begin
|
| 126 |
+
if(addr == linked_list_addr[i]) begin
|
| 127 |
+
dummy.push_back(i);
|
| 128 |
+
$display("%0t Addr %0d found at Index %0d", $realtime, addr, i);
|
| 129 |
+
end
|
| 130 |
+
end
|
| 131 |
+
end
|
| 132 |
+
endtask
|
| 133 |
+
|
| 134 |
+
task find_next_addr (output integer next_addr);
|
| 135 |
+
begin
|
| 136 |
+
next_addr = 0;
|
| 137 |
+
for (int i = 0; i < (linked_list_addr.size()+1); i = i + 1) begin
|
| 138 |
+
dummy = {};
|
| 139 |
+
//dummy = (linked_list_addr.find_first_index(x) with ( x == i )); // icarus does not support built in find_first_index method, so used workaround below.
|
| 140 |
+
find_first_index2(i);
|
| 141 |
+
if(dummy.size() == 0) begin
|
| 142 |
+
next_addr = i;
|
| 143 |
+
//break; //icarus does not support break statement, so used workaround below.
|
| 144 |
+
i = linked_list_addr.size()+1;
|
| 145 |
+
end
|
| 146 |
+
end
|
| 147 |
+
$display("%0t Next Addr = %0d", $realtime, next_addr);
|
| 148 |
+
end
|
| 149 |
+
endtask
|
| 150 |
+
|
| 151 |
+
task read_n_front(input integer count);
|
| 152 |
+
begin
|
| 153 |
+
$display("%0t OP_Read from front %0d times", $realtime,count);
|
| 154 |
+
i = 0;
|
| 155 |
+
@(posedge (clk));
|
| 156 |
+
#1
|
| 157 |
+
op = OP_Read;
|
| 158 |
+
op_start = 1;
|
| 159 |
+
addr_in = head;
|
| 160 |
+
i = i + 1;
|
| 161 |
+
while (i<=count) begin
|
| 162 |
+
@(posedge (clk));
|
| 163 |
+
#1
|
| 164 |
+
if(op_done) begin
|
| 165 |
+
if( (i-1) >= linked_list_exp.size()) begin
|
| 166 |
+
if(fault) begin
|
| 167 |
+
$display("%0t Data read out of bound, fault flag is asserted correctly",$realtime);
|
| 168 |
+
end else begin
|
| 169 |
+
$error("%0t Data read out of bound, fault flag is not asserted",$realtime);
|
| 170 |
+
err_cnt = err_cnt + 1;
|
| 171 |
+
end
|
| 172 |
+
end else if(data_out == linked_list_exp[i-1]) begin
|
| 173 |
+
$display("%0t Data read: %0d",$realtime,data_out);
|
| 174 |
+
end else begin
|
| 175 |
+
$error("%0t Data read: %0d, Data Exp: %0d", $realtime, data_out, linked_list_exp[i-1]);
|
| 176 |
+
err_cnt = err_cnt + 1;
|
| 177 |
+
end
|
| 178 |
+
if(i == count) begin
|
| 179 |
+
op_start = 0;
|
| 180 |
+
end else if ( ((i-1) == 0) && ((i-1) < linked_list_exp.size()-2) ) begin
|
| 181 |
+
if(next_node_addr != linked_list_addr[i]) begin
|
| 182 |
+
$error("%0t Next Addr: %0d, Addr Exp: %0d", $realtime, next_node_addr, linked_list_addr[i]);
|
| 183 |
+
err_cnt = err_cnt + 1;
|
| 184 |
+
end
|
| 185 |
+
if(pre_node_addr != ADDR_NULL) begin
|
| 186 |
+
$error("%0t Pre Addr: %0d, Addr Exp: %0d", $realtime, pre_node_addr, ADDR_NULL);
|
| 187 |
+
err_cnt = err_cnt + 1;
|
| 188 |
+
end
|
| 189 |
+
end else if ( ((i-1) > 0) && ((i-1) < linked_list_exp.size()-2) ) begin
|
| 190 |
+
if(next_node_addr != linked_list_addr[i]) begin
|
| 191 |
+
$error("%0t Next Addr: %0d, Addr Exp: %0d", $realtime, next_node_addr, linked_list_addr[i]);
|
| 192 |
+
err_cnt = err_cnt + 1;
|
| 193 |
+
end
|
| 194 |
+
if(pre_node_addr != linked_list_addr[i-2]) begin
|
| 195 |
+
$error("%0t Pre Addr: %0d, Addr Exp: %0d", $realtime, pre_node_addr, linked_list_addr[i-2]);
|
| 196 |
+
err_cnt = err_cnt + 1;
|
| 197 |
+
end
|
| 198 |
+
end else if ( (i-1) == linked_list_exp.size()-1) begin
|
| 199 |
+
if(next_node_addr != ADDR_NULL) begin
|
| 200 |
+
$error("%0t Next Addr: %0d, Addr Exp: %0d", $realtime, next_node_addr, ADDR_NULL);
|
| 201 |
+
err_cnt = err_cnt + 1;
|
| 202 |
+
end
|
| 203 |
+
if(pre_node_addr != linked_list_addr[i-2]) begin
|
| 204 |
+
$error("%0t Pre Addr: %0d, Addr Exp: %0d", $realtime, pre_node_addr, linked_list_addr[i-2]);
|
| 205 |
+
err_cnt = err_cnt + 1;
|
| 206 |
+
end
|
| 207 |
+
end
|
| 208 |
+
addr_in = next_node_addr;
|
| 209 |
+
i = i + 1;
|
| 210 |
+
end
|
| 211 |
+
end
|
| 212 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 213 |
+
list_print_contents();
|
| 214 |
+
//$display("%0t Complete OP_Read from front %0d times, linked_list_exp = %p", $realtime,count,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 215 |
+
//$display("%0t Complete OP_Read from front %0d times, linked_list_addr = %p\n", $realtime,count,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 216 |
+
end
|
| 217 |
+
endtask
|
| 218 |
+
|
| 219 |
+
task read_n_back(input integer count);
|
| 220 |
+
begin
|
| 221 |
+
$display("%0t OP_Read from back %0d times", $realtime,count);
|
| 222 |
+
i = 0;
|
| 223 |
+
@(posedge (clk));
|
| 224 |
+
#1
|
| 225 |
+
op = OP_Read;
|
| 226 |
+
op_start = 1;
|
| 227 |
+
addr_in = tail;
|
| 228 |
+
i = i + 1;
|
| 229 |
+
while (i<=count) begin
|
| 230 |
+
@(posedge (clk));
|
| 231 |
+
#1
|
| 232 |
+
if(op_done) begin
|
| 233 |
+
if( (i-1) >= linked_list_exp.size()) begin
|
| 234 |
+
if(fault) begin
|
| 235 |
+
$display("%0t Data read out of bound, fault flag is asserted correctly",$realtime);
|
| 236 |
+
end else begin
|
| 237 |
+
$error("%0t Data read out of bound, fault flag is not asserted",$realtime);
|
| 238 |
+
err_cnt = err_cnt + 1;
|
| 239 |
+
end
|
| 240 |
+
end else if(data_out == linked_list_exp[linked_list_exp.size()-1-(i-1)]) begin
|
| 241 |
+
$display("%0t Data read: %0d",$realtime,data_out);
|
| 242 |
+
end else begin
|
| 243 |
+
$error("%0t Data read: %0d, Data Exp: %0d", $realtime, data_out, linked_list_exp[linked_list_exp.size()-1-(i-1)]);
|
| 244 |
+
err_cnt = err_cnt + 1;
|
| 245 |
+
end
|
| 246 |
+
if(i == count) begin
|
| 247 |
+
op_start = 0;
|
| 248 |
+
end else if ( ((i-1) == 0) && ((i-1) < linked_list_exp.size()-2) ) begin
|
| 249 |
+
if(next_node_addr != ADDR_NULL) begin
|
| 250 |
+
$error("%0t Next Addr: %0d, Addr Exp: %0d", $realtime, next_node_addr, ADDR_NULL);
|
| 251 |
+
err_cnt = err_cnt + 1;
|
| 252 |
+
end
|
| 253 |
+
if(pre_node_addr != linked_list_addr[linked_list_exp.size()-1-(i-2)]) begin
|
| 254 |
+
$error("%0t Pre Addr: %0d, Addr Exp: %0d", $realtime, pre_node_addr, linked_list_addr[linked_list_exp.size()-1-(i-2)]);
|
| 255 |
+
err_cnt = err_cnt + 1;
|
| 256 |
+
end else if ( ((i-1) > 0) && ((i-1) < linked_list_exp.size()-2) ) begin
|
| 257 |
+
if(next_node_addr != linked_list_addr[linked_list_exp.size()-1-(i)]) begin
|
| 258 |
+
$error("%0t Next Addr: %0d, Addr Exp: %0d", $realtime, next_node_addr, linked_list_addr[linked_list_exp.size()-1-(i)]);
|
| 259 |
+
err_cnt = err_cnt + 1;
|
| 260 |
+
end
|
| 261 |
+
if(pre_node_addr != linked_list_addr[linked_list_exp.size()-1-(i-2)]) begin
|
| 262 |
+
$error("%0t Pre Addr: %0d, Addr Exp: %0d", $realtime, pre_node_addr, linked_list_addr[linked_list_exp.size()-1-(i-2)]);
|
| 263 |
+
err_cnt = err_cnt + 1;
|
| 264 |
+
end
|
| 265 |
+
end else if ( (i-1) == linked_list_exp.size()-1) begin
|
| 266 |
+
if(next_node_addr != linked_list_addr[linked_list_exp.size()-1-(i)]) begin
|
| 267 |
+
$error("%0t Next Addr: %0d, Addr Exp: %0d", $realtime, next_node_addr, linked_list_addr[linked_list_exp.size()-1-(i)]);
|
| 268 |
+
err_cnt = err_cnt + 1;
|
| 269 |
+
end
|
| 270 |
+
if(pre_node_addr != ADDR_NULL) begin
|
| 271 |
+
$error("%0t Pre Addr: %0d, Addr Exp: %0d", $realtime, pre_node_addr, ADDR_NULL);
|
| 272 |
+
err_cnt = err_cnt + 1;
|
| 273 |
+
end
|
| 274 |
+
end
|
| 275 |
+
end
|
| 276 |
+
addr_in = pre_node_addr;
|
| 277 |
+
i = i + 1;
|
| 278 |
+
end
|
| 279 |
+
end
|
| 280 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 281 |
+
list_print_contents();
|
| 282 |
+
// $display("%0t Complete OP_Read from back %0d times, linked_list_exp = %p", $realtime,count,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 283 |
+
// $display("%0t Complete OP_Read from back %0d times, linked_list_addr = %p\n", $realtime,count,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 284 |
+
end
|
| 285 |
+
endtask
|
| 286 |
+
|
| 287 |
+
bit found = 0;
|
| 288 |
+
|
| 289 |
+
task delete_value(input integer value);
|
| 290 |
+
begin
|
| 291 |
+
$display("%0t OP_Delete_Value %0d value", $realtime,value);
|
| 292 |
+
i = 0;
|
| 293 |
+
found = 0;
|
| 294 |
+
@(posedge (clk));
|
| 295 |
+
#1
|
| 296 |
+
op = OP_Delete_Value;
|
| 297 |
+
data_in = value;
|
| 298 |
+
op_start = 1;
|
| 299 |
+
wait (op_done)
|
| 300 |
+
#1
|
| 301 |
+
for (int j = 0; j < linked_list_exp.size(); j=j+1) begin
|
| 302 |
+
if(value == linked_list_exp[j]) begin
|
| 303 |
+
$display("%0t Data %0d at Index %0d is Deleted_by_Value", $realtime, linked_list_exp[j],j);
|
| 304 |
+
linked_list_exp.delete(j);
|
| 305 |
+
linked_list_addr.delete(j);
|
| 306 |
+
found = 1;
|
| 307 |
+
//break;
|
| 308 |
+
j = linked_list_exp.size() + 1;
|
| 309 |
+
end
|
| 310 |
+
end
|
| 311 |
+
if (!found) begin
|
| 312 |
+
if(fault) begin
|
| 313 |
+
$display("%0t Data delete out of bound, fault flag is asserted correctly",$realtime);
|
| 314 |
+
end else begin
|
| 315 |
+
$error("%0t Data delete out of bound, fault flag is not asserted",$realtime);
|
| 316 |
+
err_cnt = err_cnt + 1;
|
| 317 |
+
end
|
| 318 |
+
end else begin
|
| 319 |
+
if(fault) begin
|
| 320 |
+
$error("%0t fault flag is asserted incorrectly",$realtime);
|
| 321 |
+
err_cnt = err_cnt + 1;
|
| 322 |
+
end
|
| 323 |
+
end
|
| 324 |
+
op_start = 0;
|
| 325 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 326 |
+
list_print_contents();
|
| 327 |
+
//$display("%0t Complete OP_Delete_Value %0d value, linked_list_exp = %p", $realtime,value,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 328 |
+
//$display("%0t Complete OP_Delete_Value %0d value, linked_list_addr = %p\n", $realtime,value,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 329 |
+
end
|
| 330 |
+
endtask
|
| 331 |
+
|
| 332 |
+
task delete_at_index (input integer addr);
|
| 333 |
+
begin
|
| 334 |
+
$display("%0t OP_Delete_At_Index %0d index", $realtime,addr);
|
| 335 |
+
i = 0;
|
| 336 |
+
@(posedge (clk));
|
| 337 |
+
#1
|
| 338 |
+
op = OP_Delete_At_Index;
|
| 339 |
+
addr_in = addr;
|
| 340 |
+
op_start = 1;
|
| 341 |
+
|
| 342 |
+
wait (op_done)
|
| 343 |
+
#1
|
| 344 |
+
if( addr >= linked_list_exp.size()) begin
|
| 345 |
+
if(fault) begin
|
| 346 |
+
$display("%0t Data delete out of bound, fault flag is asserted correctly",$realtime);
|
| 347 |
+
end else begin
|
| 348 |
+
$error("%0t Data delete out of bound, fault flag is not asserted",$realtime);
|
| 349 |
+
err_cnt = err_cnt + 1;
|
| 350 |
+
end
|
| 351 |
+
end else if ( addr == 0 ) begin
|
| 352 |
+
if(fault) begin
|
| 353 |
+
$error("%0t fault flag is asserted incorrectly",$realtime);
|
| 354 |
+
err_cnt = err_cnt + 1;
|
| 355 |
+
end
|
| 356 |
+
$display("%0t Data %0d at Front is Deleted", $realtime, linked_list_exp[0]);
|
| 357 |
+
temp2 = linked_list_exp.pop_front();
|
| 358 |
+
temp2 = linked_list_addr.pop_front();
|
| 359 |
+
end else begin
|
| 360 |
+
if(fault) begin
|
| 361 |
+
$error("%0t fault flag is asserted incorrectly",$realtime);
|
| 362 |
+
err_cnt = err_cnt + 1;
|
| 363 |
+
end
|
| 364 |
+
$display("%0t Data %0d at Index %0d is Deleted", $realtime, linked_list_exp[addr],addr);
|
| 365 |
+
linked_list_exp.delete(addr);
|
| 366 |
+
linked_list_addr.delete(addr);
|
| 367 |
+
end
|
| 368 |
+
if(linked_list_exp.size() == 0) begin
|
| 369 |
+
if(empty) begin
|
| 370 |
+
$display("%0t Queue is empty and empty flag is asserted correctly",$realtime);
|
| 371 |
+
end else begin
|
| 372 |
+
$error("%0t Queue is empty but empty flag is not asserted",$realtime);
|
| 373 |
+
err_cnt = err_cnt + 1;
|
| 374 |
+
end
|
| 375 |
+
end else if(empty) begin
|
| 376 |
+
$error("%0t Empty flag is asserted incorrectly",$realtime);
|
| 377 |
+
err_cnt = err_cnt + 1;
|
| 378 |
+
end
|
| 379 |
+
op_start = 0;
|
| 380 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 381 |
+
list_print_contents();
|
| 382 |
+
//$display("%0t Complete OP_Delete_At_Index %0d index, linked_list_exp = %p", $realtime,addr,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 383 |
+
//$display("%0t Complete OP_Delete_At_Index %0d index, linked_list_addr = %p\n", $realtime,addr,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 384 |
+
end
|
| 385 |
+
endtask
|
| 386 |
+
|
| 387 |
+
task insert_at_index (input integer addr, input integer value);
|
| 388 |
+
begin
|
| 389 |
+
$display("%0t OP_Insert_At_Index %0d index, %0d value", $realtime,addr,value);
|
| 390 |
+
i = 0;
|
| 391 |
+
@(posedge (clk));
|
| 392 |
+
#1
|
| 393 |
+
op = OP_Insert_At_Index;
|
| 394 |
+
addr_in = addr;
|
| 395 |
+
data_in = value;
|
| 396 |
+
op_start = 1;
|
| 397 |
+
wait (op_done)
|
| 398 |
+
#1
|
| 399 |
+
if(linked_list_exp.size() >= DUT_MAX_NODE) begin
|
| 400 |
+
if(!fault) begin
|
| 401 |
+
$error("%0t Fault flag is not asserted",$realtime);
|
| 402 |
+
err_cnt = err_cnt + 1;
|
| 403 |
+
end else begin
|
| 404 |
+
$display("%0t Fault flag is asserted correctly",$realtime);
|
| 405 |
+
end
|
| 406 |
+
end else if( addr == 0 ) begin
|
| 407 |
+
if(fault) begin
|
| 408 |
+
$error("%0t Fault flag is asserted incorrectly",$realtime);
|
| 409 |
+
err_cnt = err_cnt + 1;
|
| 410 |
+
end
|
| 411 |
+
linked_list_exp.push_front(value);
|
| 412 |
+
find_next_addr(next);
|
| 413 |
+
linked_list_addr.push_front(next);
|
| 414 |
+
$display("%0t Data Written to Front : %0d",$realtime,value);
|
| 415 |
+
end else if ( addr >= linked_list_exp.size() ) begin
|
| 416 |
+
if(fault) begin
|
| 417 |
+
$error("%0t Fault flag is asserted incorrectly",$realtime);
|
| 418 |
+
err_cnt = err_cnt + 1;
|
| 419 |
+
end
|
| 420 |
+
linked_list_exp.push_back(value);
|
| 421 |
+
find_next_addr(next);
|
| 422 |
+
linked_list_addr.push_back(next);
|
| 423 |
+
$display("%0t Data Written to Back : %0d",$realtime,value);
|
| 424 |
+
end else begin
|
| 425 |
+
if(fault) begin
|
| 426 |
+
$error("%0t Fault flag is asserted incorrectly",$realtime);
|
| 427 |
+
err_cnt = err_cnt + 1;
|
| 428 |
+
end
|
| 429 |
+
linked_list_exp.insert(addr, value);
|
| 430 |
+
find_next_addr(next);
|
| 431 |
+
linked_list_addr.insert(addr, next);
|
| 432 |
+
$display("%0t Data Written to Index %0d : %0d",$realtime,addr,value);
|
| 433 |
+
end
|
| 434 |
+
if(linked_list_exp.size() >= (DUT_MAX_NODE)) begin
|
| 435 |
+
if(full) begin
|
| 436 |
+
$display("%0t Queue is full and full flag is asserted correctly",$realtime);
|
| 437 |
+
end else begin
|
| 438 |
+
$error("%0t Queue is full but full flag is not asserted",$realtime);
|
| 439 |
+
err_cnt = err_cnt + 1;
|
| 440 |
+
end
|
| 441 |
+
end else if(full) begin
|
| 442 |
+
$error("%0t Full flag is asserted incorrectly",$realtime);
|
| 443 |
+
err_cnt = err_cnt + 1;
|
| 444 |
+
end
|
| 445 |
+
op_start = 0;
|
| 446 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 447 |
+
list_print_contents();
|
| 448 |
+
//$display("%0t Complete OP_Insert_At_Index %0d index %0d value, linked_list_exp = %p", $realtime,addr,value,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 449 |
+
//$display("%0t Complete OP_Insert_At_Index %0d index %0d value, linked_list_addr = %p\n", $realtime,addr,value,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 450 |
+
end
|
| 451 |
+
endtask
|
| 452 |
+
|
| 453 |
+
task delete_at_addr (input int addr);
|
| 454 |
+
begin
|
| 455 |
+
$display("%0t OP_Delete_At_Addr %0d Addr", $realtime,addr);
|
| 456 |
+
i = 0;
|
| 457 |
+
@(posedge (clk));
|
| 458 |
+
#1
|
| 459 |
+
op = OP_Delete_At_Addr;
|
| 460 |
+
addr_in = addr;
|
| 461 |
+
op_start = 1;
|
| 462 |
+
pre_head = head;
|
| 463 |
+
pre_tail = tail;
|
| 464 |
+
|
| 465 |
+
wait (op_done)
|
| 466 |
+
#1
|
| 467 |
+
if( addr >= ADDR_NULL) begin
|
| 468 |
+
if(fault) begin
|
| 469 |
+
$display("%0t Data delete out of bound, fault flag is asserted correctly",$realtime);
|
| 470 |
+
end else begin
|
| 471 |
+
$error("%0t Data delete out of bound, fault flag is not asserted",$realtime);
|
| 472 |
+
err_cnt = err_cnt + 1;
|
| 473 |
+
end
|
| 474 |
+
end else if ( addr == pre_head ) begin
|
| 475 |
+
if(fault) begin
|
| 476 |
+
$error("%0t fault flag is asserted incorrectly",$realtime);
|
| 477 |
+
err_cnt = err_cnt + 1;
|
| 478 |
+
end
|
| 479 |
+
$display("%0t Data %0d at Front is Deleted", $realtime, linked_list_exp[0]);
|
| 480 |
+
temp2 = linked_list_exp.pop_front();
|
| 481 |
+
temp2 = linked_list_addr.pop_front();
|
| 482 |
+
end else if ( addr == pre_tail ) begin
|
| 483 |
+
if(fault) begin
|
| 484 |
+
$error("%0t fault flag is asserted incorrectly",$realtime);
|
| 485 |
+
err_cnt = err_cnt + 1;
|
| 486 |
+
end
|
| 487 |
+
$display("%0t Data %0d at Back is Deleted", $realtime, linked_list_exp[0]);
|
| 488 |
+
temp2 = linked_list_exp.pop_back();
|
| 489 |
+
temp2 = linked_list_addr.pop_back();
|
| 490 |
+
end else begin
|
| 491 |
+
temp = {};
|
| 492 |
+
// for (int j = 0; j <1; j = j+1) begin
|
| 493 |
+
// temp = (linked_list_addr.find_first_index(x) with (x == addr));
|
| 494 |
+
// end
|
| 495 |
+
find_first_index(addr);
|
| 496 |
+
if (temp.size() == 0) begin
|
| 497 |
+
if(!fault) begin
|
| 498 |
+
$error("%0t Fault flag is not asserted",$realtime);
|
| 499 |
+
err_cnt = err_cnt + 1;
|
| 500 |
+
end else begin
|
| 501 |
+
$display("%0t Fault flag is asserted correctly",$realtime);
|
| 502 |
+
end
|
| 503 |
+
end else begin
|
| 504 |
+
$display("%0t Data %0d at Addr %0d is Deleted", $realtime, linked_list_exp[temp[0]],linked_list_addr[temp[0]]);
|
| 505 |
+
linked_list_exp.delete(temp[0]);
|
| 506 |
+
linked_list_addr.delete(temp[0]);
|
| 507 |
+
end
|
| 508 |
+
end
|
| 509 |
+
if(linked_list_exp.size() == 0) begin
|
| 510 |
+
if(empty) begin
|
| 511 |
+
$display("%0t Queue is empty and empty flag is asserted correctly",$realtime);
|
| 512 |
+
end else begin
|
| 513 |
+
$error("%0t Queue is empty but empty flag is not asserted",$realtime);
|
| 514 |
+
err_cnt = err_cnt + 1;
|
| 515 |
+
end
|
| 516 |
+
end else if(empty) begin
|
| 517 |
+
$error("%0t Empty flag is asserted incorrectly",$realtime);
|
| 518 |
+
err_cnt = err_cnt + 1;
|
| 519 |
+
end
|
| 520 |
+
op_start = 0;
|
| 521 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 522 |
+
list_print_contents();
|
| 523 |
+
//$display("%0t Complete OP_Delete_At_Addr %0d addr, linked_list_exp = %p", $realtime,addr,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 524 |
+
//$display("%0t Complete OP_Delete_At_Addr %0d addr, linked_list_addr = %p\n", $realtime,addr,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 525 |
+
end
|
| 526 |
+
endtask
|
| 527 |
+
|
| 528 |
+
task insert_at_addr (input int addr, input integer value);
|
| 529 |
+
begin
|
| 530 |
+
$display("%0t OP_Insert_At_Addr %0d addr, %0d value", $realtime,addr,value);
|
| 531 |
+
i = 0;
|
| 532 |
+
@(posedge (clk));
|
| 533 |
+
#1
|
| 534 |
+
op = OP_Insert_At_Addr;
|
| 535 |
+
addr_in = addr;
|
| 536 |
+
data_in = value;
|
| 537 |
+
op_start = 1;
|
| 538 |
+
pre_head = head;
|
| 539 |
+
pre_tail = tail;
|
| 540 |
+
wait (op_done)
|
| 541 |
+
#1
|
| 542 |
+
if(linked_list_exp.size() >= DUT_MAX_NODE) begin
|
| 543 |
+
if(!fault) begin
|
| 544 |
+
$error("%0t Fault flag is not asserted",$realtime);
|
| 545 |
+
err_cnt = err_cnt + 1;
|
| 546 |
+
end else begin
|
| 547 |
+
$display("%0t Fault flag is asserted correctly",$realtime);
|
| 548 |
+
end
|
| 549 |
+
end else if( addr == pre_head ) begin
|
| 550 |
+
if(fault) begin
|
| 551 |
+
$error("%0t Fault flag is asserted incorrectly",$realtime);
|
| 552 |
+
err_cnt = err_cnt + 1;
|
| 553 |
+
end
|
| 554 |
+
linked_list_exp.push_front(value);
|
| 555 |
+
find_next_addr(next);
|
| 556 |
+
linked_list_addr.push_front(next);
|
| 557 |
+
$display("%0t Data Written to Front : %0d",$realtime,value);
|
| 558 |
+
end else if( addr == pre_tail ) begin
|
| 559 |
+
if(fault) begin
|
| 560 |
+
$error("%0t Fault flag is asserted incorrectly",$realtime);
|
| 561 |
+
err_cnt = err_cnt + 1;
|
| 562 |
+
end
|
| 563 |
+
linked_list_exp.insert(linked_list_exp.size()-1, value);
|
| 564 |
+
find_next_addr(next);
|
| 565 |
+
linked_list_addr.insert(linked_list_addr.size()-1, next);
|
| 566 |
+
$display("%0t Data Written to Back : %0d",$realtime,value);
|
| 567 |
+
end else if ( addr >= ADDR_NULL ) begin
|
| 568 |
+
if(fault) begin
|
| 569 |
+
$error("%0t Fault flag is asserted incorrectly",$realtime);
|
| 570 |
+
err_cnt = err_cnt + 1;
|
| 571 |
+
end
|
| 572 |
+
linked_list_exp.push_back(value);
|
| 573 |
+
find_next_addr(next);
|
| 574 |
+
linked_list_addr.push_back(next);
|
| 575 |
+
$display("%0t Data Written to Back : %0d",$realtime,value);
|
| 576 |
+
end else begin
|
| 577 |
+
temp = {};
|
| 578 |
+
// for (int j = 0; j <1; j = j+1) begin
|
| 579 |
+
// temp = (linked_list_addr.find_first_index(x) with (x == addr));
|
| 580 |
+
// end
|
| 581 |
+
find_first_index(addr);
|
| 582 |
+
if (temp.size() == 0) begin
|
| 583 |
+
if(!fault) begin
|
| 584 |
+
$error("%0t Fault flag is not asserted",$realtime);
|
| 585 |
+
err_cnt = err_cnt + 1;
|
| 586 |
+
end else begin
|
| 587 |
+
$display("%0t Fault flag is asserted correctly",$realtime);
|
| 588 |
+
end
|
| 589 |
+
end else begin
|
| 590 |
+
linked_list_exp.insert(temp[0], value);
|
| 591 |
+
find_next_addr(next);
|
| 592 |
+
linked_list_addr.insert(temp[0], next);
|
| 593 |
+
$display("%0t Data Written to Addr %0d : %0d",$realtime,addr,value);
|
| 594 |
+
end
|
| 595 |
+
end
|
| 596 |
+
if(linked_list_exp.size() >= (DUT_MAX_NODE)) begin
|
| 597 |
+
if(full) begin
|
| 598 |
+
$display("%0t Queue is full and full flag is asserted correctly",$realtime);
|
| 599 |
+
end else begin
|
| 600 |
+
$error("%0t Queue is full but full flag is not asserted",$realtime);
|
| 601 |
+
err_cnt = err_cnt + 1;
|
| 602 |
+
end
|
| 603 |
+
end else if(full) begin
|
| 604 |
+
$error("%0t Full flag is asserted incorrectly",$realtime);
|
| 605 |
+
err_cnt = err_cnt + 1;
|
| 606 |
+
end
|
| 607 |
+
op_start = 0;
|
| 608 |
+
// icarus does not support %p concanation, so used workaround below.
|
| 609 |
+
list_print_contents();
|
| 610 |
+
//$display("%0t Complete OP_Insert_At_Addr %0d addr %0d value, linked_list_exp = %p", $realtime,addr,value,linked_list_exp[0:(linked_list_exp.size()-1)]);
|
| 611 |
+
//$display("%0t Complete OP_Insert_At_Addr %0d addr %0d value, linked_list_addr = %p\n", $realtime,addr,value,linked_list_addr[0:(linked_list_addr.size()-1)]);
|
| 612 |
+
end
|
| 613 |
+
endtask
|
| 614 |
+
|
| 615 |
+
task direct_index_op_test();
|
| 616 |
+
begin
|
| 617 |
+
$display("\n======================================");
|
| 618 |
+
$display("Direct Index Op Test");
|
| 619 |
+
$display("======================================");
|
| 620 |
+
//DIRECT TEST Index Mode
|
| 621 |
+
rst = 1'b1;
|
| 622 |
+
#100
|
| 623 |
+
rst = 1'b0;
|
| 624 |
+
linked_list_exp = {};
|
| 625 |
+
linked_list_addr = {};
|
| 626 |
+
insert_at_index(0,3);
|
| 627 |
+
insert_at_index(0,0);
|
| 628 |
+
#100
|
| 629 |
+
insert_at_index(4,5);
|
| 630 |
+
insert_at_index(0,6);
|
| 631 |
+
insert_at_index(0,7);
|
| 632 |
+
insert_at_index(1,3);
|
| 633 |
+
insert_at_index(2,4);
|
| 634 |
+
insert_at_index(ADDR_NULL,3);
|
| 635 |
+
insert_at_index(ADDR_NULL,4);
|
| 636 |
+
read_n_back(linked_list_exp.size());
|
| 637 |
+
insert_at_index(ADDR_NULL,1);
|
| 638 |
+
insert_at_index(0,3);
|
| 639 |
+
#200
|
| 640 |
+
read_n_front(linked_list_exp.size());
|
| 641 |
+
#500
|
| 642 |
+
delete_value(7);
|
| 643 |
+
delete_at_index(0);
|
| 644 |
+
read_n_back(linked_list_exp.size());
|
| 645 |
+
delete_at_index(0);
|
| 646 |
+
delete_value(2);
|
| 647 |
+
delete_value(4);
|
| 648 |
+
delete_at_index(0);
|
| 649 |
+
read_n_front(linked_list_exp.size());
|
| 650 |
+
delete_at_index(7);
|
| 651 |
+
delete_at_index(length-1);
|
| 652 |
+
delete_at_index(length-1);
|
| 653 |
+
delete_at_index(0);
|
| 654 |
+
delete_at_index(0);
|
| 655 |
+
delete_at_index(0);
|
| 656 |
+
#500;
|
| 657 |
+
end
|
| 658 |
+
endtask
|
| 659 |
+
|
| 660 |
+
task direct_addr_op_test();
|
| 661 |
+
begin
|
| 662 |
+
//DIRECT TEST Index Mode
|
| 663 |
+
$display("\n======================================");
|
| 664 |
+
$display("Direct Address Op Test");
|
| 665 |
+
$display("======================================");
|
| 666 |
+
rst = 1'b1;
|
| 667 |
+
#100
|
| 668 |
+
rst = 1'b0;
|
| 669 |
+
linked_list_exp = {};
|
| 670 |
+
linked_list_addr = {};
|
| 671 |
+
insert_at_addr(head,3);
|
| 672 |
+
insert_at_addr(head,0);
|
| 673 |
+
#100
|
| 674 |
+
insert_at_addr(0,5);
|
| 675 |
+
insert_at_addr(head,6);
|
| 676 |
+
insert_at_addr(linked_list_addr[2],7);
|
| 677 |
+
insert_at_addr(tail,3);
|
| 678 |
+
insert_at_addr(head,4);
|
| 679 |
+
read_n_back(linked_list_exp.size());
|
| 680 |
+
insert_at_addr(ADDR_NULL,3);
|
| 681 |
+
insert_at_addr(ADDR_NULL,4);
|
| 682 |
+
insert_at_addr(ADDR_NULL,1);
|
| 683 |
+
insert_at_addr(0,3);
|
| 684 |
+
#200
|
| 685 |
+
read_n_front(linked_list_exp.size());
|
| 686 |
+
#500
|
| 687 |
+
delete_value(7);
|
| 688 |
+
read_n_front(linked_list_exp.size());
|
| 689 |
+
delete_at_addr(0);
|
| 690 |
+
delete_at_addr(head);
|
| 691 |
+
delete_value(2);
|
| 692 |
+
read_n_front(linked_list_exp.size());
|
| 693 |
+
read_n_back(linked_list_exp.size());
|
| 694 |
+
delete_value(4);
|
| 695 |
+
read_n_front(linked_list_exp.size());
|
| 696 |
+
delete_at_addr(head);
|
| 697 |
+
delete_at_addr(7);
|
| 698 |
+
delete_at_addr(tail);
|
| 699 |
+
delete_at_addr(tail-1);
|
| 700 |
+
delete_at_addr(0);
|
| 701 |
+
#500;
|
| 702 |
+
end
|
| 703 |
+
endtask
|
| 704 |
+
|
| 705 |
+
initial begin
|
| 706 |
+
string vcdfile;
|
| 707 |
+
int vcdlevel;
|
| 708 |
+
int seed;
|
| 709 |
+
int temp;
|
| 710 |
+
|
| 711 |
+
rst = 1'b1;
|
| 712 |
+
if ($value$plusargs("VCDFILE=%s",vcdfile))
|
| 713 |
+
$dumpfile(vcdfile);
|
| 714 |
+
if ($value$plusargs("VCDLEVEL=%d",vcdlevel))
|
| 715 |
+
$dumpvars(vcdlevel,tb);
|
| 716 |
+
if ($value$plusargs("SEED=%d",seed)) begin
|
| 717 |
+
temp = $urandom(seed);
|
| 718 |
+
$display("Seed = %d",seed);
|
| 719 |
+
end
|
| 720 |
+
|
| 721 |
+
direct_index_op_test();
|
| 722 |
+
|
| 723 |
+
#1000;
|
| 724 |
+
|
| 725 |
+
direct_addr_op_test();
|
| 726 |
+
|
| 727 |
+
//DIRECT TEST Index Mode
|
| 728 |
+
|
| 729 |
+
if (err_cnt > 0) begin
|
| 730 |
+
$display("\n%0t TEST FAILED",$realtime);
|
| 731 |
+
$display("Error count = %d\n", err_cnt);
|
| 732 |
+
end else
|
| 733 |
+
$display("\n%0t TEST PASSED\n", $realtime);
|
| 734 |
+
$finish;
|
| 735 |
+
end
|
| 736 |
+
|
| 737 |
+
initial begin
|
| 738 |
+
#(SIM_TIMEOUT)
|
| 739 |
+
$display("\n%0t TEST FAILED", $realtime);
|
| 740 |
+
$display("SIM TIMEOUT!\n");
|
| 741 |
+
$finish;
|
| 742 |
+
end
|
| 743 |
+
|
| 744 |
+
endmodule
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/vip/pyuvm/Makefile
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Makefile for Doubly Linked List pyUVM VIP
|
| 2 |
+
|
| 3 |
+
SIM ?= icarus
|
| 4 |
+
TOPLEVEL_LANG ?= verilog
|
| 5 |
+
WAVES ?= 1 # Set 1 to enable waveform dump
|
| 6 |
+
|
| 7 |
+
PWD=$(shell pwd)
|
| 8 |
+
|
| 9 |
+
# RTL source files
|
| 10 |
+
VERILOG_SOURCES = $(PWD)/../../src/doubly_linked_list.sv
|
| 11 |
+
|
| 12 |
+
TOPLEVEL = doubly_linked_list # DUT Top
|
| 13 |
+
MODULE = tb_dll # Top Python file (without .py)
|
| 14 |
+
|
| 15 |
+
# DUT parameters - passed to simulator
|
| 16 |
+
COMPILE_ARGS = -Pdoubly_linked_list.DATA_WIDTH=8
|
| 17 |
+
COMPILE_ARGS += -Pdoubly_linked_list.MAX_NODE=8
|
| 18 |
+
|
| 19 |
+
# Set RANDOM_SEED number (optional)
|
| 20 |
+
#PLUSARGS = +seed=42
|
| 21 |
+
|
| 22 |
+
# Time units
|
| 23 |
+
COCOTB_HDL_TIMEUNIT = 1ns
|
| 24 |
+
COCOTB_HDL_TIMEPRECISION = 1ps
|
| 25 |
+
|
| 26 |
+
# Icarus Verilog waveform dump
|
| 27 |
+
ifeq ($(SIM), icarus)
|
| 28 |
+
ifeq ($(WAVES), 1)
|
| 29 |
+
$(shell echo 'module iverilog_dump();' > iverilog_dump.v)
|
| 30 |
+
$(shell echo 'initial begin' >> iverilog_dump.v)
|
| 31 |
+
$(shell echo ' $$dumpfile("$(TOPLEVEL).vcd");' >> iverilog_dump.v)
|
| 32 |
+
$(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
|
| 33 |
+
$(shell echo 'end' >> iverilog_dump.v)
|
| 34 |
+
$(shell echo 'endmodule' >> iverilog_dump.v)
|
| 35 |
+
VERILOG_SOURCES += $(PWD)/iverilog_dump.v
|
| 36 |
+
COMPILE_ARGS += -s iverilog_dump
|
| 37 |
+
endif
|
| 38 |
+
endif
|
| 39 |
+
|
| 40 |
+
# Include cocotb Makefile
|
| 41 |
+
include $(shell cocotb-config --makefiles)/Makefile.sim
|
| 42 |
+
|
| 43 |
+
# Additional targets
|
| 44 |
+
.PHONY: help
|
| 45 |
+
help:
|
| 46 |
+
@echo "Doubly Linked List pyUVM VIP Makefile"
|
| 47 |
+
@echo "======================================"
|
| 48 |
+
@echo ""
|
| 49 |
+
@echo "Usage:"
|
| 50 |
+
@echo " make - Run all tests with Icarus Verilog"
|
| 51 |
+
@echo " make WAVES=0 - Disable waveforms"
|
| 52 |
+
@echo " make clean - Clean build files"
|
| 53 |
+
@echo ""
|
| 54 |
+
@echo "Environment Variables:"
|
| 55 |
+
@echo " WAVES - Enable waveforms (0/1)"
|
| 56 |
+
@echo " PLUSARGS - Additional simulator arguments"
|
| 57 |
+
@echo ""
|
| 58 |
+
@echo "Examples:"
|
| 59 |
+
@echo " make # Run with icarus, waves enabled"
|
| 60 |
+
@echo " make WAVES=0 # Run without waveforms (faster)"
|
| 61 |
+
@echo " make PLUSARGS=+seed=123 # Run with specific seed"
|
Weiyet_RTLStructLib/source/Doubly_Linked_List/vip/uvm/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Doubly Linked List UVM VIP (Verification IP) User Guide
|
| 2 |
+
|
| 3 |
+
## 📁 Directory Structure
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
uvm/
|
| 7 |
+
├── README.md [User guide and documentation]
|
| 8 |
+
├── common/ [Core VIP source files]
|
| 9 |
+
│ ├── dll_vip_pkg.sv [Main package + enums]
|
| 10 |
+
│ ├── dll_vip_config.sv [Configuration class]
|
| 11 |
+
│ └── dll_vip_seq_item.sv [Transaction definitions]
|
| 12 |
+
├── interface/ [Interface definition]
|
| 13 |
+
│ └── dll_vip_if.sv [Virtual interface]
|
| 14 |
+
├── agent/ [Agent layer components]
|
| 15 |
+
│ ├── dll_vip_driver.sv [Driver implementation]
|
| 16 |
+
│ ├── dll_vip_monitor.sv [Monitor implementation]
|
| 17 |
+
│ ├── dll_vip_sequencer.sv [Sequencer]
|
| 18 |
+
│ └── dll_vip_agent.sv [Agent wrapper]
|
| 19 |
+
├── env/ [Environment layer]
|
| 20 |
+
│ ├── dll_vip_env.sv [Environment]
|
| 21 |
+
│ └── dll_vip_scoreboard.sv [Checking with doubly linked list model]
|
| 22 |
+
├── sequences/ [Test sequences]
|
| 23 |
+
│ ├── dll_vip_base_seq.sv [Base sequence]
|
| 24 |
+
│ ├── dll_vip_insert_seq.sv [Insert sequences (addr & index)]
|
| 25 |
+
│ ├── dll_vip_read_seq.sv [Read sequence]
|
| 26 |
+
│ └── dll_vip_delete_seq.sv [Delete sequences (addr, index, value)]
|
| 27 |
+
└── sim/ [Testbench]
|
| 28 |
+
├── tb_top.sv [Testbench top module]
|
| 29 |
+
└── tests/
|
| 30 |
+
├── dll_vip_base_test.sv [Base test class]
|
| 31 |
+
└── dll_vip_simple_test.sv [Simple & random tests]
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## 🚀 Quick Start
|
| 35 |
+
|
| 36 |
+
**Step 1:** Update interface signals in your testbench:
|
| 37 |
+
```systemverilog
|
| 38 |
+
dll_vip_if dut_if(clk);
|
| 39 |
+
// Connect to DUT
|
| 40 |
+
uvm_config_db#(virtual dll_vip_if)::set(null, "*", "dll_vip_vif", dut_if);
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
**Step 2:** Configure DUT parameters in your test:
|
| 44 |
+
```systemverilog
|
| 45 |
+
cfg = dll_vip_config::type_id::create("cfg");
|
| 46 |
+
cfg.DATA_WIDTH = 8;
|
| 47 |
+
cfg.MAX_NODE = 8;
|
| 48 |
+
uvm_config_db#(dll_vip_config)::set(this, "*", "dll_vip_cfg", cfg);
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
**Step 3:** Create environment:
|
| 52 |
+
```systemverilog
|
| 53 |
+
dll_env = dll_vip_env::type_id::create("dll_env", this);
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
## 🚀 Available Sequences
|
| 57 |
+
|
| 58 |
+
**Insert at Address:**
|
| 59 |
+
```systemverilog
|
| 60 |
+
dll_vip_insert_at_addr_seq insert_seq = dll_vip_insert_at_addr_seq::type_id::create("insert_seq");
|
| 61 |
+
insert_seq.num_inserts = 5;
|
| 62 |
+
insert_seq.start(env.get_sequencer());
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
**Insert at Index:**
|
| 66 |
+
```systemverilog
|
| 67 |
+
dll_vip_insert_at_index_seq insert_seq = dll_vip_insert_at_index_seq::type_id::create("insert_seq");
|
| 68 |
+
insert_seq.num_inserts = 5;
|
| 69 |
+
insert_seq.start(env.get_sequencer());
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
**Read from Address:**
|
| 73 |
+
```systemverilog
|
| 74 |
+
dll_vip_read_seq read_seq = dll_vip_read_seq::type_id::create("read_seq");
|
| 75 |
+
read_seq.num_reads = 5;
|
| 76 |
+
read_seq.start(env.get_sequencer());
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
**Delete at Address:**
|
| 80 |
+
```systemverilog
|
| 81 |
+
dll_vip_delete_at_addr_seq delete_seq = dll_vip_delete_at_addr_seq::type_id::create("delete_seq");
|
| 82 |
+
delete_seq.num_deletes = 3;
|
| 83 |
+
delete_seq.start(env.get_sequencer());
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
**Delete at Index:**
|
| 87 |
+
```systemverilog
|
| 88 |
+
dll_vip_delete_at_index_seq delete_seq = dll_vip_delete_at_index_seq::type_id::create("delete_seq");
|
| 89 |
+
delete_seq.num_deletes = 3;
|
| 90 |
+
delete_seq.start(env.get_sequencer());
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
**Delete by Value:**
|
| 94 |
+
```systemverilog
|
| 95 |
+
dll_vip_delete_value_seq delete_seq = dll_vip_delete_value_seq::type_id::create("delete_seq");
|
| 96 |
+
delete_seq.num_deletes = 2;
|
| 97 |
+
delete_seq.start(env.get_sequencer());
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## 🧪 Available Tests
|
| 101 |
+
|
| 102 |
+
### 1. Simple Test
|
| 103 |
+
Basic insert, read, and delete operations:
|
| 104 |
+
```bash
|
| 105 |
+
vsim -c +UVM_TESTNAME=simple_test -do "run -all; quit"
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### 2. Random Test
|
| 109 |
+
Random sequence of insert/read/delete operations:
|
| 110 |
+
```bash
|
| 111 |
+
vsim -c +UVM_TESTNAME=random_test -do "run -all; quit"
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
## 📋 Doubly Linked List Operations
|
| 115 |
+
|
| 116 |
+
The VIP supports 6 operations matching the DUT (doubly_linked_list.sv):
|
| 117 |
+
|
| 118 |
+
| Operation | op | Description | Inputs | Outputs |
|
| 119 |
+
|-----------|-------|-------------|--------|---------|
|
| 120 |
+
| **READ_ADDR** | 3'b000 | Read data at address | addr_in | data_out, pre_node_addr, next_node_addr |
|
| 121 |
+
| **INSERT_AT_ADDR** | 3'b001 | Insert at address | addr_in, data_in | head, tail, length |
|
| 122 |
+
| **DELETE_VALUE** | 3'b010 | Delete first occurrence of value | data_in | head, tail, length |
|
| 123 |
+
| **DELETE_AT_ADDR** | 3'b011 | Delete node at address | addr_in | head, tail, length |
|
| 124 |
+
| **INSERT_AT_INDEX** | 3'b101 | Insert at index position | addr_in (index), data_in | head, tail, length |
|
| 125 |
+
| **DELETE_AT_INDEX** | 3'b111 | Delete at index position | addr_in (index) | head, tail, length |
|
| 126 |
+
|
| 127 |
+
## ✅ Self-Checking Features
|
| 128 |
+
|
| 129 |
+
The scoreboard automatically verifies:
|
| 130 |
+
- ✅ Data integrity for READ operations
|
| 131 |
+
- ✅ Correct list length after INSERT/DELETE
|
| 132 |
+
- ✅ INSERT when full behavior
|
| 133 |
+
- ✅ READ/DELETE when empty behavior
|
| 134 |
+
- ✅ Address-based operations vs index-based operations
|
| 135 |
+
- ✅ DELETE_VALUE finds correct first occurrence
|
| 136 |
+
- ✅ Fault flag correctness
|
| 137 |
+
- ✅ Head/tail pointer management
|
| 138 |
+
|
| 139 |
+
## 📊 Test Coverage Comparison
|
| 140 |
+
|
| 141 |
+
| tb/sv/tb.sv | UVM VIP Equivalent | Description |
|
| 142 |
+
|-------------|-------------------|-------------|
|
| 143 |
+
| `read_n_front()` (line 151) | `dll_vip_read_seq` | Read from front (head) |
|
| 144 |
+
| `read_n_back()` (line 219) | `dll_vip_read_seq` | Read from back (tail) |
|
| 145 |
+
| Insert operations | `dll_vip_insert_at_addr_seq` | Insert at address |
|
| 146 |
+
| Insert operations | `dll_vip_insert_at_index_seq` | Insert at index |
|
| 147 |
+
| Delete operations | `dll_vip_delete_at_addr_seq` | Delete at address |
|
| 148 |
+
| Delete operations | `dll_vip_delete_at_index_seq` | Delete at index |
|
| 149 |
+
| Delete operations | `dll_vip_delete_value_seq` | Delete by value |
|
| 150 |
+
|
| 151 |
+
## 🔧 Key Features
|
| 152 |
+
|
| 153 |
+
1. **Address-based and Index-based Operations**: Supports both addressing schemes
|
| 154 |
+
2. **Doubly Linked Structure**: Tracks both previous and next node addresses
|
| 155 |
+
3. **Value-based Deletion**: Can delete nodes by searching for value
|
| 156 |
+
4. **Intelligent Scoreboard**: Models linked list with address and data tracking
|
| 157 |
+
5. **Fault Detection**: Validates boundary conditions and error flags
|
| 158 |
+
6. **Head/Tail Tracking**: Monitors list head and tail pointers
|
| 159 |
+
|
| 160 |
+
## 🔍 Differences from Singly Linked List
|
| 161 |
+
|
| 162 |
+
| Aspect | Singly Linked List | Doubly Linked List |
|
| 163 |
+
|--------|-------------------|-------------------|
|
| 164 |
+
| **Node Structure** | data + next pointer | data + next + previous pointers |
|
| 165 |
+
| **Traversal** | Forward only | Forward and backward |
|
| 166 |
+
| **Operations** | 8 ops (includes sort, sum) | 6 ops (focus on insert/delete/read) |
|
| 167 |
+
| **Address Outputs** | Single next pointer | Both pre and next pointers |
|
| 168 |
+
| **Complexity** | Higher (functional ops) | Moderate (structural focus) |
|
| 169 |
+
|
| 170 |
+
## 🚨 Common Issues & Solutions
|
| 171 |
+
|
| 172 |
+
### Issue: Interface signal width mismatch
|
| 173 |
+
**Solution:** Update `dll_vip_if.sv` lines 9-19 to match your DLL's parameters:
|
| 174 |
+
```systemverilog
|
| 175 |
+
logic [DATA_WIDTH-1:0] data_in;
|
| 176 |
+
logic [ADDR_WIDTH-1:0] addr_in;
|
| 177 |
+
logic [DATA_WIDTH-1:0] data_out;
|
| 178 |
+
logic [ADDR_WIDTH-1:0] pre_node_addr;
|
| 179 |
+
logic [ADDR_WIDTH-1:0] next_node_addr;
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
### Issue: Address vs Index confusion
|
| 183 |
+
**Solution:**
|
| 184 |
+
- **Address operations (op[2]==0)**: Use actual node addresses from DUT
|
| 185 |
+
- **Index operations (op[2]==1)**: Use sequential index (0, 1, 2, ...)
|
| 186 |
+
|
| 187 |
+
### Future Work
|
| 188 |
+
- Add assertions for doubly-linked integrity (prev->next consistency)
|
| 189 |
+
- Add functional coverage for:
|
| 190 |
+
- Insert/delete at head/tail/middle
|
| 191 |
+
- Forward vs backward traversal
|
| 192 |
+
- Empty to full transitions
|
| 193 |
+
- Enhanced scoreboard to track full doubly-linked structure
|
| 194 |
+
|
| 195 |
+
## 📚 Example Usage
|
| 196 |
+
|
| 197 |
+
```systemverilog
|
| 198 |
+
class my_test extends base_test;
|
| 199 |
+
`uvm_component_utils(my_test)
|
| 200 |
+
|
| 201 |
+
task run_phase(uvm_phase phase);
|
| 202 |
+
dll_vip_insert_at_index_seq insert_seq;
|
| 203 |
+
dll_vip_read_seq read_seq;
|
| 204 |
+
dll_vip_delete_value_seq delete_seq;
|
| 205 |
+
|
| 206 |
+
phase.raise_objection(this);
|
| 207 |
+
|
| 208 |
+
// Build a list
|
| 209 |
+
insert_seq = dll_vip_insert_at_index_seq::type_id::create("insert_seq");
|
| 210 |
+
insert_seq.num_inserts = 5;
|
| 211 |
+
insert_seq.start(env.get_sequencer());
|
| 212 |
+
|
| 213 |
+
#500ns;
|
| 214 |
+
|
| 215 |
+
// Read from front to back
|
| 216 |
+
read_seq = dll_vip_read_seq::type_id::create("read_seq");
|
| 217 |
+
read_seq.num_reads = 5;
|
| 218 |
+
read_seq.start(env.get_sequencer());
|
| 219 |
+
|
| 220 |
+
#500ns;
|
| 221 |
+
|
| 222 |
+
// Delete specific values
|
| 223 |
+
delete_seq = dll_vip_delete_value_seq::type_id::create("delete_seq");
|
| 224 |
+
delete_seq.num_deletes = 2;
|
| 225 |
+
delete_seq.start(env.get_sequencer());
|
| 226 |
+
|
| 227 |
+
#500ns;
|
| 228 |
+
phase.drop_objection(this);
|
| 229 |
+
endtask
|
| 230 |
+
endclass
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
## 🎯 Key Characteristics
|
| 234 |
+
|
| 235 |
+
- **Bidirectional Traversal**: Can navigate both forward (head→tail) and backward (tail→head)
|
| 236 |
+
- **Address Management**: Internal addresses managed by DUT, not sequential
|
| 237 |
+
- **Flexible Insert/Delete**: Supports both address-based and index-based operations
|
| 238 |
+
- **Value Search**: Can find and delete nodes by data value
|
| 239 |
+
|
| 240 |
+
**Happy Verifying! 🚀**
|
| 241 |
+
|
| 242 |
+
*This VIP demonstrates advanced verification of pointer-based data structures with UVM.*
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/agent/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Agent Components
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .fifo_vip_driver import *
|
| 7 |
+
from .fifo_vip_monitor import *
|
| 8 |
+
from .fifo_vip_sequencer import *
|
| 9 |
+
from .fifo_vip_agent import *
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/agent/fifo_vip_driver.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Driver
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
import cocotb
|
| 8 |
+
from cocotb.triggers import RisingEdge, FallingEdge
|
| 9 |
+
from ..common.fifo_vip_types import FifoOp
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class FifoVipDriver(uvm_driver):
|
| 13 |
+
"""Driver for FIFO transactions"""
|
| 14 |
+
|
| 15 |
+
def __init__(self, name, parent, driver_type="WR"):
|
| 16 |
+
super().__init__(name, parent)
|
| 17 |
+
self.driver_type = driver_type # "WR" or "RD"
|
| 18 |
+
self.dut = None
|
| 19 |
+
self.cfg = None
|
| 20 |
+
|
| 21 |
+
def build_phase(self):
|
| 22 |
+
super().build_phase()
|
| 23 |
+
# Get DUT handle
|
| 24 |
+
self.dut = cocotb.top
|
| 25 |
+
# Get config
|
| 26 |
+
self.cfg = ConfigDB().get(self, "", "fifo_vip_cfg")
|
| 27 |
+
if self.cfg is None:
|
| 28 |
+
self.logger.critical("No config found")
|
| 29 |
+
|
| 30 |
+
async def run_phase(self):
|
| 31 |
+
"""Main driver run phase"""
|
| 32 |
+
# Initialize signals
|
| 33 |
+
if self.driver_type == "WR":
|
| 34 |
+
self.dut.wr_en.value = 0
|
| 35 |
+
self.dut.data_wr.value = 0
|
| 36 |
+
# Wait for reset
|
| 37 |
+
await FallingEdge(self.dut.rst)
|
| 38 |
+
await RisingEdge(self.dut.wr_clk)
|
| 39 |
+
else: # RD
|
| 40 |
+
self.dut.rd_en.value = 0
|
| 41 |
+
# Wait for reset
|
| 42 |
+
await FallingEdge(self.dut.rst)
|
| 43 |
+
await RisingEdge(self.dut.rd_clk)
|
| 44 |
+
|
| 45 |
+
# Main loop
|
| 46 |
+
while True:
|
| 47 |
+
item = await self.seq_item_port.get_next_item()
|
| 48 |
+
await self.drive_item(item)
|
| 49 |
+
self.seq_item_port.item_done()
|
| 50 |
+
|
| 51 |
+
async def drive_item(self, item):
|
| 52 |
+
"""Drive a single transaction"""
|
| 53 |
+
# Set config on item
|
| 54 |
+
item.set_config(self.cfg)
|
| 55 |
+
|
| 56 |
+
if item.op == FifoOp.WRITE and self.driver_type == "WR":
|
| 57 |
+
await self.drive_write(item)
|
| 58 |
+
elif item.op == FifoOp.READ and self.driver_type == "RD":
|
| 59 |
+
await self.drive_read(item)
|
| 60 |
+
elif item.op == FifoOp.IDLE:
|
| 61 |
+
# Just wait 2 clocks
|
| 62 |
+
if self.driver_type == "WR":
|
| 63 |
+
await RisingEdge(self.dut.wr_clk)
|
| 64 |
+
await RisingEdge(self.dut.wr_clk)
|
| 65 |
+
else:
|
| 66 |
+
await RisingEdge(self.dut.rd_clk)
|
| 67 |
+
await RisingEdge(self.dut.rd_clk)
|
| 68 |
+
|
| 69 |
+
async def drive_write(self, item):
|
| 70 |
+
"""Drive write transaction"""
|
| 71 |
+
await RisingEdge(self.dut.wr_clk)
|
| 72 |
+
# Mask data to correct width
|
| 73 |
+
data_mask = (1 << self.cfg.DATA_WIDTH) - 1
|
| 74 |
+
self.dut.data_wr.value = item.data & data_mask
|
| 75 |
+
self.dut.wr_en.value = 1
|
| 76 |
+
|
| 77 |
+
await RisingEdge(self.dut.wr_clk)
|
| 78 |
+
item.full = bool(self.dut.fifo_full.value)
|
| 79 |
+
item.success = not item.full
|
| 80 |
+
self.dut.wr_en.value = 0
|
| 81 |
+
|
| 82 |
+
self.logger.debug(f"WR_DRV: Write: {item.convert2string()}")
|
| 83 |
+
|
| 84 |
+
async def drive_read(self, item):
|
| 85 |
+
"""Drive read transaction"""
|
| 86 |
+
await RisingEdge(self.dut.rd_clk)
|
| 87 |
+
self.dut.rd_en.value = 1
|
| 88 |
+
|
| 89 |
+
await RisingEdge(self.dut.rd_clk)
|
| 90 |
+
item.empty = bool(self.dut.fifo_empty.value)
|
| 91 |
+
item.success = not item.empty
|
| 92 |
+
|
| 93 |
+
# Wait extra cycle for buffered read
|
| 94 |
+
if self.cfg.RD_BUFFER:
|
| 95 |
+
await RisingEdge(self.dut.rd_clk)
|
| 96 |
+
|
| 97 |
+
item.read_data = int(self.dut.data_rd.value)
|
| 98 |
+
self.dut.rd_en.value = 0
|
| 99 |
+
|
| 100 |
+
self.logger.debug(f"RD_DRV: Read: {item.convert2string()}")
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/agent/fifo_vip_sequencer.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Sequencer
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class FifoVipSequencer(uvm_sequencer):
|
| 10 |
+
"""Sequencer for FIFO transactions"""
|
| 11 |
+
|
| 12 |
+
def __init__(self, name, parent):
|
| 13 |
+
super().__init__(name, parent)
|
| 14 |
+
|
| 15 |
+
def build_phase(self):
|
| 16 |
+
super().build_phase()
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Common Components
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .fifo_vip_config import *
|
| 7 |
+
from .fifo_vip_seq_item import *
|
| 8 |
+
from .fifo_vip_types import *
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/fifo_vip_config.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Configuration Class
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
from .fifo_vip_types import FifoAgentMode
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class FifoVipConfig(uvm_object):
|
| 11 |
+
"""Configuration object for FIFO VIP"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, name="fifo_vip_config"):
|
| 14 |
+
super().__init__(name)
|
| 15 |
+
# DUT parameters - CHANGE THESE FOR YOUR FIFO
|
| 16 |
+
self.DEPTH = 12
|
| 17 |
+
self.DATA_WIDTH = 8
|
| 18 |
+
self.ASYNC = 1 # 1=async clocks, 0=sync
|
| 19 |
+
self.RD_BUFFER = 1 # 1=buffered read, 0=combinational
|
| 20 |
+
|
| 21 |
+
# VIP control
|
| 22 |
+
self.has_wr_agent = True
|
| 23 |
+
self.has_rd_agent = True
|
| 24 |
+
self.enable_scoreboard = True
|
| 25 |
+
|
| 26 |
+
# Agent modes
|
| 27 |
+
self.wr_agent_mode = FifoAgentMode.MASTER
|
| 28 |
+
self.rd_agent_mode = FifoAgentMode.MASTER
|
| 29 |
+
|
| 30 |
+
def print_config(self):
|
| 31 |
+
"""Print configuration"""
|
| 32 |
+
self.logger.info(
|
| 33 |
+
f"DEPTH={self.DEPTH}, DATA_WIDTH={self.DATA_WIDTH}, "
|
| 34 |
+
f"ASYNC={self.ASYNC}, RD_BUFFER={self.RD_BUFFER}"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
def __str__(self):
|
| 38 |
+
return (f"FifoVipConfig: DEPTH={self.DEPTH}, DATA_WIDTH={self.DATA_WIDTH}, "
|
| 39 |
+
f"ASYNC={self.ASYNC}, RD_BUFFER={self.RD_BUFFER}")
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/fifo_vip_seq_item.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Sequence Item
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
from .fifo_vip_types import FifoOp
|
| 8 |
+
import random
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class FifoVipSeqItem(uvm_sequence_item):
|
| 12 |
+
"""Sequence item for FIFO transactions"""
|
| 13 |
+
|
| 14 |
+
def __init__(self, name="fifo_vip_seq_item"):
|
| 15 |
+
super().__init__(name)
|
| 16 |
+
# Transaction fields
|
| 17 |
+
self.op = FifoOp.WRITE
|
| 18 |
+
self.data = 0
|
| 19 |
+
|
| 20 |
+
# Response fields
|
| 21 |
+
self.read_data = 0
|
| 22 |
+
self.full = False
|
| 23 |
+
self.empty = False
|
| 24 |
+
self.success = True
|
| 25 |
+
|
| 26 |
+
# Config reference
|
| 27 |
+
self.cfg = None
|
| 28 |
+
|
| 29 |
+
def randomize(self):
|
| 30 |
+
"""Randomize transaction fields"""
|
| 31 |
+
# Randomize operation
|
| 32 |
+
self.op = random.choice([FifoOp.WRITE, FifoOp.READ])
|
| 33 |
+
|
| 34 |
+
# Randomize data based on config
|
| 35 |
+
if self.cfg is not None:
|
| 36 |
+
max_val = (1 << self.cfg.DATA_WIDTH) - 1
|
| 37 |
+
else:
|
| 38 |
+
max_val = 255 # 8-bit default
|
| 39 |
+
|
| 40 |
+
self.data = random.randint(0, max_val)
|
| 41 |
+
return True
|
| 42 |
+
|
| 43 |
+
def randomize_with_op(self, op):
|
| 44 |
+
"""Randomize with specific operation"""
|
| 45 |
+
self.op = op
|
| 46 |
+
if self.cfg is not None:
|
| 47 |
+
max_val = (1 << self.cfg.DATA_WIDTH) - 1
|
| 48 |
+
else:
|
| 49 |
+
max_val = 255
|
| 50 |
+
self.data = random.randint(0, max_val)
|
| 51 |
+
return True
|
| 52 |
+
|
| 53 |
+
def set_config(self, cfg):
|
| 54 |
+
"""Set configuration reference"""
|
| 55 |
+
self.cfg = cfg
|
| 56 |
+
|
| 57 |
+
def convert2string(self):
|
| 58 |
+
"""Convert to string for printing"""
|
| 59 |
+
return (f"Op:{self.op.name} Data:0x{self.data:x} ReadData:0x{self.read_data:x} "
|
| 60 |
+
f"Full:{self.full} Empty:{self.empty} Success:{self.success}")
|
| 61 |
+
|
| 62 |
+
def __str__(self):
|
| 63 |
+
return self.convert2string()
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/common/fifo_vip_types.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Types and Enums
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from enum import Enum, auto
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class FifoOp(Enum):
|
| 10 |
+
"""FIFO operation types"""
|
| 11 |
+
WRITE = auto()
|
| 12 |
+
READ = auto()
|
| 13 |
+
IDLE = auto()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class FifoAgentMode(Enum):
|
| 17 |
+
"""Agent mode types"""
|
| 18 |
+
MASTER = auto()
|
| 19 |
+
SLAVE = auto()
|
| 20 |
+
MONITOR_ONLY = auto()
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/env/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Environment Components
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .fifo_vip_scoreboard import *
|
| 7 |
+
from .fifo_vip_env import *
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/env/fifo_vip_env.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Environment
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
from ..agent.fifo_vip_agent import FifoVipAgent
|
| 8 |
+
from .fifo_vip_scoreboard import FifoVipScoreboard
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class FifoVipEnv(uvm_env):
|
| 12 |
+
"""Environment for FIFO VIP"""
|
| 13 |
+
|
| 14 |
+
def __init__(self, name, parent):
|
| 15 |
+
super().__init__(name, parent)
|
| 16 |
+
self.cfg = None
|
| 17 |
+
self.wr_agent = None
|
| 18 |
+
self.rd_agent = None
|
| 19 |
+
self.sb = None
|
| 20 |
+
|
| 21 |
+
def build_phase(self):
|
| 22 |
+
super().build_phase()
|
| 23 |
+
|
| 24 |
+
# Get config
|
| 25 |
+
self.cfg = ConfigDB().get(self, "", "fifo_vip_cfg")
|
| 26 |
+
if self.cfg is None:
|
| 27 |
+
self.logger.critical("No config found")
|
| 28 |
+
|
| 29 |
+
# Set config for all components
|
| 30 |
+
ConfigDB().set(self, "*", "fifo_vip_cfg", self.cfg)
|
| 31 |
+
|
| 32 |
+
# Create agents
|
| 33 |
+
if self.cfg.has_wr_agent:
|
| 34 |
+
self.wr_agent = FifoVipAgent("wr_agent", self, agent_type="WR")
|
| 35 |
+
|
| 36 |
+
if self.cfg.has_rd_agent:
|
| 37 |
+
self.rd_agent = FifoVipAgent("rd_agent", self, agent_type="RD")
|
| 38 |
+
|
| 39 |
+
# Create scoreboard
|
| 40 |
+
if self.cfg.enable_scoreboard:
|
| 41 |
+
self.sb = FifoVipScoreboard("sb", self)
|
| 42 |
+
|
| 43 |
+
def connect_phase(self):
|
| 44 |
+
super().connect_phase()
|
| 45 |
+
|
| 46 |
+
# Connect agents to scoreboard
|
| 47 |
+
if self.cfg.enable_scoreboard and self.sb is not None:
|
| 48 |
+
if self.wr_agent is not None:
|
| 49 |
+
self.wr_agent.ap.connect(self.sb.wr_export)
|
| 50 |
+
# Connect write callback
|
| 51 |
+
self.sb.wr_export.connect_transaction_handler(self.sb.write_wr)
|
| 52 |
+
|
| 53 |
+
if self.rd_agent is not None:
|
| 54 |
+
self.rd_agent.ap.connect(self.sb.rd_export)
|
| 55 |
+
# Connect read callback
|
| 56 |
+
self.sb.rd_export.connect_transaction_handler(self.sb.write_rd)
|
| 57 |
+
|
| 58 |
+
def get_wr_sequencer(self):
|
| 59 |
+
"""Get write sequencer"""
|
| 60 |
+
if self.wr_agent is not None:
|
| 61 |
+
return self.wr_agent.sequencer
|
| 62 |
+
return None
|
| 63 |
+
|
| 64 |
+
def get_rd_sequencer(self):
|
| 65 |
+
"""Get read sequencer"""
|
| 66 |
+
if self.rd_agent is not None:
|
| 67 |
+
return self.rd_agent.sequencer
|
| 68 |
+
return None
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/env/fifo_vip_scoreboard.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Scoreboard
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
from ..common.fifo_vip_types import FifoOp
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class FifoVipScoreboard(uvm_scoreboard):
|
| 11 |
+
"""Scoreboard for FIFO VIP"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, name, parent):
|
| 14 |
+
super().__init__(name, parent)
|
| 15 |
+
# Simple queue model
|
| 16 |
+
self.fifo_model = []
|
| 17 |
+
self.errors = 0
|
| 18 |
+
self.wr_count = 0
|
| 19 |
+
self.rd_count = 0
|
| 20 |
+
|
| 21 |
+
# Create analysis exports
|
| 22 |
+
self.wr_export = uvm_analysis_export("wr_export", self)
|
| 23 |
+
self.rd_export = uvm_analysis_export("rd_export", self)
|
| 24 |
+
|
| 25 |
+
def build_phase(self):
|
| 26 |
+
super().build_phase()
|
| 27 |
+
|
| 28 |
+
def connect_phase(self):
|
| 29 |
+
super().connect_phase()
|
| 30 |
+
|
| 31 |
+
def write_wr(self, item):
|
| 32 |
+
"""Write port callback for write transactions"""
|
| 33 |
+
if item.op == FifoOp.WRITE and item.success:
|
| 34 |
+
self.fifo_model.append(item.data)
|
| 35 |
+
self.wr_count += 1
|
| 36 |
+
self.logger.info(
|
| 37 |
+
f"SB: Write: data=0x{item.data:x}, queue_size={len(self.fifo_model)}"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
def write_rd(self, item):
|
| 41 |
+
"""Write port callback for read transactions"""
|
| 42 |
+
if item.op == FifoOp.READ and item.success:
|
| 43 |
+
if len(self.fifo_model) > 0:
|
| 44 |
+
expected = self.fifo_model.pop(0)
|
| 45 |
+
self.rd_count += 1
|
| 46 |
+
if item.read_data == expected:
|
| 47 |
+
self.logger.info(
|
| 48 |
+
f"SB: Read OK: data=0x{item.read_data:x}, queue_size={len(self.fifo_model)}"
|
| 49 |
+
)
|
| 50 |
+
else:
|
| 51 |
+
self.logger.error(
|
| 52 |
+
f"SB: Data mismatch! Expected:0x{expected:x} Got:0x{item.read_data:x}"
|
| 53 |
+
)
|
| 54 |
+
self.errors += 1
|
| 55 |
+
else:
|
| 56 |
+
self.logger.error("SB: Read from empty FIFO model")
|
| 57 |
+
self.errors += 1
|
| 58 |
+
|
| 59 |
+
def report_phase(self):
|
| 60 |
+
"""Report phase - print results"""
|
| 61 |
+
self.logger.info(f"\n{'='*50}")
|
| 62 |
+
self.logger.info(f"FIFO VIP Scoreboard Report")
|
| 63 |
+
self.logger.info(f"{'='*50}")
|
| 64 |
+
self.logger.info(f"Total Writes: {self.wr_count}")
|
| 65 |
+
self.logger.info(f"Total Reads: {self.rd_count}")
|
| 66 |
+
self.logger.info(f"Errors: {self.errors}")
|
| 67 |
+
self.logger.info(f"Final Queue Size: {len(self.fifo_model)}")
|
| 68 |
+
|
| 69 |
+
if self.errors == 0:
|
| 70 |
+
self.logger.info("*** TEST PASSED ***")
|
| 71 |
+
else:
|
| 72 |
+
self.logger.error(f"*** TEST FAILED - {self.errors} errors ***")
|
| 73 |
+
self.logger.info(f"{'='*50}\n")
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Sequences
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .fifo_vip_base_seq import *
|
| 7 |
+
from .fifo_vip_write_req_seq import *
|
| 8 |
+
from .fifo_vip_read_req_seq import *
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/fifo_vip_base_seq.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Base Sequence
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class FifoVipBaseSeq(uvm_sequence):
|
| 10 |
+
"""Base sequence for FIFO VIP"""
|
| 11 |
+
|
| 12 |
+
def __init__(self, name="fifo_vip_base_seq"):
|
| 13 |
+
super().__init__(name)
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/fifo_vip_read_req_seq.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Read Request Sequence
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
from .fifo_vip_base_seq import FifoVipBaseSeq
|
| 8 |
+
from ..common.fifo_vip_seq_item import FifoVipSeqItem
|
| 9 |
+
from ..common.fifo_vip_types import FifoOp
|
| 10 |
+
import random
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class FifoVipReadReqSeq(FifoVipBaseSeq):
|
| 14 |
+
"""Read request sequence for FIFO VIP"""
|
| 15 |
+
|
| 16 |
+
def __init__(self, name="fifo_vip_read_req_seq"):
|
| 17 |
+
super().__init__(name)
|
| 18 |
+
self.num_reads = random.randint(1, 20)
|
| 19 |
+
|
| 20 |
+
async def body(self):
|
| 21 |
+
"""Sequence body"""
|
| 22 |
+
self.logger.info(f"RD_SEQ: Starting {self.num_reads} reads")
|
| 23 |
+
|
| 24 |
+
for i in range(self.num_reads):
|
| 25 |
+
item = FifoVipSeqItem(f"rd_item_{i}")
|
| 26 |
+
await self.start_item(item)
|
| 27 |
+
item.randomize_with_op(FifoOp.READ)
|
| 28 |
+
await self.finish_item(item)
|
Weiyet_RTLStructLib/source/FIFO/vip/pyuvm/sequences/fifo_vip_write_req_seq.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FIFO VIP Write Request Sequence
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pyuvm import *
|
| 7 |
+
from .fifo_vip_base_seq import FifoVipBaseSeq
|
| 8 |
+
from ..common.fifo_vip_seq_item import FifoVipSeqItem
|
| 9 |
+
from ..common.fifo_vip_types import FifoOp
|
| 10 |
+
import random
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class FifoVipWriteReqSeq(FifoVipBaseSeq):
|
| 14 |
+
"""Write request sequence for FIFO VIP"""
|
| 15 |
+
|
| 16 |
+
def __init__(self, name="fifo_vip_write_req_seq"):
|
| 17 |
+
super().__init__(name)
|
| 18 |
+
self.num_writes = random.randint(1, 20)
|
| 19 |
+
|
| 20 |
+
async def body(self):
|
| 21 |
+
"""Sequence body"""
|
| 22 |
+
self.logger.info(f"WR_SEQ: Starting {self.num_writes} writes")
|
| 23 |
+
|
| 24 |
+
for i in range(self.num_writes):
|
| 25 |
+
item = FifoVipSeqItem(f"wr_item_{i}")
|
| 26 |
+
await self.start_item(item)
|
| 27 |
+
item.randomize_with_op(FifoOp.WRITE)
|
| 28 |
+
await self.finish_item(item)
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_agent.sv
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 08:57 PM
|
| 5 |
+
// Module Name: fifo_vip_agent
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the FIFO VIP agent.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_agent extends uvm_agent;
|
| 12 |
+
`uvm_component_utils(fifo_vip_agent)
|
| 13 |
+
|
| 14 |
+
fifo_vip_driver driver;
|
| 15 |
+
fifo_vip_monitor monitor;
|
| 16 |
+
fifo_vip_sequencer sequencer;
|
| 17 |
+
|
| 18 |
+
uvm_analysis_port #(fifo_vip_seq_item) ap;
|
| 19 |
+
|
| 20 |
+
function new(string name = "fifo_vip_agent", uvm_component parent = null);
|
| 21 |
+
super.new(name, parent);
|
| 22 |
+
endfunction
|
| 23 |
+
|
| 24 |
+
function void build_phase(uvm_phase phase);
|
| 25 |
+
super.build_phase(phase);
|
| 26 |
+
|
| 27 |
+
monitor = fifo_vip_monitor::type_id::create("monitor", this);
|
| 28 |
+
|
| 29 |
+
if (is_active == UVM_ACTIVE) begin
|
| 30 |
+
driver = fifo_vip_driver::type_id::create("driver", this);
|
| 31 |
+
sequencer = fifo_vip_sequencer::type_id::create("sequencer", this);
|
| 32 |
+
end
|
| 33 |
+
endfunction
|
| 34 |
+
|
| 35 |
+
function void connect_phase(uvm_phase phase);
|
| 36 |
+
super.connect_phase(phase);
|
| 37 |
+
|
| 38 |
+
ap = monitor.ap;
|
| 39 |
+
|
| 40 |
+
if (is_active == UVM_ACTIVE) begin
|
| 41 |
+
driver.seq_item_port.connect(sequencer.seq_item_export);
|
| 42 |
+
end
|
| 43 |
+
endfunction
|
| 44 |
+
|
| 45 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_driver.sv
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 08:45 PM
|
| 5 |
+
// Module Name: fifo_vip_driver
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the FIFO VIP driver.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class fifo_vip_driver extends uvm_driver #(fifo_vip_seq_item);
|
| 13 |
+
`uvm_component_utils(fifo_vip_driver)
|
| 14 |
+
|
| 15 |
+
virtual fifo_vip_if vif;
|
| 16 |
+
fifo_vip_config cfg;
|
| 17 |
+
string driver_type; // "WR" or "RD"
|
| 18 |
+
|
| 19 |
+
function new(string name = "fifo_vip_driver", uvm_component parent = null);
|
| 20 |
+
super.new(name, parent);
|
| 21 |
+
endfunction
|
| 22 |
+
|
| 23 |
+
function void build_phase(uvm_phase phase);
|
| 24 |
+
if (!uvm_config_db#(virtual fifo_vip_if)::get(this, "", "vif", vif))
|
| 25 |
+
`uvm_fatal("DRV", "No virtual interface")
|
| 26 |
+
if (!uvm_config_db#(fifo_vip_config)::get(this, "", "cfg", cfg))
|
| 27 |
+
`uvm_fatal("DRV", "No config")
|
| 28 |
+
|
| 29 |
+
// Figure out if this is write or read driver
|
| 30 |
+
driver_type = (get_name().substr(0,1) == "w") ? "WR" : "RD";
|
| 31 |
+
endfunction
|
| 32 |
+
|
| 33 |
+
task run_phase(uvm_phase phase);
|
| 34 |
+
fifo_vip_seq_item item;
|
| 35 |
+
|
| 36 |
+
// Initialize
|
| 37 |
+
if (driver_type == "WR") begin
|
| 38 |
+
vif.wr_cb.wr_en <= 0;
|
| 39 |
+
vif.wr_cb.data_wr <= 0;
|
| 40 |
+
end else begin
|
| 41 |
+
vif.rd_cb.rd_en <= 0;
|
| 42 |
+
end
|
| 43 |
+
|
| 44 |
+
// Wait for reset
|
| 45 |
+
@(negedge vif.rst);
|
| 46 |
+
@(posedge vif.wr_clk);
|
| 47 |
+
|
| 48 |
+
forever begin
|
| 49 |
+
seq_item_port.get_next_item(item);
|
| 50 |
+
drive_item(item);
|
| 51 |
+
seq_item_port.item_done();
|
| 52 |
+
end
|
| 53 |
+
endtask
|
| 54 |
+
|
| 55 |
+
task drive_item(fifo_vip_seq_item item);
|
| 56 |
+
// Set config on item
|
| 57 |
+
item.set_config(cfg);
|
| 58 |
+
|
| 59 |
+
case (item.op)
|
| 60 |
+
WRITE: if (driver_type == "WR") drive_write(item);
|
| 61 |
+
READ: if (driver_type == "RD") drive_read(item);
|
| 62 |
+
IDLE: repeat(2) @(vif.wr_cb);
|
| 63 |
+
endcase
|
| 64 |
+
endtask
|
| 65 |
+
|
| 66 |
+
task drive_write(fifo_vip_seq_item item);
|
| 67 |
+
@(vif.wr_cb);
|
| 68 |
+
vif.wr_cb.data_wr <= item.data[cfg.DATA_WIDTH-1:0];
|
| 69 |
+
vif.wr_cb.wr_en <= 1;
|
| 70 |
+
@(vif.wr_cb);
|
| 71 |
+
item.full = vif.wr_cb.fifo_full;
|
| 72 |
+
item.success = !vif.wr_cb.fifo_full;
|
| 73 |
+
vif.wr_cb.wr_en <= 0;
|
| 74 |
+
`uvm_info("WR_DRV", $sformatf("Write: %s", item.convert2string()), UVM_HIGH)
|
| 75 |
+
endtask
|
| 76 |
+
|
| 77 |
+
task drive_read(fifo_vip_seq_item item);
|
| 78 |
+
@(vif.rd_cb);
|
| 79 |
+
vif.rd_cb.rd_en <= 1;
|
| 80 |
+
@(vif.rd_cb);
|
| 81 |
+
item.empty = vif.rd_cb.fifo_empty;
|
| 82 |
+
item.success = !vif.rd_cb.fifo_empty;
|
| 83 |
+
if (cfg.RD_BUFFER) @(vif.rd_cb); // Wait extra cycle for buffered read
|
| 84 |
+
item.read_data = vif.rd_cb.data_rd;
|
| 85 |
+
vif.rd_cb.rd_en <= 0;
|
| 86 |
+
`uvm_info("RD_DRV", $sformatf("Read: %s", item.convert2string()), UVM_HIGH)
|
| 87 |
+
endtask
|
| 88 |
+
|
| 89 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_monitor.sv
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 08:56 PM
|
| 5 |
+
// Module Name: fifo_vip_monitor
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the FIFO VIP monitor.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_monitor extends uvm_monitor;
|
| 12 |
+
`uvm_component_utils(fifo_vip_monitor)
|
| 13 |
+
|
| 14 |
+
virtual fifo_vip_if vif;
|
| 15 |
+
fifo_vip_config cfg;
|
| 16 |
+
uvm_analysis_port #(fifo_vip_seq_item) ap;
|
| 17 |
+
string monitor_type; // "WR" or "RD"
|
| 18 |
+
|
| 19 |
+
function new(string name = "fifo_vip_monitor", uvm_component parent = null);
|
| 20 |
+
super.new(name, parent);
|
| 21 |
+
ap = new("ap", this);
|
| 22 |
+
endfunction
|
| 23 |
+
|
| 24 |
+
function void build_phase(uvm_phase phase);
|
| 25 |
+
if (!uvm_config_db#(virtual fifo_vip_if)::get(this, "", "fifo_vip_vif", vif))
|
| 26 |
+
`uvm_fatal("MON", "No virtual interface")
|
| 27 |
+
if (!uvm_config_db#(fifo_vip_config)::get(this, "", "fifo_vip_cfg", cfg))
|
| 28 |
+
`uvm_fatal("MON", "No config")
|
| 29 |
+
|
| 30 |
+
// Figure out monitor type
|
| 31 |
+
monitor_type = (get_name().substr(0,1) == "w") ? "WR" : "RD";
|
| 32 |
+
endfunction
|
| 33 |
+
|
| 34 |
+
task run_phase(uvm_phase phase);
|
| 35 |
+
@(negedge vif.rst);
|
| 36 |
+
|
| 37 |
+
if (monitor_type == "WR") begin
|
| 38 |
+
monitor_writes();
|
| 39 |
+
end else begin
|
| 40 |
+
monitor_reads();
|
| 41 |
+
end
|
| 42 |
+
endtask
|
| 43 |
+
|
| 44 |
+
task monitor_writes();
|
| 45 |
+
fifo_vip_seq_item item;
|
| 46 |
+
forever begin
|
| 47 |
+
@(posedge vif.wr_clk);
|
| 48 |
+
if (vif.wr_en && !vif.rst) begin
|
| 49 |
+
item = fifo_vip_seq_item::type_id::create("wr_item");
|
| 50 |
+
item.op = WRITE;
|
| 51 |
+
item.data = vif.data_wr;
|
| 52 |
+
item.full = vif.fifo_full;
|
| 53 |
+
item.success = !vif.fifo_full;
|
| 54 |
+
ap.write(item);
|
| 55 |
+
`uvm_info("WR_MON", $sformatf("Monitored: %s", item.convert2string()), UVM_HIGH)
|
| 56 |
+
end
|
| 57 |
+
end
|
| 58 |
+
endtask
|
| 59 |
+
|
| 60 |
+
task monitor_reads();
|
| 61 |
+
fifo_vip_seq_item item;
|
| 62 |
+
forever begin
|
| 63 |
+
@(posedge vif.rd_clk);
|
| 64 |
+
if (vif.rd_en && !vif.rst) begin
|
| 65 |
+
item = fifo_vip_seq_item::type_id::create("rd_item");
|
| 66 |
+
item.op = READ;
|
| 67 |
+
item.empty = vif.fifo_empty;
|
| 68 |
+
item.success = !vif.fifo_empty;
|
| 69 |
+
if (cfg.RD_BUFFER) @(posedge vif.rd_clk); // Wait for buffered read
|
| 70 |
+
item.read_data = vif.data_rd;
|
| 71 |
+
ap.write(item);
|
| 72 |
+
`uvm_info("RD_MON", $sformatf("Monitored: %s", item.convert2string()), UVM_HIGH)
|
| 73 |
+
end
|
| 74 |
+
end
|
| 75 |
+
endtask
|
| 76 |
+
|
| 77 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/agent/fifo_vip_sequencer.sv
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:25 PM
|
| 5 |
+
// Module Name: fifo_vip_sequencer
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains all the components of the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class fifo_vip_sequencer extends uvm_sequencer #(fifo_vip_seq_item);
|
| 13 |
+
`uvm_component_utils(fifo_vip_sequencer)
|
| 14 |
+
|
| 15 |
+
function new(string name = "fifo_vip_sequencer", uvm_component parent = null);
|
| 16 |
+
super.new(name, parent);
|
| 17 |
+
endfunction
|
| 18 |
+
|
| 19 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/common/fifo_vip_config.sv
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 08:41 PM
|
| 5 |
+
// Module Name: fifo_vip_config
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the configuration class for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_config extends uvm_object;
|
| 12 |
+
`uvm_object_utils(fifo_vip_config)
|
| 13 |
+
|
| 14 |
+
// DUT parameters - CHANGE THESE FOR YOUR FIFO
|
| 15 |
+
int DEPTH = 12;
|
| 16 |
+
int DATA_WIDTH = 8;
|
| 17 |
+
bit ASYNC = 1;
|
| 18 |
+
bit RD_BUFFER = 1;
|
| 19 |
+
|
| 20 |
+
// VIP control
|
| 21 |
+
bit has_wr_agent = 1;
|
| 22 |
+
bit has_rd_agent = 1;
|
| 23 |
+
bit enable_scoreboard = 1;
|
| 24 |
+
|
| 25 |
+
// Agent modes
|
| 26 |
+
fifo_agent_mode_e wr_agent_mode = MASTER;
|
| 27 |
+
fifo_agent_mode_e rd_agent_mode = MASTER;
|
| 28 |
+
|
| 29 |
+
function new(string name = "fifo_vip_config");
|
| 30 |
+
super.new(name);
|
| 31 |
+
endfunction
|
| 32 |
+
|
| 33 |
+
function void print_config();
|
| 34 |
+
`uvm_info("CFG", $sformatf("DEPTH=%0d, DATA_WIDTH=%0d, ASYNC=%0b, RD_BUFFER=%0b",
|
| 35 |
+
DEPTH, DATA_WIDTH, ASYNC, RD_BUFFER), UVM_LOW)
|
| 36 |
+
endfunction
|
| 37 |
+
|
| 38 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/common/fifo_vip_pkg.sv
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 10:37 PM
|
| 5 |
+
// Module Name: fifo_vip_pkg
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains all the components of the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
package fifo_vip_pkg;
|
| 12 |
+
|
| 13 |
+
import uvm_pkg::*;
|
| 14 |
+
`include "uvm_macros.svh"
|
| 15 |
+
|
| 16 |
+
// Types and enums defined directly in package
|
| 17 |
+
typedef enum {
|
| 18 |
+
WRITE,
|
| 19 |
+
READ,
|
| 20 |
+
IDLE
|
| 21 |
+
} fifo_op_e;
|
| 22 |
+
|
| 23 |
+
typedef enum {
|
| 24 |
+
MASTER,
|
| 25 |
+
SLAVE,
|
| 26 |
+
MONITOR_ONLY
|
| 27 |
+
} fifo_agent_mode_e;
|
| 28 |
+
|
| 29 |
+
// Include files in order
|
| 30 |
+
`include "../src/fifo_vip_config.sv"
|
| 31 |
+
`include "../src/fifo_vip_seq_item.sv"
|
| 32 |
+
`include "../agent/fifo_vip_driver.sv"
|
| 33 |
+
`include "../agent/fifo_vip_monitor.sv"
|
| 34 |
+
`include "../agent/fifo_vip_sequencer.sv"
|
| 35 |
+
`include "../agent/fifo_vip_agent.sv"
|
| 36 |
+
`include "../env/fifo_vip_scoreboard.sv"
|
| 37 |
+
`include "../env/fifo_vip_env.sv"
|
| 38 |
+
`include "../sequences/fifo_vip_base_seq.sv"
|
| 39 |
+
`include "../sequences/fifo_vip_write_req_seq.sv"
|
| 40 |
+
`include "../sequences/fifo_vip_read_req_seq.sv"
|
| 41 |
+
|
| 42 |
+
endpackage
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/common/fifo_vip_seq_item.sv
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 08:37 PM
|
| 5 |
+
// Module Name: fifo_vip_seq_item
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the sequence item for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_seq_item extends uvm_sequence_item;
|
| 12 |
+
`uvm_object_utils(fifo_vip_seq_item)
|
| 13 |
+
|
| 14 |
+
// Transaction fields
|
| 15 |
+
rand fifo_op_e op;
|
| 16 |
+
rand bit [31:0] data;
|
| 17 |
+
|
| 18 |
+
// Response fields
|
| 19 |
+
bit [31:0] read_data;
|
| 20 |
+
bit full;
|
| 21 |
+
bit empty;
|
| 22 |
+
bit success;
|
| 23 |
+
|
| 24 |
+
// Config reference
|
| 25 |
+
fifo_vip_config cfg;
|
| 26 |
+
|
| 27 |
+
// Simple constraints
|
| 28 |
+
constraint op_dist {
|
| 29 |
+
op dist {WRITE := 50, READ := 50};
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
constraint data_c {
|
| 33 |
+
if (cfg != null) {
|
| 34 |
+
data < (1 << cfg.DATA_WIDTH);
|
| 35 |
+
} else {
|
| 36 |
+
data < 256; // 8-bit default
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function new(string name = "fifo_vip_seq_item");
|
| 41 |
+
super.new(name);
|
| 42 |
+
success = 1;
|
| 43 |
+
endfunction
|
| 44 |
+
|
| 45 |
+
function string convert2string();
|
| 46 |
+
return $sformatf("Op:%s Data:0x%0h ReadData:0x%0h Full:%0b Empty:%0b Success:%0b",
|
| 47 |
+
op.name(), data, read_data, full, empty, success);
|
| 48 |
+
endfunction
|
| 49 |
+
|
| 50 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/env/fifo_vip_env.sv
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 08:57 PM
|
| 5 |
+
// Module Name: fifo_vip_env
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the FIFO VIP environment.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
class fifo_vip_env extends uvm_env;
|
| 11 |
+
`uvm_component_utils(fifo_vip_env)
|
| 12 |
+
|
| 13 |
+
fifo_vip_config cfg;
|
| 14 |
+
fifo_vip_agent wr_agent;
|
| 15 |
+
fifo_vip_agent rd_agent;
|
| 16 |
+
fifo_vip_scoreboard sb;
|
| 17 |
+
|
| 18 |
+
function new(string name = "fifo_vip_env", uvm_component parent = null);
|
| 19 |
+
super.new(name, parent);
|
| 20 |
+
endfunction
|
| 21 |
+
|
| 22 |
+
function void build_phase(uvm_phase phase);
|
| 23 |
+
super.build_phase(phase);
|
| 24 |
+
|
| 25 |
+
if (!uvm_config_db#(fifo_vip_config)::get(this, "", "fifo_vip_cfg", cfg))
|
| 26 |
+
`uvm_fatal("ENV", "No config")
|
| 27 |
+
|
| 28 |
+
// Set config for all components
|
| 29 |
+
uvm_config_db#(fifo_vip_config)::set(this, "*", "fifo_vip_cfg", cfg);
|
| 30 |
+
|
| 31 |
+
// Create agents
|
| 32 |
+
if (cfg.has_wr_agent) begin
|
| 33 |
+
wr_agent = fifo_vip_agent::type_id::create("wr_agent", this);
|
| 34 |
+
end
|
| 35 |
+
|
| 36 |
+
if (cfg.has_rd_agent) begin
|
| 37 |
+
rd_agent = fifo_vip_agent::type_id::create("rd_agent", this);
|
| 38 |
+
end
|
| 39 |
+
|
| 40 |
+
// Create scoreboard
|
| 41 |
+
if (cfg.enable_scoreboard) begin
|
| 42 |
+
sb = fifo_vip_scoreboard::type_id::create("sb", this);
|
| 43 |
+
end
|
| 44 |
+
endfunction
|
| 45 |
+
|
| 46 |
+
function void connect_phase(uvm_phase phase);
|
| 47 |
+
super.connect_phase(phase);
|
| 48 |
+
|
| 49 |
+
if (cfg.enable_scoreboard && sb != null) begin
|
| 50 |
+
if (wr_agent != null) wr_agent.ap.connect(sb.wr_imp);
|
| 51 |
+
if (rd_agent != null) rd_agent.ap.connect(sb.rd_imp);
|
| 52 |
+
end
|
| 53 |
+
endfunction
|
| 54 |
+
|
| 55 |
+
// Helper functions for tests
|
| 56 |
+
function fifo_vip_sequencer get_wr_sequencer();
|
| 57 |
+
return (wr_agent != null) ? wr_agent.sequencer : null;
|
| 58 |
+
endfunction
|
| 59 |
+
|
| 60 |
+
function fifo_vip_sequencer get_rd_sequencer();
|
| 61 |
+
return (rd_agent != null) ? rd_agent.sequencer : null;
|
| 62 |
+
endfunction
|
| 63 |
+
|
| 64 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/env/fifo_vip_scoreboard.sv
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:01 PM
|
| 5 |
+
// Module Name: fifo_vip_scoreboard.sv
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the FIFO VIP scoreboard.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_scoreboard extends uvm_scoreboard;
|
| 12 |
+
`uvm_component_utils(fifo_vip_scoreboard)
|
| 13 |
+
|
| 14 |
+
uvm_analysis_imp_wr #(fifo_vip_seq_item, fifo_vip_scoreboard) wr_imp;
|
| 15 |
+
uvm_analysis_imp_rd #(fifo_vip_seq_item, fifo_vip_scoreboard) rd_imp;
|
| 16 |
+
|
| 17 |
+
// Simple queue model
|
| 18 |
+
int fifo_model[$];
|
| 19 |
+
int errors = 0;
|
| 20 |
+
|
| 21 |
+
function new(string name = "fifo_vip_scoreboard", uvm_component parent = null);
|
| 22 |
+
super.new(name, parent);
|
| 23 |
+
wr_imp = new("wr_imp", this);
|
| 24 |
+
rd_imp = new("rd_imp", this);
|
| 25 |
+
endfunction
|
| 26 |
+
|
| 27 |
+
function void write_wr(fifo_vip_seq_item item);
|
| 28 |
+
if (item.op == WRITE && item.success) begin
|
| 29 |
+
fifo_model.push_back(item.data);
|
| 30 |
+
`uvm_info("SB", $sformatf("Write: data=0x%0h, queue_size=%0d", item.data, fifo_model.size()), UVM_MEDIUM)
|
| 31 |
+
end
|
| 32 |
+
endfunction
|
| 33 |
+
|
| 34 |
+
function void write_rd(fifo_vip_seq_item item);
|
| 35 |
+
if (item.op == READ && item.success) begin
|
| 36 |
+
if (fifo_model.size() > 0) begin
|
| 37 |
+
int expected = fifo_model.pop_front();
|
| 38 |
+
if (item.read_data == expected) begin
|
| 39 |
+
`uvm_info("SB", $sformatf("Read OK: data=0x%0h, queue_size=%0d", item.read_data, fifo_model.size()), UVM_MEDIUM)
|
| 40 |
+
end else begin
|
| 41 |
+
`uvm_error("SB", $sformatf("Data mismatch! Expected:0x%0h Got:0x%0h", expected, item.read_data))
|
| 42 |
+
errors++;
|
| 43 |
+
end
|
| 44 |
+
end else begin
|
| 45 |
+
`uvm_error("SB", "Read from empty FIFO model")
|
| 46 |
+
errors++;
|
| 47 |
+
end
|
| 48 |
+
end
|
| 49 |
+
endfunction
|
| 50 |
+
|
| 51 |
+
function void report_phase(uvm_phase phase);
|
| 52 |
+
if (errors == 0)
|
| 53 |
+
`uvm_info("SB", "*** TEST PASSED ***", UVM_LOW)
|
| 54 |
+
else
|
| 55 |
+
`uvm_error("SB", $sformatf("*** TEST FAILED - %0d errors ***", errors))
|
| 56 |
+
endfunction
|
| 57 |
+
|
| 58 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/interface/fifo_vip_if.sv
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:28 PM
|
| 5 |
+
// Module Name: fifo_vip_if
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the FIFO VIP interface.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
interface fifo_vip_if(input logic wr_clk, input logic rd_clk);
|
| 13 |
+
|
| 14 |
+
// Signals matching your FIFO
|
| 15 |
+
logic rst;
|
| 16 |
+
logic [7:0] data_wr;
|
| 17 |
+
logic wr_en;
|
| 18 |
+
logic fifo_full;
|
| 19 |
+
logic [7:0] data_rd;
|
| 20 |
+
logic rd_en;
|
| 21 |
+
logic fifo_empty;
|
| 22 |
+
|
| 23 |
+
// Simple clocking blocks
|
| 24 |
+
clocking wr_cb @(posedge wr_clk);
|
| 25 |
+
output data_wr, wr_en;
|
| 26 |
+
input fifo_full;
|
| 27 |
+
endclocking
|
| 28 |
+
|
| 29 |
+
clocking rd_cb @(posedge rd_clk);
|
| 30 |
+
output rd_en;
|
| 31 |
+
input data_rd, fifo_empty;
|
| 32 |
+
endclocking
|
| 33 |
+
|
| 34 |
+
// Modports
|
| 35 |
+
modport wr_drv (clocking wr_cb, input rst);
|
| 36 |
+
modport rd_drv (clocking rd_cb, input rst);
|
| 37 |
+
|
| 38 |
+
endinterface
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/sequences/fifo_vip_base_seq.sv
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:27 PM
|
| 5 |
+
// Module Name: fifo_vip_base_seq
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This sequence serves as a base class for FIFO VIP sequences.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_base_seq extends uvm_sequence #(fifo_vip_seq_item);
|
| 12 |
+
`uvm_object_utils(fifo_vip_base_seq)
|
| 13 |
+
|
| 14 |
+
fifo_vip_config cfg;
|
| 15 |
+
|
| 16 |
+
function new(string name = "fifo_vip_base_seq");
|
| 17 |
+
super.new(name);
|
| 18 |
+
endfunction
|
| 19 |
+
|
| 20 |
+
task pre_body();
|
| 21 |
+
if (!uvm_config_db#(fifo_vip_config)::get(m_sequencer, "", "fifo_vip_cfg", cfg)) begin
|
| 22 |
+
`uvm_warning("SEQ", "No config found")
|
| 23 |
+
end
|
| 24 |
+
endtask
|
| 25 |
+
|
| 26 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/sequences/fifo_vip_read_req_seq.sv
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:04 PM
|
| 5 |
+
// Module Name: fifo_vip_read_req_seq
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This sequence generates read requests for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class fifo_vip_read_req_seq extends fifo_vip_base_seq;
|
| 12 |
+
`uvm_object_utils(fifo_vip_read_req_seq)
|
| 13 |
+
|
| 14 |
+
rand int num_reads;
|
| 15 |
+
|
| 16 |
+
constraint num_reads_c {
|
| 17 |
+
num_reads inside {[1:20]};
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function new(string name = "fifo_vip_read_req_seq");
|
| 21 |
+
super.new(name);
|
| 22 |
+
endfunction
|
| 23 |
+
|
| 24 |
+
task body();
|
| 25 |
+
fifo_vip_seq_item item;
|
| 26 |
+
|
| 27 |
+
`uvm_info("RD_SEQ", $sformatf("Starting %0d reads", num_reads), UVM_MEDIUM)
|
| 28 |
+
|
| 29 |
+
repeat(num_reads) begin
|
| 30 |
+
item = fifo_vip_seq_item::type_id::create("item");
|
| 31 |
+
start_item(item);
|
| 32 |
+
assert(item.randomize() with {op == READ;});
|
| 33 |
+
finish_item(item);
|
| 34 |
+
end
|
| 35 |
+
endtask
|
| 36 |
+
|
| 37 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/sequences/fifo_vip_write_req_seq.sv
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:25 PM
|
| 5 |
+
// Module Name: fifo_vip_write_req_seq
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This sequence generates write requests for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class fifo_vip_write_req_seq extends fifo_vip_base_seq;
|
| 13 |
+
`uvm_object_utils(fifo_vip_write_req_seq)
|
| 14 |
+
|
| 15 |
+
rand int num_writes;
|
| 16 |
+
|
| 17 |
+
constraint num_writes_c {
|
| 18 |
+
num_writes inside {[1:20]};
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function new(string name = "fifo_vip_write_req_seq");
|
| 22 |
+
super.new(name);
|
| 23 |
+
endfunction
|
| 24 |
+
|
| 25 |
+
task body();
|
| 26 |
+
fifo_vip_seq_item item;
|
| 27 |
+
|
| 28 |
+
`uvm_info("WR_SEQ", $sformatf("Starting %0d writes", num_writes), UVM_MEDIUM)
|
| 29 |
+
|
| 30 |
+
repeat(num_writes) begin
|
| 31 |
+
item = fifo_vip_seq_item::type_id::create("item");
|
| 32 |
+
start_item(item);
|
| 33 |
+
assert(item.randomize() with {op == WRITE;});
|
| 34 |
+
finish_item(item);
|
| 35 |
+
end
|
| 36 |
+
endtask
|
| 37 |
+
|
| 38 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/sim/tb_top.sv
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 09:04 PM
|
| 5 |
+
// Module Name: tb_top
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This is the top-level testbench for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
`timescale 1ns/1ps
|
| 13 |
+
|
| 14 |
+
module tb_top;
|
| 15 |
+
import uvm_pkg::*;
|
| 16 |
+
import fifo_vip_pkg::*;
|
| 17 |
+
|
| 18 |
+
// Clocks
|
| 19 |
+
logic wr_clk = 0;
|
| 20 |
+
logic rd_clk = 0;
|
| 21 |
+
|
| 22 |
+
// Clock generation - MODIFY PERIODS AS NEEDED
|
| 23 |
+
always #10 wr_clk = ~wr_clk; // 50MHz
|
| 24 |
+
always #16 rd_clk = ~rd_clk; // 31.25MHz
|
| 25 |
+
|
| 26 |
+
// Interface
|
| 27 |
+
fifo_vip_if dut_if(wr_clk, rd_clk);
|
| 28 |
+
|
| 29 |
+
// Reset
|
| 30 |
+
initial begin
|
| 31 |
+
dut_if.rst = 1;
|
| 32 |
+
repeat(5) @(posedge wr_clk);
|
| 33 |
+
dut_if.rst = 0;
|
| 34 |
+
end
|
| 35 |
+
|
| 36 |
+
// DUT instantiation - MODIFY FOR YOUR FIFO
|
| 37 |
+
fifo #(
|
| 38 |
+
.DEPTH(12),
|
| 39 |
+
.DATA_WIDTH(8),
|
| 40 |
+
.ASYNC(1),
|
| 41 |
+
.RD_BUFFER(1)
|
| 42 |
+
) dut (
|
| 43 |
+
.rd_clk(rd_clk),
|
| 44 |
+
.wr_clk(wr_clk),
|
| 45 |
+
.rst(dut_if.rst),
|
| 46 |
+
.data_wr(dut_if.data_wr),
|
| 47 |
+
.wr_en(dut_if.wr_en),
|
| 48 |
+
.fifo_full(dut_if.fifo_full),
|
| 49 |
+
.data_rd(dut_if.data_rd),
|
| 50 |
+
.rd_en(dut_if.rd_en),
|
| 51 |
+
.fifo_empty(dut_if.fifo_empty)
|
| 52 |
+
);
|
| 53 |
+
|
| 54 |
+
// UVM testbench
|
| 55 |
+
initial begin
|
| 56 |
+
uvm_config_db#(virtual fifo_vip_if)::set(null, "*", "fifo_vip_vif", dut_if);
|
| 57 |
+
|
| 58 |
+
$dumpfile("waves.vcd");
|
| 59 |
+
$dumpvars(0, tb_top);
|
| 60 |
+
|
| 61 |
+
run_test();
|
| 62 |
+
end
|
| 63 |
+
|
| 64 |
+
// Timeout
|
| 65 |
+
initial begin
|
| 66 |
+
#50us;
|
| 67 |
+
$finish;
|
| 68 |
+
end
|
| 69 |
+
|
| 70 |
+
endmodule
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/sim/tests/fifo_vip_base_test.sv
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 10:04 PM
|
| 5 |
+
// Module Name: fifo_vip_base_test
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the base test for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class base_test extends uvm_test;
|
| 12 |
+
`uvm_component_utils(base_test)
|
| 13 |
+
|
| 14 |
+
fifo_vip_env env;
|
| 15 |
+
fifo_vip_config cfg;
|
| 16 |
+
|
| 17 |
+
function new(string name = "base_test", uvm_component parent = null);
|
| 18 |
+
super.new(name, parent);
|
| 19 |
+
endfunction
|
| 20 |
+
|
| 21 |
+
function void build_phase(uvm_phase phase);
|
| 22 |
+
super.build_phase(phase);
|
| 23 |
+
|
| 24 |
+
// Create config - MODIFY FOR YOUR FIFO
|
| 25 |
+
cfg = fifo_vip_config::type_id::create("cfg");
|
| 26 |
+
cfg.DEPTH = 12; // Change this
|
| 27 |
+
cfg.DATA_WIDTH = 8; // Change this
|
| 28 |
+
cfg.ASYNC = 1; // Change this
|
| 29 |
+
cfg.RD_BUFFER = 1; // Change this
|
| 30 |
+
|
| 31 |
+
// Set config in database with better field name
|
| 32 |
+
uvm_config_db#(fifo_vip_config)::set(this, "*", "fifo_vip_cfg", cfg);
|
| 33 |
+
|
| 34 |
+
env = fifo_vip_env::type_id::create("env", this);
|
| 35 |
+
endfunction
|
| 36 |
+
|
| 37 |
+
function void end_of_elaboration_phase(uvm_phase phase);
|
| 38 |
+
cfg.print_config();
|
| 39 |
+
uvm_top.print_topology();
|
| 40 |
+
endfunction
|
| 41 |
+
|
| 42 |
+
endclass
|
Weiyet_RTLStructLib/source/FIFO/vip/uvm/sim/tests/fifo_vip_simple_test.sv
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// Create Date: 05/24/2024 03:37 PM
|
| 4 |
+
// Last Update Date: 05/24/2024 10:04 PM
|
| 5 |
+
// Module Name: fifo_vip_base_test
|
| 6 |
+
// Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
|
| 7 |
+
// Description: This package contains the base test for the FIFO VIP.
|
| 8 |
+
//
|
| 9 |
+
//////////////////////////////////////////////////////////////////////////////////
|
| 10 |
+
|
| 11 |
+
class simple_test extends base_test;
|
| 12 |
+
`uvm_component_utils(simple_test)
|
| 13 |
+
|
| 14 |
+
function new(string name = "simple_test", uvm_component parent = null);
|
| 15 |
+
super.new(name, parent);
|
| 16 |
+
endfunction
|
| 17 |
+
|
| 18 |
+
task run_phase(uvm_phase phase);
|
| 19 |
+
fifo_vip_write_req_seq wr_seq;
|
| 20 |
+
fifo_vip_read_req_seq rd_seq;
|
| 21 |
+
|
| 22 |
+
phase.raise_objection(this);
|
| 23 |
+
|
| 24 |
+
// Write some data
|
| 25 |
+
wr_seq = fifo_vip_write_req_seq::type_id::create("wr_seq");
|
| 26 |
+
wr_seq.num_writes = 8;
|
| 27 |
+
wr_seq.start(env.get_wr_sequencer());
|
| 28 |
+
|
| 29 |
+
#200ns;
|
| 30 |
+
|
| 31 |
+
// Read it back
|
| 32 |
+
rd_seq = fifo_vip_read_req_seq::type_id::create("rd_seq");
|
| 33 |
+
rd_seq.num_reads = 8;
|
| 34 |
+
rd_seq.start(env.get_rd_sequencer());
|
| 35 |
+
|
| 36 |
+
#200ns;
|
| 37 |
+
phase.drop_objection(this);
|
| 38 |
+
endtask
|
| 39 |
+
|
| 40 |
+
endclass
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/agent/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Hash Table VIP Agent Package
|
| 3 |
+
"""
|
| 4 |
+
from .ht_vip_driver import HtVipDriver
|
| 5 |
+
from .ht_vip_monitor import HtVipMonitor
|
| 6 |
+
from .ht_vip_sequencer import HtVipSequencer
|
| 7 |
+
from .ht_vip_agent import HtVipAgent
|
| 8 |
+
|
| 9 |
+
__all__ = ['HtVipDriver', 'HtVipMonitor', 'HtVipSequencer', 'HtVipAgent']
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/agent/ht_vip_agent.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Agent"""
|
| 2 |
+
from pyuvm import *
|
| 3 |
+
from .ht_vip_driver import HtVipDriver
|
| 4 |
+
from .ht_vip_monitor import HtVipMonitor
|
| 5 |
+
from .ht_vip_sequencer import HtVipSequencer
|
| 6 |
+
|
| 7 |
+
class HtVipAgent(uvm_agent):
|
| 8 |
+
def __init__(self, name, parent):
|
| 9 |
+
super().__init__(name, parent)
|
| 10 |
+
self.driver = None
|
| 11 |
+
self.monitor = None
|
| 12 |
+
self.sequencer = None
|
| 13 |
+
self.ap = None
|
| 14 |
+
|
| 15 |
+
def build_phase(self):
|
| 16 |
+
super().build_phase()
|
| 17 |
+
self.monitor = HtVipMonitor("monitor", self)
|
| 18 |
+
cfg = ConfigDB().get(self, "", "ht_vip_cfg")
|
| 19 |
+
if cfg and cfg.is_active:
|
| 20 |
+
self.driver = HtVipDriver("driver", self)
|
| 21 |
+
self.sequencer = HtVipSequencer("sequencer", self)
|
| 22 |
+
|
| 23 |
+
def connect_phase(self):
|
| 24 |
+
super().connect_phase()
|
| 25 |
+
self.ap = self.monitor.ap
|
| 26 |
+
cfg = ConfigDB().get(self, "", "ht_vip_cfg")
|
| 27 |
+
if cfg and cfg.is_active and self.driver and self.sequencer:
|
| 28 |
+
self.driver.seq_item_port.connect(self.sequencer.seq_item_export)
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/agent/ht_vip_driver.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Driver"""
|
| 2 |
+
from pyuvm import *
|
| 3 |
+
import cocotb
|
| 4 |
+
from cocotb.triggers import RisingEdge
|
| 5 |
+
from ..common.ht_vip_seq_item import HtVipSeqItem
|
| 6 |
+
from ..common.ht_vip_types import HtOp
|
| 7 |
+
|
| 8 |
+
class HtVipDriver(uvm_driver):
|
| 9 |
+
def __init__(self, name, parent):
|
| 10 |
+
super().__init__(name, parent)
|
| 11 |
+
self.dut = None
|
| 12 |
+
self.cfg = None
|
| 13 |
+
|
| 14 |
+
def build_phase(self):
|
| 15 |
+
super().build_phase()
|
| 16 |
+
self.cfg = ConfigDB().get(self, "", "ht_vip_cfg")
|
| 17 |
+
|
| 18 |
+
async def run_phase(self):
|
| 19 |
+
self.dut = ConfigDB().get(self, "", "ht_vip_dut")
|
| 20 |
+
self.dut.op_sel.value = 3
|
| 21 |
+
self.dut.op_en.value = 0
|
| 22 |
+
self.dut.key_in.value = 0
|
| 23 |
+
self.dut.value_in.value = 0
|
| 24 |
+
|
| 25 |
+
while True:
|
| 26 |
+
item = await self.seq_item_port.get_next_item()
|
| 27 |
+
await self.drive_item(item)
|
| 28 |
+
self.seq_item_port.item_done()
|
| 29 |
+
|
| 30 |
+
async def drive_item(self, item):
|
| 31 |
+
await RisingEdge(self.dut.clk)
|
| 32 |
+
self.dut.op_sel.value = item.op.value
|
| 33 |
+
self.dut.op_en.value = 1
|
| 34 |
+
self.dut.key_in.value = item.key
|
| 35 |
+
self.dut.value_in.value = item.value
|
| 36 |
+
|
| 37 |
+
await RisingEdge(self.dut.clk)
|
| 38 |
+
self.dut.op_en.value = 0
|
| 39 |
+
|
| 40 |
+
while not self.dut.op_done.value:
|
| 41 |
+
await RisingEdge(self.dut.clk)
|
| 42 |
+
|
| 43 |
+
item.result_value = int(self.dut.value_out.value)
|
| 44 |
+
item.op_done = bool(self.dut.op_done.value)
|
| 45 |
+
item.op_error = bool(self.dut.op_error.value)
|
| 46 |
+
item.collision_count = int(self.dut.collision_count.value)
|
| 47 |
+
|
| 48 |
+
await RisingEdge(self.dut.clk)
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Hash Table VIP Common Package
|
| 3 |
+
Contains configuration, types, and sequence item definitions
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .ht_vip_types import HtOp
|
| 7 |
+
from .ht_vip_config import HtVipConfig
|
| 8 |
+
from .ht_vip_seq_item import HtVipSeqItem
|
| 9 |
+
|
| 10 |
+
__all__ = [
|
| 11 |
+
'HtOp',
|
| 12 |
+
'HtVipConfig',
|
| 13 |
+
'HtVipSeqItem',
|
| 14 |
+
]
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/ht_vip_config.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Hash Table VIP Configuration
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
|
| 5 |
+
Configuration class for Hash Table VIP
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from pyuvm import *
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class HtVipConfig(uvm_object):
|
| 12 |
+
"""Configuration object for Hash Table VIP"""
|
| 13 |
+
|
| 14 |
+
def __init__(self, name="ht_vip_config"):
|
| 15 |
+
super().__init__(name)
|
| 16 |
+
|
| 17 |
+
# DUT parameters
|
| 18 |
+
self.KEY_WIDTH = 32
|
| 19 |
+
self.VALUE_WIDTH = 32
|
| 20 |
+
self.TOTAL_INDEX = 8
|
| 21 |
+
self.CHAINING_SIZE = 4
|
| 22 |
+
self.COLLISION_METHOD = "MULTI_STAGE_CHAINING"
|
| 23 |
+
self.HASH_ALGORITHM = "MODULUS"
|
| 24 |
+
|
| 25 |
+
# VIP configuration
|
| 26 |
+
self.has_agent = True
|
| 27 |
+
self.enable_scoreboard = True
|
| 28 |
+
self.is_active = True
|
| 29 |
+
|
| 30 |
+
def do_print(self, printer=None):
|
| 31 |
+
"""Print configuration"""
|
| 32 |
+
self.logger.info(f"KEY_WIDTH: {self.KEY_WIDTH}")
|
| 33 |
+
self.logger.info(f"VALUE_WIDTH: {self.VALUE_WIDTH}")
|
| 34 |
+
self.logger.info(f"TOTAL_INDEX: {self.TOTAL_INDEX}")
|
| 35 |
+
self.logger.info(f"CHAINING_SIZE: {self.CHAINING_SIZE}")
|
| 36 |
+
self.logger.info(f"COLLISION_METHOD: {self.COLLISION_METHOD}")
|
| 37 |
+
self.logger.info(f"HASH_ALGORITHM: {self.HASH_ALGORITHM}")
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/ht_vip_seq_item.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Hash Table VIP Sequence Item
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
|
| 5 |
+
Transaction item for Hash Table operations (key-value pairs)
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from pyuvm import *
|
| 9 |
+
import random
|
| 10 |
+
from .ht_vip_types import HtOp
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class HtVipSeqItem(uvm_sequence_item):
|
| 14 |
+
"""Sequence item for Hash Table transactions"""
|
| 15 |
+
|
| 16 |
+
def __init__(self, name="ht_vip_seq_item"):
|
| 17 |
+
super().__init__(name)
|
| 18 |
+
|
| 19 |
+
# Transaction fields (key-value pairs)
|
| 20 |
+
self.op = HtOp.INSERT
|
| 21 |
+
self.key = 0
|
| 22 |
+
self.value = 0
|
| 23 |
+
|
| 24 |
+
# Response fields
|
| 25 |
+
self.result_value = 0
|
| 26 |
+
self.op_done = False
|
| 27 |
+
self.op_error = False
|
| 28 |
+
self.collision_count = 0
|
| 29 |
+
|
| 30 |
+
# Config reference
|
| 31 |
+
self.cfg = None
|
| 32 |
+
|
| 33 |
+
def randomize_with_op(self, op):
|
| 34 |
+
"""Randomize item with specific operation"""
|
| 35 |
+
self.op = op
|
| 36 |
+
|
| 37 |
+
if self.cfg:
|
| 38 |
+
key_max = (1 << self.cfg.KEY_WIDTH) - 1
|
| 39 |
+
value_max = (1 << self.cfg.VALUE_WIDTH) - 1
|
| 40 |
+
else:
|
| 41 |
+
key_max = 0xFFFFFFFF
|
| 42 |
+
value_max = 0xFFFFFFFF
|
| 43 |
+
|
| 44 |
+
# Key should not be 0
|
| 45 |
+
self.key = random.randint(1, key_max)
|
| 46 |
+
self.value = random.randint(0, value_max)
|
| 47 |
+
|
| 48 |
+
def randomize(self):
|
| 49 |
+
"""Randomize all fields with distribution"""
|
| 50 |
+
# Random operation with distribution
|
| 51 |
+
op_choice = random.choices(
|
| 52 |
+
[HtOp.INSERT, HtOp.DELETE, HtOp.SEARCH],
|
| 53 |
+
weights=[40, 30, 30]
|
| 54 |
+
)[0]
|
| 55 |
+
|
| 56 |
+
self.randomize_with_op(op_choice)
|
| 57 |
+
|
| 58 |
+
def convert2string(self):
|
| 59 |
+
"""Convert to string for printing"""
|
| 60 |
+
return (f"Op:{self.op.name} Key:0x{self.key:x} Value:0x{self.value:x} "
|
| 61 |
+
f"Result:0x{self.result_value:x} Done:{self.op_done} "
|
| 62 |
+
f"Error:{self.op_error} Collisions:{self.collision_count}")
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/common/ht_vip_types.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Hash Table VIP Types
|
| 3 |
+
Create Date: 01/05/2026
|
| 4 |
+
|
| 5 |
+
Enumerations and types for Hash Table VIP
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from enum import Enum
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class HtOp(Enum):
|
| 12 |
+
"""Hash Table operation types matching DUT operations"""
|
| 13 |
+
INSERT = 0 # Insert key-value pair
|
| 14 |
+
DELETE = 1 # Delete by key
|
| 15 |
+
SEARCH = 2 # Search by key
|
| 16 |
+
IDLE = 3 # No operation
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/env/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Environment Package"""
|
| 2 |
+
from .ht_vip_scoreboard import HtVipScoreboard
|
| 3 |
+
from .ht_vip_env import HtVipEnv
|
| 4 |
+
__all__ = ['HtVipScoreboard', 'HtVipEnv']
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/env/ht_vip_env.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Environment"""
|
| 2 |
+
from pyuvm import *
|
| 3 |
+
from ..agent.ht_vip_agent import HtVipAgent
|
| 4 |
+
from .ht_vip_scoreboard import HtVipScoreboard
|
| 5 |
+
|
| 6 |
+
class HtVipEnv(uvm_env):
|
| 7 |
+
def __init__(self, name, parent):
|
| 8 |
+
super().__init__(name, parent)
|
| 9 |
+
self.cfg = None
|
| 10 |
+
self.agent = None
|
| 11 |
+
self.sb = None
|
| 12 |
+
|
| 13 |
+
def build_phase(self):
|
| 14 |
+
super().build_phase()
|
| 15 |
+
self.cfg = ConfigDB().get(self, "", "ht_vip_cfg")
|
| 16 |
+
ConfigDB().set(self, "*", "ht_vip_cfg", self.cfg)
|
| 17 |
+
if self.cfg.has_agent:
|
| 18 |
+
self.agent = HtVipAgent("agent", self)
|
| 19 |
+
if self.cfg.enable_scoreboard:
|
| 20 |
+
self.sb = HtVipScoreboard("sb", self)
|
| 21 |
+
|
| 22 |
+
def connect_phase(self):
|
| 23 |
+
super().connect_phase()
|
| 24 |
+
if self.cfg.enable_scoreboard and self.sb and self.agent:
|
| 25 |
+
self.agent.ap.connect(self.sb.imp)
|
| 26 |
+
|
| 27 |
+
def get_sequencer(self):
|
| 28 |
+
return self.agent.sequencer if self.agent else None
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/env/ht_vip_scoreboard.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Scoreboard - tracks key-value pairs"""
|
| 2 |
+
from pyuvm import *
|
| 3 |
+
from ..common.ht_vip_types import HtOp
|
| 4 |
+
|
| 5 |
+
class HtVipScoreboard(uvm_scoreboard):
|
| 6 |
+
def __init__(self, name, parent):
|
| 7 |
+
super().__init__(name, parent)
|
| 8 |
+
self.imp = uvm_analysis_export("imp", self)
|
| 9 |
+
self.hash_model = {} # Python dict as reference model
|
| 10 |
+
self.error_count = 0
|
| 11 |
+
|
| 12 |
+
def connect_phase(self):
|
| 13 |
+
super().connect_phase()
|
| 14 |
+
self.imp.connect(self)
|
| 15 |
+
|
| 16 |
+
def write(self, item):
|
| 17 |
+
if item.op == HtOp.INSERT:
|
| 18 |
+
if not item.op_error:
|
| 19 |
+
self.hash_model[item.key] = item.value
|
| 20 |
+
self.logger.info(f"INSERT key=0x{item.key:x} value=0x{item.value:x}")
|
| 21 |
+
elif item.op == HtOp.DELETE:
|
| 22 |
+
if not item.op_error:
|
| 23 |
+
if item.key in self.hash_model:
|
| 24 |
+
del self.hash_model[item.key]
|
| 25 |
+
self.logger.info(f"DELETE key=0x{item.key:x}")
|
| 26 |
+
elif item.op == HtOp.SEARCH:
|
| 27 |
+
if item.key in self.hash_model:
|
| 28 |
+
if item.result_value != self.hash_model[item.key]:
|
| 29 |
+
self.logger.error(f"SEARCH mismatch! Expected=0x{self.hash_model[item.key]:x} Actual=0x{item.result_value:x}")
|
| 30 |
+
self.error_count += 1
|
| 31 |
+
else:
|
| 32 |
+
self.logger.info(f"SEARCH key=0x{item.key:x} MATCH")
|
| 33 |
+
|
| 34 |
+
def report_phase(self):
|
| 35 |
+
super().report_phase()
|
| 36 |
+
self.logger.info("="*50)
|
| 37 |
+
self.logger.info(f"Hash Table Size: {len(self.hash_model)}")
|
| 38 |
+
self.logger.info(f"Error Count: {self.error_count}")
|
| 39 |
+
if self.error_count > 0:
|
| 40 |
+
self.logger.error(f"Test FAILED with {self.error_count} errors")
|
| 41 |
+
else:
|
| 42 |
+
self.logger.info("Test PASSED")
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/sequences/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Sequences Package"""
|
| 2 |
+
from .ht_vip_base_seq import HtVipBaseSeq
|
| 3 |
+
from .ht_vip_insert_seq import HtVipInsertSeq
|
| 4 |
+
from .ht_vip_search_seq import HtVipSearchSeq
|
| 5 |
+
from .ht_vip_delete_seq import HtVipDeleteSeq
|
| 6 |
+
__all__ = ['HtVipBaseSeq', 'HtVipInsertSeq', 'HtVipSearchSeq', 'HtVipDeleteSeq']
|
Weiyet_RTLStructLib/source/Hash_Table/vip/pyuvm/sequences/ht_vip_base_seq.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hash Table VIP Base Sequence"""
|
| 2 |
+
from pyuvm import *
|
| 3 |
+
from ..common.ht_vip_seq_item import HtVipSeqItem
|
| 4 |
+
|
| 5 |
+
class HtVipBaseSeq(uvm_sequence):
|
| 6 |
+
def __init__(self, name):
|
| 7 |
+
super().__init__(name)
|
| 8 |
+
self.cfg = None
|
| 9 |
+
|
| 10 |
+
async def pre_body(self):
|
| 11 |
+
self.cfg = ConfigDB().get(None, "", "ht_vip_cfg")
|
| 12 |
+
|
| 13 |
+
async def body(self):
|
| 14 |
+
pass
|