Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

How to change the priority of an ISR?

Posted by Joe Flowers on December 30, 2012
On page 155 of the "Using The FreeRTOS Real Time Kernel, NXP LPC17xx Edition" 2nd edition book, it says, "Do not use any API functions from an interrupt that has been assigned an interrupt priority above configMAX_SYSCALL_INTERRUPT_PRIORITY."

My question is how can I violate this rule?
If I am reading/understanding this correctly, how can I change the priority of an ISR? Is there more than one way to change this priority?

Thanks!

RE: How to change the priority of an ISR?

Posted by Richard on December 31, 2012
All the (non exception) interrupt priorities can be configured directly by writing to the NVIC (Nested Vectored Interrupt Controller) registers, which are part of the Cortex-M3 core. Working out how to do this directly is however somewhat difficult and required reading the Cortex-M technical reference manuals from ARM (to get the register addresses) and the datasheet from the microcontroller manufacturer (to find which peripheral interrupts map to which NVIC interrupts). Therefore, these days at least, it is extremely rare to try and do this yourself. Instead there are library functions that make the task much easier.

If you are using CMSIS libraries then you can use the NVIC_SetPriority() function. For example on the LPC17xx you can call NVIC_SetPriority(TIMER0_IRQn, configMAX_SYSCALL_INTERRUPT_PRIORITY); to give an interrupt priority the maximum value allowable if it uses a FreeRTOS API function [TIMER_0_IRQn is defined in the CMSIS libraries provided by NXP].

Other manufacturers use different API functions, but the CMSIS version is normally available too.

There are two things that complicate it further (interrupts on the Cortex-M are generally more complex than other CPUs):

1) Different microcontrollers implement a different number priority bits. Again if you are using CMSIS you should have __NVIC_PRIO_BITS defined which tells you how many there are. On the LPC17xx I think it is 4, so priorities can go from 0 (the highest) to 0x0f (the lowest).

2) The priority bits are sub-divided into preemption priority and sub priority. You want all the bits to be assigned to be preemption priority bits, and that is the default in the NXP libraries so you need not worry about that (generally in my experience the libraries from ST are the only ones where this is not the case.

Further reading on the subject if you are feeling brave:
http://www.freertos.org/RTOS-Cortex-M3-M4.html

Regards.

RE: How to change the priority of an ISR?

Posted by Joe Flowers on December 31, 2012
Thanks Richard!

How do we tell what priority an ISR has relative to the other tasks?


RE: How to change the priority of an ISR?

Posted by Richard on December 31, 2012
Don't confuse interrupt priorities with task priorities.

Interrupt priorities are purely a hardware thing. Task priorities are purely a software thing. Tasks have the ability to mask out interrupts, but if interrupts are not masked they will always interrupt a task - even if it is the lowest priority interrupt that is interrupting the highest priority task.

Regards.

RE: How to change the priority of an ISR?

Posted by Joe Flowers on December 31, 2012
So FreeRTOS can mask interrupts with this:

taskENTER_CRITICAL() and taskEXIT_CRITICAL() sections of code.

Are there other FreeRTOS ways of doing this?

Thanks!

RE: How to change the priority of an ISR?

Posted by Richard on December 31, 2012
It is intended that taskENTER_CRITICAL() and taskEXIT_CRITICAL() is the only method used as these count the call nesting depth. For example, if you call ENTER_CRITICAL() twice you also have to call EXIT_CRITICAL() twice before interrupts are unmasked again.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner