Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support/avr platform #12

Merged
merged 12 commits into from
Apr 8, 2022
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build
run: ./ci.sh
run: ./ci.sh
27 changes: 27 additions & 0 deletions avr-specs/avr-atmega328p.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"arch": "avr",
"atomic-cas": false,
"cpu": "atmega328p",
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
"eh-frame-header": false,
"exe-suffix": ".elf",
"executables": true,
"late-link-args": {
"gcc": [
"-lgcc"
]
},
"linker": "avr-gcc",
"linker-is-gnu": true,
"llvm-target": "avr-unknown-unknown",
"max-atomic-width": 8,
"no-default-libraries": false,
"pre-link-args": {
"gcc": [
"-mmcu=atmega328p",
"-Wl,--as-needed"
]
},
"target-c-int-width": "16",
"target-pointer-width": "16"
}
3 changes: 3 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -euxo pipefail

rustup toolchain install nightly-2021-01-07 --component rust-src
cargo +nightly-2021-01-07 build -Zbuild-std=core --target avr-specs/avr-atmega328p.json

cargo build
cargo build --target thumbv6m-none-eabi
cargo build --target thumbv7em-none-eabi
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ targets = [
"thumbv7em-none-eabi",
"riscv32imc-unknown-none-elf",
"riscv32imac-unknown-none-elf",
"avr-specs/avr-atmpeg328p.json",
]
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![no_std]
#![cfg_attr(target_arch = "avr", feature(llvm_asm))]
#![cfg_attr(target_arch = "avr", feature(extended_key_value_attributes))]
#![doc = include_str!("../README.md")]

pub use bare_metal::CriticalSection;
Expand Down Expand Up @@ -118,6 +120,25 @@ cfg_if::cfg_if! {
cortex_m::interrupt::enable()
}
}
} else if #[cfg(target_arch = "avr")] {
#[no_mangle]
unsafe fn _critical_section_acquire() -> u8 {
let mut sreg: u8;
llvm_asm!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the newer asm!, or is it not supported on AVR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last I checked asm! was not supported by Rust for AVR target.

Also, the last time I dealt with assembly language was 1987 on an 8086.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, just wanted to confirm!

Also, the last time I dealt with assembly language was 1987 on an 8086.

😂

"in $0, 0x3F
cli"
: "=r"(sreg)
::: "volatile"
);
sreg
}

#[no_mangle]
unsafe fn _critical_section_release(token: u8) {
if token & 0x80 == 0x80 {
llvm_asm!("sei" :::: "volatile");
}
}
} else if #[cfg(target_arch = "riscv32")] {
#[no_mangle]
unsafe fn _critical_section_acquire() -> u8 {
Expand Down