2 #include "FPGAAnalogDemultiplexer.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunk.h"
9 :
FPGAIO5771(NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_UserCommandIdle
10 , NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_PLLLocked
11 , NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_Configured
12 , NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_UserError
13 , NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorU8_UserCommandStatus
14 , NiFpga_AnalogDemultiplexerV2_NI5771_ControlU8_UserCommand
15 , NiFpga_AnalogDemultiplexerV2_NI5771_ControlU16_UserData0
16 , NiFpga_AnalogDemultiplexerV2_NI5771_ControlU8_UserData1
17 , NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_UserCommandCommit) {
18 assert(SCOPE_NAREAS <= 2);
19 status = NiFpga_Initialize();
21 char*
const Bitfile =
"devices\\fpga\\" NiFpga_AnalogDemultiplexerV2_NI5771_Bitfile;
24 status = NiFpga_Open(Bitfile, NiFpga_AnalogDemultiplexerV2_NI5771_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_AnalogDemultiplexerV2_NI5771_TargetToHostFifoU64_ToHostA1FIFO;
40 fifos[1] = NiFpga_AnalogDemultiplexerV2_NI5771_TargetToHostFifoU64_ToHostA2FIFO;
41 reqpixels[0] = NiFpga_AnalogDemultiplexerV2_NI5771_ControlU32_RequestedpixelsA1;
42 reqpixels[1] = NiFpga_AnalogDemultiplexerV2_NI5771_ControlU32_RequestedpixelsA2;
43 smplsperpixel = NiFpga_AnalogDemultiplexerV2_NI5771_ControlU16_Samplesperpixel;
49 status = NiFpga_Finalize();
50 DBOUT(L
"FPGAAnalogDemultiplexer::~FPGAAnalogDemultiplexer session closed");
65 uint16_t samplesperpixel = round2ui16(_pixeltime * 1E-6 * 1.5E9);
69 DBOUT(L
"FPGADemultiplexer::SetPixeltime Clockcycles per pixel" << samplesperpixel);
71 if ( samplesperpixel%8 != 0 ) {
72 samplesperpixel -= (samplesperpixel%8);
73 DBOUT(L
"FPGADemultiplexer::SetPixeltime Coerced samples per pixel" << samplesperpixel);
77 return static_cast<double>(samplesperpixel)*1E6/1.5E9;
86 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_Waitfortrigger, _waitfortrigger);
90 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_Acquirecontinuously, _cont);
95 DBOUT(L
"FPGAAnalogDemultiplexer::SetRequestedPixels area " << _area << L
": " << _reqpixels);
99 NiFpga_Bool alreadyrunning =
false;
100 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_Acquire, &alreadyrunning);
103 if ( !alreadyrunning ) {
106 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_Acquire,
true);
111 DBOUT(L
"FPGAAnalogDemultiplexer::StopAcquisition");
112 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_Acquire,
false);
116 size_t remaining = 0;
119 assert( (_chunk.NChannels() == 2) && (_chunk.Area() <= 1) );
122 assert(_chunk.
data.size() >= _chunk.PerChannel() * _chunk.NChannels());
124 NiFpga_Status stat = NiFpga_Status_Success;
127 std::vector<uint64_t> u64data(_chunk.PerChannel());
130 std::vector<const uint8_t> bitshift(2);
138 stat = NiFpga_ReadFifoU64(
session
139 ,
fifos[_chunk.Area()]
141 , _chunk.PerChannel()
142 ,
static_cast<uint32_t
>(_timeout * 1000)
144 _timedout = (stat == NiFpga_Status_FifoTimeout);
146 DBOUT(L
"FPGAAnalogDemultiplexer::ReadPixels area " << _chunk.Area() << L
" remaining: " << remaining);
154 auto itch1 = std::begin(_chunk.
data);
155 auto itch2 = std::begin(_chunk.
data) + _chunk.PerChannel();
156 std::for_each(std::begin(u64data), std::end(u64data), [&](
const uint64_t& u64) {
157 *itch1 =
static_cast<uint16_t
>((u64 >> 32) >> bitshift[0]);
158 *itch2 =
static_cast<uint16_t
>((u64 & 0xffff) >> bitshift[1]);
164 return _chunk.PerChannel();
179 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_ToHostA1FIFOOverflow, &b);
181 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_ToHostA2FIFOOverflow, &b);
183 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_InterloopFIFOOverflow, &b);
185 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_InterloopFIFOtimeout, &b);
187 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_IOModuleAIOverRange, &b);
189 status = NiFpga_ReadBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_IndicatorBool_Acquiring, &b);
194 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_ClearInterloopFIFO, 1);
195 std::this_thread::sleep_for(std::chrono::milliseconds(50));
196 status = NiFpga_WriteBool(
session, NiFpga_AnalogDemultiplexerV2_NI5771_ControlBool_ClearInterloopFIFO, 0);
199 for (
auto f :
fifos )
201 std::this_thread::sleep_for(std::chrono::milliseconds(50));
204 for (
auto f : fifos )
206 std::this_thread::sleep_for(std::chrono::milliseconds(50));
208 DBOUT(L
"FPGAAnalogDemultiplexer::ClearFIFOs()");
parameters::InputsFPGAAnalogDemultiplexer * parameters
the parameter set
void StartAcquisition() override
Starts the acquisition on the FPGA.
void SetTriggering(const bool &_waitfortrigger) override
Sets if the FPGA should wait for a trigger before starting acquisition.
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 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...
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.
void SetChannelProps()
Set channel properties as baseline cutoff and bitshift.
std::array< NiFpga_AnalogDemultiplexerV2_NI5771_TargetToHostFifoU64, 2 > fifos
all FIFOs for both areas
std::array< NiFpga_AnalogDemultiplexerV2_NI5771_ControlU32, 2 > reqpixels
requested pixels for both areas
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 StopAcquisition() override
Stops the acquisition on the FPGA.
FPGAStatusSafe status
current FPGA status.
NiFpga_AnalogDemultiplexerV2_NI5771_ControlU16 smplsperpixel
samples per pixel for both areas
#define DBOUT(s)
A debug output to the debug console.
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)
void SetContinuousAcquisition(const bool &_cont) override
Sets if the FPGA should acquire data continuously or acquire the number of pixels per channel set wit...
void Initialize(parameters::InputsFPGA *_parameters) override
Set initial parameters.
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...
int32_t ReadPixels(DaqChunk &_chunk, const double &_timeout, bool &_timedout) override
Read only pixels from the FPGA FIFO.
~FPGAAnalogDemultiplexer()
Close FPGA session.
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.
NiFpga_Session session
NI FPGA session handle.
FPGAAnalogDemultiplexer()
Load the FPGA bitfile, set the IO module's onboard clock and initialize the acquisition.