libdragon
Macros | Enumerations | Functions

Interrupt Controller. More...

Go to the source code of this file.

Macros

#define RESET_TIME_LENGTH   TICKS_FROM_MS(200)
 Guaranteed length of the reset time. More...
 

Enumerations

enum  interrupt_state_t { INTERRUPTS_UNINITIALIZED , INTERRUPTS_DISABLED , INTERRUPTS_ENABLED }
 State of interrupts on the system. More...
 

Functions

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

Detailed Description

Interrupt Controller.

Macro Definition Documentation

◆ RESET_TIME_LENGTH

#define RESET_TIME_LENGTH   TICKS_FROM_MS(200)

Guaranteed length of the reset time.

This is the guaranteed length of the reset time, that is the time that goes between the user pressing the reset button, and the CPU actually resetting. See exception_reset_time for more details.

Note
The general knowledge about this is that the reset time should be 500 ms. Testing on different consoles show that, while most seem to reset after 500 ms, a few EU models reset after 200ms. So we define the timer shorter for greater compatibility.

Function Documentation

◆ register_AI_handler()

void register_AI_handler ( void(*)()  callback)

Register an AI callback.

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

◆ register_VI_handler()

void register_VI_handler ( void(*)()  callback)

Register a VI callback.

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

◆ register_PI_handler()

void register_PI_handler ( void(*)()  callback)

Register a PI callback.

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

◆ register_DP_handler()

void register_DP_handler ( void(*)()  callback)

Register a DP callback.

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

◆ register_SI_handler()

void register_SI_handler ( void(*)()  callback)

Register a SI callback.

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

◆ register_SP_handler()

void register_SP_handler ( void(*)()  callback)

Register a SP callback.

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

◆ 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

◆ 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

◆ 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_AI_handler()

void unregister_AI_handler ( void(*)()  callback)

Unregister an AI callback.

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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.

◆ 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.

◆ 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.