gabrav commited on
Commit
23d4ee0
·
verified ·
1 Parent(s): 7f39e0f

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. Weiyet_RTLStructLib/source/.gitignore +10 -0
  2. Weiyet_RTLStructLib/source/Doubly_Linked_List/README.md +156 -0
  3. Weiyet_RTLStructLib/source/Dual_Edge_FF/README.md +46 -0
  4. Weiyet_RTLStructLib/source/Dual_Edge_FF/src/dual_edge_ff.sv +61 -0
  5. Weiyet_RTLStructLib/source/Dual_Edge_FF/src/rtl_list.f +1 -0
  6. Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/cocotb/Makefile +42 -0
  7. Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/cocotb/tb.py +134 -0
  8. Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/sv/Makefile +48 -0
  9. Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/sv/tb.sv +193 -0
  10. Weiyet_RTLStructLib/source/Dual_Edge_FF/vip/pyuvm/Makefile +46 -0
  11. Weiyet_RTLStructLib/source/Dual_Edge_FF/vip/pyuvm/__init__.py +9 -0
  12. Weiyet_RTLStructLib/source/Dual_Edge_FF/vip/uvm/README.md +318 -0
  13. Weiyet_RTLStructLib/source/FIFO/README.md +95 -0
  14. Weiyet_RTLStructLib/source/Hash_Table/README.md +91 -0
  15. Weiyet_RTLStructLib/source/LICENSE +21 -0
  16. Weiyet_RTLStructLib/source/LIFO/README.md +114 -0
  17. Weiyet_RTLStructLib/source/LIFO/src/lifo.sv +77 -0
  18. Weiyet_RTLStructLib/source/LIFO/src/rtl_list.f +1 -0
  19. Weiyet_RTLStructLib/source/LIFO/tb/cocotb/Makefile +43 -0
  20. Weiyet_RTLStructLib/source/LIFO/tb/cocotb/tb.py +182 -0
  21. Weiyet_RTLStructLib/source/LIFO/tb/sv/Makefile +29 -0
  22. Weiyet_RTLStructLib/source/LIFO/tb/sv/tb.sv +229 -0
  23. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/Makefile +46 -0
  24. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/README.md +72 -0
  25. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/__init__.py +1 -0
  26. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/__init__.py +1 -0
  27. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_agent.py +35 -0
  28. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_driver.py +78 -0
  29. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_monitor.py +68 -0
  30. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_sequencer.py +7 -0
  31. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/common/__init__.py +8 -0
  32. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/common/lifo_vip_config.py +14 -0
  33. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/common/lifo_vip_seq_item.py +40 -0
  34. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/env/__init__.py +1 -0
  35. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/env/lifo_vip_env.py +38 -0
  36. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/env/lifo_vip_scoreboard.py +92 -0
  37. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/__init__.py +1 -0
  38. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_base_seq.py +13 -0
  39. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_pop_seq.py +17 -0
  40. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_push_seq.py +18 -0
  41. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_random_seq.py +16 -0
  42. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tb_lifo.py +36 -0
  43. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tests/__init__.py +1 -0
  44. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tests/lifo_vip_base_test.py +37 -0
  45. Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tests/lifo_vip_simple_test.py +35 -0
  46. Weiyet_RTLStructLib/source/LIFO/vip/uvm/README.md +194 -0
  47. Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_agent.sv +44 -0
  48. Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_driver.sv +80 -0
  49. Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_monitor.sv +74 -0
  50. Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_sequencer.sv +17 -0
