From d890acbef24fa096d90adda12be873ccb55e5d13 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Tue, 22 Mar 2022 17:27:45 -0400 Subject: [PATCH 1/8] first draft at support for AVR/Arduino --- Cargo.toml | 10 +++++++--- build.rs | 3 ++- src/sorted_linked_list.rs | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 41ad73a4..6317f6ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,13 +31,17 @@ defmt-impl = ["defmt"] scoped_threadpool = "0.1.8" [target.thumbv6m-none-eabi.dependencies] -atomic-polyfill = { version = "0.1.2", optional = true } +atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } [target.riscv32i-unknown-none-elf.dependencies] -atomic-polyfill = { version = "0.1.4", optional = true } +atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } [target.riscv32imc-unknown-none-elf.dependencies] -atomic-polyfill = { version = "0.1.4", optional = true } +atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } + +[target.avr-atmega328p.dependencies] +atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } + [dependencies] hash32 = "0.2.1" diff --git a/build.rs b/build.rs index 0840d6fb..48c0fa78 100644 --- a/build.rs +++ b/build.rs @@ -43,6 +43,7 @@ fn main() -> Result<(), Box> { match &target[..] { "avr-unknown-gnu-atmega328" | "msp430-none-elf" + | "avr-atmega328p" // | "riscv32i-unknown-none-elf" // supported by atomic-polyfill // | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill => {} @@ -55,7 +56,7 @@ fn main() -> Result<(), Box> { // Let the code know if it should use atomic-polyfill or not, and what aspects // of polyfill it requires match &target[..] { - "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => { + "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" | "avr-atmega328p" => { println!("cargo:rustc-cfg=full_atomic_polyfill"); println!("cargo:rustc-cfg=cas_atomic_polyfill"); } diff --git a/src/sorted_linked_list.rs b/src/sorted_linked_list.rs index bb418bb2..3768d6c2 100644 --- a/src/sorted_linked_list.rs +++ b/src/sorted_linked_list.rs @@ -180,6 +180,9 @@ macro_rules! impl_index_and_const_new { impl_index_and_const_new!(LinkedIndexU8, u8, new_u8, 254); // val is 2^8 - 2 (one less than max) impl_index_and_const_new!(LinkedIndexU16, u16, new_u16, 65_534); // val is 2^16 - 2 +#[cfg(target_pointer_width = "16")] +impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, 65_534); // val is 2^16 - 2 +#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, 4_294_967_294); // val is 2^32 - 2 impl SortedLinkedList From 75f330caa2b3c90099365ed1497c1a1e7c45e39e Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Tue, 29 Mar 2022 17:20:45 -0400 Subject: [PATCH 2/8] add support for the Arduino Mega 2560 board --- Cargo.toml | 3 +++ build.rs | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6317f6ef..47c510f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,9 @@ atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", bran [target.avr-atmega328p.dependencies] atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } +[target.avr-atmega2560.dependencies] +atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } + [dependencies] hash32 = "0.2.1" diff --git a/build.rs b/build.rs index 48c0fa78..c9cc1c9c 100644 --- a/build.rs +++ b/build.rs @@ -44,6 +44,7 @@ fn main() -> Result<(), Box> { "avr-unknown-gnu-atmega328" | "msp430-none-elf" | "avr-atmega328p" + | "avr-atmega2560" // | "riscv32i-unknown-none-elf" // supported by atomic-polyfill // | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill => {} @@ -56,7 +57,10 @@ fn main() -> Result<(), Box> { // Let the code know if it should use atomic-polyfill or not, and what aspects // of polyfill it requires match &target[..] { - "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" | "avr-atmega328p" => { + "riscv32i-unknown-none-elf" + | "riscv32imc-unknown-none-elf" + | "avr-atmega328p" + | "avr-atmega2560" => { println!("cargo:rustc-cfg=full_atomic_polyfill"); println!("cargo:rustc-cfg=cas_atomic_polyfill"); } From cde5da25e4da9edf38f5f6fabf43ef26aabeda9b Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Tue, 12 Apr 2022 14:34:05 -0400 Subject: [PATCH 3/8] rely on packages that use us to patch crates.io for AVR --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47c510f5..fdbad18e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,19 +31,19 @@ defmt-impl = ["defmt"] scoped_threadpool = "0.1.8" [target.thumbv6m-none-eabi.dependencies] -atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } +atomic-polyfill = { version = "0.1.2", optional = true } [target.riscv32i-unknown-none-elf.dependencies] -atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } +atomic-polyfill = { version = "0.1.4", optional = true } [target.riscv32imc-unknown-none-elf.dependencies] -atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } +atomic-polyfill = { version = "0.1.4", optional = true } [target.avr-atmega328p.dependencies] -atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } +atomic-polyfill = { version = "0.1.7", optional = true } [target.avr-atmega2560.dependencies] -atomic-polyfill = { git="https://github.com/mutantbob/atomic-polyfill.git", branch="main", optional = true } +atomic-polyfill = { version = "0.1.7", optional = true } [dependencies] From ff4cdab2abb54ee369397b252ab87fdff2693321 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Tue, 12 Apr 2022 16:27:28 -0400 Subject: [PATCH 4/8] release 0.1.8 of atomic-polyfill now supports AVR --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fdbad18e..9daa85c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,10 +40,10 @@ atomic-polyfill = { version = "0.1.4", optional = true } atomic-polyfill = { version = "0.1.4", optional = true } [target.avr-atmega328p.dependencies] -atomic-polyfill = { version = "0.1.7", optional = true } +atomic-polyfill = { version = "0.1.8", optional = true } [target.avr-atmega2560.dependencies] -atomic-polyfill = { version = "0.1.7", optional = true } +atomic-polyfill = { version = "0.1.8", optional = true } [dependencies] From ef94d68a047621e4f2a3e5e63e82e2a32f668858 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Wed, 13 Apr 2022 15:32:52 -0400 Subject: [PATCH 5/8] make my code look more like jeremysalwen --- CHANGELOG.md | 2 ++ src/sorted_linked_list.rs | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76db5231..659a596a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- Added support for AVR architecture + ### Changed ## [v0.7.10] - 2022-01-21 diff --git a/src/sorted_linked_list.rs b/src/sorted_linked_list.rs index 3768d6c2..ee55e612 100644 --- a/src/sorted_linked_list.rs +++ b/src/sorted_linked_list.rs @@ -95,7 +95,7 @@ where // Internal macro for generating indexes for the linkedlist and const new for the linked list macro_rules! impl_index_and_const_new { - ($name:ident, $ty:ty, $new_name:ident, $max_val:literal) => { + ($name:ident, $ty:ty, $new_name:ident, $max_val:expr) => { /// Index for the [`SortedLinkedList`] with specific backing storage. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct $name($ty); @@ -178,12 +178,11 @@ macro_rules! impl_index_and_const_new { }; } -impl_index_and_const_new!(LinkedIndexU8, u8, new_u8, 254); // val is 2^8 - 2 (one less than max) -impl_index_and_const_new!(LinkedIndexU16, u16, new_u16, 65_534); // val is 2^16 - 2 -#[cfg(target_pointer_width = "16")] -impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, 65_534); // val is 2^16 - 2 -#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] -impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, 4_294_967_294); // val is 2^32 - 2 +impl_index_and_const_new!(LinkedIndexU8, u8, new_u8, { u8::MAX as usize - 1 }); +impl_index_and_const_new!(LinkedIndexU16, u16, new_u16, { u16::MAX as usize - 1 }); +impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, { + usize::MAX as usize - 1 +}); impl SortedLinkedList where From 2150effc73b20587fc4b3014b00dbe8e6d7da4c6 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Fri, 3 Jun 2022 12:32:23 -0400 Subject: [PATCH 6/8] it seems that I do not need to emit cargo:rustc-cfg=has_atomics for avr-atmega* --- build.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.rs b/build.rs index 70dd13a7..51a0d1c3 100644 --- a/build.rs +++ b/build.rs @@ -45,8 +45,6 @@ fn main() -> Result<(), Box> { match &target[..] { "avr-unknown-gnu-atmega328" | "msp430-none-elf" - | "avr-atmega328p" - | "avr-atmega2560" // | "riscv32i-unknown-none-elf" // supported by atomic-polyfill // | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill => {} From c8e6dcc3da66ef17c3769d154a76e17fd74a1c47 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Tue, 14 Jun 2022 13:47:05 -0400 Subject: [PATCH 7/8] act on japaric's requests using techniques from Rahix to more generically support AVR --- Cargo.toml | 5 +---- build.rs | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1536a96d..d8dda5d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,10 +36,7 @@ atomic-polyfill = { version = "0.1.4" } [target.riscv32imc-unknown-none-elf.dependencies] atomic-polyfill = { version = "0.1.4" } -[target.avr-atmega328p.dependencies] -atomic-polyfill = { version = "0.1.8", optional = true } - -[target.avr-atmega2560.dependencies] +[target.'cfg(target_arch = "avr")'.dependencies] atomic-polyfill = { version = "0.1.8", optional = true } diff --git a/build.rs b/build.rs index 51a0d1c3..9021e3ce 100644 --- a/build.rs +++ b/build.rs @@ -23,10 +23,15 @@ fn main() -> Result<(), Box> { println!("cargo:rustc-cfg=armv7a"); } + let is_avr = env::var("CARGO_CFG_TARGET_ARCH") == Ok("avr".to_string()); + // built-in targets with no atomic / CAS support as of nightly-2022-01-13 // AND not supported by the atomic-polyfill crate // see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file - match &target[..] { + if is_avr { + // lacks cas + } else { + match &target[..] { "avr-unknown-gnu-atmega328" | "bpfeb-unknown-none" | "bpfel-unknown-none" @@ -40,11 +45,14 @@ fn main() -> Result<(), Box> { _ => { println!("cargo:rustc-cfg=has_cas"); } + } }; - match &target[..] { - "avr-unknown-gnu-atmega328" - | "msp430-none-elf" + if is_avr { + // lacks atomics + } else { + match &target[..] { + "msp430-none-elf" // | "riscv32i-unknown-none-elf" // supported by atomic-polyfill // | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill => {} @@ -52,23 +60,26 @@ fn main() -> Result<(), Box> { _ => { println!("cargo:rustc-cfg=has_atomics"); } + } }; // Let the code know if it should use atomic-polyfill or not, and what aspects // of polyfill it requires - match &target[..] { - "riscv32i-unknown-none-elf" - | "riscv32imc-unknown-none-elf" - | "avr-atmega328p" - | "avr-atmega2560" => { - println!("cargo:rustc-cfg=full_atomic_polyfill"); - println!("cargo:rustc-cfg=cas_atomic_polyfill"); - } + if is_avr { + println!("cargo:rustc-cfg=full_atomic_polyfill"); + println!("cargo:rustc-cfg=cas_atomic_polyfill"); + } else { + match &target[..] { + "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => { + println!("cargo:rustc-cfg=full_atomic_polyfill"); + println!("cargo:rustc-cfg=cas_atomic_polyfill"); + } - "thumbv6m-none-eabi" => { - println!("cargo:rustc-cfg=cas_atomic_polyfill"); + "thumbv6m-none-eabi" => { + println!("cargo:rustc-cfg=cas_atomic_polyfill"); + } + _ => {} } - _ => {} } if !matches!( From 178d44cc4f30eb2b8b58485b1912b10b1ce685a1 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Tue, 14 Jun 2022 13:50:34 -0400 Subject: [PATCH 8/8] that cast was unnecessary --- src/sorted_linked_list.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sorted_linked_list.rs b/src/sorted_linked_list.rs index ee55e612..041895cd 100644 --- a/src/sorted_linked_list.rs +++ b/src/sorted_linked_list.rs @@ -180,9 +180,7 @@ macro_rules! impl_index_and_const_new { impl_index_and_const_new!(LinkedIndexU8, u8, new_u8, { u8::MAX as usize - 1 }); impl_index_and_const_new!(LinkedIndexU16, u16, new_u16, { u16::MAX as usize - 1 }); -impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, { - usize::MAX as usize - 1 -}); +impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, { usize::MAX - 1 }); impl SortedLinkedList where