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

powered by: WebSVN 2.1.0

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