blob: e20a5f6ce7ba6e1a4126f239260e4cde383a9d47 [file]
#pragma once
#include "CLI/CLI.hpp"
#include "include/common_utility.hpp"
#include "include/power_rail/pmbus_lib.hpp"
#include <nlohmann/json.hpp>
#include <fstream>
#include <optional>
#include <string>
#include <vector>
namespace max34451
{
constexpr uint8_t kVoutUvWarn = 0x20; // 00010000
constexpr uint8_t kVoutUvFault = 0x10; // 00001000
constexpr std::string_view kBus = "Bus";
constexpr std::string_view kAddress = "Address";
constexpr std::string_view kSource = "Source";
constexpr std::string_view kIncludeWarnings = "IncludeWarnings";
constexpr std::string_view kRegisters = "Registers";
constexpr std::string_view kFaultLogConfig = "FaultLogConfig";
constexpr std::string_view kEnableBits = "EnableBits";
constexpr std::string_view kCommand = "Command";
constexpr std::string_view kOffset = "Offset";
constexpr std::string_view kForceLog = "ForceLog";
constexpr std::string_view kClearLog = "ClearLog";
constexpr std::string_view kSequencerRegisters = "SequencerRegisters";
constexpr std::string_view kPageToPowerRailMap = "PageToPowerRailMap";
constexpr std::string_view kRailPriority = "RailPriority";
constexpr std::string_view kMfrChannelConfigReg = "MfrChannelConfigReg";
constexpr std::string_view kMfrPsenConfigReg = "MfrPsenConfigReg";
constexpr std::string_view kMfrPwmConfigReg = "MfrPwmConfigReg";
constexpr std::string_view kMfrNvFaultLogReg = "MfrNvFaultLogReg";
constexpr std::string_view kMfrNvLogConfigReg = "MfrNvLogConfigReg";
constexpr std::string_view kStatusWordReg = "StatusWordReg";
constexpr std::string_view kStatusCmlReg = "StatusCmlReg";
constexpr std::string_view kStatusMfrSpecificReg = "StatusMfrSpecificReg";
constexpr std::string_view kStatusVout = "STATUS_VOUT";
constexpr std::string_view kStatusIout = "STATUS_IOUT";
constexpr std::string_view kStatusCml = "STATUS_CML";
constexpr std::string_view kMfrChannelConfig = "MFR_CHANNEL_CONFIG";
constexpr std::string_view kMfrPsenConfig = "MFR_PSEN_CONFIG";
constexpr std::string_view kMfrPwmConfig = "MFR_PWM_CONFIG";
struct Max34451Logger
{
uint8_t bus{};
uint8_t address{};
std::string source;
bool includeWarnings = false;
uint8_t faultLogCommand{};
uint8_t faultLogOffset{};
uint8_t forceLogBit{};
std::vector<uint8_t> clearLogBits;
uint8_t mfrChannelConfigReg{};
uint8_t mfrPsenConfigReg{};
uint8_t mfrPwmConfigReg{};
uint8_t mfrNvFaultLogReg{};
uint8_t mfrNvLogConfigReg{};
uint8_t statusWordReg{};
uint8_t statusCmlReg{};
uint8_t statusMfrSpecificReg{};
std::vector<json> sequencerRegisters;
std::vector<std::string> railPriority;
void loadConfig(std::string_view configFilePath);
};
/**
* @brief Retrieves the Max34451 BB (burst buffer) data.
*
* @param logger The Max34451Logger object to retrieve the BB data from.
*/
std::vector<uint8_t> getMax34451BB(const Max34451Logger& logger);
/**
* @brief Get the power rail fault logs.
*
* This function takes a Max34451Logger object and a vector of uint8_t as
* parameters and returns the power rail fault logs as a string.
*
* @param logger The Max34451Logger object to retrieve the power rail fault logs
* from.
* @param faultLog The vector of uint8_t to retrieve the power rail fault logs
* from.
* @param logFile The log file to write to.
* @return The power rail fault logs as a string.
*/
void max34451PowerRailParser(const Max34451Logger& logger,
const std::vector<uint8_t>& faultLog,
std::ostream& logFile);
/**
* @brief Set the MFR channel configuration.
*
* @param logger The Max34451Logger object to set the MFR channel
* configuration in.
* @param value The value to set as the MFR channel configuration.
*/
void setMfrNvLogConfig(const Max34451Logger& logger, uint8_t enableBit);
/**
* @brief Force the Max34451 to log.
*
* @param logger The Max34451Logger object to force the Max34451 to log.
*/
void forceMax34451Log(const Max34451Logger& logger);
/**
* @brief Clear the Max34451 log.
*
* @param logger The Max34451Logger object to clear the Max34451 log.
*/
void clearMax34451BB(const Max34451Logger& logger);
/**
* @brief Get the word at the specified indices and log it.
*
* @param logFile The log file to write to.
* @param data The vector of uint8_t to retrieve the word from.
* @param highIndex The index of the high byte.
* @param lowIndex The index of the low byte.
* @param label The label to write before the word.
* @return The word at the specified indices.
*/
uint16_t getWordAndLog(std::ostream& logFile, const std::vector<uint8_t>& data,
uint8_t highIndex, uint8_t lowIndex,
const std::string& label);
/**
* @brief Check if the power rail has a fault.
*
* @param data The data to check.
* @param includeWarnings True if warnings should be included, false otherwise.
* @return True if the power rail has a fault, false otherwise.
*/
inline bool checkPowerRailFault(const uint8_t data, const bool includeWarnings)
{
return includeWarnings
? static_cast<int>(data & (kVoutUvWarn | kVoutUvFault)) != 0
: static_cast<int>(data & kVoutUvFault) != 0;
}
} // namespace max34451