OpenCores
URL https://opencores.org/ocsvn/neural_net_perceptron/neural_net_perceptron/trunk

Subversion Repositories neural_net_perceptron

[/] [neural_net_perceptron/] [trunk/] [rtl/] [vhdl/] [p0300_m00028_s_v02_latency_fsm.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 fpga_is_fu
-- COPYRIGHT (C) 2022 by Jens Gutschmidt / VIVARE GmbH Switzerland
2
-- (email: opencores@vivare-services.com)
3
-- 
4
-- This program is free software: you can redistribute it and/or modify it
5
-- under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or any
7
-- later version.
8
-- 
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
-- See the GNU General Public License for more details.
13
-- 
14
-- You should have received a copy of the GNU General Public License
15
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
-- 
17
-- 
18
LIBRARY ieee;
19
USE ieee.std_logic_1164.all;
20
USE ieee.std_logic_arith.all;
21
--USE ieee.numeric_std.all;
22
LIBRARY work;
23
USE work.memory_vhd_v03_pkg.ALL;
24
 
25
ENTITY p0300_m00028_s_v02_latency_fsm IS
26
   PORT(
27
      clk_i         : IN     std_logic;
28
      dw_i          : IN     DATA_T;
29
      rst_n_i       : IN     std_logic;
30
      cnt_alllat_o  : OUT    MEM_LAT_CNT_WIDTH_T;
31
      cnteni_o      : OUT    std_logic;
32
      cntenj_o      : OUT    std_logic;
33
      ctrl_memerr_o : OUT    std_logic;
34
      ctrl_rdlat_o  : OUT    MEM_LAT_CNT_WIDTH_T;
35
      ctrl_rdy_o    : OUT    std_logic;
36
      ctrl_run_o    : OUT    std_logic;
37
      ctrl_wrlat_o  : OUT    MEM_LAT_CNT_WIDTH_T;
38
      dout_o        : OUT    DATA_T;
39
      we_w_o        : OUT    std_logic
40
   );
41
 
42
-- Declarations
43
 
44
END p0300_m00028_s_v02_latency_fsm ;
45
-- COPYRIGHT (C) 2022 Jens Gutschmidt /
46
-- VIVARE GmbH Switzerland
47
-- (email: opencores@vivare-services.com)
48
-- 
49
-- Versions:
50
-- Revision 2.0  2022/07/04
51
-- - Introsuced latency for write
52
-- Revision 1.0  2022/07/02
53
-- -- First draft
54
-- 
55
LIBRARY ieee;
56
USE ieee.std_logic_1164.all;
57
USE ieee.std_logic_arith.all;
58
--USE ieee.numeric_std.all;
59
LIBRARY work;
60
USE work.memory_vhd_v03_pkg.ALL;
61
 
62
ARCHITECTURE fsm OF p0300_m00028_s_v02_latency_fsm IS
63
 
64
   -- Architecture Declarations
65
   SIGNAL cnt_alllat_reg : MEM_LAT_CNT_WIDTH_T;
66
   SIGNAL ctrl_memerr_reg : std_logic;
67
   SIGNAL ctrl_rdlat_reg : MEM_LAT_CNT_WIDTH_T;
68
   SIGNAL ctrl_rdy_reg : std_logic;
69
   SIGNAL ctrl_run_reg : std_logic;
70
   SIGNAL ctrl_wrlat_reg : MEM_LAT_CNT_WIDTH_T;
71
   SIGNAL dw_reg : DATA_T;
72
 
73
   TYPE STATE_TYPE IS (
74
      S00,
75
      S01,
76
      S02,
77
      S03,
78
      S04,
79
      S06,
80
      S05,
81
      S08,
82
      SERR,
83
      S07,
84
      SRDY,
85
      S11,
86
      S7,
87
      S8
88
   );
89
 
90
   -- Declare current and next state signals
91
   SIGNAL current_state : STATE_TYPE;
92
   SIGNAL next_state : STATE_TYPE;
93
 
94
BEGIN
95
 
96
   -----------------------------------------------------------------
97
   clocked_proc : PROCESS (
98
      clk_i
99
   )
100
   -----------------------------------------------------------------
101
   BEGIN
102
      IF (clk_i'EVENT AND clk_i = '1') THEN
103
         IF (rst_n_i = '0') THEN
104
            current_state <= S00;
105
            -- Default Reset Values
106
            cnt_alllat_reg <= (others => '0');
107
            ctrl_memerr_reg <= '0';
108
            ctrl_rdlat_reg <= (others => '0');
109
            ctrl_rdy_reg <= '0';
110
            ctrl_run_reg <= '0';
111
            ctrl_wrlat_reg <= (others => '0');
112
            dw_reg <= (others => '0');
113
         ELSE
114
            current_state <= next_state;
115
            -- Default Assignment To Internals
116
            cnt_alllat_reg <= cnt_alllat_reg;
117
            ctrl_memerr_reg <= ctrl_memerr_reg;
118
            ctrl_rdlat_reg <= ctrl_rdlat_reg;
119
            ctrl_rdy_reg <= ctrl_rdy_reg;
120
            ctrl_run_reg <= ctrl_run_reg;
121
            ctrl_wrlat_reg <= ctrl_wrlat_reg;
122
            dw_reg <= dw_i;
123
 
124
            -- Combined Actions
125
            CASE current_state IS
126
               -- Reset state
127
               WHEN S00 =>
128
                  ctrl_run_reg <= '1';
129
                  ctrl_rdy_reg <= '0';
130
               -- Init values
131
               WHEN S01 =>
132
                  ctrl_wrlat_reg <= (others => '0');
133
                  ctrl_memerr_reg <= '0';
134
               -- Wait for max
135
               -- latency
136
               WHEN S03 =>
137
                  ctrl_wrlat_reg <= ctrl_wrlat_reg ( MEM_LAT_CNT_WIDTH-2 downto 0 ) & '1';
138
               -- Last address
139
               -- [1][1]
140
               WHEN S04 =>
141
                  ctrl_wrlat_reg <= (others => '0');
142
               -- Write -1 to
143
               -- last address
144
               -- [1][1]
145
               WHEN S06 =>
146
                  ctrl_wrlat_reg <= (others => '0');
147
               -- Wait for max
148
               -- latency
149
               WHEN S05 =>
150
                  ctrl_wrlat_reg <= ctrl_wrlat_reg ( MEM_LAT_CNT_WIDTH-2 downto 0 ) & '1';
151
               -- Release END
152
               -- conditions (for)
153
               WHEN S08 =>
154
                  cnt_alllat_reg <= (others => '0');
155
                  ctrl_wrlat_reg <= (others => '0');
156
                  ctrl_rdlat_reg <= (others => '0');
157
               -- Memory
158
               -- ERROR
159
               WHEN SERR =>
160
                  ctrl_memerr_reg <= '1';
161
                  ctrl_run_reg <= '0';
162
               -- Wait for max
163
               -- latency
164
               WHEN S07 =>
165
                  ctrl_wrlat_reg <= ctrl_wrlat_reg ( MEM_LAT_CNT_WIDTH-2 downto 0 ) & '1';
166
               -- END / READY
167
               -- state
168
               WHEN SRDY =>
169
                  ctrl_rdy_reg <= '1';
170
                  ctrl_run_reg <= '0';
171
               -- Address [0][0]
172
               -- reaches memory
173
               -- WS=1...max
174
               WHEN S11 =>
175
                  cnt_alllat_reg <= unsigned (cnt_alllat_reg) + 1;
176
                  ctrl_rdlat_reg <= ctrl_rdlat_reg ( MEM_LAT_CNT_WIDTH-2 downto 0 ) & '1';
177
                  IF (signed (dw_reg) = 0) THEN
178
                     cnt_alllat_reg <= cnt_alllat_reg;
179
                     ctrl_rdlat_reg <= ctrl_rdlat_reg;
180
                  END IF;
181
               -- Wait for
182
               -- dw_i = -1
183
               WHEN S8 =>
184
                  ctrl_wrlat_reg <= ctrl_wrlat_reg ( MEM_LAT_CNT_WIDTH-2 downto 0 ) & '1';
185
                  IF (signed (dw_reg) = -1) THEN
186
                     ctrl_wrlat_reg <= ctrl_wrlat_reg;
187
                  END IF;
188
               WHEN OTHERS =>
189
                  NULL;
190
            END CASE;
191
         END IF;
192
      END IF;
193
   END PROCESS clocked_proc;
194
 
195
   -----------------------------------------------------------------
196
   nextstate_proc : PROCESS (
197
      ctrl_rdlat_reg,
198
      ctrl_wrlat_reg,
199
      current_state,
200
      dw_reg
201
   )
202
   -----------------------------------------------------------------
203
   BEGIN
204
      CASE current_state IS
205
         -- Reset state
206
         WHEN S00 =>
207
            next_state <= S01;
208
         -- Init values
209
         WHEN S01 =>
210
            next_state <= S02;
211
         -- Write 0 to
212
         -- first address
213
         -- [0][0]
214
         WHEN S02 =>
215
            next_state <= S03;
216
         -- Wait for max
217
         -- latency
218
         WHEN S03 =>
219
            IF (signed (ctrl_wrlat_reg) = -1) THEN
220
               next_state <= S04;
221
            ELSE
222
               next_state <= S03;
223
            END IF;
224
         -- Last address
225
         -- [1][1]
226
         WHEN S04 =>
227
            next_state <= S05;
228
         -- Write -1 to
229
         -- last address
230
         -- [1][1]
231
         WHEN S06 =>
232
            next_state <= S07;
233
         -- Wait for max
234
         -- latency
235
         WHEN S05 =>
236
            IF (signed (ctrl_wrlat_reg) = -1) THEN
237
               next_state <= S06;
238
            ELSE
239
               next_state <= S05;
240
            END IF;
241
         -- Release END
242
         -- conditions (for)
243
         WHEN S08 =>
244
            IF (signed (dw_reg) = -1) THEN
245
               next_state <= S11;
246
            ELSE
247
               -- -1 not read on dw
248
               -- after max latency
249
               -- time causes ERROR
250
               next_state <= SERR;
251
            END IF;
252
         -- Memory
253
         -- ERROR
254
         WHEN SERR =>
255
            next_state <= SERR;
256
         -- Wait for max
257
         -- latency
258
         WHEN S07 =>
259
            IF (signed (ctrl_wrlat_reg) = -1) THEN
260
               next_state <= S08;
261
            ELSE
262
               next_state <= S07;
263
            END IF;
264
         -- END / READY
265
         -- state
266
         WHEN SRDY =>
267
            next_state <= SRDY;
268
         -- Address [0][0]
269
         -- reaches memory
270
         -- WS=1...max
271
         WHEN S11 =>
272
            IF (signed (dw_reg) = 0) THEN
273
               next_state <= S7;
274
            ELSIF (signed (ctrl_rdlat_reg) = -1) THEN
275
               next_state <= SERR;
276
            ELSE
277
               next_state <= S11;
278
            END IF;
279
         -- Write -1 to
280
         -- last address
281
         -- [1][1]
282
         WHEN S7 =>
283
            next_state <= S8;
284
         -- Wait for
285
         -- dw_i = -1
286
         WHEN S8 =>
287
            IF (signed (dw_reg) = -1) THEN
288
               next_state <= SRDY;
289
            ELSIF (signed (ctrl_wrlat_reg) = -1) THEN
290
               next_state <= SERR;
291
            ELSE
292
               next_state <= S8;
293
            END IF;
294
         WHEN OTHERS =>
295
            next_state <= S00;
296
      END CASE;
297
   END PROCESS nextstate_proc;
298
 
299
   -----------------------------------------------------------------
300
   output_proc : PROCESS (
301
      cnt_alllat_reg,
302
      ctrl_memerr_reg,
303
      ctrl_rdlat_reg,
304
      ctrl_rdy_reg,
305
      ctrl_run_reg,
306
      ctrl_wrlat_reg,
307
      current_state
308
   )
309
   -----------------------------------------------------------------
310
   BEGIN
311
      -- Default Assignment
312
      cnt_alllat_o <= cnt_alllat_reg;
313
      cnteni_o <= '0';
314
      cntenj_o <= '0';
315
      ctrl_memerr_o <= ctrl_memerr_reg;
316
      ctrl_rdlat_o <= ctrl_rdlat_reg;
317
      ctrl_rdy_o <= ctrl_rdy_reg;
318
      ctrl_run_o <= ctrl_run_reg;
319
      ctrl_wrlat_o <= ctrl_wrlat_reg;
320
      dout_o <= (others => '0');
321
      we_w_o <= '0';
322
 
323
      -- Combined Actions
324
      CASE current_state IS
325
         -- Write 0 to
326
         -- first address
327
         -- [0][0]
328
         WHEN S02 =>
329
            dout_o <= (others => '0');
330
            we_w_o <= '1';
331
         -- Last address
332
         -- [1][1]
333
         WHEN S04 =>
334
            cnteni_o <= '1';
335
            cntenj_o <= '1';
336
         -- Write -1 to
337
         -- last address
338
         -- [1][1]
339
         WHEN S06 =>
340
            dout_o <= (others => '1');
341
            we_w_o <= '1';
342
         -- Release END
343
         -- conditions (for)
344
         WHEN S08 =>
345
            cnteni_o <= '1';
346
            cntenj_o <= '1';
347
         -- Write -1 to
348
         -- last address
349
         -- [1][1]
350
         WHEN S7 =>
351
            dout_o <= (others => '1');
352
            we_w_o <= '1';
353
         WHEN OTHERS =>
354
            NULL;
355
      END CASE;
356
   END PROCESS output_proc;
357
 
358
END fsm;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.