Skip to content
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
5 changes: 3 additions & 2 deletions examples/versatileab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ version = "0.0.0"
[dependencies]
aarch32-cpu = { path = "../../aarch32-cpu", features = ["critical-section-single-core"] }
aarch32-rt = { path = "../../aarch32-rt" }
semihosting = { version = "0.1.18", features = ["stdio"] }
libm = "0.2.15"
derive-mmio = "0.6.1"
libm = "0.2.15"
pl190-vic = "0.1.0"
portable-atomic = { version = "1.11.1", features = ["critical-section"] }
semihosting = { version = "0.1.18", features = ["stdio"] }

[build-dependencies]
arm-targets = { version = "0.3.0", path = "../../arm-targets" }
Expand Down
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-armv4t-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-armv5te-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-armv7a-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
15 changes: 15 additions & 0 deletions examples/versatileab/reference/interrupt-armv7a-none-eabihf-dp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Setting up interrupts...
Firing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-armv7a-none-eabihf.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-armv7r-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-armv7r-none-eabihf.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-thumbv4t-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
14 changes: 13 additions & 1 deletion examples/versatileab/reference/interrupt-thumbv5te-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Setting up interrupts...
Firing interrupt...
Clearing interrupt...
> interrupt_handler()
> soft_handler1()
> interrupt_handler()
> soft_handler2()
< soft_handler2()
< interrupt_handler()
< soft_handler1()
< interrupt_handler()
Got interrupted :)
> interrupt_handler()
catchall_handler() fired
< interrupt_handler()
catch all works. All done!
2 changes: 2 additions & 0 deletions examples/versatileab/reference/svc-a32-thumbv4t-none-eabi.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
x = 1, y = 2, z = 3.000
In svc_handler, with arg=0xabcdef
In svc_handler, with arg=0x456789
x = 1, y = 2, z = 3.000
PANIC: PanicInfo {
message: I am an example panic,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
x = 1, y = 2, z = 3.000
In svc_handler, with arg=0xabcdef
In svc_handler, with arg=0x456789
x = 1, y = 2, z = 3.000
PANIC: PanicInfo {
message: I am an example panic,
Expand Down
72 changes: 63 additions & 9 deletions examples/versatileab/src/bin/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,58 @@
use portable_atomic::{AtomicU32, Ordering::SeqCst};

use aarch32_rt::{entry, exception};
use pl190_vic::{InterruptId, Pl190Driver, VectorId};
use semihosting::println;
use versatileab::Pl190;

static MARKER: AtomicU32 = AtomicU32::new(0);

static PL190: Pl190Driver = unsafe { Pl190Driver::new_static(versatileab::PL190_BASE_ADDRESS) };

// We can pick any three interrupt ID values here
const TEST_INTERRUPT1: InterruptId = InterruptId::new(1);
const TEST_INTERRUPT2: InterruptId = InterruptId::new(2);
const TEST_INTERRUPT3: InterruptId = InterruptId::new(3);

// We can pick any two vector ID values here, as long as TEST_VECTOR1 is
// higher than TEST_VECTOR2 (i.e. TEST_VECTOR2 is higher priority than
// TEST_VECTOR1).
const TEST_VECTOR1: VectorId = VectorId::new(7);
const TEST_VECTOR2: VectorId = VectorId::new(4);

/// The entry-point to the Rust application.
///
/// It is called by the start-up.
#[entry]
fn my_main() -> ! {
let mut pl190 = Pl190::create();

// Safety: Not in a critical-section
unsafe {
aarch32_cpu::interrupt::enable();
}

println!("Setting up interrupts...");
PL190.set_handler(TEST_INTERRUPT1, TEST_VECTOR1, Some(soft_handler1));
PL190.set_handler(TEST_INTERRUPT2, TEST_VECTOR2, Some(soft_handler2));
PL190.set_default_handler(catchall_handler);
PL190.enable_interrupt(TEST_INTERRUPT1);
PL190.enable_interrupt(TEST_INTERRUPT2);
PL190.enable_interrupt(TEST_INTERRUPT3);

println!("Firing interrupt...");
pl190.write_vic_intenable(1);
pl190.write_vic_softint(1);
PL190.pend_sw_interrupt(TEST_INTERRUPT1);

// wait for it
for _ in 0..1_000 {
if MARKER.load(SeqCst) == 1 {
println!("Got interrupted :)");
// this one has no handler
PL190.pend_sw_interrupt(TEST_INTERRUPT3);
break;
}
}

for _ in 0..1_000 {
if MARKER.load(SeqCst) == 2 {
println!("catch all works. All done!");
semihosting::process::exit(0);
}
}
Expand All @@ -39,10 +66,37 @@ fn my_main() -> ! {
semihosting::process::exit(1);
}

/// Our low-prio handler re-enables interrupts and triggers a second,
/// higher-priority, handler.
fn soft_handler1() {
unsafe {
aarch32_cpu::interrupt::enable();
}
println!("> soft_handler1()");
PL190.clear_sw_interrupt(TEST_INTERRUPT1);
PL190.pend_sw_interrupt(TEST_INTERRUPT2);
println!("< soft_handler1()");
}

/// Our high-prio handler sets a global flag
fn soft_handler2() {
println!("> soft_handler2()");
PL190.clear_sw_interrupt(TEST_INTERRUPT2);
MARKER.store(1, SeqCst);
println!("< soft_handler2()");
}

/// Our catch-all handler sets a global flag
fn catchall_handler() {
println!("catchall_handler() fired");
PL190.clear_sw_interrupt(TEST_INTERRUPT3);
MARKER.store(2, SeqCst);
}

/// Our IRQ handler asks the PL190 what to do, and does it.
#[exception(Irq)]
unsafe fn interrupt_handler() {
println!("Clearing interrupt...");
let mut pl190 = Pl190::create();
pl190.write_vic_softintclear(1);
MARKER.store(1, SeqCst);
println!("> interrupt_handler()");
PL190.irq_process();
println!("< interrupt_handler()");
}
23 changes: 19 additions & 4 deletions examples/versatileab/src/bin/svc-a32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn main() -> ! {
let y = x + 1;
let z = (y as f64) * 1.5;
println!("x = {}, y = {}, z = {:0.3}", x, y, z);
#[cfg(arm_isa = "a32")]
aarch32_cpu::svc!(0xABCDEF);
do_svc1();
println!("x = {}, y = {}, z = {:0.3}", x, y, z);

panic!("I am an example panic");
}

Expand All @@ -28,7 +28,22 @@ fn svc_handler(arg: u32) {
println!("In svc_handler, with arg=0x{:06x}", arg);
if arg == 0xABCDEF {
// test nested SVC calls
#[cfg(arm_isa = "a32")]
aarch32_cpu::svc!(0x456789);
do_svc2();
}
}

#[cfg_attr(
any(arm_architecture = "v4t", arm_architecture = "v5te"),
instruction_set(arm::a32)
)]
fn do_svc1() {
aarch32_cpu::svc!(0xABCDEF);
}

#[cfg_attr(
any(arm_architecture = "v4t", arm_architecture = "v5te"),
instruction_set(arm::a32)
)]
fn do_svc2() {
aarch32_cpu::svc!(0x456789);
}
6 changes: 2 additions & 4 deletions examples/versatileab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

#![no_std]

mod pl190;

#[doc(inline)]
pub use pl190::Pl190;
/// The base address of our PL190 interrupt controller
pub const PL190_BASE_ADDRESS: usize = 0x1014_0000;

#[cfg(arm_architecture = "v8-r")]
compile_error!("This example/board is not compatible with the ARMv8-R architecture");
Expand Down
51 changes: 0 additions & 51 deletions examples/versatileab/src/pl190.rs

This file was deleted.