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

powered by: WebSVN 2.1.0

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