• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: OS Abstract Layer.
15  */
16 
17 /**
18  * @defgroup osal_interrupt osal_interrupt
19  */
20 #ifndef __OSAL_INTERRUPT_H__
21 #define __OSAL_INTERRUPT_H__
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define OSAL_CPU_ALL 0
30 #define OSAL_CPU_0 (1 << 1)
31 #define OSAL_CPU_1 (1 << 2)
32 #define OSAL_CPU_2 (1 << 3)
33 #define OSAL_CPU_3 (1 << 4)
34 
35 typedef struct {
36     void *tasklet;
37     void (*handler)(unsigned long data);
38     unsigned long data;
39 } osal_tasklet;
40 
41 enum osal_irqreturn {
42     OSAL_IRQ_NONE = (0 << 0),
43     OSAL_IRQ_HANDLED = (1 << 0),
44     OSAL_IRQ_WAKE_THREAD = (1 << 1),
45 };
46 typedef int (*osal_irq_handler)(int, void *);
47 
48 /**
49  * @ingroup osal_interrupt
50  * @brief get irq_handler dev.
51  *
52  * @param param_dev [in] Parameters passed to the callback function.
53  *
54  * @return Returns the parameters that can be used directly.
55  *
56  * @par Support System:
57  * linux liteos freertos seliteos.
58  */
59 void *osal_irq_get_private_dev(void *param_dev);
60 
61 /**
62  * @ingroup osal_interrupt
63  * @brief alloc an interrupt line.
64  *
65  * @param irq [in] Interrupt line to alloc.
66  * @param handler [in] Function to be called when the IRQ occurs. Primary handler for threaded interrupts.
67  * If NULL and thread_fn != NULL the default primary handler is installed.
68  * @param thread_fn [in] Function called from the irq handler thread. If NULL, no irq thread is created.
69  * @param name [in] An ascii name for the claiming device.
70  * @param dev [in] A cookie passed back to the handler function.
71  *
72  * @attention In linux userspace, the type of the dev parameter must be (drval_irq_arg *).
73  *
74  * @return OSAL_SUCCESS/OSAL_FAILURE
75  *
76  * @par Support System:
77  * linux liteos seliteos freertos.
78  */
79 int osal_irq_request(unsigned int irq, osal_irq_handler handler, osal_irq_handler thread_fn, const char *name,
80     void *dev);
81 
82 /**
83  * @ingroup osal_interrupt
84  * @brief free an interrupt allocd with request_irq.
85  *
86  * @param irq [in] Interrupt line to free.
87  * @param dev [in] Device identity to free.
88  *
89  * @attention This function must not be called from interrupt context. In linux userspace,
90  *            the parameter dev must be the same as the dev parameter of the osal_irq_request function.
91  *
92  * @par Support System:
93  * linux liteos seliteos freertos.
94  */
95 void osal_irq_free(unsigned int irq, void *dev);
96 
97 /**
98  * @ingroup osal_interrupt
99  * @brief Set interrupts priority.
100  *
101  * @par Description:
102  * Set interrupts priority.
103  *
104  * @attention
105  * This function depends on the hardware implementation of the interrupt controller and CPU architecture.
106  *
107  * @return OSAL_SUCCESS/OSAL_FAILURE
108  *
109  * @par Support System:
110  * liteos freertos.
111  */
112 int osal_irq_set_priority(unsigned int irq, unsigned short priority);
113 
114 /**
115  * @ingroup osal_interrupt
116  * @brief Setting the CPU Affinity of Interrupts.
117  *
118  * @par Description:
119  * Setting the CPU Affinity of Interrupts.
120  *
121  * @param irq [in] irq number.
122  * @param name [in] irq name.
123  * @param cpu_mask [in] cpu_musk. one of the following: OSAL_CPU_ALL, OSAL_CPU_0, OSAL_CPU_1, OSAL_CPU_2, OSAL_CPU_3
124  *
125  * @par Support System:
126  * linux liteos seliteos.
127  */
128 int osal_irq_set_affinity(unsigned int irq, const char *name, int cpu_mask);
129 
130 /**
131  * @ingroup osal_interrupt
132  * @brief enable handling of an irq.
133  *
134  * @par Description:
135  * Undoes the effect of one call to disable_irq().
136  * If this matches the last disable, processing of interrupts on this IRQ line is re-enabled.
137  *
138  * @param irq [in] Interrupt to enable.
139  *
140  * @par Support System:
141  * linux liteos seliteos freertos.
142  */
143 void osal_irq_enable(unsigned int irq);
144 
145 /**
146  * @ingroup osal_interrupt
147  * @brief disable an irq and wait for completion.
148  *
149  * @par Description:
150  * Disable the selected interrupt line.
151  *
152  * @param irq [in] Interrupt to disable.
153  *
154  * @par Support System:
155  * linux liteos seliteos freertos.
156  */
157 void osal_irq_disable(unsigned int irq);
158 
159 /**
160  * @ingroup osal_interrupt
161  * @brief Disable all interrupts.
162  *
163  * @par Description:
164  * This API is used to disable all IRQ and FIQ interrupts in the CPSR.
165  *
166  * @return CPSR value before all interrupts are disabled.
167  *
168  * @par Support System:
169  * liteos seliteos nonos freertos.
170  */
171 unsigned int osal_irq_lock(void);
172 
173 /**
174  * @ingroup osal_interrupt
175  * @brief Enable all interrupts.
176  *
177  * @par Description:
178  * This API is used to enable all IRQ and FIQ interrupts in the CPSR.
179  *
180  * @return CPSR value after all interrupts are enabled.
181  *
182  * @par Support System:
183  * liteos seliteos nonos freertos.
184  */
185 unsigned int osal_irq_unlock(void);
186 
187 /**
188  * @ingroup osal_interrupt
189  * @brief Restore interrupts.
190  *
191  * @par Description:
192  * This API is used to restore the CPSR value obtained before all interrupts are disabled by #osal_irq_lock.
193  *
194  * @attention
195  * This API can be called only after all interrupts are disabled, and the input parameter value should be
196  * the value returned by osal_irq_lock.
197  *
198  * @par Support System:
199  * liteos seliteos nonos freertos.
200  */
201 void osal_irq_restore(unsigned int irq_status);
202 
203 /**
204  * @ingroup osal_interrupt
205  * @brief Clear the pending status of other interrupts.
206  *
207  * @par Description:
208  * This API is used to clear the pending status of other interrupts.
209  *
210  * @param vector [in] interrupt vector.
211  *
212  * @par Support System:
213  * liteos freertos.
214  */
215 unsigned int osal_irq_clear(unsigned int vector);
216 
217 /**
218  * @ingroup osal_interrupt
219  * @brief Check whether the current interrupt is in interrupt.
220  *
221  * @par Description:
222  * Check whether the current interrupt is in the context of hard interrupts, soft interrupts, and unmaskable interrupts.
223  *
224  * @return false/true
225  *
226  * @par Support System:
227  * linux liteos nonos freertos.
228  */
229 int osal_in_interrupt(void);
230 
231 /**
232  * @ingroup osal_interrupt
233  * @brief initialize tasklet.
234  *
235  * @par Description:
236  * initialize tasklet.
237  *
238  * @attention
239  * Before invoking this interface,
240  * assign values to the handler and data members of osal_tasklet and leave the tasklet member tasklet empty.
241  *
242  * @param tasklet [in/out] The tasklet to be initialized.
243  *
244  * @par Support System:
245  * linux liteos seliteos.
246  */
247 int osal_tasklet_init(osal_tasklet *tasklet);
248 
249 /**
250  * @ingroup osal_interrupt
251  * @brief schedule tasklet.
252  *
253  * @par Support System:
254  * linux liteos seliteos.
255  */
256 int osal_tasklet_schedule(osal_tasklet *tasklet);
257 
258 /**
259  * @ingroup osal_interrupt
260  * @brief Close tasklet.
261  *
262  * @par Description:
263  * Close tasklet.
264  *
265  * @par Support System:
266  * linux liteos seliteos.
267  */
268 int osal_tasklet_kill(osal_tasklet *tasklet);
269 
270 /**
271  * @ingroup osal_interrupt
272  * @brief Update tasklet.
273  *
274  * @par Description:
275  * Update tasklet.
276  *
277  * @par Support System:
278  * linux liteos seliteos.
279  */
280 int osal_tasklet_update(osal_tasklet *tasklet);
281 
282 #ifdef __cplusplus
283 #if __cplusplus
284 }
285 #endif
286 #endif
287 #endif /* __OSAL_INTERRUPT_H__ */
288