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