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

Subversion Repositories tosnet

[/] [tosnet/] [trunk/] [gateware/] [MicroBlaze_Peripheral_rev3_2/] [pcores/] [tosnet_v3_20_a/] [hdl/] [vhdl/] [tdl_app_net.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sonicwave
----------------------------------------------------------------------------------
2
-- Company:             University of Southern Denmark
3
-- Engineer:            Simon Falsig
4
-- 
5
-- Create Date:         10/3/2010 
6
-- Design Name          TosNet
7
-- Module Name:         app_net - Behavioral 
8
-- File Name:           app_net.vhd
9
-- Project Name:        TosNet
10
-- Target Devices:      Spartan3/6
11
-- Tool versions:       Xilinx ISE 12.2
12
-- Description:         The network discorvery module runs during startup, and 
13
--                                      performs network discovery. It is initiated by the master
14
--                                      node, and polls all attached nodes for their node_ids which
15
--                                      are stored together with the addresses of the nodes (that is,
16
--                                      their position in the ring, relative to the master) in the
17
--                                      network registers on all nodes.
18
--
19
-- Revision: 
20
-- Revision 3.2 -       Initial release
21
--
22
-- Copyright 2010
23
--
24
-- This module is free software: you can redistribute it and/or modify
25
-- it under the terms of the GNU Lesser General Public License as published by
26
-- the Free Software Foundation, either version 3 of the License, or
27
-- (at your option) any later version.
28
--
29
-- This module is distributed in the hope that it will be useful,
30
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
31
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
-- GNU Lesser General Public License for more details.
33
--
34
-- You should have received a copy of the GNU Lesser General Public License
35
-- along with this module.  If not, see <http://www.gnu.org/licenses/>.
36
----------------------------------------------------------------------------------
37
library IEEE;
38
use IEEE.STD_LOGIC_1164.ALL;
39
use IEEE.STD_LOGIC_ARITH.ALL;
40
use IEEE.STD_LOGIC_UNSIGNED.ALL;
41
use work.commandpack.all;
42
 
43
 
44
entity tdl_app_net is
45
        Port (  app_enable                                      : in    STD_LOGIC;
46
                        app_data_in                                     : in    STD_LOGIC_VECTOR(7 downto 0);
47
                        app_data_in_strobe                      : in    STD_LOGIC;
48
                        app_data_out                            : out   STD_LOGIC_VECTOR(7 downto 0);
49
                        app_data_out_strobe                     : out   STD_LOGIC;
50
                        app_data_out_enable                     : out   STD_LOGIC;
51
                        app_buffer_full                         : in    STD_LOGIC;
52
                        app_packet_error                        : in    STD_LOGIC;
53
                        app_force_packet_error          : out   STD_LOGIC;
54
                        app_cmd_valid                           : in    STD_LOGIC;
55
                        app_sync_strobe                         : in    STD_LOGIC;
56
                        app_is_master                           : in    STD_LOGIC;
57
                        app_dsc_done                            : out   STD_LOGIC;
58
                        app_network_reg_clk                     : out   STD_LOGIC;
59
                        app_network_reg_addr            : out   STD_LOGIC_VECTOR(5 downto 0);
60
                        app_network_reg_data_in         : in    STD_LOGIC_VECTOR(7 downto 0);
61
                        app_network_reg_data_out        : out   STD_LOGIC_VECTOR(7 downto 0);
62
                        app_network_reg_we                      : inout STD_LOGIC_VECTOR(0 downto 0);
63
                        app_node_count                          : out   STD_LOGIC_VECTOR(3 downto 0);
64
                        app_node_address                        : out   STD_LOGIC_VECTOR(3 downto 0);
65
                        app_node_id                                     : in    STD_LOGIC_VECTOR(3 downto 0);
66
                        app_clk                                         : in    STD_LOGIC;
67
                        app_reset                                       : in    STD_LOGIC);
68
end tdl_app_net;
69
 
70
architecture Behavioral of tdl_app_net is
71
 
72
        type STATES is (OFF, IDLE, CLEAR_NETWORKREG, DSC_SEND, DSC_RECEIVE, DSC_RESPOND, SET_SEND, SET_RECEIVE, SET_RESPOND, DONE);
73
 
74
        signal state                                            : STATES := OFF;
75
        signal next_state                                       : STATES := OFF;
76
 
77
        signal last_data_in_strobe                      : STD_LOGIC;
78
        signal node_count                                       : STD_LOGIC_VECTOR(3 downto 0) := "0000";
79
        signal node_address                                     : STD_LOGIC_VECTOR(3 downto 0) := "0000";
80
        signal nodes_received                           : STD_LOGIC_VECTOR(4 downto 0) := "00000";
81
 
82
        signal cmd_received                                     : STD_LOGIC := '0';
83
 
84
        signal counter                                          : STD_LOGIC_VECTOR(8 downto 0) := "000000000";
85
 
86
begin
87
 
88
        process(app_clk)
89
        begin
90
                if(app_clk = '1' and app_clk'EVENT) then
91
                        if(app_reset = '1') then
92
                                state <= OFF;
93
                        else
94
                                state <= next_state;
95
                        end if;
96
 
97
                        if(app_buffer_full = '1') then
98
                                counter <= counter;
99
                        elsif(state = next_state) then
100
                                counter <= counter + 1;
101
                        else
102
                                counter <= "000000000";
103
                        end if;
104
 
105
                        case state is
106
 
107
                                when OFF =>
108
                                        app_data_out_enable <= '0';
109
                                        app_data_out_strobe <= '0';
110
                                        app_data_out <= "00000000";
111
                                        app_force_packet_error <= 'Z';
112
                                        app_dsc_done <= '0';
113
                                        app_network_reg_clk <= '0';
114
                                        app_network_reg_addr <= "000000";
115
                                        app_network_reg_data_out <= "00000000";
116
                                        app_network_reg_we <= "0";
117
                                        last_data_in_strobe <= '0';
118
                                        node_count <= "0000";
119
                                        nodes_received <= "00000";
120
                                        cmd_received <= '0';
121
                                        node_address <= "0000";
122
 
123
                                when IDLE =>
124
                                        app_data_out_enable <= '0';
125
                                        app_data_out_strobe <= '0';
126
                                        app_dsc_done <= '0';
127
                                        app_network_reg_clk <= '0';
128
                                        app_network_reg_we <= "0";
129
 
130
                                when CLEAR_NETWORKREG =>
131
                                        app_network_reg_we <= "1";
132
                                        if(counter(0) = '0') then
133
                                                app_network_reg_clk <= '0';
134
                                                app_network_reg_addr <= counter(6 downto 1);
135
                                                app_network_reg_data_out <= "00000000";
136
                                        else
137
                                                app_network_reg_clk <= '1';
138
                                        end if;
139
 
140
                                when DSC_SEND =>                                                --Send discovery packet (master only)
141
                                        if(counter(8 downto 1) = 0) then
142
                                                app_data_out_enable <= '1';
143
                                                app_data_out <= CMD_NET_DSC & "0001";
144
                                                app_data_out_strobe <= '1';
145
                                        elsif(counter(8 downto 1) = 1) then
146
                                                app_data_out_strobe <= '0';
147
                                        elsif(counter(8 downto 1) = 2) then
148
                                                app_data_out <= "0000" & app_node_id;
149
                                                app_data_out_strobe <= '1';
150
                                        else
151
                                                app_data_out_enable <= '0';
152
                                                app_data_out_strobe <= '0';
153
                                        end if;
154
 
155
                                when DSC_RECEIVE =>                                     --Receive discovery packet
156
                                        if(app_data_in_strobe = '1' and last_data_in_strobe = '0') then
157
                                                if(node_count = 0 and app_data_in(7 downto 4) = CMD_NET_DSC and cmd_received = '0') then
158
                                                        node_count <= app_data_in(3 downto 0);
159
                                                        node_address <= app_data_in(3 downto 0);
160
                                                        nodes_received <= "00000";
161
                                                        cmd_received <= '1';
162
                                                else
163
                                                        app_network_reg_addr <= nodes_received(3 downto 0) & "00";
164
                                                        app_network_reg_data_out <= app_data_in;
165
                                                        app_network_reg_we <= "1";
166
                                                        app_network_reg_clk <= '0';
167
                                                        nodes_received <= nodes_received + 1;
168
                                                end if;
169
                                        elsif(app_data_in_strobe = '0' and last_data_in_strobe = '1' and app_network_reg_we = "1") then
170
                                                app_network_reg_clk <= '1';
171
                                        else
172
                                                app_network_reg_clk <= '0';
173
                                        end if;
174
 
175
                                when DSC_RESPOND =>                             --Forward discovery packet (slave only)
176
                                        app_network_reg_we <= "0";
177
 
178
                                        if(counter(8 downto 1) = 0) then
179
                                                app_network_reg_clk <= '0';
180
                                                app_network_reg_addr <= counter(5 downto 2) & "00";
181
                                                app_data_out_enable <= '1';
182
                                                app_data_out_strobe <= '1';
183
                                                app_data_out <= CMD_NET_DSC & (node_count + 1);
184
                                        elsif(counter(5 downto 1) = node_count & '1') then
185
                                                app_data_out_strobe <= '0';
186
                                        elsif(counter(5 downto 1) = (node_count + 1) & '0') then
187
                                                app_data_out_strobe <= '1';
188
                                                app_data_out <= node_count & app_node_id;
189
                                        elsif(counter(5 downto 1) = (node_count + 1) & '1') then
190
                                                app_data_out_strobe <= '0';
191
                                                app_data_out_enable <= '0';
192
                                                node_count <= "0000";                           --Reset node_count and nodes_received, as the combinatorial part doesn't work otherwise
193
                                                nodes_received <= "00000";
194
                                                cmd_received <= '0';
195
                                        elsif(counter(1) = '1') then
196
                                                app_data_out_strobe <= '0';
197
                                                app_network_reg_clk <= '1';
198
                                        else
199
                                                app_data_out_strobe <= '1';
200
                                                app_data_out <= app_network_reg_data_in;
201
                                                app_network_reg_clk <= '0';
202
                                                app_network_reg_addr <= counter(5 downto 2) & "00";
203
                                        end if;
204
 
205
                                when SET_SEND =>                                        --Transmit set packet (master only)
206
                                        app_network_reg_we <= "0";
207
                                        if(counter(8 downto 1) = 0) then
208
                                                app_network_reg_clk <= '0';
209
                                                app_network_reg_addr <= counter(5 downto 2) & "00";
210
                                                app_data_out_enable <= '1';
211
                                                app_data_out_strobe <= '1';
212
                                                app_data_out <= CMD_NET_SET & node_count;
213
                                        elsif(counter(5 downto 1) = node_count & '1') then
214
                                                app_network_reg_clk <= '0';
215
                                                app_data_out_strobe <= '0';
216
                                                app_data_out_enable <= '0';
217
                                                node_count <= "0000";                           --Reset node_count and nodes_received, as the combinatorial part doesn't work otherwise
218
                                                nodes_received <= "00000";
219
                                                cmd_received <= '0';
220
                                        elsif(counter(1) = '1') then
221
                                                app_data_out_strobe <= '0';
222
                                                app_network_reg_clk <= '1';
223
                                        else
224
                                                app_data_out_strobe <= '1';
225
                                                app_data_out <= app_network_reg_data_in;
226
                                                app_network_reg_clk <= '0';
227
                                                app_network_reg_addr <= counter(5 downto 2) & "00";
228
                                        end if;
229
 
230
                                when SET_RECEIVE =>                             --Receive set packet
231
                                        if(app_data_in_strobe = '1' and last_data_in_strobe = '0') then
232
                                                if(node_count = 0 and app_data_in(7 downto 4) = CMD_NET_SET and cmd_received = '0') then
233
                                                        node_count <= app_data_in(3 downto 0);
234
                                                        nodes_received <= "00000";
235
                                                        cmd_received <= '1';
236
                                                else
237
                                                        app_network_reg_addr <= nodes_received(3 downto 0) & "00";
238
                                                        app_network_reg_data_out <= app_data_in;
239
                                                        app_network_reg_we <= "1";
240
                                                        app_network_reg_clk <= '0';
241
                                                        nodes_received <= nodes_received + 1;
242
                                                end if;
243
                                        elsif(app_data_in_strobe = '0' and last_data_in_strobe = '1' and app_network_reg_we = "1") then
244
                                                app_network_reg_clk <= '1';
245
                                        else
246
                                                app_network_reg_clk <= '0';
247
                                        end if;
248
 
249
                                when SET_RESPOND =>                             --Forward set packet (slave only)
250
                                        app_network_reg_we <= "0";
251
                                        if(counter(8 downto 1) = 0) then
252
                                                app_network_reg_clk <= '0';
253
                                                app_network_reg_addr <= counter(5 downto 2) & "00";
254
                                                app_data_out_enable <= '1';
255
                                                app_data_out_strobe <= '1';
256
                                                app_data_out <= CMD_NET_SET & node_count;
257
                                        elsif(counter(5 downto 1) = node_count & '1') then
258
                                                app_network_reg_clk <= '0';
259
                                                app_data_out_strobe <= '0';
260
                                                app_data_out_enable <= '0';
261
                                        elsif(counter(1) = '1') then
262
                                                app_data_out_strobe <= '0';
263
                                                app_network_reg_clk <= '1';
264
                                        else
265
                                                app_data_out_strobe <= '1';
266
                                                app_data_out <= app_network_reg_data_in;
267
                                                app_network_reg_clk <= '0';
268
                                                app_network_reg_addr <= counter(5 downto 2) & "00";
269
                                        end if;
270
 
271
                                when DONE =>                                    --Done!
272
                                        app_network_reg_we <= "0";
273
                                        if(app_is_master = '1') then
274
                                                app_node_address <= "0000";
275
                                        else
276
                                                app_node_address <= node_address;
277
                                        end if;
278
                                        app_node_count <= node_count;
279
                                        app_network_reg_clk <= '0';
280
                                        app_network_reg_addr <= "000000";
281
                                        app_network_reg_data_out <= "00000000";
282
                                        app_dsc_done <= '1';
283
                                        app_data_out_enable <= '0';
284
                                        app_data_out_strobe <= '0';
285
                                        app_data_out <= "00000000";
286
                                        app_force_packet_error <= 'Z';
287
                        end case;
288
 
289
                        last_data_in_strobe <= app_data_in_strobe;
290
 
291
                end if;
292
        end process;
293
 
294
 
295
        process(state, app_enable, app_data_in_strobe, counter, node_count, nodes_received, app_is_master)
296
        begin
297
                case state is
298
 
299
                        when OFF =>
300
                                if(app_enable = '1') then
301
                                        next_state <= IDLE;
302
                                else
303
                                        next_state <= OFF;
304
                                end if;
305
 
306
                        when IDLE =>
307
                                next_state <= CLEAR_NETWORKREG;
308
 
309
                        when CLEAR_NETWORKREG =>
310
                                if(counter = 128) then
311
                                        if(app_is_master = '1') then
312
                                                next_state <= DSC_SEND;
313
                                        else
314
                                                next_state <= DSC_RECEIVE;
315
                                        end if;
316
                                else
317
                                        next_state <= CLEAR_NETWORKREG;
318
                                end if;
319
 
320
                        when DSC_SEND =>
321
                                if(counter(8 downto 1) = 3) then
322
                                        next_state <= DSC_RECEIVE;
323
                                else
324
                                        next_state <= DSC_SEND;
325
                                end if;
326
 
327
                        when DSC_RECEIVE =>
328
                                next_state <= DSC_RECEIVE;
329
 
330
                                if((nodes_received = node_count) and not (node_count = 0) and (app_data_in_strobe = '0')) then
331
                                        if(app_is_master = '0') then
332
                                                next_state <= DSC_RESPOND;
333
                                        else
334
                                                next_state <= SET_SEND;
335
                                        end if;
336
                                end if;
337
 
338
                        when DSC_RESPOND =>
339
                                if(counter(5 downto 1) = (node_count + 1) & '1') then
340
                                        next_state <= SET_RECEIVE;
341
                                else
342
                                        next_state <= DSC_RESPOND;
343
                                end if;
344
 
345
                        when SET_SEND =>
346
                                if(counter(5 downto 1) = node_count & '1') then
347
                                        next_state <= SET_RECEIVE;
348
                                else
349
                                        next_state <= SET_SEND;
350
                                end if;
351
 
352
                        when SET_RECEIVE =>
353
                                next_state <= SET_RECEIVE;
354
                                if((nodes_received = node_count) and not (node_count = 0) and (app_data_in_strobe = '0')) then
355
                                        if(app_is_master = '0') then
356
                                                next_state <= SET_RESPOND;
357
                                        else
358
                                                next_state <= DONE;
359
                                        end if;
360
                                end if;
361
 
362
                        when SET_RESPOND =>
363
                                if(counter(5 downto 1) = node_count & '1') then
364
                                        next_state <= DONE;
365
                                else
366
                                        next_state <= SET_RESPOND;
367
                                end if;
368
 
369
                        when DONE =>
370
                                next_state <= DONE;
371
 
372
                end case;
373
        end process;
374
 
375
 
376
end Behavioral;
377
 

powered by: WebSVN 2.1.0

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