Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary use of atomic-polyfill. #1125

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
"rust-analyzer.checkOnSave.noDefaultFeatures": true,
"rust-analyzer.cargo.noDefaultFeatures": true,
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
//"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
"rust-analyzer.cargo.features": [
// These are needed to prevent embassy-net from failing to build
//"embassy-net/medium-ethernet",
//"embassy-net/tcp",
//"embassy-net/pool-16",
//"time-tick-16mhz",
//"defmt-timestamp-uptime",
"nightly",
//"nightly",
//"unstable-traits",
],
"rust-analyzer.linkedProjects": [
// Declare for the target you wish to develop
//"embassy-executor/Cargo.toml",
//"embassy-sync/Cargo.toml",
"examples/nrf/Cargo.toml",
//"examples/nrf/Cargo.toml",
// "examples/nrf-rtos-trace/Cargo.toml",
// "examples/rp/Cargo.toml",
// "examples/std/Cargo.toml",
// "examples/stm32f0/Cargo.toml",
// "examples/stm32f1/Cargo.toml",
//"examples/stm32f1/Cargo.toml",
// "examples/stm32f2/Cargo.toml",
// "examples/stm32f3/Cargo.toml",
// "examples/stm32f4/Cargo.toml",
Expand All @@ -35,7 +36,7 @@
// "examples/stm32l0/Cargo.toml",
// "examples/stm32l1/Cargo.toml",
// "examples/stm32l4/Cargo.toml",
// "examples/stm32l5/Cargo.toml",
"examples/stm32l5/Cargo.toml",
// "examples/stm32u5/Cargo.toml",
// "examples/stm32wb/Cargo.toml",
// "examples/stm32wb55/Cargo.toml",
Expand Down
3 changes: 1 addition & 2 deletions embassy-executor/src/arch/riscv32.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::marker::PhantomData;
use core::ptr;

use atomic_polyfill::{AtomicBool, Ordering};
use core::sync::atomic::{AtomicBool, Ordering};

use super::{raw, Spawner};

Expand Down
3 changes: 1 addition & 2 deletions embassy-executor/src/arch/xtensa.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::marker::PhantomData;
use core::ptr;

use atomic_polyfill::{AtomicBool, Ordering};
use core::sync::atomic::{AtomicBool, Ordering};

use super::{raw, Spawner};

Expand Down
1 change: 0 additions & 1 deletion embassy-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ generic-array = { version = "0.14.4", default-features = false }
stable_deref_trait = { version = "1.2.0", default-features = false }
futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
atomic-pool = "1.0"
atomic-polyfill = "1.0.1"
embedded-nal-async = { version = "0.3.0", optional = true }

[dependencies.smoltcp]
Expand Down
2 changes: 1 addition & 1 deletion embassy-net/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ pub mod client {
use core::cell::UnsafeCell;
use core::mem::MaybeUninit;
use core::ptr::NonNull;
use core::sync::atomic::{AtomicBool, Ordering};

use atomic_polyfill::{AtomicBool, Ordering};
use embedded_nal_async::IpAddr;

use super::*;
Expand Down
4 changes: 1 addition & 3 deletions embassy-rp/src/multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
//! ```

use core::mem::ManuallyDrop;
use core::sync::atomic::{compiler_fence, Ordering};

use atomic_polyfill::AtomicBool;
use core::sync::atomic::{compiler_fence, AtomicBool, Ordering};

use crate::interrupt::{Interrupt, InterruptExt};
use crate::peripherals::CORE1;
Expand Down
3 changes: 1 addition & 2 deletions embassy-rp/src/usb.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use core::future::poll_fn;
use core::marker::PhantomData;
use core::slice;
use core::sync::atomic::Ordering;
use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;

use atomic_polyfill::compiler_fence;
use embassy_hal_common::into_ref;
use embassy_sync::waitqueue::AtomicWaker;
use embassy_usb_driver as driver;
Expand Down
3 changes: 2 additions & 1 deletion embassy-stm32/src/adc/v4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use atomic_polyfill::{AtomicU8, Ordering};
use core::sync::atomic::{AtomicU8, Ordering};

use embedded_hal_02::blocking::delay::DelayUs;
use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel};
use pac::adccommon::vals::Presc;
Expand Down
3 changes: 1 addition & 2 deletions embassy-stm32/src/flash/f4.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::convert::TryInto;
use core::ptr::write_volatile;

use atomic_polyfill::{fence, Ordering};
use core::sync::atomic::{fence, Ordering};

use super::{ERASE_SIZE, FLASH_BASE, FLASH_SIZE};
use crate::flash::Error;
Expand Down
3 changes: 1 addition & 2 deletions embassy-stm32/src/flash/f7.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::convert::TryInto;
use core::ptr::write_volatile;

use atomic_polyfill::{fence, Ordering};
use core::sync::atomic::{fence, Ordering};

use crate::flash::Error;
use crate::pac;
Expand Down
4 changes: 2 additions & 2 deletions embassy-stm32/src/flash/h7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error

cortex_m::asm::isb();
cortex_m::asm::dsb();
atomic_polyfill::fence(atomic_polyfill::Ordering::SeqCst);
core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst);

