Skip to content

Commit 7a06098

Browse files
committed
Added requester agent mode
1 parent b8756bf commit 7a06098

14 files changed

Lines changed: 585 additions & 3 deletions

example/ahb_tb_example.f

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-incdir .
2+
3+
-F ../ahb_agent.f
4+
5+
ahb_tb_example_pkg.sv
6+
tb.sv

example/ahb_tb_example_pkg.sv

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/************************************************************************************
2+
* A full-featured AHB UVM Agent
3+
* Copyright (C) 2025 RISCY-Lib Contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
************************************************************************************/
18+
19+
package ahb_tb_example_pkg;
20+
21+
import uvm_pkg::*;
22+
`include "uvm_macros.svh"
23+
24+
import ahb_agent_pkg::*;
25+
26+
`include "uvm_src/ahb_env_example.svh"
27+
`include "uvm_src/ahb_seq.svh"
28+
`include "uvm_src/ahb_test.svh"
29+
30+
endpackage

example/tb.sv

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/************************************************************************************
2+
* A full-featured AHB UVM Agent
3+
* Copyright (C) 2025 RISCY-Lib Contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
************************************************************************************/
18+
19+
module tb();
20+
import uvm_pkg::*;
21+
`include "uvm_macros.svh"
22+
23+
import ahb_tb_example_pkg::*;
24+
25+
logic hclk;
26+
logic hresetn;
27+
28+
`AHB_IF_INST(32, 32, 0, 4, 0, AHB, hclk, hresetn)
29+
30+
initial begin
31+
hclk = 1'b0;
32+
forever begin
33+
#10ns;
34+
hclk = ~hclk;
35+
end
36+
end
37+
38+
initial begin
39+
hresetn = 1'b0;
40+
41+
repeat(3) begin
42+
@(posedge hclk);
43+
end
44+
45+
hresetn = 1'b1;
46+
end
47+
48+
initial begin
49+
run_test();
50+
end
51+
endmodule : tb
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/************************************************************************************
2+
* A full-featured AHB UVM Agent
3+
* Copyright (C) 2025 RISCY-Lib Contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
************************************************************************************/
18+
19+
class ahb_env_example extends uvm_env;
20+
`uvm_component_utils(ahb_env_example)
21+
22+
typedef ahb_agent#(
23+
.DATA_WIDTH(32),
24+
.ADDR_WIDTH(32),
25+
.HBURST_WIDTH(0),
26+
.HPROT_WIDTH(4),
27+
.HMASTER_WIDTH
28+
) example_agent;
29+
30+
// Group: Class Properties
31+
////////////////////////////////////////////////////////////////////////////////////////////////
32+
33+
example_agent completer_agent;
34+
example_agent requester_agent;
35+
36+
// Group: Constructor
37+
////////////////////////////////////////////////////////////////////////////////////////////////
38+
39+
// Constructor: new
40+
function new(string name="ahb_env_example", uvm_component parent=null);
41+
super.new(name, parent);
42+
endfunction : new
43+
44+
virtual function void build_phase(uvm_phase phase);
45+
super.build_phase(phase);
46+
47+
completer_agent = example_agent::type_id::create("completer_agent", this);
48+
completer_agent.m_cfg = ahb_agent_config::type_id::create("completer_cfg");
49+
completer_agent.m_cfg.agent_mode = AHB_COMPLETER_AGENT;
50+
completer_agent.m_cfg.is_active = UVM_ACTIVE;
51+
52+
requester_agent = example_agent::type_id::create("requester_agent", this);
53+
requester_agent.m_cfg = ahb_agent_config::type_id::create("completer_cfg");
54+
requester_agent.m_cfg.agent_mode = AHB_REQUESTER_AGENT;
55+
requester_agent.m_cfg.is_active = UVM_ACTIVE;
56+
57+
endfunction : build_phase
58+
59+
endclass : ahb_env_example

example/uvm_src/ahb_seq.svh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/************************************************************************************
2+
* A full-featured AHB UVM Agent
3+
* Copyright (C) 2025 RISCY-Lib Contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
************************************************************************************/
18+
19+
// Class: ahb_tb_example_pkg.ahb_seq
20+
class ahb_seq extends uvm_sequence#(
21+
ahb_transaction#(
22+
.DATA_WIDTH(32),
23+
.ADDR_WIDTH(32),
24+
.HBURST_WIDTH(0),
25+
.HPROT_WIDTH(4),
26+
.HMASTER_WIDTH(0)
27+
)
28+
);
29+
`uvm_object_utils(ahb_seq)
30+
31+
logic[31:0] addr_q[$];
32+
33+
function new(string name="ahb_seq");
34+
super.new(name);
35+
endfunction : new
36+
37+
virtual task body();
38+
repeat(10) begin
39+
ahb_transaction#(.DATA_WIDTH(32), .ADDR_WIDTH(32)) trans;
40+
41+
trans = ahb_transaction#(.DATA_WIDTH(32), .ADDR_WIDTH(32))::type_id::create("trans");
42+
43+
start_item(trans);
44+
trans.rand_type = AHB_SUBORDINATE_AGENT;
45+
void'(trans.randomize());
46+
`uvm_info(get_type_name(), $sformatf("Sending Transaction: %s", trans.sprint()), UVM_LOW)
47+
if (trans.write == AHB_WRITE)
48+
addr_q.push_back(trans.addr);
49+
finish_item(trans);
50+
end
51+
52+
while(addr_q.size() > 0) begin
53+
ahb_transaction#(.DATA_WIDTH(32), .ADDR_WIDTH(32)) trans;
54+
55+
trans = ahb_transaction#(.DATA_WIDTH(32), .ADDR_WIDTH(32))::type_id::create("trans");
56+
57+
start_item(trans);
58+
trans.rand_type = AHB_SUBORDINATE_AGENT;
59+
trans.addr = addr_q.pop_front();
60+
trans.write = AHB_READ;
61+
`uvm_info(get_type_name(), $sformatf("Sending Transaction: %s", trans.sprint()), UVM_LOW)
62+
finish_item(trans);
63+
end
64+
endtask : body
65+
endclass : ahb_seq

