1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : Initialization Module for LAN91C111
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : Originally: DM9kA_init_module.vhd
|
6 |
|
|
-- Author : Antti Alhonen (Original (simple) DM9000A version by Jussi Nieminen)
|
7 |
|
|
-- Company : DCS/TUT
|
8 |
|
|
-- Last update: 2011-11-08
|
9 |
|
|
-- Platform :
|
10 |
|
|
-------------------------------------------------------------------------------
|
11 |
|
|
-- Description: Initializes LAN91C111. Half of the registers on the very same
|
12 |
|
|
-- integrated chip are separated from the others for some mystical reason* and are
|
13 |
|
|
-- accessed by EMULATING A SERIAL INTERFACE by issuing the serial data signals,
|
14 |
|
|
-- including clock timing, through the registers of the other half. YES, you
|
15 |
|
|
-- read it correctly, it really is true.
|
16 |
|
|
-- Furthermore, some of the configuration options are located in both sections
|
17 |
|
|
-- and you have to manually make sure they match in the correct way; or, some of
|
18 |
|
|
-- them are fakes and only the ones in the right section really work. In addition,
|
19 |
|
|
-- user has to copy information between the sections. Etc.
|
20 |
|
|
|
21 |
|
|
-- (*) (yes I know why they did that but that's not an excuse;
|
22 |
|
|
-- they probably took two finished designs for MAC & PHY and made a quick
|
23 |
|
|
-- hack to connect them together in a way that somehow works but is hell to
|
24 |
|
|
-- use; it would be easier to use separate chips. Then, this chip is manufactured
|
25 |
|
|
-- for years and years to come. A decent replacement is not made.
|
26 |
|
|
|
27 |
|
|
-- The design also seems to suffer from some legacy from the ISA bus era,
|
28 |
|
|
-- despite the fact that the chip is NOT (specifically) meant for ISA busses; and
|
29 |
|
|
-- AFAIK is introduced years after the ISA went obsolete. Quite the opposite,
|
30 |
|
|
-- this is marketed as a chip for direct use with an embedded processor etc.
|
31 |
|
|
|
32 |
|
|
-- It probably would have been too easy to:
|
33 |
|
|
-- - Put all the configuration registers behind one unified interface (OMG),
|
34 |
|
|
-- - ONCE THEY HAVE THE 15-BIT ADDRESS BUS (for some mystical reason), really use *gasp*
|
35 |
|
|
-- FIVE bits (instead of the current three), thus eliminating the dumb concept of "IO
|
36 |
|
|
-- BANKS" (which, despite the name, has nothing to do with "IO"s).
|
37 |
|
|
-- Oh, the DM9000A guys did it like that... The specifications may be in poor English
|
38 |
|
|
-- for that chip but it's not completely ****** up.
|
39 |
|
|
--
|
40 |
|
|
-- Congratulations for choosing LAN91C111 :-)! Good luck and have fun!
|
41 |
|
|
-------------------------------------------------------------------------------
|
42 |
|
|
-- Revisions :
|
43 |
|
|
-- Date Version Author Description
|
44 |
|
|
-- 2009/08/24 1.0 niemin95 Created
|
45 |
|
|
-------------------------------------------------------------------------------
|
46 |
|
|
|
47 |
|
|
library ieee;
|
48 |
|
|
use ieee.std_logic_1164.all;
|
49 |
|
|
use ieee.numeric_std.all;
|
50 |
|
|
|
51 |
|
|
-- constants
|
52 |
|
|
use work.lan91c111_ctrl_pkg.all;
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
entity lan91c111_init_module is
|
56 |
|
|
|
57 |
|
|
generic (
|
58 |
|
|
enable_tx_g : std_logic := '1';
|
59 |
|
|
enable_rx_g : std_logic := '1');
|
60 |
|
|
|
61 |
|
|
port (
|
62 |
|
|
clk : in std_logic;
|
63 |
|
|
rst_n : in std_logic;
|
64 |
|
|
ready_out : out std_logic;
|
65 |
|
|
reg_addr_out : out std_logic_vector( real_addr_width_c-1 downto 0 );
|
66 |
|
|
config_data_out : out std_logic_vector( lan91_data_width_c-1 downto 0 );
|
67 |
|
|
nBE_out : out std_logic_vector( 3 downto 0 );
|
68 |
|
|
read_not_write_out : out std_logic;
|
69 |
|
|
config_valid_out : out std_logic;
|
70 |
|
|
data_from_comm_in : in std_logic_vector( lan91_data_width_c-1 downto 0 );
|
71 |
|
|
data_from_comm_valid_in : in std_logic;
|
72 |
|
|
comm_busy_in : in std_logic
|
73 |
|
|
);
|
74 |
|
|
|
75 |
|
|
end lan91c111_init_module;
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
architecture rtl of lan91c111_init_module is
|
79 |
|
|
|
80 |
|
|
type init_table_type is record
|
81 |
|
|
phy : std_logic; -- If '1', communicate with PHY registers
|
82 |
|
|
-- instead of MAC. Addr will be 5 bits
|
83 |
|
|
-- instead of 3, value will be 16 bits
|
84 |
|
|
-- instead of 32 and nBE will be ignored.
|
85 |
|
|
addr : std_logic_vector( 4 downto 0 ); -- for normal MAC operations, use
|
86 |
|
|
-- only 2 downto 0.
|
87 |
|
|
value : std_logic_vector( lan91_data_width_c-1 downto 0 );
|
88 |
|
|
nBE : std_logic_vector( 3 downto 0 );
|
89 |
|
|
writing : std_logic;
|
90 |
|
|
sleep_time : integer range 0 to max_sleep_c;
|
91 |
|
|
only_sleep : std_logic; -- don't do anything but sleep.
|
92 |
|
|
|
93 |
|
|
poll_until : std_logic; -- use when writing='0'; if set to '1', don't advance to next step until
|
94 |
|
|
poll_bit_num : integer; -- poll_bit_num bit of the read value equals to poll_value. Sleeping will
|
95 |
|
|
poll_value : std_logic; -- be done on every poll cycle, also after a match.
|
96 |
|
|
|
97 |
|
|
copy : std_logic; -- When writing='1', use copy = '1' to write LAST READ VALUE (from
|
98 |
|
|
-- the SAME section (phy/mac)) instead of the "value" field; IN ADDITION,
|
99 |
|
|
-- if "poll_until" is '1', take the copy_bit_num'th bit FROM THE OTHER SECTION
|
100 |
|
|
copy_bit_num: integer; -- and put it in the poll_bit_num'th place. So: copy one bit from the PHY index x to
|
101 |
|
|
-- MAC index y; read MAC, READ PHY, write MAC with copy = 1, poll_until = 1,
|
102 |
|
|
-- copy_bit_num = x and poll_bit_num = y. (So this is not a poll, just reusing fields.
|
103 |
|
|
-- Poll happens only when writing = '0'.)
|
104 |
|
|
end record;
|
105 |
|
|
|
106 |
|
|
constant init_values_c : integer := 28;
|
107 |
|
|
type init_table_array is array (0 to init_values_c-1) of init_table_type;
|
108 |
|
|
|
109 |
|
|
-- Remember: manually change the bank to 3 before entering any PHY commands.
|
110 |
|
|
constant init_table_c : init_table_array := (
|
111 |
|
|
-- PHY ADDR DATA nBE W? Sleep Sleep_only POLL, POLLBIT, POLLVAL, COPY, COPYBIT
|
112 |
|
|
('0', "00000", x"00000000", "0000", '1', clk_hz_c/20, '1', '0', 0, '0', '0', 0), -- Sleep 50 ms
|
113 |
|
|
('0', "00111", x"00000000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 0
|
114 |
|
|
('0', "00010", x"00008000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Soft reset
|
115 |
|
|
('0', "00010", x"00000000", "1100", '1', clk_hz_c/20, '0', '0', 0, '0', '0', 0), -- Clear soft reset and sleep 50 ms.
|
116 |
|
|
('0', "00000", x"000000" & "0000000" & enable_tx_g,"1100", '1', 0, '0', '0', 0, '0', '0', 0), -- TX Enable according to enable_tx_g. Padding doesn't work, don't bother
|
117 |
|
|
('0', "00101", x"0000" & "00111000" & "00010000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Autonegotiation on, leds.
|
118 |
|
|
-- Reset the PHY to start autonegotiation.
|
119 |
|
|
('0', "00111", x"00000003", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 3
|
120 |
|
|
('1', "00000", x"00008000", "1100", '1', clk_hz_c/20, '0', '0', 0, '0', '0', 0), -- Reset PHY, sleep 50 ms.
|
121 |
|
|
('1', "00000", x"0000" & "0011000100000000", "1100", '1', clk_hz_c*2, '0', '0', 0, '0', '0', 0), -- PHY isolation mode off, ANEG on. Sleep 2 sec.
|
122 |
|
|
-- ('1', "00010", x"00000000", "1100", '0', 50 ,'0', '0', 0, '0', '0', 0), -- DEBUG: Read reg 2 from PHY, company ID.
|
123 |
|
|
('1', "00001", x"00000000", "1100", '0', clk_hz_c/200,'0', '1', 5, '1', '0', 0), -- Poll for ANEG_ACK in PHY for every 5 ms until '1'.
|
124 |
|
|
('1', "00001", x"00000000", "1100", '0', clk_hz_c/200,'0', '1', 2, '1', '0', 0), -- Poll for LINK in PHY for every 5 ms until '1'.
|
125 |
|
|
-- Autonegotiation is done.
|
126 |
|
|
-- Now, copy one PHY register bit to appropriate location in the MAC register.
|
127 |
|
|
('0', "00111", x"00000000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 0
|
128 |
|
|
('0', "00000", x"00000000", "1100", '0', 0, '0', '0', 0, '0', '0', 0), -- Read BANK 0 offset 0 to get a local copy here (MAC).
|
129 |
|
|
('0', "00111", x"00000003", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 3 to be able to access PHY.
|
130 |
|
|
('1', "10010", x"00000000", "1100", '0', 0, '0', '0', 0, '0', '0', 0), -- Read PHY register 18 to get a local copy here (PHY).
|
131 |
|
|
('0', "00111", x"00000000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 0
|
132 |
|
|
('0', "00000", x"ACDCABBA", "1100", '1', 0, '0', '1', 15, '0', '1', 6), -- Copy bit 6 from PHY we read earlier to MAC offset 0 bit 15.
|
133 |
|
|
|
134 |
|
|
-- Now, configure all MAC registers:
|
135 |
|
|
('0', "00111", x"00000000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 0
|
136 |
|
|
('0', "00010", x"0000" & "0000001" & enable_rx_g & x"00", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- STRIP CRC = on, RX enable according to enable_rx_g.
|
137 |
|
|
('0', "00111", x"00000001", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 1
|
138 |
|
|
('0', "00010", MAC_addr_c(23 downto 16) & MAC_addr_c(31 downto 24) & MAC_addr_c(39 downto 32) & MAC_addr_c(47 downto 40), "0000",'1',0,'0','0',0,'0','0',0), -- MAC Address 32 LSb's.
|
139 |
|
|
('0', "00100", x"0000" & MAC_addr_c(7 downto 0) & MAC_addr_c(15 downto 8),"1100",'1',0,'0','0',0, '0', '0', 0), -- MAC Address 16 MSb's.
|
140 |
|
|
('0', "00110", x"0000" & "0001101000010000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- AUTO_RELEASE on.
|
141 |
|
|
('0', "00111", x"00000002", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Select BANK 2
|
142 |
|
|
('0', "00000", x"000000" & "01000000", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- Issue MMU Reset Command, just to be sure.
|
143 |
|
|
('0', "00110", x"0000" & "0000000" & enable_rx_g & x"FF", "1100", '1', 0, '0', '0', 0, '0', '0', 0), -- RCV interrupt mask according to enable_rx_g. Also ack all.
|
144 |
|
|
-- Alles in Ordnung, and link should be up. Let's sleep for a few seconds so that the other side is up, too.
|
145 |
|
|
('0', "00000", x"ACDCABBA", "1111", '1', clk_hz_c*3, '1', '0', 0, '0', '0', 0), -- Sleep only, three seconds.
|
146 |
|
|
-- ('0', "00110", x"00000000", "1100", '0', 50 ,'0', '0', 0, '0', '0', 0), -- DEBUG: Read that interrupt mask register.
|
147 |
|
|
('0', "00000", x"ACDCABBA", "1111", '1', clk_hz_c*3, '1', '0', 0, '0', '0', 0) -- Sleep only, three seconds.
|
148 |
|
|
); -- And note, we left in BANK 2, as we should!! Other modules expect this.
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
signal init_cnt_r : integer range 0 to init_values_c - 1;
|
152 |
|
|
signal ready_r : std_logic;
|
153 |
|
|
signal data_from_comm_r : std_logic_vector( lan91_data_width_c-1 downto 0 );
|
154 |
|
|
|
155 |
|
|
type init_state_type is (start, read_data, wait_busy, sleep, phy_horror, finished);
|
156 |
|
|
signal state_r : init_state_type;
|
157 |
|
|
|
158 |
|
|
type phy_horror_state_type is (start_horror,
|
159 |
|
|
write1, wait1, write2, wait2, write3, wait3,
|
160 |
|
|
read3, waitread -- they come after wait2, only if reading
|
161 |
|
|
);
|
162 |
|
|
|
163 |
|
|
signal phy_horror_state_r : phy_horror_state_type;
|
164 |
|
|
|
165 |
|
|
constant phy_horror_length_c : integer := 64; -- PHY configuration horror
|
166 |
|
|
-- cycle lasts for 64 serial
|
167 |
|
|
-- clock cycles, including the
|
168 |
|
|
-- "IDLE" period that could be
|
169 |
|
|
-- called a START CONDITION
|
170 |
|
|
-- as it is a condition for
|
171 |
|
|
-- a successful start.
|
172 |
|
|
|
173 |
|
|
signal phy_horror_counter_r : integer range 0 to phy_horror_length_c;
|
174 |
|
|
-- let's use 250 ns waiting time between clk cycles. There is some extra
|
175 |
|
|
-- cycles in addition to this.
|
176 |
|
|
constant phy_horror_wait_time_c : integer := clk_hz_c/4000000;
|
177 |
|
|
signal phy_horror_wait_cnt_r : integer range 0 to phy_horror_wait_time_c;
|
178 |
|
|
-- Phy horror register includes first (leftmost) 34 bits hard-wired to the start condition.
|
179 |
|
|
-- Rightmost bits are registers. Leftmosts (MSb's) are send first. Register
|
180 |
|
|
-- is set before the sending of the serial bits starts.
|
181 |
|
|
signal phy_horror_register_r : std_logic_vector(phy_horror_length_c-1 downto 0);
|
182 |
|
|
signal phy_horror_interface_MDOE_r : std_logic; -- '0' if we want to instruct the Phy horror interface to hi-Z state.
|
183 |
|
|
signal phy_horror_read_data_flowing_r : std_logic; -- Comes high two Horror Cycles after
|
184 |
|
|
-- MDOE_r goes low.
|
185 |
|
|
|
186 |
|
|
signal horror_read_r : std_logic_vector(15 downto 0);
|
187 |
|
|
|
188 |
|
|
signal reset_sleep_cnt_r : integer range 0 to reset_sleep_c;
|
189 |
|
|
signal sleep_cnt_r : integer range 0 to max_sleep_c;
|
190 |
|
|
|
191 |
|
|
-- 1 second with 25MHz (yes, it's really necessary)
|
192 |
|
|
constant link_wait_time_c : integer := 25000000;
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
-------------------------------------------------------------------------------
|
197 |
|
|
begin -- rtl
|
198 |
|
|
-------------------------------------------------------------------------------
|
199 |
|
|
|
200 |
|
|
assert phy_horror_wait_time_c > 0 report "this has to be 1 or more" severity failure;
|
201 |
|
|
|
202 |
|
|
ready_out <= ready_r;
|
203 |
|
|
|
204 |
|
|
-- Concurrent part of the phy_horror_register: the start condition consisting
|
205 |
|
|
-- of things called "IDLE" and "START BITS".
|
206 |
|
|
phy_horror_register_r(63 downto 30) <= "1111111111111111111111111111111101";
|
207 |
|
|
|
208 |
|
|
init: process (clk, rst_n)
|
209 |
|
|
begin -- process init
|
210 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
211 |
|
|
|
212 |
|
|
ready_r <= '0';
|
213 |
|
|
init_cnt_r <= 0;
|
214 |
|
|
data_from_comm_r <= (others => '0');
|
215 |
|
|
reset_sleep_cnt_r <= 0;
|
216 |
|
|
reg_addr_out <= (others => '0');
|
217 |
|
|
config_data_out <= (others => '0');
|
218 |
|
|
read_not_write_out <= '0';
|
219 |
|
|
config_valid_out <= '0';
|
220 |
|
|
state_r <= start;
|
221 |
|
|
phy_horror_state_r <= start_horror;
|
222 |
|
|
|
223 |
|
|
horror_read_r <= (others => '0');
|
224 |
|
|
sleep_cnt_r <= 0;
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
228 |
|
|
|
229 |
|
|
-- DEFAULTS:
|
230 |
|
|
config_valid_out <= '0';
|
231 |
|
|
|
232 |
|
|
if reset_sleep_cnt_r /= reset_sleep_c then
|
233 |
|
|
-- sleep for a while after reset release
|
234 |
|
|
reset_sleep_cnt_r <= reset_sleep_cnt_r + 1;
|
235 |
|
|
|
236 |
|
|
elsif ready_r = '0' then
|
237 |
|
|
|
238 |
|
|
case state_r is
|
239 |
|
|
when start =>
|
240 |
|
|
if init_table_c(init_cnt_r).only_sleep = '1' then
|
241 |
|
|
sleep_cnt_r <= init_table_c(init_cnt_r).sleep_time;
|
242 |
|
|
state_r <= sleep;
|
243 |
|
|
elsif init_table_c(init_cnt_r).phy = '1' then
|
244 |
|
|
-- Enter the psycho mode.
|
245 |
|
|
state_r <= phy_horror;
|
246 |
|
|
else
|
247 |
|
|
-- A _*NORMAL*_ OPERATION (at least quite normal)!
|
248 |
|
|
reg_addr_out <= init_table_c( init_cnt_r ).addr(real_addr_width_c-1 downto 0);
|
249 |
|
|
if init_table_c( init_cnt_r ).copy = '1' then
|
250 |
|
|
config_data_out <= data_from_comm_r;
|
251 |
|
|
if init_table_c(init_cnt_r).poll_until = '1' then -- this means the "modify" command.
|
252 |
|
|
config_data_out(init_table_c(init_cnt_r).poll_bit_num) <= horror_read_r(init_table_c(init_cnt_r).copy_bit_num);
|
253 |
|
|
-- bypass this one bit.
|
254 |
|
|
end if;
|
255 |
|
|
else
|
256 |
|
|
config_data_out <= init_table_c( init_cnt_r ).value;
|
257 |
|
|
end if;
|
258 |
|
|
read_not_write_out <= not init_table_c( init_cnt_r ).writing;
|
259 |
|
|
nBE_out <= init_table_c( init_cnt_r ).nBE;
|
260 |
|
|
config_valid_out <= '1';
|
261 |
|
|
|
262 |
|
|
-- change state once busy is up (comm is working)
|
263 |
|
|
if comm_busy_in = '1' then
|
264 |
|
|
if init_table_c( init_cnt_r ).writing = '0' then
|
265 |
|
|
state_r <= read_data;
|
266 |
|
|
else
|
267 |
|
|
state_r <= wait_busy;
|
268 |
|
|
end if;
|
269 |
|
|
end if;
|
270 |
|
|
end if;
|
271 |
|
|
|
272 |
|
|
when read_data =>
|
273 |
|
|
|
274 |
|
|
-- reading is quite useless at the moment, but for example some
|
275 |
|
|
-- registers can be cleared by reading if necessary
|
276 |
|
|
if data_from_comm_valid_in = '1' then
|
277 |
|
|
data_from_comm_r <= data_from_comm_in;
|
278 |
|
|
state_r <= wait_busy;
|
279 |
|
|
end if;
|
280 |
|
|
|
281 |
|
|
when wait_busy =>
|
282 |
|
|
if comm_busy_in = '0' then
|
283 |
|
|
sleep_cnt_r <= init_table_c(init_cnt_r).sleep_time;
|
284 |
|
|
state_r <= sleep;
|
285 |
|
|
end if;
|
286 |
|
|
|
287 |
|
|
when sleep =>
|
288 |
|
|
if sleep_cnt_r /= 0 then
|
289 |
|
|
sleep_cnt_r <= sleep_cnt_r - 1;
|
290 |
|
|
else
|
291 |
|
|
-- Were we polling something?
|
292 |
|
|
if init_table_c(init_cnt_r).poll_until = '1' and
|
293 |
|
|
((init_table_c(init_cnt_r).phy = '1' and horror_read_r(init_table_c(init_cnt_r).poll_bit_num) /= init_table_c(init_cnt_r).poll_value) or
|
294 |
|
|
(init_table_c(init_cnt_r).phy = '0' and data_from_comm_r(init_table_c(init_cnt_r).poll_bit_num) /= init_table_c(init_cnt_r).poll_value))
|
295 |
|
|
then
|
296 |
|
|
state_r <= start; -- back to start to poll again!
|
297 |
|
|
else
|
298 |
|
|
-- We were not polling, or got what we wanted.
|
299 |
|
|
if init_cnt_r = init_values_c-1 then
|
300 |
|
|
state_r <= finished;
|
301 |
|
|
else
|
302 |
|
|
init_cnt_r <= init_cnt_r + 1; -- to next row.
|
303 |
|
|
state_r <= start;
|
304 |
|
|
end if;
|
305 |
|
|
end if;
|
306 |
|
|
end if;
|
307 |
|
|
|
308 |
|
|
when phy_horror =>
|
309 |
|
|
case phy_horror_state_r is
|
310 |
|
|
when start_horror =>
|
311 |
|
|
phy_horror_register_r(29 downto 0) <=
|
312 |
|
|
not init_table_c(init_cnt_r).writing &
|
313 |
|
|
init_table_c(init_cnt_r).writing &
|
314 |
|
|
"00000" &
|
315 |
|
|
init_table_c(init_cnt_r).addr(4 downto 0) &
|
316 |
|
|
"10" & -- "turnaround" is written always
|
317 |
|
|
-- as "10". Request for high-impedance
|
318 |
|
|
-- is done separately.
|
319 |
|
|
init_table_c(init_cnt_r).value(15 downto 0);
|
320 |
|
|
|
321 |
|
|
if init_table_c( init_cnt_r ).copy = '1' then
|
322 |
|
|
phy_horror_register_r(15 downto 0) <= horror_read_r; -- bypass the value.
|
323 |
|
|
if init_table_c(init_cnt_r).poll_until = '1' then -- this means the "modify" command.
|
324 |
|
|
phy_horror_register_r(init_table_c(init_cnt_r).poll_bit_num) <= data_from_comm_r(init_table_c(init_cnt_r).copy_bit_num);
|
325 |
|
|
-- bypass this one bit.
|
326 |
|
|
end if;
|
327 |
|
|
end if;
|
328 |
|
|
|
329 |
|
|
phy_horror_counter_r <= phy_horror_length_c-1;
|
330 |
|
|
-- Everything will be 16 bit writes to the same stupid
|
331 |
|
|
-- "Management Interface" register.
|
332 |
|
|
reg_addr_out <= "100";
|
333 |
|
|
nBE_out <= "1100";
|
334 |
|
|
phy_horror_interface_MDOE_r <= '1';
|
335 |
|
|
phy_horror_read_data_flowing_r <= '0';
|
336 |
|
|
phy_horror_state_r <= write1;
|
337 |
|
|
|
338 |
|
|
when write1 =>
|
339 |
|
|
if comm_busy_in = '0' then
|
340 |
|
|
read_not_write_out <= '0';
|
341 |
|
|
config_data_out <= x"0000" & "00110011" & "0011"
|
342 |
|
|
& phy_horror_interface_MDOE_r
|
343 |
|
|
& '0' -- MCLK
|
344 |
|
|
& '0' -- MDI
|
345 |
|
|
& phy_horror_register_r(phy_horror_counter_r);
|
346 |
|
|
config_valid_out <= '1';
|
347 |
|
|
phy_horror_state_r <= wait1;
|
348 |
|
|
phy_horror_wait_cnt_r <= phy_horror_wait_time_c;
|
349 |
|
|
end if;
|
350 |
|
|
|
351 |
|
|
when wait1 =>
|
352 |
|
|
if comm_busy_in = '0' then
|
353 |
|
|
if phy_horror_wait_cnt_r = 0 then
|
354 |
|
|
if init_table_c(init_cnt_r).writing = '0' and phy_horror_read_data_flowing_r = '1' then
|
355 |
|
|
phy_horror_state_r <= read3;
|
356 |
|
|
else
|
357 |
|
|
phy_horror_state_r <= write2;
|
358 |
|
|
end if;
|
359 |
|
|
else
|
360 |
|
|
phy_horror_wait_cnt_r <= phy_horror_wait_cnt_r - 1;
|
361 |
|
|
end if;
|
362 |
|
|
end if;
|
363 |
|
|
|
364 |
|
|
when write2 =>
|
365 |
|
|
if comm_busy_in = '0' then
|
366 |
|
|
read_not_write_out <= '0';
|
367 |
|
|
config_data_out <= x"0000" & "00110011" & "0011"
|
368 |
|
|
& phy_horror_interface_MDOE_r
|
369 |
|
|
& '1' -- OOOOOOOHHH, create the clock edge!!!!
|
370 |
|
|
& '0' -- MDI
|
371 |
|
|
& phy_horror_register_r(phy_horror_counter_r);
|
372 |
|
|
config_valid_out <= '1';
|
373 |
|
|
phy_horror_state_r <= wait2;
|
374 |
|
|
phy_horror_wait_cnt_r <= phy_horror_wait_time_c;
|
375 |
|
|
end if;
|
376 |
|
|
|
377 |
|
|
when wait2 =>
|
378 |
|
|
if comm_busy_in = '0' then
|
379 |
|
|
if phy_horror_wait_cnt_r = 0 then
|
380 |
|
|
phy_horror_state_r <= write3;
|
381 |
|
|
else
|
382 |
|
|
phy_horror_wait_cnt_r <= phy_horror_wait_cnt_r - 1;
|
383 |
|
|
end if;
|
384 |
|
|
end if;
|
385 |
|
|
|
386 |
|
|
when read3 =>
|
387 |
|
|
-- This state is skipped when writing.
|
388 |
|
|
if comm_busy_in = '0' then
|
389 |
|
|
read_not_write_out <= '1'; -- read operation to the same addr
|
390 |
|
|
config_valid_out <= '1';
|
391 |
|
|
phy_horror_state_r <= waitread;
|
392 |
|
|
end if;
|
393 |
|
|
|
394 |
|
|
when waitread =>
|
395 |
|
|
-- This state is skipped when writing.
|
396 |
|
|
if data_from_comm_valid_in = '1' then
|
397 |
|
|
-- data valid means also not busy so no need to check that.
|
398 |
|
|
-- Just read the data we are interested in here
|
399 |
|
|
horror_read_r(phy_horror_counter_r) <= data_from_comm_in(1);
|
400 |
|
|
phy_horror_state_r <= write2;
|
401 |
|
|
end if;
|
402 |
|
|
|
403 |
|
|
when write3 =>
|
404 |
|
|
if comm_busy_in = '0' then
|
405 |
|
|
read_not_write_out <= '0';
|
406 |
|
|
config_data_out <= x"0000" & "00110011" & "0011"
|
407 |
|
|
& phy_horror_interface_MDOE_r
|
408 |
|
|
& '0' -- MCLK Low again, OMG
|
409 |
|
|
& '0' -- MDI
|
410 |
|
|
& phy_horror_register_r(phy_horror_counter_r);
|
411 |
|
|
config_valid_out <= '1';
|
412 |
|
|
phy_horror_state_r <= wait3;
|
413 |
|
|
phy_horror_wait_cnt_r <= phy_horror_wait_time_c;
|
414 |
|
|
end if;
|
415 |
|
|
|
416 |
|
|
when wait3 =>
|
417 |
|
|
if comm_busy_in = '0' then
|
418 |
|
|
if phy_horror_wait_cnt_r = 0 then
|
419 |
|
|
if phy_horror_counter_r = 0 then
|
420 |
|
|
-- OH YES, we got all the bits done.
|
421 |
|
|
phy_horror_state_r <= start_horror;
|
422 |
|
|
state_r <= wait_busy; -- This is good, away from the horror FSM.
|
423 |
|
|
else
|
424 |
|
|
phy_horror_counter_r <= phy_horror_counter_r - 1;
|
425 |
|
|
phy_horror_state_r <= write1; -- To the next bit...
|
426 |
|
|
if init_table_c(init_cnt_r).writing = '0' then
|
427 |
|
|
if phy_horror_counter_r = 18 then
|
428 |
|
|
-- Turnaround time.
|
429 |
|
|
phy_horror_interface_MDOE_r <= '0';
|
430 |
|
|
elsif phy_horror_counter_r = 16 then
|
431 |
|
|
-- Valid data is coming next (hopefully)
|
432 |
|
|
phy_horror_read_data_flowing_r <= '1';
|
433 |
|
|
end if;
|
434 |
|
|
end if;
|
435 |
|
|
end if;
|
436 |
|
|
else
|
437 |
|
|
phy_horror_wait_cnt_r <= phy_horror_wait_cnt_r - 1;
|
438 |
|
|
end if;
|
439 |
|
|
end if;
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
when others => null;
|
443 |
|
|
end case;
|
444 |
|
|
|
445 |
|
|
when finished =>
|
446 |
|
|
|
447 |
|
|
ready_r <= '1';
|
448 |
|
|
|
449 |
|
|
when others => null;
|
450 |
|
|
end case;
|
451 |
|
|
|
452 |
|
|
else
|
453 |
|
|
-- ready_r = '1'
|
454 |
|
|
|
455 |
|
|
reg_addr_out <= (others => '0');
|
456 |
|
|
config_data_out <= (others => '0');
|
457 |
|
|
read_not_write_out <= '0';
|
458 |
|
|
config_valid_out <= '0';
|
459 |
|
|
|
460 |
|
|
end if;
|
461 |
|
|
end if;
|
462 |
|
|
end process init;
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
end rtl;
|