let ret = {
let mut ret: Result<(), Error> = Ok(());
Expand Down Expand Up @@ -70,7 +70,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error

cortex_m::asm::isb();
cortex_m::asm::dsb();
atomic_polyfill::fence(atomic_polyfill::Ordering::SeqCst);
core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst);

ret
}
Expand Down
5 changes: 3 additions & 2 deletions embassy-stm32/src/i2c/v2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::cmp;
use core::future::poll_fn;
use core::sync::atomic::{AtomicUsize, Ordering};
use core::task::Poll;

use atomic_polyfill::{AtomicUsize, Ordering};
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{into_ref, PeripheralRef};
Expand Down Expand Up @@ -131,7 +131,8 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {

if isr.tcr() || isr.tc() {
let state = T::state();
state.chunks_transferred.fetch_add(1, Ordering::Relaxed);
let transferred = state.chunks_transferred.load(Ordering::Relaxed);
state.chunks_transferred.store(transferred + 1, Ordering::Relaxed);
state.waker.wake();
}
// The flag can only be cleared by writting to nbytes, we won't do that here, so disable
Expand Down
2 changes: 1 addition & 1 deletion embassy-stm32/src/usart/buffered.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::cell::RefCell;
use core::future::poll_fn;
use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;

use atomic_polyfill::{compiler_fence, Ordering};
use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
use embassy_hal_common::ring_buffer::RingBuffer;
use embassy_sync::waitqueue::WakerRegistration;
Expand Down
2 changes: 1 addition & 1 deletion embassy-stm32/src/usart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use core::future::poll_fn;
use core::marker::PhantomData;
use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;

use atomic_polyfill::{compiler_fence, Ordering};
use embassy_cortex_m::interrupt::InterruptExt;
use embassy_futures::select::{select, Either};
use embassy_hal_common::drop::OnDrop;
Expand Down
66 changes: 33 additions & 33 deletions embassy-stm32/src/usb/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use core::future::poll_fn;
use core::marker::PhantomData;
use core::sync::atomic::Ordering;
use core::sync::atomic::{AtomicBool, Ordering};
use core::task::Poll;

use atomic_polyfill::{AtomicBool, AtomicU8};
use embassy_hal_common::into_ref;
use embassy_sync::waitqueue::AtomicWaker;
use embassy_time::{block_for, Duration};
Expand Down Expand Up @@ -35,10 +34,9 @@ static BUS_WAKER: AtomicWaker = NEW_AW;
static EP0_SETUP: AtomicBool = AtomicBool::new(false);
static EP_IN_WAKERS: [AtomicWaker; EP_COUNT] = [NEW_AW; EP_COUNT];
static EP_OUT_WAKERS: [AtomicWaker; EP_COUNT] = [NEW_AW; EP_COUNT];
static IRQ_FLAGS: AtomicU8 = AtomicU8::new(0);
const IRQ_FLAG_RESET: u8 = 0x01;
const IRQ_FLAG_SUSPEND: u8 = 0x02;
const IRQ_FLAG_RESUME: u8 = 0x04;
static IRQ_RESET: AtomicBool = AtomicBool::new(false);
static IRQ_SUSPEND: AtomicBool = AtomicBool::new(false);
static IRQ_RESUME: AtomicBool = AtomicBool::new(false);

fn convert_type(t: EndpointType) -> EpType {
match t {
Expand Down Expand Up @@ -184,47 +182,51 @@ impl<'d, T: Instance> Driver<'d, T> {

let istr = regs.istr().read();

let mut flags: u8 = 0;

if istr.susp() {
//trace!("USB IRQ: susp");
flags |= IRQ_FLAG_SUSPEND;
IRQ_SUSPEND.store(true, Ordering::Relaxed);
regs.cntr().modify(|w| {
w.set_fsusp(true);
w.set_lpmode(true);
})
});

// Write 0 to clear.
let mut clear = regs::Istr(!0);
clear.set_susp(false);
regs.istr().write_value(clear);

// Wake main thread.
BUS_WAKER.wake();
}

if istr.wkup() {
//trace!("USB IRQ: wkup");
flags |= IRQ_FLAG_RESUME;
IRQ_RESUME.store(true, Ordering::Relaxed);
regs.cntr().modify(|w| {
w.set_fsusp(false);
w.set_lpmode(false);
})
});

// Write 0 to clear.
let mut clear = regs::Istr(!0);
clear.set_wkup(false);
regs.istr().write_value(clear);

// Wake main thread.
BUS_WAKER.wake();
}

