Interrupt Controller#

NVIC (Nested Vector Interrupt Controller)#

Defined in namespace hal::cortex_m

#include <libhal-arm-mcu/interrupt.hpp>

enum class hal::cortex_m::irq : irq_t#

IRQ numbers for core processor interrupts.

All core IRQs are enabled by default.

Values:

enumerator top_of_stack#
enumerator reset#
enumerator non_maskable_interrupt#
enumerator hard_fault#
enumerator memory_management_fault#
enumerator bus_fault#
enumerator usage_fault#
enumerator reserve7#
enumerator reserve8#
enumerator reserve9#
enumerator reserve10#
enumerator software_call#
enumerator reserve12#
enumerator reserve13#
enumerator pend_sv#
enumerator systick#
void hal::cortex_m::default_interrupt_handler()#

A default interrupt handler that loops forever.

void hal::cortex_m::hard_fault_handler()#

Default hard fault handler.

Used by developers in debug mode to see if they landed in the default hard fault handler.

void hal::cortex_m::memory_management_fault_handler()#

Default memory management fault handler.

Used by developers in debug mode to see if they landed in the default memory management fault handler.

void hal::cortex_m::bus_fault_handler()#

Default bus fault handler.

Used by developers in debug mode to see if they landed in the default bus fault handler.

void hal::cortex_m::usage_fault_handler()#

Default usage fault handler.

Used by developers in debug mode to see if they landed in the default usage fault handler.

void hal::cortex_m::revert_interrupt_vector_table()#

Sets the interrupt vector table back to a form where it can be initialized again().

Recommended to never call this function in your application. If it is called, it should be well documented why this choice was necessary.

Will clear all pending interrupts and sets the internal state to uninitialized. This call is dangerous and should only be done before any drivers depend on their interrupts to function.

void hal::cortex_m::initialize_interrupts(std::span<interrupt_pointer> p_vector_table)#

Initialize the interrupt vector table.

Using this function directly is not recommended. Use the templated version of this in drivers and in application code. Only use this if you need to control precisely where the interrupt vector table is located.

If the input vector table has the same address as the previous vector table, then this function does nothing.

This function does the following:

  • Sets the default for hard_fault to hard_fault_handler

  • Sets the default for memory_management_fault to memory_management_fault_handler

  • Sets the default for bus_fault to bus_fault_handler

  • Sets the default for usage_fault to usage_fault_handler

  • Sets the default for everything else to nop

  • Assign a global vector_table span to the the passed vector table.

  • Relocates the system’s interrupt vector table away from the hard coded vector table in ROM/Flash memory to the table passed in.

All default functions contain an infinite loop and it is encouraged to swap these out if you plan to use the interrupts.

Parameters:

p_vector_table – - must have length > 16 to accommodate the core interrupts.

bool hal::cortex_m::interrupt_vector_table_initialized()#

Returns true if the interrupt vector table has been initialized.

This API should NOT be called by platform peripheral drivers. Those drivers should call initialize_interrupts<irq::max>(). That API will do the check for you and will either return early if interrupts are already enabled. There is no reason to call this API directly then call initialize_interrupts<irq::max>(). That is unecessary cycles.

This API should be used by cortex m drivers like systick, which cannot know the size of the interrupt vector table as it is different for each microcontroller.

Returns:

true - interrupt vector table is initialized

Returns:

false - interrupt vector table is not initialized

void hal::cortex_m::disable_all_interrupts()#

Disable all interrupts.

void hal::cortex_m::enable_all_interrupts()#

Re-enable all interrupts.

std::span<interrupt_pointer> const hal::cortex_m::get_vector_table()#

Get a reference to interrupt vector table object.

Returns:

const std::span<interrupt_pointer> - interrupt vector table

void hal::cortex_m::enable_interrupt(irq_t p_irq, interrupt_pointer p_handler)#

Enable interrupt and set the service routine handler.

If the irq is not valid, meaning it is outside of the range of the interrupt vector table, then nothing happens.

Using this with a core cortex-m interrupt will assign its handler.

Parameters:
  • p_irq – - irq to enable. If the value is beyond the range of the interrupt vector table, then this function does nothing.

  • p_handler – - the interrupt service routine handler to be executed when the hardware interrupt is fired.

void hal::cortex_m::disable_interrupt(irq_t p_irq)#

disable interrupt and set the service routine handler to their default.

This function does nothing if the vector table has not yet been initialized.

Parameters:

p_irq – - irq to disable, if the value is below 0 or out of range then this function does nothing.

bool hal::cortex_m::is_interrupt_enabled(irq_t p_irq)#

determine if a particular interrupt has been enabled.

This is only to determine if that particular entry is enabled, it does not care about what handler is inside.

Parameters:

p_irq – - irq to check.

Returns:

true - the interrupt has been enabled.

Returns:

false - the interrupt is disabled or is invalid.

bool hal::cortex_m::verify_vector_enabled(irq_t p_irq, interrupt_pointer p_handler)#

determine if a particular handler has been put into the interrupt vector table.

Generally used by unit testing code.

Parameters:
  • p_irq – - irq to check

  • p_handler – - the handler to check against. The address of the handler must match what is in the interrupt vector table.

Returns:

true - the handler is equal to the handler in the table

Returns:

false - the handler is not at this index in the table or p_irq is not valid.