diff --git a/libraries/AP_HAL_FLYMAPLE/FlymaplePortingNotes.txt b/libraries/AP_HAL_FLYMAPLE/FlymaplePortingNotes.txt index dc8ec860c6..1ac110f832 100644 --- a/libraries/AP_HAL_FLYMAPLE/FlymaplePortingNotes.txt +++ b/libraries/AP_HAL_FLYMAPLE/FlymaplePortingNotes.txt @@ -110,6 +110,29 @@ LIBMAPLE_PATH = $(HOME)/libmaple # Also, the ARM compiler tools MUST be in your current PATH #config.mk END +Interrupt disabling on ARM + +On AVR, ISRs run by default with the global interrupt enable flag disabled, +whereas mainline code runs by default with global interrupt enable flag +*enabled*. Which means that cli()/sei() in an ISR will have a different effect +to cli()sei() in mainline code. Thats why code that *might* run in an ISR must +use the special idiom: so that it restores the flag to the state it was before +the critical block + +On ARM, the global interrupt disable flag PRIMASK is not altered behind your +back by hardware. By default its always clear (ie enabled) even in ISRs. A +different mechanism prevents ISRs from being reinterrupted. This means that +non-nested noInterrupts()/interrupts() will always leave the PRIMASK as it was +(interrupts enabled) when the critical block started, whether in ISRs or +mainline code. + +Conclusion: + +On AVR, cli()/sei() is dangerous both in ISRs *and* when nested. + +On ARM, noInterrupts()/interrupts() is only dangerous when nested. + + Remaining issues: 1. For reasons I do not yet understand, the magnetic heading reported by diff --git a/libraries/AP_HAL_FLYMAPLE/Scheduler.cpp b/libraries/AP_HAL_FLYMAPLE/Scheduler.cpp index 056db34c73..d4e4f40c61 100644 --- a/libraries/AP_HAL_FLYMAPLE/Scheduler.cpp +++ b/libraries/AP_HAL_FLYMAPLE/Scheduler.cpp @@ -1,30 +1,17 @@ -/* - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ -/* - Flymaple port by Mike McCauley - */ -#include - -#if CONFIG_HAL_BOARD == HAL_BOARD_FLYMAPLE - // Scheduler.cpp // // Flymaple Scheduler. // We use systick interrupt for the 1kHz ordinary timers. // We use a slightly higher priority HardwareTimer 2 for the failsafe callbacks // so a hung timer wont prevent the failsafe timer interrupt running +// +// Use of noInterrupts()/interrupts() on FLymaple ARM processor. +// Please see the notes in FlymaplePortingNotes.txt in this directory for +// information about disabling interrupts on Flymaple + +#include + +#if CONFIG_HAL_BOARD == HAL_BOARD_FLYMAPLE #include "Scheduler.h"