mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-09-18 11:28:04 +02:00
Handle denials of power appropriately
This commit is contained in:
@@ -19,9 +19,8 @@ void Power::begin() {
|
||||
if (!(powerScheduler->tryAccquireCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::ESP,
|
||||
PowerParameters::CurrentConsumptions::CURRENT_ESP_AVG))) {
|
||||
Serial.println("Alledgedly not enough power available to reserve the "
|
||||
"ESP32s base power consumption. Something is wrong.");
|
||||
return;
|
||||
ESP_LOGE(TAG, "Could not get power for ESP");
|
||||
throw "Could not get power for ESP";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,8 @@
|
||||
#ifndef Power_h
|
||||
#define Power_h
|
||||
|
||||
#define TAG "Power"
|
||||
|
||||
enum TaskResumptionReason { POWER_AVAILABLE, TIMEOUT };
|
||||
|
||||
class Power {
|
||||
|
@@ -22,7 +22,7 @@ bool PowerScheduler::tryAccquireCurrentAllowance(
|
||||
this->freeLimitCurrentBudget + existingConsumption > 0;
|
||||
const bool currentAvailableBelowMaximum =
|
||||
this->freeMaximumCurrentBudget + existingConsumption >= neededCurrent;
|
||||
const bool currentIsInsignificant = neededCurrent < 0.1;
|
||||
const bool currentIsInsignificant = neededCurrent < 1;
|
||||
if (currentIsInsignificant ||
|
||||
(currentAvailableBelowLimit && currentAvailableBelowMaximum)) {
|
||||
if (existingConsumption > 0) {
|
||||
@@ -115,6 +115,9 @@ bool PowerScheduler::waitForCurrentAllowance(
|
||||
.requestedAt = initialTickCount,
|
||||
.grantedAt = xTaskGetTickCount(),
|
||||
.granted = true});
|
||||
ESP_LOGV(TAG, "%d mA granted to consumer %d after %d ms",
|
||||
neededCurrent, static_cast<int>(consumer),
|
||||
xTaskGetTickCount() - initialTickCount);
|
||||
return true;
|
||||
} else {
|
||||
// Still not enough power available for us. Wait the remaining ticks.
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#ifndef PowerScheduler_h
|
||||
#define PowerScheduler_h
|
||||
|
||||
#define TAG "PowerScheduler"
|
||||
|
||||
class PowerScheduler {
|
||||
private:
|
||||
static constexpr uint16_t DEFAULT_SLACK_TIME_MS = 100;
|
||||
@@ -43,6 +45,9 @@ public:
|
||||
/// @param neededCurrent the amount of current we want to be accounted for (in
|
||||
/// mA)
|
||||
/// @return whether the current could be successfully allocated
|
||||
/// @note This takes existing power consumption by the same consumer into account,
|
||||
/// so requesting the same or less power will always succeed. Also, small amounts
|
||||
/// of power (below 1 mA) will always be granted.
|
||||
bool tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer,
|
||||
uint16_t neededcurrent,
|
||||
uint16_t requestedDurationMs = 0);
|
||||
|
Reference in New Issue
Block a user