Skip to content

Commit

Permalink
rust: Bring in portable atomic as a dependency
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
d3zd3z committed Sep 17, 2024
1 parent 5e9cede commit c88376c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions zephyr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ zephyr-sys = { version = "3.7.0", path = "../zephyr-sys" }
[dependencies.fugit]
version = "0.3.7"

[dependencies.portable-atomic]
version = "1.7.0"
# We assume that the instances where portable atomic must provide its own implementation (target
# does not have atomic instructions), are only single CPU. This is the case currently with Zephyr,
# so this should only match the same implementation.
# features = ["fallback", "unsafe-assume-single-core"]
features = ["fallback", "critical-section"]

# Provides an implementation of Arc that either directs to 'alloc', or implements using portable
# atomic.
[dependencies.portable-atomic-util]
version = "0.2.2"
# Technically, this should only be used if the Rust feature for allocation is defined. But, it
# should be safe to build the crate even if the Rust code doesn't use it because of configs.
features = ["alloc"]

# These are needed at build time.
# Whether these need to be vendored is an open question. They are not
# used by the core Zephyr tree, but are needed by zephyr applications.
Expand Down

0 comments on commit c88376c

Please sign in to comment.