blob: 5314d39cd11104881349f0bf5e2869b6c61616dd [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**************************************************************************
2*
3* Copyright (c) 2012 ZTE Corporation.
4*
5***************************************************************************
6* Ä£ ¿é Ãû : P98C_OSS
7* ÎÄ ¼þ Ãû : oss_irq.h
8* Ïà¹ØÎļþ :
9* ʵÏÖ¹¦ÄÜ : ÖжÏÇëÇóÄ£¿é
10* ×÷ Õß : chenxingfang
11* °æ ±¾ : V1.0
12* Íê³ÉÈÕÆÚ : 2012-08-10
13* ÆäËü˵Ã÷ :
14**************************************************************************/
15
16/**************************************************************************
17* Ð޸ļǼ
18**************************************************************************/
19#ifndef _OSS_IRQ_H
20#define _OSS_IRQ_H
21
22/**************************************************************************
23* #includeÇø
24**************************************************************************/
25#ifdef _OS_LINUX
26#include <linux/irqflags.h>
27#endif
28
29#ifdef __cplusplus
30extern "C"
31{
32#endif
33
34/**************************************************************************
35* ³£Á¿¶¨ÒåÇø
36**************************************************************************/
37#ifdef _OS_TOS
38extern long tos_irq_level;
39extern long tos_isr_level;
40extern long tos_dsr_level;
41#endif
42
43#if defined _OS_TOS
44#define TOS_STATISTIC_IRQ
45
46#define TOS_TRACE_IRQ
47
48#define TOS_DISABLE_IRQ() \
49 { \
50 CYG_INTERRUPT_STATE old_intr; \
51 \
52 HAL_DISABLE_INTERRUPTS(old_intr);
53
54#define TOS_ENABLE_IRQ() \
55 HAL_RESTORE_INTERRUPTS(old_intr); \
56 }
57
58/* TOS 3.0²Ù×÷ϵͳµÄȥʹÄÜ¡¢Ê¹ÄÜ¡¢±£´æ¡¢»Ö¸´ÖжϷ½°¸ */
59#define TOS_DISABLE_IRQ_FAST() HAL_DISABLE_INTERRUPTS(old_intr)
60#define TOS_ENABLE_IRQ_FAST() HAL_RESTORE_INTERRUPTS(old_intr)
61#define TOS_SAVE_IRQ(old_intr) HAL_DISABLE_INTERRUPTS(old_intr)
62#define TOS_RESTORE_IRQ(old_intr) HAL_RESTORE_INTERRUPTS(old_intr)
63#define TOS_QUERY_IRQ(old_intr) HAL_QUERY_INTERRUPTS(old_intr)
64
65/* Ö§³ÅµÄȥʹÄÜ¡¢Ê¹ÄÜ¡¢±£´æ¡¢»Ö¸´ÖжϷ½°¸£¬ÐèÒªÕë¶Ô²»Í¬µÄ²Ù×÷ϵͳƽ̨½øÐÐÒÆÖ² */
66#define ZOSS_INTR CYG_INTERRUPT_STATE
67#define ZOSS_DISABLE_IRQ() TOS_DISABLE_IRQ()
68#define ZOSS_ENABLE_IRQ() TOS_ENABLE_IRQ()
69#define ZOSS_DISABLE_IRQ_FAST() TOS_DISABLE_IRQ_FAST()
70#define ZOSS_ENABLE_IRQ_FAST() TOS_ENABLE_IRQ_FAST()
71#define ZOSS_SAVE_IRQ(old_intr) TOS_SAVE_IRQ(old_intr)
72#define ZOSS_RESTORE_IRQ(old_intr) TOS_RESTORE_IRQ(old_intr)
73#define ZOSS_QUERY_IRQ(old_intr) TOS_QUERY_IRQ(old_intr)
74
75/* ÊÊÅäÔ­ÓдúÂëÖеÄȥʹÄÜ¡¢Ê¹ÄÜ¡¢±£´æ¡¢»Ö¸´ÖжϷ½°¸ */
76#define LOCK_SAVE(old_intr) ZOSS_SAVE_IRQ(old_intr)
77#define LOCK_RESTORE(old_intr) ZOSS_RESTORE_IRQ(old_intr)
78#elif defined _OS_OSE
79#define ZOSS_INTR unsigned long
80
81#define ZOSS_DISABLE_IRQ() \
82 { \
83 unsigned long msr; \
84 LOCK_SAVE(msr);
85
86#define ZOSS_ENABLE_IRQ() \
87 LOCK_RESTORE(msr); \
88 }
89
90#define ZOSS_DISABLE_IRQ_FAST() LOCK_SAVE(old_intr)
91#define ZOSS_ENABLE_IRQ_FAST() LOCK_RESTORE(old_intr)
92
93#define ZOSS_SAVE_IRQ(old_intr) LOCK_SAVE(old_intr)
94#define ZOSS_RESTORE_IRQ(old_intr) LOCK_RESTORE(old_intr)
95#elif defined _OS_LINUX
96#define LINUX_STATISTIC_IRQ
97#define LINUX_TRACE_IRQ
98#define LINUX_DISABLE_IRQ() \
99 { \
100 unsigned long flags; \
101 \
102 local_irq_save(flags);
103
104#define LINUX_ENABLE_IRQ() \
105 local_irq_restore(flags); \
106 }
107
108/* LINUX ²Ù×÷ϵͳµÄȥʹÄÜ¡¢Ê¹ÄÜ¡¢±£´æ¡¢»Ö¸´ÖжϷ½°¸ */
109#define LINUX_DISABLE_IRQ_FAST() local_irq_save(old_intr)
110#define LINUX_ENABLE_IRQ_FAST() local_irq_restore(old_intr)
111#define LINUX_SAVE_IRQ(old_intr) local_irq_save(old_intr)
112#define LINUX_RESTORE_IRQ(old_intr) local_irq_restore(old_intr)
113#define LINUX_QUERY_IRQ(old_intr) local_save_flags(old_intr)
114
115/* Ö§³ÅµÄȥʹÄÜ¡¢Ê¹ÄÜ¡¢±£´æ¡¢»Ö¸´ÖжϷ½°¸£¬ÐèÒªÕë¶Ô²»Í¬µÄ²Ù×÷ϵͳƽ̨½øÐÐÒÆÖ² */
116#define ZOSS_INTR unsigned long
117#define ZOSS_DISABLE_IRQ() LINUX_DISABLE_IRQ()
118#define ZOSS_ENABLE_IRQ() LINUX_ENABLE_IRQ()
119#define ZOSS_DISABLE_IRQ_FAST() LINUX_DISABLE_IRQ_FAST()
120#define ZOSS_ENABLE_IRQ_FAST() LINUX_ENABLE_IRQ_FAST()
121#define ZOSS_SAVE_IRQ(old_intr) LINUX_SAVE_IRQ(old_intr)
122#define ZOSS_RESTORE_IRQ(old_intr) LINUX_RESTORE_IRQ(old_intr)
123#define ZOSS_QUERY_IRQ(old_intr) LINUX_QUERY_IRQ(old_intr)
124
125/* ÊÊÅäÔ­ÓдúÂëÖеÄȥʹÄÜ¡¢Ê¹ÄÜ¡¢±£´æ¡¢»Ö¸´ÖжϷ½°¸ */
126#define LOCK_SAVE(old_intr) ZOSS_SAVE_IRQ(old_intr)
127#define LOCK_RESTORE(old_intr) ZOSS_RESTORE_IRQ(old_intr)
128#endif
129
130#define zDrv_DisableIrq() ZOSS_DISABLE_IRQ()
131#define zDrv_EnableIrq() ZOSS_ENABLE_IRQ()
132
133/**************************************************************************
134* Êý¾Ý½á¹¹¶¨ÒåÇø
135**************************************************************************/
136#ifdef _OS_TOS
137typedef UINT32 tos_isr_t(UINT32 vector, UINT32 data);
138typedef VOID tos_dsr_t(UINT32 vector, UINT32 count, UINT32 data);
139#elif defined _OS_LINUX
140typedef UINT32 linux_isr_t(UINT32 vector, UINT32 data);
141typedef VOID linux_dsr_t(UINT32 vector, UINT32 count, UINT32 data);
142#endif
143
144/**************************************************************************
145* º¯ÊýÉùÃ÷Çø
146**************************************************************************/
147#ifdef _OS_TOS
148UINT32 tos_default_isr( UINT32 vector, UINT32 data);
149#ifdef _USE_OSS_MIN
150UINT32 tos_create_irq(UINT32 vector, UINT32 priority, UINT32 data, tos_isr_t isr, tos_dsr_t dsr, cyg_interrupt *interrupt);
151#else
152UINT32 tos_create_irq(UINT32 vector, UINT32 priority, UINT32 data, tos_isr_t isr, tos_dsr_t dsr);
153#endif
154void tos_delete_irq(UINT32 interrupt_handle);
155
156#ifdef TOS_STATISTIC_IRQ
157void tos_statistic_irq_open(void);
158void tos_statistic_irq_close(void);
159void tos_statistic_irq_assert(void);
160void tos_statistic_irq_thread_start(void);
161void tos_statistic_irq_thread_end(void);
162#endif
163
164#ifdef TOS_TRACE_IRQ
165void tos_trace_irq_open(void);
166void tos_trace_irq_close(void);
167void tos_trace_irq_assert(void);
168#endif
169
170static inline SINT32 tos_get_irq_nesting_level(VOID)
171{
172 return tos_irq_level;
173}
174
175static inline SINT32 tos_get_isr_nesting_level(VOID)
176{
177 return tos_isr_level;
178}
179
180static inline SINT32 tos_get_dsr_nesting_level(VOID)
181{
182 return tos_dsr_level;
183}
184
185#ifdef _USE_OSS_MIN
186static inline UINT32 tos_create_isr(UINT32 vector, /* ÖжÏÏòÁ¿ */
187 UINT32 priority, /* ÖжÏÓÅÏȼ¶ */
188 UINT32 data, /* Êý¾ÝÖ¸Õë */
189 tos_isr_t isr, /* ÖжϷþÎñÀý³Ì */
190 cyg_interrupt *interrupt) /* ÖжϽṹÌåÖ¸Õë */
191{
192 return tos_create_irq(vector, /* ÖжÏÏòÁ¿ */
193 priority, /* ÖжÏÓÅÏȼ¶ */
194 data, /* Êý¾ÝÖ¸Õë */
195 isr, /* ÖжϷþÎñÀý³Ì */
196 NULL, /* ÖжÏÑÓ³Ù·þÎñÀý³Ì */
197 interrupt); /* ÖжϽṹÌåÖ¸Õë */
198}
199
200static inline UINT32 tos_create_dsr(UINT32 vector, /* ÖжÏÏòÁ¿ */
201 UINT32 priority, /* ÖжÏÓÅÏȼ¶ */
202 UINT32 data, /* Êý¾ÝÖ¸Õë */
203 tos_dsr_t dsr, /* ÖжϷþÎñÀý³Ì */
204 cyg_interrupt *interrupt) /* ÖжϽṹÌåÖ¸Õë */
205{
206 return tos_create_irq(vector, /* ÖжÏÏòÁ¿ */
207 priority, /* ÖжÏÓÅÏȼ¶ */
208 data, /* Êý¾ÝÖ¸Õë */
209 tos_default_isr, /* ÖжϷþÎñÀý³Ì */
210 dsr, /* ÖжÏÑÓ³Ù·þÎñÀý³Ì */
211 interrupt); /* ÖжϽṹÌåÖ¸Õë */
212}
213#else
214static inline UINT32 tos_create_isr(UINT32 vector, /* ÖжÏÏòÁ¿ */
215 UINT32 priority, /* ÖжÏÓÅÏȼ¶ */
216 UINT32 data, /* Êý¾ÝÖ¸Õë */
217 tos_isr_t isr) /* ÖжϷþÎñÀý³Ì */
218{
219 return tos_create_irq(vector,
220 priority,
221 data,
222 isr,
223 NULL); /* ÖжϷþÎñÀý³Ì */
224}
225
226static inline UINT32 tos_create_dsr(UINT32 vector, /* ÖжÏÏòÁ¿ */
227 UINT32 priority, /* ÖжÏÓÅÏȼ¶ */
228 UINT32 data, /* Êý¾ÝÖ¸Õë */
229 tos_dsr_t dsr) /* ÖжϷþÎñÀý³Ì */
230{
231 return tos_create_irq(vector,
232 priority,
233 data,
234 tos_default_isr, /* ÖжϷþÎñÀý³Ì */
235 dsr);
236}
237#endif
238
239static inline VOID tos_delete_isr(UINT32 interrupt_handle)
240{
241 tos_delete_irq(interrupt_handle);
242}
243
244static inline VOID tos_delete_dsr(UINT32 interrupt_handle)
245{
246 tos_delete_irq(interrupt_handle);
247}
248#elif defined _OS_LINUX
249UINT32 linux_default_isr( UINT32 vector, UINT32 data);
250
251UINT32 linux_create_irq(UINT32 vector, UINT32 priority, UINT32 data, linux_isr_t isr, linux_dsr_t dsr);
252
253void linux_delete_irq(UINT32 interrupt_handle);
254
255static inline UINT32 linux_create_isr(UINT32 vector, /* ÖжÏÏòÁ¿ */
256 UINT32 priority, /* ÖжÏÓÅÏȼ¶ */
257 UINT32 data, /* Êý¾ÝÖ¸Õë */
258 linux_isr_t isr) /* ÖжϷþÎñÀý³Ì */
259{
260 return 0x00;
261}
262
263static inline UINT32 linux_create_dsr(UINT32 vector, /* ÖжÏÏòÁ¿ */
264 UINT32 priority, /* ÖжÏÓÅÏȼ¶ */
265 UINT32 data, /* Êý¾ÝÖ¸Õë */
266 linux_dsr_t dsr) /* ÖжϷþÎñÀý³Ì */
267{
268 return 0x00;
269}
270
271static inline VOID linux_delete_isr(UINT32 interrupt_handle)
272{
273 linux_delete_irq(interrupt_handle);
274}
275
276static inline VOID linux_delete_dsr(UINT32 interrupt_handle)
277{
278 linux_delete_irq(interrupt_handle);
279}
280#endif
281
282/**************************************************************************
283* È«¾Ö±äÁ¿ÉùÃ÷Çø
284**************************************************************************/
285
286#ifdef __cplusplus
287}
288#endif
289
290#endif /* _OSS_IRQ_H */
291
292