Bird
Raised Fist0
FreeRTOSprogramming~7 mins

FreeRTOS interrupt priority restrictions

Choose your learning style10 modes available
Introduction

FreeRTOS requires certain rules for interrupt priorities to keep the system stable and responsive. These rules help avoid conflicts between interrupts and the FreeRTOS kernel.

When configuring interrupts that interact with FreeRTOS APIs.
When writing interrupt service routines (ISRs) that use FreeRTOS functions.
When setting up the priority levels for hardware interrupts in a FreeRTOS project.
When debugging unexpected behavior caused by interrupt priority conflicts.
When porting FreeRTOS to a new microcontroller or processor architecture.
Syntax
FreeRTOS
/* Example: Setting interrupt priority in FreeRTOS (C) */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 5

void ISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    // Use FreeRTOS API safe for ISRs
    xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

The macro configMAX_SYSCALL_INTERRUPT_PRIORITY defines the highest interrupt priority that can safely call FreeRTOS API functions.

Interrupts with priority numerically equal to or higher (lower urgency) than this can use FreeRTOS APIs; others cannot.

Examples
This ISR runs at a priority allowed to call FreeRTOS API functions safely.
FreeRTOS
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 5

// ISR with safe priority
void Safe_ISR(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
This ISR runs at a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY and must not call FreeRTOS APIs.
FreeRTOS
// ISR with too high priority (numerically lower)
void Unsafe_ISR(void) {
    // Calling FreeRTOS API here can cause issues
    // Do not call FreeRTOS API functions in this ISR
}
Sample Program

This program creates a binary semaphore and a task that waits for it. The ISR safely gives the semaphore using FreeRTOS API functions at a safe interrupt priority.

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include <stdio.h>

#define configMAX_SYSCALL_INTERRUPT_PRIORITY 5

SemaphoreHandle_t xSemaphore;

void Safe_ISR(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

void vTaskFunction(void *pvParameters) {
    for(;;) {
        if(xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) {
            // Semaphore taken, do work
            // For demo, just print
            printf("Semaphore received in task\n");
        }
    }
}

int main(void) {
    xSemaphore = xSemaphoreCreateBinary();
    xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
OutputSuccess
Important Notes

Interrupt priorities in FreeRTOS are often inverted: lower numeric value means higher priority.

Always set configMAX_SYSCALL_INTERRUPT_PRIORITY according to your hardware's priority scheme.

Calling FreeRTOS API functions from interrupts with priority above the allowed limit can cause system crashes or unpredictable behavior.

Summary

FreeRTOS restricts which interrupt priorities can safely call its API.

Use configMAX_SYSCALL_INTERRUPT_PRIORITY to define this limit.

ISRs with priority above this limit must not call FreeRTOS API functions.

Practice

(1/5)
1.

What does configMAX_SYSCALL_INTERRUPT_PRIORITY control in FreeRTOS?

easy
A. The maximum number of interrupts allowed
B. The lowest interrupt priority allowed in the system
C. The highest interrupt priority that can safely call FreeRTOS API functions
D. The priority of the idle task

Solution

  1. Step 1: Understand FreeRTOS interrupt priority limits

    FreeRTOS restricts API calls to interrupts at or below a certain priority level to maintain system stability.
  2. Step 2: Role of configMAX_SYSCALL_INTERRUPT_PRIORITY

    This configuration sets the highest interrupt priority that can safely call FreeRTOS API functions.
  3. Final Answer:

    The highest interrupt priority that can safely call FreeRTOS API functions -> Option C
  4. Quick Check:

    configMAX_SYSCALL_INTERRUPT_PRIORITY = highest safe ISR priority [OK]
Hint: Remember: configMAX_SYSCALL_INTERRUPT_PRIORITY limits safe ISR API calls [OK]
Common Mistakes:
  • Confusing highest with lowest priority
  • Thinking it limits number of interrupts
  • Assuming it sets task priorities
2.

Which of the following is the correct way to define configMAX_SYSCALL_INTERRUPT_PRIORITY in FreeRTOSConfig.h?

#define configMAX_SYSCALL_INTERRUPT_PRIORITY  ( ??? )
easy
A. 0x80 // Mid-level priority
B. 0x00 // Highest priority
C. 0xFF // Lowest priority
D. "5" // Priority as string

Solution

  1. Step 1: Understand priority values in FreeRTOS

    Lower numeric values represent higher priorities; 0x00 is highest, 0xFF is lowest.
  2. Step 2: Correct format for configMAX_SYSCALL_INTERRUPT_PRIORITY

    This macro must be a numeric value representing the highest interrupt priority allowed to call FreeRTOS API, typically a mid-level priority like 0x80.
  3. Final Answer:

    0x80 // Mid-level priority -> Option A
  4. Quick Check:

    Priority value must be numeric, not string [OK]
Hint: Use numeric hex values for priorities, not strings [OK]
Common Mistakes:
  • Using string instead of numeric value
  • Setting priority to 0x00 (too high)
  • Using lowest priority 0xFF which disables API calls
3.

Given configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 0x50, which ISR priority can safely call FreeRTOS API functions?

ISR Priority Options:
A) 0x40
B) 0x50
C) 0x60
D) 0x30
medium
A. 0x40
B. 0x30
C. 0x50
D. 0x60

