prod2u_mrdimm_uart_e2e_tb.v 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. `include "tests/sim/motor_control_hold_monitor.vh"
  2. `timescale 1ns/1ps
  3. // UART-level end-to-end test for the mrdimm-chamber product stack over the
  4. // unified 16-bit-length protocol: real UART byte timing -> frame_rx ->
  5. // mrdimm_host_command -> mrdimm_output_core + motor_engine. Vectors are
  6. // generated by the independent Python codec (hth_protocol).
  7. module prod2u_mrdimm_uart_e2e_tb;
  8. localparam integer CLKS = 8;
  9. reg clk = 1'b0;
  10. reg rst_n = 1'b0;
  11. reg rx = 1'b1;
  12. reg tick_us = 1'b0;
  13. reg tick_1s = 1'b0;
  14. reg [2:0] limit_lower_raw = 3'b000;
  15. reg [2:0] limit_upper_raw = 3'b000;
  16. wire frame_valid, frame_ready, frame_accept_enable;
  17. wire [7:0] frame_type;
  18. wire [15:0] frame_length;
  19. wire [15:0] payload_rd_addr;
  20. wire [7:0] payload_rd_data;
  21. wire payload_wr_en;
  22. wire [15:0] payload_wr_addr;
  23. wire [7:0] payload_wr_data;
  24. wire thermal_wr_en, thermal_commit, thermal_commit_done, thermal_commit_ok;
  25. wire [2:0] thermal_wr_addr;
  26. wire [7:0] thermal_wr_data;
  27. wire keepalive_reload, snapshot_capture, snapshot_ready;
  28. wire qw_byte_we, qw_submit, qw_accept, ctl_valid, ctl_accept;
  29. wire [6:0] qw_byte_addr;
  30. wire [7:0] qw_byte_data, qw_status, ctl_status;
  31. wire [3:0] qw_count;
  32. wire [15:0] qw_detail, ctl_detail;
  33. wire [2:0] ctl_op;
  34. wire [15:0] ctl_axis_mask;
  35. wire [7:0] ctl_flags;
  36. wire [31:0] ctl_value;
  37. wire [7:0] ev_rd_index_w;
  38. wire ev_hold;
  39. wire [3:0] ev_rd_byte_index;
  40. wire [7:0] ev_rd_byte_data;
  41. wire ev_view_ready;
  42. wire [7:0] ev_view_count;
  43. wire [7:0] ev_count, ev_overflow;
  44. wire [31:0] ev_time_us;
  45. wire ev_clear_n_w;
  46. wire [7:0] ev_clear_count_w;
  47. wire [7:0] status_byte_in;
  48. wire tx_start, tx_done;
  49. wire [7:0] tx_frame_type, tx_payload_data;
  50. wire [15:0] tx_payload_length;
  51. wire host_command_busy;
  52. wire [3:0] fan_on, ptc_on;
  53. wire [7:0] applied_fan0;
  54. wire [2:0] step_bus, dir_bus;
  55. wire host_response_done_w;
  56. integer commits, acks;
  57. reg in_data_phase;
  58. reg [15:0] data_len_seen;
  59. always #1 clk = ~clk;
  60. // Accelerated wall clock, but the production25 clocks per microsecond
  61. // and one-clock enable are preserved for motor/snapshot scheduling.
  62. integer tick_divider=0;
  63. always @(negedge clk)begin
  64. if(!rst_n)begin tick_divider=0;tick_us=0;end
  65. else if(tick_divider==24)begin tick_divider=0;tick_us=1;end
  66. else begin tick_divider=tick_divider+1;tick_us=0;end
  67. end
  68. uart_rx_byte #(.CLKS_PER_BIT(CLKS)) u_uart_rx (
  69. .clk(clk), .rst_n(rst_n), .rx_i(rx),
  70. .byte_valid(), .byte_data(), .framing_error()
  71. );
  72. // Byte-level feeder shared by frame_rx: reuse uart_rx_byte output via
  73. // explicit wires (declared above as internal names).
  74. wire uart_rx_valid_w;
  75. wire [7:0] uart_rx_data_w;
  76. wire uart_framing_error_w;
  77. uart_rx_byte #(.CLKS_PER_BIT(CLKS)) u_host_rx (
  78. .clk(clk), .rst_n(rst_n), .rx_i(rx),
  79. .byte_valid(uart_rx_valid_w), .byte_data(uart_rx_data_w),
  80. .framing_error(uart_framing_error_w)
  81. );
  82. frame_rx #(.MAX_PAYLOAD(256), .INTER_BYTE_TIMEOUT_CYCLES(400), .EXTERNAL_CRC(1)) u_frame_rx (
  83. .clk(clk), .rst_n(rst_n), .byte_valid(uart_rx_valid_w),
  84. .byte_data(uart_rx_data_w), .accept_enable(frame_accept_enable),
  85. .frame_valid(frame_valid), .frame_ready(frame_ready),
  86. .frame_type(frame_type), .frame_length(frame_length),
  87. .payload_read_addr(payload_rd_addr), .payload_read_data(payload_rd_data),
  88. .payload_wr_en(payload_wr_en), .payload_wr_addr(payload_wr_addr),
  89. .payload_wr_data(payload_wr_data),
  90. .crc_start_o(crc_start_w), .crc_data_valid_o(crc_dv_w), .crc_data_o(crc_byte_w),
  91. .crc_busy_i(host_crc_busy_w), .crc_data_done_i(crc_done_w), .crc_value_i(crc_val_w)
  92. );
  93. wire qw_stage_active_w;
  94. wire [6:0] qw_stage_addr_w;
  95. wire [7:0] active_payload_rd_addr = qw_stage_active_w ?
  96. (8'd1 + {1'b0, qw_stage_addr_w}) : payload_rd_addr[7:0];
  97. payload_ram #(.DEPTH(256), .ADDR_WIDTH(8)) u_payload (
  98. .clk(clk), .wr_en(payload_wr_en), .wr_addr(payload_wr_addr),
  99. .wr_data(payload_wr_data), .rd_addr(active_payload_rd_addr), .rd_data(payload_rd_data)
  100. );
  101. wire host_crc_busy_w, crc_start_w, crc_dv_w, crc_done_w;
  102. wire [7:0] crc_byte_w;
  103. wire [15:0] crc_val_w;
  104. crc16_serial u_crc (
  105. .clk(clk), .rst_n(rst_n),
  106. .start(crc_start_w), .data_valid(crc_dv_w),
  107. .data(crc_byte_w), .busy(host_crc_busy_w),
  108. .data_done(crc_done_w), .crc(crc_val_w)
  109. );
  110. mrdimm_host_command #(.SNAPSHOT_LENGTH(352)) dut (
  111. .clk(clk), .rst_n(rst_n),
  112. .frame_valid(frame_valid), .frame_ready(frame_ready),
  113. .frame_accept_enable(frame_accept_enable), .frame_type(frame_type),
  114. .frame_length(frame_length),
  115. .payload_read_addr(payload_rd_addr), .payload_read_data(payload_rd_data),
  116. .thermal_wr_en(thermal_wr_en), .thermal_wr_addr(thermal_wr_addr),
  117. .thermal_wr_data(thermal_wr_data), .thermal_commit(thermal_commit),
  118. .thermal_commit_done(thermal_commit_done), .thermal_commit_ok(thermal_commit_ok),
  119. .lease_active(lease_active_w), .keepalive_reload(keepalive_reload),
  120. .snapshot_capture(snapshot_capture), .snapshot_ready(snapshot_ready),
  121. .qw_byte_we(qw_byte_we), .qw_byte_addr(qw_byte_addr),
  122. .qw_byte_data(qw_byte_data), .qw_submit(qw_submit), .qw_count(qw_count),
  123. .qw_accept(qw_accept), .qw_status(qw_status), .qw_detail(qw_detail),
  124. .qw_stage_active(qw_stage_active_w),
  125. .ctl_valid(ctl_valid), .ctl_op(ctl_op), .ctl_axis_mask(ctl_axis_mask),
  126. .ctl_flags(ctl_flags), .ctl_value(ctl_value),
  127. .ctl_accept(ctl_accept), .ctl_status(ctl_status), .ctl_detail(ctl_detail),
  128. .ev_rd_index(ev_rd_index_w), .ev_hold(ev_hold),
  129. .ev_rd_byte_index(ev_rd_byte_index),.ev_rd_byte_data(ev_rd_byte_data), .ev_count(ev_count), .ev_overflow(ev_overflow),
  130. .ev_view_ready(ev_view_ready), .ev_view_count(ev_view_count),
  131. .ev_clear_n(ev_clear_n_w), .ev_clear_count(ev_clear_count_w),
  132. .status_byte_in(status_byte_in),
  133. .tx_payload_addr(u_frame_tx.payload_addr),
  134. .ack_payload_data(), .tx_payload_data(tx_payload_data),
  135. .tx_start(tx_start), .tx_frame_type(tx_frame_type),
  136. .tx_payload_length(tx_payload_length), .tx_done(host_response_done_w),
  137. .transaction_done(), .busy(host_command_busy)
  138. );
  139. wire lease_active_w;
  140. wire [7:0] applied_fan [0:3];
  141. wire [7:0] applied_ptc [0:3];
  142. wire [7:0] watchdog_remaining_w;
  143. wire [31:0] applied_fan_packed;
  144. assign applied_fan[0]=applied_fan_packed[0*8 +:8];
  145. assign applied_fan[1]=applied_fan_packed[1*8 +:8];
  146. assign applied_fan[2]=applied_fan_packed[2*8 +:8];
  147. assign applied_fan[3]=applied_fan_packed[3*8 +:8];
  148. wire [31:0] applied_ptc_packed;
  149. assign applied_ptc[0]=applied_ptc_packed[0*8 +:8];
  150. assign applied_ptc[1]=applied_ptc_packed[1*8 +:8];
  151. assign applied_ptc[2]=applied_ptc_packed[2*8 +:8];
  152. assign applied_ptc[3]=applied_ptc_packed[3*8 +:8];
  153. mrdimm_output_core #(
  154. .LEASE_SECONDS(8'd30), .PWM_PERIOD_CLKS(1000), .PWM_CLKS_PER_PERCENT(10)
  155. ) u_output (
  156. .clk(clk), .rst_n(rst_n), .tick_1s(tick_1s),
  157. .wr_en(thermal_wr_en), .wr_addr(thermal_wr_addr), .wr_data(thermal_wr_data),
  158. .commit(thermal_commit), .commit_done(thermal_commit_done),
  159. .commit_ok(thermal_commit_ok), .keepalive_reload(keepalive_reload),
  160. .applied_fan(applied_fan_packed), .applied_ptc(applied_ptc_packed),
  161. .manual_active(), .lease_active(lease_active_w),
  162. .watchdog_remaining(watchdog_remaining_w),
  163. .fan_pwm_on(fan_on), .ptc_pwm_on(ptc_on)
  164. );
  165. wire [1535:0] axis_telemetry;
  166. wire [4:0] status_word_addr;
  167. wire [3:0] status_axis;
  168. wire [15:0] status_word_data;
  169. wire [31:0] unused_time;
  170. motor_engine #(
  171. .AXIS_COUNT(3),
  172. .X_DEFAULT_HALF_US(32'd500), .Y_DEFAULT_HALF_US(32'd500), .Z_DEFAULT_HALF_US(32'd20000),
  173. .X_MIN_HALF_US(32'd500), .Y_MIN_HALF_US(32'd500), .Z_MIN_HALF_US(32'd20000),
  174. .DIR_SETUP_TICKS(1000),
  175. .EXTERNAL_STAGE_RAM(1)
  176. ) u_motor (
  177. .clk(clk), .rst_n(rst_n), .tick_us(tick_us),
  178. .limit_lower_raw(limit_lower_raw), .limit_upper_raw(limit_upper_raw),
  179. .qw_byte_we(qw_byte_we), .qw_byte_addr(qw_byte_addr),
  180. .qw_byte_data(qw_byte_data), .qw_submit(qw_submit), .qw_count(qw_count),
  181. .qw_accept(qw_accept), .qw_status(qw_status), .qw_detail(qw_detail),
  182. .qw_stage_addr(qw_stage_addr_w), .qw_stage_data(payload_rd_data),
  183. .ctl_valid(ctl_valid), .ctl_op(ctl_op), .ctl_axis_mask(ctl_axis_mask),
  184. .ctl_flags(ctl_flags), .ctl_value(ctl_value),
  185. .ctl_accept(ctl_accept), .ctl_status(ctl_status), .ctl_detail(ctl_detail),
  186. .startup_seek(1'b0),
  187. .ev_rd_index(ev_rd_index_w), .ev_hold(ev_hold),
  188. .ev_rd_data(),.ev_rd_byte_index(ev_rd_byte_index),.ev_rd_byte_data(ev_rd_byte_data), .ev_count(ev_count), .ev_overflow(ev_overflow),
  189. .ev_view_ready(ev_view_ready), .ev_view_count(ev_view_count),
  190. .ev_time_us(unused_time),
  191. .ev_clear_n(ev_clear_n_w), .ev_clear_count(ev_clear_count_w),
  192. .axis_telemetry(axis_telemetry),
  193. .telemetry_word_addr(status_word_addr),.telemetry_axis(status_axis),.telemetry_word_data(status_word_data),
  194. .step_out(step_bus), .dir_out(dir_bus)
  195. );
  196. mrdimm_snapshot_mux #(.SCANNER_WORD_PORT(1)) u_snapshot (
  197. .clk(clk),.rst_n(rst_n),.capture(snapshot_capture),.source_ready(u_motor.motor_telemetry_ready),.source_epoch(u_motor.motor_status_epoch),.ready(snapshot_ready),.locked(),
  198. .bmc_locked_bank(),.ct_locked_bank(),
  199. .fan_applied({applied_fan[3],applied_fan[2],applied_fan[1],applied_fan[0]}),
  200. .ptc_applied({applied_ptc[3],applied_ptc[2],applied_ptc[1],applied_ptc[0]}),
  201. .fan_requested({applied_fan[3],applied_fan[2],applied_fan[1],applied_fan[0]}),
  202. .ptc_requested({applied_ptc[3],applied_ptc[2],applied_ptc[1],applied_ptc[0]}),
  203. .watchdog_active(lease_active_w),.watchdog_remaining(watchdog_remaining_w),
  204. .bmc_active_bank(1'b0),.ct_active_bank(1'b0),.bmc_stale(1'b1),.ct_stale(1'b1),
  205. .bmc_epoch(16'd0),.ct_epoch(16'd0),.bmc_age(16'd0),.ct_age(16'd0),
  206. .bmc_valid_mask(24'd0),.ct_valid_mask(27'd0),.bmc_rd_index(),.ct_rd_index(),
  207. .bmc_rd_raw(16'd0),.ct_rd_raw(16'd0),.axis_data(axis_telemetry),
  208. .scanner_axis(status_axis),.scanner_word_data(status_word_data),.scanner_word_addr(status_word_addr),
  209. .time_us(unused_time),.time_high(32'd0),.event_overflow(32'd0),
  210. .event_pending_overflow(32'd0),.ev_count(ev_count),.global_flags(32'd0),
  211. .read_addr(frame_tx_payload_addr_w[9:0]),.read_data(status_byte_in)
  212. );
  213. // frame_tx consumes the command core payload for ACK/DATA lengths.
  214. wire frame_tx_done_w, frame_tx_busy_w, frame_tx_byte_valid_w;
  215. wire [7:0] frame_tx_byte_data_w;
  216. wire [15:0] frame_tx_payload_addr_w;
  217. frame_tx #(.PAYLOAD_IDX_BITS(10), .EXTERNAL_CRC(0), .PAYLOAD_READ_LATENCY(1)) u_frame_tx (
  218. .clk(clk), .rst_n(rst_n), .start(tx_start), .frame_type(tx_frame_type),
  219. .payload_length(tx_payload_length), .busy(frame_tx_busy_w),
  220. .byte_valid(frame_tx_byte_valid_w), .byte_data(frame_tx_byte_data_w),
  221. .byte_ready(1'b1), .payload_addr(frame_tx_payload_addr_w),
  222. .payload_data(tx_payload_data), .done(frame_tx_done_w),
  223. .crc_start_o(), .crc_data_valid_o(), .crc_data_o(),
  224. .crc_busy_i(1'b0), .crc_data_done_i(), .crc_value_i()
  225. );
  226. assign host_response_done_w = frame_tx_done_w;
  227. // ---- UART byte feeder (shared for all frames) ----
  228. task send_byte;
  229. input [7:0] value;
  230. integer k;
  231. begin
  232. rx = 1'b0;
  233. repeat (CLKS) @(posedge clk);
  234. for (k = 0; k < 8; k = k + 1) begin
  235. rx = value[k];
  236. repeat (CLKS) @(posedge clk);
  237. end
  238. rx = 1'b1;
  239. repeat (CLKS) @(posedge clk);
  240. end
  241. endtask
  242. initial begin
  243. commits = 0; acks = 0;
  244. forever begin
  245. @(posedge clk);
  246. if (thermal_commit) commits = commits + 1;
  247. if (tx_start && tx_frame_type==8'h80) begin
  248. acks = acks + 1;
  249. if (tx_frame_type !== 8'h80)
  250. $fatal(1, "frame %02x is not an ACK", tx_frame_type);
  251. if (tx_payload_length !== 16'd4)
  252. $fatal(1, "ACK payload length %0d", tx_payload_length);
  253. end
  254. end
  255. end
  256. initial begin
  257. wait (rst_n);
  258. // ---- SET_ALL fan20/ptc0, endpoints FF (no motor touch) ----
  259. send_byte(8'hA5); send_byte(8'h5A); send_byte(8'h01);
  260. send_byte(8'h0B); send_byte(8'h00);
  261. send_byte(8'h14); send_byte(8'h14); send_byte(8'h14); send_byte(8'h14);
  262. send_byte(8'h00); send_byte(8'h00); send_byte(8'h00); send_byte(8'h00);
  263. send_byte(8'hFF); send_byte(8'hFF); send_byte(8'hFF);
  264. send_byte(8'h89); send_byte(8'h04);
  265. repeat (2000) @(posedge clk);
  266. if (commits !== 1) $fatal(1, "SET_ALL commits=%0d", commits);
  267. if (acks !== 1) $fatal(1, "SET_ALL acks=%0d", acks);
  268. if (applied_fan[0] !== 8'd20) $fatal(1, "fan duty not applied");
  269. if (u_motor.ax_active[0] !== 1'b0)
  270. $fatal(1, "FF endpoint must not touch motors");
  271. // ---- SET_ALL with X=lower endpoint: commit + engine accepted ----
  272. send_byte(8'hA5); send_byte(8'h5A); send_byte(8'h01);
  273. send_byte(8'h0B); send_byte(8'h00);
  274. send_byte(8'h14); send_byte(8'h14); send_byte(8'h14); send_byte(8'h14);
  275. send_byte(8'h00); send_byte(8'h00); send_byte(8'h00); send_byte(8'h00);
  276. send_byte(8'hFF); send_byte(8'h00); send_byte(8'hFF);
  277. send_byte(8'h76); send_byte(8'h07);
  278. repeat (3000) @(posedge clk);
  279. if (commits !== 2) $fatal(1, "X-low commits=%0d", commits);
  280. if (u_motor.ax_active[0] !== 1'b1)
  281. $fatal(1, "X seek not accepted");
  282. if (u_motor.u_axes.r_mode[0] !== 3'd1)
  283. $fatal(1, "X must run seek_lower");
  284. // ---- bad CRC: silent ----
  285. send_byte(8'hA5); send_byte(8'h5A); send_byte(8'h01);
  286. send_byte(8'h0B); send_byte(8'h00);
  287. send_byte(8'h14); send_byte(8'h14); send_byte(8'h14); send_byte(8'h14);
  288. send_byte(8'h00); send_byte(8'h00); send_byte(8'h00); send_byte(8'h00);
  289. send_byte(8'hFF); send_byte(8'hFF); send_byte(8'hFF);
  290. send_byte(8'h89); send_byte(8'hFB);
  291. repeat (1000) @(posedge clk);
  292. if (commits !== 2) $fatal(1, "bad CRC committed");
  293. if (acks !== 2) $fatal(1, "bad CRC acked");
  294. // ---- MOTOR_QUEUE_WRITE with count=0: BAD_LENGTH NACK ----
  295. send_byte(8'hA5); send_byte(8'h5A); send_byte(8'h03);
  296. send_byte(8'h11); send_byte(8'h00);
  297. for (int j = 0; j < 17; j = j + 1) send_byte(8'h00);
  298. send_byte(8'h2F); send_byte(8'h46);
  299. repeat (2000) @(posedge clk);
  300. if (acks !== 3) $fatal(1, "QW acks=%0d", acks);
  301. if (commits !== 2) $fatal(1, "QW must not commit");
  302. // ---- KEEPALIVE contract vector: ACK only ----
  303. send_byte(8'hA5); send_byte(8'h5A); send_byte(8'h05);
  304. send_byte(8'h00); send_byte(8'h00);
  305. send_byte(8'h6C); send_byte(8'h27);
  306. repeat (500) @(posedge clk);
  307. if (acks !== 4) $fatal(1, "keepalive acks=%0d", acks);
  308. if (commits !== 2) $fatal(1, "keepalive must not commit");
  309. // ---- GET_ALL while a real seek is active: ACK then81 DATA(352B) ----
  310. wait(step_bus[0]);
  311. send_byte(8'hA5); send_byte(8'h5A); send_byte(8'h02);
  312. send_byte(8'h00); send_byte(8'h00);
  313. send_byte(8'hFC); send_byte(8'hA2);
  314. wait(response_checks==6);@(negedge clk);
  315. if (data_len_seen !== 16'd352) $fatal(1, "ALL_STATUS length %0d", data_len_seen);
  316. if (response_checks!==6) $fatal(1,"incomplete serialized responses: %0d",response_checks);
  317. // Abort the running X seek, then read its stable event through 80/83.
  318. send_byte(8'hA5);send_byte(8'h5A);send_byte(8'h04);send_byte(8'h08);send_byte(0);
  319. send_byte(1);send_byte(1);repeat(6) send_byte(0);send_byte(8'hB1);send_byte(8'h30);
  320. repeat(1000) @(posedge clk);
  321. if(u_motor.ax_active[0] || acks!=6) $fatal(1,"control abort transaction");
  322. send_byte(8'hA5);send_byte(8'h5A);send_byte(8'h08);send_byte(1);send_byte(0);
  323. send_byte(8);send_byte(8'h3B);send_byte(8'hB7);
  324. repeat(2000) @(posedge clk);
  325. if(response_checks!=9 || acks!=7) $fatal(1,"EVENT_READ did not complete ACK plus DATA");
  326. send_byte(8'hA5);send_byte(8'h5A);send_byte(4);send_byte(8);send_byte(0);
  327. send_byte(8);send_byte(1);repeat(6)send_byte(0);send_byte(8'hB8);send_byte(8'h69);
  328. repeat(1000)@(posedge clk);
  329. if(response_checks!=10 || acks!=8)$fatal(1,"invalid MOTOR_CONTROL did not NACK");
  330. $display("prod2u_mrdimm_uart_e2e_tb PASS");
  331. $finish;
  332. end
  333. // track the DATA phase length of GET_ALL responses
  334. always @(posedge clk) begin
  335. if (tx_start && tx_frame_type == 8'h81) data_len_seen <= tx_payload_length;
  336. end
  337. // Independently inspect the actual serializer bytes. Counting tx_start
  338. // alone would miss a one-bit payload bus or DATA being sent in an ACK.
  339. reg [7:0] response_bytes [0:1023];
  340. integer response_count=0, response_checks=0, rb, bitno;
  341. reg [15:0] crc_check;
  342. always @(posedge clk) begin
  343. if (frame_tx_byte_valid_w) begin
  344. response_bytes[response_count]=frame_tx_byte_data_w;
  345. response_count=response_count+1;
  346. end
  347. if (frame_tx_done_w) begin
  348. if(response_count != 7+{response_bytes[4],response_bytes[3]})
  349. $fatal(1,"response length does not match wire bytes");
  350. crc_check=16'hFFFF;
  351. for(rb=2;rb<response_count-2;rb=rb+1) begin
  352. crc_check=crc_check ^ {response_bytes[rb],8'd0};
  353. for(bitno=0;bitno<8;bitno=bitno+1)
  354. crc_check=crc_check[15] ? (crc_check<<1)^16'h1021 : crc_check<<1;
  355. end
  356. if(crc_check !== {response_bytes[response_count-1],response_bytes[response_count-2]})
  357. $fatal(1,"response CRC mismatch");
  358. if(response_bytes[2]==8'h80) begin
  359. if(response_bytes[5] !== ((acks<=2) ? 8'h01 : (acks==3 ? 8'h03 : (acks==4 ? 8'h05 : (acks==5 ? 8'h02 : (acks==7 ? 8'h08 : 8'h04))))))
  360. $fatal(1,"ACK request type corrupted: %02x",response_bytes[5]);
  361. if(response_bytes[6] !== (acks==3 ? 8'd2 : (acks==8 ? 8'd3 : 8'd0)))
  362. $fatal(1,"ACK business status corrupted: %02x",response_bytes[6]);
  363. end else if(response_bytes[2]==8'h81) begin
  364. if(acks!=5) $fatal(1,"DATA preceded its ACK");
  365. end else if(response_bytes[2]==8'h83) begin
  366. if(acks!=7 || response_bytes[5]!=2 || response_bytes[10]!=8'hFF || response_bytes[11]!=6 ||
  367. response_bytes[26]!=0 || response_bytes[27]!=4)
  368. $fatal(1,"EVENT payload count/axis/code corruption");
  369. end else $fatal(1,"unexpected response type");
  370. response_checks=response_checks+1;response_count=0;
  371. end
  372. end
  373. initial begin #1000000; $fatal(1,"MRDIMM e2e deadline");end
  374. initial begin
  375. clk = 1'b0;
  376. repeat (4) @(posedge clk);
  377. rst_n = 1'b1;
  378. end
  379. motor_control_hold_monitor control_hold(clk,rst_n,ctl_valid,ctl_accept,ctl_op,ctl_axis_mask,ctl_flags,ctl_value);
  380. held_payload_monitor ack_hold(clk,rst_n,tx_start && tx_frame_type==8'h80,host_response_done_w,
  381. {dut.ack_detail,dut.ack_status,dut.ack_request});
  382. endmodule