|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // template\template_assp\interrupts.cpp |
|
15 // Template ASSP interrupt control and dispatch |
|
16 // |
|
17 // |
|
18 |
|
19 #include <template_assp_priv.h> |
|
20 |
|
21 SInterruptHandler TemplateInterrupt::Handlers[KNumTemplateInts]; |
|
22 |
|
23 void TemplateInterrupt::DisableAndClearAll() |
|
24 { |
|
25 // |
|
26 // TO DO: (mandatory) |
|
27 // |
|
28 // Disable and clear all Hardware Interrupt sources |
|
29 // |
|
30 } |
|
31 |
|
32 void TemplateInterrupt::Init1() |
|
33 { |
|
34 // |
|
35 // need to hook the ARM IRQ and FIQ handlers as early as possible and disable and clear all interrupt sources |
|
36 // |
|
37 __KTRACE_OPT(KBOOT,Kern::Printf("TemplateInterrupt::Init1()")); |
|
38 TInt i; |
|
39 for (i=0; i<KNumTemplateInts; i++) |
|
40 { |
|
41 Handlers[i].iPtr=(TAny*)i; |
|
42 Handlers[i].iIsr=Spurious; |
|
43 } |
|
44 DisableAndClearAll(); |
|
45 Arm::SetIrqHandler((TLinAddr)TemplateInterrupt::IrqDispatch); |
|
46 Arm::SetFiqHandler((TLinAddr)TemplateInterrupt::FiqDispatch); |
|
47 } |
|
48 |
|
49 void TemplateInterrupt::Init3() |
|
50 { |
|
51 // |
|
52 // TO DO: (optional) |
|
53 // |
|
54 // Any further initialisation of the Hardware Interrupt Controller |
|
55 // |
|
56 } |
|
57 |
|
58 void TemplateInterrupt::Spurious(TAny* anId) |
|
59 { |
|
60 // |
|
61 // TO DO: (mandatory) |
|
62 // |
|
63 // handle an unexpected interrupt |
|
64 // |
|
65 Kern::Fault("SpuriousInt", (TInt)anId); // EXAMPLE ONLY |
|
66 } |
|
67 |
|
68 // |
|
69 // The APIs below assume ther is a second level Interrupt controller located at Variant level which handles |
|
70 // interrupts generated by hardware at that level. |
|
71 // |
|
72 |
|
73 EXPORT_C TInt Interrupt::Bind(TInt anId, TIsr anIsr, TAny* aPtr) |
|
74 { |
|
75 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Bind id=%d func=%08x ptr=%08x",anId,anIsr,aPtr)); |
|
76 TInt r=KErrNone; |
|
77 // if ID indicates a chained interrupt, call variant... |
|
78 if (anId<0 && ((((TUint)anId)>>16)&0x7fff)<(TUint)KNumTemplateInts) |
|
79 r=TemplateAssp::Variant->InterruptBind(anId,anIsr,aPtr); |
|
80 else if ((TUint)anId >= (TUint)KNumTemplateInts) |
|
81 r=KErrArgument; |
|
82 else |
|
83 { |
|
84 SInterruptHandler& h=TemplateInterrupt::Handlers[anId]; |
|
85 TInt irq=NKern::DisableAllInterrupts(); |
|
86 if (h.iIsr != TemplateInterrupt::Spurious) |
|
87 r=KErrInUse; |
|
88 else |
|
89 { |
|
90 h.iPtr=aPtr; |
|
91 h.iIsr=anIsr; |
|
92 } |
|
93 NKern::RestoreInterrupts(irq); |
|
94 } |
|
95 return r; |
|
96 } |
|
97 |
|
98 EXPORT_C TInt Interrupt::Unbind(TInt anId) |
|
99 { |
|
100 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Unbind id=%d",anId)); |
|
101 TInt r=KErrNone; |
|
102 // if ID indicates a chained interrupt, call variant... |
|
103 if (anId<0 && ((((TUint)anId)>>16)&0x7fff)<(TUint)KNumTemplateInts) |
|
104 r=TemplateAssp::Variant->InterruptUnbind(anId); |
|
105 else if ((TUint)anId >= (TUint)KNumTemplateInts) |
|
106 r=KErrArgument; |
|
107 else |
|
108 { |
|
109 SInterruptHandler& h=TemplateInterrupt::Handlers[anId]; |
|
110 TInt irq=NKern::DisableAllInterrupts(); |
|
111 if (h.iIsr == TemplateInterrupt::Spurious) |
|
112 r=KErrGeneral; |
|
113 else |
|
114 { |
|
115 h.iPtr=(TAny*)anId; |
|
116 h.iIsr=TemplateInterrupt::Spurious; |
|
117 // |
|
118 // TO DO: (mandatory) |
|
119 // |
|
120 // Disable the corresponding Hardware Interrupt source |
|
121 // |
|
122 } |
|
123 NKern::RestoreInterrupts(irq); |
|
124 } |
|
125 return r; |
|
126 } |
|
127 |
|
128 EXPORT_C TInt Interrupt::Enable(TInt anId) |
|
129 { |
|
130 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Enable id=%d",anId)); |
|
131 TInt r=KErrNone; |
|
132 // if ID indicates a chained interrupt, call variant... |
|
133 if (anId<0 && ((((TUint)anId)>>16)&0x7fff)<(TUint)KNumTemplateInts) |
|
134 r=TemplateAssp::Variant->InterruptEnable(anId); |
|
135 else if ((TUint)anId>=(TUint)KNumTemplateInts) |
|
136 r=KErrArgument; |
|
137 else if (TemplateInterrupt::Handlers[anId].iIsr==TemplateInterrupt::Spurious) |
|
138 r=KErrNotReady; |
|
139 else |
|
140 { |
|
141 // |
|
142 // TO DO: (mandatory) |
|
143 // |
|
144 // Enable the corresponding Hardware Interrupt source |
|
145 // |
|
146 } |
|
147 return r; |
|
148 } |
|
149 |
|
150 EXPORT_C TInt Interrupt::Disable(TInt anId) |
|
151 { |
|
152 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Disable id=%d",anId)); |
|
153 TInt r=KErrNone; |
|
154 // if ID indicates a chained interrupt, call variant... |
|
155 if (anId<0 && ((((TUint)anId)>>16)&0x7fff)<(TUint)KNumTemplateInts) |
|
156 r=TemplateAssp::Variant->InterruptDisable(anId); |
|
157 else if ((TUint)anId>=(TUint)KNumTemplateInts) |
|
158 r=KErrArgument; |
|
159 else |
|
160 { |
|
161 // |
|
162 // TO DO: (mandatory) |
|
163 // |
|
164 // Disable the corresponding Hardware Interrupt source |
|
165 // |
|
166 } |
|
167 return r; |
|
168 } |
|
169 |
|
170 EXPORT_C TInt Interrupt::Clear(TInt anId) |
|
171 { |
|
172 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Clear id=%d",anId)); |
|
173 TInt r=KErrNone; |
|
174 // if ID indicates a chained interrupt, call variant... |
|
175 if (anId<0 && ((((TUint)anId)>>16)&0x7fff)<(TUint)KNumTemplateInts) |
|
176 r=TemplateAssp::Variant->InterruptClear(anId); |
|
177 else if ((TUint)anId>=(TUint)KNumTemplateInts) |
|
178 r=KErrArgument; |
|
179 else |
|
180 { |
|
181 // |
|
182 // TO DO: (mandatory) |
|
183 // |
|
184 // Clear the corresponding Hardware Interrupt source |
|
185 // |
|
186 } |
|
187 return r; |
|
188 } |
|
189 |
|
190 EXPORT_C TInt Interrupt::SetPriority(TInt /*anId*/, TInt /*aPriority*/) |
|
191 { |
|
192 // |
|
193 // If Interrupt priorities are supported the dispatchers need to take this in consideration |
|
194 // (IrqDispatch/FiqDispatch) |
|
195 // |
|
196 return KErrNotSupported; |
|
197 } |