Skip to content

Commit 0d47ee6

Browse files
committed
Created initial apb_agent with completer mode support
0 parents  commit 0d47ee6

13 files changed

Lines changed: 950 additions & 0 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Log Files
2+
*.log
3+
4+
# Tooling directories
5+
.dvt/*
6+
7+

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# APB Agent
2+
3+
A UVM Agent for the AMBA APB Protocol
4+
5+
## Usage
6+
7+
```SystemVerilog
8+
9+
class user_env extends uvm_env;
10+
11+
endclass : user env
12+
13+
```

apb_agent.f

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-incdir ./src
2+
-incdir ./include
3+
4+
./src/apb_agent_pkg.sv
5+
./src/interfaces/apb_vip_if.sv

include/apb_agent_macros.svh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/************************************************************************************
2+
* A full-featured APB 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+
`ifndef __APB_AGENT_MACROS__SVH__
20+
`define __APB_AGENT_MACROS__SVH__
21+
22+
`define _APB_AGENT_PARAM_DEFS \
23+
parameter int ADDR_WIDTH = 32, \
24+
parameter int DATA_WIDTH = 32
25+
26+
`define _APB_AGENT_PARAM_MAP \
27+
.ADDR_WIDTH(ADDR_WIDTH), \
28+
.DATA_WIDTH(DATA_WIDTH)
29+
30+
`define APB_IF_INST(ADDR, DATA, HBURST, HPROT, HMASTER, IF_NAME=APB, CLK_NAME=hclk, RST_NAME=hresetn) \
31+
apb_vip_if #( \
32+
`_APB_AGENT_PARAM_MAP \
33+
) IF_NAME ( \
34+
.pclk(CLK_NAME), \
35+
.preset_n(RST_NAME) \
36+
); \
37+
initial begin \
38+
uvm_config_db#( \
39+
virtual apb_vip_if #( \
40+
`_APB_AGENT_PARAM_MAP \
41+
) \
42+
)::set(null, "*", "m_vif", IF_NAME); \
43+
end
44+
45+
`endif // __APB_AGENT_MACROS__SVH__

src/agent/apb_agent.svh

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/************************************************************************************
2+
* A full-featured APB 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: apb_agent_pkg.apb_agent
20+
class apb_agent #(
21+
`_APB_AGENT_PARAM_DEFS
22+
) extends uvm_agent;
23+
`uvm_component_param_utils(apb_agent#(`_APB_AGENT_PARAM_MAP))
24+
`uvm_type_name_decl("apb_agent")
25+
26+
// Group: Class Properties
27+
////////////////////////////////////////////////////////////////////////////////////////////////
28+
29+
// Reference: m_cfg
30+
// The agent config for this APB Agent
31+
apb_agent_config m_cfg;
32+
33+
// Reference: ap
34+
// Analysis Port for APB Transactions. Internal reference to monitor AP
35+
uvm_analysis_port #(apb_transaction#(`_APB_AGENT_PARAM_MAP)) ap;
36+
37+
// Property: m_monitor
38+
// The UVM Monitor for the APB Agent
39+
apb_monitor#(`_APB_AGENT_PARAM_MAP) m_monitor;
40+
41+
// Property: m_sequencer
42+
// The UVM Sequencer for the APB Agent
43+
uvm_sequencer#(apb_transaction#(`_APB_AGENT_PARAM_MAP)) m_sequencer;
44+
45+
// Property: m_driver
46+
// The UVM Driver for the APB Agent
47+
apb_driver#(`_APB_AGENT_PARAM_MAP) m_driver;
48+
49+
// Property: m_cov
50+
// The UVM Coverage Collector for the APB Agent
51+
apb_cov#(`_APB_AGENT_PARAM_MAP) m_cov;
52+
53+
// Group: Constructors
54+
////////////////////////////////////////////////////////////////////////////////////////////////
55+
56+
// Constructor: new
57+
function new(string name = "apb_agent", uvm_component parent = null);
58+
super.new(name, parent);
59+
endfunction : new
60+
61+
// Group: UVM Build Phases
62+
////////////////////////////////////////////////////////////////////////////////////////////////
63+
64+
// Function: build_phase
65+
// The build_phase for the APB Agent.
66+
//
67+
// This phase performs the following
68+
// - Get the configuration object if not set
69+
// - Check the parameters fall within the APB Spec
70+
// - Build the monitor
71+
// - Build the driver and sequencer if active
72+
// - Build the coverage collector if enabled in the config
73+
virtual function void build_phase(uvm_phase phase);
74+
super.build_phase(phase);
75+
76+
if (m_cfg == null) begin
77+
if (!uvm_config_db#(apb_agent_config)::get(this, "", "m_cfg", m_cfg)) begin
78+
`uvm_fatal(
79+
get_type_name(),
80+
"Cannot get() configuration 'm_cfg' from uvm_config_db. Did you set() it?"
81+
)
82+
end
83+
end
84+
85+
check_params();
86+
87+
// Instantiate the Monitor (always present)
88+
m_monitor = apb_monitor#(`_APB_AGENT_PARAM_MAP)::type_id::create("m_monitor", this);
89+
m_monitor.m_cfg = m_cfg;
90+
91+
ap = new("ap", this);
92+
93+
// Build the driver and sequencer if active
94+
if (m_cfg.is_active == UVM_ACTIVE) begin
95+
m_driver = apb_driver#(`_APB_AGENT_PARAM_MAP)::type_id::create("m_driver", this);
96+
m_driver.m_cfg = m_cfg;
97+
98+
m_sequencer = uvm_sequencer#(apb_transaction#(`_APB_AGENT_PARAM_MAP))::
99+
type_id::create("m_sequencer", this);
100+
end
101+
102+
// Build the coverage if there is functional coverage
103+
if (m_cfg.has_functional_coverage) begin
104+
m_cov = apb_cov#(`_APB_AGENT_PARAM_MAP)::type_id::create("m_cov", this);
105+
m_cov.m_cfg = m_cfg;
106+
end
107+
108+
endfunction : build_phase
109+
110+
// Function: connect_phase
111+
// The connect_phase for the APB Agent.
112+
//
113+
// This phase performs the following
114+
// - Connect the monitor to the agent AP
115+
// - Connect the driver and sequencer if the agent is active
116+
// - Connect the monitor and coverage collector if there is functional coverage
117+
virtual function void connect_phase(uvm_phase phase);
118+
super.connect_phase(phase);
119+
120+
// Connect the analysis port of the monitor
121+
ap = m_monitor.ap;
122+
123+
// Connect driver and sequencer if the agent is active
124+
if (m_cfg.is_active == UVM_ACTIVE) begin
125+
m_driver.seq_item_port.connect(m_sequencer.seq_item_export);
126+
end
127+
128+
// Connect the coverage collector if there is functional coverage
129+
if (m_cfg.has_functional_coverage) begin
130+
m_monitor.ap.connect(m_cov.analysis_export);
131+
end
132+
endfunction : connect_phase
133+
134+
// Function: check_params
135+
// A function which checks that the params fall within the limits perscribed by the spec
136+
virtual function void check_params();
137+
if (m_cfg.no_parameter_check)
138+
return;
139+
140+
if (ADDR_WIDTH > 32) begin
141+
`uvm_error(
142+
get_type_name(),
143+
$sformatf(
144+
"ADDR_WIDTH is set to %0d. APB Spec requires ADDR_WDITH be <= 32. (Section 2.1)",
145+
ADDR_WIDTH
146+
)
147+
)
148+
end
149+
150+
if (!DATA_WIDTH inside {8, 16, 32}) begin
151+
`uvm_error(
152+
get_type_name(),
153+
$sformatf(
154+
"DATA_WIDTH is set to %0d. APB Spec requires DATA_WIDTH be 8, 16, or 32. (Section 2.1)",
155+
DATA_WIDTH
156+
)
157+
)
158+
end
159+
160+
endfunction : check_params
161+
162+
endclass : apb_agent

src/agent/apb_agent_config.svh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/************************************************************************************
2+
* A full-featured APB 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: apb_agent_pkg.apb_agent_config
20+
class apb_agent_config extends uvm_object;
21+
`uvm_object_utils(apb_agent_config)
22+
23+
// Group: Class Properties
24+
////////////////////////////////////////////////////////////////////////////////////////////////
25+
26+
// Property: is_active
27+
// Determine whether the agent is passive or active
28+
uvm_active_passive_enum is_active = UVM_ACTIVE;
29+
30+
// Property: has_functional_coverage
31+
// Determine if the agent has functional coverage
32+
bit has_functional_coverage = 1'b1;
33+
34+
// Property: no_parameter_check
35+
// Determine whether the agent should produce errors when the parameters are set incorrectly
36+
bit no_parameter_check = 1'b0;
37+
38+
// Property: agent_mode
39+
// The mode the agent operates in.
40+
apb_agent_mode_e agent_mode = APB_COMPLETER_AGENT;
41+
42+
// Reference: vif_handle
43+
// The uvm_config_db 'field_name' handle to the virtual interface
44+
string vif_handle="m_vif";
45+
46+
// Group: Constructors
47+
////////////////////////////////////////////////////////////////////////////////////////////////
48+
49+
// Constructor: new
50+
function new(string name = "apb_agent_config");
51+
super.new(name);
52+
endfunction : new
53+
54+
endclass : apb_agent_config

src/agent/apb_cov.svh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/************************************************************************************
2+
* A full-featured APB 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: apb_agent_pkg.apb_cov
20+
// The coverage collector for the APB UVM Agent
21+
class apb_cov#(`_APB_AGENT_PARAM_DEFS) extends uvm_subscriber#(apb_transaction#(`_APB_AGENT_PARAM_MAP));
22+
`uvm_component_param_utils(apb_cov#(`_APB_AGENT_PARAM_MAP))
23+
`uvm_type_name_decl("apb_cov")
24+
25+
// Group: Class Properties
26+
////////////////////////////////////////////////////////////////////////////////////////////////
27+
28+
// Property: pkt
29+
// The apb_transaction packet which is transmitted
30+
apb_transaction#(`_APB_AGENT_PARAM_MAP) pkt;
31+
32+
// Reference: m_cfg
33+
// The agent config for this APB Agent
34+
apb_agent_config m_cfg;
35+
36+
// Group: Covergroups
37+
////////////////////////////////////////////////////////////////////////////////////////////////
38+
39+
// Covergroup: apb_cg
40+
// The functional cover group
41+
covergroup apb_cg(string name = "apb_cg");
42+
option.name = name;
43+
option.per_instance = 1;
44+
endgroup
45+
46+
// Group: Constructor
47+
////////////////////////////////////////////////////////////////////////////////////////////////
48+
49+
// Constructor: new
50+
function new(string name="apb_cov", uvm_component parent=null);
51+
super.new(name, parent);
52+
endfunction : new
53+
54+
// Group: UVM Build Phases
55+
////////////////////////////////////////////////////////////////////////////////////////////////
56+
57+
// Function: build_phase
58+
// The build_phase for apb_cov
59+
//
60+
// Performs the following
61+
// - Fetches teh config if it isn't set
62+
virtual function void build_phase(uvm_phase phase);
63+
super.build_phase(phase);
64+
65+
if (m_cfg == null) begin
66+
if (!uvm_config_db#(apb_agent_config)::get(this, "", "m_cfg", m_cfg)) begin
67+
`uvm_fatal(
68+
get_type_name(),
69+
"Cannot get() configuration 'm_cfg' from uvm_config_db. Did you set() it?"
70+
)
71+
end
72+
end
73+
endfunction : build_phase
74+
75+
// Group: UVM Run Phases
76+
////////////////////////////////////////////////////////////////////////////////////////////////
77+
78+
// Group: UVM Subscriber Methods
79+
////////////////////////////////////////////////////////////////////////////////////////////////
80+
81+
virtual function void write (apb_transaction#(`_APB_AGENT_PARAM_MAP) t);
82+
pkt = t;
83+
84+
apb_cg.sample();
85+
endfunction
86+
endclass : apb_cov

0 commit comments

Comments
 (0)