libdragon
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables

Interrupt Controller. More...

Data Structures

struct  _callback_link
 Structure of an interrupt callback. More...
 

Macros

#define PI_CLEAR_INTERRUPT   0x02
 Bit to set to clear the PI interrupt.
 
#define SI_CLEAR_INTERRUPT   0
 Bit to set to clear the SI interrupt.
 
#define SP_CLEAR_INTERRUPT   0x08
 Bit to set to clear the SP interrupt.
 
#define DP_CLEAR_INTERRUPT   0x0800
 Bit to set to clear the DP interrupt.
 
#define AI_CLEAR_INTERRUPT   0
 Bit to set to clear the AI interrupt.
 
#define MAX_RESET_HANDLERS   4
 Maximum number of reset handlers that can be registered.
 

Functions

void __MI_handler (void)
 Handle an MI interrupt.
 
void __TI_handler (void)
 Handle a timer interrupt.
 
void __CART_handler (void)
 Handle a CART interrupt.
 
void __RESET_handler (void)
 Handle a RESET (pre-NMI) interrupt.
 
void register_AI_handler (void(*callback)())
 Register an AI callback.
 
void unregister_AI_handler (void(*callback)())
 Unregister an AI callback.
 
void register_VI_handler (void(*callback)())
 Register a VI callback.
 
void unregister_VI_handler (void(*callback)())
 Unregister a VI callback.
 
void register_PI_handler (void(*callback)())
 Register a PI callback.
 
void unregister_PI_handler (void(*callback)())
 Unegister a PI callback.
 
void register_DP_handler (void(*callback)())
 Register a DP callback.
 
void unregister_DP_handler (void(*callback)())
 Unregister a DP callback.
 
void register_SI_handler (void(*callback)())
 Register a SI callback.
 
void unregister_SI_handler (void(*callback)())
 Unegister a SI callback.
 
void register_SP_handler (void(*callback)())
 Register a SP callback.
 
void unregister_SP_handler (void(*callback)())
 Unegister a SP callback.
 
void register_TI_handler (void(*callback)())
 Register a timer callback.
 
void unregister_TI_handler (void(*callback)())
 Unregister a timer callback.
 
void register_CART_handler (void(*callback)())
 Register a CART interrupt callback.
 
void unregister_CART_handler (void(*callback)())
 Unregister a CART interrupt callback.
 
void register_RESET_handler (void(*callback)())
 Register a handler that will be called when the user presses the RESET button.
 
void unregister_RESET_handler (void(*callback)())
 Unregister a RESET interrupt callback.
 
void set_AI_interrupt (int active)
 Enable or disable the AI interrupt.
 
void set_VI_interrupt (int active, unsigned long line)
 Enable or disable the VI interrupt.
 
void set_PI_interrupt (int active)
 Enable or disable the PI interrupt.
 
void set_DP_interrupt (int active)
 Enable or disable the DP interrupt.
 
void set_SI_interrupt (int active)
 Enable or disable the SI interrupt.
 
void set_SP_interrupt (int active)
 Enable or disable the SP interrupt.
 
void set_TI_interrupt (int active)
 Enable or disable the timer interrupt.
 
void set_CART_interrupt (int active)
 Enable or disable the CART interrupt.
 
void set_RESET_interrupt (int active)
 Enable the RESET interrupt.
 
void __init_interrupts ()
 Initialize the interrupt controller.
 
void disable_interrupts ()
 Disable interrupts systemwide.
 
void enable_interrupts ()
 Enable interrupts systemwide.
 
interrupt_state_t get_interrupts_state ()
 Return the current state of interrupts.
 
uint32_t exception_reset_time (void)
 Check whether the RESET button was pressed and how long we are into the reset process.
 

Variables

struct callback_link * AI_callback = 0
 Linked list of AI callbacks.
 
struct callback_link * VI_callback = 0
 Linked list of VI callbacks.
 
struct callback_link * PI_callback = 0
 Linked list of PI callbacks.
 
struct callback_link * DP_callback = 0
 Linked list of DP callbacks.
 
struct callback_link * SI_callback = 0
 Linked list of SI callbacks.
 
struct callback_link * SP_callback = 0
 Linked list of SP callbacks.
 
struct callback_link * TI_callback = 0
 Linked list of TI callbacks.
 
struct callback_link * CART_callback = 0
 Linked list of CART callbacks.
 

Detailed Description

Interrupt Controller.

Function Documentation

◆ __MI_handler()

void __MI_handler ( void  )

Handle an MI interrupt.

Note
This function handles most of the interrupts on the system as they come through the MI.

◆ __RESET_handler()

void __RESET_handler ( void  )

Handle a RESET (pre-NMI) interrupt.

Calls the handlers registered by register_RESET_handler.

◆ register_AI_handler()

void register_AI_handler ( void(*)()  callback)

Register an AI callback.

Parameters
[in]callbackFunction to call when an AI interrupt occurs

◆ unregister_AI_handler()

void unregister_AI_handler ( void(*)()  callback)

Unregister an AI callback.

Parameters
[in]callbackFunction that should no longer be called on AI interrupts

◆ register_VI_handler()

void register_VI_handler ( void(*)()  callback)

Register a VI callback.

Parameters
[in]callbackFunction to call when a VI interrupt occurs

◆ unregister_VI_handler()

void unregister_VI_handler ( void(*)()  callback)

Unregister a VI callback.

Parameters
[in]callbackFunction that should no longer be called on VI interrupts

◆ register_PI_handler()

void register_PI_handler ( void(*)()  callback)

Register a PI callback.

Parameters
[in]callbackFunction to call when a PI interrupt occurs

◆ unregister_PI_handler()

void unregister_PI_handler ( void(*)()  callback)

Unegister a PI callback.

Parameters
[in]callbackFunction that should no longer be called on PI interrupts

◆ register_DP_handler()

void register_DP_handler ( void(*)()  callback)

Register a DP callback.

Parameters
[in]callbackFunction to call when a DP interrupt occurs

◆ unregister_DP_handler()

void unregister_DP_handler ( void(*)()  callback)

Unregister a DP callback.

Parameters
[in]callbackFunction that should no longer be called on DP interrupts

◆ register_SI_handler()

void register_SI_handler ( void(*)()  callback)

Register a SI callback.

Parameters
[in]callbackFunction to call when a SI interrupt occurs

◆ unregister_SI_handler()

void unregister_SI_handler ( void(*)()  callback)

Unegister a SI callback.

Parameters
[in]callbackFunction that should no longer be called on SI interrupts

◆ register_SP_handler()

void register_SP_handler ( void(*)()  callback)

Register a SP callback.

Parameters
[in]callbackFunction to call when a SP interrupt occurs

◆ unregister_SP_handler()

void unregister_SP_handler ( void(*)()  callback)

Unegister a SP callback.

Parameters
[in]callbackFunction that should no longer be called on SP interrupts

◆ register_TI_handler()

void register_TI_handler ( void(*)()  callback)

Register a timer callback.

The callback will be used when the timer interrupt is triggered by the CPU. This happens when the COP0 COUNT register reaches the same value of the COP0 COMPARE register.

This function is useful only if you want to do your own low level programming of the internal CPU timer and handle the interrupt yourself. In this case, also remember to activate the timer interrupt using set_TI_interrupt.

Note
If you use the timer library (timer_init and new_timer), you do not need to call this function, as timer interrupt are already handled by the timer library.
Parameters
[in]callbackFunction to call when a timer interrupt occurs

◆ unregister_TI_handler()

void unregister_TI_handler ( void(*)()  callback)

Unregister a timer callback.

Note
If you use the timer library (timer_init and new_timer), you do not need to call this function, as timer interrupt are already handled by the timer library.
Parameters
[in]callbackFunction that should no longer be called on timer interrupts

◆ register_CART_handler()

void register_CART_handler ( void(*)()  callback)

Register a CART interrupt callback.

The callback will be called when a CART interrupt is triggered. CART interrupts are interrupts triggered by devices attached to the PI bus (aka CART bus), for instance the 64DD, or the modem cassette.

CART interrupts are disabled by default in libdragon. Use set_CART_interrupt to enable/disable them.

Notice that there is no generic way to acknowledge those interrupts, so if you activate CART interrupts, make also sure to register an handler that acknowledge them, otherwise the interrupt will deadlock the console.

Parameters
[in]callbackFunction that should no longer be called on CART interrupts

◆ unregister_CART_handler()

void unregister_CART_handler ( void(*)()  callback)

Unregister a CART interrupt callback.

Parameters
[in]callbackFunction that should no longer be called on CART interrupts

◆ register_RESET_handler()

void register_RESET_handler ( void(*)()  callback)

Register a handler that will be called when the user presses the RESET button.

The N64 sends an interrupt when the RESET button is pressed, and then actually resets the console after about ~500ms (but less on some models, see RESET_TIME_LENGTH).

Registering a handler can be used to perform a clean reset. Technically, at the hardware level, it is important that the RCP is completely idle when the reset happens, or it might freeze and require a power-cycle to unfreeze. This means that any I/O, audio, video activity must cease before RESET_TIME_LENGTH has elapsed.

This entry point can be used by the game code to basically halts itself and stops issuing commands. Libdragon itself will register handlers to halt internal modules so to provide a basic good reset experience.

Handlers can use exception_reset_time to read how much has passed since the RESET button was pressed.

Parameters
callbackCallback to invoke when the reset button is pressed.
Note
Reset handlers are called under interrupt.

◆ unregister_RESET_handler()

void unregister_RESET_handler ( void(*)()  callback)

Unregister a RESET interrupt callback.

Parameters
[in]callbackFunction that should no longer be called on RESET interrupts

◆ set_AI_interrupt()

void set_AI_interrupt ( int  active)

Enable or disable the AI interrupt.

Parameters
[in]activeFlag to specify whether the AI interrupt should be active

◆ set_VI_interrupt()

void set_VI_interrupt ( int  active,
unsigned long  line 
)

Enable or disable the VI interrupt.

The VI interrupt is generated when the VI begins displaying a specific line of the display output. The line number configured always refers to the final TV output, so it should be either in the range 0..524 (NTSC) or 0..624 (PAL). The vblank happens at the beginning of the display period, in range 0..33 (NTSC) or 0..43 (PAL). A common value used to trigger the interrupt at the beginning of the vblank is 2.

In non-interlaced modes, the VI only draws on even lines, so configuring the interrupt on an odd line causes the interrupt to never trigger. In interlace modes, instead, the VI alternates between even lines and odd lines, so any specific line will trigger an interrupt only every other frame. If you need an interrupt every frame in interlaced mode, you will need to reconfigure the interrupt every frame, alternating between an odd and an even number.

Parameters
[in]activeFlag to specify whether the VI interrupt should be active
[in]lineThe vertical line that causes this interrupt to fire. Ignored when setting the interrupt inactive. This line number refers to the lines in the TV output, and is unrelated to the current resolution.

◆ set_PI_interrupt()

void set_PI_interrupt ( int  active)

Enable or disable the PI interrupt.

Parameters
[in]activeFlag to specify whether the PI interrupt should be active

◆ set_DP_interrupt()

void set_DP_interrupt ( int  active)

Enable or disable the DP interrupt.

Parameters
[in]activeFlag to specify whether the DP interrupt should be active

◆ set_SI_interrupt()

void set_SI_interrupt ( int  active)

Enable or disable the SI interrupt.

Parameters
[in]activeFlag to specify whether the SI interrupt should be active

◆ set_SP_interrupt()

void set_SP_interrupt ( int  active)

Enable or disable the SP interrupt.

Parameters
[in]activeFlag to specify whether the SP interrupt should be active

◆ set_TI_interrupt()

void set_TI_interrupt ( int  active)

Enable or disable the timer interrupt.

Note
If you use the timer library (timer_init and new_timer), you do not need to call this function, as timer interrupt is already handled by the timer library.
Parameters
[in]activeFlag to specify whether the timer interrupt should be active
See also
register_TI_handler

◆ set_CART_interrupt()

void set_CART_interrupt ( int  active)

Enable or disable the CART interrupt.

Parameters
[in]activeFlag to specify whether the CART interrupt should be active
See also
register_CART_handler

◆ set_RESET_interrupt()

void set_RESET_interrupt ( int  active)

Enable the RESET interrupt.

Parameters
[in]activeFlag to specify whether the RESET interrupt should be active
Note
RESET interrupt is active by default.
See also
register_RESET_handler

◆ disable_interrupts()

void disable_interrupts ( )

Disable interrupts systemwide.

Note
If interrupts are already disabled on the system or interrupts have not been initialized, this function will not modify the system state.

◆ enable_interrupts()

void enable_interrupts ( )

Enable interrupts systemwide.

Note
If this is called inside a nested disable call, it will have no effect on the system. Therefore it is safe to nest disable/enable calls. After the least nested enable call, systemwide interrupts will be reenabled.

◆ get_interrupts_state()

interrupt_state_t get_interrupts_state ( )

Return the current state of interrupts.

Return values
INTERRUPTS_UNINITIALIZEDif the interrupt system has not been initialized yet.
INTERRUPTS_DISABLEDif interrupts have been disabled.
INTERRUPTS_ENABLEDif interrupts are currently enabled.

◆ exception_reset_time()

uint32_t exception_reset_time ( void  )

Check whether the RESET button was pressed and how long we are into the reset process.

This function returns how many ticks have elapsed since the user has pressed the RESET button, or 0 if the user has not pressed it.

It can be used by user code to perform actions during the RESET process (see register_RESET_handler). It is also possible to simply poll this value to check at any time if the button has been pressed or not.

The reset process takes about 500ms between the user pressing the RESET button and the CPU being actually reset, though on some consoles it seems to be much less. See RESET_TIME_LENGTH for more information. For the broadest compatibility, please use RESET_TIME_LENGTH to implement the reset logic.

Notice also that the reset process is initiated when the user presses the button, but the reset will not happen until the user releases the button. So keeping the button pressed is a good way to check if the application actually winds down correctly.

Returns
Ticks elapsed since RESET button was pressed, or 0 if the RESET button was not pressed.
See also
register_RESET_handler
RESET_TIME_LENGTH