Skip to content

Add support for building the e310x crate #185

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

Merged
merged 3 commits into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ main() {
echo 'cortex-m-rt = "0.3.0"' >> $td/Cargo.toml
echo 'vcell = "0.1.0"' >> $td/Cargo.toml
echo 'msp430 = "0.1.0"' >> $td/Cargo.toml
echo 'riscv = "0.1.4"' >> $td/Cargo.toml
echo 'riscv-rt = "0.1.3"' >> $td/Cargo.toml
echo '[profile.dev]' >> $td/Cargo.toml
echo 'incremental = false' >> $td/Cargo.toml

Expand Down Expand Up @@ -391,6 +393,9 @@ main() {
cd $td &&
curl -LO \
https://github.com/pftbest/msp430g2553/raw/v0.1.0/msp430g2553.svd
cd $td &&
curl -LO \
https://raw.githubusercontent.com/riscv-rust/e310x/master/e310x.svd
)

target/$TARGET/release/svd2rust --target msp430 -i $td/msp430g2553.svd | \
Expand All @@ -402,6 +407,11 @@ main() {
( rustfmt 2>/dev/null > $td/src/lib.rs || true )

cargo check --manifest-path $td/Cargo.toml

target/$TARGET/release/svd2rust --target riscv -i $td/e310x.svd | \
( rustfmt 2>/dev/null > $td/src/lib.rs || true )

cargo check --manifest-path $td/Cargo.toml
;;

Nordic)
Expand Down
9 changes: 9 additions & 0 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn render(d: &Device, target: &Target) -> Result<Vec<Tokens>> {
#![deny(warnings)]
#![allow(non_camel_case_types)]
#![feature(const_fn)]
#![feature(try_from)]
#![no_std]
});

Expand All @@ -62,6 +63,13 @@ pub fn render(d: &Device, target: &Target) -> Result<Vec<Tokens>> {
extern crate msp430_rt;
});
}
Target::RISCV => {
out.push(quote! {
extern crate riscv;
#[cfg(feature = "rt")]
extern crate riscv_rt;
});
}
Target::None => {}
}

Expand Down Expand Up @@ -141,6 +149,7 @@ pub fn render(d: &Device, target: &Target) -> Result<Vec<Tokens>> {
let take = match *target {
Target::CortexM => Some(Ident::new("cortex_m")),
Target::Msp430 => Some(Ident::new("msp430")),
Target::RISCV => Some(Ident::new("riscv")),
Target::None => None,
}.map(|krate| {
quote! {
Expand Down
23 changes: 23 additions & 0 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
interrupts.sort_by_key(|i| i.value);

let mut arms = vec![];
let mut from_arms = vec![];
let mut elements = vec![];
let mut names = vec![];
let mut variants = vec![];
Expand Down Expand Up @@ -60,6 +61,10 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
Interrupt::#name_uc => #value,
});

from_arms.push(quote! {
#value => Ok(Interrupt::#name_uc),
});

elements.push(quote!(Some(#name_uc)));
names.push(name_uc);
}
Expand Down Expand Up @@ -169,6 +174,7 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
];
});
}
Target::RISCV => {}
Target::None => {}
}

Expand All @@ -186,6 +192,23 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
}
}
}

use core::convert::TryFrom;

#[derive(Debug, Copy, Clone)]
pub struct TryFromInterruptError(());

impl TryFrom<u8> for Interrupt {
type Error = TryFromInterruptError;

#[inline]
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
#(#from_arms)*
_ => Err(TryFromInterruptError(())),
}
}
}
});

if *target != Target::None {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use errors::*;
pub enum Target {
CortexM,
Msp430,
RISCV,
None,
}

Expand All @@ -33,6 +34,7 @@ impl Target {
Ok(match s {
"cortex-m" => Target::CortexM,
"msp430" => Target::Msp430,
"riscv" => Target::RISCV,
"none" => Target::None,
_ => bail!("unknown target {}", s),
})
Expand Down