Compare commits
No commits in common. "a1a211334f7fe8ebaec46e5d307238fbf37ab4fd" and "cf17a1c60a667bcc68772224d2fa98f1cf3fceee" have entirely different histories.
a1a211334f
...
cf17a1c60a
|
@ -4,7 +4,7 @@
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use alloc::{borrow::ToOwned, collections::BTreeMap, format};
|
use alloc::{borrow::ToOwned, collections::BTreeMap, format};
|
||||||
use core::task::Poll;
|
use core::{mem::transmute, task::Poll};
|
||||||
use libasync::{
|
use libasync::{
|
||||||
delay,
|
delay,
|
||||||
smoltcp::{Sockets, TcpStream},
|
smoltcp::{Sockets, TcpStream},
|
||||||
|
@ -30,6 +30,7 @@ use libcortex_a9::{
|
||||||
};
|
};
|
||||||
use libregister::RegisterR;
|
use libregister::RegisterR;
|
||||||
use libsupport_zynq::{
|
use libsupport_zynq::{
|
||||||
|
alloc::{vec, vec::Vec},
|
||||||
boot, ram,
|
boot, ram,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
@ -180,11 +181,24 @@ pub fn main_core0() {
|
||||||
println!("Eth on");
|
println!("Eth on");
|
||||||
|
|
||||||
const RX_LEN: usize = 8;
|
const RX_LEN: usize = 8;
|
||||||
|
let mut rx_descs = (0..RX_LEN)
|
||||||
|
.map(|_| zynq::eth::rx::DescEntry::zeroed())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let mut rx_buffers = vec![zynq::eth::Buffer::new(); RX_LEN];
|
||||||
// Number of transmission buffers (minimum is two because with
|
// Number of transmission buffers (minimum is two because with
|
||||||
// one, duplicate packet transmission occurs)
|
// one, duplicate packet transmission occurs)
|
||||||
const TX_LEN: usize = 8;
|
const TX_LEN: usize = 8;
|
||||||
let eth = eth.start_rx(RX_LEN);
|
let mut tx_descs = (0..TX_LEN)
|
||||||
let mut eth = eth.start_tx(TX_LEN);
|
.map(|_| zynq::eth::tx::DescEntry::zeroed())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let mut tx_buffers = vec![zynq::eth::Buffer::new(); TX_LEN];
|
||||||
|
let eth = eth.start_rx(&mut rx_descs, &mut rx_buffers);
|
||||||
|
// let mut eth = eth.start_tx(&mut tx_descs, &mut tx_buffers);
|
||||||
|
let mut eth = eth.start_tx(
|
||||||
|
// HACK
|
||||||
|
unsafe { transmute(tx_descs.as_mut_slice()) },
|
||||||
|
unsafe { transmute(tx_buffers.as_mut_slice()) },
|
||||||
|
);
|
||||||
|
|
||||||
let ethernet_addr = EthernetAddress(HWADDR);
|
let ethernet_addr = EthernetAddress(HWADDR);
|
||||||
// IP stack
|
// IP stack
|
||||||
|
@ -233,7 +247,7 @@ pub fn main_core0() {
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let _ = stream.close().await;
|
let _ = stream.flush().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -263,9 +263,9 @@ impl<'r, RX, TX> Eth<'r, RX, TX> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_rx(self, rx_size: usize) -> Eth<'r, rx::DescList, TX> {
|
pub fn start_rx<'rx>(self, rx_list: &'rx mut [rx::DescEntry], rx_buffers: &'rx mut [Buffer]) -> Eth<'r, rx::DescList<'rx>, TX> {
|
||||||
let new_self = Eth {
|
let new_self = Eth {
|
||||||
rx: rx::DescList::new(rx_size),
|
rx: rx::DescList::new(rx_list, rx_buffers),
|
||||||
tx: self.tx,
|
tx: self.tx,
|
||||||
inner: self.inner,
|
inner: self.inner,
|
||||||
phy: self.phy,
|
phy: self.phy,
|
||||||
|
@ -282,10 +282,10 @@ impl<'r, RX, TX> Eth<'r, RX, TX> {
|
||||||
new_self
|
new_self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_tx(self, tx_size: usize) -> Eth<'r, RX, tx::DescList> {
|
pub fn start_tx<'tx>(self, tx_list: &'tx mut [tx::DescEntry], tx_buffers: &'tx mut [Buffer]) -> Eth<'r, RX, tx::DescList<'tx>> {
|
||||||
let new_self = Eth {
|
let new_self = Eth {
|
||||||
rx: self.rx,
|
rx: self.rx,
|
||||||
tx: tx::DescList::new(tx_size),
|
tx: tx::DescList::new(tx_list, tx_buffers),
|
||||||
inner: self.inner,
|
inner: self.inner,
|
||||||
phy: self.phy,
|
phy: self.phy,
|
||||||
};
|
};
|
||||||
|
@ -302,7 +302,7 @@ impl<'r, RX, TX> Eth<'r, RX, TX> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, TX> Eth<'r, rx::DescList, TX> {
|
impl<'r, 'rx, TX> Eth<'r, rx::DescList<'rx>, TX> {
|
||||||
pub fn recv_next<'s: 'p, 'p>(&'s mut self) -> Result<Option<rx::PktRef<'p>>, rx::Error> {
|
pub fn recv_next<'s: 'p, 'p>(&'s mut self) -> Result<Option<rx::PktRef<'p>>, rx::Error> {
|
||||||
let status = self.inner.regs.rx_status.read();
|
let status = self.inner.regs.rx_status.read();
|
||||||
if status.hresp_not_ok() {
|
if status.hresp_not_ok() {
|
||||||
|
@ -350,15 +350,15 @@ impl<'r, TX> Eth<'r, rx::DescList, TX> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, RX> Eth<'r, RX, tx::DescList> {
|
impl<'r, 'tx, RX> Eth<'r, RX, tx::DescList<'tx>> {
|
||||||
pub fn send<'s: 'p, 'p>(&'s mut self, length: usize) -> Option<tx::PktRef<'p>> {
|
pub fn send<'s: 'p, 'p>(&'s mut self, length: usize) -> Option<tx::PktRef<'p>> {
|
||||||
self.tx.send(self.inner.regs, length)
|
self.tx.send(self.inner.regs, length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, 'a> smoltcp::phy::Device<'a> for &mut Eth<'r, rx::DescList, tx::DescList> {
|
impl<'r, 'rx, 'tx: 'a, 'a> smoltcp::phy::Device<'a> for &mut Eth<'r, rx::DescList<'rx>, tx::DescList<'tx>> {
|
||||||
type RxToken = rx::PktRef<'a>;
|
type RxToken = rx::PktRef<'a>;
|
||||||
type TxToken = tx::Token<'a>;
|
type TxToken = tx::Token<'a, 'tx>;
|
||||||
|
|
||||||
fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities {
|
fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities {
|
||||||
use smoltcp::phy::{DeviceCapabilities, ChecksumCapabilities, Checksum};
|
use smoltcp::phy::{DeviceCapabilities, ChecksumCapabilities, Checksum};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use alloc::{vec, vec::Vec};
|
|
||||||
use libregister::*;
|
use libregister::*;
|
||||||
use super::Buffer;
|
use super::Buffer;
|
||||||
|
|
||||||
|
@ -54,18 +53,14 @@ register_bit!(desc_word1, multi_hash_match, 30);
|
||||||
register_bit!(desc_word1, global_broadcast, 31);
|
register_bit!(desc_word1, global_broadcast, 31);
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct DescList {
|
pub struct DescList<'a> {
|
||||||
list: Vec<DescEntry>,
|
list: &'a mut [DescEntry],
|
||||||
buffers: Vec<Buffer>,
|
buffers: &'a mut [Buffer],
|
||||||
next: usize,
|
next: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DescList {
|
impl<'a> DescList<'a> {
|
||||||
pub fn new(size: usize) -> Self {
|
pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [Buffer]) -> Self {
|
||||||
let mut list: Vec<_> = (0..size).map(|_| DescEntry::zeroed())
|
|
||||||
.collect();
|
|
||||||
let mut buffers = vec![Buffer::new(); size];
|
|
||||||
|
|
||||||
let last = list.len().min(buffers.len()) - 1;
|
let last = list.len().min(buffers.len()) - 1;
|
||||||
for (i, (entry, buffer)) in list.iter_mut().zip(buffers.iter_mut()).enumerate() {
|
for (i, (entry, buffer)) in list.iter_mut().zip(buffers.iter_mut()).enumerate() {
|
||||||
let is_last = i == last;
|
let is_last = i == last;
|
||||||
|
@ -83,7 +78,8 @@ impl DescList {
|
||||||
}
|
}
|
||||||
|
|
||||||
DescList {
|
DescList {
|
||||||
list,
|
// Shorten the list of descriptors to the required number.
|
||||||
|
list: &mut list[0..=last],
|
||||||
buffers,
|
buffers,
|
||||||
next: 0,
|
next: 0,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use alloc::{vec, vec::Vec};
|
|
||||||
use libregister::*;
|
use libregister::*;
|
||||||
use super::{Buffer, regs};
|
use super::{Buffer, regs};
|
||||||
|
|
||||||
|
@ -41,18 +40,14 @@ impl DescEntry {
|
||||||
pub const DESCS: usize = 8;
|
pub const DESCS: usize = 8;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct DescList {
|
pub struct DescList<'a> {
|
||||||
list: Vec<DescEntry>,
|
list: &'a mut [DescEntry],
|
||||||
buffers: Vec<Buffer>,
|
buffers: &'a mut [Buffer],
|
||||||
next: usize,
|
next: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DescList {
|
impl<'a> DescList<'a> {
|
||||||
pub fn new(size: usize) -> Self {
|
pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [Buffer]) -> Self {
|
||||||
let mut list: Vec<_> = (0..size).map(|_| DescEntry::zeroed())
|
|
||||||
.collect();
|
|
||||||
let mut buffers = vec![Buffer::new(); size];
|
|
||||||
|
|
||||||
let last = list.len().min(buffers.len()) - 1;
|
let last = list.len().min(buffers.len()) - 1;
|
||||||
// Sending seems to not work properly with only one packet
|
// Sending seems to not work properly with only one packet
|
||||||
// buffer (two duplicates get send with every packet), so
|
// buffer (two duplicates get send with every packet), so
|
||||||
|
@ -78,7 +73,8 @@ impl DescList {
|
||||||
}
|
}
|
||||||
|
|
||||||
DescList {
|
DescList {
|
||||||
list,
|
// Shorten the list of descriptors to the required number.
|
||||||
|
list: &mut list[0..=last],
|
||||||
buffers,
|
buffers,
|
||||||
next: 0,
|
next: 0,
|
||||||
}
|
}
|
||||||
|
@ -146,12 +142,12 @@ impl<'a> DerefMut for PktRef<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TxToken for smoltcp support
|
/// TxToken for smoltcp support
|
||||||
pub struct Token<'a> {
|
pub struct Token<'a, 'tx: 'a> {
|
||||||
pub regs: &'a mut regs::RegisterBlock,
|
pub regs: &'a mut regs::RegisterBlock,
|
||||||
pub desc_list: &'a mut DescList,
|
pub desc_list: &'a mut DescList<'tx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> smoltcp::phy::TxToken for Token<'a> {
|
impl<'a, 'tx: 'a> smoltcp::phy::TxToken for Token<'a, 'tx> {
|
||||||
fn consume<R, F>(self, _timestamp: smoltcp::time::Instant, len: usize, f: F) -> smoltcp::Result<R>
|
fn consume<R, F>(self, _timestamp: smoltcp::time::Instant, len: usize, f: F) -> smoltcp::Result<R>
|
||||||
where F: FnOnce(&mut [u8]) -> smoltcp::Result<R>
|
where F: FnOnce(&mut [u8]) -> smoltcp::Result<R>
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate alloc;
|
|
||||||
|
|
||||||
/// Re-export so that dependents can always use the same version
|
/// Re-export so that dependents can always use the same version
|
||||||
pub use smoltcp;
|
pub use smoltcp;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue