Merge pull request #48 from akiles/thumbv6m
thumbv6m support with emulated atomics
This commit is contained in:
commit
030b0441f0
3
.github/workflows/rust.yml
vendored
3
.github/workflows/rust.yml
vendored
@ -18,8 +18,9 @@ jobs:
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
target: thumbv7em-none-eabi
|
||||
components: rust-src
|
||||
override: true
|
||||
- name: install
|
||||
run: rustup target add thumbv7em-none-eabi thumbv6m-none-eabi
|
||||
- name: Build
|
||||
run: ./ci.sh
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -4,6 +4,8 @@
|
||||
"rust-analyzer.cargo.allFeatures": false,
|
||||
"rust-analyzer.checkOnSave.allFeatures": false,
|
||||
"rust-analyzer.checkOnSave.allTargets": false,
|
||||
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
|
||||
"rust-analyzer.checkOnSave.target": "thumbv6m-none-eabi",
|
||||
"rust-analyzer.procMacro.enable": true,
|
||||
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
|
||||
"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
|
||||
|
1
ci.sh
1
ci.sh
@ -9,6 +9,7 @@ set -euxo pipefail
|
||||
(cd embassy; cargo build --target thumbv7em-none-eabi)
|
||||
(cd embassy; cargo build --target thumbv7em-none-eabi --features log)
|
||||
(cd embassy; cargo build --target thumbv7em-none-eabi --features defmt)
|
||||
(cd embassy; cargo build --target thumbv6m-none-eabi --features defmt)
|
||||
|
||||
# embassy-nrf
|
||||
|
||||
|
@ -157,17 +157,17 @@ pub fn interrupt_take(item: TokenStream) -> TokenStream {
|
||||
static HANDLER: ::embassy::interrupt::Handler;
|
||||
}
|
||||
|
||||
let func = HANDLER.func.load(::core::sync::atomic::Ordering::Acquire);
|
||||
let ctx = HANDLER.ctx.load(::core::sync::atomic::Ordering::Acquire);
|
||||
let func = HANDLER.func.load(::embassy::atomic::Ordering::Acquire);
|
||||
let ctx = HANDLER.ctx.load(::embassy::atomic::Ordering::Acquire);
|
||||
if !func.is_null() {
|
||||
let func: fn(*mut ()) = ::core::mem::transmute(func);
|
||||
func(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
static TAKEN: ::core::sync::atomic::AtomicBool = ::core::sync::atomic::AtomicBool::new(false);
|
||||
static TAKEN: ::embassy::atomic::AtomicBool = ::embassy::atomic::AtomicBool::new(false);
|
||||
|
||||
if TAKEN.compare_exchange(false, true, ::core::sync::atomic::Ordering::AcqRel, ::core::sync::atomic::Ordering::Acquire).is_err() {
|
||||
if TAKEN.compare_exchange(false, true, ::embassy::atomic::Ordering::AcqRel, ::embassy::atomic::Ordering::Acquire).is_err() {
|
||||
panic!("IRQ Already taken");
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,9 @@ defmt = { version = "0.2.0", optional = true }
|
||||
log = { version = "0.4.11", optional = true }
|
||||
|
||||
cortex-m = "0.7.1"
|
||||
futures = { version = "0.3.5", default-features = false }
|
||||
futures = { version = "0.3.5", default-features = false, features = [ "cfg-target-has-atomic", "unstable" ] }
|
||||
pin-project = { version = "1.0.2", default-features = false }
|
||||
embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
|
||||
embassy-traits = { version = "0.1.0", path = "../embassy-traits"}
|
||||
atomic-polyfill = { version = "0.1.0" }
|
||||
|
||||
|
29
embassy/build.rs
Normal file
29
embassy/build.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let target = env::var("TARGET").unwrap();
|
||||
|
||||
if target.starts_with("thumbv6m-") {
|
||||
println!("cargo:rustc-cfg=cortex_m");
|
||||
println!("cargo:rustc-cfg=armv6m");
|
||||
} else if target.starts_with("thumbv7m-") {
|
||||
println!("cargo:rustc-cfg=cortex_m");
|
||||
println!("cargo:rustc-cfg=armv7m");
|
||||
} else if target.starts_with("thumbv7em-") {
|
||||
println!("cargo:rustc-cfg=cortex_m");
|
||||
println!("cargo:rustc-cfg=armv7m");
|
||||
println!("cargo:rustc-cfg=armv7em"); // (not currently used)
|
||||
} else if target.starts_with("thumbv8m.base") {
|
||||
println!("cargo:rustc-cfg=cortex_m");
|
||||
println!("cargo:rustc-cfg=armv8m");
|
||||
println!("cargo:rustc-cfg=armv8m_base");
|
||||
} else if target.starts_with("thumbv8m.main") {
|
||||
println!("cargo:rustc-cfg=cortex_m");
|
||||
println!("cargo:rustc-cfg=armv8m");
|
||||
println!("cargo:rustc-cfg=armv8m_main");
|
||||
}
|
||||
|
||||
if target.ends_with("-eabihf") {
|
||||
println!("cargo:rustc-cfg=has_fpu");
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
use core::pin::Pin;
|
||||
use core::ptr::NonNull;
|
||||
use core::sync::atomic::Ordering;
|
||||
use core::task::{Context, Poll};
|
||||
use core::{mem, ptr};
|
||||
|
||||
@ -16,6 +15,7 @@ mod util;
|
||||
mod waker;
|
||||
|
||||
use self::util::UninitCell;
|
||||
use crate::atomic::Ordering;
|
||||
use crate::fmt::panic;
|
||||
use crate::interrupt::{Interrupt, InterruptExt};
|
||||
use crate::time::Alarm;
|
||||
|
@ -3,13 +3,13 @@ use core::cmp::min;
|
||||
use core::marker::PhantomData;
|
||||
use core::ptr;
|
||||
use core::ptr::NonNull;
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use core::task::Waker;
|
||||
|
||||
use super::run_queue::{RunQueue, RunQueueItem};
|
||||
use super::timer_queue::{TimerQueue, TimerQueueItem};
|
||||
use super::util::UninitCell;
|
||||
use super::waker;
|
||||
use crate::atomic::{AtomicU32, Ordering};
|
||||
use crate::time::{Alarm, Instant};
|
||||
|
||||
/// Task is spawned (has a future)
|
||||
|
@ -1,8 +1,8 @@
|
||||
use core::ptr;
|
||||
use core::ptr::NonNull;
|
||||
use core::sync::atomic::{AtomicPtr, Ordering};
|
||||
|
||||
use super::raw::Task;
|
||||
use crate::atomic::{AtomicPtr, Ordering};
|
||||
|
||||
pub(crate) struct RunQueueItem {
|
||||
next: AtomicPtr<Task>,
|
||||
|
@ -2,9 +2,9 @@ use core::cell::Cell;
|
||||
use core::cmp::min;
|
||||
use core::ptr;
|
||||
use core::ptr::NonNull;
|
||||
use core::sync::atomic::Ordering;
|
||||
|
||||
use super::raw::{Task, STATE_TIMER_QUEUED};
|
||||
use crate::atomic::{AtomicPtr, Ordering};
|
||||
use crate::time::Instant;
|
||||
|
||||
pub(crate) struct TimerQueueItem {
|
||||
|
@ -1,7 +1,8 @@
|
||||
use core::ptr;
|
||||
use core::sync::atomic::{AtomicPtr, Ordering};
|
||||
use cortex_m::peripheral::NVIC;
|
||||
|
||||
use crate::atomic::{AtomicBool, AtomicPtr, Ordering};
|
||||
|
||||
pub use embassy_macros::interrupt_declare as declare;
|
||||
pub use embassy_macros::interrupt_take as take;
|
||||
|
||||
@ -45,6 +46,7 @@ pub trait InterruptExt: Interrupt {
|
||||
fn set_handler_context(&self, ctx: *mut ());
|
||||
fn enable(&self);
|
||||
fn disable(&self);
|
||||
#[cfg(not(armv6m))]
|
||||
fn is_active(&self) -> bool;
|
||||
fn is_enabled(&self) -> bool;
|
||||
fn is_pending(&self) -> bool;
|
||||
@ -83,6 +85,7 @@ impl<T: Interrupt + ?Sized> InterruptExt for T {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(armv6m))]
|
||||
fn is_active(&self) -> bool {
|
||||
NVIC::is_active(NrWrap(self.number()))
|
||||
}
|
||||
|
@ -16,3 +16,4 @@ pub mod time;
|
||||
pub mod util;
|
||||
|
||||
pub use embassy_traits as traits;
|
||||
pub use atomic_polyfill as atomic;
|
||||
|
@ -1,6 +1,7 @@
|
||||
use core::cell::UnsafeCell;
|
||||
use core::mem::MaybeUninit;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use crate::atomic::{AtomicBool, Ordering};
|
||||
|
||||
pub struct Forever<T> {
|
||||
used: AtomicBool,
|
||||
|
Loading…
Reference in New Issue
Block a user