fix portable atomic support #174
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- Added `CcsdsPacketCreator`, `CcsdsPacketReader` and `CcsdsPacketCreatorWithReservedData`
|
||||
which simplify the process of creating full CCSDS space packets.
|
||||
- Added new optional `portable-atomic` because portable atomics might not work on every
|
||||
architecture in addition to requiring atomic CAS support enabled inside for the crate.
|
||||
|
||||
## Fixed
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ num_enum = { version = "0.7", default-features = false }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
serde = { version = "1", optional = true, default-features = false, features = ["derive"] }
|
||||
arbitrary-int = { version = "2" }
|
||||
portable-atomic = "1"
|
||||
portable-atomic = { version = "1", optional = true }
|
||||
bitbybit = "1.4"
|
||||
|
||||
time = { version = "0.3", default-features = false, optional = true }
|
||||
@@ -32,6 +32,7 @@ defmt = { version = "1", default-features = false, optional = true }
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["alloc", "chrono/std", "chrono/clock", "thiserror/std"]
|
||||
portable-atomic = ["dep:portable-atomic", "portable-atomic/require-cas"]
|
||||
defmt = ["dep:defmt", "arbitrary-int/defmt"]
|
||||
serde = ["dep:serde", "chrono?/serde", "arbitrary-int/serde"]
|
||||
alloc = ["chrono?/alloc", "defmt?/alloc", "serde?/alloc"]
|
||||
|
||||
@@ -43,6 +43,9 @@ Currently, this includes the following components:
|
||||
- [`timelib`](https://crates.io/crates/time): Add basic support for the `time` time library.
|
||||
- [`defmt`](https://defmt.ferrous-systems.com/): Add support for the `defmt` by adding the
|
||||
[`defmt::Format`](https://defmt.ferrous-systems.com/format) derive on many types.
|
||||
- [`portable-atomic`](https://github.com/taiki-e/portable-atomic): Basic support for `portable-atomic`
|
||||
crate in addition to the support for core atomic types. This support requires atomic CAS support
|
||||
enabled in the portable atomic crate.
|
||||
|
||||
# Examples
|
||||
|
||||
|
||||
1
justfile
1
justfile
@@ -11,6 +11,7 @@ check:
|
||||
|
||||
embedded:
|
||||
cargo build --target thumbv7em-none-eabihf --no-default-features
|
||||
cargo build --target thumbv6m-none-eabi --no-default-features
|
||||
|
||||
test:
|
||||
cargo nextest r --all-features
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
//! - [`timelib`](https://crates.io/crates/time): Add basic support for the `time` time library.
|
||||
//! - [`defmt`](https://defmt.ferrous-systems.com/): Add support for the `defmt` by adding the
|
||||
//! [`defmt::Format`](https://defmt.ferrous-systems.com/format) derive on many types.
|
||||
//! - [`portable-atomic`]: Basic support for `portable-atomic` crate in addition to the support
|
||||
//! for core atomic types. This support requires atomic CAS support enabled in the portable
|
||||
//! atomic crate.
|
||||
//!
|
||||
//! ## Module
|
||||
//!
|
||||
|
||||
@@ -184,59 +184,63 @@ impl SequenceCounter for core::sync::atomic::AtomicU64 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "portable-atomic")]
|
||||
impl SequenceCounter for portable_atomic::AtomicU8 {
|
||||
type Raw = u8;
|
||||
|
||||
const MAX_BIT_WIDTH: usize = 8;
|
||||
|
||||
fn get(&self) -> Self::Raw {
|
||||
self.load(core::sync::atomic::Ordering::Relaxed)
|
||||
self.load(portable_atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn increment(&self) {
|
||||
self.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
||||
self.fetch_add(1, portable_atomic::Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "portable-atomic")]
|
||||
impl SequenceCounter for portable_atomic::AtomicU16 {
|
||||
type Raw = u16;
|
||||
|
||||
const MAX_BIT_WIDTH: usize = 16;
|
||||
|
||||
fn get(&self) -> Self::Raw {
|
||||
self.load(core::sync::atomic::Ordering::Relaxed)
|
||||
self.load(portable_atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn increment(&self) {
|
||||
self.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
||||
self.fetch_add(1, portable_atomic::Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "portable-atomic")]
|
||||
impl SequenceCounter for portable_atomic::AtomicU32 {
|
||||
type Raw = u32;
|
||||
|
||||
const MAX_BIT_WIDTH: usize = 32;
|
||||
|
||||
fn get(&self) -> Self::Raw {
|
||||
self.load(core::sync::atomic::Ordering::Relaxed)
|
||||
self.load(portable_atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn increment(&self) {
|
||||
self.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
||||
self.fetch_add(1, portable_atomic::Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "portable-atomic")]
|
||||
impl SequenceCounter for portable_atomic::AtomicU64 {
|
||||
type Raw = u64;
|
||||
|
||||
const MAX_BIT_WIDTH: usize = 64;
|
||||
|
||||
fn get(&self) -> Self::Raw {
|
||||
self.load(core::sync::atomic::Ordering::Relaxed)
|
||||
self.load(portable_atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn increment(&self) {
|
||||
self.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
||||
self.fetch_add(1, portable_atomic::Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user