Skip to content

Commit 4397640

Browse files
Merge #527
527: add device.x for riscv targets, and provides __EXTERNAL_INTERRUPTS r=therealprof a=allexoll This PR is a proposal to address #526 . `__EXTERNAL_INTERRUPTS` is the symbol used since `__INTERRUPTS` is used by [riscv-rt](https://github.com/rust-embedded/riscv-rt/blob/47ece5f5163a2e38ce5e4685b5d3145713d7954a/src/lib.rs#L505) I think it fits because the peripheral interrupts are supposed to be pending through the external interrupt. This provides hals with information to manage interrupt request. either through a PLIC or trough the vectored interrupt when that is implemented (in [riscv-rt](https://github.com/rust-embedded/riscv-rt/issues/1) i suppose). Remarks welcome Co-authored-by: Alexis Marquet <[email protected]>
2 parents 8b373fa + 7ecdfb1 commit 4397640

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Support for device.x generation for riscv targets and `__EXTERNAL_INTERRUPTS` vector table
11+
1012
## [v0.19.0] - 2021-05-26
1113

1214
### Added

src/generate/interrupt.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,31 @@ pub fn render(
125125
];
126126
});
127127
}
128-
Target::RISCV => {}
128+
Target::RISCV => {
129+
for name in &names {
130+
writeln!(device_x, "PROVIDE({} = DefaultHandler);", name)?;
131+
}
132+
133+
root.extend(quote! {
134+
#[cfg(feature = "rt")]
135+
extern "C" {
136+
#(fn #names();)*
137+
}
138+
139+
#[doc(hidden)]
140+
pub union Vector {
141+
pub _handler: unsafe extern "C" fn(),
142+
pub _reserved: usize,
143+
}
144+
145+
#[cfg(feature = "rt")]
146+
#[doc(hidden)]
147+
#[no_mangle]
148+
pub static __EXTERNAL_INTERRUPTS: [Vector; #n] = [
149+
#elements
150+
];
151+
});
152+
}
129153
Target::XtensaLX => {
130154
for name in &names {
131155
writeln!(device_x, "PROVIDE({} = DefaultHandler);", name)?;

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ fn run() -> Result<()> {
160160
file.write_all(data.as_ref())
161161
.expect("Could not write code to lib.rs");
162162

163-
if target == Target::CortexM || target == Target::Msp430 || target == Target::XtensaLX {
163+
if target == Target::CortexM
164+
|| target == Target::Msp430
165+
|| target == Target::XtensaLX
166+
|| target == Target::RISCV
167+
{
164168
writeln!(File::create(path.join("device.x"))?, "{}", device_x)?;
165169
writeln!(File::create(path.join("build.rs"))?, "{}", build_rs())?;
166170
}

0 commit comments

Comments
 (0)