Merge #1054
1054: riscv fixes r=lulf a=swolix With these changes I can run embassy on our RISC-V processor, please consider merging this, feedback is very welcome. I don't fully understand the code in the executor, but I have implemented a critical section by globally disabling interrupts, which means the wfi inside the critical section will hang the whole thing. Co-authored-by: Sijmen Woutersen <sijmen.woutersen@gmail.com>
This commit is contained in:
commit
2fa2c1a6fe
4 changed files with 20 additions and 15 deletions
|
@ -31,6 +31,7 @@ flavors = [
|
|||
default = []
|
||||
std = ["embassy-macros/std", "critical-section/std"]
|
||||
wasm = ["dep:wasm-bindgen", "dep:js-sys", "embassy-macros/wasm"]
|
||||
riscv = ["embassy-macros/riscv"]
|
||||
|
||||
# Enable nightly-only features
|
||||
nightly = []
|
||||
|
|
|
@ -55,19 +55,11 @@ impl Executor {
|
|||
unsafe {
|
||||
self.inner.poll();
|
||||
// we do not care about race conditions between the load and store operations, interrupts
|
||||
//will only set this value to true.
|
||||
critical_section::with(|_| {
|
||||
// if there is work to do, loop back to polling
|
||||
// TODO can we relax this?
|
||||
if SIGNAL_WORK_THREAD_MODE.load(Ordering::SeqCst) {
|
||||
SIGNAL_WORK_THREAD_MODE.store(false, Ordering::SeqCst);
|
||||
}
|
||||
// if not, wait for interrupt
|
||||
else {
|
||||
core::arch::asm!("wfi");
|
||||
}
|
||||
});
|
||||
// if an interrupt occurred while waiting, it will be serviced here
|
||||
// will only set this value to true.
|
||||
// if there is work to do, loop back to polling
|
||||
if !SIGNAL_WORK_THREAD_MODE.fetch_and(false, Ordering::SeqCst) {
|
||||
core::arch::asm!("wfi");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ proc-macro = true
|
|||
[features]
|
||||
std = []
|
||||
wasm = []
|
||||
riscv = []
|
||||
|
||||
# Enabling this cause interrupt::take! to require embassy-executor
|
||||
rtos-trace-interrupt = []
|
||||
|
|
|
@ -45,7 +45,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||
}
|
||||
};
|
||||
|
||||
#[cfg(all(feature = "std", not(feature = "wasm")))]
|
||||
#[cfg(all(feature = "std", not(feature = "wasm"), not(feature = "riscv")))]
|
||||
let main = quote! {
|
||||
fn main() -> ! {
|
||||
let mut executor = ::embassy_executor::Executor::new();
|
||||
|
@ -57,13 +57,24 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||
}
|
||||
};
|
||||
|
||||
#[cfg(all(not(feature = "std"), not(feature = "wasm")))]
|
||||
#[cfg(all(not(feature = "std"), not(feature = "wasm"), not(feature = "riscv")))]
|
||||
let main = quote! {
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
let mut executor = ::embassy_executor::Executor::new();
|
||||
let executor = unsafe { __make_static(&mut executor) };
|
||||
executor.run(|spawner| {
|
||||
spawner.must_spawn(__embassy_main(spawner));
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(all(not(feature = "std"), not(feature = "wasm"), feature = "riscv"))]
|
||||
let main = quote! {
|
||||
#[riscv_rt::entry]
|
||||
fn main() -> ! {
|
||||
let mut executor = ::embassy_executor::Executor::new();
|
||||
let executor = unsafe { __make_static(&mut executor) };
|
||||
executor.run(|spawner| {
|
||||
spawner.must_spawn(__embassy_main(spawner));
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue