os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/inc/template_power.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// template\template_variant\inc\template_power.h
sl@0
    15
// Template Power Management Header
sl@0
    16
// (see also assp.cpp for a discussion on Sleep modes and xyin.cpp for example
sl@0
    17
// of usage of Resource Manager and Peripheral self power down and interaction
sl@0
    18
// with Power Controller for Wakeup Events)
sl@0
    19
// 
sl@0
    20
//
sl@0
    21
sl@0
    22
#ifndef __PM_STD_H__
sl@0
    23
#define __PM_STD_H__
sl@0
    24
#include <kernel/kpower.h>
sl@0
    25
#include "variant.h"
sl@0
    26
sl@0
    27
//
sl@0
    28
// TO DO: (mandatory)
sl@0
    29
//
sl@0
    30
// Definition of the DPowerController derived class
sl@0
    31
//
sl@0
    32
NONSHARABLE_CLASS(DTemplatePowerController) : public DPowerController
sl@0
    33
	{
sl@0
    34
public: // from DPowerController
sl@0
    35
	void CpuIdle();
sl@0
    36
	void EnableWakeupEvents();
sl@0
    37
	void AbsoluteTimerExpired();
sl@0
    38
	void DisableWakeupEvents();
sl@0
    39
	void PowerDown(TTimeK aWakeupTime);
sl@0
    40
public:
sl@0
    41
	DTemplatePowerController();
sl@0
    42
private:
sl@0
    43
	void DoStandby(TBool aTimed, TUint32 aWakeupRTC);
sl@0
    44
public:
sl@0
    45
	TBool iWakeupEventsOn;
sl@0
    46
	};
sl@0
    47
sl@0
    48
//
sl@0
    49
// TO DO: (optional)
sl@0
    50
//
sl@0
    51
// If you need to access to the Power Controller from Drivers/Extensions/Variant 
sl@0
    52
// or access to Resource Manager then define an accessor class as below
sl@0
    53
//
sl@0
    54
sl@0
    55
class TemplateResourceManager;
sl@0
    56
sl@0
    57
class TTemplatePowerController
sl@0
    58
	{
sl@0
    59
public:
sl@0
    60
	// to allow Variant/Drivers/Extensions access to Resource Manager
sl@0
    61
	IMPORT_C static TemplateResourceManager* ResourceManager();
sl@0
    62
	// used by drivers/extensions to signal a wakeup event to Power Controller
sl@0
    63
	IMPORT_C static void WakeupEvent();
sl@0
    64
sl@0
    65
	inline static void RegisterPowerController(DTemplatePowerController* aPowerController);
sl@0
    66
private:
sl@0
    67
	static DTemplatePowerController* iPowerController;
sl@0
    68
	};
sl@0
    69
sl@0
    70
NONSHARABLE_CLASS(SharedBinaryResource1) : public MPowerInput
sl@0
    71
	{
sl@0
    72
public: // from MPowerInput
sl@0
    73
	void Use();
sl@0
    74
	void Release();
sl@0
    75
public:
sl@0
    76
	TUint GetCount();		// gets current usage count
sl@0
    77
private:
sl@0
    78
	TUint	iCount;
sl@0
    79
	};
sl@0
    80
sl@0
    81
// Prototype class for Multilevel resources
sl@0
    82
sl@0
    83
class MSharedMultilevelResource			// Multilevel Shared Input
sl@0
    84
	{
sl@0
    85
public:
sl@0
    86
	virtual void IncreaseToLevel(TUint aLevel, TInt aRequester) = 0;
sl@0
    87
	virtual void ReduceToLevel(TUint aLevel, TInt aRequester) = 0;
sl@0
    88
	virtual TUint GetResourceLevel() = 0;
sl@0
    89
	};
sl@0
    90
sl@0
    91
// EXAMPLE ONLY
sl@0
    92
const TUint KSharers = 3;
sl@0
    93
sl@0
    94
