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

refactor(mrdimm): map event and status storage to explicit BRAM

codex 3 месяцев назад
Родитель
Сommit
d0fb5b8aa1
2 измененных файлов с 32 добавлено и 14 удалено
  1. 20 8
      src/motor/motor_event_ring.v
  2. 12 6
      src/telemetry/mrdimm_snapshot_mux.v

+ 20 - 8
src/motor/motor_event_ring.v

@@ -1,6 +1,6 @@
 `timescale 1ns/1ps
 // 64 x 16-byte records plus an eight-record host view. Capture pauses the
-// writer for at most ten clocks, never for the duration of a Host transfer.
+// writer for at most eighteen clocks, never for the duration of a Host transfer.
 module motor_event_ring #(parameter integer DEPTH=64) (
     input wire clk,rst_n,wr_req,
     output reg wr_ack,
@@ -19,31 +19,42 @@ module motor_event_ring #(parameter integer DEPTH=64) (
     input wire [7:0] clear_count
 );
     localparam integer AW=$clog2(DEPTH);
-    reg [127:0] mem [0:DEPTH-1];
     reg [127:0] view_mem [0:7];
     reg [AW-1:0] head,view_base;
     reg [7:0] count;
     reg [31:0] overflow;
     reg hold_q,copy_active;
     reg [3:0] copy_index;
+    reg copy_phase;
+    wire [127:0] memory_data;
     wire freeze_start=rd_hold && !hold_q;
     wire write_fire=wr_req && !wr_ack && !freeze_start && !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] read_address=head-count[AW-1:0]+rd_index[AW-1:0];
     wire [AW-1:0] copy_address=view_base+copy_index;
+    wire [AW-1:0] memory_address=copy_active ? copy_address : read_address;
     wire [7:0] axis_byte=(wr_axis==4'hF) ? 8'hFF : {4'd0,wr_axis};
+    wire [127:0] write_data={wr_total,wr_position,wr_tag,wr_event,axis_byte,time_us};
+    genvar word_index;
+    generate for(word_index=0;word_index<4;word_index=word_index+1) begin:g_record_word
+        ef2_bram_dp #(.DATA_WIDTH(32),.ADDR_WIDTH(AW),.DATA_DEPTH(DEPTH)) u_memory (
+            .clk(clk),.a_en(write_fire),.a_we(write_fire),.a_addr(head),
+            .a_wdata(write_data[word_index*32+:32]),.a_rdata(),
+            .b_en(1'b1),.b_we(1'b0),.b_addr(memory_address),.b_wdata(32'd0),
+            .b_rdata(memory_data[word_index*32+:32])
+        );
+    end endgenerate
     assign record_count=count;
     assign overflow_lsb=overflow[7:0];
     assign overflow_count=overflow;
     always @(posedge clk) begin
-        if(write_fire) mem[head]<={wr_total,wr_position,wr_tag,wr_event,axis_byte,time_us};
-        if(copy_active && copy_index<view_count) view_mem[copy_index[2:0]]<=mem[copy_address];
+        if(copy_active && copy_phase && copy_index<view_count) view_mem[copy_index[2:0]]<=memory_data;
     end
     always @(posedge clk or negedge rst_n) begin
         if(!rst_n) begin
             head<=0;count<=0;overflow<=0;wr_ack<=0;rd_data<=0;
-            hold_q<=0;copy_active<=0;copy_index<=0;view_base<=0;
+            hold_q<=0;copy_active<=0;copy_index<=0;view_base<=0;copy_phase<=0;
             view_ready<=0;view_count<=0;
         end else begin
             hold_q<=rd_hold;wr_ack<=0;count<=after_clear;
@@ -54,13 +65,14 @@ module motor_event_ring #(parameter integer DEPTH=64) (
             end
             if(freeze_start) begin
                 view_base<=head-count[AW-1:0];view_count<=count>8 ? 8'd8 : count;
-                copy_index<=0;copy_active<=1;view_ready<=0;
+                copy_index<=0;copy_active<=1;view_ready<=0;copy_phase<=0;
             end else if(copy_active) begin
                 if(copy_index>=view_count) begin copy_active<=0;view_ready<=1;end
-                else copy_index<=copy_index+1'b1;
+                else if(copy_phase) begin copy_index<=copy_index+1'b1;copy_phase<=0;end
+                else copy_phase<=1;
             end else if(!rd_hold) view_ready<=0;
             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 ? mem[read_address] : 128'd0;
+            else rd_data<=rd_index<count ? memory_data : 128'd0;
         end
     end
 endmodule

+ 12 - 6
src/telemetry/mrdimm_snapshot_mux.v

@@ -21,11 +21,13 @@ module mrdimm_snapshot_mux #(
     input wire [31:0] time_us,time_high,event_overflow,event_pending_overflow,global_flags,
     input wire [7:0] ev_count,
     input wire [9:0] read_addr,
-    output reg [7:0] read_data
+    output wire [7:0] read_data
 );
     reg [`MR_SNAPSHOT_AXIS_OFFSET*8-1:0] header_shadow;
     reg [AXIS_COUNT*`MR_AXIS_RECORD_BYTES*8-1:0] axis_shadow;
-    reg [7:0] memory [0:SNAPSHOT_LENGTH-1];
+    localparam integer SNAPSHOT_ADDR_WIDTH=$clog2(SNAPSHOT_LENGTH);
+    wire [7:0] memory_read_data;
+    reg read_in_range;
     reg [9:0] index;
     reg [1:0] phase;
     reg capture_pending;
@@ -39,10 +41,14 @@ module mrdimm_snapshot_mux #(
     wire [7:0] copy_data=in_bmc ? (bmc_relative[0] ? bmc_rd_raw[15:8] : bmc_rd_raw[7:0]) :
         in_ct ? (ct_relative[0] ? ct_rd_raw[15:8] : ct_rd_raw[7:0]) :
         index>=`MR_SNAPSHOT_AXIS_OFFSET ? axis_shadow[axis_relative*8 +:8] : header_shadow[index*8 +:8];
-    always @(posedge clk) begin
-        if(locked && phase==2) memory[index]<=copy_data;
-        read_data<=read_addr<SNAPSHOT_LENGTH ? memory[read_addr] : 8'hFF;
-    end
+    ef2_bram_dp #(.DATA_WIDTH(8),.ADDR_WIDTH(SNAPSHOT_ADDR_WIDTH),.DATA_DEPTH(SNAPSHOT_LENGTH)) u_snapshot_memory (
+        .clk(clk),.a_en(locked && phase==2),.a_we(locked && phase==2),
+        .a_addr(index[SNAPSHOT_ADDR_WIDTH-1:0]),.a_wdata(copy_data),.a_rdata(),
+        .b_en(1'b1),.b_we(1'b0),.b_addr(read_addr[SNAPSHOT_ADDR_WIDTH-1:0]),
+        .b_wdata(8'd0),.b_rdata(memory_read_data)
+    );
+    always @(posedge clk) read_in_range<=read_addr<SNAPSHOT_LENGTH;
+    assign read_data=read_in_range ? memory_read_data : 8'hFF;
     always @(posedge clk or negedge rst_n) begin
         if(!rst_n) begin
             ready<=0;locked<=0;bmc_locked_bank<=0;ct_locked_bank<=0;index<=0;phase<=0;