Generic abstract interface for the power management system.

A PowerManagement implementation class handles power related events and sets up the system. The ApplicationContext object initializes an instance of this class automatically. Use can find a pointer to the PowerManagement object in the static IApplicationContext class.

Depending on the system (mono device or simulator), the concrete sub-class implementation of this interface varies.

The active IApplicationContext initializes this class and calls its POR initialization functions. Implementations of this class then calls and initializes any nessasary related classes, like the power supply IC sub-system (IPowerSubSystem).

This interface defines queues of objects that implement the IPowerAware interface. This interface lets classes handle critical power events like:

  • Power-On-Reset (POR): Called when the chip powers up after a reset
  • Enter Sleep Mode: Called before system goes in to low power sleep mode
  • Awake From Sleep: Called when nornal mode is restored after sleep

Power Awareness

Classes that handle components like I2C, Display, etc can use the PowerAware interface to receive these type of events. Its the PowerManagement object task to call these IPowerAware objects.

The interface defines a protected member object powerAwarenessQueue that is a pointer to the first object in the queue. The Power Awareness Queue is a list of objects that implment the IpowerAware interface and have added themselves to the queue by calling AppendToPowerAwareQueue

Objects in the queue receive power aware notifications on event like enter sleep mode, wake from sleep and battery low. You can add your own objects to the queue to make them “power aware” or you remove the system components that gets added by default. (But why would you do that?)

Public Functions

virtual void mono::power::IPowerManagement::EnterSleep()
= 0

Send Mono to sleep mode, and stop CPU execution. In sleep mode the CPU does not excute instruction and powers down into a low power state. The power system will turn off dynamically powered peripherals.

Any power aware objects (IPowerAware), that has registered itself in the powerAwarenessQueuemust have its onSystemEnterSleep method called.

NOTE: Before you call this method, make sure you have configured a way to go out of sleep.

virtual void mono::power::IPowerManagement::AppendToPowerAwareQueue(IPowerAware *object)

Add a IPowerAware object to the awareness queue

By added object to the Power Awareness Queue they receive callbacks on power related events, such as reset and sleep.

  • object -

    A pointer to the object that is power aware

virtual bool mono::power::IPowerManagement::RemoveFromPowerAwareQueue(IPowerAware *object)

Remove an object from the Power Awareness Queue.

Searches the Power Awareness Queue for the object and removes it, if it is found. This object will no longer receive power related notifications.

true if object was removed, false if the object was not in the queue
  • object -

    A pointer to the object that should be removed from the queue

Public Members

IPowerSubSystem *mono::power::IPowerManagement::PowerSystem

A pointer to the initialized power sub-system. This is initialize automatically and depends on compiled environment. The power system to used to control power supply to periphirals and to give interrupt on power related events.

WARNING: Use this class with extreme caution! Wrong power settings can fry the MCU and other peripherals!

Public Static Attributes

volatile bool IPowerManagement::__shouldWakeUp

This variable must be true before sleep mode is aborted.

EnterSleep() must set this to false, you should set it to true to abort sleep mode and re-enter the run loop execution. EnterSleep() will not return before this is set to true.

**Note: The class QueuedInterrupt will set this automatically!**

volatile bool IPowerManagement::__busySleep

Global flag to indicate to not halt CPU during sleep mode.

Some processes might require hardware to run async under what is normally sleep mode, where hardware peripherals are halted.

Set this flag to true to keep the the CPU awake inside the sleep mode loop. This is especially useful when handled debouncing of edge triggered interrupts.

Note: You should keep this flag false to ensure power presevation

Protected Functions

virtual void mono::power::IPowerManagement::processResetAwarenessQueue()

Call all the power aware objects right after Power-On-Reset The singleton power management object must call this method on reset

Protected Attributes

IPowerAware *mono::power::IPowerManagement::powerAwarenessQueue

A pointer to the top object in the Power Awareness Queue

The Power Awareness queue is realized by having the power object themselves hold references to the next and previous object in the queue. This eliminates the need for dynamic memory allocation a runtime.

The IPowerAware interface defines the next and previous pointers for the object in the linked list. This class only holds a reference to the first object in the queue.