forked from M-Labs/zynq-rs
eth: recv_next()
This commit is contained in:
parent
f92ea3b99d
commit
81a892b618
@ -332,6 +332,12 @@ impl<RX, TX> Eth<RX, TX> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rx, TX> Eth<rx::DescList<'rx>, TX> {
|
||||
pub fn recv_next(&mut self) -> Option<&[u8]> {
|
||||
self.rx.recv_next()
|
||||
}
|
||||
}
|
||||
|
||||
impl<RX, TX> phy::PhyAccess for Eth<RX, TX> {
|
||||
fn read_phy(&mut self, addr: u8, reg: u8) -> u16 {
|
||||
self.wait_phy_idle();
|
||||
|
@ -39,6 +39,7 @@ pub const DESCS: usize = 8;
|
||||
pub struct DescList<'a> {
|
||||
list: [DescEntry; DESCS],
|
||||
buffers: [&'a mut [u8]; DESCS],
|
||||
next: usize,
|
||||
}
|
||||
|
||||
impl<'a> DescList<'a> {
|
||||
@ -59,6 +60,25 @@ impl<'a> DescList<'a> {
|
||||
);
|
||||
}
|
||||
|
||||
DescList { list, buffers }
|
||||
DescList {
|
||||
list, buffers,
|
||||
next: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recv_next(&mut self) -> Option<&[u8]> {
|
||||
if self.list[self.next].word0.read().used() {
|
||||
let len = self.list[self.next].word1
|
||||
.read().frame_length_lsbs()
|
||||
.into();
|
||||
let pkt = &self.buffers[self.next][0..len];
|
||||
self.next += 1;
|
||||
if self.next >= self.list.len() {
|
||||
self.next = 0;
|
||||
}
|
||||
Some(pkt)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,14 @@ fn main() {
|
||||
}
|
||||
let mut eth = eth.start_rx(rx_buffer_ptrs);
|
||||
|
||||
loop {}
|
||||
loop {
|
||||
match eth.recv_next() {
|
||||
None => {}
|
||||
Some(pkt) => {
|
||||
writeln!(uart, "eth: received {} bytes", pkt.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
panic!("End");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user