Skip to content

Commit

Permalink
Merge pull request #30 from lsst-ts/tickets/DM-40800
Browse files Browse the repository at this point in the history
Use IRQ to signal end of read
  • Loading branch information
pkubanek authored Sep 22, 2023
2 parents 68d4bf8 + e4cb804 commit 812d751
Show file tree
Hide file tree
Showing 27 changed files with 62,785 additions and 67,152 deletions.
129,383 changes: 62,465 additions & 66,918 deletions Bitfiles/NiFpga_ts_M1M3ThermalFPGA.lvbitx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lsstts/develop-env:c0028.004 as crio-develop
FROM lsstts/develop-env:develop as crio-develop

ARG XML_BRANCH=develop

Expand All @@ -11,7 +11,7 @@ ARG XML_BRANCH=main
WORKDIR /home/saluser

RUN source ~/.setup.sh \
&& mamba install -y readline yaml-cpp boost-cpp catch2 spdlog \
&& mamba install -y readline yaml-cpp catch2 spdlog \
&& echo > .crio_setup.sh -e \
echo "Configuring cRIO development environment" \\n\
export SHELL=bash \\n\
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ properties(
node {
def SALUSER_HOME = "/home/saluser"
def BRANCH = (env.CHANGE_BRANCH != null) ? env.CHANGE_BRANCH : env.BRANCH_NAME
def SAME_CRIO_BRANCH = ["main", "tickets/DM-40574"]
def SAME_CRIO_BRANCH = ["main", "tickets/DM-40800"]

stage('Cloning sources')
{
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ src/libM1M3TS.a: FORCE

ts-M1M3thermald: src/ts-M1M3thermald.cpp.o src/libM1M3TS.a
@echo '[LD ] $@'
${co}$(CPP) $(LIBS_FLAGS) -o $@ $^ $(LIBS) $(SAL_LIBS) ../ts_cRIOcpp/lib/libcRIOcpp.a
${co}$(CPP) $(LIBS_FLAGS) -o $@ $^ $(LIBS) $(SAL_LIBS) ../ts_cRIOcpp/lib/libcRIOcpp.a $(shell pkg-config --libs readline $(silence))


m1m3tscli: src/m1m3tscli.cpp.o src/libM1M3TS.a
@echo '[LD ] $@'
${co}$(CPP) $(LIBS_FLAGS) -o $@ $^ $(LIBS) ../ts_cRIOcpp/lib/libcRIOcpp.a -lreadline
${co}$(CPP) $(LIBS_FLAGS) -o $@ $^ $(LIBS) ../ts_cRIOcpp/lib/libcRIOcpp.a $(shell pkg-config --libs readline $(silence))

# Other Targets
clean:
Expand Down
1 change: 0 additions & 1 deletion Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ else
CPP := g++ -std=c++14 -Wall -fmessage-length=0 ${c_opts} -ldl -lpthread
endif

BOOST_CPPFLAGS += -I/usr/include/boost169
PKG_CPPFLAGS := $(shell pkg-config yaml-cpp --cflags $(silence)) $(shell pkg-config spdlog --cflags $(silence))

SAL_CPPFLAGS += $(PKG_CPPFLAGS) -I${OSPL_HOME}/include -I${OSPL_HOME}/include/sys -I${OSPL_HOME}/include/dcps/C++/SACPP -I${SAL_WORK_DIR}/MTM1M3TS/cpp/src -I${SAL_WORK_DIR}/include -I${SAL_HOME}/include -I${LSST_SDK_INSTALL}/include
Expand Down
15 changes: 0 additions & 15 deletions doc/version-history.rst

This file was deleted.

3 changes: 2 additions & 1 deletion src/LSST/M1M3/TS/Commands/SAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ void changeAllILCsMode(uint16_t mode) {
}

bool SAL_start::validate() {
// TODO needs new, single file config
if (params.configurationOverride.empty()) {
return false;
params.configurationOverride = "Default";
}
return true;
}
Expand Down
12 changes: 5 additions & 7 deletions src/LSST/M1M3/TS/Commands/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include "Events/Heartbeat.h"
#include "Events/SummaryState.h"

#include "Telemetry/FlowMeter.h"
#include "Telemetry/VFD.h"
#include "Telemetry/VFDSAL.h"
#include "Telemetry/GlycolLoopTemperature.h"
#include "Telemetry/MixingValve.h"
#include "Telemetry/ThermalData.h"
Expand Down Expand Up @@ -98,19 +97,18 @@ void Update::_sendFCU() {

void Update::_sendFlowMeter() {
try {
Telemetry::FlowMeter::instance().update();
Telemetry::FlowMeter::instance().send();
IFPGA::get().flowMeter->runLoop(IFPGA::get());
} catch (std::exception &e) {
SPDLOG_WARN("Cannot poll Flow Meter: {}", e.what());
IFPGA::get().flowMeter->clearCommanded();
}
}

void Update::_sendVFD() {
try {
Telemetry::VFD::instance().update();
Telemetry::VFD::instance().send();
Events::GlycolPumpStatus::instance().update();
IFPGA::get().vfd->runLoop(IFPGA::get());
} catch (std::exception &e) {
SPDLOG_WARN("Cannot poll VFD: {}", e.what());
IFPGA::get().vfd->clearCommanded();
}
}
6 changes: 3 additions & 3 deletions src/LSST/M1M3/TS/Events/GlycolPumpStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ GlycolPumpStatus::GlycolPumpStatus(token) {
_last_errorCode = 0xFFFF;
}

void GlycolPumpStatus::update() {
auto status = IFPGA::get().vfd->getStatus();
auto errorCode = IFPGA::get().vfd->getDriveErrorCodes();
void GlycolPumpStatus::update(VFD& vfd) {
auto status = vfd.getStatus();
auto errorCode = vfd.getDriveErrorCodes();
if (status != _last_status || errorCode != _last_errorCode) {
// bits are from VFD manual
ready = status & 0x0001;
Expand Down
4 changes: 3 additions & 1 deletion src/LSST/M1M3/TS/Events/GlycolPumpStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <SAL_MTM1M3TS.h>
#include <cRIO/Singleton.h>

#include <MPU/VFD.h>

namespace LSST {
namespace M1M3 {
namespace TS {
Expand All @@ -35,7 +37,7 @@ class GlycolPumpStatus final : MTM1M3TS_logevent_glycolPumpStatusC, public cRIO:
public:
GlycolPumpStatus(token);

void update();
void update(VFD& vfd);

private:
uint16_t _last_status;
Expand Down
25 changes: 21 additions & 4 deletions src/LSST/M1M3/TS/IFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
#include <ThermalFPGA.h>
#endif

#include <MPU/FlowMeter.h>
#include <MPU/VFD.h>

using namespace std::chrono_literals;
using namespace LSST::M1M3::TS;

IFPGA::IFPGA() : cRIO::FPGA(cRIO::fpgaType::TS) {
vfd = std::make_shared<VFD>(1, 100);
flowMeter = std::make_shared<FlowMeter>(2, 1);
}
IFPGA::IFPGA() : cRIO::FPGA(cRIO::fpgaType::TS) {}

IFPGA& IFPGA::get() {
#ifdef SIMULATOR
Expand All @@ -47,6 +48,14 @@ IFPGA& IFPGA::get() {
#endif
}

void IFPGA::setMPUs(std::shared_ptr<VFD> _vfd, std::shared_ptr<FlowMeter> _flowMeter) {
vfd = _vfd;
vfd->setLoopTimeOut(1000ms);

flowMeter = _flowMeter;
flowMeter->setLoopTimeOut(2000ms);
}

float IFPGA::getMixingValvePosition() {
uint16_t buf = FPGAAddress::MIXING_VALVE_POSITION;
writeRequestFIFO(&buf, 1, 1);
Expand Down Expand Up @@ -108,3 +117,11 @@ void IFPGA::setHeartbeat(bool heartbeat) {
buf[1] = heartbeat;
writeCommandFIFO(buf, 2, 0);
}

void IFPGA::processMPUResponse(LSST::cRIO::MPU& mpu, uint8_t* data, uint16_t len) {
uint16_t u16_data[len];
for (int i = 0; i < len; i++) {
u16_data[i] = data[i];
}
mpu.processResponse(u16_data, len);
}
4 changes: 3 additions & 1 deletion src/LSST/M1M3/TS/IFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class IFPGA : public cRIO::FPGA {
IFPGA();
virtual ~IFPGA() {}

void setMPUs(std::shared_ptr<VFD> vfd, std::shared_ptr<FlowMeter> flowMeter);

static IFPGA& get();

virtual void readSGLResponseFIFO(float* data, size_t length, uint32_t timeout) = 0;
Expand Down Expand Up @@ -91,7 +93,7 @@ class IFPGA : public cRIO::FPGA {
std::shared_ptr<FlowMeter> flowMeter;

protected:
virtual void processMPUResponse(LSST::cRIO::MPU& mpu, uint8_t* data, uint16_t len) {}
virtual void processMPUResponse(LSST::cRIO::MPU& mpu, uint8_t* data, uint16_t len);
};

} // namespace TS
Expand Down
22 changes: 20 additions & 2 deletions src/LSST/M1M3/TS/MPU/FlowMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <endian.h>
#include <iomanip>
#include <iostream>

#include <spdlog/spdlog.h>

#include <MPU/FlowMeter.h>

using namespace LSST::M1M3::TS;

void FlowMeter::poll() {
void FlowMeter::loopWrite() {
SPDLOG_TRACE("Requesting FlowMeter registers");
readHoldingRegisters(1000, 4, 255);
readHoldingRegisters(2500, 6, 255);
readHoldingRegisters(5500, 1, 255);
Expand All @@ -53,3 +57,17 @@ double FlowMeter::_getDoubleValue(uint16_t reg) {
}
return buffer.ddouble;
}

void FlowMeterPrint::loopRead(bool timedout) {
if (timedout) {
std::cout << "FlowMeter readout timedouted." << std::endl;
return;
}

std::cout << std::setfill(' ') << std::fixed << "Signal Strength: " << getSignalStrength() << std::endl
<< std::setw(20) << "Flow Rate: " << getFlowRate() << std::endl
<< std::setw(20) << "Net Totalizer: " << getNetTotalizer() << std::endl
<< std::setw(20) << "Positive Totalizer: " << getPositiveTotalizer() << std::endl
<< std::setw(20) << "Negative Totalizer: " << getNegativeTotalizer() << std::endl
<< std::endl;
}
9 changes: 8 additions & 1 deletion src/LSST/M1M3/TS/MPU/FlowMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FlowMeter : public cRIO::MPU {
public:
FlowMeter(uint8_t bus, uint8_t mpu_address) : MPU(bus, mpu_address) {}

void poll();
void loopWrite() override;

uint16_t getSignalStrength() { return getRegister(5500); }
double getFlowRate() { return _getFloatValue(1000); }
Expand All @@ -49,6 +49,13 @@ class FlowMeter : public cRIO::MPU {
double _getDoubleValue(uint16_t reg);
};

class FlowMeterPrint : public FlowMeter {
public:
FlowMeterPrint(uint8_t bus, uint8_t mpu_address) : FlowMeter(bus, mpu_address) {}

void loopRead(bool timedout) override;
};

} // namespace TS
} // namespace M1M3
} // namespace LSST
Expand Down
57 changes: 56 additions & 1 deletion src/LSST/M1M3/TS/MPU/VFD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <iomanip>
#include <iostream>

#include <spdlog/spdlog.h>

#include <MPU/VFD.h>

using namespace LSST::M1M3::TS;

void VFD::poll() {
void VFD::loopWrite() {
readHoldingRegisters(0x2000, 3, 255);
readHoldingRegisters(0x2100, 7, 255);
}
Expand All @@ -43,3 +48,53 @@ const char *VFD::getDriveError(uint16_t code) {
return "Unknown error";
}
}

void VFDPrint::loopRead(bool timedout) {
SPDLOG_TRACE("Requesting glycol pump VFD registers");
if (timedout) {
std::cout << "VFD readout timed-out." << std::endl;
return;
}

// status bits
static const std::string status[16] = {"Ready",
"Active (Running)",
"Cmd Forward",
"Rotating Forward",
"Accelerating",
"Decelerating",
"",
"Faulted",
"At Reference",
"Main Freq Controlled by Active Comm",
"Operation Cmd Controlled by Active Comm",
"Parameters have been locked",
"Digital input 1 Status (DigIn TermBlk 05)"
"Digital input 2 Status (DigIn TermBlk 06)"
"Digital input 3 Status (DigIn TermBlk 07)"
"Digital input 4 Status (DigIn TermBlk 08)"};

uint16_t bits = getVelocityPositionBits();

std::cout << std::setfill(' ') << std::setw(20) << "Status: "
<< "0x" << std::hex << getStatus() << std::endl
<< std::setw(20) << "Commanded Freq.: " << std::fixed << std::setprecision(2)
<< getCommandedFrequency() << std::endl
<< std::setw(20) << "Vel./Pos. Bits: " << std::hex << bits << std::dec << std::endl;

for (int i = 0; i < 16; i++) {
if (bits & 0x01)
std::cout << " " << (bits == 0x01 ? "" : "") << "━━▶ " << status[i] << std::endl;
bits >>= 1;
}

std::cout << std::setw(20) << "Drive Error Codes: " << getDriveErrorCodes() << std::endl
<< std::setw(20) << "Target Frequency: " << std::fixed << std::setprecision(2)
<< getTargetFrequency() << std::endl
<< std::setw(20) << "Output Frequency: " << getOutputFrequency() << std::endl
<< std::setw(20) << "Output Current: " << getOutputCurrent() << std::endl
<< std::setw(20) << "DC Bus Voltage: " << std::dec << getDCBusVoltage() << std::endl
<< std::setw(20) << "Output Voltage: " << std::fixed << std::setprecision(1)
<< getOutputVoltage() << std::endl
<< std::endl;
}
9 changes: 8 additions & 1 deletion src/LSST/M1M3/TS/MPU/VFD.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class VFD : public cRIO::MPU {
public:
VFD(uint8_t bus, uint8_t mpu_address) : MPU(bus, mpu_address) {}

void poll();
void loopWrite() override;

uint16_t getStatus() { return getRegister(0x2000); }
float getCommandedFrequency() { return getRegister(0x2001) / 100.0f; }
Expand Down Expand Up @@ -70,6 +70,13 @@ class VFD : public cRIO::MPU {
static const char* getDriveError(uint16_t code);
};

class VFDPrint : public VFD {
public:
VFDPrint(uint8_t bus, uint8_t mpu_address) : VFD(bus, mpu_address) {}

void loopRead(bool timedout) override;
};

} // namespace TS
} // namespace M1M3
} // namespace LSST
Expand Down
Loading

0 comments on commit 812d751

Please sign in to comment.