~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/scriptedwizard/resources/arm/files/phyCORE-PXA255/src/irq.c

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*====================================================================
 
2
* Project: Board Support Package (BSP)
 
3
* Developed using:
 
4
* Function: Handling of IRQ interrupts on Intel XScale PXA255
 
5
*
 
6
* Copyright HighTec EDV-Systeme GmbH 1982-2006
 
7
*====================================================================*/
 
8
 
 
9
#include "pxa255regs.h"
 
10
#include "irq.h"
 
11
 
 
12
#define IRQ_MAX_NUM             ISR_MAX+1               /* first and second level */
 
13
#define IRQ_MAX_HW_NUM  ISR_MAX_HW+1    /* first level only */
 
14
 
 
15
/* IRQ dispatcher table for ISRs */
 
16
static PFV irqVector[IRQ_MAX_NUM];
 
17
 
 
18
static void IrqGPIOHandler(void);
 
19
 
 
20
/*
 
21
 * Priority resolution table
 
22
 * Index with a bit mask and you get the highest priority in the mask
 
23
 * which is set in the mask.  Least significant bit is highest priority.
 
24
 */
 
25
static const unsigned char unmapTbl[] =
 
26
{
 
27
        0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
28
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
29
        5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
30
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
31
        6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
32
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
33
        5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
34
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
35
        7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
36
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
37
        5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
38
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
39
        6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
40
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
41
        5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
42
        4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
 
43
};
 
44
 
 
45
 
 
46
/*---------------------------------------------------------------------
 
47
        Function:       IrqInit
 
48
        Purpose:        Initialization of IRQ handling
 
49
        Arguments:      void
 
50
        Return:         void
 
51
---------------------------------------------------------------------*/
 
52
void IrqInit(void)
 
53
{
 
54
        int i;
 
55
 
 
56
        *ICMR = 0;              /* disable all interrupts */
 
57
        *ICLR = 0;              /* all mapped to IRQ */
 
58
 
 
59
        /* clear all GPIO edge register */
 
60
        *GRER0 = 0;
 
61
        *GRER1 = 0;
 
62
        *GRER2 = 0;
 
63
        *GFER0 = 0;
 
64
        *GFER1 = 0;
 
65
        *GFER2 = 0;
 
66
        /* reset edge flags */
 
67
        *GEDR0 = *GEDR0;
 
68
        *GEDR1 = *GEDR1;
 
69
        *GEDR2 = *GEDR2;
 
70
 
 
71
        *ICCR = 1;              /* only enabled IRQs can wake up */
 
72
 
 
73
        /* Clear the interrupt vector table */
 
74
        for (i = 0; i < IRQ_MAX_NUM; ++i)
 
75
        {
 
76
                irqVector[i] = (PFV) 0;
 
77
        }
 
78
 
 
79
        /* Install dispatcher for GPIO[80:2] IRQs */
 
80
        irqVector[GPIO_INT_ID] = IrqGPIOHandler;
 
81
}
 
82
 
 
83
/*---------------------------------------------------------------------
 
84
        Function:       IrqEnable
 
85
        Purpose:        enable IRQ for an IRQ interrupt
 
86
        Arguments:      int irqNum - number of IRQ interrupt
 
87
        Return:         void
 
88
---------------------------------------------------------------------*/
 
89
void IrqEnable(int irqNum)
 
90
{
 
91
        if ((irqNum < IRQ_MAX_HW_NUM) && (irqNum >= ISR_MIN))
 
92
        {
 
93
                *ICMR |= (1 << irqNum);
 
94
        }
 
95
}
 
96
 
 
97
/*---------------------------------------------------------------------
 
98
        Function:       IrqDisable
 
99
        Purpose:        disable IRQ for an IRQ interrupt
 
100
        Arguments:      int irqNum - number of IRQ interrupt
 
101
        Return:         void
 
102
---------------------------------------------------------------------*/
 
103
void IrqDisable(int irqNum)
 
104
{
 
105
        if ((irqNum < IRQ_MAX_HW_NUM) && (irqNum >= ISR_MIN))
 
106
        {
 
107
                *ICMR &= ~(1 << irqNum);
 
108
        }
 
109
}
 
110
 
 
111
/*---------------------------------------------------------------------
 
112
        Function:       IrqInstall
 
113
        Purpose:        Install a service handler for an IRQ interrupt
 
114
        Arguments:      int irqNum  - number of IRQ interrupt
 
115
                                PFV isrProc - pointer to service routine
 
116
        Return:         PFV         - pointer to old service routine
 
117
---------------------------------------------------------------------*/
 
118
PFV IrqInstall(int irqNum, PFV isrProc)
 
119
{
 
120
        PFV oldIsr;
 
121
 
 
122
        if (irqNum < ISR_MIN || IRQ_MAX_NUM <= irqNum)
 
123
        {
 
124
                return (PFV) 0;
 
125
        }
 
126
 
 
127
        oldIsr = irqVector[irqNum];
 
128
        irqVector[irqNum] = isrProc;
 
129
 
 
130
        if (irqNum < IRQ_MAX_HW_NUM)
 
131
        {
 
132
                IrqEnable(irqNum);
 
133
        }
 
134
        else if (irqNum >= GPIO2_INT_ID)
 
135
        {
 
136
                IrqEnable(GPIO_INT_ID);
 
137
        }
 
138
 
 
139
        return oldIsr;
 
140
}
 
141
 
 
142
/*---------------------------------------------------------------------
 
143
        Function:       IrqSetEdge
 
144
        Purpose:        Set edge type for GPIO IRQ interrupts
 
145
                                This must be done before installing handler routine.
 
146
        Arguments:      int irqNum  - number of GPIO IRQ interrupt
 
147
                                int edge    - egde type (falling or rising or both)
 
148
        Return:         void
 
149
---------------------------------------------------------------------*/
 
150
void IrqSetEdge(int irqNum, int edge)
 
151
{
 
152
        if (    irqNum == GPIO0_INT_ID
 
153
                 || irqNum == GPIO1_INT_ID
 
154
                 || (irqNum >= GPIO2_INT_ID && irqNum <= GPIO80_INT_ID))
 
155
        {
 
156
                int index, bit;
 
157
 
 
158
                if (irqNum >= GPIO2_INT_ID)
 
159
                {
 
160
                        IrqDisable(GPIO_INT_ID);
 
161
                        index = irqNum - GPIO2_INT_ID + 2;
 
162
                }
 
163
                else
 
164
                {
 
165
                        index = irqNum - GPIO0_INT_ID;
 
166
                }
 
167
                bit = index & 31;
 
168
 
 
169
                /* set pin as GPIO input */
 
170
                if (index >= 64)
 
171
                {
 
172
                        *GPDR2 &= ~(1 << bit);
 
173
                        if (index >= 80)
 
174
                        {
 
175
                                *GAFR2_U &= ~(3 << (2*(bit-16)));
 
176
                        }
 
177
                        else
 
178
                        {
 
179
                                *GAFR2_L &= ~(3 << (2*bit));
 
180
                        }
 
181
                }
 
182
                else if (index >= 32)
 
183
                {
 
184
                        *GPDR1 &= ~(1 << bit);
 
185
                        if (index >= 48)
 
186
                        {
 
187
                                *GAFR1_U &= ~(3 << (2*(bit-16)));
 
188
                        }
 
189
                        else
 
190
                        {
 
191
                                *GAFR1_L &= ~(3 << (2*bit));
 
192
                        }
 
193
                }
 
194
                else
 
195
                {
 
196
                        *GPDR0 &= ~(1 << bit);
 
197
                        if (index >= 16)
 
198
                        {
 
199
                                *GAFR0_U &= ~(3 << (2*(bit-16)));
 
200
                        }
 
201
                        else
 
202
                        {
 
203
                                *GAFR0_L &= ~(3 << (2*bit));
 
204
                        }
 
205
                }
 
206
 
 
207
                /* reset edge detect status */
 
208
                if (index >= 64)
 
209
                {
 
210
                        *GEDR2 = 1 << bit;
 
211
                }
 
212
                else if (index >= 32)
 
213
                {
 
214
                        *GEDR1 = 1 << bit;
 
215
                }
 
216
                else
 
217
                {
 
218
                        *GEDR0 = 1 << bit;
 
219
                }
 
220
 
 
221
                /* set edge(s) */
 
222
                if (edge & GPIO_FALLING_EDGE)
 
223
                {
 
224
                        if (index >= 64)
 
225
                        {
 
226
                                *GFER2 |= (1 << bit);
 
227
                        }
 
228
                        else if (index >= 32)
 
229
                        {
 
230
                                *GFER1 |= (1 << bit);
 
231
                        }
 
232
                        else
 
233
                        {
 
234
                                *GFER0 |= (1 << bit);
 
235
                        }
 
236
                }
 
237
                if (edge & GPIO_RISING_EDGE)
 
238
                {
 
239
                        if (index >= 64)
 
240
                        {
 
241
                                *GRER2 |= (1 << bit);
 
242
                        }
 
243
                        else if (index >= 32)
 
244
                        {
 
245
                                *GRER1 |= (1 << bit);
 
246
                        }
 
247
                        else
 
248
                        {
 
249
                                *GRER0 |= (1 << bit);
 
250
                        }
 
251
                }
 
252
        }
 
253
}
 
254
 
 
255
/*---------------------------------------------------------------------
 
256
        Function:       IrqGPIOHandler
 
257
        Purpose:        dispatcher for GPIO IRQ interrupts
 
258
        Arguments:      void
 
259
        Return:         void
 
260
---------------------------------------------------------------------*/
 
261
static void IrqGPIOHandler(void)
 
262
{
 
263
        unsigned int i, gedr, spurious;
 
264
        PFV  isr;
 
265
 
 
266
        while (gedr = (*GEDR0 & ~3), gedr != 0)
 
267
        {
 
268
                spurious = gedr & ~(*GFER0 | *GRER0);
 
269
                if (spurious)
 
270
                {
 
271
                        *GEDR0 = spurious;
 
272
                        gedr ^= spurious;
 
273
                        if (!gedr)
 
274
                        {
 
275
                                continue;
 
276
                        }
 
277
                }
 
278
                for (i = 2; i < 32; ++i)
 
279
                {
 
280
                        if (gedr & (1<<i))
 
281
                        {
 
282
                                isr = irqVector[i+32];
 
283
                                if (isr)
 
284
                                {
 
285
                                        (*(isr))();
 
286
                                }
 
287
                        }
 
288
                }
 
289
                *GEDR0 = gedr;
 
290
        }
 
291
 
 
292
        while (gedr = (*GEDR1), gedr != 0)
 
293
        {
 
294
                spurious = gedr & ~(*GFER1 | *GRER1);
 
295
                if (spurious)
 
296
                {
 
297
                        *GEDR1 = spurious;
 
298
                        gedr ^= spurious;
 
299
                        if (!gedr)
 
300
                        {
 
301
                                continue;
 
302
                        }
 
303
                }
 
304
                for (i = 0; i < 32; ++i)
 
305
                {
 
306
                        if (gedr & (1<<i))
 
307
                        {
 
308
                                isr = irqVector[i+64];
 
309
                                if (isr)
 
310
                                {
 
311
                                        (*(isr))();
 
312
                                }
 
313
                        }
 
314
                }
 
315
                *GEDR1 = gedr;
 
316
        }
 
317
 
 
318
        while (gedr = (*GEDR2), gedr != 0)
 
319
        {
 
320
                spurious = gedr & ~(*GFER2 | *GRER2);
 
321
                if (spurious)
 
322
                {
 
323
                        *GEDR2 = spurious;
 
324
                        gedr ^= spurious;
 
325
                        if (!gedr)
 
326
                        {
 
327
                                continue;
 
328
                        }
 
329
                }
 
330
                for (i = 0; i < 32; ++i)
 
331
                {
 
332
                        if (gedr & (1<<i))
 
333
                        {
 
334
                                isr = irqVector[i+96];
 
335
                                if (isr)
 
336
                                {
 
337
                                        (*(isr))();
 
338
                                }
 
339
                        }
 
340
                }
 
341
                *GEDR2 = gedr;
 
342
        }
 
343
}
 
344
 
 
345
/*---------------------------------------------------------------------
 
346
        Function:       IrqHandler
 
347
        Purpose:        dispatcher for IRQ interrupts
 
348
        Arguments:      void
 
349
        Return:         void
 
350
---------------------------------------------------------------------*/
 
351
void IrqHandler(void)
 
352
{
 
353
        unsigned int rq, rq1;
 
354
        PFV  isr;
 
355
 
 
356
        rq = *ICIP;             /* read pending IRQs */
 
357
 
 
358
        /* splitting in 4 bytes (size of unmapTbl) */
 
359
        rq1 = rq & 0xFF;
 
360
        if (rq1 != 0)
 
361
        {
 
362
                isr = irqVector[unmapTbl[rq1]];
 
363
                if (isr)
 
364
                {
 
365
                        (*(isr))();
 
366
                }
 
367
                return;
 
368
        }
 
369
 
 
370
        rq >>= 8;
 
371
        rq1 = rq & 0xFF;
 
372
        if (rq1 != 0)
 
373
        {
 
374
                isr = irqVector[unmapTbl[rq1]+8];
 
375
                if (isr)
 
376
                {
 
377
                        (*(isr))();
 
378
                }
 
379
                return;
 
380
        }
 
381
 
 
382
        rq >>= 8;
 
383
        rq1 = rq & 0xFF;
 
384
        if (rq1 != 0)
 
385
        {
 
386
                isr = irqVector[unmapTbl[rq1]+16];
 
387
                if (isr)
 
388
                {
 
389
                        (*(isr))();
 
390
                }
 
391
                return;
 
392
        }
 
393
 
 
394
        rq >>= 8;
 
395
        if (rq != 0)
 
396
        {
 
397
                isr = irqVector[unmapTbl[rq]+24];
 
398
                if (isr)
 
399
                {
 
400
                        (*(isr))();
 
401
                }
 
402
                return;
 
403
        }
 
404
}