startup_close_seek_formal.v 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. module startup_close_seek_formal (
  2. input wire clk,
  3. input wire rst_n,
  4. input wire tick_500us,
  5. input wire [1:0] limit_sync
  6. );
  7. localparam integer FORMAL_MAX_BURSTS = 2;
  8. localparam integer FORMAL_INTER_BURST_TICKS = 2;
  9. localparam integer FORMAL_FIXED_STEPS = 2;
  10. localparam integer FORMAL_DIR_SETUP_TICKS = 1;
  11. localparam integer FORMAL_STEP_HALF_CYCLES = 2;
  12. localparam [1:0] FORMAL_DIR_MASK = 2'b11;
  13. wire startup_done;
  14. wire motor_start;
  15. wire [1:0] motor_active_mask;
  16. wire [1:0] motor_dir_mask;
  17. wire [1:0] motor_stop_mask;
  18. wire motor_done;
  19. reg [2:0] reset_cycles;
  20. reg [3:0] burst_counter;
  21. reg motor_busy;
  22. reg formal_sync_valid;
  23. // The synchronizer is modelled as invalid for the first three cycles after reset.
  24. always @(posedge clk or negedge rst_n) begin
  25. if (!rst_n) begin
  26. formal_sync_valid <= 1'b0;
  27. end else if (reset_cycles < 3) begin
  28. formal_sync_valid <= 1'b0;
  29. end else begin
  30. formal_sync_valid <= 1'b1;
  31. end
  32. end
  33. startup_close_seek #(
  34. .FIXED_STEPS(FORMAL_FIXED_STEPS),
  35. .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS),
  36. .STEP_HALF_CYCLES(FORMAL_STEP_HALF_CYCLES),
  37. .MAX_BURSTS(FORMAL_MAX_BURSTS),
  38. .INTER_BURST_TICKS(FORMAL_INTER_BURST_TICKS),
  39. .DIR_MASK(FORMAL_DIR_MASK)
  40. ) u_startup (
  41. .clk(clk),
  42. .rst_n(rst_n),
  43. .tick_500us(tick_500us),
  44. .limit_sync_valid(formal_sync_valid),
  45. .limit_sync(limit_sync),
  46. .startup_done(startup_done),
  47. .motor_start(motor_start),
  48. .motor_active_mask(motor_active_mask),
  49. .motor_dir_mask(motor_dir_mask),
  50. .motor_stop_mask(motor_stop_mask),
  51. .motor_done(motor_done)
  52. );
  53. // Fair motor model: when start is asserted, it becomes busy for a bounded
  54. // number of ticks and then asserts done for one cycle.
  55. reg [3:0] motor_count;
  56. always @(posedge clk or negedge rst_n) begin
  57. if (!rst_n) begin
  58. motor_busy <= 1'b0;
  59. motor_count <= 4'd0;
  60. end else begin
  61. if (motor_start && !motor_busy) begin
  62. motor_busy <= 1'b1;
  63. motor_count <= 4'd0;
  64. end else if (motor_busy) begin
  65. if (motor_count < FORMAL_FIXED_STEPS + FORMAL_DIR_SETUP_TICKS) begin
  66. motor_count <= motor_count + 1'b1;
  67. end else begin
  68. motor_busy <= 1'b0;
  69. end
  70. end
  71. end
  72. end
  73. assign motor_done = motor_busy && (motor_count == FORMAL_FIXED_STEPS + FORMAL_DIR_SETUP_TICKS);
  74. initial reset_cycles = 3'd0;
  75. always @(posedge clk) begin
  76. assume (rst_n == 1'b0 || rst_n == 1'b1);
  77. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  78. assume ((^limit_sync) == 1'b0 || (^limit_sync) == 1'b1);
  79. if ($initstate || reset_cycles < 3) begin
  80. assume (!rst_n);
  81. reset_cycles <= reset_cycles + 1'b1;
  82. end else begin
  83. assume (rst_n);
  84. end
  85. if (rst_n) begin
  86. // Once done, the module must stay done and inactive. Use $past so
  87. // the check observes the settled register values one cycle after the
  88. // transition into DONE, avoiding combinational-delta races between
  89. // the DUT and the witness assertions.
  90. if (!$initstate && $past(startup_done)) begin
  91. assert (startup_done);
  92. assert (motor_start == 1'b0);
  93. assert (motor_active_mask == 2'b00);
  94. assert (motor_dir_mask == 2'b00);
  95. // Post-calibration one-shot: stop mask to the motor engine is inert.
  96. assert (motor_stop_mask == 2'b00);
  97. end
  98. // Active mask is always a subset of the two axes and never changes
  99. // during a burst except at burst boundaries.
  100. assert (motor_active_mask == 2'b00 || motor_active_mask == 2'b01 ||
  101. motor_active_mask == 2'b10 || motor_active_mask == 2'b11);
  102. // Direction mask is either zero or the configured close direction.
  103. assert (motor_dir_mask == 2'b00 || motor_dir_mask == FORMAL_DIR_MASK);
  104. // motor_start is a single-cycle pulse.
  105. if ($past(motor_start)) assert (!motor_start);
  106. end
  107. end
  108. always @(posedge clk) begin
  109. cover (rst_n && startup_done);
  110. cover (rst_n && motor_active_mask == 2'b11);
  111. cover (rst_n && startup_done && limit_sync == 2'b00);
  112. cover (rst_n && startup_done && limit_sync == 2'b11);
  113. end
  114. endmodule