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

Subversion Repositories esoc

[/] [esoc/] [trunk/] [Sources/] [altera/] [esoc_port_mac/] [testbench/] [model/] [mdio_slave.vhd] - Blame information for rev 42

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 42 lmaarsen
-- -------------------------------------------------------------------------
2
-- -------------------------------------------------------------------------
3
--
4
-- Revision Control Information
5
--
6
-- $RCSfile: $
7
-- $Source: $
8
--
9
-- $Revision: #1 $
10
-- $Date: 2008/08/09 $
11
-- Check in by : $Author: sc-build $
12
-- Author      : SKNg/TTChong
13
--
14
-- Project     : Triple Speed Ethernet - 10/100/1000 MAC
15
--
16
-- Description : (Simulation only)
17
--
18
-- MDIO slave's register interface controller 
19
-- Instantiated in top_mdio_slave (top_mdio_slave.vhd)
20
--
21
-- 
22
-- ALTERA Confidential and Proprietary
23
-- Copyright 2006 (c) Altera Corporation
24
-- All rights reserved
25
--
26
-- -------------------------------------------------------------------------
27
-- -------------------------------------------------------------------------
28
 
29
 
30
 
31
library ieee;
32
use     ieee.std_logic_1164.all;
33
use     ieee.std_logic_arith.all;
34
use     ieee.std_logic_unsigned.all;
35
use     ieee.std_logic_misc.all;
36
 
37
 
38
entity mdio_slave is port (
39
 
40
        reset           : in std_logic;                         -- asynch reset
41
        mdc             : in std_logic;                         -- system clock
42
        mdio            : inout std_logic;                      -- Data Bus
43
        dev_addr        : in  std_logic_vector(4 downto 0);     -- Device address
44
        reg_addr        : out std_logic_vector(4 downto 0);     -- Address register
45
        reg_read        : out std_logic;                        -- Read register         
46
        reg_write       : out std_logic;                        -- Write register         
47
        reg_dout        : out std_logic_vector(15 downto 0);    -- Data Bus OUT
48
        reg_din         : in  std_logic_vector(15 downto 0)) ;  -- Data Bus IN
49
 
50
end mdio_slave;
51
 
52
architecture rtl of mdio_slave is
53
 
54
        signal phy_add            : std_logic_vector(4 downto 0);   -- Phy Address
55
        signal reg_add            : std_logic_vector(4 downto 0);   -- Register Address
56
        signal reg_out            : std_logic_vector(15 downto 0);  -- Register data out
57
        signal reg_in             : std_logic_vector(15 downto 0);  -- Register data in
58
        signal en_phy_add         : std_logic;                      -- Write phy Address
59
        signal en_reg_add         : std_logic;                      -- Write register Address
60
        signal en_data_out        : std_logic;                      -- Write register data out
61
        signal en_data_in         : std_logic;                      -- Write register data in
62
        signal shift_data_in      : std_logic;                      -- Send register data in
63
        signal phy_add_ok         : std_logic;                      -- Phy Address correct
64
        signal cnt_32             : std_logic_vector(4 downto 0);   -- Frame Bit counter
65
        signal run_cnt_32         : std_logic;                      -- Run Frame Bit counter
66
        signal ok_32              : std_logic;                      -- Preambule length reached
67
        signal ok_16              : std_logic;                      -- Data length reached
68
        signal ok_10              : std_logic;                      -- Reg address length reach
69
        signal ok_5               : std_logic;                      -- Phy address length reach
70
        signal cd_oe              : std_logic;                      -- Output Enable command
71
        signal mux_0              : std_logic;                      -- Mux zero
72
        signal mdio_wait          : std_logic;                      -- Wait state of State machine
73
        signal mdio_run           : std_logic_vector(16 downto 0);  -- State machine core
74
 
75
begin
76
 
77
 
78
 
79
--=====================================================================
80
-- Data logic structure  
81
--=====================================================================
82
p_data:process(mdc,reset)
83
begin
84
if (reset='1') then
85
 
86
    phy_add            <= (others=>'0');   -- Phy Address
87
    reg_add            <= (others=>'0');   -- Register Address
88
    reg_out            <= (others=>'0');   -- Register data out
89
    reg_in             <= (others=>'0');    -- Register data in
90
    --
91
    cnt_32             <= (others=>'0');   -- Frame Bit counter
92
    --
93
 
