Skip to content

Commit c88376c

Browse files
committed
rust: Bring in portable atomic as a dependency
Direct dependency: so this will need to get vendored. Portable atomic provides an implementation of atomic operations that can use compiler intrinsics when those are available, and has fallbacks when not. This, specifically, allows atomics to be used on the Cortex-M-{0,0+,3} where there are no atomic instructions. We will enable the crticial section implementation, which will result in a Zephyr spinlock being used to mask interrupts. Zephyr already has directives to catch the case of SMP and CPUs that don't have atomic instructions. The RP2040 has a special device to support this, but that will have to be implemented in a general sense, not really related to rust support. Signed-off-by: David Brown <[email protected]>
1 parent 5e9cede commit c88376c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

zephyr/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ zephyr-sys = { version = "3.7.0", path = "../zephyr-sys" }
1515
[dependencies.fugit]
1616
version = "0.3.7"
1717

18+
[dependencies.portable-atomic]
19+
version = "1.7.0"
20+
# We assume that the instances where portable atomic must provide its own implementation (target
21+
# does not have atomic instructions), are only single CPU. This is the case currently with Zephyr,
22+
# so this should only match the same implementation.
23+
# features = ["fallback", "unsafe-assume-single-core"]
24+
features = ["fallback", "critical-section"]
25+
26+
# Provides an implementation of Arc that either directs to 'alloc', or implements using portable
27+
# atomic.
28+
[dependencies.portable-atomic-util]
29+
version = "0.2.2"
30+
# Technically, this should only be used if the Rust feature for allocation is defined. But, it
31+
# should be safe to build the crate even if the Rust code doesn't use it because of configs.
32+
features = ["alloc"]
33+
1834
# These are needed at build time.
1935
# Whether these need to be vendored is an open question. They are not
2036
# used by the core Zephyr tree, but are needed by zephyr applications.

0 commit comments

Comments
 (0)