Guest User

Untitled

a guest
Nov 2nd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. class TestFSM(Module):
  2.     def __init__(self):
  3.         self.a = Signal()
  4.         self.b = Signal()
  5.         self.n = Signal()
  6.         fsm = FSM(reset_state="STATE0")
  7.         self.submodules += fsm
  8.        
  9.         fsm.act("STATE0",
  10.                self.a.eq(self.b),
  11.                If(self.n, NextState("STATE1")))
  12.        
  13.         fsm.act("STATE1",
  14.                If(~self.n, NextState("STATE0")))
  15.  
  16. dut = TestFSM()
  17. print(verilog.convert(dut))
  18.  
  19.  
  20. """
  21. --> OUTPUTS
  22. /* Machine-generated using Migen */
  23. module top(
  24.     input sys_clk,
  25.     input sys_rst
  26. );
  27.  
  28. reg a = 1'd0;
  29. reg b = 1'd0;
  30. reg n = 1'd0;
  31. reg state = 1'd0;
  32. reg next_state = 1'd0;
  33.  
  34. // synthesis translate_off
  35. reg dummy_s;
  36. initial dummy_s <= 1'd0;
  37. // synthesis translate_on
  38.  
  39. // synthesis translate_off
  40. reg dummy_d;
  41. // synthesis translate_on
  42. always @(*) begin
  43.     a <= 1'd0;
  44.     next_state <= 1'd0;
  45.     next_state <= state;
  46.     case (state)
  47.         1'd1: begin
  48.             if ((~n)) begin
  49.                 next_state <= 1'd0;
  50.             end
  51.         end
  52.         default: begin
  53.             a <= b;
  54.             if (n) begin
  55.                 next_state <= 1'd1;
  56.             end
  57.         end
  58.     endcase
  59. // synthesis translate_off
  60.     dummy_d <= dummy_s;
  61. // synthesis translate_on
  62. end
  63.  
  64. always @(posedge sys_clk) begin
  65.     if (sys_rst) begin
  66.         state <= 1'd0;
  67.     end else begin
  68.         state <= next_state;
  69.     end
  70. end
  71.  
  72. endmodule
  73. """
Advertisement
Add Comment
Please, Sign In to add comment