STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
NVIC

Interrupt enable, pending and priority control. More...

Collaboration diagram for NVIC:

Macros

#define NVIC_PRIORITY_MAX   ((1U << NVIC_PRIO_BITS) - 1U)
 Lowest-urgency priority value: 15, from NVIC_PRIO_BITS implemented bits.

Functions

DRIVER_MUST_CHECK DriverStatus_e nvicEnableIrq (NvicRegisters_t *nvic, IRQn_e irqn)
 Enable a device interrupt.
DRIVER_MUST_CHECK DriverStatus_e nvicDisableIrq (NvicRegisters_t *nvic, IRQn_e irqn)
 Disable a device interrupt.
DRIVER_MUST_CHECK DriverStatus_e nvicSetPending (NvicRegisters_t *nvic, IRQn_e irqn)
 Make a device interrupt pending (ISPR).
DRIVER_MUST_CHECK DriverStatus_e nvicClearPending (NvicRegisters_t *nvic, IRQn_e irqn)
 Clear a device interrupt's pending state (ICPR).
DRIVER_MUST_CHECK DriverStatus_e nvicSetPriority (NvicRegisters_t *nvic, IRQn_e irqn, uint32_t priority)
 Set a device interrupt's priority.
DRIVER_MUST_CHECK DriverStatus_e nvicGetPriority (const NvicRegisters_t *nvic, IRQn_e irqn, uint32_t *priority)
 Read a device interrupt's priority, as nvicSetPriority() takes it.
DRIVER_MUST_CHECK DriverStatus_e nvicSetSystemHandlerPriority (ScbRegisters_t *scb, IRQn_e irqn, uint32_t priority)
 Set a configurable system handler's priority (SCB SHPR1-3).
static DriverStatus_e nvicValidateIrq (IRQn_e irqn)
 Accept only a real device interrupt.
static void nvicCompilerBarrier (void)
 Compiler barrier: stops stores being reordered across the ISER write (as CMSIS __NVIC_EnableIRQ() does).
static void nvicSyncBarrier (void)
 DSB then ISB on the target (a compiler barrier on the host), so a disabled interrupt cannot be taken after nvicDisableIrq() returns.
static uint32_t nvicIrqWord (IRQn_e irqn)
 Word index into ISER/ICER/ISPR/ICPR for a validated IRQn.
static uint32_t nvicIrqBit (IRQn_e irqn)
 Bit mask within that word for a validated IRQn.

Detailed Description

Interrupt enable, pending and priority control.

Macro Definition Documentation

◆ NVIC_PRIORITY_MAX

#define NVIC_PRIORITY_MAX   ((1U << NVIC_PRIO_BITS) - 1U)

Lowest-urgency priority value: 15, from NVIC_PRIO_BITS implemented bits.

Definition at line 36 of file nvic.h.

Referenced by nvicSetPriority(), and nvicSetSystemHandlerPriority().

Function Documentation

◆ nvicEnableIrq()

DriverStatus_e nvicEnableIrq ( NvicRegisters_t * nvic,
IRQn_e irqn )

Enable a device interrupt.

Writes only its ISER bit, between compiler barriers, so state set up before the call is not reordered after the enable.

Parameters
nvicNVIC block (e.g. NVIC).
irqnDevice interrupt.
Return values
DRIVER_STATUS_OKEnabled.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is negative, above ::FMPI2C1_Error_IRQn or reserved.

Definition at line 97 of file nvic.c.

References DRIVER_STATUS_OK, NvicRegisters_t::ISER, nvicCompilerBarrier(), nvicEnableIrq(), nvicIrqBit(), nvicIrqWord(), and nvicValidateIrq().

Referenced by nvicEnableIrq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicDisableIrq()

DriverStatus_e nvicDisableIrq ( NvicRegisters_t * nvic,
IRQn_e irqn )

Disable a device interrupt.

Writes its ICER bit, then DSB and ISB. Once this returns the interrupt is not taken, even if it was already pending.

Parameters
nvicNVIC block (e.g. NVIC).
irqnDevice interrupt.
Return values
DRIVER_STATUS_OKDisabled.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is not a valid device interrupt.

Definition at line 111 of file nvic.c.

References DRIVER_STATUS_OK, NvicRegisters_t::ICER, nvicDisableIrq(), nvicIrqBit(), nvicIrqWord(), nvicSyncBarrier(), and nvicValidateIrq().

Referenced by nvicDisableIrq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicSetPending()

DriverStatus_e nvicSetPending ( NvicRegisters_t * nvic,
IRQn_e irqn )

Make a device interrupt pending (ISPR).

Parameters
nvicNVIC block (e.g. NVIC).
irqnDevice interrupt.
Return values
DRIVER_STATUS_OKPending.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is not a valid device interrupt.

Definition at line 124 of file nvic.c.

References DRIVER_STATUS_OK, NvicRegisters_t::ISPR, nvicIrqBit(), nvicIrqWord(), nvicSetPending(), and nvicValidateIrq().

Referenced by nvicSetPending().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicClearPending()

DriverStatus_e nvicClearPending ( NvicRegisters_t * nvic,
IRQn_e irqn )

Clear a device interrupt's pending state (ICPR).

Parameters
nvicNVIC block (e.g. NVIC).
irqnDevice interrupt.
Return values
DRIVER_STATUS_OKCleared.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is not a valid device interrupt.

Definition at line 136 of file nvic.c.

References DRIVER_STATUS_OK, NvicRegisters_t::ICPR, nvicClearPending(), nvicIrqBit(), nvicIrqWord(), and nvicValidateIrq().

Referenced by nvicClearPending().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicSetPriority()

DriverStatus_e nvicSetPriority ( NvicRegisters_t * nvic,
IRQn_e irqn,
uint32_t priority )

