otsdaq_prepmodernization
v2_05_02_indev
Return to top level
Main Page
Classes
Files
File List
ram_comm_dec.vhd
1
-------------------------------------------------------------------------------
2
--
3
-- Title : RAM_COMM_DEC
4
-- Design : ethernet_controller
5
-- Author : aprosser
6
-- Company : CD_CEPA_ESE
7
--
8
-------------------------------------------------------------------------------
9
--
10
-- File : d:\Projects\otsdaq\OtS Ethernet MAC firmware\ActiveHDL_proj\ethernet_controller\compile\ram_comm_dec.vhd
11
-- Generated : 02/29/16 11:09:23
12
-- From : d:/Projects/otsdaq/OtS Ethernet MAC firmware/ActiveHDL_proj/ethernet_controller/src/ram_comm_dec.asf
13
-- By : FSM2VHDL ver. 5.0.7.2
14
--
15
-------------------------------------------------------------------------------
16
--
17
-- Description :
18
--
19
-------------------------------------------------------------------------------
20
21
library
IEEE
;
22
use
IEEE.std_logic_1164.
all
;
23
use
IEEE.NUMERIC_STD.
all
;
24
use
work.params_package.
all
;
25
26
entity
ram_comm_dec
is
27
port
(
28
clock
:
in
STD_LOGIC
;
29
crc_err_flag
:
in
STD_LOGIC
;
30
reset
:
in
STD_LOGIC
;
31
rx_data_fifo_full
:
in
STD_LOGIC
;
32
rx_data_fifo_rd_data
:
in
STD_LOGIC_VECTOR
(
63
downto
0
)
;
33
rx_info_fifo_empty
:
in
STD_LOGIC
;
34
rx_info_fifo_full
:
in
STD_LOGIC
;
35
rx_info_fifo_rd_data
:
in
STD_LOGIC_VECTOR
(
15
downto
0
)
;
36
tx_info_fifo_full
:
in
STD_LOGIC
;
37
user_ready
:
in
STD_LOGIC
;
38
user_rx_valid_out
:
in
STD_LOGIC
;
39
clear_crc_err_flag
:
out
STD_LOGIC
;
40
ram_addr
:
out
STD_LOGIC_VECTOR
(
63
downto
0
)
;
41
ram_rden
:
out
STD_LOGIC
;
42
ram_wdata
:
out
STD_LOGIC_VECTOR
(
63
downto
0
)
;
43
ram_wren
:
out
STD_LOGIC
;
44
rx_data_fifo_rden
:
out
STD_LOGIC
;
45
Rx_FIFO_Reset
:
out
STD_LOGIC
;
46
rx_info_fifo_rden
:
out
STD_LOGIC
;
47
tx_data_fifo_wren
:
out
STD_LOGIC
;
48
Tx_FIFO_Reset
:
out
STD_LOGIC
;
49
tx_info_fifo_wr_data
:
out
STD_LOGIC_VECTOR
(
15
downto
0
)
;
50
tx_info_fifo_wren
:
out
STD_LOGIC
)
;
51
end
ram_comm_dec
;
52
53
architecture
arch
of
ram_comm_dec
is
54
55
-- diagram signals declarations
56
signal
comm_dec_ready
:
STD_LOGIC
;
57
signal
comm_reg
:
STD_LOGIC
;
58
signal
crc_err
:
STD_LOGIC
;
59
signal
first_write_qword
:
STD_LOGIC
;
60
signal
mem_loc_count_reg
:
UNSIGNED
(
7
downto
0
)
;
61
signal
no_addrs_incr
:
STD_LOGIC
;
62
signal
no_ret_to_sender
:
STD_LOGIC
;
63
signal
q_w_count_reg
:
UNSIGNED
(
7
downto
0
)
;
64
signal
ram_addr_sig
:
UNSIGNED
(
63
downto
0
)
;
65
signal
ram_rden_sig
:
STD_LOGIC
;
66
signal
ram_wren_sig
:
STD_LOGIC
;
67
signal
rx_data_fifo_full_flag
:
STD_LOGIC
;
68
signal
rx_data_fifo_rden_sig
:
STD_LOGIC
;
69
signal
rx_info_fifo_full_flag
:
STD_LOGIC
;
70
signal
rx_protocol_err_flag
:
STD_LOGIC
;
71
signal
user_ready_mask
:
STD_LOGIC
;
72
73
-- BINARY ENCODED state machine: Sreg0
74
attribute
ENUM_ENCODING
:
string
;
75
type
Sreg0_type
is
(
76
write_com_S8
,
read_com_S13
,
read_com_S14
,
read_com_S15
,
read_com_S1
,
read_com_S18
,
write_com_S42
,
write_com_S40
,
write_com_S9
,
77
pro_comm
,
dec_comm
,
idle
,
return_st
,
get_comm
,
err_dec
78
)
;
79
attribute
ENUM_ENCODING
of
Sreg0_type
:
type
is
80
"0000 "
&
-- write_com_S8
81
"0001 "
&
-- read_com_S13
82
"0010 "
&
-- read_com_S14
83
"0011 "
&
-- read_com_S15
84
"0100 "
&
-- read_com_S1
85
"0101 "
&
-- read_com_S18
86
"0110 "
&
-- write_com_S42
87
"0111 "
&
-- write_com_S40
88
"1000 "
&
-- write_com_S9
89
"1001 "
&
-- pro_comm
90
"1010 "
&
-- dec_comm
91
"1011 "
&
-- idle
92
"1100 "
&
-- return_st
93
"1101 "
&
-- get_comm
94
"1110"
;
-- err_dec
95
96
signal
Sreg0
:
Sreg0_type
;
97
98
attribute
STATE_VECTOR
:
string
;
99
attribute
STATE_VECTOR
of
arch
:
architecture
is
"Sreg0"
;
100
101
begin
102
103
-- concurrent signals assignments
104
105
-- Diagram ACTION
106
ram_rden
<=
ram_rden_sig
;
107
ram_wren
<=
ram_wren_sig
;
108
rx_data_fifo_rden
<=
rx_data_fifo_rden_sig
or
(
user_ready
and
user_ready_mask
)
;
109
---- handle generating ready sig once a sufficient
110
---- time has passed since last received packet
111
---- to gaurantee crc err has been considered
112
----
113
---- also, handle generating rx fifo full flags
114
flag_handling_gen :
for
i
in
0
to
0
generate
115
signal
tmp_cnt
:
unsigned
(
4
downto
0
)
:=
(
others
=
>
'
1
'
)
;
116
signal
old_rx_v
:
std_logic
;
117
signal
is_counting
:
std_logic
:=
'
0
'
;
118
begin
119
process
(clock)
120
begin
121
if
(
rising_edge
(
clock
)
)
then
122
old_rx_v
<=
user_rx_valid_out
;
123
if
(
reset
=
'
1
'
)
then
124
tmp_cnt
<=
(
others
=
>
'
1
'
)
;
125
comm_dec_ready
<=
'
1
'
;
126
rx_info_fifo_full_flag
<=
'
0
'
;
127
rx_data_fifo_full_flag
<=
'
0
'
;
128
else
129
-- manage comm_dec_ready signal
130
if
(
old_rx_v
=
'
0
'
and
user_rx_valid_out
=
'
1
'
)
then
131
-- reset signal at start of receiving a packet
132
comm_dec_ready
<=
'
0
'
;
133
is_counting
<=
'
0
'
;
134
tmp_cnt
<=
(
others
=
>
'
1
'
)
;
135
else
136
if
(
old_rx_v
=
'
1
'
and
user_rx_valid_out
=
'
0
'
)
then
137
is_counting
<=
'
1
'
;
138
-- start counting after packet rcv'd
139
end
if
;
140
if
(
tmp_cnt
=
0
)
then
-- done waiting for crc, let's go!
141
comm_dec_ready
<=
'
1
'
;
142
elsif
(
is_counting
=
'
1
'
)
then
-- count down waiting for crc
143
tmp_cnt
<=
tmp_cnt
-
1
;
144
end
if
;
145
end
if
;
146
if
(
rx_info_fifo_full
=
'
1
'
)
then
147
rx_info_fifo_full_flag
<=
'
1
'
;
148
--hold full flag until reset!
149
end
if
;
150
if
(
rx_data_fifo_full
=
'
1
'
)
then
151
rx_data_fifo_full_flag
<=
'
1
'
;
152
--hold full flag until reset!
153
end
if
;
154
end
if
;
155
end
if
;
156
end
process
;
157
end
generate
;
158
159
----------------------------------------------------------------------
160
-- Machine: Sreg0
161
----------------------------------------------------------------------
162
Sreg0_machine:
process
(clock)
163
begin
164
if
clock
'
event
and
clock
=
'
1
'
then
165
if
reset
=
'
1
'
then
166
Sreg0
<=
idle
;
167
-- Set default values for outputs, signals and variables
168
tx_info_fifo_wren
<=
'
0
'
;
169
Rx_FIFO_Reset
<=
'
0
'
;
170
Tx_FIFO_Reset
<=
'
0
'
;
171
clear_crc_err_flag
<=
'
0
'
;
172
-- Initialize registers
173
comm_reg
<=
'
0
'
;
174
q_w_count_reg
<=
(
others
=
>
'
0
'
)
;
175
mem_loc_count_reg
<=
(
others
=
>
'
0
'
)
;
176
crc_err
<=
'
0
'
;
177
rx_protocol_err_flag
<=
'
0
'
;
178
--indicates err in packets received (sz 0 read/write?!)
179
-- Initialize outputs
180
tx_info_fifo_wr_data
<=
(
others
=
>
'
0
'
)
;
181
tx_info_fifo_wren
<=
'
0
'
;
182
tx_data_fifo_wren
<=
'
0
'
;
183
-- ram controls
184
ram_wdata
<=
(
others
=
>
'
0
'
)
;
185
ram_addr_sig
<=
(
others
=
>
'
0
'
)
;
186
ram_wren_sig
<=
'
0
'
;
187
ram_rden_sig
<=
'
0
'
;
188
rx_info_fifo_rden
<=
'
0
'
;
189
rx_data_fifo_rden_sig
<=
'
0
'
;
190
Rx_FIFO_Reset
<=
'
1
'
;
191
-- Reset FIFOs
192
Tx_FIFO_Reset
<=
'
1
'
;
193
no_addrs_incr
<=
'
0
'
;
194
first_write_qword
<=
'
0
'
;
195
user_ready_mask
<=
'
0
'
;
196
else
197
-- Set default values for outputs, signals and variables
198
tx_info_fifo_wren
<=
'
0
'
;
199
Rx_FIFO_Reset
<=
'
0
'
;
200
Tx_FIFO_Reset
<=
'
0
'
;
201
clear_crc_err_flag
<=
'
0
'
;
202
case
Sreg0
is
203
when
pro_comm
=
>
204
Sreg0
<=
err_dec
;
205
comm_reg
<=
rx_info_fifo_rd_data
(
0
)
;
206
-- 1 write/0 read
207
q_w_count_reg
<=
unsigned
(
rx_info_fifo_rd_data
(
15
downto
8
)
)
;
208
-- get the number of 8 byte quad words from
209
-- the info fifo word
210
crc_err
<=
crc_err_flag
;
211
-- get the crc error indicator
212
no_addrs_incr
<=
rx_info_fifo_rd_data
(
3
)
;
213
-- get the no addr increment flag
214
no_ret_to_sender
<=
rx_info_fifo_rd_data
(
1
)
;
215
-- get the no return to sender flag
216
mem_loc_count_reg
<=
unsigned
(
rx_info_fifo_rd_data
(
15
downto
8
)
)
;
217
tx_info_fifo_wr_data
(
7
)
<=
rx_info_fifo_rd_data
(
7
)
;
218
tx_info_fifo_wr_data
(
6
)
<=
crc_err_flag
;
219
tx_info_fifo_wr_data
(
5
)
<=
rx_data_fifo_full_flag
or
rx_info_fifo_full_flag
;
220
tx_info_fifo_wr_data
(
4
)
<=
rx_protocol_err_flag
;
221
if
(
rx_info_fifo_rd_data
(
2
)
=
'
1
'
or
crc_err_flag
=
'
1
'
)
then
--ACK
222
-- handle ACK info (no data for ACK)
223
tx_info_fifo_wr_data
(
15
downto
8
)
<=
(
others
=
>
'
0
'
)
;
224
--size 0
225
tx_info_fifo_wr_data
(
3
downto
0
)
<=
rx_info_fifo_rd_data
(
3
downto
0
)
;
226
tx_info_fifo_wren
<=
'
1
'
;
227
-- write to tx info fifo
228
end
if
;
229
when
dec_comm
=
>
230
if
comm_reg
=
'
0
'
then
231
Sreg0
<=
read_com_S1
;
232
elsif
comm_reg
=
'
1
'
then
233
Sreg0
<=
write_com_S8
;
234
rx_data_fifo_rden_sig
<=
'
1
'
;
235
-- read address qword
236
else
237
Sreg0
<=
return_st
;
238
--unrecognized command!
239
Rx_FIFO_Reset
<=
'
1
'
;
240
end
if
;
241
when
idle
=
>
242
if
comm_dec_ready
=
'
1
'
and
rx_info_fifo_empty
=
'
0
'
then
243
Sreg0
<=
get_comm
;
244
rx_info_fifo_rden
<=
'
1
'
;
245
end
if
;
246
when
return_st
=
>
247
Sreg0
<=
idle
;
248
when
get_comm
=
>
249
Sreg0
<=
pro_comm
;
250
rx_info_fifo_rden
<=
'
0
'
;
251
when
err_dec
=
>
252
if
crc_err
=
'
1
'
then
253
Sreg0
<=
return_st
;
254
Rx_FIFO_Reset
<=
'
1
'
;
255
clear_crc_err_flag
<=
'
1
'
;
256
else
257
Sreg0
<=
dec_comm
;
258
end
if
;
259
when
read_com_S13
=
>
260
if
(
mem_loc_count_reg
=
1
and
user_ready
=
'
1
'
)
then
261
ram_rden_sig
<=
'
0
'
;
262
--done
263
else
264
ram_rden_sig
<=
'
1
'
;
265
-- Enable the RAM
266
end
if
;
267
if
(
user_ready
=
'
1
'
)
then
-- only if user is ready take next data
268
if
(
no_addrs_incr
=
'
0
'
and
mem_loc_count_reg
/=
1
)
then
269
ram_addr_sig
<=
ram_addr_sig
+
1
;
270
end
if
;
271
mem_loc_count_reg
<=
mem_loc_count_reg
-
1
;
272
end
if
;
273
-- write data into fifo 1 clock later if user's data is ready
274
tx_data_fifo_wren
<=
user_ready
and
ram_rden_sig
;
275
if
mem_loc_count_reg
=
1
and
user_ready
=
'
1
'
then
-- done with read
276
Sreg0
<=
read_com_S15
;
277
tx_info_fifo_wr_data
(
15
downto
8
)
<=
std_logic_vector
(
q_w_count_reg
)
;
278
tx_info_fifo_wr_data
(
1
)
<=
no_ret_to_sender
;
279
tx_info_fifo_wr_data
(
2
)
<=
'
0
'
;
280
tx_info_fifo_wr_data
(
0
)
<=
'
0
'
;
281
tx_info_fifo_wren
<=
'
1
'
;
282
end
if
;
283
when
read_com_S14
=
>
284
Sreg0
<=
read_com_S18
;
285
rx_data_fifo_rden_sig
<=
'
0
'
;
286
when
read_com_S15
=
>
287
Sreg0
<=
return_st
;
288
tx_data_fifo_wren
<=
'
0
'
;
289
when
read_com_S1
=
>
290
if
q_w_count_reg
=
0
then
-- err? there is no starting address
291
Sreg0
<=
read_com_S15
;
292
rx_protocol_err_flag
<=
'
1
'
;
293
--err in protocol!
294
Rx_FIFO_Reset
<=
'
1
'
;
295
tx_info_fifo_wr_data
(
15
downto
8
)
<=
std_logic_vector
(
q_w_count_reg
)
;
296
tx_info_fifo_wr_data
(
1
)
<=
no_ret_to_sender
;
297
tx_info_fifo_wr_data
(
2
)
<=
'
0
'
;
298
tx_info_fifo_wr_data
(
0
)
<=
'
0
'
;
299
tx_info_fifo_wren
<=
'
1
'
;
300
else
301
Sreg0
<=
read_com_S14
;
302
-- there is at least one quad word in the data fifo
303
rx_data_fifo_rden_sig
<=
'
1
'
;
304
end
if
;
305
when
read_com_S18
=
>
306
Sreg0
<=
read_com_S13
;
307
ram_addr_sig
<=
unsigned
(
rx_data_fifo_rd_data
)
;
308
-- obtain starting address
309
ram_rden_sig
<=
'
1
'
;
310
-- enable ram read
311
when
write_com_S8
=
>
312
if
q_w_count_reg
=
0
then
-- err? there is no starting address
313
Sreg0
<=
return_st
;
314
rx_protocol_err_flag
<=
'
1
'
;
315
--err in protocol!
316
Rx_FIFO_Reset
<=
'
1
'
;
317
-- Turn off read accesses of the
318
rx_data_fifo_rden_sig
<=
'
0
'
;
319
else
320
Sreg0
<=
write_com_S40
;
321
first_write_qword
<=
'
1
'
;
322
rx_data_fifo_rden_sig
<=
'
1
'
;
323
--read first data qword
324
end
if
;
325
when
write_com_S42
=
>
326
if
user_ready
=
'
1
'
then
327
Sreg0
<=
return_st
;
328
ram_wren_sig
<=
'
0
'
;
329
--done with write
330
end
if
;
331
when
write_com_S40
=
>
332
Sreg0
<=
write_com_S9
;
333
ram_addr_sig
<=
unsigned
(
rx_data_fifo_rd_data
)
;
334
--set base address
335
if
(
mem_loc_count_reg
=
1
)
then
336
-- Turn off read accesses (done)
337
rx_data_fifo_rden_sig
<=
'
0
'
;
338
else
339
user_ready_mask
<=
'
1
'
;
340
-- allow user_ready to control rden of fifo
341
end
if
;
342
mem_loc_count_reg
<=
mem_loc_count_reg
-
1
;
343
when
write_com_S9
=
>
344
ram_wren_sig
<=
'
1
'
;
345
-- flag for writing
346
if
(
first_write_qword
=
'
1
'
)
then
347
first_write_qword
<=
'
0
'
;
348
end
if
;
349
if
(
first_write_qword
=
'
1
'
or
user_ready
=
'
1
'
)
then
350
ram_wdata
<=
rx_data_fifo_rd_data
;
351
--output next write data
352
end
if
;
353
rx_data_fifo_rden_sig
<=
'
0
'
;
354
--let user ready control rden strobe
355
if
(
mem_loc_count_reg
=
1
and
user_ready
=
'
1
'
)
then
356
-- Turn off read accesses (done)
357
user_ready_mask
<=
'
0
'
;
358
-- disallow user_ready to control rden of fifo
359
--else
360
-- read data out of fifo 1 clock later if user is ready
361
--rx_data_fifo_rden_sig <= user_ready;
362
-- data is assumed ready on next clock (1 clock fifo read)
363
end
if
;
364
--handle write address
365
if
(
user_ready
=
'
1
'
and
no_addrs_incr
=
'
0
'
and
first_write_qword
=
'
0
'
)
then
366
ram_addr_sig
<=
ram_addr_sig
+
1
;
367
end
if
;
368
--handle tracking number of words left in fifo
369
if
(
user_ready
=
'
1
'
or
first_write_qword
=
'
1
'
)
then
370
mem_loc_count_reg
<=
mem_loc_count_reg
-
1
;
371
end
if
;
372
if
mem_loc_count_reg
=
0
then
373
Sreg0
<=
write_com_S42
;
374
user_ready_mask
<=
'
0
'
;
375
-- disallow user_ready to control rden of fifo
376
end
if
;
377
--vhdl_cover_off
378
when
others
=
>
379
null
;
380
--vhdl_cover_on
381
end
case
;
382
end
if
;
383
end
if
;
384
end
process
;
385
386
-- signal assignment statements for combinatorial outputs
387
ram_addr_assignment
:
388
ram_addr
<=
std_logic_vector
(
ram_addr_sig
)
when
(
Sreg0
=
idle
)
else
389
std_logic_vector
(
ram_addr_sig
)
;
390
391
end
arch
;
ram_comm_dec
Definition:
ram_comm_dec.vhd:26
otsdaq_prepmodernization
firmware
g-2
KickerControllerFirmware
oei
ram_comm_dec.vhd
Generated on Wed Apr 29 2020 18:41:42 for otsdaq_prepmodernization by
1.8.5