Commit 49ab6d63 authored by Holger Witsch's avatar Holger Witsch

long time no commit!

parent 291620e1
......@@ -7,3 +7,5 @@ obj
bin
build
.project
/.metadata/
.settings/
This source diff could not be displayed because it is too large. You can view the blob instead.
1: Analog input range (10000.000000)\n\
2: Trigger Edge (0 = Negative , 1 = Positive)\n\
3: Moving Average frame size in samples: (Min 0, Max 128. 0 or 1 = No Moving Average)\n\
4: Timestep resolution in ns: (Min 25, Max 64. 0 or 1 = No Timestep)\n\
5: Timestep multiplier: (Final Timestep = resolution*multiplier)\n\
6: Timestep Mode ( 0 = No trigger synchronization, 1 = Timestep is synchronized with trigger)\n\
7: Number of triggers to be allowed? (0 = No limit on number of triggers)\n\
8: Number of waveforms to average\n\
9: Number of samples per waveform for each channel (steps of 2 samples, e.g. 40)\n\
10: Target number of averaged waveforms to collect (1)\
Filename
This diff is collapsed.
......@@ -8,20 +8,20 @@
// project : Waveform Averaging using Fast Acqusition PCI cards
//
// This file is part of Tango device class.
//
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
//
//
// Copyright (C): 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017
// European Synchrotron Radiation Facility
......@@ -38,6 +38,21 @@
#define FPGA_H
#include <tango.h>
#define LINUX
#include <Numbat.h>
// redefine this, as it uses printf in the original version
#define CHECKEXIT(f) if(!(f)){ERROR_STREAM << "Error in" << #f ; last_error = 1;}
//#define CHECKADQ(f) if(!(f)){ERROR_STREAM << "Error in " << #f; last_error = 1;}
// ADQ_GetLastError(adq_cu, adq_num)
#define CHECKADQ(f) if(!(f)){ \
sprintf(err,"%s failed %s", #f, get_name().c_str()); \
Tango::Except::throw_exception( \
(const char *)"FPGA::error_init", \
(const char *)err, \
(const char *)"FPGA::init_device");\
}
/*----- PROTECTED REGION END -----*/ // FPGA.h
......@@ -51,7 +66,7 @@ namespace FPGA_ns
{
/*----- PROTECTED REGION ID(FPGA::Additional Class Declarations) ENABLED START -----*/
// Additional Class Declarations
// Additional Class Declarations
/*----- PROTECTED REGION END -----*/ // FPGA::Additional Class Declarations
......@@ -60,7 +75,49 @@ class FPGA : public TANGO_BASE_CLASS
/*----- PROTECTED REGION ID(FPGA::Data Members) ENABLED START -----*/
// Add your own data members
// Add your own data members
long last_error;
string fname = "Filename not set yet !";
unsigned int n_of_devices = 0;
int n_of_failed = 0;
unsigned int adq_num;
int n_of_opened_devices = 0;
int n_of_ADQ = 0;
char* product_name;
struct ADQInfoListEntry* ADQlist;
char err[256];
void* adq_cu;
unsigned int nofbuffers = 20;
int samples_per_waveform;
unsigned int nofchannels;
unsigned int buffers_filled = 0;
unsigned int buffer_error = 0;
unsigned int overflow = 0;
int exit = 0;
unsigned int collect_result = 0;
unsigned long long int collected_waveforms = 0;
unsigned int number_of_waveforms_to_collect;
unsigned int pulse_counter_average_en = 0;
string FileDir;
string FileName;
string FilePrefix;
string FileNum;
string FilePostfix;
int* data_stream;
int trigger_mode;
unsigned long long int sent_waveforms = 0;
int *analog_data_target[4] = {NULL}; // the 4 pointers are NULL
int* temp_data_target;
int* pch[5];
Tango::DevVarLongArray *data_pointer;
Tango::MultiAttribute *attr_list;
/*----- PROTECTED REGION END -----*/ // FPGA::Data Members
......@@ -82,6 +139,7 @@ public:
Tango::DevLong *attr_NumberSamples_read;
Tango::DevLong *attr_TargetNumberWaveforms_read;
Tango::DevString *attr_FileName_read;
Tango::DevULong *attr_MovingAverageSize_read;
// Constructors and destructors
public:
......@@ -307,6 +365,16 @@ public:
*/
virtual void read_FileName(Tango::Attribute &attr);
virtual bool is_FileName_allowed(Tango::AttReqType type);
/**
* Attribute MovingAverageSize related methods
* Description:
*
* Data type: Tango::DevULong
* Attr type: Scalar
*/
virtual void read_MovingAverageSize(Tango::Attribute &attr);
virtual void write_MovingAverageSize(Tango::WAttribute &attr);
virtual bool is_MovingAverageSize_allowed(Tango::AttReqType type);
//--------------------------------------------------------
......@@ -357,7 +425,7 @@ public:
*
* @returns data
*/
virtual Tango::DevLong read();
virtual Tango::DevVarLongArray *read();
virtual bool is_Read_allowed(const CORBA::Any &any);
/**
* Command Save related method
......@@ -380,14 +448,15 @@ public:
/*----- PROTECTED REGION ID(FPGA::Additional Method prototypes) ENABLED START -----*/
// Additional Method prototypes
// Additional Method prototypes
void filename();
/*----- PROTECTED REGION END -----*/ // FPGA::Additional Method prototypes
};
/*----- PROTECTED REGION ID(FPGA::Additional Classes Definitions) ENABLED START -----*/
// Additional Classes Definitions
// Additional Classes Definitions
/*----- PROTECTED REGION END -----*/ // FPGA::Additional Classes Definitions
......
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
<classes name="FPGA" pogoRevision="9.5">
<classes name="FPGA" pogoRevision="9.6">
<description description="" title="Waveform Averaging using Fast Acqusition PCI cards" sourcePath="/mntdirect/_bliss/users/witsch/BEAMLINES/XMAS/FPGA/DS" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Copyright (C): 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017&#xA; European Synchrotron Radiation Facility&#xA; BP 220, Grenoble 38043&#xA; France" hasMandatoryProperty="false" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at esrf.fr - holger.witsch" author="holger.witsch" emailDomain="esrf.fr" classFamily="Acquisition" siteSpecific="ESRF" platform="Unix Like" bus="Compact PCI" manufacturer="Signal Processing Devices Sweden AB" reference="ADQ14"/>
......@@ -55,7 +55,7 @@
<type xsi:type="pogoDsl:VoidType"/>
</argin>
<argout description="data">
<type xsi:type="pogoDsl:IntType"/>
<type xsi:type="pogoDsl:IntArrayType"/>
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</commands>
......@@ -188,6 +188,14 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="concatenate file parameters to one long string representing the current file name" label="file name" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="MovingAverageSize" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:UIntType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<states name="FAULT" description="Fault state">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
......
......@@ -791,6 +791,31 @@ void FPGAClass::attribute_factory(vector<Tango::Attr *> &att_list)
// Not Memorized
att_list.push_back(filename);
// Attribute : MovingAverageSize
MovingAverageSizeAttrib *movingaveragesize = new MovingAverageSizeAttrib();
Tango::UserDefaultAttrProp movingaveragesize_prop;
// description not set for MovingAverageSize
// label not set for MovingAverageSize
// unit not set for MovingAverageSize
// standard_unit not set for MovingAverageSize
// display_unit not set for MovingAverageSize
// format not set for MovingAverageSize
// max_value not set for MovingAverageSize
// min_value not set for MovingAverageSize
// max_alarm not set for MovingAverageSize
// min_alarm not set for MovingAverageSize
// max_warning not set for MovingAverageSize
// min_warning not set for MovingAverageSize
// delta_t not set for MovingAverageSize
// delta_val not set for MovingAverageSize
movingaveragesize->set_default_properties(movingaveragesize_prop);
// Not Polled
movingaveragesize->set_disp_level(Tango::OPERATOR);
movingaveragesize->set_memorized();
movingaveragesize->set_memorized_init(false);
att_list.push_back(movingaveragesize);
// Create a list of static attributes
create_static_attribute_list(get_class_attr()->get_attr_list());
......@@ -866,7 +891,7 @@ void FPGAClass::command_factory()
// Command Read
ReadClass *pReadCmd =
new ReadClass("Read",
Tango::DEV_VOID, Tango::DEV_LONG,
Tango::DEV_VOID, Tango::DEVVAR_LONGARRAY,
"",
"data",
Tango::OPERATOR);
......
......@@ -281,6 +281,21 @@ public:
{return (static_cast<FPGA *>(dev))->is_FileName_allowed(ty);}
};
// Attribute MovingAverageSize class definition
class MovingAverageSizeAttrib: public Tango::Attr
{
public:
MovingAverageSizeAttrib():Attr("MovingAverageSize",
Tango::DEV_ULONG, Tango::READ_WRITE) {};
~MovingAverageSizeAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<FPGA *>(dev))->read_MovingAverageSize(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<FPGA *>(dev))->write_MovingAverageSize(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<FPGA *>(dev))->is_MovingAverageSize_allowed(ty);}
};
//=========================================
// Define classes for commands
......
......@@ -349,6 +349,26 @@ bool FPGA::is_FileName_allowed(TANGO_UNUSED(Tango::AttReqType type))
return true;
}
//--------------------------------------------------------
/**
* Method : FPGA::is_MovingAverageSize_allowed()
* Description : Execution allowed for MovingAverageSize attribute
*/
//--------------------------------------------------------
bool FPGA::is_MovingAverageSize_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Not any excluded states for MovingAverageSize attribute in Write access.
/*----- PROTECTED REGION ID(FPGA::MovingAverageSizeStateAllowed_WRITE) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // FPGA::MovingAverageSizeStateAllowed_WRITE
// Not any excluded states for MovingAverageSize attribute in read access.
/*----- PROTECTED REGION ID(FPGA::MovingAverageSizeStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // FPGA::MovingAverageSizeStateAllowed_READ
return true;
}
//=================================================
// Commands Allowed Methods
......
#define _CRT_SECURE_NO_WARNINGS
#include "ADQAPI.h"
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#ifdef LINUX
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define _kbhit() kbhit_linux()
#define Sleep(a) usleep(1000*a)
#include <stdint.h>
#include <sys/time.h>
#else
#include <conio.h>
#endif
#ifdef _DEBUG
#define scanf(a, b) noscanf()
//#define printf(A, ...) ADQControlUnit_UserLogMessage(adq_cu, 0x00010000, A, ##__VA_ARGS__)
#endif
#ifndef __Numbat_H
#define __Numbat_H
//#define CHECKADQ(f) if(!(f)){printf("Error in " #f "\n"); last_error = 1; goto error;}
//#define CHECKEXIT(f) if(!(f)){printf("Error in " #f "\n"); last_error = 1;}
#define MIN(a,b) ((a) > (b) ? (b) : (a))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define USRREG_READ_BASE 0x1A
#define USRREG_WRITE_BASE 0x10
//Bit position for WFA_CONTROL_ADDR register
#define WFA_ARM_POS 0u
#define WFA_BYPASS_INV_POS 1u
#define WFA_AUTO_REARM_POS 2u
#define WFA_IMMEDIATE_READOUT_POS 3u
#define WFA_READOUT_POS 4u
#define WFA_SCHEDULE_SHUTDOWN_POS 5u
#define WFA_WAVEFORM_PER_TRIGGER_POS 6u
#define WFA_TRIGGER_COUNT_MODE_POS 7u
#define PULSE_AVERAGE_ENABLE_POS 29u
#define TRIGGER_TEST_POS 30u
#define TRIGGER_EDGE_POS 31u
#define WFA_ARM_BIT 1u
#define WFA_BYPASS_INV_BIT 1u << WFA_BYPASS_INV_POS
#define WFA_AUTO_REARM_BIT 1u << WFA_AUTO_REARM_POS
#define WFA_IMMEDIATE_READOUT_BIT 1u << WFA_IMMEDIATE_READOUT_POS
#define WFA_READOUT_BIT 1u << WFA_READOUT_POS
#define WFA_SCHEDULE_SHUTDOWN_BIT 1u << WFA_SCHEDULE_SHUTDOWN_POS
#define WFA_WAVEFORM_PER_TRIGGER_BIT 1u << WFA_WAVEFORM_PER_TRIGGER_POS
#define WFA_TRIGGER_COUNT_MODE_BIT 1u << WFA_TRIGGER_COUNT_MODE_POS
#define TRIGGER_EDGE_BIT 1u << TRIGGER_EDGE_POS
#define TRIGGER_TEST_BIT 1u << TRIGGER_TEST_POS
#define PULSE_AVERAGE_ENABLE_BIT 1u << PULSE_AVERAGE_ENABLE_POS
#define NORMAL_READOUT 0
#define IMMEDIATE_READOUT 1
#define MANUAL_REARM 0
#define AUTO_REARM 1
#define SINGLE_TRIGGER_NO_DEAD_TIME 0
#define MULTI_TRIGGER_WAVEFORM_PER_TRIGGER 1
//Writable registers
#define MOVING_AVERAGE_CONTROL_ADDR USRREG_WRITE_BASE+0
#define TIMESTEP_CONTROL_ADDR USRREG_WRITE_BASE+1
#define WFA_CONTROL_ADDR USRREG_WRITE_BASE+2
#define WFA_NOF_SAMPLESCYCLES_ADDR USRREG_WRITE_BASE+3
#define WFA_NOF_WAVEFORMS_ADDR USRREG_WRITE_BASE+4
#define WFA_NOF_PRETRIGGERCYCLES_ADDR USRREG_WRITE_BASE+5
#define WFA_NOF_HOLDOFFCYCLES_ADDR USRREG_WRITE_BASE+6
#define WFA_NOF_READOUTWAITCYCLES_ADDR USRREG_WRITE_BASE+7
#define WFA_NOF_TRIGGERS_LIMIT_ADDR USRREG_WRITE_BASE+8
#define DEBUG_PULSE_GENERATOR_ADDR USRREG_WRITE_BASE+9
//Read only registers
#define ANALOG_AVERAGE_STATUS_ADDR USRREG_READ_BASE+0
#define DIGITAL_AVERAGE_STATUS_ADDR USRREG_READ_BASE+1
#define ANALOG_WAVEFORMS_COLLECTED_ADDR USRREG_READ_BASE+2
#define DIGITAL_WAVEFORMS_COLLECTED_ADDR USRREG_READ_BASE+3
//Trigger modes constants
#define SET_SW_TRIGGER_MODE 1
#define SET_EXT_TRIGGER_MODE 2
#define SET_LEVEL_TRIGGER_MODE 3
#define SET_INTERNAL_TRIGGER_MODE 4
#define TIMESTEP_RESOLUTION_POS 0u
#define TIMESTEP_MULTIPLIER_POS 5u
#define TIMESTEP_SYNC_MODE_POS 31u
//Bit position for debug pulse generator that is also used to chose gpio pin
#define PULSE_PERIOD_CYCLES_POS 0u
#define PULSES_PER_TRAIN_POS 16u
#define GPIO_PIN_SELECT_POS 25u
#define PULSE_TRAIN_MODE_POS 30u
#define PULSE_GEN_ONOFF_POS 31u
//Bit position for overflow flags
#define STREAMING_OVERFLOW_POS 0u // 0 = Global Device Streaming Overflow Flag
#define ANALOG_OUTPUT_FIFO_OVERFLOW_POS 1u // 1 = Analog Waveform Average Output Fifo Overflow
#define ANALOG_MA_OVERFLOW_POS 2u // 2 = Analog Moving Average Bit Overflow (Accumulation sum exceeds 23 bits)
#define ANALOG_WFA_OVERFLOW_POS 3u // 3 = Analog Waveform Average Accumulation Overflow (Accumulation sum exceeds 32 bits)
#define DIGITAL_OUTPUT_FIFO_OVERFLOW_POS 4u // 4 = Digital Waveform Average Output Fifo Overflow
#define DIGITAL_SCHEDULE_FIFO_OVERFLOW_POS 5u // 5 = Digital Waveform Average Schedule Fifo Overflow
#define DIGITAL_WFA_OVERFLOW_POS 6u // 6 = Digital Waveform Average Accumulation Overflow (Accumulation sum exceeds 32 bits)
#define STREAMING_OVERFLOW_BIT 1u << STREAMING_OVERFLOW_POS // 0 = Global Device Streaming Overflow Flag
#define ANALOG_OUTPUT_FIFO_OVERFLOW_BIT 1u << ANALOG_OUTPUT_FIFO_OVERFLOW_POS // 1 = Analog Waveform Average Output Fifo Overflow
#define ANALOG_MA_OVERFLOW_BIT 1u << ANALOG_MA_OVERFLOW_POS // 2 = Analog Moving Average Bit Overflow (Accumulation sum exceeds 23 bits)
#define ANALOG_WFA_OVERFLOW_BIT 1u << ANALOG_WFA_OVERFLOW_POS // 3 = Analog Waveform Average Accumulation Overflow (Accumulation sum exceeds 32 bits)
#define DIGITAL_OUTPUT_FIFO_OVERFLOW_BIT 1u << DIGITAL_OUTPUT_FIFO_OVERFLOW_POS // 4 = Digital Waveform Average Output Fifo Overflow
#define DIGITAL_SCHEDULE_FIFO_OVERFLOW_BIT 1u << DIGITAL_SCHEDULE_FIFO_OVERFLOW_POS // 5 = Digital Waveform Average Schedule Fifo Overflow
#define DIGITAL_WFA_OVERFLOW_BIT 1u << DIGITAL_WFA_OVERFLOW_POS // 6 = Digital Waveform Average Accumulation Overflow (Accumulation sum exceeds 32 bits)
//Bit position for GPIO
#define GPIO_PIN_0 0u
#define GPIO_PIN_1 1u
#define GPIO_PIN_2 2u
#define GPIO_PIN_3 3u
#define GPIO_PIN_4 4u
#define GPIO_PIN_5 5u
#define GPIO_PIN_6 6u
#define GPIO_PIN_7 7u
#define GPIO_PIN_8 8u
#define GPIO_PIN_9 9u
#define GPIO_PIN_10 10u
#define GPIO_PIN_11 11u
#define GPIO_PIN_12 12u
#define GPIO_PIN_13 13u
#define GPIO_PIN_14 14u
#define GPIO_PIN_15 15u
#define TRIGGER_EVENT 16u
void ManualReArmExample(void *adq_cu, int adq_num, int argc, char **argv);
void AutoReArmExample(void *adq_cu, int adq_num);
int kbhit_linux (void);
//User register controlled functions
unsigned int Numbat_SetMovingAverageSize(void* adq_cu, int adq_num, unsigned int framesize_in_samples);
unsigned int Numbat_SetTimeStepSize(void* adq_cu, int adq_num, unsigned int timestep_sync_mode, unsigned int multiplier, unsigned int resolution_in_ns);
unsigned int Numbat_SetPulseCounterAveragingMode(void* adq_cu, int adq_num, unsigned int mode);
unsigned int Numbat_WfaSetup(void* adq_cu,
int adq_num,
unsigned int NofWaveforms,
unsigned int NofSamples,
unsigned int NofPreTriggerSamples,
unsigned int NofHoldOffSamples,
unsigned int triggers_limit,
unsigned int trigger_count_mode,
unsigned int trigger_edge,
unsigned int pulse_average_mode,
unsigned int ArmMode,
unsigned int ReadoutMode,
unsigned int AccMode);
unsigned int Numbat_SoftwareTrigger(void* adq_cu, int adq_num);
unsigned int Numbat_WfaSetTriggerEdge(void* adq_cu, int adq_num, unsigned int trigger_edge);
unsigned int Numbat_WfaAccMode(void* adq_cu, int adq_num, unsigned int accumulation_mode);
unsigned int Numbat_WfaSetNumberOfTriggers(void* adq_cu, int adq_num, unsigned int triggers_limit);
unsigned int Numbat_WfaSetTriggerCountMode(void* adq_cu, int adq_num, unsigned int trigger_count_mode);
unsigned int Numbat_WfaSetArmMode(void* adq_cu, int adq_num, unsigned int arm_mode);
unsigned int Numbat_WfaArm(void* adq_cu, int adq_num);
unsigned int Numbat_ParseDataStream(unsigned int samples_per_record, int* data_stream, int** data_target);
unsigned int Numbat_WfaShutdown(void* adq_cu, int adq_num);
unsigned int Numbat_WfaGetStatus(void* adq_cu, int adq_num, unsigned int* data_available, unsigned int* waveforms_accumulated, unsigned int* in_idle);
unsigned int Numbat_WfaGetWaveform(void* adq_cu, int adq_num);
unsigned int Numbat_WfaDisarm(void* adq_cu, int adq_num);
unsigned int Numbat_FlushData(void* adq_cu, int adq_num);
unsigned int Numbat_ResetUserRegisters(void* adq_cu, int adq_num);
unsigned int Numbat_GetStreamOverflow(void* adq_cu, int adq_num, unsigned int* overflow);
unsigned int Numbat_SetupDebugPulseGen(void* adq_cu, int adq_num, unsigned int onoff_mux, unsigned int train_mode, unsigned int pulses_per_train, unsigned int pulse_period_cycles);
unsigned int Numbat_SelectGPIO(void* adq_cu, int adq_num, unsigned int gpio_pin);
void noscanf();
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment