1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00
LibrePilot/flight/PiOS/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
..
FreeRTOSConfig.h freertos: fix RTOS API calls from interrupt level 2010-05-18 04:50:38 +00:00
pios_adc.h Update to headers in the flight portion of the code. Just formatting. 2010-03-10 09:12:31 +00:00
pios_bmp085.h Updated BMP085 test code. 2010-03-23 04:01:11 +00:00
pios_com.h Flight\Telemetry Implement telemetry settings object, added functions for changing the baud rate in PiOS 2010-05-08 02:44:26 +00:00
pios_debug.h OP-36 PIOS_DEBUG_Assert() function 2010-03-14 10:20:27 +00:00
pios_delay.h Update to headers in the flight portion of the code. Just formatting. 2010-03-10 09:12:31 +00:00
pios_exti.h Add PIOS_EXTI. 2010-03-21 20:23:20 +00:00
pios_gpio.h Add PIOS_GPIO for controlling the auxiliary connections on the OpenPilot board. 2010-03-14 11:59:11 +00:00
pios_hmc5843.h Finalised and verified PIOS_HMC5843 library. 2010-05-15 12:50:05 +00:00
pios_i2c.h More updates to cross-target compatibility. 2010-05-12 08:18:49 +00:00
pios_irq.h Update to headers in the flight portion of the code. Just formatting. 2010-03-10 09:12:31 +00:00
pios_led.h Small changes to random files. 2010-03-03 07:53:15 +00:00
pios_ppm.h Working on the PPM functionality. Getting there but it is still not 100% correct. 2010-03-30 04:48:15 +00:00
pios_pwm.h Added "supervisor" and comments to PIOS_PWM. 2010-03-07 14:19:43 +00:00
pios_sdcard.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
pios_servo.h Added provisions for TurboPWM and other custom servo update rates. 2010-03-03 07:46:40 +00:00
pios_spektrum.h OP-22 Flight/PiOS: Spektrum simple decoder works, getting seven working channels with my DX7 tx 2010-05-16 10:04:07 +00:00
pios_spi.h Update to headers in the flight portion of the code. Just formatting. 2010-03-10 09:12:31 +00:00
pios_sys.h PIOS_LED: Initialise all LED's as off. 2010-03-14 06:47:57 +00:00
pios_usart.h Flight\Telemetry Implement telemetry settings object, added functions for changing the baud rate in PiOS 2010-05-08 02:44:26 +00:00
pios_usb_com.h Added ability to enable and disable PiOS modules. 2010-02-28 06:47:49 +00:00
pios_usb_hid.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_usb.h Update to headers in the flight portion of the code. Just formatting. 2010-03-10 09:12:31 +00:00
stm32f10x_conf.h Added debugging port buffer handling. 2010-03-13 15:37:00 +00:00