Skip to content

Commit 40a47d4

Browse files
committed
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
1 parent 7f744a2 commit 40a47d4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

ports/atmel-samd/background.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ bool stack_ok_so_far = true;
4545

4646
static bool running_background_tasks = false;
4747

48+
#ifdef MONITOR_BACKGROUND_TASKS
49+
// PB03 is physical pin "SCL" on the Metro M4 express
50+
// so you can't use this code AND an i2c peripheral
51+
// at the same time unless you change this
52+
STATIC void start_background_task(void) {
53+
REG_PORT_DIRSET1 = (1<<3);
54+
REG_PORT_OUTSET1 = (1<<3);
55+
}
56+
57+
STATIC void finish_background_task(void) {
58+
REG_PORT_OUTCLR1 = (1<<3);
59+
}
60+
#else
61+
STATIC void start_background_task(void) {}
62+
STATIC void finish_background_task(void) {}
63+
#endif
64+
4865
void background_tasks_reset(void) {
4966
running_background_tasks = false;
5067
}
@@ -54,6 +71,9 @@ void run_background_tasks(void) {
5471
if (running_background_tasks) {
5572
return;
5673
}
74+
75+
start_background_task();
76+
5777
assert_heap_ok();
5878
running_background_tasks = true;
5979

@@ -73,6 +93,7 @@ void run_background_tasks(void) {
7393
assert_heap_ok();
7494

7595
last_finished_tick = supervisor_ticks_ms64();
96+
finish_background_task();
7697
}
7798

7899
bool background_tasks_ok(void) {

0 commit comments

Comments
 (0)