Skip to content

Instantly share code, notes, and snippets.

@Feder1co5oave
Created April 10, 2012 19:38
Show Gist options
  • Save Feder1co5oave/2353935 to your computer and use it in GitHub Desktop.
Save Feder1co5oave/2353935 to your computer and use it in GitHub Desktop.
module RS_PIC(p, reset_, intr, inta, index, irr7_irr0, reset_irr);
input p, reset_, inta;
input [7:0] irr7_irr0;
output intr;
output [7:0] reset_irr;
output [2:0] index;
reg [ :0] STAR;
reg [2:0] INDEX;
reg [7:0] RESET_IRR;
reg INTR;
assign intr = INTR;
assign reset_irr = RESET_IRR;
assign index = INDEX;
parameter S0 = ...
always @(posedge p or negedge reset_)
if (reset_ == 0) begin
STAR <= RS; INTR <= 0; RESET_IRR <= 'HFF;
end else
casex (STAR)
RS: STAR <= S0; // wait per un reset sicuro
S0: begin
RESET_IRR <= 0; INTR <= (irr7_irr0 == 'H00) ? 0 : 1;
INDEX <= priority_encoder(irr7_irr0);
STAR <= (inta == 1) ? S1 : S0; end
S1: begin
INTR <= 0; STAR <= (inta == 1) ? S1 : S2; end
S2: begin
RESET_IRR <= decoder(INDEX); STAR <= S0;
endcase
function [2:0] priority_encoder;
input [7:0] irr7_irr0;
casex (irr7_irr0)
'B???????1: priority_encoder = 'B000;
'B??????10: priority_encoder = 'B001;
'B?????100: priority_encoder = 'B010;
'B????1000: priority_encoder = 'B011;
'B???10000: priority_encoder = 'B100;
'B??100000: priority_encoder = 'B101;
'B?1000000: priority_encoder = 'B110;
'B10000000: priority_encoder = 'B111;
default: priority_encoder = 'BXXX;
endcase
endfunction
function [7:0] decoder;
input [2:0] INDEX;
casex (INDEX)
'B000: decoder = 'B00000001;
'B001: decoder = 'B00000010;
'B010: decoder = 'B00000100;
'B011: decoder = 'B00001000;
'B100: decoder = 'B00010000;
'B101: decoder = 'B00100000;
'B110: decoder = 'B01000000;
'B111: decoder = 'B10000000;
endcase
endfunction
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment