forked from M-Labs/artiq
1
0
Fork 0

firmware: reset ethphy before initializing smoltcp (fixes #884).

This commit is contained in:
whitequark 2018-01-04 11:37:52 +00:00
parent 67746cc7a0
commit fc9766d2fa
3 changed files with 21 additions and 7 deletions

View File

@ -158,10 +158,12 @@ fn network_boot() {
println!("Using MAC address {} and IP address {}", eth_addr, ip_addr); println!("Using MAC address {} and IP address {}", eth_addr, ip_addr);
let net_device = unsafe { ethmac::EthernetDevice::new() }; let mut net_device = unsafe { ethmac::EthernetDevice::new() };
let mut neighbor_cache_storage = [None; 2]; net_device.reset();
let mut neighbor_map = [None; 2];
let neighbor_cache = let neighbor_cache =
smoltcp::iface::NeighborCache::new(&mut neighbor_cache_storage[..]); smoltcp::iface::NeighborCache::new(&mut neighbor_map[..]);
let mut ip_addrs = [IpCidr::new(ip_addr, 0)]; let mut ip_addrs = [IpCidr::new(ip_addr, 0)];
let mut interface = let mut interface =
smoltcp::iface::EthernetInterfaceBuilder::new(net_device) smoltcp::iface::EthernetInterfaceBuilder::new(net_device)

View File

@ -4,6 +4,7 @@ use smoltcp::phy::{self, DeviceCapabilities, Device};
use csr; use csr;
use mem::ETHMAC_BASE; use mem::ETHMAC_BASE;
use clock;
const RX_SLOTS: usize = csr::ETHMAC_RX_SLOTS as usize; const RX_SLOTS: usize = csr::ETHMAC_RX_SLOTS as usize;
const TX_SLOTS: usize = csr::ETHMAC_TX_SLOTS as usize; const TX_SLOTS: usize = csr::ETHMAC_TX_SLOTS as usize;
@ -45,6 +46,15 @@ impl EthernetDevice {
pub unsafe fn new() -> EthernetDevice { pub unsafe fn new() -> EthernetDevice {
EthernetDevice(()) EthernetDevice(())
} }
pub fn reset(&mut self) {
unsafe {
csr::ethphy::crg_reset_write(1);
clock::spin_us(2_000);
csr::ethphy::crg_reset_write(0);
clock::spin_us(2_000);
}
}
} }
impl<'a> Device<'a> for EthernetDevice { impl<'a> Device<'a> for EthernetDevice {

View File

@ -130,18 +130,20 @@ fn startup_ethernet() {
} }
} }
let mut net_device = unsafe { ethmac::EthernetDevice::new() };
net_device.reset();
// fn _net_trace_writer<U>(timestamp: u64, printer: smoltcp::wire::PrettyPrinter<U>) // fn _net_trace_writer<U>(timestamp: u64, printer: smoltcp::wire::PrettyPrinter<U>)
// where U: smoltcp::wire::pretty_print::PrettyPrint { // where U: smoltcp::wire::pretty_print::PrettyPrint {
// let seconds = timestamp / 1000; // let seconds = timestamp / 1000;
// let micros = timestamp % 1000 * 1000; // let micros = timestamp % 1000 * 1000;
// print!("\x1b[37m[{:6}.{:06}s]\n{}\x1b[0m\n", seconds, micros, printer) // print!("\x1b[37m[{:6}.{:06}s]\n{}\x1b[0m\n", seconds, micros, printer)
// } // }
let net_device = unsafe { ethmac::EthernetDevice::new() };
// let net_device = smoltcp::phy::EthernetTracer::new(net_device, _net_trace_writer); // let net_device = smoltcp::phy::EthernetTracer::new(net_device, _net_trace_writer);
let mut neighbor_cache_storage = [None; 8];
let mut neighbor_map = [None; 8];
let neighbor_cache = let neighbor_cache =
smoltcp::iface::NeighborCache::new(&mut neighbor_cache_storage[..]); smoltcp::iface::NeighborCache::new(&mut neighbor_map[..]);
let mut interface = let mut interface =
smoltcp::iface::EthernetInterfaceBuilder::new(net_device) smoltcp::iface::EthernetInterfaceBuilder::new(net_device)
.neighbor_cache(neighbor_cache) .neighbor_cache(neighbor_cache)