This is the documentation for the latest (main) development branch. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

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

  1. Register Hardware Interrupt Vector — Attach a hardware interrupt vector and replace the software vector.

  2. Deregister Hardware Interrupt Vector — Detach a hardware interrupt vector.

  3. Register Software Interrupt Vector — Attach a software interrupt vector and callback function.

  4. Deregister Software Interrupt Vector — Detach a software interrupt vector.

  5. Disable and Save Interrupt State — Disable global interrupts and save the previous state.

  6. Restore Interrupt State — Enable global interrupts using the previously saved state.

  7. Enable Interrupt — Enable a specified interrupt.

  8. Disable Interrupt — Disable a specified interrupt.

  9. Set Interrupt Pending — Set a specified interrupt as pending.

  10. Clear Interrupt Pending — Clear the pending status of a specified interrupt.

  11. Set Wakeup Interrupt — Set a specified interrupt as a wakeup interrupt.

Function Overview

The diagram below illustrates the management of the interrupt vector table.

Interrupt Vector Table Diagram

In interrupt management, a set of software interrupt registration mechanisms is provided. In principle, users only need to register software vectors. However, for performance reasons, an interface for directly writing to the hardware vector table is also provided. Note that when both hardware and software interrupts are registered on the same interrupt vector, the hardware interrupt has a higher priority and will override the corresponding software interrupt, rendering the software interrupt ineffective. If a hardware interrupt is registered first, the software interrupt cannot be registered afterward.

Main Functions

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

Deregister Hardware Interrupt Vector

Call the function wm_drv_irq_detach_hw_vector() to detach a hardware interrupt vector. Example:

wm_drv_irq_detach_hw_vector(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Register Software Interrupt Vector

Call the function wm_drv_irq_attach_sw_vector() to attach a software interrupt vector and callback function. Example:

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

Deregister Software Interrupt Vector

Call the function wm_drv_irq_detach_sw_vector() to detach a software interrupt vector. Example:

wm_drv_irq_detach_sw_vector(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Disable and Save Interrupt State

Call the function wm_drv_irq_save() to disable interrupts and save the previous state. Example:

uint32_t irq_state;
irq_state = wm_drv_irq_save();

This function returns the previous interrupt state, of type uint32_t.

Restore Interrupt State

Call the function wm_drv_irq_restore() to enable interrupts using the previously saved state. Example:

uint32_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. You can use this saved state to restore the interrupt state. The parameter is the previously saved interrupt state, of type uint32_t.

Enable Interrupt

Call the function wm_drv_irq_enable() to enable a specified interrupt. Example:

wm_drv_irq_enable(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Disable Interrupt

Call the function wm_drv_irq_disable() to disable a specified interrupt. Example:

wm_drv_irq_disable(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Set Interrupt Pending

Call the function wm_drv_irq_set_pending() to set a specified interrupt as pending. Example:

wm_drv_irq_set_pending(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Clear Interrupt Pending

Call the function wm_drv_irq_clear_pending() to clear the pending status of a specified interrupt. Example:

wm_drv_irq_clear_pending(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Set Wakeup Interrupt

Call the function wm_drv_irq_set_wakeup() 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. Example:

wm_drv_irq_set_wakeup(WM_IRQ_I2C);

The parameter is the interrupt number, of type wm_irq_no_t.

Application Example

For a basic example of using IRQ, please refer to: examples/peripheral/irq

API Reference

To find IRQ-related APIs, please refer to:

IRQ API Reference