samd: background: Allow monitoring time taken in background task

If you define MONITOR_BACKGROUND_TASK, then a physical output pin
(Metro M4 Express's "SCL" pin by default) will be set HIGH while in
the background task and LOW at other times
This commit is contained in:
Jeff Epler 2019-11-18 10:51:16 -06:00
parent 7f744a2369
commit 40a47d41df
1 changed files with 21 additions and 0 deletions

View File

@ -45,6 +45,23 @@ bool stack_ok_so_far = true;
static bool running_background_tasks = false;
#ifdef MONITOR_BACKGROUND_TASKS
// PB03 is physical pin "SCL" on the Metro M4 express
// so you can't use this code AND an i2c peripheral
// at the same time unless you change this
STATIC void start_background_task(void) {
REG_PORT_DIRSET1 = (1<<3);
REG_PORT_OUTSET1 = (1<<3);
}
STATIC void finish_background_task(void) {
REG_PORT_OUTCLR1 = (1<<3);
}
#else
STATIC void start_background_task(void) {}
STATIC void finish_background_task(void) {}
#endif
void background_tasks_reset(void) {
running_background_tasks = false;
}
@ -54,6 +71,9 @@ void run_background_tasks(void) {
if (running_background_tasks) {
return;
}
start_background_task();
assert_heap_ok();
running_background_tasks = true;
@ -73,6 +93,7 @@ void run_background_tasks(void) {
assert_heap_ok();
last_finished_tick = supervisor_ticks_ms64();
finish_background_task();
}
bool background_tasks_ok(void) {