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