1  /*
2   * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3   *
4   * HDF is dual licensed: you can use it either under the terms of
5   * the GPL, or the BSD license, at your option.
6   * See the LICENSE file in the root of this repository for complete details.
7   */
8  
9  /**
10   * @addtogroup OSAL
11   * @{
12   *
13   * @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
14   *
15   * The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
16   * including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
17   * atomic, firmware, and I/O operation modules.
18   *
19   * @since 1.0
20   * @version 1.0
21   */
22  
23  /**
24   * @file osal_irq.h
25   *
26   * @brief Declares interrupt request (IRQ) interfaces and common IRQ trigger modes.
27   *
28   * @since 1.0
29   * @version 1.0
30   */
31  
32  #ifndef OSAL_IRQ_H
33  #define OSAL_IRQ_H
34  
35  #include "hdf_base.h"
36  
37  #ifdef __cplusplus
38  extern "C" {
39  #endif /* __cplusplus */
40  
41  /**
42   * @brief Enumerates interrupt trigger modes.
43   *
44   * @since 1.0
45   * @version 1.0
46   */
47  typedef enum {
48      OSAL_IRQF_TRIGGER_NONE = 0, /**< Edge-triggered is not set */
49      OSAL_IRQF_TRIGGER_RISING = 1, /**< Rising edge triggered */
50      OSAL_IRQF_TRIGGER_FALLING = 2, /**< Falling edge triggered */
51      OSAL_IRQF_TRIGGER_HIGH = 4, /**< High-level triggered */
52      OSAL_IRQF_TRIGGER_LOW = 8, /**< Low-level triggered */
53  } OSAL_IRQ_TRIGGER_MODE;
54  
55  /**
56   * @brief Defines an IRQ type.
57   *
58   * @since 1.0
59   * @version 1.0
60   */
61  typedef uint32_t (*OsalIRQHandle)(uint32_t irqId, void *dev);
62  
63  /**
64   * @brief Registers the function for processing the specified IRQ.
65   *
66   * @param irqId Indicates the IRQ ID.
67   * @param config Indicates the interrupt trigger mode. For details, see {@link OSAL_IRQ_TRIGGER_MODE}.
68   * @param handle Indicates the interrupt processing function.
69   * @param name Indicates the pointer to the device name for registering an IRQ.
70   * @param dev Indicates the pointer to the parameter passed to the interrupt processing function.
71   *
72   * @return Returns a value listed below: \n
73   * HDF_STATUS | Description
74   * ----------------------| -----------------------
75   * HDF_SUCCESS | The operation is successful.
76   * HDF_FAILURE | Failed to invoke the system function to register the IRQ.
77   * HDF_ERR_INVALID_PARAM | Invalid parameter.
78   *
79   * @since 1.0
80   * @version 1.0
81   */
82  int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char *name, void *dev);
83  
84  /**
85   * @brief Unregisters the interrupt processing function so that the system will no longer process the specified IRQ.
86   *
87   * @param irqId Indicates the IRQ ID.
88   * @param dev Indicates the pointer to the parameter passed to the interrupt processing function
89   *        in {@link OsalRegisterIrq}.
90   *
91   * @return Returns a value listed below: \n
92   * HDF_STATUS | Description
93   * ----------------------| -----------------------
94   * HDF_SUCCESS | The operation is successful.
95   * HDF_FAILURE | Failed to invoke the system function to unregister the IRQ.
96   * HDF_ERR_INVALID_PARAM | Invalid parameter.
97   *
98   * @since 1.0
99   * @version 1.0
100   */
101  int32_t OsalUnregisterIrq(uint32_t irqId, void *dev);
102  
103  /**
104   * @brief Enables the processing of the specified IRQ.
105   *
106   * @param irqId Indicates the IRQ ID.
107   *
108   * @return Returns a value listed below: \n
109   * HDF_STATUS | Description
110   * ----------------------| -----------------------
111   * HDF_SUCCESS | The operation is successful.
112   * HDF_ERR_INVALID_PARAM | Invalid parameter.
113   *
114   * @since 1.0
115   * @version 1.0
116   */
117  int32_t OsalEnableIrq(uint32_t irqId);
118  
119  /**
120   * @brief Disables the IRQ function of a device.
121   *
122   * @param irqId Indicates the IRQ ID.
123   *
124   * @return Returns a value listed below: \n
125   * HDF_STATUS | Description
126   * ----------------------| -----------------------
127   * HDF_SUCCESS | The operation is successful.
128   * HDF_ERR_INVALID_PARAM | Invalid parameter.
129   *
130   * @since 1.0
131   * @version 1.0
132   */
133  int32_t OsalDisableIrq(uint32_t irqId);
134  
135  #ifdef __cplusplus
136  }
137  #endif /* __cplusplus */
138  
139  #endif /* OSAL_IRQ_H */
140  /** @} */
141