os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/specific/soundsc_rx.cpp
Update contrib.
1 // Copyright (c) 2006-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_variant\specific\soundsc_rx.cpp
15 // Implementation of the Template record shared chunk sound physical device driver (PDD).
16 // This file is part of the Template Base port
24 #include "soundsc_plat.h"
28 Constructor for the Template record shared chunk sound driver physical device driver (PDD).
30 DTemplateSoundScRxPdd::DTemplateSoundScRxPdd()
32 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::DTemplateSoundScRxPdd"));
40 Destructor for the Template record shared chunk sound driver physical device driver (PDD).
42 DTemplateSoundScRxPdd::~DTemplateSoundScRxPdd()
44 // Delete the DMA request objects
45 for (TInt i=0; i<KTemplateMaxRxDmaRequests; i++)
48 delete iDmaRequest[i];
51 // Close the DMA channel.
57 Second stage constructor for the Template record shared chunk sound driver physical device driver (PDD).
58 Note that this constructor is called before the second stage constructor for the LDD so it is not
59 possible to call methods on the LDD here.
60 @return KErrNone if successful, otherwise one of the other system wide error codes.
62 TInt DTemplateSoundScRxPdd::DoCreate()
64 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::DoCreate"));
66 SetCaps(); // Setup the capabilities of this device.
68 // Setup a DMA channel for record
70 // Setup the DMA channel information for this record device.
71 TDmaChannel::SCreateInfo info;
73 info.iDfcQ=DfcQ(KSoundScRxUnit0);
74 // info.iDfcPriority=???
75 info.iDesCount=KTemplateMaxRxDmaRequests;
76 // coverity[uninit_use_in_call]
77 // The values info.iCookie and info.iDfcPriority are to be initialized when implemented
78 TInt r=TDmaChannel::Open(info,iDmaChannel);
80 // Create the DMA request objects for use with the DMA channel.
83 for (TInt i=0; i<KTemplateMaxRxDmaRequests; i++)
85 iDmaRequest[i] = new DTemplateSoundScRxDmaRequest(*iDmaChannel,this);
86 if (iDmaRequest[i] == NULL)
94 __KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::DoCreate - %d",r));
99 Return the DFC queue to be used by this record device.
100 @return The DFC queue to use.
102 TDfcQue* DTemplateSoundScRxPdd::DfcQ(TInt /*aUnit*/)
104 return(iPhysicalDevice->iDfcQ);
108 Called from the LDD to return the shared chunk create information to be used by this record device.
109 @param aChunkCreateInfo A chunk create info. object to be to be filled with the settings
110 required for this device.
112 void DTemplateSoundScRxPdd::GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)
114 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::GetChunkCreateInfo"));
116 // TO DO: (mandatory)
117 // Setup the shared chunk create information in aChunkCreateInfo for this record device.
118 aChunkCreateInfo.iType=TChunkCreateInfo::ESharedKernelMultiple;
119 // aChunkCreateInfo.iMapAttr=???
120 aChunkCreateInfo.iOwnsMemory=ETrue; // Using RAM pages.
121 aChunkCreateInfo.iDestroyedDfc=NULL; // No chunk destroy DFC.
125 Called from the LDD to return the capabilities of this device.
126 @param aCapsBuf A packaged TSoundFormatsSupportedV02 object to be filled with the record
127 capabilities of this device. This descriptor is in kernel memory and can be accessed directly.
128 @see TSoundFormatsSupportedV02.
130 void DTemplateSoundScRxPdd::Caps(TDes8& aCapsBuf) const
132 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::Caps"));
135 TPtrC8 ptr((const TUint8*)&iCaps,sizeof(iCaps));
136 aCapsBuf.FillZ(aCapsBuf.MaxLength());
137 aCapsBuf=ptr.Left(Min(ptr.Length(),aCapsBuf.MaxLength()));
141 Called from the LDD to return the maximum transfer length in bytes that this device can support in a single data transfer.
142 @return The maximum transfer length in bytes.
144 TInt DTemplateSoundScRxPdd::MaxTransferLen() const
146 return(KTemplateMaxRxDmaTransferLen);
150 Called from the LDD to configure or reconfigure the device using the the configuration supplied.
151 @param aConfigBuf A packaged TCurrentSoundFormatV02 object which contains the new configuration settings.
152 This descriptor is in kernel memory and can be accessed directly.
153 @return KErrNone if successful, otherwise one of the other system wide error codes.
154 @see TCurrentSoundFormatV02.
156 TInt DTemplateSoundScRxPdd::SetConfig(const TDesC8& aConfigBuf)
158 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::SetConfig"));
160 // Read the new configuration from the LDD.
161 TCurrentSoundFormatV02 config;
162 TPtr8 ptr((TUint8*)&config,sizeof(config));
163 Kern::InfoCopy(ptr,aConfigBuf);
165 // TO DO: (mandatory)
166 // Apply the specified audio configuration to the audio device.
169 __KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::SetConfig - %d",r));
174 Called from the LDD to set the record level.
175 @param aVolume The record level to be set - a value in the range 0 to 255. The value 255 equates
176 to the maximum record level and each value below this equates to a 0.5dB step below it.
177 @return KErrNone if successful, otherwise one of the other system wide error codes.
179 TInt DTemplateSoundScRxPdd::SetVolume(TInt aVolume)
181 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::SetVolume"));
183 // TO DO: (mandatory)
184 // Set the specified record volume on the audio device.
191 Called from the LDD to prepare the audio device for recording.
192 @return KErrNone if successful, otherwise one of the other system wide error codes.
194 TInt DTemplateSoundScRxPdd::StartTransfer()
196 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::StartTransfer"));
198 // TO DO: (mandatory)
199 // Prepare the audio device for record.
202 __KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::StartTransfer - %d",r));
207 Called from the LDD to initiate the recording of a portion of data from the audio device.
208 When the transfer is complete, the PDD signals this event using the LDD function RecordCallback().
209 @param aTransferID A value assigned by the LDD to allow it to uniquely identify a particular transfer fragment.
210 @param aLinAddr The linear address within the shared chunk for storing the recorded data.
211 @param aPhysAddr The physical address within the shared chunk for storing the recorded data.
212 @param aNumBytes The number of bytes to be recorded.
213 @return KErrNone if the transfer has been initiated successfully;
214 KErrNotReady if the device is unable to accept the transfer for the moment;
215 otherwise one of the other system-wide error codes.
217 TInt DTemplateSoundScRxPdd::TransferData(TUint aTransferID,TLinAddr aLinAddr,TPhysAddr /*aPhysAddr*/,TInt aNumBytes)
219 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::TransferData(ID:%xH,Addr:%xH,Len:%d)",aLinAddr,aNumBytes));
223 // Check that we can accept the request
224 if (iPendingRecord>=KTemplateMaxRxDmaRequests)
228 // Start a DMA transfer.
229 iDmaRequest[iFlag]->iTransferID=aTransferID;
230 iDmaRequest[iFlag]->iTransferSize=aNumBytes;
231 // TO DO: (mandatory)
232 // Supply the DMA source information.
233 TUint32 src=0; // ???
234 r=iDmaRequest[iFlag]->Fragment(src,aLinAddr,aNumBytes,KDmaMemDest|KDmaIncDest,0);
237 iDmaRequest[iFlag]->Queue();
239 if ((++iFlag)>=KTemplateMaxRxDmaRequests)
242 // TO DO: (mandatory)
243 // Start the audio device transfering data.
247 __KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::TransferData - %d",r));
252 Called from the LDD to terminate the recording of a data from the device and to release any resources necessary for
254 The LDD will leave the audio device capturing record data even when there are no record requests pending from the client.
255 Transfer will only be terminated when the client either issues RSoundSc::CancelRecordData() or closes the channel. Once
256 this function had been called, the LDD will not issue any further TransferData() commands without first issueing a
257 StartTransfer() command.
259 void DTemplateSoundScRxPdd::StopTransfer()
261 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::StopTransfer"));
263 // Stop the DMA channel.
264 iDmaChannel->CancelAll();
268 // TO DO: (mandatory)
269 // Stop the audio device transfering data.
273 Called from the LDD to halt the recording of data from the sound device but not to release any resources necessary for
275 All active transfers should be aborted. When recording is halted the PDD signals this event with a single call of the LDD
276 function RecordCallback() - reporting back any partial data already received. If transfer is resumed later, the LDD will
277 issue a new TransferData() request to re-commence data transfer.
278 @return KErrNone if successful, otherwise one of the other system wide error codes.
280 TInt DTemplateSoundScRxPdd::PauseTransfer()
282 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::PauseTransfer"));
284 // Stop the DMA channel.
285 iDmaChannel->CancelAll();
289 // TO DO: (mandatory)
290 // Determine how much data was successfully transferred to the record buffer before transfer was aborted.
291 TInt byteCount=0; // ???
292 Ldd()->RecordCallback(0,KErrNone,byteCount); // We can use a NULL transfer ID when pausing.
297 // TO DO: (mandatory)
298 // Halt recording on the audio device.
305 Called from the LDD to resume the recording of data from the sound device following a request to halt recording.
306 Any active transfer would have been aborted when the device was halted so its just a case of re-creating the same setup
307 acheived following StartTransfer().
308 @return KErrNone if successful, otherwise one of the other system wide error codes.
310 TInt DTemplateSoundScRxPdd::ResumeTransfer()
312 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::ResumeTransfer"));
314 // TO DO: (mandatory)
315 // Resume recording on the audio device.
322 Called from the LDD to power up the sound device when the channel is first opened and if ever the phone is brought out
324 @return KErrNone if successful, otherwise one of the other system wide error codes.
326 TInt DTemplateSoundScRxPdd::PowerUp()
328 // TO DO: (mandatory)
329 // Power up the audio device.
335 Called from the LDD to power down the sound device when the channel is closed and just before the phone powers down when
336 being turned off or going into standby.
338 void DTemplateSoundScRxPdd::PowerDown()
340 // TO DO: (mandatory)
341 // Power down the audio device.
345 Called from the LDD to handle a custom configuration request.
346 @param aFunction A number identifying the request.
347 @param aParam A 32-bit value passed to the driver. Its meaning depends on the request.
348 @return KErrNone if successful, otherwise one of the other system wide error codes.
350 TInt DTemplateSoundScRxPdd::CustomConfig(TInt /*aFunction*/,TAny* /*aParam*/)
352 return(KErrNotSupported);
356 Called from the LDD to find out how many microseconds of data have been recorded. This is called
357 in the context of the DFC thread.
358 @param aTimeTransferred A reference to a variable into which to place the number of microseconds of audio.
359 @param aStatus The current status of this channel
360 @return KErrNone if time is valid or KErrNotSupported.
362 TInt DTemplateSoundScRxPdd::TimeTransferred(TInt64& aTimeTransferred, TInt aStatus)
364 return(KErrNotSupported);
368 Called each time a record DMA transfer completes - from the DMA callback function in the sound thread's DFC context.
369 @param aTransferID The transfer ID of the DMA transfer.
370 @param aTransferResult The result of the DMA transfer.
371 @param aBytesTransferred The number of bytes transferred.
373 void DTemplateSoundScRxPdd::RecordCallback(TUint aTransferID,TInt aTransferResult,TInt aBytesTransferred)
375 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::RecordCallback"));
379 Ldd()->RecordCallback(aTransferID,aTransferResult,aBytesTransferred);
383 Initialise the data member DTemplateSoundScRxPdd::iCaps with the record capabilities of this audio device.
385 void DTemplateSoundScRxPdd::SetCaps()
387 __KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::SetCaps"));
389 // The data transfer direction for this unit is record.
390 iCaps.iDirection=ESoundDirRecord;
392 // TO DO: (mandatory)
393 // Setup the rest of the capabilities structure DTemplateSoundScRxPdd::iCaps with the capabilities of this
394 // audio record device.
398 Constructor for a shared chunk sound driver record DMA request.
400 DTemplateSoundScRxDmaRequest::DTemplateSoundScRxDmaRequest(TDmaChannel& aChannel,DTemplateSoundScRxPdd* aPdd,TInt aMaxTransferSize)
401 : DDmaRequest(aChannel,DTemplateSoundScRxDmaRequest::DmaService,this,aMaxTransferSize),
406 DMA rx service routine. Called in the sound thread's DFC context by the s/w DMA controller.
407 @param aResult Status of DMA transfer.
408 @param aArg Argument passed to DMA controller.
410 void DTemplateSoundScRxDmaRequest::DmaService(TResult aResult, TAny* aArg)
412 __KTRACE_SND(Kern::Printf(">SndRxDmaService - %d",aResult));
413 DTemplateSoundScRxDmaRequest& req=*(DTemplateSoundScRxDmaRequest*)aArg;
416 TInt bytesTransferred=req.iTransferSize;
417 if (aResult!=DDmaRequest::EOk)
423 // Inform the LDD of the result of the transfer.
424 req.iPdd->RecordCallback(req.iTransferID,res,bytesTransferred);