Skip to content

Commit

Permalink
s/all/take/g, s/_all/steal/g and tweak CI
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Dec 9, 2017
1 parent d5c07e9 commit e114878
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ matrix:
os: osx

install:
- sh ci/install.sh
- bash ci/install.sh

script:
- bash ci/script.sh
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ keywords = [
license = "MIT OR Apache-2.0"
name = "svd2rust"
repository = "https://github.com/japaric/svd2rust"
version = "0.11.4"
version = "0.12.0"

[[bin]]
doc = false
Expand Down
2 changes: 1 addition & 1 deletion ci/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set -ex
set -euxo pipefail

main() {
local sort=
Expand Down
9 changes: 4 additions & 5 deletions ci/script.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set -ex
set -o pipefail
set -euxo pipefail

test_svd() {
(
Expand All @@ -15,7 +14,7 @@ test_svd() {
}

main() {
cross build --target $TARGET
cross check --target $TARGET

if [ -z $VENDOR ]; then
return
Expand All @@ -35,7 +34,7 @@ main() {
# test crate
cargo init --name foo $td
echo 'bare-metal = "0.1.0"' >> $td/Cargo.toml
echo 'cortex-m = "0.3.0"' >> $td/Cargo.toml
echo 'cortex-m = { git = "https://github.com/japaric/cortex-m" }' >> $td/Cargo.toml
echo 'cortex-m-rt = "0.3.0"' >> $td/Cargo.toml
echo 'vcell = "0.1.0"' >> $td/Cargo.toml

Expand Down Expand Up @@ -609,6 +608,6 @@ main() {
rm -rf $td
}

if [ -z $TRAVIS_TAG ]; then
if [ -z ${TRAVIS_TAG-} ]; then
main
fi
17 changes: 10 additions & 7 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ pub fn device(d: &Device, target: &Target, items: &mut Vec<Tokens>) -> Result<()
}

items.push(quote! {
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
// crate as that would let you `take` the device peripherals more than once (one per minor
// version)
#[no_mangle]
static mut PERIPHERALS: bool = false;
static mut DEVICE_PERIPHERALS: bool = false;

/// All the peripherals
#[allow(non_snake_case)]
Expand All @@ -154,21 +157,21 @@ pub fn device(d: &Device, target: &Target, items: &mut Vec<Tokens>) -> Result<()

impl Peripherals {
/// Returns all the peripherals *once*
pub fn all() -> Option<Self> {
pub fn take() -> Option<Self> {
cortex_m::interrupt::free(|_| {
if unsafe { PERIPHERALS } {
if unsafe { DEVICE_PERIPHERALS } {
None
} else {
Some(unsafe { Peripherals::_all() })
Some(unsafe { Peripherals::steal() })
}
})
}

#[doc(hidden)]
pub unsafe fn _all() -> Self {
debug_assert!(!PERIPHERALS);
pub unsafe fn steal() -> Self {
debug_assert!(!DEVICE_PERIPHERALS);

PERIPHERALS = true;
DEVICE_PERIPHERALS = true;

Peripherals {
#(#exprs,)*
Expand Down

0 comments on commit e114878

Please sign in to comment.