mirror of
https://github.com/YosysHQ/yosys
synced 2025-09-01 07:40:42 +00:00
initial import
This commit is contained in:
commit
7764d0ba1d
481 changed files with 54634 additions and 0 deletions
69
tests/simple/fsm.v
Normal file
69
tests/simple/fsm.v
Normal file
|
@ -0,0 +1,69 @@
|
|||
|
||||
// `define ASYNC_RESET
|
||||
|
||||
module test(clk, reset, button_a, button_b, red_a, green_a, red_b, green_b);
|
||||
|
||||
input clk, reset, button_a, button_b;
|
||||
output reg red_a, green_a, red_b, green_b;
|
||||
|
||||
(* gentb_constant = 0 *)
|
||||
wire reset;
|
||||
|
||||
integer state;
|
||||
reg [3:0] cnt;
|
||||
|
||||
`ifdef ASYNC_RESET
|
||||
always @(posedge clk, posedge reset)
|
||||
`else
|
||||
always @(posedge clk)
|
||||
`endif
|
||||
begin
|
||||
cnt <= 0;
|
||||
red_a <= 1;
|
||||
red_b <= 1;
|
||||
green_a <= 0;
|
||||
green_b <= 0;
|
||||
|
||||
if (reset)
|
||||
state <= 100;
|
||||
else
|
||||
case (state)
|
||||
100: begin
|
||||
if (button_a && !button_b)
|
||||
state <= 200;
|
||||
if (!button_a && button_b)
|
||||
state <= 300;
|
||||
end
|
||||
200: begin
|
||||
red_a <= 0;
|
||||
green_a <= 1;
|
||||
cnt <= cnt + 1;
|
||||
if (cnt == 5)
|
||||
state <= 210;
|
||||
end
|
||||
210: begin
|
||||
red_a <= 0;
|
||||
green_a <= cnt[0];
|
||||
cnt <= cnt + 1;
|
||||
if (cnt == 10)
|
||||
state <= 100;
|
||||
end
|
||||
300: begin
|
||||
red_b <= 0;
|
||||
green_b <= 1;
|
||||
cnt <= cnt + 1;
|
||||
if (cnt == 5)
|
||||
state <= 310;
|
||||
end
|
||||
310: begin
|
||||
red_b <= 0;
|
||||
green_b <= cnt[0];
|
||||
cnt <= cnt + 1;
|
||||
if (cnt == 10)
|
||||
state <= 100;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue