Skip to content

Commit 92067f7

Browse files
committed
Auto merge of #164 - japaric:gh161, r=japaric
add tests for the msp430 and none targets fix codegen for the msp430 target closes #161
2 parents 227a0b1 + 7d3155e commit 92067f7

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ matrix:
3333
rust: nightly
3434
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Toshiba
3535
rust: nightly
36+
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=OTHER
37+
rust: nightly
3638

3739
# Linux
3840
- env: TARGET=i686-unknown-linux-gnu

ci/script.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ test_svd() {
88
)
99

1010
# NOTE we care about errors in svd2rust, but not about errors / warnings in rustfmt
11-
target/$TARGET/release/svd2rust -i $td/${1}.svd | ( rustfmt 2>/dev/null > $td/src/lib.rs || true )
11+
target/$TARGET/release/svd2rust -i $td/${1}.svd | \
12+
( rustfmt 2>/dev/null > $td/src/lib.rs || true )
1213

1314
cargo check --manifest-path $td/Cargo.toml
1415
}
@@ -381,6 +382,27 @@ main() {
381382
test_svd ht32f275x
382383
;;
383384

385+
# test other targets (architectures)
386+
OTHER)
387+
echo 'msp430 = "0.1.0"' >> $td/Cargo.toml
388+
389+
(
390+
cd $td &&
391+
curl -LO \
392+
https://github.com/pftbest/msp430g2553/raw/v0.1.0/msp430g2553.svd
393+
)
394+
395+
target/$TARGET/release/svd2rust --target msp430 -i $td/msp430g2553.svd | \
396+
( rustfmt 2>/dev/null > $td/src/lib.rs || true )
397+
398+
cargo check --manifest-path $td/Cargo.toml
399+
400+
target/$TARGET/release/svd2rust --target none -i $td/msp430g2553.svd | \
401+
( rustfmt 2>/dev/null > $td/src/lib.rs || true )
402+
403+
cargo check --manifest-path $td/Cargo.toml
404+
;;
405+
384406
Nordic)
385407
# BAD-SVD two enumeratedValues have the same value
386408
# test_svd nrf52

src/generate.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn device(d: &Device, target: &Target, items: &mut Vec<Tokens>) -> Result<()
5757
}
5858
Target::Msp430 => {
5959
items.push(quote! {
60+
extern crate msp430;
6061
#[macro_reexport(default_handler)]
6162
#[cfg(feature = "rt")]
6263
extern crate msp430_rt;
@@ -142,6 +143,24 @@ pub fn device(d: &Device, target: &Target, items: &mut Vec<Tokens>) -> Result<()
142143
exprs.push(quote!(#id: #id { _marker: PhantomData }));
143144
}
144145

146+
let take = match *target {
147+
Target::CortexM => Some(Ident::new("cortex_m")),
148+
Target::Msp430 => Some(Ident::new("msp430")),
149+
Target::None => None,
150+
}.map(|krate| quote! {
151+
/// Returns all the peripherals *once*
152+
#[inline]
153+
pub fn take() -> Option<Self> {
154+
#krate::interrupt::free(|_| {
155+
if unsafe { DEVICE_PERIPHERALS } {
156+
None
157+
} else {
158+
Some(unsafe { Peripherals::steal() })
159+
}
160+
})
161+
}
162+
});
163+
145164
items.push(quote! {
146165
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
147166
// crate as that would let you `take` the device peripherals more than once (one per minor
@@ -156,17 +175,7 @@ pub fn device(d: &Device, target: &Target, items: &mut Vec<Tokens>) -> Result<()
156175
}
157176

158177
impl Peripherals {
159-
/// Returns all the peripherals *once*
160-
#[inline(always)]
161-
pub fn take() -> Option<Self> {
162-
cortex_m::interrupt::free(|_| {
163-
if unsafe { DEVICE_PERIPHERALS } {
164-
None
165-
} else {
166-
Some(unsafe { Peripherals::steal() })
167-
}
168-
})
169-
}
178+
#take
170179

171180
/// Unchecked version of `Peripherals::take`
172181
pub unsafe fn steal() -> Self {

0 commit comments

Comments
 (0)