Skip to content

Commit ee4f4ab

Browse files
irq_handler: Initial commit (#176)
Signed-off-by: Istvan-Zsolt Szekely <istvan.szekely@analog.com>
1 parent 99a0257 commit ee4f4ab

File tree

67 files changed

+1925
-642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1925
-642
lines changed

library/includes/Makeinclude_common.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
include $(ADI_TB_DIR)/library/includes/Makeinclude_axi.mk
77

88
# All test-bench dependencies except test programs
9+
910
SV_DEPS += $(ADI_TB_DIR)/library/utilities/utils.svh
1011
SV_DEPS += $(ADI_TB_DIR)/library/utilities/logger_pkg.sv
1112
SV_DEPS += $(ADI_TB_DIR)/library/utilities/adi_common_pkg.sv
1213
SV_DEPS += $(ADI_TB_DIR)/library/utilities/adi_vip_pkg.sv
1314
SV_DEPS += $(ADI_TB_DIR)/library/utilities/adi_environment_pkg.sv
1415
SV_DEPS += $(ADI_TB_DIR)/library/utilities/test_harness_env.sv
1516
SV_DEPS += $(ADI_TB_DIR)/library/drivers/common/watchdog.sv
17+
SV_DEPS += $(ADI_TB_DIR)/library/utilities/adi_api_pkg.sv
18+
SV_DEPS += $(ADI_TB_DIR)/library/utilities/irq_handler_pkg.sv
19+
SV_DEPS += $(ADI_TB_DIR)/library/vip/adi/io_vip/io_vip_if_base_pkg.sv
1620

1721
SV_DEPS += system_tb.sv
1822

23+
SIM_LIB_DEPS += io_vip
24+
1925
ENV_DEPS += system_project.tcl
2026
ENV_DEPS += system_bd.tcl
2127
ENV_DEPS += $(ADI_TB_DIR)/scripts/adi_sim.tcl

library/includes/sp_include_common.tcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ adi_sim_project_files [list \
4141
"$ad_tb_dir/library/utilities/logger_pkg.sv" \
4242
"$ad_tb_dir/library/utilities/adi_common_pkg.sv" \
4343
"$ad_tb_dir/library/utilities/adi_vip_pkg.sv" \
44+
"$ad_tb_dir/library/utilities/adi_api_pkg.sv" \
4445
"$ad_tb_dir/library/utilities/adi_environment_pkg.sv" \
4546
"$ad_tb_dir/library/utilities/test_harness_env.sv" \
47+
"$ad_tb_dir/library/utilities/irq_handler_pkg.sv" \
4648
"$ad_tb_dir/library/drivers/common/watchdog.sv" \
49+
"$ad_tb_dir/library/vip/adi/io_vip/io_vip_if_base_pkg.sv" \
4750
"system_tb.sv" \
4851
]

library/utilities/adi_api_pkg.sv

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,27 @@ package adi_api_pkg;
7272
endtask
7373

7474
task axi_read(
75-
input [31:0] addr,
76-
output [31:0] data);
75+
input bit [31:0] addr,
76+
output bit [31:0] data,
77+
input bit priority_packet = 0);
7778

78-
this.bus.RegRead32(this.base_address + addr, data);
79+
this.bus.RegRead32(this.base_address + addr, data, priority_packet);
7980
endtask: axi_read
8081

8182
task axi_write(
82-
input [31:0] addr,
83-
input [31:0] data);
83+
input bit [31:0] addr,
84+
input bit [31:0] data,
85+
input bit priority_packet = 0);
8486

85-
this.bus.RegWrite32(this.base_address + addr, data);
87+
this.bus.RegWrite32(this.base_address + addr, data, priority_packet);
8688
endtask: axi_write
8789

8890
task axi_verify(
89-
input [31:0] addr,
90-
input [31:0] data);
91+
input bit [31:0] addr,
92+
input bit [31:0] data,
93+
input bit priority_packet = 0);
9194

92-
this.bus.RegReadVerify32(this.base_address + addr, data);
95+
this.bus.RegReadVerify32(this.base_address + addr, data, priority_packet);
9396
endtask: axi_verify
9497

