M1M3 Support System
Loading...
Searching...
No Matches
SimulatedFPGA.h
1/*
2 * This file is part of LSST M1M3 support system package.
3 *
4 * Developed for the Vera C. Rubin Telescope and Site System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef LSST_M1M3_SS_FPGA_SIMULATEDFPGA_H_
25#define LSST_M1M3_SS_FPGA_SIMULATEDFPGA_H_
26
27#include <chrono>
28#include <mutex>
29#include <queue>
30#include <thread>
31
32#include <SAL_MTM1M3C.h>
33#include <SAL_MTMount.h>
34#include <SAL_MTMountC.h>
35
36#include <HardpointActuatorSettings.h>
37#include <IFPGA.h>
38#include <ILCSubnetData.h>
39
40namespace LSST {
41namespace M1M3 {
42namespace SS {
43
47class SimulatedFPGA : public IFPGA {
48public:
50
52
53 void initialize() override;
54 void open() override;
55 void close() override;
56 void finalize() override;
57
58 void waitForOuterLoopClock(uint32_t) override;
59 void ackOuterLoopClock() override;
60
61 void waitForPPS(uint32_t) override;
62 void ackPPS() override;
63
64 void waitForModbusIRQs(uint32_t, uint32_t) override;
65 void ackModbusIRQs() override;
66
67 void pullTelemetry() override;
68 void pullHealthAndStatus() override;
69
70 void writeCommandFIFO(uint16_t *data, size_t length, uint32_t timeoutInMs) override;
71 void writeRequestFIFO(uint16_t *data, size_t length, uint32_t timeoutInMs) override;
72 void writeTimestampFIFO(uint64_t timestamp) override;
73 void readU8ResponseFIFO(uint8_t *data, size_t length, uint32_t timeoutInMs) override;
74 void readU16ResponseFIFO(uint16_t *data, size_t length, uint32_t timeoutInMs) override;
75
76 void writeMPUFIFO(cRIO::MPU &mpu, const std::vector<uint8_t> &data, uint32_t timeout) override {}
77 std::vector<uint8_t> readMPUFIFO(cRIO::MPU &mpu) override { throw std::runtime_error("readMPU called"); }
78
79 void waitOnIrqs(uint32_t irqs, uint32_t timeout, bool &timedout, uint32_t *triggered = NULL) override {
80 timedout = false;
81 }
82 void ackIrqs(uint32_t irqs) override {}
83 uint32_t getIrq(uint8_t bus) override { return 0; }
84
85 void writeHealthAndStatusFIFO(uint16_t request, uint16_t param = 0) override;
86 void readHealthAndStatusFIFO(uint64_t *data, size_t length, uint32_t timeoutInMs = 10) override;
87
88 void readRawAccelerometerFIFO(uint64_t *raw, size_t samples) override;
89
90private:
91 std::thread _monitorMountElevationThread;
92 std::mutex _elevationReadWriteLock;
93 SAL_MTMount _mgrMTMount;
94
95 MTM1M3_hardpointActuatorDataC *_hardpointActuatorData;
96 HardpointActuatorSettings *_hardpointActuatorSettings;
97
98 int _lastRequest;
99 std::queue<uint16_t> _u8Response;
100 std::queue<uint16_t> _u16Response;
101 std::queue<uint16_t> _subnetAResponse;
102 std::queue<uint16_t> _subnetBResponse;
103 std::queue<uint16_t> _subnetCResponse;
104 std::queue<uint16_t> _subnetDResponse;
105 std::queue<uint16_t> _subnetEResponse;
106
107 std::queue<uint16_t> _crcVector;
108 void _writeModbus(std::queue<uint16_t> *response, uint16_t data);
109 void _writeModbus16(std::queue<uint16_t> *reponse, int16_t data);
110 void _writeModbus32(std::queue<uint16_t> *reponse, int32_t data);
111 void _writeModbusFloat(std::queue<uint16_t> *response, float data);
112 void _writeModbusCRC(std::queue<uint16_t> *response);
113 void _writeHP_ILCStatus(std::queue<uint16_t> *response, int index);
114
115 void _monitorElevation(void);
116
117 float _mountElevation = 90.;
118 std::chrono::steady_clock::time_point _mountElevationValidTo;
119 bool _simulatingToHorizon;
120 bool _mountSimulatedMovementFirstPass = true;
121
122 bool _exitThread = false;
123
124 bool _sendResponse;
125
126 // simulates properly clock signal
127 std::chrono::time_point<std::chrono::steady_clock> _nextClock;
128
129 // simulates pressure raising after air valve is opened
130 std::chrono::time_point<std::chrono::steady_clock> _lastAirOpen;
131
132 float _getAirPressure();
133
134 uint64_t _error_counter;
135};
136
145double getRndPM1();
146
147} /* namespace SS */
148} /* namespace M1M3 */
149} /* namespace LSST */
150
151#endif /* LSST_M1M3_SS_FPGA_SIMULATEDFPGA_H_ */
Definition HardpointActuatorSettings.h:43
Abstract interface for FPGA.
Definition IFPGA.h:46
FPGA simulator.
Definition SimulatedFPGA.h:47
void waitForPPS(uint32_t) override
Waits for Peer-to-Peer Synchronization interrupt (10).
Definition SimulatedFPGA.cpp:147
void pullHealthAndStatus() override
Retrieve Health&Status data.
Definition SimulatedFPGA.cpp:308
void pullTelemetry() override
Retrieve telemetry data.
Definition SimulatedFPGA.cpp:165
void ackPPS() override
Acknowledge (clear) Peer-to-Peer Synchronization interrupt.
Definition SimulatedFPGA.cpp:149
void readU8ResponseFIFO(uint8_t *data, size_t length, uint32_t timeoutInMs) override
Definition SimulatedFPGA.cpp:978
void waitForOuterLoopClock(uint32_t) override
Wait for outer loop clock interrupt for synchronization between C++ and FPGA code.
Definition SimulatedFPGA.cpp:140
void waitForModbusIRQs(uint32_t, uint32_t) override
Wait for ModBus interrupts.
Definition SimulatedFPGA.cpp:151
void ackOuterLoopClock() override
Acknowledge (clear interrupt 0) outer loop clock.
Definition SimulatedFPGA.cpp:145
void readRawAccelerometerFIFO(uint64_t *raw, size_t samples) override
Reads raw accelerometer FIFO.
Definition SimulatedFPGA.cpp:995
void ackModbusIRQs() override
Acknowledge ModBus interrupt reception.
Definition SimulatedFPGA.cpp:163
void writeHealthAndStatusFIFO(uint16_t request, uint16_t param=0) override
Requests HealthAndStatus data.
Definition SimulatedFPGA.cpp:987
void writeTimestampFIFO(uint64_t timestamp) override
Write current timestamp value into timestampFIFO.
Definition SimulatedFPGA.cpp:976
void readHealthAndStatusFIFO(uint64_t *data, size_t length, uint32_t timeoutInMs=10) override
Copy HealthAndStatus data into supplied data buffer.
Definition SimulatedFPGA.cpp:989