Set a device interrupt's priority.

Parameters
nvicNVIC block (e.g. NVIC).
irqnDevice interrupt.
priority0 (most urgent) to NVIC_PRIORITY_MAX.
Return values
DRIVER_STATUS_OKSet.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is not valid, or priority is too large.

Definition at line 148 of file nvic.c.

References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, NvicRegisters_t::IP, NVIC_PRIO_Pos, NVIC_PRIORITY_MAX, nvicSetPriority(), and nvicValidateIrq().

Referenced by nvicSetPriority().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicGetPriority()

DriverStatus_e nvicGetPriority ( const NvicRegisters_t * nvic,
IRQn_e irqn,
uint32_t * priority )

Read a device interrupt's priority, as nvicSetPriority() takes it.

Parameters
nvicNVIC block (e.g. NVIC).
irqnDevice interrupt.
priorityReceives 0 to NVIC_PRIORITY_MAX; written only on success.
Return values
DRIVER_STATUS_OKRead.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is not valid, or priority is NULL.

Definition at line 165 of file nvic.c.

References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, NvicRegisters_t::IP, NVIC_PRIO_Pos, nvicGetPriority(), and nvicValidateIrq().

Referenced by nvicGetPriority().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicSetSystemHandlerPriority()

DriverStatus_e nvicSetSystemHandlerPriority ( ScbRegisters_t * scb,
IRQn_e irqn,
uint32_t priority )

Set a configurable system handler's priority (SCB SHPR1-3).

Changes only that handler's byte; SHPR3 is shared by PendSV and SysTick.

Parameters
scbSCB block (e.g. SCB).
irqn::MemoryManagement_IRQn, ::BusFault_IRQn, ::UsageFault_IRQn, ::SVCall_IRQn, ::PendSV_IRQn or ::SysTick_IRQn.
priority0 (most urgent) to NVIC_PRIORITY_MAX.
Precondition
For PendSV and SysTick: called before SysTick is enabled, so no tick runs at the default priority.
Return values
DRIVER_STATUS_OKSet.
DRIVER_STATUS_ERR_INVALID_PARAMirqn is not one of the six handlers, or priority is too large.
Warning
The SHPR read-modify-write is not atomic; see Concurrency.

Definition at line 182 of file nvic.c.

References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, NVIC_PRIO_Pos, NVIC_PRIORITY_MAX, nvicSetSystemHandlerPriority(), SCB_SHPR1_PRI_4_Msk, SCB_SHPR1_PRI_4_Pos, SCB_SHPR1_PRI_5_Msk, SCB_SHPR1_PRI_5_Pos, SCB_SHPR1_PRI_6_Msk, SCB_SHPR1_PRI_6_Pos, SCB_SHPR2_PRI_11_Msk, SCB_SHPR2_PRI_11_Pos, SCB_SHPR3_PRI_14_Msk, SCB_SHPR3_PRI_14_Pos, SCB_SHPR3_PRI_15_Msk, SCB_SHPR3_PRI_15_Pos, ScbRegisters_t::SHPR1, ScbRegisters_t::SHPR2, and ScbRegisters_t::SHPR3.

Referenced by nvicSetSystemHandlerPriority().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicValidateIrq()

DriverStatus_e nvicValidateIrq ( IRQn_e irqn)
static

Accept only a real device interrupt.

Negative values (system exceptions) and values past ::FMPI2C1_Error_IRQn would index outside the implemented banks. Reserved positions have no vector, so pending one would jump through address 0.

Parameters
irqnCandidate interrupt.
Return values
DRIVER_STATUS_OK0 to ::FMPI2C1_Error_IRQn and not reserved.
DRIVER_STATUS_ERR_INVALID_PARAMOtherwise.

Definition at line 25 of file nvic.c.

References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, and nvicValidateIrq().

Referenced by nvicClearPending(), nvicDisableIrq(), nvicEnableIrq(), nvicGetPriority(), nvicSetPending(), nvicSetPriority(), and nvicValidateIrq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicCompilerBarrier()

void nvicCompilerBarrier ( void )
inlinestatic

Compiler barrier: stops stores being reordered across the ISER write (as CMSIS __NVIC_EnableIRQ() does).

Emits no instruction.

Definition at line 59 of file nvic.c.

References nvicCompilerBarrier().

Referenced by nvicCompilerBarrier(), nvicEnableIrq(), and nvicSyncBarrier().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicSyncBarrier()

void nvicSyncBarrier ( void )
inlinestatic

DSB then ISB on the target (a compiler barrier on the host), so a disabled interrupt cannot be taken after nvicDisableIrq() returns.

Definition at line 68 of file nvic.c.

References nvicCompilerBarrier(), and nvicSyncBarrier().

Referenced by nvicDisableIrq(), and nvicSyncBarrier().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicIrqWord()

uint32_t nvicIrqWord ( IRQn_e irqn)
static

Word index into ISER/ICER/ISPR/ICPR for a validated IRQn.

Parameters
irqnDevice interrupt number, already validated.
Returns
irqn / 32.

Definition at line 82 of file nvic.c.

References nvicIrqWord().

Referenced by nvicClearPending(), nvicDisableIrq(), nvicEnableIrq(), nvicIrqWord(), and nvicSetPending().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nvicIrqBit()

uint32_t nvicIrqBit ( IRQn_e irqn)
static

Bit mask within that word for a validated IRQn.

Parameters
irqnDevice interrupt number, already validated.
Returns
A single set bit at position irqn % 32.

Definition at line 92 of file nvic.c.

References nvicIrqBit().

Referenced by nvicClearPending(), nvicDisableIrq(), nvicEnableIrq(), nvicIrqBit(), and nvicSetPending().

Here is the call graph for this function:
Here is the caller graph for this function: