Просмотр исходного кода

refactor(motor): retain data at its producer until consumer completion

codex 3 месяцев назад
Родитель
Сommit
e2f6dbabab

Разница между файлами не показана из-за своего большого размера
+ 3 - 4
src/motor/motor_axis_core.v


+ 5 - 4
src/motor/motor_engine.v

@@ -261,7 +261,6 @@ module motor_engine #(
     reg [15:0] ax_seg_tag [0:AXIS_COUNT-1];
     reg [AXIS_COUNT-1:0] ax_start_armed, ax_abort, ax_preempt;
     reg [AXIS_COUNT-1:0] ax_pos_load, ax_ctr_clear, ax_pos_zero, ax_lat_clear;
-    reg [31:0] ax_pos_value [0:AXIS_COUNT-1];
 
     wire [AXIS_COUNT*3-1:0] bank_seg_mode;
     wire [AXIS_COUNT*32-1:0] bank_seg_count;
@@ -299,7 +298,7 @@ module motor_engine #(
         assign bank_seg_count[g*32 +:32]=ax_seg_count[g];
         assign bank_seg_half_us[g*32 +:32]=ax_seg_half[g];
         assign bank_seg_tag[g*16 +:16]=ax_seg_tag[g];
-        assign bank_position_value[g*32 +:32]=ax_pos_value[g];
+        assign bank_position_value[g*32 +:32]=cs_value;
         assign ax_reason[g]=bank_done_reason[g*4 +:4];
         assign ax_dtag[g]=bank_done_tag[g*16 +:16];
         assign ax_dexec[g]=bank_done_executed[g*32 +:32];
@@ -703,7 +702,7 @@ module motor_engine #(
                             end
                             OP_CLEAR_QUEUE: begin depth_r[i]<=0;urgent_valid_r[i]<=0;end
                             OP_CLEAR_COUNTERS: begin ax_ctr_clear[i]<=1;ax_pos_zero[i]<=cs_flags[0];end
-                            OP_SET_POSITION: begin ax_pos_load[i]<=1;ax_pos_value[i]<=cs_value;end
+                            OP_SET_POSITION: ax_pos_load[i]<=1;
                             OP_CLEAR_LIMIT_LATCH: ax_lat_clear[i]<=1;
                             OP_HOME_LOWER,OP_SEEK_UPPER: begin
                                 ax_preempt[i]<=1;depth_r[i]<=0;queue_paused_r[i]<=0;
@@ -722,7 +721,9 @@ module motor_engine #(
             end else if(cs_state==3 && (ax_armed & cs_start_mask)==cs_start_mask && fx_state==FX_IDLE && ax_seg_load==0) begin
                 ax_start_armed<=cs_start_mask;
                 cs_state<=2;
-            end else if(cs_state==2) begin
+            // Keep the shared value stable until the scanner consumed all
+            // control pulses. ACK then releases the one command context.
+            end else if(cs_state==2 && !bank_telemetry_changing) begin
                 ctl_accept<=1;ctl_status<=ST_OK;cs_state<=0;
             end
 

+ 11 - 9
src/motor/motor_event_ring.v

@@ -2,7 +2,7 @@
 // 64 x 16-byte records in a 512 x 16-bit BRAM. A record commits only after
 // all eight words are written. A frozen host view copies at most eight
 // records in 128 read clocks; only this bounded copy pauses the writer.
-module motor_event_ring #(parameter integer DEPTH=64) (
+module motor_event_ring #(parameter integer DEPTH=64, parameter integer LIVE_DIAGNOSTIC_VIEW=0) (
     input wire clk,rst_n,wr_req,
     output reg wr_ack,
     input wire [3:0] wr_axis,
@@ -27,18 +27,21 @@ module motor_event_ring #(parameter integer DEPTH=64) (
     reg hold_q,freeze_pending,copy_active,read_phase,write_active;
     reg [3:0] copy_index;
     reg [2:0] read_word,write_word;
-    reg [127:0] write_shift,read_shift,live_data;
+    reg [127:0] read_shift,live_data;
     wire [15:0] memory_data;
     wire freeze_start=rd_hold && !hold_q;
     wire write_start=wr_req && !wr_ack && !write_active && !freeze_start && !freeze_pending && !copy_active;
     wire [7:0] after_clear=!clear_n ? count :
         ((clear_count==8'hFF || clear_count>=count) ? 8'd0 : count-clear_count);
-    wire [AW-1:0] memory_record=copy_active ? view_base+copy_index : live_base;
+    wire [AW-1:0] memory_record=(!LIVE_DIAGNOSTIC_VIEW || copy_active) ? view_base+copy_index : live_base;
     wire [7:0] axis_byte=(wr_axis==4'hF) ? 8'hFF : {4'd0,wr_axis};
+    // The producer holds req and all record fields until ack. Stream from
+    // that owner directly instead of maintaining a duplicate128-bit shift.
+    wire [127:0] write_record={wr_total,wr_position,wr_tag,wr_event,axis_byte,time_us};
     wire [127:0] assembled={memory_data,read_shift[127:16]};
     ef2_bram_dp #(.DATA_WIDTH(16),.ADDR_WIDTH(AW+3),.DATA_DEPTH(DEPTH*8)) u_memory (
         .clk(clk),.a_en(write_active),.a_we(write_active),.a_addr({head,write_word}),
-        .a_wdata(write_shift[15:0]),.a_rdata(),.b_en(1'b1),.b_we(1'b0),
+        .a_wdata(write_record[{write_word,4'b0000}+:16]),.a_rdata(),.b_en(1'b1),.b_we(1'b0),
         .b_addr({memory_record,read_word}),.b_wdata(16'd0),.b_rdata(memory_data)
     );
     assign record_count=count;
@@ -53,16 +56,14 @@ module motor_event_ring #(parameter integer DEPTH=64) (
             head<=0;count<=0;overflow<=0;wr_ack<=0;rd_data<=0;
             hold_q<=0;freeze_pending<=0;copy_active<=0;copy_index<=0;view_base<=0;
             view_ready<=0;view_count<=0;read_phase<=0;read_word<=0;
-            write_active<=0;write_word<=0;write_shift<=0;read_shift<=0;
+            write_active<=0;write_word<=0;read_shift<=0;
             live_base<=0;live_requested_index<=0;live_published_index<=0;live_data<=0;
         end else begin
             hold_q<=rd_hold;wr_ack<=0;count<=after_clear;
             if(freeze_start)freeze_pending<=1;
             if(write_start)begin
-                write_shift<={wr_total,wr_position,wr_tag,wr_event,axis_byte,time_us};
                 write_word<=0;write_active<=1;
             end else if(write_active)begin
-                write_shift<=write_shift>>16;
                 if(write_word==7)begin
                     write_active<=0;head<=head+1'b1;wr_ack<=1;
                     if(after_clear==DEPTH)overflow<=overflow+1'b1;
@@ -75,7 +76,8 @@ module motor_event_ring #(parameter integer DEPTH=64) (
                 freeze_pending<=0;view_base<=head-count[AW-1:0];
                 view_count<=count>8 ? 8'd8 : count;view_ready<=count==0;
                 copy_active<=count!=0;copy_index<=0;read_word<=0;read_phase<=0;
-            end else if(!read_phase)read_phase<=1;
+            end else if(!LIVE_DIAGNOSTIC_VIEW && !copy_active)begin read_phase<=0;read_word<=0;end
+            else if(!read_phase)read_phase<=1;
             else begin
                 read_phase<=0;read_shift<=assembled;
                 if(read_word==7)begin
@@ -94,7 +96,7 @@ module motor_event_ring #(parameter integer DEPTH=64) (
             // Ready frozen views retain the one-clock production read port.
             // The diagnostic live view settles within two eight-word reads.
             if(rd_hold)rd_data<=(view_ready && rd_index<view_count) ? view_mem[rd_index[2:0]] : 128'd0;
-            else rd_data<=(rd_index<count && live_published_index==rd_index) ? live_data : 128'd0;
+            else rd_data<=(LIVE_DIAGNOSTIC_VIEW && rd_index<count && live_published_index==rd_index) ? live_data : 128'd0;
         end
     end
 endmodule

+ 1 - 1
tests/sim/motor_event_ring_tb.v

@@ -10,7 +10,7 @@ module motor_event_ring_tb;
     wire [127:0] data;
     wire [7:0] count,overflow;
     wire view_ready;
-    motor_event_ring dut(.clk(clk),.rst_n(rst_n),.wr_req(req),.wr_ack(ack),
+    motor_event_ring #(.LIVE_DIAGNOSTIC_VIEW(1)) dut(.clk(clk),.rst_n(rst_n),.wr_req(req),.wr_ack(ack),
         .wr_axis(axis),.wr_event(event_code),.wr_tag(tag),.wr_position(pos),
         .wr_total(total),.time_us(time_us),.rd_index(index),.rd_hold(hold_view),
         .rd_data(data),.record_count(count),.overflow_lsb(overflow),