libdragon
|
Interrupt Controller. More...
Data Structures | |
struct | _callback_link |
Structure of an interrupt callback. More... | |
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. | |
Interrupt Controller.
void __MI_handler | ( | void | ) |
Handle an MI interrupt.
void __RESET_handler | ( | void | ) |
Handle a RESET (pre-NMI) interrupt.
Calls the handlers registered by register_RESET_handler.
void register_AI_handler | ( | void(*)() | callback | ) |
Register an AI callback.
[in] | callback | Function to call when an AI interrupt occurs |
void unregister_AI_handler | ( | void(*)() | callback | ) |
Unregister an AI callback.
[in] | callback | Function that should no longer be called on AI interrupts |
void register_VI_handler | ( | void(*)() | callback | ) |
Register a VI callback.
[in] | callback | Function to call when a VI interrupt occurs |
void unregister_VI_handler | ( | void(*)() | callback | ) |
Unregister a VI callback.
[in] | callback | Function that should no longer be called on VI interrupts |
void register_PI_handler | ( | void(*)() | callback | ) |
Register a PI callback.
[in] | callback | Function to call when a PI interrupt occurs |
void unregister_PI_handler | ( | void(*)() | callback | ) |
Unegister a PI callback.
[in] | callback | Function that should no longer be called on PI interrupts |
void register_DP_handler | ( | void(*)() | callback | ) |
Register a DP callback.
[in] | callback | Function to call when a DP interrupt occurs |
void unregister_DP_handler | ( | void(*)() | callback | ) |
Unregister a DP callback.
[in] | callback | Function that should no longer be called on DP interrupts |
void register_SI_handler | ( | void(*)() | callback | ) |
Register a SI callback.
[in] | callback | Function to call when a SI interrupt occurs |
void unregister_SI_handler | ( | void(*)() | callback | ) |
Unegister a SI callback.
[in] | callback | Function that should no longer be called on SI interrupts |
void register_SP_handler | ( | void(*)() | callback | ) |
Register a SP callback.
[in] | callback | Function to call when a SP interrupt occurs |
void unregister_SP_handler | ( | void(*)() | callback | ) |
Unegister a SP callback.
[in] | callback | Function that should no longer be called on SP interrupts |
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.
[in] | callback | Function to call when a timer interrupt occurs |
void unregister_TI_handler | ( | void(*)() | callback | ) |
Unregister a timer callback.
[in] | callback | Function that should no longer be called on timer interrupts |
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.
[in] | callback | Function that should no longer be called on CART interrupts |
void unregister_CART_handler | ( | void(*)() | callback | ) |
Unregister a CART interrupt callback.
[in] | callback | Function that should no longer be called on CART interrupts |
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.
callback | Callback to invoke when the reset button is pressed. |
void unregister_RESET_handler | ( | void(*)() | callback | ) |
Unregister a RESET interrupt callback.
[in] | callback | Function that should no longer be called on RESET interrupts |
void set_AI_interrupt | ( | int | active | ) |
Enable or disable the AI interrupt.
[in] | active | Flag to specify whether the AI interrupt should be active |
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.
[in] | active | Flag to specify whether the VI interrupt should be active |
[in] | line | The 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. |
void set_PI_interrupt | ( | int | active | ) |
Enable or disable the PI interrupt.
[in] | active | Flag to specify whether the PI interrupt should be active |
void set_DP_interrupt | ( | int | active | ) |
Enable or disable the DP interrupt.
[in] | active | Flag to specify whether the DP interrupt should be active |
void set_SI_interrupt | ( | int | active | ) |
Enable or disable the SI interrupt.
[in] | active | Flag to specify whether the SI interrupt should be active |
void set_SP_interrupt | ( | int | active | ) |
Enable or disable the SP interrupt.
[in] | active | Flag to specify whether the SP interrupt should be active |
void set_TI_interrupt | ( | int | active | ) |
Enable or disable the timer interrupt.
[in] | active | Flag to specify whether the timer interrupt should be active |
void set_CART_interrupt | ( | int | active | ) |
Enable or disable the CART interrupt.
[in] | active | Flag to specify whether the CART interrupt should be active |
void set_RESET_interrupt | ( | int | active | ) |
Enable the RESET interrupt.
[in] | active | Flag to specify whether the RESET interrupt should be active |
void disable_interrupts | ( | ) |
Disable interrupts systemwide.
void enable_interrupts | ( | ) |
Enable interrupts systemwide.
interrupt_state_t get_interrupts_state | ( | ) |
Return the current state of interrupts.
INTERRUPTS_UNINITIALIZED | if the interrupt system has not been initialized yet. |
INTERRUPTS_DISABLED | if interrupts have been disabled. |
INTERRUPTS_ENABLED | if interrupts are currently enabled. |
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.