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