os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/specific/soundsc_rx.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-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_variant\specific\soundsc_rx.cpp
sl@0
    15
// Implementation of the Template record shared chunk sound physical device driver (PDD).
sl@0
    16
// This file is part of the Template Base port
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "soundsc_plat.h"
sl@0
    25
sl@0
    26
sl@0
    27
/**
sl@0
    28
Constructor for the Template record shared chunk sound driver physical device driver (PDD).
sl@0
    29
*/
sl@0
    30
DTemplateSoundScRxPdd::DTemplateSoundScRxPdd()
sl@0
    31
	{		
sl@0
    32
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::DTemplateSoundScRxPdd"));
sl@0
    33
	
sl@0
    34
//	iDmaChan=NULL;
sl@0
    35
//	iPendingRecord=0;
sl@0
    36
//	iFlag=0;
sl@0
    37
	}
sl@0
    38
	
sl@0
    39
/**
sl@0
    40
Destructor for the Template record shared chunk sound driver physical device driver (PDD).
sl@0
    41
*/
sl@0
    42
DTemplateSoundScRxPdd::~DTemplateSoundScRxPdd()
sl@0
    43
	{
sl@0
    44
	// Delete the DMA request objects
sl@0
    45
	for (TInt i=0; i<KTemplateMaxRxDmaRequests; i++)
sl@0
    46
		{
sl@0
    47
		if (iDmaRequest[i])
sl@0
    48
			delete iDmaRequest[i];
sl@0
    49
		}
sl@0
    50
	
sl@0
    51
	// Close the DMA channel.
sl@0
    52
	if (iDmaChannel)
sl@0
    53
		iDmaChannel->Close();
sl@0
    54
	}
sl@0
    55
	
sl@0
    56
/**
sl@0
    57
Second stage constructor for the Template record shared chunk sound driver physical device driver (PDD).
sl@0
    58
Note that this constructor is called before the second stage constructor for the LDD so it is not
sl@0
    59
possible to call methods on the LDD here.
sl@0
    60
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
    61
*/	
sl@0
    62
TInt DTemplateSoundScRxPdd::DoCreate()
sl@0
    63
	{
sl@0
    64
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::DoCreate"));
sl@0
    65
		
sl@0
    66
	SetCaps();								// Setup the capabilities of this device.
sl@0
    67
	
sl@0
    68
	// Setup a DMA channel for record
sl@0
    69
	// TO DO: (mandatory)
sl@0
    70
	// Setup the DMA channel information for this record device.
sl@0
    71
	TDmaChannel::SCreateInfo info;
sl@0
    72
//	info.iCookie=???
sl@0
    73
	info.iDfcQ=DfcQ(KSoundScRxUnit0);
sl@0
    74
//	info.iDfcPriority=???
sl@0
    75
	info.iDesCount=KTemplateMaxRxDmaRequests;
sl@0
    76
	// coverity[uninit_use_in_call]
sl@0
    77
	// The values info.iCookie and info.iDfcPriority are to be initialized when implemented
sl@0
    78
	TInt r=TDmaChannel::Open(info,iDmaChannel);
sl@0
    79
	
sl@0
    80
	// Create the DMA request objects for use with the DMA channel.
sl@0
    81
	if (r==KErrNone)
sl@0
    82
		{
sl@0
    83
		for (TInt i=0; i<KTemplateMaxRxDmaRequests; i++)
sl@0
    84
			{
sl@0
    85
			iDmaRequest[i] = new DTemplateSoundScRxDmaRequest(*iDmaChannel,this);
sl@0
    86
			if (iDmaRequest[i] == NULL)
sl@0
    87
				{
sl@0
    88
				r=KErrNoMemory;
sl@0
    89
				break;
sl@0
    90
				}
sl@0
    91
			}
sl@0
    92
		}
sl@0
    93
	
sl@0
    94
	__KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::DoCreate - %d",r));
sl@0
    95
	return(r);
sl@0
    96
	}
sl@0
    97
	
sl@0
    98
/**
sl@0
    99
Return the DFC queue to be used by this record device.
sl@0
   100
@return The DFC queue to use.
sl@0
   101
*/	
sl@0
   102
TDfcQue* DTemplateSoundScRxPdd::DfcQ(TInt /*aUnit*/)
sl@0
   103
	{
sl@0
   104
	return(iPhysicalDevice->iDfcQ);
sl@0
   105
	}
sl@0
   106
		
sl@0
   107
