Report FPGA temperature

This commit is contained in:
Joris van Rantwijk 2024-09-30 20:52:35 +02:00
parent ddbeb20633
commit 3eecc2cd6c
1 changed files with 45 additions and 0 deletions

View File

@ -403,6 +403,40 @@ bool run_calibration_script()
} }
/* ******** Temperature ******** */
/** Read FPGA temperature. */
bool read_fpga_temperature(double& temp)
{
const std::string xadc_dir =
"/sys/devices/soc0/axi/f8007100.adc/iio:device0";
std::ifstream is(xadc_dir + "/in_temp0_raw");
double temp_raw;
is >> temp_raw;
if (!is) {
return false;
}
is = std::ifstream(xadc_dir + "/in_temp0_offset");
double temp_offset;
is >> temp_offset;
if (!is) {
return false;
}
is = std::ifstream(xadc_dir + "/in_temp0_scale");
double temp_scale;
is >> temp_scale;
if (!is) {
return false;
}
temp = (temp_raw + temp_offset) * temp_scale / 1000.0;
return true;
}
/* ******** class CommandHandler ******** */ /* ******** class CommandHandler ******** */
// Forward declaration. // Forward declaration.
@ -902,6 +936,16 @@ private:
return "ERROR Unconfigured"; return "ERROR Unconfigured";
} }
/** Handle command TEMP:FPGA? */
std::string qry_temp_fpga(CommandEnvironment env)
{
double temp;
if (! read_fpga_temperature(temp)) {
return "ERROR Reading temperature failed";
}
return str_format("%.1f", temp);
}
/** Handle command RESET */ /** Handle command RESET */
std::string cmd_reset(CommandEnvironment env) std::string cmd_reset(CommandEnvironment env)
{ {
@ -1331,6 +1375,7 @@ private:
{ "tt:event:mask?", &CommandHandler::qry_tt_event_mask }, { "tt:event:mask?", &CommandHandler::qry_tt_event_mask },
{ "ipcfg?", &CommandHandler::qry_ipcfg }, { "ipcfg?", &CommandHandler::qry_ipcfg },
{ "ipcfg:saved?", &CommandHandler::qry_ipcfg }, { "ipcfg:saved?", &CommandHandler::qry_ipcfg },
{ "temp:fpga?", &CommandHandler::qry_temp_fpga },
{ "reset", &CommandHandler::cmd_reset }, { "reset", &CommandHandler::cmd_reset },
{ "halt", &CommandHandler::cmd_halt }, { "halt", &CommandHandler::cmd_halt },
{ "reboot", &CommandHandler::cmd_reboot }, { "reboot", &CommandHandler::cmd_reboot },