First public contribution.
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 // e32\drivers\adc\d_adc.cpp
22 /******************************************************
24 ******************************************************/
25 EXPORT_C TAdcChannel::TAdcChannel(TInt anAdc)
26 : iChannelId(-1), iCommandCount(0), iCommandList(NULL),
31 if (anAdc>=0 && anAdc<DAdc::NumberOfAdcs)
32 iAdc=DAdc::TheAdcs[anAdc];
37 EXPORT_C void TAdcChannel::Read(TInt* aReadingBuffer)
39 // Initiate a reading of this channel
42 TInt irq=NKern::DisableAllInterrupts();
45 iReadings=aReadingBuffer;
48 NKern::RestoreInterrupts(irq);
51 EXPORT_C void TAdcChannel::Preamble()
53 // Default preamble does nothing
58 EXPORT_C void TAdcChannel::Postamble()
60 // Default postamble does nothing
66 /******************************************************
68 ******************************************************/
69 LOCAL_C void timerExpired(TAny* aPtr)
71 ((DAdc*)aPtr)->TimerExpired();
75 : iTimer(timerExpired,this)
77 // iCurrentChannel=NULL;
88 EXPORT_C TInt DAdc::SetMinPriority(TInt anAdc, TInt aPriority)
90 if (anAdc<0 || anAdc>=NumberOfAdcs)
92 if (aPriority<0 || aPriority>KNumAdcChannelPriorities)
94 return TheAdcs[anAdc]->DoSetMinPriority(aPriority);
97 TInt DAdc::DoSetMinPriority(TInt aPriority)
99 TInt irq=NKern::DisableAllInterrupts();
100 if (aPriority<iMinPriority)
102 if (iList.iPresent[0])
104 TAdcChannel* pN=iList.First();
105 if (pN->iPriority>=aPriority)
112 iMinPriority=aPriority;
113 NKern::RestoreInterrupts(irq);
117 void DAdc::Add(TAdcChannel* aChannel)
119 // Queue another ADC reading request
122 if (iCurrentChannel || (aChannel->iPriority<iMinPriority))
128 void DAdc::Execute(TAdcChannel* aChannel)
130 // Begin execution of an ADC request
131 // This runs in an ISR or with interrupts disabled
134 aChannel->iNext=(TPriListLink*)1; // so channel will not be queued again
135 iCurrentChannel=aChannel;
136 iCommandPtr=aChannel->iCommandList;
137 iCommandCount=aChannel->iCommandCount;
141 void DAdc::NextCommand()
143 // Perform the next command in the command list
144 // This runs in an ISR or with interrupts disabled
148 TAdcChannel* pC=iCurrentChannel;
151 TInt c=*iCommandPtr++;
154 if (c & EAdcCmdPreamble)
156 if (c & EAdcCmdPostamble)
160 iTimer.OneShot(c & 0xffff);
163 else if (c & EAdcCmdReading)
165 StartConversion(pC->iChannelId);
169 if (iCommandCount==0 && !wait)
171 iCurrentChannel=NULL;
173 if (iList.iPresent[0])
175 TAdcChannel* pN=iList.First();
176 if (pN->iPriority>=iMinPriority)
188 // Called on completion of initialisation to start processing requests
189 // This runs in an ISR
192 iCurrentChannel=NULL;
193 if (iList.iPresent[0])
195 TAdcChannel* pN=iList.First();
201 void DAdc::ConversionComplete(TInt aValue)
203 // Called when a conversion has completed
204 // This runs in an ISR
207 if ((iCurrentCommand & EAdcCmdDiscard)==0)
208 *(iCurrentChannel->iReadings)++=aValue;
212 void DAdc::TimerExpired()
214 // Called in ISR when timer expires