@@ -138,9 +138,12 @@ CoopTask* taskButton;
138
138
#endif
139
139
CoopTask* taskBlink;
140
140
CoopTask* taskText;
141
- CoopTask* taskReport;
142
- #if defined(ESP8266) || defined(ESP32)
141
+ CoopTask* taskReport0;
142
+ CoopTask* taskReport1;
143
+ CoopTask* taskReport2;
144
+ CoopTask* taskReport3;
143
145
CoopSemaphore reportSema (0 );
146
+ #if defined(ESP8266) || defined(ESP32)
144
147
CoopTask* taskWeb;
145
148
#endif
146
149
@@ -152,8 +155,11 @@ void printStackReport(CoopTask* task)
152
155
Serial.println (task->getFreeStack ());
153
156
}
154
157
158
+ uint32_t reportCnt;
159
+ uint32_t start;
160
+
155
161
// to demonstrate that yield and delay work in subroutines
156
- void printReport (uint32_t & reportCnt, uint32_t & start )
162
+ void printReport ()
157
163
{
158
164
// CoopTask::delayMicroseconds(4000000);
159
165
Serial.print (" Loop latency: " );
@@ -164,7 +170,7 @@ void printReport(uint32_t& reportCnt, uint32_t& start)
164
170
#endif
165
171
printStackReport (taskBlink);
166
172
printStackReport (taskText);
167
- printStackReport (taskReport );
173
+ printStackReport (& CoopTask::self () );
168
174
#if defined(ESP8266) || defined(ESP32)
169
175
printStackReport (taskWeb);
170
176
#endif
@@ -173,8 +179,6 @@ void printReport(uint32_t& reportCnt, uint32_t& start)
173
179
start = micros ();
174
180
};
175
181
176
- uint32_t reportCnt = 0 ;
177
-
178
182
void setup ()
179
183
{
180
184
#ifdef ESP8266
@@ -248,30 +252,48 @@ void setup()
248
252
#endif
249
253
if (!*taskText) Serial.println (" CoopTask Text out of stack" );
250
254
251
- taskReport = new CoopTask (F (" Report" ), []()
252
- {
253
- uint32_t start = micros ();
254
- for (;;) {
255
- #if defined(ESP8266) ||defined(ESP32)
256
- if (!reportSema.wait ())
257
- {
258
- Serial.println (" report: wait failed" );
259
- yield ();
260
- continue ;
255
+ auto reportFunc = []()
256
+ {
257
+ for (;;) {
258
+ if (!reportSema.wait ())
259
+ {
260
+ Serial.println (" report: wait failed" );
261
+ yield ();
262
+ continue ;
261
263
}
264
+ Serial.println (CoopTask::self ().name ());
265
+ printReport ();
266
+ }
267
+ return 0 ;
268
+ };
269
+ taskReport0 = new CoopTask (F (" Report0" ), reportFunc
270
+ #if defined(ESP8266) || defined(ESP32)
271
+ , 0x380 );
262
272
#else
263
- CoopTask::sleep ( );
273
+ , 0x68 );
264
274
#endif
265
- printReport (reportCnt, start);
266
- }
267
- return 0 ;
268
- }
275
+ if (!*taskReport0) Serial.println (" CoopTask Report out of stack" );
276
+ taskReport1 = new CoopTask (F (" Report1" ), reportFunc
277
+ #if defined(ESP8266) || defined(ESP32)
278
+ , 0x380 );
279
+ #else
280
+ , 0x68 );
281
+ #endif
282
+ if (!*taskReport1) Serial.println (" CoopTask Report out of stack" );
283
+ taskReport2 = new CoopTask (F (" Report2" ), reportFunc
284
+ #if defined(ESP8266) || defined(ESP32)
285
+ , 0x380 );
286
+ #else
287
+ , 0x68 );
288
+ #endif
289
+ if (!*taskReport2) Serial.println (" CoopTask Report out of stack" );
290
+ taskReport3 = new CoopTask (F (" Report3" ), reportFunc
269
291
#if defined(ESP8266) || defined(ESP32)
270
- , 0x380 );
292
+ , 0x380 );
271
293
#else
272
- , 0x68 );
294
+ , 0x68 );
273
295
#endif
274
- if (!*taskReport ) Serial.println (" CoopTask Report out of stack" );
296
+ if (!*taskReport3 ) Serial.println (" CoopTask Report out of stack" );
275
297
276
298
#if defined(ESP8266) || defined(ESP32)
277
299
taskWeb = new CoopTask (F (" Web" ), []()
@@ -287,54 +309,60 @@ void setup()
287
309
}, 0x800 );
288
310
if (!*taskWeb) Serial.printf (" CoopTask %s out of stack\n " , taskWeb->name ().c_str ());
289
311
290
- // #ifdef ESP8266
291
- // scheduleTask(taskButton);
292
- // scheduleTask(taskBlink);
293
- // scheduleTask(taskText);
294
- // scheduleTask(taskReport);
295
- // scheduleTask(taskWeb);
296
- // #endif
312
+ #ifdef ESP8266
313
+ scheduleTask (taskButton);
314
+ scheduleTask (taskBlink);
315
+ scheduleTask (taskText);
316
+ scheduleTask (taskReport0);
317
+ scheduleTask (taskReport1);
318
+ scheduleTask (taskReport2);
319
+ scheduleTask (taskReport3);
320
+ scheduleTask (taskWeb);
321
+ #endif
297
322
#endif
298
323
299
324
Serial.println (" Scheduler test" );
325
+
326
+ reportCnt = 0 ;
327
+ start = micros ();
300
328
}
301
329
302
- // #ifndef ESP8266
330
+ #ifndef ESP8266
303
331
#if defined(ESP8266) || defined(ESP32)
304
332
uint32_t taskButtonRunnable = 1 ;
305
333
#endif
306
334
uint32_t taskBlinkRunnable = 1 ;
307
335
uint32_t taskTextRunnable = 1 ;
308
- uint32_t taskReportRunnable = 1 ;
336
+ uint32_t taskReportRunnable0 = 1 ;
337
+ uint32_t taskReportRunnable1 = 1 ;
338
+ uint32_t taskReportRunnable2 = 1 ;
339
+ uint32_t taskReportRunnable3 = 1 ;
309
340
#if defined(ESP8266) || defined(ESP32)
310
341
uint32_t taskWebRunnable = 1 ;
311
342
#endif
312
- // #endif
343
+ #endif
313
344
314
345
void loop ()
315
346
{
316
- // #ifndef ESP8266
347
+ #ifndef ESP8266
317
348
#if defined(ESP8266) || defined(ESP32)
318
349
if (taskButtonRunnable != 0 ) taskButtonRunnable = taskButton->run ();
319
350
#endif
320
351
if (taskBlinkRunnable != 0 ) taskBlinkRunnable = taskBlink->run ();
321
352
if (taskTextRunnable != 0 ) taskTextRunnable = taskText->run ();
322
- if (taskReportRunnable != 0 ) taskReportRunnable = taskReport->run ();
353
+ if (taskReportRunnable0 != 0 ) taskReportRunnable0 = taskReport0->run ();
354
+ if (taskReportRunnable1 != 0 ) taskReportRunnable1 = taskReport1->run ();
355
+ if (taskReportRunnable2 != 0 ) taskReportRunnable2 = taskReport2->run ();
356
+ if (taskReportRunnable3 != 0 ) taskReportRunnable3 = taskReport3->run ();
323
357
#if defined(ESP8266) || defined(ESP32)
324
358
if (taskWebRunnable != 0 ) taskWebRunnable = taskWeb->run ();
325
359
#endif
326
- // #endif
360
+ #endif
327
361
328
362
// taskReport sleeps on first run(), and after each report.
329
363
// It resets reportCnt to 0 on each report.
330
364
++reportCnt;
331
365
if (reportCnt > 200000 ) {
332
- #if defined(ESP8266) || defined(ESP32)
333
366
reportSema.post ();
334
- #else
335
- taskReport->sleep (false );
336
- // // paranoid check to prevent taskReport from being duplicate scheduled.
337
- // if (taskReport->sleeping()) scheduleTask(taskReport, true);
338
- #endif
339
367
}
340
368
}
0 commit comments