Solution

  1. Step 1: Compare ISR priorities with configMAX_SYSCALL_INTERRUPT_PRIORITY

    Only ISRs with priority equal or numerically higher (lower urgency) than 0x50 can call FreeRTOS API.
  2. Step 2: Evaluate each option

    0x40 and 0x30 are higher priority (lower number) than 0x50, so cannot call API. 0x50 equals limit, allowed. 0x60 is lower priority (higher number), also allowed.
  3. Final Answer:

    0x50 and 0x60 -> Option D
  4. Quick Check:

    ISR priority must be >= configMAX_SYSCALL_INTERRUPT_PRIORITY [OK]
Hint: ISR priority must be equal or lower urgency than configMAX_SYSCALL_INTERRUPT_PRIORITY [OK]
Common Mistakes:
  • Confusing numeric priority order
  • Allowing higher urgency ISRs to call API
  • Ignoring equal priority as allowed
4.

Identify the error in this ISR code snippet if configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 0x60:

void ISR_Handler(void) {
    NVIC_SetPriority(IRQn, 0x40);
    vTaskNotifyGiveFromISR(taskHandle, NULL);
}
medium
A. ISR priority 0x40 is higher than allowed to call FreeRTOS API
B. vTaskNotifyGiveFromISR cannot be called from ISR
C. NVIC_SetPriority should not be called inside ISR
D. No error, code is correct

Solution

  1. Step 1: Check ISR priority against configMAX_SYSCALL_INTERRUPT_PRIORITY

    Priority 0x40 is higher urgency (lower number) than 0x60, so ISR cannot safely call FreeRTOS API.
  2. Step 2: Analyze API call in ISR

    Calling vTaskNotifyGiveFromISR requires ISR priority at or below 0x60, which is violated here.
  3. Final Answer:

    ISR priority 0x40 is higher than allowed to call FreeRTOS API -> Option A
  4. Quick Check:

    ISR priority must not exceed configMAX_SYSCALL_INTERRUPT_PRIORITY [OK]
Hint: ISR priority must be equal or lower urgency than configMAX_SYSCALL_INTERRUPT_PRIORITY [OK]
Common Mistakes:
  • Ignoring priority set inside ISR
  • Thinking API calls are always allowed in ISR
  • Confusing priority numeric order
5.

You have two ISRs: ISR_A with priority 0x70 and ISR_B with priority 0x40. configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 0x60. Which statement is true?

hard
A. Neither ISR can call FreeRTOS API
B. ISR_A can call FreeRTOS API, ISR_B cannot
C. Both ISRs can call FreeRTOS API safely
D. ISR_B can call FreeRTOS API, ISR_A cannot

Solution

  1. Step 1: Compare ISR priorities with configMAX_SYSCALL_INTERRUPT_PRIORITY

    Only ISRs with priority numerically equal or higher (lower urgency) than 0x60 can call FreeRTOS API.
  2. Step 2: Evaluate ISR_A and ISR_B priorities

    ISR_A priority 0x70 is lower urgency than 0x60, so it can call API. ISR_B priority 0x40 is higher urgency, so it cannot.
  3. Final Answer:

    ISR_A can call FreeRTOS API, ISR_B cannot -> Option B
  4. Quick Check:

    Only ISRs with priority >= configMAX_SYSCALL_INTERRUPT_PRIORITY call API [OK]
Hint: Only ISRs with priority numerically >= configMAX_SYSCALL_INTERRUPT_PRIORITY call API [OK]
Common Mistakes:
  • Assuming higher urgency ISRs can call API
  • Confusing numeric priority order
  • Thinking all ISRs can call API regardless of priority
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard