This update adds more options of generating timestamps from an EVM module, while keeping the existing configuration as the default so established systems do not need to modify any configuration files or EPICS database.
How does the existing code work
Both EVM and EVR are considered time stamp provider (source) and they use the shared code in mrmShared/src, like mrmtimesrc.cpp. For an EVM module, the 1pps input is selected as the external interrupt source. When the interrupt happens, the interrupt service function calls the callback function, and the callback function calls the shared tickSecond() function. In the tickSecond() function, the second counter is encoded as a sequence of 0x70 and 0x71 events, generated as soft events. The TS reset event 0x7d must be configured manually as an triggered event in the EVM.
Timestamp generator provided by the EVM board
The MRF firmware also provided a few ways to generate timestamps.
DBus5 input can be configured as the 1pps input, and Dbus4 input can be configured as the timestamp clock. The TS reset event 0x7d is generated by the first falling edge of DBus4 after DBus5's rising edge. The EVM has a register that holds the second value and it automatically increments at the same time as 0x7d is generated, and then the EVM sends out the 0x70 and 0x71 events automatically. The APS is using this method now.
DBus6 and DBus7 inputs can be used to generate event 0x70 and 0x71 events via external signals. If these events must be transmitted in a controlled way, this option provides more space for maneuver. However, in this mode the EVM itself may not get the timestamp, while the EVRs can.
Summary of changes
Register addresses, masks and shift values are added to facilitate the hardware-based timestamp generators. More details can be found in the mrf manual.
Added a member of evgMrm to track the TSGenerator type: m_TSGenerator
0 - Software: Upon the 1PPS interrupt, 0x70 and 0x71 events are generated by the tickSecond fuction. Event 0x7d must be configured as a trigger Event with the same 1PPS source
1 - Internal: DBus5 generates the event 0x7d synchronized to DBus4. EVM increments its internal second counter and sends events 0x70 and 0x71 automatically. DBus5 must be triggered by the same 1PPS source.
2 - External: DBus5 generates the event 0x7d synchronized to DBus4. Events 0x70 and 0x71 are generated by an external source via DBus6 and 7
Support functions setTSGenerator and getTSGenerator are added
Instead of calling tickSecond() direction in the interrupt callback, a new function tsHandler() is called. This function decides what to execute based on the TS generator type. For the Software generator, it calls tickSecond() directly. For the internal mode, it calls a new function updateSecond(ts_val) under mrmShared. The updateSecond function just update the second value kept by TimeStampSource class based on the register value from the EVM. Upon a resync, the updateSecond function returns a new value. The tsHandler can catch this change and write to the EVM register when it happens.
EPICS records $(P)TSGen-SP and $(P)TSGen-RB are added for user interface.
I also found it useful to make an EPICS record with 1-second periodic scan as the 1pps source when I have no 1pps source for some test. I added 1 EPICS record $(P)SoftTickSecond-Cmd for this purpose, and added the "EPICS Scan" as one option of the 1Pps source selection record. The record $(P)SoftTickSecond-Cmd calls the postSoftSecondSrc() function which is already in the existing code. I added a line in this function to generate event 0x7d as a soft event to make it fully work.
This update adds more options of generating timestamps from an EVM module, while keeping the existing configuration as the default so established systems do not need to modify any configuration files or EPICS database.
How does the existing code work
Both EVM and EVR are considered time stamp provider (source) and they use the shared code in mrmShared/src, like mrmtimesrc.cpp. For an EVM module, the 1pps input is selected as the external interrupt source. When the interrupt happens, the interrupt service function calls the callback function, and the callback function calls the shared tickSecond() function. In the tickSecond() function, the second counter is encoded as a sequence of 0x70 and 0x71 events, generated as soft events. The TS reset event 0x7d must be configured manually as an triggered event in the EVM.
Timestamp generator provided by the EVM board
The MRF firmware also provided a few ways to generate timestamps.
Summary of changes