Weiyet_RTLStructLib/source/.gitignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ignore simulation files
2
+ *.log
3
+ *.vcd
4
+ *.sim
5
+ XilinxUnisimLibrary
6
+ *netlist.v
7
+ __pycache__
8
+ iverilog_dump.v
9
+ results.xml
10
+ sim_build
Weiyet_RTLStructLib/source/Doubly_Linked_List/README.md ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Doubly Linked List
2
+
3
+ A configurable hardware implementation of a doubly linked list data structure in Verilog. The module supports bidirectional traversal with both forward and backward pointers, providing efficient insertion, deletion, and reading operations at specific addresses or indices.
4
+
5
+ ## Features
6
+
7
+ - Configurable data width and maximum node count
8
+ - Bidirectional traversal support
9
+ - Multiple insertion and deletion operations
10
+ - Hardware-based node management
11
+ - Full status monitoring (full, empty, length)
12
+ - Fault detection
13
+ - Head and tail pointer tracking
14
+ - Synchronous operation with start/done handshaking
15
+
16
+ ## Parameters
17
+
18
+ | Parameter | Description | Default |
19
+ |-------------|--------------------------------------------------|---------|
20
+ | DATA_WIDTH | Width of data stored in each node | 8 |
21
+ | MAX_NODE | Maximum number of nodes supported | 8 |
22
+
23
+ ## Interface Signals
24
+
25
+ | Signal | Direction | Width | Description |
26
+ |-----------------|-----------|---------------|------------------------------------------------|
27
+ | clk | Input | 1 | System clock |
28
+ | rst | Input | 1 | Active high reset |
29
+ | data_in | Input | DATA_WIDTH | Input data for insertion |
30
+ | addr_in | Input | ADDR_WIDTH | Target address/index for operations |
31
+ | op | Input | 3 | Operation code |
32
+ | op_start | Input | 1 | Start signal for operation |
33
+ | op_done | Output | 1 | Operation completion signal |
34
+ | data_out | Output | DATA_WIDTH | Output data from read operations |
35
+ | pre_node_addr | Output | ADDR_WIDTH | Address of previous node in list |
36
+ | next_node_addr | Output | ADDR_WIDTH | Address of next node in list |
37
+ | length | Output | ADDR_WIDTH | Current number of nodes in list |
38
+ | head | Output | ADDR_WIDTH | Address of first node |
39
+ | tail | Output | ADDR_WIDTH | Address of last node |
40
+ | full | Output | 1 | List full indicator |
41
+ | empty | Output | 1 | List empty indicator |
42
+ | fault | Output | 1 | Error indicator |
43
+
44
+ ## Supported Operations
45
+
46
+ | Op Code | Operation | Description |
47
+ |---------|------------------|---------------------------------------------------------|
48
+ | 0 | Read_Addr | Read data at specified address |
49
+ | 1 | Insert_Addr | Insert new node at specified address |
50
+ | 2 | Delete_Value | Delete first occurrence of specified value |
51
+ | 3 | Delete_Addr | Delete node at specified address |
52
+ | 5 | Insert_Index | Insert new node at specified index |
53
+ | 7 | Delete_Index | Delete node at specified index |
54
+
55
+ ## State Machine
56
+
57
+ The module implements a FSM with the following states:
58
+
59
+ 1. **IDLE (3'b000)**
60
+ - Initial state, waits for operation start
61
+ - Validates operation parameters
62
+ - Handles direct head/tail operations
63
+
64
+ 2. **FIND_ADDR (3'b001)**
65
+ - Traverses list to find target address
66
+ - Used for address-based operations
67
+
68
+ 3. **FIND_VALUE (3'b010)**
69
+ - Traverses list to find target value
70
+ - Used for value-based deletion
71
+
72
+ 4. **FIND_INDEX (3'b110)**
73
+ - Traverses list to find target index
74
+ - Supports both ascending and descending search
75
+
76
+ 5. **INSERT_STG1 (3'b011)**
77
+ - First stage of node insertion
78
+ - Updates bidirectional links
79
+
80
+ 6. **EXECUTE (3'b100)**
81
+ - Completes operation
82
+ - Updates status signals
83
+
84
+ 7. **FAULT (3'b101)**
85
+ - Handles error conditions
86
+
87
+ ## Memory Organization
88
+
89
+ The implementation uses three separate memory arrays:
90
+ 1. Data storage (`node_data`)
91
+ 2. Forward pointers (`node_next_node_addr`)
92
+ 3. Backward pointers (`node_pre_node_addr`)
93
+
94
+ This organization allows for:
95
+ - Independent access to data and pointers
96
+ - Efficient pointer updates
97
+ - Parallel validity checking
98
+
99
+ ## Usage Example
100
+
101
+ ```verilog
102
+ // Instantiate a doubly linked list with 16 nodes and 32-bit data
103
+ doubly_linked_list #(
104
+ .DATA_WIDTH(32),
105
+ .MAX_NODE(16)
106
+ ) list_inst (
107
+ .clk(system_clock),
108
+ .rst(reset),
109
+ .data_in(input_data),
110
+ .addr_in(target_addr),
111
+ .op(operation_code),
112
+ .op_start(start_signal),
113
+ .op_done(done_signal),
114
+ .data_out(output_data),
115
+ .pre_node_addr(prev_addr),
116
+ .next_node_addr(next_addr),
117
+ .length(list_length),
118
+ .head(head_addr),
119
+ .tail(tail_addr),
120
+ .full(list_full),
121
+ .empty(list_empty),
122
+ .fault(error_signal)
123
+ );
124
+ ```
125
+ ## Reset Behavior
126
+
127
+ On assertion of reset:
128
+ - All nodes are invalidated
129
+ - Head and tail pointers set to NULL
130
+ - Length cleared to zero
131
+ - All node data cleared
132
+ - All status signals deasserted
133
+
134
+ ## Implementation Notes
135
+
136
+ 1. **Memory Organization**:
137
+ - Next node pointers stored separately
138
+ - Valid bits for node tracking
139
+
140
+ 2. **Address Handling**:
141
+ - NULL address = MAX_NODE
142
+ - Valid addresses: 0 to (MAX_NODE-1)
143
+
144
+ 3. **Error Conditions**:
145
+ - List full during insertion
146
+ - List empty during deletion/read
147
+ - Invalid address/index
148
+ - Address overflow
149
+
150
+ ## Limitations
151
+
152
+ - Fixed maximum size defined by MAX_NODE
153
+ - Sequential search for operations
154
+ - Single operation at a time
155
+ - No concurrent access support
156
+
Weiyet_RTLStructLib/source/Dual_Edge_FF/README.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dual Edge Flip Flop
2
+ ## Overview
3
+ This Verilog module implements a dual-edge triggered flip-flop that can capture data on both the positive and negative edges of the clock signal. This design effectively doubles the data throughput rate compared to traditional single-edge flip-flops by utilizing both clock transitions for data latching operations.
4
+
5
+ ## Parameters
6
+ | Parameter | Description | Default |
7
+ |-------------|---------------------------------------|---------|
8
+ | DATA_WIDTH | Width of data bus in bits | 8 |
9
+ | RESET_VALUE | Reset value of flops | 0 |
10
+
11
+ ## Port Descriptions
12
+ ### Input Ports
13
+ | Port | Width | Description |
14
+ |-------------------|-------------|------------------------------------------------|
15
+ | clk | 1 | System clock signal |
16
+ | rst_n | 1 | Active-low asynchronous reset signal |
17
+ | data_in | DATA_WIDTH | Input data to be latched |
18
+ | pos_edge_latch_en | DATA_WIDTH | Per-bit latch enable for positive clock edge |
19
+ | neg_edge_latch_en | DATA_WIDTH | Per-bit latch enable for negative clock edge |
20
+
21
+ ### Output Ports
22
+ | Port | Width | Description |
23
+ |----------|------------|--------------------------------|
24
+ | data_out | DATA_WIDTH | Latched output data |
25
+
26
+
27
+ ## Usage Example
28
+ Below shows a simple usage of a counter that increments on both edges of the clock.
29
+ ```verilog
30
+ always @ (*) begin
31
+ if (data_out <= {(DATA_WIDTH){1'b1}}) input_data <= data_out + 1;
32
+ else input_data <= data_out;
33
+ end
34
+
35
+ dual_edge_ff #(
36
+ .DATA_WIDTH(16),
37
+ .RESET_VALUE(16'h0000)
38
+ ) dual_ff_inst (
39
+ .clk(system_clk),
40
+ .rst_n(system_rst_n),
41
+ .data_in(input_data),
42
+ .pos_edge_latch_en(16'hFFFF), // Enable all bits on positive edge
43
+ .neg_edge_latch_en(16'hFFFF), // Enable all bits on negative edge
44
+ .data_out(output_data)
45
+ );
46
+ ```
Weiyet_RTLStructLib/source/Dual_Edge_FF/src/dual_edge_ff.sv ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Create Date: 30/07/2025 07:22 PM
4
+ // Created By: https://www.linkedin.com/in/wei-yet-ng-065485119/
5
+ // Last Update: 03/08/2025 02:30 PM
6
+ // Last Updated By: https://www.linkedin.com/in/wei-yet-ng-065485119/
7
+ // Module Name: Dual Edge Flip Flop
8
+ // Description: Synthesiazble structure that can latch data corresponding to dual edge of clock to achive double input and output rate.
9
+ // Additional Comments: .
10
+ //
11
+ //////////////////////////////////////////////////////////////////////////////////
12
+
13
+
14
+ module dual_edge_ff #(
15
+ parameter DATA_WIDTH = 8,
16
+ parameter RESET_VALUE = 0
17
+ )(
18
+ input wire clk,
19
+ input wire rst_n,
20
+ input wire [DATA_WIDTH-1:0] data_in,
21
+ input wire [DATA_WIDTH-1:0] pos_edge_latch_en,
22
+ input wire [DATA_WIDTH-1:0] neg_edge_latch_en,
23
+ output wire [DATA_WIDTH-1:0] data_out
24
+ );
25
+
26
+ reg [DATA_WIDTH-1:0] d_in_pos;
27
+ reg [DATA_WIDTH-1:0] q_out_pos;
28
+ reg [DATA_WIDTH-1:0] d_in_neg;
29
+ reg [DATA_WIDTH-1:0] q_out_neg;
30
+
31
+
32
+ assign clk_n = ~clk; // Invert clock for negative edge latching
33
+
34
+ genvar i;
35
+
36
+ generate
37
+ for(i=0;i<DATA_WIDTH;i=i+1) begin
38
+
39
+ assign d_in_pos[i] = data_in[i] ^ q_out_neg[i];
40
+ always @ (posedge clk or negedge rst_n) begin
41
+ if(!rst_n)
42
+ q_out_pos[i] <= RESET_VALUE[i];
43
+ else if(pos_edge_latch_en[i])
44
+ q_out_pos[i] <= d_in_pos[i];
45
+ end
46
+
47
+ assign d_in_neg[i] = (data_in[i] ^ q_out_pos[i]);
48
+ always @ (posedge clk_n or negedge rst_n) begin
49
+ if(!rst_n)
50
+ q_out_neg[i] <= 1'b0;
51
+ else if(neg_edge_latch_en[i])
52
+ q_out_neg[i] <= d_in_neg[i];
53
+ end
54
+
55
+ assign data_out[i] = q_out_pos[i] ^ q_out_neg[i];
56
+ end
57
+ endgenerate
58
+
59
+
60
+
61
+ endmodule
Weiyet_RTLStructLib/source/Dual_Edge_FF/src/rtl_list.f ADDED
@@ -0,0 +1 @@
 
 
1
+ dual_edge_ff.sv
Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/cocotb/Makefile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ SRC_DIR = ../../src
10
+ VERILOG_SOURCES = $(addprefix $(SRC_DIR)/, $(shell cat ../../src/rtl_list.f))
11
+
12
+ # DUT Top
13
+ TOPLEVEL = dual_edge_ff
14
+ # top python file name
15
+ MODULE = tb
16
+
17
+ #use , separtor to run multiple TESTCASE, by default all @cocotb.test will be run
18
+ TESTCASE = direct_test
19
+
20
+ COMPILE_ARGS = -Pdual_edge_ff.DATA_WIDTH=8 # DUT parameter #"-p" (parameter) iverilog command flags
21
+ COMPILE_ARGS += -Pdual_edge_ff.RESET_VALUE=0 # DUT parameter #"-p" (parameter) iverilog command flags
22
+ #run make clean before running with new parameter.
23
+
24
+ #Set RANDOM_SEED number
25
+ #PLUSARGS = +seed=1716033254
26
+ COCOTB_HDL_TIMEUNIT = 1ns
27
+ COCOTB_HDL_TIMEPRECISION = 1ps
28
+
29
+ ifeq ($(SIM), icarus)
30
+ $(shell echo 'module iverilog_dump();' > iverilog_dump.v)
31
+ $(shell echo 'initial begin' >> iverilog_dump.v)
32
+ $(shell echo ' $$dumpfile("$(TOPLEVEL).vcd");' >> iverilog_dump.v)
33
+ $(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
34
+ $(shell echo 'end' >> iverilog_dump.v)
35
+ $(shell echo 'endmodule' >> iverilog_dump.v)
36
+ VERILOG_SOURCES += $(PWD)/iverilog_dump.v
37
+ COMPILE_ARGS += -s iverilog_dump
38
+ endif
39
+
40
+ include $(shell cocotb-config --makefiles)/Makefile.sim
41
+
42
+
Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/cocotb/tb.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ #import asyncio
3
+ import math
4
+ import cocotb
5
+ from cocotb.triggers import Timer, RisingEdge, FallingEdge, ReadOnly
6
+ from cocotb.clock import Clock
7
+ from cocotb_bus.drivers import BusDriver
8
+ from cocotb_bus.monitors import BusMonitor
9
+ from cocotb.binary import BinaryValue
10
+
11
+ #BIN string
12
+ #BinaryValue(dut.data_wr.value, n_bits=8) ; BinaryValue.integar ; BinaryValue.hex ; BinaryValue.binstr; BinaryValue.signed_integer ; can represent x,z
13
+
14
+ DUT_DATA_WIDTH = 8 # DUT paramter
15
+ DUT_RESET_VALUE = 0 # DUT parameter
16
+ TB_CLK_PERIOD = 30 # TB clk generator
17
+ TB_SIM_TIMEOUT = 30 # TB sim timeout 30ms
18
+ TB_TEST_WEIGHT = 1
19
+
20
+ err_cnt = 0
21
+
22
+ # dual_edge_ff #(
23
+ # .DATA_WIDTH(DUT_DATA_WIDTH),
24
+ # .RESET_VALUE(DUT_RESET_VALUE)
25
+ # ) DUT (
26
+ # /*input wire */.clk(clk),
27
+ # /*input wire */.rst_n(rst_n),
28
+ # /*input wire [DATA_WIDTH-1:0] */.data_in(data_in),
29
+ # /*input wire [DATA_WIDTH-1:0] */.pos_edge_latch_en(pos_edge_latch_en),
30
+ # /*input wire [DATA_WIDTH-1:0] */.neg_edge_latch_en(neg_edge_latch_en),
31
+ # /*output wire [DATA_WIDTH-1:0] */.data_out(data_out)
32
+ # );
33
+
34
+ async def dut_init(dut):
35
+ global DUT_DATA_WIDTH # DUT parameter
36
+ global DUT_RESET_VALUE # DUT parameter
37
+ DUT_DATA_WIDTH = dut.DATA_WIDTH.value
38
+ DUT_RESET_VALUE = dut.RESET_VALUE.value
39
+ await cocotb.start(Clock(dut.clk, TB_CLK_PERIOD, units="ns").start())
40
+ dut.data_in.value = 0
41
+ dut.pos_edge_latch_en.value = 0
42
+ dut.neg_edge_latch_en.value = 0
43
+ dut.rst_n.value = 0
44
+ await(Timer(100,'ns'))
45
+ dut.rst_n.value = 1
46
+ await(Timer(100,'ns'))
47
+
48
+
49
+ @cocotb.test()
50
+ async def direct_test(dut):
51
+ global err_cnt
52
+ await dut_init(dut)
53
+ cocotb.log.info("SEED NUMBER = %d",cocotb.RANDOM_SEED)
54
+
55
+ for j in range(TB_TEST_WEIGHT):
56
+ for i in range(20):
57
+ k = random.randint(0, 3)
58
+ match k:
59
+ case 0: # positive edge only
60
+ input_data = random.randint(0, 2**DUT_DATA_WIDTH)
61
+ await FallingEdge(dut.clk)
62
+ await Timer(1, units='ns')
63
+ dut.data_in.value = input_data
64
+ dut.pos_edge_latch_en.value = 2**DUT_DATA_WIDTH - 1
65
+ await RisingEdge(dut.clk)
66
+ await(Timer(1, units='ns'))
67
+ if(dut.data_out.value != input_data):
68
+ cocotb.log.error("Data out is incorrect at posedge, EXP: %0d, ACT: %0d", input_data, dut.data_out.value)
69
+ err_cnt += 1
70
+ else:
71
+ cocotb.log.info("Data out is correct at posedge with value %0d", dut.data_out.value)
72
+
73
+ dut.data_in.value = input_data + 1
74
+ await FallingEdge(dut.clk)
75
+ await(Timer(1, units='ns'))
76
+ if(dut.data_out.value != input_data):
77
+ cocotb.log.error("Data out is incorrect, should not be updated at negedge, EXP: %0d, ACT: %0d", input_data + 1, dut.data_out.value)
78
+ err_cnt += 1
79
+ dut.pos_edge_latch_en.value = 0
80
+ case 1: # negative edge only
81
+ input_data = random.randint(0, 2**DUT_DATA_WIDTH)
82
+ await RisingEdge(dut.clk)
83
+ await Timer(1, units='ns')
84
+ dut.data_in.value = input_data
85
+ dut.neg_edge_latch_en.value = 2**DUT_DATA_WIDTH - 1
86
+ await FallingEdge(dut.clk)
87
+ await(Timer(1, units='ns'))
88
+ if(dut.data_out.value != input_data):
89
+ cocotb.log.error("Data out is incorrect at negedge, EXP: %0d, ACT: %0d", input_data, dut.data_out.value)
90
+ err_cnt += 1
91
+ else:
92
+ cocotb.log.info("Data out is correct at negedge with value %0d", dut.data_out.value)
93
+
94
+ dut.data_in.value = input_data + 1
95
+ await RisingEdge(dut.clk)
96
+ await(Timer(1, units='ns'))
97
+ if(dut.data_out.value != input_data):
98
+ cocotb.log.error("Data out is incorrect, should not be updated at posedge, EXP: %0d, ACT: %0d", input_data + 1, dut.data_out.value)
99
+ err_cnt += 1
100
+ dut.neg_edge_latch_en.value = 0
101
+
102
+ case 2: # both edges
103
+ input_data = random.randint(0, 2**DUT_DATA_WIDTH)
104
+ await FallingEdge(dut.clk)
105
+ await Timer(1, units='ns')
106
+ dut.data_in.value = input_data
107
+ dut.pos_edge_latch_en.value = 2**DUT_DATA_WIDTH - 1
108
+ dut.neg_edge_latch_en.value = 2**DUT_DATA_WIDTH - 1
109
+ await RisingEdge(dut.clk)
110
+ await(Timer(1, units='ns'))
111
+ if(dut.data_out.value != input_data):
112
+ cocotb.log.error("Data out is incorrect at posedge, EXP: %0d, ACT: %0d", input_data, dut.data_out.value)
113
+ err_cnt += 1
114
+ else:
115
+ cocotb.log.info("Data out is correct at posedge with value %0d", dut.data_out.value)
116
+
117
+ input_data = random.randint(0, 2**DUT_DATA_WIDTH)
118
+ dut.data_in.value = input_data
119
+ await FallingEdge(dut.clk)
120
+ await(Timer(1, units='ns'))
121
+ if(dut.data_out.value != input_data):
122
+ cocotb.log.error("Data out is incorrect at negedge, EXP: %0d, ACT: %0d", input_data, dut.data_out.value)
123
+ err_cnt += 1
124
+ else:
125
+ cocotb.log.info("Data out is correct at negedge with value %0d", dut.data_out.value)
126
+
127
+ dut.pos_edge_latch_en.value = 0
128
+ dut.neg_edge_latch_en.value = 0
129
+
130
+ if (err_cnt > 0):
131
+ cocotb.log.error("Errors count = %d",err_cnt)
132
+ #cocotb.result.test_fail()
133
+ #assert False, f"Test failed with {err_cnt} errors"
134
+ raise cocotb.result.TestFailure(f"Test failed with {err_cnt} errors")
Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/sv/Makefile ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .PHONY: sim gen_sim synth netlist_sim gen_netlist_sim clean
3
+
4
+ DUT ?= list
5
+ SRC_DIR = ../../src
6
+ SIM_OPTS ?= $(addprefix $(SRC_DIR)/, $(shell cat ../../src/rtl_list.f))
7
+ SEED ?= $$(shuf -i 1-10000 -n 1)
8
+
9
+ # DUT parameter #"-P" iverilog command flags
10
+ COMPILE_ARGS ?= -P DUT_DATA_WIDTH=8
11
+ COMPILE_ARGS += -P DUT_RESET_VALUE=0
12
+ COMPILE_ARGS += -P TB_CLK_PERIOD=100
13
+ COMPILE_ARGS += -P TB_TEST_WEIGHT=1
14
+ COMPILE_ARGS += -P TB_SIM_TIMEOUT=30 #//ms.
15
+
16
+ XILINX_LIB_URL ?= https://github.com/Xilinx/XilinxUnisimLibrary.git
17
+ XILINX_LIB_DIR ?= XilinxUnisimLibrary/verilog/src
18
+
19
+ sim: gen_sim
20
+ ./${DUT}.sim +VCDFILE=sim.vcd +VCDLEVEL=0 +SEED=${SEED} | tee sim.log
21
+
22
+ gen_sim: tb.sv ${SIM_OPTS} # to generate executable file by using iverilator
23
+ iverilog -g2012 -s tb ${COMPILE_ARGS} -o ${DUT}.sim $^
24
+
25
+ synth: ${SIM_OPTS}
26
+ yosys -p synth_xilinx ${SIM_OPTS} -L synth.log -o ${DUT}.netlist.v
27
+ #timeout
28
+
29
+ netlist_sim: gen_netlist_sim
30
+ ./${DUT}.netlist.sim +VCDFILE=netlist_sim.vcd +VCDLEVEL=0 +SEED=${SEED} | tee netlist_sim.log
31
+
32
+ gen_netlist_sim: tb.sv ${DUT}.netlist.v | ${XILINX_LIBS_DIR}/.git
33
+ iverilog -g2012 -s tb -y ${XILINX_LIB_DIR} -y ${XILINX_LIB_DIR}/unisims -DXILINX_GLS ${COMPILE_ARGS} -o ${DUT}.netlist.sim $^
34
+
35
+ ${XILINX_LIBS_DIR}/.git:
36
+ @echo "XILINX_LIBS_DIR = ${XILINX_LIBS_DIR}"
37
+ @echo "XILINX_LIB_URL = ${XILINX_LIB_URL}"
38
+ @echo "Checking if XilinxUnisimLibrar/.git exists..."
39
+ @if [ ! -d "XilinxUnisimLibrary/.git" ]; then \
40
+ echo "Directory XilinxUnisimLibrar/.git does not exist, cloning..."; \
41
+ git clone ${XILINX_LIB_URL}; \
42
+ else \
43
+ echo "Xilinx library already cloned"; \
44
+ fi
45
+
46
+ clean:
47
+ rm -f ${DUT}_sim sim.log sim.vcd
48
+ rm -f ${DUT}.netlist.v synth.log
Weiyet_RTLStructLib/source/Dual_Edge_FF/tb/sv/tb.sv ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Create Date: 09/22/2024 01:42:52 PM
4
+ // Created By: https://www.linkedin.com/in/wei-yet-ng-065485119/
5
+ // Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
6
+ // Last Update: 13/06/2025 09:23 PM
7
+ // Last Updated By: https://www.linkedin.com/in/wei-yet-ng-065485119/
8
+ // Module Name: tb
9
+ // Description: Testbench for dual_edge_ff module.
10
+ // Additional Comments:
11
+ //
12
+ //////////////////////////////////////////////////////////////////////////////////
13
+
14
+
15
+ module tb(
16
+ );
17
+ // DUT parameter
18
+ localparam DUT_DATA_WIDTH = 8;
19
+ localparam DUT_RESET_VALUE = 0; // Max number of nodes in the list
20
+
21
+ // TB parameter
22
+ localparam TB_CLK_PERIOD = 25;
23
+ localparam TB_TEST_WEIGHT = 1;
24
+ localparam SIM_TIMEOUT = 500000;
25
+
26
+ integer err_cnt = 0;
27
+
28
+ // input
29
+ reg clk = 0;
30
+ reg rst_n = 1;
31
+ reg [DUT_DATA_WIDTH-1:0] data_in = 0;
32
+ reg [DUT_DATA_WIDTH-1:0] pos_edge_latch_en = 0;
33
+ reg [DUT_DATA_WIDTH-1:0] neg_edge_latch_en = 0;
34
+ // output
35
+ wire [DUT_DATA_WIDTH-1:0] data_out;
36
+
37
+ `ifdef XILINX_GLS
38
+ // for xilinx gate sim
39
+ glbl glbl();
40
+ `endif
41
+
42
+
43
+
44
+ dual_edge_ff #(
45
+ .DATA_WIDTH(DUT_DATA_WIDTH),
46
+ .RESET_VALUE(DUT_RESET_VALUE)
47
+ ) DUT (
48
+ /*input wire */.clk(clk),
49
+ /*input wire */.rst_n(rst_n),
50
+ /*input wire [DATA_WIDTH-1:0] */.data_in(data_in),
51
+ /*input wire [DATA_WIDTH-1:0] */.pos_edge_latch_en(pos_edge_latch_en),
52
+ /*input wire [DATA_WIDTH-1:0] */.neg_edge_latch_en(neg_edge_latch_en),
53
+ /*output wire [DATA_WIDTH-1:0] */.data_out(data_out)
54
+ );
55
+
56
+ always #(TB_CLK_PERIOD/2) clk = ~clk;
57
+
58
+ integer i = 0;
59
+ integer j = 0;
60
+ reg [DUT_DATA_WIDTH-1:0] target_data_wr;
61
+
62
+ task direct_test();
63
+ begin
64
+ $display("Starting direct operation test");
65
+ for (i = 0; i<50; i=i+1) begin
66
+ j = $urandom_range(0,2);
67
+ case (j)
68
+ 0: begin //posedge only
69
+ @ (negedge clk) // change data_in at negedge, expect DUT to latch at next posedge
70
+ #1;
71
+ pos_edge_latch_en= 2**DUT_DATA_WIDTH -1;
72
+ target_data_wr = $urandom;
73
+ data_in = target_data_wr;
74
+ @ (posedge clk)
75
+ #1;
76
+ if (data_out != target_data_wr) begin
77
+ $error("%0t Data out is incorrect at posedge, EXP: %0d, ACT: %0d",$realtime, target_data_wr, data_out);
78
+ err_cnt = err_cnt + 1;
79
+ end else begin
80
+ $display("%0t Data out is correctly latched at posedge with value %0d", $realtime, data_out);
81
+ end
82
+
83
+ data_in = target_data_wr + 1;
84
+ @ (negedge clk)
85
+ #1;
86
+ if (data_out != target_data_wr) begin
87
+ $error("%0t Data out is incorrect, should not be updated at posedge, EXP: %0d, ACT: %0d",$realtime, target_data_wr, data_out);
88
+ err_cnt = err_cnt + 1;
89
+ end
90
+ pos_edge_latch_en = 1'b0;
91
+
92
+ end
93
+ 1: begin //negedge only
94
+ @ (posedge clk) // change data in at posedge, expect DUT to latch at next negedge
95
+ #1;
96
+ neg_edge_latch_en= 2**DUT_DATA_WIDTH -1;
97
+ target_data_wr = $urandom;
98
+ data_in = target_data_wr;
99
+ @ (negedge clk)
100
+ #1;
101
+ if (data_out != target_data_wr) begin
102
+ $error("%0t Data out is incorrect at negedge, EXP: %0d, ACT: %0d",$realtime, target_data_wr, data_out);
103
+ err_cnt = err_cnt + 1;
104
+ end else begin
105
+ $display("%0t Data out is correctly latched at negedge with value %0d", $realtime, data_out);
106
+ end
107
+
108
+ data_in = target_data_wr + 1;
109
+ @ (posedge clk)
110
+ #1;
111
+ if (data_out != target_data_wr) begin
112
+ $error("%0t Data out is incorrect, should not be updated at posedge, EXP: %0d, ACT: %0d",$realtime, target_data_wr, data_out);
113
+ err_cnt = err_cnt + 1;
114
+ end
115
+ neg_edge_latch_en = 1'b0;
116
+
117
+ end
118
+ default: begin // both edge
119
+ @ (posedge clk) // change data in at posedge, expect DUT to latch at next negedge
120
+ #1;
121
+ neg_edge_latch_en= 2**DUT_DATA_WIDTH -1;
122
+ pos_edge_latch_en= 2**DUT_DATA_WIDTH -1;
123
+ target_data_wr = $urandom;
124
+ data_in = target_data_wr;
125
+ @ (negedge clk)
126
+ #1;
127
+ if (data_out != target_data_wr) begin
128
+ $error("%0t Data out is incorrect at negedge, EXP: %0d, ACT: %0d",$realtime, target_data_wr, data_out);
129
+ err_cnt = err_cnt + 1;
130
+ end else begin
131
+ $display("%0t Data out is correctly latched at negedge with value %0d", $realtime, data_out);
132
+ end
133
+
134
+ target_data_wr = $urandom;
135
+ data_in = target_data_wr;
136
+ @ (posedge clk)
137
+ #1;
138
+ if (data_out != target_data_wr) begin
139
+ $error("%0t Data out is incorrect at posedge, EXP: %0d, ACT: %0d",$realtime, target_data_wr, data_out);
140
+ err_cnt = err_cnt + 1;
141
+ end else begin
142
+ $display("%0t Data out is correctly latched at posedge with value %0d", $realtime, data_out);
143
+ end
144
+ neg_edge_latch_en= 0;
145
+ pos_edge_latch_en= 0;
146
+ end
147
+
148
+ endcase;
149
+
150
+ end
151
+
152
+
153
+ end
154
+ endtask
155
+
156
+ initial begin
157
+ string vcdfile;
158
+ int vcdlevel;
159
+ int seed;
160
+ int temp;
161
+
162
+ rst_n = 1'b0;
163
+ if ($value$plusargs("VCDFILE=%s",vcdfile))
164
+ $dumpfile(vcdfile);
165
+ if ($value$plusargs("VCDLEVEL=%d",vcdlevel))
166
+ $dumpvars(vcdlevel,tb);
167
+ if ($value$plusargs("SEED=%d",seed)) begin
168
+ temp = $urandom(seed);
169
+ $display("Seed = %0d",seed);
170
+ end
171
+ #100;
172
+ rst_n = 1'b1;
173
+ direct_test();
174
+
175
+ #1000;
176
+
177
+ if (err_cnt > 0) begin
178
+ $display("\n%0t TEST FAILED",$realtime);
179
+ $display("Error count = %0d\n", err_cnt);
180
+ end else
181
+ $display("\n%0t TEST PASSED\n", $realtime);
182
+ $finish;
183
+ end
184
+
185
+ initial begin
186
+ #(SIM_TIMEOUT)
187
+ $display("\n%0t TEST FAILED", $realtime);
188
+ $display("SIM TIMEOUT!\n");
189
+ $finish;
190
+ end
191
+
192
+ endmodule
193
+
Weiyet_RTLStructLib/source/Dual_Edge_FF/vip/pyuvm/Makefile ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for Dual Edge FF pyUVM VIP
2
+
3
+ SIM ?= icarus
4
+ TOPLEVEL_LANG ?= verilog
5
+ WAVES ?= 1
6
+
7
+ PWD=$(shell pwd)
8
+
9
+ # RTL source files
10
+ VERILOG_SOURCES = $(PWD)/../../src/dual_edge_ff.sv
11
+
12
+ TOPLEVEL = dual_edge_ff
13
+ MODULE = tb_deff
14
+
15
+ # DUT parameters
16
+ COMPILE_ARGS = -Pdual_edge_ff.DATA_WIDTH=8
17
+ COMPILE_ARGS += -Pdual_edge_ff.RESET_VALUE=0
18
+
19
+ COCOTB_HDL_TIMEUNIT = 1ns
20
+ COCOTB_HDL_TIMEPRECISION = 1ps
21
+
22
+ # Waveform dump
23
+ ifeq ($(SIM), icarus)
24
+ ifeq ($(WAVES), 1)
25
+ $(shell echo 'module iverilog_dump();' > iverilog_dump.v)
26
+ $(shell echo 'initial begin' >> iverilog_dump.v)
27
+ $(shell echo ' $$dumpfile("$(TOPLEVEL).vcd");' >> iverilog_dump.v)
28
+ $(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
29
+ $(shell echo 'end' >> iverilog_dump.v)
30
+ $(shell echo 'endmodule' >> iverilog_dump.v)
31
+ VERILOG_SOURCES += $(PWD)/iverilog_dump.v
32
+ COMPILE_ARGS += -s iverilog_dump
33
+ endif
34
+ endif
35
+
36
+ include $(shell cocotb-config --makefiles)/Makefile.sim
37
+
38
+ .PHONY: help
39
+ help:
40
+ @echo "Dual Edge FF pyUVM VIP Makefile"
41
+ @echo "================================"
42
+ @echo ""
43
+ @echo "Usage:"
44
+ @echo " make - Run test with Icarus Verilog"
45
+ @echo " make WAVES=0 - Disable waveforms"
46
+ @echo " make clean - Clean build files"
Weiyet_RTLStructLib/source/Dual_Edge_FF/vip/pyuvm/__init__.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ """Dual Edge FF VIP - pyUVM Implementation
2
+ Create Date: 01/05/2026
3
+ """
4
+ __version__ = "1.0.0"
5
+ from .common import *
6
+ from .agent import *
7
+ from .env import *
8
+ from .sequences import *
9
+ from .tests import *
Weiyet_RTLStructLib/source/Dual_Edge_FF/vip/uvm/README.md ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dual Edge Flip-Flop 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
+ │ ├── deff_vip_pkg.sv [Main package]
10
+ │ ├── deff_vip_config.sv [Configuration class]
11
+ │ └── deff_vip_seq_item.sv [Transaction definitions]
12
+ ├── interface/ [Interface definition]
13
+ │ └── deff_vip_if.sv [Virtual interface]
14
+ ├── agent/ [Agent layer components]
15
+ │ ├── deff_vip_driver.sv [Driver implementation]
16
+ │ ├── deff_vip_monitor.sv [Monitor implementation]
17
+ │ ├── deff_vip_sequencer.sv [Sequencer]
18
+ │ └── deff_vip_agent.sv [Agent wrapper]
19
+ ├── env/ [Environment layer]
20
+ │ ├── deff_vip_env.sv [Environment]
21
+ │ └── deff_vip_scoreboard.sv [Checking with dual-edge model]
22
+ ├── sequences/ [Test sequences]
23
+ │ ├── deff_vip_base_seq.sv [Base sequence]
24
+ │ └── deff_vip_random_seq.sv [Random, pos-edge, neg-edge, dual-edge]
25
+ └── sim/ [Testbench]
26
+ ├── tb_top.sv [Testbench top module]
27
+ └── tests/
28
+ ├── deff_vip_base_test.sv [Base test class]
29
+ └── deff_vip_simple_test.sv [Multiple test scenarios]
30
+ ```
31
+
32
+ ## 🚀 Quick Start
33
+
34
+ **Step 1:** Update interface signals in your testbench:
35
+ ```systemverilog
36
+ deff_vip_if dut_if(clk);
37
+ // Connect to DUT
38
+ uvm_config_db#(virtual deff_vip_if)::set(null, "*", "deff_vip_vif", dut_if);
39
+ ```
40
+
41
+ **Step 2:** Configure DUT parameters in your test:
42
+ ```systemverilog
43
+ cfg = deff_vip_config::type_id::create("cfg");
44
+ cfg.DATA_WIDTH = 8;
45
+ cfg.RESET_VALUE = 8'h00;
46
+ uvm_config_db#(deff_vip_config)::set(this, "*", "deff_vip_cfg", cfg);
47
+ ```
48
+
49
+ **Step 3:** Create environment:
50
+ ```systemverilog
51
+ deff_env = deff_vip_env::type_id::create("deff_env", this);
52
+ ```
53
+
54
+ ## 🚀 Available Sequences
55
+
56
+ **Random (Both Edges):**
57
+ ```systemverilog
58
+ deff_vip_random_seq seq = deff_vip_random_seq::type_id::create("seq");
59
+ seq.num_items = 50;
60
+ seq.start(env.get_sequencer());
61
+ ```
62
+
63
+ **Positive Edge Only:**
64
+ ```systemverilog
65
+ deff_vip_pos_edge_only_seq seq = deff_vip_pos_edge_only_seq::type_id::create("seq");
66
+ seq.num_items = 30;
67
+ seq.start(env.get_sequencer());
68
+ ```
69
+
70
+ **Negative Edge Only:**
71
+ ```systemverilog
72
+ deff_vip_neg_edge_only_seq seq = deff_vip_neg_edge_only_seq::type_id::create("seq");
73
+ seq.num_items = 30;
74
+ seq.start(env.get_sequencer());
75
+ ```
76
+
77
+ **Dual Edge (Both Active):**
78
+ ```systemverilog
79
+ deff_vip_dual_edge_seq seq = deff_vip_dual_edge_seq::type_id::create("seq");
80
+ seq.num_items = 30;
81
+ seq.start(env.get_sequencer());
82
+ ```
83
+
84
+ ## 🧪 Available Tests
85
+
86
+ ### 1. Simple Test
87
+ Random transactions with mixed edge enables:
88
+ ```bash
89
+ vsim -c +UVM_TESTNAME=simple_test -do "run -all; quit"
90
+ ```
91
+
92
+ ### 2. Positive Edge Test
93
+ Only positive edge latching active:
94
+ ```bash
95
+ vsim -c +UVM_TESTNAME=pos_edge_test -do "run -all; quit"
96
+ ```
97
+
98
+ ### 3. Negative Edge Test
99
+ Only negative edge latching active:
100
+ ```bash
101
+ vsim -c +UVM_TESTNAME=neg_edge_test -do "run -all; quit"
102
+ ```
103
+
104
+ ### 4. Dual Edge Test
105
+ Both edges active simultaneously:
106
+ ```bash
107
+ vsim -c +UVM_TESTNAME=dual_edge_test -do "run -all; quit"
108
+ ```
109
+
110
+ ### 5. Random Test
111
+ Mix of all edge configurations:
112
+ ```bash
113
+ vsim -c +UVM_TESTNAME=random_test -do "run -all; quit"
114
+ ```
115
+
116
+ ## 📋 Dual Edge FF Operation
117
+
118
+ The Dual Edge FF latches data on **both** positive and negative clock edges to achieve **double data rate**:
119
+
120
+ | Signal | Description | Width |
121
+ |--------|-------------|-------|
122
+ | **data_in** | Input data | 8 bits |
123
+ | **pos_edge_latch_en** | Enable latching on positive edge (per-bit) | 8 bits |
124
+ | **neg_edge_latch_en** | Enable latching on negative edge (per-bit) | 8 bits |
125
+ | **data_out** | Output data (XOR of pos and neg registers) | 8 bits |
126
+
127
+ ## ✅ Self-Checking Features
128
+
129
+ The scoreboard automatically verifies:
130
+ - ✅ Correct XOR behavior between pos and neg registers
131
+ - ✅ Positive edge latching when enabled
132
+ - ✅ Negative edge latching when enabled
133
+ - ✅ Per-bit independent latch enable control
134
+ - ✅ Reset value initialization
135
+ - ✅ Output = q_out_pos XOR q_out_neg
136
+
137
+ ## 🔧 Key Features
138
+
139
+ 1. **Dual-Edge Triggering**: Latches on both rising and falling clock edges
140
+ 2. **Per-Bit Control**: Independent latch enable for each bit
141
+ 3. **XOR Output**: Output is XOR of positive and negative edge registers
142
+ 4. **Double Data Rate**: Can capture data at 2× clock frequency
143
+ 5. **Synthesizable**: Uses XOR encoding for dual-edge behavior
144
+ 6. **Intelligent Scoreboard**: Models both pos and neg registers
145
+
146
+ ## 📊 Dual Edge FF Architecture
147
+
148
+ ### Internal Structure:
149
+ ```
150
+ For each bit i:
151
+
152
+ Positive Edge Path:
153
+ d_in_pos[i] = data_in[i] XOR q_out_neg[i]
154
+ @ posedge clk: if (pos_edge_latch_en[i]) q_out_pos[i] <= d_in_pos[i]
155
+
156
+ Negative Edge Path:
157
+ d_in_neg[i] = data_in[i] XOR q_out_pos[i]
158
+ @ negedge clk: if (neg_edge_latch_en[i]) q_out_neg[i] <= d_in_neg[i]
159
+
160
+ Output:
161
+ data_out[i] = q_out_pos[i] XOR q_out_neg[i]
162
+ ```
163
+
164
+ ### Why XOR Encoding?
165
+ The XOR encoding allows **synthesizable** dual-edge behavior:
166
+ - Traditional dual-edge FFs need special libraries
167
+ - XOR encoding works with standard cells
168
+ - Positive and negative edge FFs can be synthesized normally
169
+ - XOR gates combine the outputs
170
+
171
+ ## 🔍 Operation Modes
172
+
173
+ ### Mode 1: Positive Edge Only
174
+ ```systemverilog
175
+ pos_edge_latch_en = 8'hFF; // All bits enabled
176
+ neg_edge_latch_en = 8'h00; // All bits disabled
177
+ // Behaves like normal positive-edge FF
178
+ ```
179
+
180
+ ### Mode 2: Negative Edge Only
181
+ ```systemverilog
182
+ pos_edge_latch_en = 8'h00; // All bits disabled
183
+ neg_edge_latch_en = 8'hFF; // All bits enabled
184
+ // Behaves like negative-edge FF
185
+ ```
186
+
187
+ ### Mode 3: Dual Edge (DDR)
188
+ ```systemverilog
189
+ pos_edge_latch_en = 8'hFF; // All bits enabled
190
+ neg_edge_latch_en = 8'hFF; // All bits enabled
191
+ // Captures data on BOTH edges (double data rate)
192
+ ```
193
+
194
+ ### Mode 4: Per-Bit Mixed
195
+ ```systemverilog
196
+ pos_edge_latch_en = 8'hF0; // Upper nibble on pos edge
197
+ neg_edge_latch_en = 8'h0F; // Lower nibble on neg edge
198
+ // Different bits use different edges
199
+ ```
200
+
201
+ ## 🚨 Common Issues & Solutions
202
+
203
+ ### Issue: Output doesn't match expected
204
+ **Solution:** Remember output is **XOR** of two registers:
205
+ ```systemverilog
206
+ data_out = q_out_pos XOR q_out_neg
207
+ ```
208
+ Not a simple register value.
209
+
210
+ ### Issue: Understanding XOR encoding
211
+ **Solution:**
212
+ - When only pos_edge active: q_out_neg stays 0, so data_out = q_out_pos
213
+ - When only neg_edge active: q_out_pos stays at reset, output depends on XOR
214
+ - When both active: data toggles between edges
215
+
216
+ ### Issue: Reset behavior
217
+ **Solution:**
218
+ - q_out_pos resets to RESET_VALUE
219
+ - q_out_neg always resets to 0
220
+ - Initial data_out = RESET_VALUE XOR 0 = RESET_VALUE
221
+
222
+ ## 📚 Example Usage
223
+
224
+ ```systemverilog
225
+ class my_test extends base_test;
226
+ `uvm_component_utils(my_test)
227
+
228
+ task run_phase(uvm_phase phase);
229
+ deff_vip_pos_edge_only_seq pos_seq;
230
+ deff_vip_neg_edge_only_seq neg_seq;
231
+ deff_vip_dual_edge_seq dual_seq;
232
+
233
+ phase.raise_objection(this);
234
+
235
+ // Test positive edge latching
236
+ pos_seq = deff_vip_pos_edge_only_seq::type_id::create("pos_seq");
237
+ pos_seq.num_items = 20;
238
+ pos_seq.start(env.get_sequencer());
239
+
240
+ #200ns;
241
+
242
+ // Test negative edge latching
243
+ neg_seq = deff_vip_neg_edge_only_seq::type_id::create("neg_seq");
244
+ neg_seq.num_items = 20;
245
+ neg_seq.start(env.get_sequencer());
246
+
247
+ #200ns;
248
+
249
+ // Test dual edge (DDR) mode
250
+ dual_seq = deff_vip_dual_edge_seq::type_id::create("dual_seq");
251
+ dual_seq.num_items = 20;
252
+ dual_seq.start(env.get_sequencer());
253
+
254
+ #200ns;
255
+ phase.drop_objection(this);
256
+ endtask
257
+ endclass
258
+ ```
259
+
260
+ ## 🎯 Key Characteristics
261
+
262
+ - **Dual-Edge Sensitive**: Responds to both rising and falling clock edges
263
+ - **XOR-Based Encoding**: Synthesizable implementation of dual-edge behavior
264
+ - **Per-Bit Control**: Each bit can independently use pos/neg/both edges
265
+ - **Double Data Rate**: Effective 2× data throughput
266
+ - **Standard Cell Compatible**: No special library cells required
267
+
268
+ ## 📈 Performance Characteristics
269
+
270
+ **Effective Frequency:**
271
+ - Single edge FF: 1× clock frequency
272
+ - Dual edge FF: 2× clock frequency (captures on both edges)
273
+
274
+ **Example at 40MHz:**
275
+ - Clock period: 25ns
276
+ - Pos edge: data captured at 0ns, 25ns, 50ns...
277
+ - Neg edge: data captured at 12.5ns, 37.5ns, 62.5ns...
278
+ - Effective rate: 80 Mega-samples/second
279
+
280
+ ## 🔬 Test Strategy
281
+
282
+ The test suite covers:
283
+
284
+ 1. **simple_test**: Random mix of edge enables
285
+ 2. **pos_edge_test**: Verify positive edge path only
286
+ 3. **neg_edge_test**: Verify negative edge path only
287
+ 4. **dual_edge_test**: Verify both edges active (DDR mode)
288
+ 5. **random_test**: Random switching between modes
289
+
290
+ **Coverage Goals:**
291
+ - All 256 combinations of pos_edge_latch_en
292
+ - All 256 combinations of neg_edge_latch_en
293
+ - Edge transitions (pos→neg, neg→pos, both→single)
294
+ - Data patterns (walking 1s, walking 0s, random)
295
+
296
+ ## 🔍 Differences from Standard FF
297
+
298
+ | Aspect | Standard FF | Dual Edge FF |
299
+ |--------|------------|--------------|
300
+ | **Edge Sensitivity** | Single edge (pos or neg) | Both edges |
301
+ | **Data Rate** | 1× clock | 2× clock |
302
+ | **Implementation** | Simple D-FF | XOR-encoded dual registers |
303
+ | **Output** | Direct Q | XOR of two registers |
304
+ | **Complexity** | Low | Medium |
305
+ | **Use Case** | Normal clocking | DDR, high-speed I/O |
306
+
307
+ ## 💡 Applications
308
+
309
+ The Dual Edge FF is used in:
310
+ - **DDR Memory Interfaces**: Data on both edges
311
+ - **High-Speed Serial I/O**: Double throughput
312
+ - **Clock Domain Crossing**: Phase alignment
313
+ - **Video Interfaces**: Pixel clock doubling
314
+ - **FPGA I/O Blocks**: Standard DDR support
315
+
316
+ **Happy Verifying! 🚀**
317
+
318
+ *This VIP demonstrates verification of dual-edge triggered flip-flops with XOR encoding using UVM.*
Weiyet_RTLStructLib/source/FIFO/README.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FIFO (Queue)
2
+
3
+ A configurable FIFO (First-In-First-Out) buffer implementation in Verilog with support for both synchronous and asynchronous clock domains. The module uses Gray code for pointer synchronization in asynchronous mode to prevent metastability issues.
4
+
5
+ ## Features
6
+
7
+ - Configurable data width and depth
8
+ - Support for both synchronous and asynchronous clock domains
9
+ - Optional registered read output
10
+ - Gray code synchronization for clock domain crossing
11
+ - Full and empty status flags
12
+ - Automatic pointer wraparound
13
+ - Parameterized design for easy customization
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Description | Default |
18
+ |-------------|--------------------------------------------------|---------|
19
+ | DEPTH | Number of entries in the FIFO | 12 |
20
+ | DATA_WIDTH | Width of each data entry | 8 |
21
+ | ASYNC | Enable asynchronous mode (1) or synchronous (0) | 1 |
22
+ | RD_BUFFER | Enable registered read output (1) or bypass (0) | 1 |
23
+
24
+ ## Interface Signals
25
+
26
+ | Signal | Direction | Width | Description |
27
+ |-------------|-----------|---------------|------------------------------------------------|
28
+ | rd_clk | Input | 1 | Read clock domain |
29
+ | wr_clk | Input | 1 | Write clock domain |
30
+ | rst | Input | 1 | Active high reset |
31
+ | data_wr | Input | DATA_WIDTH | Data input for writing |
32
+ | wr_en | Input | 1 | Write enable signal |
33
+ | fifo_full | Output | 1 | FIFO full indicator |
34
+ | data_rd | Output | DATA_WIDTH | Data output from reading |
35
+ | rd_en | Input | 1 | Read enable signal |
36
+ | fifo_empty | Output | 1 | FIFO empty indicator |
37
+
38
+ ## Usage Example
39
+
40
+ ```verilog
41
+ // Instantiate a 16-deep, 32-bit wide asynchronous FIFO with registered output
42
+ fifo #(
43
+ .DEPTH(16),
44
+ .DATA_WIDTH(32),
45
+ .ASYNC(1),
46
+ .RD_BUFFER(1)
47
+ ) fifo_inst (
48
+ .rd_clk(read_clock),
49
+ .wr_clk(write_clock),
50
+ .rst(reset),
51
+ .data_wr(write_data),
52
+ .wr_en(write_enable),
53
+ .fifo_full(full_flag),
54
+ .data_rd(read_data),
55
+ .rd_en(read_enable),
56
+ .fifo_empty(empty_flag)
57
+ );
58
+ ```
59
+
60
+ ## Design Notes
61
+
62
+ 1. **Clock Domain Crossing**: In asynchronous mode (ASYNC=1), the design uses Gray code encoding for pointer synchronization to prevent metastability issues when crossing clock domains.
63
+
64
+ 2. **Read Buffer**: When RD_BUFFER=1, the read data output is registered, adding one clock cycle of latency but improving timing. When RD_BUFFER=0, the read data is combinatorial.
65
+
66
+ 3. **Full/Empty Flags**:
67
+ - The empty flag is asserted when read and write pointers are equal
68
+ - The full flag is asserted when the next write pointer would equal the current read pointer
69
+
70
+ 4. **Reset Behavior**:
71
+ - All pointers are reset to zero
72
+ - All memory locations are cleared
73
+ - All flags are deasserted
74
+
75
+ ## Implementation Details
76
+
77
+ The module uses separate read and write pointers for tracking FIFO occupancy. In asynchronous mode, these pointers are converted to Gray code before being synchronized across clock domains. The implementation includes:
78
+
79
+ - Binary counters for read/write operation
80
+ - Gray code conversion for pointer synchronization
81
+ - Two-stage synchronizers for clock domain crossing
82
+ - Configurable output registration
83
+ - Automatic pointer wraparound at FIFO boundaries
84
+
85
+ ## Timing Considerations
86
+
87
+ 1. In asynchronous mode, allow at least 2 clock cycles for pointer synchronization
88
+ 2. When RD_BUFFER=1, read data is available one clock cycle after rd_en assertion
89
+ 3. Full and empty flags are registered outputs
90
+
91
+ ## Limitations
92
+
93
+ - The DEPTH parameter must be a power of 2 for proper wraparound behavior
94
+ - Simultaneous read/write at full/empty conditions should be managed by external logic
95
+ - The reset signal must be synchronized to both clock domains
Weiyet_RTLStructLib/source/Hash_Table/README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hash Table Module
2
+ ## Overview
3
+ This Verilog module implements a flexible hash table with configurable collision resolution methods and hash algorithms. It provides support for key-value storage with operations such as insert, delete, and search.
4
+
5
+ ## Features
6
+ - Configurable key and value widths
7
+ - Support for different collision resolution methods
8
+ - Multiple hash algorithm options
9
+ - Synchronous operation with reset capability
10
+ - Collision tracking and error reporting
11
+
12
+ ## Parameters
13
+ | Parameter | Description | Default |
14
+ |-----------|-------------|---------|
15
+ | KEY_WIDTH | Width of keys in bits | 32 |
16
+ | VALUE_WIDTH | Width of values in bits | 32 |
17
+ | TOTAL_ENTRY | Number of indices in the hash table | 64 |
18
+ | CHAINING_SIZE | Maximum chain length for collision resolution | 4 |
19
+ | COLLISION_METHOD | Method for handling collisions | "MULTI_STAGE_CHAINING" |
20
+ | HASH_ALGORITHM | Algorithm used for hashing | "MODULUS" |
21
+
22
+ ## Port Descriptions
23
+ ### Input Ports
24
+ | Port | Width | Description |
25
+ |------|-------|-------------|
26
+ | clk | 1 | System clock signal |
27
+ | rst | 1 | Active-high reset signal |
28
+ | key_in | KEY_WIDTH | Key for insert, delete, or search operations |
29
+ | value_in | VALUE_WIDTH | Value to be stored (for insert operations) |
30
+ | op_sel | 2 | Operation selector (00: Insert, 01: Delete, 10: Search) |
31
+ | op_en | 1 | Operation enable signal |
32
+
33
+ ### Output Ports
34
+ | Port | Width | Description |
35
+ |------|-------|-------------|
36
+ | value_out | VALUE_WIDTH | Value retrieved during search operations |
37
+ | op_done | 1 | Operation completion indicator |
38
+ | op_error | 1 | Error indicator (FULL for insert, KEY_NOT_FOUND for delete/search) |
39
+ | collision_count | log2(CHAINING_SIZE) | Number of collisions encountered |
40
+
41
+ ## Collision Methods
42
+ - **MULTI_STAGE_CHAINING**: Multiple entries at the same index using a linked list approach
43
+ - **LINEAR_PROBING**: Referenced in parameters but not fully implemented in the provided code
44
+
45
+ ## Hash Algorithms
46
+ - **MODULUS**: Simple modulus operation (key % TABLE_SIZE)
47
+ - **SHA1**, **FNV1A**: Referenced in parameters but not fully implemented in the provided code
48
+
49
+ ## Timing
50
+ - All operations are synchronized to the positive edge of the clock
51
+ - Reset is asynchronous and active-high
52
+ - Operations are initiated when op_en is asserted
53
+ - op_done indicates completion of an operation
54
+
55
+ ## Usage Example
56
+ ```verilog
57
+ hash_table #(
58
+ .KEY_WIDTH(32),
59
+ .VALUE_WIDTH(32),
60
+ .TOTAL_ENTRY(128),
61
+ .CHAINING_SIZE(8),
62
+ .COLLISION_METHOD("MULTI_STAGE_CHAINING"),
63
+ .HASH_ALGORITHM("MODULUS")
64
+ ) hash_module (
65
+ .clk(system_clk),
66
+ .rst(system_rst),
67
+ .key_in(key),
68
+ .value_in(value),
69
+ .op_sel(operation),
70
+ .op_en(enable),
71
+ .value_out(retrieved_value),
72
+ .op_done(operation_complete),
73
+ .op_error(operation_error),
74
+ .collision_count(collisions)
75
+ );
76
+ ```
77
+
78
+ ## Implementation Details
79
+ - Uses a state machine for operation control
80
+ - Implements chained hash entries for collision resolution
81
+ - Provides error reporting for table overflow or key not found conditions
82
+ - Uses Verilog parameter-based configuration for flexibility
83
+
84
+ ## Limitations and Issues
85
+ - Implementation for alternative hash algorithms is mentioned but not provided
86
+
87
+ ## Performance Considerations
88
+ - Search and delete operations may require multiple cycles depending on chain length
89
+ - Performance degrades as collision chains grow longer
90
+ - No optimization for locality or cache behavior
91
+ - Please consider using [CAM(Content Addressable Memory)](https://en.wikipedia.org/wiki/Content-addressable_memory) if you have the resources.
Weiyet_RTLStructLib/source/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) [Wei Yet Ng]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Weiyet_RTLStructLib/source/LIFO/README.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LIFO (Stack)
2
+
3
+ A configurable LIFO (Last-In-First-Out) buffer implementation in Verilog. This module implements a stack-like behavior where the last element written is the first one to be read out. The design includes bypass functionality for simultaneous read/write operations.
4
+
5
+ ## Features
6
+
7
+ - Configurable data width and depth
8
+ - Single clock domain operation
9
+ - Full and empty status flags
10
+ - Bypass path for simultaneous read/write
11
+ - Registered read output
12
+ - Automatic pointer management
13
+ - Parameterized design for easy customization
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Description | Default |
18
+ |-------------|--------------------------------------------------|---------|
19
+ | DEPTH | Number of entries in the LIFO | 12 |
20
+ | DATA_WIDTH | Width of each data entry | 8 |
21
+
22
+ ## Interface Signals
23
+
24
+ | Signal | Direction | Width | Description |
25
+ |-------------|-----------|---------------|------------------------------------------------|
26
+ | clk | Input | 1 | System clock |
27
+ | rst | Input | 1 | Active high reset |
28
+ | data_wr | Input | DATA_WIDTH | Data input for writing |
29
+ | wr_en | Input | 1 | Write enable signal |
30
+ | lifo_full | Output | 1 | LIFO full indicator |
31
+ | data_rd | Output | DATA_WIDTH | Data output from reading |
32
+ | rd_en | Input | 1 | Read enable signal |
33
+ | lifo_empty | Output | 1 | LIFO empty indicator |
34
+
35
+ ## Usage Example
36
+
37
+ ```verilog
38
+ // Instantiate a 16-deep, 32-bit wide LIFO
39
+ lifo #(
40
+ .DEPTH(16),
41
+ .DATA_WIDTH(32)
42
+ ) lifo_inst (
43
+ .clk(system_clock),
44
+ .rst(reset),
45
+ .data_wr(write_data),
46
+ .wr_en(write_enable),
47
+ .lifo_full(full_flag),
48
+ .data_rd(read_data),
49
+ .rd_en(read_enable),
50
+ .lifo_empty(empty_flag)
51
+ );
52
+ ```
53
+
54
+ ## Operation Modes
55
+
56
+ The module supports three operation modes:
57
+
58
+ 1. **Write Operation (wr_op)**
59
+ - Activated when wr_en=1 and rd_en=0
60
+ - Data is written to current pointer location
61
+ - Pointer increments if not full
62
+
63
+ 2. **Read Operation (rd_op)**
64
+ - Activated when rd_en=1 and wr_en=0
65
+ - Data is read from (pointer-1) location
66
+ - Pointer decrements if not empty
67
+
68
+ 3. **Bypass Operation (bypass_op)**
69
+ - Activated when both wr_en=1 and rd_en=1
70
+ - Input data (data_wr) is directly passed to output (data_rd)
71
+ - Pointer remains unchanged
72
+
73
+ ## Design Notes
74
+
75
+ 1. **Pointer Management**:
76
+ - Single pointer tracks both read and write positions
77
+ - Increments on write, decrements on read
78
+ - Range: 0 to (DEPTH-1)
79
+
80
+ 2. **Memory Organization**:
81
+ - Stack-like structure with DEPTH entries
82
+ - Each entry is DATA_WIDTH bits wide
83
+ - Last written data is first to be read
84
+
85
+ 3. **Flag Generation**:
86
+ - Empty flag is combinatorial (pointer = 0)
87
+ - Full flag is registered (pointer = DEPTH-1)
88
+ - Flags prevent invalid operations
89
+
90
+ ## Reset Behavior
91
+
92
+ On assertion of reset:
93
+ - Pointer is cleared to zero
94
+ - All memory locations are cleared
95
+ - Full flag is deasserted
96
+ - Output data is cleared
97
+ - Empty flag becomes active
98
+
99
+ ## Timing Considerations
100
+
101
+ 1. All outputs except lifo_empty are registered
102
+ 2. Data is available on the next clock cycle after rd_en assertion
103
+ 3. Bypass operation provides data in the same clock cycle
104
+
105
+ ## Limitations
106
+
107
+ - Single clock domain operation only
108
+ - No protection against overflow/underflow if flags are ignored
109
+ - DEPTH parameter should be at least 2 for proper operation
110
+ - Simultaneous read/write operations bypass the stack memory
111
+
112
+ ## Alternative Implementation Note
113
+
114
+ The commented code at the bottom of the module suggests an alternative implementation for full flag handling and read operations, which could be implemented if different timing behavior is needed.
Weiyet_RTLStructLib/source/LIFO/src/lifo.sv ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module lifo #(
2
+ parameter DEPTH = 12,
3
+ parameter DATA_WIDTH = 8
4
+ )(
5
+ input wire clk,
6
+ input wire rst,
7
+ input wire [DATA_WIDTH-1:0] data_wr,
8
+ input wire wr_en,
9
+ output reg lifo_full,
10
+ output reg [DATA_WIDTH-1:0] data_rd,
11
+ input wire rd_en,
12
+ output wire lifo_empty
13
+ );
14
+ localparam CNTR_WIDTH = $clog2(DEPTH);
15
+
16
+ reg [CNTR_WIDTH-1:0] pointer;
17
+ reg [DATA_WIDTH-1:0] lifo_stored [DEPTH-1:0];
18
+ wire wr_op;
19
+ wire rd_op;
20
+ wire bypass_op;
21
+
22
+ integer i;
23
+
24
+ assign wr_op = wr_en & !rd_en;
25
+ assign rd_op = rd_en & !wr_en;
26
+ assign bypass_op = wr_en & rd_en;
27
+
28
+ // pointer logic
29
+ always @ (posedge clk, posedge rst) begin
30
+ if(rst) begin
31
+ pointer <= {CNTR_WIDTH{1'b0}};
32
+ end else if(rd_op & !lifo_empty) begin
33
+ pointer <= pointer - 1;
34
+ end else if(wr_op & !lifo_full) begin
35
+ pointer <= pointer + 1;
36
+ end
37
+ end
38
+
39
+ // lifo memory
40
+ always @ (posedge clk, posedge rst) begin
41
+ if(rst) begin
42
+ for (i = 0; i < DEPTH; i = i + 1)
43
+ lifo_stored[i] <= {DATA_WIDTH{1'b0}};
44
+ end else if (wr_op & !lifo_full) begin
45
+ lifo_stored[pointer] <= data_wr;
46
+ end
47
+ end
48
+
49
+ // data_rd
50
+ always @ (posedge clk, posedge rst) begin
51
+ if(rst) begin
52
+ data_rd <= {DATA_WIDTH{1'b0}};
53
+ end else if (rd_op & !lifo_empty) begin
54
+ data_rd <= lifo_stored[pointer-1];
55
+ end else if (bypass_op) begin
56
+ data_rd <= data_wr;
57
+ end
58
+ end
59
+
60
+ // flag
61
+ assign lifo_empty = pointer == {CNTR_WIDTH{1'b0}};
62
+ always @ (posedge clk, posedge rst) begin
63
+ if(rst) begin
64
+ lifo_full <= 1'b0;
65
+ end else if(rd_op) begin
66
+ lifo_full <= 1'b0;
67
+ end else if(pointer == (DEPTH-1) & wr_op) begin
68
+ lifo_full <= 1'b1;
69
+ end
70
+ end
71
+
72
+ // assign lifo_full = pointer == (DEPTH);
73
+ // can use this as flag and modify read cond when lifo is full
74
+ // if lifo_full : data_rd <= (lifo_stored[pointer-1]) else data_rd <= lifo_stored[pointer]
75
+ // : pointer <= pointer - 2 else pointer <= pointer <= pointer -1
76
+
77
+ endmodule
Weiyet_RTLStructLib/source/LIFO/src/rtl_list.f ADDED
@@ -0,0 +1 @@
 
 
1
+ lifo.sv
Weiyet_RTLStructLib/source/LIFO/tb/cocotb/Makefile ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/lifo.sv
10
+
11
+ # DUT Top
12
+ TOPLEVEL = lifo
13
+ # top python file
14
+ MODULE = tb
15
+
16
+ #use , separtor to run multiple TESTCASE, by default all @cocotb.test will be run
17
+ #TESTCASE = lifo_rand_op_test
18
+ TESTCASE = lifo_rand_op_test
19
+
20
+ COMPILE_ARGS = -Plifo.DEPTH=12 # DUT parameter #"-p" iverilog command flags
21
+ COMPILE_ARGS += -Plifo.DATA_WIDTH=8 # DUT parameter #"-p" iverilog command flags
22
+ #run make clean before running with new parameter.
23
+
24
+ #Set RANDOM_SEED number
25
+ #PLUSARGS = +seed=1716033254
26
+ COCOTB_HDL_TIMEUNIT = 1ns
27
+ COCOTB_HDL_TIMEPRECISION = 1ps
28
+
29
+ ifeq ($(SIM), icarus)
30
+ $(shell echo 'module iverilog_dump();' > iverilog_dump.v)
31
+ $(shell echo 'initial begin' >> iverilog_dump.v)
32
+ $(shell echo ' $$dumpfile("$(TOPLEVEL).vcd");' >> iverilog_dump.v)
33
+ $(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
34
+ $(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
35
+ $(shell echo 'end' >> iverilog_dump.v)
36
+ $(shell echo 'endmodule' >> iverilog_dump.v)
37
+ VERILOG_SOURCES += $(PWD)/iverilog_dump.v
38
+ COMPILE_ARGS += -s iverilog_dump
39
+ endif
40
+
41
+ include $(shell cocotb-config --makefiles)/Makefile.sim
42
+
43
+
Weiyet_RTLStructLib/source/LIFO/tb/cocotb/tb.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ #import asyncio
3
+ import cocotb
4
+ from cocotb.triggers import Timer, RisingEdge, ReadOnly
5
+ from cocotb.clock import Clock
6
+ from cocotb_bus.drivers import BusDriver
7
+ from cocotb_bus.monitors import BusMonitor
8
+
9
+ DEPTH = 12 # DUT parameter
10
+ DATA_WIDTH = 8 # DUT paramter
11
+ TEST_WEIGHT = 1 # TB multiplier for stimulus injected
12
+ CLK_PERIOD = 20 # TB clk generator
13
+ #SIM_TIMEOUT = 100000; // TB simulation time out
14
+ MAX_DATA = 2**DATA_WIDTH - 1
15
+ err_cnt = 0
16
+
17
+ # lifo #(
18
+ # .DEPTH(DEPTH),
19
+ # .DATA_WIDTH(DATA_WIDTH)) DUT (
20
+ # /*input wire*/ .clk(clk),
21
+ # /*input wire*/ .rst(rst),
22
+ # /*input wire [DATA_WIDTH-1:0]*/ .data_wr(data_wr),
23
+ # /*input wire*/ .wr_en(wr_en),
24
+ # /*output reg*/ .lifo_full(lifo_full),
25
+ # /*output reg [DATA_WIDTH-1:0]*/ .data_rd(data_rd),
26
+ # /*input wire*/ .rd_en(rd_en),
27
+ # /*output wire*/ .lifo_empty(lifo_empty));
28
+
29
+ class OutputDriver(BusDriver):
30
+ _signals = ["wr_en", "rd_en", "data_wr"] #dut.wr_en ; dut.rd_en; dut.data_wr
31
+
32
+ def __init__(self, dut, name, clk):
33
+ BusDriver.__init__(self, dut, name, clk)
34
+ self.bus.wr_en.value = 0
35
+ self.bus.rd_en.value = 0
36
+ self.dut = dut
37
+ self.clk = clk
38
+
39
+ async def _driver_send(self, op_sel, op_count):
40
+ match op_sel:
41
+ case 0:
42
+ wr_data_array = []
43
+ for i in range (op_count):
44
+ wr_data_array.append(random.randint(0,MAX_DATA))
45
+ await self.lifo_write(wr_data_array)
46
+ case 1:
47
+ await self.lifo_read(op_count)
48
+ case 2:
49
+ wr_data_array = []
50
+ for i in range (op_count):
51
+ wr_data_array.append(random.randint(0,MAX_DATA))
52
+ await self.lifo_read_write_simul(wr_data_array)
53
+
54
+ async def lifo_write(self, wr_data_array):
55
+ data_w = 0
56
+ while len(wr_data_array) != 0:
57
+ await RisingEdge(self.clk)
58
+ await Timer (1, units = 'ns')
59
+ self.bus.wr_en.value = 1
60
+ data_w = wr_data_array.pop()
61
+ self.bus.data_wr.value = data_w
62
+ self.dut._log.info("Driver: Writting Data = %d",data_w)
63
+ await RisingEdge(self.clk)
64
+ self.bus.wr_en.value = 0
65
+
66
+ async def lifo_read(self,op_count):
67
+ for i in range(op_count):
68
+ await RisingEdge(self.clk)
69
+ self.bus.rd_en.value = 1
70
+ self.dut._log.info("Driver: Reading Data = %d",)
71
+ await RisingEdge(self.clk)
72
+ await Timer (1, units='ns')
73
+ self.bus.rd_en.value = 0
74
+
75
+ async def lifo_read_write_simul(self,wr_data_array):
76
+ data_w = 0
77
+ while len(wr_data_array) != 0:
78
+ await RisingEdge(self.clk)
79
+ await Timer (1, units = 'ns')
80
+ self.bus.rd_en.value = 1
81
+ self.bus.wr_en.value = 1
82
+ data_w = wr_data_array.pop()
83
+ self.bus.data_wr.value = data_w
84
+ self.dut._log.info("Driver: Simultanenous read write, data = %d",data_w)
85
+ await RisingEdge(self.clk)
86
+ await Timer (1, units='ns')
87
+ self.bus.rd_en.value = 0
88
+ self.bus.wr_en.value = 0
89
+
90
+ class InputMonitor(BusMonitor):
91
+ _signals = ["wr_en","rd_en","lifo_empty","lifo_full","data_rd","data_wr"]
92
+
93
+ def __init__(self, dut, name, clk, reset):
94
+ BusMonitor.__init__(self, dut, name, clk, reset)
95
+ self.clk = clk
96
+ self.reset = reset
97
+ self.dut = dut
98
+
99
+ async def _monitor_recv(self):
100
+ global err_cnt
101
+ lifo_expected = []
102
+ rd_en_buf = 0
103
+ wr_en_buf = 0
104
+ data_wr_buf = 0
105
+ while True:
106
+ await RisingEdge(self.clock)
107
+ await Timer(3,units='ns')
108
+ await ReadOnly()
109
+
110
+ if self.reset.value == 1:
111
+ rd_en_buf = 0
112
+ wr_en_buf = 0
113
+ data_wr_buf = 0
114
+ continue
115
+
116
+ if(rd_en_buf == 1 and wr_en_buf == 1):
117
+ if(self.bus.data_rd.value == data_wr_buf):
118
+ self.dut._log.info("Monitor: Simultaneous Data read/write, ACT = %d, EXP = %d, FIFO entry = %d", self.bus.data_rd.value, data_wr_buf, len(lifo_expected))
119
+ elif(wr_en_buf and len(lifo_expected) != DEPTH):
120
+ lifo_expected.append(data_wr_buf)
121
+ self.dut._log.info("Monitor: Data write = %d, FIFO entry = %d", data_wr_buf, len(lifo_expected))
122
+ elif(rd_en_buf == 1 and len(lifo_expected) != 0):
123
+ lifo_expected.pop()
124
+ self.dut._log.info("Monitor: Data read = %d, FIFO entry = %d", self.bus.data_rd.value, len(lifo_expected))
125
+
126
+ if(len(lifo_expected) == 0):
127
+ if(self.bus.lifo_empty.value):
128
+ self.dut._log.info("Monitor: LIFO is empty, lifo_full flag is asserted correctly")
129
+ else:
130
+ self.dut._log.error("Monitor: LIFO is empty, but lifo_full flag is not asserted")
131
+ err_cnt += 1
132
+ elif(self.bus.lifo_empty.value):
133
+ self.dut._log.error("Monitor: LIFO is not empty, but lifo_empty flag is asserted")
134
+
135
+ if(len(lifo_expected) == DEPTH):
136
+ if(self.bus.lifo_full.value):
137
+ self.dut._log.info("Monitor: LIFO is full, lifo_full flag is asserted correctly")
138
+ else:
139
+ self.dut._log.error("Monitor: LIFO is full, but lifo_full flag is not asserted")
140
+ err_cnt += 1
141
+ elif(self.bus.lifo_full.value):
142
+ self.dut._log.error("Monitor: LIFO is not full, but lifo_full flag is asserted")
143
+
144
+ rd_en_buf = int(self.bus.rd_en.value)
145
+ wr_en_buf = int(self.bus.wr_en.value)
146
+ data_wr_buf = int(self.bus.data_wr.value)
147
+
148
+
149
+ async def dut_init(dut):
150
+ global DEPTH
151
+ global DATA_WIDTH
152
+ global MAX_DATA
153
+ DEPTH = dut.DEPTH.value
154
+ DATA_WIDTH = dut.DATA_WIDTH.value
155
+ MAX_DATA = 2**DATA_WIDTH - 1
156
+ await cocotb.start(Clock(dut.clk, CLK_PERIOD, units="ns").start())
157
+ dut.data_wr.value = 0
158
+ dut.rd_en.value = 0
159
+ dut.wr_en.value = 0
160
+ dut.rst.value = 1
161
+ await(Timer(100,'ns'))
162
+ dut.rst.value = 0
163
+ await(Timer(100,'ns'))
164
+
165
+
166
+ @cocotb.test()
167
+ async def lifo_rand_op_test(dut):
168
+ await dut_init(dut)
169
+ driver = OutputDriver(dut, None, dut.clk) #set name='None', refer to Bus class
170
+ monitor = InputMonitor(dut, None, dut.clk, dut.rst)
171
+ cocotb.log.info("SEED NUMBER = %d",cocotb.RANDOM_SEED)
172
+ i = DEPTH
173
+ lifo_expected = []
174
+ while(i >= 0):
175
+ op_sel = random.randint(0,1)
176
+ op_count = random.randint(1,5)
177
+ i = i - op_count
178
+ await driver._driver_send(op_sel,op_count)
179
+ await Timer(CLK_PERIOD,'ns')
180
+ if (err_cnt > 0):
181
+ cocotb.log.error("Errors count = %d",err_cnt)
182
+ cocotb.result.test_fail()
Weiyet_RTLStructLib/source/LIFO/tb/sv/Makefile ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ DUT = lifo
3
+ SIM_OPTS ?= ../../src/lifo.sv
4
+ SEED ?= $$(shuf -i 1-10000 -n 1)
5
+ XILINX_LIB_URL ?= https://github.com/Xilinx/XilinxUnisimLibrary.git
6
+ XILINX_LIB_DIR ?= XilinxUnisimLibrary/verilog/src
7
+
8
+ sim: gen_sim
9
+ ./${DUT}.sim +VCDFILE=sim.vcd +VCDLEVEL=0 +SEED=${SEED} | tee sim.log
10
+
11
+ gen_sim: tb.sv ${SIM_OPTS} # to generate executable file by using iverilator
12
+ iverilog -g2012 -s tb -o ${DUT}.sim $^
13
+
14
+ synth: ${SIM_OPTS}
15
+ yosys -p synth_xilinx ${SIM_OPTS} -L synth.log -o ${DUT}.netlist.v
16
+ #timeout
17
+
18
+ netlist_sim: gen_netlist_sim
19
+ ./${DUT}.netlist.sim +VCDFILE=netlist_sim.vcd +VCDLEVEL=0 +SEED=${SEED} | tee netlist_sim.log
20
+
21
+ gen_netlist_sim: tb.sv ${DUT}.netlist.v | ${XILINX_LIBS_DIR}/.git
22
+ iverilog -g2012 -s tb -y ${XILINX_LIB_DIR} -y ${XILINX_LIB_DIR}/unisims -DXILINX_GLS -o ${DUT}.netlist.sim $^
23
+
24
+ ${XILINX_LIBS_DIR}/.git:
25
+ git clone ${XILINX_LIB_URL}
26
+
27
+ clean:
28
+ rm -f ${DUT}_sim sim.log sim.vcd
29
+ rm -f ${DUT}.netlist.v synth.log
Weiyet_RTLStructLib/source/LIFO/tb/sv/tb.sv ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ //
4
+ // Create Date: 05/05/2024 05:05:34 PM
5
+ // Last Update Date: 05/05/2024 05:05:34 PM
6
+ // Module Name: tb
7
+ // Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
8
+ // Description: 1. lifo_random_op_test
9
+ // - Read/Write/Read_write_simultaneous
10
+ // Additional Comments:
11
+ //
12
+ //////////////////////////////////////////////////////////////////////////////////
13
+
14
+
15
+ module tb(
16
+ );
17
+ parameter DEPTH = 12; // DUT parameter
18
+ parameter DATA_WIDTH = 8; // DUT paramter
19
+ parameter CLK_PERIOD = 20; // TB clk generator
20
+ parameter SIM_TIMEOUT = 100000; // TB simulation time out
21
+ parameter TEST_WEIGHT = 1; //TB Test weight
22
+
23
+ integer lifo_expected [$];
24
+ integer i;
25
+ integer op_sel,op_count;
26
+ integer err_cnt = 0;
27
+ reg clk = 0;
28
+
29
+ reg rst = 1;
30
+ reg [DATA_WIDTH-1:0] data_wr = 0;
31
+ reg wr_en = 0;
32
+ reg rd_en = 0;
33
+ wire [DATA_WIDTH-1:0] data_rd;
34
+ wire lifo_empty;
35
+ wire lifo_full;
36
+
37
+ `ifdef XILINX_GLS
38
+ // for xilinx gate sim
39
+ glbl glbl();
40
+ `endif
41
+
42
+ lifo #(
43
+ .DEPTH(DEPTH),
44
+ .DATA_WIDTH(DATA_WIDTH)) DUT (
45
+ /*input wire*/ .clk(clk),
46
+ /*input wire*/ .rst(rst),
47
+ /*input wire [DATA_WIDTH-1:0]*/ .data_wr(data_wr),
48
+ /*input wire*/ .wr_en(wr_en),
49
+ /*output reg*/ .lifo_full(lifo_full),
50
+ /*output reg [DATA_WIDTH-1:0]*/ .data_rd(data_rd),
51
+ /*input wire*/ .rd_en(rd_en),
52
+ /*output wire*/ .lifo_empty(lifo_empty));
53
+
54
+ always #(CLK_PERIOD>>1) clk = ~clk;
55
+
56
+ integer exp_data_wr = 0;
57
+
58
+ task lifo_write(input integer wr_data_array[$]);
59
+ while($size(wr_data_array) != 0) begin
60
+ exp_data_wr = wr_data_array.pop_front();
61
+ @(posedge(clk))
62
+ wr_en <= 1;
63
+ data_wr <= exp_data_wr;
64
+ #1
65
+ if($size(lifo_expected)<DEPTH) begin
66
+ if(!lifo_full) begin
67
+ lifo_expected.push_back(exp_data_wr);
68
+ $display("%0t Data written = %d, entry = %d",$realtime,exp_data_wr,$size(lifo_expected));
69
+ end
70
+ else begin
71
+ $error("%0t LIFO is not full but lifo_full flag is asserted incorrectly",$realtime);
72
+ err_cnt = err_cnt + 1;
73
+ end
74
+ end else begin
75
+ if(lifo_full) begin
76
+ $display("%0t LIFO is full, lifo_full flag is asserted correctly",$realtime);
77
+ end
78
+ else begin
79
+ $error("%0t LIFO is full but lifo_full flag is not asserted",$realtime);
80
+ err_cnt = err_cnt + 1;
81
+ end
82
+ end
83
+ end
84
+ @(posedge(clk))
85
+ wr_en <= 0;
86
+ endtask
87
+
88
+ integer j;
89
+ integer act_data_rd = 0;
90
+ integer exp_data_rd = 0;
91
+
92
+ task lifo_read(input integer count);
93
+ @(posedge(clk))
94
+ rd_en <= 1;
95
+ for (j = 0; j<count; j=j+1)begin
96
+ @(posedge(clk))
97
+ if($size(lifo_expected)>0) begin
98
+ if(lifo_empty) begin
99
+ $error("%0t LIFO is not empty but lifo_empty flag is asserted incorrectly",$realtime);
100
+ end
101
+ #1
102
+ act_data_rd = data_rd;
103
+ exp_data_rd = lifo_expected.pop_back();
104
+ if(act_data_rd == exp_data_rd) begin
105
+ $display("%0t Data read = %d, FIFO entry = %d", $realtime, act_data_rd, $size(lifo_expected));
106
+ end
107
+ else begin
108
+ $error("%0t Data read mismatch, ACT = %d, EXP =%d, FIFO entry = %d", $realtime, act_data_rd, exp_data_rd, $size(lifo_expected));
109
+ err_cnt = err_cnt + 1;
110
+ end
111
+ end else begin
112
+ if(!lifo_empty) begin
113
+ $error("%0t LIFO is empty but lifo_empty flag is not asserted",$realtime);
114
+ err_cnt = err_cnt + 1;
115
+ end
116
+ else begin
117
+ $display("%0t LIFO is empty, lifo_empty flag is asserted correctly",$realtime);
118
+ end
119
+ end
120
+ end
121
+ rd_en = 0;
122
+ endtask
123
+
124
+ task lifo_simul_read_write(input integer wr_data_array[$]);
125
+ exp_data_wr = wr_data_array.pop_front();
126
+ @(posedge(clk))
127
+ rd_en <= 1;
128
+ wr_en <= 1;
129
+ data_wr <= exp_data_wr;
130
+
131
+ while($size(wr_data_array) != 0) begin
132
+ @(posedge(clk))
133
+ #1
134
+ act_data_rd = data_rd;
135
+ if(act_data_rd == exp_data_wr) begin
136
+ $display("%0t Simultaneous Data read/write = %d, FIFO entry = %d", $realtime, act_data_rd, $size(lifo_expected));
137
+ end
138
+ else begin
139
+ $error("%0t Simultaneous Data read/write, ACT = %d, EXP = %d, FIFO entry = %d", $realtime, act_data_rd, exp_data_wr, $size(lifo_expected));
140
+ end
141
+ #1
142
+ exp_data_wr = wr_data_array.pop_front();
143
+ data_wr <= exp_data_wr;
144
+ end
145
+ @(posedge(clk))
146
+ wr_en <= 0;
147
+ rd_en <= 0;
148
+ #1
149
+ act_data_rd = data_rd;
150
+ if(act_data_rd == exp_data_wr) begin
151
+ $display("%0t Simultaneous Data read/write = %d, FIFO entry = %d", $realtime, act_data_rd, $size(lifo_expected));
152
+ end
153
+ else begin
154
+ $error("%0t Simultaneous Data read/write, ACT = %d, EXP = %d, FIFO entry = %d", $realtime, act_data_rd, exp_data_wr, $size(lifo_expected));
155
+ end
156
+ endtask
157
+
158
+ integer wr_data_array[$];
159
+ integer k;
160
+
161
+ task lifo_random_op_test(input integer count);
162
+ i = count;
163
+ while (i > 0) begin
164
+ op_sel = $urandom_range(0,2);
165
+ op_count = $urandom_range(1,i);
166
+ i = i - op_count;
167
+ case(op_sel)
168
+ 0: begin // read
169
+ $display("%0t LIFO Read %d times", $realtime, op_count);
170
+ lifo_read(op_count);
171
+ end
172
+ 1: begin // write
173
+ $display("%0t LIFO Write %d times", $realtime, op_count);
174
+ for(k=0 ; k < op_count; k = k+1) begin
175
+ wr_data_array.push_back($urandom_range(0,2**DATA_WIDTH-1));
176
+ end
177
+ lifo_write(wr_data_array);
178
+ end
179
+ 2: begin // simultaneous read write
180
+ $display("%0t LIFO Simul Read Write %d times", $realtime, op_count);
181
+ for(k=0 ; k < op_count; k = k+1) begin
182
+ wr_data_array.push_back($urandom_range(0,2**DATA_WIDTH-1));
183
+ end
184
+ lifo_simul_read_write(wr_data_array);
185
+ end
186
+ endcase
187
+ end
188
+ endtask
189
+
190
+ initial begin
191
+ string vcdfile;
192
+ int vcdlevel;
193
+ int seed;
194
+ int temp;
195
+ if ($value$plusargs("VCDFILE=%s",vcdfile))
196
+ $dumpfile(vcdfile);
197
+ if ($value$plusargs("VCDLEVEL=%d",vcdlevel))
198
+ $dumpvars(vcdlevel, tb);
199
+ $display("Seed number: %d",vcdlevel);
200
+ if ($value$plusargs("SEED=%d",seed)) begin
201
+ $display("Seed number: %d",seed);
202
+ temp = $urandom(seed);
203
+ end
204
+
205
+ repeat(TEST_WEIGHT) begin
206
+ rst = 1;
207
+ #100
208
+ rst = 0;
209
+ #100
210
+ lifo_expected = {};
211
+ lifo_random_op_test(DEPTH);
212
+ #1000;
213
+ end
214
+ if (err_cnt > 0) begin
215
+ $display("\n%0t TEST FAILED",$realtime);
216
+ $display("Error count = %d\n", err_cnt);
217
+ end else
218
+ $display("\n%0t TEST PASSED\n", $realtime);
219
+ $finish;
220
+ end
221
+
222
+ initial begin
223
+ #(SIM_TIMEOUT);
224
+ $display("\n%0t TEST FAILED", $realtime);
225
+ $display("SIM TIMEOUT!\n");
226
+ $finish;
227
+ end
228
+
229
+ endmodule
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/Makefile ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for LIFO pyUVM VIP
2
+
3
+ SIM ?= icarus
4
+ TOPLEVEL_LANG ?= verilog
5
+ WAVES ?= 1
6
+
7
+ PWD=$(shell pwd)
8
+
9
+ # RTL source files
10
+ VERILOG_SOURCES = $(PWD)/../../src/lifo.sv
11
+
12
+ TOPLEVEL = lifo
13
+ MODULE = tb_lifo
14
+
15
+ # DUT parameters
16
+ COMPILE_ARGS = -Plifo.DEPTH=12
17
+ COMPILE_ARGS += -Plifo.DATA_WIDTH=8
18
+
19
+ COCOTB_HDL_TIMEUNIT = 1ns
20
+ COCOTB_HDL_TIMEPRECISION = 1ps
21
+
22
+ # Waveform dump
23
+ ifeq ($(SIM), icarus)
24
+ ifeq ($(WAVES), 1)
25
+ $(shell echo 'module iverilog_dump();' > iverilog_dump.v)
26
+ $(shell echo 'initial begin' >> iverilog_dump.v)
27
+ $(shell echo ' $$dumpfile("$(TOPLEVEL).vcd");' >> iverilog_dump.v)
28
+ $(shell echo ' $$dumpvars(0, $(TOPLEVEL));' >> iverilog_dump.v)
29
+ $(shell echo 'end' >> iverilog_dump.v)
30
+ $(shell echo 'endmodule' >> iverilog_dump.v)
31
+ VERILOG_SOURCES += $(PWD)/iverilog_dump.v
32
+ COMPILE_ARGS += -s iverilog_dump
33
+ endif
34
+ endif
35
+
36
+ include $(shell cocotb-config --makefiles)/Makefile.sim
37
+
38
+ .PHONY: help
39
+ help:
40
+ @echo "LIFO pyUVM VIP Makefile"
41
+ @echo "======================="
42
+ @echo ""
43
+ @echo "Usage:"
44
+ @echo " make - Run test with Icarus Verilog"
45
+ @echo " make WAVES=0 - Disable waveforms"
46
+ @echo " make clean - Clean build files"
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/README.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LIFO pyUVM VIP User Guide
2
+
3
+ ## Overview
4
+
5
+ Complete pyUVM-based Verification IP for **Last-In-First-Out (LIFO) Stack** - standard stack data structure.
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ cd LIFO/vip/pyuvm
11
+ make # Run test
12
+ gtkwave lifo.vcd # View waveforms
13
+ ```
14
+
15
+ ## LIFO Features
16
+
17
+ **Key Capability**: Last-In-First-Out stack with PUSH and POP operations
18
+
19
+ | Signal | Description | Width |
20
+ |--------|-------------|-------|
21
+ | `data_wr` | Write data for PUSH | DATA_WIDTH |
22
+ | `wr_en` | Write enable (PUSH) | 1 |
23
+ | `rd_en` | Read enable (POP) | 1 |
24
+ | `data_rd` | Read data from POP | DATA_WIDTH |
25
+ | `lifo_full` | Stack full flag | 1 |
26
+ | `lifo_empty` | Stack empty flag | 1 |
27
+
28
+ ## Configuration
29
+
30
+ ```python
31
+ cfg = LifoVipConfig("cfg")
32
+ cfg.DEPTH = 12
33
+ cfg.DATA_WIDTH = 8
34
+ ```
35
+
36
+ ## Self-Checking
37
+
38
+ The scoreboard uses a Python list as the LIFO reference model:
39
+ - PUSH: `list.append(data)` - adds to end
40
+ - POP: `list.pop()` - removes from end (LIFO behavior)
41
+
42
+ ## Example
43
+
44
+ ```python
45
+ from sequences.lifo_vip_push_seq import LifoVipPushSeq
46
+ from sequences.lifo_vip_pop_seq import LifoVipPopSeq
47
+
48
+ # Push data
49
+ push_seq = LifoVipPushSeq("push_seq")
50
+ push_seq.num_trans = 10
51
+ await push_seq.start(env.get_sequencer())
52
+
53
+ # Pop data
54
+ pop_seq = LifoVipPopSeq("pop_seq")
55
+ pop_seq.num_trans = 5
56
+ await pop_seq.start(env.get_sequencer())
57
+ ```
58
+
59
+ ## Available Sequences
60
+
61
+ - `LifoVipPushSeq` - Push-only operations
62
+ - `LifoVipPopSeq` - Pop-only operations
63
+ - `LifoVipRandomSeq` - Random PUSH/POP mix
64
+
65
+ ## Use Cases
66
+
67
+ - Stack data structure verification
68
+ - LIFO behavior validation
69
+ - Full/empty flag checking
70
+ - Bypass operation testing (simultaneous push/pop)
71
+
72
+ **Happy Verifying!**
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """LIFO VIP - pyUVM Verification IP for Last-In-First-Out Stack"""
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """LIFO VIP Agent Components"""
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_agent.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Agent"""
2
+ from pyuvm import uvm_agent
3
+ from .lifo_vip_driver import LifoVipDriver
4
+ from .lifo_vip_monitor import LifoVipMonitor
5
+ from .lifo_vip_sequencer import LifoVipSequencer
6
+
7
+ class LifoVipAgent(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.cfg = None
14
+
15
+ def build_phase(self):
16
+ super().build_phase()
17
+ from pyuvm import ConfigDB
18
+ arr = []
19
+ if not ConfigDB().get(self, "", "lifo_vip_cfg", arr):
20
+ self.logger.critical("No config found in ConfigDB!")
21
+ else:
22
+ self.cfg = arr[0]
23
+
24
+ # Always create monitor
25
+ self.monitor = LifoVipMonitor("monitor", self)
26
+
27
+ # Create driver and sequencer if active
28
+ if self.cfg.is_active:
29
+ self.driver = LifoVipDriver("driver", self)
30
+ self.sequencer = LifoVipSequencer("sequencer", self)
31
+
32
+ def connect_phase(self):
33
+ super().connect_phase()
34
+ if self.cfg.is_active:
35
+ self.driver.seq_item_port.connect(self.sequencer.seq_item_export)
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_driver.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Driver"""
2
+ from pyuvm import uvm_driver
3
+ from cocotb.triggers import RisingEdge
4
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
5
+ from ..common import LifoOp
6
+
7
+ class LifoVipDriver(uvm_driver):
8
+ def __init__(self, name, parent):
9
+ super().__init__(name, parent)
10
+ self.dut = None
11
+ self.cfg = None
12
+
13
+ def build_phase(self):
14
+ super().build_phase()
15
+ from pyuvm import ConfigDB
16
+ arr = []
17
+ if not ConfigDB().get(self, "", "lifo_vip_dut", arr):
18
+ self.logger.critical("No DUT found in ConfigDB!")
19
+ else:
20
+ self.dut = arr[0]
21
+
22
+ arr = []
23
+ if not ConfigDB().get(self, "", "lifo_vip_cfg", arr):
24
+ self.logger.critical("No config found in ConfigDB!")
25
+ else:
26
+ self.cfg = arr[0]
27
+
28
+ async def run_phase(self):
29
+ while True:
30
+ item = await self.seq_item_port.get_next_item()
31
+ await self.drive_item(item)
32
+ self.seq_item_port.item_done()
33
+
34
+ async def drive_item(self, item):
35
+ """Drive transaction to DUT"""
36
+ if item.op == LifoOp.PUSH:
37
+ await self.drive_push(item)
38
+ elif item.op == LifoOp.POP:
39
+ await self.drive_pop(item)
40
+ elif item.op == LifoOp.IDLE:
41
+ await self.drive_idle()
42
+
43
+ async def drive_push(self, item):
44
+ """Drive PUSH operation"""
45
+ await RisingEdge(self.dut.clk)
46
+ self.dut.wr_en.value = 1
47
+ self.dut.rd_en.value = 0
48
+ data_mask = (1 << self.cfg.DATA_WIDTH) - 1
49
+ self.dut.data_wr.value = item.data & data_mask
50
+
51
+ await RisingEdge(self.dut.clk)
52
+ item.full = bool(self.dut.lifo_full.value)
53
+ item.success = not item.full
54
+
55
+ self.dut.wr_en.value = 0
56
+
57
+ self.logger.debug(f"PUSH: data=0x{item.data:x} full={item.full}")
58
+
59
+ async def drive_pop(self, item):
60
+ """Drive POP operation"""
61
+ await RisingEdge(self.dut.clk)
62
+ self.dut.rd_en.value = 1
63
+ self.dut.wr_en.value = 0
64
+
65
+ await RisingEdge(self.dut.clk)
66
+ item.empty = bool(self.dut.lifo_empty.value)
67
+ item.read_data = int(self.dut.data_rd.value)
68
+ item.success = not item.empty
69
+
70
+ self.dut.rd_en.value = 0
71
+
72
+ self.logger.debug(f"POP: data=0x{item.read_data:x} empty={item.empty}")
73
+
74
+ async def drive_idle(self):
75
+ """Drive IDLE cycle"""
76
+ await RisingEdge(self.dut.clk)
77
+ self.dut.wr_en.value = 0
78
+ self.dut.rd_en.value = 0
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_monitor.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Monitor"""
2
+ from pyuvm import uvm_monitor
3
+ from cocotb.triggers import RisingEdge
4
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
5
+ from ..common import LifoOp
6
+
7
+ class LifoVipMonitor(uvm_monitor):
8
+ def __init__(self, name, parent):
9
+ super().__init__(name, parent)
10
+ self.dut = None
11
+ self.cfg = None
12
+ from pyuvm import uvm_analysis_port
13
+ self.ap = uvm_analysis_port("ap", self)
14
+
15
+ def build_phase(self):
16
+ super().build_phase()
17
+ from pyuvm import ConfigDB
18
+ arr = []
19
+ if not ConfigDB().get(self, "", "lifo_vip_dut", arr):
20
+ self.logger.critical("No DUT found in ConfigDB!")
21
+ else:
22
+ self.dut = arr[0]
23
+
24
+ arr = []
25
+ if not ConfigDB().get(self, "", "lifo_vip_cfg", arr):
26
+ self.logger.critical("No config found in ConfigDB!")
27
+ else:
28
+ self.cfg = arr[0]
29
+
30
+ async def run_phase(self):
31
+ while True:
32
+ await RisingEdge(self.dut.clk)
33
+
34
+ wr_en = bool(self.dut.wr_en.value)
35
+ rd_en = bool(self.dut.rd_en.value)
36
+
37
+ # Detect push operation
38
+ if wr_en and not rd_en:
39
+ item = LifoVipSeqItem("item")
40
+ item.op = LifoOp.PUSH
41
+ item.data = int(self.dut.data_wr.value)
42
+ item.full = bool(self.dut.lifo_full.value)
43
+ item.success = not item.full
44
+ self.ap.write(item)
45
+ self.logger.debug(f"Observed PUSH: data=0x{item.data:x} full={item.full}")
46
+
47
+ # Detect pop operation
48
+ elif rd_en and not wr_en:
49
+ await RisingEdge(self.dut.clk) # Wait one cycle to capture read data
50
+ item = LifoVipSeqItem("item")
51
+ item.op = LifoOp.POP
52
+ item.read_data = int(self.dut.data_rd.value)
53
+ item.empty = bool(self.dut.lifo_empty.value)
54
+ item.success = not item.empty
55
+ self.ap.write(item)
56
+ self.logger.debug(f"Observed POP: data=0x{item.read_data:x} empty={item.empty}")
57
+
58
+ # Detect simultaneous push/pop (bypass)
59
+ elif wr_en and rd_en:
60
+ await RisingEdge(self.dut.clk)
61
+ item = LifoVipSeqItem("item")
62
+ item.op = LifoOp.PUSH # Record as push for scoreboard
63
+ item.data = int(self.dut.data_wr.value)
64
+ item.read_data = int(self.dut.data_rd.value) # Bypass data
65
+ item.full = bool(self.dut.lifo_full.value)
66
+ item.empty = bool(self.dut.lifo_empty.value)
67
+ self.ap.write(item)
68
+ self.logger.debug(f"Observed BYPASS: wr=0x{item.data:x} rd=0x{item.read_data:x}")
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/agent/lifo_vip_sequencer.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Sequencer"""
2
+ from pyuvm import uvm_sequencer
3
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
4
+
5
+ class LifoVipSequencer(uvm_sequencer):
6
+ def __init__(self, name, parent):
7
+ super().__init__(name, parent)
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/common/__init__.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Common Components"""
2
+ from enum import IntEnum
3
+
4
+ class LifoOp(IntEnum):
5
+ """LIFO Operation Types"""
6
+ PUSH = 0
7
+ POP = 1
8
+ IDLE = 2
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/common/lifo_vip_config.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Configuration"""
2
+ from pyuvm import uvm_object
3
+
4
+ class LifoVipConfig(uvm_object):
5
+ def __init__(self, name="lifo_vip_config"):
6
+ super().__init__(name)
7
+ # DUT parameters
8
+ self.DEPTH = 12
9
+ self.DATA_WIDTH = 8
10
+
11
+ # VIP configuration
12
+ self.has_agent = True
13
+ self.enable_scoreboard = True
14
+ self.is_active = True
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/common/lifo_vip_seq_item.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Sequence Item"""
2
+ from pyuvm import uvm_sequence_item
3
+ from .import LifoOp
4
+ import random
5
+
6
+ class LifoVipSeqItem(uvm_sequence_item):
7
+ def __init__(self, name="lifo_vip_seq_item"):
8
+ super().__init__(name)
9
+ # Transaction fields
10
+ self.op = LifoOp.PUSH
11
+ self.data = 0
12
+
13
+ # Response fields
14
+ self.read_data = 0
15
+ self.full = False
16
+ self.empty = False
17
+ self.success = True
18
+
19
+ # Config reference
20
+ self.cfg = None
21
+
22
+ def randomize(self):
23
+ """Randomize transaction fields"""
24
+ # Randomize operation
25
+ self.op = random.choice([LifoOp.PUSH, LifoOp.POP])
26
+
27
+ # Randomize data
28
+ if self.cfg:
29
+ max_val = (1 << self.cfg.DATA_WIDTH) - 1
30
+ else:
31
+ max_val = 255 # 8-bit default
32
+ self.data = random.randint(0, max_val)
33
+
34
+ return True
35
+
36
+ def __str__(self):
37
+ op_name = self.op.name if hasattr(self.op, 'name') else str(self.op)
38
+ return (f"Op:{op_name} Data:0x{self.data:x} "
39
+ f"ReadData:0x{self.read_data:x} Full:{self.full} "
40
+ f"Empty:{self.empty} Success:{self.success}")
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/env/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """LIFO VIP Environment Components"""
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/env/lifo_vip_env.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Environment"""
2
+ from pyuvm import uvm_env, ConfigDB
3
+ from ..agent.lifo_vip_agent import LifoVipAgent
4
+ from .lifo_vip_scoreboard import LifoVipScoreboard
5
+
6
+ class LifoVipEnv(uvm_env):
7
+ def __init__(self, name, parent):
8
+ super().__init__(name, parent)
9
+ self.agent = None
10
+ self.scoreboard = None
11
+ self.cfg = None
12
+
13
+ def build_phase(self):
14
+ super().build_phase()
15
+ arr = []
16
+ if not ConfigDB().get(self, "", "lifo_vip_cfg", arr):
17
+ self.logger.critical("No config found in ConfigDB!")
18
+ else:
19
+ self.cfg = arr[0]
20
+
21
+ # Create agent
22
+ if self.cfg.has_agent:
23
+ self.agent = LifoVipAgent("agent", self)
24
+
25
+ # Create scoreboard
26
+ if self.cfg.enable_scoreboard:
27
+ self.scoreboard = LifoVipScoreboard("scoreboard", self)
28
+
29
+ def connect_phase(self):
30
+ super().connect_phase()
31
+ if self.cfg.has_agent and self.cfg.enable_scoreboard:
32
+ self.agent.monitor.ap.connect(self.scoreboard.imp)
33
+
34
+ def get_sequencer(self):
35
+ """Return sequencer for use by sequences"""
36
+ if self.agent and self.agent.sequencer:
37
+ return self.agent.sequencer
38
+ return None
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/env/lifo_vip_scoreboard.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Scoreboard"""
2
+ from pyuvm import uvm_scoreboard, uvm_analysis_imp
3
+ from ..common import LifoOp
4
+
5
+ class LifoVipScoreboard(uvm_scoreboard):
6
+ def __init__(self, name, parent):
7
+ super().__init__(name, parent)
8
+ self.imp = uvm_analysis_imp("imp", self)
9
+ self.cfg = None
10
+ self.expected_queue = [] # Python list as LIFO model
11
+ self.push_count = 0
12
+ self.pop_count = 0
13
+ self.error_count = 0
14
+ self.bypass_count = 0
15
+
16
+ def build_phase(self):
17
+ super().build_phase()
18
+ from pyuvm import ConfigDB
19
+ arr = []
20
+ if not ConfigDB().get(self, "", "lifo_vip_cfg", arr):
21
+ self.logger.critical("No config found in ConfigDB!")
22
+ else:
23
+ self.cfg = arr[0]
24
+
25
+ def write(self, item):
26
+ """Receive transaction from monitor"""
27
+ if item.op == LifoOp.PUSH:
28
+ self.check_push(item)
29
+ elif item.op == LifoOp.POP:
30
+ self.check_pop(item)
31
+
32
+ def check_push(self, item):
33
+ """Check PUSH operation"""
34
+ if item.success:
35
+ # Successful push - add to model
36
+ self.expected_queue.append(item.data)
37
+ self.push_count += 1
38
+ self.logger.info(f"PUSH: data=0x{item.data:x} depth={len(self.expected_queue)}")
39
+
40
+ # Check full flag
41
+ if len(self.expected_queue) == self.cfg.DEPTH and not item.full:
42
+ self.logger.error(f"LIFO should be full but full flag not set. Depth={len(self.expected_queue)}")
43
+ self.error_count += 1
44
+ else:
45
+ # Failed push due to full LIFO
46
+ if not item.full:
47
+ self.logger.error("Push failed but full flag not set")
48
+ self.error_count += 1
49
+ self.logger.info("PUSH failed - LIFO full")
50
+
51
+ def check_pop(self, item):
52
+ """Check POP operation"""
53
+ if item.success:
54
+ # Successful pop - check data
55
+ if len(self.expected_queue) == 0:
56
+ self.logger.error("Pop succeeded but model is empty")
57
+ self.error_count += 1
58
+ return
59
+
60
+ expected_data = self.expected_queue.pop() # LIFO: pop from back
61
+ self.pop_count += 1
62
+
63
+ if item.read_data != expected_data:
64
+ self.logger.error(f"Data mismatch! Expected=0x{expected_data:x} Actual=0x{item.read_data:x}")
65
+ self.error_count += 1
66
+ else:
67
+ self.logger.info(f"POP: data=0x{item.read_data:x} depth={len(self.expected_queue)} MATCH")
68
+
69
+ # Check empty flag
70
+ if len(self.expected_queue) == 0 and not item.empty:
71
+ self.logger.error("LIFO should be empty but empty flag not set")
72
+ self.error_count += 1
73
+ else:
74
+ # Failed pop due to empty LIFO
75
+ if not item.empty:
76
+ self.logger.error("Pop failed but empty flag not set")
77
+ self.error_count += 1
78
+ self.logger.info("POP failed - LIFO empty")
79
+
80
+ def report_phase(self):
81
+ super().report_phase()
82
+ self.logger.info("=" * 50)
83
+ self.logger.info(f"Push Count: {self.push_count}")
84
+ self.logger.info(f"Pop Count: {self.pop_count}")
85
+ self.logger.info(f"Error Count: {self.error_count}")
86
+ self.logger.info(f"Final Queue Depth: {len(self.expected_queue)}")
87
+ self.logger.info("=" * 50)
88
+
89
+ if self.error_count > 0:
90
+ self.logger.error(f"Test FAILED with {self.error_count} errors")
91
+ else:
92
+ self.logger.info("Test PASSED - No errors detected")
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """LIFO VIP Sequences"""
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_base_seq.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Base Sequence"""
2
+ from pyuvm import uvm_sequence
3
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
4
+
5
+ class LifoVipBaseSeq(uvm_sequence):
6
+ def __init__(self, name):
7
+ super().__init__(name)
8
+ self.num_trans = 10
9
+ self.cfg = None
10
+
11
+ async def body(self):
12
+ """Sequence body - override in derived classes"""
13
+ pass
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_pop_seq.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Pop Sequence"""
2
+ from .lifo_vip_base_seq import LifoVipBaseSeq
3
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
4
+ from ..common import LifoOp
5
+
6
+ class LifoVipPopSeq(LifoVipBaseSeq):
7
+ def __init__(self, name):
8
+ super().__init__(name)
9
+
10
+ async def body(self):
11
+ """Generate POP transactions"""
12
+ for i in range(self.num_trans):
13
+ item = LifoVipSeqItem(f"pop_item_{i}")
14
+ item.cfg = self.cfg
15
+ item.op = LifoOp.POP
16
+ await self.start_item(item)
17
+ await self.finish_item(item)
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_push_seq.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Push Sequence"""
2
+ from .lifo_vip_base_seq import LifoVipBaseSeq
3
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
4
+ from ..common import LifoOp
5
+
6
+ class LifoVipPushSeq(LifoVipBaseSeq):
7
+ def __init__(self, name):
8
+ super().__init__(name)
9
+
10
+ async def body(self):
11
+ """Generate PUSH transactions"""
12
+ for i in range(self.num_trans):
13
+ item = LifoVipSeqItem(f"push_item_{i}")
14
+ item.cfg = self.cfg
15
+ item.op = LifoOp.PUSH
16
+ item.randomize()
17
+ await self.start_item(item)
18
+ await self.finish_item(item)
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/sequences/lifo_vip_random_seq.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Random Sequence"""
2
+ from .lifo_vip_base_seq import LifoVipBaseSeq
3
+ from ..common.lifo_vip_seq_item import LifoVipSeqItem
4
+
5
+ class LifoVipRandomSeq(LifoVipBaseSeq):
6
+ def __init__(self, name):
7
+ super().__init__(name)
8
+
9
+ async def body(self):
10
+ """Generate random PUSH/POP transactions"""
11
+ for i in range(self.num_trans):
12
+ item = LifoVipSeqItem(f"rand_item_{i}")
13
+ item.cfg = self.cfg
14
+ item.randomize() # Randomizes op and data
15
+ await self.start_item(item)
16
+ await self.finish_item(item)
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tb_lifo.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Testbench"""
2
+ import cocotb
3
+ from cocotb.clock import Clock
4
+ from cocotb.triggers import Timer, FallingEdge
5
+ from pyuvm import *
6
+ from tests.lifo_vip_simple_test import SimpleTest
7
+
8
+ async def dut_init(dut):
9
+ """Initialize DUT"""
10
+ cocotb.log.info("="*60)
11
+ cocotb.log.info("LIFO VIP Testbench Initialization")
12
+ cocotb.log.info("="*60)
13
+
14
+ # Start clock
15
+ cocotb.start_soon(Clock(dut.clk, 10, units="ns").start())
16
+
17
+ # Reset
18
+ dut.rst.value = 1
19
+ dut.data_wr.value = 0
20
+ dut.wr_en.value = 0
21
+ dut.rd_en.value = 0
22
+
23
+ await Timer(50, units="ns")
24
+ dut.rst.value = 0
25
+ await Timer(10, units="ns")
26
+
27
+ cocotb.log.info("DUT initialization complete")
28
+ ConfigDB().set(None, "*", "lifo_vip_dut", dut)
29
+
30
+ @cocotb.test()
31
+ async def lifo_simple_test(dut):
32
+ """Simple test for LIFO"""
33
+ await dut_init(dut)
34
+ cocotb.log.info("Starting LIFO Simple Test (pyUVM)")
35
+ await uvm_root().run_test("SimpleTest")
36
+ cocotb.log.info("LIFO Simple Test Complete")
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tests/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """LIFO VIP Tests"""
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tests/lifo_vip_base_test.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Base Test"""
2
+ from pyuvm import *
3
+ from ..env.lifo_vip_env import LifoVipEnv
4
+ from ..common.lifo_vip_config import LifoVipConfig
5
+
6
+ class BaseTest(uvm_test):
7
+ def __init__(self, name, parent):
8
+ super().__init__(name, parent)
9
+ self.env = None
10
+ self.cfg = None
11
+
12
+ def build_phase(self):
13
+ super().build_phase()
14
+
15
+ # Create configuration
16
+ self.cfg = LifoVipConfig("cfg")
17
+ self.cfg.DEPTH = 12
18
+ self.cfg.DATA_WIDTH = 8
19
+ self.cfg.has_agent = True
20
+ self.cfg.enable_scoreboard = True
21
+ self.cfg.is_active = True
22
+
23
+ # Set config in ConfigDB
24
+ ConfigDB().set(None, "*", "lifo_vip_cfg", self.cfg)
25
+
26
+ # Get DUT from ConfigDB
27
+ arr = []
28
+ if not ConfigDB().get(self, "", "lifo_vip_dut", arr):
29
+ self.logger.critical("No DUT found in ConfigDB!")
30
+
31
+ # Create environment
32
+ self.env = LifoVipEnv("env", self)
33
+
34
+ async def run_phase(self):
35
+ self.raise_objection()
36
+ # Base test does nothing - override in derived classes
37
+ self.drop_objection()
Weiyet_RTLStructLib/source/LIFO/vip/pyuvm/tests/lifo_vip_simple_test.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LIFO VIP Simple Test"""
2
+ from pyuvm import *
3
+ from cocotb.triggers import Timer
4
+ from .lifo_vip_base_test import BaseTest
5
+ from ..sequences.lifo_vip_push_seq import LifoVipPushSeq
6
+ from ..sequences.lifo_vip_pop_seq import LifoVipPopSeq
7
+ from ..sequences.lifo_vip_random_seq import LifoVipRandomSeq
8
+
9
+ class SimpleTest(BaseTest):
10
+ def __init__(self, name, parent):
11
+ super().__init__(name, parent)
12
+
13
+ async def run_phase(self):
14
+ self.raise_objection()
15
+
16
+ # Push some data
17
+ push_seq = LifoVipPushSeq("push_seq")
18
+ push_seq.cfg = self.cfg
19
+ push_seq.num_trans = 10
20
+ await push_seq.start(self.env.get_sequencer())
21
+
22
+ # Pop some data
23
+ pop_seq = LifoVipPopSeq("pop_seq")
24
+ pop_seq.cfg = self.cfg
25
+ pop_seq.num_trans = 5
26
+ await pop_seq.start(self.env.get_sequencer())
27
+
28
+ # Random sequence
29
+ rand_seq = LifoVipRandomSeq("rand_seq")
30
+ rand_seq.cfg = self.cfg
31
+ rand_seq.num_trans = 20
32
+ await rand_seq.start(self.env.get_sequencer())
33
+
34
+ await Timer(200, units="ns")
35
+ self.drop_objection()
Weiyet_RTLStructLib/source/LIFO/vip/uvm/README.md ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LIFO (Stack) UVM VIP (Verification IP) User Guide
2
+
3
+ ## 📁 Directory Structure
4
+
5
+ ```
6
+ uvm/
7
+ ├── common/ # Core VIP source files
8
+ │ ├── lifo_vip_pkg.sv # Main package + types/enums
9
+ │ ├── lifo_vip_config.sv # Configuration class
10
+ │ └── lifo_vip_seq_item.sv # Transaction definitions
11
+ ├── agent/ # Agent layer components
12
+ │ ├── lifo_vip_driver.sv # Driver implementation
13
+ │ ├── lifo_vip_monitor.sv # Monitor implementation
14
+ │ ├── lifo_vip_sequencer.sv # Sequencer (simple)
15
+ │ └── lifo_vip_agent.sv # Agent wrapper
16
+ ├── env/ # Environment layer
17
+ │ ├── lifo_vip_env.sv # Environment
18
+ │ └── lifo_vip_scoreboard.sv # Checking components
19
+ ├── sequences/ # Test sequences
20
+ │ ├── lifo_vip_base_seq.sv # Base sequence
21
+ │ ├── lifo_vip_push_seq.sv # Push sequences
22
+ │ └── lifo_vip_pop_seq.sv # Pop sequences
23
+ ├── interface/ # Interface definition
24
+ │ └── lifo_vip_if.sv # Virtual interface
25
+ └── sim/ # Testbench
26
+ ├── tests/
27
+ │ ├── lifo_vip_base_test.sv # Base test class
28
+ │ └── lifo_vip_simple_test.sv # Simple test + random test + full/empty test
29
+ └── tb_top.sv # Testbench top module
30
+ ```
31
+
32
+ ## 🚀 Quick Start
33
+
34
+ **Step 1:** Update Agent Interface with correct internal signals (refer to `lifo_vip_if.sv`) in your top level testbench:
35
+ ```systemverilog
36
+ // Update interface signal widths and connections in tb_top.sv
37
+ lifo_vip_if dut_if(clk);
38
+ assign dut_if.rst = u_lifo.rst;
39
+ assign dut_if.data_wr = u_lifo.data_wr;
40
+ assign dut_if.wr_en = u_lifo.wr_en;
41
+ assign dut_if.lifo_full = u_lifo.lifo_full;
42
+ assign dut_if.data_rd = u_lifo.data_rd;
43
+ assign dut_if.rd_en = u_lifo.rd_en;
44
+ assign dut_if.lifo_empty = u_lifo.lifo_empty;
45
+
46
+ // Set interface in config DB
47
+ uvm_config_db#(virtual lifo_vip_if)::set(null, "*", "lifo_vip_vif", dut_if);
48
+ ```
49
+
50
+ **Step 2:** Update DUT parameters/configuration (refer to `lifo_vip_config.sv`) in your test:
51
+ ```systemverilog
52
+ // In your test's build_phase()
53
+ cfg = lifo_vip_config::type_id::create("cfg");
54
+ cfg.DEPTH = 12; // Match your LIFO depth
55
+ cfg.DATA_WIDTH = 8; // Match your data width
56
+
57
+ // Set config in database
58
+ uvm_config_db#(lifo_vip_config)::set(this, "*", "lifo_vip_cfg", cfg);
59
+ ```
60
+
61
+ **Step 3:** Agent instantiation in your environment (refer to `lifo_vip_env.sv`):
62
+ ```systemverilog
63
+ // Create LIFO VIP environment
64
+ lifo_env = lifo_vip_env::type_id::create("lifo_env", this);
65
+ ```
66
+
67
+ ## 🚀 Available Sequences
68
+
69
+ **Push Sequence:**
70
+ ```systemverilog
71
+ lifo_vip_push_seq push_seq = lifo_vip_push_seq::type_id::create("push_seq");
72
+ push_seq.num_pushes = 10;
73
+ push_seq.start(env.get_sequencer());
74
+ ```
75
+
76
+ **Pop Sequence:**
77
+ ```systemverilog
78
+ lifo_vip_pop_seq pop_seq = lifo_vip_pop_seq::type_id::create("pop_seq");
79
+ pop_seq.num_pops = 10;
80
+ pop_seq.start(env.get_sequencer());
81
+ ```
82
+
83
+ ## 🧪 Available Tests
84
+
85
+ The VIP includes three pre-built tests that match the testing patterns from `tb/sv/tb.sv`:
86
+
87
+ ### 1. Simple Test
88
+ Basic push and pop operations:
89
+ ```bash
90
+ # Run simple test
91
+ vsim -c +UVM_TESTNAME=simple_test -do "run -all; quit"
92
+ ```
93
+
94
+ ### 2. Random Test
95
+ Random sequence of push/pop operations (similar to `lifo_random_op_test` in tb.sv):
96
+ ```bash
97
+ # Run random test
98
+ vsim -c +UVM_TESTNAME=random_test -do "run -all; quit"
99
+ ```
100
+
101
+ ### 3. Full/Empty Test
102
+ Tests boundary conditions - filling LIFO completely and emptying it:
103
+ ```bash
104
+ # Run full/empty test
105
+ vsim -c +UVM_TESTNAME=full_empty_test -do "run -all; quit"
106
+ ```
107
+
108
+ ## ✅ Self-Checking Features
109
+
110
+ The scoreboard automatically verifies:
111
+ - ✅ Data integrity through LIFO (Last-In-First-Out order)
112
+ - ✅ Push when full behavior
113
+ - ✅ Pop when empty behavior
114
+ - ✅ LIFO flag correctness (full/empty)
115
+ - ✅ Transaction success/failure
116
+ - ✅ LIFO depth tracking
117
+
118
+ ## 📊 Test Coverage Comparison
119
+
120
+ The UVM VIP tests provide equivalent coverage to the original testbench:
121
+
122
+ | tb/sv/tb.sv | UVM VIP Test | Description |
123
+ |-------------|--------------|-------------|
124
+ | `lifo_write()` | `lifo_vip_push_seq` | Push data to LIFO |
125
+ | `lifo_read()` | `lifo_vip_pop_seq` | Pop data from LIFO |
126
+ | `lifo_random_op_test()` | `random_test` | Random push/pop/bypass operations |
127
+ | `lifo_simul_read_write()` | Monitor bypass detection | Simultaneous read/write |
128
+ | Full/empty flag checking | `full_empty_test` + scoreboard | Boundary condition testing |
129
+
130
+ ## 🔧 Key Differences from FIFO VIP
131
+
132
+ 1. **Single Clock Domain**: LIFO uses single clock (synchronous), unlike FIFO's dual-clock support
133
+ 2. **Operation Types**:
134
+ - FIFO: `WRITE`, `READ`, `IDLE`
135
+ - LIFO: `PUSH`, `POP`, `IDLE`
136
+ 3. **Data Order**:
137
+ - FIFO: First-In-First-Out (queue model)
138
+ - LIFO: Last-In-First-Out (stack model - `push_back`/`pop_back`)
139
+ 4. **Bypass Mode**: LIFO supports simultaneous push/pop (bypass operation)
140
+ 5. **Single Agent**: One agent handles all operations (vs separate read/write agents in FIFO)
141
+
142
+ ## 🚨 Common Issues & Solutions
143
+
144
+ ### Issue: Interface signal width mismatch
145
+ **Solution:** Update `lifo_vip_if.sv` line 16-17 to match your LIFO's `DATA_WIDTH`:
146
+ ```systemverilog
147
+ logic [DATA_WIDTH-1:0] data_wr;
148
+ logic [DATA_WIDTH-1:0] data_rd;
149
+ ```
150
+
151
+ ### Issue: Config parameters don't match DUT
152
+ **Solution:** Ensure `lifo_vip_config.sv` parameters match your DUT instantiation in `tb_top.sv`
153
+
154
+ ### Future Work
155
+ - Add assertions to `lifo_vip_if.sv` or create a separate checker component
156
+ - Add functional coverage for:
157
+ - Push/pop distribution
158
+ - Full/empty transitions
159
+ - Bypass operations
160
+ - Back-to-back operations
161
+
162
+ ## 📚 Example Usage
163
+
164
+ ```systemverilog
165
+ class my_test extends base_test;
166
+ `uvm_component_utils(my_test)
167
+
168
+ task run_phase(uvm_phase phase);
169
+ lifo_vip_push_seq push_seq;
170
+ lifo_vip_pop_seq pop_seq;
171
+
172
+ phase.raise_objection(this);
173
+
174
+ // Fill LIFO
175
+ push_seq = lifo_vip_push_seq::type_id::create("push_seq");
176
+ push_seq.num_pushes = cfg.DEPTH;
177
+ push_seq.start(env.get_sequencer());
178
+
179
+ #100ns;
180
+
181
+ // Empty LIFO and verify LIFO order
182
+ pop_seq = lifo_vip_pop_seq::type_id::create("pop_seq");
183
+ pop_seq.num_pops = cfg.DEPTH;
184
+ pop_seq.start(env.get_sequencer());
185
+
186
+ #100ns;
187
+ phase.drop_objection(this);
188
+ endtask
189
+ endclass
190
+ ```
191
+
192
+ **Happy Verifying! 🚀**
193
+
194
+ *This VIP follows UVM best practices while keeping complexity minimal for ease of use and learning.*
Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_agent.sv ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // Create Date: 01/04/2026
4
+ // Module Name: lifo_vip_agent
5
+ // Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
6
+ // Description: Agent wrapper containing driver, monitor, and sequencer
7
+ //
8
+ //////////////////////////////////////////////////////////////////////////////////
9
+
10
+ class lifo_vip_agent extends uvm_agent;
11
+ `uvm_component_utils(lifo_vip_agent)
12
+
13
+ lifo_vip_driver driver;
14
+ lifo_vip_monitor monitor;
15
+ lifo_vip_sequencer sequencer;
16
+
17
+ uvm_analysis_port #(lifo_vip_seq_item) ap;
18
+
19
+ function new(string name = "lifo_vip_agent", uvm_component parent = null);
20
+ super.new(name, parent);
21
+ endfunction
22
+
23
+ function void build_phase(uvm_phase phase);
24
+ super.build_phase(phase);
25
+
26
+ monitor = lifo_vip_monitor::type_id::create("monitor", this);
27
+
28
+ if (is_active == UVM_ACTIVE) begin
29
+ driver = lifo_vip_driver::type_id::create("driver", this);
30
+ sequencer = lifo_vip_sequencer::type_id::create("sequencer", this);
31
+ end
32
+ endfunction
33
+
34
+ function void connect_phase(uvm_phase phase);
35
+ super.connect_phase(phase);
36
+
37
+ ap = monitor.ap;
38
+
39
+ if (is_active == UVM_ACTIVE) begin
40
+ driver.seq_item_port.connect(sequencer.seq_item_export);
41
+ end
42
+ endfunction
43
+
44
+ endclass
Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_driver.sv ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // Create Date: 01/04/2026
4
+ // Module Name: lifo_vip_driver
5
+ // Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
6
+ // Description: Driver for LIFO VIP - drives transactions to DUT
7
+ //
8
+ //////////////////////////////////////////////////////////////////////////////////
9
+
10
+ class lifo_vip_driver extends uvm_driver #(lifo_vip_seq_item);
11
+ `uvm_component_utils(lifo_vip_driver)
12
+
13
+ virtual lifo_vip_if vif;
14
+ lifo_vip_config cfg;
15
+
16
+ function new(string name = "lifo_vip_driver", uvm_component parent = null);
17
+ super.new(name, parent);
18
+ endfunction
19
+
20
+ function void build_phase(uvm_phase phase);
21
+ super.build_phase(phase);
22
+ if (!uvm_config_db#(virtual lifo_vip_if)::get(this, "", "lifo_vip_vif", vif))
23
+ `uvm_fatal("DRIVER", "No virtual interface")
24
+ if (!uvm_config_db#(lifo_vip_config)::get(this, "", "lifo_vip_cfg", cfg))
25
+ `uvm_fatal("DRIVER", "No config")
26
+ endfunction
27
+
28
+ task run_phase(uvm_phase phase);
29
+ forever begin
30
+ seq_item_port.get_next_item(req);
31
+ drive_item(req);
32
+ seq_item_port.item_done();
33
+ end
34
+ endtask
35
+
36
+ task drive_item(lifo_vip_seq_item item);
37
+ case (item.op)
38
+ PUSH: drive_push(item);
39
+ POP: drive_pop(item);
40
+ IDLE: drive_idle();
41
+ endcase
42
+ endtask
43
+
44
+ task drive_push(lifo_vip_seq_item item);
45
+ @(vif.cb);
46
+ vif.cb.wr_en <= 1'b1;
47
+ vif.cb.rd_en <= 1'b0;
48
+ vif.cb.data_wr <= item.data[cfg.DATA_WIDTH-1:0];
49
+
50
+ @(vif.cb);
51
+ item.full = vif.cb.lifo_full;
52
+ item.success = !vif.cb.lifo_full;
53
+
54
+ vif.cb.wr_en <= 1'b0;
55
+
56
+ `uvm_info("DRIVER", $sformatf("Push: data=0x%0h full=%0b", item.data, item.full), UVM_HIGH)
57
+ endtask
58
+
59
+ task drive_pop(lifo_vip_seq_item item);
60
+ @(vif.cb);
61
+ vif.cb.rd_en <= 1'b1;
62
+ vif.cb.wr_en <= 1'b0;
63
+
64
+ @(vif.cb);
65
+ item.empty = vif.cb.lifo_empty;
66
+ item.read_data = vif.cb.data_rd;
67
+ item.success = !vif.cb.lifo_empty;
68
+
69
+ vif.cb.rd_en <= 1'b0;
70
+
71
+ `uvm_info("DRIVER", $sformatf("Pop: data=0x%0h empty=%0b", item.read_data, item.empty), UVM_HIGH)
72
+ endtask
73
+
74
+ task drive_idle();
75
+ @(vif.cb);
76
+ vif.cb.wr_en <= 1'b0;
77
+ vif.cb.rd_en <= 1'b0;
78
+ endtask
79
+
80
+ endclass
Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_monitor.sv ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // Create Date: 01/04/2026
4
+ // Module Name: lifo_vip_monitor
5
+ // Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
6
+ // Description: Monitor for LIFO VIP - observes DUT signals
7
+ //
8
+ //////////////////////////////////////////////////////////////////////////////////
9
+
10
+ class lifo_vip_monitor extends uvm_monitor;
11
+ `uvm_component_utils(lifo_vip_monitor)
12
+
13
+ virtual lifo_vip_if vif;
14
+ lifo_vip_config cfg;
15
+ uvm_analysis_port #(lifo_vip_seq_item) ap;
16
+
17
+ function new(string name = "lifo_vip_monitor", uvm_component parent = null);
18
+ super.new(name, parent);
19
+ ap = new("ap", this);
20
+ endfunction
21
+
22
+ function void build_phase(uvm_phase phase);
23
+ super.build_phase(phase);
24
+ if (!uvm_config_db#(virtual lifo_vip_if)::get(this, "", "lifo_vip_vif", vif))
25
+ `uvm_fatal("MONITOR", "No virtual interface")
26
+ if (!uvm_config_db#(lifo_vip_config)::get(this, "", "lifo_vip_cfg", cfg))
27
+ `uvm_fatal("MONITOR", "No config")
28
+ endfunction
29
+
30
+ task run_phase(uvm_phase phase);
31
+ lifo_vip_seq_item item;
32
+
33
+ forever begin
34
+ @(vif.mon_cb);
35
+
36
+ // Detect push operation
37
+ if (vif.mon_cb.wr_en && !vif.mon_cb.rd_en) begin
38
+ item = lifo_vip_seq_item::type_id::create("item");
39
+ item.op = PUSH;
40
+ item.data = vif.mon_cb.data_wr;
41
+ item.full = vif.mon_cb.lifo_full;
42
+ item.success = !vif.mon_cb.lifo_full;
43
+ ap.write(item);
44
+ `uvm_info("MONITOR", $sformatf("Observed PUSH: data=0x%0h full=%0b", item.data, item.full), UVM_HIGH)
45
+ end
46
+
47
+ // Detect pop operation
48
+ else if (vif.mon_cb.rd_en && !vif.mon_cb.wr_en) begin
49
+ @(vif.mon_cb); // Wait one cycle to capture read data
50
+ item = lifo_vip_seq_item::type_id::create("item");
51
+ item.op = POP;
52
+ item.read_data = vif.mon_cb.data_rd;
53
+ item.empty = vif.mon_cb.lifo_empty;
54
+ item.success = !vif.mon_cb.lifo_empty;
55
+ ap.write(item);
56
+ `uvm_info("MONITOR", $sformatf("Observed POP: data=0x%0h empty=%0b", item.read_data, item.empty), UVM_HIGH)
57
+ end
58
+
59
+ // Detect simultaneous push/pop (bypass)
60
+ else if (vif.mon_cb.wr_en && vif.mon_cb.rd_en) begin
61
+ @(vif.mon_cb);
62
+ item = lifo_vip_seq_item::type_id::create("item");
63
+ item.op = PUSH; // Record as push for scoreboard
64
+ item.data = vif.mon_cb.data_wr;
65
+ item.read_data = vif.mon_cb.data_rd; // Bypass data
66
+ item.full = vif.mon_cb.lifo_full;
67
+ item.empty = vif.mon_cb.lifo_empty;
68
+ ap.write(item);
69
+ `uvm_info("MONITOR", $sformatf("Observed BYPASS: wr=0x%0h rd=0x%0h", item.data, item.read_data), UVM_HIGH)
70
+ end
71
+ end
72
+ endtask
73
+
74
+ endclass
Weiyet_RTLStructLib/source/LIFO/vip/uvm/agent/lifo_vip_sequencer.sv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // Create Date: 01/04/2026
4
+ // Module Name: lifo_vip_sequencer
5
+ // Author: https://www.linkedin.com/in/wei-yet-ng-065485119/
6
+ // Description: Sequencer for LIFO VIP - coordinates sequences
7
+ //
8
+ //////////////////////////////////////////////////////////////////////////////////
9
+
10
+ class lifo_vip_sequencer extends uvm_sequencer #(lifo_vip_seq_item);
11
+ `uvm_component_utils(lifo_vip_sequencer)
12
+
13
+ function new(string name = "lifo_vip_sequencer", uvm_component parent = null);
14
+ super.new(name, parent);
15
+ endfunction
16
+
17
+ endclass