NONSHARABLE_CLASS(SharedMultilevelResource1) : public MSharedMultilevelResource
sl@0
    95
	{
sl@0
    96
public:
sl@0
    97
	enum TRequesterId
sl@0
    98
		{
sl@0
    99
		//
sl@0
   100
		// Identify all possible users of this resource
sl@0
   101
		//
sl@0
   102
		ERequesterX = 0,
sl@0
   103
		ERequesterY = 1,
sl@0
   104
		ERequesterZ = 2
sl@0
   105
		};
sl@0
   106
	SharedMultilevelResource1();
sl@0
   107
public:	// from MSharedMultilevelResource
sl@0
   108
	void IncreaseToLevel(TUint aLevel, TInt aRequester);
sl@0
   109
	void ReduceToLevel(TUint aLevel, TInt aRequester);
sl@0
   110
	TUint GetResourceLevel();
sl@0
   111
private:
sl@0
   112
	void FindMaxLevel(TUint* aLevel, TInt* aId);
sl@0
   113
private:
sl@0
   114
	TUint	Levels[KSharers];		// one element per user of resource
sl@0
   115
	TUint	iCurrentLevel;
sl@0
   116
	TInt	iCurrentLevelOwnerId;
sl@0
   117
	};
sl@0
   118
sl@0
   119
//
sl@0
   120
// TO DO: (optional)
sl@0
   121
//
sl@0
   122
// The Resource Manager class
sl@0
   123
//
sl@0
   124
NONSHARABLE_CLASS(TemplateResourceManager)
sl@0
   125
	{
sl@0
   126
public:
sl@0
   127
	enum TResource			// a list of controllable resources (e.g clocks, voltages, power lines)
sl@0
   128
		{
sl@0
   129
		SynchBinResourceUsedByZOnly,
sl@0
   130
		AsynchBinResourceUsedByZOnly,
sl@0
   131
		//	... other non-shared binary resources, synchronous or asynchronous
sl@0
   132
		BinResourceSharedByZAndY,
sl@0
   133
		//	...	other shared binary resources, synchronous or asynchronous
sl@0
   134
		SynchMlResourceUsedByXOnly,
sl@0
   135
		AsynchMlResourceUsedByXOnly,
sl@0
   136
		//	... other non-shared multilevel resources, synchronous or asynchronous
sl@0
   137
		MlResourceSharedByXAndW,
sl@0
   138
		//	...	other shared multilevel resources, synchronous or asynchronous
sl@0
   139
		};
sl@0
   140
	enum TSleepModes
sl@0
   141
		{
sl@0
   142
		Snooze,
sl@0
   143
		// ...
sl@0
   144
		Sleep,
sl@0
   145
		// ...
sl@0
   146
		DeepSleep,
sl@0
   147
		// ...
sl@0
   148
		Coma
sl@0
   149
		};
sl@0
   150
sl@0
   151
	void InitResources();									// initialises power Resources not initialised by Bootstrap
sl@0
   152
sl@0
   153
	inline TSleepModes MapSleepMode(TInt aSleepPeriod);
sl@0
   154
sl@0
   155
	// interface for non-shared shared resources
sl@0
   156
sl@0
   157
	inline void Modify(TResource aResource, TBool aOnOff);			// for non-shared binary resources
sl@0
   158
	inline void ModifyToLevel(TResource aResource, TInt aLevel);	// for non-shared multilevel resources
sl@0
   159
	// the following functions may be used by Drivers/Extensions or the Idle routine to 
sl@0
   160
	// determine what resources are On or Off or their levels
sl@0
   161
	inline TBool GetResourceState(TResource aResource);			// for non-shared binary resources
sl@0
   162
	inline TUint GetResourceLevel(TResource aResource);			// for non-shared multilevel resources 
sl@0
   163
public:
sl@0
   164
	// interface for shared resources
sl@0
   165
sl@0
   166
	SharedBinaryResource1 iSharedBResource1;
sl@0
   167
	//	...	other shared Binary resources, synchronous or asynchronous
sl@0
   168
	inline SharedBinaryResource1* SharedBResource1();
sl@0
   169
sl@0
   170
	SharedMultilevelResource1 iSharedMlResource1;
sl@0
   171
	//	...	other shared Multilevel resources
sl@0
   172
	inline SharedMultilevelResource1* SharedMlResource1();
sl@0
   173
	};
sl@0
   174
sl@0
   175
#include "template_power.inl"
sl@0
   176
sl@0
   177
#endif