|
|
@@ -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
|