2019-05-08 01:28:33 +08:00
|
|
|
use crate::regs::*;
|
|
|
|
|
|
|
|
mod regs;
|
|
|
|
|
|
|
|
pub struct Eth {
|
2019-05-24 00:01:18 +08:00
|
|
|
regs: &'static mut regs::RegisterBlock,
|
2019-05-08 01:28:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Eth {
|
|
|
|
pub fn gem0() -> Self {
|
2019-05-24 05:18:17 +08:00
|
|
|
let regs = regs::RegisterBlock::gem0();
|
2019-05-08 01:28:33 +08:00
|
|
|
Eth { regs }.init()
|
|
|
|
}
|
2019-05-24 05:18:17 +08:00
|
|
|
|
2019-05-08 01:28:33 +08:00
|
|
|
pub fn gem1() -> Self {
|
2019-05-24 05:18:17 +08:00
|
|
|
let regs = regs::RegisterBlock::gem1();
|
2019-05-08 01:28:33 +08:00
|
|
|
Eth { regs }.init()
|
|
|
|
}
|
2019-05-24 05:18:17 +08:00
|
|
|
|
2019-05-08 01:28:33 +08:00
|
|
|
fn init(self) -> Self {
|
|
|
|
// Clear the Network Control register.
|
|
|
|
self.regs.net_ctrl.write(regs::NetCtrl::zeroed());
|
|
|
|
self.regs.net_ctrl.write(regs::NetCtrl::zeroed().clear_stat_regs(true));
|
|
|
|
// Clear the Status registers.
|
|
|
|
self.regs.rx_status.write(
|
|
|
|
regs::RxStatus::zeroed()
|
|
|
|
.buffer_not_avail(true)
|
|
|
|
.frame_recd(true)
|
|
|
|
.rx_overrun(true)
|
|
|
|
.hresp_not_ok(true)
|
|
|
|
);
|
|
|
|
self.regs.tx_status.write(
|
|
|
|
regs::TxStatus::zeroed()
|
|
|
|
.used_bit_read(true)
|
|
|
|
.collision(true)
|
|
|
|
.retry_limit_exceeded(true)
|
|
|
|
.tx_go(true)
|
|
|
|
.tx_corr_ahb_err(true)
|
|
|
|
.tx_complete(true)
|
|
|
|
.tx_under_run(true)
|
|
|
|
.late_collision(true)
|
2019-05-24 05:18:17 +08:00
|
|
|
// not in the manual:
|
2019-05-08 01:28:33 +08:00
|
|
|
.hresp_not_ok(true)
|
|
|
|
);
|
|
|
|
// Disable all interrupts.
|
|
|
|
self.regs.intr_dis.write(
|
|
|
|
regs::IntrDis::zeroed()
|
|
|
|
.mgmt_done(true)
|
|
|
|
.rx_complete(true)
|
|
|
|
.rx_used_read(true)
|
|
|
|
.tx_used_read(true)
|
|
|
|
.tx_underrun(true)
|
|
|
|
.retry_ex_late_collisn(true)
|
|
|
|
.tx_corrupt_ahb_err(true)
|
|
|
|
.tx_complete(true)
|
|
|
|
.link_chng(true)
|
|
|
|
.rx_overrun(true)
|
|
|
|
.hresp_not_ok(true)
|
|
|
|
.pause_nonzeroq(true)
|
|
|
|
.pause_zero(true)
|
|
|
|
.pause_tx(true)
|
|
|
|
.ex_intr(true)
|
|
|
|
.autoneg_complete(true)
|
|
|
|
.partner_pg_rx(true)
|
|
|
|
.delay_req_rx(true)
|
|
|
|
.sync_rx(true)
|
|
|
|
.delay_req_tx(true)
|
|
|
|
.sync_tx(true)
|
|
|
|
.pdelay_req_rx(true)
|
|
|
|
.pdelay_resp_rx(true)
|
|
|
|
.pdelay_req_tx(true)
|
|
|
|
.pdelay_resp_tx(true)
|
|
|
|
.tsu_sec_incr(true)
|
|
|
|
);
|
|
|
|
// Clear the buffer queues.
|
|
|
|
self.regs.rx_qbar.write(
|
|
|
|
regs::RxQbar::zeroed()
|
|
|
|
);
|
|
|
|
self.regs.tx_qbar.write(
|
|
|
|
regs::TxQbar::zeroed()
|
|
|
|
);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|