Skip to content

Commit

Permalink
Back to telemetry on FIFOs
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Sep 19, 2024
1 parent 4e8b313 commit 83b988f
Show file tree
Hide file tree
Showing 8 changed files with 60,288 additions and 65,473 deletions.
125,622 changes: 60,205 additions & 65,417 deletions Bitfiles/NiFpga_ts_M1M3ThermalFPGA.lvbitx

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/LSST/M1M3/TS/MPU/FlowMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ using namespace LSST::M1M3::TS;

void FlowMeter::readInfo() {
clear();
readHoldingRegisters(1000, 4, 255);
readHoldingRegisters(2500, 6, 255);
readHoldingRegisters(1600, 4, 255);
readHoldingRegisters(2600, 12, 255);
readHoldingRegisters(5500, 1, 255);
}

Expand All @@ -53,7 +53,7 @@ double FlowMeter::_getDoubleValue(uint16_t reg) {
} buffer;

for (int i = 0; i < 4; i++) {
buffer.data[i] = getRegister(reg + 4 - i);
buffer.data[i] = getRegister(reg + 3 - i);
}
return buffer.ddouble;
}
Expand Down
8 changes: 4 additions & 4 deletions src/LSST/M1M3/TS/MPU/FlowMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class FlowMeter : public cRIO::MPU {
void readInfo();

uint16_t getSignalStrength() { return getRegister(5500); }
double getFlowRate() { return _getFloatValue(1000); }
double getNetTotalizer() { return _getFloatValue(2500); }
double getPositiveTotalizer() { return _getFloatValue(2502); }
double getNegativeTotalizer() { return _getFloatValue(2504); }
double getFlowRate() { return _getFloatValue(1600); }
double getNetTotalizer() { return _getDoubleValue(2600); }
double getPositiveTotalizer() { return _getDoubleValue(2604); }
double getNegativeTotalizer() { return _getDoubleValue(2608); }

private:
float _getFloatValue(uint16_t reg);
Expand Down
4 changes: 2 additions & 2 deletions src/LSST/M1M3/TS/MPU/VFD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void VFDPrint::print() {

uint16_t bits = getVelocityPositionBits();

std::cout << std::setfill(' ') << std::setw(20) << "Status: "
<< "0x" << std::hex << getStatus() << std::endl
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;
Expand Down
9 changes: 9 additions & 0 deletions src/LSST/M1M3/TS/SimulatedFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ std::vector<uint8_t> SimulatedFPGA::readMPUFIFO(cRIO::MPU &mpu) {
return ret;
}

MPUTelemetry SimulatedFPGA::readMPUTelemetry(LSST::cRIO::MPU &mpu) {
static uint64_t data[2] = {0, 0};

data[0] += 2;
data[1] += 3;

return MPUTelemetry(reinterpret_cast<uint8_t *>(data));
}

void SimulatedFPGA::writeCommandFIFO(uint16_t *data, size_t length, uint32_t timeout) {
uint16_t *d = data;
while (d < data + length) {
Expand Down
2 changes: 1 addition & 1 deletion src/LSST/M1M3/TS/SimulatedFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SimulatedFPGA : public IFPGA, public LSST::cRIO::ThermalILC {
void finalize() override {}
void writeMPUFIFO(cRIO::MPU &mpu, const std::vector<uint8_t> &data, uint32_t timeout) override;
std::vector<uint8_t> readMPUFIFO(cRIO::MPU &mpu) override;
LSST::cRIO::MPUTelemetry readMPUTelemetry(LSST::cRIO::MPU &mpu) override{};
LSST::cRIO::MPUTelemetry readMPUTelemetry(LSST::cRIO::MPU &mpu) override;
void writeCommandFIFO(uint16_t *data, size_t length, uint32_t timeout) override;
void writeRequestFIFO(uint16_t *data, size_t length, uint32_t timeout) override;
void readSGLResponseFIFO(float *data, size_t length, uint32_t timeout) override;
Expand Down
96 changes: 63 additions & 33 deletions src/LSST/M1M3/TS/ThermalFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,75 +84,105 @@ void ThermalFPGA::writeMPUFIFO(MPU &mpu, const std::vector<uint8_t> &data, uint3
throw std::runtime_error(fmt::format("Invalid bus number - {}", mpu.getBus()));
}

uint8_t header[2] = {1, static_cast<uint8_t>(data.size())};
NiThrowError(__PRETTY_FUNCTION__, NiFpga_WriteFifoU8(_session, bus_id, header, 2, timeout, NULL));

NiThrowError(__PRETTY_FUNCTION__,
NiFpga_WriteFifoU8(_session, bus_id, data.data(), data.size(), timeout, NULL));
}

std::vector<uint8_t> ThermalFPGA::readMPUFIFO(MPU &mpu) {
uint32_t instr_bus = 0;
uint32_t bus_id = 0;
switch (mpu.getBus()) {
case SerialBusses::GLYCOOL_BUS:
instr_bus = NiFpga_ts_M1M3ThermalFPGA_HostToTargetFifoU8_GlycoolWrite;
bus_id = NiFpga_ts_M1M3ThermalFPGA_TargetToHostFifoU8_GlycoolRead;
break;
case SerialBusses::FLOWMETER_BUS:
instr_bus = NiFpga_ts_M1M3ThermalFPGA_HostToTargetFifoU8_FlowMeterWrite;
bus_id = NiFpga_ts_M1M3ThermalFPGA_TargetToHostFifoU8_FlowMeterRead;
break;
default:
throw std::runtime_error(fmt::format("Invalid bus number - {}", mpu.getBus()));
}

size_t len = 255;

uint8_t data[255];
size_t len = 0;

int remaining_time = 2000;

// bussy wait for data
while (remaining_time > 0) {
uint8_t req = 2;
uint8_t response[2];

NiThrowError("ThermalFPGA::readMPUFIFO: requesting response",
NiFpga_WriteFifoU8(_session, instr_bus, &req, 1, 0, NULL));

NiThrowError("ThermalFPGA::readMPUFIFO: reading response and its length",
NiFpga_ReadFifoU8(_session, bus_id, response, 2, 10, NULL));

NiThrowError(__PRETTY_FUNCTION__, NiFpga_ReadFifoU8(_session, bus_id, data, 0, 0, &len));
if (response[0] != 2) {
throw std::runtime_error(fmt::format("Invalid reply from bus - {}, expected 2", response[0]));
}
if (response[1] == 0) {
// if there isn't reply and some data were received, process those - don't read further
if (len > 0) {
break;
}
continue;
}

NiThrowError(__PRETTY_FUNCTION__, NiFpga_ReadFifoU8(_session, bus_id, data, len, -1, NULL));
NiThrowError("ThermalFPGA::readMPUFIFO: reading response",
NiFpga_ReadFifoU8(_session, bus_id, data + len, response[1], 10, NULL));

writeDebugFile<uint8_t>("MPU>", data, len);
len += response[1];

writeDebugFile<uint8_t>("MPU>", data, len);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
remaining_time -= 1000;
}

std::vector<uint8_t> ret(data, data + len);

return ret;
}

LSST::cRIO::MPUTelemetry ThermalFPGA::readMPUTelemetry(LSST::cRIO::MPU &mpu) {
MPUTelemetry telemetry;

int32_t readCount;
int32_t transmitCount;
NiFpga_Bool timeout;

uint32_t instr_bus = 0;
uint32_t bus_id = 0;
switch (mpu.getBus()) {
case SerialBusses::GLYCOOL_BUS:
NiThrowError(
__PRETTY_FUNCTION__,
NiFpga_ReadI32(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_GlycoolRead, &readCount));
NiThrowError(__PRETTY_FUNCTION__,
NiFpga_ReadI32(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_GlycoolTransmitted,
&transmitCount));
NiThrowError(__PRETTY_FUNCTION__,
NiFpga_ReadBool(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorBool_GlycoolTimeout,
&timeout));
instr_bus = NiFpga_ts_M1M3ThermalFPGA_HostToTargetFifoU8_GlycoolWrite;
bus_id = NiFpga_ts_M1M3ThermalFPGA_TargetToHostFifoU8_GlycoolRead;
break;
case SerialBusses::FLOWMETER_BUS:
NiThrowError(__PRETTY_FUNCTION__,
NiFpga_ReadI32(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_FlowMeterRead,
&readCount));
NiThrowError(__PRETTY_FUNCTION__,
NiFpga_ReadI32(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_FlowMeterTransmitted,
&transmitCount));
NiThrowError(__PRETTY_FUNCTION__,
NiFpga_ReadBool(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorBool_FlowMeterTimeout,
&timeout));
instr_bus = NiFpga_ts_M1M3ThermalFPGA_HostToTargetFifoU8_FlowMeterWrite;
bus_id = NiFpga_ts_M1M3ThermalFPGA_TargetToHostFifoU8_FlowMeterRead;
break;
default:
throw std::runtime_error(fmt::format("Invalid bus number - {}", mpu.getBus()));
}

uint8_t data[255];

data[0] = 0;

NiThrowError(__PRETTY_FUNCTION__, NiFpga_WriteFifoU8(_session, instr_bus, data, 1, 0, NULL));

NiThrowError(__PRETTY_FUNCTION__, NiFpga_ReadFifoU8(_session, bus_id, data, 1, 200, NULL));

if (data[0] != 0) {
throw std::runtime_error(fmt::format("Invalid reply from bus - {}, expected 0", data[0]));
}

telemetry.readBytes = readCount;
telemetry.writeBytes = transmitCount;
telemetry.readTimedout = timeout;
std::cout << "Getting reply:" << std::endl;

NiThrowError(__PRETTY_FUNCTION__, NiFpga_ReadFifoU8(_session, bus_id, data, 16, 0, NULL));

return telemetry;
return MPUTelemetry(data);
}

void ThermalFPGA::writeCommandFIFO(uint16_t *data, size_t length, uint32_t timeout) {
Expand Down
14 changes: 1 addition & 13 deletions src/NiFpga/NiFpga_ts_M1M3ThermalFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,12 @@
/**
* The signature of the FPGA bitfile.
*/
static const char* const NiFpga_ts_M1M3ThermalFPGA_Signature = "E512D0EBAF61A28351D1B42190EDA7BA";
static const char* const NiFpga_ts_M1M3ThermalFPGA_Signature = "ED0F19AAFA7D700679F77FE9F50B1FFE";

#if NiFpga_Cpp
extern "C" {
#endif

typedef enum {
NiFpga_ts_M1M3ThermalFPGA_IndicatorBool_FlowMeterTimeout = 0x1801A,
NiFpga_ts_M1M3ThermalFPGA_IndicatorBool_GlycoolTimeout = 0x1800E
} NiFpga_ts_M1M3ThermalFPGA_IndicatorBool;

typedef enum {
NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_FlowMeterRead = 0x18014,
NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_FlowMeterTransmitted = 0x18010,
NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_GlycoolRead = 0x18008,
NiFpga_ts_M1M3ThermalFPGA_IndicatorI32_GlycoolTransmitted = 0x18004
} NiFpga_ts_M1M3ThermalFPGA_IndicatorI32;

typedef enum {
NiFpga_ts_M1M3ThermalFPGA_TargetToHostFifoU8_FlowMeterRead = 8,
NiFpga_ts_M1M3ThermalFPGA_TargetToHostFifoU8_GlycoolRead = 6,
Expand Down

0 comments on commit 83b988f

Please sign in to comment.