Ulf Lilleengen
3c2daf0d32
Remove unused import
2021-10-20 14:36:16 +02:00
Ulf Lilleengen
6c9420978b
Prevent overflow in std timer driver
...
This prevents the std time driver from overflowing when setting the next
wakeup time. If an overflow occurs, default to sleeping up to 1 second.
Fixes #438
2021-10-20 14:36:16 +02:00
bors[bot]
729b17bc25
Merge #428
...
428: executor: Use critical sections instead of atomic CAS loops r=lulf a=Dirbaio
Optimize executor wakes.
CAS loops (either `fetch_update`, or manual `load + compare_exchange_weak`) generate surprisingly horrible code: https://godbolt.org/z/zhscnM1cb
This switches to using critical sections, which makes it faster. On thumbv6 (Cortex-M0) it should make it even faster, as it is currently using `atomic-polyfill`, which will make many critical sections for each `compare_exchange_weak` anyway.
```
opt-level=3 opt-level=s
atmics: 105 cycles 101 cycles
CS: 76 cycles 72 cycles
CS+inline: 72 cycles 64 cycles
```
Measured in nrf52 with icache disabled, with this code:
```rust
poll_fn(|cx| {
let task = unsafe { task_from_waker(cx.waker()) };
compiler_fence(Ordering::SeqCst);
let a = cortex_m::peripheral::DWT::get_cycle_count();
compiler_fence(Ordering::SeqCst);
unsafe { wake_task(task) }
compiler_fence(Ordering::SeqCst);
let b = cortex_m::peripheral::DWT::get_cycle_count();
compiler_fence(Ordering::SeqCst);
defmt::info!("cycles: {=u32}", b.wrapping_sub(a));
Poll::Ready(())
})
.await;
````
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-18 12:05:43 +00:00
Dario Nieuwenhuis
a2e7c24e00
Clippy fixes
2021-10-18 01:05:29 +02:00
Dario Nieuwenhuis
4c0fa03c14
interrupt: transmute instead of steal.
...
That steal method has a TAKEN=true write [here](6b013138b7/src/peripheral/mod.rs (L180)
).
This is not zero cost, we don't want it. Transmute instead, which is zero cost.
2021-10-16 04:11:19 +02:00
Dario Nieuwenhuis
d32477f5a1
executor: Inline enqueue fns
2021-10-16 01:50:10 +02:00
Dario Nieuwenhuis
39e5677621
executor: Use critical sections instead of atomic CAS loops
2021-10-16 01:49:54 +02:00
Daniel Bevenius
a7c37d2ff4
Fix typo in RunQueue documentation
2021-10-11 13:55:05 +02:00
Ulf Lilleengen
99a94f1d50
Update version of critical-section
2021-09-13 17:05:17 +02:00
Ulf Lilleengen
e24528051b
Add WASM support for executor
...
* Adds an executor for WASM runtimes based on wasm_bindgen.
* Add time driver based on JS time handling.
* Add example that can run in browser locally.
* Update to critical-section version that supports 'std' flag
2021-09-13 16:42:39 +02:00
Dario Nieuwenhuis
70e5877d68
embassy/channel: switch to use MutexKind
2021-09-13 00:08:41 +02:00
Dario Nieuwenhuis
5be5bdfd20
embassy/blocking_mutex: add MutexKind to allow writing code generic over mutex kinds.
2021-09-12 23:28:00 +02:00
Dario Nieuwenhuis
e1f9dd1170
embassy/channel: remove unused receiver_consumed
2021-09-11 02:58:41 +02:00
Dario Nieuwenhuis
b78f4695c4
embassy/channel: use heapless::Deque.
2021-09-11 02:49:16 +02:00
Dario Nieuwenhuis
ead987245d
embassy: Refactor module structure to remove kitchen-sink util
.
2021-09-11 02:35:35 +02:00
Dario Nieuwenhuis
f2623e7e9b
Update lots of deps
2021-09-11 01:35:23 +02:00
Dario Nieuwenhuis
11d2b0cdc1
Remove more unused features.
2021-09-03 17:13:54 +02:00
Dario Nieuwenhuis
de016e8456
Remove trait_alias, allow(incomplete_features).
...
trait_alias seems unused. no idea why it's there.
2021-09-03 17:00:58 +02:00
Ulf Lilleengen
5f04d6e6c5
Fix embassy::main macros for std target
2021-09-02 14:45:54 +02:00
Dario Nieuwenhuis
297de612e5
Improve executor naming. Add docs.
2021-08-31 23:59:28 +02:00
Dario Nieuwenhuis
c4b9c8ac87
std: fold into embassy core, add non-hacky time driver.
2021-08-25 21:06:27 +02:00
Dario Nieuwenhuis
7c0990ad1e
time: allow storing state inside the driver struct.
2021-08-25 21:06:27 +02:00
Dario Nieuwenhuis
55b2d7b524
io: move std stuff to own module
2021-08-25 21:06:27 +02:00
Dario Nieuwenhuis
503be49417
Document embassy::time
2021-08-25 21:06:27 +02:00
Dario Nieuwenhuis
ae179d49af
executor: improve module structure
2021-08-25 00:20:29 +02:00
Richard Dodd
7ca745a5c0
Refactor to allow defmt to intern strings.
2021-08-22 00:11:19 +01:00
Richard Dodd
4d3c07f71b
Fix fmt
2021-08-21 22:38:02 +01:00
Richard Dodd
170121cdf6
Add defmt support for mpsc errors.
2021-08-21 22:36:23 +01:00
Ben Gamari
a3b56a3764
embassy-macros: Use defmt::unwrap!
when spawning embassy::main
...
But only when `defmt` feature is enabled.
2021-08-05 22:40:12 +02:00
Dario Nieuwenhuis
36402b5487
Merge pull request #348 from embassy-rs/remove-portal
...
Remove Portal. Fixes #32
2021-08-05 22:31:06 +02:00
Dario Nieuwenhuis
b1240217bd
Remove Portal. Fixes #32
...
Portal is very niche, I've only ever used it in `nrf-softdevice` and in a very particular case:
sending event raw-pointers across tasks but "synchronously", because the destination task must process
it now, so it's not deallocated. For most usecases, Signal or channels is enough.
It's unclear to me whether it can be made ub-free. It has problems with reentrancy. It's also not leak-safe, which is quite annoying.
So, remove it for now. We can always add it back later.
2021-08-05 22:24:03 +02:00
Dario Nieuwenhuis
aaa0d1419c
util: fix unsoundness when dropping ThreadModeMutex outside thread mode.
...
Fixes #283
2021-08-05 22:20:45 +02:00
Dario Nieuwenhuis
0ea6a2d890
time: replace dyn clock/alarm with a global Driver trait
2021-08-05 19:14:09 +02:00
Dario Nieuwenhuis
07d4b196f7
Update nightly, remove removed features.
2021-08-04 19:48:14 +02:00
Dario Nieuwenhuis
250f1cd0a5
util: fix unused return warning
2021-08-04 19:38:05 +02:00
Dario Nieuwenhuis
6043383008
Remove version pinning workaround.
2021-08-02 20:47:30 +02:00
Ulf Lilleengen
f2c2ad06ca
Use lifetime to ensure only a single future is created at a time
2021-08-02 12:42:06 +02:00
Ulf Lilleengen
4d8d8e386f
Make RecvFuture sync
...
RecvFuture always locks the underlying Channel when polled.
2021-08-02 11:18:59 +02:00
Ulf Lilleengen
332bc44b8c
Expose SendFuture and RecvFuture types
...
Having these types available makes it easier to store futures for later
use as the named types can be embedded in other types at compile time.
2021-08-02 10:45:50 +02:00
Dario Nieuwenhuis
c8a48d726a
Merge pull request #277 from Liamolucko/fix-peripheral-ub
...
extras: Fix UB in `Peripheral`
2021-07-29 13:08:30 +02:00
Liam Murphy
1b7ad7080e
Add Send/Sync
bounds to PeripheralState
2021-07-24 12:53:57 +10:00
huntc
72d6f79ec7
Feature no longer required given 1.55
2021-07-15 12:31:53 +10:00
huntc
3778f55d80
Provides a cleaner construction of the channel with the common "new" naming
2021-07-15 12:31:53 +10:00
huntc
6f78527aeb
Partial borrow for receiver to enforce compile-time mpssc
2021-07-15 12:31:53 +10:00
huntc
076198a3b9
Small tidy up
2021-07-15 12:31:53 +10:00
huntc
d711e8a82c
Eliminates unsoundness by using an UnsafeCell for sharing the channel
2021-07-15 12:31:53 +10:00
huntc
babee7f32a
Tighten sender/receiver bounds
2021-07-15 12:31:53 +10:00
huntc
d86892ca56
Removed the closing state as it was not required
2021-07-15 12:31:53 +10:00
huntc
a247fa4f2c
Explicitly drop non consumed items
2021-07-15 12:31:53 +10:00
huntc
7c723d2bfd
Removed UB code around the send future
2021-07-15 12:31:52 +10:00
huntc
baab52d40c
Avoid a race condition by reducing the locks to one
2021-07-15 12:31:52 +10:00
huntc
5a5795ef2b
NoopMutex does not require an UnsafeCell
2021-07-15 12:31:52 +10:00
huntc
9b5f2e465b
Tidying
2021-07-15 12:31:52 +10:00
huntc
108cffcba0
Migrated to the waker registration functionality for Embassy specific optimisations
2021-07-15 12:31:52 +10:00
huntc
dcd0c38109
Return a new future each time recv is called
2021-07-15 12:31:52 +10:00
huntc
f159beec1c
Use of a NoopMutex
2021-07-15 12:31:52 +10:00
huntc
5f87c7808c
Remove the cell and trait
...
At the expense of exposing the channel types again. We do this as we want to avoid using dyn traits given their overhead for embedded environments.
2021-07-15 12:31:52 +10:00
huntc
56b3e927fe
ChannelState should be private
2021-07-15 12:31:52 +10:00
huntc
3fdf61c819
Constraint the use of ChannelCell to just channels
2021-07-15 12:31:52 +10:00
huntc
ae62948d6c
Replace UnsafeCell
...
Using a new ChannelCell so that there's no leaking of the abstraction
2021-07-15 12:31:52 +10:00
huntc
1b49acc2f7
Fixed some clippy warnings
2021-07-15 12:31:52 +10:00
huntc
a156f72bfb
Improves the representation of side effects
2021-07-15 12:31:52 +10:00
huntc
816b78c0d9
Reduces the types on sender and receiver
...
In exchange for an UnsafeCell being passed into split
2021-07-15 12:31:52 +10:00
huntc
1b9d5e5071
Multi Producer Single Consumer channel
...
An MPSC inspired by Tokio and Crossbeam. The MPSC is designed to support both single and multi core processors, with only single core implemented at this time. The allocation of the channel’s buffer is inspired by the const generic parameters that Heapless provides.
2021-07-15 12:31:52 +10:00
Dario Nieuwenhuis
c210a6efd1
embassy/time: remove useless impl
2021-07-12 03:45:48 +02:00
Dario Nieuwenhuis
16bb678368
Merge BlockingTimer and Delay
2021-07-12 03:45:48 +02:00
Dario Nieuwenhuis
35a76c364a
embassy/time: make optional via Cargo feature
2021-07-12 03:45:48 +02:00
Dario Nieuwenhuis
94bd4eb7d5
embassy/time: refactor module structure
2021-07-12 03:45:48 +02:00
huntc
e13aa4c2a0
Add tests to our CI
...
Also found some doctests that were failing
2021-07-06 12:29:08 +10:00
Rukai
56d0c5ffe1
Fix warnings in std and rp
2021-07-04 12:46:04 +10:00
Thales Fragoso
51583afc1e
Add docs for BlockingTimer and rename tick features
2021-06-28 18:52:27 -03:00
Thales Fragoso
54197d1663
Add BlockingTimer and features to choose tick rate
2021-06-28 18:01:40 -03:00
Dario Nieuwenhuis
3be49d3e79
fmt: Add dunmy use to avoid "unused variable" errors when no log is enabled.
2021-06-07 03:21:37 +02:00
Dario Nieuwenhuis
ef1ebefec0
fmt: use absolute paths
2021-06-07 03:15:05 +02:00
Dario Nieuwenhuis
e7dc5c0939
fmt: make all macros macro_rules
so scoping is consistent.
2021-06-07 00:16:39 +02:00
Timo Kröger
628e58020f
Add Unborrow
trait bound for Interrupt
...
Allows the compiler to figure out bounds for wrapper code of owned
peripherals and interrupts.
Example: https://gist.github.com/timokroeger/f025ef590557f1cd6c2e9c7ab30442d2
2021-06-04 23:42:25 +02:00
Ulf Lilleengen
ec9b51833c
Allow non-mut register and wake
2021-06-01 15:18:53 +02:00
Dario Nieuwenhuis
1c0ad53841
Unborrow docs
2021-05-19 23:39:45 +02:00
Dario Nieuwenhuis
105c8504b6
Mark Unborrow as unsafe to implement
2021-05-19 23:29:33 +02:00
Dario Nieuwenhuis
dc67d2f4a4
impl Unborrow for &'a mut T
...
This plays nicer with user code that's generic over peripheral traits like `Instance` or `Pin`.
2021-05-19 23:20:26 +02:00
Dario Nieuwenhuis
a8902b0592
Fix build with executor-agnostic
2021-05-19 13:00:01 +02:00
Dario Nieuwenhuis
cd0d3c4b0d
Merge branch 'stm32-neo'
2021-05-17 02:16:17 +02:00
Thales Fragoso
490152d028
Better interrupt handling
2021-05-14 23:42:09 -03:00
Ulf Lilleengen
3b86e85770
Bump version of critical-section to 0.2.1
2021-05-13 18:17:50 +02:00
Dario Nieuwenhuis
7fa0e57172
Use critical_section
crate
2021-05-11 01:15:30 +02:00
Rukai
6c3299c82f
Fix build on the latest nightly
2021-05-10 00:36:23 +02:00
Rukai
ab00c6987a
Fix build on the latest nightly
2021-05-08 13:23:17 +10:00
Dario Nieuwenhuis
97ca54fa66
Rename PeripheralBorrow to Unborrow
2021-04-14 19:59:52 +02:00
Dario Nieuwenhuis
d336a4b38a
Remove Pin from Delay trait
2021-04-14 17:04:40 +02:00
Dario Nieuwenhuis
fa8dc796a7
Workaround broken cast crate
2021-04-12 13:30:21 +02:00
Ulf Lilleengen
708e622ab0
Allow signals to be used when building for std
2021-04-12 12:06:42 +02:00
xoviat
009e1896bf
stm32: consolidate crates
2021-03-30 10:05:52 -05:00
xoviat
49d87ac868
add with_timeout
2021-03-29 15:48:57 -05:00
Dario Nieuwenhuis
d7c3a38efc
Reexport macros at root, use eveywhere as #[embassy::task]
2021-03-29 03:00:48 +02:00
Dario Nieuwenhuis
1c9f98e1b6
nrf/gpiote: fix irq race condition
...
The interrupt could fire between checking if sense=disabled and registering the waker,
in which case the future would get stuck.
2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
4ce46df160
Code size optimizations.
2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
0e8bb5dc0b
util: Do not unregister waker on wake in AtomicWaker.
2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
df42c38492
nrf/uarte: update to new api
2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
a134fce122
nrf: nicer Peripherals api, add take()
2021-03-29 00:58:57 +02:00
Dario Nieuwenhuis
ba6e0a4058
util: add wake_on_interrupt.
...
This is a lighter version of InterruptFuture.
2021-03-29 00:58:57 +02:00