2 #include "FPGAAnalogIntegrator.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunk.h"
9 :
FPGAIO5771(NiFpga_AnalogIntegrator_NI5771_IndicatorBool_UserCommandIdle
10 , NiFpga_AnalogIntegrator_NI5771_IndicatorBool_PLLLocked
11 , NiFpga_AnalogIntegrator_NI5771_IndicatorBool_Configured
12 , NiFpga_AnalogIntegrator_NI5771_IndicatorBool_UserError
13 , NiFpga_AnalogIntegrator_NI5771_IndicatorU8_UserCommandStatus
14 , NiFpga_AnalogIntegrator_NI5771_ControlU8_UserCommand
15 , NiFpga_AnalogIntegrator_NI5771_ControlU16_UserData0
16 , NiFpga_AnalogIntegrator_NI5771_ControlU8_UserData1
17 , NiFpga_AnalogIntegrator_NI5771_ControlBool_UserCommandCommit) {
18 assert(SCOPE_NAREAS == 1);
20 status = NiFpga_Initialize();
22 char*
const Bitfile =
"devices\\fpga\\" NiFpga_AnalogIntegrator_NI5771_Bitfile;
25 status = NiFpga_Open(Bitfile, NiFpga_AnalogIntegrator_NI5771_Signature,
"RIO0", 0, &
session);
26 DBOUT(L
"FPGAAnalogIntegrator: FPGA Session opened");
34 std::this_thread::sleep_for(std::chrono::milliseconds(500));
41 fifos[0] = NiFpga_AnalogIntegrator_NI5771_TargetToHostFifoU32_ToHostCh1FIFO;
42 fifos[1] = NiFpga_AnalogIntegrator_NI5771_TargetToHostFifoU32_ToHostCh2FIFO;
47 status = NiFpga_Finalize();
48 DBOUT(L
"FPGAAnalogIntegrator::~FPGAAnalogIntegrator session closed");
63 uint16_t samplesperpixel = round2ui16(_pixeltime * 1E-6 * 1.5E9);
64 status = NiFpga_WriteU16(
session, NiFpga_AnalogIntegrator_NI5771_ControlU32_Samplesperpixel, samplesperpixel);
66 DBOUT(L
"FPGAAnalogIntegrator::SetPixeltime samples per pixel" << samplesperpixel);
68 if ( samplesperpixel%8 != 0 ) {
69 samplesperpixel -= (samplesperpixel%8);
70 DBOUT(L
"FPGAAnalogIntegrator::SetPixeltime Coerced samples per per pixel" << samplesperpixel);
73 return static_cast<double>(samplesperpixel)*1E6/1.5E9;
78 uint16_t samplesperline = round2ui32(_linetime * 1E-6 * 1.5E9);
79 status = NiFpga_WriteU16(
session, NiFpga_AnalogIntegrator_NI5771_ControlU32_Samplesperline, samplesperline);
81 DBOUT(L
"FPGAAnalogIntegrator::SetPixeltime samples per line" << samplesperline);
83 if ( samplesperline%8 != 0 ) {
84 samplesperline -= (samplesperline%8);
85 DBOUT(L
"FPGAAnalogIntegrator::SetPixeltime Coerced samples per per pixel" << samplesperline);
88 return static_cast<double>(samplesperline)*1E6/1.5E9;
92 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_ControlBool_Waitfortrigger, _waitfortrigger);
96 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_ControlBool_Acquirecontinuously, _cont);
100 status = NiFpga_WriteU32(
session, NiFpga_AnalogIntegrator_NI5771_ControlU32_Requestedpixels, _reqpixels);
106 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_ControlBool_Acquire,
true);
110 size_t remaining = 0;
113 assert( (_chunk.NChannels() == 2) && (_chunk.Area() == 0) );
116 assert(_chunk.
data.size() >= _chunk.PerChannel() * _chunk.NChannels());
118 NiFpga_Status stat = NiFpga_Status_Success;
120 std::vector<uint32_t> u32data(_chunk.PerChannel());
121 std::vector<const uint8_t> bitshift(_chunk.NChannels());
126 for ( uint32_t c = 0 ; c < _chunk.NChannels() ; c++ ) {
127 stat = NiFpga_ReadFifoU32(
session
130 , _chunk.PerChannel()
131 ,
static_cast<uint32_t
>(_timeout * 1000)
134 _timedout = (stat == NiFpga_Status_FifoTimeout);
144 std::transform(std::begin(u32data), std::end(u32data), std::begin(_chunk.
data)+c*_chunk.PerChannel(), [&](
const uint32_t& u32) {
145 return static_cast<uint16_t
>(u32 >> bitshift[c]);
151 return _chunk.PerChannel();
157 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_ControlBool_Acquire,
false);
173 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_IndicatorBool_ToHostCh1FIFOOverflow, &b);
175 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_IndicatorBool_ToHostCh2FIFOOverflow, &b);
177 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_IndicatorBool_InterloopFIFOOverflow, &b);
179 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_IndicatorBool_InterloopFIFOTimeout, &b);
181 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_IndicatorBool_Acquiring, &b);
183 status = NiFpga_ReadBool(
session, NiFpga_AnalogIntegrator_NI5771_IndicatorBool_IOModuleAIOverRange, &b);
189 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_ControlBool_ClearInterloopFIFO,
true);
190 std::this_thread::sleep_for(std::chrono::milliseconds(50));
191 status = NiFpga_WriteBool(
session, NiFpga_AnalogIntegrator_NI5771_ControlBool_ClearInterloopFIFO,
false);
194 for (
auto f :
fifos )
196 std::this_thread::sleep_for(std::chrono::milliseconds(50));
199 for (
auto f : fifos )
201 std::this_thread::sleep_for(std::chrono::milliseconds(50));
std::array< NiFpga_AnalogIntegrator_NI5771_TargetToHostFifoU32, 2 > fifos
both fifos for both channels
FPGAAnalogIntegrator()
Load the FPGA bitfile, set the IO module's onboard clock and initialize the acquisition.
int32_t ReadPixels(DaqChunk &_chunk, const double &_timeout, bool &_timedout) override
Read only pixels from the FPGA FIFO.
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.
Handels the NI FlexRIO adapter module IO-5771.
std::vector< uint16_t > data
The data vector.
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
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 StartAcquisition() override
Starts the acquisition on the FPGA.
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 StopAcquisition() override
Stops the acquisition on the FPGA.
FPGAStatusSafe status
current FPGA status.
void SetContinuousAcquisition(const bool &_cont) override
Sets if the FPGA should acquire data continuously or acquire the number of pixels per channel set wit...
#define DBOUT(s)
A debug output to the debug console.
void SetChannelProps()
Set channel properties as baseline and bitshift.
~FPGAAnalogIntegrator()
Close FPGA session.
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...
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)
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) ...
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
parameters::InputsFPGAAnalogIntegrator * parameters
the parameter set
NiFpga_Session session
NI FPGA session handle.
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.