1
0
Fork 0

eth: recv_next()

This commit is contained in:
Astro 2019-06-10 02:44:29 +02:00
parent f92ea3b99d
commit 81a892b618
3 changed files with 35 additions and 2 deletions

View File

@ -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();

View File

@ -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
}
}
}

View File

@ -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");
}