Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 9ff11de

Browse files
committed
CS testing code
1 parent 22e64c0 commit 9ff11de

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/main.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ thread_local! {
108108
static TLS: RefCell<u32> = RefCell::new(13);
109109
}
110110

111+
static CS: esp_idf_hal::task::CriticalSection = esp_idf_hal::task::CriticalSection::new();
112+
111113
fn main() -> Result<()> {
112114
esp_idf_sys::link_patches();
113115

@@ -133,6 +135,48 @@ fn main() -> Result<()> {
133135
#[allow(unused)]
134136
let pins = peripherals.pins;
135137

138+
// If interrupt critical sections work fine, the code below should panic with the IWDT triggering
139+
// {
140+
// info!("Testing interrupt critical sections");
141+
142+
// let mut x = 0;
143+
144+
// esp_idf_hal::interrupt::free(move || {
145+
// for _ in 0..2000000 {
146+
// for _ in 0..2000000 {
147+
// x += 1;
148+
149+
// if x == 1000000 {
150+
// break;
151+
// }
152+
// }
153+
// }
154+
// });
155+
// }
156+
157+
{
158+
info!("Testing critical sections");
159+
160+
{
161+
let th = {
162+
let _guard = CS.enter();
163+
164+
let th = std::thread::spawn(move || {
165+
info!("Waiting for critical section");
166+
let _guard = CS.enter();
167+
168+
info!("Critical section acquired");
169+
});
170+
171+
std::thread::sleep(Duration::from_secs(5));
172+
173+
th
174+
};
175+
176+
th.join().unwrap();
177+
}
178+
}
179+
136180
#[allow(unused)]
137181
let sysloop = EspSystemEventLoop::take()?;
138182

0 commit comments

Comments
 (0)