Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Macro for implementing vectored interrupts #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

romancardenas
Copy link
Contributor

@romancardenas romancardenas commented Mar 13, 2023

I developed a macro by example to ease the definition of vectored interrupt handlers (see rust-embedded/riscv#158). The macro accepts one pattern with four parameters:

  • INTERRUPT: interrupt callback function to be defined. Usually, it is set to MachineExternal. However, I left this parameter open so you can easily implement vector callbacks for other interrupt types.
  • CLAIM: function to claim/deduce the interrupt source number. Its signature must be fn() -> u16.
  • EXTI_TABLE: path to the table of external interrupt callbacks. This must be a static array of callbacks for the different interrupt sources. Its signature must be static [unsafe extern "C" fn(); N_EXTIS], where N_EXTIS corresponds to the number of different interrupt sources of the target. Note that interrupt number 0 is reserved for "no interrupt". Thus, the callback for interrupt number i must be in the i - 1 index of the array.
  • COMPLETE: function to mark a pending interrupt as complete. Its signature must be fn(u16).

As a simple example, you could do something like this:

// Just a silly example, don't pay attention to the implementation
fn claim() -> u16 {0}
static EXTI: [unsafe extern "C" fn(); 1] = [GPIO0]; 
fn complete(_a: u16) {}

vectored_interrupt!(MachineExternal, claim, EXTI, complete);  // MachineExternal is now vectored
vectored_interrupt!(SupervisorExternal, claim, EXTI, complete);  // same for SupervisorExternal

PACs can provide a feature for implementing this automatically for the users.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant