1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00
LibrePilot/flight/OpenPilot/System/inc
stac 514d46f5b6 freertos: fix RTOS API calls from interrupt level
FreeRTOS has a strict requirement that even interrupt-safe API calls (ie.
those ending in "FromISR") can only be called from ISRs that are at lesser
or equal priorities to configMAX_SYSCALL_INTERRUPT_PRIORITY.  See the
"configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY"
section at:
  http://www.freertos.org/a00110.html

The interrupt numbers used on the Cortex-M3 CPU has a somewhat backward
representation of the interrupt numbers so 255 = lowest priority and
0 = highest priority.

The calculation is further complicated by the STM32 implementation only using
the upper 4 bits of the priority value.  Only 0x00, 0x10, 0x20, ..., 0xE0, 0xF0
represent useful interrupt priorities.

FreeRTOS requires that MAX_SYSCALL and KERNEL interrupt priorities are expressed
as raw unshifted 8-bit values to be programmed directly into the BASEPRI register.

The priority values passed to the NVIC initialization, however, are expected
to be 4-bit values and are shifted up by 4 within NVIC_Init() for you.

The end result is that we need this arrangement:

[highest priority]
   NVIC_0 (Non-maskable-interrupt)
   NVIC_1
   NVIC_2
[Must NOT call FreeRTOS APIs above here]
   configMAX_SYSCALL_INTERRUPT_PRIORITY (now at 48 = 0x30 = NVIC_3)
   PIOS_IRQ_PRIO_HIGHEST (cur. NVIC_4)
   PIOS_IRQ_PRIO_HIGH    (cur. NVIC_5)
   PIOS_IRQ_PRIO_MID     (cur. NVIC_8)
   PIOS_IRQ_PRIO_LOW     (cur. NVIC_12)
   configKERNEL_INTERRUPT_PRIORITY (240 = 0xF0 = NVIC_15)
[lowest priority]

The previous config had configMAX_SYSCALL_INTERRUPT_PRIORITY set at
191 (0xBF) which is effectively NVIC_11.  This was allowing all of
the MID, HIGH and HIGHEST interrupt handlers to preempt the OS in
its critical sections.  Since some of these ISRs were calling
FreeRTOS APIs, this would result in corrupting internal data structures
within the OS.

It should be ok to move the configKERNEL_INTERRUPT_PRIORITY to a higher
priority as long as it is less than configMAX_SYSCALL_INTERRUPT_PRIORITY.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@637 ebee16cc-31ac-478f-84a7-5cbb03baadba
2010-05-18 04:50:38 +00:00
..
alarms.h Flight/Alarms Implemented Alarms library, now checking for stack overflow, out of memory, event and other errors (see the SystemAlarms object). All modules will be reporting their alarms using this library. 2010-04-27 01:55:28 +00:00
op_config.h Update to headers in the flight portion of the code. Just formatting. 2010-03-10 09:12:31 +00:00
openpilot.h Loopback test of HID working. Still a WIP but committing what I have to show progress. 2010-05-04 18:54:43 +00:00
pios_board.h freertos: fix RTOS API calls from interrupt level 2010-05-18 04:50:38 +00:00
pios_config.h OP-22 Flight/PiOS: Spektrum satellite protocol started 2010-05-15 18:22:03 +00:00