Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches
API Functions

Overview

Function definitions for interrupt handler, exception.

Main Trap Entry Point (Naked).

Hardware vector target (written to mtvec).

void trap_entry (void)
 The Main Trap Entry Point (Naked).

CPU Interrupt Handler.

Handle interrupt from external, timer, software interrupts.

Note
These are weak aliases pointing to irq_handleDefault. The user can override them by defining a function with the same name.
int irq_handleSoft (void)
 Handlers for CPU interrupts (Software).
int irq_handleTimer (void)
 Handlers for CPU interrupts (Timer).
void irq_handleExt (void)
 External Interrupt Handler (PLIC).

Dispatcher/Exception Handlers (Function)

Trap Dispatcher mainly for external interrupt and exception handler.

Note
These are weak aliases pointing to irq_handleDefault. The user can override them by defining a function with the same name.
void trap (void)
 Main C Trap Dispatcher.
void crash (void)
 Fatal Exception Handler.

Function Documentation

◆ crash()

void crash ( void )

#include <mtrap.h>

Fatal Exception Handler.

Warning
Called when the CPU encounters a synchronous fault (e.g., Illegal Instruction, Load/Store Misaligned). Default implementation prints the registers (mepc, mcause) and hangs.

Definition at line 164 of file mtrap.c.

◆ irq_handleExt()

void irq_handleExt ( void )

#include <mtrap.h>

External Interrupt Handler (PLIC).

Called by the trap dispatcher when mcause indicates an External Interrupt. It queries the PLIC for the specific source ID.

Definition at line 125 of file mtrap.c.

◆ irq_handleSoft()

int irq_handleSoft ( void )

#include <mtrap.h>

Handlers for CPU interrupts (Software).

Note
This function points to irq_handleDefault which is also a weak alias. User can override it by defining a function with the same name.

◆ irq_handleTimer()

int irq_handleTimer ( void )

#include <mtrap.h>

Handlers for CPU interrupts (Timer).

Note
This function points to irq_handleDefault which is also a weak alias. User can override it by assigning a function with same name.

◆ trap()

void trap ( void )

#include <mtrap.h>

Main C Trap Dispatcher.

Called by trap_entry after context save. It reads mcause to determine if the event was an Interrupt (Async) or Exception (Sync).

  • Interrupt: Calls irq_handle* functions.
  • Exception: Calls crash().

Definition at line 184 of file mtrap.c.

◆ trap_entry()

void trap_entry ( void )

#include <mtrap.h>

The Main Trap Entry Point (Naked).

This function is the hardware vector target (written to mtvec).

Note
It performs the following:
  • Allocates stack space.
  • Saves all CPU registers (Context Save).
  • Calls trap() (The C dispatcher).
  • Restores all CPU registers (Context Restore).
  • Executes mret (Return from Machine Mode).
Declared naked because it contains pure assembly and must not have a compiler-generated prologue/epilogue.

Definition at line 72 of file mtrap.c.