Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // template\template_assp\interrupts.cpp
15 // Template ASSP interrupt control and dispatch
19 #include <template_assp_priv.h>
21 SInterruptHandler TemplateInterrupt::Handlers[KNumTemplateInts];
23 void TemplateInterrupt::DisableAndClearAll()
28 // Disable and clear all Hardware Interrupt sources
32 void TemplateInterrupt::Init1()
35 // need to hook the ARM IRQ and FIQ handlers as early as possible and disable and clear all interrupt sources
37 __KTRACE_OPT(KBOOT,Kern::Printf("TemplateInterrupt::Init1()"));
39 for (i=0; i<KNumTemplateInts; i++)
41 Handlers[i].iPtr=(TAny*)i;
42 Handlers[i].iIsr=Spurious;
45 Arm::SetIrqHandler((TLinAddr)TemplateInterrupt::IrqDispatch);
46 Arm::SetFiqHandler((TLinAddr)TemplateInterrupt::FiqDispatch);
49 void TemplateInterrupt::Init3()
54 // Any further initialisation of the Hardware Interrupt Controller
58 void TemplateInterrupt::Spurious(TAny* anId)
63 // handle an unexpected interrupt
65 Kern::Fault("SpuriousInt", (TInt)anId); // EXAMPLE ONLY
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.
73 EXPORT_C TInt Interrupt::Bind(TInt anId, TIsr anIsr, TAny* aPtr)
75 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Bind id=%d func=%08x ptr=%08x",anId,anIsr,aPtr));
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)
84 SInterruptHandler& h=TemplateInterrupt::Handlers[anId];
85 TInt irq=NKern::DisableAllInterrupts();
86 if (h.iIsr != TemplateInterrupt::Spurious)
93 NKern::RestoreInterrupts(irq);
98 EXPORT_C TInt Interrupt::Unbind(TInt anId)
100 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Unbind id=%d",anId));
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)
109 SInterruptHandler& h=TemplateInterrupt::Handlers[anId];
110 TInt irq=NKern::DisableAllInterrupts();
111 if (h.iIsr == TemplateInterrupt::Spurious)
116 h.iIsr=TemplateInterrupt::Spurious;
118 // TO DO: (mandatory)
120 // Disable the corresponding Hardware Interrupt source
123 NKern::RestoreInterrupts(irq);
128 EXPORT_C TInt Interrupt::Enable(TInt anId)
130 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Enable id=%d",anId));
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)
137 else if (TemplateInterrupt::Handlers[anId].iIsr==TemplateInterrupt::Spurious)
142 // TO DO: (mandatory)
144 // Enable the corresponding Hardware Interrupt source
150 EXPORT_C TInt Interrupt::Disable(TInt anId)
152 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Disable id=%d",anId));
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)
162 // TO DO: (mandatory)
164 // Disable the corresponding Hardware Interrupt source
170 EXPORT_C TInt Interrupt::Clear(TInt anId)
172 __KTRACE_OPT(KEXTENSION,Kern::Printf("Interrupt::Clear id=%d",anId));
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)
182 // TO DO: (mandatory)
184 // Clear the corresponding Hardware Interrupt source
190 EXPORT_C TInt Interrupt::SetPriority(TInt /*anId*/, TInt /*aPriority*/)
193 // If Interrupt priorities are supported the dispatchers need to take this in consideration
194 // (IrqDispatch/FiqDispatch)
196 return KErrNotSupported;