Skip to content

Commit

Permalink
Merge pull request #68 from lsst-ts/tickets/DM-45837
Browse files Browse the repository at this point in the history
Simplify MPU communication
  • Loading branch information
pkubanek authored Sep 20, 2024
2 parents f2ff870 + af1dde9 commit 4d6b3fd
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 149 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ jobs:
make
make junit || true
centos:
runs-on: ubuntu-latest
name: Test compile on Centos7
container:
image: centos/devtoolset-7-toolchain-centos7
options: -u root
steps:
- name: Install dependencies
run: |
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y make catch-devel readline-devel yaml-cpp-devel git
- name: Checkout
uses: actions/checkout@v3
- name: make junit
run: |
git clone https://github.com/gabime/spdlog.git
mv spdlog/include/spdlog include/
git clone https://github.com/fmtlib/fmt
mv fmt/include/fmt include
make
make junit || true
ubuntu:
runs-on: ubuntu-latest
name: Test compile on Ubuntu
Expand Down
5 changes: 5 additions & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
Version History
###############

v1.12.0
-------
* simplified MPU communication

v1.11.1
-------
* SensorMonitor ILC
* broadcast commands to step and freeze
* SimpleFPGACliApp class
* formatDuration template class
* More constants

v1.11.0
-------
Expand Down
1 change: 1 addition & 0 deletions include/cRIO/ElectromechanicalPneumaticILC.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ElectromechanicalPneumaticILC : public virtual ILC::ILCBusList {
REPORT_DCA_GAIN = 74,
SET_FORCE_OFFSET = 75,
REPORT_FA_FORCE_STATUS = 76,
SET_ADC_SCANRATE = 80,
SET_OFFSET_AND_SENSITIVITY = 81,
REPORT_CALIBRATION_DATA = 110,
REPORT_MEZZANINE_PRESSURE = 119,
Expand Down
3 changes: 2 additions & 1 deletion include/cRIO/FPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ class FPGA : public SimpleFPGA {
/**
* Commands FPGA to write to MPU commands buffer.
*
* @param mpu Modbus Processing Unit that shall be written
* @param data data to write to the MPU command buffer
* @param timeout timeout in milliseconds
*/
virtual void writeMPUFIFO(const std::vector<uint8_t>& data, uint32_t timeout) = 0;
virtual void writeMPUFIFO(MPU& mpu, const std::vector<uint8_t>& data, uint32_t timeout) = 0;

/**
* Commands FPGA to copy MPU output FIFO to FPGA-C/C++ output FIFO. This
Expand Down
9 changes: 7 additions & 2 deletions include/cRIO/MPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
namespace LSST {
namespace cRIO {

struct CommandedInfo {
CommandedInfo(uint16_t _addres, uint16_t _length) : address(_addres), length(_length) {}
uint16_t address;
uint16_t length;
};

/**
* The Modbus Processing Unit class. Prepares buffer with commands to send to
* FPGA, read responses & telemetry values.
Expand Down Expand Up @@ -138,8 +144,7 @@ class MPU : public Modbus::BusList {
/**
* Address of register/input which will be read by the command
*/
uint16_t _commanded_address = 0;
uint16_t _commanded_length = 0;
std::list<CommandedInfo> _commanded_info;

std::mutex _registerMutex;

Expand Down
37 changes: 4 additions & 33 deletions include/cRIO/MPUTelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,12 @@ class MPUTelemetry {
*
* @param data[45] data as received from FPGA
*/
MPUTelemetry(uint8_t* data);
uint32_t writeBytes; /// Number of bytes written
uint32_t readBytes; /// Number of bytes read
uint16_t readTimedout; /// read timedout counter
MPUTelemetry(const uint8_t* data);

friend std::ostream& operator<<(std::ostream& os, const MPUTelemetry& tel);
uint64_t writeBytes; /// Number of bytes written
uint64_t readBytes; /// Number of bytes read

/**
* Updates MPU telemetry SAL message structure.
*
* @tparam message class with telemetry filed. Shall be SAL declared class
* @param msg message to check and update
*
* @return true if message shall be send, false if updates are minor and it should not be send
*/
template <class message>
bool sendUpdates(message* msg) {
return false;

/**
if (msg->readBytes != readBytes || msg->writeTimedout != writeTimedout ||
msg->instructionPointerOnError != instructionPointerOnError || msg->errorCode != errorCode) {
send = true;
}
msg->instructionPointer = instructionPointer;
msg->outputCounter = outputCounter;
msg->inputCounter = inputCounter;
msg->outputTimeouts = outputTimeouts;
msg->inputTimeouts = inputTimeouts;
msg->instructionPointerOnError = instructionPointerOnError;
msg->writeTimeout = writeTimeout;
msg->readTimeout = readTimeout;
msg->errorCode = errorCode;
return send; */
}
friend std::ostream& operator<<(std::ostream& os, const MPUTelemetry& tel);
};

} // namespace cRIO
Expand Down
2 changes: 2 additions & 0 deletions include/cRIO/PrintILC.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class PrintILC : public virtual ILC::ILCBusList {
WRITE_VERIFY_APPLICATION = 103
};

static constexpr uint8_t APPLICATION_PAGE_LENGTH = 192;

protected:
void processServerID(uint8_t address, uint64_t uniqueID, uint8_t ilcAppType, uint8_t networkNodeType,
uint8_t ilcSelectedOptions, uint8_t networkNodeOptions, uint8_t majorRev,
Expand Down
10 changes: 5 additions & 5 deletions include/cRIO/SimpleFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class SimpleFPGA {
*/
void openDebugFile(const char* path);

void writeDebugFile(const char* message);
void writeDebugFile(const std::string& message);

template <typename dt>
const void writeDebugFile(const char* message, const std::vector<dt>& data) {
const void writeDebugFile(const std::string& message, const std::vector<dt>& data) {
if (_debug_stream.is_open()) {
try {
auto now = std::chrono::system_clock::now();
Expand All @@ -117,7 +117,7 @@ class SimpleFPGA {
}

template <typename dt>
const void writeDebugFile(const char* message, dt* buf, size_t length) {
const void writeDebugFile(const std::string& message, dt* buf, size_t length) {
if (_debug_stream.is_open()) {
try {
auto now = std::chrono::system_clock::now();
Expand All @@ -132,7 +132,7 @@ class SimpleFPGA {
}

template <typename dt>
const void writeDebugFile(const char* message, ModbusBuffer& mb) {
const void writeDebugFile(const std::string& message, ModbusBuffer& mb) {
if (_debug_stream.is_open()) {
try {
auto now = std::chrono::system_clock::now();
Expand All @@ -146,7 +146,7 @@ class SimpleFPGA {
}
}

void writeDebugFile(const char* message, ModbusBuffer& mb);
void writeDebugFile(const std::string& message, ModbusBuffer& mb);

void closeDebugFile();

Expand Down
5 changes: 3 additions & 2 deletions include/cRIO/SimpleFPGACliApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <unistd.h>

#include <cRIO/CliApp.h>
#include <cRIO/formatDuration.h>
#include <cRIO/SimpleFPGA.h>

namespace LSST {
Expand Down Expand Up @@ -181,8 +182,8 @@ class TemplateFPGACliApp : public CliApp {
auto end = std::chrono::steady_clock::now();

if (_timeIt) {
std::chrono::duration<double> diff = end - start;
std::cout << "Took " << std::setprecision(3) << (diff.count() * 1000.0) << " ms" << std::endl;
std::cout << "Took " << std::setprecision(3) << std::fixed << formatDuration(end - start)
<< std::endl;
}

return ret;
Expand Down
96 changes: 96 additions & 0 deletions include/cRIO/formatDuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
* (https://www.lsst.org). See the COPYRIGHT file at the top-level directory of
* this distribution for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef _formatDuration_H_
#define _formatDuration_H_

#include <chrono>
#include <sstream>
#include <string>

using namespace std::chrono;

/***
* Template function to format chrono::duration to human readable string.
*
* @parametr timeunit
*
* @return human-readable string (such as 1m:41s:341.179.283ns)
*/
template <typename T>
inline std::string formatDuration(T timeunit) {
nanoseconds ns = duration_cast<nanoseconds>(timeunit);
std::ostringstream os;
bool foundNonZero = false;
os.fill('0');
typedef duration<int, std::ratio<86400 * 365>> years;
const auto y = duration_cast<years>(ns);
if (y.count()) {
foundNonZero = true;
os << y.count() << "y:";
ns -= y;
}
typedef duration<int, std::ratio<86400>> days;
const auto d = duration_cast<days>(ns);
if (d.count()) {
foundNonZero = true;
os << d.count() << "d:";
ns -= d;
}
const auto h = duration_cast<hours>(ns);
if (h.count() || foundNonZero) {
foundNonZero = true;
os << h.count() << "h:";
ns -= h;
}
const auto m = duration_cast<minutes>(ns);
if (m.count() || foundNonZero) {
foundNonZero = true;
os << m.count() << "m:";
ns -= m;
}
const auto s = duration_cast<seconds>(ns);
if (s.count() || foundNonZero) {
foundNonZero = true;
os << s.count() << "s:";
ns -= s;
}
const auto ms = duration_cast<milliseconds>(ns);
if (ms.count() || foundNonZero) {
if (foundNonZero) {
os << std::setw(3);
}
os << ms.count() << ".";
ns -= ms;
foundNonZero = true;
}
const auto us = duration_cast<microseconds>(ns);
if (us.count() || foundNonZero) {
if (foundNonZero) {
os << std::setw(3);
}
os << us.count() << ".";
ns -= us;
}
os << std::setw(3) << ns.count() << "ns";
return os.str();
}

#endif ///!_formatDuration_H_
8 changes: 1 addition & 7 deletions src/LSST/cRIO/FPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,7 @@ void FPGA::mpuCommands(MPU &mpu, const std::chrono::duration<double> &timeout) {
// construct buffer to send
std::vector<uint8_t> data;

data.push_back(mpu.getBus());
data.push_back(cmd.buffer.size() + 2);
data.push_back(MPUCommands::WRITE);
data.push_back(cmd.buffer.size());
data.insert(data.end(), cmd.buffer.begin(), cmd.buffer.end());

writeMPUFIFO(data, 0);
writeMPUFIFO(mpu, cmd.buffer, 0);

// read reply
auto answer = readMPUFIFO(mpu);
Expand Down
Loading

0 comments on commit 4d6b3fd

Please sign in to comment.