kernel/eka/drivers/pbus/spbus.cpp
changeset 47 46fffbe7b5a7
parent 43 96e5fb8b040d
child 62 4a8fed1c0ef6
child 90 947f0dc9f7a8
equal deleted inserted replaced
46:0bf4040442f9 47:46fffbe7b5a7
    14 // e32\drivers\pbus\spbus.cpp
    14 // e32\drivers\pbus\spbus.cpp
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 #include <drivers/pbus.h>
    18 #include <drivers/pbus.h>
       
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "locmedia_ost.h"
       
    22 #ifdef __VC32__
       
    23 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
       
    24 #endif
       
    25 #include "spbusTraces.h"
       
    26 #endif
       
    27 
    19 
    28 
    20 const TInt KPBusSocketThreadPriority=26;
    29 const TInt KPBusSocketThreadPriority=26;
    21 
    30 
    22 GLDEF_D DMediaChangeBase* TheMediaChanges[KMaxMediaChanges];
    31 GLDEF_D DMediaChangeBase* TheMediaChanges[KMaxMediaChanges];
    23 GLDEF_D DPBusSocket* TheSockets[KMaxPBusSockets];
    32 GLDEF_D DPBusSocket* TheSockets[KMaxPBusSockets];
    28  * Peripheral bus callback
    37  * Peripheral bus callback
    29  ********************************************/
    38  ********************************************/
    30 EXPORT_C TPBusCallBack::TPBusCallBack()
    39 EXPORT_C TPBusCallBack::TPBusCallBack()
    31 	:	iSocket(NULL), iFunction(NULL), iIntMask(0), iPtr(NULL)
    40 	:	iSocket(NULL), iFunction(NULL), iIntMask(0), iPtr(NULL)
    32 	{
    41 	{
       
    42 	OstTraceFunctionEntry0( TPBUSCALLBACK_TPBUSCALLBACK1_ENTRY );
    33 	iNext=NULL;
    43 	iNext=NULL;
       
    44 	OstTraceFunctionExit0( TPBUSCALLBACK_TPBUSCALLBACK1_EXIT );
    34 	}
    45 	}
    35 
    46 
    36 EXPORT_C TPBusCallBack::TPBusCallBack(TPBusCallBackFn aFunction, TAny* aPtr)
    47 EXPORT_C TPBusCallBack::TPBusCallBack(TPBusCallBackFn aFunction, TAny* aPtr)
    37 	: iSocket(NULL), iFunction(aFunction), iIntMask(0), iPtr(aPtr)
    48 	: iSocket(NULL), iFunction(aFunction), iIntMask(0), iPtr(aPtr)
    38 	{
    49 	{
       
    50 	OstTraceFunctionEntry0( TPBUSCALLBACK_TPBUSCALLBACK2_ENTRY );
    39 	iNext=NULL;
    51 	iNext=NULL;
       
    52 	OstTraceFunctionExit0( TPBUSCALLBACK_TPBUSCALLBACK2_EXIT );
    40 	}
    53 	}
    41 
    54 
    42 EXPORT_C TPBusCallBack::TPBusCallBack(TPBusIsr anIsr, TAny* aPtr, TUint anIntMask)
    55 EXPORT_C TPBusCallBack::TPBusCallBack(TPBusIsr anIsr, TAny* aPtr, TUint anIntMask)
    43 	: iSocket(NULL), iFunction(NULL), iIntMask(anIntMask), iIsr(anIsr), iPtr(aPtr)
    56 	: iSocket(NULL), iFunction(NULL), iIntMask(anIntMask), iIsr(anIsr), iPtr(aPtr)
    44 	{
    57 	{
       
    58 	OstTraceFunctionEntry0( TPBUSCALLBACK_TPBUSCALLBACK3_ENTRY );
    45 	iNext=NULL;
    59 	iNext=NULL;
       
    60 	OstTraceFunctionExit0( TPBUSCALLBACK_TPBUSCALLBACK3_EXIT );
    46 	}
    61 	}
    47 
    62 
    48 EXPORT_C void TPBusCallBack::Remove()
    63 EXPORT_C void TPBusCallBack::Remove()
    49 	{
    64 	{
       
    65 	OstTraceFunctionEntry0( TPBUSCALLBACK_REMOVE_ENTRY );
    50 	TInt irq=NKern::DisableAllInterrupts();
    66 	TInt irq=NKern::DisableAllInterrupts();
    51 	if (iNext)
    67 	if (iNext)
    52 		Deque();
    68 		Deque();
    53 	iNext=NULL;
    69 	iNext=NULL;
    54 	NKern::RestoreInterrupts(irq);
    70 	NKern::RestoreInterrupts(irq);
       
    71 	OstTraceFunctionExit0( TPBUSCALLBACK_REMOVE_EXIT );
    55 	}
    72 	}
    56 
    73 
    57 EXPORT_C void TPBusCallBack::SetSocket(TInt aSocket)
    74 EXPORT_C void TPBusCallBack::SetSocket(TInt aSocket)
    58 	{
    75 	{
       
    76 	OstTraceFunctionEntryExt( TPBUSCALLBACK_SETSOCKET_ENTRY, this );
    59 	iSocket=TheSockets[aSocket];
    77 	iSocket=TheSockets[aSocket];
       
    78 	OstTraceFunctionExit1( TPBUSCALLBACK_SETSOCKET_EXIT, this );
    60 	}
    79 	}
    61 
    80 
    62 /********************************************
    81 /********************************************
    63  * Media change base class
    82  * Media change base class
    64  ********************************************/
    83  ********************************************/
    71 EXPORT_C DMediaChangeBase::DMediaChangeBase(TInt aMediaChangeNum)
    90 EXPORT_C DMediaChangeBase::DMediaChangeBase(TInt aMediaChangeNum)
    72 	:	iMediaChangeNum(aMediaChangeNum),
    91 	:	iMediaChangeNum(aMediaChangeNum),
    73 		iReplyCount(0),
    92 		iReplyCount(0),
    74 		iDoorOpenDfc(DoorOpenDfcFn,this,Kern::DfcQue1(),1)
    93 		iDoorOpenDfc(DoorOpenDfcFn,this,Kern::DfcQue1(),1)
    75 	{
    94 	{
       
    95 	OstTraceFunctionEntryExt( DMEDIACHANGEBASE_DMEDIACHANGEBASE_ENTRY, this );
    76 	}
    96 	}
    77 
    97 
    78 
    98 
    79 /**
    99 /**
    80  * Creates a DMediaChangeBase object.
   100  * Creates a DMediaChangeBase object.
   104  * generally related to a media door or slot being opened.
   124  * generally related to a media door or slot being opened.
   105  */
   125  */
   106 EXPORT_C void DMediaChangeBase::DoorOpenService()
   126 EXPORT_C void DMediaChangeBase::DoorOpenService()
   107 	{
   127 	{
   108 	if (NKern::CurrentContext()==NKern::EInterrupt)
   128 	if (NKern::CurrentContext()==NKern::EInterrupt)
       
   129 	    {
       
   130 	    OstTrace0(TRACE_INTERNALS, DMEDIACHANGEBASE_DOOROPENSERVICE, "Interrupt driven asynchronous media change event");
   109 		iDoorOpenDfc.Add();
   131 		iDoorOpenDfc.Add();
       
   132 	    }
   110 	else 
   133 	else 
   111 		{
   134 		{
   112 		if (Kern::DfcQue1()->iThread==(NThreadBase *)NKern::CurrentThread()) 	// check if this is being called from PBUS thread
   135 		if (Kern::DfcQue1()->iThread==(NThreadBase *)NKern::CurrentThread()) 	// check if this is being called from PBUS thread
       
   136 		    {
       
   137 		    OstTrace0(TRACE_INTERNALS, DMEDIACHANGEBASE_DOOROPENSERVICE2, "Synchronous media change event");
   113 			MediaChangeEvent(ETrue);
   138 			MediaChangeEvent(ETrue);
       
   139 		    }
   114 		else
   140 		else
       
   141 		    {
       
   142 		    OstTrace0(TRACE_INTERNALS, DMEDIACHANGEBASE_DOOROPENSERVICE3, "Different thread is queueing request, asynchronous media change event");
   115 			iDoorOpenDfc.Enque();
   143 			iDoorOpenDfc.Enque();
       
   144 		    }
   116 		}
   145 		}
   117 	}
   146 	}
   118 
   147 
   119 
   148 
   120 /**
   149 /**
   124  * 
   153  * 
   125  * @param aPtr Pointer to an instantiated class which enqued/added this DFC event
   154  * @param aPtr Pointer to an instantiated class which enqued/added this DFC event
   126  */
   155  */
   127 void DMediaChangeBase::DoorOpenDfcFn(TAny* aPtr)
   156 void DMediaChangeBase::DoorOpenDfcFn(TAny* aPtr)
   128 	{
   157 	{
       
   158 	OstTraceFunctionEntry0( DMEDIACHANGEBASE_DOOROPENDFCFN_ENTRY );
   129 	DMediaChangeBase* pM=(DMediaChangeBase*)aPtr;
   159 	DMediaChangeBase* pM=(DMediaChangeBase*)aPtr;
   130 	pM->MediaChangeEvent(ETrue);
   160 	pM->MediaChangeEvent(ETrue);
       
   161 	OstTraceFunctionExit0( DMEDIACHANGEBASE_DOOROPENDFCFN_EXIT );
   131 	}
   162 	}
   132 
   163 
   133 /**
   164 /**
   134  *
   165  *
   135  * Notifies sockets of door close event.
   166  * Notifies sockets of door close event.
   136  *
   167  *
   137  * This function must be called by variant when door close has been detected.
   168  * This function must be called by variant when door close has been detected.
   138  */
   169  */
   139 EXPORT_C void DMediaChangeBase::DoorClosedService()
   170 EXPORT_C void DMediaChangeBase::DoorClosedService()
   140 	{
   171 	{
       
   172 	OstTraceFunctionEntry1( DMEDIACHANGEBASE_DOORCLOSEDSERVICE_ENTRY, this );
   141 	MediaChangeEvent(EFalse);
   173 	MediaChangeEvent(EFalse);
       
   174 	OstTraceFunctionExit1( DMEDIACHANGEBASE_DOORCLOSEDSERVICE_EXIT, this );
   142 	}
   175 	}
   143 
   176 
   144 /**
   177 /**
   145  * Notifies relevant peripheral bus sockets of door open or close events.
   178  * Notifies relevant peripheral bus sockets of door open or close events.
   146  *
   179  *
   148  *
   181  *
   149  * @see DPBusSocket::DPBusSocket
   182  * @see DPBusSocket::DPBusSocket
   150  */
   183  */
   151 void DMediaChangeBase::MediaChangeEvent(TBool aDoorOpened)
   184 void DMediaChangeBase::MediaChangeEvent(TBool aDoorOpened)
   152 	{
   185 	{
       
   186 	OstTraceFunctionEntry1( DMEDIACHANGEBASE_MEDIACHANGEEVENT_ENTRY, this );
   153 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DMediaChangeBase(%d)::MediaChangeEvent(%d)",iMediaChangeNum,aDoorOpened));
   187 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DMediaChangeBase(%d)::MediaChangeEvent(%d)",iMediaChangeNum,aDoorOpened));
       
   188 	OstTraceExt2(TRACE_INTERNALS, DMEDIACHANGEBASE_DMEDIACHANGEBASE, "iMediaChangeNum=%d; aDoorOpened=%d", iMediaChangeNum,aDoorOpened);
   154 	TInt i;
   189 	TInt i;
   155 
   190 
   156 	// notify all sockets affected
   191 	// notify all sockets affected
   157 	for (i=0; i<KMaxPBusSockets; i++)
   192 	for (i=0; i<KMaxPBusSockets; i++)
   158 		{
   193 		{
   163 			if (!pS->iMediaChangeDfc.Queued())
   198 			if (!pS->iMediaChangeDfc.Queued())
   164 			    __e32_atomic_add_ord32(&iReplyCount, 1);
   199 			    __e32_atomic_add_ord32(&iReplyCount, 1);
   165 			pS->MediaChangeEvent(aDoorOpened);
   200 			pS->MediaChangeEvent(aDoorOpened);
   166 			}
   201 			}
   167 		}
   202 		}
       
   203 	OstTraceFunctionExit1( DMEDIACHANGEBASE_MEDIACHANGEEVENT_EXIT, this );
   168 	}
   204 	}
   169 
   205 
   170 /**
   206 /**
   171  * To be called by peripheral bus socket derived classes when
   207  * To be called by peripheral bus socket derived classes when
   172  * door open/close event has been processed.
   208  * door open/close event has been processed.
   177  * @see DPBusSocket::DoorOpenEvent()
   213  * @see DPBusSocket::DoorOpenEvent()
   178  * @see DPBusSocket::DoorCloseEvent()
   214  * @see DPBusSocket::DoorCloseEvent()
   179  */
   215  */
   180 void DMediaChangeBase::AcknowledgeEvent(TBool aDoorOpened)
   216 void DMediaChangeBase::AcknowledgeEvent(TBool aDoorOpened)
   181 	{
   217 	{
       
   218 	OstTraceFunctionEntryExt( DMEDIACHANGEBASE_ACKNOWLEDGEEVENT_ENTRY, this );
   182 	TInt c = __e32_atomic_tas_ord32(&iReplyCount, 1, -1, 0);
   219 	TInt c = __e32_atomic_tas_ord32(&iReplyCount, 1, -1, 0);
   183 	if (c==1)
   220 	if (c==1)
   184 		{
   221 		{
   185 		if (aDoorOpened)
   222 		if (aDoorOpened)
   186 			DoDoorOpen();
   223 			DoDoorOpen();
   187 		else
   224 		else
   188 			DoDoorClosed();
   225 			DoDoorClosed();
   189 		}
   226 		}
       
   227 	OstTraceFunctionExit1( DMEDIACHANGEBASE_ACKNOWLEDGEEVENT_EXIT, this );
   190 	}
   228 	}
   191 
   229 
   192 /********************************************
   230 /********************************************
   193  * Power supply base class
   231  * Power supply base class
   194  ********************************************/
   232  ********************************************/
   195 void psuTick(TAny* aPtr)
   233 void psuTick(TAny* aPtr)
   196 	{
   234 	{
       
   235 	OstTraceFunctionEntry0( _PSUTICK_ENTRY );
   197 	DPBusPsuBase* pP=(DPBusPsuBase*)aPtr;
   236 	DPBusPsuBase* pP=(DPBusPsuBase*)aPtr;
   198 	pP->iPsuDfc.Enque();
   237 	pP->iPsuDfc.Enque();
       
   238 	OstTraceFunctionExit0( _PSUTICK_EXIT );
   199 	}
   239 	}
   200 	
   240 	
   201 void psuDfc(TAny* aPtr)
   241 void psuDfc(TAny* aPtr)
   202 	{
   242 	{
       
   243 	OstTraceFunctionEntry0( _PSUDFC_ENTRY );
   203 	DPBusPsuBase* pP=(DPBusPsuBase*)aPtr;
   244 	DPBusPsuBase* pP=(DPBusPsuBase*)aPtr;
   204 	pP->DoTickService();
   245 	pP->DoTickService();
       
   246 	OstTraceFunctionExit0( _PSUDFC_EXIT );
   205 	}
   247 	}
   206 
   248 
   207 /**
   249 /**
   208 Constructor for a DPBusPsuBase object.
   250 Constructor for a DPBusPsuBase object.
   209 
   251 
   213 DPBusPsuBase::DPBusPsuBase(TInt aPsuNum, TInt aMediaChangeNum)
   255 DPBusPsuBase::DPBusPsuBase(TInt aPsuNum, TInt aMediaChangeNum)
   214 	: iPsuNum(aPsuNum), iMediaChangeNum(aMediaChangeNum), iVoltCheckMethod(EPsuChkComparator), iState(EPsuOff),
   256 	: iPsuNum(aPsuNum), iMediaChangeNum(aMediaChangeNum), iVoltCheckMethod(EPsuChkComparator), iState(EPsuOff),
   215 	iPsuDfc(psuDfc, this, 4),
   257 	iPsuDfc(psuDfc, this, 4),
   216 	iPwrDownCheckFn(DoPwrDownCheck)
   258 	iPwrDownCheckFn(DoPwrDownCheck)
   217 	{
   259 	{
       
   260 	OstTraceFunctionEntryExt( DPBUSPSUBASE_DPBUSPSUBASE_ENTRY, this );
   218 //	iCurrLimited=EFalse;
   261 //	iCurrLimited=EFalse;
   219 //	iVoltageSupported=0;
   262 //	iVoltageSupported=0;
   220 //	iMaxCurrentInMicroAmps=0;
   263 //	iMaxCurrentInMicroAmps=0;
   221 //	iVoltCheckInterval=0;
   264 //	iVoltCheckInterval=0;
   222 //	iInactivityCount=0;
   265 //	iInactivityCount=0;
   225 //	iNotLockedTimeout=0;
   268 //	iNotLockedTimeout=0;
   226 	}
   269 	}
   227 
   270 
   228 void DPBusPsuBase::DoPwrDownCheck(TAny* aPtr)
   271 void DPBusPsuBase::DoPwrDownCheck(TAny* aPtr)
   229 	{
   272 	{
       
   273 	OstTraceFunctionEntry0( DPBUSPSUBASE_DOPWRDOWNCHECK_ENTRY );
   230 	DPBusPsuBase& self = *static_cast<DPBusPsuBase*>(aPtr);
   274 	DPBusPsuBase& self = *static_cast<DPBusPsuBase*>(aPtr);
   231 	self.PwrDownCheck();
   275 	self.PwrDownCheck();
       
   276 	OstTraceFunctionExit0( DPBUSPSUBASE_DOPWRDOWNCHECK_EXIT );
   232 	}
   277 	}
   233 
   278 
   234 /**
   279 /**
   235 Initialises a DPBusPsuBase object.
   280 Initialises a DPBusPsuBase object.
   236 
   281 
   242 @see DPBusPsuBase::PsuInfo()
   287 @see DPBusPsuBase::PsuInfo()
   243 @see DPBusPsuBase::DoCreate()
   288 @see DPBusPsuBase::DoCreate()
   244 */
   289 */
   245 TInt DPBusPsuBase::Create()
   290 TInt DPBusPsuBase::Create()
   246 	{
   291 	{
       
   292 	OstTraceFunctionEntry1( DPBUSPSUBASE_CREATE_ENTRY, this );
   247 
   293 
   248 	TPBusPsuInfo pi;
   294 	TPBusPsuInfo pi;
   249 	PsuInfo(pi);
   295 	PsuInfo(pi);
   250 	iVoltageSupported=pi.iVoltageSupported;
   296 	iVoltageSupported=pi.iVoltageSupported;
   251 	iMaxCurrentInMicroAmps=pi.iMaxCurrentInMicroAmps;
   297 	iMaxCurrentInMicroAmps=pi.iMaxCurrentInMicroAmps;
   254 	iInactivityTimeout=pi.iInactivityTimeOut;
   300 	iInactivityTimeout=pi.iInactivityTimeOut;
   255 	iNotLockedTimeout=pi.iNotLockedTimeOut;
   301 	iNotLockedTimeout=pi.iNotLockedTimeOut;
   256 
   302 
   257 	TInt r=DoCreate();
   303 	TInt r=DoCreate();
   258 	if (r!=KErrNone)
   304 	if (r!=KErrNone)
       
   305 	    {
       
   306 		OstTraceFunctionExitExt( DPBUSPSUBASE_CREATE_EXIT1, this, r );
   259 		return r;
   307 		return r;
       
   308 	    }
   260 	
   309 	
   261 	iPsuDfc.SetDfcQ(&iSocket->iDfcQ);
   310 	iPsuDfc.SetDfcQ(&iSocket->iDfcQ);
   262 	
   311 	
       
   312 	OstTraceFunctionExitExt( DPBUSPSUBASE_CREATE_EXIT2, this, KErrNone );
   263 	return KErrNone;
   313 	return KErrNone;
   264 	}
   314 	}
   265 
   315 
   266 
   316 
   267 /**
   317 /**
   274 
   324 
   275 @return KErrNone
   325 @return KErrNone
   276 */
   326 */
   277 EXPORT_C TInt DPBusPsuBase::DoCreate()
   327 EXPORT_C TInt DPBusPsuBase::DoCreate()
   278 	{
   328 	{
   279 	return KErrNone;
   329 	OstTraceFunctionEntry1( DPBUSPSUBASE_DOCREATE_ENTRY, this );
       
   330 	TInt r = KErrNone;
       
   331 	OstTraceFunctionExitExt( DPBUSPSUBASE_DOCREATE_EXIT, this, r );
       
   332 	return r;
   280 	}
   333 	}
   281 
   334 
   282 
   335 
   283 /**
   336 /**
   284 Reset (turn off) the power supply unit.
   337 Reset (turn off) the power supply unit.
   285 Sets PSU state to EPsuOff.
   338 Sets PSU state to EPsuOff.
   286 */
   339 */
   287 void DPBusPsuBase::Reset()
   340 void DPBusPsuBase::Reset()
   288 	{
   341 	{
       
   342 	OstTraceFunctionEntry1( DPBUSPSUBASE_RESET_ENTRY, this );
   289 	SetState(EPsuOff);
   343 	SetState(EPsuOff);
   290 	iCurrLimited=EFalse;
   344 	iCurrLimited=EFalse;
       
   345 	OstTraceFunctionExit1( DPBUSPSUBASE_RESET_EXIT, this );
   291 	}
   346 	}
   292 
   347 
   293 
   348 
   294 /**
   349 /**
   295 Checks whether this PSU is powering a bus containing
   350 Checks whether this PSU is powering a bus containing
   318 @see TPBusPsuState
   373 @see TPBusPsuState
   319 @see DPBusPsuBase::DoSetState()
   374 @see DPBusPsuBase::DoSetState()
   320 */
   375 */
   321 EXPORT_C TInt DPBusPsuBase::SetState(TPBusPsuState aState)
   376 EXPORT_C TInt DPBusPsuBase::SetState(TPBusPsuState aState)
   322 	{
   377 	{
       
   378 	OstTraceFunctionEntry1( DPBUSPSUBASE_SETSTATE_ENTRY, this );
   323 
   379 
   324 	TInt r=KErrGeneral;
   380 	TInt r=KErrGeneral;
   325 	if (aState==EPsuOff)
   381 	if (aState==EPsuOff)
   326 		{
   382 		{
   327 		iTickLink.Cancel(); // No point in having the 1 second tick running while the PSU is off
   383 		iTickLink.Cancel(); // No point in having the 1 second tick running while the PSU is off
   341 		DoSetState(aState);
   397 		DoSetState(aState);
   342 		iState=aState;
   398 		iState=aState;
   343 		r=KErrNone;
   399 		r=KErrNone;
   344 		}
   400 		}
   345 	__KTRACE_OPT(KPBUS2,Kern::Printf("<Psu(%d):Set(%d)-%d",iPsuNum,aState,r));
   401 	__KTRACE_OPT(KPBUS2,Kern::Printf("<Psu(%d):Set(%d)-%d",iPsuNum,aState,r));
       
   402 	OstTraceExt3(TRACE_INTERNALS, DPBUSPSUBASE_SETSTATE, "iPsuNum=%d; aState=%d; retval=%d", iPsuNum, (TInt) aState, r);
       
   403 	OstTraceFunctionExit1( DPBUSPSUBASE_SETSTATE_EXIT, this );
   346 	return r;
   404 	return r;
   347 	}
   405 	}
   348 
   406 
   349 
   407 
   350 /**
   408 /**
   361 @see DPBusPsuBase::DoTickService()
   419 @see DPBusPsuBase::DoTickService()
   362 @see DPBusPsuBase::DoCheckVoltage()
   420 @see DPBusPsuBase::DoCheckVoltage()
   363 */
   421 */
   364 TInt DPBusPsuBase::CheckVoltage(TUint aCheckStatus)
   422 TInt DPBusPsuBase::CheckVoltage(TUint aCheckStatus)
   365 	{
   423 	{
       
   424 	OstTraceFunctionEntryExt( DPBUSPSUBASE_CHECKVOLTAGE_ENTRY, this );
   366 	// Check that voltage checking is in order at this time
   425 	// Check that voltage checking is in order at this time
   367 	if (
   426 	if (
   368 		(aCheckStatus&iVoltCheckInterval) &&
   427 		(aCheckStatus&iVoltCheckInterval) &&
   369 		((aCheckStatus&KPsuChkOnPwrUp) || ((aCheckStatus&KPsuChkWhileOn)&&iState==EPsuOnFull))
   428 		((aCheckStatus&KPsuChkOnPwrUp) || ((aCheckStatus&KPsuChkWhileOn)&&iState==EPsuOnFull))
   370 	   )
   429 	   )
   371 		{
   430 		{
   372 		DoCheckVoltage();
   431 		DoCheckVoltage();
       
   432 		OstTraceFunctionExitExt( DPBUSPSUBASE_CHECKVOLTAGE_EXIT, this, KErrNone );
   373 		return KErrNone;
   433 		return KErrNone;
   374 		}
   434 		}
       
   435 	OstTraceFunctionExitExt( DPBUSPSUBASE_CHECKVOLTAGE_EXIT2, this, KErrNotSupported );
   375 	return KErrNotSupported;
   436 	return KErrNotSupported;
   376 	}
   437 	}
   377 
   438 
   378 
   439 
   379 /**
   440 /**
   391 @see DPBusPsuBase::DoCheckVoltage()
   452 @see DPBusPsuBase::DoCheckVoltage()
   392 @see DPBusSocket::PsuFault()
   453 @see DPBusSocket::PsuFault()
   393 */
   454 */
   394 EXPORT_C void DPBusPsuBase::ReceiveVoltageCheckResult(TInt anError)
   455 EXPORT_C void DPBusPsuBase::ReceiveVoltageCheckResult(TInt anError)
   395 	{
   456 	{
       
   457 	OstTraceFunctionEntryExt( DPBUSPSUBASE_RECEIVEVOLTAGECHECKRESULT_ENTRY, this );
   396 //	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusPsuBase(%d)::ReceiveVoltageCheckResult(%d)",iPsuNum,anError));
   458 //	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusPsuBase(%d)::ReceiveVoltageCheckResult(%d)",iPsuNum,anError));
       
   459 	OstTraceExt2(TRACE_INTERNALS, DPBUSPSUBASE_RECEVIVEVOLTAGECHECKRESULT,"iPsuNum=%d; ReceiveVoltageCheckResult=%d",iPsuNum,anError );
   397 	if (anError==KErrGeneral)
   460 	if (anError==KErrGeneral)
   398 		{
   461 		{
   399 		SetCurrLimited();
   462 		SetCurrLimited();
   400 		iSocket->PsuFault(KErrCorrupt);
   463 		iSocket->PsuFault(KErrCorrupt);
   401 		}
   464 		}
       
   465 	OstTraceFunctionExit1( DPBUSPSUBASE_RECEIVEVOLTAGECHECKRESULT_EXIT, this );
   402 	}
   466 	}
   403 
   467 
   404 /**
   468 /**
   405 Get the current power supply unit status
   469 Get the current power supply unit status
   406 
   470 
   408 
   472 
   409 @see TPBusPsuStatus
   473 @see TPBusPsuStatus
   410 */
   474 */
   411 TPBusPsuStatus DPBusPsuBase::Status()
   475 TPBusPsuStatus DPBusPsuBase::Status()
   412 	{
   476 	{
       
   477 	OstTraceFunctionEntry1( DPBUSPSUBASE_STATUS_ENTRY, this );
   413 	if (iCurrLimited)
   478 	if (iCurrLimited)
       
   479 	    {
       
   480 		OstTraceFunctionExit1( DPBUSPSUBASE_STATUS_EXIT1, this );
   414 		return(EPsuStatError);
   481 		return(EPsuStatError);
       
   482 	    }
   415 	else
   483 	else
       
   484 	    {
       
   485 	    OstTraceFunctionExit1( DPBUSPSUBASE_STATUS_EXIT2, this );
   416 		return( (iState==EPsuOff) ? EPsuStatOff : EPsuStatOn );
   486 		return( (iState==EPsuOff) ? EPsuStatOff : EPsuStatOn );
       
   487 	    }
   417 	}
   488 	}
   418 
   489 
   419 
   490 
   420 /**
   491 /**
   421 Checks if power supply unit can be turned off.
   492 Checks if power supply unit can be turned off.
   422 
   493 
   423 @see DPBusPsuBase::DoTickService()
   494 @see DPBusPsuBase::DoTickService()
   424 */
   495 */
   425 void DPBusPsuBase::PwrDownCheck()
   496 void DPBusPsuBase::PwrDownCheck()
   426 	{
   497 	{
   427 
   498 OstTraceFunctionEntry1( DPBUSPSUBASE_PWRDOWNCHECK_ENTRY, this );
   428 	if (
   499 	if (
   429 		(iNotLockedTimeout&&!IsLocked()&&++iNotLockedCount>iNotLockedTimeout) ||
   500 		(iNotLockedTimeout&&!IsLocked()&&++iNotLockedCount>iNotLockedTimeout) ||
   430 		(iInactivityTimeout&&++iInactivityCount>iInactivityTimeout)
   501 		(iInactivityTimeout&&++iInactivityCount>iInactivityTimeout)
   431 	   )
   502 	   )
   432 			iSocket->PsuTimeout();
   503 			iSocket->PsuTimeout();
       
   504 	OstTraceFunctionExit1( DPBUSPSUBASE_PWRDOWNCHECK_EXIT, this );
   433 	}
   505 	}
   434 	
   506 	
   435 	
   507 	
   436 /**
   508 /**
   437 Services the Pc Card Tick (called in timer thread).
   509 Services the Pc Card Tick (called in timer thread).
   438 */
   510 */
   439 EXPORT_C void DPBusPsuBase::DoTickService()
   511 EXPORT_C void DPBusPsuBase::DoTickService()
   440 	{
   512 	{
       
   513 	OstTraceFunctionEntry1( DPBUSPSUBASE_DOTICKSERVICE_ENTRY, this );
   441 	if (iPwrDownCheckFn)
   514 	if (iPwrDownCheckFn)
   442 		(*iPwrDownCheckFn)(this);	
   515 		(*iPwrDownCheckFn)(this);	
   443 	CheckVoltage(KPsuChkWhileOn);	// Check voltage level
   516 	CheckVoltage(KPsuChkWhileOn);	// Check voltage level
       
   517 	OstTraceFunctionExit1( DPBUSPSUBASE_DOTICKSERVICE_EXIT, this );
   444 	}
   518 	}
   445 
   519 
   446 
   520 
   447 /********************************************
   521 /********************************************
   448  * Peripheral bus power handler
   522  * Peripheral bus power handler
   449  ********************************************/
   523  ********************************************/
   450 DPBusPowerHandler::DPBusPowerHandler(DPBusSocket* aSocket)
   524 DPBusPowerHandler::DPBusPowerHandler(DPBusSocket* aSocket)
   451 	:	DPowerHandler(*aSocket->iName),
   525 	:	DPowerHandler(*aSocket->iName),
   452 		iSocket(aSocket)
   526 		iSocket(aSocket)
   453 	{
   527 	{
       
   528 	OstTraceFunctionEntryExt( DPBUSPOWERHANDLER_DPBUSPOWERHANDLER_ENTRY, this );
   454 	}
   529 	}
   455 
   530 
   456 void DPBusPowerHandler::PowerUp()
   531 void DPBusPowerHandler::PowerUp()
   457 	{
   532 	{
       
   533 	OstTraceFunctionEntry1( DPBUSPOWERHANDLER_POWERUP_ENTRY, this );
   458 	iSocket->iPowerUpDfc.Enque();
   534 	iSocket->iPowerUpDfc.Enque();
       
   535 	OstTraceFunctionExit1( DPBUSPOWERHANDLER_POWERUP_EXIT, this );
   459 	}
   536 	}
   460 
   537 
   461 void DPBusPowerHandler::PowerDown(TPowerState)
   538 void DPBusPowerHandler::PowerDown(TPowerState)
   462 	{
   539 	{
       
   540 	OstTraceFunctionEntry1( DPBUSPOWERHANDLER_POWERDOWN_ENTRY, this );
   463 	iSocket->iPowerDownDfc.Enque();
   541 	iSocket->iPowerDownDfc.Enque();
       
   542 	OstTraceFunctionExit1( DPBUSPOWERHANDLER_POWERDOWN_EXIT, this );
   464 	}
   543 	}
   465 
   544 
   466 /********************************************
   545 /********************************************
   467  * Peripheral bus socket base class
   546  * Peripheral bus socket base class
   468  ********************************************/
   547  ********************************************/
   469 void mediaChangeDfc(TAny* aPtr)
   548 void mediaChangeDfc(TAny* aPtr)
   470 	{
   549 	{
       
   550 	OstTraceFunctionEntry0( _MEDIACHANGEDFC_ENTRY );
   471 	DPBusSocket* pS=(DPBusSocket*)aPtr;
   551 	DPBusSocket* pS=(DPBusSocket*)aPtr;
   472 	if (pS->iDoorOpened)
   552 	if (pS->iDoorOpened)
   473 		pS->DoorOpenEvent();
   553 		pS->DoorOpenEvent();
   474 	else
   554 	else
   475 		pS->DoorCloseEvent();
   555 		pS->DoorCloseEvent();
       
   556 	OstTraceFunctionExit0( _MEDIACHANGEDFC_EXIT );
   476 	}
   557 	}
   477 
   558 
   478 void powerUpDfc(TAny* aPtr)
   559 void powerUpDfc(TAny* aPtr)
   479 	{
   560 	{
       
   561 	OstTraceFunctionEntry0( _POWERUPDFC_ENTRY );
   480 	DPBusSocket* pS=(DPBusSocket*)aPtr;
   562 	DPBusSocket* pS=(DPBusSocket*)aPtr;
   481 	pS->DoPowerUp();
   563 	pS->DoPowerUp();
       
   564 	OstTraceFunctionExit0( _POWERUPDFC_EXIT );
   482 	}
   565 	}
   483 
   566 
   484 void powerDownDfc(TAny* aPtr)
   567 void powerDownDfc(TAny* aPtr)
   485 	{
   568 	{
       
   569 	OstTraceFunctionEntry0( _POWERDOWNDFC_ENTRY );
   486 	DPBusSocket* pS=(DPBusSocket*)aPtr;
   570 	DPBusSocket* pS=(DPBusSocket*)aPtr;
   487 	pS->DoPowerDown();
   571 	pS->DoPowerDown();
       
   572 	OstTraceFunctionExit0( _POWERDOWNDFC_EXIT );
   488 	}
   573 	}
   489 
   574 
   490 	/**
   575 	/**
   491     PBus Socket panics. Faults the system. 
   576     PBus Socket panics. Faults the system. 
   492 	This will start the Crash Debugger if it is present, otherwise the system is rebooted by calling Kern::Restart(0)
   577 	This will start the Crash Debugger if it is present, otherwise the system is rebooted by calling Kern::Restart(0)
   506 			KErrNotReady if there is any postponed events outstanding.
   591 			KErrNotReady if there is any postponed events outstanding.
   507 	@see DPBusSocket::EndInCritical()
   592 	@see DPBusSocket::EndInCritical()
   508 	*/
   593 	*/
   509 EXPORT_C TInt DPBusSocket::InCritical()
   594 EXPORT_C TInt DPBusSocket::InCritical()
   510 	{
   595 	{
       
   596 	OstTraceFunctionEntry1( DPBUSSOCKET_INCRITICAL_ENTRY, this );
   511 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::InCritical",iSocketNumber));
   597 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::InCritical",iSocketNumber));
       
   598 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_INCRITICAL, "iSocketNumber=%d",iSocketNumber );
   512 	if (iPostponeCount==0 && iPostponedEvents!=0)
   599 	if (iPostponeCount==0 && iPostponedEvents!=0)
       
   600 	    {
       
   601 		OstTraceFunctionExitExt( DPBUSSOCKET_INCRITICAL_EXIT1, this, KErrNotReady );
   513 		return KErrNotReady;	// we are about to do media change/power down
   602 		return KErrNotReady;	// we are about to do media change/power down
       
   603 	    }
   514 	++iPostponeCount;
   604 	++iPostponeCount;
       
   605 	OstTraceFunctionExitExt( DPBUSSOCKET_INCRITICAL_EXIT2, this, KErrNone );
   515 	return KErrNone;
   606 	return KErrNone;
   516 	}
   607 	}
   517 
   608 
   518 	/**
   609 	/**
   519     Flags the media driver as leaving a critical part of its processing.
   610     Flags the media driver as leaving a critical part of its processing.
   521 	@see TPostponedEvent
   612 	@see TPostponedEvent
   522 	@see DPBusSocket::InCritical()
   613 	@see DPBusSocket::InCritical()
   523 	*/
   614 	*/
   524 EXPORT_C void DPBusSocket::EndInCritical()
   615 EXPORT_C void DPBusSocket::EndInCritical()
   525 	{
   616 	{
       
   617 	OstTraceFunctionEntry1( DPBUSSOCKET_ENDINCRITICAL_ENTRY, this );
   526 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::EndInCritical",iSocketNumber));
   618 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::EndInCritical",iSocketNumber));
       
   619 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_ENDINCRITICAL1, "iSocketNumber=%d",iSocketNumber);
   527 	if (iPostponeCount && --iPostponeCount==0)
   620 	if (iPostponeCount && --iPostponeCount==0)
   528 		{
   621 		{
   529 		if (iPostponedEvents & EMediaChange)
   622 		if (iPostponedEvents & EMediaChange)
   530 			{
   623 			{
   531 			iMediaChangeDfc.Enque();
   624 			iMediaChangeDfc.Enque();
   532 			__KTRACE_OPT(KPBUS1,Kern::Printf("Media change - done postponed"));
   625 			__KTRACE_OPT(KPBUS1,Kern::Printf("Media change - done postponed"));
       
   626 			OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_ENDINCRITICAL2, "Media change - done postponed");
   533 			}
   627 			}
   534 		if (iPostponedEvents & EPowerDown)
   628 		if (iPostponedEvents & EPowerDown)
   535 			{
   629 			{
   536 			iPowerDownDfc.Enque();
   630 			iPowerDownDfc.Enque();
   537 			__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("Power down - done postponed"));
   631 			__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("Power down - done postponed"));
       
   632 			OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_ENDINCRITICAL3, "Power down - done postponed");
   538 			}
   633 			}
   539 		}
   634 		}
       
   635 	OstTraceFunctionExit1( DPBUSSOCKET_ENDINCRITICAL_EXIT, this );
   540 	}
   636 	}
   541 
   637 
   542 	/**
   638 	/**
   543 	Sets the incremental value of current consumption to aCurrent.
   639 	Sets the incremental value of current consumption to aCurrent.
   544     @param	aCurrent	Delta Current in Milliamps 
   640     @param	aCurrent	Delta Current in Milliamps 
   545 	@see DPowerHandler::DeltaCurrentConsumption()
   641 	@see DPowerHandler::DeltaCurrentConsumption()
   546 	*/
   642 	*/
   547 EXPORT_C void DPBusSocket::DeltaCurrentConsumption(TInt aDelta)
   643 EXPORT_C void DPBusSocket::DeltaCurrentConsumption(TInt aDelta)
   548 	{
   644 	{
       
   645 	OstTraceFunctionEntryExt( DPBUSSOCKET_DELTACURRENTCONSUMPTION_ENTRY, this );
   549 	iPowerHandler->DeltaCurrentConsumption(aDelta);
   646 	iPowerHandler->DeltaCurrentConsumption(aDelta);
       
   647 	OstTraceFunctionExit1( DPBUSSOCKET_DELTACURRENTCONSUMPTION_EXIT, this );
   550 	}
   648 	}
   551 
   649 
   552 	/**
   650 	/**
   553 	Constructor for DPBusSocket.
   651 	Constructor for DPBusSocket.
   554 	Sets the iSocketNumber and initializes the DFC queue for Media Change Dfc, PowerUp Dfc, PowerDown Dfc and PSU Dfc queue.
   652 	Sets the iSocketNumber and initializes the DFC queue for Media Change Dfc, PowerUp Dfc, PowerDown Dfc and PSU Dfc queue.
   559 		iMediaChangeDfc(mediaChangeDfc, this, 6),
   657 		iMediaChangeDfc(mediaChangeDfc, this, 6),
   560 		iPowerUpDfc(powerUpDfc, this, 4),
   658 		iPowerUpDfc(powerUpDfc, this, 4),
   561 		iPowerDownDfc(powerDownDfc, this, 4),
   659 		iPowerDownDfc(powerDownDfc, this, 4),
   562 		iPsuDfc(psuDfc, this, 4)
   660 		iPsuDfc(psuDfc, this, 4)
   563 	{
   661 	{
       
   662 	OstTraceFunctionEntryExt( DPBUSSOCKET_DPBUSSOCKET_ENTRY, this );
   564 //	iPowerGroup=0;
   663 //	iPowerGroup=0;
   565 //	iName=NULL;
   664 //	iName=NULL;
   566 //	iState=EPBusCardAbsent;
   665 //	iState=EPBusCardAbsent;
   567 //	iPostponeCount=0;
   666 //	iPostponeCount=0;
   568 //	iPostponedEvents=0;
   667 //	iPostponedEvents=0;
   581 	@see iPowerDownDfc
   680 	@see iPowerDownDfc
   582 	@see iPsuDfc
   681 	@see iPsuDfc
   583 	*/
   682 	*/
   584 TInt DPBusSocket::Create(const TDesC* aName)
   683 TInt DPBusSocket::Create(const TDesC* aName)
   585 	{
   684 	{
       
   685 	OstTraceFunctionEntry1( DPBUSSOCKET_CREATE_ENTRY, this );
   586 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::Create %lS",iSocketNumber,aName));
   686 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::Create %lS",iSocketNumber,aName));
       
   687 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_CREATE, "iSocketNumber=%d",iSocketNumber);
   587 	iName=aName;
   688 	iName=aName;
   588 	DPBusPowerHandler* pH=new DPBusPowerHandler(this);
   689 	DPBusPowerHandler* pH=new DPBusPowerHandler(this);
   589 	if (!pH)
   690 	if (!pH)
       
   691 	    {
       
   692 		OstTraceFunctionExitExt( DPBUSSOCKET_CREATE_EXIT1, this, KErrNoMemory );
   590 		return KErrNoMemory;
   693 		return KErrNoMemory;
       
   694 	    }
   591 	iPowerHandler=pH;
   695 	iPowerHandler=pH;
   592 	pH->Add();		// register power handler
   696 	pH->Add();		// register power handler
   593 	TInt r=Kern::DfcQInit(&iDfcQ, KPBusSocketThreadPriority, iName);
   697 	TInt r=Kern::DfcQInit(&iDfcQ, KPBusSocketThreadPriority, iName);
   594 	if (r!=KErrNone)
   698 	if (r!=KErrNone)
       
   699 	    {
       
   700 		OstTraceFunctionExitExt( DPBUSSOCKET_CREATE_EXIT2, this, r );
   595 		return r;
   701 		return r;
       
   702 	    }
   596 	iMediaChangeDfc.SetDfcQ(&iDfcQ);
   703 	iMediaChangeDfc.SetDfcQ(&iDfcQ);
   597 	iPowerUpDfc.SetDfcQ(&iDfcQ);
   704 	iPowerUpDfc.SetDfcQ(&iDfcQ);
   598 	iPowerDownDfc.SetDfcQ(&iDfcQ);
   705 	iPowerDownDfc.SetDfcQ(&iDfcQ);
   599 	
   706 	
       
   707 	OstTraceFunctionExitExt( DPBUSSOCKET_CREATE_EXIT3, this, KErrNone );
   600 	return KErrNone;
   708 	return KErrNone;
   601 	}
   709 	}
   602 
   710 
   603 	/**
   711 	/**
   604 	Initializes the PBus socket by changing its state to EPBusOff.
   712 	Initializes the PBus socket by changing its state to EPBusOff.
   605 	@return	KErrNone	if successful,
   713 	@return	KErrNone	if successful,
   606 			otherwise one of the other system wide error codes.
   714 			otherwise one of the other system wide error codes.
   607 	*/
   715 	*/
   608 TInt DPBusSocket::Init()
   716 TInt DPBusSocket::Init()
   609 	{
   717 	{
       
   718 	OstTraceFunctionEntry1( DPBUSSOCKET_INIT_ENTRY, this );
   610 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::Init",iSocketNumber));
   719 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::Init",iSocketNumber));
       
   720 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_INIT, "iSocketNumber=%d",iSocketNumber);
   611 	__PM_ASSERT(iState == EPBusCardAbsent);
   721 	__PM_ASSERT(iState == EPBusCardAbsent);
   612 	if (MediaState()==EDoorClosed && CardIsPresent())
   722 	if (MediaState()==EDoorClosed && CardIsPresent())
   613 		ChangeState(EPBusOff,KErrNotReady);
   723 		ChangeState(EPBusOff,KErrNotReady);
       
   724 	OstTraceFunctionExitExt( DPBUSSOCKET_INIT_EXIT, this, KErrNone );
   614 	return KErrNone;
   725 	return KErrNone;
   615 	}
   726 	}
   616 
   727 
   617 void DPBusSocket::ResetSocket(TBool aFullReset)
   728 void DPBusSocket::ResetSocket(TBool aFullReset)
   618 	{
   729 	{
       
   730 	OstTraceFunctionEntryExt( DPBUSSOCKET_RESETSOCKET_ENTRY, this );
       
   731 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_RESETSOCKET, "iSocketNumber=%d; aFullReset=%d", iSocketNumber, aFullReset);
   619 	Reset1();
   732 	Reset1();
   620 	iVcc->Reset();
   733 	iVcc->Reset();
   621 	if (aFullReset)
   734 	if (aFullReset)
   622 		Reset2();
   735 		Reset2();
       
   736 	OstTraceFunctionExit1( DPBUSSOCKET_RESETSOCKET_EXIT, this );
   623 	}
   737 	}
   624 
   738 
   625 void DPBusSocket::ChangeState(TInt aState, TInt anError)
   739 void DPBusSocket::ChangeState(TInt aState, TInt anError)
   626 //
   740 //
   627 // Change state, notifying all clients
   741 // Change state, notifying all clients
   628 //
   742 //
   629 	{
   743 	{
       
   744 	OstTraceFunctionEntryExt( DPBUSSOCKET_CHANGESTATE_ENTRY, this );
   630 	__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d ChangeState %d to %d, err %d",iSocketNumber,iState,aState,anError));
   745 	__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d ChangeState %d to %d, err %d",iSocketNumber,iState,aState,anError));
       
   746 	OstTraceExt4(TRACE_INTERNALS, DPBUSSOCKET_CHANGESTATE , "iSocketNumber=%d; ChangeState %d to %d; anError=%d",iSocketNumber,iState,aState,anError);
   631 	if (iState!=aState)
   747 	if (iState!=aState)
   632 		{
   748 		{
   633 		if(iState == EPBusCardAbsent && aState == EPBusOff && anError == KErrTimedOut)
   749 		if(iState == EPBusCardAbsent && aState == EPBusOff && anError == KErrTimedOut)
   634 			{
   750 			{
   635 			// Maintain the internal state to EPBusCardAbsent when PSU
   751 			// Maintain the internal state to EPBusCardAbsent when PSU
   646 			{
   762 			{
   647 			((TPBusCallBack*)pC)->NotifyPBusStateChange(aState,anError);
   763 			((TPBusCallBack*)pC)->NotifyPBusStateChange(aState,anError);
   648 			pC=pC->iNext;
   764 			pC=pC->iNext;
   649 			}
   765 			}
   650 		}
   766 		}
       
   767 	OstTraceFunctionExit1( DPBUSSOCKET_CHANGESTATE_EXIT, this );
   651 	}
   768 	}
   652 
   769 
   653 void DPBusSocket::Isr(TInt anId)
   770 void DPBusSocket::Isr(TInt anId)
   654 //
   771 //
   655 // Service a card interrupt
   772 // Service a card interrupt
   656 //
   773 //
   657 	{
   774 	{
       
   775 	OstTraceFunctionEntry1( DPBUSSOCKET_ISR_ENTRY, this );
       
   776 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_ISR, "iSocketNumber=%d; anId=%d", iSocketNumber, anId );
   658 	// notify all interested clients of interrupt
   777 	// notify all interested clients of interrupt
   659 	SDblQueLink* pC=iCallBackQ.iA.iNext;
   778 	SDblQueLink* pC=iCallBackQ.iA.iNext;
   660 #ifdef _DEBUG
   779 #ifdef _DEBUG
   661 	TInt n=0;
   780 	TInt n=0;
   662 #endif
   781 #endif
   668 		((TPBusCallBack*)pC)->Isr(anId);
   787 		((TPBusCallBack*)pC)->Isr(anId);
   669 		pC=pC->iNext;
   788 		pC=pC->iNext;
   670 		}
   789 		}
   671 #ifdef _DEBUG
   790 #ifdef _DEBUG
   672 	__KTRACE_OPT(KPBUS1,Kern::Printf("!%d",n));
   791 	__KTRACE_OPT(KPBUS1,Kern::Printf("!%d",n));
       
   792 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_ISR2, "!%d", n);
   673 #endif
   793 #endif
       
   794 	OstTraceFunctionExit1( DPBUSSOCKET_ISR_EXIT, this );
   674 	}
   795 	}
   675 
   796 
   676 	/**
   797 	/**
   677 	This function adds a callback function to the socket.
   798 	This function adds a callback function to the socket.
   678 	@param aCallBack is a pointer to PBus callback function for event notification.
   799 	@param aCallBack is a pointer to PBus callback function for event notification.
   679 	@see TPBusCallBack
   800 	@see TPBusCallBack
   680 	*/
   801 	*/
   681 EXPORT_C void DPBusSocket::Add(TPBusCallBack* aCallBack)
   802 EXPORT_C void DPBusSocket::Add(TPBusCallBack* aCallBack)
   682 	{
   803 	{
       
   804 	OstTraceFunctionEntry1( DPBUSSOCKET_ADD_ENTRY, this );
   683 	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusSocket(%d)::Add(%08x) next %08x",iSocketNumber,aCallBack,aCallBack->iNext));
   805 	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusSocket(%d)::Add(%08x) next %08x",iSocketNumber,aCallBack,aCallBack->iNext));
       
   806 	OstTraceExt3(TRACE_INTERNALS, DPBUSSOCKET_ADD, "iSocketNumber=%d; aCallBack=0x%08x; aCallBack->iNext=0x%08x",iSocketNumber, (TUint) aCallBack, (TUint) aCallBack->iNext);
   684 	TInt irq=NKern::DisableAllInterrupts();
   807 	TInt irq=NKern::DisableAllInterrupts();
   685 	if (!aCallBack->iNext)
   808 	if (!aCallBack->iNext)
   686 		iCallBackQ.Add(aCallBack);
   809 		iCallBackQ.Add(aCallBack);
   687 	NKern::RestoreInterrupts(irq);
   810 	NKern::RestoreInterrupts(irq);
       
   811 	OstTraceFunctionExit1( DPBUSSOCKET_ADD_EXIT, this );
   688 	}
   812 	}
   689 
   813 
   690 	/**
   814 	/**
   691 	Called by clients to power up the socket.
   815 	Called by clients to power up the socket.
   692 	@return	KErrNone	if successful, otherwise one of the other system-wide error codes including: 
   816 	@return	KErrNone	if successful, otherwise one of the other system-wide error codes including: 
   698     @panic PBUS 1, if PBUS state is invalid.
   822     @panic PBUS 1, if PBUS state is invalid.
   699 	@see TPBusState
   823 	@see TPBusState
   700 	*/
   824 	*/
   701 EXPORT_C TInt DPBusSocket::PowerUp()
   825 EXPORT_C TInt DPBusSocket::PowerUp()
   702 	{
   826 	{
       
   827 	OstTraceFunctionEntry1( DPBUSSOCKET_POWERUP_ENTRY, this );
   703 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf(">DPBusSocket(%d)::PowerUp state %d",iSocketNumber,iState));
   828 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf(">DPBusSocket(%d)::PowerUp state %d",iSocketNumber,iState));
       
   829 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_POWERUP1, "iSocketNumber=%d; iState=%d",iSocketNumber,iState);
   704 	TInt r=KErrNone;
   830 	TInt r=KErrNone;
   705 	switch (iState)
   831 	switch (iState)
   706 		{
   832 		{
   707 		case EPBusCardAbsent:		// card absent or media change has occurred
   833 		case EPBusCardAbsent:		// card absent or media change has occurred
   708 			r=KErrNotReady;
   834 			r=KErrNotReady;
   735 			ChangeState(EPBusPoweringUp,KErrNone);
   861 			ChangeState(EPBusPoweringUp,KErrNone);
   736 			InitiatePowerUpSequence();
   862 			InitiatePowerUpSequence();
   737 			}
   863 			}
   738 		}
   864 		}
   739 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("<DPBusSocket(%d)::PowerUp ret %d, state %d",iSocketNumber,r,iState));
   865 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("<DPBusSocket(%d)::PowerUp ret %d, state %d",iSocketNumber,r,iState));
       
   866 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_POWERUP2, "iSocketNumber=%d; iState=%d",iSocketNumber,iState);
       
   867 	OstTraceFunctionExitExt( DPBUSSOCKET_POWERUP_EXIT, this, r );
   740 	return r;
   868 	return r;
   741 	}
   869 	}
   742 	/**
   870 	/**
   743 	This function is called upon completion of the power up sequence of the device.
   871 	This function is called upon completion of the power up sequence of the device.
   744 	This is method is called by the derived class methods to terminate the powerup sequence with error codes.
   872 	This is method is called by the derived class methods to terminate the powerup sequence with error codes.
   747 	@see DPBusSocket::InitiatePowerUpSequence()
   875 	@see DPBusSocket::InitiatePowerUpSequence()
   748 	*/
   876 	*/
   749 
   877 
   750 EXPORT_C void DPBusSocket::PowerUpSequenceComplete(TInt anError)
   878 EXPORT_C void DPBusSocket::PowerUpSequenceComplete(TInt anError)
   751 	{
   879 	{
       
   880 	OstTraceFunctionEntry1( DPBUSSOCKET_POWERUPSEQUENCECOMPLETE_ENTRY, this );
   752 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("DPBusSocket(%d)::PowerUpSequenceComplete state %d error %d",iSocketNumber,iState,anError));
   881 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("DPBusSocket(%d)::PowerUpSequenceComplete state %d error %d",iSocketNumber,iState,anError));
       
   882 	OstTraceExt3(TRACE_INTERNALS, DPBUSSOCKET_POWERUPSEQUENCECOMPLETE, "iSocketNumber=%d; iState=%d; anError=%d",iSocketNumber,iState,anError);
   753 	if (iState!=EPBusCardAbsent && iState!=EPBusOff)
   883 	if (iState!=EPBusCardAbsent && iState!=EPBusOff)
   754 		{
   884 		{
   755 		if (anError==KErrNone)
   885 		if (anError==KErrNone)
   756 			ChangeState(EPBusOn,KErrNone);
   886 			ChangeState(EPBusOn,KErrNone);
   757 		else if (anError==KErrBadPower || anError==KErrAbort || anError==KErrTimedOut)
   887 		else if (anError==KErrBadPower || anError==KErrAbort || anError==KErrTimedOut)
   759 		else if (anError == KErrNotReady)
   889 		else if (anError == KErrNotReady)
   760 			ChangeState(EPBusCardAbsent,KErrAbort);
   890 			ChangeState(EPBusCardAbsent,KErrAbort);
   761 		else
   891 		else
   762 			ChangeState(EPBusPsuFault,anError);
   892 			ChangeState(EPBusPsuFault,anError);
   763 		}
   893 		}
       
   894 	OstTraceFunctionExit1( DPBUSSOCKET_POWERUPSEQUENCECOMPLETE_EXIT, this );
   764 	}
   895 	}
   765 
   896 
   766 void DPBusSocket::PsuFault(TInt anError)
   897 void DPBusSocket::PsuFault(TInt anError)
   767 	{
   898 	{
   768 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::PsuFault state %d error %d",iSocketNumber,iState,anError));
   899 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::PsuFault state %d error %d",iSocketNumber,iState,anError));
       
   900 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_PSUFAULT, "iSocketNumber=%d; iState=%d",iSocketNumber,iState );
   769 	ResetSocket(ETrue);
   901 	ResetSocket(ETrue);
   770 	ChangeState(EPBusPsuFault,anError);
   902 	ChangeState(EPBusPsuFault,anError);
   771 	}
   903 	}
   772 
   904 
   773 void DPBusSocket::PsuTimeout()
   905 void DPBusSocket::PsuTimeout()
   774 	{
   906 	{
   775 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::PsuTimeout state %d",iSocketNumber,iState));
   907 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::PsuTimeout state %d",iSocketNumber,iState));
       
   908 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_PSUTIMEOUT, "iSocketNumber=%d; iState=%d",iSocketNumber,iState );
   776 	ResetSocket(EFalse);
   909 	ResetSocket(EFalse);
   777 	ChangeState(EPBusOff,KErrTimedOut);
   910 	ChangeState(EPBusOff,KErrTimedOut);
   778 	}
   911 	}
   779 
   912 
   780 void DPBusSocket::DoPowerUp()
   913 void DPBusSocket::DoPowerUp()
   781 //
   914 //
   782 // Called on transition from standby
   915 // Called on transition from standby
   783 //
   916 //
   784 	{
   917 	{
       
   918 	OstTraceFunctionEntry1( DPBUSSOCKET_DOPOWERUP_ENTRY, this );
       
   919 	
   785 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("DPBusSocket(%d)::DoPowerUp state %d",iSocketNumber,iState));
   920 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("DPBusSocket(%d)::DoPowerUp state %d",iSocketNumber,iState));
       
   921 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_DOPOWERUP, "iSocketNumber=%d; iState=%d",iSocketNumber,iState );
   786 	__PM_ASSERT(iStandby);
   922 	__PM_ASSERT(iStandby);
   787 	if (iState!=EPBusCardAbsent && iState!=EPBusOff && iState!=EPBusPowerUpPending)
   923 	if (iState!=EPBusCardAbsent && iState!=EPBusOff && iState!=EPBusPowerUpPending)
   788 		Panic(EMcPowerUpInvalidState);
   924 		Panic(EMcPowerUpInvalidState);
   789 
   925 
   790 	// when we power up, check whether the door is closed and a card is present
   926 	// when we power up, check whether the door is closed and a card is present
   812 		}
   948 		}
   813 	else
   949 	else
   814 		ChangeState(EPBusOff,KErrNotReady);
   950 		ChangeState(EPBusOff,KErrNotReady);
   815 	iStandby = EFalse;
   951 	iStandby = EFalse;
   816 	iPowerHandler->PowerUpDone();
   952 	iPowerHandler->PowerUpDone();
       
   953 	OstTraceFunctionExit1( DPBUSSOCKET_DOPOWERUP_EXIT, this );
   817 	}
   954 	}
   818 
   955 
   819 void DPBusSocket::DoPowerDown()
   956 void DPBusSocket::DoPowerDown()
   820 //
   957 //
   821 // Called by DPowerManager on transition to standby
   958 // Called by DPowerManager on transition to standby
   822 //
   959 //
   823 	{
   960 	{
       
   961 	OstTraceFunctionEntry1( DPBUSSOCKET_DOPOWERDOWN_ENTRY, this );
   824 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("DPBusSocket(%d)::DoPowerDown state %d",iSocketNumber,iState));
   962 	__KTRACE_OPT2(KPBUS1,KPOWER,Kern::Printf("DPBusSocket(%d)::DoPowerDown state %d",iSocketNumber,iState));
       
   963 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_DOPOWERDOWN1, "iSocketNumber=%d; iState=%d",iSocketNumber,iState );
   825 	__PM_ASSERT(!iStandby);
   964 	__PM_ASSERT(!iStandby);
   826 	if (iPostponeCount)
   965 	if (iPostponeCount)
   827 		{
   966 		{
   828 		iPostponedEvents |= EPowerDown;
   967 		iPostponedEvents |= EPowerDown;
   829 		__KTRACE_OPT(KPBUS1,Kern::Printf("Power down postponed"));
   968 		__KTRACE_OPT(KPBUS1,Kern::Printf("Power down postponed"));
       
   969 		OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_DOPOWERDOWN2, "Power down postponed");
   830 		return;
   970 		return;
   831 		}
   971 		}
   832 	iPostponedEvents &= ~EPowerDown;
   972 	iPostponedEvents &= ~EPowerDown;
   833 	switch (iState)
   973 	switch (iState)
   834 		{
   974 		{
   848 		{
   988 		{
   849 		ResetSocket(EFalse);
   989 		ResetSocket(EFalse);
   850 		iStandby = ETrue;
   990 		iStandby = ETrue;
   851 		iPowerHandler->PowerDownDone();
   991 		iPowerHandler->PowerDownDone();
   852 		}
   992 		}
       
   993 	OstTraceFunctionExit1( DUP1_DPBUSSOCKET_DOPOWERDOWN_EXIT, this );
   853 	}
   994 	}
   854 
   995 
   855 	/**
   996 	/**
   856 	Notifies the socket that we are deferring this power down event. 
   997 	Notifies the socket that we are deferring this power down event. 
   857 	The function increments the iRequestPowerDownCount reference count
   998 	The function increments the iRequestPowerDownCount reference count
   858 	@see DPBusSocket::PowerDownComplete()
   999 	@see DPBusSocket::PowerDownComplete()
   859 	*/
  1000 	*/
   860 EXPORT_C void DPBusSocket::RequestAsyncPowerDown()
  1001 EXPORT_C void DPBusSocket::RequestAsyncPowerDown()
   861 	{
  1002 	{
   862 	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusSocket::RequestAsyncPowerDown"));	
  1003 	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusSocket::RequestAsyncPowerDown"));
       
  1004 	OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_REQUESTASYNCPOWERDOWN1, "DPBusSocket::RequestAsyncPowerDown");
   863     __e32_atomic_add_ord32(&iRequestPowerDownCount, 1);
  1005     __e32_atomic_add_ord32(&iRequestPowerDownCount, 1);
   864 	__KTRACE_OPT(KPBUS1,Kern::Printf("   >> count=%d", iRequestPowerDownCount));
  1006 	__KTRACE_OPT(KPBUS1,Kern::Printf("   >> count=%d", iRequestPowerDownCount));
       
  1007 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_REQUESTASYNCPOWERDOWN2, "iRequestPowerDownCount=%d", iRequestPowerDownCount);
   865 	}
  1008 	}
   866 
  1009 
   867 	/**
  1010 	/**
   868 	This function power down the PBus. Powers down the PBus if iRequestPowerDownCount is equal to 1.
  1011 	This function power down the PBus. Powers down the PBus if iRequestPowerDownCount is equal to 1.
   869 	@see DPBusSocket::RequestAsyncPowerDown()
  1012 	@see DPBusSocket::RequestAsyncPowerDown()
   870 	@see iRequestPowerDownCount
  1013 	@see iRequestPowerDownCount
   871 	*/
  1014 	*/
   872 EXPORT_C void DPBusSocket::PowerDownComplete()
  1015 EXPORT_C void DPBusSocket::PowerDownComplete()
   873 	{
  1016 	{
   874 	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusSocket::PowerDownComplete"));
  1017 	__KTRACE_OPT(KPBUS1,Kern::Printf("DPBusSocket::PowerDownComplete"));
       
  1018 	OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_POWERDOWNCOMPLETE, "DPBusSocket::PowerDownComplete");
   875 	if (__e32_atomic_tas_ord32(&iRequestPowerDownCount, 1, -1, 0) == 1)
  1019 	if (__e32_atomic_tas_ord32(&iRequestPowerDownCount, 1, -1, 0) == 1)
   876 		{
  1020 		{
   877 		__KTRACE_OPT(KPBUS1,Kern::Printf("   > Signalling Power Down (deferred)"));
  1021 		__KTRACE_OPT(KPBUS1,Kern::Printf("   > Signalling Power Down (deferred)"));
       
  1022 		OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_POWERDOWNCOMPLETE2, "Signalling Power Down (deferred)");
   878 		DoPowerDown();
  1023 		DoPowerDown();
   879 		}
  1024 		}
   880 	__KTRACE_OPT(KPBUS1,Kern::Printf("   >> count=%d", iRequestPowerDownCount));
  1025 	__KTRACE_OPT(KPBUS1,Kern::Printf("   >> count=%d", iRequestPowerDownCount));
       
  1026 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_POWERDOWNCOMPLETE3, "iRequestPowerDownCount=%d", iRequestPowerDownCount);
   881 	}
  1027 	}
   882 	
  1028 	
   883 	/**
  1029 	/**
   884 	This function is called by the local media device driver to force a remount of the media device.
  1030 	This function is called by the local media device driver to force a remount of the media device.
   885 	@see DMediaChangeBase::ForceMediaChange()
  1031 	@see DMediaChangeBase::ForceMediaChange()
   886 	*/
  1032 	*/
   887 EXPORT_C void DPBusSocket::ForceMediaChange()
  1033 EXPORT_C void DPBusSocket::ForceMediaChange()
   888 	{
  1034 	{
       
  1035 	OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_FORCEMEDIACHANGE, "iSocketNumber=%d", iSocketNumber);
   889 	iMediaChange->ForceMediaChange();
  1036 	iMediaChange->ForceMediaChange();
   890 	}
  1037 	}
   891 
  1038 
   892 void DPBusSocket::MediaChangeEvent(TBool aDoorOpened)
  1039 void DPBusSocket::MediaChangeEvent(TBool aDoorOpened)
   893 //
  1040 //
   894 // Called in high-priority DFC
  1041 // Called in high-priority DFC
   895 //
  1042 //
   896 	{
  1043 	{
   897 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::MediaChangeEvent %d state %d",iSocketNumber,aDoorOpened,iState));
  1044 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::MediaChangeEvent %d state %d",iSocketNumber,aDoorOpened,iState));
       
  1045 	OstTraceExt3(TRACE_INTERNALS, DPBUSSOCKET_MEDIACHANGEEVENT, "iSocketNumber=%d; aDoorOpened=%d; iState=%d",iSocketNumber,aDoorOpened,iState);
   898 	iDoorOpened=aDoorOpened;
  1046 	iDoorOpened=aDoorOpened;
   899 	iMediaChangeDfc.Enque();
  1047 	iMediaChangeDfc.Enque();
   900 	}
  1048 	}
   901 
  1049 
   902 void DPBusSocket::DoorOpenEvent()
  1050 void DPBusSocket::DoorOpenEvent()
   903 //
  1051 //
   904 // Called in socket thread
  1052 // Called in socket thread
   905 //
  1053 //
   906 	{
  1054 	{
       
  1055 	OstTraceFunctionEntry1( DPBUSSOCKET_DOOROPENEVENT_ENTRY, this );
       
  1056 	
   907 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::DoorOpenEvent state %d",iSocketNumber,iState));
  1057 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::DoorOpenEvent state %d",iSocketNumber,iState));
       
  1058 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_DOOROPENEVENT1, "iSocketNumber=%d; iState=%d",iSocketNumber,iState);
   908 
  1059 
   909 	if (iPostponeCount)
  1060 	if (iPostponeCount)
   910 		{
  1061 		{
   911 		iPostponedEvents |= EMediaChange;
  1062 		iPostponedEvents |= EMediaChange;
   912 		__KTRACE_OPT(KPBUS1,Kern::Printf("Media change postponed"));
  1063 		__KTRACE_OPT(KPBUS1,Kern::Printf("Media change postponed"));
       
  1064 		OstTraceFunctionExit1( DPBUSSOCKET_DOOROPENEVENT_EXIT1, this );
   913 		return;
  1065 		return;
   914 		}
  1066 		}
   915 	iPostponedEvents &= ~EMediaChange;
  1067 	iPostponedEvents &= ~EMediaChange;
   916 
  1068 
   917     // notify all clients of media change
  1069     // notify all clients of media change
   945 #else
  1097 #else
   946 	if (mediaState == EDoorClosed && CardIsPresent())
  1098 	if (mediaState == EDoorClosed && CardIsPresent())
   947 #endif
  1099 #endif
   948 		{
  1100 		{
   949 		__KTRACE_OPT(KPBUS1,Kern::Printf("At least 1 door still closed"));;
  1101 		__KTRACE_OPT(KPBUS1,Kern::Printf("At least 1 door still closed"));;
       
  1102 		OstTrace0(TRACE_INTERNALS, DPBUSSOCKET_DOOROPENEVENT2 , "At least 1 door still closed");
   950 		ChangeState(EPBusOff,KErrNotReady);
  1103 		ChangeState(EPBusOff,KErrNotReady);
   951 		}
  1104 		}
   952 
  1105 
       
  1106 	OstTraceFunctionExit1( DPBUSSOCKET_DOOROPENEVENT_EXIT2, this );
   953 	}
  1107 	}
   954 
  1108 
   955 void DPBusSocket::DoorCloseEvent()
  1109 void DPBusSocket::DoorCloseEvent()
   956 	{
  1110 	{
       
  1111 	OstTraceFunctionEntry1( DPBUSSOCKET_DOORCLOSEEVENT_ENTRY, this );
   957 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::DoorCloseEvent state %d",iSocketNumber,iState));
  1112 	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPBusSocket(%d)::DoorCloseEvent state %d",iSocketNumber,iState));
       
  1113 	OstTraceExt2(TRACE_INTERNALS, DPBUSSOCKET_DOORCLOSEEVENT , "iSocketNumber=%d; iState=%d",iSocketNumber,iState);
   958 
  1114 
   959 	// NB If there are multiple doors then the bus may already be powererd up, 
  1115 	// NB If there are multiple doors then the bus may already be powererd up, 
   960 	// so it's not possible to determine the bus state.
  1116 	// so it's not possible to determine the bus state.
   961 	//if (iState!=EPBusCardAbsent)
  1117 	//if (iState!=EPBusCardAbsent)
   962 	//	Panic(EDoorCloseInvalidState);
  1118 	//	Panic(EDoorCloseInvalidState);
   998 	if(iSimulatedMediaState == EPeriphBusMediaNormal)
  1154 	if(iSimulatedMediaState == EPeriphBusMediaNormal)
   999 		iMediaChange->AcknowledgeEvent(EFalse);
  1155 		iMediaChange->AcknowledgeEvent(EFalse);
  1000 #else
  1156 #else
  1001 	iMediaChange->AcknowledgeEvent(EFalse);
  1157 	iMediaChange->AcknowledgeEvent(EFalse);
  1002 #endif
  1158 #endif
       
  1159 	OstTraceFunctionExit1( DPBUSSOCKET_DOORCLOSEEVENT_EXIT, this );
  1003 	}
  1160 	}
  1004 	/**
  1161 	/**
  1005 	Gets pointer to the PBus Socket corresponding to the opened logical unit.
  1162 	Gets pointer to the PBus Socket corresponding to the opened logical unit.
  1006 	@param anId	logical id of the PBus Socket.	
  1163 	@param anId	logical id of the PBus Socket.	
  1007 	@return Pointer to the PBusSocket for valid anId, else NULL.
  1164 	@return Pointer to the PBusSocket for valid anId, else NULL.
  1008 	*/
  1165 	*/
  1009 EXPORT_C DPBusSocket* DPBusSocket::SocketFromId(TInt anId)
  1166 EXPORT_C DPBusSocket* DPBusSocket::SocketFromId(TInt anId)
  1010 	{
  1167 	{
       
  1168 	OstTraceFunctionEntry0( DPBUSSOCKET_SOCKETFROMID_ENTRY );
  1011 	if (anId>=0 && anId<KMaxPBusSockets)
  1169 	if (anId>=0 && anId<KMaxPBusSockets)
       
  1170 	    {
       
  1171 		OstTraceFunctionExit0( DPBUSSOCKET_SOCKETFROMID_EXIT1 );
  1012 		return TheSockets[anId];
  1172 		return TheSockets[anId];
       
  1173 	    }
       
  1174 	OstTraceFunctionExit0( DPBUSSOCKET_SOCKETFROMID_EXIT2 );
  1013 	return NULL;
  1175 	return NULL;
  1014 	}
  1176 	}
  1015 
  1177 
  1016 	/**
  1178 	/**
  1017 	Default implementation for handling debug functionality.
  1179 	Default implementation for handling debug functionality.
  1029 	@see TPBusSimulateMediaState
  1191 	@see TPBusSimulateMediaState
  1030 	@see TPBusDebugFunction
  1192 	@see TPBusDebugFunction
  1031 	*/
  1193 	*/
  1032 EXPORT_C TInt DPBusSocket::ControlIO(TInt aFunction, TAny* aParam1, TAny* /*aParam2*/)
  1194 EXPORT_C TInt DPBusSocket::ControlIO(TInt aFunction, TAny* aParam1, TAny* /*aParam2*/)
  1033 	{
  1195 	{
       
  1196 	OstTraceExt3(TRACE_FLOW, DPBUSSOCKET_CONTROLIO_ENTRY,"DPBusSocket::ControlIO;aFunction=%d;aParam1=%d;this=%x", (TInt) aFunction, (TInt) aParam1, (TUint) this);
  1034 	TInt err = KErrNone;
  1197 	TInt err = KErrNone;
  1035 
  1198 
  1036 	switch(aFunction)
  1199 	switch(aFunction)
  1037 		{
  1200 		{
  1038 		case EControlMediaState:
  1201 		case EControlMediaState:
  1044 #ifdef __ENABLE_SIMULATED_MEDIA_CHANGE
  1207 #ifdef __ENABLE_SIMULATED_MEDIA_CHANGE
  1045 			TUint16 newState = (TUint16)(TInt)aParam1;
  1208 			TUint16 newState = (TUint16)(TInt)aParam1;
  1046 			if(newState != iSimulatedMediaState)
  1209 			if(newState != iSimulatedMediaState)
  1047 				{
  1210 				{
  1048 				iSimulatedMediaState = newState;
  1211 				iSimulatedMediaState = newState;
  1049 
  1212 	            OstTrace1(TRACE_INTERNALS, DPBUSSOCKET_CONTROLIO , "iSimulatedMediaState=%d",iSimulatedMediaState);
  1050 				switch(iSimulatedMediaState)
  1213 				switch(iSimulatedMediaState)
  1051 					{
  1214 					{
  1052 					case EPeriphBusMediaNormal:
  1215 					case EPeriphBusMediaNormal:
  1053 						//
  1216 						//
  1054 						// Normal state
  1217 						// Normal state
  1099 		default:
  1262 		default:
  1100 			err = KErrNotSupported;
  1263 			err = KErrNotSupported;
  1101 			break;
  1264 			break;
  1102 		}
  1265 		}
  1103 
  1266 
       
  1267 	OstTraceFunctionExitExt( DPBUSSOCKET_CONTROLIO_EXIT, this, err );
  1104 	return err;
  1268 	return err;
  1105 	}
  1269 	}
  1106 
  1270 
  1107 /********************************************
  1271 /********************************************
  1108  * Extension entry point
  1272  * Extension entry point