1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78
79 //-------------------------------------------------------------------------------------------------
80 // Include Files
81 //-------------------------------------------------------------------------------------------------
82
83 #if defined (MSOS_TYPE_ECOS)
84
85 #include <cyg/kernel/kapi.h>
86 #include "MsCommon.h"
87 #include "MsOS.h"
88 #include "halIRQTBL.h"
89 #include "halCHIP.h"
90 #include "regCHIP.h"
91 #include "asmCPU.h"
92
93 //-------------------------------------------------------------------------------------------------
94 // Driver Compiler Options
95 //-------------------------------------------------------------------------------------------------
96
97 //-------------------------------------------------------------------------------------------------
98 // Local Defines
99 //-------------------------------------------------------------------------------------------------
100 #define CHIP_LISR_MAX 2 //vector0: IRQ, vector1: FIQ, vector5: Timer INT
101
102 //-------------------------------------------------------------------------------------------------
103 // Local Structures
104 //-------------------------------------------------------------------------------------------------
105 //typedef void (*LISR_Entry) (MS_S32);
106 typedef struct
107 {
108 cyg_handle_t stIntr;
109 cyg_interrupt stIntrInfo;
110
111 } CHIP_LISR_Info;
112
113 typedef struct
114 {
115 MS_BOOL bUsed;
116 MS_BOOL bPending;
117 // MS_BOOL priority;
118 InterruptCb pIntCb;
119
120 } CHIP_HISR_Info;
121
122 //-------------------------------------------------------------------------------------------------
123 // Global Variables
124 //-------------------------------------------------------------------------------------------------
125
126 //-------------------------------------------------------------------------------------------------
127 // Local Variables
128 //-------------------------------------------------------------------------------------------------
129 static CHIP_LISR_Info _LISR_Info[CHIP_LISR_MAX];
130 static MS_BOOL _bInLISR = FALSE;
131
132 static CHIP_HISR_Info _HISR_Info[MS_IRQ_MAX];
133 static MS_BOOL _bInHISR = FALSE;
134
135 //-------------------------------------------------------------------------------------------------
136 // Debug Functions
137 //-------------------------------------------------------------------------------------------------
138
139 //-------------------------------------------------------------------------------------------------
140 // Local Functions
141 //-------------------------------------------------------------------------------------------------
142 MS_BOOL CHIP_DisableIRQ(InterruptNum eIntNum);
143
144 // -- Jerry --
145 // Leave these to be chip independent. Different chip can have the opportunities to
146 // revise the priority policy for different interrupts.
147
148 //-------------------------------------------------------------------------------------------------
149 // ISR of IRQ
150 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
151 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
152 // @return ISR result
153 //-------------------------------------------------------------------------------------------------
_CHIP_LISR0(MS_U32 u32VectorNum,MS_U32 u32Data)154 static MS_U32 _CHIP_LISR0(MS_U32 u32VectorNum, MS_U32 u32Data)
155 {
156 MS_U32 u32Reg;
157 MS_U32 u32Bit;
158 IRQFIQNum eVector;
159 InterruptNum eIntNum;
160
161 u32Reg = 0;
162
163 //in interrupt context
164 _bInLISR = TRUE;
165
166 u32Reg = IRQ_REG(REG_IRQ_PENDING_H);
167 u32Reg <<= 16;
168 u32Reg |= IRQ_REG(REG_IRQ_PENDING_L);
169
170 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
171 {
172 if(u32Bit < 16)
173 {
174 eVector = (IRQFIQNum)(u32Bit + E_IRQL_START);
175 }
176 else
177 {
178 eVector = (IRQFIQNum)((u32Bit-16) + E_IRQH_START);
179 }
180
181 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
182 CHIP_DisableIRQ(eIntNum);
183 if(_HISR_Info[eVector].bUsed)
184 {
185 _HISR_Info[eVector].bPending = TRUE;
186 }
187 u32Reg &= ~(0x01 << u32Bit);
188 }
189
190 u32Reg = 0;
191 u32Reg = IRQ_REG(REG_IRQEXP_PENDING_H);
192 u32Reg <<= 16;
193 u32Reg |= IRQ_REG(REG_IRQEXP_PENDING_L);
194
195 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
196 {
197 if(u32Bit < 16)
198 {
199 eVector = (IRQFIQNum)(u32Bit + E_IRQEXPL_START);
200 }
201 else
202 {
203 eVector = (IRQFIQNum)((u32Bit-16) + E_IRQEXPH_START);
204 }
205
206 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
207 CHIP_DisableIRQ(eIntNum);
208 if(_HISR_Info[eVector].bUsed)
209 {
210 _HISR_Info[eVector].bPending = TRUE;
211 }
212 u32Reg &= ~(0x01 << u32Bit);
213 }
214
215 u32Reg = 0;
216 u32Reg = IRQHYP_REG(REG_IRQHYP_PENDING_H);
217 u32Reg <<= 16;
218 u32Reg |= IRQHYP_REG(REG_IRQHYP_PENDING_L);
219
220 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
221 {
222 if(u32Bit < 16)
223 {
224 eVector = (IRQFIQNum)(u32Bit + E_IRQHYPL_START);
225 }
226 else
227 {
228 eVector = (IRQFIQNum)((u32Bit-16) + E_IRQHYPH_START);
229 }
230
231 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
232 CHIP_DisableIRQ(eIntNum);
233 if(_HISR_Info[eVector].bUsed)
234 {
235 _HISR_Info[eVector].bPending = TRUE;
236 }
237 u32Reg &= ~(0x01 << u32Bit);
238 }
239
240 // Mask this interrupt until the DSR completes.
241 cyg_interrupt_mask(E_INTERRUPT_IRQ); //why mask INT0 -> cause can still be 1 ???
242
243 // Tell the processor that we have received the interrupt.
244 cyg_interrupt_acknowledge(E_INTERRUPT_IRQ);
245
246 _bInLISR = FALSE;
247
248 // Tell the kernel that the ISR processing is done and the DSR needs to be executed next.
249 return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
250 }
251
252 //-------------------------------------------------------------------------------------------------
253 // ISR of FIQ
254 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
255 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
256 // @return ISR result
257 // @note FIQ - handle interrupt service routine in ISR
258 //-------------------------------------------------------------------------------------------------
_CHIP_LISR1(MS_U32 u32VectorNum,MS_U32 u32Data)259 static MS_U32 _CHIP_LISR1(MS_U32 u32VectorNum, MS_U32 u32Data)
260 {
261 MS_U32 u32Reg;
262 MS_U32 u32Bit;
263 IRQFIQNum eVector;
264 InterruptNum eIntNum;
265
266 //in interrupt context
267 _bInLISR = TRUE;
268
269 u32Reg = 0;
270 u32Reg = IRQ_REG(REG_FIQ_PENDING_H);
271 u32Reg <<= 16;
272 u32Reg |= IRQ_REG(REG_FIQ_PENDING_L);
273
274 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
275 {
276 if(u32Bit < 16)
277 {
278 eVector = (IRQFIQNum)(u32Bit + E_FIQL_START);
279 }
280 else
281 {
282 eVector = (IRQFIQNum)((u32Bit-16) + E_FIQH_START);
283 }
284 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
285 CHIP_DisableIRQ(eIntNum);
286 if(_HISR_Info[eVector].bUsed)
287 {
288 _HISR_Info[eVector].bPending = TRUE;
289 }
290 u32Reg &= ~(0x01 << u32Bit);
291 }
292
293 u32Reg = 0;
294 u32Reg = IRQ_REG(REG_FIQEXP_PENDING_H);
295 u32Reg <<=16;
296 u32Reg |= IRQ_REG(REG_FIQEXP_PENDING_L);
297
298 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
299 {
300 if(u32Bit<16)
301 {
302 eVector = (IRQFIQNum)(u32Bit + E_FIQEXPL_START);
303 }
304 else
305 {
306 eVector = (IRQFIQNum)((u32Bit-16) + E_FIQEXPH_START);
307 }
308 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
309 CHIP_DisableIRQ(eIntNum);
310 if(_HISR_Info[eVector].bUsed)
311 {
312 _HISR_Info[eVector].bPending = TRUE;
313 }
314 u32Reg &= ~(0x1 << u32Bit);
315 }
316
317 u32Reg = 0;
318 u32Reg = IRQHYP_REG(REG_FIQHYP_PENDING_H);
319 u32Reg <<=16;
320 u32Reg |= IRQHYP_REG(REG_FIQHYP_PENDING_L);
321
322 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
323 {
324 if(u32Bit<16)
325 {
326 eVector = (IRQFIQNum)(u32Bit + E_FIQHYPL_START);
327 }
328 else
329 {
330 eVector = (IRQFIQNum)((u32Bit-16) + E_FIQHYPH_START);
331 }
332 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
333 CHIP_DisableIRQ(eIntNum);
334 if(_HISR_Info[eVector].bUsed)
335 {
336 _HISR_Info[eVector].bPending = TRUE;
337 }
338 u32Reg &= ~(0x1 << u32Bit);
339 }
340
341 // Mask this interrupt until the ISR completes.
342 cyg_interrupt_mask(E_INTERRUPT_FIQ);
343
344 // Tell the processor that we have received the interrupt.
345 cyg_interrupt_acknowledge(E_INTERRUPT_FIQ);
346
347 _bInLISR = FALSE;
348 return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
349 }
350
351 //-------------------------------------------------------------------------------------------------
352 // DSR of IRQ
353 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
354 // @param u32Count \b IN: # of occurrences
355 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
356 // @return None
357 //-------------------------------------------------------------------------------------------------
_CHIP_HISR0(MS_U32 u32VectorNum,MS_U32 u32Count,MS_U32 u32Data)358 static void _CHIP_HISR0(MS_U32 u32VectorNum, MS_U32 u32Count, MS_U32 u32Data)
359 {
360 InterruptNum i;
361
362 _bInHISR = TRUE; //in interrupt context
363
364 // Process all pending DSRs, then enable relative IRQ again
365 // The following SW processing flow decides the priorities from high to low
366 //for loop later
367 // IRQ H
368 for(i = (InterruptNum) E_IRQL_START; i <= (InterruptNum) E_IRQL_END; i++)
369 {
370 if (_HISR_Info[i].bPending)
371 {
372 _HISR_Info[i].bPending = FALSE;
373 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
374 }
375 }
376 for(i = (InterruptNum) E_IRQH_START; i <= (InterruptNum) E_IRQH_END; i++)
377 {
378 if(_HISR_Info[i].bPending)
379 {
380 _HISR_Info[i].bPending = FALSE;
381 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
382 }
383 }
384
385 for(i = (InterruptNum) E_IRQEXPL_START; i <= (InterruptNum) E_IRQEXPL_END; i++)
386 {
387 if(_HISR_Info[i].bPending)
388 {
389 _HISR_Info[i].bPending = FALSE;
390 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
391 }
392 }
393
394 for(i = (InterruptNum) E_IRQEXPH_START; i <= (InterruptNum) E_IRQEXPH_END; i++)
395 {
396 if(_HISR_Info[i].bPending)
397 {
398 _HISR_Info[i].bPending = FALSE;
399 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
400 }
401 }
402
403 for(i = (InterruptNum) E_IRQHYPL_START; i <= (InterruptNum) E_IRQHYPL_END; i++)
404 {
405 if(_HISR_Info[i].bPending)
406 {
407 _HISR_Info[i].bPending = FALSE;
408 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
409 }
410 }
411
412 for(i = (InterruptNum) E_IRQHYPH_START; i <= (InterruptNum) E_IRQHYPH_END; i++)
413 {
414 if(_HISR_Info[i].bPending)
415 {
416 _HISR_Info[i].bPending = FALSE;
417 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
418 }
419 }
420 _bInHISR = FALSE;
421 // Allow this interrupt to occur again.
422 cyg_interrupt_unmask(E_INTERRUPT_IRQ);
423 }
424
_CHIP_HISR1(MS_U32 u32VectorNum,MS_U32 u32Count,MS_U32 u32Data)425 static void _CHIP_HISR1(MS_U32 u32VectorNum, MS_U32 u32Count, MS_U32 u32Data)
426 {
427 InterruptNum i;
428
429 _bInHISR = TRUE; //in interrupt context
430
431
432 for(i = (InterruptNum) E_FIQL_START; i <=(InterruptNum) E_IRQL_END; i++)
433 {
434 if(_HISR_Info[i].bPending)
435 {
436 _HISR_Info[i].bPending = FALSE;
437 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
438 }
439 }
440 for(i = (InterruptNum) E_FIQH_START; i <= (InterruptNum) E_FIQH_END; i++)
441 {
442 if(_HISR_Info[i].bPending)
443 {
444 _HISR_Info[i].bPending = FALSE;
445 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
446 }
447 }
448
449 for(i = (InterruptNum) E_FIQEXPL_START; i <= (InterruptNum) E_FIQEXPL_END; i++)
450 {
451 if(_HISR_Info[i].bPending)
452 {
453 _HISR_Info[i].bPending = FALSE;
454 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
455 }
456 }
457
458 for(i = (InterruptNum) E_FIQEXPH_START; i<= (InterruptNum) E_FIQEXPH_END; i++)
459 {
460 if(_HISR_Info[i].bPending)
461 {
462 _HISR_Info[i].bPending = FALSE;
463 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
464 }
465 }
466
467 for(i = (InterruptNum) E_FIQHYPL_START; i <= (InterruptNum) E_FIQHYPL_END; i++)
468 {
469 if(_HISR_Info[i].bPending)
470 {
471 _HISR_Info[i].bPending = FALSE;
472 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
473 }
474 }
475
476 for(i = (InterruptNum) E_FIQHYPH_START; i<= (InterruptNum) E_FIQHYPH_END; i++)
477 {
478 if(_HISR_Info[i].bPending)
479 {
480 _HISR_Info[i].bPending = FALSE;
481 _HISR_Info[i].pIntCb((InterruptNum) HWIdx2IntEnum[i]);
482 }
483 }
484
485 //exit interrupt context
486 _bInHISR = FALSE;
487
488 // Allow this interrupt to occur again.
489 cyg_interrupt_unmask(E_INTERRUPT_FIQ);
490 }
491
492 //-------------------------------------------------------------------------------------------------
493 // Global Functions
494 //-------------------------------------------------------------------------------------------------
495
CHIP_EnableIRQ(InterruptNum eIntNum)496 MS_BOOL CHIP_EnableIRQ(InterruptNum eIntNum)
497 {
498 MS_BOOL bRet = TRUE;
499 MS_U8 u8VectorIndex = 0;
500
501 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
502
503 if(_HISR_Info[u8VectorIndex].bUsed)
504 {
505 if (u8VectorIndex == E_IRQ_FIQ_ALL)
506 {
507 IRQ_REG(REG_IRQ_MASK_L) &= ~0xFFFF;
508 IRQ_REG(REG_IRQ_MASK_H) &= ~0xFFFF;
509 IRQ_REG(REG_IRQEXP_MASK_L) &= ~0xFFFF;
510 IRQ_REG(REG_IRQEXP_MASK_H) &= ~0xFFFF;
511 IRQ_REG(REG_FIQ_MASK_L) &= ~0xFFFF;
512 IRQ_REG(REG_FIQ_MASK_H) &= ~0xFFFF;
513 IRQ_REG(REG_FIQEXP_MASK_L) &= ~0xFFFF;
514 IRQ_REG(REG_FIQEXP_MASK_H) &= ~0xFFFF;
515
516 IRQHYP_REG(REG_IRQHYP_MASK_L) &= ~0xFFFF;
517 IRQHYP_REG(REG_IRQHYP_MASK_H) &= ~0xFFFF;
518 IRQHYP_REG(REG_FIQHYP_MASK_L) &= ~0xFFFF;
519 IRQHYP_REG(REG_FIQHYP_MASK_H) &= ~0xFFFF;
520 }
521 else if((u8VectorIndex >= E_IRQL_START) && (u8VectorIndex <= (MS_U8) E_IRQL_END))
522 {
523 IRQ_REG(REG_IRQ_MASK_L) &= ~(0x01 << (u8VectorIndex - E_IRQL_START));
524 }
525 else if((u8VectorIndex >= (MS_U8) E_IRQH_START) && (u8VectorIndex <= (MS_U8) E_IRQH_END))
526 {
527 IRQ_REG(REG_IRQ_MASK_H) &= ~(0x01 << (u8VectorIndex - E_IRQH_START));
528 }
529 else if((u8VectorIndex >= (MS_U8) E_IRQEXPL_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPL_END))
530 {
531 IRQ_REG(REG_IRQEXP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_IRQEXPL_START));
532 }
533 else if((u8VectorIndex >= (MS_U8) E_IRQEXPH_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPH_END))
534 {
535 IRQ_REG(REG_IRQEXP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_IRQEXPH_START));
536 }
537 else if((u8VectorIndex >= (MS_U8) E_IRQHYPL_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPL_END))
538 {
539 IRQHYP_REG(REG_IRQHYP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_IRQHYPL_START));
540 }
541 else if((u8VectorIndex >= (MS_U8) E_IRQHYPH_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPH_END))
542 {
543 IRQHYP_REG(REG_IRQHYP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_IRQHYPH_START));
544 }
545 else if((u8VectorIndex >= (MS_U8) E_FIQL_START) && (u8VectorIndex <= (MS_U8) E_FIQL_END))
546 {
547 IRQ_REG(REG_FIQ_MASK_L) &= ~(0x01 << (u8VectorIndex - E_FIQL_START));
548 }
549 else if((u8VectorIndex >= (MS_U8) E_FIQH_START) && (u8VectorIndex <= (MS_U8) E_FIQH_END))
550 {
551 IRQ_REG(REG_FIQ_MASK_H) &= ~(0x01 << (u8VectorIndex - E_FIQH_START));
552 }
553 else if((u8VectorIndex >= (MS_U8) E_FIQEXPL_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPL_END))
554 {
555 IRQ_REG(REG_FIQEXP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_FIQEXPL_START));
556 }
557 else if((u8VectorIndex >= (MS_U8) E_FIQEXPH_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPH_END))
558 {
559 IRQ_REG(REG_FIQEXP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_FIQEXPH_START));
560 }
561 else if((u8VectorIndex >= (MS_U8) E_FIQHYPL_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPL_END))
562 {
563 IRQHYP_REG(REG_FIQHYP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_FIQHYPL_START));
564 }
565 else if((u8VectorIndex >= (MS_U8) E_FIQHYPH_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPH_END))
566 {
567 IRQHYP_REG(REG_FIQHYP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_FIQHYPH_START));
568 }
569 }
570 else
571 {
572 bRet = FALSE;
573 }
574
575 return bRet;
576 }
577
CHIP_DisableIRQ(InterruptNum eIntNum)578 MS_BOOL CHIP_DisableIRQ(InterruptNum eIntNum)
579 {
580 MS_U8 u8VectorIndex = 0;
581
582 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
583
584 if (u8VectorIndex == E_IRQ_FIQ_ALL)
585 {
586 IRQ_REG(REG_IRQ_MASK_L) |= 0xFFFF;
587 IRQ_REG(REG_IRQ_MASK_H) |= 0xFFFF;
588 IRQ_REG(REG_IRQEXP_MASK_L) |= 0xFFFF;
589 IRQ_REG(REG_IRQEXP_MASK_H) |= 0xFFFF;
590 IRQ_REG(REG_FIQ_MASK_L) |= 0xFFFF;
591 IRQ_REG(REG_FIQ_MASK_H) |= 0xFFFF;
592 IRQ_REG(REG_FIQEXP_MASK_L) |= 0xFFFF;
593 IRQ_REG(REG_FIQEXP_MASK_H) |= 0xFFFF;
594
595 IRQHYP_REG(REG_IRQHYP_MASK_L) |= 0xFFFF;
596 IRQHYP_REG(REG_IRQHYP_MASK_H) |= 0xFFFF;
597 IRQHYP_REG(REG_FIQHYP_MASK_L) |= 0xFFFF;
598 IRQHYP_REG(REG_FIQHYP_MASK_H) |= 0xFFFF;
599 }
600 else if((u8VectorIndex >= E_IRQL_START) && (u8VectorIndex <= (MS_U8) E_IRQL_END))
601 {
602 IRQ_REG(REG_IRQ_MASK_L) |= (0x01 << (u8VectorIndex - E_IRQL_START));
603 }
604 else if((u8VectorIndex >= (MS_U8) E_IRQH_START) && (u8VectorIndex <= (MS_U8) E_IRQH_END))
605 {
606 IRQ_REG(REG_IRQ_MASK_H) |= (0x01 << (u8VectorIndex - E_IRQH_START));
607 }
608 else if((u8VectorIndex >= (MS_U8) E_IRQEXPL_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPL_END))
609 {
610 IRQ_REG(REG_IRQEXP_MASK_L) |= (0x01 << (u8VectorIndex - E_IRQEXPL_START));
611 }
612 else if((u8VectorIndex >= (MS_U8) E_IRQEXPH_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPH_END))
613 {
614 IRQ_REG(REG_IRQEXP_MASK_H) |= (0x01 << (u8VectorIndex - E_IRQEXPH_START));
615 }
616 else if((u8VectorIndex >= (MS_U8) E_IRQHYPL_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPL_END))
617 {
618 IRQHYP_REG(REG_IRQHYP_MASK_L) |= (0x01 << (u8VectorIndex - E_IRQHYPL_START));
619 }
620 else if((u8VectorIndex >= (MS_U8) E_IRQHYPH_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPH_END))
621 {
622 IRQHYP_REG(REG_IRQHYP_MASK_H) |= (0x01 << (u8VectorIndex - E_IRQHYPH_START));
623 }
624 else if((u8VectorIndex >= (MS_U8) E_FIQL_START) && (u8VectorIndex <= (MS_U8) E_FIQL_END))
625 {
626 IRQ_REG(REG_FIQ_MASK_L) |= (0x01 << (u8VectorIndex - E_FIQL_START));
627 IRQ_REG(REG_FIQ_CLEAR_L) = (0x01 << (u8VectorIndex - E_FIQL_START));
628 }
629 else if((u8VectorIndex >= (MS_U8) E_FIQH_START) && (u8VectorIndex <= (MS_U8) E_FIQH_END))
630 {
631 IRQ_REG(REG_FIQ_MASK_H) |= (0x01 << (u8VectorIndex - E_FIQH_START));
632 IRQ_REG(REG_FIQ_CLEAR_H) = (0x01 << (u8VectorIndex - E_FIQH_START));
633 }
634 else if((u8VectorIndex >= (MS_U8) E_FIQEXPL_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPL_END))
635 {
636 IRQ_REG(REG_FIQEXP_MASK_L) |= (0x01 << (u8VectorIndex - E_FIQEXPL_START));
637 IRQ_REG(REG_FIQEXP_CLEAR_L) = (0x01 << (u8VectorIndex - E_FIQEXPL_START));
638 }
639 else if((u8VectorIndex >= (MS_U8) E_FIQEXPH_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPH_END))
640 {
641 IRQ_REG(REG_FIQEXP_MASK_H) |= (0x01 << (u8VectorIndex - E_FIQEXPH_START));
642 IRQ_REG(REG_FIQEXP_CLEAR_H) = (0x01 << (u8VectorIndex - E_FIQEXPH_START));
643 }
644 else if((u8VectorIndex >= (MS_U8) E_FIQHYPL_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPL_END))
645 {
646 IRQHYP_REG(REG_FIQHYP_MASK_L) |= (0x01 << (u8VectorIndex - E_FIQHYPL_START));
647 IRQHYP_REG(REG_FIQHYP_CLEAR_L) = (0x01 << (u8VectorIndex - E_FIQHYPL_START));
648 }
649 else if((u8VectorIndex >= (MS_U8) E_FIQHYPH_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPH_END))
650 {
651 IRQHYP_REG(REG_FIQHYP_MASK_H) |= (0x01 << (u8VectorIndex - E_FIQHYPH_START));
652 IRQHYP_REG(REG_FIQHYP_CLEAR_H) = (0x01 << (u8VectorIndex - E_FIQHYPH_START));
653 }
654 return TRUE;
655 }
656
CHIP_AttachISR(InterruptNum eIntNum,InterruptCb pIntCb)657 MS_BOOL CHIP_AttachISR(InterruptNum eIntNum, InterruptCb pIntCb)
658 {
659 MS_U8 u8VectorIndex = 0;
660
661 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
662 _HISR_Info[u8VectorIndex].pIntCb = pIntCb;
663 _HISR_Info[u8VectorIndex].bUsed = TRUE;
664
665 return TRUE;
666 }
667
CHIP_DetachISR(InterruptNum eIntNum)668 MS_BOOL CHIP_DetachISR(InterruptNum eIntNum)
669 {
670 MS_U8 u8VectorIndex = 0;
671
672 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
673 _HISR_Info[u8VectorIndex].bUsed = FALSE;
674
675 return TRUE;
676 }
677
CHIP_InISRContext(void)678 MS_BOOL CHIP_InISRContext(void)
679 {
680 if (_bInLISR || _bInHISR)
681 {
682 return TRUE;
683 }
684 else
685 {
686 return FALSE;
687 }
688 }
689
CHIP_InitISR(void)690 void CHIP_InitISR(void)
691 {
692 MS_U32 i = 0;
693
694 HAL_InitIrqTable();
695
696 for(i = 0; i < MS_IRQ_MAX; i++)
697 {
698 _HISR_Info[i].bUsed = FALSE;
699 _HISR_Info[i].bPending = FALSE;
700 }
701
702 // Create the interrupt (0: IRQ register ISR/DSR; 1:FIQ register ISR)
703 cyg_interrupt_create(E_INTERRUPT_IRQ, 0, 0, (cyg_ISR_t *)_CHIP_LISR0, (cyg_DSR_t *)_CHIP_HISR0, &_LISR_Info[0].stIntr, &_LISR_Info[0].stIntrInfo);
704 cyg_interrupt_create(E_INTERRUPT_FIQ, 0, 1, (cyg_ISR_t*)_CHIP_LISR1, (cyg_DSR_t *)_CHIP_HISR1, &_LISR_Info[1].stIntr, &_LISR_Info[1].stIntrInfo);
705
706 // Attach the interrupt created to the vector.
707 cyg_interrupt_attach(_LISR_Info[0].stIntr);
708 cyg_interrupt_attach(_LISR_Info[1].stIntr);
709
710 // Unmask the interrupt we just configured.
711 cyg_interrupt_unmask(E_INTERRUPT_IRQ);
712 cyg_interrupt_unmask(E_INTERRUPT_FIQ);
713 }
714
715
716 //
717 // CHIP_DetectIRQSource will be called by hal_IRQ_handler() of eCospro
718 //
CHIP_DetectIRQSource(void)719 InterruptNum CHIP_DetectIRQSource(void)
720 {
721 MS_U32 u32Reg;
722
723 ////////////////////////
724 // Detect FIQ
725 ////////////////////////
726 u32Reg=0;
727
728 u32Reg = IRQ_REG(REG_FIQ_PENDING_H);
729 u32Reg <<=16;
730 u32Reg |= IRQ_REG(REG_FIQ_PENDING_L);
731
732
733 if(u32Reg != 0)
734 {
735 return E_INTERRUPT_FIQ;
736 }
737
738 u32Reg=0;
739
740 u32Reg = IRQ_REG(REG_FIQEXP_PENDING_H);
741 u32Reg <<=16;
742 u32Reg |= IRQ_REG(REG_FIQEXP_PENDING_L);
743
744
745 if(u32Reg != 0)
746 {
747 return E_INTERRUPT_FIQ;
748 }
749
750 u32Reg=0;
751
752 u32Reg = IRQHYP_REG(REG_FIQHYP_PENDING_H);
753 u32Reg <<=16;
754 u32Reg |= IRQHYP_REG(REG_FIQHYP_PENDING_L);
755
756
757 if(u32Reg != 0)
758 {
759 return E_INTERRUPT_FIQ;
760 }
761
762 ////////////////////////
763 // Detect IRQ
764 ////////////////////////
765 u32Reg=0;
766
767 u32Reg = IRQ_REG(REG_IRQ_PENDING_H);
768 u32Reg <<=16;
769 u32Reg |= IRQ_REG(REG_IRQ_PENDING_L);
770
771 if(u32Reg != 0)
772 {
773 return E_INTERRUPT_IRQ;
774 }
775
776 u32Reg=0;
777
778 u32Reg = IRQ_REG(REG_IRQEXP_PENDING_H);
779 u32Reg <<=16;
780 u32Reg |= IRQ_REG(REG_IRQEXP_PENDING_L);
781
782 if(u32Reg != 0)
783 {
784 return E_INTERRUPT_IRQ;
785 }
786
787 u32Reg=0;
788
789 u32Reg = IRQHYP_REG(REG_IRQHYP_PENDING_H);
790 u32Reg <<=16;
791 u32Reg |= IRQHYP_REG(REG_IRQHYP_PENDING_L);
792
793 if(u32Reg != 0)
794 {
795 return E_INTERRUPT_IRQ;
796 }
797
798 return E_INTERRUPT_IRQ;
799 }
800
801 #endif
802
803 #if defined (MSOS_TYPE_LINUX)
804
805 #include <fcntl.h>
806 #include <errno.h>
807
808 #include <stdlib.h>
809 #include <unistd.h>
810 #include <pthread.h>
811 #include <signal.h>
812 #include <time.h>
813 #include <limits.h>
814 #include <memory.h>
815 #include <sys/ioctl.h>
816 #include <sys/prctl.h>
817
818 #include "MsCommon.h"
819 #include "MsOS.h"
820 #include "halIRQTBL.h"
821 #include "regCHIP.h"
822 #ifdef CONFIG_ENABLE_MENUCONFIG
823 #include "autoconf.h"
824 #endif
825
826 //-------------------------------------------------------------------------------------------------
827 // Driver Compiler Options
828 //-------------------------------------------------------------------------------------------------
829
830 //-------------------------------------------------------------------------------------------------
831 // Local Defines
832 //-------------------------------------------------------------------------------------------------
833 // support 8 vector inerrupts on 4KEc
834 #define CHIP_LISR_MAX 2 //vector0: IRQ, vector1: FRQ, vector5: Timer INT
835 #define MAX_NAME 30 //max thread_name_length
836 #define SEND_ACK 0 //send ack to kernel before executing registered ISR
837
838 #ifdef CONFIG_INT_SPI_MODE
839 #define CHIP_INT_BASE 32 //vector0: IRQ, vector1: FIQ, vector5: Timer INT
840 #else
841 #define CHIP_INT_BASE 128 //vector0: IRQ, vector1: FIQ, vector5: Timer INT
842 #endif
843
844 //-------------------------------------------------------------------------------------------------
845 // Local Structures
846 //-------------------------------------------------------------------------------------------------
847 struct irq_desc
848 {
849 void *driverp;
850 void (*handler)(InterruptNum eIntNum);
851 int irqfd;
852 MS_U16 u16irq;
853 };
854
855 struct pollfd
856 {
857 int fd; /* File descriptor to poll. */
858 short int events; /* Types of events poller cares about. */
859 short int revents; /* Types of events that actually occurred. */
860 };
861
862 typedef struct
863 {
864 MS_BOOL bUsed;
865 MS_BOOL bPending;
866 MS_BOOL bEnable;
867 pthread_t ithr;
868 InterruptCb pIntCb;
869 void *pThreadParam;
870
871 } CHIP_HISR_Info;
872
873 typedef unsigned long int nfds_t;
874 extern int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout);
875
876 //-------------------------------------------------------------------------------------------------
877 // Local Variables
878 //-------------------------------------------------------------------------------------------------
879 static CHIP_HISR_Info _HISR_Info[MS_IRQ_MAX];
880 static MS_BOOL _bInHISR = FALSE;
881 static MS_BOOL _bInLISR = FALSE;
882 //static MS_BOOL _bEnableAll = FALSE;
883
884 //-------------------------------------------------------------------------------------------------
885 // Debug Functions
886 //-------------------------------------------------------------------------------------------------
887
888 //-------------------------------------------------------------------------------------------------
889 // Local Functions
890 //-------------------------------------------------------------------------------------------------
891
892 // -- Jerry --
893 // Leave these to be chip independent. Different chip can have the opportunities to
894 // revise the priority policy for different interrupts.
895
896 //-------------------------------------------------------------------------------------------------
897 // ISR of IRQ
898 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
899 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
900 // @return ISR result
901 //-------------------------------------------------------------------------------------------------
902 /*
903 static MS_U32 _CHIP_LISR0(MS_U32 u32VectorNum, MS_U32 u32Data)
904 {
905 return FALSE;
906 }
907 */
908
909 //-------------------------------------------------------------------------------------------------
910 // ISR of FIQ
911 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
912 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
913 // @return ISR result
914 // @note FIQ - handle interrupt service routine in ISR
915 //-------------------------------------------------------------------------------------------------
916 /*
917 static MS_U32 _CHIP_LISR1(MS_U32 u32VectorNum, MS_U32 u32Data)
918 {
919 return FALSE;
920 }
921 */
922
923 //-------------------------------------------------------------------------------------------------
924 // DSR of IRQ
925 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
926 // @param u32Count \b IN: # of occurrences
927 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
928 // @return None
929 //-------------------------------------------------------------------------------------------------
930 /*
931 static void _CHIP_HISR0(MS_U32 u32VectorNum, MS_U32 u32Count, MS_U32 u32Data)
932 {
933 }
934
935
936 static void _CHIP_HISR1(MS_U32 u32VectorNum, MS_U32 u32Count, MS_U32 u32Data)
937 {
938 }
939 */
940
941 //-------------------------------------------------------------------------------------------------
942 // Global Functions
943 //-------------------------------------------------------------------------------------------------
944
interrupt_thread(void * arg)945 static void *interrupt_thread(void *arg)
946 {
947 struct irq_desc *ip = (struct irq_desc *)arg;
948 int fd = ip->irqfd;
949 int err;
950 struct pollfd PollFd;
951 int irq;
952 char irq_thd_name[MAX_NAME];
953
954 //naming the irq thread
955 irq = ip->u16irq + CHIP_INT_BASE;
956 memset(irq_thd_name, '\0', sizeof(irq_thd_name));
957 snprintf(irq_thd_name, MAX_NAME - 1, "IRQThread_%d", irq);
958 prctl(PR_SET_NAME, (unsigned long) irq_thd_name, NULL, NULL, NULL);
959 memset(irq_thd_name, '\0', sizeof(irq_thd_name));
960 prctl(PR_GET_NAME, (unsigned long) irq_thd_name, NULL, NULL, NULL);
961 //printf("%s\n", irq_thd_name);
962
963 PollFd.fd = fd;
964 PollFd.events = POLLIN;
965 PollFd.revents = 0;
966
967 for(;;)
968 {
969 if(!_HISR_Info[ip->u16irq].bUsed)
970 {
971 //normal exit
972 break;
973 }
974
975
976 err = poll(&PollFd, 1, 100);
977 if (err == -1)
978 {
979 // errno use from standard c library
980 // coverity[dereference]
981 if(errno==EINTR)
982 {
983 continue;
984 }
985 else
986 {
987 printf("IRQ %d ", (ip->u16irq + CHIP_INT_BASE));
988 perror("polling error!!");
989 break;
990 }
991 }
992 else if(PollFd.revents & (0x08 | 0x10 | 0x20)) //<= we can not include poll.h so use 0x08=POLLERR 0x10=POLLHUP 0x20=POLLNVAL
993 {
994 printf("IRQ %d ",(ip->u16irq + CHIP_INT_BASE));
995 perror("polling error!!");
996 break;
997 }
998
999 if(PollFd.revents & POLLIN)
1000 {
1001 //after successful polling, interrupt had been disable by Kernel
1002 _HISR_Info[(IRQFIQNum)ip->u16irq].bEnable = FALSE;
1003 #if SEND_ACK == 1
1004 int enable = E_IRQ_ACK;
1005 write(fd, &enable, sizeof(enable));
1006 #endif
1007 (void)(ip->handler)((InterruptNum) HWIdx2IntEnum[ip->u16irq]);
1008 }
1009
1010
1011 }
1012
1013 return NULL;
1014 }
1015
CHIP_EnableAllInterrupt(void)1016 MS_BOOL CHIP_EnableAllInterrupt(void)
1017 {
1018 //_bEnableAll = TRUE;
1019 return TRUE;
1020 }
1021
CHIP_DisableAllInterrupt(void)1022 MS_BOOL CHIP_DisableAllInterrupt(void)
1023 {
1024 //_bEnableAll = FALSE;
1025 return TRUE;
1026 }
1027
CHIP_ProcessIRQ(InterruptNum eIntNum,IrqDebugOpt eIrqDebugOpt)1028 static MS_BOOL CHIP_ProcessIRQ(InterruptNum eIntNum, IrqDebugOpt eIrqDebugOpt)
1029 {
1030 int opt = eIrqDebugOpt;
1031 int fd;
1032 MS_U8 u8VectorIndex = 0;
1033
1034 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1035
1036 if (_HISR_Info[u8VectorIndex].pThreadParam)
1037 {
1038 fd = ((struct irq_desc *)_HISR_Info[u8VectorIndex].pThreadParam)->irqfd;
1039 write(fd, &opt, sizeof(opt));
1040 }
1041
1042 if (eIrqDebugOpt == E_IRQ_ENABLE)
1043 {
1044 _HISR_Info[u8VectorIndex].bEnable = TRUE ;
1045 }
1046 else if (eIrqDebugOpt == E_IRQ_DISABLE)
1047 {
1048 _HISR_Info[u8VectorIndex].bEnable = FALSE ;
1049 }
1050
1051 return TRUE ;
1052 }
1053
CHIP_DebugIRQ(InterruptNum eIntNum,IrqDebugOpt eIrqDebugOpt)1054 MS_BOOL CHIP_DebugIRQ(InterruptNum eIntNum, IrqDebugOpt eIrqDebugOpt)
1055 {
1056 return CHIP_ProcessIRQ(eIntNum, eIrqDebugOpt);
1057 }
1058
CHIP_EnableIRQ(InterruptNum eIntNum)1059 MS_BOOL CHIP_EnableIRQ(InterruptNum eIntNum)
1060 {
1061 return CHIP_ProcessIRQ(eIntNum, E_IRQ_ENABLE);
1062 }
1063
CHIP_DisableIRQ(InterruptNum eIntNum)1064 MS_BOOL CHIP_DisableIRQ(InterruptNum eIntNum)
1065 {
1066 return CHIP_ProcessIRQ(eIntNum, E_IRQ_DISABLE);
1067 }
1068
CHIP_CompleteIRQ(InterruptNum eIntNum)1069 MS_BOOL CHIP_CompleteIRQ(InterruptNum eIntNum)
1070 {
1071 return CHIP_ProcessIRQ(eIntNum, E_IRQ_COMPLETE);
1072 }
1073
UTL_memset(void * d,int c,size_t n)1074 void *UTL_memset(void *d, int c, size_t n)
1075 {
1076 MS_U8 *pu8Dst = d;
1077 register MS_U32 u32Cnt = n;
1078 register MS_U32 u32Val;
1079 register MS_U32 *pu32Dst;
1080
1081 c &= 0xff;
1082
1083 while ((MS_VIRT)pu8Dst & 3 && u32Cnt)
1084 {
1085 *pu8Dst++ = (MS_U8)c;
1086 u32Cnt--;
1087 }
1088
1089 pu32Dst = (MS_U32 *)pu8Dst;
1090 u32Val = (c << 8) | c;
1091 u32Val = (u32Val << 16) | u32Val;
1092 while(u32Cnt >= 32)
1093 {
1094 pu32Dst[0]= u32Val;
1095 pu32Dst[1]= u32Val;
1096 pu32Dst[2]= u32Val;
1097 pu32Dst[3]= u32Val;
1098 pu32Dst[4]= u32Val;
1099 pu32Dst[5]= u32Val;
1100 pu32Dst[6]= u32Val;
1101 pu32Dst[7]= u32Val;
1102 pu32Dst += 8;
1103 u32Cnt -= 32;
1104 }
1105
1106 while(u32Cnt >= 4)
1107 {
1108 *pu32Dst++ = u32Val;
1109 u32Cnt -= 4;
1110 }
1111
1112 pu8Dst = (MS_U8 *)pu32Dst;
1113 while(u32Cnt)
1114 {
1115 *pu8Dst++ = (MS_U8)c;
1116 u32Cnt--;
1117 }
1118
1119 return d;
1120 }
1121
CHIP_AttachISR(InterruptNum eIntNum,InterruptCb pIntCb)1122 MS_BOOL CHIP_AttachISR(InterruptNum eIntNum, InterruptCb pIntCb)
1123 {
1124 int fd = 0;
1125 char name[48];
1126 struct irq_desc *idp;
1127 pthread_attr_t attr;
1128 struct sched_param schp;
1129 MS_U8 u8VectorIndex = 0;
1130
1131 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1132
1133 idp = (struct irq_desc*) malloc(sizeof(*idp));
1134 MS_ASSERT(idp != NULL);
1135 if (idp == NULL)
1136 {
1137 return FALSE;
1138 }
1139
1140 snprintf(name, sizeof(name) - 1, "/proc/irq/%d/irq", (u8VectorIndex + CHIP_INT_BASE));
1141 //printf("name=%s\n", name);
1142
1143 fd = open(name, O_RDWR | O_EXCL);
1144 if (fd < 0)
1145 {
1146 printf("Cannot open interrupt descriptor for irq=%d ", (MS_U16)(u8VectorIndex + CHIP_INT_BASE));
1147 perror("");
1148 free(idp);
1149 return FALSE;
1150 }
1151
1152 idp->irqfd = fd;
1153 idp->u16irq = (MS_U16)u8VectorIndex;
1154 idp->driverp = &(idp->u16irq);
1155 idp->handler = (pIntCb);
1156
1157 UTL_memset(&schp, 0, sizeof(schp));
1158 schp.sched_priority = sched_get_priority_max(SCHED_FIFO);
1159
1160 pthread_attr_init(&attr);
1161 pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
1162 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
1163 pthread_attr_setschedparam(&attr, &schp);
1164
1165 _HISR_Info[u8VectorIndex].pIntCb = pIntCb;
1166 _HISR_Info[u8VectorIndex].pThreadParam = idp;
1167 _HISR_Info[u8VectorIndex].bUsed = TRUE;
1168 _HISR_Info[u8VectorIndex].bEnable = FALSE;
1169
1170 if(0 != pthread_create(&_HISR_Info[u8VectorIndex].ithr, &attr, interrupt_thread, idp))
1171 {
1172 printf("Create interrupt thread fail!!!\n");
1173 close(fd);
1174 free(idp);
1175 return FALSE;
1176 }
1177
1178 return TRUE;
1179 }
1180
1181
CHIP_DetachISR(InterruptNum eIntNum)1182 MS_BOOL CHIP_DetachISR(InterruptNum eIntNum)
1183 {
1184 MS_U8 u8VectorIndex = 0;
1185
1186 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1187
1188 if(TRUE == _HISR_Info[u8VectorIndex].bEnable)
1189 {
1190 CHIP_DisableIRQ(eIntNum);
1191 }
1192
1193 _HISR_Info[u8VectorIndex].bUsed = FALSE;
1194
1195 if(_HISR_Info[u8VectorIndex].ithr)
1196 {
1197 int ret;
1198
1199 if((ret=pthread_join(_HISR_Info[u8VectorIndex].ithr, NULL))!=0)
1200 {
1201 printf("IRQ %d ", (MS_U16)(u8VectorIndex + CHIP_INT_BASE));
1202 perror("polling thread destroy failed");
1203 }
1204 else
1205 {
1206 printf("IRQ %d polling thread destroyed\n", (MS_U16)(u8VectorIndex + CHIP_INT_BASE));
1207
1208 }
1209 _HISR_Info[u8VectorIndex].ithr = 0;
1210 }
1211
1212
1213
1214 if(_HISR_Info[u8VectorIndex].pThreadParam)
1215 {
1216 int ret;
1217
1218 if(-1 == ioctl(((struct irq_desc *)_HISR_Info[u8VectorIndex].pThreadParam)->irqfd, 137))
1219 {
1220 printf("%s.%d ioctl fail\n",__FUNCTION__, __LINE__);
1221 }
1222 if((ret = close(((struct irq_desc *) _HISR_Info[u8VectorIndex].pThreadParam)->irqfd)) == -1)
1223 {
1224 printf("IRQ %d ", (MS_U16)(u8VectorIndex + CHIP_INT_BASE));
1225 perror("polling fd close failed");
1226 }
1227 else
1228 {
1229 printf("IRQ %d polling fd closed!!\n", (MS_U16)(u8VectorIndex + CHIP_INT_BASE));
1230 }
1231 free(_HISR_Info[u8VectorIndex].pThreadParam);
1232 _HISR_Info[u8VectorIndex].pThreadParam = NULL;
1233 }
1234
1235 return TRUE;
1236 }
1237
CHIP_InISRContext(void)1238 MS_BOOL CHIP_InISRContext(void)
1239 {
1240 if (_bInLISR || _bInHISR)
1241 {
1242 return TRUE;
1243 }
1244 else
1245 {
1246 return FALSE;
1247 }
1248 }
1249
CHIP_InitISR(void)1250 void CHIP_InitISR(void)
1251 {
1252 MS_U16 i = 0;
1253
1254 HAL_InitIrqTable();
1255
1256 for(i = 0; i < MS_IRQ_MAX; i++)
1257 {
1258 _HISR_Info[i].bUsed = 0;
1259 _HISR_Info[i].bPending = 0;
1260 _HISR_Info[i].bEnable = 0;
1261 _HISR_Info[i].ithr = 0;
1262 _HISR_Info[i].pIntCb = 0;
1263 _HISR_Info[i].pThreadParam = NULL;
1264 }
1265
1266 //printf("+pthread_mutex_init\n");
1267 //pthread_mutex_init(&_HISR_Info,NULL);
1268 //printf("-CHIP_InitISR\n");
1269 }
1270
1271 #endif
1272
1273 #if defined (MSOS_TYPE_UCOS)
1274
1275 #include "MsCommon.h"
1276 #include "MsOS.h"
1277 #include "halIRQTBL.h"
1278 #include "halCHIP.h"
1279 #include "regCHIP.h"
1280 #include "asmCPU.h"
1281 #include "ucos_ii.h"
1282
1283 //-------------------------------------------------------------------------------------------------
1284 // Driver Compiler Options
1285 //-------------------------------------------------------------------------------------------------
1286
1287 //-------------------------------------------------------------------------------------------------
1288 // Local Defines
1289 //-------------------------------------------------------------------------------------------------
1290 #define CHIP_LISR_MAX 2 //vector0: IRQ, vector1: FIQ, vector5: Timer INT
1291
1292 //-------------------------------------------------------------------------------------------------
1293 // Local Structures
1294 //-------------------------------------------------------------------------------------------------
1295
1296 typedef struct
1297 {
1298 MS_BOOL bUsed;
1299 MS_BOOL bPending;
1300 InterruptCb pIntCb;
1301 } CHIP_HISR_Info;
1302
1303 //-------------------------------------------------------------------------------------------------
1304 // Global Variables
1305 //-------------------------------------------------------------------------------------------------
1306
1307 //-------------------------------------------------------------------------------------------------
1308 // Local Variables
1309 //-------------------------------------------------------------------------------------------------
1310 static CHIP_HISR_Info _HISR_Info[MS_IRQ_MAX];
1311 static MS_BOOL _bInHISR = FALSE;
1312
1313 //-------------------------------------------------------------------------------------------------
1314 // Debug Functions
1315 //-------------------------------------------------------------------------------------------------
1316
1317 //-------------------------------------------------------------------------------------------------
1318 // Local Functions
1319 //-------------------------------------------------------------------------------------------------
1320 MS_BOOL CHIP_DisableIRQ(InterruptNum eIntNum);
1321
1322 // -- Jerry --
1323 // Leave these to be chip independent. Different chip can have the opportunities to
1324 // revise the priority policy for different interrupts.
1325
1326 //
1327 // _CHIP_DetectIRQSource will be called by _CHIP_HISR0
1328 //
_CHIP_DetectIRQSource(void)1329 InterruptNum _CHIP_DetectIRQSource(void)
1330 {
1331 MS_U32 u32Reg;
1332
1333 ////////////////////////
1334 // Detect FIQ
1335 ////////////////////////
1336 u32Reg=0;
1337
1338 u32Reg = IRQ_REG(REG_FIQ_PENDING_H);
1339 u32Reg <<=16;
1340 u32Reg |= IRQ_REG(REG_FIQ_PENDING_L);
1341
1342
1343 if(u32Reg != 0)
1344 {
1345 return E_INTERRUPT_FIQ;
1346 }
1347
1348 u32Reg=0;
1349
1350 u32Reg = IRQ_REG(REG_FIQEXP_PENDING_H);
1351 u32Reg <<=16;
1352 u32Reg |= IRQ_REG(REG_FIQEXP_PENDING_L);
1353
1354
1355 if(u32Reg != 0)
1356 {
1357 return E_INTERRUPT_FIQ;
1358 }
1359
1360 u32Reg=0;
1361
1362 u32Reg = IRQHYP_REG(REG_FIQHYP_PENDING_H);
1363 u32Reg <<=16;
1364 u32Reg |= IRQHYP_REG(REG_FIQHYP_PENDING_L);
1365
1366
1367 if(u32Reg != 0)
1368 {
1369 return E_INTERRUPT_FIQ;
1370 }
1371
1372 ////////////////////////
1373 // Detect IRQ
1374 ////////////////////////
1375 u32Reg=0;
1376
1377 u32Reg = IRQ_REG(REG_IRQ_PENDING_H);
1378 u32Reg <<=16;
1379 u32Reg |= IRQ_REG(REG_IRQ_PENDING_L);
1380
1381 if(u32Reg != 0)
1382 {
1383 return E_INTERRUPT_IRQ;
1384 }
1385
1386 u32Reg=0;
1387
1388 u32Reg = IRQ_REG(REG_IRQEXP_PENDING_H);
1389 u32Reg <<=16;
1390 u32Reg |= IRQ_REG(REG_IRQEXP_PENDING_L);
1391
1392 if(u32Reg != 0)
1393 {
1394 return E_INTERRUPT_IRQ;
1395 }
1396
1397 u32Reg=0;
1398
1399 u32Reg = IRQHYP_REG(REG_IRQHYP_PENDING_H);
1400 u32Reg <<=16;
1401 u32Reg |= IRQHYP_REG(REG_IRQHYP_PENDING_L);
1402
1403 if(u32Reg != 0)
1404 {
1405 return E_INTERRUPT_IRQ;
1406 }
1407
1408 return E_INTERRUPT_IRQ;
1409 }
1410
__CHIP_HISR1(MS_U32 u32VectorNum,MS_U32 u32Data)1411 void __CHIP_HISR1(MS_U32 u32VectorNum, MS_U32 u32Data)
1412 {
1413 MS_U32 u32Reg;
1414 MS_U32 u32Bit;
1415 IRQFIQNum eVector;
1416 InterruptNum eIntNum;
1417
1418 //in interrupt context
1419 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
1420 OS_CPU_SR cpu_sr = 0;
1421 #endif
1422
1423 _bInHISR = TRUE; //in interrupt context
1424
1425 u32Reg = 0;
1426 u32Reg = IRQ_REG(REG_FIQ_PENDING_H);
1427 u32Reg <<= 16;
1428 u32Reg |= IRQ_REG(REG_FIQ_PENDING_L);
1429
1430 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
1431 {
1432 if(u32Bit < 16)
1433 {
1434 eVector = (IRQFIQNum)(u32Bit + E_FIQL_START);
1435 }
1436 else
1437 {
1438 eVector = (IRQFIQNum)((u32Bit-16) + E_FIQH_START);
1439 }
1440 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
1441 CHIP_DisableIRQ(eIntNum);
1442 if(_HISR_Info[eVector].bUsed)
1443 {
1444 _HISR_Info[eVector].bPending = FALSE;
1445 _HISR_Info[eVector].pIntCb((InterruptNum)eIntNum);
1446 }
1447 u32Reg &= ~(0x01 << u32Bit);
1448 }
1449
1450 u32Reg = 0;
1451 u32Reg = IRQ_REG(REG_FIQEXP_PENDING_H);
1452 u32Reg <<=16;
1453 u32Reg |= IRQ_REG(REG_FIQEXP_PENDING_L);
1454
1455 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
1456 {
1457 if(u32Bit<16)
1458 {
1459 eVector = (IRQFIQNum)(u32Bit + E_FIQEXPL_START);
1460 }
1461 else
1462 {
1463 eVector = (IRQFIQNum)((u32Bit-16) + E_FIQEXPH_START);
1464 }
1465 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
1466 CHIP_DisableIRQ(eIntNum);
1467 if(_HISR_Info[eVector].bUsed)
1468 {
1469 _HISR_Info[eVector].bPending = FALSE;
1470 _HISR_Info[eVector].pIntCb((InterruptNum)eIntNum);
1471 }
1472 u32Reg &= ~(0x1 << u32Bit);
1473 }
1474
1475 u32Reg = 0;
1476 u32Reg = IRQHYP_REG(REG_FIQHYP_PENDING_H);
1477 u32Reg <<=16;
1478 u32Reg |= IRQHYP_REG(REG_FIQHYP_PENDING_L);
1479
1480 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
1481 {
1482 if(u32Bit<16)
1483 {
1484 eVector = (IRQFIQNum)(u32Bit + E_FIQHYPL_START);
1485 }
1486 else
1487 {
1488 eVector = (IRQFIQNum)((u32Bit-16) + E_FIQHYPH_START);
1489 }
1490 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
1491 CHIP_DisableIRQ(eIntNum);
1492 if(_HISR_Info[eVector].bUsed)
1493 {
1494 _HISR_Info[eVector].bPending = FALSE;
1495 _HISR_Info[eVector].pIntCb((InterruptNum)eIntNum);
1496 }
1497 u32Reg &= ~(0x1 << u32Bit);
1498 }
1499
1500 //exit interrupt context
1501 _bInHISR = FALSE;
1502 }
1503
1504
1505
1506 //-------------------------------------------------------------------------------------------------
1507 // DSR of IRQ
1508 // @param u32VectorNum \b IN: 0: IRQ 1: FIQ
1509 // @param u32Count \b IN: # of occurrences
1510 // @param u32Data \b IN: argument 3 of cyg_interrupt_create
1511 // @return None
1512 //-------------------------------------------------------------------------------------------------
_CHIP_HISR0(MS_U32 u32VectorNum,MS_U32 u32Data)1513 void _CHIP_HISR0(MS_U32 u32VectorNum, MS_U32 u32Data)
1514 {
1515 MS_U32 u32Reg;
1516 MS_U32 u32Bit;
1517 IRQFIQNum eVector;
1518 InterruptNum eIntNum;
1519
1520 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
1521 OS_CPU_SR cpu_sr = 0;
1522 #endif
1523
1524 OS_ENTER_CRITICAL();
1525 if (_CHIP_DetectIRQSource()==E_INTERRUPT_IRQ)
1526 {
1527 _bInHISR = TRUE; //in interrupt context
1528
1529 u32Reg = 0;
1530 u32Reg = IRQ_REG(REG_IRQ_PENDING_H);
1531 u32Reg <<= 16;
1532 u32Reg |= IRQ_REG(REG_IRQ_PENDING_L);
1533
1534 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
1535 {
1536 if(u32Bit < 16)
1537 {
1538 eVector = (IRQFIQNum)(u32Bit + E_IRQL_START);
1539 }
1540 else
1541 {
1542 eVector = (IRQFIQNum)((u32Bit-16) + E_IRQH_START);
1543 }
1544
1545 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
1546 CHIP_DisableIRQ(eIntNum);
1547 if(_HISR_Info[eVector].bUsed)
1548 {
1549 _HISR_Info[eVector].bPending = FALSE;
1550 _HISR_Info[eVector].pIntCb((InterruptNum)eIntNum);
1551 }
1552 u32Reg &= ~(0x01 << u32Bit);
1553 }
1554
1555 u32Reg = 0;
1556 u32Reg = IRQ_REG(REG_IRQEXP_PENDING_H);
1557 u32Reg <<= 16;
1558 u32Reg |= IRQ_REG(REG_IRQEXP_PENDING_L);
1559
1560 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
1561 {
1562 if(u32Bit < 16)
1563 {
1564 eVector = (IRQFIQNum)(u32Bit + E_IRQEXPL_START);
1565 }
1566 else
1567 {
1568 eVector = (IRQFIQNum)((u32Bit-16) + E_IRQEXPH_START);
1569 }
1570
1571 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
1572 CHIP_DisableIRQ(eIntNum);
1573 if(_HISR_Info[eVector].bUsed)
1574 {
1575 _HISR_Info[eVector].bPending = FALSE;
1576 _HISR_Info[eVector].pIntCb((InterruptNum)eIntNum);
1577 }
1578 u32Reg &= ~(0x01 << u32Bit);
1579 }
1580
1581 u32Reg = 0;
1582 u32Reg = IRQHYP_REG(REG_IRQHYP_PENDING_H);
1583 u32Reg <<= 16;
1584 u32Reg |= IRQHYP_REG(REG_IRQHYP_PENDING_L);
1585
1586 while(32 != (u32Bit = MAsm_CPU_GetTrailOne(u32Reg)))
1587 {
1588 if(u32Bit < 16)
1589 {
1590 eVector = (IRQFIQNum)(u32Bit + E_IRQHYPL_START);
1591 }
1592 else
1593 {
1594 eVector = (IRQFIQNum)((u32Bit-16) + E_IRQHYPH_START);
1595 }
1596
1597 eIntNum = (InterruptNum) HWIdx2IntEnum[eVector];
1598 CHIP_DisableIRQ(eIntNum);
1599 if(_HISR_Info[eVector].bUsed)
1600 {
1601 _HISR_Info[eVector].bPending = FALSE;
1602 _HISR_Info[eVector].pIntCb((InterruptNum)eIntNum);
1603 }
1604 u32Reg &= ~(0x01 << u32Bit);
1605 }
1606
1607 _bInHISR = FALSE;
1608 }
1609 else if (_CHIP_DetectIRQSource()==E_INTERRUPT_FIQ)
1610 {
1611 __CHIP_HISR1(u32VectorNum,u32Data);
1612 }
1613 OS_EXIT_CRITICAL();
1614 }
1615
_CHIP_HISR1(MS_U32 u32VectorNum,MS_U32 u32Data)1616 void _CHIP_HISR1(MS_U32 u32VectorNum, MS_U32 u32Data)
1617 {
1618 //in interrupt context
1619 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
1620 OS_CPU_SR cpu_sr = 0;
1621 #endif
1622 OS_ENTER_CRITICAL();
1623 __CHIP_HISR1(u32VectorNum,u32Data);
1624 //exit interrupt context
1625 OS_EXIT_CRITICAL();
1626 }
1627
1628 //-------------------------------------------------------------------------------------------------
1629 // Global Functions
1630 //-------------------------------------------------------------------------------------------------
1631
CHIP_EnableIRQ(InterruptNum eIntNum)1632 MS_BOOL CHIP_EnableIRQ(InterruptNum eIntNum)
1633 {
1634 MS_BOOL bRet = TRUE;
1635 MS_U8 u8VectorIndex = 0;
1636
1637 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1638
1639 if(_HISR_Info[u8VectorIndex].bUsed)
1640 {
1641 if (u8VectorIndex == E_IRQ_FIQ_ALL)
1642 {
1643 IRQ_REG(REG_IRQ_MASK_L) &= ~0xFFFF;
1644 IRQ_REG(REG_IRQ_MASK_H) &= ~0xFFFF;
1645 IRQ_REG(REG_IRQEXP_MASK_L) &= ~0xFFFF;
1646 IRQ_REG(REG_IRQEXP_MASK_H) &= ~0xFFFF;
1647 IRQ_REG(REG_FIQ_MASK_L) &= ~0xFFFF;
1648 IRQ_REG(REG_FIQ_MASK_H) &= ~0xFFFF;
1649 IRQ_REG(REG_FIQEXP_MASK_L) &= ~0xFFFF;
1650 IRQ_REG(REG_FIQEXP_MASK_H) &= ~0xFFFF;
1651
1652 IRQHYP_REG(REG_IRQHYP_MASK_L) &= ~0xFFFF;
1653 IRQHYP_REG(REG_IRQHYP_MASK_H) &= ~0xFFFF;
1654 IRQHYP_REG(REG_FIQHYP_MASK_L) &= ~0xFFFF;
1655 IRQHYP_REG(REG_FIQHYP_MASK_H) &= ~0xFFFF;
1656 }
1657 else if((u8VectorIndex >= E_IRQL_START) && (u8VectorIndex <= (MS_U8) E_IRQL_END))
1658 {
1659 IRQ_REG(REG_IRQ_MASK_L) &= ~(0x01 << (u8VectorIndex - E_IRQL_START));
1660 }
1661 else if((u8VectorIndex >= (MS_U8) E_IRQH_START) && (u8VectorIndex <= (MS_U8) E_IRQH_END))
1662 {
1663 IRQ_REG(REG_IRQ_MASK_H) &= ~(0x01 << (u8VectorIndex - E_IRQH_START));
1664 }
1665 else if((u8VectorIndex >= (MS_U8) E_IRQEXPL_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPL_END))
1666 {
1667 IRQ_REG(REG_IRQEXP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_IRQEXPL_START));
1668 }
1669 else if((u8VectorIndex >= (MS_U8) E_IRQEXPH_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPH_END))
1670 {
1671 IRQ_REG(REG_IRQEXP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_IRQEXPH_START));
1672 }
1673 else if((u8VectorIndex >= (MS_U8) E_IRQHYPL_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPL_END))
1674 {
1675 IRQHYP_REG(REG_IRQHYP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_IRQHYPL_START));
1676 }
1677 else if((u8VectorIndex >= (MS_U8) E_IRQHYPH_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPH_END))
1678 {
1679 IRQHYP_REG(REG_IRQHYP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_IRQHYPH_START));
1680 }
1681 else if((u8VectorIndex >= (MS_U8) E_FIQL_START) && (u8VectorIndex <= (MS_U8) E_FIQL_END))
1682 {
1683 IRQ_REG(REG_FIQ_MASK_L) &= ~(0x01 << (u8VectorIndex - E_FIQL_START));
1684 }
1685 else if((u8VectorIndex >= (MS_U8) E_FIQH_START) && (u8VectorIndex <= (MS_U8) E_FIQH_END))
1686 {
1687 IRQ_REG(REG_FIQ_MASK_H) &= ~(0x01 << (u8VectorIndex - E_FIQH_START));
1688 }
1689 else if((u8VectorIndex >= (MS_U8) E_FIQEXPL_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPL_END))
1690 {
1691 IRQ_REG(REG_FIQEXP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_FIQEXPL_START));
1692 }
1693 else if((u8VectorIndex >= (MS_U8) E_FIQEXPH_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPH_END))
1694 {
1695 IRQ_REG(REG_FIQEXP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_FIQEXPH_START));
1696 }
1697 else if((u8VectorIndex >= (MS_U8) E_FIQHYPL_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPL_END))
1698 {
1699 IRQHYP_REG(REG_FIQHYP_MASK_L) &= ~(0x01 << (u8VectorIndex - E_FIQHYPL_START));
1700 }
1701 else if((u8VectorIndex >= (MS_U8) E_FIQHYPH_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPH_END))
1702 {
1703 IRQHYP_REG(REG_FIQHYP_MASK_H) &= ~(0x01 << (u8VectorIndex - E_FIQHYPH_START));
1704 }
1705 }
1706 else
1707 {
1708 bRet = FALSE;
1709 }
1710
1711 return bRet;
1712 }
1713
CHIP_DisableIRQ(InterruptNum eIntNum)1714 MS_BOOL CHIP_DisableIRQ(InterruptNum eIntNum)
1715 {
1716 MS_U8 u8VectorIndex = 0;
1717
1718 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1719
1720 if (u8VectorIndex == E_IRQ_FIQ_ALL)
1721 {
1722 IRQ_REG(REG_IRQ_MASK_L) |= 0xFFFF;
1723 IRQ_REG(REG_IRQ_MASK_H) |= 0xFFFF;
1724 IRQ_REG(REG_IRQEXP_MASK_L) |= 0xFFFF;
1725 IRQ_REG(REG_IRQEXP_MASK_H) |= 0xFFFF;
1726 IRQ_REG(REG_FIQ_MASK_L) |= 0xFFFF;
1727 IRQ_REG(REG_FIQ_MASK_H) |= 0xFFFF;
1728 IRQ_REG(REG_FIQEXP_MASK_L) |= 0xFFFF;
1729 IRQ_REG(REG_FIQEXP_MASK_H) |= 0xFFFF;
1730
1731 IRQHYP_REG(REG_IRQHYP_MASK_L) |= 0xFFFF;
1732 IRQHYP_REG(REG_IRQHYP_MASK_H) |= 0xFFFF;
1733 IRQHYP_REG(REG_FIQHYP_MASK_L) |= 0xFFFF;
1734 IRQHYP_REG(REG_FIQHYP_MASK_H) |= 0xFFFF;
1735 }
1736 else if((u8VectorIndex >= E_IRQL_START) && (u8VectorIndex <= (MS_U8) E_IRQL_END))
1737 {
1738 IRQ_REG(REG_IRQ_MASK_L) |= (0x01 << (u8VectorIndex - E_IRQL_START));
1739 }
1740 else if((u8VectorIndex >= (MS_U8) E_IRQH_START) && (u8VectorIndex <= (MS_U8) E_IRQH_END))
1741 {
1742 IRQ_REG(REG_IRQ_MASK_H) |= (0x01 << (u8VectorIndex - E_IRQH_START));
1743 }
1744 else if((u8VectorIndex >= (MS_U8) E_IRQEXPL_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPL_END))
1745 {
1746 IRQ_REG(REG_IRQEXP_MASK_L) |= (0x01 << (u8VectorIndex - E_IRQEXPL_START));
1747 }
1748 else if((u8VectorIndex >= (MS_U8) E_IRQEXPH_START) && (u8VectorIndex <= (MS_U8) E_IRQEXPH_END))
1749 {
1750 IRQ_REG(REG_IRQEXP_MASK_H) |= (0x01 << (u8VectorIndex - E_IRQEXPH_START));
1751 }
1752 else if((u8VectorIndex >= (MS_U8) E_IRQHYPL_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPL_END))
1753 {
1754 IRQHYP_REG(REG_IRQHYP_MASK_L) |= (0x01 << (u8VectorIndex - E_IRQHYPL_START));
1755 }
1756 else if((u8VectorIndex >= (MS_U8) E_IRQHYPH_START) && (u8VectorIndex <= (MS_U8) E_IRQHYPH_END))
1757 {
1758 IRQHYP_REG(REG_IRQHYP_MASK_H) |= (0x01 << (u8VectorIndex - E_IRQHYPH_START));
1759 }
1760 else if((u8VectorIndex >= (MS_U8) E_FIQL_START) && (u8VectorIndex <= (MS_U8) E_FIQL_END))
1761 {
1762 IRQ_REG(REG_FIQ_MASK_L) |= (0x01 << (u8VectorIndex - E_FIQL_START));
1763 IRQ_REG(REG_FIQ_CLEAR_L) = (0x01 << (u8VectorIndex - E_FIQL_START));
1764 }
1765 else if((u8VectorIndex >= (MS_U8) E_FIQH_START) && (u8VectorIndex <= (MS_U8) E_FIQH_END))
1766 {
1767 IRQ_REG(REG_FIQ_MASK_H) |= (0x01 << (u8VectorIndex - E_FIQH_START));
1768 IRQ_REG(REG_FIQ_CLEAR_H) = (0x01 << (u8VectorIndex - E_FIQH_START));
1769 }
1770 else if((u8VectorIndex >= (MS_U8) E_FIQEXPL_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPL_END))
1771 {
1772 IRQ_REG(REG_FIQEXP_MASK_L) |= (0x01 << (u8VectorIndex - E_FIQEXPL_START));
1773 IRQ_REG(REG_FIQEXP_CLEAR_L) = (0x01 << (u8VectorIndex - E_FIQEXPL_START));
1774 }
1775 else if((u8VectorIndex >= (MS_U8) E_FIQEXPH_START) && (u8VectorIndex <= (MS_U8) E_FIQEXPH_END))
1776 {
1777 IRQ_REG(REG_FIQEXP_MASK_H) |= (0x01 << (u8VectorIndex - E_FIQEXPH_START));
1778 IRQ_REG(REG_FIQEXP_CLEAR_H) = (0x01 << (u8VectorIndex - E_FIQEXPH_START));
1779 }
1780 else if((u8VectorIndex >= (MS_U8) E_FIQHYPL_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPL_END))
1781 {
1782 IRQHYP_REG(REG_FIQHYP_MASK_L) |= (0x01 << (u8VectorIndex - E_FIQHYPL_START));
1783 IRQHYP_REG(REG_FIQHYP_CLEAR_L) = (0x01 << (u8VectorIndex - E_FIQHYPL_START));
1784 }
1785 else if((u8VectorIndex >= (MS_U8) E_FIQHYPH_START) && (u8VectorIndex <= (MS_U8) E_FIQHYPH_END))
1786 {
1787 IRQHYP_REG(REG_FIQHYP_MASK_H) |= (0x01 << (u8VectorIndex - E_FIQHYPH_START));
1788 IRQHYP_REG(REG_FIQHYP_CLEAR_H) = (0x01 << (u8VectorIndex - E_FIQHYPH_START));
1789 }
1790 return TRUE;
1791 }
1792
CHIP_AttachISR(InterruptNum eIntNum,InterruptCb pIntCb)1793 MS_BOOL CHIP_AttachISR(InterruptNum eIntNum, InterruptCb pIntCb)
1794 {
1795 MS_U8 u8VectorIndex = 0;
1796
1797 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1798 _HISR_Info[u8VectorIndex].pIntCb = pIntCb;
1799 _HISR_Info[u8VectorIndex].bUsed = TRUE;
1800
1801 return TRUE;
1802 }
1803
CHIP_DetachISR(InterruptNum eIntNum)1804 MS_BOOL CHIP_DetachISR(InterruptNum eIntNum)
1805 {
1806 MS_U8 u8VectorIndex = 0;
1807
1808 u8VectorIndex = (MS_U8)IntEnum2HWIdx[eIntNum];
1809 _HISR_Info[u8VectorIndex].bUsed = FALSE;
1810
1811 return TRUE;
1812 }
1813
CHIP_InISRContext(void)1814 MS_BOOL CHIP_InISRContext(void)
1815 {
1816 if (0 < OSIntNesting)
1817 {
1818 if (FALSE == _bInHISR)
1819 {
1820 printf("[%s][%d] bad status maybe\n", __FUNCTION__, __LINE__);
1821 *((int*)0)= 0;
1822 }
1823 }
1824 else
1825 {
1826 if (TRUE == _bInHISR)
1827 {
1828 printf("[%s][%d] bad status maybe\n", __FUNCTION__, __LINE__);
1829 *((int*)0)= 0;
1830 }
1831 }
1832 return _bInHISR;
1833 }
1834
CHIP_InitISR(void)1835 void CHIP_InitISR(void)
1836 {
1837 MS_U32 i = 0;
1838
1839 HAL_InitIrqTable();
1840
1841 for(i = 0; i < MS_IRQ_MAX; i++)
1842 {
1843 _HISR_Info[i].bUsed = FALSE;
1844 _HISR_Info[i].bPending = FALSE;
1845 }
1846 }
1847
1848 #endif // #if defined (MSOS_TYPE_UCOS)
1849