os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/specific/soundsc_tx.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_tx.cpp
15 // Implementation of the Template playback shared chunk sound physical device driver (PDD).
16 // This file is part of the Template Base port
24 #include "soundsc_plat.h"
27 // Declare a name for this driver. The format of this name should be
28 // "SoundSc.xxxx" where xxxx is the variant name.
29 _LIT(KSoundScPddName,"SoundSc.Template");
31 // Definitions for the kernel thread created for this sound driver.
32 _LIT(KSoundScDriverThreadName,"SoundDriverThread");
33 const TInt KSoundScDriverThreadPriority=26; // One less than DFC thread 0
36 Define a function at ordinal 0 which returns a new instance of a DPhysicalDevice-derived factory class.
38 DECLARE_STANDARD_PDD()
40 return new DTemplateSoundScPddFactory;
44 Constructor for the shared chunk sound PDD factory class.
46 DTemplateSoundScPddFactory::DTemplateSoundScPddFactory()
48 __KTRACE_SND(Kern::Printf(">DTemplateSoundScPddFactory::DTemplateSoundScPddFactory"));
52 // Support units KSoundScTxUnit0 & KSoundScRxUnit0.
53 iUnitsMask=(1<<KSoundScRxUnit0)|(1<<KSoundScTxUnit0);
55 // Set version number for this device.
56 iVersion=RSoundSc::VersionRequired();
60 Destructor for the shared chunk sound PDD factory class.
62 DTemplateSoundScPddFactory::~DTemplateSoundScPddFactory()
64 __KTRACE_SND(Kern::Printf(">DTemplateSoundScPddFactory::~DTemplateSoundScPddFactory"));
66 // Destroy the kernel thread.
72 Second stage constructor for the shared chunk sound PDD factory class.
73 @return KErrNone if successful, otherwise one of the other system wide error codes.
75 TInt DTemplateSoundScPddFactory::Install()
80 // Create a new sound driver DFC queue (and associated kernel thread).
81 r=Kern::DynamicDfcQCreate(iDfcQ,KSoundScDriverThreadPriority,KSoundScDriverThreadName);
86 r=SetName(&KSoundScPddName); // Set the name of the driver object
89 __KTRACE_SND(Kern::Printf("<DTemplateSoundScPddFactory::Install - %d",r));
94 Returns the PDD's capabilities. This is not used by the Symbian OS device driver framework
96 @param aDes A descriptor to write capabilities information into
98 void DTemplateSoundScPddFactory::GetCaps(TDes8& /*aDes*/) const
102 Called by the kernel's device driver framework to check if this PDD is suitable for use
103 with a logical channel.
104 This is called in the context of the client thread which requested the creation of a logical
105 channel - through a call to RBusLogicalChannel::DoCreate().
106 The thread is in a critical section.
107 @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate().
108 @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate() - not used.
109 @param aVer The version number of the logical channel which will use this physical channel.
110 @return KErrNone if successful, otherwise one of the other system wide error codes.
112 TInt DTemplateSoundScPddFactory::Validate(TInt aUnit, const TDesC8* /*aInfo*/, const TVersion& aVer)
114 // Check that the version specified is compatible.
115 if (!Kern::QueryVersionSupported(RSoundSc::VersionRequired(),aVer))
116 return(KErrNotSupported);
118 // Check the unit number is compatible
119 if (aUnit!=KSoundScTxUnit0 && aUnit!=KSoundScRxUnit0)
120 return(KErrNotSupported);
126 Called by the kernel's device driver framework to create a physical channel object.
127 This is called in the context of the client thread which requested the creation of a logical
128 channel - through a call to RBusLogicalChannel::DoCreate().
129 The thread is in a critical section.
130 @param aChannel Set by this function to point to the created physical channel object.
131 @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate().
132 @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate().
133 @param aVer The version number of the logical channel which will use this physical channel.
134 @return KErrNone if successful, otherwise one of the other system wide error codes.
136 TInt DTemplateSoundScPddFactory::Create(DBase*& aChannel, TInt aUnit, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
138 __KTRACE_SND(Kern::Printf(">DTemplateSoundScPddFactory::Create"));
140 // Create the appropriate PDD channel object.
142 if (aUnit==KSoundScRxUnit0)
144 // Create a record PDD channel object
145 DTemplateSoundScRxPdd* pD=new DTemplateSoundScRxPdd;
149 pD->iPhysicalDevice=this;
156 // Create a playback PDD channel object
157 DTemplateSoundScTxPdd* pD=new DTemplateSoundScTxPdd;
161 pD->iPhysicalDevice=this;
170 Constructor for the Template playback shared chunk sound driver physical device driver (PDD).
172 DTemplateSoundScTxPdd::DTemplateSoundScTxPdd()
174 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::DTemplateSoundScTxPdd"));
182 Destructor for the Template playback shared chunk sound driver physical device driver (PDD).
184 DTemplateSoundScTxPdd::~DTemplateSoundScTxPdd()
186 // Delete the DMA request objects
187 for (TInt i=0; i<KTemplateMaxTxDmaRequests; i++)
190 delete iDmaRequest[i];
193 // Close the DMA channel.
195 iDmaChannel->Close();
199 Second stage constructor for the Template playback shared chunk sound driver physical device driver (PDD).
200 Note that this constructor is called before the second stage constructor for the LDD so it is not
201 possible to call methods on the LDD here.
202 @return KErrNone if successful, otherwise one of the other system wide error codes.
204 TInt DTemplateSoundScTxPdd::DoCreate()
206 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::DoCreate"));
208 SetCaps(); // Setup the capabilities of this device.
210 // Setup a DMA channel for playback
211 // TO DO: (mandatory)
212 // Setup the DMA channel information for this play device.
213 TDmaChannel::SCreateInfo info;
215 info.iDfcQ=DfcQ(KSoundScTxUnit0);
216 // info.iDfcPriority=???
217 info.iDesCount=KTemplateMaxTxDmaRequests;
218 // coverity[uninit_use_in_call]
219 // The values info.iCookie and info.iDfcPriority are to be initialized when implemented
220 TInt r=TDmaChannel::Open(info,iDmaChannel);
222 // Create the DMA request objects for use with the DMA channel.
225 for (TInt i=0; i<KTemplateMaxTxDmaRequests; i++)
227 iDmaRequest[i] = new DTemplateSoundScTxDmaRequest(*iDmaChannel,this);
228 if (iDmaRequest[i] == NULL)
236 __KTRACE_SND(Kern::Printf("<DTemplateSoundScTxPdd::DoCreate - %d",r));
241 Return the DFC queue to be used by this playback device.
242 @return The DFC queue to use.
244 TDfcQue* DTemplateSoundScTxPdd::DfcQ(TInt /*aUnit*/)
246 return(iPhysicalDevice->iDfcQ);
250 Called from the LDD to return the shared chunk create information to be used by this play device.
251 @param aChunkCreateInfo A chunk create info. object to be to be filled with the settings
252 required for this device.
254 void DTemplateSoundScTxPdd::GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)
256 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::GetChunkCreateInfo"));
258 // TO DO: (mandatory)
259 // Setup the shared chunk create information in aChunkCreateInfo for this play device.
260 aChunkCreateInfo.iType=TChunkCreateInfo::ESharedKernelMultiple;
261 // aChunkCreateInfo.iMapAttr=???
262 aChunkCreateInfo.iOwnsMemory=ETrue; // Using RAM pages.
263 aChunkCreateInfo.iDestroyedDfc=NULL; // No chunk destroy DFC.
267 Called from the LDD to return the capabilities of this device.
268 @param aCapsBuf A packaged TSoundFormatsSupportedV02 object to be filled with the play
269 capabilities of this device. This descriptor is in kernel memory and can be accessed directly.
270 @see TSoundFormatsSupportedV02.
272 void DTemplateSoundScTxPdd::Caps(TDes8& aCapsBuf) const
274 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::Caps"));
277 TPtrC8 ptr((const TUint8*)&iCaps,sizeof(iCaps));
278 aCapsBuf.FillZ(aCapsBuf.MaxLength());
279 aCapsBuf=ptr.Left(Min(ptr.Length(),aCapsBuf.MaxLength()));
283 Called from the LDD to return the maximum transfer length in bytes that this device can support in a single data transfer.
284 @return The maximum transfer length in bytes.
286 TInt DTemplateSoundScTxPdd::MaxTransferLen() const
288 return(KTemplateMaxTxDmaTransferLen);
292 Called from the LDD to configure or reconfigure the device using the the configuration supplied.
293 @param aConfigBuf A packaged TCurrentSoundFormatV02 object which contains the new configuration settings.
294 This descriptor is in kernel memory and can be accessed directly.
295 @return KErrNone if successful, otherwise one of the other system wide error codes.
296 @see TCurrentSoundFormatV02.
298 TInt DTemplateSoundScTxPdd::SetConfig(const TDesC8& aConfigBuf)
300 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::SetConfig"));
302 // Read the new configuration from the LDD.
303 TCurrentSoundFormatV02 config;
304 TPtr8 ptr((TUint8*)&config,sizeof(config));
305 Kern::InfoCopy(ptr,aConfigBuf);
307 // TO DO: (mandatory)
308 // Apply the specified audio configuration to the audio device.
311 __KTRACE_SND(Kern::Printf("<DTemplateSoundScTxPdd::SetConfig - %d",r));
316 Called from the LDD to set the play volume.
317 @param aVolume The play volume to be set - a value in the range 0 to 255. The value 255 equates
318 to the maximum volume and each value below this equates to a 0.5dB step below it.
319 @return KErrNone if successful, otherwise one of the other system wide error codes.
321 TInt DTemplateSoundScTxPdd::SetVolume(TInt aVolume)
323 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::SetVolume"));
325 // TO DO: (mandatory)
326 // Set the specified play volume on the audio device.
333 Called from the LDD to prepare the audio device for playback.
334 @return KErrNone if successful, otherwise one of the other system wide error codes.
336 TInt DTemplateSoundScTxPdd::StartTransfer()
338 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::StartTransfer"));
340 // TO DO: (mandatory)
341 // Prepare the audio device for playback.
344 __KTRACE_SND(Kern::Printf("<DTemplateSoundScTxPdd::StartTransfer - %d",r));
349 Called from the LDD to initiate the playback of a portion of data to the audio device.
350 When the transfer is complete, the PDD signals this event using the LDD function PlayCallback().
351 @param aTransferID A value assigned by the LDD to allow it to uniquely identify a particular transfer fragment.
352 @param aLinAddr The linear address within the shared chunk of the start of the data to be played.
353 @param aPhysAddr The physical address within the shared chunk of the start of the data to be played.
354 @param aNumBytes The number of bytes to be played.
355 @return KErrNone if the transfer has been initiated successfully;
356 KErrNotReady if the device is unable to accept the transfer for the moment;
357 otherwise one of the other system-wide error codes.
359 TInt DTemplateSoundScTxPdd::TransferData(TUint aTransferID,TLinAddr aLinAddr,TPhysAddr /*aPhysAddr*/,TInt aNumBytes)
361 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::TransferData(ID:%xH,Addr:%xH,Len:%d)",aLinAddr,aNumBytes));
365 // Check that we can accept the request
366 if (iPendingPlay>=KTemplateMaxTxDmaRequests)
370 // Start a DMA transfer.
371 iDmaRequest[iFlag]->iTransferID=aTransferID;
372 iDmaRequest[iFlag]->iTransferSize=aNumBytes;
373 // TO DO: (mandatory)
374 // Supply the DMA destination information.
375 TUint32 dest=0; // ???
376 r=iDmaRequest[iFlag]->Fragment(aLinAddr,dest,aNumBytes,KDmaMemSrc|KDmaIncSrc,0);
379 iDmaRequest[iFlag]->Queue();
381 if ((++iFlag)>=KTemplateMaxTxDmaRequests)
384 // TO DO: (mandatory)
385 // Start the audio device transfering data.
389 __KTRACE_SND(Kern::Printf("<DTemplateSoundScTxPdd::TransferData - %d",r));
394 Called from the LDD to terminate the playback of a data to the device and to release any resources necessary for playback.
395 This is called soon after the last pending play request from the client has been completed. Once this function had been
396 called, the LDD will not issue any further TransferData() commands without first issueing a StartTransfer() command.
398 void DTemplateSoundScTxPdd::StopTransfer()
400 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::StopTransfer"));
402 // Stop the DMA channel.
403 iDmaChannel->CancelAll();
407 // TO DO: (mandatory)
408 // Stop the audio device transfering data.
412 Called from the LDD to halt the playback of data to the sound device but not to release any resources necessary for
414 If possible, any active transfer should be suspended in such a way that it can be resumed later - starting from next
415 sample following the one last played.
416 @return KErrNone if successful, otherwise one of the other system wide error codes.
418 TInt DTemplateSoundScTxPdd::PauseTransfer()
420 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::PauseTransfer"));
422 // TO DO: (mandatory)
423 // Halt playback on the audio device.
430 Called from the LDD to resume the playback of data to the sound device following a request to halt playback.
431 If possible, any transfer which was active when the device was halted should be resumed - starting from next sample
432 following the one last played. Once complete, it should be reported using PlayCallback()
434 @return KErrNone if successful, otherwise one of the other system wide error codes.
436 TInt DTemplateSoundScTxPdd::ResumeTransfer()
438 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::ResumeTransfer"));
440 // TO DO: (mandatory)
441 // Resume playback on the audio device.
448 Called from the LDD to power up the sound device when the channel is first opened and if ever the phone is brought out
450 @return KErrNone if successful, otherwise one of the other system wide error codes.
452 TInt DTemplateSoundScTxPdd::PowerUp()
454 // TO DO: (mandatory)
455 // Power up the audio device.
461 Called from the LDD to power down the sound device when the channel is closed and just before the phone powers down when
462 being turned off or going into standby.
464 void DTemplateSoundScTxPdd::PowerDown()
466 // TO DO: (mandatory)
467 // Power down the audio device.
471 Called from the LDD to handle a custom configuration request.
472 @param aFunction A number identifying the request.
473 @param aParam A 32-bit value passed to the driver. Its meaning depends on the request.
474 @return KErrNone if successful, otherwise one of the other system wide error codes.
476 TInt DTemplateSoundScTxPdd::CustomConfig(TInt /*aFunction*/,TAny* /*aParam*/)
478 return(KErrNotSupported);
482 Called from the LDD to find out how many microseconds of data have been played. This is called
483 in the context of the DFC thread.
484 @param aTimeTransferred A reference to a variable into which to place the number of microseconds of audio.
485 @param aStatus The current status of this channel
486 @return KErrNone if time is valid or KErrNotSupported.
488 TInt DTemplateSoundScTxPdd::TimeTransferred(TInt64& aTimeTransferred, TInt aStatus)
490 return(KErrNotSupported);
494 Called each time a playback DMA transfer completes - from the DMA callback function in the sound thread's DFC context.
495 @param aTransferID The transfer ID of the DMA transfer.
496 @param aTransferResult The result of the DMA transfer.
497 @param aBytesTransferred The number of bytes transferred.
499 void DTemplateSoundScTxPdd::PlayCallback(TUint aTransferID,TInt aTransferResult,TInt aBytesTransferred)
501 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::PlayCallback"));
505 Ldd()->PlayCallback(aTransferID,aTransferResult,aBytesTransferred);
509 Initialise the data member DTemplateSoundScTxPdd::iCaps with the play capabilities of this audio playback device.
511 void DTemplateSoundScTxPdd::SetCaps()
513 __KTRACE_SND(Kern::Printf(">DTemplateSoundScTxPdd::SetCaps"));
515 // The data transfer direction for this unit is play.
516 iCaps.iDirection=ESoundDirPlayback;
518 // TO DO: (mandatory)
519 // Setup the rest of the capabilities structure DTemplateSoundScTxPdd::iCaps with the capabilities of this
520 // audio playback device.
524 Constructor for a shared chunk sound driver playback DMA request.
526 DTemplateSoundScTxDmaRequest::DTemplateSoundScTxDmaRequest(TDmaChannel& aChannel,DTemplateSoundScTxPdd* aPdd,TInt aMaxTransferSize)
527 : DDmaRequest(aChannel,DTemplateSoundScTxDmaRequest::DmaService,this,aMaxTransferSize),
532 DMA tx service routine. Called in the sound thread's DFC context by the s/w DMA controller.
533 @param aResult Status of DMA transfer.
534 @param aArg Argument passed to DMA controller.
536 void DTemplateSoundScTxDmaRequest::DmaService(TResult aResult, TAny* aArg)
538 __KTRACE_SND(Kern::Printf(">SndTxDmaService - %d",aResult));
539 DTemplateSoundScTxDmaRequest& req=*(DTemplateSoundScTxDmaRequest*)aArg;
542 TInt bytesTransferred=req.iTransferSize;
543 if (aResult!=DDmaRequest::EOk)
549 // Inform the LDD of the result of the transfer.
550 req.iPdd->PlayCallback(req.iTransferID,res,bytesTransferred);