Commit e9862dab authored by Andrey Filippov's avatar Andrey Filippov

Converting event_logger to use serial timestamps and 4 sesnor channels

parent 6a297fff
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Author: andrey * Author: andrey
* Description: move data from xclk to mclk domain * Description: move data from xclk to mclk domain
* *
* Copyright (c) 2015 <set up in Preferences-Verilog/VHDL Editor-Templates> . * Copyright (c) 2015 Elphel, Inc.
* buf_xclk_mclk16_393.v is free software; you can redistribute it and/or modify * buf_xclk_mclk16_393.v is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
...@@ -21,21 +21,13 @@ ...@@ -21,21 +21,13 @@
`timescale 1ns/1ps `timescale 1ns/1ps
module buf_xclk_mclk16_393( module buf_xclk_mclk16_393(
xclk, // posedge input mclk, // system clock, posedge
mclk, // posedge input xclk, // half frequency (80 MHz nominal)
rst, // @posedge xclk input rst, // @posedge xclk reset module
din, input [15:0] din,
din_stb, input din_stb,
dout, output reg [15:0] dout,
dout_stb); output reg dout_stb);
input xclk; // half frequency (80 MHz nominal)
input mclk; // system clock - frequency (160 MHz nominal)
input rst; // reset module
input [15:0] din;
input din_stb;
output [15:0] dout;
output dout_stb;
reg [1:0] wa; reg [1:0] wa;
reg [1:0] wa_mclk; reg [1:0] wa_mclk;
...@@ -45,12 +37,12 @@ module buf_xclk_mclk16_393( ...@@ -45,12 +37,12 @@ module buf_xclk_mclk16_393(
reg [1:0] ra_next; reg [1:0] ra_next;
reg inc_ra; reg inc_ra;
wire [15:0] pre_dout; wire [15:0] pre_dout;
reg [15:0] dout;
reg dout_stb;
always @ (posedge xclk) begin always @ (posedge xclk) begin
if (rst) wa[1:0] <= 2'h0; if (rst) wa[1:0] <= 2'h0;
else if (din_stb) wa[1:0] <={wa[0],~wa[1]}; else if (din_stb) wa[1:0] <={wa[0],~wa[1]};
end end
always @ (posedge mclk) begin always @ (posedge mclk) begin
wa_mclk[1:0] <= wa[1:0]; wa_mclk[1:0] <= wa[1:0];
wa_mclk_d[1:0] <= wa_mclk[1:0]; wa_mclk_d[1:0] <= wa_mclk[1:0];
...@@ -66,18 +58,9 @@ module buf_xclk_mclk16_393( ...@@ -66,18 +58,9 @@ module buf_xclk_mclk16_393(
if (inc_ra) dout[15:0] <= pre_dout[15:0]; if (inc_ra) dout[15:0] <= pre_dout[15:0];
end end
reg [15:0] fifo_4x16_ram[0:3];
myRAM_WxD_D #( .DATA_WIDTH(16),.DATA_DEPTH(2)) always @ (posedge xclk) if (din_stb) fifo_4x16_ram[wa[1:0]] <= din[15:0];
i_fifo_4x16 (.D(din[15:0]), assign pre_dout[15:0] = fifo_4x16_ram[ra[1:0]];
.WE(din_stb),
.clk(xclk),
.AW(wa[1:0]),
.AR(ra[1:0]),
.QW(),
.QR(pre_dout[15:0]));
endmodule
endmodule endmodule
This diff is collapsed.
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Author: andrey * Author: andrey
* Description: * Description:
* *
* Copyright (c) 2015 <set up in Preferences-Verilog/VHDL Editor-Templates> . * Copyright (c) 2015 Elphel, Inc.
* imu_message393.v is free software; you can redistribute it and/or modify * imu_message393.v is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
...@@ -27,73 +27,58 @@ de-assert the trig input - message with the timestamp will be logged ...@@ -27,73 +27,58 @@ de-assert the trig input - message with the timestamp will be logged
fixed-length de-noise circuitry with latency 256*T(xclk) (~3usec) fixed-length de-noise circuitry with latency 256*T(xclk) (~3usec)
*/ */
module imu_message393 ( sclk, // system clock, negedge module imu_message393 (
xclk, // half frequency (80 MHz nominal) input mclk, // system clock, negedge TODO:COnvert to posedge!
we, // write enable for registers to log (@negedge sclk), with lower data half input xclk, // half frequency (80 MHz nominal)
wa, // write address for register (4 bits, @negedge sclk) input we, // write enable for registers to log (@negedge mclk), with lower data half
di, // 16-bit data in multiplexed input [3:0] wa, // write address for register (4 bits, @negedge mclk)
en, // enable module operation, if 0 - reset // input [15:0] di, // 16-bit data in multiplexed
trig, // leading edge - sample time, trailing set rdy input [31:0] din, // 32-bit data in, non-multiplexed
ts, // timestamop request input en, // enable module operation, if 0 - reset
rdy, // data ready input trig, // leading edge - sample time, trailing set rdy
rd_stb, // data read strobe (increment address) output ts, // timestamop request
rdata); // data out (16 bits) output rdy, // data ready
input rd_stb, // data read strobe (increment address)
input sclk; // system clock, negedge output [15:0] rdata); // data out (16 bits)
input xclk; // half frequency (80 MHz nominal)
input we; // write enable for registers to log (@negedge sclk)
input [3:0] wa; // write address for register (4 bits, @negedge sclk)
input [15:0] di; // 16-bit data in (32 multiplexed)
input en; // enable
input trig; // leading edge - sample time, trailing set rdy
output ts; // timestamp request
output rdy; // encoded nmea data ready
input rd_stb; // encoded nmea data read strobe (increment address)
output [15:0] rdata; // encoded data (16 bits)
reg [ 4:0] raddr; reg [ 4:0] raddr;
reg rdy=1'b0; reg rdy_r=1'b0;
reg we_d;
reg [ 4:1] waddr;
reg [ 2:0] trig_d; reg [ 2:0] trig_d;
reg [ 7:0] denoise_count; reg [ 7:0] denoise_count;
reg [ 1:0] trig_denoise; reg [ 1:0] trig_denoise;
reg ts; reg ts_r;
reg [15:0] di_d;
assign rdy = rdy_r;
assign ts = ts_r;
always @ (negedge sclk) begin
di_d[15:0] <= di[15:0];
waddr[4:1] <= wa[3:0];
we_d <=we;
end
always @ (posedge xclk) begin always @ (posedge xclk) begin
if (!en) trig_d[2:0] <= 3'h0; if (!en) trig_d[2:0] <= 3'h0;
else trig_d[2:0] <= {trig_d[1:0], trig}; else trig_d[2:0] <= {trig_d[1:0], trig};
if (!en) trig_denoise[0] <= 1'b0; if (!en) trig_denoise[0] <= 1'b0;
else if (denoise_count[7:0]==8'h0) trig_denoise[0] <= trig_d[2]; else if (denoise_count[7:0]==8'h0) trig_denoise[0] <= trig_d[2];
if (trig_d[2]==trig_denoise[0]) denoise_count[7:0] <= 8'hff; if (trig_d[2]==trig_denoise[0]) denoise_count[7:0] <= 8'hff;
else denoise_count[7:0] <= denoise_count[7:0] - 1; else denoise_count[7:0] <= denoise_count[7:0] - 1;
trig_denoise[1] <= trig_denoise[0]; trig_denoise[1] <= trig_denoise[0];
ts <= !trig_denoise[1] && trig_denoise[0];
if (!en || ts) raddr[4:0] <= 5'h0; ts_r <= !trig_denoise[1] && trig_denoise[0];
if (!en || ts_r) raddr[4:0] <= 5'h0;
else if (rd_stb) raddr[4:0] <= raddr[4:0] + 1; else if (rd_stb) raddr[4:0] <= raddr[4:0] + 1;
if (ts || (rd_stb && (raddr[4:0]==5'h1b)) || !en) rdy <= 1'b0; if (ts_r || (rd_stb && (raddr[4:0]==5'h1b)) || !en) rdy_r <= 1'b0;
else if (trig_denoise[1] && !trig_denoise[0]) rdy <= 1'b1; else if (trig_denoise[1] && !trig_denoise[0]) rdy_r <= 1'b1;
end end
myRAM_WxD_D #( .DATA_WIDTH(16),.DATA_DEPTH(5)) reg [31:0] odbuf0_ram[0:15];
i_odbuf (.D(di_d[15:0]), wire [31:0] odbuf0_ram_out;
.WE(we | we_d), always @ (posedge mclk) if (we) begin
.clk(~sclk), odbuf0_ram[wa[3:0]] <= din[31:0];
.AW({waddr[4:1],we_d}), end
.AR(raddr[4:0]), assign odbuf0_ram_out = odbuf0_ram[raddr[4:1]];
.QW(), assign rdata[15:0] = raddr[0] ? odbuf0_ram_out[15:0] : odbuf0_ram_out[31:16];
.QR(rdata[15:0]));
endmodule
endmodule endmodule
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Author: andrey * Author: andrey
* Description: Acquire timestmps for events * Description: Acquire timestmps for events
* *
* Copyright (c) 2015 <set up in Preferences-Verilog/VHDL Editor-Templates> . * Copyright (c) 2015 Elphel, Inc.
* imu_timestamps393.v is free software; you can redistribute it and/or modify * imu_timestamps393.v is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Author: andrey * Author: andrey
* Description: arbiter for the event_logger * Description: arbiter for the event_logger
* *
* Copyright (c) 2015 <set up in Preferences-Verilog/VHDL Editor-Templates> . * Copyright (c) 2015 Elphel, Inc.
* logger_arbiter393.v is free software; you can redistribute it and/or modify * logger_arbiter393.v is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
...@@ -21,19 +21,19 @@ ...@@ -21,19 +21,19 @@
`timescale 1ns/1ps `timescale 1ns/1ps
module logger_arbiter393( module logger_arbiter393(
xclk, // 80 MHz, posedge input xclk, // half frequency (80 MHz nominal)
rst, // module reset input rst, // module reset (sync)
ts_rq_in, // in requests for timestamp (single-cycle - just leading edge ) input [3:0] ts_rq_in, // in requests for timestamp (single-cycle - just leading edge )
ts_rq, // out request for timestamp, to timestmp module output [3:0] ts_rq, // out request for timestamp, to timestmp module
ts_grant, // granted ts requests from timestamping module input [3:0] ts_grant, // granted ts requests from timestamping module
rdy, // channels ready (leading edge - became ready, trailing - no more data, use zero) input [3:0] rdy, // channels ready (leading edge - became ready, trailing - no more data, use zero)
nxt, // pulses to modules to output next word output reg [3:0] nxt, // pulses to modules to output next word
channel, // decoded channel number (2 bits) output [1:0] channel, // decoded channel number (2 bits)
ts_sel, // select timestamp word to be output (0..3) output [1:0] ts_sel, // select timestamp word to be output (0..3)
ts_en, // 1 - use timestamp, 0 - channel data (or 16'h0 if !ready) output ts_en, // 1 - use timestamp, 0 - channel data (or 16'h0 if !ready)
dv, // output data valid (from registered mux - 2 stage - first selects data and ready, second ts/data/zero) output reg dv, // output data valid (from registered mux - 2 stage - first selects data and ready, second ts/data/zero)
sample_counter);// number of 64-byte samples logged output [23:0] sample_counter);// number of 64-byte samples logged
/*
input xclk; // half frequency (80 MHz nominal) input xclk; // half frequency (80 MHz nominal)
input rst; // reset module input rst; // reset module
input [ 3:0] ts_rq_in; // in requests for timestamp (sinlgle-cycle) input [ 3:0] ts_rq_in; // in requests for timestamp (sinlgle-cycle)
...@@ -46,54 +46,53 @@ module logger_arbiter393( ...@@ -46,54 +46,53 @@ module logger_arbiter393(
output ts_en; // 1 - use timestamp, 0 - channel data (or 16'h0 if !ready) output ts_en; // 1 - use timestamp, 0 - channel data (or 16'h0 if !ready)
output dv; // output data valid (from registered mux - 2 stage - first selects data and ready, second ts/data/zero) output dv; // output data valid (from registered mux - 2 stage - first selects data and ready, second ts/data/zero)
output [23:0] sample_counter;// number of 64-byte samples logged output [23:0] sample_counter;// number of 64-byte samples logged
*/
reg [3:0] ts_rq_in_d; reg [3:0] ts_rq_in_d;
reg [3:0] ts_rq; reg [3:0] ts_rq_r;
reg [3:0] ts_valid; reg [3:0] ts_valid;
// reg [3:0] ts_rq_reset; // reg [3:0] ts_rq_reset;
reg [3:0] channels_ready;// channels granted and ready reg [3:0] channels_ready;// channels granted and ready
reg [3:1] chn1hot; // channels 1-hot - granted and ready, priority applied reg [3:1] chn1hot; // channels 1-hot - granted and ready, priority applied
reg rq_not_zero; // at least one channel is ready for processing (same time as chn1hot[3:0]) reg rq_not_zero; // at least one channel is ready for processing (same time as chn1hot[3:0])
reg [1:0] channel; reg [1:0] channel_r;
reg start; // reg start; Not used!
reg busy; reg busy;
wire wstart; wire wstart;
reg ts_en; reg ts_en_r;
reg [4:0] seq_cntr; reg [4:0] seq_cntr;
reg seq_cntr_last; reg seq_cntr_last;
reg [1:0] ts_sel; reg [1:0] ts_sel_r;
reg dv; // reg dv;
reg inc_sample_counter; reg inc_sample_counter;
reg [23:0] sample_counter;// number of 64-byte samples logged reg [23:0] sample_counter_r;// number of 64-byte samples logged
reg [ 3:0] nxt; // reg [ 3:0] nxt;
reg pre_nxt; reg pre_nxt;
reg [ 3:0] chn_servicing; //1-hot channel being service reg [ 3:0] chn_servicing; //1-hot channel being service
// reg [ 3:0] rdy_d;
wire [3:0] wts_rq; wire [3:0] wts_rq;
assign wstart= !busy && rq_not_zero;
assign wts_rq[3:0]= ts_rq_in[3:0] & ~ts_rq_in_d[3:0] & (~rdy[3:0] | chn_servicing[3:0]); assign wstart = !busy && rq_not_zero;
assign wts_rq[3:0] = ts_rq_in[3:0] & ~ts_rq_in_d[3:0] & (~rdy[3:0] | chn_servicing[3:0]);
assign sample_counter = sample_counter_r;
assign ts_rq = ts_rq_r;
assign channel = channel_r;
assign ts_en = ts_en_r;
assign ts_sel = ts_sel_r;
always @ (posedge xclk) begin always @ (posedge xclk) begin
ts_rq_in_d[3:0] <= ts_rq_in[3:0]; ts_rq_in_d[3:0] <= ts_rq_in[3:0];
// rdy_d[3:0] <=rdy[3:0];
if (wstart) channel[1:0] <= {chn1hot[3] | chn1hot[2],chn1hot[3] | chn1hot[1]}; if (wstart) channel_r[1:0] <= {chn1hot[3] | chn1hot[2],chn1hot[3] | chn1hot[1]};
if (wstart) chn_servicing[3:0] <= {chn1hot[3:1], ~|chn1hot[3:1]}; if (wstart) chn_servicing[3:0] <= {chn1hot[3:1], ~|chn1hot[3:1]};
else if (!busy) chn_servicing[3:0] <= 4'h0; else if (!busy) chn_servicing[3:0] <= 4'h0;
// if (rst) ts_rq[3:0] <= 4'h0;
// else ts_rq[3:0] <= ~ts_rq_reset[3:0] & ((ts_rq_in[3:0] & ~ts_rq_in_d[3:0]) | ts_rq[3:0]);
if (rst) ts_rq[3:0] <= 4'h0; if (rst) ts_rq_r[3:0] <= 4'h0;
// else ts_rq[3:0] <= ~ts_grant & ( (ts_rq_in[3:0] & ~ts_rq_in_d[3:0] & (~rdy[3:0] | ~ts_valid[3:0])) | ts_rq[3:0]); else ts_rq_r[3:0] <= ~ts_grant & ( wts_rq[3:0] | ts_rq_r[3:0]);
else ts_rq[3:0] <= ~ts_grant & ( wts_rq[3:0] | ts_rq[3:0]);
if (rst) ts_valid[3:0] <= 4'h0; if (rst) ts_valid[3:0] <= 4'h0;
// else ts_valid[3:0] <= ~ts_rq_reset[3:0] &( ts_grant[3:0] | (ts_valid & ~(ts_rq_in[3:0] & ~ts_rq_in_d[3:0] & ~rdy[3:0])));
else ts_valid[3:0] <= (ts_grant[3:0] | (ts_valid & ~wts_rq[3:0])); else ts_valid[3:0] <= (ts_grant[3:0] | (ts_valid & ~wts_rq[3:0]));
// if (rst) request[3:0] <= 4'h0;
// else request[3:0] <= ~ts_rq_reset[3:0] &( request[3:0] | (rdy[3:0] & ~rdy_d[3:0])));
// channels_ready[3:0] <= ts_grant[3:0] & rdy[3:0];
channels_ready[3:0] <= ts_valid[3:0] & rdy[3:0] & ~chn_servicing[3:0]; // ready should go down during servicing channels_ready[3:0] <= ts_valid[3:0] & rdy[3:0] & ~chn_servicing[3:0]; // ready should go down during servicing
rq_not_zero <= channels_ready[3:0] != 4'h0; rq_not_zero <= channels_ready[3:0] != 4'h0;
...@@ -102,46 +101,33 @@ module logger_arbiter393( ...@@ -102,46 +101,33 @@ module logger_arbiter393(
channels_ready[2] & ~|channels_ready[1:0], channels_ready[2] & ~|channels_ready[1:0],
channels_ready[1] & ~channels_ready[0]}; channels_ready[1] & ~channels_ready[0]};
start <= wstart; // start <= wstart; Not used !
if ((seq_cntr[4:0]=='h1e) || rst) busy <= 1'b0; if ((seq_cntr[4:0]=='h1e) || rst) busy <= 1'b0;
else if (rq_not_zero) busy <= 1'b1; else if (rq_not_zero) busy <= 1'b1;
// if (!busy) seq_cntr[4:0] <= 5'h1f;
if (!busy) seq_cntr[4:0] <= 5'h0; if (!busy) seq_cntr[4:0] <= 5'h0;
else seq_cntr[4:0] <= seq_cntr[4:0] + 1; else seq_cntr[4:0] <= seq_cntr[4:0] + 1;
seq_cntr_last <= (seq_cntr[4:0]=='h1e); seq_cntr_last <= (seq_cntr[4:0]=='h1e);
if (wstart) ts_en <=1'b1; if (wstart) ts_en_r <=1'b1;
else if (seq_cntr[1:0]==2'h3) ts_en <=1'b0; else if (seq_cntr[1:0]==2'h3) ts_en_r <=1'b0;
if (!ts_en) ts_sel[1:0] <= 2'h0; if (!ts_en_r) ts_sel_r[1:0] <= 2'h0;
else ts_sel[1:0] <= ts_sel[1:0] + 1; else ts_sel_r[1:0] <= ts_sel_r[1:0] + 1;
if (!busy || (seq_cntr[4:0]=='h1d)) pre_nxt <= 1'b0; if (!busy || (seq_cntr[4:0]=='h1d)) pre_nxt <= 1'b0;
else if (seq_cntr[4:0]=='h01) pre_nxt <= 1'b1; else if (seq_cntr[4:0]=='h01) pre_nxt <= 1'b1;
/*
nxt [3:0] <= pre_nxt? { channel[1] & channel[0],
channel[1] & ~channel[0],
~channel[1] & channel[0],
~channel[1] & ~channel[0]}:4'h0;
*/
nxt [3:0] <= pre_nxt? chn_servicing[3:0]:4'h0; nxt [3:0] <= pre_nxt? chn_servicing[3:0]:4'h0;
/*
ts_rq_reset[3:0] <= start? { channel[1] & channel[0],
channel[1] & ~channel[0],
~channel[1] & channel[0],
~channel[1] & ~channel[0]}:4'h0;
*/
dv <= busy || seq_cntr_last; dv <= busy || seq_cntr_last;
inc_sample_counter <= seq_cntr_last; inc_sample_counter <= seq_cntr_last;
if (rst) sample_counter[23:0] <= 24'h0; if (rst) sample_counter_r[23:0] <= 24'h0;
else if (inc_sample_counter) sample_counter[23:0] <= sample_counter[23:0] +1; else if (inc_sample_counter) sample_counter_r[23:0] <= sample_counter_r[23:0] +1;
end end
endmodule endmodule
\ No newline at end of file
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Author: andrey * Author: andrey
* Description: rs232 receiver * Description: rs232 receiver
* *
* Copyright (c) 2015 <set up in Preferences-Verilog/VHDL Editor-Templates> . * Copyright (c) 2015 Elphel, Inc.
* rs232_rcv393.v is free software; you can redistribute it and/or modify * rs232_rcv393.v is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
...@@ -21,32 +21,19 @@ ...@@ -21,32 +21,19 @@
`timescale 1ns/1ps `timescale 1ns/1ps
module rs232_rcv393( module rs232_rcv393(
xclk, // half frequency (80 MHz nominal) input xclk, // half frequency (80 MHz nominal)
bitHalfPeriod, // half of the serial bit duration, in xclk cycles input [15:0] bitHalfPeriod, // half of the serial bit duration, in xclk cycles
ser_di, // rs232 (ttl) serial data in input ser_di, // rs232 (ttl) serial data in
ser_rst, // reset (force re-sync) input ser_rst, // reset (force re-sync)
ts_stb, // strobe timestamp (start of message) (reset bit counters in nmea decoder) output ts_stb, // strobe timestamp (start of message) (reset bit counters in nmea decoder)
wait_just_pause,// may be used as reset for decoder output reg wait_just_pause,// may be used as reset for decoder
start, // serial character start (single pulse) output start, // serial character start (single pulse)
// char, // byte out output reg ser_do, // serial data out(@posedge xclk) LSB first!
// char_stb); // char strobe (@posedge xclk) output reg ser_do_stb, // output data strobe (@posedge xclk), first cycle after ser_do becomes valid
ser_do, // serial data out(@posedge xclk) LSB first! // Next outputs are just fro debugging
ser_do_stb, // output data strobe (@posedge xclk), first cycle after ser_do becomes valid output [4:0] debug, // {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset
debug, // {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset output [15:0] bit_dur_cntr,
bit_dur_cntr, output [4:0] bit_cntr);
bit_cntr);
input xclk; // half frequency (80 MHz nominal)
input [15:0] bitHalfPeriod; // half of the serial bit duration, in xclk cycles
input ser_di; // rs232 (ttl) serial data in
input ser_rst; // reset (force re-sync)
output ts_stb; // strobe timestamp (start of message)
output wait_just_pause;// may be used as reset for decoder
output start; // serial character start (single pulse)
output [4:0] debug; // {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset
output ser_do; // serial data out(@posedge xclk)
output ser_do_stb; // output data strobe (@posedge xclk), 2 cycles after ser_do becomes valid
output [15:0] bit_dur_cntr; // debug
output [4:0] bit_cntr; // debug
reg [4:0] ser_di_d; reg [4:0] ser_di_d;
reg ser_filt_di; reg ser_filt_di;
...@@ -56,36 +43,37 @@ module rs232_rcv393( ...@@ -56,36 +43,37 @@ module rs232_rcv393(
reg wait_pause; // waiting input to stay at 1 for 10 cycles reg wait_pause; // waiting input to stay at 1 for 10 cycles
reg wait_start; // (or use in_sync - set it after wait_pause is over? reg wait_start; // (or use in_sync - set it after wait_pause is over?
reg receiving_byte; reg receiving_byte;
reg start; reg start_r;
reg [15:0] bit_dur_cntr; // bit duration counter (half bit duration) reg [15:0] bit_dur_cntr_r; // bit duration counter (half bit duration)
reg [4:0] bit_cntr; // counts half-bit intervals reg [4:0] bit_cntr_r; // counts half-bit intervals
wire error; // low level during stop slot wire error; // low level during stop slot
reg [1:0] restart; reg [1:0] restart;
wire reset_wait_pause; wire reset_wait_pause;
reg ts_stb; reg ts_stb_r;
reg shift_en; reg shift_en;
reg ser_do;
reg ser_do_stb;
wire sample_bit; wire sample_bit;
wire reset_bit_duration; wire reset_bit_duration;
reg wait_just_pause;
wire wstart; wire wstart;
wire [4:0] debug; // reg [4:0] debug0; // {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset
reg [4:0] debug0; // {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset assign reset_wait_pause = (restart[1] && !restart[0]) || (wait_pause && !wait_start && !ser_di);
assign reset_wait_pause= (restart[1] && !restart[0]) || (wait_pause && !wait_start && !ser_di); assign error = !ser_filt_di && last_half_bit && bit_half_end && receiving_byte;
assign error=!ser_filt_di && last_half_bit && bit_half_end && receiving_byte; assign sample_bit = shift_en && bit_half_end && !bit_cntr[0];
assign sample_bit=shift_en && bit_half_end && !bit_cntr[0]; assign reset_bit_duration = reset_wait_pause || start || bit_half_end || ser_rst;
assign reset_bit_duration= reset_wait_pause || start || bit_half_end || ser_rst;
assign wstart=wait_start && ser_filt_di_d && !ser_filt_di; assign wstart = wait_start && ser_filt_di_d && !ser_filt_di;
// assign debug[4:0] = {1'b0,wait_start,wait_pause,receiving_byte,shift_en};
assign debug[4:0] = {error, wait_start, wait_pause, receiving_byte, shift_en};
assign bit_dur_cntr = bit_dur_cntr_r; // bit duration counter (half bit duration)
assign bit_cntr = bit_cntr_r; // counts half-bit intervals
assign start = start_r;
assign ts_stb = ts_stb_r;
assign debug[4:0] = {1'b0,wait_start,wait_pause,receiving_byte,shift_en};
always @ (posedge xclk) begin always @ (posedge xclk) begin
// reg [4:0] ser_di_d;
// reg ser_filt_di;
// reg ser_filt_di_d;
ser_di_d[4:0] <= {ser_di_d[3:0],ser_di}; ser_di_d[4:0] <= {ser_di_d[3:0],ser_di};
if (ser_rst || &ser_di_d[4:0]) ser_filt_di <= 1'b1; if (ser_rst || &ser_di_d[4:0]) ser_filt_di <= 1'b1;
else if (~|ser_di_d[4:0]) ser_filt_di <= 1'b0; else if (~|ser_di_d[4:0]) ser_filt_di <= 1'b0;
...@@ -95,35 +83,29 @@ module rs232_rcv393( ...@@ -95,35 +83,29 @@ module rs232_rcv393(
wait_pause <= !ser_rst && (reset_wait_pause || wait_pause <= !ser_rst && (reset_wait_pause ||
(receiving_byte && last_half_bit && bit_half_end ) || (receiving_byte && last_half_bit && bit_half_end ) ||
(wait_pause && !(last_half_bit && bit_half_end) && !(wait_start && !ser_filt_di))); (wait_pause && !(last_half_bit && bit_half_end) && !(wait_start && !ser_filt_di)));
// start <= wait_start && ser_di_d && !ser_di; start_r <= wstart;
start <= wstart; ts_stb_r <= !wait_pause && wstart; // only first start after pause
// ts_stb <= !wait_pause && wait_start && ser_di_d && !ser_di; bit_half_end <=(bit_dur_cntr_r[15:0]==16'h1) && !reset_bit_duration;
ts_stb <= !wait_pause && wstart; // only first start after pause
bit_half_end <=(bit_dur_cntr[15:0]==16'h1) && !reset_bit_duration;
// wait_start <= ser_di && !ser_rst && ((wait_pause || receiving_byte) && last_half_bit && bit_half_end || wait_start);
wait_start <= !ser_rst && ((wait_pause || receiving_byte) && last_half_bit && bit_half_end || (wait_start && !wstart)); wait_start <= !ser_rst && ((wait_pause || receiving_byte) && last_half_bit && bit_half_end || (wait_start && !wstart));
// receiving_byte <= !ser_rst && !error && (start || (receiving_byte && !(last_half_bit && bit_half_end))); receiving_byte <= !ser_rst && (start_r || (receiving_byte && !(last_half_bit && bit_half_end)));
receiving_byte <= !ser_rst && (start || (receiving_byte && !(last_half_bit && bit_half_end)));
wait_just_pause <=wait_pause && !wait_start; wait_just_pause <=wait_pause && !wait_start;
if (reset_bit_duration) bit_dur_cntr[15:0] <= bitHalfPeriod[15:0]; if (reset_bit_duration) bit_dur_cntr_r[15:0] <= bitHalfPeriod[15:0];
else bit_dur_cntr[15:0] <= bit_dur_cntr[15:0] - 1; else bit_dur_cntr_r[15:0] <= bit_dur_cntr_r[15:0] - 1;
if (reset_wait_pause || ser_rst) bit_cntr[4:0] <= 5'h13; if (reset_wait_pause || ser_rst) bit_cntr_r[4:0] <= 5'h13;
else if (start) bit_cntr[4:0] <= 5'h12; else if (start_r) bit_cntr_r[4:0] <= 5'h12;
else if (bit_half_end) bit_cntr[4:0] <= bit_cntr[4:0] - 1; else if (bit_half_end) bit_cntr_r[4:0] <= bit_cntr_r[4:0] - 1;
last_half_bit <= ((bit_cntr[4:0] == 5'h0) && !bit_half_end);
shift_en <= receiving_byte && ((bit_half_end && ( bit_cntr[3:0]==4'h2))? bit_cntr[4]:shift_en);
last_half_bit <= ((bit_cntr_r[4:0] == 5'h0) && !bit_half_end);
shift_en <= receiving_byte && ((bit_half_end && ( bit_cntr_r[3:0]==4'h2))? bit_cntr_r[4]:shift_en);
if (sample_bit) ser_do <= ser_filt_di; if (sample_bit) ser_do <= ser_filt_di;
ser_do_stb <= sample_bit; ser_do_stb <= sample_bit;
// if (ser_rst) debug0[4:0] <=5'b0;
if (ser_rst) debug0[4:0] <=5'b0; // else debug0[4:0] <= debug | {ts_stb_r,start_r,error,ser_di_d,~ser_di_d};
else debug0[4:0] <= debug | {ts_stb,start,error,ser_di_d,~ser_di_d};
end end
endmodule endmodule
...@@ -30,7 +30,7 @@ module timestamp_fifo( ...@@ -30,7 +30,7 @@ module timestamp_fifo(
input pre_stb, // marks pre-first input byte (s0,s1,s2,s3,u0,u1,u2,u3) input pre_stb, // marks pre-first input byte (s0,s1,s2,s3,u0,u1,u2,u3)
input [7:0] din, // data in - valid for 8 cycles after pre_stb input [7:0] din, // data in - valid for 8 cycles after pre_stb
input aclk, // clock to synchronize advance puls input aclk, // clock to synchronize "advance" commands
input advance, // @aclk advance registers input advance, // @aclk advance registers
input rclk, // output clock input rclk, // output clock
...@@ -65,10 +65,10 @@ module timestamp_fifo( ...@@ -65,10 +65,10 @@ module timestamp_fifo(
always @(posedge rst or posedge rclk) begin always @(posedge rst or posedge rclk) begin
if (rst) snd <= 0; if (rst) snd <= 0;
else if (rstb) snd <= 1; else if (rstb) snd <= 1;
else if (&rpntr[2:0]) snd <= 0; else if (&rpntr[2:1]) snd <= 0; // at count 6
if (rst) rpntr[2:0] <= 0; if (rst) rpntr[2:0] <= 0;
else if (!snd) rpntr[2:0] <= 0; else if (!snd && !rstb) rpntr[2:0] <= 0;
else rpntr[2:0] <= rpntr[2:0] + 1; else rpntr[2:0] <= rpntr[2:0] + 1;
if (snd) dout <= fifo_ram[rpntr]; if (snd) dout <= fifo_ram[rpntr];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment