kernel/eka/drivers/sdapc/d_sdapc.cpp
author hgs
Thu, 10 Jun 2010 11:48:01 +0100
changeset 149 d9f1e5bfe28c
permissions -rw-r--r--
201021_18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
149
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     2
// All rights reserved.
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     6
// at the URL " http://www.eclipse.org/legal/epl-v10.html ".
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     7
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     8
// Initial Contributors:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    10
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    11
// Contributors:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    12
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    13
// Description:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    14
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    15
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    16
#include <kernel/kernel.h>
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    17
#include <drivers/mmc.h>
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    18
#include <drivers/sdcard.h>
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    19
#include <drivers/sdio/sdio.h>
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    20
#include <drivers/d_sdapc.h>
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    21
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    22
#include "OstTraceDefinitions.h"
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    23
#ifdef OST_TRACE_COMPILER_IN_USE
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    24
#include "locmedia_ost.h"
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    25
#ifdef __VC32__
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    26
#pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    27
#endif
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    28
#include "d_sdapcTraces.h"
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    29
#endif
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    30
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    31
_LIT(KLddName,"D_SDAPC");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    32
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    33
const TInt KMajorVersionNumber=1;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    34
const TInt KMinorVersionNumber=0;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    35
const TInt KBuildVersionNumber=1;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    36
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    37
const TInt KSocketNumber = 0;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    38
const TInt KStackNumber  = 0;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    39
const TInt KCardNumber   = 0;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    40
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    41
// global Dfc Que
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    42
TDynamicDfcQue* gDfcQ;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    43
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    44
class DSDAuxiliaryPowerControlFactory : public DLogicalDevice
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    45
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    46
// LDD factory
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    47
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    48
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    49
public:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    50
	DSDAuxiliaryPowerControlFactory();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    51
	~DSDAuxiliaryPowerControlFactory();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    52
	virtual TInt Install(); 					//overriding pure virtual
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    53
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    54
	virtual TInt Create(DLogicalChannelBase*& aChannel); 	//overriding pure virtual
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    55
	};
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    56
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    57
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    58
class DSDAuxiliaryPowerControl : public DLogicalChannel
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    59
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    60
// Logical channel
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    61
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    62
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    63
public:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    64
	DSDAuxiliaryPowerControl();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    65
	virtual ~DSDAuxiliaryPowerControl();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    66
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    67
protected:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    68
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    69
	virtual void HandleMsg(class TMessageBase *);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    70
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    71
private:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    72
	static void BusCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    73
	TInt PowerUpStack();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    74
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    75
private:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    76
	DMMCSocket* iSocketP;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    77
	DMMCStack*  iStackP;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    78
	TSDCard*  iCardP;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    79
    
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    80
	DThread* iClient;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    81
	
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    82
	TPBusCallBack iBusCallBack;		
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    83
	DSemaphore* iPowerUpSemaphore;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    84
	TBool iInitialised;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    85
	};
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    86
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    87
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    88
DECLARE_STANDARD_LDD()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    89
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    90
	return new DSDAuxiliaryPowerControlFactory;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    91
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    92
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    93
DSDAuxiliaryPowerControlFactory::DSDAuxiliaryPowerControlFactory()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    94
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    95
// Constructor
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    96
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    97
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    98
    OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROLFACTORY_DSDAUXILIARYPOWERCONTROLFACTORY, "DSDAuxiliaryPowerControlFactory::DSDAuxiliaryPowerControlFactory");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
    99
	__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDAuxiliaryPowerControlFactory::DSDAuxiliaryPowerControlFactory"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   100
    iParseMask=KDeviceAllowUnit;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   101
	iUnitsMask=0xffffffff;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   102
	iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   103
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   104
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   105
TInt DSDAuxiliaryPowerControlFactory::Create(DLogicalChannelBase*& aChannel)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   106
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   107
// Create a new DSDAuxiliaryPowerControl on this logical device
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   108
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   109
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   110
    OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROLFACTORY_CREATE, "DSDAuxiliaryPowerControlFactory::Create");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   111
	__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDAuxiliaryPowerControlFactory::Create"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   112
	aChannel=new DSDAuxiliaryPowerControl;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   113
	return aChannel ? KErrNone : KErrNoMemory;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   114
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   115
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   116
const TInt KDSDAuxiliaryPowerControlApiThreadPriority = 27;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   117
_LIT(KDSDAuxiliaryPowerControlApiThread,"DSDAuxiliaryPowerControlApiThread");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   118
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   119
TInt DSDAuxiliaryPowerControlFactory::Install()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   120
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   121
// Install the LDD - overriding pure virtual
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   122
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   123
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   124
	// Allocate a kernel thread to run the DFC 
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   125
	TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDSDAuxiliaryPowerControlApiThreadPriority, KDSDAuxiliaryPowerControlApiThread);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   126
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   127
	if (r != KErrNone)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   128
		return r; 	
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   129
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   130
	return SetName(&KLddName);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   131
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   132
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   133
void DSDAuxiliaryPowerControlFactory::GetCaps(TDes8& aDes) const
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   134
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   135
// Get capabilities - overriding pure virtual
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   136
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   137
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   138
	TCapsTestV01 b;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   139
	b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   140
    Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   141
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   142
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   143
/**
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   144
  Destructor
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   145
*/
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   146
DSDAuxiliaryPowerControlFactory::~DSDAuxiliaryPowerControlFactory()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   147
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   148
    OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROLFACTORY_DSDAUXILIARYPOWERCONTROLFACTORY_DTOR, "DSDAuxiliaryPowerControlFactory::~DSDAuxiliaryPowerControlFactory");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   149
	__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDAuxiliaryPowerControlFactory::~DSDAuxiliaryPowerControlFactory"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   150
	if (gDfcQ)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   151
		gDfcQ->Destroy();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   152
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   153
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   154
void DSDAuxiliaryPowerControl::BusCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   155
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   156
	DSDAuxiliaryPowerControl* pTest = (DSDAuxiliaryPowerControl*)aPtr;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   157
	TPBusState busState = (TPBusState) (TInt) a1;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   158
	switch (aReason)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   159
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   160
		case TPBusCallBack::EPBusStateChange:
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   161
			if (busState != EPBusPoweringUp)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   162
				Kern::SemaphoreSignal(*(pTest->iPowerUpSemaphore));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   163
			break;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   164
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   165
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   166
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   167
TInt DSDAuxiliaryPowerControl::PowerUpStack()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   168
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   169
	iBusCallBack.iFunction = BusCallBack;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   170
	iBusCallBack.iPtr=this;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   171
	iBusCallBack.SetSocket(iSocketP->iSocketNumber);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   172
	iBusCallBack.Add();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   173
	TInt r = Kern::SemaphoreCreate(iPowerUpSemaphore, _L("SDPowerUpSem"), 0);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   174
	if (r == KErrNone)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   175
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   176
		r = iSocketP->PowerUp();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   177
		if (r == KErrNone)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   178
			Kern::SemaphoreWait(*iPowerUpSemaphore);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   179
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   180
	return r;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   181
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   182
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   183
TInt DSDAuxiliaryPowerControl::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   184
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   185
// Create channel
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   186
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   187
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   188
    OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_1, "DSDAuxiliaryPowerControl::DoCreate()");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   189
	__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDAuxiliaryPowerControl::DoCreate()"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   190
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   191
	if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   192
		return KErrNotSupported;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   193
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   194
	//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   195
	// Obtain the appropriate card from the socket/stack
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   196
	//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   197
	iSocketP = static_cast<DMMCSocket*>(DPBusSocket::SocketFromId(KSocketNumber));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   198
	if(iSocketP == NULL)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   199
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   200
        OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_2, "DSDAuxiliaryPowerControl::DoCreate() : Didn't obtain socket");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   201
		__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::DoCreate() : Didn't obtain socket"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   202
		return KErrNoMemory;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   203
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   204
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   205
	iStackP = static_cast<DSDStack*>(iSocketP->Stack(KStackNumber));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   206
	if(iStackP == NULL)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   207
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   208
        OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_3, "DSDAuxiliaryPowerControl::DoCreate() : Didn't obtain stack");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   209
		__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::DoCreate() : Didn't obtain stack"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   210
		return KErrNoMemory;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   211
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   212
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   213
	iCardP = static_cast<TSDCard*>(iStackP->CardP(KCardNumber));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   214
	if(iCardP == NULL)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   215
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   216
        OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_4, "DSDAuxiliaryPowerControl::DoCreate() : Didn't obtain card");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   217
		__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::DoCreate() : Didn't obtain card"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   218
		return KErrNoMemory;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   219
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   220
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   221
	SetDfcQ(gDfcQ);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   222
	iMsgQ.Receive();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   223
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   224
	// Make sure stack is powered up
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   225
	TInt r = PowerUpStack();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   226
	if (r != KErrNone && r != KErrCompletion)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   227
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   228
        OstTrace1( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_5, "DSDAuxiliaryPowerControl::DoCreate() : Failed To Power up stack, r = %d", r);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   229
		__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::DoCreate() : Failed To Power up stack, r = %d", r));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   230
		return r;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   231
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   232
		
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   233
	if(!iCardP->IsReady())
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   234
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   235
        OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_6, "DSDAuxiliaryPowerControl::DoCreate() : Card not ready");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   236
		__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::DoCreate() : Card not ready"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   237
		return KErrNotReady;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   238
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   239
    	
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   240
	if(!iCardP->ClientsRegistered())
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   241
		{		
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   242
		iCardP->RegisterClient();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   243
		((DSDIOPsu*)(iSocketP->iVcc))->Lock();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   244
		TBool locked = ((DSDIOPsu*)(iSocketP->iVcc))->IsLocked();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   245
		OstTrace1( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DOCREATE_7, "DSDAuxiliaryPowerControl::DoCreate() : PSU IsLocked(), locked = %d", locked);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   246
		__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::DoCreate() : PSU IsLocked(), locked = %d", locked));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   247
		if(!locked)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   248
			return KErrNotReady;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   249
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   250
		
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   251
	return KErrNone;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   252
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   253
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   254
DSDAuxiliaryPowerControl::DSDAuxiliaryPowerControl()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   255
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   256
// Constructor
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   257
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   258
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   259
	iClient=&Kern::CurrentThread();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   260
	((DObject*)iClient)->Open();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   261
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   262
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   263
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   264
DSDAuxiliaryPowerControl::~DSDAuxiliaryPowerControl()
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   265
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   266
// Destructor
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   267
//
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   268
	{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   269
    OstTrace0( TRACE_FLOW, DSDAUXILIARYPOWERCONTROL_DSDAUXILIARYPOWERCONTROL_DTOR, "DSDAuxiliaryPowerControl::~DSDAuxiliaryPowerControl");
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   270
	__KTRACE_OPT(KPBUS1, Kern::Printf("DSDAuxiliaryPowerControl::~DSDAuxiliaryPowerControl"));
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   271
	iBusCallBack.Remove();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   272
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   273
	if (iSocketP)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   274
		iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusMediaNormal, NULL);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   275
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   276
	
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   277
	if(iCardP->ClientsRegistered())
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   278
		{		
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   279
		iCardP->DeregisterClient();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   280
		((DSDIOPsu*)(iSocketP->iVcc))->Unlock();
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   281
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   282
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   283
	iPowerUpSemaphore->Close(NULL);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   284
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   285
	Kern::SafeClose((DObject*&)iClient,NULL);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   286
	}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   287
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   288
void DSDAuxiliaryPowerControl::HandleMsg(TMessageBase* aMsg)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   289
    {
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   290
    TThreadMessage& m=*(TThreadMessage*)aMsg;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   291
    TInt id=m.iValue;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   292
    
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   293
	if (id==(TInt)ECloseMsg)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   294
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   295
		if (iSocketP)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   296
			iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusMediaNormal, NULL);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   297
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   298
		m.Complete(KErrNone, EFalse);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   299
		return;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   300
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   301
    else if (id==KMaxTInt)
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   302
		{
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   303
		// DoCancel
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   304
		m.Complete(KErrNone,ETrue);
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   305
		return;
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   306
		}
d9f1e5bfe28c 201021_18
hgs
parents:
diff changeset
   307
	}