Skip to content

Commit 5153986

Browse files
committedApr 12, 2015
liteeth/phy/gmii_mii: add clock counter and use it in bios to select mode
1 parent 857bee8 commit 5153986

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed
 

Diff for: ‎misoclib/com/liteeth/phy/gmii_mii.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from migen.genlib.io import DDROutput
22
from migen.flow.plumbing import Multiplexer, Demultiplexer
3+
from migen.genlib.cdc import MultiReg
34

45
from misoclib.com.liteeth.common import *
56
from misoclib.com.liteeth.generic import *
67

7-
from misoclib.com.liteeth.phy.gmii import LiteEthPHYGMIIMIICRG
8+
from misoclib.com.liteeth.phy.gmii import LiteEthPHYGMIICRG
89
from misoclib.com.liteeth.phy.mii import LiteEthPHYMIITX, LiteEthPHYMIIRX
910
from misoclib.com.liteeth.phy.gmii import LiteEthPHYGMIITX, LiteEthPHYGMIIRX
1011

@@ -67,13 +68,27 @@ def __init__(self, pads, mode):
6768
Record.connect(mux.source, source)
6869
]
6970

71+
class LiteEthGMIIMIIClockCounter(Module, AutoCSR):
72+
def __init__(self):
73+
self._reset = CSRStorage()
74+
self._value = CSRStatus(32)
75+
###
76+
counter = RenameClockDomains(Counter(32), "eth_rx")
77+
self.submodules += counter
78+
self.comb += [
79+
counter.reset.eq(self._reset.storage), #slow, don't need CDC
80+
counter.ce.eq(1),
81+
]
82+
self.specials += MultiReg(counter.value, self._value.status)
83+
7084
class LiteEthPHYGMIIMII(Module, AutoCSR):
7185
def __init__(self, clock_pads, pads, with_hw_init_reset=True):
7286
self.dw = 8
7387
self._mode = CSRStorage()
7488
mode = self._mode.storage
7589
# Note: we can use GMII CRG since it also handles tx clock pad used for MII
7690
self.submodules.crg = LiteEthPHYGMIICRG(clock_pads, pads, with_hw_init_reset)
91+
self.submodules.clock_counter = LiteEthGMIIMIIClockCounter()
7792
self.submodules.tx = RenameClockDomains(LiteEthPHYGMIIMIITX(pads, mode), "eth_tx")
7893
self.submodules.rx = RenameClockDomains(LiteEthPHYGMIIMIIRX(pads, mode), "eth_rx")
7994
self.sink, self.source = self.tx.sink, self.rx.source

Diff for: ‎software/bios/main.c

+3
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ static void boot_sequence(void)
502502
flashboot();
503503
#endif
504504
serialboot();
505+
#ifdef CSR_ETHPHY_MODE_ADDR
506+
ethmode();
507+
#endif
505508
#ifdef CSR_ETHMAC_BASE
506509
netboot();
507510
#endif

Diff for: ‎software/include/net/microudp.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ void microudp_set_callback(udp_callback callback);
1515
void microudp_service(void);
1616

1717
void ethreset(void);
18+
void ethmode(void);
1819

1920
#endif /* __MICROUDP_H */

Diff for: ‎software/libnet/microudp.c

+23
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,27 @@ void ethreset(void)
444444
busy_wait(2);
445445
}
446446

447+
void ethmode(void)
448+
{
449+
ethphy_clock_counter_reset_write(1);
450+
busy_wait(1);
451+
ethphy_clock_counter_reset_write(0);
452+
busy_wait(1);
453+
454+
printf("Ethernet phy mode: ");
455+
/* if freq > 120 MHz, use GMII (5MHz margin)*/
456+
if (ethphy_clock_counter_value_read() > 120000000/10) {
Has conversations. Original line has conversations.
457+
ethphy_mode_write(0);
458+
printf("GMII");
459+
/* else use MII */
460+
} else {
461+
ethphy_mode_write(1);
462+
printf("MII");
463+
}
464+
printf("\n");
465+
466+
ethphy_clock_counter_reset_write(1);
467+
}
468+
447469
#endif
470+

0 commit comments

Comments
 (0)
Please sign in to comment.