1 |
5 |
sergeykhbr |
-----------------------------------------------------------------------------
|
2 |
|
|
--! @file
|
3 |
|
|
--! @copyright Copyright 2017 GNSS Sensor Ltd. All right reserved.
|
4 |
|
|
--! @author Sergey Khabarov - sergeykhbr@gmail.com
|
5 |
|
|
--! @brief Interrupt controller with the AXI4 interface
|
6 |
|
|
--! @details This module generates interrupt via dedicated CPU
|
7 |
|
|
--! line 'ext_interrupt'.
|
8 |
|
|
-----------------------------------------------------------------------------
|
9 |
|
|
|
10 |
|
|
library ieee;
|
11 |
|
|
use ieee.std_logic_1164.all;
|
12 |
|
|
use ieee.numeric_std.all;
|
13 |
|
|
library commonlib;
|
14 |
|
|
use commonlib.types_common.all;
|
15 |
|
|
--! AMBA system bus specific library.
|
16 |
|
|
library ambalib;
|
17 |
|
|
--! AXI4 configuration constants.
|
18 |
|
|
use ambalib.types_amba4.all;
|
19 |
|
|
library misclib;
|
20 |
|
|
use misclib.types_misc.all;
|
21 |
|
|
|
22 |
|
|
entity nasti_irqctrl is
|
23 |
|
|
generic (
|
24 |
|
|
xaddr : integer := 0;
|
25 |
|
|
xmask : integer := 16#fffff#
|
26 |
|
|
);
|
27 |
|
|
port
|
28 |
|
|
(
|
29 |
|
|
clk : in std_logic;
|
30 |
|
|
nrst : in std_logic;
|
31 |
|
|
i_irqs : in std_logic_vector(CFG_IRQ_TOTAL-1 downto 1);
|
32 |
|
|
o_cfg : out nasti_slave_config_type;
|
33 |
|
|
i_axi : in nasti_slave_in_type;
|
34 |
|
|
o_axi : out nasti_slave_out_type;
|
35 |
|
|
o_irq_meip : out std_logic
|
36 |
|
|
);
|
37 |
|
|
end;
|
38 |
|
|
|
39 |
|
|
architecture nasti_irqctrl_rtl of nasti_irqctrl is
|
40 |
|
|
|
41 |
|
|
constant xconfig : nasti_slave_config_type := (
|
42 |
|
|
descrtype => PNP_CFG_TYPE_SLAVE,
|
43 |
|
|
descrsize => PNP_CFG_SLAVE_DESCR_BYTES,
|
44 |
|
|
irq_idx => 0,
|
45 |
|
|
xaddr => conv_std_logic_vector(xaddr, CFG_NASTI_CFG_ADDR_BITS),
|
46 |
|
|
xmask => conv_std_logic_vector(xmask, CFG_NASTI_CFG_ADDR_BITS),
|
47 |
|
|
vid => VENDOR_GNSSSENSOR,
|
48 |
|
|
did => GNSSSENSOR_IRQCTRL
|
49 |
|
|
);
|
50 |
|
|
|
51 |
|
|
type local_addr_array_type is array (0 to CFG_WORDS_ON_BUS-1)
|
52 |
|
|
of integer;
|
53 |
|
|
|
54 |
|
|
constant IRQ_ZERO : std_logic_vector(CFG_IRQ_TOTAL-1 downto 1) := (others => '0');
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
type registers is record
|
58 |
|
|
bank_axi : nasti_slave_bank_type;
|
59 |
|
|
|
60 |
|
|
--! interrupt signal delay signal to detect interrupt positive edge
|
61 |
|
|
irqs_z : std_logic_vector(CFG_IRQ_TOTAL-1 downto 1);
|
62 |
|
|
irqs_zz : std_logic_vector(CFG_IRQ_TOTAL-1 downto 1);
|
63 |
|
|
|
64 |
|
|
--! mask irq disabled: 1=disabled; 0=enabled
|
65 |
|
|
irqs_mask : std_logic_vector(CFG_IRQ_TOTAL-1 downto 1);
|
66 |
|
|
--! irq pending bit mask
|
67 |
|
|
irqs_pending : std_logic_vector(CFG_IRQ_TOTAL-1 downto 1);
|
68 |
|
|
--! interrupt handler address initialized by FW:
|
69 |
|
|
isr_table : std_logic_vector(63 downto 0);
|
70 |
|
|
--! hold-on generation of interrupt.
|
71 |
|
|
irq_lock : std_logic;
|
72 |
|
|
--! delayed interrupt
|
73 |
|
|
irq_wait_unlock : std_logic_vector(CFG_IRQ_TOTAL-1 downto 1);
|
74 |
|
|
irq_cause_idx : std_logic_vector(31 downto 0);
|
75 |
|
|
--! Function trap_entry copies the values of CSRs into these two regs:
|
76 |
|
|
dbg_cause : std_logic_vector(63 downto 0);
|
77 |
|
|
dbg_epc : std_logic_vector(63 downto 0);
|
78 |
|
|
end record;
|
79 |
|
|
|
80 |
|
|
signal r, rin: registers;
|
81 |
|
|
begin
|
82 |
|
|
|
83 |
|
|
comblogic : process(nrst, i_irqs, i_axi, r)
|
84 |
|
|
variable v : registers;
|
85 |
|
|
variable raddr_reg : local_addr_array_type;
|
86 |
|
|
variable waddr_reg : local_addr_array_type;
|
87 |
|
|
variable rdata : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
|
88 |
|
|
variable tmp : std_logic_vector(31 downto 0);
|
89 |
|
|
variable wstrb : std_logic_vector(CFG_ALIGN_BYTES-1 downto 0);
|
90 |
|
|
|
91 |
|
|
variable w_generate_ipi : std_logic;
|
92 |
|
|
begin
|
93 |
|
|
v := r;
|
94 |
|
|
w_generate_ipi := '0';
|
95 |
|
|
|
96 |
|
|
procedureAxi4(i_axi, xconfig, r.bank_axi, v.bank_axi);
|
97 |
|
|
|
98 |
|
|
for n in 0 to CFG_WORDS_ON_BUS-1 loop
|
99 |
|
|
raddr_reg(n) := conv_integer(r.bank_axi.raddr(n)(11 downto 2));
|
100 |
|
|
tmp := (others => '0');
|
101 |
|
|
case raddr_reg(n) is
|
102 |
|
|
when 0 => tmp(CFG_IRQ_TOTAL-1 downto 1) := r.irqs_mask; --! [RW]: 1=irq disable; 0=enable
|
103 |
|
|
when 1 => tmp(CFG_IRQ_TOTAL-1 downto 1) := r.irqs_pending; --! [RO]: Rised interrupts.
|
104 |
|
|
when 2 => tmp := (others => '0'); --! [WO]: Clear interrupts mask.
|
105 |
|
|
when 3 => tmp := (others => '0'); --! [WO]: Rise interrupts mask.
|
106 |
|
|
when 4 => tmp := r.isr_table(31 downto 0); --! [RW]: LSB of the function address
|
107 |
|
|
when 5 => tmp := r.isr_table(63 downto 32); --! [RW]: MSB of the function address
|
108 |
|
|
when 6 => tmp := r.dbg_cause(31 downto 0); --! [RW]: Cause of the interrupt
|
109 |
|
|
when 7 => tmp := r.dbg_cause(63 downto 32); --! [RW]:
|
110 |
|
|
when 8 => tmp := r.dbg_epc(31 downto 0); --! [RW]: Instruction pointer
|
111 |
|
|
when 9 => tmp := r.dbg_epc(63 downto 32); --! [RW]:
|
112 |
|
|
when 10 => tmp(0) := r.irq_lock;
|
113 |
|
|
when 11 => tmp := r.irq_cause_idx;
|
114 |
|
|
when others =>
|
115 |
|
|
end case;
|
116 |
|
|
rdata(8*CFG_ALIGN_BYTES*(n+1)-1 downto 8*CFG_ALIGN_BYTES*n) := tmp;
|
117 |
|
|
end loop;
|
118 |
|
|
|
119 |
|
|
if i_axi.w_valid = '1' and
|
120 |
|
|
r.bank_axi.wstate = wtrans and
|
121 |
|
|
r.bank_axi.wresp = NASTI_RESP_OKAY then
|
122 |
|
|
|
123 |
|
|
for n in 0 to CFG_WORDS_ON_BUS-1 loop
|
124 |
|
|
waddr_reg(n) := conv_integer(r.bank_axi.waddr(n)(11 downto 2));
|
125 |
|
|
tmp := i_axi.w_data(32*(n+1)-1 downto 32*n);
|
126 |
|
|
wstrb := i_axi.w_strb(CFG_ALIGN_BYTES*(n+1)-1 downto CFG_ALIGN_BYTES*n);
|
127 |
|
|
|
128 |
|
|
if conv_integer(wstrb) /= 0 then
|
129 |
|
|
case waddr_reg(n) is
|
130 |
|
|
when 0 => v.irqs_mask := tmp(CFG_IRQ_TOTAL-1 downto 1);
|
131 |
|
|
when 1 => --! Read only
|
132 |
|
|
when 2 =>
|
133 |
|
|
v.irqs_pending := r.irqs_pending and (not tmp(CFG_IRQ_TOTAL-1 downto 1));
|
134 |
|
|
when 3 =>
|
135 |
|
|
w_generate_ipi := '1';
|
136 |
|
|
v.irqs_pending := (not r.irqs_mask) and tmp(CFG_IRQ_TOTAL-1 downto 1);
|
137 |
|
|
when 4 => v.isr_table(31 downto 0) := tmp;
|
138 |
|
|
when 5 => v.isr_table(63 downto 32) := tmp;
|
139 |
|
|
when 6 => v.dbg_cause(31 downto 0) := tmp;
|
140 |
|
|
when 7 => v.dbg_cause(63 downto 32) := tmp;
|
141 |
|
|
when 8 => v.dbg_epc(31 downto 0) := tmp;
|
142 |
|
|
when 9 => v.dbg_epc(63 downto 32) := tmp;
|
143 |
|
|
when 10 => v.irq_lock := tmp(0);
|
144 |
|
|
when 11 => v.irq_cause_idx := tmp;
|
145 |
|
|
when others =>
|
146 |
|
|
end case;
|
147 |
|
|
end if;
|
148 |
|
|
end loop;
|
149 |
|
|
end if;
|
150 |
|
|
|
151 |
|
|
v.irqs_z := i_irqs;
|
152 |
|
|
v.irqs_zz := r.irqs_z;
|
153 |
|
|
for n in 1 to CFG_IRQ_TOTAL-1 loop
|
154 |
|
|
if (r.irqs_z(n) = '1' and r.irqs_zz(n) = '0') or r.irq_wait_unlock(n) = '1' then
|
155 |
|
|
if r.irq_lock = '0' then
|
156 |
|
|
v.irq_wait_unlock(n) := '0';
|
157 |
|
|
v.irqs_pending(n) := not r.irqs_mask(n);
|
158 |
|
|
w_generate_ipi := w_generate_ipi or (not r.irqs_mask(n));
|
159 |
|
|
else
|
160 |
|
|
v.irq_wait_unlock(n) := '1';
|
161 |
|
|
end if;
|
162 |
|
|
end if;
|
163 |
|
|
end loop;
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
o_axi <= functionAxi4Output(r.bank_axi, rdata);
|
167 |
|
|
if r.irqs_pending = IRQ_ZERO or r.irq_lock = '1' then
|
168 |
|
|
o_irq_meip <= '0';
|
169 |
|
|
else
|
170 |
|
|
o_irq_meip <= '1';
|
171 |
|
|
end if;
|
172 |
|
|
|
173 |
|
|
if nrst = '0' then
|
174 |
|
|
v.bank_axi := NASTI_SLAVE_BANK_RESET;
|
175 |
|
|
v.irqs_mask := (others => '1'); -- all interrupts disabled
|
176 |
|
|
v.irqs_pending := (others => '0');
|
177 |
|
|
v.irqs_z := (others => '0');
|
178 |
|
|
v.irqs_zz := (others => '0');
|
179 |
|
|
v.isr_table := (others => '0');
|
180 |
|
|
v.irq_lock := '0';
|
181 |
|
|
v.irq_wait_unlock := (others => '0');
|
182 |
|
|
v.irq_cause_idx := (others => '0');
|
183 |
|
|
v.dbg_cause := (others => '0');
|
184 |
|
|
v.dbg_epc := (others => '0');
|
185 |
|
|
end if;
|
186 |
|
|
|
187 |
|
|
rin <= v;
|
188 |
|
|
end process;
|
189 |
|
|
|
190 |
|
|
o_cfg <= xconfig;
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
-- registers:
|
194 |
|
|
regs : process(clk)
|
195 |
|
|
begin
|
196 |
|
|
if rising_edge(clk) then
|
197 |
|
|
r <= rin;
|
198 |
|
|
end if;
|
199 |
|
|
end process;
|
200 |
|
|
end;
|