Skip to content

Don't let a background task call run_background_tasks() #1773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "lib/mp-readline/readline.h"
#include "lib/utils/pyexec.h"

#include "background.h"
#include "mpconfigboard.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/cpu.h"
Expand Down Expand Up @@ -86,6 +87,8 @@ void start_mp(supervisor_allocation* heap) {
reset_status_led();
autoreload_stop();

background_tasks_reset();

// Stack limit should be less than real stack size, so we have a chance
// to recover from limit hit. (Limit is measured in bytes.)
mp_stack_ctrl_init();
Expand Down
13 changes: 13 additions & 0 deletions ports/atmel-samd/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,20 @@ volatile uint64_t last_finished_tick = 0;

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) {
// Don't call ourselves recursively.
if (running_background_tasks) {
return;
}
assert_heap_ok();
running_background_tasks = true;

#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
audio_dma_background();
#endif
Expand All @@ -56,6 +68,7 @@ void run_background_tasks(void) {
#endif
filesystem_background();
usb_background();
running_background_tasks = false;
assert_heap_ok();

last_finished_tick = ticks_ms;
Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/background.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <stdbool.h>

void background_tasks_reset(void);
void run_background_tasks(void);
void run_background_vm_tasks(void);
bool background_tasks_ok(void);
Expand Down
12 changes: 12 additions & 0 deletions ports/nrf/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@
#include "shared-module/displayio/__init__.h"
#endif

static bool running_background_tasks = false;

void background_tasks_reset(void) {
running_background_tasks = false;
}

void run_background_tasks(void) {
// Don't call ourselves recursively.
if (running_background_tasks) {
return;
}
running_background_tasks = true;
filesystem_background();
usb_background();

#ifdef CIRCUITPY_DISPLAYIO
displayio_refresh_displays();
#endif
running_background_tasks = false;

assert_heap_ok();
}
35 changes: 35 additions & 0 deletions ports/nrf/background.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions ports/nrf/supervisor/qspi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ bool spi_flash_command(uint8_t command) {
.wipwait = false,
.wren = false
};
nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
return true;
return nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL) == NRFX_SUCCESS;
}

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