bthci/hci2implementations/hctls/brcmh4/src/controllermanager.cpp
branchbroadcom_h4
changeset 37 f53839ff73b7
equal deleted inserted replaced
4:28479eeba3fb 37:f53839ff73b7
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include "controllermanager.h"
       
    22 
       
    23 #include "broadcom_hctl_h4.h"
       
    24 #include "broadcom_hctl_h4_utils.h"
       
    25 
       
    26 #include <bluetooth/hci/controllerstateobserver.h>
       
    27 #include <bluetooth/hci/hctlchannelobserver.h>
       
    28 #include <bluetooth/logger.h>
       
    29 
       
    30 #ifdef __FLOG_ACTIVE
       
    31 _LIT8(KLogComponent, LOG_COMPONENT_HCTL_BCM_H4);
       
    32 #endif
       
    33 
       
    34 
       
    35 CControllerManager* CControllerManager::NewL(CHCTLBcmH4& aHctl) 
       
    36 	{
       
    37 	LOG_STATIC_FUNC
       
    38 
       
    39 	CControllerManager* self = new(ELeave) CControllerManager(aHctl);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 CControllerManager::CControllerManager(CHCTLBcmH4& aHctl)
       
    44   :	iHctl(aHctl)
       
    45 	{
       
    46 	LOG_FUNC
       
    47 	}
       
    48 
       
    49 TInt CControllerManager::MhpiGetPower(TBTPowerState& aState)
       
    50 	{
       
    51 	LOG_FUNC
       
    52 
       
    53 	// Return current state.
       
    54 	aState = iHctl.CurrentPowerState();
       
    55 	return KErrNone;
       
    56 	}
       
    57 	
       
    58 TInt CControllerManager::MhpiSetPower(TBTPowerState aState)
       
    59 	{
       
    60 	LOG_FUNC
       
    61 
       
    62 	TInt rerr = KErrAlreadyExists;
       
    63 	// Check that the requested state differs from the current state.
       
    64 	if(aState != iHctl.CurrentPowerState())
       
    65 		{
       
    66 		__ASSERT_ALWAYS(aState == EBTOff || aState == EBTOn, 
       
    67 		                PANIC(KBcmHctlH4Panic, EUnexpectedCtrlMgrPowerState));
       
    68 		__ASSERT_ALWAYS(iControllerStateObserver, 
       
    69 		                PANIC(KBcmHctlH4Panic, EStateObserverNotAvailable));		
       
    70 
       
    71 		iControllerStateObserver->McsoProcessPowerChange(KErrNone,
       
    72 														 MControllerStateObserver::EBTFatalChange,
       
    73 														 aState);
       
    74 
       
    75 		if(aState == EBTOff)
       
    76 			{
       
    77 			// Cancel any reads / writes.
       
    78 			iHctl.HandlePowerOff();
       
    79 			}
       
    80 		else
       
    81 			{
       
    82 			// Re-start the sender and receiver.
       
    83 			iHctl.HandlePowerOn();
       
    84 			}
       
    85 		
       
    86 		rerr = KErrNone;
       
    87 		}
       
    88 
       
    89 	return rerr;
       
    90 	}
       
    91 	
       
    92 
       
    93 void CControllerManager::HardReset()
       
    94 	{
       
    95 	LOG_FUNC
       
    96 	
       
    97 	// Check if the power is currently switched off.  This takes priority over
       
    98 	// hard reset.
       
    99 	if(iHctl.CurrentPowerState() == EBTOn)
       
   100 		{
       
   101 		__ASSERT_ALWAYS(iControllerStateObserver, 
       
   102 		                PANIC(KBcmHctlH4Panic, EStateObserverNotAvailable));		
       
   103 
       
   104 		// Switch the power off then on to perform the reset.
       
   105 		iControllerStateObserver->McsoProcessHardResetPhaseChange(KErrNone, MControllerStateObserver::EBTFatalChange, EBTResetStarted);
       
   106 		// Cancel any reads / writes.
       
   107 		iHctl.HandlePowerOff();
       
   108 
       
   109 		iHctl.HandlePowerOn();
       
   110 
       
   111 		// Reset is complete.
       
   112 		iControllerStateObserver->McsoProcessHardResetPhaseChange(KErrNone, MControllerStateObserver::EBTFatalChange, EBTResetComplete);
       
   113 		}
       
   114 	}
       
   115 
       
   116 
       
   117 void CControllerManager::SetControllerStateObserver(MControllerStateObserver& aControllerStateObserver)
       
   118 	{
       
   119 	LOG_FUNC
       
   120 
       
   121 	iControllerStateObserver = &aControllerStateObserver;
       
   122 	}