example/uvm_src/ahb_test.svh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/************************************************************************************
2+
* A full-featured AHB UVM Agent
3+
* Copyright (C) 2025 RISCY-Lib Contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
************************************************************************************/
18+
19+
class ahb_test extends uvm_test;
20+
`uvm_component_utils(ahb_test)
21+
22+
ahb_env_example m_env;
23+
ahb_requester_no_wait_states_seq#(.ADDR_WIDTH(32), .DATA_WIDTH(32)) requester_seq;
24+
ahb_seq completer_seq;
25+
26+
function new(string name="ahb_test", uvm_component parent=null);
27+
super.new(name, parent);
28+
endfunction : new
29+
30+
virtual function void build_phase(uvm_phase phase);
31+
super.build_phase(phase);
32+
33+
m_env = ahb_env_example::type_id::create("m_env", this);
34+
endfunction : build_phase
35+
36+
virtual task reset_phase(uvm_phase phase);
37+
phase.raise_objection(this);
38+
39+
#100ns;
40+
41+
phase.drop_objection(this);
42+
endtask : reset_phase
43+
44+
virtual task main_phase(uvm_phase phase);
45+
phase.raise_objection(this);
46+
47+
fork
48+
begin
49+
requester_seq = ahb_requester_no_wait_states_seq#(.ADDR_WIDTH(32), .DATA_WIDTH(32))::type_id::create("requester_seq");
50+
requester_seq.start(m_env.requester_agent.m_sequencer);
51+
end
52+
join_none
53+
54+
completer_seq = ahb_seq::type_id::create("completer_seq");
55+
completer_seq.start(m_env.completer_agent.m_sequencer);
56+
57+
phase.drop_objection(this);
58+
endtask : main_phase
59+
endclass : ahb_test

src/agent/ahb_driver.svh

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class ahb_driver#(`_AHB_AGENT_PARAM_DEFS) extends uvm_driver#(ahb_transaction#(`
8787
if (m_cfg.agent_mode == AHB_SUBORDINATE_AGENT) begin
8888
subordinate_run_phase(phase);
8989
end
90-
// else if (m_cfg.agent_mode == AHB_MANAGER_AGENT) begin
91-
// manager_run_phase(phase);
92-
// end
90+
else if (m_cfg.agent_mode == AHB_MANAGER_AGENT) begin
91+
manager_run_phase(phase);
92+
end
9393
else begin
9494
`uvm_error(
9595
get_type_name(),
@@ -205,7 +205,41 @@ class ahb_driver#(`_AHB_AGENT_PARAM_DEFS) extends uvm_driver#(ahb_transaction#(`
205205
// Task: manager_run_phase
206206
// The UVM Run-Phase for a manager agent
207207
virtual task manager_run_phase(uvm_phase phase);
208+
ahb_transaction#(`_AHB_AGENT_PARAM_MAP) trans;
209+
int wait_states;
210+
211+
fork
212+
forever begin
213+
m_vif.hready = m_vif.hreadyout;
214+
@(m_vif.hreadyout);
215+
end
216+
join_none
208217

218+
m_vif.hrdata = '0;
219+
m_vif.hreadyout = 1'b1;
220+
m_vif.hresp = 1'b0;
221+
m_vif.hexokay = 1'b1;
222+
223+
forever begin
224+
m_vif.hreadyout = 1'b1;
225+
226+
seq_item_port.get_next_item(trans);
227+
m_vif.hreadyout = 1'b0;
228+
229+
repeat(trans.wait_states) begin
230+
@(posedge m_vif.hclk);
231+
end
232+
233+
if (trans.write == AHB_READ) begin
234+
m_vif.hrdata = trans.data;
235+
end
236+
237+
m_vif.hreadyout = 1'b1;
238+
m_vif.hresp = trans.error;
239+
240+
@(posedge m_vif.hclk);
241+
seq_item_port.item_done();
242+
end
209243
endtask : manager_run_phase
210244

211245
endclass

src/agent/ahb_monitor.svh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class ahb_monitor#(`_AHB_AGENT_PARAM_DEFS) extends uvm_monitor;
3333
// The analysis port which this monitor uses to export to
3434
uvm_analysis_port #(ahb_transaction#(`_AHB_AGENT_PARAM_MAP)) ap;
3535

36+
// Property: req_ap
37+
// The analysis port which sends request transactions to be used by reactive agent sequences
38+
uvm_analysis_port #(ahb_transaction#(`_AHB_AGENT_PARAM_MAP)) req_ap;
39+
3640
// Reference: m_cfg
3741
// The agent config for this AHB agent
3842
ahb_agent_config m_cfg;
@@ -134,6 +138,14 @@ class ahb_monitor#(`_AHB_AGENT_PARAM_DEFS) extends uvm_monitor;
134138
break;
135139
end
136140
end
141+
142+
if (m_cfg.agent_mode == AHB_MANAGER_AGENT) begin
143+
ahb_transaction#(`_AHB_AGENT_PARAM_MAP) req;
144+
145+
req = trans.clone();
146+
req.data = m_vifg.hwdata;
147+
req_ap.write(req);
148+
end
137149
end
138150
end
139151
else begin

0 commit comments

Comments
 (0)