9598
endclass: adi_api
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// ***************************************************************************
2+
// ***************************************************************************
3+
// Copyright (C) 2025 Analog Devices, Inc. All rights reserved.
4+
//
5+
// In this HDL repository, there are many different and unique modules, consisting
6+
// of various HDL (Verilog or VHDL) components. The individual modules are
7+
// developed independently, and may be accompanied by separate and unique license
8+
// terms.
9+
//
10+
// The user should read each of these license terms, and understand the
11+
// freedoms and responsabilities that he or she has by using this source/core.
12+
//
13+
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
14+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15+
// A PARTICULAR PURPOSE.
16+
//
17+
// Redistribution and use of source or resulting binaries, with or without modification
18+
// of this file, are permitted under one of the following two license terms:
19+
//
20+
// 1. The GNU General Public License version 2 as published by the
21+
// Free Software Foundation, which can be found in the top level directory
22+
// of this repository (LICENSE_GPL2), and also online at:
23+
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
24+
//
25+
// OR
26+
//
27+
// 2. An ADI specific BSD license, which can be found in the top level directory
28+
// of this repository (LICENSE_ADIBSD), and also on-line at:
29+
// https://github.com/analogdevicesinc/hdl/blob/main/LICENSE_ADIBSD
30+
// This will allow to generate bit files and not release the source code,
31+
// as long as it attaches to an ADI device.
32+
//
33+
// ***************************************************************************
34+
// ***************************************************************************
35+
36+
`include "utils.svh"
37+
38+
package irq_handler_pkg;
39+
40+
import logger_pkg::*;
41+
import adi_common_pkg::*;
42+
import adi_api_pkg::*;
43+
import m_axi_sequencer_pkg::*;
44+
import io_vip_if_base_pkg::*;
45+
46+
class irq_handler_class extends adi_api;
47+
48+
protected io_vip_if_base irq_vip_if;
49+
50+
protected event irq_event_list [31:0];
51+
protected bit [31:0] irq_valid_list;
52+
53+
protected bit software_testing;
54+
55+
// constructor
56+
function new(
57+
input string name,
58+
input m_axi_sequencer_base bus,
59+
input bit [31:0] base_address,
60+
input io_vip_if_base irq_vip_if,
61+
input adi_component parent = null);
62+
63+
super.new(name, bus, base_address, parent);
64+
65+
this.irq_vip_if = irq_vip_if;
66+
this.irq_valid_list = 'h0;
67+
this.software_testing = 1'b0;
68+
endfunction: new
69+
70+
// enable software testing at startup
71+
function void enable_software_testing();
72+
this.software_testing = 1'b1;
73+
endfunction: enable_software_testing
74+
75+
// software IRQ test-phase
76+
task software_irq_testing();
77+
logic [31:0] enable_irq = 'h0;
78+
79+
for (int i=0; i<32; ++i) begin
80+
enable_irq = enable_irq | (this.irq_valid_list[i] << i);
81+
end
82+
this.info($sformatf("Enables: %d", enable_irq), ADI_VERBOSITY_HIGH);
83+
this.axi_write('h00, enable_irq, 1); // software trigger IRQ
84+
85+
// negative edge detection
86+
if (this.irq_vip_if.get_io() == 1'b0) begin
87+
this.irq_vip_if.wait_io_change();
88+
end
89+
this.irq_vip_if.wait_io_change();
90+
endtask: software_irq_testing
91+
92+
// IRQ event handler
93+
task start();
94+
logic [31:0] irq_triggered;
95+
logic [31:0] enable_irq = 'h0;
96+
97+
for (int i=0; i<32; ++i) begin
98+
enable_irq = enable_irq | (this.irq_valid_list[i] << i);
99+
end
100+
101+
this.axi_write('h10, enable_irq, 1); // enable all IRQ handles
102+
this.axi_write('h1C, 'b01, 1); // enable IRQ controller / software interrupt disabled
103+
104+
fork forever begin
105+
if (this.irq_vip_if.get_io() == 1'b0) begin
106+
this.irq_vip_if.wait_io_change();
107+
end
108+
109+
this.info($sformatf("IRQ controller triggered"), ADI_VERBOSITY_HIGH);
110+
111+
this.axi_read('h04, irq_triggered, 1); // check pending IRQ (status + enable)
112+
113+
for (int i=0; i<32; ++i) begin
114+
if (irq_triggered[i]) begin
115+
if (this.irq_valid_list[i] == 1'b0) begin
116+
this.fatal($sformatf("IRQ triggered on a non-registered device!"));
117+
end
118+
->this.irq_event_list[i];
119+
@(this.irq_event_list[i]);
120+
this.axi_write('h0C, 'h1 << i, 1); // acknowledge IRQ
121+
end
122+
end
123+
end join_none
124+
125+
if (this.software_testing) begin
126+
this.software_irq_testing();
127+
end
128+
129+
this.axi_write('h1C, 'b11, 1); // enable IRQ controller + software interrupt enabled
130+
endtask: start
131+
132+
// register IRQ device
133+
function event register_device(input int position);
134+
if (this.irq_valid_list[position]) begin
135+
this.fatal($sformatf("An interrupt handler is already assigned to position %0d!", position));
136+
end
137+
this.irq_valid_list[position] = 1'b1;
138+
return this.irq_event_list[position];
139+
endfunction: register_device
140+
141+
endclass: irq_handler_class
142+
143+
endpackage: irq_handler_pkg

library/utilities/test_harness_env.sv

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ package test_harness_env_pkg;
4242
import adi_environment_pkg::*;
4343
import adi_axi_agent_pkg::*;
4444
import watchdog_pkg::*;
45+
import irq_handler_pkg::*;
46+
import io_vip_if_base_pkg::*;
47+
import vip_agent_typedef_pkg::*;
4548

46-
47-
class test_harness_env #(`AXI_VIP_PARAM_DECL(mng), `AXI_VIP_PARAM_DECL(ddr)) extends adi_environment;
49+
class test_harness_env extends adi_environment;
4850

4951
// Agents
50-
adi_axi_master_agent #(`AXI_VIP_PARAM_ORDER(mng)) mng;
51-
adi_axi_slave_mem_agent #(`AXI_VIP_PARAM_ORDER(ddr)) ddr;
52+
adi_axi_agent_base mng;
53+
adi_axi_agent_base ddr;
54+
55+
irq_handler_class irq_handler;
5256