94
 elsif (mdc'event and mdc='1') then
95
 
96
 
97
     ------------------------
98
     -- Phy Address
99
     ------------------------
100
     if (en_phy_add='1')
101
         then phy_add(4 downto 0) <= (phy_add(3 downto 0) & mdio);
102
         else phy_add <= phy_add;
103
     end if;
104
     ------------------------
105
 
106
 
107
     -------------------------
108
     -- Register Address 
109
     -------------------------  
110
     if (en_reg_add='1')
111
         then reg_add(4 downto 0) <= (reg_add(3 downto 0) & mdio);
112
         else reg_add <= reg_add;
113
     end if;
114
     -------------------------
115
 
116
 
117
     -------------------------
118
     -- Register data out 
119
     -------------------------  
120
     if (en_data_out='1')
121
         then reg_out(15 downto 0) <= (reg_out(14 downto 0) & mdio);
122
         else reg_out <= reg_out;
123
     end if;
124
     -------------------------
125
 
126
 
127
     -------------------------------------------
128
     -- Register data in
129
     -------------------------------------------
130
     if (en_data_in='1')
131
         then reg_in(15 downto 0) <= reg_din;
132
     elsif (shift_data_in='1')
133
      then reg_in(15 downto 1) <= reg_in(14 downto 0);
134
     else   reg_in              <= reg_in;
135
     end if;
136
     --    
137
     --------------------------------------------
138
 
139
 
140
     ----------------------
141
     -- Frame Bit counter
142
     ---------------------
143
     if (run_cnt_32='1')
144
        then cnt_32 <= cnt_32 + 1;
145
        else cnt_32 <= "00000";
146
     end if;
147
     ---------------------
148
 
149
 
150
end if;
151
end process;
152
--
153
----------------------------
154
-- Phy Address correct
155
----------------------------
156
phy_add_ok <= '1' when  (phy_add = dev_addr) else '0';
157
--
158
-----------------------------
159
-- Preambule length reached
160
-----------------------------
161
ok_32  <= '1' when  (cnt_32 = "11110") else '0';
162
--  
163
----------------------------
164
-- Data length reached
165
----------------------------
166
ok_16  <= '1' when  (cnt_32 = "01111") else '0';
167
-- 
168
----------------------------
169
-- Reg address length reach
170
----------------------------
171
ok_10  <= '1' when  (cnt_32 = "01010") else '0';
172
--  
173
----------------------------
174
-- Phy address length reach
175
----------------------------
176
ok_5  <= '1' when  (cnt_32 = "00101") else '0';
177
--                      
178
------------------------
179
-- -- Address register
180
------------------------
181
reg_addr <= reg_add;
182
--
183
------------------------
184
-- Data Bus OUT
185
------------------------
186
reg_dout <=  reg_out;
187
--
188
------------------------
189
-- Mux zero
190
------------------------
191
mux_0 <= '0' when (mdio_run(8)='1') else (reg_in(15));
192
--
193
------------------------
194
-- Data Bus
195
------------------------
196
mdio <= mux_0 after 20 ns when (cd_oe='0') else 'Z' after 20 ns ;
197
--        
198
--=====================================================================
199
 
200
 
201
 
202
 
203
--=====================================================================
204
-- State machine body  
205
--=====================================================================
206
p_state:process(mdc,reset)
207
begin
208
if (reset='1') then
209
 
210
    mdio_wait          <= '1';             -- Wait state of State machine
211
    mdio_run           <= (others=>'0');   -- State machine core
212
    --
213
    cd_oe              <= '1';             -- Output Enable command
214
    --
215
    en_phy_add         <= '0';             -- Write phy Address
216
    en_reg_add         <= '0';             -- Write register Address
217
    en_data_out        <= '0';             -- Write register data out
218
    --
219
    -- 
220
 
221
 
222
 elsif (mdc'event and mdc='1') then
223
 
224
 
225
    ----------------------------------------
226
    -- wait for a frame
227
    ----------------------------------------
228
    if (mdio_wait='1'    and mdio='0') or
229
       (mdio_run(0)='1'  and mdio='0') or
230
       (mdio_run(2)='1'  and mdio='0') or
231
       (mdio_run(4)='1'  and mdio='1') or
232
       (mdio_run(6)='1'  and phy_add_ok='0') or
233
       (mdio_run(7)='1'  and mdio='0') or
234
       (mdio_run(9)='1'  and ok_16='1') or
235
       (mdio_run(10)='1' and mdio='0') or
236
       (mdio_run(12)='1' and phy_add_ok='0') or
237
       (mdio_run(13)='1' and mdio='0') or
238
       (mdio_run(14)='1' and mdio='1') or
239
       (mdio_run(16)='1') or
240
       (mdio_run(0)='0' and mdio_run(1)='0' and mdio_run(2)='0' and mdio_run(3)='0' and
241
        mdio_run(4)='0' and mdio_run(5)='0' and mdio_run(6)='0' and mdio_run(7)='0' and
242
        mdio_run(8)='0' and mdio_run(9)='0' and mdio_run(10)='0' and mdio_run(11)='0' and
243
        mdio_run(12)='0' and mdio_run(13)='0' and mdio_run(14)='0' and mdio_run(15)='0' and
244
        mdio_run(16)='0')
245
      then mdio_wait <= '1';
246
      else mdio_wait <= '0';
247
     end if;
248
     --
249
    ----------------------------------------------
250
    -- Check preambule
251
    ----------------------------------------------
252
    if (mdio_wait='1'   and mdio='1') or
253
         (mdio_run(0)='1' and mdio='1' and ok_32='0')
254
         then mdio_run(0) <= '1';
255
         else mdio_run(0) <= '0';
256
     end if;
257
     --
258
    if (mdio_run(0)='1' and mdio='1' and ok_32='1') or
259
         (mdio_run(1)='1'  and mdio='1')
260
          then mdio_run(1) <= '1';
261
         else mdio_run(1) <= '0';
262
     end if;
263
     ----------------------------------------------
264
    -- Check ST
265
    ----------------------------------------------
266
     if (mdio_run(1)='1'  and mdio='0')
267
         then mdio_run(2) <= '1';
268
         else mdio_run(2) <= '0';
269
     end if;
270
     --   
271
     if (mdio_run(2)='1'  and mdio='1')
272
         then mdio_run(3) <= '1';
273
         else mdio_run(3) <= '0';
274
     end if;
275
     ----------------------------------------------
276
    -- Check OP
277
    ----------------------------------------------      
278
     if (mdio_run(3)='1'  and mdio='1')
279
         then mdio_run(4) <= '1';
280
         else mdio_run(4) <= '0';
281
     end if;
282
     ----------------------------------------------
283
    -- Read OP
284
    ----------------------------------------------              
285
     if (mdio_run(4)='1'  and mdio='0') or
286
         (mdio_run(5)='1' and ok_5='0')
287
         then mdio_run(5) <= '1';
288
         else mdio_run(5) <= '0';
289
     end if;
290
     -- 
291
     if (mdio_run(5)='1' and ok_5='1') or
292
          (mdio_run(6)='1' and ok_10='0' and phy_add_ok='1')
293
         then mdio_run(6) <= '1';
294
         else mdio_run(6) <= '0';
295
     end if;
296
     --
297
     if (mdio_run(6)='1' and ok_10='1' and phy_add_ok='1')
298
         then mdio_run(7) <= '1';
299
         else mdio_run(7) <= '0';
300
     end if;
301
     --
302
     if (mdio_run(7)='1'  and mdio/='0')
303
        then mdio_run(8) <= '1';
304
         else mdio_run(8) <= '0';
305
     end if;
306
     --
307
    if (mdio_run(8)='1') or
308
          (mdio_run(9)='1' and ok_16='0')
309
         then mdio_run(9) <= '1';
310
         else mdio_run(9) <= '0';
311
     end if;
312
     --
313
     ----------------------------------------------
314
    -- Write OP
315
    ----------------------------------------------                   
316
    if (mdio_run(3)='1' and mdio='0')
317
         then mdio_run(10) <= '1';
318
         else mdio_run(10) <= '0';
319
     end if;
320
     -- 
321
     if (mdio_run(10)='1' and mdio='1') or
322
          (mdio_run(11)='1' and ok_5='0')
323
         then mdio_run(11) <= '1';
324
         else mdio_run(11) <= '0';
325
     end if;
326
     -- 
327
      if (mdio_run(11)='1' and ok_5='1') or
328
           (mdio_run(12)='1' and ok_10='0' and phy_add_ok='1')
329
         then mdio_run(12) <= '1';
330
         else mdio_run(12) <= '0';
331
     end if;
332
     --
333
     if (mdio_run(12)='1' and ok_10='1' and phy_add_ok='1')
334
         then mdio_run(13) <= '1';
335
         else mdio_run(13) <= '0';
336
     end if;
337
     --
338
     if (mdio_run(13)='1' and mdio='1')
339
         then mdio_run(14) <= '1';
340
         else mdio_run(14) <= '0';
341
     end if;
342
     -- 
343
     if (mdio_run(14)='1' and mdio='0') or
344
        (mdio_run(15)='1' and ok_16='0')
345
         then mdio_run(15) <= '1';
346
         else mdio_run(15) <= '0';
347
     end if;
348
     --
349
     if (mdio_run(15)='1' and ok_16='1')
350
         then mdio_run(16) <= '1';
351
         else mdio_run(16) <= '0';
352
     end if;
353
     --
354
    ------------------------------    
355
 
356
 
357
 
358
     ----------------------
359
    -- Write phy Address    
360
     ----------------------          
361
    if (mdio_run(4)='1'  and mdio='0') or
362
         (mdio_run(5)='1' and ok_5='0') or
363
 
364
         (mdio_run(10)='1' and mdio='1') or
365
          (mdio_run(11)='1' and ok_5='0')
366
 
367
         then en_phy_add <= '1';
368
         else en_phy_add <= '0';
369
     end if;
370
     --            
371
    ---------------------
372
 
373
 
374
    ----------------------------           
375
    -- Write register Address
376
     ----------------------------
377
     if (mdio_run(5)='1' and ok_5='1') or
378
          (mdio_run(6)='1' and ok_10='0') or
379
 
380
         (mdio_run(11)='1' and ok_5='1') or
381
          (mdio_run(12)='1' and ok_10='0')
382
 
383
        then en_reg_add <= '1';
384
        else en_reg_add <= '0';
385
     end if;
386
     -----------------------------
387
 
388
 
389
    ----------------------------           
390
    -- Write register data out
391
     ----------------------------
392
     if (mdio_run(14)='1' and mdio='0') or
393
        (mdio_run(15)='1' and ok_16='0')
394
        then en_data_out <= '1';
395
        else en_data_out <= '0';
396
     end if;
397
     -----------------------------
398
 
399
 
400
    ----------------------------           
401
    -- Output Enable command
402
     ----------------------------
403
     if (mdio_run(7)='1' and mdio/='0') or
404
         (mdio_run(8)='1') or
405
          (mdio_run(9)='1' and ok_16='0')
406
        then cd_oe <= '0' ;
407
        else cd_oe <= '1' ;
408
     end if;
409
     -----------------------------
410
 
411
 
412
end if;
413
end process;
414
--
415
---------------------------
416
-- Write register data in
417
---------------------------
418
en_data_in <= mdio_run(8);
419
--
420
---------------------------
421
-- Send register data in   
422
---------------------------          
423
shift_data_in <= mdio_run(9);
424
--    
425
---------------------------          
426
-- Read register 
427
---------------------------          
428
reg_read <= '1' when (mdio_run(7)='1' and mdio/='0') or (mdio_run(8)='1') else '0';
429
--                             
430
---------------------------  
431
-- Write register
432
---------------------------
433
reg_write <= mdio_run(16);
434
--      
435
----------------------------------
436
-- Run Frame Bit counter
437
-----------------------------------
438
run_cnt_32 <= '1' when   (mdio_wait='1'   and mdio='1') or
439
                           (mdio_run(0)='1' and mdio='1' and ok_32='0')  or
440
 
441
                               (mdio_run(4)='1'  and mdio='0') or
442
                                 (mdio_run(5)='1' and ok_5='0') or
443
 
444
                               (mdio_run(5)='1' and ok_5='1') or
445
                                  (mdio_run(6)='1' and ok_10='0') or
446
 
447
                                 (mdio_run(9)='1') or
448
 
449
                               (mdio_run(10)='1' and mdio='1') or
450
                                  (mdio_run(11)='1' and ok_5='0') or
451
 
452
                               (mdio_run(11)='1' and ok_5='1') or
453
                                (mdio_run(12)='1' and ok_10='0') or
454
 
455
                               (mdio_run(15)='1' and ok_16='0')
456
 
457
                       else '0';
458
-----------------------------------
459
--
460
--=====================================================================
461
 
462
 
463
 
464
 
465
end rtl;

powered by: WebSVN 2.1.0

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