continue driver impl
Some checks failed
ci / Check build (push) Has been cancelled
ci / Check formatting (push) Has been cancelled
ci / Check Documentation Build (push) Has been cancelled
ci / Clippy (push) Has been cancelled
ci / Check build (pull_request) Has been cancelled
ci / Check formatting (pull_request) Has been cancelled
ci / Check Documentation Build (pull_request) Has been cancelled
ci / Clippy (pull_request) Has been cancelled
Some checks failed
ci / Check build (push) Has been cancelled
ci / Check formatting (push) Has been cancelled
ci / Check Documentation Build (push) Has been cancelled
ci / Clippy (push) Has been cancelled
ci / Check build (pull_request) Has been cancelled
ci / Check formatting (pull_request) Has been cancelled
ci / Check Documentation Build (pull_request) Has been cancelled
ci / Clippy (pull_request) Has been cancelled
This commit is contained in:
@@ -35,6 +35,7 @@ critical-section = "1"
|
|||||||
libm = "0.2"
|
libm = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
embassy-sync = "0.6"
|
embassy-sync = "0.6"
|
||||||
|
embassy-net = { path = "../../../Rust/embassy/embassy-net", version = "0.7" }
|
||||||
raw-slicee = "0.1"
|
raw-slicee = "0.1"
|
||||||
embedded-io-async = "0.6"
|
embedded-io-async = "0.6"
|
||||||
|
|
||||||
|
|||||||
106
zynq7000-hal/src/eth/embassy_net.rs
Normal file
106
zynq7000-hal/src/eth/embassy_net.rs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
use embassy_sync::waitqueue::AtomicWaker;
|
||||||
|
|
||||||
|
pub use super::rx_descr;
|
||||||
|
pub use super::tx_descr;
|
||||||
|
|
||||||
|
static TX_WAKER: AtomicWaker = AtomicWaker::new();
|
||||||
|
static RX_WAKER: AtomicWaker = AtomicWaker::new();
|
||||||
|
|
||||||
|
pub struct EthernetEmbassyNet {
|
||||||
|
pub eth: super::Ethernet,
|
||||||
|
pub burst_size: usize,
|
||||||
|
pub mac_addr: [u8; 6],
|
||||||
|
pub rx_descr: &'static [rx_descr::Descriptor],
|
||||||
|
pub rx_index: usize,
|
||||||
|
pub tx_descr: &'static [tx_descr::Descriptor],
|
||||||
|
pub tx_index: usize,
|
||||||
|
pub link_state: embassy_net::driver::LinkState,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct EmbassyNetRxToken {
|
||||||
|
rx_descr_ref: rx_descr::DescriptorList<'static>,
|
||||||
|
rx_index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl embassy_net::driver::RxToken for EmbassyNetRxToken {
|
||||||
|
fn consume<R, F>(self, f: F) -> R
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut [u8]) -> R,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct EmbassyNetTxToken {
|
||||||
|
tx_descr_ref: tx_descr::DescriptorListRef<'static>,
|
||||||
|
tx_index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl embassy_net::driver::TxToken for EmbassyNetRxToken {
|
||||||
|
fn consume<R, F>(self, len: usize, f: F) -> R
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut [u8]) -> R,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EthernetEmbassyNet {
|
||||||
|
#[inline]
|
||||||
|
pub fn update_link_state(&mut self, link_state: embassy_net::driver::LinkState) {
|
||||||
|
self.link_state = link_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_link_state_up(&mut self) {
|
||||||
|
self.update_link_state(embassy_net::driver::LinkState::Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_link_state_down(&mut self) {
|
||||||
|
self.update_link_state(embassy_net::driver::LinkState::Down);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl embassy_net::Driver for EthernetEmbassyNet {
|
||||||
|
type RxToken<'a>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
= EmbassyNetRxToken;
|
||||||
|
|
||||||
|
type TxToken<'a>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
= EmbassyNetTxToken;
|
||||||
|
|
||||||
|
fn receive(
|
||||||
|
&mut self,
|
||||||
|
cx: &mut core::task::Context,
|
||||||
|
) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
|
||||||
|
RX_WAKER.register(cx.waker());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn transmit(&mut self, cx: &mut core::task::Context) -> Option<Self::TxToken<'_>> {
|
||||||
|
TX_WAKER.register(cx.waker());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn link_state(&mut self, cx: &mut core::task::Context) -> embassy_net::driver::LinkState {
|
||||||
|
self.link_state
|
||||||
|
}
|
||||||
|
|
||||||
|
fn capabilities(&self) -> embassy_net::driver::Capabilities {
|
||||||
|
embassy_net::driver::Capabilities {
|
||||||
|
max_transmission_unit: super::MTU,
|
||||||
|
max_burst_size: Some(self.burst_size),
|
||||||
|
checksum: embassy_net::driver::ChecksumCapabilities {
|
||||||
|
ipv4: true,
|
||||||
|
udp: true,
|
||||||
|
tcp: true,
|
||||||
|
icmpv4: true,
|
||||||
|
icmpv6: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hardware_address(&self) -> embassy_net::driver::HardwareAddress {
|
||||||
|
embassy_net::driver::HardwareAddress::Ethernet(self.mac_addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
use arbitrary_int::{u2, u3};
|
use arbitrary_int::{u2, u3};
|
||||||
pub use zynq7000::eth::MdcClkDiv;
|
pub use zynq7000::eth::MdcClkDiv;
|
||||||
use zynq7000::eth::{
|
use zynq7000::eth::{
|
||||||
BurstLength, DmaRxBufSize, MmioEthernet, SpeedMode, GEM_0_BASE_ADDR,
|
BurstLength, DmaRxBufSize, MmioEthernet, SpeedMode, GEM_0_BASE_ADDR, GEM_1_BASE_ADDR,
|
||||||
GEM_1_BASE_ADDR,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use ll::{ClkConfig, EthernetLowLevel, Speed};
|
pub use ll::{ClkConfig, EthernetLowLevel, Speed};
|
||||||
@@ -11,6 +10,7 @@ pub mod ll;
|
|||||||
pub mod mdio;
|
pub mod mdio;
|
||||||
pub mod rx_descr;
|
pub mod rx_descr;
|
||||||
pub mod tx_descr;
|
pub mod tx_descr;
|
||||||
|
pub mod embassy_net;
|
||||||
|
|
||||||
pub const MTU: usize = 1536;
|
pub const MTU: usize = 1536;
|
||||||
pub const MAX_MDC_SPEED: Hertz = Hertz::from_raw(2_500_000);
|
pub const MAX_MDC_SPEED: Hertz = Hertz::from_raw(2_500_000);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! RX buffer descriptor module.
|
//! RX buffer descriptor module.
|
||||||
pub use super::shared::Ownership;
|
pub use super::shared::Ownership;
|
||||||
use arbitrary_int::{u2, u3, u13, u30};
|
use arbitrary_int::{u13, u2, u3, u30};
|
||||||
|
|
||||||
/// RX buffer descriptor.
|
/// RX buffer descriptor.
|
||||||
///
|
///
|
||||||
@@ -86,6 +86,11 @@ impl Descriptor {
|
|||||||
self.word0.set_ownership(ownership);
|
self.word0.set_ownership(ownership);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn ownership(&self) -> Ownership {
|
||||||
|
self.word0.ownership()
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_wrap_bit(&mut self) {
|
pub fn set_wrap_bit(&mut self) {
|
||||||
self.word0.set_wrap(true);
|
self.word0.set_wrap(true);
|
||||||
@@ -104,19 +109,28 @@ impl Default for Descriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DescriptorListRef<'a>(&'a mut [Descriptor]);
|
pub struct DescriptorList<'a> {
|
||||||
|
list: &'a mut [Descriptor],
|
||||||
|
idx: usize,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> DescriptorListRef<'a> {
|
impl<'a> DescriptorList<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(descriptor: &'a mut [Descriptor]) -> Self {
|
pub fn new(descr_list: &'a mut [Descriptor]) -> Option<Self> {
|
||||||
Self(descriptor)
|
if descr_list.len() == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(Self {
|
||||||
|
list: descr_list,
|
||||||
|
idx: 0,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DescriptorListRef<'_> {
|
impl DescriptorList<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn base_ptr(&self) -> *const Descriptor {
|
pub fn base_ptr(&self) -> *const Descriptor {
|
||||||
self.0.as_ptr()
|
self.list.as_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -125,13 +139,15 @@ impl DescriptorListRef<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&mut self) {
|
pub fn init(&mut self) {
|
||||||
for desc in self.0.iter_mut() {
|
self.idx = 0;
|
||||||
|
for desc in self.list.iter_mut() {
|
||||||
desc.set_ownership(Ownership::Hardware);
|
desc.set_ownership(Ownership::Hardware);
|
||||||
}
|
}
|
||||||
self.0.last_mut().unwrap().set_wrap_bit();
|
self.list.last_mut().unwrap().set_wrap_bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_rx_buf_address(&mut self, index: usize, addr: u32) {
|
#[inline]
|
||||||
self.0[index].write_rx_addr(addr);
|
pub fn set_rx_buf_address(&mut self, index: usize, buf: &[u8]) {
|
||||||
|
self.list[index].write_rx_addr(addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user