1 | /* General Shared Interrupt handling function interface |
---|
2 | * |
---|
3 | * The functions does not manipulate the IRQ controller or the |
---|
4 | * interrupt level of the CPU. It simply helps the caller with |
---|
5 | * managing shared interrupts where multiple interrupt routines |
---|
6 | * share on interrupt vector/number. |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 2008. |
---|
9 | * Cobham Gaisler AB. |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef __GENIRQ_H__ |
---|
17 | #define __GENIRQ_H__ |
---|
18 | |
---|
19 | #ifdef __cplusplus |
---|
20 | extern "C" { |
---|
21 | #endif |
---|
22 | |
---|
23 | typedef void (*genirq_handler)(void *arg); |
---|
24 | typedef void* genirq_t; |
---|
25 | |
---|
26 | struct genirq_stats { |
---|
27 | unsigned int irq_cnt; |
---|
28 | }; |
---|
29 | |
---|
30 | /* Initialize the genirq interface. Must be the first function |
---|
31 | * called. |
---|
32 | * |
---|
33 | * Returns zero on success, otherwise failure. |
---|
34 | */ |
---|
35 | extern genirq_t genirq_init(int number_of_irqs); |
---|
36 | |
---|
37 | /* Free the dynamically allocated memory that the genirq interface has |
---|
38 | * allocated. |
---|
39 | * |
---|
40 | * Returns zero on success, otherwise failure. |
---|
41 | */ |
---|
42 | extern void genirq_destroy(genirq_t d); |
---|
43 | |
---|
44 | /* Check IRQ number validity |
---|
45 | * |
---|
46 | * Returns zero for valid IRQ numbers, -1 of invalid IRQ numbers. |
---|
47 | */ |
---|
48 | extern int genirq_check(genirq_t d, int irq); |
---|
49 | |
---|
50 | /* Register shared interrupt handler. |
---|
51 | * |
---|
52 | * \param irq The interrupt number to register ISR on |
---|
53 | * \param isr The interrupt service routine called upon IRQ |
---|
54 | * \param arg The argument given to isr() when called. |
---|
55 | * |
---|
56 | * Return Values |
---|
57 | * -1 = Failed |
---|
58 | * 0 = Handler registered Successfully, first handler on this IRQ |
---|
59 | * 1 = Handler registered Successfully, _not_ first handler on this IRQ |
---|
60 | */ |
---|
61 | extern int genirq_register(genirq_t d, int irq, genirq_handler isr, void *arg); |
---|
62 | |
---|
63 | /* Unregister an previous registered interrupt handler |
---|
64 | * |
---|
65 | * Return Values |
---|
66 | * -1 = ISR not registered before |
---|
67 | * 0 = ISR unregistered |
---|
68 | * 1 = Unable to unregister enabled ISR |
---|
69 | */ |
---|
70 | extern int genirq_unregister(genirq_t d, int irq, genirq_handler isr, void *arg); |
---|
71 | |
---|
72 | /* Enables IRQ only for this isr[arg] combination. Records if this |
---|
73 | * is the first interrupt enable, only then must interrupts be enabled |
---|
74 | * on the interrupt controller. |
---|
75 | * |
---|
76 | * IRQs must be disabled before entering this function. |
---|
77 | * |
---|
78 | * Return values |
---|
79 | * -1 = Failure, for example isr[arg] not registered on this irq |
---|
80 | * 0 = IRQ must be enabled, it is the first IRQ handler to be enabled |
---|
81 | * 1 = IRQ has already been enabled, either by isr[arg] or by another handler |
---|
82 | */ |
---|
83 | extern int genirq_enable(genirq_t d, int irq, genirq_handler isr, void *arg); |
---|
84 | |
---|
85 | /* Disables IRQ only for this isr[arg] combination. Records if this |
---|
86 | * is the only interrupt handler that is enabled on this IRQ, only then |
---|
87 | * must interrupts be disabled on the interrupt controller. |
---|
88 | * |
---|
89 | * IRQs must be disabled before entering this function. |
---|
90 | * |
---|
91 | * Return values |
---|
92 | * -1 = Failure, for example isr[arg] not registered on this irq |
---|
93 | * 0 = IRQ must be disabled, no ISR are enabled for this IRQ |
---|
94 | * 1 = ISR has already been disabled, or other ISRs are still enabled |
---|
95 | */ |
---|
96 | extern int genirq_disable(genirq_t d, int irq, genirq_handler isr, void *arg); |
---|
97 | |
---|
98 | /* Must be called by user when an IRQ has fired, the argument 'irq' |
---|
99 | * is the IRQ number of the IRQ which was fired. |
---|
100 | */ |
---|
101 | extern void genirq_doirq(genirq_t d, int irq); |
---|
102 | |
---|
103 | #ifdef __cplusplus |
---|
104 | } |
---|
105 | #endif |
---|
106 | |
---|
107 | #endif |
---|