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_m00024_s_v02_test_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_m00024_s_v02_test_fsm IS
26
   PORT(
27
      clk_i        : IN     std_logic;
28
      cnti_end_i   : IN     std_logic;
29
      cntj_end_i   : IN     std_logic;
30
      ctrl_rdlat_i : IN     MEM_LAT_CNT_WIDTH_T;
31
      ctrl_rdy7_i  : IN     std_logic;
32
      ctrl_start_i : IN     std_logic;
33
      ctrl_wrlat_i : IN     MEM_LAT_CNT_WIDTH_T;
34
      ds_i         : IN     DATA_T;
35
      dt_i         : IN     DATA_T;
36
      dw_i         : IN     DATA_T;
37
      offset_i     : IN     DATA_T;
38
      rst_n_i      : IN     std_logic;
39
      cnteni_o     : OUT    std_logic;
40
      cntenj_o     : OUT    std_logic;
41
      ctrl_int_o   : OUT    std_logic;
42
      ctrl_rdy_o   : OUT    std_logic;
43
      dout_o       : OUT    DATA_T;
44
      we_s_o       : OUT    std_logic;
45
      we_t_o       : OUT    std_logic;
46
      we_w_o       : OUT    std_logic
47
   );
48
 
49
-- Declarations
50
 
51
END p0300_m00024_s_v02_test_fsm ;
52
-- COPYRIGHT (C) 2022 Jens Gutschmidt /
53
-- VIVARE GmbH Switzerland
54
-- (email: opencores@vivare-services.com)
55
-- 
56
-- Versions:
57
-- Revision 2.0  2022/07/02
58
-- - Introduced latency for write
59
-- Revision 1.0  2022/06/17
60
-- -- First draft
61
-- 
62
LIBRARY ieee;
63
USE ieee.std_logic_1164.all;
64
USE ieee.std_logic_arith.all;
65
--USE ieee.numeric_std.all;
66
LIBRARY work;
67
USE work.memory_vhd_v03_pkg.ALL;
68
 
69
ARCHITECTURE fsm OF p0300_m00024_s_v02_test_fsm IS
70
 
71
   -- Architecture Declarations
72
   SIGNAL ctrl_int_reg : std_logic;
73
   SIGNAL ctrl_rdlat_reg : MEM_LAT_CNT_WIDTH_T;
74
   SIGNAL ctrl_start_reg : std_logic;
75
   SIGNAL ctrl_wrlat_reg : MEM_LAT_CNT_WIDTH_T;
76
   SIGNAL dt_reg : DATA_T;
77
   SIGNAL dw_reg : DATA_T;
78
 
79
   TYPE STATE_TYPE IS (
80
      S02,
81
      S05,
82
      S04,
83
      S07,
84
      S06,
85
      S11,
86
      S12,
87
      S13,
88
      S14,
89
      S15,
90
      S01,
91
      S00,
92
      S09,
93
      S08,
94
      S10,
95
      S03
96
   );
97
 
98
   -- Declare current and next state signals
99
   SIGNAL current_state : STATE_TYPE;
100
   SIGNAL next_state : STATE_TYPE;
101
 
102
BEGIN
103
 
104
   -----------------------------------------------------------------
105
   clocked_proc : PROCESS (
106
      clk_i
107
   )
108
   -----------------------------------------------------------------
109
   BEGIN
110
      IF (clk_i'EVENT AND clk_i = '1') THEN
111
         IF (rst_n_i = '0') THEN
112
            current_state <= S00;
113
            -- Default Reset Values
114
            ctrl_int_reg <= '0';
115
            ctrl_rdlat_reg <= (others => '0');
116
            ctrl_start_reg <= '0';
117
            ctrl_wrlat_reg <= (others => '0');
118
            dt_reg <= (others => '0');
119
            dw_reg <= (others => '0');
120
         ELSE
121
            current_state <= next_state;
122
            -- Default Assignment To Internals
123
            ctrl_int_reg <= '0';
124
            ctrl_rdlat_reg <= ctrl_rdlat_reg;
125
            ctrl_start_reg <= ctrl_start_i;
126
            ctrl_wrlat_reg <= ctrl_wrlat_reg;
127
            dt_reg <= dt_i;
128
            dw_reg <= dw_i;
129
 
130
            -- Combined Actions
131
            CASE current_state IS
132
               -- Clear T
133
               WHEN S02 =>
134
                  ctrl_wrlat_reg <= ctrl_wrlat_i;
135
               -- Replace
136
               -- multiplication
137
               WHEN S04 =>
138
                  ctrl_wrlat_reg <= ctrl_wrlat_i;
139
               -- Dummy cycles to
140
               -- equalize latency.
141
               -- j-path
142
               WHEN S13 =>
143
                  ctrl_rdlat_reg <= '0' & ctrl_rdlat_reg ( MEM_LAT_CNT_WIDTH - 1 downto 1 );
144
               -- Set interrupt
145
               -- flag
146
               WHEN S14 =>
147
                  ctrl_int_reg <= '1';
148
               -- Dummy cycles to
149
               -- equalize latency.
150
               -- End-path
151
               WHEN S15 =>
152
                  ctrl_rdlat_reg <= '0' & ctrl_rdlat_reg ( MEM_LAT_CNT_WIDTH - 1 downto 1 );
153
               -- Next i
154
               WHEN S09 =>
155
                  ctrl_rdlat_reg <= ctrl_rdlat_i;
156
               -- Dummy cycles to
157
               -- equalize latency.
158
               -- Write-path (i)
159
               WHEN S08 =>
160
                  ctrl_wrlat_reg <= '0' & ctrl_wrlat_reg ( MEM_LAT_CNT_WIDTH - 1 downto 1 );
161
               -- Dummy cycles to
162
               -- equalize latency.
163
               -- i-path
164
               WHEN S10 =>
165
                  ctrl_rdlat_reg <= '0' & ctrl_rdlat_reg ( MEM_LAT_CNT_WIDTH - 1 downto 1 );
166
               -- Dummy cycles to
167
               -- equalize latency.
168
               -- Write-path (i)
169
               WHEN S03 =>
170
                  ctrl_wrlat_reg <= '0' & ctrl_wrlat_reg ( MEM_LAT_CNT_WIDTH - 1 downto 1 );
171
               WHEN OTHERS =>
172
                  NULL;
173
            END CASE;
174
         END IF;
175
      END IF;
176
   END PROCESS clocked_proc;
177
 
178
   -----------------------------------------------------------------
179
   nextstate_proc : PROCESS (
180
      cnti_end_i,
181
      cntj_end_i,
182
      ctrl_rdlat_reg,
183
      ctrl_rdy7_i,
184
      ctrl_start_reg,
185
      ctrl_wrlat_reg,
186
      current_state,
187
      ds_i
188
   )
189
   -----------------------------------------------------------------
190
   BEGIN
191
      CASE current_state IS
192
         -- Clear T
193
         WHEN S02 =>
194
            next_state <= S03;
195
         -- ADD if
196
         -- DS > 0
197
         WHEN S05 =>
198
            next_state <= S08;
199
         -- Replace
200
         -- multiplication
201
         WHEN S04 =>
202
            IF (signed (ds_i) > 0) THEN
203
               next_state <= S05;
204
            ELSIF (signed (ds_i) < 0) THEN
205
               next_state <= S07;
206
            ELSE
207
               next_state <= S06;
208
            END IF;
209
         -- SUB if
210
         -- DS < 0
211
         WHEN S07 =>
212
            next_state <= S08;
213
         -- Do nothing if
214
         -- DS = 0
215
         WHEN S06 =>
216
            next_state <= S08;
217
         -- Add offset to T
218
         WHEN S11 =>
219
            next_state <= S12;
220
         -- Next j
221
         WHEN S12 =>
222
            IF (cntj_end_i = '1') THEN
223
               next_state <= S14;
224
            ELSE
225
               next_state <= S13;
226
            END IF;
227
         -- Dummy cycles to
228
         -- equalize latency.
229
         -- j-path
230
         WHEN S13 =>
231
            IF (unsigned ( ctrl_rdlat_reg ) <= 3) THEN
232
               next_state <= S02;
233
            ELSE
234
               next_state <= S13;
235
            END IF;
236
         -- Set interrupt
237
         -- flag
238
         WHEN S14 =>
239
            next_state <= S15;
240
         -- Dummy cycles to
241
         -- equalize latency.
242
         -- End-path
243
         WHEN S15 =>
244
            IF (unsigned ( ctrl_rdlat_reg ) <= 7) THEN
245
               next_state <= S01;
246
            ELSE
247
               next_state <= S15;
248
            END IF;
249
         -- Wait for next
250
         -- TEST request
251
         WHEN S01 =>
252
            IF (ctrl_start_reg = '1') THEN
253
               next_state <= S02;
254
            ELSE
255
               next_state <= S01;
256
            END IF;
257
         -- Reset state
258
         WHEN S00 =>
259
            IF (ctrl_rdy7_i = '1') THEN
260
               next_state <= S01;
261
            ELSE
262
               next_state <= S00;
263
            END IF;
264
         -- Next i
265
         WHEN S09 =>
266
            IF (cnti_end_i = '1') THEN
267
               next_state <= S11;
268
            ELSE
269
               next_state <= S10;
270
            END IF;
271
         -- Dummy cycles to
272
         -- equalize latency.
273
         -- Write-path (i)
274
         WHEN S08 =>
275
            IF (unsigned ( ctrl_wrlat_reg ) <= 3) THEN
276
               next_state <= S09;
277
            ELSE
278
               next_state <= S08;
279
            END IF;
280
         -- Dummy cycles to
281
         -- equalize latency.
282
         -- i-path
283
         WHEN S10 =>
284
            IF (unsigned ( ctrl_rdlat_reg ) <= 3) THEN
285
               next_state <= S04;
286
            ELSE
287
               next_state <= S10;
288
            END IF;
289
         -- Dummy cycles to
290
         -- equalize latency.
291
         -- Write-path (i)
292
         WHEN S03 =>
293
            IF (unsigned ( ctrl_wrlat_reg ) <= 1) THEN
294
               next_state <= S04;
295
            ELSE
296
               next_state <= S03;
297
            END IF;
298
         WHEN OTHERS =>
299
            next_state <= S00;
300
      END CASE;
301
   END PROCESS nextstate_proc;
302
 
303
   -----------------------------------------------------------------
304
   output_proc : PROCESS (
305
      ctrl_int_reg,
306
      current_state,
307
      dt_reg,
308
      dw_reg,
309
      offset_i
310
   )
311
   -----------------------------------------------------------------
312
   BEGIN
313
      -- Default Assignment
314
      cnteni_o <= '0';
315
      cntenj_o <= '0';
316
      ctrl_int_o <= ctrl_int_reg;
317
      ctrl_rdy_o <= '0';
318
      dout_o <= (others => '0');
319
      we_s_o <= '0';
320
      we_t_o <= '0';
321
      we_w_o <= '0';
322
 
323
      -- Combined Actions
324
      CASE current_state IS
325
         -- Clear T
326
         WHEN S02 =>
327
            dout_o <= (others => '0');
328
            we_t_o <= '1';
329
         -- ADD if
330
         -- DS > 0
331
         WHEN S05 =>
332
            --dout_o <= signed (dt_i) + signed (dw_i);
333
            dout_o <= signed (dt_reg) + signed (dw_reg);
334
            we_t_o <= '1';
335
         -- SUB if
336
         -- DS < 0
337
         WHEN S07 =>
338
            --dout_o <= signed (dt_i) - signed (dw_i);
339
            dout_o <= signed (dt_reg) - signed (dw_reg);
340
            we_t_o <= '1';
341
         -- Add offset to T
342
         WHEN S11 =>
343
            --dout_o <= signed (dt_i) + signed (offset_i);
344
            dout_o <= signed (dt_reg) + signed (offset_i);
345
            we_t_o <= '1';
346
         -- Next j
347
         WHEN S12 =>
348
            cntenj_o <= '1';
349
         -- Wait for next
350
         -- TEST request
351
         WHEN S01 =>
352
            ctrl_rdy_o <= '1';
353
         -- Next i
354
         WHEN S09 =>
355
            cnteni_o <= '1';
356
         WHEN OTHERS =>
357
            NULL;
358
      END CASE;
359
   END PROCESS output_proc;
360
 
361
END fsm;

powered by: WebSVN 2.1.0

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