prod2u_mrdimm_final_e2e_tb.v 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. `timescale 1ns/1ps
  2. // Full E2E bit-level simulation testbench for MRDIMM Final Architecture.
  3. module prod2u_mrdimm_final_e2e_tb;
  4. localparam integer BIT_CLKS = 27; // 921600 baud @ 25 MHz
  5. reg clk = 1'b0;
  6. reg rst_n = 1'b0;
  7. reg rs232_rx = 1'b1;
  8. wire rs232_tx;
  9. reg [11:0] limit_lower_raw = 12'd0;
  10. reg [11:0] limit_upper_raw = 12'd0;
  11. reg hood_switch_in = 1'b0;
  12. wire buzzer_out;
  13. wire [23:0] ptc_pwm_out;
  14. wire [3:0] fan_pwm_out;
  15. wire motor_en_n;
  16. wire [11:0] motor_step_gate;
  17. wire [11:0] motor_dir_gate;
  18. wire x_step = motor_step_gate[0];
  19. wire x_dir = motor_dir_gate[0];
  20. wire y_step = motor_step_gate[1];
  21. wire y_dir = motor_dir_gate[1];
  22. wire z_step = motor_step_gate[2];
  23. wire z_dir = motor_dir_gate[2];
  24. always #20 clk = ~clk; // 25 MHz
  25. prod2u_mrdimm_final_top #(
  26. .CLOCK_HZ(25000000),
  27. .HOST_BAUD(921600),
  28. .BMC_BAUD(115200),
  29. .PWM_PERIOD_CLKS(5000),
  30. .PWM_CLKS_PER_PERCENT(50),
  31. .HOST_TIMEOUT_CYCLES(2500)
  32. ) dut (
  33. .sys_clk(clk),
  34. .host_rs232_rx(rs232_rx),
  35. .host_rs232_tx(rs232_tx),
  36. .host_ttl_rx(1'b1),
  37. .host_ttl_tx(),
  38. .bmc_rs232_rx(1'b1),
  39. .bmc_rs232_tx(),
  40. .temp_scl(),
  41. .temp_sda(),
  42. .limit_lower_raw(limit_lower_raw),
  43. .limit_upper_raw(limit_upper_raw),
  44. .ptc_pwm_out(ptc_pwm_out),
  45. .fan_pwm_out(fan_pwm_out),
  46. .motor_en_n(motor_en_n),
  47. .motor_step_gate(motor_step_gate),
  48. .motor_dir_gate(motor_dir_gate),
  49. .hood_switch_in(hood_switch_in),
  50. .buzzer_out(buzzer_out)
  51. );
  52. // Byte-wise CRC over TYPE, LENGTH and PAYLOAD (excludes header A5 5A)
  53. reg [7:0] frame_bytes [0:255];
  54. function [15:0] crc_over_frame;
  55. input integer count;
  56. integer i;
  57. integer b;
  58. reg [15:0] c;
  59. reg [7:0] d;
  60. begin
  61. c = 16'hFFFF;
  62. for (i = 2; i < count; i = i + 1) begin
  63. d = frame_bytes[i];
  64. for (b = 7; b >= 0; b = b - 1)
  65. c = (c[15] ^ d[b]) ? ({c[14:0], 1'b0} ^ 16'h1021)
  66. : {c[14:0], 1'b0};
  67. end
  68. crc_over_frame = c;
  69. end
  70. endfunction
  71. // UART TX to DUT
  72. task uart_send_byte;
  73. input [7:0] value;
  74. integer b;
  75. begin
  76. rs232_rx = 1'b0;
  77. repeat (BIT_CLKS) @(posedge clk);
  78. for (b = 0; b < 8; b = b + 1) begin
  79. rs232_rx = value[b];
  80. repeat (BIT_CLKS) @(posedge clk);
  81. end
  82. rs232_rx = 1'b1;
  83. repeat (BIT_CLKS) @(posedge clk);
  84. end
  85. endtask
  86. task uart_send_frame;
  87. input integer n;
  88. integer i;
  89. reg [15:0] c;
  90. begin
  91. c = crc_over_frame(n);
  92. for (i = 0; i < n; i = i + 1)
  93. uart_send_byte(frame_bytes[i]);
  94. uart_send_byte(c[7:0]);
  95. uart_send_byte(c[15:8]);
  96. end
  97. endtask
  98. // UART RX from DUT
  99. reg [7:0] rx_bytes [0:511];
  100. integer rx_count = 0;
  101. reg [3:0] rx_bit = 0;
  102. reg [7:0] rx_shift = 0;
  103. integer rx_clk_cnt = 0;
  104. reg rx_busy = 0;
  105. initial begin
  106. forever begin
  107. @(posedge clk);
  108. if (!rx_busy && rs232_tx === 1'b0) begin
  109. rx_busy = 1'b1;
  110. rx_clk_cnt = BIT_CLKS + (BIT_CLKS / 2) - 1;
  111. rx_bit = 0;
  112. end else if (rx_busy) begin
  113. if (rx_clk_cnt == 0) begin
  114. if (rx_bit < 8) begin
  115. rx_shift[rx_bit] = rs232_tx;
  116. rx_bit = rx_bit + 1;
  117. rx_clk_cnt = BIT_CLKS - 1;
  118. end else begin
  119. rx_bytes[rx_count] = rx_shift;
  120. rx_count = rx_count + 1;
  121. rx_busy = 1'b0;
  122. end
  123. end else begin
  124. rx_clk_cnt = rx_clk_cnt - 1;
  125. end
  126. end
  127. end
  128. end
  129. // Step edge counters
  130. integer x_steps_count = 0;
  131. integer y_steps_count = 0;
  132. integer z_steps_count = 0;
  133. always @(posedge x_step) x_steps_count = x_steps_count + 1;
  134. always @(posedge y_step) y_steps_count = y_steps_count + 1;
  135. always @(posedge z_step) z_steps_count = z_steps_count + 1;
  136. // Timeout guard
  137. initial begin
  138. #30000000; // 30ms simulation time
  139. $display("FATAL: Simulation timeout!");
  140. $fflush;
  141. $finish;
  142. end
  143. integer start_idx;
  144. integer i;
  145. initial begin
  146. $display("=== STARTING MRDIMM FINAL E2E TESTBENCH ===");
  147. $fflush;
  148. rst_n = 1'b0;
  149. limit_lower_raw = 3'b000;
  150. limit_upper_raw = 3'b000;
  151. repeat (100) @(posedge clk);
  152. rst_n = 1'b1;
  153. repeat (2000) @(posedge clk);
  154. // --------------------------------------------------------------------
  155. // TEST A: Legal GET_ALL at reset
  156. // --------------------------------------------------------------------
  157. $display("[TEST A] Sending GET_ALL request...");
  158. $fflush;
  159. frame_bytes[0] = 8'hA5;
  160. frame_bytes[1] = 8'h5A;
  161. frame_bytes[2] = 8'h02; // GET_ALL
  162. frame_bytes[3] = 8'h00; // LEN 0
  163. start_idx = rx_count;
  164. uart_send_frame(4);
  165. // Expect GET_ACK (6 bytes: A5 5A 82 00 F5 60) + GET_DATA (71 bytes: A5 5A 42 41 ... CRC)
  166. // Total bytes = 6 + 71 = 77 bytes
  167. wait(rx_count >= start_idx + 77);
  168. $display(" -> Received 77 bytes from GET_ALL");
  169. $fflush;
  170. // Verify GET_ACK
  171. if (rx_bytes[start_idx] !== 8'hA5 || rx_bytes[start_idx+1] !== 8'h5A ||
  172. rx_bytes[start_idx+2] !== 8'h82 || rx_bytes[start_idx+3] !== 8'h00) begin
  173. $fatal(1, "FAIL A: GET_ACK mismatch: %02h %02h %02h %02h",
  174. rx_bytes[start_idx], rx_bytes[start_idx+1], rx_bytes[start_idx+2], rx_bytes[start_idx+3]);
  175. end
  176. $display(" -> Verified GET_ACK (82 00)");
  177. $fflush;
  178. // Verify GET_DATA
  179. start_idx = start_idx + 6;
  180. if (rx_bytes[start_idx] !== 8'hA5 || rx_bytes[start_idx+1] !== 8'h5A ||
  181. rx_bytes[start_idx+2] !== 8'h42 || rx_bytes[start_idx+3] !== 8'h41) begin
  182. $fatal(1, "FAIL A: GET_DATA header mismatch: %02h %02h %02h %02h",
  183. rx_bytes[start_idx], rx_bytes[start_idx+1], rx_bytes[start_idx+2], rx_bytes[start_idx+3]);
  184. end
  185. // Check FAN 0..3 defaults = 20 (0x14) at payload 0..3 (indices start_idx+4 .. +7)
  186. if (rx_bytes[start_idx+4] !== 8'd20 || rx_bytes[start_idx+5] !== 8'd20 ||
  187. rx_bytes[start_idx+6] !== 8'd20 || rx_bytes[start_idx+7] !== 8'd20) begin
  188. $fatal(1, "FAIL A: fan defaults wrong");
  189. end
  190. // Check PTC 0..3 defaults = 0 at payload 4..7 (indices start_idx+8 .. +11)
  191. if (rx_bytes[start_idx+8] !== 8'd0 || rx_bytes[start_idx+9] !== 8'd0 ||
  192. rx_bytes[start_idx+10] !== 8'd0 || rx_bytes[start_idx+11] !== 8'd0) begin
  193. $fatal(1, "FAIL A: ptc defaults wrong");
  194. end
  195. // Check hood_switch (byte 63) and buzzer_state (byte 64) default to 0
  196. if (rx_bytes[start_idx+4+63] !== 8'd0 || rx_bytes[start_idx+4+64] !== 8'd0) begin
  197. $fatal(1, "FAIL A: hood/buzzer defaults wrong: hood=%h buzzer=%h",
  198. rx_bytes[start_idx+4+63], rx_bytes[start_idx+4+64]);
  199. end
  200. $display(" -> TEST A PASSED! GET_ACK and GET_DATA (65B) verified.");
  201. $fflush;
  202. // --------------------------------------------------------------------
  203. // TEST B: SET_ALL with PUSH_DOWN on Axis 0 (X) for 5 steps
  204. // --------------------------------------------------------------------
  205. $display("[TEST B] Sending SET_ALL: Axis 0 PUSH_DOWN 5 steps (half_period 20us)...");
  206. $fflush;
  207. frame_bytes[0] = 8'hA5;
  208. frame_bytes[1] = 8'h5A;
  209. frame_bytes[2] = 8'h01; // SET_ALL
  210. frame_bytes[3] = 8'd68; // LEN 68
  211. // Payload 0..3: FAN 20
  212. frame_bytes[4] = 8'd20; frame_bytes[5] = 8'd20; frame_bytes[6] = 8'd20; frame_bytes[7] = 8'd20;
  213. // Payload 4..7: PTC 0
  214. frame_bytes[8] = 8'd0; frame_bytes[9] = 8'd0; frame_bytes[10] = 8'd0; frame_bytes[11] = 8'd0;
  215. // Axis 0: payload 8..12 (frame_bytes 12..16)
  216. frame_bytes[12] = 8'h01; // action PUSH_DOWN
  217. frame_bytes[13] = 8'd5; // steps low
  218. frame_bytes[14] = 8'd0; // steps high
  219. frame_bytes[15] = 8'd20; // half_period low = 20 us
  220. frame_bytes[16] = 8'd0; // half_period high
  221. // Axis 1..11: NOTHING (0)
  222. for (i = 17; i < 4 + 68; i = i + 1) frame_bytes[i] = 8'd0;
  223. start_idx = rx_count;
  224. x_steps_count = 0;
  225. uart_send_frame(72);
  226. // Expect SET_ACK (6 bytes: A5 5A 81 00 A6 35)
  227. wait(rx_count >= start_idx + 6);
  228. if (rx_bytes[start_idx+2] !== 8'h81 || rx_bytes[start_idx+3] !== 8'h00) begin
  229. $fatal(1, "FAIL B: expected SET_ACK (81 00), got %02h %02h", rx_bytes[start_idx+2], rx_bytes[start_idx+3]);
  230. end
  231. $display(" -> Verified SET_ACK (81 00)");
  232. $fflush;
  233. // Expect MOTOR_DONE (10 bytes: A5 5A 50 04 <axis> <reason> <steps_lo> <steps_hi> <crc_lo> <crc_hi>)
  234. wait(rx_count >= start_idx + 6 + 10);
  235. start_idx = start_idx + 6;
  236. if (rx_bytes[start_idx+2] !== 8'h50 || rx_bytes[start_idx+3] !== 8'h04) begin
  237. $fatal(1, "FAIL B: expected MOTOR_DONE (50 04), got %02h %02h", rx_bytes[start_idx+2], rx_bytes[start_idx+3]);
  238. end
  239. $display(" -> Got MOTOR_DONE: axis=%0d, reason=%0d, steps_done=%0d",
  240. rx_bytes[start_idx+4], rx_bytes[start_idx+5], {rx_bytes[start_idx+7], rx_bytes[start_idx+6]});
  241. $fflush;
  242. if (rx_bytes[start_idx+4] !== 8'd0) $fatal(1, "FAIL B: wrong axis, expected 0");
  243. if (rx_bytes[start_idx+5] !== 8'd0) $fatal(1, "FAIL B: wrong reason, expected 0");
  244. if ({rx_bytes[start_idx+7], rx_bytes[start_idx+6]} !== 16'd5) $fatal(1, "FAIL B: wrong steps_done, expected 5");
  245. if (x_steps_count !== 5) $fatal(1, "FAIL B: x_step edge count mismatch, expected 5 got %0d", x_steps_count);
  246. $display(" -> TEST B PASSED! Exactly 5 pulses emitted on x_step and completed normally.");
  247. $fflush;
  248. // --------------------------------------------------------------------
  249. // TEST C: Limit switch triggered during motion on Axis 1 (Y)
  250. // --------------------------------------------------------------------
  251. $display("[TEST C] Sending SET_ALL: Axis 1 PUSH_DOWN 50 steps, tripping limit...");
  252. $fflush;
  253. // Axis 0: NOTHING
  254. frame_bytes[12] = 8'd0; frame_bytes[13] = 8'd0; frame_bytes[14] = 8'd0; frame_bytes[15] = 8'd0; frame_bytes[16] = 8'd0;
  255. // Axis 1: payload 13..17 (frame_bytes 17..21)
  256. frame_bytes[17] = 8'h01; // action PUSH_DOWN
  257. frame_bytes[18] = 8'd50; // 50 steps
  258. frame_bytes[19] = 8'd0;
  259. frame_bytes[20] = 8'd20; // 20 us
  260. frame_bytes[21] = 8'd0;
  261. start_idx = rx_count;
  262. y_steps_count = 0;
  263. uart_send_frame(72);
  264. // Wait for SET_ACK
  265. wait(rx_count >= start_idx + 6);
  266. $display(" -> Got SET_ACK, motor Y running...");
  267. $fflush;
  268. // Wait for 3 steps, then assert lower limit
  269. wait(y_steps_count >= 3);
  270. @(posedge clk);
  271. $display(" -> Asserting Axis 1 lower limit at y_steps_count=%0d", y_steps_count);
  272. $fflush;
  273. limit_lower_raw[1] = 1'b1;
  274. // Wait for MOTOR_DONE
  275. wait(rx_count >= start_idx + 6 + 10);
  276. start_idx = start_idx + 6;
  277. $display(" -> Got MOTOR_DONE: axis=%0d, reason=%0d, steps_done=%0d",
  278. rx_bytes[start_idx+4], rx_bytes[start_idx+5], {rx_bytes[start_idx+7], rx_bytes[start_idx+6]});
  279. $fflush;
  280. if (rx_bytes[start_idx+4] !== 8'd1) $fatal(1, "FAIL C: wrong axis, expected 1");
  281. if (rx_bytes[start_idx+5] !== 8'd1) $fatal(1, "FAIL C: wrong reason, expected 1 (lower limit)");
  282. if ({rx_bytes[start_idx+7], rx_bytes[start_idx+6]} !== y_steps_count) begin
  283. $fatal(1, "FAIL C: steps_done mismatch: got %0d, counted %0d",
  284. {rx_bytes[start_idx+7], rx_bytes[start_idx+6]}, y_steps_count);
  285. end
  286. $display(" -> TEST C PASSED! Limit aborted motion cleanly.");
  287. $fflush;
  288. limit_lower_raw[1] = 1'b0;
  289. // --------------------------------------------------------------------
  290. // TEST D: Blocked at start on Axis 2 (Z)
  291. // --------------------------------------------------------------------
  292. $display("[TEST D] Asserting upper limit on Axis 2, then sending PUSH_UP...");
  293. $fflush;
  294. limit_upper_raw[2] = 1'b1;
  295. repeat (100) @(posedge clk);
  296. // Axis 1: NOTHING
  297. frame_bytes[17] = 8'd0; frame_bytes[18] = 8'd0; frame_bytes[19] = 8'd0; frame_bytes[20] = 8'd0; frame_bytes[21] = 8'd0;
  298. // Axis 2: payload 18..22 (frame_bytes 22..26)
  299. frame_bytes[22] = 8'h02; // PUSH_UP
  300. frame_bytes[23] = 8'd50; // 50 steps
  301. frame_bytes[24] = 8'd0;
  302. frame_bytes[25] = 8'd20; // 20 us
  303. frame_bytes[26] = 8'd0;
  304. start_idx = rx_count;
  305. z_steps_count = 0;
  306. uart_send_frame(72);
  307. // Wait for SET_ACK + MOTOR_DONE (16 bytes)
  308. wait(rx_count >= start_idx + 16);
  309. $display(" -> Got SET_ACK and MOTOR_DONE");
  310. start_idx = start_idx + 6;
  311. $display(" -> MOTOR_DONE: axis=%0d, reason=%0d, steps_done=%0d",
  312. rx_bytes[start_idx+4], rx_bytes[start_idx+5], {rx_bytes[start_idx+7], rx_bytes[start_idx+6]});
  313. $fflush;
  314. if (rx_bytes[start_idx+4] !== 8'd2) $fatal(1, "FAIL D: wrong axis, expected 2");
  315. if (rx_bytes[start_idx+5] !== 8'd2) $fatal(1, "FAIL D: wrong reason, expected 2 (upper limit)");
  316. if ({rx_bytes[start_idx+7], rx_bytes[start_idx+6]} !== 16'd0) $fatal(1, "FAIL D: expected 0 steps done");
  317. if (z_steps_count !== 0) $fatal(1, "FAIL D: z_step emitted pulses when blocked!");
  318. $display(" -> TEST D PASSED! Emitted 0 pulses when blocked at start.");
  319. $fflush;
  320. limit_upper_raw[2] = 1'b0;
  321. // --------------------------------------------------------------------
  322. // TEST E: STOP_CLEAR on Axis 0
  323. // --------------------------------------------------------------------
  324. $display("[TEST E] Starting long move on Axis 0, then issuing STOP_CLEAR...");
  325. $fflush;
  326. // Axis 2: NOTHING
  327. frame_bytes[22] = 8'd0; frame_bytes[23] = 8'd0; frame_bytes[24] = 8'd0; frame_bytes[25] = 8'd0; frame_bytes[26] = 8'd0;
  328. // Axis 0: 1000 steps
  329. frame_bytes[12] = 8'h01; // PUSH_DOWN
  330. frame_bytes[13] = 8'hE8; // 1000 steps low
  331. frame_bytes[14] = 8'h03; // 1000 steps high
  332. frame_bytes[15] = 8'd20; // 20 us
  333. frame_bytes[16] = 8'd0;
  334. start_idx = rx_count;
  335. x_steps_count = 0;
  336. uart_send_frame(72);
  337. wait(rx_count >= start_idx + 6);
  338. $display(" -> Got SET_ACK, motor running...");
  339. $fflush;
  340. wait(x_steps_count >= 5);
  341. $display(" -> Sending STOP_CLEAR (action=0xFF) for Axis 0...");
  342. $fflush;
  343. frame_bytes[12] = 8'hFF; // STOP_CLEAR
  344. frame_bytes[13] = 8'd0; frame_bytes[14] = 8'd0; frame_bytes[15] = 8'd0; frame_bytes[16] = 8'd0;
  345. start_idx = rx_count;
  346. uart_send_frame(72);
  347. wait(rx_count >= start_idx + 6);
  348. $display(" -> Got SET_ACK for STOP_CLEAR");
  349. $fflush;
  350. repeat (2000) @(posedge clk);
  351. if (x_step !== 1'b0) $fatal(1, "FAIL E: x_step not low after STOP_CLEAR");
  352. $display(" -> TEST E PASSED! Motor stopped immediately and queue cleared.");
  353. $fflush;
  354. // --------------------------------------------------------------------
  355. // TEST F: V3.2.0 69-byte SET_ALL (buzzer=1, 4000Hz 80% duty) + hood_switch on GET_ALL
  356. // --------------------------------------------------------------------
  357. $display("[TEST F] Testing 69B SET_ALL buzzer 4000Hz 80%% ON/OFF + hood_switch on GET_ALL...");
  358. $fflush;
  359. frame_bytes[0] = 8'hA5;
  360. frame_bytes[1] = 8'h5A;
  361. frame_bytes[2] = 8'h01; // SET_ALL
  362. frame_bytes[3] = 8'd69; // LEN 69 (with buzzer byte 68)
  363. for (i = 4; i < 4 + 69; i = i + 1) frame_bytes[i] = 8'd0;
  364. frame_bytes[4] = 8'd20; frame_bytes[5] = 8'd20; frame_bytes[6] = 8'd20; frame_bytes[7] = 8'd20;
  365. frame_bytes[4 + 68] = 8'd1; // buzzer ON
  366. start_idx = rx_count;
  367. uart_send_frame(73);
  368. wait(rx_count >= start_idx + 6);
  369. if (rx_bytes[start_idx+2] !== 8'h81) $fatal(1, "FAIL F: expected SET_ACK for 69B SET_ALL");
  370. repeat (50) @(posedge clk);
  371. begin : check_mr_bz_on
  372. integer bz_hi, bz_lo, bz_k;
  373. bz_hi = 0; bz_lo = 0;
  374. for (bz_k = 0; bz_k < 6250; bz_k = bz_k + 1) begin
  375. @(posedge clk);
  376. if (buzzer_out === 1'b1) bz_hi = bz_hi + 1;
  377. else if (buzzer_out === 1'b0) bz_lo = bz_lo + 1;
  378. end
  379. if (bz_hi !== 5000 || bz_lo !== 1250)
  380. $fatal(1, "FAIL F: buzzer_out 4000Hz 80%% mismatch: high=%0d low=%0d", bz_hi, bz_lo);
  381. end
  382. // Press hood_switch_in and verify GET_ALL reports hood=1, buzzer=1
  383. hood_switch_in = 1'b1;
  384. repeat (20) @(posedge clk);
  385. frame_bytes[0] = 8'hA5; frame_bytes[1] = 8'h5A;
  386. frame_bytes[2] = 8'h02; frame_bytes[3] = 8'h00;
  387. start_idx = rx_count;
  388. uart_send_frame(4);
  389. wait(rx_count >= start_idx + 77);
  390. start_idx = start_idx + 6;
  391. if (rx_bytes[start_idx+3] !== 8'h41 ||
  392. rx_bytes[start_idx+4+63] !== 8'd1 || rx_bytes[start_idx+4+64] !== 8'd1) begin
  393. $fatal(1, "FAIL F: expected hood=1 buzzer=1, got len=%0d hood=%h buzzer=%h",
  394. rx_bytes[start_idx+3], rx_bytes[start_idx+4+63], rx_bytes[start_idx+4+64]);
  395. end
  396. // Release hood_switch and turn buzzer OFF via 69B SET_ALL
  397. hood_switch_in = 1'b0;
  398. frame_bytes[0] = 8'hA5; frame_bytes[1] = 8'h5A;
  399. frame_bytes[2] = 8'h01; frame_bytes[3] = 8'd69;
  400. for (i = 4; i < 4 + 69; i = i + 1) frame_bytes[i] = 8'd0;
  401. frame_bytes[4] = 8'd20; frame_bytes[5] = 8'd20; frame_bytes[6] = 8'd20; frame_bytes[7] = 8'd20;
  402. frame_bytes[4 + 68] = 8'd0; // buzzer OFF
  403. start_idx = rx_count;
  404. uart_send_frame(73);
  405. wait(rx_count >= start_idx + 6);
  406. repeat (50) @(posedge clk);
  407. if (buzzer_out !== 1'b0) $fatal(1, "FAIL F: buzzer_out did not clear to LOW");
  408. $display(" -> TEST F PASSED! Buzzer ON/OFF & hood_switch GET_ALL verified.");
  409. $fflush;
  410. // --------------------------------------------------------------------
  411. // ALL TESTS PASSED!
  412. // --------------------------------------------------------------------
  413. $display("\n==================================================");
  414. $display("PROD2U MRDIMM FINAL E2E TESTBENCH: ALL TESTS PASS!");
  415. $display("prod2u_mrdimm_final_e2e_tb PASS");
  416. $display("==================================================");
  417. $fflush;
  418. $finish;
  419. end
  420. endmodule