forked from M-Labs/zynq-rs
Compare commits
No commits in common. "e73ec731aa7da805434ebed9b1e5e323148ea0e0" and "bb09d253784639e6f783118ee1c5e3666bcd6468" have entirely different histories.
e73ec731aa
...
bb09d25378
@ -81,14 +81,7 @@ impl Sockets {
|
|||||||
/// TODO: this was called through eg. TcpStream, another poll()
|
/// TODO: this was called through eg. TcpStream, another poll()
|
||||||
/// might want to send packets before sleeping for an interrupt.
|
/// might want to send packets before sleeping for an interrupt.
|
||||||
pub(crate) fn register_waker(waker: Waker) {
|
pub(crate) fn register_waker(waker: Waker) {
|
||||||
let mut wakers = Self::instance().wakers.borrow_mut();
|
Self::instance().wakers.borrow_mut()
|
||||||
for (i, w) in wakers.iter().enumerate() {
|
.push(waker);
|
||||||
if w.will_wake(&waker) {
|
|
||||||
let last = wakers.len() - 1;
|
|
||||||
wakers.swap(i, last);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wakers.push(waker);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ edition = "2018"
|
|||||||
[features]
|
[features]
|
||||||
target_zc706 = []
|
target_zc706 = []
|
||||||
target_cora_z7_10 = []
|
target_cora_z7_10 = []
|
||||||
ipv6 = [ "smoltcp/proto-ipv6" ]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
volatile-register = "0.2"
|
volatile-register = "0.2"
|
||||||
@ -22,5 +21,5 @@ libcortex_a9 = { path = "../libcortex_a9" }
|
|||||||
|
|
||||||
[dependencies.smoltcp]
|
[dependencies.smoltcp]
|
||||||
version = "0.6"
|
version = "0.6"
|
||||||
features = ["ethernet", "proto-ipv4", "socket-tcp"]
|
features = ["ethernet", "proto-ipv4", "proto-ipv6", "socket-tcp"]
|
||||||
default-features = false
|
default-features = false
|
||||||
|
@ -132,8 +132,10 @@ impl<'a> Drop for PktRef<'a> {
|
|||||||
dcc_slice(self.buffer);
|
dcc_slice(self.buffer);
|
||||||
|
|
||||||
self.entry.word1.modify(|_, w| w.used(false));
|
self.entry.word1.modify(|_, w| w.used(false));
|
||||||
// Start the TX engine
|
if ! self.regs.tx_status.read().tx_go() {
|
||||||
self.regs.net_ctrl.modify(|_, w| w.start_tx(true));
|
// Start TX if not already running
|
||||||
|
self.regs.net_ctrl.modify(|_, w| w.start_tx(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +166,10 @@ impl<'a> smoltcp::phy::TxToken for Token<'a> {
|
|||||||
None =>
|
None =>
|
||||||
Err(smoltcp::Error::Exhausted),
|
Err(smoltcp::Error::Exhausted),
|
||||||
Some(mut pktref) => {
|
Some(mut pktref) => {
|
||||||
f(pktref.deref_mut())
|
let result = f(pktref.deref_mut());
|
||||||
|
// TODO: on result.is_err() don;t send
|
||||||
|
drop(pktref);
|
||||||
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
|
|||||||
use core::cell::UnsafeCell;
|
use core::cell::UnsafeCell;
|
||||||
use super::{
|
use super::{
|
||||||
spin_lock_yield, notify_spin_lock,
|
spin_lock_yield, notify_spin_lock,
|
||||||
asm::{enter_critical, exit_critical}
|
asm::{dmb, enter_critical, exit_critical}
|
||||||
};
|
};
|
||||||
|
|
||||||
const LOCKED: u32 = 1;
|
const LOCKED: u32 = 1;
|
||||||
@ -32,27 +32,30 @@ impl<T> Mutex<T> {
|
|||||||
/// Lock the Mutex, blocks when already locked
|
/// Lock the Mutex, blocks when already locked
|
||||||
pub fn lock(&self) -> MutexGuard<T> {
|
pub fn lock(&self) -> MutexGuard<T> {
|
||||||
let mut irq = unsafe { enter_critical() };
|
let mut irq = unsafe { enter_critical() };
|
||||||
while self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::AcqRel) != UNLOCKED {
|
while self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::Acquire) != UNLOCKED {
|
||||||
unsafe {
|
unsafe {
|
||||||
exit_critical(irq);
|
exit_critical(irq);
|
||||||
spin_lock_yield();
|
spin_lock_yield();
|
||||||
irq = enter_critical();
|
irq = enter_critical();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dmb();
|
||||||
MutexGuard { mutex: self, irq }
|
MutexGuard { mutex: self, irq }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_lock(&self) -> Option<MutexGuard<T>> {
|
pub fn try_lock(&self) -> Option<MutexGuard<T>> {
|
||||||
let irq = unsafe { enter_critical() };
|
let irq = unsafe { enter_critical() };
|
||||||
if self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::AcqRel) != UNLOCKED {
|
if self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::Acquire) != UNLOCKED {
|
||||||
unsafe { exit_critical(irq) };
|
unsafe { exit_critical(irq) };
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
dmb();
|
||||||
Some(MutexGuard { mutex: self, irq })
|
Some(MutexGuard { mutex: self, irq })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unlock(&self) {
|
fn unlock(&self) {
|
||||||
|
dmb();
|
||||||
self.locked.store(UNLOCKED, Ordering::Release);
|
self.locked.store(UNLOCKED, Ordering::Release);
|
||||||
|
|
||||||
notify_spin_lock();
|
notify_spin_lock();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use core::{
|
use core::{
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
future::Future,
|
future::Future,
|
||||||
|
ptr::drop_in_place,
|
||||||
sync::atomic::{AtomicPtr, AtomicUsize, Ordering},
|
sync::atomic::{AtomicPtr, AtomicUsize, Ordering},
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
@ -37,7 +38,7 @@ impl<'a, T> Sender<'a, T> where T: Clone {
|
|||||||
notify_spin_lock();
|
notify_spin_lock();
|
||||||
if !prev.is_null() {
|
if !prev.is_null() {
|
||||||
unsafe {
|
unsafe {
|
||||||
Box::from_raw(prev);
|
drop_in_place(prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -91,7 +92,7 @@ impl<'a, T> Sender<'a, T> where T: Clone {
|
|||||||
for v in self.list.iter() {
|
for v in self.list.iter() {
|
||||||
let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed);
|
let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed);
|
||||||
if !original.is_null() {
|
if !original.is_null() {
|
||||||
Box::from_raw(original);
|
drop_in_place(original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user