Skip to content

Commit a8f06bf

Browse files
committed
add device.x linker script for riscv targets, and provides __EXTERNAL_INTERRUPTS vector table in pacs for device specific interrupt management
1 parent 8b373fa commit a8f06bf

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/generate/interrupt.rs

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