navienginebsp/ne1_tb/soundsc/soundsc.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 * \bsp\hwip_nec_naviengine\ne1_tb\soundsc\sound.cpp
       
    16 * Implementation of a sound physical device driver (PDD) factory
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include "soundsc_plat.h"
       
    23 #include <naviengine.h>
       
    24 #include <i2s.h>
       
    25 
       
    26 _LIT(KSoundScPddName,"SoundSc.NE1_TBVariant");
       
    27 
       
    28 // Definitions for the kernel thread created for this sound driver.
       
    29 _LIT(KSoundScDriverThreadName,"SoundDriverThread");
       
    30 const TInt KSoundScDriverThreadPriority=26;				// One less than DFC thread 0 (26)
       
    31 
       
    32 /**
       
    33 Define a function at ordinal 0 which returns a new instance of a DPhysicalDevice-derived factory class.
       
    34 */
       
    35 DECLARE_STANDARD_PDD()
       
    36 	{
       
    37 	return new DSoundScPddNE1_TB;
       
    38 	}
       
    39 
       
    40 /**
       
    41 Constructor for the shared chunk sound PDD factory class.
       
    42 */
       
    43 DSoundScPddNE1_TB::DSoundScPddNE1_TB()
       
    44 	{
       
    45 	__KTRACE_SND(Kern::Printf(">DSoundScPddNE1_TB::DSoundScPddNE1_TB"));
       
    46 
       
    47 	// Support units KSoundScTxUnit0 & KSoundScRxUnit0.
       
    48     iUnitsMask=(1<<KSoundScRxUnit0)|(1<<KSoundScTxUnit0);
       
    49 
       
    50     // Set version number for this device.
       
    51 	iVersion=RSoundSc::VersionRequired();
       
    52 	}
       
    53 
       
    54 /**
       
    55 Destructor for the shared chunk sound PDD factory class.
       
    56 This function is called from the client thread context.
       
    57 */
       
    58 DSoundScPddNE1_TB::~DSoundScPddNE1_TB()
       
    59 	{
       
    60 	__KTRACE_SND(Kern::Printf(">DSoundScPddNE1_TB::~DSoundScPddNE1_TB"));
       
    61 
       
    62 	// Destroy the kernel thread.
       
    63 	if (iDfcQ)
       
    64 		{
       
    65 		iDfcQ->Destroy();
       
    66 		}
       
    67 	}
       
    68 
       
    69 /**
       
    70 Second stage constructor for the shared chunk sound PDD factory class.
       
    71 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
    72 */
       
    73 TInt DSoundScPddNE1_TB::Install()
       
    74 	{
       
    75 	__KTRACE_SND(Kern::Printf(">DSoundScPddNE1_TB::Install"));
       
    76 	TInt r = KErrNone;
       
    77 	if (!iDfcQ)
       
    78 		{
       
    79 		// Create a new sound driver DFC queue (and associated kernel thread).
       
    80 		r = Kern::DynamicDfcQCreate(iDfcQ, KSoundScDriverThreadPriority, KSoundScDriverThreadName);
       
    81 		if (r != KErrNone)
       
    82 			{
       
    83 			return r;
       
    84 			}
       
    85 		}
       
    86 
       
    87 #ifdef CPU_AFFINITY_ANY
       
    88 	NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny);
       
    89 #endif
       
    90 
       
    91 	r = SetName(&KSoundScPddName); 				// Set the name of the driver object
       
    92 
       
    93 	return(r);
       
    94 	}
       
    95 
       
    96 /**
       
    97 Returns the PDD's capabilities. This is not used by the Symbian OS device driver framework
       
    98 or by the LDD.
       
    99 @param aDes A descriptor to write capabilities information into
       
   100 */
       
   101 void DSoundScPddNE1_TB::GetCaps(TDes8& /*aDes*/) const
       
   102 	{}
       
   103 
       
   104 /**
       
   105 Called by the kernel's device driver framework to check if this PDD is suitable for use
       
   106 with a logical channel.
       
   107 This is called in the context of the client thread which requested the creation of a logical
       
   108 channel - through a call to RBusLogicalChannel::DoCreate().
       
   109 The thread is in a critical section.
       
   110 @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate().
       
   111 @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate() - not used.
       
   112 @param aVer The version number of the logical channel which will use this physical channel.
       
   113 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
   114 */
       
   115 TInt DSoundScPddNE1_TB::Validate(TInt aUnit, const TDesC8* /*aInfo*/, const TVersion& aVer)
       
   116 	{
       
   117 	// Check that the version specified is compatible.
       
   118 	if (!Kern::QueryVersionSupported(RSoundSc::VersionRequired(), aVer))
       
   119 		{
       
   120 		return(KErrNotSupported);
       
   121 		}
       
   122 
       
   123 	// Check the unit number is compatible
       
   124 	if (aUnit!=KSoundScTxUnit0 && aUnit!=KSoundScRxUnit0)
       
   125 		{
       
   126 		return(KErrNotSupported);
       
   127 		}
       
   128 
       
   129 	return(KErrNone);
       
   130 	}
       
   131 
       
   132 /**
       
   133 Called by the kernel's device driver framework to create a physical channel object.
       
   134 This is called in the context of the client thread which requested the creation of a logical
       
   135 channel - through a call to RBusLogicalChannel::DoCreate().
       
   136 The thread is in a critical section.
       
   137 @param aChannel Set by this function to point to the created physical channel object.
       
   138 @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate().
       
   139 @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate().
       
   140 @param aVer The version number of the logical channel which will use this physical channel.
       
   141 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
   142 */
       
   143 TInt DSoundScPddNE1_TB::Create(DBase*& aChannel, TInt aUnit, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
       
   144 	{
       
   145 	__KTRACE_SND(Kern::Printf(">DSoundScPddNE1_TB::Create"));
       
   146 
       
   147 	TInt r = KErrNone;
       
   148 
       
   149 	// Create the appropriate PDD channel object.
       
   150 	DNE1_TBSoundScPddChannel* pD = NULL;
       
   151 
       
   152 	if (aUnit==KSoundScRxUnit0)
       
   153 		{
       
   154 		// Create a record PDD channel object
       
   155 		pD = new DNE1_TBSoundScPddChannel(ESoundDirRecord);
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		// Create a playback PDD channel object
       
   160 		pD = new DNE1_TBSoundScPddChannel(ESoundDirPlayback);
       
   161 		}
       
   162 
       
   163 	r = KErrNoMemory;
       
   164 	if (pD)
       
   165 		{
       
   166 		pD->iPhysicalDevice = this;
       
   167 		r = pD->DoCreate();
       
   168 		aChannel = pD;
       
   169 		}
       
   170 	return(r);
       
   171 	}