1 |
2 |
madsilicon |
-----------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-----------------------------------------------------------------
|
4 |
|
|
-- --
|
5 |
|
|
-- Copyright (C) 2016 Stefano Tonello --
|
6 |
|
|
-- --
|
7 |
|
|
-- This source file may be used and distributed without --
|
8 |
|
|
-- restriction provided that this copyright statement is not --
|
9 |
|
|
-- removed from the file and that any derivative work contains --
|
10 |
|
|
-- the original copyright notice and the associated disclaimer.--
|
11 |
|
|
-- --
|
12 |
|
|
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY --
|
13 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED --
|
14 |
|
|
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS --
|
15 |
|
|
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR --
|
16 |
|
|
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, --
|
17 |
|
|
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES --
|
18 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE --
|
19 |
|
|
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR --
|
20 |
|
|
-- BUSINESS REQERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
|
21 |
|
|
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
22 |
|
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT --
|
23 |
|
|
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE --
|
24 |
|
|
-- POSSIBILITY OF SUCH DAMAGE. --
|
25 |
|
|
-- --
|
26 |
|
|
-----------------------------------------------------------------
|
27 |
|
|
|
28 |
|
|
---------------------------------------------------------------
|
29 |
|
|
-- RV01 PLIC core
|
30 |
|
|
---------------------------------------------------------------
|
31 |
|
|
|
32 |
|
|
library IEEE;
|
33 |
|
|
use IEEE.std_logic_1164.all;
|
34 |
|
|
use IEEE.numeric_std.all;
|
35 |
|
|
|
36 |
|
|
library work;
|
37 |
|
|
use work.RV01_CONSTS_PKG.all;
|
38 |
|
|
use work.RV01_FUNCS_PKG.all;
|
39 |
|
|
use work.RV01_PLIC_PKG.all;
|
40 |
|
|
|
41 |
|
|
entity RV01_PLIC_CORE is
|
42 |
|
|
generic(
|
43 |
|
|
SRC_CNT : natural := 8
|
44 |
|
|
);
|
45 |
|
|
port(
|
46 |
|
|
CLK_i : in std_logic;
|
47 |
|
|
RST_i : in std_logic;
|
48 |
|
|
REG_A_i : in std_logic_vector(log2(SRC_CNT+1)-1 downto 0);
|
49 |
|
|
REG_WE_i : in std_logic;
|
50 |
|
|
REG_D_i : in std_logic_vector(SDLEN-1 downto 0);
|
51 |
|
|
IP_i : in std_logic_vector(SRC_CNT-1 downto 0);
|
52 |
|
|
|
53 |
|
|
REG_Q_o : out std_logic_vector(SDLEN-1 downto 0);
|
54 |
|
|
EIP_o : out std_logic;
|
55 |
|
|
IS_o : out std_logic_vector(SRC_CNT-1 downto 0)
|
56 |
|
|
);
|
57 |
|
|
end RV01_PLIC_CORE;
|
58 |
|
|
|
59 |
|
|
architecture ARC of RV01_PLIC_CORE is
|
60 |
|
|
|
61 |
|
|
-- interrupt Id number of bits.
|
62 |
|
|
constant ID_WIDTH : natural := 8;
|
63 |
|
|
-- interrupt priority number of bits.
|
64 |
|
|
constant PRI_WIDTH : natural := 8;
|
65 |
|
|
|
66 |
|
|
subtype PRIORITY_TYPE is unsigned(PRI_WIDTH-1 downto 0);
|
67 |
|
|
subtype ID_TYPE is unsigned(ID_WIDTH-1 downto 0);
|
68 |
|
|
|
69 |
|
|
-- interrupt-claim bit index
|
70 |
|
|
constant ICLM_NDX : natural := 8;
|
71 |
|
|
-- interrupt-complete bit index
|
72 |
|
|
constant ICMPLT_NDX : natural := 9;
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
-- interrupt id. hi/lo bit bounds
|
77 |
|
|
constant ID_LO : natural := 0;
|
78 |
|
|
constant ID_HI : natural := ID_LO + ID_WIDTH - 1;
|
79 |
|
|
-- interrupt priority hi/lo bit bounds
|
80 |
|
|
constant PRI_LO : natural := 8;
|
81 |
|
|
constant PRI_HI : natural := PRI_LO + PRI_WIDTH - 1;
|
82 |
|
|
-- interrupt priority threshold hi/lo bit bounds
|
83 |
|
|
constant PRIT_LO : natural := 0;
|
84 |
|
|
constant PRIT_HI : natural := PRIT_LO + PRI_WIDTH - 1;
|
85 |
|
|
|
86 |
|
|
constant IPTR_ADR : unsigned(log2(SRC_CNT+3)-1 downto 0) :=
|
87 |
|
|
to_unsigned(SRC_CNT,log2(SRC_CNT+3));
|
88 |
|
|
|
89 |
|
|
constant IEBR_ADR : unsigned(log2(SRC_CNT+3)-1 downto 0) :=
|
90 |
|
|
to_unsigned(SRC_CNT+1,log2(SRC_CNT+3));
|
91 |
|
|
|
92 |
|
|
constant ICR_ADR : unsigned(log2(SRC_CNT+3)-1 downto 0) :=
|
93 |
|
|
to_unsigned(SRC_CNT+2,log2(SRC_CNT+3));
|
94 |
|
|
|
95 |
|
|
component RV01_RAM_1RW1R is
|
96 |
|
|
generic(
|
97 |
|
|
-- I/O data bus width
|
98 |
|
|
DWIDTH : integer := 16;
|
99 |
|
|
-- word count
|
100 |
|
|
WCOUNT : integer := 256
|
101 |
|
|
);
|
102 |
|
|
port(
|
103 |
|
|
CLK_i : in std_logic;
|
104 |
|
|
A_i : in unsigned(log2(WCOUNT)-1 downto 0);
|
105 |
|
|
DPRA_i : in unsigned(log2(WCOUNT)-1 downto 0);
|
106 |
|
|
D_i : in std_logic_vector(DWIDTH-1 downto 0);
|
107 |
|
|
WE_i : in std_logic;
|
108 |
|
|
|
109 |
|
|
Q_o : out std_logic_vector(DWIDTH-1 downto 0);
|
110 |
|
|
DPQ_o : out std_logic_vector(DWIDTH-1 downto 0)
|
111 |
|
|
);
|
112 |
|
|
end component;
|
113 |
|
|
|
114 |
|
|
---------------------------------------------------------
|
115 |
|
|
-- Interrupt Source Registers (ISR)
|
116 |
|
|
---------------------------------------------------------
|
117 |
|
|
-- 3322 2222 2222 1111 1111 1100 0000 0000
|
118 |
|
|
-- 1098 7654 3210 9876 5432 1098 7654 3210 Descr.
|
119 |
|
|
-- dddd dddd Int. ID (R/W)
|
120 |
|
|
-- dddd dddd Int. priority (R/W)
|
121 |
|
|
|
122 |
|
|
---------------------------------------------------------
|
123 |
|
|
-- Interrupt Priority Threshold Register (IPTR)
|
124 |
|
|
---------------------------------------------------------
|
125 |
|
|
-- 3322 2222 2222 1111 1111 1100 0000 0000
|
126 |
|
|
-- 1098 7654 3210 9876 5432 1098 7654 3210 Descr.
|
127 |
|
|
-- dddd dddd Int. priority thresh. (R/W)
|
128 |
|
|
|
129 |
|
|
---------------------------------------------------------
|
130 |
|
|
-- Interrupt Enable Bits Register (IEBR)
|
131 |
|
|
---------------------------------------------------------
|
132 |
|
|
-- 3322 2222 2222 1111 1111 1100 0000 0000
|
133 |
|
|
-- 1098 7654 3210 9876 5432 1098 7654 3210 Descr.
|
134 |
|
|
-- dddd dddd dddd dddd dddd dddd dddd dddd IE bits (R/W)
|
135 |
|
|
|
136 |
|
|
---------------------------------------------------------
|
137 |
|
|
-- Interrupt Control Register (ICR)
|
138 |
|
|
---------------------------------------------------------
|
139 |
|
|
-- 3322 2222 2222 1111 1111 1100 0000 0000
|
140 |
|
|
-- 1098 7654 3210 9876 5432 1098 7654 3210 Descr.
|
141 |
|
|
-- dddd dddd Int. ID (R)
|
142 |
|
|
-- d Int. Claim (W)
|
143 |
|
|
-- d Int. Complete (W)
|
144 |
|
|
|
145 |
|
|
type STATE_TYPE is (
|
146 |
|
|
S_IDLE,
|
147 |
|
|
S_WAIT,
|
148 |
|
|
S_EVAL1,
|
149 |
|
|
S_EVAL2,
|
150 |
|
|
S_WCLM,
|
151 |
|
|
S_WCMPLT
|
152 |
|
|
);
|
153 |
|
|
|
154 |
|
|
signal ISR_A,ISR_DPRA : unsigned(log2(SRC_CNT)-1 downto 0);
|
155 |
|
|
signal ISR_D,ISR_Q,ISR_DPQ : std_logic_vector(ID_WIDTH+PRI_WIDTH-1 downto 0);
|
156 |
|
|
signal ISR_WE : std_logic;
|
157 |
|
|
signal IPTR_q : PRIORITY_TYPE;
|
158 |
|
|
signal IPTR_WE : std_logic;
|
159 |
|
|
signal IEBR_q : std_logic_vector(SRC_CNT-1 downto 0);
|
160 |
|
|
signal IEBR_WE : std_logic;
|
161 |
|
|
signal EVAL,EVAL_q : std_logic;
|
162 |
|
|
signal S,S_q : STATE_TYPE;
|
163 |
|
|
signal ICLM : std_logic;
|
164 |
|
|
signal ICMPLT : std_logic;
|
165 |
|
|
signal SCNT_RST,SCNT_INC,SCNT_END : std_logic;
|
166 |
|
|
signal SCNT_q,SCNT_q2 : natural range 0 to SRC_CNT-1;
|
167 |
|
|
signal EIP_q : std_logic;
|
168 |
|
|
signal EIP_SET,EIP_CLR : std_logic;
|
169 |
|
|
signal MAX_PRI_q : PRIORITY_TYPE;
|
170 |
|
|
signal MAX_PRI_WE : std_logic;
|
171 |
|
|
signal MIN_ID_WE : std_logic;
|
172 |
|
|
signal PRI_GT_MAX,PRI_EQ_MAX,PRI_MAX_GT_TRSH : std_logic;
|
173 |
|
|
signal MIN_ID_q : ID_TYPE;
|
174 |
|
|
signal ID_LT_MIN : std_logic;
|
175 |
|
|
signal RSEL,RSEL_q : std_logic_vector(2-1 downto 0);
|
176 |
|
|
signal CURR_IP,CURR_IP_q : std_logic;
|
177 |
|
|
signal CURR_ID : ID_TYPE;
|
178 |
|
|
signal CURR_PRI : PRIORITY_TYPE;
|
179 |
|
|
signal IPSRC_q : natural range 0 to SRC_CNT-1;
|
180 |
|
|
signal IP_q : std_logic_vector(SRC_CNT-1 downto 0);
|
181 |
|
|
|
182 |
|
|
begin
|
183 |
|
|
|
184 |
|
|
---------------------------------------------------------
|
185 |
|
|
-- Interrupt Source Registers
|
186 |
|
|
---------------------------------------------------------
|
187 |
|
|
|
188 |
|
|
U_ISR : RV01_RAM_1RW1R
|
189 |
|
|
generic map(
|
190 |
|
|
DWIDTH => (ID_WIDTH + PRI_WIDTH),
|
191 |
|
|
WCOUNT => SRC_CNT
|
192 |
|
|
)
|
193 |
|
|
port map(
|
194 |
|
|
CLK_i => CLK_i,
|
195 |
|
|
A_i => ISR_A,
|
196 |
|
|
DPRA_i => ISR_DPRA,
|
197 |
|
|
D_i => ISR_D,
|
198 |
|
|
WE_i => ISR_WE,
|
199 |
|
|
|
200 |
|
|
Q_o => ISR_Q,
|
201 |
|
|
DPQ_o => ISR_DPQ
|
202 |
|
|
);
|
203 |
|
|
|
204 |
|
|
ISR_A <= to_unsigned(REG_A_i(log2(SRC_CNT)-1 downto 0));
|
205 |
|
|
ISR_DPRA <= to_unsigned(SCNT_q,log2(SRC_CNT));
|
206 |
|
|
ISR_D <= REG_D_i(PRI_WIDTH+ID_WIDTH-1 downto 0);
|
207 |
|
|
ISR_WE <= REG_WE_i when (to_unsigned(REG_A_i) < SRC_CNT) else '0';
|
208 |
|
|
|
209 |
|
|
CURR_ID <= to_unsigned(ISR_DPQ(ID_HI downto ID_LO));
|
210 |
|
|
CURR_PRI <= to_unsigned(ISR_DPQ(PRI_HI downto PRI_LO));
|
211 |
|
|
|
212 |
|
|
---------------------------------------------------------
|
213 |
|
|
-- Interrupt Priority Threshold Register
|
214 |
|
|
---------------------------------------------------------
|
215 |
|
|
|
216 |
|
|
process(CLK_i)
|
217 |
|
|
begin
|
218 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
219 |
|
|
if(RST_i = '1') then
|
220 |
|
|
IPTR_q <= (others => '0');
|
221 |
|
|
elsif(IPTR_WE = '1') then
|
222 |
|
|
IPTR_q <= to_unsigned(REG_D_i(PRIT_HI downto PRIT_LO));
|
223 |
|
|
end if;
|
224 |
|
|
end if;
|
225 |
|
|
end process;
|
226 |
|
|
|
227 |
|
|
IPTR_WE <= REG_WE_i when (to_unsigned(REG_A_i) = IPTR_ADR) else '0';
|
228 |
|
|
|
229 |
|
|
---------------------------------------------------------
|
230 |
|
|
-- Interrupt Enable Bits Register
|
231 |
|
|
---------------------------------------------------------
|
232 |
|
|
|
233 |
|
|
process(CLK_i)
|
234 |
|
|
begin
|
235 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
236 |
|
|
if(RST_i = '1') then
|
237 |
|
|
IEBR_q <= (others => '0');
|
238 |
|
|
elsif(IEBR_WE = '1') then
|
239 |
|
|
IEBR_q <= REG_D_i(SRC_CNT-1 downto 0);
|
240 |
|
|
end if;
|
241 |
|
|
end if;
|
242 |
|
|
end process;
|
243 |
|
|
|
244 |
|
|
IEBR_WE <= REG_WE_i when (to_unsigned(REG_A_i) = IEBR_ADR) else '0';
|
245 |
|
|
|
246 |
|
|
CURR_IP <= IEBR_q(SCNT_q) and IP_q(SCNT_q);
|
247 |
|
|
|
248 |
|
|
process(CLK_i)
|
249 |
|
|
begin
|
250 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
251 |
|
|
CURR_IP_q <= CURR_IP;
|
252 |
|
|
end if;
|
253 |
|
|
end process;
|
254 |
|
|
|
255 |
|
|
---------------------------------------------------------
|
256 |
|
|
-- Interrupt Control Register
|
257 |
|
|
---------------------------------------------------------
|
258 |
|
|
|
259 |
|
|
-- There's no physical storage for this register as its
|
260 |
|
|
-- bits (Int. Claim and Int. Complete) are write-only.
|
261 |
|
|
|
262 |
|
|
-- Interrupt claim flag
|
263 |
|
|
ICLM <= (REG_WE_i and REG_D_i(ICLM_NDX)) when (to_unsigned(REG_A_i) = ICR_ADR) else '0';
|
264 |
|
|
|
265 |
|
|
-- Interrupt complete flag
|
266 |
|
|
ICMPLT <= (REG_WE_i and REG_D_i(ICMPLT_NDX)) when (to_unsigned(REG_A_i) = ICR_ADR) else '0';
|
267 |
|
|
|
268 |
|
|
---------------------------------------------------------
|
269 |
|
|
-- Refresh Signal
|
270 |
|
|
---------------------------------------------------------
|
271 |
|
|
|
272 |
|
|
-- Pending interrup status must be re-evaluated every time
|
273 |
|
|
-- PLIC core registers are written or pending interrupt
|
274 |
|
|
-- inputs change.
|
275 |
|
|
|
276 |
|
|
process(CLK_i)
|
277 |
|
|
begin
|
278 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
279 |
|
|
if(RST_i = '1') then
|
280 |
|
|
IP_q <= (others => '0');
|
281 |
|
|
else
|
282 |
|
|
IP_q <= IP_i;
|
283 |
|
|
end if;
|
284 |
|
|
end if;
|
285 |
|
|
end process;
|
286 |
|
|
|
287 |
|
|
process(CLK_i)
|
288 |
|
|
begin
|
289 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
290 |
|
|
if(RST_i = '1') then
|
291 |
|
|
EVAL_q <= '0';
|
292 |
|
|
else
|
293 |
|
|
EVAL_q <= EVAL;
|
294 |
|
|
end if;
|
295 |
|
|
end if;
|
296 |
|
|
end process;
|
297 |
|
|
|
298 |
|
|
EVAL <= not(EIP_q) when (REG_WE_i = '1' or not(IP_i = IP_q)) else '0';
|
299 |
|
|
|
300 |
|
|
---------------------------------------------------------
|
301 |
|
|
-- Control FSM
|
302 |
|
|
---------------------------------------------------------
|
303 |
|
|
|
304 |
|
|
process(CLK_i)
|
305 |
|
|
begin
|
306 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
307 |
|
|
if(RST_i = '1') then
|
308 |
|
|
S_q <= S_IDLE;
|
309 |
|
|
else
|
310 |
|
|
S_q <= S;
|
311 |
|
|
end if;
|
312 |
|
|
end if;
|
313 |
|
|
end process;
|
314 |
|
|
|
315 |
|
|
process(S_q,EVAL_q,SCNT_END,PRI_GT_MAX,PRI_EQ_MAX,ID_LT_MIN,
|
316 |
|
|
PRI_MAX_GT_TRSH,CURR_IP_q,ICLM,ICMPLT)
|
317 |
|
|
begin
|
318 |
|
|
|
319 |
|
|
SCNT_RST <= '0';
|
320 |
|
|
SCNT_INC <= '0';
|
321 |
|
|
MAX_PRI_WE <= '0';
|
322 |
|
|
MIN_ID_WE <= '0';
|
323 |
|
|
EIP_SET <= '0';
|
324 |
|
|
EIP_CLR <= '0';
|
325 |
|
|
|
326 |
|
|
case S_q is
|
327 |
|
|
|
328 |
|
|
-- Wait for next pending interrupt evaluation
|
329 |
|
|
when S_IDLE =>
|
330 |
|
|
if(EVAL_q = '1') then
|
331 |
|
|
-- Reset source count
|
332 |
|
|
SCNT_RST <= '1';
|
333 |
|
|
-- Start evaluation
|
334 |
|
|
S <= S_WAIT;
|
335 |
|
|
end if;
|
336 |
|
|
|
337 |
|
|
-- A wait state allows is needed for register RAM
|
338 |
|
|
-- output to update after source count is reset.
|
339 |
|
|
when S_WAIT =>
|
340 |
|
|
if(EVAL_q = '1') then
|
341 |
|
|
-- Reset source count
|
342 |
|
|
SCNT_RST <= '1';
|
343 |
|
|
-- Re-start evaluation
|
344 |
|
|
S <= S_WAIT;
|
345 |
|
|
else
|
346 |
|
|
-- Increment source count
|
347 |
|
|
SCNT_INC <= '1';
|
348 |
|
|
-- Go on with evaluation
|
349 |
|
|
S <= S_EVAL1;
|
350 |
|
|
end if;
|
351 |
|
|
|
352 |
|
|
-- Perform pending interrupt evaluation
|
353 |
|
|
when S_EVAL1 =>
|
354 |
|
|
if(EVAL_q = '1') then
|
355 |
|
|
-- Reset source count
|
356 |
|
|
SCNT_RST <= '1';
|
357 |
|
|
-- Re-start evaluation
|
358 |
|
|
S <= S_WAIT;
|
359 |
|
|
elsif(SCNT_END = '1') then
|
360 |
|
|
-- end evaluation, there's no pending
|
361 |
|
|
-- interrupt, go back to idle state.
|
362 |
|
|
S <= S_IDLE;
|
363 |
|
|
else
|
364 |
|
|
-- Increment source count
|
365 |
|
|
SCNT_INC <= '1';
|
366 |
|
|
-- Check for pending interrupts...
|
367 |
|
|
if(CURR_IP_q = '1') then
|
368 |
|
|
-- If current interrupt priority is higher than
|
369 |
|
|
-- max. priority, update max. priority.
|
370 |
|
|
MAX_PRI_WE <= PRI_GT_MAX;
|
371 |
|
|
-- If current interrupt priority is higher than
|
372 |
|
|
-- max. priority, OR
|
373 |
|
|
-- if current interrupt priority is equal to
|
374 |
|
|
-- max. priority and current id. is
|
375 |
|
|
-- lower then min. id, update min. id.
|
376 |
|
|
MIN_ID_WE <= PRI_GT_MAX or (PRI_EQ_MAX and ID_LT_MIN);
|
377 |
|
|
-- Go on with evaluation
|
378 |
|
|
S <= S_EVAL2;
|
379 |
|
|
else
|
380 |
|
|
-- Go on with evaluation
|
381 |
|
|
S <= S_EVAL1;
|
382 |
|
|
end if;
|
383 |
|
|
end if;
|
384 |
|
|
|
385 |
|
|
-- Perform pending interrupt evaluation
|
386 |
|
|
when S_EVAL2 =>
|
387 |
|
|
if(EVAL_q = '1') then
|
388 |
|
|
-- Reset source count
|
389 |
|
|
SCNT_RST <= '1';
|
390 |
|
|
-- Re-start evaluation
|
391 |
|
|
S <= S_WAIT;
|
392 |
|
|
elsif(SCNT_END = '1') then
|
393 |
|
|
-- end evaluation, there's a pending
|
394 |
|
|
-- interrupt: check if its priority
|
395 |
|
|
-- exceed treshold value...
|
396 |
|
|
if(PRI_MAX_GT_TRSH = '1') then
|
397 |
|
|
-- it does: SET EIP register
|
398 |
|
|
EIP_SET <= '1';
|
399 |
|
|
S <= S_WCLM;
|
400 |
|
|
else
|
401 |
|
|
-- it doesn't: go back to idle state.
|
402 |
|
|
S <= S_IDLE;
|
403 |
|
|
end if;
|
404 |
|
|
else
|
405 |
|
|
-- Increment source count
|
406 |
|
|
SCNT_INC <= '1';
|
407 |
|
|
-- Check for pending interrupts...
|
408 |
|
|
if(CURR_IP_q = '1') then
|
409 |
|
|
-- If current interrupt priority is higher than
|
410 |
|
|
-- max. priority, update max. priority.
|
411 |
|
|
MAX_PRI_WE <= PRI_GT_MAX;
|
412 |
|
|
-- If current interrupt priority is higher than
|
413 |
|
|
-- max. priority, OR
|
414 |
|
|
-- if current interrupt priority is equal to
|
415 |
|
|
-- max. priority and current id. is
|
416 |
|
|
-- lower then min. id, update min. id.
|
417 |
|
|
MIN_ID_WE <= PRI_GT_MAX or (PRI_EQ_MAX and ID_LT_MIN);
|
418 |
|
|
-- Go on with evaluation
|
419 |
|
|
S <= S_EVAL2;
|
420 |
|
|
else
|
421 |
|
|
-- Go on with evaluation
|
422 |
|
|
S <= S_EVAL2;
|
423 |
|
|
end if;
|
424 |
|
|
end if;
|
425 |
|
|
|
426 |
|
|
-- Wait for claim signal from target
|
427 |
|
|
when S_WCLM =>
|
428 |
|
|
if(ICLM = '1') then
|
429 |
|
|
-- Clear EIP register
|
430 |
|
|
EIP_CLR <= '1';
|
431 |
|
|
S <= S_WCMPLT;
|
432 |
|
|
else
|
433 |
|
|
S <= S_WCLM;
|
434 |
|
|
end if;
|
435 |
|
|
|
436 |
|
|
-- Wait for completion signal from target
|
437 |
|
|
when S_WCMPLT =>
|
438 |
|
|
if(ICMPLT = '1') then
|
439 |
|
|
EIP_CLR <= '1';
|
440 |
|
|
S <= S_IDLE;
|
441 |
|
|
else
|
442 |
|
|
S <= S_WCMPLT;
|
443 |
|
|
end if;
|
444 |
|
|
|
445 |
|
|
when others =>
|
446 |
|
|
S <= S_IDLE;
|
447 |
|
|
|
448 |
|
|
end case;
|
449 |
|
|
end process;
|
450 |
|
|
|
451 |
|
|
---------------------------------------------------------
|
452 |
|
|
--
|
453 |
|
|
---------------------------------------------------------
|
454 |
|
|
|
455 |
|
|
-- Max. source priority register
|
456 |
|
|
process(CLK_i)
|
457 |
|
|
begin
|
458 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
459 |
|
|
if(RST_i = '1') then
|
460 |
|
|
MAX_PRI_q <= to_unsigned(1,PRI_WIDTH);
|
461 |
|
|
elsif(MAX_PRI_WE = '1') then
|
462 |
|
|
MAX_PRI_q <= CURR_PRI;
|
463 |
|
|
end if;
|
464 |
|
|
end if;
|
465 |
|
|
end process;
|
466 |
|
|
|
467 |
|
|
-- Current source priority greater-than max. priority flag
|
468 |
|
|
PRI_GT_MAX <= '1' when CURR_PRI > MAX_PRI_q else '0';
|
469 |
|
|
|
470 |
|
|
-- Current source priority equal-to max. priority flag
|
471 |
|
|
PRI_EQ_MAX <= '1' when CURR_PRI > MAX_PRI_q else '0';
|
472 |
|
|
|
473 |
|
|
-- Max. source priority greater-than priority treshold flag
|
474 |
|
|
PRI_MAX_GT_TRSH <= '1' when MAX_PRI_q > IPTR_q else '0';
|
475 |
|
|
|
476 |
|
|
-- Min. source id. register
|
477 |
|
|
process(CLK_i)
|
478 |
|
|
begin
|
479 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
480 |
|
|
if(RST_i = '1') then
|
481 |
|
|
MIN_ID_q <= (others => '1');
|
482 |
|
|
elsif(MIN_ID_WE = '1') then
|
483 |
|
|
MIN_ID_q <= CURR_ID;
|
484 |
|
|
end if;
|
485 |
|
|
end if;
|
486 |
|
|
end process;
|
487 |
|
|
|
488 |
|
|
-- Current source id. lower-than min. id. flag.
|
489 |
|
|
ID_LT_MIN <= '1' when CURR_ID < MIN_ID_q else '0';
|
490 |
|
|
|
491 |
|
|
---------------------------------------------------------
|
492 |
|
|
-- Pending Interrupt register
|
493 |
|
|
---------------------------------------------------------
|
494 |
|
|
|
495 |
|
|
process(CLK_i)
|
496 |
|
|
begin
|
497 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
498 |
|
|
if(RST_i = '1' or EIP_CLR = '1') then
|
499 |
|
|
EIP_q <= '0';
|
500 |
|
|
elsif(EIP_SET = '1') then
|
501 |
|
|
EIP_q <= '1';
|
502 |
|
|
end if;
|
503 |
|
|
end if;
|
504 |
|
|
end process;
|
505 |
|
|
|
506 |
|
|
EIP_o <= EIP_q;
|
507 |
|
|
|
508 |
|
|
---------------------------------------------------------
|
509 |
|
|
-- Pending Interrupt Source register
|
510 |
|
|
---------------------------------------------------------
|
511 |
|
|
|
512 |
|
|
process(CLK_i)
|
513 |
|
|
begin
|
514 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
515 |
|
|
if(MIN_ID_WE = '1') then
|
516 |
|
|
IPSRC_q <= SCNT_q2;
|
517 |
|
|
end if;
|
518 |
|
|
end if;
|
519 |
|
|
end process;
|
520 |
|
|
|
521 |
|
|
process(ICMPLT,IPSRC_q)
|
522 |
|
|
variable TMP : std_logic_vector(SRC_CNT-1 downto 0);
|
523 |
|
|
begin
|
524 |
|
|
TMP := (others => '0');
|
525 |
|
|
TMP(IPSRC_q) := ICMPLT;
|
526 |
|
|
IS_o <= TMP;
|
527 |
|
|
end process;
|
528 |
|
|
|
529 |
|
|
---------------------------------------------------------
|
530 |
|
|
-- Source counter
|
531 |
|
|
---------------------------------------------------------
|
532 |
|
|
|
533 |
|
|
process(CLK_i)
|
534 |
|
|
begin
|
535 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
536 |
|
|
if(SCNT_RST = '1') then
|
537 |
|
|
SCNT_q <= 0;
|
538 |
|
|
SCNT_q2 <= 0;
|
539 |
|
|
elsif(SCNT_INC = '1' and SCNT_END = '0') then
|
540 |
|
|
SCNT_q <= SCNT_q + 1;
|
541 |
|
|
SCNT_q2 <= SCNT_q;
|
542 |
|
|
end if;
|
543 |
|
|
end if;
|
544 |
|
|
end process;
|
545 |
|
|
|
546 |
|
|
SCNT_END <= '1' when (SCNT_q = SRC_CNT-1) else '0';
|
547 |
|
|
|
548 |
|
|
---------------------------------------------------------
|
549 |
|
|
-- Output mux
|
550 |
|
|
---------------------------------------------------------
|
551 |
|
|
|
552 |
|
|
process(REG_A_i)
|
553 |
|
|
begin
|
554 |
|
|
if(to_unsigned(REG_A_i) <= SRC_CNT) then
|
555 |
|
|
RSEL <= "00";
|
556 |
|
|
elsif(to_unsigned(REG_A_i) = IPTR_ADR) then
|
557 |
|
|
RSEL <= "01";
|
558 |
|
|
elsif(to_unsigned(REG_A_i) = IEBR_ADR) then
|
559 |
|
|
RSEL <= "10";
|
560 |
|
|
else
|
561 |
|
|
RSEL <= "11";
|
562 |
|
|
end if;
|
563 |
|
|
end process;
|
564 |
|
|
|
565 |
|
|
-- Delay selector value by one cycle to match
|
566 |
|
|
-- ISR sync.RAM read delay.
|
567 |
|
|
process(CLK_i)
|
568 |
|
|
begin
|
569 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
570 |
|
|
RSEL_q <= RSEL;
|
571 |
|
|
end if;
|
572 |
|
|
end process;
|
573 |
|
|
|
574 |
|
|
process(RSEL_q,ISR_Q,IPTR_q,IEBR_q)
|
575 |
|
|
variable TMP : std_logic_vector(SDLEN-1 downto 0);
|
576 |
|
|
begin
|
577 |
|
|
TMP := (others => '0');
|
578 |
|
|
case RSEL_q is
|
579 |
|
|
when "00" =>
|
580 |
|
|
TMP(ID_HI downto ID_LO) := ISR_q(ID_WIDTH-1 downto 0);
|
581 |
|
|
TMP(PRI_HI downto PRI_LO) := ISR_q(PRI_WIDTH+ID_WIDTH-1 downto ID_WIDTH);
|
582 |
|
|
REG_Q_o <= TMP;
|
583 |
|
|
when "01" =>
|
584 |
|
|
TMP(PRI_HI downto PRI_LO) := to_std_logic_vector(IPTR_q);
|
585 |
|
|
REG_Q_o <= TMP;
|
586 |
|
|
when "10" =>
|
587 |
|
|
TMP(SRC_CNT-1 downto 0) := IEBR_q(ID_WIDTH-1 downto 0);
|
588 |
|
|
REG_Q_o <= TMP;
|
589 |
|
|
when others =>
|
590 |
|
|
REG_Q_o <= (others => '0');
|
591 |
|
|
end case;
|
592 |
|
|
end process;
|
593 |
|
|
|
594 |
|
|
---------------------------------------------------------
|
595 |
|
|
-- Notes
|
596 |
|
|
---------------------------------------------------------
|
597 |
|
|
-- The PLIC core has an address space of log2(SRC_CNT+2)
|
598 |
|
|
-- bit, with addresses ranging from 0 to SRC_CNT+1.
|
599 |
|
|
-- Address SRC_CNT+1 selects the Interrupt Enable Bit
|
600 |
|
|
-- Registers.
|
601 |
|
|
-- Address SRC_CNT selects the Interrupt Priority
|
602 |
|
|
-- Threshold Register.
|
603 |
|
|
-- Addresses 0:SRC_CNT-1 select the Interrupt registers
|
604 |
|
|
-- (one per interrupt source).
|
605 |
|
|
-- Each Interrupt register stores interrupt id and
|
606 |
|
|
-- priority for an interrupt source.
|
607 |
|
|
-- Interrupt registers are read and written by the RV01
|
608 |
|
|
-- core through a memory-mapped interface consisting of
|
609 |
|
|
-- the REG_ADR_i, REG_WE_i, REG_D_i and REG_Q_o ports.
|
610 |
|
|
|
611 |
|
|
end ARC;
|