/** 
sl@0
   108
Called from the LDD to return the shared chunk create information to be used by this record device.
sl@0
   109
@param aChunkCreateInfo A chunk create info. object to be to be filled with the settings
sl@0
   110
						required for this device.
sl@0
   111
*/		
sl@0
   112
void DTemplateSoundScRxPdd::GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)
sl@0
   113
	{
sl@0
   114
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::GetChunkCreateInfo"));
sl@0
   115
sl@0
   116
	// TO DO: (mandatory)
sl@0
   117
	// Setup the shared chunk create information in aChunkCreateInfo for this record device.
sl@0
   118
	aChunkCreateInfo.iType=TChunkCreateInfo::ESharedKernelMultiple;
sl@0
   119
//	aChunkCreateInfo.iMapAttr=???
sl@0
   120
	aChunkCreateInfo.iOwnsMemory=ETrue; 				// Using RAM pages.
sl@0
   121
	aChunkCreateInfo.iDestroyedDfc=NULL; 				// No chunk destroy DFC.
sl@0
   122
	}
sl@0
   123
sl@0
   124
/**
sl@0
   125
Called from the LDD to return the capabilities of this device.
sl@0
   126
@param aCapsBuf A packaged TSoundFormatsSupportedV02 object to be filled with the record
sl@0
   127
				capabilities of this device. This descriptor is in kernel memory and can be accessed directly.
sl@0
   128
@see TSoundFormatsSupportedV02.
sl@0
   129
*/
sl@0
   130
void DTemplateSoundScRxPdd::Caps(TDes8& aCapsBuf) const
sl@0
   131
	{
sl@0
   132
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::Caps"));
sl@0
   133
	
sl@0
   134
	// Copy iCaps back.
sl@0
   135
	TPtrC8 ptr((const TUint8*)&iCaps,sizeof(iCaps));
sl@0
   136
	aCapsBuf.FillZ(aCapsBuf.MaxLength());
sl@0
   137
	aCapsBuf=ptr.Left(Min(ptr.Length(),aCapsBuf.MaxLength()));		
sl@0
   138
	}
sl@0
   139
	
sl@0
   140
/**
sl@0
   141
Called from the LDD to return the maximum transfer length in bytes that this device can support in a single data transfer.
sl@0
   142
@return The maximum transfer length in bytes.
sl@0
   143
*/
sl@0
   144
TInt DTemplateSoundScRxPdd::MaxTransferLen() const
sl@0
   145
	{
sl@0
   146
	return(KTemplateMaxRxDmaTransferLen);
sl@0
   147
	}	
sl@0
   148
sl@0
   149
/**
sl@0
   150
Called from the LDD to configure or reconfigure the device using the the configuration supplied.
sl@0
   151
@param aConfigBuf A packaged TCurrentSoundFormatV02 object which contains the new configuration settings.
sl@0
   152
				  This descriptor is in kernel memory and can be accessed directly.
sl@0
   153
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   154
@see TCurrentSoundFormatV02.
sl@0
   155
*/	
sl@0
   156
TInt DTemplateSoundScRxPdd::SetConfig(const TDesC8& aConfigBuf)
sl@0
   157
	{
sl@0
   158
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::SetConfig"));
sl@0
   159
	
sl@0
   160
	// Read the new configuration from the LDD.
sl@0
   161
	TCurrentSoundFormatV02 config;
sl@0
   162
	TPtr8 ptr((TUint8*)&config,sizeof(config));
sl@0
   163
	Kern::InfoCopy(ptr,aConfigBuf);
sl@0
   164
	
sl@0
   165
	// TO DO: (mandatory)
sl@0
   166
	// Apply the specified audio configuration to the audio device.
sl@0
   167
	TInt r=KErrNone;
sl@0
   168
	
sl@0
   169
	__KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::SetConfig - %d",r));
sl@0
   170
	return(r);
sl@0
   171
	}
sl@0
   172
	
sl@0
   173
/**
sl@0
   174
Called from the LDD to set the record level.
sl@0
   175
@param aVolume The record level to be set - a value in the range 0 to 255. The value 255 equates 
sl@0
   176
	   to the maximum record level and each value below this equates to a 0.5dB step below it.
sl@0
   177
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   178
*/
sl@0
   179
