source: rtems/c/src/lib/libbsp/arm/nds/libnds/source/common/interrupts.c @ 0d34641c

4.104.115
Last change on this file since 0d34641c was 0d34641c, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 04:14:38

Remove CVS-'s.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*---------------------------------------------------------------------------------
2        $Id$
3
4        Copyright (C) 2005
5                Dave Murphy (WinterMute)
6
7        This software is provided 'as-is', without any express or implied
8        warranty.  In no event will the authors be held liable for any
9        damages arising from the use of this software.
10
11        Permission is granted to anyone to use this software for any
12        purpose, including commercial applications, and to alter it and
13        redistribute it freely, subject to the following restrictions:
14
15        1.      The origin of this software must not be misrepresented; you
16                must not claim that you wrote the original software. If you use
17                this software in a product, an acknowledgment in the product
18                documentation would be appreciated but is not required.
19        2.      Altered source versions must be plainly marked as such, and
20                must not be misrepresented as being the original software.
21        3.      This notice may not be removed or altered from any source
22                distribution.
23
24---------------------------------------------------------------------------------*/
25
26#include <nds/interrupts.h>
27#include <nds/system.h>
28
29void IntrMain(void);    // Prototype for assembly interrupt dispatcher
30
31//---------------------------------------------------------------------------------
32void irqDummy(void) {}
33//---------------------------------------------------------------------------------
34
35
36#ifdef ARM9
37#define INT_TABLE_SECTION __attribute__((section(".itcm")))
38#else
39#define INT_TABLE_SECTION
40#endif
41
42struct IntTable irqTable[MAX_INTERRUPTS] INT_TABLE_SECTION;
43
44//---------------------------------------------------------------------------------
45void irqSet(int mask, IntFn handler) {
46//---------------------------------------------------------------------------------
47        if (!mask) return;
48
49        int i;
50
51        for     (i=0;i<MAX_INTERRUPTS;i++)
52                if      (!irqTable[i].mask || irqTable[i].mask == mask) break;
53
54        if ( i == MAX_INTERRUPTS ) return;
55
56        irqTable[i].handler     = handler;
57        irqTable[i].mask        = mask;
58
59        if(mask & IRQ_VBLANK)
60                REG_DISPSTAT |= DISP_VBLANK_IRQ ;
61        if(mask & IRQ_HBLANK)
62                REG_DISPSTAT |= DISP_HBLANK_IRQ ;
63
64        REG_IE |= mask;
65}
66
67//---------------------------------------------------------------------------------
68void irqInit() {
69//---------------------------------------------------------------------------------
70        int i;
71
72        // Set all interrupts to dummy functions.
73        for(i = 0; i < MAX_INTERRUPTS; i ++)
74        {
75                irqTable[i].handler = irqDummy;
76                irqTable[i].mask = 0;
77        }
78
79        IRQ_HANDLER = IntrMain;
80
81        REG_IE  = 0;                    // disable all interrupts
82        REG_IF  = IRQ_ALL;              // clear all pending interrupts
83        REG_IME = 1;                    // enable global interrupt
84
85}
86
87
88//---------------------------------------------------------------------------------
89void irqClear(int mask) {
90//---------------------------------------------------------------------------------
91        int i = 0;
92
93        for     (i=0;i<MAX_INTERRUPTS;i++)
94                if      (irqTable[i].mask == mask) break;
95
96        if ( i == MAX_INTERRUPTS ) return;
97
98        irqTable[i].handler     = irqDummy;
99
100        if (mask & IRQ_VBLANK)
101                REG_DISPSTAT &= ~DISP_VBLANK_IRQ ;
102        if (mask & IRQ_HBLANK)
103                REG_DISPSTAT &= ~DISP_HBLANK_IRQ ;
104        if (mask & IRQ_VCOUNT)
105                REG_DISPSTAT &= ~DISP_YTRIGGER_IRQ;
106
107        REG_IE &= ~mask;
108}
109
110
111//---------------------------------------------------------------------------------
112void irqInitHandler(IntFn handler) {
113//---------------------------------------------------------------------------------
114        REG_IME = 0;
115        REG_IF = ~0;
116        REG_IE = 0;
117
118        IRQ_HANDLER = handler;
119
120        REG_IME = 1;
121}
122
123//---------------------------------------------------------------------------------
124void irqEnable(uint32 irq) {
125//---------------------------------------------------------------------------------
126        if (irq & IRQ_VBLANK)
127                REG_DISPSTAT |= DISP_VBLANK_IRQ ;
128        if (irq & IRQ_HBLANK)
129                REG_DISPSTAT |= DISP_HBLANK_IRQ ;
130        if (irq & IRQ_VCOUNT)
131                REG_DISPSTAT |= DISP_YTRIGGER_IRQ;
132
133        REG_IE |= irq;
134        REG_IME = 1;
135}
136
137//---------------------------------------------------------------------------------
138void irqDisable(uint32 irq) {
139//---------------------------------------------------------------------------------
140        if (irq & IRQ_VBLANK)
141                REG_DISPSTAT &= ~DISP_VBLANK_IRQ ;
142        if (irq & IRQ_HBLANK)
143                REG_DISPSTAT &= ~DISP_HBLANK_IRQ ;
144        if (irq & IRQ_VCOUNT)
145                REG_DISPSTAT &= ~DISP_YTRIGGER_IRQ;
146
147        REG_IE &= ~irq;
148}
149
Note: See TracBrowser for help on using the repository browser.