6400_transport_identification_properties_formal.v 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Command-level Identification proof. Physical UART serialization and its
  2. // final Stop Bit remain covered by source inspection and full-UART Cocotb;
  3. // this harness proves command admission, atomic stimulus commit, ACK metadata,
  4. // repeat handling, and silent invalid-command retirement.
  5. module thermal_6400_transport_identification_properties_formal (
  6. input wire clk,
  7. input wire rst_n
  8. );
  9. (* anyseq *) reg frame_valid;
  10. (* anyseq *) reg [7:0] frame_type;
  11. (* anyseq *) reg [7:0] frame_length;
  12. (* anyseq *) reg snapshot_ready;
  13. (* anyseq *) reg tx_done;
  14. // Every request in one proof trace uses the same payload case. Case zero
  15. // is valid duration=2 / duty=50, case one has duration zero, and cases two
  16. // and three contain a duty of 101. All four anyconst values therefore have
  17. // an explicit semantic class without an extra proof assumption.
  18. (* anyconst *) reg [1:0] payload_case;
  19. wire frame_ready;
  20. wire frame_accept_enable;
  21. wire [7:0] payload_read_addr;
  22. reg [7:0] payload_read_data;
  23. wire target_commit;
  24. wire [7:0] target_celsius;
  25. wire stimulus_wr_en;
  26. wire [4:0] stimulus_wr_addr;
  27. wire [7:0] stimulus_wr_data;
  28. wire stimulus_commit;
  29. wire [7:0] stimulus_duration_seconds;
  30. wire snapshot_capture;
  31. wire tx_start;
  32. wire [7:0] tx_frame_type;
  33. wire [7:0] tx_payload_length;
  34. wire transaction_done;
  35. wire command_busy;
  36. wire [3:0] formal_state;
  37. wire [5:0] formal_index;
  38. wire formal_stimulus_bad;
  39. wire bank_commit_applied;
  40. wire stimulus_bank_active;
  41. (* anyconst *) reg [4:0] formal_bank_address;
  42. wire [7:0] formal_active_stimulus_data;
  43. always @* begin
  44. if (payload_read_addr == 0)
  45. payload_read_data = (payload_case == 1) ? 8'd0 : 8'd2;
  46. else if (payload_case[1] && payload_read_addr == 17)
  47. payload_read_data = 8'd101;
  48. else
  49. payload_read_data = 8'd50;
  50. end
  51. thermal_host_command #(.ENABLE_STIMULUS(1), .SNAPSHOT_LENGTH(193)) u_command (
  52. .clk(clk), .rst_n(rst_n), .frame_valid(frame_valid), .frame_ready(frame_ready),
  53. .frame_accept_enable(frame_accept_enable), .frame_type(frame_type),
  54. .frame_length(frame_length), .payload_read_addr(payload_read_addr),
  55. .payload_read_data(payload_read_data), .target_commit(target_commit),
  56. .target_celsius(target_celsius), .stimulus_wr_en(stimulus_wr_en),
  57. .stimulus_wr_addr(stimulus_wr_addr), .stimulus_wr_data(stimulus_wr_data),
  58. .stimulus_commit(stimulus_commit),
  59. .stimulus_duration_seconds(stimulus_duration_seconds),
  60. .snapshot_capture(snapshot_capture), .snapshot_ready(snapshot_ready),
  61. .tx_start(tx_start), .tx_frame_type(tx_frame_type),
  62. .tx_payload_length(tx_payload_length), .tx_done(tx_done),
  63. .transaction_done(transaction_done), .busy(command_busy),
  64. .formal_state_o(formal_state), .formal_index_o(formal_index),
  65. .formal_stimulus_bad_o(formal_stimulus_bad)
  66. );
  67. // Real Identification command-to-storage wiring. Physical UART
  68. // serialization and its final Stop Bit are deliberately outside this
  69. // command-level proof and remain covered by full-UART Cocotb.
  70. stimulus_atomic_bank u_stimulus_bank (
  71. .clk(clk), .rst_n(rst_n),
  72. .write_enable(stimulus_wr_en),
  73. .write_address(stimulus_wr_addr),
  74. .write_data(stimulus_wr_data),
  75. .stimulus_commit(stimulus_commit),
  76. .commit_applied(bank_commit_applied),
  77. .active_bank(stimulus_bank_active),
  78. .read_bank(stimulus_bank_active),
  79. .read_address(formal_bank_address),
  80. .read_data(formal_active_stimulus_data)
  81. );
  82. wire command_accept = frame_valid && frame_ready && frame_accept_enable;
  83. wire stimulus_shape = frame_type == 8'h03 && frame_length == 8'd33;
  84. wire legal_stimulus_accept = command_accept && stimulus_shape && payload_case == 0;
  85. wire invalid_payload_accept = command_accept && stimulus_shape && payload_case != 0;
  86. wire supported_shape =
  87. (frame_type == 8'h01 && frame_length == 8'd1) ||
  88. (frame_type == 8'h02 && frame_length == 8'd0) || stimulus_shape;
  89. wire invalid_shape_accept = command_accept && !supported_shape;
  90. wire invalid_stimulus_length_accept = command_accept &&
  91. frame_type == 8'h03 && frame_length != 8'd33;
  92. wire unknown_type_accept = command_accept &&
  93. frame_type != 8'h01 && frame_type != 8'h02 && frame_type != 8'h03;
  94. reg [1:0] reset_cycles = 0;
  95. reg formal_past_valid = 0;
  96. reg legal_pending;
  97. reg invalid_pending;
  98. reg [5:0] pending_age;
  99. reg [31:0] writes_seen;
  100. reg completed_legal;
  101. reg repeat_pending;
  102. reg repeated_ack_seen;
  103. reg invalid_duration_silent_seen;
  104. reg invalid_duty_silent_seen;
  105. reg invalid_entry_bank;
  106. always @(posedge clk) begin
  107. formal_past_valid <= 1'b1;
  108. if (reset_cycles < 2) begin
  109. assume(!rst_n);
  110. reset_cycles <= reset_cycles + 1'b1;
  111. end else begin
  112. assume(rst_n);
  113. end
  114. if (!rst_n) begin
  115. legal_pending <= 1'b0;
  116. invalid_pending <= 1'b0;
  117. pending_age <= 0;
  118. writes_seen <= 0;
  119. completed_legal <= 1'b0;
  120. repeat_pending <= 1'b0;
  121. repeated_ack_seen <= 1'b0;
  122. invalid_duration_silent_seen <= 1'b0;
  123. invalid_duty_silent_seen <= 1'b0;
  124. invalid_entry_bank <= 1'b0;
  125. end else begin
  126. assume(formal_bank_address < 32);
  127. if (legal_stimulus_accept || invalid_payload_accept) begin
  128. assert(!legal_pending && !invalid_pending);
  129. legal_pending <= legal_stimulus_accept;
  130. invalid_pending <= invalid_payload_accept;
  131. pending_age <= 0;
  132. writes_seen <= 0;
  133. repeat_pending <= legal_stimulus_accept && completed_legal;
  134. if (invalid_payload_accept)
  135. invalid_entry_bank <= stimulus_bank_active;
  136. end else if (legal_pending || invalid_pending) begin
  137. pending_age <= pending_age + 1'b1;
  138. end
  139. if (stimulus_wr_en) begin
  140. assert(legal_pending || invalid_pending);
  141. assert(stimulus_wr_data <= 100);
  142. writes_seen[stimulus_wr_addr] <= 1'b1;
  143. assert(!stimulus_commit);
  144. end
  145. // The monitor age is an exact image of the deterministic command
  146. // pipeline. These invariants turn the bounded completion claim
  147. // into an inductive proof rather than a simulation-like timeout.
  148. if (legal_pending || invalid_pending) begin
  149. assert(pending_age <= 34);
  150. if (formal_state == 4'd3)
  151. assert(pending_age == 0);
  152. if (formal_state == 4'd4)
  153. assert(pending_age == formal_index);
  154. if (formal_state == 4'd5)
  155. assert(pending_age == 33);
  156. end
  157. if (legal_pending) begin
  158. assert(!formal_stimulus_bad);
  159. assert(formal_state == 4'd3 || formal_state == 4'd4 ||
  160. formal_state == 4'd5 || formal_state == 4'd6);
  161. if (formal_state == 4'd6) begin
  162. assert(pending_age == 34);
  163. assert(stimulus_commit);
  164. assert(tx_start && tx_frame_type == 8'h83 && tx_payload_length == 0);
  165. end
  166. end
  167. if (invalid_pending) begin
  168. assert(formal_state == 4'd3 || formal_state == 4'd4 ||
  169. formal_state == 4'd5 || formal_state == 4'd7);
  170. assert(!stimulus_commit);
  171. assert(!(tx_start && tx_frame_type == 8'h83));
  172. assert(stimulus_bank_active == invalid_entry_bank);
  173. if (formal_state == 4'd7) begin
  174. assert(pending_age == 34);
  175. assert(transaction_done);
  176. end
  177. end
  178. // A legal request becomes visible atomically only after all 32
  179. // duty bytes have been admitted. The independent ACK starts from
  180. // that same commit edge and always has zero payload length.
  181. if (stimulus_commit || (tx_start && tx_frame_type == 8'h83)) begin
  182. assert(legal_pending);
  183. assert(writes_seen == 32'hFFFF_FFFF);
  184. assert(stimulus_duration_seconds == 2);
  185. assert(stimulus_commit);
  186. assert(bank_commit_applied);
  187. assert(tx_start && tx_frame_type == 8'h83 && tx_payload_length == 0);
  188. legal_pending <= 1'b0;
  189. completed_legal <= 1'b1;
  190. if (repeat_pending)
  191. repeated_ack_seen <= 1'b1;
  192. repeat_pending <= 1'b0;
  193. end
  194. if (repeat_pending)
  195. assert(legal_pending);
  196. if (formal_past_valid && $past(rst_n)) begin
  197. if ($past(stimulus_wr_en)) begin
  198. assert(stimulus_bank_active == $past(stimulus_bank_active));
  199. assert(formal_active_stimulus_data ==
  200. $past(formal_active_stimulus_data));
  201. end
  202. if ($past(bank_commit_applied)) begin
  203. assert(stimulus_bank_active != $past(stimulus_bank_active));
  204. end
  205. if (!$past(bank_commit_applied))
  206. assert(stimulus_bank_active == $past(stimulus_bank_active));
  207. end
  208. if (invalid_pending && transaction_done) begin
  209. invalid_pending <= 1'b0;
  210. if (payload_case == 1)
  211. invalid_duration_silent_seen <= 1'b1;
  212. if (payload_case[1])
  213. invalid_duty_silent_seen <= 1'b1;
  214. end
  215. // Wrong lengths and unknown request types retire immediately and
  216. // silently. Bad CRC remains proved through frame_rx in the
  217. // unchanged Production transport harness.
  218. if (formal_past_valid && $past(rst_n) &&
  219. $past(invalid_shape_accept)) begin
  220. assert(transaction_done);
  221. assert(!tx_start);
  222. assert(!stimulus_commit);
  223. end
  224. cover(repeated_ack_seen);
  225. cover(formal_past_valid && $past(bank_commit_applied) &&
  226. stimulus_bank_active != $past(stimulus_bank_active) &&
  227. formal_active_stimulus_data == 8'd50);
  228. cover(invalid_duration_silent_seen);
  229. cover(invalid_duty_silent_seen);
  230. cover(formal_past_valid && $past(invalid_stimulus_length_accept) &&
  231. transaction_done && !tx_start);
  232. cover(formal_past_valid && $past(unknown_type_accept) &&
  233. transaction_done && !tx_start);
  234. end
  235. end
  236. endmodule