2 #include "FPGAAnalogDemultiplexerResonance.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunkResonance.h"
9 :
FPGAIO5771(NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_UserCommandIdle
10 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_PLLLocked
11 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_Configured
12 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_UserError
13 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorU8_UserCommandStatus
14 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU8_UserCommand
15 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU16_UserData0
16 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU8_UserData1
17 , NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_UserCommandCommit) {
18 assert(SCOPE_NAREAS <= 2);
19 status = NiFpga_Initialize();
21 char*
const Bitfile =
"devices\\fpga\\" NiFpga_AnalogDemultiplexer_NI5771_Resonance_Bitfile;
24 status = NiFpga_Open(Bitfile, NiFpga_AnalogDemultiplexer_NI5771_Resonance_Signature,
"RIO0", 0, &
session);
25 DBOUT(L
"FPGADemultiplexer: FPGA Session opened");
33 std::this_thread::sleep_for(std::chrono::milliseconds(500));
39 fifos[0] = NiFpga_AnalogDemultiplexer_NI5771_Resonance_TargetToHostFifoU64_ToHostA1FIFO;
40 fifos[1] = NiFpga_AnalogDemultiplexer_NI5771_Resonance_TargetToHostFifoU64_ToHostA2FIFO;
41 reqpixels[0] = NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU32_RequestedpixelsA1;
42 reqpixels[1] = NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU32_RequestedpixelsA2;
43 smplsperpixel = NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU16_Samplesperpixel;
49 status = NiFpga_Finalize();
50 DBOUT(L
"FPGAAnalogDemultiplexerResonance::~FPGAAnalogDemultiplexerResonance session closed");
60 uint32_t chunksize = 1000000;
71 uint16_t samplesperpixel = round2ui16(_pixeltime * 1E-6 * 1.5E9);
75 DBOUT(L
"FPGADemultiplexer::SetPixeltime Clockcycles per pixel" << samplesperpixel);
77 if ( samplesperpixel%8 != 0 ) {
78 samplesperpixel -= (samplesperpixel%8);
79 DBOUT(L
"FPGADemultiplexer::SetPixeltime Coerced samples per pixel" << samplesperpixel);
83 return static_cast<double>(samplesperpixel)*1E6/1.5E9;
92 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_Waitfortrigger, _waitfortrigger);
96 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_Acquirecontinuously, _cont);
101 DBOUT(L
"FPGAAnalogDemultiplexerResonance::SetRequestedPixels area " << _area << L
": " << _reqpixels);
105 NiFpga_Bool alreadyrunning =
false;
106 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_Acquire, &alreadyrunning);
109 if ( !alreadyrunning ) {
112 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_Acquire,
true);
117 DBOUT(L
"FPGAAnalogDemultiplexerResonance::StopAcquisition");
118 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_Acquire,
false);
122 size_t remaining = 0;
128 assert( (_chunk.NChannels() == 2) && (_chunk.Area() == 0) );
131 assert(_chunk.
data.size() >= _chunk.PerChannel() * _chunk.NChannels());
133 NiFpga_Status stat = NiFpga_Status_Success;
136 std::vector<uint64_t> u64data(_chunk.PerChannel());
139 std::vector<uint8_t> bitshift(2);
147 stat = NiFpga_ReadFifoU64(
session
148 ,
fifos[_chunk.Area()]
150 , _chunk.PerChannel()
151 ,
static_cast<uint32_t
>(_timeout * 1000)
153 _timedout = (stat == NiFpga_Status_FifoTimeout);
155 DBOUT(L
"FPGAAnalogDemultiplexerResonance::ReadPixels area " << _chunk.Area() << L
" remaining: " << remaining);
163 auto itch1 = std::begin(chunkres.data);
164 auto itch2 = std::begin(chunkres.data) + chunkres.PerChannel();
166 auto itsync = std::begin(chunkres.resSync);
167 for(
const uint64_t& u64 : u64data) {
170 *itch1 =
static_cast<uint16_t
>((u64 >> 32) >> bitshift[0]);
171 *itch2 =
static_cast<uint16_t
>((u64 & 0xffff) >> bitshift[1]);
172 *itsync = (u64 >> 63) != 0;
179 return chunkres.PerChannel();
194 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_ToHostA1FIFOOverflow, &b);
196 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_ToHostA2FIFOOverflow, &b);
198 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_InterloopFIFOOverflow, &b);
200 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_InterloopFIFOtimeout, &b);
202 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_IOModuleAIOverRange, &b);
204 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_IndicatorBool_Acquiring, &b);
209 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_ClearInterloopFIFO, 1);
210 std::this_thread::sleep_for(std::chrono::milliseconds(50));
211 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlBool_ClearInterloopFIFO, 0);
214 for (
auto f :
fifos )
216 std::this_thread::sleep_for(std::chrono::milliseconds(50));
219 for (
auto f : fifos )
221 std::this_thread::sleep_for(std::chrono::milliseconds(50));
223 DBOUT(L
"FPGAAnalogDemultiplexerResonance::ClearFIFOs()");
NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU16 smplsperpixel
samples per pixel for both areas
void SetTriggering(const bool &_waitfortrigger) override
Sets if the FPGA should wait for a trigger before starting acquisition.
std::array< NiFpga_AnalogDemultiplexer_NI5771_Resonance_TargetToHostFifoU64, 2 > fifos
all FIFOs for both areas
A DaqChunk contains data from all channels sequentially and additionally a bool vector for the resona...
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...
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.
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)
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
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...
void StartAcquisition() override
Starts the acquisition on the FPGA.
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.
~FPGAAnalogDemultiplexerResonance()
Close FPGA session.
FPGAStatusSafe status
current FPGA status.
#define DBOUT(s)
A debug output to the debug console.
void StopAcquisition() override
Stops the acquisition on the FPGA.
parameters::InputsFPGAAnalogDemultiplexer * parameters
the parameter set
std::array< NiFpga_AnalogDemultiplexer_NI5771_Resonance_ControlU32, 2 > reqpixels
requested pixels for both areas
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...
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
FPGAAnalogDemultiplexerResonance()
Load the FPGA bitfile, set the IO module's onboard clock and initialize the acquisition.
void SetChannelProps()
Set channel properties as baseline cutoff and bitshift.
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) ...
NiFpga_Session session
NI FPGA session handle.
void Initialize(parameters::InputsFPGA *_parameters) override
Set initial parameters.