Skip to content

Commit ff6165c

Browse files
committed
fix(port_std): handle the interrupt context case in yield_cpu
1 parent 15ceea0 commit ff6165c

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/constance_port_std/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ impl State {
445445
log::trace!("yield_cpu");
446446
assert!(!self.is_cpu_lock_active());
447447

448+
// The dispatcher will automatically run when the current interrupt
449+
// handler returns the control to it
450+
if self.is_interrupt_context() {
451+
return;
452+
}
453+
448454
self.yield_cpu_inner::<System>();
449455
}
450456

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Checks the return codes of disallowed system calls made in an interrupt
2+
//! context.
3+
use constance::{
4+
kernel::{InterruptHandler, InterruptLine, Task},
5+
prelude::*,
6+
};
7+
8+
use super::Driver;
9+
10+
#[derive(Debug)]
11+
pub struct App<System> {
12+
task2: Task<System>,
13+
int: Option<InterruptLine<System>>,
14+
}
15+
16+
impl<System: Kernel> App<System> {
17+
constance::configure! {
18+
pub const fn new<D: Driver<Self>>(_: &mut CfgBuilder<System>) -> Self {
19+
new! { Task<_>, start = task_body1::<System, D>, priority = 1, active = true };
20+
let task2 = new! { Task<_>, start = task_body2::<System, D>, priority = 0 };
21+
22+
let int = if let [int_line, ..] = *D::INTERRUPT_LINES {
23+
unsafe {
24+
new! { InterruptHandler<_>,
25+
line = int_line, start = isr::<System, D>, unmanaged };
26+
}
27+
28+
Some(new! { InterruptLine<_>, line = int_line, enabled = true })
29+
} else {
30+
None
31+
};
32+
33+
App { task2, int }
34+
}
35+
}
36+
}
37+
38+
fn task_body1<System: Kernel, D: Driver<App<System>>>(_: usize) {
39+
let int = if let Some(int) = D::app().int {
40+
int
41+
} else {
42+
log::warn!("No interrupt lines defined, skipping the test");
43+
D::success();
44+
return;
45+
};
46+
47+
int.pend().unwrap();
48+
}
49+
50+
fn isr<System: Kernel, D: Driver<App<System>>>(_: usize) {
51+
D::app().task2.activate().unwrap();
52+
}
53+
54+
fn task_body2<System: Kernel, D: Driver<App<System>>>(_: usize) {
55+
D::success();
56+
}

src/constance_test_suite/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub mod kernel_tests {
148148
(mod interrupt_disallowed_services {}, "interrupt_disallowed_services"),
149149
(mod interrupt_misc {}, "interrupt_misc"),
150150
(mod interrupt_priority {}, "interrupt_priority"),
151+
(mod interrupt_task_activate {}, "interrupt_task_activate"),
151152
(mod priority_boost {}, "priority_boost"),
152153
(mod task_activate_and_dispatch {}, "task_activate_and_dispatch"),
153154
(mod task_activate_and_do_not_dispatch {}, "task_activate_and_do_not_dispatch"),

0 commit comments

Comments
 (0)