From 4fa4d449c6ef728dc964260bf3ee027f8139346c Mon Sep 17 00:00:00 2001 From: Petr Kubanek Date: Tue, 31 Oct 2023 10:52:22 +0100 Subject: [PATCH 01/12] handleMissingReply method --- doc/version-history.rst | 5 +++++ include/cRIO/ModbusBuffer.h | 13 +++++++++++++ src/LSST/cRIO/ModbusBuffer.cpp | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/doc/version-history.rst b/doc/version-history.rst index cfd7bcd7..2d277313 100644 --- a/doc/version-history.rst +++ b/doc/version-history.rst @@ -2,6 +2,11 @@ Version History ############### +v1.10.0 +======= + +* handleMissingReply, MissingReply exception + v1.9.0 ====== diff --git a/include/cRIO/ModbusBuffer.h b/include/cRIO/ModbusBuffer.h index a851707e..ffab8897 100644 --- a/include/cRIO/ModbusBuffer.h +++ b/include/cRIO/ModbusBuffer.h @@ -505,6 +505,11 @@ class ModbusBuffer { EmptyCommanded(uint8_t address, uint8_t function); }; + class MissingReply : public std::runtime_error { + public: + MissingReply(uint8_t address, uint8_t func); + }; + class UnmatchedFunction : public std::runtime_error { public: UnmatchedFunction(uint8_t address, uint8_t function); @@ -521,6 +526,14 @@ class ModbusBuffer { void incIndex() { _index++; } void resetCRC() { _crc.reset(); } + /** + * Called when a reply to command is missing. + * + * @parameter address ILC address + * @parameter func called function + */ + virtual void handleMissingReply(uint8_t address, uint8_t func); + /** * Return data item to write to buffer. Updates CRC counter. * diff --git a/src/LSST/cRIO/ModbusBuffer.cpp b/src/LSST/cRIO/ModbusBuffer.cpp index 5d8aa9f0..f285574f 100644 --- a/src/LSST/cRIO/ModbusBuffer.cpp +++ b/src/LSST/cRIO/ModbusBuffer.cpp @@ -253,6 +253,10 @@ ModbusBuffer::EmptyCommanded::EmptyCommanded(uint8_t address, uint8_t func) fmt::format("Empty commanded buffer, but reply was received. Address {}, function {}.", address, func)) {} +ModbusBuffer::MissingReply::MissingReply(uint8_t address, uint8_t func) + : std::runtime_error( + fmt::format("Missing reply for function {} from ILC with address {}.", func, address)) {} + ModbusBuffer::UnmatchedFunction::UnmatchedFunction(uint8_t address, uint8_t func) : std::runtime_error(fmt::format( "Received response {1} with address {0} without matching send function.", address, func)) {} @@ -263,6 +267,8 @@ ModbusBuffer::UnmatchedFunction::UnmatchedFunction(uint8_t address, uint8_t func "{2} (0x{2:02x}) from {3}.", expectedFunction, expectedAddress, func, address)) {} +void ModbusBuffer::handleMissingReply(uint8_t address, uint8_t func) { throw MissingReply(address, func); } + uint16_t ModbusBuffer::getByteInstruction(uint8_t data) { processDataCRC(data); return data; @@ -312,6 +318,15 @@ void ModbusBuffer::checkCommanded(uint8_t address, uint8_t function) { } std::pair last = _commanded.front(); _commanded.pop(); + // in case some ILC isn't responding, find the first matching the address + while (last.first != address) { + handleMissingReply(last.first, last.second); + if (_commanded.empty()) { + return; + } + last = _commanded.front(); + _commanded.pop(); + } if (last.first != address || last.second != function) { throw UnmatchedFunction(address, function, last.first, last.second); } From f10f2b7a9ebd7f40bc41e3f3003754ff5d5be0fc Mon Sep 17 00:00:00 2001 From: Petr Kubanek Date: Thu, 2 Nov 2023 17:43:49 +0100 Subject: [PATCH 02/12] IRQTimeout handling --- doc/version-history.rst | 1 + include/cRIO/CliApp.h | 12 ++---------- include/cRIO/FPGA.h | 4 +++- include/cRIO/MPU.h | 16 +++++++++++++++- include/cRIO/ModbusBuffer.h | 22 ++++++++++++++++++++++ src/LSST/cRIO/CliApp.cpp | 1 + src/LSST/cRIO/MPU.cpp | 15 +++++++++++++++ src/LSST/cRIO/ModbusBuffer.cpp | 4 +++- tests/TestFPGA.h | 6 ++++-- tests/test_CSC.cpp | 2 +- tests/test_FirmwareLoad.cpp | 4 ++-- tests/test_ModbusBuffer.cpp | 6 ++++++ 12 files changed, 75 insertions(+), 18 deletions(-) diff --git a/doc/version-history.rst b/doc/version-history.rst index 2d277313..a8af60be 100644 --- a/doc/version-history.rst +++ b/doc/version-history.rst @@ -6,6 +6,7 @@ v1.10.0 ======= * handleMissingReply, MissingReply exception +* IRQTimeout handling v1.9.0 ====== diff --git a/include/cRIO/CliApp.h b/include/cRIO/CliApp.h index f1dae68a..e4449f06 100644 --- a/include/cRIO/CliApp.h +++ b/include/cRIO/CliApp.h @@ -18,12 +18,10 @@ #ifndef __CliApp_h #define __CliApp_h -#include #include -#include #include -#include +#include namespace LSST { namespace cRIO { @@ -226,13 +224,7 @@ get_the_answer command. */ template static const void printHexBuffer(dt* buf, size_t len, std::ostream& os = std::cout) { - OStreamRestore res(os); - - os << std::hex << std::setfill('0'); - for (size_t i = 0; i < len; i++) { - os << " " << std::setw(sizeof(dt) * 2) << +(buf[i]); - } - os << std::dec; + os << ModbusBuffer::hexDump
(buf, len); } static const void printDecodedBuffer(uint16_t* buf, size_t len, std::ostream& os = std::cout); diff --git a/include/cRIO/FPGA.h b/include/cRIO/FPGA.h index 9ca9873e..d5713861 100644 --- a/include/cRIO/FPGA.h +++ b/include/cRIO/FPGA.h @@ -122,8 +122,10 @@ class FPGA : public SimpleFPGA { * the data. * * @param mpu Modbus Processing Unit to read the data + * + * @return data read from the port */ - virtual void readMPUFIFO(MPU& mpu) = 0; + virtual std::vector readMPUFIFO(MPU& mpu) = 0; /** * Writes buffer to command FIFO. Command FIFO is processed in diff --git a/include/cRIO/MPU.h b/include/cRIO/MPU.h index 140a3938..c0962bfc 100644 --- a/include/cRIO/MPU.h +++ b/include/cRIO/MPU.h @@ -48,7 +48,7 @@ const static uint8_t READ_US = 2; const static uint8_t READ_MS = 3; const static uint8_t IRQ = 240; const static uint8_t TELEMETRY = 254; -const static uint8_t CLEAR = 255; +const static uint8_t RESET = 255; } // namespace MPUCommands typedef enum { WRITE, READ, IDLE } loop_state_t; @@ -76,6 +76,11 @@ class MPU : public ModbusBuffer { void clearCommanded(); + /** + * Reset bus. Clear all FIFOs. + */ + void resetBus(); + /** * Returns bus number (internal FPGA identifier). * @@ -146,6 +151,15 @@ class MPU : public ModbusBuffer { */ virtual void loopWrite() = 0; + /** + * Exception raised when read timeouts. + */ + class IRQTimeout : public std::runtime_error { + public: + IRQTimeout(std::vector _data); + std::vector data; + }; + /*** * Called to process data read in the loop. * diff --git a/include/cRIO/ModbusBuffer.h b/include/cRIO/ModbusBuffer.h index ffab8897..485eaac6 100644 --- a/include/cRIO/ModbusBuffer.h +++ b/include/cRIO/ModbusBuffer.h @@ -22,8 +22,10 @@ #define CRIO_MODBUSBUFFER_H_ #include +#include #include #include +#include #include #include #include @@ -178,6 +180,26 @@ class ModbusBuffer { */ std::vector getReadData(int32_t length); + /** + * Dumps hex data to ostring stream. + * + * + * @param + */ + template + static const std::string hexDump(dt* buf, size_t len) { + std::ostringstream os; + os << std::setfill('0') << std::hex; + for (size_t i = 0; i < len; i++) { + if (i > 0) { + os << " "; + } + os << std::setw(sizeof(dt) * 2) << +(buf[i]); + } + os << std::dec; + return os.str(); + } + /** * Reads data from buffer. Updates CRC as it reads the data. Size of * receiving buffer is assumed to be equal or greater than len. diff --git a/src/LSST/cRIO/CliApp.cpp b/src/LSST/cRIO/CliApp.cpp index e0379847..174c4be9 100644 --- a/src/LSST/cRIO/CliApp.cpp +++ b/src/LSST/cRIO/CliApp.cpp @@ -37,6 +37,7 @@ #include "cRIO/CliApp.h" #include "cRIO/ModbusBuffer.h" +#include "cRIO/OStreamRestore.h" #include "cRIO/Timestamp.h" namespace LSST { diff --git a/src/LSST/cRIO/MPU.cpp b/src/LSST/cRIO/MPU.cpp index 2237f317..2865422b 100644 --- a/src/LSST/cRIO/MPU.cpp +++ b/src/LSST/cRIO/MPU.cpp @@ -20,12 +20,19 @@ * this program. If not, see . */ +#include #include +#include #include using namespace LSST::cRIO; +MPU::IRQTimeout::IRQTimeout(std::vector _data) + : std::runtime_error(fmt::format("Din't receive any data, reseting MPU. Read data: " + + ModbusBuffer::hexDump(_data.data(), _data.size()))), + data(_data) {} + MPU::MPU(uint8_t bus, uint8_t mpu_address) : _bus(bus), _mpu_address(mpu_address), _contains_read(false) { _loop_state = loop_state_t::WRITE; @@ -146,6 +153,8 @@ void MPU::clearCommanded() { _presetRegisters.clear(); } +void MPU::resetBus() { _commands.push_back(MPUCommands::RESET); } + void MPU::readInputStatus(uint16_t address, uint16_t count, uint16_t timeout) { callFunction(_mpu_address, 2, 0, address, count); @@ -268,9 +277,15 @@ void MPU::runLoop(FPGA& fpga) { bool timedout; fpga.waitOnIrqs(getIrq(), 0, timedout); if (timedout) { + // there is still time to retrive data, wait for IRQ if (_loop_next_read > std::chrono::steady_clock::now()) { return; } + auto data = fpga.readMPUFIFO(*this); + clearCommanded(); + resetBus(); + fpga.writeMPUFIFO(*this); + throw IRQTimeout(data); } else { fpga.readMPUFIFO(*this); } diff --git a/src/LSST/cRIO/ModbusBuffer.cpp b/src/LSST/cRIO/ModbusBuffer.cpp index f285574f..1c8cbbc6 100644 --- a/src/LSST/cRIO/ModbusBuffer.cpp +++ b/src/LSST/cRIO/ModbusBuffer.cpp @@ -18,11 +18,13 @@ * this program. If not, see . */ +#include +#include #include #include -#include #include +#include #include #include diff --git a/tests/TestFPGA.h b/tests/TestFPGA.h index aef19ab1..18f0b4b8 100644 --- a/tests/TestFPGA.h +++ b/tests/TestFPGA.h @@ -31,7 +31,7 @@ enum FPGAAddress { MODBUS_A_RX = 21, MODBUS_A_TX = 25, HEARTBEAT = 62 }; // nam class TestILC : public LSST::cRIO::PrintILC { public: - TestILC(uint8_t bus) : PrintILC(bus) {} + TestILC(uint8_t bus) : LSST::cRIO::PrintILC(bus) {} protected: void processChangeILCMode(uint8_t address, uint16_t mode) override; @@ -49,7 +49,9 @@ class TestFPGA : public LSST::cRIO::FPGA, public LSST::cRIO::PrintILC { uint16_t getRxCommand(uint8_t bus) override { return FPGAAddress::MODBUS_A_RX; } uint32_t getIrq(uint8_t bus) override { return 1; } void writeMPUFIFO(LSST::cRIO::MPU&) override {} - void readMPUFIFO(LSST::cRIO::MPU&) override {} + std::vector readMPUFIFO(LSST::cRIO::MPU&) override { + return std::vector({0xff, 0x0fe}); + } 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 readU16ResponseFIFO(uint16_t* data, size_t length, uint32_t timeout) override; diff --git a/tests/test_CSC.cpp b/tests/test_CSC.cpp index 01cc52d0..2360384c 100644 --- a/tests/test_CSC.cpp +++ b/tests/test_CSC.cpp @@ -46,7 +46,7 @@ class TestFPGA : public FPGA { uint16_t getRxCommand(uint8_t) override { return 0; } uint32_t getIrq(uint8_t) override { return 0; } void writeMPUFIFO(MPU&) override {} - void readMPUFIFO(MPU&) override {} + std::vector readMPUFIFO(MPU&) override { return std::vector({0x04, 0x05}); } void writeCommandFIFO(uint16_t*, size_t, uint32_t) override {} void writeRequestFIFO(uint16_t*, size_t, uint32_t) override {} void readU16ResponseFIFO(uint16_t*, size_t, uint32_t) override {} diff --git a/tests/test_FirmwareLoad.cpp b/tests/test_FirmwareLoad.cpp index e05bd7e5..26dc0132 100644 --- a/tests/test_FirmwareLoad.cpp +++ b/tests/test_FirmwareLoad.cpp @@ -56,7 +56,7 @@ class TestFPGA : public FPGA { uint32_t getIrq(uint8_t bus) override { return 1; } void writeMPUFIFO(MPU& mpu) override {} - void readMPUFIFO(MPU& mpu) override {} + std::vector readMPUFIFO(MPU& mpu) override { return std::vector({0x01, 0x02}); } void writeCommandFIFO(uint16_t* data, size_t length, uint32_t timeout) override; void writeRequestFIFO(uint16_t* data, size_t length, uint32_t timeout) override {} @@ -134,7 +134,7 @@ void TestFPGA::readU16ResponseFIFO(uint16_t* data, size_t length, uint32_t timeo void TestFPGA::_printBuffer(uint16_t* data, size_t length, const char* prefix, bool cmp) { std::stringstream ss; - ss << prefix; + ss << prefix << " "; CliApp::printHexBuffer(data, length, ss); if (cmp) { std::string l; diff --git a/tests/test_ModbusBuffer.cpp b/tests/test_ModbusBuffer.cpp index b3715d61..08e00a53 100644 --- a/tests/test_ModbusBuffer.cpp +++ b/tests/test_ModbusBuffer.cpp @@ -366,3 +366,9 @@ TEST_CASE("CRC class constructed from buffer", "[ModbusBuffer::CRC]") { REQUIRE(crc.get() == 0x6310); } + +TEST_CASE("Hex dumping", "[ModbusBuffer::hexDump]") { + std::vector data({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255}); + + REQUIRE(ModbusBuffer::hexDump(data.data(), data.size()) == "01 02 03 04 05 06 07 08 09 0a 0b ff"); +} From 6f26c4dddb350f8ccabb39e75c1e1002e8f9af1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Thu, 2 Nov 2023 23:27:21 +0000 Subject: [PATCH 03/12] removed doc from clean directories --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4fe3bf12..52012fb3 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ lib/libcRIOcpp.a: FORCE # Other Targets clean: - @$(foreach file,doc,echo '[RM ] ${file}'; $(RM) -r $(file);) + @$(foreach file,,echo '[RM ] ${file}'; $(RM) -r $(file);) @$(foreach dir,src tests,$(MAKE) -C ${dir} $@;) tests: tests/Makefile tests/*.cpp From fdaf32399a23c7877c2ac3a397035a5b64d4ae35 Mon Sep 17 00:00:00 2001 From: Petr Kubanek Date: Fri, 3 Nov 2023 11:37:23 +0100 Subject: [PATCH 04/12] Ignore warning status (positive for NI). --- include/cRIO/NiError.h | 15 +++++++++------ src/LSST/cRIO/NiError.cpp | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/cRIO/NiError.h b/include/cRIO/NiError.h index 01fab7b6..a7638760 100644 --- a/include/cRIO/NiError.h +++ b/include/cRIO/NiError.h @@ -46,37 +46,40 @@ class NiError : public std::runtime_error { }; /** - * Throws NI exception if an error occurred. + * Throws NI exception if an error occurred. Ignores positive status values, as + * those signal a warning - see NiFpga_IsError. * * @param msg message associated with the error * @param status NI status * - * @throw NiError if status != 0 + * @throw NiError if status < 0 * * @see NiError */ void NiThrowError(const char *msg, int32_t status); /** - * Throws NI exception if an error occurred. + * Throws NI exception if an error occurred. Ignores positive status values, as + * those signal a warning - see NiFpga_IsError. * * @param msg message associated with the error * @param status NI status * - * @throw NiError if status != 0 + * @throw NiError if status < 0 * * @see NiError */ inline void NiThrowError(const std::string &msg, int32_t status) { NiThrowError(msg.c_str(), status); } /** - * Throws NI exception if an error occurred. + * Throws NI exception if an error occurred. Ignores positive status values, as + * those signal a warning - see NiFpga_IsError. * * @param func reporting function * @param ni_func Ni function name signaling the exception * @param status NI status * - * @throw NiError if status != 0 + * @throw NiError if status < 0 * * @see NiError */ diff --git a/src/LSST/cRIO/NiError.cpp b/src/LSST/cRIO/NiError.cpp index 42110329..dd0660b6 100644 --- a/src/LSST/cRIO/NiError.cpp +++ b/src/LSST/cRIO/NiError.cpp @@ -31,7 +31,7 @@ NiError::NiError(const char *msg, NiFpga_Status status) : std::runtime_error(NiS } void NiThrowError(const char *msg, int32_t status) { - if (status != 0) { + if (status < 0) { throw NiError(msg, status); } } From 57ab3570f2d23293d678643059ccd5e2e0d3ab1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Fri, 3 Nov 2023 11:39:59 +0000 Subject: [PATCH 05/12] Don't clear buffer before writing loop - enables command chaining --- src/LSST/cRIO/MPU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LSST/cRIO/MPU.cpp b/src/LSST/cRIO/MPU.cpp index 2865422b..4dfd0c56 100644 --- a/src/LSST/cRIO/MPU.cpp +++ b/src/LSST/cRIO/MPU.cpp @@ -267,7 +267,6 @@ std::vector MPU::getCommandVector() { void MPU::runLoop(FPGA& fpga) { switch (_loop_state) { case loop_state_t::WRITE: - clearCommanded(); _loop_next_read = std::chrono::steady_clock::now() + _loop_timeout; loopWrite(); fpga.writeMPUFIFO(*this); @@ -287,6 +286,7 @@ void MPU::runLoop(FPGA& fpga) { fpga.writeMPUFIFO(*this); throw IRQTimeout(data); } else { + fpga.ackIrqs(getIrq()); fpga.readMPUFIFO(*this); } From 18bfdfca789ef8e013e23644b448ec10dba6d3f4 Mon Sep 17 00:00:00 2001 From: Petr Kubanek Date: Mon, 6 Nov 2023 14:16:23 +0100 Subject: [PATCH 06/12] runLoop returns bool - true if that's last call in a loop --- include/cRIO/MPU.h | 2 +- src/LSST/cRIO/MPU.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/cRIO/MPU.h b/include/cRIO/MPU.h index c0962bfc..c21f798a 100644 --- a/include/cRIO/MPU.h +++ b/include/cRIO/MPU.h @@ -179,7 +179,7 @@ class MPU : public ModbusBuffer { * * @param FPGA fpga used to process MPU commands. */ - void runLoop(FPGA &fpga); + bool runLoop(FPGA &fpga); loop_state_t getLoopState() { return _loop_state; } diff --git a/src/LSST/cRIO/MPU.cpp b/src/LSST/cRIO/MPU.cpp index 4dfd0c56..a5894912 100644 --- a/src/LSST/cRIO/MPU.cpp +++ b/src/LSST/cRIO/MPU.cpp @@ -264,7 +264,7 @@ std::vector MPU::getCommandVector() { return _commands; } -void MPU::runLoop(FPGA& fpga) { +bool MPU::runLoop(FPGA& fpga) { switch (_loop_state) { case loop_state_t::WRITE: _loop_next_read = std::chrono::steady_clock::now() + _loop_timeout; @@ -278,7 +278,7 @@ void MPU::runLoop(FPGA& fpga) { if (timedout) { // there is still time to retrive data, wait for IRQ if (_loop_next_read > std::chrono::steady_clock::now()) { - return; + return false; } auto data = fpga.readMPUFIFO(*this); clearCommanded(); @@ -295,11 +295,12 @@ void MPU::runLoop(FPGA& fpga) { } break; case loop_state_t::IDLE: if (_loop_next_read > std::chrono::steady_clock::now()) { - return; + return false; } _loop_state = loop_state_t::WRITE; - break; + return true; } + return false; } void MPU::_pushTimeout(uint16_t timeout) { From c484c5ab5a1dc20083fac6a64f92dcac1a1fe663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Wed, 8 Nov 2023 10:51:15 +0000 Subject: [PATCH 07/12] Fixed IRQ responses --- include/cRIO/MPU.h | 16 ++++++++++++++++ src/LSST/cRIO/MPU.cpp | 14 +++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/cRIO/MPU.h b/include/cRIO/MPU.h index c21f798a..86e55491 100644 --- a/include/cRIO/MPU.h +++ b/include/cRIO/MPU.h @@ -46,6 +46,8 @@ namespace MPUCommands { const static uint8_t WRITE = 1; const static uint8_t READ_US = 2; const static uint8_t READ_MS = 3; +const static uint8_t WAIT_US = 100; +const static uint8_t WAIT_MS = 101; const static uint8_t IRQ = 240; const static uint8_t TELEMETRY = 254; const static uint8_t RESET = 255; @@ -81,6 +83,20 @@ class MPU : public ModbusBuffer { */ void resetBus(); + /** + * Wait for given number of microseonds. + * + * @param us number of microseconds to wait + */ + void waitUs(uint16_t us); + + /** + * Wait for given number of milliseconds. + * + * @param ms number of milliseconds to wait + */ + void waitMs(uint16_t ms); + /** * Returns bus number (internal FPGA identifier). * diff --git a/src/LSST/cRIO/MPU.cpp b/src/LSST/cRIO/MPU.cpp index a5894912..b43f749c 100644 --- a/src/LSST/cRIO/MPU.cpp +++ b/src/LSST/cRIO/MPU.cpp @@ -29,7 +29,7 @@ using namespace LSST::cRIO; MPU::IRQTimeout::IRQTimeout(std::vector _data) - : std::runtime_error(fmt::format("Din't receive any data, reseting MPU. Read data: " + + : std::runtime_error(fmt::format("Din't receive IRQ, reseting MPU. Read data: " + ModbusBuffer::hexDump(_data.data(), _data.size()))), data(_data) {} @@ -155,6 +155,16 @@ void MPU::clearCommanded() { void MPU::resetBus() { _commands.push_back(MPUCommands::RESET); } +void MPU::waitUs(uint16_t us) { + _commands.push_back(MPUCommands::WAIT_US); + _pushTimeout(us); +} + +void MPU::waitMs(uint16_t ms) { + _commands.push_back(MPUCommands::WAIT_MS); + _pushTimeout(ms); +} + void MPU::readInputStatus(uint16_t address, uint16_t count, uint16_t timeout) { callFunction(_mpu_address, 2, 0, address, count); @@ -284,6 +294,8 @@ bool MPU::runLoop(FPGA& fpga) { clearCommanded(); resetBus(); fpga.writeMPUFIFO(*this); + fpga.waitOnIrqs(getIrq(), 100, timedout); + fpga.ackIrqs(getIrq()); throw IRQTimeout(data); } else { fpga.ackIrqs(getIrq()); From 066db829f513469bb955aaba4af9f579714cd255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Wed, 8 Nov 2023 10:52:13 +0000 Subject: [PATCH 08/12] Expanded DataTypes.h --- include/cRIO/DataTypes.h | 44 +++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/include/cRIO/DataTypes.h b/include/cRIO/DataTypes.h index 437cb10d..9c5dd818 100644 --- a/include/cRIO/DataTypes.h +++ b/include/cRIO/DataTypes.h @@ -1,21 +1,24 @@ /* - * 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 file is part of LSST M1M3 support system package. * - * 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. + * Developed for the Vera C. Rubin Telescope and Site System. + * This product includes software developed by the LSST 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 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. + * 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. * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . + * 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 . */ #ifndef DATATYPES_H_ @@ -23,6 +26,10 @@ #include +#define ACK_INPROGRESS 301 //* Acknowledges command reception, command is being executed. +#define ACK_COMPLETE 303 //* Command is completed. +#define ACK_FAILED -302 //* Command execution failed. + /** * Number of ModBus subnets. Subnets are connected and commanded through cRIO * DIOs. @@ -41,6 +48,15 @@ /// Number of actuators in Z axis - shall equal to total number of actuators. #define FA_Z_COUNT 156 +/// Number of secondary (X or Y) actuators. +#define FA_S_COUNT (FA_X_COUNT + FA_Y_COUNT) + +/// Maximal number of Force Actuator near neighbors +#define FA_MAX_NEAR_COUNT 7 + +/// Number of Force Actuator neighbors +#define FA_FAR_COUNT 12 + /// Number of hardpoints. #define HP_COUNT 6 From f415edd7c570e9cc98cffe09ec493636471d908b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Thu, 16 Nov 2023 00:49:53 +0000 Subject: [PATCH 09/12] Fixed IRQ responses --- include/cRIO/MPU.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/cRIO/MPU.h b/include/cRIO/MPU.h index 86e55491..7fa30839 100644 --- a/include/cRIO/MPU.h +++ b/include/cRIO/MPU.h @@ -87,7 +87,11 @@ class MPU : public ModbusBuffer { * Wait for given number of microseonds. * * @param us number of microseconds to wait +<<<<<<< HEAD */ +======= + */ +>>>>>>> cf704ee... Fixed IRQ responses void waitUs(uint16_t us); /** From 066686610d08c377ca6a9f9553ff28fda11587fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Wed, 8 Nov 2023 10:52:13 +0000 Subject: [PATCH 10/12] Expanded DataTypes.h --- include/cRIO/MPU.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/cRIO/MPU.h b/include/cRIO/MPU.h index 7fa30839..b6444839 100644 --- a/include/cRIO/MPU.h +++ b/include/cRIO/MPU.h @@ -87,11 +87,7 @@ class MPU : public ModbusBuffer { * Wait for given number of microseonds. * * @param us number of microseconds to wait -<<<<<<< HEAD - */ -======= */ ->>>>>>> cf704ee... Fixed IRQ responses void waitUs(uint16_t us); /** From 2967ab60437eebdf67ed601e2221bb3d1a94112e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Thu, 16 Nov 2023 00:48:58 +0000 Subject: [PATCH 11/12] Moved ACK_ to SAL/Command --- Makefile.inc | 2 +- include/cRIO/Command.h | 6 +++--- include/cRIO/DataTypes.h | 3 --- include/cRIO/SAL/Command.h | 8 +++++--- tests/test_PrintILC.cpp | 2 ++ 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 1877f4c3..2e999087 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -4,7 +4,7 @@ ifndef VERBOSE silence := --silence-errors endif -c_opts := -fdata-sections -ffunction-sections -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE -DSPDLOG_FMT_EXTERNAL +c_opts := -fdata-sections -ffunction-sections -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE # -DSPDLOG_FMT_EXTERNAL ifdef DEBUG c_opts += -g diff --git a/include/cRIO/Command.h b/include/cRIO/Command.h index 7adf7591..d0d2f739 100644 --- a/include/cRIO/Command.h +++ b/include/cRIO/Command.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef COMMAND_H_ -#define COMMAND_H_ +#ifndef __CRIO_COMMAND_H_ +#define __CRIO_COMMAND_H_ #include @@ -74,4 +74,4 @@ class Command { } // namespace cRIO } // namespace LSST -#endif /* COMMAND_H_ */ +#endif /* __CRIO_COMMAND_H_ */ diff --git a/include/cRIO/DataTypes.h b/include/cRIO/DataTypes.h index 9c5dd818..2de527f8 100644 --- a/include/cRIO/DataTypes.h +++ b/include/cRIO/DataTypes.h @@ -26,9 +26,6 @@ #include -#define ACK_INPROGRESS 301 //* Acknowledges command reception, command is being executed. -#define ACK_COMPLETE 303 //* Command is completed. -#define ACK_FAILED -302 //* Command execution failed. /** * Number of ModBus subnets. Subnets are connected and commanded through cRIO diff --git a/include/cRIO/SAL/Command.h b/include/cRIO/SAL/Command.h index 22c9249a..af1f1b30 100644 --- a/include/cRIO/SAL/Command.h +++ b/include/cRIO/SAL/Command.h @@ -23,9 +23,11 @@ namespace LSST { namespace cRIO { namespace SAL { -constexpr int ACK_INPROGRESS = 301; -constexpr int ACK_COMPLETE = 303; -constexpr int ACK_FAILED = -302; + +constexpr int32_t ACK_INPROGRESS = 301; /// Acknowledges command reception, command is being executed. +constexpr int32_t ACK_COMPLETE = 303; /// Command is completed. +constexpr int32_t ACK_FAILED = -302; /// Command execution failed. + } // namespace SAL } // namespace cRIO } // namespace LSST diff --git a/tests/test_PrintILC.cpp b/tests/test_PrintILC.cpp index ac4ecbe1..a401036f 100644 --- a/tests/test_PrintILC.cpp +++ b/tests/test_PrintILC.cpp @@ -20,6 +20,8 @@ * this program. If not, see . */ +#define CATCH_CONFIG_MAIN + #include #include From ab01bccf475482c470e84d68abbc61d7a06aa081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Thu, 16 Nov 2023 00:41:55 -0300 Subject: [PATCH 12/12] Fixed tests --- include/cRIO/DataTypes.h | 1 - include/cRIO/PrintILC.h | 2 +- tests/test_FPGACliApp.cpp | 2 +- tests/test_ILC.cpp | 6 ++---- tests/test_PrintILC.cpp | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/cRIO/DataTypes.h b/include/cRIO/DataTypes.h index 2de527f8..86e50fdf 100644 --- a/include/cRIO/DataTypes.h +++ b/include/cRIO/DataTypes.h @@ -26,7 +26,6 @@ #include - /** * Number of ModBus subnets. Subnets are connected and commanded through cRIO * DIOs. diff --git a/include/cRIO/PrintILC.h b/include/cRIO/PrintILC.h index 4d9c741d..baa512bf 100644 --- a/include/cRIO/PrintILC.h +++ b/include/cRIO/PrintILC.h @@ -177,4 +177,4 @@ class PrintILC : public virtual ILC { } // namespace cRIO } // namespace LSST -#endif // !_cRIO_ILC_ +#endif // !_cRIO_PrintILC_ diff --git a/tests/test_FPGACliApp.cpp b/tests/test_FPGACliApp.cpp index f9caa226..01ead023 100644 --- a/tests/test_FPGACliApp.cpp +++ b/tests/test_FPGACliApp.cpp @@ -27,7 +27,7 @@ #include #include -#include "TestFPGA.h" +#include using namespace LSST::cRIO; diff --git a/tests/test_ILC.cpp b/tests/test_ILC.cpp index 49049d96..88bff63e 100644 --- a/tests/test_ILC.cpp +++ b/tests/test_ILC.cpp @@ -455,8 +455,7 @@ TEST_CASE("Unmatched response", "[ILC]") { ilc1.clear(); ilc1.reportServerID(132); ilc1.reportServerStatus(141); - REQUIRE_THROWS_AS(ilc1.processResponse(ilc2.getBuffer(), ilc2.getLength()), - ModbusBuffer::UnmatchedFunction); + REQUIRE_THROWS_AS(ilc1.processResponse(ilc2.getBuffer(), ilc2.getLength()), ModbusBuffer::MissingReply); // missing reply constructCommands(); @@ -476,8 +475,7 @@ TEST_CASE("Unmatched response", "[ILC]") { // invalid function ilc2.getBuffer()[1] = 0x1200 | (1 << 1); - REQUIRE_THROWS_AS(ilc1.processResponse(ilc2.getBuffer(), ilc2.getLength()), - ModbusBuffer::UnmatchedFunction); + REQUIRE_THROWS_AS(ilc1.processResponse(ilc2.getBuffer(), ilc2.getLength()), ModbusBuffer::MissingReply); // reset function ilc3.write(17); diff --git a/tests/test_PrintILC.cpp b/tests/test_PrintILC.cpp index a401036f..bf4d0dd3 100644 --- a/tests/test_PrintILC.cpp +++ b/tests/test_PrintILC.cpp @@ -27,7 +27,7 @@ #include #include -#include "TestFPGA.h" +#include using namespace LSST::cRIO;