blob: 515472c790cb4d3193c7737a6fe59016a7fa10ac [file] [log] [blame]
Andrew Attwood1d1e8c32021-11-26 15:05:07 +00001// Copyright lowRISC contributors.
2// Copyright 2017 ETH Zurich and University of Bologna.
3// Licensed under the Apache License, Version 2.0, see LICENSE for details.
4// SPDX-License-Identifier: Apache-2.0
5
6////////////////////////////////////////////////////////////////////////////////
7// Engineer: Matthias Baer - baermatt@student.ethz.ch //
8// //
9// Additional contributions by: //
10// Sven Stucki - svstucki@student.ethz.ch //
11// //
12// //
13// Design Name: RISC-V processor core //
14// Project Name: ibex //
15// Language: SystemVerilog //
16// //
17// Description: Defines for various constants used by the processor core. //
18// //
19////////////////////////////////////////////////////////////////////////////////
20
nguyendao-uom4b10c632021-11-25 11:23:15 +000021module ibex_int_controller (
22 clk,
23 rst_n,
24 irq_req_ctrl_o,
25 irq_id_ctrl_o,
26 ctrl_ack_i,
27 ctrl_kill_i,
28 irq_i,
29 irq_id_i,
30 m_IE_i
31);
32 input wire clk;
33 input wire rst_n;
34 output wire irq_req_ctrl_o;
35 output wire [4:0] irq_id_ctrl_o;
36 input wire ctrl_ack_i;
37 input wire ctrl_kill_i;
38 input wire irq_i;
39 input wire [4:0] irq_id_i;
40 input wire m_IE_i;
41 reg [1:0] exc_ctrl_ns;
42 reg [1:0] exc_ctrl_cs;
43 wire irq_enable_ext;
44 reg [4:0] irq_id_d;
45 reg [4:0] irq_id_q;
46 assign irq_enable_ext = m_IE_i;
47 localparam [1:0] IRQ_PENDING = 1;
48 assign irq_req_ctrl_o = exc_ctrl_cs == IRQ_PENDING;
49 assign irq_id_ctrl_o = irq_id_q;
50 localparam [1:0] IDLE = 0;
51 always @(posedge clk or negedge rst_n)
52 if (!rst_n) begin
53 irq_id_q <= {5 {1'sb0}};
54 exc_ctrl_cs <= IDLE;
55 end
56 else begin
57 irq_id_q <= irq_id_d;
58 exc_ctrl_cs <= exc_ctrl_ns;
59 end
60 localparam [1:0] IRQ_DONE = 2;
61 always @(*) begin
62 irq_id_d = irq_id_q;
63 exc_ctrl_ns = exc_ctrl_cs;
64 case (exc_ctrl_cs)
65 IDLE:
66 if (irq_enable_ext && irq_i) begin
67 exc_ctrl_ns = IRQ_PENDING;
68 irq_id_d = irq_id_i;
69 end
70 IRQ_PENDING:
71 case (1'b1)
72 ctrl_ack_i: exc_ctrl_ns = IRQ_DONE;
73 ctrl_kill_i: exc_ctrl_ns = IDLE;
74 default: exc_ctrl_ns = IRQ_PENDING;
75 endcase
76 IRQ_DONE: exc_ctrl_ns = IDLE;
77 endcase
78 end
79endmodule