This repository was archived by the owner on Aug 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,8 @@ thread_local! {
108
108
static TLS : RefCell <u32 > = RefCell :: new( 13 ) ;
109
109
}
110
110
111
+ static CS : esp_idf_hal:: task:: CriticalSection = esp_idf_hal:: task:: CriticalSection :: new ( ) ;
112
+
111
113
fn main ( ) -> Result < ( ) > {
112
114
esp_idf_sys:: link_patches ( ) ;
113
115
@@ -133,6 +135,48 @@ fn main() -> Result<()> {
133
135
#[ allow( unused) ]
134
136
let pins = peripherals. pins ;
135
137
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
+
136
180
#[ allow( unused) ]
137
181
let sysloop = EspSystemEventLoop :: take ( ) ?;
138
182
You can’t perform that action at this time.
0 commit comments