|
|
@@ -549,10 +549,22 @@ module motor_engine #(
|
|
|
// Both producers register the previous scan axis. The same rotating
|
|
|
// storage serves each independent write stream; unused upper bits vanish.
|
|
|
// u_done_history merged into u_history_brams
|
|
|
- // Reset clears owner validity, never exposing stale stored events.
|
|
|
+ // Reset clears owner validity, never exposing stale stored records.
|
|
|
always @(posedge clk)begin
|
|
|
if(PARALLEL_TELEMETRY && rst_n && (|ax_limit_pulse))limit_record[limit_write_axis]<={ax_limit_time_high,ax_limit_data};
|
|
|
end
|
|
|
+ // Sync-BRAM history returns data one cycle after the address is presented.
|
|
|
+ // A record written at edge W would read back stale (pre-write) data if the
|
|
|
+ // rotating head lands on that axis at W+1; defer that dispatch one rotation.
|
|
|
+ reg [AXIS_COUNT-1:0] history_fresh;
|
|
|
+ always @(posedge clk or negedge rst_n) begin
|
|
|
+ if(!rst_n) history_fresh <= {AXIS_COUNT{1'b0}};
|
|
|
+ else begin
|
|
|
+ history_fresh <= {AXIS_COUNT{1'b0}};
|
|
|
+ if(|ax_limit_pulse) history_fresh[limit_write_axis] <= 1'b1;
|
|
|
+ if(done_record_write) history_fresh[done_write_axis] <= 1'b1;
|
|
|
+ end
|
|
|
+ end
|
|
|
function [7:0] event_for_stop;
|
|
|
input [3:0] r;
|
|
|
begin
|
|
|
@@ -606,7 +618,7 @@ module motor_engine #(
|
|
|
if(ev_wr_req && ev_ack) ev_wr_req<=0;
|
|
|
else if(!ev_wr_req && reset_pending) begin
|
|
|
ev_wr_req<=1;ev_axis<=4'hF;ev_code<=6;ev_tag<=0;ev_pos<=0;ev_total<=0;ev_timestamp<=0;reset_pending<=0;
|
|
|
- end else if(!ev_wr_req && ev_select>=0 && event_dispatch_ready) begin
|
|
|
+ end else if(!ev_wr_req && ev_select>=0 && event_dispatch_ready && !history_fresh[ev_select]) begin
|
|
|
ev_wr_req<=1;ev_axis<=selected_record[35:32];ev_timestamp<=selected_record[31:0];ev_code<=selected_record[47:40];
|
|
|
ev_tag<=selected_record[63:48];ev_pos<=selected_record[95:64];ev_total<=selected_record[127:96];
|
|
|
if(select_limit)limit_pending[ev_select]<=0;else done_pending[ev_select]<=0;
|
|
|
@@ -687,9 +699,15 @@ module motor_engine #(
|
|
|
end else if(qc_state==QC_STAGE_WAIT) begin
|
|
|
qc_state<=QC_STAGE_READ;
|
|
|
end else if(qc_state==QC_STAGE_READ) begin
|
|
|
- stage_data<={stage_read_data,stage_data[127:8]};
|
|
|
- if(stage_byte_index==15) qc_state<=stage_for_write ? QC_WRITE : QC_VALIDATE;
|
|
|
- else begin stage_byte_index<=stage_byte_index+1'b1;qc_state<=QC_STAGE_WAIT;end
|
|
|
+ // The queue storage streams the live wr_data port across its
|
|
|
+ // four write words. Hold the validated descriptor untouched
|
|
|
+ // until the in-flight write has drained, or words 1..3 would
|
|
|
+ // capture the next descriptor's first staging bytes.
|
|
|
+ if(!q_write_busy) begin
|
|
|
+ stage_data<={stage_read_data,stage_data[127:8]};
|
|
|
+ if(stage_byte_index==15) qc_state<=stage_for_write ? QC_WRITE : QC_VALIDATE;
|
|
|
+ else begin stage_byte_index<=stage_byte_index+1'b1;qc_state<=QC_STAGE_WAIT;end
|
|
|
+ end
|
|
|
end else if(qc_state==QC_VALIDATE) begin
|
|
|
if(qc_index==qc_count) qc_state<=QC_SPACE;
|
|
|
else if(f_axis(stage_data)>=AXIS_COUNT || f_mode(stage_data)>M_HOLD ||
|