forked from M-Labs/zynq-rs
1
0
Fork 0

eth: start_tx

This commit is contained in:
Astro 2019-06-09 20:28:33 +02:00
parent f07a541c99
commit f92ea3b99d
2 changed files with 45 additions and 0 deletions

View File

@ -312,6 +312,21 @@ impl<RX, TX> Eth<RX, TX> {
new_self new_self
} }
pub fn start_tx<'tx>(self, tx_buffers: [&'tx [u8]; tx::DESCS]) -> Eth<RX, tx::DescList<'tx>> {
let new_self = Eth {
regs: self.regs,
rx: self.rx,
tx: tx::DescList::new(tx_buffers),
};
let list_addr = &new_self.tx as *const _ as u32;
assert!(list_addr & 0b11 == 0);
new_self.regs.tx_qbar.write(
regs::TxQbar::zeroed()
.tx_q_baseaddr(list_addr >> 2)
);
new_self
}
fn wait_phy_idle(&self) { fn wait_phy_idle(&self) {
while !self.regs.net_status.read().phy_mgmt_idle() {} while !self.regs.net_status.read().phy_mgmt_idle() {}
} }

View File

@ -1,3 +1,4 @@
use core::mem::uninitialized;
use crate::{register, register_bit, register_bits, register_bits_typed, regs::*}; use crate::{register, register_bit, register_bits, register_bits_typed, regs::*};
/// Descriptor entry /// Descriptor entry
@ -21,3 +22,32 @@ register_bit!(desc_word1, retry_limit_exceeded, 29);
register_bit!(desc_word1, wrap, 30); register_bit!(desc_word1, wrap, 30);
/// true if owned by software, false if owned by hardware /// true if owned by software, false if owned by hardware
register_bit!(desc_word1, used, 31); register_bit!(desc_word1, used, 31);
/// Number of descriptors
pub const DESCS: usize = 8;
#[repr(C)]
pub struct DescList<'a> {
list: [DescEntry; DESCS],
buffers: [&'a [u8]; DESCS],
}
impl<'a> DescList<'a> {
pub fn new(buffers: [&'a [u8]; DESCS]) -> Self {
let mut list: [DescEntry; DESCS] = unsafe { uninitialized() };
for i in 0..DESCS {
let buffer_addr = &buffers[i][0] as *const _ as u32;
list[i].word0.write(
DescWord0::zeroed()
.address(buffer_addr)
);
list[i].word1.write(
DescWord1::zeroed()
.used(true)
.wrap(i == DESCS - 1)
);
}
DescList { list, buffers }
}
}