circuitpython/ports/nrf/common-hal
Jeff Epler dc74ae83da nRF: Always use sd_nvic_critical_region calls
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-15 09:26:47 -05:00
..
_bleio nrf: _bleio: clean up timeout calculation 2020-05-19 21:56:39 +08:00
analogio new pin validation routines; don't use mp_const_none if NULL will do 2020-02-28 23:43:04 -05:00
audiobusio nrf: code style 2020-05-13 10:40:41 -05:00
audiopwmio nrf: Ensure ticks enabled while playing audio 2020-05-13 10:40:36 -05:00
board Remove nRF52832 support 2018-12-30 22:49:20 -05:00
busio Compiles! 2020-06-24 12:47:59 -07:00
digitalio Update digitalio api for other ports 2020-05-20 09:23:42 -07:00
displayio First try at lowering the power consumption 2020-03-13 11:12:30 -07:00
microcontroller nRF: Always use sd_nvic_critical_region calls 2020-07-15 09:26:47 -05:00
neopixel_write Fix up end of file and trailing whitespace. 2020-06-03 10:56:35 +01:00
nvm wip 2020-01-03 10:24:07 -05:00
os os.urandom: remove unneeded sleep 2020-01-08 16:48:17 -06:00
pulseio Merge remote-tracking branch 'adafruit/master' into lower_power 2020-04-14 17:14:44 -07:00
rgbmatrix RGBMatrix: finish renaming from Protomatter 2020-04-17 18:44:07 -05:00
rotaryio Fix up end of file and trailing whitespace. 2020-06-03 10:56:35 +01:00
rtc Fix up end of file and trailing whitespace. 2020-06-03 10:56:35 +01:00
supervisor Fix up end of file and trailing whitespace. 2020-06-03 10:56:35 +01:00
watchdog watchdog: use common_hal_watchdog_* pattern 2020-05-27 11:38:29 +08:00