Skip to content

Commit d633928

Browse files
committed
Don't let a background task call run_background_tasks()
1 parent 5015036 commit d633928

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "lib/mp-readline/readline.h"
4444
#include "lib/utils/pyexec.h"
4545

46+
#include "background.h"
4647
#include "mpconfigboard.h"
4748
#include "shared-module/displayio/__init__.h"
4849
#include "supervisor/cpu.h"
@@ -86,6 +87,8 @@ void start_mp(supervisor_allocation* heap) {
8687
reset_status_led();
8788
autoreload_stop();
8889

90+
background_tasks_reset();
91+
8992
// Stack limit should be less than real stack size, so we have a chance
9093
// to recover from limit hit. (Limit is measured in bytes.)
9194
mp_stack_ctrl_init();

ports/atmel-samd/background.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,20 @@ volatile uint64_t last_finished_tick = 0;
4242

4343
bool stack_ok_so_far = true;
4444

45+
static bool running_background_tasks = false;
46+
47+
void background_tasks_reset(void) {
48+
running_background_tasks = false;
49+
}
50+
4551
void run_background_tasks(void) {
52+
// Don't call ourselves recursively.
53+
if (running_background_tasks) {
54+
return;
55+
}
4656
assert_heap_ok();
57+
running_background_tasks = true;
58+
4759
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
4860
audio_dma_background();
4961
#endif
@@ -56,6 +68,7 @@ void run_background_tasks(void) {
5668
#endif
5769
filesystem_background();
5870
usb_background();
71+
running_background_tasks = false;
5972
assert_heap_ok();
6073

6174
last_finished_tick = ticks_ms;

ports/atmel-samd/background.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <stdbool.h>
3131

32+
void background_tasks_reset(void);
3233
void run_background_tasks(void);
3334
void run_background_vm_tasks(void);
3435
bool background_tasks_ok(void);

ports/nrf/background.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@
3333
#include "shared-module/displayio/__init__.h"
3434
#endif
3535

36+
static bool running_background_tasks = false;
37+
38+
void background_tasks_reset(void) {
39+
running_background_tasks = false;
40+
}
41+
3642
void run_background_tasks(void) {
43+
// Don't call ourselves recursively.
44+
if (running_background_tasks) {
45+
return;
46+
}
47+
running_background_tasks = true;
3748
filesystem_background();
3849
usb_background();
3950

4051
#ifdef CIRCUITPY_DISPLAYIO
4152
displayio_refresh_displays();
4253
#endif
54+
running_background_tasks = false;
4355

4456
assert_heap_ok();
4557
}

ports/nrf/background.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_NRF_BACKGROUND_H
28+
#define MICROPY_INCLUDED_NRF_BACKGROUND_H
29+
30+
#include <stdbool.h>
31+
32+
void background_tasks_reset(void);
33+
void run_background_tasks(void);
34+
35+
#endif // MICROPY_INCLUDED_NRF_BACKGROUND_H

ports/nrf/supervisor/qspi_flash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ bool spi_flash_command(uint8_t command) {
4747
.wipwait = false,
4848
.wren = false
4949
};
50-
nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
51-
return true;
50+
return nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL) == NRFX_SUCCESS;
5251
}
5352

5453
bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) {

0 commit comments

Comments
 (0)