From bfb3a00a4e9e35d58cb23604203be2906051f2fb Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 18 Aug 2019 22:43:56 +0200 Subject: [PATCH] eth: derive proper mdc_clk_div from clocks --- src/eth/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/eth/mod.rs b/src/eth/mod.rs index 01392a5a..d606a0f3 100644 --- a/src/eth/mod.rs +++ b/src/eth/mod.rs @@ -10,6 +10,8 @@ pub mod tx; /// Size of all the buffers pub const MTU: usize = 1536; +/// Maximum MDC clock +const MAX_MDC: u32 = 2_500_000; pub struct Eth { regs: &'static mut regs::RegisterBlock, @@ -288,6 +290,9 @@ impl Eth { } fn configure(&mut self, macaddr: [u8; 6]) { + let clocks = CpuClocks::get(); + let mut mdc_clk_div = (clocks.cpu_1x() / MAX_MDC) + 1; + self.regs.net_cfg.write( regs::NetCfg::zeroed() .full_duplex(true) @@ -301,7 +306,7 @@ impl Eth { .fcs_remove(true) // One of the slower speeds // TODO: calculate properly - .mdc_clk_div(0b110) + .mdc_clk_div((mdc_clk_div >> 4).min(0b111) as u8) ); let macaddr_msbs =