Skip to content

Instantly share code, notes, and snippets.

@simias
Created December 5, 2016 17:04
Show Gist options
  • Select an option

  • Save simias/f168437a841df4952d5d53deee111ad7 to your computer and use it in GitHub Desktop.

Select an option

Save simias/f168437a841df4952d5d53deee111ad7 to your computer and use it in GitHub Desktop.
`default_nettype none
module psx_timer #(parameter WIDTH = 16)
(input clk,
input aresetn,
input [WIDTH - 1:0] target,
input reset_on_target,
input irq_on_target,
input irq_ack,
input [WIDTH - 1:0] counter_value,
input counter_w,
output reg [WIDTH - 1:0] counter,
output reg irq);
always @(posedge clk or negedge aresetn) begin
if (~aresetn)
irq <= 0;
else begin
if (irq_ack)
irq <= 0;
else if (irq_on_target && counter == target)
irq <= 1;
else if (& counter)
irq <= 1;
else
irq <= irq;
end
end
always @(posedge clk or negedge aresetn) begin
if (~aresetn)
counter <= 0;
else begin
if (counter_w)
counter <= counter_value;
else if (reset_on_target && counter == target)
counter <= 0;
else if (& counter)
counter <= 0;
else
counter <= counter + 1;
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment