Skip to content

Commit bc14057

Browse files
committed
Add PL190 interrupt controller example
1 parent fec3e63 commit bc14057

File tree

11 files changed

+126
-4
lines changed

11 files changed

+126
-4
lines changed

examples/versatileab/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cortex-a-rt = { path = "../../cortex-a-rt" }
2121
cortex-r-rt = { path = "../../cortex-r-rt" }
2222
semihosting = { version = "0.1.18", features = ["stdio"] }
2323
libm = "0.2.15"
24+
derive-mmio = "0.6.1"
2425

2526
[build-dependencies]
2627
arm-targets = { version = "0.3.0", path = "../../arm-targets" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Firing interrupt...
2+
Clearing interrupt...
3+
Got interrupted :)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Firing interrupt...
2+
Clearing interrupt...
3+
Got interrupted :)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Firing interrupt...
2+
Clearing interrupt...
3+
Got interrupted :)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Firing interrupt...
2+
Clearing interrupt...
3+
Got interrupted :)

examples/versatileab/src/bin/abt-exception-t32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use core::sync::atomic::{AtomicU32, Ordering};
77

88
use cortex_ar::register::{Dfar, Dfsr, Sctlr};
9+
910
// pull in our start-up code
1011
use versatileab::rt::{entry, exception};
1112

examples/versatileab/src/bin/fpu-test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![no_main]
55

66
// pull in our start-up code
7-
use versatileab;
7+
use versatileab::rt::entry;
88

99
use semihosting::println;
1010

@@ -14,7 +14,7 @@ const MAX_LEN: f32 = BAR.len() as f32;
1414
/// The entry-point to the Rust application.
1515
///
1616
/// It is called by the start-up.
17-
#[versatileab::rt::entry]
17+
#[entry]
1818
fn main() -> ! {
1919
const STEPS: u16 = 100;
2020
const RADIANS_PER_STEP: f32 = (4.0 * core::f32::consts::PI) / (STEPS as f32);

examples/versatileab/src/bin/hello.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#![no_main]
55

66
// pull in our start-up code
7-
use versatileab;
7+
use versatileab::rt::entry;
88

99
use semihosting::println;
1010

1111
/// The entry-point to the Rust application.
1212
///
1313
/// It is called by the start-up.
14-
#[versatileab::rt::entry]
14+
#[entry]
1515
fn my_main() -> ! {
1616
let x = 1.0f64;
1717
let y = x * 2.0;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! PL190 soft interrupt hello-world.
2+
3+
#![no_std]
4+
#![no_main]
5+
6+
use core::sync::atomic::{AtomicU32, Ordering::SeqCst};
7+
8+
// pull in our start-up code
9+
use versatileab::{
10+
rt::{entry, exception},
11+
Pl190,
12+
};
13+
14+
use semihosting::println;
15+
16+
static MARKER: AtomicU32 = AtomicU32::new(0);
17+
18+
/// The entry-point to the Rust application.
19+
///
20+
/// It is called by the start-up.
21+
#[entry]
22+
fn my_main() -> ! {
23+
let mut pl190 = Pl190::create();
24+
25+
// Safety: Not in a critical-section
26+
unsafe {
27+
cortex_ar::interrupt::enable();
28+
}
29+
30+
println!("Firing interrupt...");
31+
pl190.write_vic_intenable(1);
32+
pl190.write_vic_softint(1);
33+
34+
// wait for it
35+
for _ in 0..1_000 {
36+
if MARKER.load(SeqCst) == 1 {
37+
println!("Got interrupted :)");
38+
semihosting::process::exit(0);
39+
}
40+
}
41+
42+
println!("Not interrupted!?");
43+
semihosting::process::exit(1);
44+
}
45+
46+
#[exception(Irq)]
47+
unsafe fn interrupt_handler() {
48+
println!("Clearing interrupt...");
49+
let mut pl190 = Pl190::create();
50+
pl190.write_vic_softintclear(1);
51+
MARKER.store(1, SeqCst);
52+
}

examples/versatileab/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
33
#![no_std]
44

5+
mod pl190;
6+
7+
#[doc(inline)]
8+
pub use pl190::Pl190;
9+
510
// Need this to bring in the start-up function
611
#[cfg(arm_profile = "a")]
712
pub use cortex_a_rt as rt;

0 commit comments

Comments
 (0)