2 #include "FPGAResonanceScanner_NI5771.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunk.h"
5 #include "helpers/DaqChunkResonance.h"
10 :
FPGAIO5771(NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_UserCommandIdle
11 , NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_PLLLocked
12 , NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_Configured
13 , NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_UserError
14 , NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorU8_UserCommandStatus
15 , NiFpga_AnalogIntegrator_NI5771_Resonance_ControlU8_UserCommand
16 , NiFpga_AnalogIntegrator_NI5771_Resonance_ControlU16_UserData0
17 , NiFpga_AnalogIntegrator_NI5771_Resonance_ControlU8_UserData1
18 , NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_UserCommandCommit) {
19 assert(SCOPE_NAREAS == 1);
21 status = NiFpga_Initialize();
23 char*
const Bitfile =
"devices\\fpga\\" NiFpga_AnalogIntegrator_NI5771_Resonance_Bitfile;
26 status = NiFpga_Open(Bitfile, NiFpga_AnalogIntegrator_NI5771_Resonance_Signature,
"RIO0", 0, &
session);
27 DBOUT(L
"FPGAResonanceScannerNI5771: FPGA Session opened");
35 std::this_thread::sleep_for(std::chrono::milliseconds(500));
42 fifos[0] = NiFpga_AnalogIntegrator_NI5771_Resonance_TargetToHostFifoU32_ToHostCh1FIFO;
43 fifos[1] = NiFpga_AnalogIntegrator_NI5771_Resonance_TargetToHostFifoU32_ToHostCh2FIFO;
48 status = NiFpga_Finalize();
49 DBOUT(L
"FPGAResonanceScannerNI5771::~FPGAResonanceScannerNI5771 session closed");
58 uint32_t chunksize = 1000000;
69 uint16_t samplesperpixel = round2ui16(_pixeltime * 1E-6 * 1.5E9);
70 status = NiFpga_WriteU16(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlU32_Samplesperpixel, samplesperpixel);
72 DBOUT(L
"FPGAResonanceScannerNI5771::SetPixeltime samples per pixel" << samplesperpixel);
74 if ( samplesperpixel%8 != 0 ) {
75 samplesperpixel -= (samplesperpixel%8);
76 DBOUT(L
"FPGAResonanceScannerNI5771::SetPixeltime Coerced samples per per pixel" << samplesperpixel);
79 return static_cast<double>(samplesperpixel)*1E6/1.5E9;
84 uint16_t samplesperline = round2ui32(_linetime * 1E-6 * 1.5E9);
85 status = NiFpga_WriteU16(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlU32_Samplesperline, samplesperline);
87 DBOUT(L
"FPGAResonanceScannerNI5771::SetPixeltime samples per line" << samplesperline);
89 if ( samplesperline%8 != 0 ) {
90 samplesperline -= (samplesperline%8);
91 DBOUT(L
"FPGAResonanceScannerNI5771::SetPixeltime Coerced samples per per pixel" << samplesperline);
94 return static_cast<double>(samplesperline)*1E6/1.5E9;
98 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_Waitfortrigger, _waitfortrigger);
102 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_Acquirecontinuously, _cont);
106 status = NiFpga_WriteU32(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlU32_Requestedpixels, _reqpixels);
112 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_Acquire,
true);
116 size_t remaining = 0;
119 assert(_chunk.NChannels() <= 2 );
122 assert(_chunk.
data.size() >= _chunk.PerChannel() * _chunk.NChannels());
124 NiFpga_Status stat = NiFpga_Status_Success;
126 std::vector<uint32_t> u32data(_chunk.PerChannel());
127 std::vector<int32_t> bitshift(_chunk.NChannels());
132 for ( uint32_t c = 0 ; c < _chunk.NChannels() ; c++ ) {
133 stat = NiFpga_ReadFifoU32(
session
136 , _chunk.PerChannel()
137 ,
static_cast<uint32_t
>(_timeout * 1000)
140 _timedout = (stat == NiFpga_Status_FifoTimeout);
151 auto itdata = std::begin(_chunk.
data) + c * _chunk.PerChannel();
152 for(
auto u32 : u32data) {
153 *itdata = u32 & 0x0000ffff;
162 auto itsync = std::begin(_chunkres.
resSync);
163 for(
auto u32 : u32data) {
164 *itsync = ((u32 >> 31) != 0);
169 return _chunk.PerChannel();
175 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_Acquire,
false);
191 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_ToHostCh1FIFOOverflow, &b);
193 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_ToHostCh2FIFOOverflow, &b);
195 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_InterloopFIFOOverflow, &b);
197 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_InterloopFIFOTimeout, &b);
199 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_Acquiring, &b);
201 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_IndicatorBool_IOModuleAIOverRange, &b);
207 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_ClearInterloopFIFO,
true);
208 std::this_thread::sleep_for(std::chrono::milliseconds(50));
209 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_Resonance_ControlBool_ClearInterloopFIFO,
false);
212 for (
auto f :
fifos )
214 std::this_thread::sleep_for(std::chrono::milliseconds(50));
217 for (
auto f : fifos )
219 std::this_thread::sleep_for(std::chrono::milliseconds(50));
void SetRequestedPixels(const uint32_t &_area, const uint32_t &_reqpixels) override
Sets the number of pixels per channel the FPGA should acquire, set to -1 for live scanning...
A DaqChunk contains data from all channels sequentially and additionally a bool vector for the resona...
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.
~FPGAResonanceScannerNI5771()
Close FPGA session.
void StartAcquisition() override
Starts the acquisition on the FPGA.
double SetLinetime(const uint32_t &_area, const double &_linetime) override
Sets the time per line (in seconds) for the generation of the line clock (if implemented) ...
void SetTriggering(const bool &_waitfortrigger) override
Sets if the FPGA should wait for a trigger before starting acquisition.
Handels the NI FlexRIO adapter module IO-5771.
std::vector< uint16_t > data
The data vector.
A DaqChunk contains data from all channels sequentially.
This is the include file for standard system include files, or project specific include files that ar...
bool initialized
true if already initialized
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)
void SetChannelProps()
Set channel properties as baseline and bitshift.
FPGAStatusSafe status
current FPGA status.
#define DBOUT(s)
A debug output to the debug console.
std::array< NiFpga_AnalogIntegrator_NI5771_Resonance_TargetToHostFifoU32, 2 > fifos
both fifos for both channels
FPGAResonanceScannerNI5771()
Load the FPGA bitfile, set the IO module's onboard clock and initialize the acquisition.
void StopAcquisition() override
Stops the acquisition on the FPGA.
void SetClockSource(NiFpga_Session _session, const uint8_t &_clock_source=0)
Possible clock sources (see adapter modules help and Configure Clock.vi from NI 5771 Clock Select exa...
parameters::InputsFPGAAnalogIntegrator * parameters
the parameter set
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
int32_t ReadPixels(DaqChunk &_chunk, const double &_timeout, bool &_timedout) override
Read only pixels from the FPGA FIFO.
void SetContinuousAcquisition(const bool &_cont) override
Sets if the FPGA should acquire data continuously or acquire the number of pixels per channel set wit...
NiFpga_Session session
NI FPGA session handle.
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.
std::vector< bool > resSync
The vector with booleans for the synchronization signal for the resonance scanner.
void Initialize(parameters::InputsFPGA *_parameters) override
Set initial parameters.