| 1 |
66 |
motilito |
//---------------------------------------------------------------------------------------
|
| 2 |
|
|
// Project: light8080 SOC WiCores Solutions
|
| 3 |
|
|
//
|
| 4 |
|
|
// File name: intr_ctrl.v (March 02, 2012)
|
| 5 |
|
|
//
|
| 6 |
|
|
// Writer: Moti Litochevski
|
| 7 |
|
|
//
|
| 8 |
|
|
// Description:
|
| 9 |
|
|
// This file contains the light8080 SOC interrupt controller. The controller
|
| 10 |
|
|
// supports 4 external interrupt requests with fixed interrupt vector addresses.
|
| 11 |
|
|
// The interrupt vectors code is implemented in the "intr_vec.h" file included in
|
| 12 |
|
|
// the projects C directory.
|
| 13 |
|
|
// Note that the controller clears the interrupt request after the CPU read the
|
| 14 |
|
|
// interrupt vector.
|
| 15 |
|
|
//
|
| 16 |
|
|
// Revision History:
|
| 17 |
|
|
//
|
| 18 |
|
|
// Rev <revnumber> <Date> <owner>
|
| 19 |
|
|
// <comment>
|
| 20 |
|
|
//
|
| 21 |
|
|
//---------------------------------------------------------------------------------------
|
| 22 |
|
|
//
|
| 23 |
|
|
// Copyright (C) 2012 Moti Litochevski
|
| 24 |
|
|
//
|
| 25 |
|
|
// This source file may be used and distributed without restriction provided that this
|
| 26 |
|
|
// copyright statement is not removed from the file and that any derivative work
|
| 27 |
|
|
// contains the original copyright notice and the associated disclaimer.
|
| 28 |
|
|
//
|
| 29 |
|
|
// THIS SOURCE FILE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
|
| 30 |
|
|
// INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
|
| 31 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
| 32 |
|
|
//
|
| 33 |
|
|
//---------------------------------------------------------------------------------------
|
| 34 |
|
|
|
| 35 |
|
|
module intr_ctrl
|
| 36 |
|
|
(
|
| 37 |
|
|
clock, reset,
|
| 38 |
|
|
ext_intr, cpu_intr,
|
| 39 |
|
|
cpu_inte, cpu_inta,
|
| 40 |
|
|
cpu_rd, cpu_inst,
|
| 41 |
|
|
intr_ena
|
| 42 |
|
|
);
|
| 43 |
|
|
//---------------------------------------------------------------------------------------
|
| 44 |
|
|
// module interfaces
|
| 45 |
|
|
// global signals
|
| 46 |
|
|
input clock; // global clock input
|
| 47 |
|
|
input reset; // global reset input
|
| 48 |
|
|
// external interrupt sources
|
| 49 |
|
|
// least significant bit has the highest priority, most significant bit has the lowest
|
| 50 |
|
|
// priority.
|
| 51 |
|
|
input [3:0] ext_intr; // active high
|
| 52 |
|
|
// CPU interface
|
| 53 |
|
|
output cpu_intr; // CPU interrupt request
|
| 54 |
|
|
input cpu_inte; // CPU interrupt enable - just to mask
|
| 55 |
|
|
input cpu_inta; // CPU interrupt acknowledge
|
| 56 |
|
|
input cpu_rd; // CPU read signal
|
| 57 |
|
|
output [7:0] cpu_inst; // interrupt calling instruction
|
| 58 |
|
|
|
| 59 |
|
|
// interrupt enable register
|
| 60 |
|
|
input [3:0] intr_ena; // set high to enable respective interrupt
|
| 61 |
|
|
|
| 62 |
|
|
//---------------------------------------------------------------------------------------
|
| 63 |
|
|
// 8080 assembly code constants
|
| 64 |
88 |
motilito |
// RST instruction opcode used to call interrupt routines at addresses
|
| 65 |
|
|
// int0: 0x08 / int1: 0x18 / int2: 0x28 / int3: 0x38
|
| 66 |
|
|
`define RST_1_INST 8'hcf
|
| 67 |
|
|
`define RST_3_INST 8'hdf
|
| 68 |
|
|
`define RST_5_INST 8'hef
|
| 69 |
|
|
`define RST_7_INST 8'hff
|
| 70 |
66 |
motilito |
|
| 71 |
|
|
//---------------------------------------------------------------------------------------
|
| 72 |
|
|
// internal declarations
|
| 73 |
|
|
// registered output
|
| 74 |
|
|
reg [7:0] cpu_inst;
|
| 75 |
|
|
|
| 76 |
|
|
// internals
|
| 77 |
|
|
reg [1:0] intSq, intSel;
|
| 78 |
|
|
reg [3:0] act_int, int_clr;
|
| 79 |
|
|
reg [7:0] int_vec;
|
| 80 |
|
|
|
| 81 |
|
|
//---------------------------------------------------------------------------------------
|
| 82 |
|
|
// module implementation
|
| 83 |
|
|
// main interrupt controller control process
|
| 84 |
|
|
always @ (posedge reset or posedge clock)
|
| 85 |
|
|
begin
|
| 86 |
|
|
if (reset)
|
| 87 |
|
|
begin
|
| 88 |
|
|
intSq <= 2'b0;
|
| 89 |
|
|
intSel <= 2'b0;
|
| 90 |
|
|
cpu_inst <= 8'b0;
|
| 91 |
|
|
end
|
| 92 |
|
|
else
|
| 93 |
|
|
begin
|
| 94 |
|
|
// interrupt controller state machine
|
| 95 |
|
|
case (intSq)
|
| 96 |
|
|
2'd0: // idle state - wait for active interrupt
|
| 97 |
|
|
if ((act_int != 4'b0) && cpu_inte)
|
| 98 |
|
|
begin
|
| 99 |
|
|
// latch the index of the active interrupt according to priority
|
| 100 |
|
|
if (act_int[0]) intSel <= 2'd0;
|
| 101 |
|
|
else if (act_int[2]) intSel <= 2'd1;
|
| 102 |
|
|
else if (act_int[3]) intSel <= 2'd2;
|
| 103 |
|
|
else intSel <= 2'd3;
|
| 104 |
|
|
// switch to next state
|
| 105 |
|
|
intSq <= 2'd1;
|
| 106 |
|
|
end
|
| 107 |
88 |
motilito |
2'd1: // wait for inta read cycle
|
| 108 |
66 |
motilito |
if (cpu_inta && cpu_rd)
|
| 109 |
|
|
begin
|
| 110 |
88 |
motilito |
// update instruction opcode
|
| 111 |
|
|
cpu_inst <= int_vec;
|
| 112 |
|
|
// switch to end for inta release
|
| 113 |
|
|
intSq <= 2'd2;
|
| 114 |
66 |
motilito |
end
|
| 115 |
88 |
motilito |
default: // wait for inta end
|
| 116 |
|
|
if (!cpu_inta)
|
| 117 |
66 |
motilito |
begin
|
| 118 |
88 |
motilito |
// reset state machine
|
| 119 |
|
|
intSq <= 2'b0;
|
| 120 |
|
|
cpu_inst <= 8'b0;
|
| 121 |
66 |
motilito |
end
|
| 122 |
|
|
endcase
|
| 123 |
|
|
end
|
| 124 |
|
|
end
|
| 125 |
|
|
|
| 126 |
|
|
// assign interrupt vector address according to selected interrupt
|
| 127 |
|
|
always @ (intSel)
|
| 128 |
|
|
begin
|
| 129 |
|
|
case (intSel)
|
| 130 |
88 |
motilito |
2'd0: int_vec <= `RST_1_INST;
|
| 131 |
|
|
2'd1: int_vec <= `RST_3_INST;
|
| 132 |
|
|
2'd2: int_vec <= `RST_5_INST;
|
| 133 |
|
|
2'd3: int_vec <= `RST_7_INST;
|
| 134 |
66 |
motilito |
endcase
|
| 135 |
|
|
end
|
| 136 |
|
|
|
| 137 |
|
|
// latch active interrupt on rising edge
|
| 138 |
|
|
always @ (posedge reset or posedge clock)
|
| 139 |
|
|
begin
|
| 140 |
|
|
if (reset)
|
| 141 |
|
|
act_int <= 4'b0;
|
| 142 |
|
|
else
|
| 143 |
|
|
act_int <= (act_int & ~int_clr) | (ext_intr & intr_ena);
|
| 144 |
|
|
end
|
| 145 |
|
|
// CPU interrupt is asserted when at least one interrupt is active
|
| 146 |
|
|
assign cpu_intr = |act_int;
|
| 147 |
|
|
|
| 148 |
|
|
// clear serviced interrupt
|
| 149 |
|
|
always @ (cpu_inta or cpu_rd or intSq or intSel)
|
| 150 |
|
|
begin
|
| 151 |
88 |
motilito |
if (cpu_inta && cpu_rd && (intSq == 2'd1))
|
| 152 |
66 |
motilito |
begin
|
| 153 |
|
|
case (intSel)
|
| 154 |
|
|
2'd0: int_clr <= 4'b0001;
|
| 155 |
|
|
2'd1: int_clr <= 4'b0010;
|
| 156 |
|
|
2'd2: int_clr <= 4'b0100;
|
| 157 |
|
|
2'd3: int_clr <= 4'b1000;
|
| 158 |
|
|
endcase
|
| 159 |
|
|
end
|
| 160 |
|
|
else
|
| 161 |
|
|
int_clr <= 4'b0;
|
| 162 |
|
|
end
|
| 163 |
|
|
|
| 164 |
|
|
endmodule
|
| 165 |
|
|
//---------------------------------------------------------------------------------------
|
| 166 |
|
|
// Th.. Th.. Th.. Thats all folks !!!
|
| 167 |
|
|
//---------------------------------------------------------------------------------------
|