5357
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(10)) sys_clk_vip_if;
5458
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(5)) dma_clk_vip_if;
@@ -58,22 +62,23 @@ package test_harness_env_pkg;
5862

5963
watchdog simulation_watchdog;
6064

65+
local bit [31:0] irq_base_address;
66+
local io_vip_if_base irq_vip_if;
67+
6168
//============================================================================
6269
// Constructor
6370
//============================================================================
6471
function new(
6572
input string name,
73+
input virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(10)) sys_clk_vip_if,
74+
input virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(5)) dma_clk_vip_if,
75+
input virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(2.5)) ddr_clk_vip_if,
76+
input virtual interface rst_vip_if #(.C_ASYNCHRONOUS(1), .C_RST_POLARITY(1)) sys_rst_vip_if,
77+
input bit [31:0] irq_base_address,
78+
input io_vip_if_base irq_vip_if,
79+
input adi_environment parent = null);
6680

67-
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(10)) sys_clk_vip_if,
68-
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(5)) dma_clk_vip_if,
69-
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(2.5)) ddr_clk_vip_if,
70-
71-
virtual interface rst_vip_if #(.C_ASYNCHRONOUS(1), .C_RST_POLARITY(1)) sys_rst_vip_if,
72-
73-
virtual interface axi_vip_if #(`AXI_VIP_IF_PARAMS(mng)) mng_vip_if,
74-
virtual interface axi_vip_if #(`AXI_VIP_IF_PARAMS(ddr)) ddr_vip_if);
75-
76-
super.new(name);
81+
super.new(name, parent);
7782

7883
this.simulation_watchdog = new("Simulation watchdog", 10**6, "Simulation might be hanging!");
7984

@@ -82,9 +87,12 @@ package test_harness_env_pkg;
8287
this.ddr_clk_vip_if = ddr_clk_vip_if;
8388
this.sys_rst_vip_if = sys_rst_vip_if;
8489

