Skip to content

Power Manager

RSX-Engineering edited this page May 25, 2023 · 1 revision

ProffieOS v6.7x009

Power Manager


Overview

The power manager turns on and off the following power domains:

  • Pixel blade
  • Audio amplifier
  • Audio booster
  • SD Card
  • Processor

The power subscribers are firmware objects that require one ore more power domains to be active in order to operate. Power subscribers request power and have each assigned a timeout, after which the power manager will consider that the subscriber no longer needs power. Each power domain gets automatically turned off when no subscriber needs it anymore, and when no domain remains on the processor will go into deep sleep mode. Waking up from deep sleep can be caused by a button action or by receiving data on the serial port.

Class diagram


Usage

The power domains are handled by the power manager. The power subscribers should do the following:

1. Subscribe

In order to become a power subscriber, a class must inherit the xPowerSubscriber class and call its constructor specifying the power domains it will subscribe to.

class MyClass : xPowerSubscriber {
    MyClass() : xPowerSubscriber(pwr4_none) {  // replace pwr_none with a bitwise OR of PDType flags
        // my constructor
    }
}

2. [optiona] Define ON/OFF actions

Once subscribed to one or more power domains, the subscriber will:

  • turn ON when all its subscribed power domains are on
  • turn OFF when at leas one of its subscribed power domains are off

The power manager provides callback functions that can be used to initialize / deinitialize objects or peripherals when the subscriber's power turns on and off.

ON/OFF actions are defined by overriding the PwrOn_Callback() and PwrOff_Callback() functions:

void PwrOn_Callback() override { 
    // Action to run immediately after subscriber's power goes on
}

void PwrOff_Callback() override { 
    // Action to run just before subscriber's power goes off
}

3. Request power

When a subscriber is requesting power:

  1. If any subscribed domain is off, it will turn on
  2. All subscribed domains will reset their own auto-power-off (timeout) timer

Power is requested by calling the RequestPower() function:

myobject.RequestPower();    // turn and keep power on

Once a domain is turned on, it will automatically turn off if the timeout expires without any subscriber requesting power from it. Each domain has its built-in timeout, which can be overriden by the subscriber requesting power:

uint32_t subscriber_timeouts[] = { 500, 10000 };  // timeout in milliseconds for each subscribed domain, in PDType order.
myobject.RequestPower(subscriber_timeouts);  // turn and keep power on, reset timeouts to specified values

4. [optional] Hold power to pause timeout

Once the subscriber's power turned on, an alternative to repeaditly request power before any domain timeouts is to hold power asynchronously. This allows the subscriber to maintain power based on logical rather than timed conditions, by overriding the HoldPower() function:

virtual bool HoldPower() override {
    // return true to hold power
    // processor will not go in deep sleep as long as any subscriber is holding power
    return false;
}

As long as HoldPower() returns true, all the subscribed domains will pause their timeout timer.


Implementation

Class diagram

Class diagram


(C) RSX Engineering SRL. FileVer. 1.1 / Apr. 2023

Clone this wiki locally