summaryrefslogtreecommitdiffhomepage
path: root/source/interrupts.v
blob: c77dfb77f648b677b3ec9c27de0f037e2d3b4c38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 *      interrupts.v
 *
 *   Copyright (C) 2018, 2019 Mind Chasers Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *	function: uC Interrupt Controller
 *
 */

`timescale 1ns /10ps


module interrupts (
	input rstn,
	input clk,
	input uc_clk,


// uC interface
	input   sel,
	input 	we,
	input 	addr,
	input 	[6:0]	d_in,
	output  [6:0]	d_out,
	
	// interrupt sources
	input cont_int,
	input [3:0] phy_int,
	input [3:0] mac_int,
	
	// int out
	output int_o
);
	
localparam	INT_CONTROLLER = 'h01,
			INT_PHY0 = 'h02,
			INT_PHY1 = 'h04,
			INT_MAC0 = 'h08,
			INT_MAC1 = 'h10,
			INT_MAC2 = 'h20,
			INT_MAC3 = 'h40;
	
reg [6:0] int_enable;
reg [6:0] int_src;

assign d_out = addr ? int_src : int_enable;
assign int_o = int_src[6] & int_enable[6] | int_src[5] & int_enable[5] | int_src[4] & int_enable[4] | int_src[3] & int_enable[3] |
				int_src[2] & int_enable[2] | int_src[1] & int_enable[1] | int_src[0] & int_enable[0];

always @(posedge uc_clk or negedge rstn)
	if (!rstn)
		int_enable <= INT_MAC2 | INT_MAC3;
	else if (sel && we && !addr)
		int_enable <= d_in;

always @(posedge uc_clk or negedge rstn)
	if (!rstn)
		int_src <= 7'h0;
	else if (sel && we && addr)
		int_src <= d_in;
	else 
		int_src <= int_src | { mac_int, phy_int[1:0], cont_int };

	
endmodule

Highly Recommended Verilog Books