x393
1.0
FPGAcodeforElphelNC393camera
logger_arbiter393.v
Go to the documentation of this file.
1
39
`timescale 1ns/1ps
40
41
module
logger_arbiter393
(
42
input
xclk
,
// half frequency (80 MHz nominal)
43
input
rst
,
// module reset (sync)
44
input
[
3
:
0
]
ts_rq_in
,
// in requests for timestamp (single-cycle - just leading edge )
45
output
[
3
:
0
]
ts_rq
,
// out request for timestamp, to timestmp module
46
input
[
3
:
0
]
ts_grant
,
// granted ts requests from timestamping module
47
input
[
3
:
0
]
rdy
,
// channels ready (leading edge - became ready, trailing - no more data, use zero)
48
output
reg
[
3
:
0
]
nxt
,
// pulses to modules to output next word
49
output
[
1
:
0
]
channel
,
// decoded channel number (2 bits)
50
output
[
1
:
0
]
ts_sel
,
// select timestamp word to be output (0..3)
51
output
ts_en
,
// 1 - use timestamp, 0 - channel data (or 16'h0 if !ready)
52
output
reg
dv
,
// output data valid (from registered mux - 2 stage - first selects data and ready, second ts/data/zero)
53
output
[
23
:
0
]
sample_counter
);
// number of 64-byte samples logged
54
/*
55
input xclk; // half frequency (80 MHz nominal)
56
input rst; // reset module
57
input [ 3:0] ts_rq_in; // in requests for timestamp (sinlgle-cycle)
58
output [ 3:0] ts_rq; // out request for timestamp, to timestmp module
59
input [ 3:0] ts_grant; // granted ts requests from timestamping module
60
input [ 3:0] rdy; // channels ready (leading edge - became ready, trailing - no more data, use zero)
61
output [ 3:0] nxt; // pulses to modules to output next word
62
output [ 1:0] channel; // decoded channel number (2 bits)
63
output [ 1:0] ts_sel; // select timestamp word to be output (0..3)
64
output ts_en; // 1 - use timestamp, 0 - channel data (or 16'h0 if !ready)
65
output dv; // output data valid (from registered mux - 2 stage - first selects data and ready, second ts/data/zero)
66
output [23:0] sample_counter;// number of 64-byte samples logged
67
*/
68
reg
[
3
:
0
]
ts_rq_in_d
;
69
reg
[
3
:
0
]
ts_rq_r
;
70
reg
[
3
:
0
]
ts_valid
;
71
// reg [3:0] ts_rq_reset;
72
reg
[
3
:
0
]
channels_ready
;
// channels granted and ready
73
reg
[
3
:
1
]
chn1hot
;
// channels 1-hot - granted and ready, priority applied
74
reg
rq_not_zero
;
// at least one channel is ready for processing (same time as chn1hot[3:0])
75
reg
[
1
:
0
]
channel_r
;
76
// reg start; Not used!
77
reg
busy
;
78
wire
wstart
;
79
reg
ts_en_r
;
80
reg
[
4
:
0
]
seq_cntr
;
81
reg
seq_cntr_last
;
82
reg
[
1
:
0
]
ts_sel_r
;
83
// reg dv;
84
reg
inc_sample_counter
;
85
reg
[
23
:
0
]
sample_counter_r
;
// number of 64-byte samples logged
86
// reg [ 3:0] nxt;
87
reg
pre_nxt
;
88
reg
[
3
:
0
]
chn_servicing
;
//1-hot channel being service
89
wire
[
3
:
0
]
wts_rq
;
90
91
assign
wstart
= !
busy
&&
rq_not_zero
;
92
assign
wts_rq
[
3
:
0
] =
ts_rq_in
[
3
:
0
] & ~
ts_rq_in_d
[
3
:
0
] & (~
rdy
[
3
:
0
] |
chn_servicing
[
3
:
0
]);
93
assign
sample_counter
=
sample_counter_r
;
94
assign
ts_rq
=
ts_rq_r
;
95
assign
channel
=
channel_r
;
96
assign
ts_en
=
ts_en_r
;
97
assign
ts_sel
=
ts_sel_r
;
98
99
always
@ (
posedge
xclk
)
begin
100
ts_rq_in_d
[
3
:
0
] <=
ts_rq_in
[
3
:
0
];
101
102
if
(
wstart
)
channel_r
[
1
:
0
] <= {
chn1hot
[
3
] |
chn1hot
[
2
],
chn1hot
[
3
] |
chn1hot
[
1
]};
103
104
if
(
wstart
)
chn_servicing
[
3
:
0
] <= {
chn1hot
[
3
:
1
], ~|
chn1hot
[
3
:
1
]};
105
else
if
(!
busy
)
chn_servicing
[
3
:
0
] <=
4'h0
;
106
107
108
if
(
rst
)
ts_rq_r
[
3
:
0
] <=
4'h0
;
109
else
ts_rq_r
[
3
:
0
] <= ~
ts_grant
& (
wts_rq
[
3
:
0
] |
ts_rq_r
[
3
:
0
]);
110
111
if
(
rst
)
ts_valid
[
3
:
0
] <=
4'h0
;
112
else
ts_valid
[
3
:
0
] <= (
ts_grant
[
3
:
0
] | (
ts_valid
& ~
wts_rq
[
3
:
0
]));
113
114
channels_ready
[
3
:
0
] <=
ts_valid
[
3
:
0
] &
rdy
[
3
:
0
] & ~
chn_servicing
[
3
:
0
];
// ready should go down during servicing
115
116
rq_not_zero
<=
channels_ready
[
3
:
0
] !=
4'h0
;
117
118
chn1hot
[
3
:
1
] <= {
channels_ready
[
3
] & ~|
channels_ready
[
2
:
0
],
119
channels_ready
[
2
] & ~|
channels_ready
[
1
:
0
],
120
channels_ready
[
1
] & ~
channels_ready
[
0
]};
121
122
// start <= wstart; Not used !
123
124
if
((
seq_cntr
[
4
:
0
]==
'h1e
) ||
rst
)
busy
<=
1'b0
;
125
else
if
(
rq_not_zero
)
busy
<=
1'b1
;
126
127
if
(!
busy
)
seq_cntr
[
4
:
0
] <=
5'h0
;
128
else
seq_cntr
[
4
:
0
] <=
seq_cntr
[
4
:
0
] +
1
;
129
130
seq_cntr_last
<= (
seq_cntr
[
4
:
0
]==
'h1e
);
131
132
133
if
(
wstart
)
ts_en_r
<=
1'b1
;
134
else
if
(
seq_cntr
[
1
:
0
]==
2'h3
)
ts_en_r
<=
1'b0
;
135
136
if
(!
ts_en_r
)
ts_sel_r
[
1
:
0
] <=
2'h0
;
137
else
ts_sel_r
[
1
:
0
] <=
ts_sel_r
[
1
:
0
] +
1
;
138
139
if
(!
busy
|| (
seq_cntr
[
4
:
0
]==
'h1d
))
pre_nxt
<=
1'b0
;
140
else
if
(
seq_cntr
[
4
:
0
]==
'h01
)
pre_nxt
<=
1'b1
;
141
142
nxt
[
3
:
0
] <=
pre_nxt
?
chn_servicing
[
3
:
0
]:
4'h0
;
143
144
dv
<=
busy
||
seq_cntr_last
;
145
146
inc_sample_counter
<=
seq_cntr_last
;
147
148
if
(
rst
)
sample_counter_r
[
23
:
0
] <=
24'h0
;
149
else
if
(
inc_sample_counter
)
sample_counter_r
[
23
:
0
] <=
sample_counter_r
[
23
:
0
] +
1
;
150
end
151
endmodule
logger_arbiter393
Definition:
logger_arbiter393.v:41
logger_arbiter393.3749chn_servicing
3749chn_servicingreg[3:0]
Definition:
logger_arbiter393.v:88
logger_arbiter393.3726rdy
[3:0] 3726rdy
Definition:
logger_arbiter393.v:47
logger_arbiter393.3721xclk
3721xclk
Definition:
logger_arbiter393.v:42
logger_arbiter393.3722rst
3722rst
Definition:
logger_arbiter393.v:43
logger_arbiter393.3732sample_counter
[23:0] 3732sample_counter
Definition:
logger_arbiter393.v:53
logger_arbiter393.3743seq_cntr
3743seq_cntrreg[4:0]
Definition:
logger_arbiter393.v:80
logger_arbiter393.3725ts_grant
[3:0] 3725ts_grant
Definition:
logger_arbiter393.v:46
logger_arbiter393.3742ts_en_r
3742ts_en_rreg
Definition:
logger_arbiter393.v:79
logger_arbiter393.3738rq_not_zero
3738rq_not_zeroreg
Definition:
logger_arbiter393.v:74
logger_arbiter393.3735ts_valid
3735ts_validreg[3:0]
Definition:
logger_arbiter393.v:70
logger_arbiter393.3734ts_rq_r
3734ts_rq_rreg[3:0]
Definition:
logger_arbiter393.v:69
logger_arbiter393.3744seq_cntr_last
3744seq_cntr_lastreg
Definition:
logger_arbiter393.v:81
logger_arbiter393.3740busy
3740busyreg
Definition:
logger_arbiter393.v:77
logger_arbiter393.3750wts_rq
3750wts_rqwire[3:0]
Definition:
logger_arbiter393.v:89
logger_arbiter393.3727nxt
reg [3:0] 3727nxt
Definition:
logger_arbiter393.v:48
logger_arbiter393.3733ts_rq_in_d
3733ts_rq_in_dreg[3:0]
Definition:
logger_arbiter393.v:68
logger_arbiter393.3737chn1hot
3737chn1hotreg[3:1]
Definition:
logger_arbiter393.v:73
logger_arbiter393.3748pre_nxt
3748pre_nxtreg
Definition:
logger_arbiter393.v:87
logger_arbiter393.3724ts_rq
[3:0] 3724ts_rq
Definition:
logger_arbiter393.v:45
logger_arbiter393.3729ts_sel
[1:0] 3729ts_sel
Definition:
logger_arbiter393.v:50
logger_arbiter393.3730ts_en
3730ts_en
Definition:
logger_arbiter393.v:51
logger_arbiter393.3731dv
reg 3731dv
Definition:
logger_arbiter393.v:52
logger_arbiter393.3745ts_sel_r
3745ts_sel_rreg[1:0]
Definition:
logger_arbiter393.v:82
logger_arbiter393.3736channels_ready
3736channels_readyreg[3:0]
Definition:
logger_arbiter393.v:72
logger_arbiter393.3739channel_r
3739channel_rreg[1:0]
Definition:
logger_arbiter393.v:75
logger_arbiter393.3746inc_sample_counter
3746inc_sample_counterreg
Definition:
logger_arbiter393.v:84
logger_arbiter393.3741wstart
3741wstartwire
Definition:
logger_arbiter393.v:78
logger_arbiter393.3728channel
[1:0] 3728channel
Definition:
logger_arbiter393.v:49
logger_arbiter393.3723ts_rq_in
[3:0] 3723ts_rq_in
Definition:
logger_arbiter393.v:44
logger_arbiter393.3747sample_counter_r
3747sample_counter_rreg[23:0]
Definition:
logger_arbiter393.v:85
logger
logger_arbiter393.v
Generated by
1.8.12