Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
x393
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
x393
Commits
e9862dab
Commit
e9862dab
authored
Jul 08, 2015
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converting event_logger to use serial timestamps and 4 sesnor channels
parent
6a297fff
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1190 additions
and
1162 deletions
+1190
-1162
buf_xclk_mclk16_393.v
logger/buf_xclk_mclk16_393.v
+38
-55
event_logger.v
logger/event_logger.v
+243
-200
imu_exttime393.v
logger/imu_exttime393.v
+155
-66
imu_message393.v
logger/imu_message393.v
+51
-66
imu_spi393.v
logger/imu_spi393.v
+283
-278
imu_timestamps393.v
logger/imu_timestamps393.v
+1
-1
logger_arbiter393.v
logger/logger_arbiter393.v
+97
-111
nmea_decoder393.v
logger/nmea_decoder393.v
+236
-281
rs232_rcv393.v
logger/rs232_rcv393.v
+81
-99
timestamp_fifo.v
timing/timestamp_fifo.v
+5
-5
No files found.
logger/buf_xclk_mclk16_393.v
View file @
e9862dab
...
...
@@ -4,7 +4,7 @@
* Author: andrey
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
...
...
@@ -21,21 +21,13 @@
`timescale
1
ns
/
1
ps
module
buf_xclk_mclk16_393
(
xclk
,
// posedge
mclk
,
// posedge
rst
,
// @posedge xclk
din
,
din_stb
,
dout
,
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
;
input
mclk
,
// system clock, posedge
input
xclk
,
// half frequency (80 MHz nominal)
input
rst
,
// @posedge xclk reset module
input
[
15
:
0
]
din
,
input
din_stb
,
output
reg
[
15
:
0
]
dout
,
output
reg
dout_stb
)
;
reg
[
1
:
0
]
wa
;
reg
[
1
:
0
]
wa_mclk
;
...
...
@@ -45,12 +37,12 @@ module buf_xclk_mclk16_393(
reg
[
1
:
0
]
ra_next
;
reg
inc_ra
;
wire
[
15
:
0
]
pre_dout
;
reg
[
15
:
0
]
dout
;
reg
dout_stb
;
always
@
(
posedge
xclk
)
begin
if
(
rst
)
wa
[
1
:
0
]
<=
2'h0
;
else
if
(
din_stb
)
wa
[
1
:
0
]
<={
wa
[
0
]
,~
wa
[
1
]
};
end
always
@
(
posedge
mclk
)
begin
wa_mclk
[
1
:
0
]
<=
wa
[
1
:
0
]
;
wa_mclk_d
[
1
:
0
]
<=
wa_mclk
[
1
:
0
]
;
...
...
@@ -66,18 +58,9 @@ module buf_xclk_mclk16_393(
if
(
inc_ra
)
dout
[
15
:
0
]
<=
pre_dout
[
15
:
0
]
;
end
myRAM_WxD_D
#(
.
DATA_WIDTH
(
16
)
,.
DATA_DEPTH
(
2
))
i_fifo_4x16
(
.
D
(
din
[
15
:
0
])
,
.
WE
(
din_stb
)
,
.
clk
(
xclk
)
,
.
AW
(
wa
[
1
:
0
])
,
.
AR
(
ra
[
1
:
0
])
,
.
QW
()
,
.
QR
(
pre_dout
[
15
:
0
]))
;
endmodule
reg
[
15
:
0
]
fifo_4x16_ram
[
0
:
3
]
;
always
@
(
posedge
xclk
)
if
(
din_stb
)
fifo_4x16_ram
[
wa
[
1
:
0
]]
<=
din
[
15
:
0
]
;
assign
pre_dout
[
15
:
0
]
=
fifo_4x16_ram
[
ra
[
1
:
0
]]
;
endmodule
logger/event_logger.v
View file @
e9862dab
This diff is collapsed.
Click to expand it.
logger/imu_exttime393.v
View file @
e9862dab
This diff is collapsed.
Click to expand it.
logger/imu_message393.v
View file @
e9862dab
...
...
@@ -4,7 +4,7 @@
* Author: andrey
* 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
* it under the terms of the GNU General Public License as published by
* 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
fixed-length de-noise circuitry with latency 256*T(xclk) (~3usec)
*/
module
imu_message393
(
sclk
,
// system clock, negedge
xclk
,
// half frequency (80 MHz nominal)
we
,
// write enable for registers to log (@negedge sclk), with lower data half
wa
,
// write address for register (4 bits, @negedge sclk)
di
,
// 16-bit data in multiplexed
en
,
// enable module operation, if 0 - reset
trig
,
// leading edge - sample time, trailing set rdy
ts
,
// timestamop request
rdy
,
// data ready
rd_stb
,
// data read strobe (increment address)
rdata
)
;
// data out (16 bits)
input
sclk
;
// system clock, negedge
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)
module
imu_message393
(
input
mclk
,
// system clock, negedge TODO:COnvert to posedge!
input
xclk
,
// half frequency (80 MHz nominal)
input
we
,
// write enable for registers to log (@negedge mclk), with lower data half
input
[
3
:
0
]
wa
,
// write address for register (4 bits, @negedge mclk)
// input [15:0] di, // 16-bit data in multiplexed
input
[
31
:
0
]
din
,
// 32-bit data in, non-multiplexed
input
en
,
// enable module operation, if 0 - reset
input
trig
,
// leading edge - sample time, trailing set rdy
output
ts
,
// timestamop request
output
rdy
,
// data ready
input
rd_stb
,
// data read strobe (increment address)
output
[
15
:
0
]
rdata
)
;
// data out (16 bits)
reg
[
4
:
0
]
raddr
;
reg
rdy
=
1'b0
;
reg
we_d
;
reg
[
4
:
1
]
waddr
;
reg
rdy_r
=
1'b0
;
reg
[
2
:
0
]
trig_d
;
reg
[
7
:
0
]
denoise_count
;
reg
[
1
:
0
]
trig_denoise
;
reg
ts
;
reg
[
15
:
0
]
di_d
;
reg
ts_r
;
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
if
(
!
en
)
trig_d
[
2
:
0
]
<=
3'h0
;
else
trig_d
[
2
:
0
]
<=
{
trig_d
[
1
:
0
]
,
trig
};
if
(
!
en
)
trig_denoise
[
0
]
<=
1'b0
;
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
;
else
denoise_count
[
7
:
0
]
<=
denoise_count
[
7
:
0
]
-
1
;
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
;
if
(
ts
||
(
rd_stb
&&
(
raddr
[
4
:
0
]
==
5'h1b
))
||
!
en
)
rdy
<=
1'b0
;
else
if
(
trig_denoise
[
1
]
&&
!
trig_denoise
[
0
])
rdy
<=
1'b1
;
if
(
ts_r
||
(
rd_stb
&&
(
raddr
[
4
:
0
]
==
5'h1b
))
||
!
en
)
rdy_r
<=
1'b0
;
else
if
(
trig_denoise
[
1
]
&&
!
trig_denoise
[
0
])
rdy_r
<=
1'b1
;
end
myRAM_WxD_D
#(
.
DATA_WIDTH
(
16
)
,.
DATA_DEPTH
(
5
))
i_odbuf
(
.
D
(
di_d
[
15
:
0
])
,
.
WE
(
we
|
we_d
)
,
.
clk
(
~
sclk
)
,
.
AW
(
{
waddr
[
4
:
1
]
,
we_d
}
)
,
.
AR
(
raddr
[
4
:
0
])
,
.
QW
()
,
.
QR
(
rdata
[
15
:
0
]))
;
endmodule
reg
[
31
:
0
]
odbuf0_ram
[
0
:
15
]
;
wire
[
31
:
0
]
odbuf0_ram_out
;
always
@
(
posedge
mclk
)
if
(
we
)
begin
odbuf0_ram
[
wa
[
3
:
0
]]
<=
din
[
31
:
0
]
;
end
assign
odbuf0_ram_out
=
odbuf0_ram
[
raddr
[
4
:
1
]]
;
assign
rdata
[
15
:
0
]
=
raddr
[
0
]
?
odbuf0_ram_out
[
15
:
0
]
:
odbuf0_ram_out
[
31
:
16
]
;
endmodule
logger/imu_spi393.v
View file @
e9862dab
This diff is collapsed.
Click to expand it.
logger/imu_timestamps393.v
View file @
e9862dab
...
...
@@ -4,7 +4,7 @@
* Author: andrey
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
...
...
logger/logger_arbiter393.v
View file @
e9862dab
...
...
@@ -4,7 +4,7 @@
* Author: andrey
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
...
...
@@ -21,19 +21,19 @@
`timescale
1
ns
/
1
ps
module
logger_arbiter393
(
xclk
,
// 80 MHz, posedge
rst
,
// module reset
ts_rq_in
,
// in requests for timestamp (single-cycle - just leading edge )
ts_rq
,
// out request for timestamp, to timestmp module
ts_grant
,
// granted ts requests from timestamping module
rdy
,
// channels ready (leading edge - became ready, trailing - no more data, use zero)
nxt
,
// pulses to modules to output next word
channel
,
// decoded channel number (2 bits)
ts_sel
,
// select timestamp word to be output (0..3)
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)
sample_counter
)
;
// number of 64-byte samples logged
input
xclk
,
// half frequency (80 MHz nominal)
input
rst
,
// module reset (sync)
input
[
3
:
0
]
ts_rq_in
,
// in requests for timestamp (single-cycle - just leading edge )
output
[
3
:
0
]
ts_rq
,
// out request for timestamp, to timestmp module
input
[
3
:
0
]
ts_grant
,
// granted ts requests from timestamping module
input
[
3
:
0
]
rdy
,
// channels ready (leading edge - became ready, trailing - no more data, use zero)
output
reg
[
3
:
0
]
nxt
,
// pulses to modules to output next word
output
[
1
:
0
]
channel
,
// decoded channel number (2 bits)
output
[
1
:
0
]
ts_sel
,
// select timestamp word to be output (0..3)
output
ts_en
,
// 1 - use timestamp, 0 - channel data (or 16'h0 if !ready)
output
reg
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
/*
input xclk; // half frequency (80 MHz nominal)
input rst; // reset module
input [ 3:0] ts_rq_in; // in requests for timestamp (sinlgle-cycle)
...
...
@@ -46,54 +46,53 @@ module logger_arbiter393(
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 [23:0] sample_counter;// number of 64-byte samples logged
*/
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_rq_reset;
reg
[
3
:
0
]
channels_ready
;
// channels granted and ready
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
[
1
:
0
]
channel
;
reg
start
;
reg
[
1
:
0
]
channel_r
;
// reg start; Not used!
reg
busy
;
wire
wstart
;
reg
ts_en
;
reg
ts_en_r
;
reg
[
4
:
0
]
seq_cntr
;
reg
seq_cntr_last
;
reg
[
1
:
0
]
ts_sel
;
reg
dv
;
reg
[
1
:
0
]
ts_sel_r
;
// reg
dv;
reg
inc_sample_counter
;
reg
[
23
:
0
]
sample_counte
r
;
// number of 64-byte samples logged
reg
[
3
:
0
]
nxt
;
reg
[
23
:
0
]
sample_counter_
r
;
// number of 64-byte samples logged
// reg
[ 3:0] nxt;
reg
pre_nxt
;
reg
[
3
:
0
]
chn_servicing
;
//1-hot channel being service
// reg [ 3:0] rdy_d;
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
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
]
};
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
;
// 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
[
3
:
0
]
<=
~
ts_grant
&
(
wts_rq
[
3
:
0
]
|
ts_rq
[
3
:
0
])
;
if
(
rst
)
ts_rq_r
[
3
:
0
]
<=
4'h0
;
else
ts_rq_r
[
3
:
0
]
<=
~
ts_grant
&
(
wts_rq
[
3
:
0
]
|
ts_rq_r
[
3
:
0
])
;
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
]))
;
// 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
rq_not_zero
<=
channels_ready
[
3
:
0
]
!=
4'h0
;
...
...
@@ -102,46 +101,33 @@ module logger_arbiter393(
channels_ready
[
2
]
&
~|
channels_ready
[
1
:
0
]
,
channels_ready
[
1
]
&
~
channels_ready
[
0
]
};
start
<=
wstart
;
// start <= wstart; Not used !
if
((
seq_cntr
[
4
:
0
]
==
'h1e
)
||
rst
)
busy
<=
1'b0
;
else
if
(
rq_not_zero
)
busy
<=
1'b1
;
// if (!busy) seq_cntr[4:0] <= 5'h1f;
if
(
!
busy
)
seq_cntr
[
4
:
0
]
<=
5'h0
;
else
seq_cntr
[
4
:
0
]
<=
seq_cntr
[
4
:
0
]
+
1
;
seq_cntr_last
<=
(
seq_cntr
[
4
:
0
]
==
'h1e
)
;
if
(
wstart
)
ts_en
<=
1'b1
;
else
if
(
seq_cntr
[
1
:
0
]
==
2'h3
)
ts_en
<=
1'b0
;
if
(
wstart
)
ts_en_r
<=
1'b1
;
else
if
(
seq_cntr
[
1
:
0
]
==
2'h3
)
ts_en_r
<=
1'b0
;
if
(
!
ts_en
)
ts_sel
[
1
:
0
]
<=
2'h0
;
else
ts_sel
[
1
:
0
]
<=
ts_sel
[
1
:
0
]
+
1
;
if
(
!
ts_en_r
)
ts_sel_r
[
1
:
0
]
<=
2'h0
;
else
ts_sel_r
[
1
:
0
]
<=
ts_sel_r
[
1
:
0
]
+
1
;
if
(
!
busy
||
(
seq_cntr
[
4
:
0
]
==
'h1d
))
pre_nxt
<=
1'b0
;
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
;
/*
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
;
inc_sample_counter
<=
seq_cntr_last
;
if
(
rst
)
sample_counter
[
23
:
0
]
<=
24'h0
;
else
if
(
inc_sample_counter
)
sample_counter
[
23
:
0
]
<=
sample_counter
[
23
:
0
]
+
1
;
if
(
rst
)
sample_counter_r
[
23
:
0
]
<=
24'h0
;
else
if
(
inc_sample_counter
)
sample_counter_r
[
23
:
0
]
<=
sample_counter_r
[
23
:
0
]
+
1
;
end
endmodule
\ No newline at end of file
logger/nmea_decoder393.v
View file @
e9862dab
This diff is collapsed.
Click to expand it.
logger/rs232_rcv393.v
View file @
e9862dab
...
...
@@ -4,7 +4,7 @@
* Author: andrey
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
...
...
@@ -21,32 +21,19 @@
`timescale
1
ns
/
1
ps
module
rs232_rcv393
(
xclk
,
// half frequency (80 MHz nominal)
bitHalfPeriod
,
// half of the serial bit duration, in xclk cycles
ser_di
,
// rs232 (ttl) serial data in
ser_rst
,
// reset (force re-sync)
ts_stb
,
// strobe timestamp (start of message) (reset bit counters in nmea decoder)
wait_just_pause
,
// may be used as reset for decoder
start
,
// serial character start (single pulse)
// char, // byte out
// char_stb); // char strobe (@posedge xclk)
ser_do
,
// serial data out(@posedge xclk) LSB first!
ser_do_stb
,
// output data strobe (@posedge xclk), first cycle after ser_do becomes valid
debug
,
// {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset
bit_dur_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
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) (reset bit counters in nmea decoder)
output
reg
wait_just_pause
,
// may be used as reset for decoder
output
start
,
// serial character start (single pulse)
output
reg
ser_do
,
// serial data out(@posedge xclk) LSB first!
output
reg
ser_do_stb
,
// output data strobe (@posedge xclk), first cycle after ser_do becomes valid
// Next outputs are just fro debugging
output
[
4
:
0
]
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
,
output
[
4
:
0
]
bit_cntr
)
;
reg
[
4
:
0
]
ser_di_d
;
reg
ser_filt_di
;
...
...
@@ -56,36 +43,37 @@ module rs232_rcv393(
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
receiving_byte
;
reg
start
;
reg
[
15
:
0
]
bit_dur_cnt
r
;
// bit duration counter (half bit duration)
reg
[
4
:
0
]
bit_cnt
r
;
// counts half-bit intervals
reg
start_r
;
reg
[
15
:
0
]
bit_dur_cntr_
r
;
// bit duration counter (half bit duration)
reg
[
4
:
0
]
bit_cntr_
r
;
// counts half-bit intervals
wire
error
;
// low level during stop slot
reg
[
1
:
0
]
restart
;
wire
reset_wait_pause
;
reg
ts_stb
;
reg
ts_stb_r
;
reg
shift_en
;
reg
ser_do
;
reg
ser_do_stb
;
wire
sample_bit
;
wire
reset_bit_duration
;
reg
wait_just_pause
;
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
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
sample_bit
=
shift_en
&&
bit_half_end
&&
!
bit_cntr
[
0
]
;
assign
reset_bit_duration
=
reset_wait_pause
||
start
||
bit_half_end
||
ser_rst
;
// 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
error
=
!
ser_filt_di
&&
last_half_bit
&&
bit_half_end
&&
receiving_byte
;
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
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
// 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
};
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
;
...
...
@@ -95,35 +83,29 @@ module rs232_rcv393(
wait_pause
<=
!
ser_rst
&&
(
reset_wait_pause
||
(
receiving_byte
&&
last_half_bit
&&
bit_half_end
)
||
(
wait_pause
&&
!
(
last_half_bit
&&
bit_half_end
)
&&
!
(
wait_start
&&
!
ser_filt_di
)))
;
// start <= wait_start && ser_di_d && !ser_di;
start
<=
wstart
;
// ts_stb <= !wait_pause && wait_start && ser_di_d && !ser_di;
ts_stb
<=
!
wait_pause
&&
wstart
;
// only first start after pause
bit_half_end
<=
(
bit_dur_cntr
[
15
:
0
]
==
16'h1
)
&&
!
reset_bit_duration
;
start_r
<=
wstart
;
ts_stb_r
<=
!
wait_pause
&&
wstart
;
// only first start after pause
bit_half_end
<=
(
bit_dur_cntr_r
[
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
))
;
// receiving_byte <= !ser_rst && !error && (start || (receiving_byte && !(last_half_bit && bit_half_end)));
receiving_byte
<=
!
ser_rst
&&
(
start
||
(
receiving_byte
&&
!
(
last_half_bit
&&
bit_half_end
)))
;
receiving_byte
<=
!
ser_rst
&&
(
start_r
||
(
receiving_byte
&&
!
(
last_half_bit
&&
bit_half_end
)))
;
wait_just_pause
<=
wait_pause
&&
!
wait_start
;
if
(
reset_bit_duration
)
bit_dur_cnt
r
[
15
:
0
]
<=
bitHalfPeriod
[
15
:
0
]
;
else
bit_dur_cntr
[
15
:
0
]
<=
bit_dur_cnt
r
[
15
:
0
]
-
1
;
if
(
reset_bit_duration
)
bit_dur_cntr_
r
[
15
:
0
]
<=
bitHalfPeriod
[
15
:
0
]
;
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
;
else
if
(
start
)
bit_cntr
[
4
:
0
]
<=
5'h12
;
else
if
(
bit_half_end
)
bit_cntr
[
4
:
0
]
<=
bit_cntr
[
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
)
;
if
(
reset_wait_pause
||
ser_rst
)
bit_cntr_r
[
4
:
0
]
<=
5'h13
;
else
if
(
start_r
)
bit_cntr_r
[
4
:
0
]
<=
5'h12
;
else
if
(
bit_half_end
)
bit_cntr_r
[
4
:
0
]
<=
bit_cntr_r
[
4
:
0
]
-
1
;
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
;
ser_do_stb
<=
sample_bit
;
if
(
ser_rst
)
debug0
[
4
:
0
]
<=
5'b0
;
else
debug0
[
4
:
0
]
<=
debug
|
{
ts_stb
,
start
,
error
,
ser_di_d
,~
ser_di_d
};
// 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};
end
endmodule
timing/timestamp_fifo.v
View file @
e9862dab
...
...
@@ -30,7 +30,7 @@ module timestamp_fifo(
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
aclk
,
// clock to synchronize
advance pul
s
input
aclk
,
// clock to synchronize
"advance" command
s
input
advance
,
// @aclk advance registers
input
rclk
,
// output clock
...
...
@@ -65,10 +65,10 @@ module timestamp_fifo(
always
@
(
posedge
rst
or
posedge
rclk
)
begin
if
(
rst
)
snd
<=
0
;
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
;
else
if
(
!
snd
)
rpntr
[
2
:
0
]
<=
0
;
else
if
(
!
snd
&&
!
rstb
)
rpntr
[
2
:
0
]
<=
0
;
else
rpntr
[
2
:
0
]
<=
rpntr
[
2
:
0
]
+
1
;
if
(
snd
)
dout
<=
fifo_ram
[
rpntr
]
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment