sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // template\template_variant\inc\template_power.h sl@0: // Template Power Management Header sl@0: // (see also assp.cpp for a discussion on Sleep modes and xyin.cpp for example sl@0: // of usage of Resource Manager and Peripheral self power down and interaction sl@0: // with Power Controller for Wakeup Events) sl@0: // sl@0: // sl@0: sl@0: #ifndef __PM_STD_H__ sl@0: #define __PM_STD_H__ sl@0: #include sl@0: #include "variant.h" sl@0: sl@0: // sl@0: // TO DO: (mandatory) sl@0: // sl@0: // Definition of the DPowerController derived class sl@0: // sl@0: NONSHARABLE_CLASS(DTemplatePowerController) : public DPowerController sl@0: { sl@0: public: // from DPowerController sl@0: void CpuIdle(); sl@0: void EnableWakeupEvents(); sl@0: void AbsoluteTimerExpired(); sl@0: void DisableWakeupEvents(); sl@0: void PowerDown(TTimeK aWakeupTime); sl@0: public: sl@0: DTemplatePowerController(); sl@0: private: sl@0: void DoStandby(TBool aTimed, TUint32 aWakeupRTC); sl@0: public: sl@0: TBool iWakeupEventsOn; sl@0: }; sl@0: sl@0: // sl@0: // TO DO: (optional) sl@0: // sl@0: // If you need to access to the Power Controller from Drivers/Extensions/Variant sl@0: // or access to Resource Manager then define an accessor class as below sl@0: // sl@0: sl@0: class TemplateResourceManager; sl@0: sl@0: class TTemplatePowerController sl@0: { sl@0: public: sl@0: // to allow Variant/Drivers/Extensions access to Resource Manager sl@0: IMPORT_C static TemplateResourceManager* ResourceManager(); sl@0: // used by drivers/extensions to signal a wakeup event to Power Controller sl@0: IMPORT_C static void WakeupEvent(); sl@0: sl@0: inline static void RegisterPowerController(DTemplatePowerController* aPowerController); sl@0: private: sl@0: static DTemplatePowerController* iPowerController; sl@0: }; sl@0: sl@0: NONSHARABLE_CLASS(SharedBinaryResource1) : public MPowerInput sl@0: { sl@0: public: // from MPowerInput sl@0: void Use(); sl@0: void Release(); sl@0: public: sl@0: TUint GetCount(); // gets current usage count sl@0: private: sl@0: TUint iCount; sl@0: }; sl@0: sl@0: // Prototype class for Multilevel resources sl@0: sl@0: class MSharedMultilevelResource // Multilevel Shared Input sl@0: { sl@0: public: sl@0: virtual void IncreaseToLevel(TUint aLevel, TInt aRequester) = 0; sl@0: virtual void ReduceToLevel(TUint aLevel, TInt aRequester) = 0; sl@0: virtual TUint GetResourceLevel() = 0; sl@0: }; sl@0: sl@0: // EXAMPLE ONLY sl@0: const TUint KSharers = 3; sl@0: sl@0: NONSHARABLE_CLASS(SharedMultilevelResource1) : public MSharedMultilevelResource sl@0: { sl@0: public: sl@0: enum TRequesterId sl@0: { sl@0: // sl@0: // Identify all possible users of this resource sl@0: // sl@0: ERequesterX = 0, sl@0: ERequesterY = 1, sl@0: ERequesterZ = 2 sl@0: }; sl@0: SharedMultilevelResource1(); sl@0: public: // from MSharedMultilevelResource sl@0: void IncreaseToLevel(TUint aLevel, TInt aRequester); sl@0: void ReduceToLevel(TUint aLevel, TInt aRequester); sl@0: TUint GetResourceLevel(); sl@0: private: sl@0: void FindMaxLevel(TUint* aLevel, TInt* aId); sl@0: private: sl@0: TUint Levels[KSharers]; // one element per user of resource sl@0: TUint iCurrentLevel; sl@0: TInt iCurrentLevelOwnerId; sl@0: }; sl@0: sl@0: // sl@0: // TO DO: (optional) sl@0: // sl@0: // The Resource Manager class sl@0: // sl@0: NONSHARABLE_CLASS(TemplateResourceManager) sl@0: { sl@0: public: sl@0: enum TResource // a list of controllable resources (e.g clocks, voltages, power lines) sl@0: { sl@0: SynchBinResourceUsedByZOnly, sl@0: AsynchBinResourceUsedByZOnly, sl@0: // ... other non-shared binary resources, synchronous or asynchronous sl@0: BinResourceSharedByZAndY, sl@0: // ... other shared binary resources, synchronous or asynchronous sl@0: SynchMlResourceUsedByXOnly, sl@0: AsynchMlResourceUsedByXOnly, sl@0: // ... other non-shared multilevel resources, synchronous or asynchronous sl@0: MlResourceSharedByXAndW, sl@0: // ... other shared multilevel resources, synchronous or asynchronous sl@0: }; sl@0: enum TSleepModes sl@0: { sl@0: Snooze, sl@0: // ... sl@0: Sleep, sl@0: // ... sl@0: DeepSleep, sl@0: // ... sl@0: Coma sl@0: }; sl@0: sl@0: void InitResources(); // initialises power Resources not initialised by Bootstrap sl@0: sl@0: inline TSleepModes MapSleepMode(TInt aSleepPeriod); sl@0: sl@0: // interface for non-shared shared resources sl@0: sl@0: inline void Modify(TResource aResource, TBool aOnOff); // for non-shared binary resources sl@0: inline void ModifyToLevel(TResource aResource, TInt aLevel); // for non-shared multilevel resources sl@0: // the following functions may be used by Drivers/Extensions or the Idle routine to sl@0: // determine what resources are On or Off or their levels sl@0: inline TBool GetResourceState(TResource aResource); // for non-shared binary resources sl@0: inline TUint GetResourceLevel(TResource aResource); // for non-shared multilevel resources sl@0: public: sl@0: // interface for shared resources sl@0: sl@0: SharedBinaryResource1 iSharedBResource1; sl@0: // ... other shared Binary resources, synchronous or asynchronous sl@0: inline SharedBinaryResource1* SharedBResource1(); sl@0: sl@0: SharedMultilevelResource1 iSharedMlResource1; sl@0: // ... other shared Multilevel resources sl@0: inline SharedMultilevelResource1* SharedMlResource1(); sl@0: }; sl@0: sl@0: #include "template_power.inl" sl@0: sl@0: #endif