Add existing code: Power consumption test cases and Semaphore power scheduler skeleton

This commit is contained in:
2024-11-24 23:09:46 +01:00
parent fb35d065af
commit 8eeb829a91
15 changed files with 597 additions and 0 deletions

40
src/power/Power.cpp Normal file
View File

@@ -0,0 +1,40 @@
/**
* @file Power.h
* @author Phillip Kühne
* @brief This component provides utilities for keeping track of power usage
* consumption.
* @version 0.1
* @date 2024-11-23
*/
#include "Power.h"
Power::Power()
{
this->free_power_budget = this->total_power_budget;
}
bool Power::tryAccquirePowerAllowance(uint16_t neededPower)
{
if (this->free_power_budget >= neededPower)
{
this->free_power_budget -= neededPower;
return true;
}
else
{
return false;
}
}
void Power::releasePower(uint16_t power)
{
if (this->free_power_budget + power <= this->total_power_budget)
{
this->free_power_budget += power;
}
else // TODO: Maybe we should actually throw an error here, since obviouslsy someone used us wrong.
{
this->free_power_budget = this->total_power_budget;
}
}

35
src/power/Power.h Normal file
View File

@@ -0,0 +1,35 @@
/**
* @file Power.h
* @author Phillip Kühne
* @brief This component provides utilities for keeping track of power usage
* consumption.
* @version 0.1
* @date 2024-11-23
*/
#include <Arduino.h>
#ifndef Power_h
#define Power_h
#define TOTAL_POWER_MILLIWATTS 700
class Power {
protected:
static const uint16_t total_power_budget = TOTAL_POWER_MILLIWATTS;
uint16_t free_power_budget;
public:
Power();
uint16_t getFreePowerBudget(void);
/// @brief Request an allowance of a certain number of milliwatts from the power scheduler
/// @param neededPower the amount of power we want to be accounted for (in mW)
/// @return whether the power could be successfully allocated
bool tryAccquirePowerAllowance(uint16_t neededPower);
/// @brief "Return" a certain amount of power when it is no longer needed
/// @param power the amount of power to return (in mW)
/// @return whether the power
void releasePower(uint16_t power);
};
#endif //Power