RMM API 2.0.0
Loading...
Searching...
No Matches
RMMClocks.h
1#pragma once
2
3#include <chrono>
4#include <iostream>
5#include <string>
6#include <thread>
7
8#include "I2CMutex.h"
9#include "RMMRegisterAccess.h"
10#include "Si570Calc.h"
11#include "si5341_config.h"
12
18 std::string modeOfSource;
19 std::string modeOfSync;
22 double si570FreqMHz;
28 double tsFreqMHz;
29 bool tsFreqOk;
31 uint32_t currentTime;
32 double syncFreqHz;
33 uint32_t mrfStatus;
35 std::string mrfMsg;
36 uint32_t mrfMeasDelay;
37 uint32_t mrfTarDelay;
38 uint32_t mrfTopology;
39 uint32_t mrfTsErrorCount;
41};
42
43enum class TimingMode { MRF = 0, LCL = 1, EXT = 2 };
44enum class BringUpMode { CONCURRENT, SEQUENCTIAL };
45
50class RMMClocks {
51 public:
53
54 rmmStatus setupAll(TimingMode timingMode);
55 rmmStatus getTimingStatus(TimingStatus* time);
56 rmmStatus getCurrentTime(uint32_t* currentTime);
57 rmmStatus setEventCode(uint32_t eventCode);
58 bool isTimingConfigDone();
59
61
62 private:
63 static constexpr double CMN_IN_REFCLK_FREQ = 88.0525;
64 static constexpr double SI570_RESET_FREQ = 156.25;
65 static constexpr double SI570_TAR_FREQ = 176.105;
66 static constexpr double SI5341_IN_TAR_FREQ = 158.4945;
67 static constexpr double TIMESTAMP_TAR_FREQ = 88.0525;
68 static constexpr double FREQ_TOLERANCE = 0.001;
69 static constexpr int SI5341_ADDR = 0x77;
70 static constexpr int SI5341_PAGE = 0x01;
71
72 static constexpr uint32_t PPS_TARGET = 0x053F9313; // 88052500 - 1
73 static constexpr uint32_t LCL_SYNC_TARGET = 0x005FF839; // (88052500/14)+1 For 14Hz-ish locally-generated sync
74 // pulses
75
76 int si5341_line_count;
77 int si5341_total_lines;
78
79 RMMRegisterAccess& RMMRegs;
80
81 rmmStatus configSi570(double new_freq = SI570_TAR_FREQ, double reset_freq = SI570_RESET_FREQ);
82 rmmStatus configTiming(TimingMode mode);
83 rmmStatus configSi5341();
84 double getSi570Frequency();
85 double getCmnInRefClkFreq();
86 double getSi5341InputFreq();
87 void setLocalTime();
88 int si5341PageSafeWrite(std::vector<si5341EntryType> si5341_map_data, int old_page);
89 void si5341ProgStatusInc();
90 double getTimestampingFreq();
91
92 uint32_t getTimingModeRaw();
93 std::string getTimingSource();
94 std::string getTimingSync();
95 std::string getTimingMode();
96};
rmmStatus getCurrentTime(uint32_t *currentTime)
Get the current timestamping for RMM.
Definition RMMClocks.cpp:618
rmmStatus setEventCode(uint32_t eventCode)
Set MRF event code.
Definition RMMClocks.cpp:637
RMMLog rmmLog
Log handler for RMMClocks messages.
Definition RMMClocks.h:60
rmmStatus setupAll(TimingMode timingMode)
Setup all clocks and the timing system.
Definition RMMClocks.cpp:56
RMMClocks(RMMRegisterAccess &RMMRegs)
Constructor of the RMMClocks.
Definition RMMClocks.cpp:28
rmmStatus getTimingStatus(TimingStatus *time)
Get the status of the timestamping system (including the embedded EVR) in the RMM.
Definition RMMClocks.cpp:542
bool isTimingConfigDone()
Checks if the hardware timing and clock configuration is complete.
Definition RMMClocks.cpp:39
Class for managing and writing log messages to different log levels and files.
Definition RMMLog.h:52
Class to handle register access over the ESS Readout Master Module.
Definition RMMRegisterAccess.h:57
Struct to hold timing-related information and status for the RMM.
Definition RMMClocks.h:17
uint32_t currentTime
The current timestamp value.
Definition RMMClocks.h:31
uint32_t mrfTopology
The MRF topology ID.
Definition RMMClocks.h:38
double cmnInRefclkFreqMHz
Frequency of the reference clock used for synchronization, usually around 88.0252MHz.
Definition RMMClocks.h:20
uint32_t mrfStatus
Status of progress of the delay compensation of the Embedded EVR, such as whether it is in reset,...
Definition RMMClocks.h:33
uint32_t mrfMeasDelay
Measured delay value for the MRF system.
Definition RMMClocks.h:36
double syncFreqHz
Frequency of the synchronization pulse in Hz.
Definition RMMClocks.h:32
uint32_t mrfTsErrorStatus
Timestamp error status.
Definition RMMClocks.h:40
std::string modeOfSource
The source of the current timing mode.
Definition RMMClocks.h:18
bool tsFreqOk
True if timestamping frequency is within tolerance, false otherwise.
Definition RMMClocks.h:29
std::string modeOfSync
The synchronization method used by the current timing system.
Definition RMMClocks.h:19
bool clkMuxLocked
Indicates whether the clock mux is locked.
Definition RMMClocks.h:30
double si570FreqMHz
Frequency of the Si570 clock in MHz. The Si570 is used as the reference clock for the GTY and the tim...
Definition RMMClocks.h:22
std::string mrfMsg
A human-readable string describing the status of the MRF system.
Definition RMMClocks.h:35
double si5341InFreqMHz
Frequency of the input clock driving the Si5341 in MHz. This clock is sourced from the timestamping s...
Definition RMMClocks.h:25
uint32_t mrfTarDelay
Target delay value for the MRF system.
Definition RMMClocks.h:37
bool si5341InFreqOk
True if the Si5341 input frequency is within tolerance, false otherwise.
Definition RMMClocks.h:27
bool cmnInRefclkFreqOk
True if common input reference clock frequency is within tolerance, false otherwise.
Definition RMMClocks.h:21
bool si570FreqOk
True if the Si570 frequency is within tolerance, false otherwise.
Definition RMMClocks.h:24
double tsFreqMHz
Frequency of the timestamping clock in MHz. Expected value is around 88.0252MHz.
Definition RMMClocks.h:28
uint32_t mrfTsErrorCount
Number of timestamp errors.
Definition RMMClocks.h:39