1 |
2 |
sonicwave |
----------------------------------------------------------------------------------
|
2 |
|
|
-- Company: University of Southern Denmark
|
3 |
|
|
-- Engineer: Simon Falsig
|
4 |
|
|
--
|
5 |
|
|
-- Create Date: 7/3/2010
|
6 |
|
|
-- Design Name TosNet
|
7 |
|
|
-- Module Name: app_sync - Behavioral
|
8 |
|
|
-- File Name: app_sync.vhd
|
9 |
|
|
-- Project Name: TosNet
|
10 |
|
|
-- Target Devices: Spartan3/6
|
11 |
|
|
-- Tool versions: Xilinx ISE 12.2
|
12 |
|
|
-- Description: The synchronization module handles the synchronization strobes
|
13 |
|
|
-- that are emitted at the end of each cycle. The strobe is
|
14 |
|
|
-- delayed for a fixed interval, depending on the node address
|
15 |
|
|
-- (which specifies the position of the node in the network
|
16 |
|
|
-- relative to the master), which causes the strobe to be emitted
|
17 |
|
|
-- at the same time in 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 |
|
|
|
42 |
|
|
---- Uncomment the following library declaration if instantiating
|
43 |
|
|
---- any Xilinx primitives in this code.
|
44 |
|
|
--library UNISIM;
|
45 |
|
|
--use UNISIM.VComponents.all;
|
46 |
|
|
|
47 |
|
|
entity tdl_app_sync is
|
48 |
|
|
Port ( app_enable : in STD_LOGIC;
|
49 |
|
|
app_data_in : in STD_LOGIC_VECTOR(7 downto 0);
|
50 |
|
|
app_data_in_strobe : in STD_LOGIC;
|
51 |
|
|
app_data_in_enable : in STD_LOGIC;
|
52 |
|
|
app_data_out : out STD_LOGIC_VECTOR(7 downto 0);
|
53 |
|
|
app_data_out_strobe : out STD_LOGIC;
|
54 |
|
|
app_data_out_enable : out STD_LOGIC;
|
55 |
|
|
app_buffer_full : in STD_LOGIC;
|
56 |
|
|
app_packet_error : in STD_LOGIC;
|
57 |
|
|
app_force_packet_error : out STD_LOGIC;
|
58 |
|
|
app_cmd_valid : in STD_LOGIC;
|
59 |
|
|
app_sync_strobe : out STD_LOGIC;
|
60 |
|
|
app_is_master : in STD_LOGIC;
|
61 |
|
|
app_dsc_done : out STD_LOGIC;
|
62 |
|
|
app_node_id : in STD_LOGIC_VECTOR(3 downto 0);
|
63 |
|
|
app_node_count : in STD_LOGIC_VECTOR(3 downto 0);
|
64 |
|
|
app_node_address : in STD_LOGIC_VECTOR(3 downto 0);
|
65 |
|
|
app_clk : in STD_LOGIC;
|
66 |
|
|
app_reset : in STD_LOGIC);
|
67 |
|
|
end tdl_app_sync;
|
68 |
|
|
|
69 |
|
|
architecture Behavioral of tdl_app_sync is
|
70 |
|
|
|
71 |
|
|
type STATES is (OFF, CALC_SYNC_DELAY, SYNC_READY, SYNC_ONLINE, SYNC_RUNNING, SYNC_SET);
|
72 |
|
|
|
73 |
|
|
signal state : STATES := OFF;
|
74 |
|
|
signal next_state : STATES := OFF;
|
75 |
|
|
|
76 |
|
|
signal last_data_in_enable : STD_LOGIC;
|
77 |
|
|
|
78 |
|
|
signal counter : STD_LOGIC_VECTOR(4 downto 0) := "00000";
|
79 |
|
|
|
80 |
|
|
signal delay_counter : STD_LOGIC_VECTOR(11 downto 0) := "000000000000";
|
81 |
|
|
signal delay_current_node : STD_LOGIC_VECTOR(11 downto 0) := "000000000000";
|
82 |
|
|
constant delay_pr_node : STD_LOGIC_VECTOR(11 downto 0) := "000100101100";
|
83 |
|
|
|
84 |
|
|
begin
|
85 |
|
|
|
86 |
|
|
process(app_clk)
|
87 |
|
|
begin
|
88 |
|
|
if(app_clk = '1' and app_clk'EVENT) then
|
89 |
|
|
if(app_reset = '1') then
|
90 |
|
|
state <= OFF;
|
91 |
|
|
else
|
92 |
|
|
state <= next_state;
|
93 |
|
|
end if;
|
94 |
|
|
|
95 |
|
|
if(state = next_state) then
|
96 |
|
|
counter <= counter + 1;
|
97 |
|
|
else
|
98 |
|
|
counter <= "00000";
|
99 |
|
|
end if;
|
100 |
|
|
|
101 |
|
|
case state is
|
102 |
|
|
|
103 |
|
|
when OFF =>
|
104 |
|
|
delay_counter <= "000000000000";
|
105 |
|
|
delay_current_node <= "000000000000";
|
106 |
|
|
app_dsc_done <= '0';
|
107 |
|
|
last_data_in_enable <= '0';
|
108 |
|
|
app_sync_strobe <= '0';
|
109 |
|
|
|
110 |
|
|
when CALC_SYNC_DELAY =>
|
111 |
|
|
if(app_is_master = '1') then
|
112 |
|
|
delay_current_node <= "000000000000";
|
113 |
|
|
elsif(counter = 0) then
|
114 |
|
|
delay_current_node <= delay_pr_node;
|
115 |
|
|
else
|
116 |
|
|
delay_current_node <= delay_current_node + delay_pr_node;
|
117 |
|
|
end if;
|
118 |
|
|
|
119 |
|
|
when SYNC_READY =>
|
120 |
|
|
if(app_is_master = '1') then
|
121 |
|
|
app_sync_strobe <= '1'; --If this is the master node, send out a single sync pulse to get the application started...
|
122 |
|
|
end if;
|
123 |
|
|
|
124 |
|
|
when SYNC_ONLINE =>
|
125 |
|
|
app_dsc_done <= '1';
|
126 |
|
|
app_sync_strobe <= '0';
|
127 |
|
|
delay_counter <= "000000000000";
|
128 |
|
|
|
129 |
|
|
when SYNC_RUNNING =>
|
130 |
|
|
delay_counter <= delay_counter + 1;
|
131 |
|
|
|
132 |
|
|
when SYNC_SET =>
|
133 |
|
|
app_sync_strobe <= '1';
|
134 |
|
|
|
135 |
|
|
end case;
|
136 |
|
|
|
137 |
|
|
last_data_in_enable <= app_data_in_enable;
|
138 |
|
|
|
139 |
|
|
end if;
|
140 |
|
|
end process;
|
141 |
|
|
|
142 |
|
|
process(state, app_enable, counter, app_node_count, app_node_address, delay_counter, delay_current_node, app_data_in_enable, last_data_in_enable)
|
143 |
|
|
begin
|
144 |
|
|
case state is
|
145 |
|
|
when OFF =>
|
146 |
|
|
if(app_enable = '1') then
|
147 |
|
|
next_state <= CALC_SYNC_DELAY;
|
148 |
|
|
else
|
149 |
|
|
next_state <= OFF;
|
150 |
|
|
end if;
|
151 |
|
|
when CALC_SYNC_DELAY =>
|
152 |
|
|
if(counter = app_node_count - app_node_address - 1) then
|
153 |
|
|
next_state <= SYNC_READY;
|
154 |
|
|
else
|
155 |
|
|
next_state <= CALC_SYNC_DELAY;
|
156 |
|
|
end if;
|
157 |
|
|
when SYNC_READY => --Make sure that the current transmission is done before going online (if not the enable signal from the received sync_set will trigger the sync mechanism... which is kinda not what we want)
|
158 |
|
|
if(app_data_in_enable = '0') then
|
159 |
|
|
next_state <= SYNC_ONLINE;
|
160 |
|
|
else
|
161 |
|
|
next_state <= SYNC_READY;
|
162 |
|
|
end if;
|
163 |
|
|
when SYNC_ONLINE =>
|
164 |
|
|
if(app_data_in_enable = '0' and last_data_in_enable = '1') then
|
165 |
|
|
next_state <= SYNC_RUNNING;
|
166 |
|
|
else
|
167 |
|
|
next_state <= SYNC_ONLINE;
|
168 |
|
|
end if;
|
169 |
|
|
when SYNC_RUNNING =>
|
170 |
|
|
if(app_data_in_enable = '1') then --If app_data_in_enable goes high before the sync_strobe something bad is happening - but let's just make sure we don't make it worse by sending a sync_strobe in the middle of a (probably erroneous) transmission...
|
171 |
|
|
next_state <= SYNC_ONLINE;
|
172 |
|
|
elsif(delay_counter = delay_current_node) then
|
173 |
|
|
next_state <= SYNC_SET;
|
174 |
|
|
else
|
175 |
|
|
next_state <= SYNC_RUNNING;
|
176 |
|
|
end if;
|
177 |
|
|
when SYNC_SET =>
|
178 |
|
|
next_state <= SYNC_ONLINE;
|
179 |
|
|
end case;
|
180 |
|
|
end process;
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
end Behavioral;
|
184 |
|
|
|