|
@@ -2,7 +2,7 @@
|
|
|
// 64 x 16-byte records in a 512 x 16-bit BRAM. A record commits only after
|
|
// 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
|
|
// 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.
|
|
// 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,
|
|
input wire clk,rst_n,wr_req,
|
|
|
output reg wr_ack,
|
|
output reg wr_ack,
|
|
|
input wire [3:0] wr_axis,
|
|
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 hold_q,freeze_pending,copy_active,read_phase,write_active;
|
|
|
reg [3:0] copy_index;
|
|
reg [3:0] copy_index;
|
|
|
reg [2:0] read_word,write_word;
|
|
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 [15:0] memory_data;
|
|
|
wire freeze_start=rd_hold && !hold_q;
|
|
wire freeze_start=rd_hold && !hold_q;
|
|
|
wire write_start=wr_req && !wr_ack && !write_active && !freeze_start && !freeze_pending && !copy_active;
|
|
wire write_start=wr_req && !wr_ack && !write_active && !freeze_start && !freeze_pending && !copy_active;
|
|
|
wire [7:0] after_clear=!clear_n ? count :
|
|
wire [7:0] after_clear=!clear_n ? count :
|
|
|
((clear_count==8'hFF || clear_count>=count) ? 8'd0 : count-clear_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};
|
|
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]};
|
|
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 (
|
|
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}),
|
|
.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)
|
|
.b_addr({memory_record,read_word}),.b_wdata(16'd0),.b_rdata(memory_data)
|
|
|
);
|
|
);
|
|
|
assign record_count=count;
|
|
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;
|
|
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;
|
|
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;
|
|
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;
|
|
live_base<=0;live_requested_index<=0;live_published_index<=0;live_data<=0;
|
|
|
end else begin
|
|
end else begin
|
|
|
hold_q<=rd_hold;wr_ack<=0;count<=after_clear;
|
|
hold_q<=rd_hold;wr_ack<=0;count<=after_clear;
|
|
|
if(freeze_start)freeze_pending<=1;
|
|
if(freeze_start)freeze_pending<=1;
|
|
|
if(write_start)begin
|
|
if(write_start)begin
|
|
|
- write_shift<={wr_total,wr_position,wr_tag,wr_event,axis_byte,time_us};
|
|
|
|
|
write_word<=0;write_active<=1;
|
|
write_word<=0;write_active<=1;
|
|
|
end else if(write_active)begin
|
|
end else if(write_active)begin
|
|
|
- write_shift<=write_shift>>16;
|
|
|
|
|
if(write_word==7)begin
|
|
if(write_word==7)begin
|
|
|
write_active<=0;head<=head+1'b1;wr_ack<=1;
|
|
write_active<=0;head<=head+1'b1;wr_ack<=1;
|
|
|
if(after_clear==DEPTH)overflow<=overflow+1'b1;
|
|
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];
|
|
freeze_pending<=0;view_base<=head-count[AW-1:0];
|
|
|
view_count<=count>8 ? 8'd8 : count;view_ready<=count==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;
|
|
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
|
|
else begin
|
|
|
read_phase<=0;read_shift<=assembled;
|
|
read_phase<=0;read_shift<=assembled;
|
|
|
if(read_word==7)begin
|
|
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.
|
|
// Ready frozen views retain the one-clock production read port.
|
|
|
// The diagnostic live view settles within two eight-word reads.
|
|
// 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;
|
|
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
|
|
|
end
|
|
end
|
|
|
endmodule
|
|
endmodule
|