This repository was archived by the owner on Oct 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathstream_FrameGenerator.vhdl
More file actions
300 lines (251 loc) · 8.19 KB
/
stream_FrameGenerator.vhdl
File metadata and controls
300 lines (251 loc) · 8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
-- EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
-- vim: tabstop=2:shiftwidth=2:noexpandtab
-- kate: tab-width 2; replace-tabs off; indent-width 2;
-- =============================================================================
-- Authors: Patrick Lehmann
--
-- Entity: A generic buffer module for the PoC.Stream protocol.
--
-- Description:
-- -------------------------------------
-- .. TODO:: No documentation available.
--
-- License:
-- =============================================================================
-- Copyright 2007-2015 Technische Universitaet Dresden - Germany
-- Chair of VLSI-Design, Diagnostics and Architecture
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS of ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- =============================================================================
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
library PoC;
use PoC.utils.all;
use PoC.vectors.all;
entity stream_FrameGenerator is
generic (
DATA_BITS : positive := 8;
WORD_BITS : positive := 16;
APPEND : T_FRAMEGEN_APPEND := FRAMEGEN_APP_NONE;
FRAMEGROUPS : T_FRAMEGEN_FRAMEGROUP_VECTOR_8 := (0 => C_FRAMEGEN_FRAMEGROUP_EMPTY)
);
port (
Clock : in std_logic;
Reset : in std_logic;
-- CSE interface
Command : in T_FRAMEGEN_COMMAND;
Status : out T_FRAMEGEN_STATUS;
-- Control interface
Pause : in T_SLV_16;
FrameGroupIndex : in T_SLV_8;
FrameIndex : in T_SLV_8;
Sequences : in T_SLV_16;
FrameLength : in T_SLV_16;
-- OUT Port
Out_Valid : out std_logic;
Out_Data : out std_logic_vector(DATA_BITS - 1 downto 0);
Out_SOF : out std_logic;
Out_EOF : out std_logic;
Out_Ack : in std_logic
);
end entity;
architecture rtl of stream_FrameGenerator is
type T_STATE is (
ST_IDLE,
ST_SEQUENCE_SOF, ST_SEQUENCE_DATA, ST_SEQUENCE_EOF,
ST_RANDOM_SOF, ST_RANDOM_DATA, ST_RANDOM_EOF,
ST_ERROR
);
signal State : T_STATE := ST_IDLE;
signal NextState : T_STATE;
signal FrameLengthCounter_rst : std_logic;
signal FrameLengthCounter_en : std_logic;
signal FrameLengthCounter_us : unsigned(15 downto 0) := (others => '0');
signal SequencesCounter_rst : std_logic;
signal SequencesCounter_en : std_logic;
signal SequencesCounter_us : unsigned(15 downto 0) := (others => '0');
signal ContentCounter_rst : std_logic;
signal ContentCounter_en : std_logic;
signal ContentCounter_us : unsigned(WORD_BITS - 1 downto 0) := (others => '0');
signal PRNG_rst : std_logic;
signal PRNG_got : std_logic;
signal PRNG_Data : std_logic_vector(DATA_BITS - 1 downto 0);
begin
process(Clock)
begin
if rising_edge(Clock) then
if (Reset = '1') then
State <= ST_IDLE;
else
State <= NextState;
end if;
end if;
end process;
process(State, Command, Out_Ack,
Sequences, FrameLength,
FrameLengthCounter_us,
SequencesCounter_us, ContentCounter_us,
PRNG_Data)
begin
NextState <= State;
Status <= FRAMEGEN_STATUS_GENERATING;
Out_Valid <= '0';
Out_Data <= (others => '0');
Out_SOF <= '0';
Out_EOF <= '0';
FrameLengthCounter_rst <= '0';
FrameLengthCounter_en <= '0';
SequencesCounter_rst <= '0';
SequencesCounter_en <= '0';
ContentCounter_rst <= '0';
ContentCounter_en <= '0';
PRNG_rst <= '0';
PRNG_got <= '0';
case State is
when ST_IDLE =>
Status <= FRAMEGEN_STATUS_IDLE;
FrameLengthCounter_rst <= '1';
SequencesCounter_rst <= '1';
ContentCounter_rst <= '1';
PRNG_rst <= '1';
case Command is
when FRAMEGEN_CMD_NONE =>
null;
when FRAMEGEN_CMD_SEQUENCE =>
NextState <= ST_SEQUENCE_SOF;
when FRAMEGEN_CMD_RANDOM =>
NextState <= ST_RANDOM_SOF;
when FRAMEGEN_CMD_SINGLE_FRAME =>
NextState <= ST_ERROR;
when FRAMEGEN_CMD_SINGLE_FRAMEGROUP =>
NextState <= ST_ERROR;
when FRAMEGEN_CMD_ALL_FRAMES =>
NextState <= ST_ERROR;
when others =>
NextState <= ST_ERROR;
end case;
-- generate sequential numbers
-- ----------------------------------------------------------------------
when ST_SEQUENCE_SOF =>
Out_Valid <= '1';
Out_Data <= std_logic_vector(ContentCounter_us);
Out_SOF <= '1';
if (Out_Ack = '1') then
FrameLengthCounter_en <= '1';
ContentCounter_en <= '1';
NextState <= ST_SEQUENCE_DATA;
end if;
when ST_SEQUENCE_DATA =>
Out_Valid <= '1';
Out_Data <= std_logic_vector(ContentCounter_us);
if (Out_Ack = '1') then
FrameLengthCounter_en <= '1';
ContentCounter_en <= '1';
if FrameLengthCounter_us = (unsigned(FrameLength) - 2) then
NextState <= ST_SEQUENCE_EOF;
end if;
end if;
when ST_SEQUENCE_EOF =>
Out_Valid <= '1';
Out_Data <= std_logic_vector(ContentCounter_us);
Out_EOF <= '1';
if (Out_Ack = '1') then
FrameLengthCounter_rst <= '1';
ContentCounter_en <= '1';
SequencesCounter_en <= '1';
-- if (Pause = (Pause'range => '0')) then
if SequencesCounter_us = (unsigned(Sequences) - 1) then
Status <= FRAMEGEN_STATUS_COMPLETE;
NextState <= ST_IDLE;
else
NextState <= ST_SEQUENCE_SOF;
end if;
-- end if;
end if;
-- generate random numbers
-- ----------------------------------------------------------------------
when ST_RANDOM_SOF =>
Out_Valid <= '1';
Out_Data <= PRNG_Data;
Out_SOF <= '1';
if (Out_Ack = '1') then
FrameLengthCounter_en <= '1';
PRNG_got <= '1';
NextState <= ST_RANDOM_DATA;
end if;
when ST_RANDOM_DATA =>
Out_Valid <= '1';
Out_Data <= PRNG_Data;
if (Out_Ack = '1') then
FrameLengthCounter_en <= '1';
PRNG_got <= '1';
if FrameLengthCounter_us = (unsigned(FrameLength) - 2) then
NextState <= ST_RANDOM_EOF;
end if;
end if;
when ST_RANDOM_EOF =>
Out_Valid <= '1';
Out_Data <= PRNG_Data;
Out_EOF <= '1';
FrameLengthCounter_rst <= '1';
if (Out_Ack = '1') then
PRNG_rst <= '1';
NextState <= ST_IDLE;
end if;
when ST_ERROR =>
Status <= FRAMEGEN_STATUS_ERROR;
NextState <= ST_IDLE;
end case;
end process;
process(Clock)
begin
if rising_edge(Clock) then
if ((Reset or FrameLengthCounter_rst) = '1') then
FrameLengthCounter_us <= (others => '0');
elsif (FrameLengthCounter_en = '1') then
FrameLengthCounter_us <= FrameLengthCounter_us + 1;
end if;
end if;
end process;
process(Clock)
begin
if rising_edge(Clock) then
if ((Reset or SequencesCounter_rst) = '1') then
SequencesCounter_us <= (others => '0');
elsif (SequencesCounter_en = '1') then
SequencesCounter_us <= SequencesCounter_us + 1;
end if;
end if;
end process;
process(Clock)
begin
if rising_edge(Clock) then
if ((Reset or ContentCounter_rst) = '1') then
ContentCounter_us <= (others => '0');
elsif (ContentCounter_en = '1') then
ContentCounter_us <= ContentCounter_us + 1;
end if;
end if;
end process;
PRNG : entity PoC.arith_prng
generic map (
BITS => DATA_BITS
)
port map (
clk => Clock,
rst => PRNG_rst,
got => PRNG_got,
val => PRNG_Data
);
end architecture;