architecture_ab_candidates.v 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. `timescale 1ns/1ps
  2. // Isolated, synthesisable architecture candidates for the eight remaining
  3. // 6400 resource A/B decisions. These modules are not part of a product source
  4. // closure. They intentionally expose the same observable transaction for
  5. // each pair so simulation/formal checks can precede resource comparison.
  6. module ab_fsm_binary (
  7. input wire clk, input wire rst_n, input wire advance, input wire recover,
  8. output reg [2:0] state_code
  9. );
  10. always @(posedge clk or negedge rst_n) begin
  11. if (!rst_n) state_code <= 3'd0;
  12. else if (recover) state_code <= 3'd0;
  13. else if (advance) begin
  14. case (state_code)
  15. 3'd0: state_code <= 3'd1;
  16. 3'd1: state_code <= 3'd2;
  17. 3'd2: state_code <= 3'd3;
  18. 3'd3: state_code <= 3'd4;
  19. 3'd4: state_code <= 3'd5;
  20. 3'd5: state_code <= 3'd6;
  21. default: state_code <= 3'd0;
  22. endcase
  23. end
  24. end
  25. endmodule
  26. module ab_fsm_onehot (
  27. input wire clk, input wire rst_n, input wire advance, input wire recover,
  28. output reg [2:0] state_code, output wire [6:0] raw_state
  29. );
  30. (* fsm_encoding = "one-hot" *) reg [6:0] state;
  31. assign raw_state = state;
  32. always @* begin
  33. case (state)
  34. 7'b0000001: state_code = 3'd0;
  35. 7'b0000010: state_code = 3'd1;
  36. 7'b0000100: state_code = 3'd2;
  37. 7'b0001000: state_code = 3'd3;
  38. 7'b0010000: state_code = 3'd4;
  39. 7'b0100000: state_code = 3'd5;
  40. 7'b1000000: state_code = 3'd6;
  41. default: state_code = 3'd0;
  42. endcase
  43. end
  44. always @(posedge clk or negedge rst_n) begin
  45. if (!rst_n) state <= 7'b0000001;
  46. else if (recover) state <= 7'b0000001;
  47. else if (advance) begin
  48. case (state)
  49. 7'b0000001: state <= 7'b0000010;
  50. 7'b0000010: state <= 7'b0000100;
  51. 7'b0000100: state <= 7'b0001000;
  52. 7'b0001000: state <= 7'b0010000;
  53. 7'b0010000: state <= 7'b0100000;
  54. 7'b0100000: state <= 7'b1000000;
  55. default: state <= 7'b0000001;
  56. endcase
  57. end
  58. end
  59. endmodule
  60. // Dedicated serializers preserve simultaneous Host response and BMC poll
  61. // progress. The shared candidate is smaller but intentionally exposes its
  62. // single-owner limitation so the concurrency test can reject it on function.
  63. module ab_bmc_tx_dedicated (
  64. input wire clk, input wire rst_n,
  65. input wire host_start, input wire [7:0] host_data,
  66. input wire bmc_start, input wire [7:0] bmc_data,
  67. output wire host_bit, output wire bmc_bit,
  68. output wire host_busy, output wire bmc_busy
  69. );
  70. reg [7:0] host_shift;
  71. reg [7:0] bmc_shift;
  72. reg [3:0] host_left;
  73. reg [3:0] bmc_left;
  74. assign host_bit = host_left == 0 ? 1'b1 : host_shift[0];
  75. assign bmc_bit = bmc_left == 0 ? 1'b1 : bmc_shift[0];
  76. assign host_busy = host_left != 0;
  77. assign bmc_busy = bmc_left != 0;
  78. always @(posedge clk or negedge rst_n) begin
  79. if (!rst_n) begin
  80. host_shift <= 0; bmc_shift <= 0; host_left <= 0; bmc_left <= 0;
  81. end else begin
  82. if (host_start && host_left == 0) begin host_shift <= host_data; host_left <= 8; end
  83. else if (host_left != 0) begin host_shift <= {1'b1, host_shift[7:1]}; host_left <= host_left - 1'b1; end
  84. if (bmc_start && bmc_left == 0) begin bmc_shift <= bmc_data; bmc_left <= 8; end
  85. else if (bmc_left != 0) begin bmc_shift <= {1'b1, bmc_shift[7:1]}; bmc_left <= bmc_left - 1'b1; end
  86. end
  87. end
  88. endmodule
  89. module ab_bmc_tx_shared (
  90. input wire clk, input wire rst_n,
  91. input wire host_start, input wire [7:0] host_data,
  92. input wire bmc_start, input wire [7:0] bmc_data,
  93. output wire host_bit, output wire bmc_bit,
  94. output wire host_busy, output wire bmc_busy
  95. );
  96. reg [7:0] shift;
  97. reg [3:0] left;
  98. reg owner_bmc;
  99. assign host_bit = (left != 0 && !owner_bmc) ? shift[0] : 1'b1;
  100. assign bmc_bit = (left != 0 && owner_bmc) ? shift[0] : 1'b1;
  101. assign host_busy = left != 0 && !owner_bmc;
  102. assign bmc_busy = left != 0 && owner_bmc;
  103. always @(posedge clk or negedge rst_n) begin
  104. if (!rst_n) begin shift <= 0; left <= 0; owner_bmc <= 0; end
  105. else if (left != 0) begin shift <= {1'b1, shift[7:1]}; left <= left - 1'b1; end
  106. else if (host_start) begin shift <= host_data; left <= 8; owner_bmc <= 0; end
  107. else if (bmc_start) begin shift <= bmc_data; left <= 8; owner_bmc <= 1; end
  108. end
  109. endmodule
  110. module ab_store_ff (
  111. input wire clk, input wire wr_en, input wire [7:0] wr_addr, input wire [7:0] wr_data,
  112. input wire [7:0] rd_addr, output reg [7:0] rd_data
  113. );
  114. (* ram_style = "registers", syn_ramstyle = "registers" *) reg [7:0] mem [0:255];
  115. always @(posedge clk) begin
  116. if (wr_en) mem[wr_addr] <= wr_data;
  117. rd_data <= mem[rd_addr];
  118. end
  119. endmodule
  120. module ab_store_eram (
  121. input wire clk, input wire wr_en, input wire [7:0] wr_addr, input wire [7:0] wr_data,
  122. input wire [7:0] rd_addr, output wire [7:0] rd_data
  123. );
  124. `ifdef PROD2U_TD_VENDOR_RAM
  125. wire [7:0] port_a_data;
  126. EF2_LOGIC_BRAM #(
  127. .DATA_WIDTH_A(8), .DATA_WIDTH_B(8),
  128. .ADDR_WIDTH_A(8), .ADDR_WIDTH_B(8),
  129. .DATA_DEPTH_A(256), .DATA_DEPTH_B(256),
  130. .BYTE_ENABLE(0), .BYTE_A(1), .BYTE_B(1),
  131. .MODE("DP"), .REGMODE_A("NOREG"), .REGMODE_B("NOREG"),
  132. .WRITEMODE_A("NORMAL"), .WRITEMODE_B("NORMAL"),
  133. .RESETMODE("ASYNC"), .IMPLEMENT("9K")
  134. ) u_ram (
  135. .dia(wr_data), .addra(wr_addr), .cea(1'b1), .ocea(1'b1),
  136. .clka(clk), .wea(wr_en), .rsta(1'b0), .bea(1'b1),
  137. .dib(8'd0), .addrb(rd_addr), .ceb(1'b1), .oceb(1'b1),
  138. .clkb(clk), .web(1'b0), .rstb(1'b0), .beb(1'b1),
  139. .doa(port_a_data), .dob(rd_data)
  140. );
  141. `else
  142. reg [7:0] mem [0:255];
  143. reg [7:0] rd_data_reg;
  144. assign rd_data = rd_data_reg;
  145. always @(posedge clk) begin
  146. if (wr_en) mem[wr_addr] <= wr_data;
  147. rd_data_reg <= mem[rd_addr];
  148. end
  149. `endif
  150. endmodule
  151. module ab_pi_positional #(
  152. parameter signed [15:0] KP = 16'sd3,
  153. parameter signed [15:0] KI = 16'sd1
  154. ) (
  155. input wire clk, input wire rst_n, input wire sample,
  156. input wire signed [15:0] error, output reg signed [31:0] control,
  157. output wire signed [31:0] integral_state
  158. );
  159. reg signed [31:0] integral;
  160. assign integral_state = integral;
  161. wire signed [31:0] p_term = KP * error;
  162. wire signed [31:0] i_term = KI * error;
  163. always @(posedge clk or negedge rst_n) begin
  164. if (!rst_n) begin integral <= 0; control <= 0; end
  165. else if (sample) begin
  166. integral <= integral + i_term;
  167. control <= p_term + integral + i_term;
  168. end
  169. end
  170. endmodule
  171. module ab_pi_incremental #(
  172. parameter signed [15:0] KP = 16'sd3,
  173. parameter signed [15:0] KI = 16'sd1
  174. ) (
  175. input wire clk, input wire rst_n, input wire sample,
  176. input wire signed [15:0] error, output reg signed [31:0] control,
  177. output wire signed [15:0] previous_error_state
  178. );
  179. reg signed [15:0] previous_error;
  180. assign previous_error_state = previous_error;
  181. wire signed [16:0] delta_error = error - previous_error;
  182. wire signed [32:0] p_delta = KP * delta_error;
  183. wire signed [31:0] p_delta_narrow = p_delta[31:0];
  184. wire signed [31:0] i_delta = KI * error;
  185. always @(posedge clk or negedge rst_n) begin
  186. if (!rst_n) begin previous_error <= 0; control <= 0; end
  187. else if (sample) begin
  188. control <= control + p_delta_narrow + i_delta;
  189. previous_error <= error;
  190. end
  191. end
  192. endmodule
  193. module ab_safety_parallel #(
  194. parameter [7:0] LIMIT = 8'd77
  195. ) (
  196. input wire clk, input wire rst_n,
  197. input wire wr_en, input wire [4:0] wr_index, input wire [7:0] wr_temperature,
  198. input wire start, output reg busy, output reg done, output reg [23:0] mask
  199. );
  200. reg [7:0] temperatures [0:23];
  201. integer i;
  202. always @(posedge clk or negedge rst_n) begin
  203. if (!rst_n) begin busy <= 0; done <= 0; mask <= 0; end
  204. else begin
  205. done <= 0;
  206. if (wr_en) temperatures[wr_index] <= wr_temperature;
  207. if (start) begin
  208. busy <= 1;
  209. for (i = 0; i < 24; i = i + 1) mask[i] <= temperatures[i] >= LIMIT;
  210. end else if (busy) begin busy <= 0; done <= 1; end
  211. end
  212. end
  213. endmodule
  214. module ab_safety_sequential #(
  215. parameter [7:0] LIMIT = 8'd77
  216. ) (
  217. input wire clk, input wire rst_n,
  218. input wire wr_en, input wire [4:0] wr_index, input wire [7:0] wr_temperature,
  219. input wire start, output reg busy, output reg done, output reg [23:0] mask
  220. );
  221. reg [7:0] temperatures [0:23];
  222. reg [4:0] index;
  223. always @(posedge clk or negedge rst_n) begin
  224. if (!rst_n) begin busy <= 0; done <= 0; mask <= 0; index <= 0; end
  225. else begin
  226. done <= 0;
  227. if (wr_en) temperatures[wr_index] <= wr_temperature;
  228. if (start && !busy) begin busy <= 1; index <= 0; end
  229. else if (busy) begin
  230. mask[index] <= temperatures[index] >= LIMIT;
  231. if (index == 23) begin busy <= 0; done <= 1; end
  232. else index <= index + 1'b1;
  233. end
  234. end
  235. end
  236. endmodule
  237. module ab_commit_copy (
  238. input wire clk, input wire rst_n,
  239. input wire wr_en, input wire [4:0] wr_index, input wire [15:0] wr_data,
  240. input wire commit, input wire [4:0] rd_index, output wire [15:0] rd_data
  241. );
  242. reg [15:0] staging [0:23];
  243. reg [15:0] active [0:23];
  244. integer i;
  245. assign rd_data = active[rd_index];
  246. always @(posedge clk or negedge rst_n) begin
  247. if (!rst_n) begin end
  248. else begin
  249. if (wr_en) staging[wr_index] <= wr_data;
  250. if (commit) for (i = 0; i < 24; i = i + 1) active[i] <= staging[i];
  251. end
  252. end
  253. endmodule
  254. module ab_commit_bank (
  255. input wire clk, input wire rst_n,
  256. input wire wr_en, input wire [4:0] wr_index, input wire [15:0] wr_data,
  257. input wire commit, input wire [4:0] rd_index, output wire [15:0] rd_data
  258. );
  259. reg [15:0] bank0 [0:23];
  260. reg [15:0] bank1 [0:23];
  261. reg active_bank;
  262. assign rd_data = active_bank ? bank1[rd_index] : bank0[rd_index];
  263. always @(posedge clk or negedge rst_n) begin
  264. if (!rst_n) active_bank <= 0;
  265. else begin
  266. if (wr_en) begin
  267. if (active_bank) bank0[wr_index] <= wr_data;
  268. else bank1[wr_index] <= wr_data;
  269. end
  270. if (commit) active_bank <= ~active_bank;
  271. end
  272. end
  273. endmodule
  274. module ab_crc_independent (
  275. input wire clk, input wire rst_n, input wire clear,
  276. input wire rx_valid, input wire [7:0] rx_data,
  277. input wire tx_valid, input wire [7:0] tx_data,
  278. output reg [15:0] rx_crc, output reg [15:0] tx_crc
  279. );
  280. function [15:0] next_crc;
  281. input [15:0] current; input [7:0] data;
  282. integer i; reg [15:0] value;
  283. begin
  284. value = current ^ {data, 8'h00};
  285. for (i = 0; i < 8; i = i + 1)
  286. value = value[15] ? (value << 1) ^ 16'h1021 : value << 1;
  287. next_crc = value;
  288. end
  289. endfunction
  290. always @(posedge clk or negedge rst_n) begin
  291. if (!rst_n) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
  292. else if (clear) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
  293. else begin
  294. if (rx_valid) rx_crc <= next_crc(rx_crc, rx_data);
  295. if (tx_valid) tx_crc <= next_crc(tx_crc, tx_data);
  296. end
  297. end
  298. endmodule
  299. module ab_crc_shared (
  300. input wire clk, input wire rst_n, input wire clear,
  301. input wire rx_valid, input wire [7:0] rx_data,
  302. input wire tx_valid, input wire [7:0] tx_data,
  303. output reg [15:0] rx_crc, output reg [15:0] tx_crc
  304. );
  305. function [15:0] next_crc;
  306. input [15:0] current; input [7:0] data;
  307. integer i; reg [15:0] value;
  308. begin
  309. value = current ^ {data, 8'h00};
  310. for (i = 0; i < 8; i = i + 1)
  311. value = value[15] ? (value << 1) ^ 16'h1021 : value << 1;
  312. next_crc = value;
  313. end
  314. endfunction
  315. wire select_rx = rx_valid;
  316. wire [15:0] selected_crc = select_rx ? rx_crc : tx_crc;
  317. wire [7:0] selected_data = select_rx ? rx_data : tx_data;
  318. wire [15:0] updated_crc = next_crc(selected_crc, selected_data);
  319. always @(posedge clk or negedge rst_n) begin
  320. if (!rst_n) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
  321. else if (clear) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
  322. else if (rx_valid) rx_crc <= updated_crc;
  323. else if (tx_valid) tx_crc <= updated_crc;
  324. end
  325. endmodule
  326. module ab_snapshot_copy (
  327. input wire clk, input wire rst_n, input wire capture, input wire [7:0] seed,
  328. input wire [7:0] rd_addr, output wire [7:0] rd_data
  329. );
  330. reg [7:0] snapshot [0:192];
  331. integer i;
  332. assign rd_data = snapshot[rd_addr];
  333. /* verilator lint_off BLKLOOPINIT */
  334. always @(posedge clk or negedge rst_n) begin
  335. if (!rst_n) begin end
  336. else if (capture)
  337. for (i = 0; i < 193; i = i + 1) snapshot[i] <= i[7:0] ^ seed;
  338. end
  339. /* verilator lint_on BLKLOOPINIT */
  340. endmodule
  341. module ab_snapshot_stream (
  342. input wire clk, input wire rst_n, input wire capture, input wire [7:0] seed,
  343. input wire [7:0] rd_addr, output wire [7:0] rd_data
  344. );
  345. reg [7:0] locked_seed;
  346. assign rd_data = rd_addr ^ locked_seed;
  347. always @(posedge clk or negedge rst_n) begin
  348. if (!rst_n) locked_seed <= 0;
  349. else if (capture) locked_seed <= seed;
  350. end
  351. endmodule