TInt DTemplateSoundScRxPdd::SetVolume(TInt aVolume)
sl@0
   180
	{
sl@0
   181
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::SetVolume"));
sl@0
   182
    
sl@0
   183
    // TO DO: (mandatory)
sl@0
   184
	// Set the specified record volume on the audio device.
sl@0
   185
	TInt r=KErrNone;
sl@0
   186
    
sl@0
   187
	return(r);
sl@0
   188
	}
sl@0
   189
		
sl@0
   190
/**
sl@0
   191
Called from the LDD to prepare the audio device for recording.
sl@0
   192
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   193
*/
sl@0
   194
TInt DTemplateSoundScRxPdd::StartTransfer()
sl@0
   195
	{
sl@0
   196
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::StartTransfer"));
sl@0
   197
	
sl@0
   198
	// TO DO: (mandatory)
sl@0
   199
	// Prepare the audio device for record.
sl@0
   200
	TInt r=KErrNone;
sl@0
   201
    
sl@0
   202
    __KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::StartTransfer - %d",r));
sl@0
   203
    return(r);
sl@0
   204
	}
sl@0
   205
sl@0
   206
/**
sl@0
   207
Called from the LDD to initiate the recording of a portion of data from the audio device.
sl@0
   208
When the transfer is complete, the PDD signals this event using the LDD function RecordCallback().
sl@0
   209
@param aTransferID A value assigned by the LDD to allow it to uniquely identify a particular transfer fragment.
sl@0
   210
@param aLinAddr The linear address within the shared chunk for storing the recorded data.
sl@0
   211
@param aPhysAddr The physical address within the shared chunk for storing the recorded data.
sl@0
   212
@param aNumBytes The number of bytes to be recorded. 
sl@0
   213
@return KErrNone if the transfer has been initiated successfully;
sl@0
   214
  		KErrNotReady if the device is unable to accept the transfer for the moment;
sl@0
   215
		otherwise one of the other system-wide error codes.
sl@0
   216
*/
sl@0
   217
TInt DTemplateSoundScRxPdd::TransferData(TUint aTransferID,TLinAddr aLinAddr,TPhysAddr /*aPhysAddr*/,TInt aNumBytes)
sl@0
   218
	{
sl@0
   219
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::TransferData(ID:%xH,Addr:%xH,Len:%d)",aLinAddr,aNumBytes));
sl@0
   220
		
sl@0
   221
	TInt r=KErrNone;
sl@0
   222
	
sl@0
   223
	// Check that we can accept the request
sl@0
   224
	if (iPendingRecord>=KTemplateMaxRxDmaRequests)
sl@0
   225
		r=KErrNotReady;
sl@0
   226
	else
sl@0
   227
		{
sl@0
   228
		// Start a DMA transfer.
sl@0
   229
		iDmaRequest[iFlag]->iTransferID=aTransferID;
sl@0
   230
		iDmaRequest[iFlag]->iTransferSize=aNumBytes;
sl@0
   231
		// TO DO: (mandatory)
sl@0
   232
		// Supply the DMA source information.
sl@0
   233
		TUint32 src=0; // ???
sl@0
   234
		r=iDmaRequest[iFlag]->Fragment(src,aLinAddr,aNumBytes,KDmaMemDest|KDmaIncDest,0);
sl@0
   235
		if (r==KErrNone)
sl@0
   236
			{
sl@0
   237
			iDmaRequest[iFlag]->Queue();
sl@0
   238
			iPendingRecord++;
sl@0
   239
			if ((++iFlag)>=KTemplateMaxRxDmaRequests)
sl@0
   240
				iFlag=0;
sl@0
   241
			
sl@0
   242
			// TO DO: (mandatory)
sl@0
   243
			// Start the audio device transfering data.
sl@0
   244
			}
sl@0
   245
		}
sl@0
   246
											
sl@0
   247
	__KTRACE_SND(Kern::Printf("<DTemplateSoundScRxPdd::TransferData - %d",r));	
sl@0
   248
	return(r);
sl@0
   249
	}
sl@0
   250
sl@0
   251
/**
sl@0
   252
Called from the LDD to terminate the recording of a data from the device and to release any resources necessary for
sl@0
   253
recording.
sl@0
   254
The LDD will leave the audio device capturing record data even when there are no record requests pending from the client.
sl@0
   255
Transfer will only be terminated when the client either issues RSoundSc::CancelRecordData() or closes the channel. Once
sl@0
   256
this function had been called, the LDD will not issue  any further TransferData() commands without first issueing a
sl@0
   257
StartTransfer() command.
sl@0
   258
*/
sl@0
   259
void DTemplateSoundScRxPdd::StopTransfer()
sl@0
   260
	{
sl@0
   261
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::StopTransfer"));
sl@0
   262
sl@0
   263
    // Stop the DMA channel.
sl@0
   264
    iDmaChannel->CancelAll();
sl@0
   265
	iFlag=0;
sl@0
   266
    iPendingRecord=0;
sl@0
   267
    
sl@0
   268
    // TO DO: (mandatory)
sl@0
   269
	// Stop the audio device transfering data.
sl@0
   270
	}
sl@0
   271
sl@0
   272
/**
sl@0
   273
Called from the LDD to halt the recording of data from the sound device but not to release any resources necessary for
sl@0
   274
recording.
sl@0
   275
All active transfers should be aborted. When recording is halted the PDD signals this event with a single call of the LDD 
sl@0
   276
function RecordCallback() - reporting back any partial data already received. If transfer is resumed later, the LDD will
sl@0
   277
issue a new TransferData() request to re-commence data transfer.
sl@0
   278
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   279
*/
sl@0
   280
TInt DTemplateSoundScRxPdd::PauseTransfer()
sl@0
   281
	{
sl@0
   282
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::PauseTransfer"));
sl@0
   283
	
sl@0
   284
	// Stop the DMA channel.
sl@0
   285
    iDmaChannel->CancelAll();
sl@0
   286
   
sl@0
   287
    if (iPendingRecord)
sl@0
   288
		{
sl@0
   289
		// TO DO: (mandatory)
sl@0
   290
		// Determine how much data was successfully transferred to the record buffer before transfer was aborted.
sl@0
   291
		TInt byteCount=0; // ???
sl@0
   292
		Ldd()->RecordCallback(0,KErrNone,byteCount);	// We can use a NULL transfer ID when pausing.
sl@0
   293
		iPendingRecord=0;
sl@0
   294
		}
sl@0
   295
	iFlag=0;
sl@0
   296
	
sl@0
   297
	// TO DO: (mandatory)
sl@0
   298
	// Halt recording on the audio device.
sl@0
   299
	TInt r=KErrNone;
sl@0
   300
    
sl@0
   301
	return(r);
sl@0
   302
	}
sl@0
   303
	
sl@0
   304
/**
sl@0
   305
Called from the LDD to resume the recording of data from the sound device following a request to halt recording.
sl@0
   306
Any active transfer would have been aborted when the device was halted so its just a case of re-creating the same setup
sl@0
   307
acheived following StartTransfer().
sl@0
   308
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   309
*/
sl@0
   310
TInt DTemplateSoundScRxPdd::ResumeTransfer()
sl@0
   311
	{
sl@0
   312
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::ResumeTransfer"));
sl@0
   313
	
sl@0
   314
	// TO DO: (mandatory)
sl@0
   315
	// Resume recording on the audio device.
sl@0
   316
	TInt r=KErrNone;
sl@0
   317
			
sl@0
   318
	return(r);
sl@0
   319
	}
sl@0
   320
sl@0
   321
/**
sl@0
   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
sl@0
   323
of standby mode.
sl@0
   324
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   325
*/
sl@0
   326
TInt DTemplateSoundScRxPdd::PowerUp()
sl@0
   327
	{
sl@0
   328
	// TO DO: (mandatory)
sl@0
   329
	// Power up the audio device.
sl@0
   330
	
sl@0
   331
	return(KErrNone);
sl@0
   332
	}
sl@0
   333
sl@0
   334
/**
sl@0
   335
Called from the LDD to power down the sound device when the channel is closed and just before the phone powers down when
sl@0
   336
being turned off or going into standby.
sl@0
   337
*/
sl@0
   338
void DTemplateSoundScRxPdd::PowerDown()
sl@0
   339
	{
sl@0
   340
	// TO DO: (mandatory)
sl@0
   341
	// Power down the audio device.
sl@0
   342
	}
sl@0
   343
	
sl@0
   344
/**
sl@0
   345
Called from the LDD to handle a custom configuration request.
sl@0
   346
@param aFunction A number identifying the request.
sl@0
   347
@param aParam A 32-bit value passed to the driver. Its meaning depends on the request.
sl@0
   348
@return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   349
*/
sl@0
   350
TInt DTemplateSoundScRxPdd::CustomConfig(TInt /*aFunction*/,TAny* /*aParam*/)
sl@0
   351
	{
sl@0
   352
	return(KErrNotSupported);
sl@0
   353
	}	
sl@0
   354
sl@0
   355
/**
sl@0
   356
Called from the LDD to find out how many microseconds of data have been recorded.  This is called
sl@0
   357
in the context of the DFC thread.
sl@0
   358
@param aTimeTransferred	A reference to a variable into which to place the number of microseconds of audio.
sl@0
   359
@param aStatus			The current status of this channel
sl@0
   360
@return KErrNone if time is valid or KErrNotSupported.
sl@0
   361
*/
sl@0
   362
TInt DTemplateSoundScRxPdd::TimeTransferred(TInt64& aTimeTransferred, TInt aStatus)
sl@0
   363
	{
sl@0
   364
	return(KErrNotSupported);
sl@0
   365
	}
sl@0
   366
sl@0
   367
/**
sl@0
   368
Called each time a record DMA transfer completes - from the DMA callback function in the sound thread's DFC context.
sl@0
   369
@param aTransferID The transfer ID of the DMA transfer.
sl@0
   370
@param aTransferResult The result of the DMA transfer.
sl@0
   371
@param aBytesTransferred The number of bytes transferred.
sl@0
   372
*/	
sl@0
   373
void DTemplateSoundScRxPdd::RecordCallback(TUint aTransferID,TInt aTransferResult,TInt aBytesTransferred)
sl@0
   374
	{
sl@0
   375
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::RecordCallback"));
sl@0
   376
	
sl@0
   377
	iPendingRecord--;
sl@0
   378
		
sl@0
   379
	Ldd()->RecordCallback(aTransferID,aTransferResult,aBytesTransferred);
sl@0
   380
	}
sl@0
   381
sl@0
   382
/**
sl@0
   383
Initialise the data member DTemplateSoundScRxPdd::iCaps with the record capabilities of this audio device.
sl@0
   384
*/	
sl@0
   385
void DTemplateSoundScRxPdd::SetCaps()
sl@0
   386
	{
sl@0
   387
	__KTRACE_SND(Kern::Printf(">DTemplateSoundScRxPdd::SetCaps"));
sl@0
   388
	
sl@0
   389
	// The data transfer direction for this unit is record.
sl@0
   390
	iCaps.iDirection=ESoundDirRecord;
sl@0
   391
	
sl@0
   392
	// TO DO: (mandatory)
sl@0
   393
	// Setup the rest of the capabilities structure DTemplateSoundScRxPdd::iCaps with the capabilities of this
sl@0
   394
	// audio record device.
sl@0
   395
	}	
sl@0
   396
sl@0
   397
/**
sl@0
   398
Constructor for a shared chunk sound driver record DMA request.
sl@0
   399
*/
sl@0
   400
DTemplateSoundScRxDmaRequest::DTemplateSoundScRxDmaRequest(TDmaChannel& aChannel,DTemplateSoundScRxPdd* aPdd,TInt aMaxTransferSize)
sl@0
   401
	: DDmaRequest(aChannel,DTemplateSoundScRxDmaRequest::DmaService,this,aMaxTransferSize),
sl@0
   402
	  iPdd(aPdd)
sl@0
   403
	{}
sl@0
   404
	
sl@0
   405
/**
sl@0
   406
DMA rx service routine. Called in the sound thread's DFC context by the s/w DMA controller.
sl@0
   407
@param aResult Status of DMA transfer.
sl@0
   408
@param aArg Argument passed to DMA controller.
sl@0
   409
*/	
sl@0
   410
void DTemplateSoundScRxDmaRequest::DmaService(TResult aResult, TAny* aArg)
sl@0
   411
	{
sl@0
   412
	__KTRACE_SND(Kern::Printf(">SndRxDmaService - %d",aResult));
sl@0
   413
	DTemplateSoundScRxDmaRequest& req=*(DTemplateSoundScRxDmaRequest*)aArg;
sl@0
   414
	
sl@0
   415
	TInt res=KErrNone;
sl@0
   416
	TInt bytesTransferred=req.iTransferSize;
sl@0
   417
	if (aResult!=DDmaRequest::EOk)
sl@0
   418
		{
sl@0
   419
		res=KErrCorrupt;
sl@0
   420
		bytesTransferred=0;
sl@0
   421
		}
sl@0
   422
		
sl@0
   423
	// Inform the LDD of the result of the transfer.
sl@0
   424
	req.iPdd->RecordCallback(req.iTransferID,res,bytesTransferred);	
sl@0
   425
	return;
sl@0
   426
	}
sl@0
   427