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

4.115
Last change on this file since ef4c461 was ef4c461, checked in by Joel Sherrill <joel.sherrill@…>, on 10/09/14 at 20:35:10

arm/nds: Warning clean up

This patch eliminates most of the warnings in this BSP but attempts
very little clean up. This BSP includes copies of a lot of code
from free NDS libraries and modifications should be kept to a minimum.

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