libparanut
A Hardware Abstraction Layer for ParaNut Architectures.
Exception Module

Functions for controlling the handling of interrupts/exceptions. More...

Collaboration diagram for Exception Module:
void pn_exception_init (void)
 Initializes libparanut internal exception handling. Interrupts (not exceptions in general!) are disabled after. Should be called before using pn_exception_set_handler().
 
int pn_exception_set_handler (void(*handler)(unsigned int cause, unsigned int program_counter, unsigned int mtval), unsigned int exception_code)
 Set your own exception handler. More...
 
void pn_ecall (void)
 Raises an environment call exception. More...
 
void pn_interrupt_enable (void)
 Enables interrupts only. More...
 
void pn_interrupt_disable (void)
 Disables interrupts only. More...
 
void pn_progress_mepc (void)
 Sets program counter of the register which keeps the exception return adress to next instruction. More...
 

Detailed Description

Functions for controlling the handling of interrupts/exceptions.

Why are we calling this exceptions, even though most people would call this an interrupt? Historic reasons. The libparanut was first written for the RISCV implementation of the ParaNut, and the RISCV specification refers to both interrupts and exceptions as exceptions.

Function Documentation

◆ pn_ecall()

void pn_ecall ( void  )

Raises an environment call exception.

Can be called without using pn_exception_init() first.

◆ pn_exception_set_handler()

int pn_exception_set_handler ( void(*)(unsigned int cause, unsigned int program_counter, unsigned int mtval)  handler,
unsigned int  exception_code 
)

Set your own exception handler.

Can be called without using pn_exception_init() first, will not work though.

Already does the work of saving away registers, setting program counter etc. for you. You can just hang in what you want to do.

Attention
For exceptions, the register that contains the adress where execution resumes is set to the faulty instruction that threw the exception. For interrupts, it already points to the instruction where execution should resume. Consider this in your handler. If you need to, use pn_progress_mepc.
Parameters
[in]handleris a function pointer to your exception handler. Will return an error (PN_ERR_PARAM) if NULL is given.
[in]exception_codeis the number that your exception has. You can look up the exception codes in the ParaNut Manual. For interrupts, the value of the most significant bit of the exception code has to be 1. For synchronous exceptions, it has to be 0. This function will return an error (PN_ERR_EXC) if a non implemented value for cause is given.
Returns
Either PN_SUCCESS, PN_ERR_EXC, or PN_ERR_PARAM.

◆ pn_interrupt_disable()

void pn_interrupt_disable ( void  )

Disables interrupts only.

Can be called without using pn_exception_init() first.

◆ pn_interrupt_enable()

void pn_interrupt_enable ( void  )

Enables interrupts only.

Can be called without using pn_exception_init() first.

◆ pn_progress_mepc()

void pn_progress_mepc ( void  )

Sets program counter of the register which keeps the exception return adress to next instruction.

Can be called without using pn_exception_init() first.