Skip to content

Commit

Permalink
Merge pull request #10 from rust-embedded/new-asm
Browse files Browse the repository at this point in the history
Update to new assembly syntax. Create release v0.3.0.
  • Loading branch information
cr1901 authored Jan 26, 2022
2 parents fd53654 + a6f514f commit 4ee7a8b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 58 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.3.0] - 2022-01-25

### Changed
- Bumped `bare-metal` to version `1.0.0`.
- Bumped `bare-metal` to version `1.0.0`. Using bare_metal v1.x causes
incompatible type errors with device crates (PACs) using bare-metal v0.2.x.
This, _among other removed features_, requires a major version bump to fix.
- All uses of the `llvm_asm!` macro have been replaced with `asm!`, in
accordance with [Issue 92816](https://github.com/rust-lang/rust/pull/92816).

### Removed
- `enable_cs` removed due to soundness hole when interacting with `Clone` and
`interrupt::free`.
- Remove `peripherals` module since the peripheral API is no longer provided by
`bare-metal`.
- `register::{sp, pc}::write` have been removed; inline assembly [mandates](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#rules-for-inline-assembly)
that the stack pointer is restored before leaving an asm block. Writing
PC is also being removed as a precaution.

## [v0.2.2] - 2020-04-23

Expand Down Expand Up @@ -50,7 +59,8 @@ Initial release.

[bare-metal]: https://github.com/japaric/bare-metal

[Unreleased]: https://github.com/rust-embedded/msp430/compare/v0.2.2...HEAD
[Unreleased]: https://github.com/rust-embedded/msp430/compare/v0.3.0...HEAD
[v0.3.0]: https://github.com/rust-embedded/msp430/compare/v0.2.2...v0.3.0
[v0.2.2]: https://github.com/rust-embedded/msp430/compare/v0.2.1...v0.2.2
[v0.2.1]: https://github.com/rust-embedded/msp430/compare/v0.2.0...v0.2.1
[v0.2.0]: https://github.com/rust-embedded/msp430/compare/v0.1.0...v0.2.0
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
This crate is based on [cortex-m](https://docs.rs/cortex-m) crate by Jorge Aparicio (@japaric).

**This crate requires a nightly rust due to the use of the `llvm_asm!`
(`0.2.2` and above) or `asm!` (`0.2.1` and below) macro.** For `0.2.2`,
`nightly-2020-04-22` is known to work. For `0.2.1`, `nightly-2020-01-04` is
known to work.
**This crate requires a nightly rust due to the use of the new `asm!` (`0.3.0`
and above), `llvm_asm!` (`0.2.2`) or old `asm!` (`0.2.1` and below) macros.**
The below table contains compilers which are known to work:

|`msp430` version|`rustc` compiler |
|----------------|--------------------|
|`0.3.0` |`nightly-2022-01-24`|
|`0.2.2` |`nightly-2020-04-22`|
|`0.2.1` |`nightly-2020-01-04`|

## [Documentation](https://docs.rs/crate/msp430)

Expand Down
10 changes: 4 additions & 6 deletions src/asm.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
//! Miscellaneous assembly instructions
use crate::asm;

/// A no-operation. Useful to prevent delay loops from being optimized away.
#[inline(always)]
pub fn nop() {
unsafe {
llvm_asm!("nop"
:
:
:
: "volatile");
asm!("nop");
}
}

/// A compiler fence, prevents instruction reordering.
#[inline(always)]
pub fn barrier() {
unsafe {
llvm_asm!("" ::: "memory" : "volatile");
asm!("");
}
}
14 changes: 4 additions & 10 deletions src/interrupt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Interrupts
use crate::asm;

pub use bare_metal::{CriticalSection, Mutex};

/// Disables all interrupts
Expand All @@ -8,11 +10,7 @@ pub fn disable() {
match () {
#[cfg(target_arch = "msp430")]
() => unsafe {
llvm_asm!("dint { nop"
:
:
: "memory"
: "volatile");
asm!("dint {{ nop");
},
#[cfg(not(target_arch = "msp430"))]
() => {}
Expand All @@ -31,11 +29,7 @@ pub unsafe fn enable() {
match () {
#[cfg(target_arch = "msp430")]
() => {
llvm_asm!("nop { eint { nop"
:
:
: "memory"
: "volatile");
asm!("nop {{ eint {{ nop");
}
#[cfg(not(target_arch = "msp430"))]
() => {}
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
//! - Safe wrappers around assembly instructions like `nop`
#![deny(missing_docs)]
#![feature(llvm_asm)]
#![feature(asm_experimental_arch)]
#![no_std]

use core::arch::asm;

extern crate bare_metal;

#[macro_use]
Expand Down
18 changes: 3 additions & 15 deletions src/register/pc.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
//! Program counter
use crate::asm;

/// Reads the CPU register
#[inline(always)]
pub fn read() -> u16 {
let r;
unsafe {
llvm_asm!("mov R0,$0"
: "=r"(r)
:
:
: "volatile");
asm!("mov R0, {0}", out(reg) r);
}
r
}

/// Writes `bits` to the CPU register
#[inline(always)]
pub unsafe fn write(bits: u16) {
llvm_asm!("mov $0,R0"
:
: "r"(bits)
:
: "volatile");
}
18 changes: 3 additions & 15 deletions src/register/sp.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
//! Main Stack Pointer
use crate::asm;

/// Reads the CPU register
#[inline(always)]
pub fn read() -> u16 {
let r;
unsafe {
llvm_asm!("mov R1,$0"
: "=r"(r)
:
:
: "volatile");
asm!("mov R1, {0}", out(reg) r);
}
r
}

/// Writes `bits` to the CPU register
#[inline(always)]
pub unsafe fn write(bits: u16) {
llvm_asm!("mov $0,R1"
:
: "r"(bits)
:
: "volatile");
}
8 changes: 3 additions & 5 deletions src/register/sr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Status Register
use crate::asm;

/// Status Register
#[derive(Clone, Copy, Debug)]
pub struct Sr {
Expand Down Expand Up @@ -77,11 +79,7 @@ impl Sr {
pub fn read() -> Sr {
let r: u16;
unsafe {
llvm_asm!("mov R2, $0"
: "=r"(r)
:
:
: "volatile");
asm!("mov R2, {0}", out(reg) r);
}
Sr { bits: r }
}

0 comments on commit 4ee7a8b

Please sign in to comment.