90+
this.irq_base_address = irq_base_address;
91+
this.irq_vip_if = irq_vip_if;
92+
8593
// Creating the agents
86-
this.mng = new("AXI Manager agent", mng_vip_if, this);
87-
this.ddr = new("AXI DDR stub agent", ddr_vip_if, this);
94+
this.mng = new("AXI Manager agent", MASTER, this);
95+
this.ddr = new("AXI DDR stub agent", SLAVE, this);
8896
endfunction
8997

9098
//============================================================================
@@ -93,14 +101,16 @@ package test_harness_env_pkg;
93101
// - Start the agents
94102
//============================================================================
95103
task start();
96-
this.simulation_watchdog.start();
104+
this.irq_handler = new("IRQ handler", this.mng.master_sequencer, this.irq_base_address, this.irq_vip_if, this);
97105

98-
this.mng.start_master();
99-
this.ddr.start_slave();
106+
this.simulation_watchdog.start();
100107

101108
this.sys_clk_vip_if.start_clock();
102109
this.dma_clk_vip_if.start_clock();
103110
this.ddr_clk_vip_if.start_clock();
111+
112+
this.mng.start_master();
113+
this.ddr.start_slave();
104114
endtask
105115

106116
//============================================================================

library/utilities/test_harness_system_bd.tcl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ ad_ip_instance axi_intc axi_intc [list \
4949
C_HAS_FAST 0 \
5050
]
5151

52+
# create IRQ VIP
53+
ad_ip_instance io_vip irq_vip [ list \
54+
ASYNC {true} \
55+
MODE {0} \
56+
]
57+
adi_sim_add_define "IRQ=irq_vip"
58+
5259
ad_ip_instance xlconcat sys_concat_intc
5360
ad_ip_parameter sys_concat_intc CONFIG.NUM_PORTS 16
5461

@@ -63,7 +70,6 @@ ad_ip_instance clk_vip sys_clk_vip [ list \
6370
]
6471
adi_sim_add_define "SYS_CLK=sys_clk_vip"
6572

66-
6773
# DMA clock
6874
ad_ip_instance clk_vip dma_clk_vip [ list \
6975
INTERFACE_MODE {MASTER} \
@@ -160,7 +166,9 @@ ad_connect sys_concat_intc/In15 GND
160166

161167
# interconnect - processor
162168

163-
ad_cpu_interconnect 0x41200000 axi_intc
169+
set IRQ_C_BASE 0x41200000
170+
ad_cpu_interconnect $IRQ_C_BASE axi_intc
171+
adi_sim_add_define "IRQ_C_BA=[format "%d" ${IRQ_C_BASE}]"
164172

165173
# interconnect - memory
166174

@@ -189,10 +197,8 @@ incr sys_cpu_interconnect_index
189197
global sys_mem_interconnect_index
190198
incr sys_mem_interconnect_index
191199

192-
# create external port for IRQ
193-
create_bd_port -dir O -type intr irq
194-
195-
ad_connect irq axi_intc/irq
200+
# connect the IRQ controller to the IRQ VIP
201+
ad_connect axi_intc/irq irq_vip/i
196202

197203
# Set DDR VIP to a range of 2G
198204
set DDR_BASE 0x80000000

library/vip/adi/io_vip/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
####################################################################################
2-
## Copyright (C) 2018-2024 Analog Devices, Inc.
2+
## Copyright (C) 2018-2025 Analog Devices, Inc.
33
## Auto-generated, do not modify!
44
####################################################################################
55

@@ -9,9 +9,10 @@ include ../../../../scripts/make_tb_path.mk
99
LIBRARY_NAME := io_vip
1010

1111
GENERIC_DEPS += io_vip.sv
12+
GENERIC_DEPS += io_vip_top.v
1213
GENERIC_DEPS += io_vip_if.sv
14+
GENERIC_DEPS += io_vip_if_base_pkg.sv
1315

1416
XILINX_DEPS += io_vip_ip.tcl
15-
XILINX_DEPS += io_vip_pkg.ttcl
1617

1718
include $(ADI_HDL_DIR)/library//scripts/library.mk

0 commit comments

Comments
 (0)