Don't let a background task call run_background_tasks()
This commit is contained in:
parent
5015036c06
commit
d633928a16
3
main.c
3
main.c
|
@ -43,6 +43,7 @@
|
||||||
#include "lib/mp-readline/readline.h"
|
#include "lib/mp-readline/readline.h"
|
||||||
#include "lib/utils/pyexec.h"
|
#include "lib/utils/pyexec.h"
|
||||||
|
|
||||||
|
#include "background.h"
|
||||||
#include "mpconfigboard.h"
|
#include "mpconfigboard.h"
|
||||||
#include "shared-module/displayio/__init__.h"
|
#include "shared-module/displayio/__init__.h"
|
||||||
#include "supervisor/cpu.h"
|
#include "supervisor/cpu.h"
|
||||||
|
@ -86,6 +87,8 @@ void start_mp(supervisor_allocation* heap) {
|
||||||
reset_status_led();
|
reset_status_led();
|
||||||
autoreload_stop();
|
autoreload_stop();
|
||||||
|
|
||||||
|
background_tasks_reset();
|
||||||
|
|
||||||
// Stack limit should be less than real stack size, so we have a chance
|
// Stack limit should be less than real stack size, so we have a chance
|
||||||
// to recover from limit hit. (Limit is measured in bytes.)
|
// to recover from limit hit. (Limit is measured in bytes.)
|
||||||
mp_stack_ctrl_init();
|
mp_stack_ctrl_init();
|
||||||
|
|
|
@ -42,8 +42,20 @@ volatile uint64_t last_finished_tick = 0;
|
||||||
|
|
||||||
bool stack_ok_so_far = true;
|
bool stack_ok_so_far = true;
|
||||||
|
|
||||||
|
static bool running_background_tasks = false;
|
||||||
|
|
||||||
|
void background_tasks_reset(void) {
|
||||||
|
running_background_tasks = false;
|
||||||
|
}
|
||||||
|
|
||||||
void run_background_tasks(void) {
|
void run_background_tasks(void) {
|
||||||
|
// Don't call ourselves recursively.
|
||||||
|
if (running_background_tasks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
assert_heap_ok();
|
assert_heap_ok();
|
||||||
|
running_background_tasks = true;
|
||||||
|
|
||||||
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
|
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
|
||||||
audio_dma_background();
|
audio_dma_background();
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,6 +68,7 @@ void run_background_tasks(void) {
|
||||||
#endif
|
#endif
|
||||||
filesystem_background();
|
filesystem_background();
|
||||||
usb_background();
|
usb_background();
|
||||||
|
running_background_tasks = false;
|
||||||
assert_heap_ok();
|
assert_heap_ok();
|
||||||
|
|
||||||
last_finished_tick = ticks_ms;
|
last_finished_tick = ticks_ms;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
void background_tasks_reset(void);
|
||||||
void run_background_tasks(void);
|
void run_background_tasks(void);
|
||||||
void run_background_vm_tasks(void);
|
void run_background_vm_tasks(void);
|
||||||
bool background_tasks_ok(void);
|
bool background_tasks_ok(void);
|
||||||
|
|
|
@ -33,13 +33,25 @@
|
||||||
#include "shared-module/displayio/__init__.h"
|
#include "shared-module/displayio/__init__.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool running_background_tasks = false;
|
||||||
|
|
||||||
|
void background_tasks_reset(void) {
|
||||||
|
running_background_tasks = false;
|
||||||
|
}
|
||||||
|
|
||||||
void run_background_tasks(void) {
|
void run_background_tasks(void) {
|
||||||
|
// Don't call ourselves recursively.
|
||||||
|
if (running_background_tasks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
running_background_tasks = true;
|
||||||
filesystem_background();
|
filesystem_background();
|
||||||
usb_background();
|
usb_background();
|
||||||
|
|
||||||
#ifdef CIRCUITPY_DISPLAYIO
|
#ifdef CIRCUITPY_DISPLAYIO
|
||||||
displayio_refresh_displays();
|
displayio_refresh_displays();
|
||||||
#endif
|
#endif
|
||||||
|
running_background_tasks = false;
|
||||||
|
|
||||||
assert_heap_ok();
|
assert_heap_ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_NRF_BACKGROUND_H
|
||||||
|
#define MICROPY_INCLUDED_NRF_BACKGROUND_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
void background_tasks_reset(void);
|
||||||
|
void run_background_tasks(void);
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_NRF_BACKGROUND_H
|
|
@ -47,8 +47,7 @@ bool spi_flash_command(uint8_t command) {
|
||||||
.wipwait = false,
|
.wipwait = false,
|
||||||
.wren = false
|
.wren = false
|
||||||
};
|
};
|
||||||
nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
|
return nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL) == NRFX_SUCCESS;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) {
|
bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) {
|
||||||
|
|
Loading…
Reference in New Issue