IRQ
Introduction
IRQ (Interrupt Request) refers to the interrupt requests from devices. The driver provides a set of functions for managing hardware and software interrupts. This module provides interfaces for registering and deregistering both hardware and software interrupts, enabling and disabling interrupts, and managing the pending status of interrupts.
Function List
Register Hardware Interrupt Vector — Attach a hardware interrupt vector and replace the software vector.
Deregister Hardware Interrupt Vector — Detach a hardware interrupt vector.
Register Software Interrupt Vector — Attach a software interrupt vector and callback function.
Deregister Software Interrupt Vector — Detach a software interrupt vector.
Disable and Save Interrupt State — Disable global interrupts and save the previous state.
Restore Interrupt State — Enable global interrupts using the previously saved state.
Enable Interrupt — Enable a specified interrupt.
Disable Interrupt — Disable a specified interrupt.
Set Interrupt Pending — Set a specified interrupt to the pending state.
Clear Interrupt Pending — Clear the pending state of a specified interrupt.
Set Wakeup Interrupt — Set a specified interrupt as a wakeup interrupt.
Function Overview
The diagram below illustrates the management of the interrupt vector table.
Main Functions
Registering Hardware Interrupt Vector
Call the function
wm_drv_irq_attach_hw_vector()
to register a hardware interrupt vector and replace the software vector. Example:void irq_callback(void) { } wm_drv_irq_attach_hw_vector(WM_IRQ_I2C, irq_callback);The first parameter is the interrupt number. The W800 chip has 32 interrupt numbers, each corresponding to an interrupt source on the W800 chip. The type is
wm_irq_no_t
.The second parameter is the interrupt callback function, of type
wm_drv_hw_irq_handle
.
Detaching a Hardware Interrupt Vector
The function
wm_drv_irq_detach_hw_vector()
is called to detach a hardware interrupt vector. An example is as follows:wm_drv_irq_detach_hw_vector(WM_IRQ_I2C);The parameter is the interrupt number, of type
wm_irq_no_t
.
Registering a Software Interrupt Vector
The function
wm_drv_irq_attach_sw_vector()
is called to attach a software interrupt vector and a callback function. An example is as follows:void irq_callback(void *arg) { } wm_drv_irq_attach_sw_vector(WM_IRQ_I2C, irq_callback, NULL);The first parameter is the interrupt number, of type
wm_irq_no_t
.The second parameter is the interrupt callback function, of type
wm_drv_sw_irq_handle
.The third parameter is user data, of type
void *
.
Detaching a Software Interrupt Vector
The function
wm_drv_irq_detach_sw_vector()
is called to detach a software interrupt vector. An example is as follows:wm_drv_irq_detach_sw_vector(WM_IRQ_I2C);The parameter is the interrupt number, of type
wm_irq_no_t
.
Saving and Disabling Interrupt State
The function
wm_drv_irq_save()
is called to disable interrupts and save the previous state. An example is as follows:uint32_t irq_state; irq_state = wm_drv_irq_save();This function returns the previous interrupt state, of type
uint32_t
.
Restoring Interrupt State
The function
wm_drv_irq_restore()
is called to enable interrupts using the previously saved state. An example is as follows:.. code:: cuint32_t irq_state; irq_state = wm_drv_irq_save();
wm_drv_irq_restore(irq_state);
Here,
irq_state
is used to save the interrupt state, which can then be used to restore the interrupt state. The parameter is the previously saved interrupt state, of typeuint32_t
.
Enabling an Interrupt
The function
wm_drv_irq_enable()
is called to enable a specified interrupt. An example is as follows:wm_drv_irq_enable(WM_IRQ_I2C);The parameter is the interrupt number, of type
wm_irq_no_t
.
Disabling an Interrupt
The function
wm_drv_irq_disable()
is called to disable a specified interrupt. An example is as follows:wm_drv_irq_disable(WM_IRQ_I2C);The parameter is the interrupt number, of type
wm_irq_no_t
.
Setting an Interrupt Pending
The function``wm_drv_irq_set_pending()`` is called to set a specified interrupt to the pending state. An example is as follows:
wm_drv_irq_set_pending(WM_IRQ_I2C);The parameter is the interrupt number, of type
wm_irq_no_t
.
Clearing an Interrupt Pending
The function
wm_drv_irq_clear_pending()
is called to clear the pending state of a specified interrupt. An example is as follows:.. code:: cwm_drv_irq_clear_pending(WM_IRQ_I2C);
The parameter is the interrupt number, of type
wm_irq_no_t
.
Setting Wakeup Interrupt
The function
wm_drv_irq_set_wakeup()
is called to set a specified interrupt as a wakeup interrupt. When the device is in low-power mode, a wakeup interrupt can trigger the device to resume normal operation from the low-power mode. An example is as follows:wm_drv_irq_set_wakeup(WM_IRQ_I2C);The parameter is the interrupt number, of type
wm_irq_no_t
.
API Reference
To find IRQ-related APIs, please refer to: