core housekeeping

This commit is contained in:
Jakob Meier 2022-03-13 16:32:40 +01:00
parent c3115fc974
commit d99825e20e
11 changed files with 418 additions and 8 deletions

View File

@ -23,3 +23,4 @@ add_subdirectory(core)
add_subdirectory(memory)
add_subdirectory(callbacks)
add_subdirectory(devices)
add_subdirectory(xadc)

View File

@ -2,6 +2,7 @@
#include <bsp_q7s/core/CoreController.h>
#include <bsp_q7s/memory/FileSystemHandler.h>
#include <bsp_q7s/xadc/Xadc.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <gps.h>
#include <libgpsmm.h>
@ -23,6 +24,7 @@ Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) {
doTestSdCard = false;
doTestScratchApi = false;
doTestGps = false;
doTestXadc = true;
}
ReturnValue_t Q7STestTask::performOneShotAction() {
@ -44,6 +46,9 @@ ReturnValue_t Q7STestTask::performPeriodicAction() {
if (doTestGps) {
testGpsDaemon();
}
if (doTestXadc) {
xadcTest();
}
return TestTask::performPeriodicAction();
}
@ -395,3 +400,53 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
}
}
}
void Q7STestTask::xadcTest() {
ReturnValue_t result = RETURN_OK;
float temperature = 0;
float vccPint = 0;
float vccPaux = 0;
float vccInt = 0;
float vccAux = 0;
float vccBram = 0;
float vccOddr = 0;
float vrefp = 0;
float vrefn = 0;
Xadc xadc;
result = xadc.getTemperature(temperature);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: Chip Temperature: " << temperature << " °C" << std::endl;
}
result = xadc.getVccPint(vccPint);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: VCC PS internal: " << vccPint << " mV" << std::endl;
}
result = xadc.getVccPaux(vccPaux);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: VCC PS auxilliary: " << vccPaux << " mV" << std::endl;
}
result = xadc.getVccInt(vccInt);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: VCC PL internal: " << vccInt << " mV" << std::endl;
}
result = xadc.getVccAux(vccAux);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: VCC PL auxilliary: " << vccAux << " mV" << std::endl;
}
result = xadc.getVccBram(vccBram);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: VCC BRAM: " << vccBram << " mV" << std::endl;
}
result = xadc.getVccOddr(vccOddr);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: VCC PS I/O DDR : " << vccOddr << " mV" << std::endl;
}
result = xadc.getVrefp(vrefp);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: Vrefp : " << vrefp << " mV" << std::endl;
}
result = xadc.getVrefn(vrefn);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Q7STestTask::xadcTest: Vrefn : " << vrefn << " mV" << std::endl;
}
}

View File

