-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for unwinding in interrupt handler.
- Loading branch information
Showing
9 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Run Tests for Interrupt Unwinding | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
cookie: | ||
required: true | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
simple: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run test simple | ||
uses: ./.github/workflows/actions/run-test | ||
with: | ||
cookie: ${{ secrets.cookie }} | ||
category: interrupt | ||
sub-category: unwind | ||
test-name: simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Run Tests for Interrupt | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
cookie: | ||
required: true | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
unwind: | ||
uses: ./.github/workflows/unwind.yaml | ||
secrets: | ||
cookie: ${{ secrets.cookie }} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//! | ||
#![no_main] | ||
#![no_std] | ||
#![feature(naked_functions)] | ||
|
||
extern crate alloc; | ||
|
||
use core::sync::atomic::{AtomicUsize, Ordering}; | ||
use hopter::{ | ||
boot::main, | ||
debug::semihosting, | ||
hprintln, | ||
interrupt::handler, | ||
sync::{AllIrqExceptSvc, MutexIrqSafe}, | ||
}; | ||
use stm32f4xx_hal::{ | ||
pac::{Interrupt, Peripherals, TIM2}, | ||
prelude::*, | ||
timer::{CounterUs, Event}, | ||
}; | ||
|
||
static TIMER: MutexIrqSafe<Option<CounterUs<TIM2>>, AllIrqExceptSvc> = MutexIrqSafe::new(None); | ||
|
||
#[main] | ||
fn main(_cp: cortex_m::Peripherals) { | ||
let dp = Peripherals::take().unwrap(); | ||
|
||
// For unknown reason QEMU accepts only the following clock frequency. | ||
let rcc = dp.RCC.constrain(); | ||
let clocks = rcc.cfgr.sysclk(16.MHz()).pclk1(8.MHz()).freeze(); | ||
|
||
let mut timer = dp.TIM2.counter(&clocks); | ||
|
||
// Generate an interrupt when the timer expires. | ||
timer.listen(Event::Update); | ||
|
||
// Enable TIM2 interrupt. | ||
unsafe { | ||
cortex_m::peripheral::NVIC::unmask(Interrupt::TIM2); | ||
} | ||
|
||
// Set the timer to expire every 1 second. | ||
// Empirically when set to 62 seconds the interval is actually | ||
// approximately 1 second. Weird QEMU. | ||
timer.start(62.secs()).unwrap(); | ||
|
||
// Move the timer into the global storage to prevent it from being dropped. | ||
*TIMER.lock() = Some(timer); | ||
} | ||
|
||
/// Get invoked approximately every 1 second. | ||
#[handler(TIM2)] | ||
extern "C" fn tim2_handler() { | ||
static IRQ_CNT: AtomicUsize = AtomicUsize::new(0); | ||
let prev_cnt = IRQ_CNT.fetch_add(1, Ordering::SeqCst); | ||
|
||
let _print_on_drop = PrintOnDrop("Resource released"); | ||
|
||
if prev_cnt % 2 == 0 { | ||
panic!(); | ||
} | ||
|
||
hprintln!("TIM2 IRQ count {}", prev_cnt); | ||
|
||
if prev_cnt >= 5 { | ||
semihosting::terminate(true); | ||
} | ||
} | ||
|
||
struct PrintOnDrop(&'static str); | ||
|
||
impl Drop for PrintOnDrop { | ||
fn drop(&mut self) { | ||
hprintln!("{}", self.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Resource released | ||
TIM2 IRQ count 1 | ||
Resource released | ||
Resource released | ||
TIM2 IRQ count 3 | ||
Resource released | ||
Resource released | ||
TIM2 IRQ count 5 |