if istr.reset() {
//trace!("USB IRQ: reset");
flags |= IRQ_FLAG_RESET;
IRQ_RESET.store(true, Ordering::Relaxed);

// Write 0 to clear.
let mut clear = regs::Istr(!0);
clear.set_reset(false);
regs.istr().write_value(clear);
}

if flags != 0 {
// Send irqs to main thread.
IRQ_FLAGS.fetch_or(flags, Ordering::AcqRel);
// Wake main thread.
BUS_WAKER.wake();

// Clear them
let mut mask = regs::Istr(0);
mask.set_wkup(true);
mask.set_susp(true);
mask.set_reset(true);
regs.istr().write_value(regs::Istr(!(istr.0 & mask.0)));
}

if istr.ctr() {
Expand Down Expand Up @@ -436,17 +438,15 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
if self.inited {
let regs = T::regs();

let flags = IRQ_FLAGS.load(Ordering::Acquire);

if flags & IRQ_FLAG_RESUME != 0 {
IRQ_FLAGS.fetch_and(!IRQ_FLAG_RESUME, Ordering::AcqRel);
if IRQ_RESUME.load(Ordering::Acquire) {
IRQ_RESUME.store(false, Ordering::Relaxed);
return Poll::Ready(Event::Resume);
}

if flags & IRQ_FLAG_RESET != 0 {
IRQ_FLAGS.fetch_and(!IRQ_FLAG_RESET, Ordering::AcqRel);
if IRQ_RESET.load(Ordering::Acquire) {
IRQ_RESET.store(false, Ordering::Relaxed);

trace!("RESET REGS WRITINGINGING");
trace!("RESET");
regs.daddr().write(|w| {
w.set_ef(true);
w.set_add(0);
Expand Down Expand Up @@ -475,8 +475,8 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
return Poll::Ready(Event::Reset);
}

if flags & IRQ_FLAG_SUSPEND != 0 {
IRQ_FLAGS.fetch_and(!IRQ_FLAG_SUSPEND, Ordering::AcqRel);
if IRQ_SUSPEND.load(Ordering::Acquire) {
IRQ_SUSPEND.store(false, Ordering::Relaxed);
return Poll::Ready(Event::Suspend);
}

Expand Down
1 change: 0 additions & 1 deletion embassy-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ defmt = { version = "0.3", optional = true }
log = { version = "0.4.14", optional = true }

futures-util = { version = "0.3.17", default-features = false }
atomic-polyfill = "1.0.1"
critical-section = "1.1"
heapless = "0.7.5"
cfg-if = "1.0.0"
Expand Down