@ -15,6 +15,7 @@ class Q7STestTask : public TestTask {
bool doTestSdCard = false;
bool doTestScratchApi = false;
bool doTestGps = false;
bool doTestXadc = false;
CoreController* coreController = nullptr;
ReturnValue_t performOneShotAction() override;
@ -24,6 +25,7 @@ class Q7STestTask : public TestTask {
void testSdCard();
void fileTests();
void xadcTest();
void testScratchApi();
void testJsonLibDirect();

View File

@ -13,7 +13,6 @@
#else
#include "fsfw/osal/common/TcpTmTcServer.h"
#endif
#include <fcntl.h>
#include <unistd.h>
@ -21,12 +20,13 @@
#include "bsp_q7s/memory/SdCardManager.h"
#include "bsp_q7s/memory/scratchApi.h"
#include "bsp_q7s/xadc/Xadc.h"
xsc::Chip CoreController::CURRENT_CHIP = xsc::Chip::NO_CHIP;
xsc::Copy CoreController::CURRENT_COPY = xsc::Copy::NO_COPY;
CoreController::CoreController(object_id_t objectId)
: ExtendedControllerBase(objectId, objects::NO_OBJECT, 5), opDivider(5) {
: ExtendedControllerBase(objectId, objects::NO_OBJECT, 5), opDivider(5), hkSet(this) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
try {
result = initWatchdogFifo();
@ -60,14 +60,23 @@ void CoreController::performControlOperation() {
performWatchdogControlOperation();
sdStateMachine();
performMountedSdCardOperations();
readHkData();
}
ReturnValue_t CoreController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(core::TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(core::PS_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(core::PL_VOLTAGE, new PoolEntry<float>({0}));
return HasReturnvaluesIF::RETURN_OK;
}
LocalPoolDataSetBase *CoreController::getDataSetHandle(sid_t sid) { return nullptr; }
LocalPoolDataSetBase *CoreController::getDataSetHandle(sid_t sid) {
if (sid.ownerSetId == core::HK_SET_ID) {
return &hkSet;
}
return nullptr;
}
ReturnValue_t CoreController::initialize() {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
@ -1645,3 +1654,37 @@ void CoreController::setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::C
}
rewriteRebootFile(rebootFile);
}
void CoreController::readHkData() {
ReturnValue_t result = RETURN_OK;
result = hkSet.read(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return;
}
Xadc xadc;
result = xadc.getTemperature(hkSet.temperature.value);
if (result != RETURN_OK) {
hkSet.temperature.setValid(false);
} else {
hkSet.temperature.setValid(true);
}
result = xadc.getVccPint(hkSet.psVoltage.value);
if (result != RETURN_OK) {
hkSet.psVoltage.setValid(false);
} else {
hkSet.psVoltage.setValid(true);
}
result = xadc.getVccInt(hkSet.plVoltage.value);
if (result != RETURN_OK) {
hkSet.plVoltage.setValid(false);
} else {
hkSet.plVoltage.setValid(true);
}
#if OBSW_PRINT_CORE_HK == 1
hkSet.printSet();
#endif /* OBSW_PRINT_CORE_HK == 1 */
result = hkSet.commit(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return;
}
}

View File

@ -9,6 +9,7 @@
#include "bsp_q7s/memory/SdCardManager.h"
#include "events/subsystemIdRanges.h"
#include "fsfw/controller/ExtendedControllerBase.h"
#include "CoreDefinitions.h"
class Timer;
class SdCardManager;
@ -120,6 +121,8 @@ class CoreController : public ExtendedControllerBase {
bool sdInitFinished() const;
private:
static constexpr MutexIF::TimeoutType TIMEOUT_TYPE = MutexIF::TimeoutType::WAITING;
static constexpr uint32_t MUTEX_TIMEOUT = 20;
// Designated value for rechecking FIFO open
static constexpr int RETRY_FIFO_OPEN = -2;
int watchdogFifoFd = 0;
@ -181,6 +184,8 @@ class CoreController : public ExtendedControllerBase {
std::array<bool, 4> protArray;
PeriodicOperationDivider opDivider;
core::HkSet hkSet;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
@ -220,6 +225,7 @@ class CoreController : public ExtendedControllerBase {
void setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::Copy tgtCopy);
bool parseRebootFile(std::string path, RebootFile& file);
void rewriteRebootFile(RebootFile file);
void readHkData();
};
#endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */

View File

@ -0,0 +1,45 @@
#ifndef BSP_Q7S_CORE_COREDEFINITIONS_H_
#define BSP_Q7S_CORE_COREDEFINITIONS_H_
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
namespace core {
static const uint8_t HK_SET_ENTRIES = 2;
static const uint32_t HK_SET_ID = 5;
enum PoolIds {
TEMPERATURE,
PS_VOLTAGE,
PL_VOLTAGE
};
/**
* @brief Set storing OBC internal housekeeping data
*/
class HkSet : public StaticLocalDataSet<HK_SET_ENTRIES> {
public:
static const size_t SIZE = 24;
HkSet(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, HK_SET_ID) {}
HkSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, HK_SET_ID)) {}
// On-chip temperature
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, PoolIds::TEMPERATURE, this);
// Processing system VCC
lp_var_t<float> psVoltage = lp_var_t<float>(sid.objectId, PoolIds::PS_VOLTAGE, this);
// Programmable logic VCC
lp_var_t<float> plVoltage = lp_var_t<float>(sid.objectId, PoolIds::PL_VOLTAGE, this);
void printSet() {
sif::info << "HkSet::printSet: On-chip temperature: " << this->temperature
<< " °C" << std::endl;
sif::info << "HkSet::printSet: PS voltage: " << this->psVoltage << " mV" << std::endl;
sif::info << "HkSet::printSet: PL voltage: " << this->plVoltage << " mV" << std::endl;
}
};
}
#endif /* BSP_Q7S_CORE_COREDEFINITIONS_H_ */

View File

@ -0,0 +1,3 @@
target_sources(${OBSW_NAME} PRIVATE
Xadc.cpp
)

144
bsp_q7s/xadc/Xadc.cpp Normal file
View File

@ -0,0 +1,144 @@
#include "Xadc.h"
#include <fcntl.h>
#include <unistd.h>
#include <sstream>
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
Xadc::Xadc() {}
Xadc::~Xadc() {}
ReturnValue_t Xadc::getTemperature(float& temperature) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
int raw = 0;
int offset = 0;
float scale = 0;
result = readValFromFile<int>(xadc::file::tempRaw.c_str(), raw);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = readValFromFile<int>(xadc::file::tempOffset.c_str(), offset);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = readValFromFile<float>(xadc::file::tempScale.c_str(), scale);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
temperature = (raw + offset) * scale / 1000;
return result;
}
ReturnValue_t Xadc::getVccPint(float& vccPint) {
ReturnValue_t result =
readVoltageFromSysfs(xadc::file::vccpintRaw, xadc::file::vccpintScale, vccPint);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVccPaux(float& vccPaux) {
ReturnValue_t result =
readVoltageFromSysfs(xadc::file::vccpauxRaw, xadc::file::vccpauxScale, vccPaux);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVccInt(float& vccInt) {
ReturnValue_t result =
readVoltageFromSysfs(xadc::file::vccintRaw, xadc::file::vccintScale, vccInt);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVccAux(float& vccAux) {
ReturnValue_t result =
readVoltageFromSysfs(xadc::file::vccauxRaw, xadc::file::vccauxScale, vccAux);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVccBram(float& vccBram) {
ReturnValue_t result =
readVoltageFromSysfs(xadc::file::vccbramRaw, xadc::file::vccbramScale, vccBram);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVccOddr(float& vccOddr) {
ReturnValue_t result =
readVoltageFromSysfs(xadc::file::vccoddrRaw, xadc::file::vccoddrScale, vccOddr);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVrefp(float& vrefp) {
ReturnValue_t result = readVoltageFromSysfs(xadc::file::vrefpRaw, xadc::file::vrefpScale, vrefp);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::getVrefn(float& vrefn) {
ReturnValue_t result = readVoltageFromSysfs(xadc::file::vrefnRaw, xadc::file::vrefnScale, vrefn);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Xadc::readVoltageFromSysfs(std::string rawFile, std::string scaleFile,
float& voltage) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
float raw = 0;
float scale = 0;
result = readValFromFile(rawFile.c_str(), raw);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = readValFromFile(scaleFile.c_str(), scale);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
voltage = calculateVoltage(raw, scale);
return result;
}
float Xadc::calculateVoltage(int raw, float scale) { return static_cast<float>(raw * scale); }
template <typename T>
ReturnValue_t Xadc::readValFromFile(const char* filename, T& val) {
FILE* fp;
fp = fopen(filename, "r");
if (fp == nullptr) {
sif::warning << "Xadc::readValFromFile: Failed to open file " << filename << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
char valstring[MAX_STR_LENGTH] = "";
char* returnVal = fgets(valstring, MAX_STR_LENGTH, fp);
if (returnVal == nullptr) {
sif::warning << "Xadc::readValFromFile: Failed to read string from file " << filename
<< std::endl;
fclose(fp);
return HasReturnvaluesIF::RETURN_FAILED;
}
std::istringstream valSstream(valstring);
valSstream >> val;
fclose(fp);
return HasReturnvaluesIF::RETURN_OK;
}

107
bsp_q7s/xadc/Xadc.h Normal file
View File

@ -0,0 +1,107 @@
#ifndef BSP_Q7S_XADC_XADC_H_
#define BSP_Q7S_XADC_XADC_H_
#include <string>
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
namespace xadc {
using namespace std;
static const string iioPath = "/sys/bus/iio/devices/iio:device1";
namespace file {
static const string tempOffset = iioPath + "/in_temp0_offset";
static const string tempRaw = iioPath + "/in_temp0_raw";
static const string tempScale = iioPath + "/in_temp0_scale";
static const string vccintRaw = iioPath + "/in_voltage0_vccint_raw";
static const string vccintScale = iioPath + "/in_voltage0_vccint_scale";
static const string vccauxRaw = iioPath + "/in_voltage1_vccaux_raw";
static const string vccauxScale = iioPath + "/in_voltage1_vccaux_scale";
static const string vccbramRaw = iioPath + "/in_voltage2_vccbram_raw";
static const string vccbramScale = iioPath + "/in_voltage2_vccbram_scale";
static const string vccpintRaw = iioPath + "/in_voltage3_vccpint_raw";
static const string vccpintScale = iioPath + "/in_voltage3_vccpint_scale";
static const string vccpauxRaw = iioPath + "/in_voltage4_vccpaux_raw";
static const string vccpauxScale = iioPath + "/in_voltage4_vccpaux_scale";
static const string vccoddrRaw = iioPath + "/in_voltage5_vccoddr_raw";
static const string vccoddrScale = iioPath + "/in_voltage5_vccoddr_scale";
static const string vrefpRaw = iioPath + "/in_voltage6_vrefp_raw";
static const string vrefpScale = iioPath + "/in_voltage6_vrefp_scale";
static const string vrefnRaw = iioPath + "/in_voltage7_vrefn_raw";
static const string vrefnScale = iioPath + "/in_voltage7_vrefn_scale";
} // namespace file
} // namespace xadc
/**
* @brief Class providing access to the data generated by the analog mixed signal module (XADC).
*
* @details Details about the XADC peripheral of the Zynq-7020 can be found in the UG480 "7-Series
* FPGAs and Zynq-7000 SoC XADC Dual 12-Bit 1 MSPS Analog-to-Digital Converter" user guide
* from Xilinx.
*
* @author J. Meier
*/
class Xadc {
public:
/**
* @brief Constructor
*/
Xadc();
virtual ~Xadc();
/**
* @brief Returns on-chip temperature degree celcius
*/
ReturnValue_t getTemperature(float& temperature);
/**
* @brief Returns PS internal logic supply voltage in millivolts
*/
ReturnValue_t getVccPint(float& vccPint);
/**
* @brief Returns PS auxiliary supply voltage in millivolts
*/
ReturnValue_t getVccPaux(float& vccPaux);
/**
* @brief Returns PL internal supply voltage in millivolts
*/
ReturnValue_t getVccInt(float& vccInt);
/**
* @brief Returns PL auxiliary supply voltage in millivolts
*/
ReturnValue_t getVccAux(float& vccAux);
/**
* @brief Returns PL block RAM supply voltage in millivolts
*/
ReturnValue_t getVccBram(float& vccBram);
/**
* @brief Returns the PS DDR I/O supply voltage
*/
ReturnValue_t getVccOddr(float& vcOddr);
/**
* @brief Returns XADC reference input voltage relative to GND in millivolts
*/
ReturnValue_t getVrefp(float& vrefp);
/**
* @brief Returns negative reference input voltage. Should normally be 0 V.
*/
ReturnValue_t getVrefn(float& vrefn);
private:
// Maximum length of the string representation of a value in a xadc sysfs file
static const uint8_t MAX_STR_LENGTH = 15;
ReturnValue_t readVoltageFromSysfs(std::string rawFile, std::string scaleFile, float& voltage);
float calculateVoltage(int raw, float scale);
template <typename T>
ReturnValue_t readValFromFile(const char* filename, T& val);
};
#endif /* BSP_Q7S_XADC_XADC_H_ */

View File

@ -24,7 +24,7 @@ debugging. */
#define OBSW_VERBOSE_LEVEL 1
//! Board defines
#define BOARD_TE0720 0
#define BOARD_TE0720 0
/*******************************************************************/
/** All of the following flags should be enabled for mission code */
@ -34,11 +34,13 @@ debugging. */
//! All of this should be enabled for mission code!
#if defined XIPHOS_Q7S
#define Q7S_EM 0
#define OBSW_USE_CCSDS_IP_CORE 1
// Set to 1 if all telemetry should be sent to the PTME IP Core
#define OBSW_TM_TO_PTME 0
#define OBSW_TM_TO_PTME 1
// Set to 1 if telecommands are received via the PDEC IP Core
#define OBSW_TC_FROM_PDEC 0
#define OBSW_TC_FROM_PDEC 1
#define OBSW_ENABLE_TIMERS 1
#define OBSW_ADD_MGT 1
@ -59,6 +61,7 @@ debugging. */
#define OBSW_SYRLINKS_SIMULATED 1
#define OBSW_STAR_TRACKER_GROUND_CONFIG 1
#define OBSW_ENABLE_PERIODIC_HK 0
#define OBSW_PRINT_CORE_HK 0
#endif

View File

@ -524,7 +524,7 @@ ReturnValue_t pst::pstUart(FixedTimeslotTaskIF *thisSequence) {
ReturnValue_t pst::pstGompaceCan(FixedTimeslotTaskIF *thisSequence) {
uint32_t length = thisSequence->getPeriodMs();
#if Q7S_EM != 1
// PCDU handlers receives two messages and both must be handled
thisSequence->addSlot(objects::PCDU_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::PCDU_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION);
@ -553,11 +553,12 @@ ReturnValue_t pst::pstGompaceCan(FixedTimeslotTaskIF *thisSequence) {
thisSequence->addSlot(objects::PDU1_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU2_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::ACU_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) {
sif::error << "GomSpace PST initialization failed" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
#endif /* Q7S_EM == 0 */
static_cast<void>(length);
return HasReturnvaluesIF::RETURN_OK;
}