Skip to content

Commit fd2b594

Browse files
committed
supervisor: factor supervisor_background_tasks from sundry ports
1 parent 6ee916c commit fd2b594

File tree

21 files changed

+94
-260
lines changed

21 files changed

+94
-260
lines changed

main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ void start_mp(supervisor_allocation* heap) {
101101
reset_status_led();
102102
autoreload_stop();
103103

104-
background_tasks_reset();
105-
106104
// Stack limit should be less than real stack size, so we have a chance
107105
// to recover from limit hit. (Limit is measured in bytes.)
108106
mp_stack_ctrl_init();

ports/atmel-samd/background.c

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,59 +39,21 @@
3939
#include "shared-module/displayio/__init__.h"
4040
#endif
4141

42-
volatile uint64_t last_finished_tick = 0;
43-
44-
bool stack_ok_so_far = true;
45-
46-
static bool running_background_tasks = false;
47-
4842
#ifdef MONITOR_BACKGROUND_TASKS
4943
// PB03 is physical pin "SCL" on the Metro M4 express
5044
// so you can't use this code AND an i2c peripheral
5145
// at the same time unless you change this
52-
STATIC void start_background_task(void) {
46+
void port_start_background_task(void) {
5347
REG_PORT_DIRSET1 = (1<<3);
5448
REG_PORT_OUTSET1 = (1<<3);
5549
}
5650

57-
STATIC void finish_background_task(void) {
51+
void port_finish_background_task(void) {
5852
REG_PORT_OUTCLR1 = (1<<3);
5953
}
6054
#else
61-
STATIC void start_background_task(void) {}
62-
STATIC void finish_background_task(void) {}
55+
void port_start_background_task(void) {}
56+
void port_finish_background_task(void) {}
6357
#endif
6458

65-
void background_tasks_reset(void) {
66-
running_background_tasks = false;
67-
}
68-
69-
void run_background_tasks(void) {
70-
// Don't call ourselves recursively.
71-
if (running_background_tasks) {
72-
return;
73-
}
74-
75-
start_background_task();
76-
77-
assert_heap_ok();
78-
running_background_tasks = true;
79-
80-
#if CIRCUITPY_DISPLAYIO
81-
displayio_background();
82-
#endif
83-
84-
#if CIRCUITPY_NETWORK
85-
network_module_background();
86-
#endif
87-
filesystem_background();
88-
running_background_tasks = false;
89-
assert_heap_ok();
90-
91-
last_finished_tick = port_get_raw_ticks(NULL);
92-
finish_background_task();
93-
}
94-
95-
bool background_tasks_ok(void) {
96-
return port_get_raw_ticks(NULL) - last_finished_tick < 1024;
97-
}
59+
void port_background_task(void) {}

ports/atmel-samd/background.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,4 @@
2929

3030
#include <stdbool.h>
3131

32-
void background_tasks_reset(void);
33-
void run_background_tasks(void);
34-
void run_background_vm_tasks(void);
35-
bool background_tasks_ok(void);
36-
3732
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H

ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "hpl_gclk_config.h"
4747

4848
#include "shared-bindings/time/__init__.h"
49+
#include "supervisor/shared/tick.h"
4950
#include "supervisor/shared/translate.h"
5051

5152
#ifdef SAMD21
@@ -132,7 +133,7 @@ void frequencyin_interrupt_handler(uint8_t index) {
132133
}
133134

134135
// Check if we've reached the upper limit of detection
135-
if (!background_tasks_ok() || self->errored_too_fast) {
136+
if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
136137
self->errored_too_fast = true;
137138
frequencyin_emergency_cancel_capture(i);
138139
}

ports/atmel-samd/common-hal/pulseio/PulseIn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "samd/timers.h"
4343
#include "shared-bindings/microcontroller/__init__.h"
4444
#include "shared-bindings/pulseio/PulseIn.h"
45+
#include "supervisor/shared/tick.h"
4546
#include "supervisor/shared/translate.h"
4647

4748
// This timer is shared amongst all PulseIn objects as a higher resolution clock.
@@ -87,7 +88,7 @@ void pulsein_interrupt_handler(uint8_t channel) {
8788
uint32_t current_count = tc->COUNT16.COUNT.reg;
8889

8990
pulseio_pulsein_obj_t* self = get_eic_channel_data(channel);
90-
if (!background_tasks_ok() || self->errored_too_fast) {
91+
if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
9192
self->errored_too_fast = true;
9293
common_hal_pulseio_pulsein_pause(self);
9394
return;

ports/cxd56/background.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,6 @@
3030
#include "supervisor/filesystem.h"
3131
#include "supervisor/shared/stack.h"
3232

33-
static bool running_background_tasks = false;
34-
35-
void background_tasks_reset(void) {
36-
running_background_tasks = false;
37-
}
38-
39-
void run_background_tasks(void) {
40-
// Don't call ourselves recursively.
41-
if (running_background_tasks) {
42-
return;
43-
}
44-
45-
assert_heap_ok();
46-
running_background_tasks = true;
47-
48-
usb_background();
49-
filesystem_background();
50-
51-
running_background_tasks = false;
52-
assert_heap_ok();
53-
}
33+
void port_background_task(void) {}
34+
void port_start_background_task(void) {}
35+
void port_finish_background_task(void) {}

ports/cxd56/background.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@
2727
#ifndef MICROPY_INCLUDED_CXD56_BACKGROUND_H
2828
#define MICROPY_INCLUDED_CXD56_BACKGROUND_H
2929

30-
void background_tasks_reset(void);
31-
void run_background_tasks(void);
32-
3330
#endif // MICROPY_INCLUDED_CXD56_BACKGROUND_H

ports/esp32s2/background.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,12 @@
3535
#include "shared-module/displayio/__init__.h"
3636
#endif
3737

38-
static bool running_background_tasks = false;
39-
40-
void background_tasks_reset(void) {
41-
running_background_tasks = false;
42-
}
43-
44-
void run_background_tasks(void) {
45-
// Don't call ourselves recursively.
46-
if (running_background_tasks) {
47-
return;
48-
}
4938

39+
void port_background_task(void) {
5040
// Zero delay in case FreeRTOS wants to switch to something else.
5141
vTaskDelay(0);
52-
running_background_tasks = true;
53-
filesystem_background();
42+
}
5443

55-
#if CIRCUITPY_DISPLAYIO
56-
displayio_background();
57-
#endif
58-
running_background_tasks = false;
44+
void port_start_background_task(void) {}
5945

60-
assert_heap_ok();
61-
}
46+
void port_finish_background_task(void) {}

ports/esp32s2/background.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,4 @@
2929

3030
#include <stdbool.h>
3131

32-
void background_tasks_reset(void);
33-
void run_background_tasks(void);
34-
3532
#endif // MICROPY_INCLUDED_ESP32S2_BACKGROUND_H

ports/litex/background.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,6 @@
2929
#include "supervisor/usb.h"
3030
#include "supervisor/shared/stack.h"
3131

32-
#if CIRCUITPY_DISPLAYIO
33-
#include "shared-module/displayio/__init__.h"
34-
#endif
35-
36-
static bool running_background_tasks = false;
37-
38-
void background_tasks_reset(void) {
39-
running_background_tasks = false;
40-
}
41-
42-
void run_background_tasks(void) {
43-
// Don't call ourselves recursively.
44-
if (running_background_tasks) {
45-
return;
46-
}
47-
running_background_tasks = true;
48-
filesystem_background();
49-
50-
#if USB_AVAILABLE
51-
usb_background();
52-
#endif
53-
54-
#if CIRCUITPY_DISPLAYIO
55-
displayio_background();
56-
#endif
57-
running_background_tasks = false;
58-
59-
assert_heap_ok();
60-
}
32+
void port_background_task(void) {}
33+
void port_start_background_task(void) {}
34+
void port_finish_background_task(void) {}

ports/litex/background.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,4 @@
2727
#ifndef MICROPY_INCLUDED_LITEX_BACKGROUND_H
2828
#define MICROPY_INCLUDED_LITEX_BACKGROUND_H
2929

30-
#include <stdbool.h>
31-
32-
void background_tasks_reset(void);
33-
void run_background_tasks(void);
34-
3530
#endif // MICROPY_INCLUDED_LITEX_BACKGROUND_H

ports/mimxrt10xx/background.c

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,13 @@
2424
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
* THE SOFTWARE.
2626
*/
27-
#include "background.h"
2827

29-
//#include "audio_dma.h"
30-
#include "supervisor/filesystem.h"
31-
#include "supervisor/shared/tick.h"
32-
#include "supervisor/usb.h"
33-
34-
#include "py/runtime.h"
35-
#include "shared-module/network/__init__.h"
36-
#include "supervisor/linker.h"
37-
#include "supervisor/shared/stack.h"
38-
39-
#ifdef CIRCUITPY_DISPLAYIO
40-
#include "shared-module/displayio/__init__.h"
41-
#endif
42-
43-
volatile uint64_t last_finished_tick = 0;
44-
45-
bool stack_ok_so_far = true;
46-
47-
static bool running_background_tasks = false;
48-
49-
void background_tasks_reset(void) {
50-
running_background_tasks = false;
51-
}
52-
53-
void PLACE_IN_ITCM(run_background_tasks)(void) {
54-
// Don't call ourselves recursively.
55-
if (running_background_tasks) {
56-
return;
57-
}
58-
assert_heap_ok();
59-
running_background_tasks = true;
28+
#include "supervisor/port.h"
6029

30+
void port_background_task(void) {
6131
#if CIRCUITPY_AUDIOIO || CIRCUITPY_AUDIOBUSIO
6232
audio_dma_background();
6333
#endif
64-
#if CIRCUITPY_DISPLAYIO
65-
displayio_background();
66-
#endif
67-
68-
#if CIRCUITPY_NETWORK
69-
network_module_background();
70-
#endif
71-
filesystem_background();
72-
usb_background();
73-
running_background_tasks = false;
74-
assert_heap_ok();
75-
76-
last_finished_tick = supervisor_ticks_ms64();
77-
}
78-
79-
bool background_tasks_ok(void) {
80-
return supervisor_ticks_ms64() - last_finished_tick < 1000;
8134
}
35+
void port_start_background_task(void) {}
36+
void port_finish_background_task(void) {}

ports/mimxrt10xx/background.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,4 @@
2828
#ifndef MICROPY_INCLUDED_MIMXRT10XX_BACKGROUND_H
2929
#define MICROPY_INCLUDED_MIMXRT10XX_BACKGROUND_H
3030

31-
#include <stdbool.h>
32-
33-
void background_tasks_reset(void);
34-
void run_background_tasks(void);
35-
void run_background_vm_tasks(void);
36-
bool background_tasks_ok(void);
37-
3831
#endif // MICROPY_INCLUDED_MIMXRT10XX_BACKGROUND_H

ports/mimxrt10xx/common-hal/pulseio/PulseIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
// // last ms.
6565
// current_us = 1000 - current_us;
6666
// pulseio_pulsein_obj_t* self = get_eic_channel_data(channel);
67-
// if (!background_tasks_ok() || self->errored_too_fast) {
67+
// if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
6868
// self->errored_too_fast = true;
6969
// common_hal_pulseio_pulsein_pause(self);
7070
// return;

ports/nrf/background.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,14 @@
4646
#include "common-hal/_bleio/bonding.h"
4747
#endif
4848

49-
static bool running_background_tasks = false;
49+
void port_start_background_task(void) {}
50+
void port_finish_background_task(void) {}
5051

51-
void background_tasks_reset(void) {
52-
running_background_tasks = false;
53-
}
54-
55-
void run_background_tasks(void) {
56-
// Don't call ourselves recursively.
57-
if (running_background_tasks) {
58-
return;
59-
}
60-
running_background_tasks = true;
61-
filesystem_background();
52+
void port_background_task(void) {
6253
#if CIRCUITPY_AUDIOPWMIO
6354
audiopwmout_background();
6455
#endif
6556
#if CIRCUITPY_AUDIOBUSIO
6657
i2s_background();
6758
#endif
68-
69-
#if CIRCUITPY_BLEIO
70-
supervisor_bluetooth_background();
71-
bonding_background();
72-
#endif
73-
74-
#if CIRCUITPY_DISPLAYIO
75-
displayio_background();
76-
#endif
77-
running_background_tasks = false;
78-
79-
assert_heap_ok();
8059
}

ports/nrf/background.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,4 @@
2727
#ifndef MICROPY_INCLUDED_NRF_BACKGROUND_H
2828
#define MICROPY_INCLUDED_NRF_BACKGROUND_H
2929

30-
#include <stdbool.h>
31-
32-
void background_tasks_reset(void);
33-
void run_background_tasks(void);
34-
3530
#endif // MICROPY_INCLUDED_NRF_BACKGROUND_H

0 commit comments

Comments
 (0)