2 #include "FPGAIO6587.h"
9 ,
const uint32_t& _clock_write_data
10 ,
const uint32_t& _clock_write
11 ,
const uint32_t& _xpoint_ready
12 ,
const uint32_t& _clock_source
13 ,
const uint32_t& _xpoint_write
14 ,
const uint32_t& _commit_control
15 ,
const uint32_t& _acquisition_reset_control)
16 : onboard_clock_ready_indicator(_clock_ready)
17 , onboard_clock_write_data_control(_clock_write_data)
18 , onboard_clock_write_control(_clock_write)
19 , xpoint_switch_ready_indicator(_xpoint_ready)
20 , clock_source_control(_clock_source)
21 , xpoint_switch_write_control(_xpoint_write)
22 , commit_control(_commit_control)
23 , acquisition_reset_control(_acquisition_reset_control)
24 , iostatus(NiFpga_Status_Success) {
33 std::vector<uint8_t> n1(65, 1);
34 std::generate(std::begin(n1)+1, std::end(n1), [&]() {
return i++*2; } );
35 std::array<uint8_t, 6> hsdiv = { 11, 9, 7, 6, 5, 4 };
36 std::array<uint8_t, 9> regaddr = { 0x89, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0x89, 0x87 };
37 std::array<uint8_t, 9> writedata = { 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40 };
39 const double xtalfreq = 114.285E6;
40 double rfreqnew_dec = 0.0;
41 uint64_t rfreqnew = 0;
42 double dconew = 5.67E9;
45 std::for_each(std::begin(n1), std::end(n1), [&](
const uint8_t& _n1) {
46 for (
auto h : hsdiv ) {
47 double tmp = _n1 * (h * _clock_freq);
48 if ( ((tmp >= 4.85E9) && (tmp < 5.67E9)) && (tmp < dconew) ) {
55 rfreqnew_dec = dconew / xtalfreq;
56 rfreqnew =
static_cast<uint64_t
>(round2ui64(rfreqnew_dec * 268435456));
57 writedata[1] = ((hsdivnew-4) << 5) + ((n1new-1) >> 2);
58 writedata[2] = ((n1new-1) << 6) +
static_cast<uint8_t
>(rfreqnew >> 32);
59 writedata[3] = HIBYTE(HIWORD(
LODWORD32(rfreqnew)));
60 writedata[4] = LOBYTE(HIWORD(
LODWORD32(rfreqnew)));
61 writedata[5] = HIBYTE(LOWORD(
LODWORD32(rfreqnew)));
62 writedata[6] = LOBYTE(LOWORD(
LODWORD32(rfreqnew)));
63 std::transform(std::begin(writedata), std::end(writedata), std::begin(regaddr), std::begin(
regndata)
64 , [](
const uint8_t& w,
const uint8_t& r) {
return MAKEWORD(w, r); } );
69 assert( (_clock_freq >= 10E6) && (_clock_freq <= 800E6) );
76 NiFpga_Bool ready =
false;
77 uint32_t waitcounter = 0;
80 std::this_thread::sleep_for(std::chrono::milliseconds(50));
82 }
while ( !ready && (waitcounter < 5000) );
83 if ( waitcounter >= 5000 )
84 throw FPGAException(-1,
"WriteOnboardClockFrequency timeout");
90 DBOUT(L
"FPGAIO6587::WriteOnboardClockFrequency finished");
94 NiFpga_Bool ready =
false;
95 uint32_t waitcounter = 0;
100 std::this_thread::sleep_for(std::chrono::milliseconds(50));
102 }
while ( !ready && (waitcounter < 5000) );
103 if ( waitcounter >= 5000 )
124 std::this_thread::sleep_for(std::chrono::milliseconds(200));
const uint32_t onboard_clock_write_control
the clock write control on the FPGA vi
void WriteOnboardClockFrequency(NiFpga_Session _session, const double &_clock_freq)
Writes the program for the Si570 clock chip to the device.
An exception for FPGA stuff.
const uint32_t xpoint_switch_write_control
the xpoint switch write control on the FPGA vi
bool CheckIOModule(NiFpga_Session _session)
Necessary calls at the moment not supported by NI FPGA API 12.0, see CheckIOModule.vi for what to do.
const uint32_t xpoint_switch_ready_indicator
the xpoint switch ready indicator on the FPGA vi
void ClockFrequencySetup(const double &_clock_freq)
Generates value for programming the Si570 clock chip.
void InitializeAcquisition(NiFpga_Session _session)
Commits the clock frequency and clock source writings and resets the IO module acquisition circuit...
const uint32_t acquisition_reset_control
the acquisition reset control on the FPGA vi
This is the include file for standard system include files, or project specific include files that ar...
std::array< uint16_t, 9 > regndata
register data for writing to the clock chip
#define LODWORD32(l)
Extracts low dword (32 bits) from an ULONG64 (64 bits)
const uint32_t clock_source_control
the clocksource control on the FPGA vi
#define DBOUT(s)
A debug output to the debug console.
const uint32_t commit_control
the commit control on the FPGA vi
const uint32_t onboard_clock_write_data_control
the clock write data control on the FPGA vi
FPGAIO6587(const uint32_t &_clock_ready, const uint32_t &_clock_write_data, const uint32_t &_clock_write, const uint32_t &_xpoint_ready, const uint32_t &_clock_source, const uint32_t &_xpoint_write, const uint32_t &_commit_control, const uint32_t &_acquisition_reset_control)
void SetClockSource(NiFpga_Session _session, const uint8_t &_clock_source=3)
Possible clock sources (see SetClockSource.vi from NI examples) .
FPGAStatusSafe iostatus
Current status of the module.
Various helper functions and classes for Scope.
const uint32_t onboard_clock_ready_indicator
the clock ready indicator on the FPGA vi