summaryrefslogtreecommitdiff
path: root/ports/nrf/supervisor
AgeCommit message (Collapse)Author
2021-03-15run code formatting scriptmicroDev
2021-02-12wipDan Halbert
2021-01-06overflowed tick counter needs 64 bits everywhereDan Halbert
2020-12-08Add `board_deinit` for use with sleepScott Shawcroft
This changes lots of files to unify `board.h` across ports. It adds `board_deinit` when CIRCUITPY_ALARM is set. `main.c` uses it to deinit the board before deep sleeping (even when pretending.) Deep sleep is now a two step process for the port. First, the port should prepare to deep sleep based on the given alarms. It should set alarms for both deep and pretend sleep. In particular, the pretend versions should be set immediately so that we don't miss an alarm as we shutdown. These alarms should also wake from `port_idle_until_interrupt` which is used when pretending to deep sleep. Second, when real deep sleeping, `alarm_enter_deep_sleep` is called. The port should set any alarms it didn't during prepare based on data it saved internally during prepare. ESP32-S2 sleep is a bit reorganized to locate more logic with TimeAlarm. This will help it scale to more alarm types. Fixes #3786
2020-11-28Add movable allocation system.Christian Walther
This allows calls to `allocate_memory()` while the VM is running, it will then allocate from the GC heap (unless there is a suitable hole among the supervisor allocations), and when the VM exits and the GC heap is freed, the allocation will be moved to the bottom of the former GC heap and transformed into a proper supervisor allocation. Existing movable allocations will also be moved to defragment the supervisor heap and ensure that the next VM run gets as much memory as possible for the GC heap. By itself this breaks terminalio because it violates the assumption that supervisor_display_move_memory() still has access to an undisturbed heap to copy the tilegrid from. It will work in many cases, but if you're unlucky you will get garbled terminal contents after exiting from the vm run that created the display. This will be fixed in the following commit, which is separate to simplify review.
2020-10-12Finer grained, per port tick lockingScott Shawcroft
Fixes #3504 hopefully.
2020-09-28Add some NORETURN attributesJeff Epler
I have a function where it should be impossible to reach the end, so I put in a safe-mode reset at the bottom: ``` int find_unused_slot(void) { // precondition: you already verified that a slot was available for (int i=0; i<NUM_SLOTS; i++) { if( slot_free(i)) { return i; } } safe_mode_reset(MICROPY_FATAL_ERROR); } ``` However, the compiler still gave a diagnostic, because safe_mode_reset was not declared NORETURN. So I started by teaching the compiler that reset_into_safe_mode never returned. This leads at least one level deeper due to reset_cpu needing to be a NORETURN function. Each port is a little different in this area. I also marked reset_to_bootloader as NORETURN. Additional notes: * stm32's reset_to_bootloader was not implemented, but now does a bare reset. Most stm32s are not fitted with uf2 bootloaders anyway. * ditto cxd56 * esp32s2 did not implement reset_cpu at all. I used esp_restart(). (not tested) * litex did not implement reset_cpu at all. I used reboot_ctrl_write. But notably this is what reset_to_bootloader already did, so one or the other must be incorrect (not tested). reboot_ctrl_write cannot be declared NORETURN, as it returns unless the special value 0xac is written), so a new unreachable forever-loop is added. * cxd56's reset is via a boardctl() call which can't generically be declared NORETURN, so a new unreacahble "for(;;)" forever-loop is added. * In several places, NVIC_SystemReset is redeclared with NORETURN applied. This is accepted just fine by gcc. I chose this as preferable to editing the multiple copies of CMSIS headers where it is normally declared. * the stub safe_mode reset simply aborts. This is used in mpy-cross.
2020-08-30merge from upstreamDan Halbert
2020-08-20merge from upstream; working; includes debug_out code for debugging via ↵Dan Halbert
Saleae for posterity
2020-08-18Split pulseio.PWMOut into pwmioScott Shawcroft
This gives us better granularity when implementing new ports because PWMOut is commonly implemented before PulseIn and PulseOut. Fixes #3211
2020-08-12nrf: Make port build with -Werror=undefJeff Epler
.. build-tested on particle_xenon
2020-08-07dynamically enable or disable QSPI by defaultYihui Xiong
2020-08-06add qspi_disable()Yihui Xiong
2020-08-05adjustYihui Xiong
2020-08-05add an option to turn off QSPI when sleepYihui Xiong
2020-08-02wip: compilesDan Halbert
2020-07-15supervisor: factor out, Handle USB via background callbackJeff Epler
2020-07-15nRF: Always use sd_nvic_critical_region callsJeff Epler
The motivation for doing this is so that we can allow common_hal_mcu_disable_interrupts in IRQ context, something that works on other ports, but not on nRF with SD enabled. This is because when SD is enabled, calling sd_softdevice_is_enabled in the context of an interrupt with priority 2 or 3 causes a HardFault. We have chosen to give the USB interrupt priority 2 on nRF, the highest priority that is compatible with SD. Since at least SoftDevice s130 v2.0.1, sd_nvic_critical_region_enter/exit have been implemented as inline functions and are safe to call even if softdevice is not enabled. Reference kindly provided by danh: https://devzone.nordicsemi.com/f/nordic-q-a/29553/sd_nvic_critical_region_enter-exit-missing-in-s130-v2 Switching to these as the default/only way to enable/disable interrupts simplifies things, and fixes several problems and potential problems: * Interrupts at priority 2 or 3 could not call common_hal_mcu_disable_interrupts because the call to sd_softdevice_is_enabled would HardFault * Hypothetically, the state of sd_softdevice_is_enabled could change from the disable to the enable call, meaning the calls would not match (__disable_irq() could be balanced with sd_nvic_critical_region_exit). This also fixes a problem I believe would exist if disable() were called twice when SD is enabled. There is a single "is_nested_critical_region" flag, and the second call would set it to 1. Both of the enable() calls that followed would call critical_region_exit(1), and interrupts would not properly be reenabled. In the new version of the code, we use our own nesting_count value to track the intended state, so now nested disable()s only call critical_region_enter() once, only updating is_nested_critical_region once; and only the second enable() call will call critical_region_exit, with the right value of i_n_c_r. Finally, in port_sleep_until_interrupt, if !sd_enabled, we really do need to __disable_irq, rather than using the common_hal_mcu routines; the reason why is documented in a comment.
2020-07-06Add license to some obvious files.Diego Elio Pettenò
2020-06-25hci early wip; refactor supervisor bluetooth.c for nrf: testedDan Halbert
2020-05-27nrf: add ticks (not subticks) to overflow count during resetSean Cross
Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27nrf: port: save rtc value across rebootsSean Cross
As part of the reset process, save the current tick count to an uninitialized memory location. That way, the current tick value will be preserved across reboots. A reboot will cause us to lose a certain number of ticks, depending on how long a reboot takes, however if reboots are infrequent then this will not be a large amount of time lost. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27nrf: reset watchdog as part of port_reset()Sean Cross
Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27nrf: boot into safe mode sometimes for watchdog resetSean Cross
If the watchdog resets the system and we're plugged into USB, boot into safe mode. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-21nrf: port: add memory barrier before wfiSean Cross
ARM recommends issuing a DSB instruction propr to issuing WFI, as it is required on many parts suchas Cortex-M7. This is effectively a no-op on the Cortex-M4 used in most NRF parts, however it ensures that we won't be surprised when new parts come out. See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0321a/BIHICBGB.html for more information. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-21nrf: disable interrupts before running wfiSean Cross
In order to ensure we don't have any outstanding requests, disable interrupts prior to issuing `WFI`. As part of this process, check to see if there are any pending USB requests, and only execute the `WFI` if there is no pending data. This fixes #2855 on NRF. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-20Merge pull request #2932 from simmel-project/nrf-rtc-resetScott Shawcroft
nrf: reset rtc as part of port_reset()
2020-05-20nrf: reset rtc as part of port_reset()Sean Cross
On NRF, the `rtc_reset()` function is never called. As a result, calls to `time.time()` return a cryptic error> ``` >>> import time >>> time.time() '' object has no attribute 'datetime' >>> ``` This is because `MP_STATE_VM(rtc_time_source)` is not initialized due to `rtc_reset()` never being called. If `CIRCUITPY_RTC` is enabled, call `rtc_reset()` as part of the `reset_port()` call. This ensures that `time.time()` works as expected. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-18Merge remote-tracking branch 'adafruit/master' into esp32s2Scott Shawcroft
2020-05-18nrf: port: call common_hal_rtc_init() during initSean Cross
Call the new function to set the RTC, or reset it if the offset is not valid. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-18nrf: port: move saved word into .uninitialized sectionSean Cross
Circuit Python supports saving a single word of data across reboots. Previously, this data was placed immediately following the .bss. However, this appeared to not work, as Circuit Python zeroes out the heap when it starts up, and the heap begins immediately after the .bss. Switch to using the new .uninitialized section in order to store this word across resets. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-18nrf: port: move the heap after .uninitializedSean Cross
Previously, it was placed following .bss. However, now that there is a new section after .bss, the heap must be moved forward. Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-15Add port_fixed_stack for more buildsScott Shawcroft
2020-04-27Merge remote-tracking branch 'adafruit/master' into lower_powerScott Shawcroft
2020-04-26Merge pull request #2805 from tannewt/update_tinyusbScott Shawcroft
Update tinyusb
2020-04-24Remove empty #if and add missing includes.Scott Shawcroft
2020-04-21nrf: supervisor: support building without BUSIOSean Cross
Only initialize i2c, spi, and uart if building with BUSIO. Signed-off-by: Sean Cross <sean@xobs.io>
2020-04-21nrf: make neopixel support optionalSean Cross
Add a conditional around the call to neopixel_write(), allowing us to build for nrf without neopixel support. Signed-off-by: Sean Cross <sean@xobs.io>
2020-04-17Update TinyUSB and add interrupt hooks.Scott Shawcroft
2020-03-13Initial work on SAMDScott Shawcroft
2020-03-13Hopefully fix flash flush and hopefully audio as well.Scott Shawcroft
2020-03-13Fix autoreload, neopixel, monotonic_ns and sleep w/o SDScott Shawcroft
2020-03-13First try at lowering the power consumptionScott Shawcroft
2020-02-28nrf: sqpi_flash: Handle unaligned readsJeff Epler
2020-02-20merge from upstreamDan Halbert
2020-01-29Merge branch 'master' into stm32-meowbithierophect
2020-01-29Move board_init to main.cLucian Copeland
2020-01-18Fix other builds missing new heap bounds functionsScott Shawcroft
2020-01-08add reset of heap to board reset for nrf portRoy Hooper
2019-12-12merge from masterDan Halbert