Skip to content
Snippets Groups Projects
Commit c7806ea2 authored by Claudio Scafuri's avatar Claudio Scafuri :speech_balloon:
Browse files

first import from SVN:...

first import from SVN: http://svn.code.sf.net/p/tango-ds/code/DeviceClasses/BeamDiagnostics/i-tech-brillance, adapted to buildong in Elettra environment
parent 68f7e0e9
No related branches found
No related tags found
No related merge requests found
Showing
with 3199 additions and 0 deletions
/* $Id: libera.h,v 1.88.2.2 2008/02/01 14:29:20 tomazb Exp $ */
/** \file libera.h */
/** Public include file for GNU/Linux Libera driver. */
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_H_
#define _LIBERA_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <linux/ioctl.h>
#ifndef __KERNEL__
#include <time.h>
#include <limits.h>
#endif
/** Libera magic number for ioctl() calls */
#define LIBERA_IOC_MAGIC 'l'
#define LIBERA_EVENT_MAGIC 'e'
#define LIBERA_DSC_MAGIC 'd'
/** Libera description */
typedef struct {
int magic; //!< Magic number.
char name[32]; //!< Libera family member name.
char fpga[32]; //!< FPGA version.
} libera_desc_t;
/** Libera signed 32-bit */
typedef int libera_S32_t;
/** Libera unsigned 32-bit */
typedef unsigned int libera_U32_t;
/** Libera signed 64-bit */
typedef long long libera_S64_t;
/** Libera unsigned 64-bit */
typedef unsigned long long libera_U64_t;
/** Libera 64-bit time storage type. Used for (L)MT & (L)ST */
typedef unsigned long long libera_hw_time_t;
/** Libera timing pair, LMT & LST */
typedef struct
{
libera_hw_time_t lst; //!< Libera System Time
libera_hw_time_t lmt; //!< Libera Machine Time
} libera_Ltimestamp_t;
/** Libera userland timing pair, MT & ST */
typedef struct
{
struct timespec st; //!< System Time
libera_hw_time_t mt; //!< Machine Time
} libera_timestamp_t;
/** Libera High resolution userland timing pair, MT + D & ST */
typedef struct
{
struct timespec st; //!< System Time
libera_hw_time_t mt; //!< Machine Time
unsigned long phase; //!< LMT phase (0...D-1)
} libera_HRtimestamp_t;
/** Libera event structure */
typedef struct
{
int id; //!< Event ID
int param; //!< Event specific parameter
} libera_event_t;
/** Helper macro for events & event masks */
#define EVENT(n) (1 << n)
/** Event IDs to be used in libera_event_t.id */
typedef enum
{
LIBERA_EVENT_USER = UINT_MAX/2, //!< User defined event
LIBERA_EVENT_OVERFLOW = EVENT(0), //!< Fifo overflow
LIBERA_EVENT_CFG = EVENT(1), //!< Configuration change
LIBERA_EVENT_SA = EVENT(2), //!< Slow Acq. sample available
LIBERA_EVENT_INTERLOCK = EVENT(3), //!< Interlock fired
LIBERA_EVENT_PM = EVENT(4), //!< Post Mortem trigger
LIBERA_EVENT_FA = EVENT(5), //!< Fast Application trigger
LIBERA_EVENT_TRIGGET = EVENT(6), //!< GET Trigger trigger
LIBERA_EVENT_TRIGSET = EVENT(7), //!< SET Trigger trigger
} libera_event_id_t;
/** Libera event specific parameter values. */
typedef enum
{
/* OVERFLOW */
LIBERA_OVERFLOW_DD_FPGA = 0, //!< Data on demand fifo overflow in FPGA
LIBERA_OVERFLOW_SA_FPGA, //!< Slow Acq. fifo overflow in FPGA
LIBERA_OVERFLOW_SA_DRV, //!< Slow Acq. fifo overflow in driver
/* FA */
LIBERA_TRIG_FA_MC0, //!< FA MC trigger #0
LIBERA_TRIG_FA_MC1, //!< FA MC trigger #1
LIBERA_TRIG_FA_SC0, //!< FA SC trigger #0
LIBERA_TRIG_FA_SC1, //!< FA SC trigger #1
} libera_event_param_t;
/** Libera interlock parameter values. */
typedef enum
{
LIBERA_INTERLOCK_X = (1<<0), //!< IL position X out of limit
LIBERA_INTERLOCK_Y = (1<<1), //!< IL position Y out of limit
LIBERA_INTERLOCK_ATTN = (1<<2), //!< Attenuators set higher than predefined value
LIBERA_INTERLOCK_ADCF = (1<<3), //!< ADC Overflow (filtered)
LIBERA_INTERLOCK_ADC = (1<<4), //!< ADC Overflow (not filtered)
} libera_interlock_param_t;
/** Available modes of operation. */
// TOOD: Possibly remove from the driver
typedef enum {
LIBERA_MODE_UNKNOWN = 0, //!< Libera mode unknown or not set.
LIBERA_MODE_DD, //!< Data-on-demand mode.
LIBERA_MODE_SA, //!< Slow Acquisition mode.
LIBERA_MODE_PM, //!< Post-Mortem mode.
LIBERA_MODE_ADC, //!< ADC-rate buffer mode.
} LIBERA_MODE;
/** Available trigger modes. */
typedef enum {
LIBERA_TRIGMODE_UNKNOWN = 0, //!< Unknown trigger mode.
LIBERA_TRIGMODE_GET, //!< Get trigger mode.
LIBERA_TRIGMODE_SET, //!< Set trigger mode.
} LIBERA_TRIGMODE;
/* LIBERA ioctl() command identifiers */
/* NOTE: The ordinal numbers (2nd paramter to _IO* IOCTL macros)
* are divided into subsets corresponding to each set/group of
* LIBERA commands. The upper bit (MSB) is group/subset bit and
* the rest 7 bits are sequential number bits. This gives us room for
* hosting 128 commands per group.
* GET_ commands MUST use _IOR macro.
* SET_ commands MUST use _IOW macro.
*/
#define LIBERA_IOC_IS_SET_METHOD(number) ((number) & 0x01)
#define LIBERA_IOC_IS_GET_METHOD(number) (!((number) & 0x01))
#define LIBERA_IOC_MASK 0xE0 /* 3 MSB bits */
#define LIBERA_IOC_CFG 0 /* Common Configuration Parameters */
#define LIBERA_IOC_SA 32 /* Slow Acquisition Parameters */
#define LIBERA_IOC_FA 64 /* Fast Application Parameters */
#define LIBERA_IOC_DD 96 /* Data on Demand Parameters */
#define LIBERA_IOC_PM 128 /* Post Mortem Parameters */
#define LIBERA_IOC_DSC 160 /* DSC Parameters */
/* Libera CFG device parameter IOC tags */
typedef enum
{
LIBERA_CFG_REQUEST = LIBERA_IOC_CFG,
LIBERA_CFG_MAGIC,
LIBERA_CFG_DESC,
#ifdef DEBUG
LIBERA_CFG_MODULERESET,
#endif
} libera_cfg_tags_t;
/* Libera SA device parameter IOC tags */
typedef enum
{
LIBERA_SA_NONE = LIBERA_IOC_SA,
} libera_sa_tags_t;
/* Libera FA device parameter IOC tags */
typedef enum
{
LIBERA_FA_NONE = LIBERA_IOC_FA,
} libera_fa_tags_t;
/* Libera DD device parameter IOC tags */
typedef enum
{
LIBERA_DD_DEC = LIBERA_IOC_DD,
LIBERA_DD_TSTAMP,
} libera_dd_tags_t;
/* Libera PM device parameter IOC tags */
typedef enum
{
LIBERA_PM_TSTAMP = LIBERA_IOC_PM,
} libera_pm_tags_t;
typedef struct
{
unsigned int idx;
unsigned int val;
} libera_cfg_request_t;
/** Configuration Parameters, common to all Libera members */
typedef enum {
/** Trigger mode (set, get, ...) */
LIBERA_CFG_TRIGMODE = 0,
/** MC PLL status */
LIBERA_CFG_MCPLL,
/** SC PLL status */
LIBERA_CFG_SCPLL,
/** Customer Feature Register */
LIBERA_CFG_FEATURE_CUSTOMER,
/** ITECH Feature Register */
LIBERA_CFG_FEATURE_ITECH,
/** First custom (Libera member specific) parameter */
LIBERA_CFG_CUSTOM_FIRST = 128,
} LIBERA_CFG_COMMON;
/** Feature detection using ioctl(CFG_GET, LIBERA_CFG_FEATURE_ITECH) */
#define LIBERA_IS_BPM(_cfg) ((_cfg & 0xf0000000) == 0)
#define LIBERA_IS_BRILLIANCE(_cfg) (LIBERA_IS_BPM(_cfg) && ((_cfg & 0x0f000000) == 0x01000000))
#define LIBERA_IS_MAF(_cfg) (LIBERA_IS_BPM(_cfg) && ((_cfg & 0x10) == 0x10))
#define LIBERA_IS_GBETHERNET(_cfg) (LIBERA_IS_BPM(_cfg) && ((_cfg & 8) == 8))
#define LIBERA_IS_GBE_DEMO(_cfg) (LIBERA_IS_BPM(_cfg) && ((_cfg & 4) == 4))
#define LIBERA_IS_DESY_MOLEX(_cfg) (LIBERA_IS_BPM(_cfg) && ((_cfg & 2) == 2))
#define LIBERA_IS_GROUPING(_cfg) (LIBERA_IS_BPM(_cfg) && ((_cfg & 1) == 1))
#ifdef _EMBEDDED_DEVICE_ //- nl-soleil-compil-workaround
enum libera_ioc_ids_t
{
/***********************************/
/* Common Configuration Parameters */
/***********************************/
/* GENERIC: Generic, nameless CFG parameters */
LIBERA_IOC_GET_CFG = _IOWR(LIBERA_IOC_MAGIC,
LIBERA_CFG_REQUEST,
libera_cfg_request_t),
LIBERA_IOC_SET_CFG = _IOW(LIBERA_IOC_MAGIC,
LIBERA_CFG_REQUEST,
libera_cfg_request_t),
/* MAGIC: Libera magic number */
LIBERA_IOC_GET_MAGIC = _IOR(LIBERA_IOC_MAGIC,
LIBERA_CFG_MAGIC, int),
/* DESC: Libera description */
LIBERA_IOC_GET_DESC = _IOR(LIBERA_IOC_MAGIC,
LIBERA_CFG_DESC, libera_desc_t),
/*******************************/
/* Slow Acquisition Parameters */
/*******************************/
/* NONE */
/*******************************/
/* Fast Acquisition Parameters */
/*******************************/
/* NONE */
/*****************************/
/* Data on Demand Parameters */
/*****************************/
/* DEC: Decimation */
LIBERA_IOC_GET_DEC = _IOR(LIBERA_IOC_MAGIC,
LIBERA_DD_DEC, libera_U32_t),
LIBERA_IOC_SET_DEC = _IOW(LIBERA_IOC_MAGIC,
LIBERA_DD_DEC, libera_U32_t),
/* DD_TSTAMP: DD data timestamp */
LIBERA_IOC_GET_DD_TSTAMP = _IOR(LIBERA_IOC_MAGIC,
LIBERA_DD_TSTAMP,
libera_timestamp_t),
/*****************************/
/* Post Mortem Parameters */
/*****************************/
/* PM_TSTAMP: PM data timestamp */
LIBERA_IOC_GET_PM_TSTAMP = _IOR(LIBERA_IOC_MAGIC,
LIBERA_PM_TSTAMP,
libera_timestamp_t),
/* All DEBUG IDs have to be declared at the bottom of enum! */
};
#endif
/**********************/
/* Event device IOCTL */
/**********************/
typedef enum
{
LIBERA_EVENT_DAC_A,
LIBERA_EVENT_DAC_B,
LIBERA_EVENT_SC_TRIG,
LIBERA_EVENT_MC_TRIG,
LIBERA_EVENT_ST,
LIBERA_EVENT_MT,
LIBERA_EVENT_SC_EVENT,
LIBERA_EVENT_SC_TRIGGER_19,
LIBERA_EVENT_SC_TRIGGER_10,
LIBERA_EVENT_SC_TRIGGER_9,
LIBERA_EVENT_MC_TRIGGER_19,
LIBERA_EVENT_MC_TRIGGER_10,
LIBERA_EVENT_FLMC,
LIBERA_EVENT_CTIME,
LIBERA_EVENT_TRIG_TRIGGER,
LIBERA_EVENT_TRIGGER_BLOCK,
LIBERA_EVENT_MASK,
LIBERA_EVENT_FLUSHING,
LIBERA_EVENT_PMBUF,
LIBERA_EVENT_MCPHI,
LIBERA_EVENT_SCPHI,
LIBERA_EVENT_MC_TRIGGER_1,
LIBERA_EVENT_MC_TRIGGER_0,
LIBERA_EVENT_NCO,
LIBERA_EVENT_MCPLL,
LIBERA_EVENT_SCPLL,
LIBERA_EVENT_FIFOLEN_SC,
LIBERA_EVENT_FIFOLEN_MC,
/* All DEBUG IDs have to be declared at the bottom of enum! */
#ifdef DEBUG
LIBERA_EVENT_PEEK_POKE,
LIBERA_EVENT_EVENTSIM,
LIBERA_EVENT_OFFPLL,
#endif
} libera_event_tags_t;
#ifdef DEBUG
typedef struct
{
unsigned long offset;
unsigned long value;
} libera_peek_poke_t;
#endif
#ifdef _EMBEDDED_DEVICE_ //- nl-soleil-compil-workaround
enum libera_event_ids_t
{
LIBERA_EVENT_SET_DAC_A = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_DAC_A,
libera_S32_t),
LIBERA_EVENT_SET_DAC_B = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_DAC_B,
libera_S32_t),
LIBERA_EVENT_SET_SC_EVENT = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SC_EVENT,
libera_S32_t),
LIBERA_EVENT_ENABLE_SC_TRIG = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SC_TRIG,
libera_S32_t),
LIBERA_EVENT_ENABLE_MC_TRIG = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MC_TRIG,
libera_S32_t),
LIBERA_EVENT_GET_SC_TRIGGER_19= _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SC_TRIGGER_19,
libera_hw_time_t),
LIBERA_EVENT_GET_MC_TRIGGER_19= _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MC_TRIGGER_19,
libera_hw_time_t),
LIBERA_EVENT_GET_SC_TRIGGER_10= _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SC_TRIGGER_10,
libera_hw_time_t),
LIBERA_EVENT_GET_SC_TRIGGER_9= _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SC_TRIGGER_9,
libera_hw_time_t),
LIBERA_EVENT_GET_MC_TRIGGER_10= _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MC_TRIGGER_10,
libera_hw_time_t),
/* ST: System Time */
LIBERA_EVENT_GET_ST = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_ST,
struct timespec),
LIBERA_EVENT_SET_ST = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_ST,
libera_HRtimestamp_t),
/* MT: Machine Time */
LIBERA_EVENT_GET_MT = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MT,
libera_hw_time_t),
LIBERA_EVENT_SET_MT = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MT,
libera_HRtimestamp_t),
/* Transfer of measured MC frequency f_MC */
LIBERA_EVENT_GET_FLMC = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_FLMC,
libera_U32_t),
LIBERA_EVENT_SET_FLMC = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_FLMC,
libera_U32_t),
LIBERA_EVENT_GET_MCPHI = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MCPHI,
libera_hw_time_t),
LIBERA_EVENT_SET_MCPHI = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MCPHI,
libera_hw_time_t),
LIBERA_EVENT_GET_SCPHI = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SCPHI,
libera_hw_time_t),
LIBERA_EVENT_SET_SCPHI = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SCPHI,
libera_hw_time_t),
/* Current Libera time */
LIBERA_EVENT_GET_CTIME = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_CTIME,
libera_Ltimestamp_t),
/* Libera time of the last TRIGGER trigger */
LIBERA_EVENT_GET_TRIG_TRIGGER = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_TRIG_TRIGGER,
libera_Ltimestamp_t),
LIBERA_EVENT_GET_MASK = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MASK,
libera_U32_t),
LIBERA_EVENT_SET_MASK = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MASK,
libera_U32_t),
LIBERA_EVENT_FLUSH = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_FLUSHING,
libera_U32_t),
LIBERA_EVENT_ACQ_PM = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_PMBUF,
libera_U32_t),
LIBERA_EVENT_GET_MC_TRIGGER_1 = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MC_TRIGGER_1,
libera_hw_time_t),
LIBERA_EVENT_GET_MC_TRIGGER_0 = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MC_TRIGGER_0,
libera_hw_time_t),
LIBERA_EVENT_SET_NCO = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_NCO,
libera_U32_t),
LIBERA_EVENT_SET_MCPLL = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_MCPLL,
libera_U32_t),
LIBERA_EVENT_SET_SCPLL = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_SCPLL,
libera_U32_t),
LIBERA_EVENT_GET_FIFOLEN_SC = _IOWR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_FIFOLEN_SC,
libera_U32_t),
LIBERA_EVENT_GET_FIFOLEN_MC = _IOWR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_FIFOLEN_MC,
libera_U32_t),
/* All DEBUG IDs have to be declared at the bottom of enum! */
#ifdef DEBUG
LIBERA_EVENT_GET_TRIGGER_BLOCKED = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_TRIGGER_BLOCK,
libera_Ltimestamp_t),
LIBERA_EVENT_SET_OFFPLL = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_OFFPLL,
libera_hw_time_t),
LIBERA_EVENT_PEEK = _IOR(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_PEEK_POKE,
libera_peek_poke_t),
LIBERA_EVENT_POKE = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_PEEK_POKE,
libera_peek_poke_t),
LIBERA_EVENT_EVENT_SIM = _IOW(LIBERA_EVENT_MAGIC,
LIBERA_EVENT_EVENTSIM,
libera_U32_t),
#endif
};
#endif
/**********************/
/* DSC device IOCTL */
/**********************/
typedef enum
{
LIBERA_DSC_SET = LIBERA_IOC_DSC,
LIBERA_DSC_BCD,
} libera_dsc_tags_t;
typedef struct
{
int X;
int Y;
} libera_offsets_t;
#ifdef _EMBEDDED_DEVICE_ //- nl-soleil-compil-workaround
enum libera_dsc_ids_t
{
LIBERA_DSC_SET_DSC = _IOW(LIBERA_DSC_MAGIC,
LIBERA_DSC_SET,
libera_U32_t),
LIBERA_DSC_BCD_OFFSETS = _IOW(LIBERA_DSC_MAGIC,
LIBERA_DSC_BCD,
libera_offsets_t),
};
#endif
/* Include family member specifics */
#ifdef EBPP
#include "ebpp.h"
#endif
#ifdef BBFP
#include "bbfp.h"
#endif
#ifdef HBPP
#include "hbpp.h"
#endif
#ifdef DPP
#include "dpp.h"
#endif
#define TRIGGER_BIT(x) (1 << (x+22))
#ifdef __cplusplus
}
#endif
#endif // _LIBERA_H
/* $Id: libera_adc.h,v 1.2 2006/01/03 10:29:46 ales Exp $ */
//! \file libera_adc.h
//! Libera GNU/Linux driver ADC-rate Data (ADC) device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_ADC_H_
#define _LIBERA_ADC_H_
#endif /* _LIBERA_ADC_H_ */
/* $Id: libera_cfg.h,v 1.6 2006/01/03 10:29:46 ales Exp $ */
//! \file libera_cfg.h
//! Libera GNU/Linux driver Configuration (CFG) device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_CFG_H_
#define _LIBERA_CFG_H_
int
libera_cfg_cmd(struct libera_cfg_device *dev,
unsigned int cmd, unsigned long arg);
#endif /* _LIBERA_CFG_H_ */
/* $Id: libera_dd.h,v 1.20 2007/10/16 14:44:02 tomazb Exp $ */
//! \file libera_dd.h
//! Libera GNU/Linux driver Data on Demand (DD) device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_DD_H_
#define _LIBERA_DD_H_
/** Convert System Time (ST) to Libera System Time (LST). */
static inline void
st2lst(const struct timespec *st,
libera_hw_time_t *lst)
{
/* NOTE: This conversion is safe regarding overflow in nsec part
* and up to 1.47e11 seconds from UNIX 0 (@ LSC = 125 MHz).
*/
*lst = (libera_hw_time_t)st->tv_sec * LSC_FREQ +
libera_do_div64u(((libera_hw_time_t)st->tv_nsec * LSC_FREQ),NS_IN_SECOND);
}
/** Convert Libera System Time (LST) to System Time (ST). */
static inline void
lst2st(const libera_hw_time_t *lst,
struct timespec *st)
{
st->tv_sec = libera_do_div64u((*lst),LSC_FREQ);
st->tv_nsec = libera_do_mod64u((*lst),LSC_FREQ)*(NS_IN_SECOND / LSC_FREQ);
}
/** Convert Machine Time (MT) to Libera Machine Time (LMT). */
static inline void
mt2lmt(const libera_hw_time_t *mt,
libera_hw_time_t *lmt)
{
*lmt = (*mt) * lgbl.d;
}
/** Convert Libera Machine Time (LMT) to Machine Time (MT). */
static inline void
lmt2mt(const libera_hw_time_t *lmt,
libera_hw_time_t *mt)
{
*mt = libera_do_div64u((*lmt), lgbl.d);
}
/** LMT to Circular Buffer transformation
*
* Provides the Circular Buffer offset (position), based on LMT.
*/
static inline libera_U32_t
get_circ_offset_lmt(libera_hw_time_t *lmt)
{
struct libera_event_device *event = &libera_event;
unsigned long long dummy_first_part, dummy_divisor ;
unsigned long return_value;
dummy_first_part = (*lmt - (event->settime.lmt.off + event->HB_start_lmt) + lgbl.d/2);
dummy_divisor = libera_do_div64u(dummy_first_part, lgbl.d);
return_value = libera_do_mod64u(dummy_divisor,LIBERA_DD_CIRCBUF_ATOMS);
return return_value;
}
/** MT to Circular Buffer transformation
*
* Provides the Circular Buffer offset (position), based on MT.
*/
static inline libera_U32_t
get_circ_offset_mt(libera_hw_time_t *mt)
{
struct libera_event_device *event = &libera_event;
unsigned long long dummy_first_part, dummy_divisor ;
unsigned long return_value;
dummy_first_part = (event->settime.lmt.off + event->HB_start_lmt);
dummy_divisor = libera_do_div64u(dummy_first_part, lgbl.d);
return_value = libera_do_mod64u((*mt - dummy_divisor),LIBERA_DD_CIRCBUF_ATOMS) ;
return return_value;
};
/** Convert Libera System Time (LST) to Libera Machine Time (LMT).
* On success, 0 is returned.
* On error, meaningful negative errno is returned.
*/
static inline int
lst2lmt(const libera_hw_time_t *lst,
libera_hw_time_t *lmt,
const libera_Ltimestamp_t *stime)
{
libera_hw_time_t deltaLST;
libera_hw_time_t deltaLMT;
int positive;
/* This is to avoid using signed 64-bit type for division
* (unresolved symbol __divdi3)
*/
if (*lst > stime->lst)
{
deltaLST = *lst - stime->lst;
positive = TRUE;
}
else
{
deltaLST = stime->lst - *lst;
positive = FALSE;
}
/* NOTE: 64-bit unsigned data type used for deltaLMT allows for
* correct transformation for times up to cca. 15.7e9 LST
* away from the stime sync point in the worst case
* scenario (LMC = f_lmc = 117.440 MHz -> Diamond storage).
* Above these times, we will get overflow problems.
* This roughly corresponds to 124 seconds (@ LSC = 125 MHz).
* Be sure to adjust DELTA_LST_OVERFLOW according to the
* worst case LMC.
*/
if (deltaLST > DELTA_LST_OVERFLOW)
{
ASSERT(TRUE);
return -ERANGE;
}
deltaLMT = libera_do_div64u((deltaLST * flmcdHz),(LSC_FREQ * FLMC_DECI_HZ));
if (positive)
*lmt = stime->lmt + deltaLMT;
else
*lmt = stime->lmt - deltaLMT;
return 0;
}
/** Convert Libera Machine Time (LMT) to Libera System Time (LST).
* On success, 0 is returned.
* On error, meaningful negative errno is returned.
*/
static inline int
lmt2lst(const libera_hw_time_t *lmt,
libera_hw_time_t *lst,
const libera_Ltimestamp_t *stime)
{
libera_hw_time_t deltaLST;
libera_hw_time_t deltaLMT;
int positive;
/* This is to avoid using signed 64-bit type for division
* (unresolved symbol __divdi3)
*/
if (*lmt > stime->lmt)
{
deltaLMT = *lmt - stime->lmt;
positive = TRUE;
}
else
{
deltaLMT = stime->lmt - *lmt;
positive = FALSE;
}
/* NOTE: 64-bit unsigned data type used for deltaLST allows for
* correct transformation for times up to cca. 14.7e9 LMT
* away from the stime sync point (@ LSC = 125 MHz).
* Above these times, we will get overflow problems.
* This roughly corresponds to 124 seconds in the worst case
* scenario (@ LMC = f_lmc = 117.440 MHz -> Diamond storage).
* Be sure to adjust DELTA_LMT_OVERFLOW according to LSC.
*/
if (deltaLMT > DELTA_LMT_OVERFLOW)
{
PDEBUG2("deltaLMT has value 0x%08lx%08lx in function %s \n",ULL(deltaLMT),__FUNCTION__);
ASSERT(TRUE);
return -ERANGE;
}
deltaLST = libera_do_div64u((deltaLMT * LSC_FREQ * FLMC_DECI_HZ),flmcdHz);
if (positive)
*lst = stime->lst + deltaLST;
else
*lst = stime->lst - deltaLST;
return 0;
}
#endif /* _LIBERA_DD_H_ */
/* $Id: libera_dsc.h,v 1.2 2007/05/16 12:59:18 janko Exp $ */
//! \file libera_dsc.h
//! Libera GNU/Linux driver Digital Signal Conditioning (DSC) device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_DSC_H_
#define _LIBERA_DSC_H_
#endif /* _LIBERA_DSC_H_ */
/* $Id: libera_event.h,v 1.5 2007/07/04 13:14:44 ales Exp $ */
//! \file libera_event.h
//! Libera GNU/Linux driver (A)synchronous Event device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#include<asm/dma.h>
#ifndef _LIBERA_EVENT_H_
#define _LIBERA_EVENT_H_
/*
FIFO libera_event miscellaneous functions
*/
static inline void flushFIFO(struct libera_fifo *q)
{
q->put=q->get=0;
}
static inline int lenFIFO(struct libera_fifo *q)
{
return ( (q->put + TRIG_LOG - q->get) & TRIG_LOG_MASK );
}
static inline int not_emptyFIFO(struct libera_fifo *q)
{
return (q->put != q->get);
}
static inline int emptyFIFO(struct libera_fifo *q)
{
return (q->put == q->get);
}
static inline int putToFIFO(struct libera_fifo *q, unsigned long long data)
{
register int index;
if((index=((q->put + 1) & TRIG_LOG_MASK)) == q->get)
{
return -1; /* fifo would overflow */
}
else
{
q->stamp[index] = data;
q->put = index;
return 0;
}
}
static inline unsigned long long* getFromFIFO(struct libera_fifo* const q)
{
if(q->put == q->get)
{
return NULL; /* fifo empty */
}
else
{
q->get = (q->get + 1) & TRIG_LOG_MASK;
return & q->stamp[q->get];
}
}
/******************************/
/* Paired Time CircBuf Queues */
/******************************/
static inline void flushCircBuf(struct libera_circbuf* const q)
{
memset(q, 0, sizeof(struct libera_circbuf));
}
/* LST should always be put to CircBuf first! -> Check interrupt priority! */
static inline void putLSTtoCircBuf(struct libera_circbuf* const q,
const libera_hw_time_t *lst)
{
q->stamp[q->put].lst = *lst;
}
/* LMT should always be put to CircBuf last! -> Check interrupt priority! */
static inline void putLMTtoCircBuf(struct libera_circbuf* const q,
const libera_hw_time_t *lmt)
{
q->stamp[q->put].lmt = *lmt;
q->put = ((q->put + 1) & TRIG_LOG_MASK);
}
static inline void putToCircBuf(struct libera_circbuf* const q,
const libera_Ltimestamp_t *data)
{
q->stamp[q->put] = *data;
q->put = ((q->put + 1) & TRIG_LOG_MASK);
}
static inline libera_Ltimestamp_t*
getFromCircBuf(struct libera_circbuf* const q)
{
register int index;
index = ((q->put - 1) & TRIG_LOG_MASK);
return & q->stamp[index];
}
/* DMA fifos */
static inline void flushDMA_FIFO(libera_dma_t *q)
{
q->put=q->get=0;
}
static inline int lenDMA_FIFO(libera_dma_t *q)
{
int ret;
spin_lock(&dma_spin_lock);
ret = ( (q->put + LIBERA_DMA_FIFO_ATOMS - q->get) & LIBERA_DMA_FIFO_MASK );
spin_unlock(&dma_spin_lock);
return ret;
}
static inline int tailDMA_FIFO(libera_dma_t *q)
{
int ret;
spin_lock(&dma_spin_lock);
ret = ( LIBERA_DMA_FIFO_ATOMS - q->put );
spin_unlock(&dma_spin_lock);
return ret;
}
static inline int not_emptyDMA_FIFO(libera_dma_t *q)
{
int ret;
spin_lock(&dma_spin_lock);
ret = (q->put != q->get);
spin_unlock(&dma_spin_lock);
return ret;
}
static inline int emptyDMA_FIFO(libera_dma_t *q)
{
int ret;
spin_lock(&dma_spin_lock);
ret = (q->put == q->get);
spin_unlock(&dma_spin_lock);
return ret;
}
static inline int putToDMA_FIFO(libera_dma_t *q, unsigned int size_atoms)
{
register int index;
if((index=((q->put + size_atoms) & LIBERA_DMA_FIFO_MASK)) == q->get)
{
return -1; /* fifo would overflow */
}
else
{
/* Only change the index as DMA copies the data */
q->put = index;
return 0;
}
}
/*
FIFO libera_event miscellaneous functions
*/
static inline void flush_eventFIFO(struct libera_event_fifo *q)
{
q->put=q->get=0;
}
static inline int len_eventFIFO(struct libera_event_fifo *q)
{
return ( (q->put + TRIG_LOG - q->get) & TRIG_LOG_MASK );
}
static inline int not_empty_eventFIFO(struct libera_event_fifo *q)
{
return (q->put != q->get);
}
static inline int empty_eventFIFO(struct libera_event_fifo *q)
{
return (q->put == q->get);
}
static inline int putTo_eventFIFO(struct libera_event_fifo *q, libera_event_t *data)
{
register int index;
if((index=((q->put + 1) & TRIG_LOG_MASK)) == q->get)
{
return -1; /* fifo would overflow */
}
else
{
q->data[index] = *data;
q->put = index;
return 0;
}
}
static inline libera_event_t* getFrom_eventFIFO(struct libera_event_fifo* const q)
{
if(q->put == q->get)
{
return NULL; /* fifo empty */
}
else
{
q->get = (q->get + 1) & TRIG_LOG_MASK;
return & q->data[q->get];
}
}
#define T_FIFO_SIZE(X) (X & 0x1FF)
#define TRIG_VECTOR TRIG_ALL_MASK /* 9 bit TRIGGER vector */
#define TRIG_ZERO 0x1 << 22
#define SELF_INC_TRIGGER 0x200 << 22 /* free running trigger (9) */
#endif /* _LIBERA_EVENT_H_ */
/* $Id: libera_fa.h,v 1.2 2006/01/03 10:29:46 ales Exp $ */
//! \file libera_fa.h
//! Libera GNU/Linux driver Fast Application (FA) device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_FA_H_
#define _LIBERA_FA_H_
#endif /* _LIBERA_FA_H_ */
This diff is collapsed.
/* $Id: libera_pipe.h,v 1.4 2006/01/03 10:29:46 ales Exp $ */
//! \file libera_pipe.h
//! Libera GNU/Linux driver: Interface to pipes, mostly used in SA
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_PIPE_H_
#define _LIBERA_PIPE_H_
ssize_t
libera_pipe_read(struct file *filp, char *buf, size_t count, loff_t *ppos);
ssize_t
libera_pipe_write(struct inode *inode, const char *buf, size_t count);
int
libera_pipe_release(struct inode *inode, int decr, int decw);
int
libera_pipe_read_release(struct inode *inode, struct file *filp);
int
libera_pipe_write_release(struct inode *inode, struct file *filp);
int
libera_pipe_rdwr_release(struct inode *inode, struct file *filp);
int
libera_pipe_read_open(struct inode *inode, struct file *filp);
int
libera_pipe_write_open(struct inode *inode, struct file *filp);
int
libera_pipe_rdwr_open(struct inode *inode, struct file *filp);
struct inode*
libera_pipe_new(struct inode* inode);
#endif
/* $Id: libera_pm.h,v 1.4 2006/01/03 10:29:46 ales Exp $ */
//! \file libera_pm.h
//! Libera GNU/Linux driver Post Mortem (PM)device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_PM_H_
#define _LIBERA_PM_H_
#endif /* _LIBERA_PM_H_ */
/* $Id: libera_sa.h,v 1.7 2007/05/10 06:53:10 janko Exp $ */
//! \file libera_sa.h
//! Libera GNU/Linux driver Slow Acquisition (SA) device interface.
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LIBERA_SA_H_
#define _LIBERA_SA_H_
/*
FIFO libera_sa_sa miscellaneous functions
*/
static inline void flush_saFIFO(struct libera_sa_fifo *q)
{
q->put=q->get=0;
}
static inline int len_saFIFO(struct libera_sa_fifo *q)
{
return ( (q->put + SA_LOG - q->get) & SA_LOG_MASK );
}
static inline int not_empty_saFIFO(struct libera_sa_fifo *q)
{
return (q->put != q->get);
}
static inline int empty_saFIFO(struct libera_sa_fifo *q)
{
return (q->put == q->get);
}
static inline int free_saFIFO(struct libera_sa_fifo *q)
{
int len;
len = len_saFIFO(q);
return ( SA_LOG-len);
}
static inline int putTo_saFIFO(struct libera_sa_fifo *q, libera_atom_sa_t *data)
{
register int index;
if((index=((q->put + 1) & SA_LOG_MASK)) == q->get)
{
return -1; /* fifo would overflow */
}
else
{
q->data[index] = *data;
q->put = index;
return 0;
}
}
static inline libera_atom_sa_t* getFrom_saFIFO(struct libera_sa_fifo* const q)
{
if(q->put == q->get)
{
return NULL; /* fifo empty */
}
else
{
q->get = (q->get + 1) & SA_LOG_MASK;
return & q->data[q->get];
}
}
static inline ssize_t libera_pipe_write (struct sa_local *sa_pipe, const char *buf, size_t count)
{
ssize_t ret, written=0;
size_t sa_count,i;
/* Null write succeeds */
ret=0;
if (0==count) goto out;
/* Filter out non-divisable count values */
if (count%sizeof(libera_atom_sa_t)){
PDEBUG("SA:libera_pipe_write(): Inappropriate count size. \n");
ret=-EINVAL;
goto out;
}
sa_count = count/sizeof(libera_atom_sa_t);
/* check if there is enough free space in pipe */
if (free_saFIFO(&sa_pipe->pipe) < sa_count) {
ret=-EFAULT;
goto out;
}
/* write must be atomic */
for(i=0;i<sa_count;i++){
libera_atom_sa_t data;
memcpy(&data,buf,sizeof(libera_atom_sa_t));
if (putTo_saFIFO(&sa_pipe->pipe,&data)) {
PDEBUG("SA:putTo_saFIFO: fifo would owerflow\n");
ret=written;
goto out;
}
written += sizeof(libera_atom_sa_t);
buf +=sizeof(libera_atom_sa_t);
ret=written;
}
out:
return ret;
}
#endif /* _LIBERA_SA_H_ */
/* $Id: llrf.h,v 1.2 2007/10/17 14:06:27 tomazb Exp $ */
/** \file llrf.h */
/** Public include file for Libera Low Level RF (LLRF). */
/*
LIBERA - Libera GNU/Linux device driver
Copyright (C) 2004-2006 Instrumentation Technologies
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
or visit http://www.gnu.org
*/
#ifndef _LLRF_H_
#define _LLRF_H_
/** Libera magic number */
#define LIBERA_MAGIC 0xad00
/** Low lever RF specific CFG parameters. */
typedef enum {
LIBERA_CFG_NONE = LIBERA_CFG_CUSTOM_FIRST, //!< Default.
} LIBERA_CFG_LLRF_GENERIC;
/** Libera Low Level RF sample */
typedef struct {
short chan[4];
} libera_sample_t;
/* Atom vs. sample vs. longwords & bytes constants */
#define LIBERA_DD_CIRCBUF_ATOMS (32*1024*1024) //<! No. of atoms in HB.
#define LIBERA_DD_MT_SAMPLES 1 //<! No. of samples in 1 MT.
#define LIBERA_DD_ATOM_MTS 1 //<! No. of MTs in 1 atom.
#define LIBERA_DD_ATOM_SAMPLES (LIBERA_DD_ATOM_MTS*LIBERA_DD_MT_SAMPLES) //<! No. of samples in 1 ATOM.
/** No. of DD atoms in one DMA block */
#define LIBERA_DMA_BLOCK_ATOMS 512
/* DMA buffer size = PAGE_SIZE << LIBERA_DMA_PAGE_ORDER */
#define LIBERA_DMA_PAGE_ORDER 5
/** No. of DD atoms in DMA fifo - Must be power of 2 and sync
* with LIBERA_DMA_PAGE_ORDER */
#define LIBERA_DMA_FIFO_ATOMS 16384
#define LIBERA_DMA_FIFO_MASK (LIBERA_DMA_FIFO_ATOMS - 1)
/** Maximal No. of samples in read(request) */
#define LLRF_MAX_SAMPLES (2*1024*1024)
/** Libera Low Level RF Data on Demand (DD) atom */
/* NOTE: The size of libera_atom_dd_t structure is important.
* The minimal lenght of libera_atom_dd_t is 4 bytes and it must be
* integer (4-byte) aligned!
*/
typedef struct {
libera_sample_t sample[LIBERA_DD_ATOM_SAMPLES];
} libera_atom_dd_t;
/* Libera LLRF ADC-rate Data (ADC) atom */
/* NOTE: The size of libera_atom_adc_t structure is important.
* The minimal lenght of libera_atom_adc_t is 4 bytes and it must be
* integer (4-byte) aligned!
*/
typedef void* libera_atom_adc_t; // Unused
/** Libera Low Level RF Slow Acquisition (SA) atom */
/* NOTE: The size of libera_atom_sa_t structure is important.
* PAGE_SIZE MUST be a multiple of sizeof(libera_atom_sa_t) for proper
* buffer wrapping. Pad this structure to the nearest common
* denominator of PAGE_SIZE and sizeof(libera_atom_sa_t).
* The minimal lenght of libera_atom_sa_t is 4 bytes and it must be
* integer (4-byte) aligned!
*/
typedef struct {
/* 4 amplitudes */
libera_S32_t Va, Vb, Vc, Vd;
/* 4 synthetic values -> X, Y, Q & Sum */
libera_S32_t X, Y, Q, Sum;
/* Cx and Cy for FF */
libera_S32_t Cx, Cy;
/* 6 values reserved for future use */
libera_S32_t reserved[6];
} libera_atom_sa_t;
#endif // _LLRF_H_
// $Id: bbfp.h,v 1.1 2006/03/08 07:58:42 miha Exp $
//! \file bbfp.h
//! Declares BBFP specific functions and classes.
#if !defined(_SRV_BBFP_H)
#define _SRV_BBFP_H
#include "cspi.h"
#include "transform.h"
typedef CSPI_CONPARAMS_DD SUPER_CONPARAMS;
//--------------------------------------------------------------------------
// return sizeof a CSPI_CONPARAMS-derived structure
inline size_t sizeof_conparams(CSPI_BITMASK flags) {
return flags & CSPI_CON_STEP ?
sizeof(CSPI_CONPARAMS_DD) : sizeof(CSPI_CONPARAMS);
}
//--------------------------------------------------------------------------
inline SUPER_CONPARAMS& ntoh(SUPER_CONPARAMS& obj)
{
typedef SUPER_CONPARAMS composite_type;
typedef uint32_t base_type;
return transform<composite_type,base_type>(obj, ntoh);
}
//--------------------------------------------------------------------------
inline SUPER_CONPARAMS& hton(SUPER_CONPARAMS& obj)
{
typedef SUPER_CONPARAMS composite_type;
typedef uint32_t base_type;
return transform<composite_type,base_type>(obj, hton);
}
//--------------------------------------------------------------------------
// return data_traits object for connection hcon
const basic_traits* mktraits(int mode)
{
ASSERT(CSPI_MODE_DD == mode);
static const data_traits<CSPI_DD_RAWATOM, CSPI_DD_RAWATOM> dd_traits;
return &dd_traits;
}
#endif // _SRV_BBFP_H
// $Id: client-lib.h,v 1.12 2006/03/01 10:56:41 miha Exp $
//! \file client-lib.h
//! Main header file for the CSPI client library.
#if !defined(_CLIENT_LIB_H)
#define _CLIENT_LIB_H
#include "cspi.h"
#include "protocol.h" // SERVER_... request codes
#include "client-proxy.h"
#endif // _CLIENT_LIB_H
// $Id: client-notify.h,v 1.3 2006/03/01 10:56:41 miha Exp $
//! \file client-notify.h
//! Header file for CSPI client library event receive and
//! dispatch mechanism.
#if !defined(_CLIENT_NOTIFY_H)
#define _CLIENT_NOTIFY_H
#include <list>
#include <algorithm>
#include <functional>
#include "cspi.h"
#include "lock.h"
// fdw decl
class subscriber_list;
// declare one and only event subscriber list
extern subscriber_list _list;
//--------------------------------------------------------------------------
/* Start event thread.
* On success, returns 0. On error, returns error code.
*/
int multicast_connect( const char *mcast_addr, int mcast_port );
//--------------------------------------------------------------------------
/* Stop event thread.
* Call after multicast_connect() to perform cleanup.
*/
void multicast_disconnect();
//--------------------------------------------------------------------------
// event subscriber
class subscriber {
public:
subscriber() : handle(0) {
std::memset(&params, 0, sizeof(params));
}
subscriber(CSPIHCON _handle, const CSPI_CONPARAMS *_params)
: handle(_handle) {
std::memcpy(&params, _params, sizeof(params));
}
~subscriber(){}
CSPIHCON handle;
CSPI_CONPARAMS params;
};
//--------------------------------------------------------------------------
class subscriber_list {
protected:
typedef std::list<subscriber> list_type;
list_type list;
mutex list_mutex;
public:
subscriber_list() {}
~subscriber_list() {}
// delete all subscribers
void clear() {
auto_lock<mutex> lock(list_mutex);
list.clear();
}
// find a subscriber
subscriber* find(CSPIHCON handle) {
auto_lock<mutex> lock(list_mutex);
list_type::iterator p;
p = std::find_if(list.begin(),
list.end(),
std::bind2nd(equal_to(),handle));
return p != list.end() ? &(*p) : 0;
}
// add new subscriber
void subscribe(CSPIHCON handle, CSPI_CONPARAMS *params) {
auto_lock<mutex> lock(list_mutex);
list.push_back(subscriber(handle, params));
}
// remove existing subscriber
void unsubscribe(CSPIHCON handle) {
auto_lock<mutex> lock(list_mutex);
list_type::iterator p;
p = std::find_if(list.begin(),
list.end(),
std::bind2nd(equal_to(),handle));
if (p != list.end()) {
list.erase(p);
}
}
// dispatch event to all subscribers
void dispatch(const CSPI_EVENTHDR& hdr) {
auto_lock<mutex> lock(list_mutex);
if (!list.empty()) {
CSPI_EVENT msg;
std::memcpy(&msg, &hdr, sizeof(CSPI_EVENTHDR));
for (list_type::iterator p=list.begin(); p!=list.end(); ++p) {
const CSPI_CONPARAMS *q = &p->params;
if (hdr.id & q->event_mask) {
msg.user_data = q->user_data;
if (q->handler && !q->handler(&msg)) break;
}
}
}
}
protected:
struct equal_to
: public std::binary_function<subscriber, CSPIHCON, bool> {
bool operator() (const subscriber& obj, CSPIHCON handle) const {
return obj.handle == handle;
}
};
};
#endif // _CLIENT_NOTIFY_H
// $Id: client-proxy.h,v 1.3 2006/03/15 09:04:45 miha Exp $
//! \file client-proxy.h
//! Header file for the CSPI client library.
#if !defined(_CLIENT_PROXY_H)
#define _CLIENT_PROXY_H
extern "C"
{
#include <netinet/in.h> // in_port_t
}
//--------------------------------------------------------------------------
/** Open connection to a Libera server. This is a
* server extension with no real CSPI counterpart.
* Return 0 on success, or -1 if an error occurred.
* The errno is set appropriately.
* If any of the port, mcast_addr or mcast_port is 0, a
* default value is used instead.
* @param addr Server IP address.
* @param port Server port.
* @param mcast_addr Multicast group address to join to.
* @param mcast_port Not implemented (must be 0).
*/
int server_connect(const char *addr, in_port_t port,
const char *mcast_addr, in_port_t mcast_port);
/** Closes open connection to Libera server. This is a
* server extension with no real CSPI counterpart.
* Returns 0 on success, or -1 if an error occurred.
* The errno is set appropriately.
*/
int server_disconnect();
/** No operation (NOOP). This is a server extension with no
* real CSPI counterpart.
* On success, returns 0. On error, returns -1. The errno
* is set appropriately.
*/
int server_noop();
/** Manipulates server-specific parameters. This is a server extension
* with no real CSPI counterpart.
* On success, returns 0. On error, returns < 0:
* -1 (the errno is set appropriately),
* SRV_E_PROTO,
* SRV_E_INVAL.
* @param code Parameter code (request code). See SERVER_PARAMS
* definition for a list of possible values.
* @param val Untyped pointer to a variable with request code
* specific value. The type of the variable depends on
* the request code:
* ---------------------------------------------------------
* code | type | value description
* ---------------------------------------------------------
* SERVER_CACHE_SIZE | integer | cache size in samples
* SERVER_CACHE_LOCK | integer | unlock if 0, lock otherwise
* ---------------------------------------------------------
*/
int server_setparam(int code, const void *val);
/** Retrieves server-specific parameter value. This is a server
* extension with no real CSPI counterpart.
* See server_setparam for description of return values and
* function arguments.
*/
int server_getparam(int code, void *val);
#endif // _CLIENT_PROXY_H
// $Id: debug.h,v 1.2 2006/03/01 10:56:41 miha Exp $
//! \file debug.h
//! Debugging macros and declarations.
#if !defined(_DEBUG_H)
#define _DEBUG_H
extern "C"
{
#include <syslog.h>
}
#if defined( DEBUG )
#include <cassert>
#endif // DEBUG
//--------------------------------------------------------------------------
// Debugging.
#if !defined(DEBUG)
#define DEBUG 0
#endif
#if DEBUG // defined(DEBUG) && DEBUG>0
#define ASSERT(f) assert(f)
#define VERIFY(f) ASSERT(f)
#define DEBUG_ONLY(f) (f)
#else // DEBUG
#define ASSERT(f) ((void)0)
#define VERIFY(f) ((void)(f))
#define DEBUG_ONLY(f) ((void)0)
#endif // !DEBUG
//--------------------------------------------------------------------------
#if DEBUG < 3
#define DEBUG_ONLY_3(f) ((void)0)
#else
#define DEBUG_ONLY_3(f) (f)
#endif
#if DEBUG < 2
#define DEBUG_ONLY_2(f) ((void)0)
#else
#define DEBUG_ONLY_2(f) (f)
#endif
#if DEBUG < 1
#define DEBUG_ONLY_1(f) ((void)0)
#else
#define DEBUG_ONLY_1(f) (f)
#endif
#define DEBUG_ONLY_0(f) (f)
//--------------------------------------------------------------------------
// The `##' token paste operator has a special meaning when placed between
// a comma and a variable argument. If you write
// #define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
// and the variable argument is left out when the eprintf macro is used,
// then the comma before the `##' will be deleted.
// This does not happen if you pass an empty argument, nor does it happen
// if the token preceding `##' is anything other than a comma.
/** Send crtitical message to the system logger. */
#define _LOG_CRIT( format, ... ) \
DEBUG_ONLY_0( syslog( LOG_ERR, format, ##__VA_ARGS__ ) )
/** Send error message to the system logger. */
#define _LOG_ERR( format, ... ) \
DEBUG_ONLY_1( syslog( LOG_ERR, format, ##__VA_ARGS__ ) )
/** Send warning message to the system logger. */
#define _LOG_WARNING( format, ... ) \
DEBUG_ONLY_1( syslog( LOG_WARNING, format, ##__VA_ARGS__ ) )
/** Send normal, but significant message to the system logger. */
#define _LOG_NOTICE( format, ... ) \
DEBUG_ONLY_2( syslog( LOG_NOTICE, format, ##__VA_ARGS__ ) )
/** Send informational message to the system logger. */
#define _LOG_INFO( format, ... ) \
DEBUG_ONLY_2( syslog( LOG_INFO, format, ##__VA_ARGS__ ) )
/** Send debug-level message to the system logger. */
#define _LOG_DEBUG( format, ... ) \
DEBUG_ONLY_3( syslog( LOG_DEBUG, format, ##__VA_ARGS__ ) )
//--------------------------------------------------------------------------
/** Dumps expression to STDERR.
* This macro is only available in DEBUG build.
* Takes a format string as used in the run-time function printf.
*/
#define TRACE( f ) DEBUG_ONLY( fprintf( stderr, f ) )
/** Same as TRACE, but takes a format string plus one argument
* (one variable that is dumped to STDERR).
*/
#define TRACE1( f, p ) DEBUG_ONLY( fprintf( stderr, f, p ) )
/** Same as TRACE, but takes a format string plus two arguments
* (two variables that are dumped to STDERR).
*/
#define TRACE2( f, p, q ) DEBUG_ONLY( fprintf( stderr, f, p, q ) )
/** Same as TRACE, but takes a format string plus three arguments
* (three variables that are dumped to STDERR).
*/
#define TRACE3( f, p, q, r ) DEBUG_ONLY( fprintf( stderr, f, p, q, r ) )
//--------------------------------------------------------------------------
#define DUMP_HEADER(h) \
"{magic=%u, cmd=%u, status=%d, cmd_val=%u, req_val=%u, data_size=%u}", \
h->magic, \
h->cmd, \
h->status, \
h->cmd_val, \
h->req_val,\
h->data_size
//--------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
//...
#ifdef __cplusplus
}
#endif
#endif // DEBUG_H
// $Id: ebpp.h,v 1.1 2006/03/01 10:37:48 miha Exp $
//! \file ebpp.h
//! Declares EBPP specific functions and classes.
#if !defined(_SRV_EBPP_H)
#define _SRV_EBPP_H
#include "cspi.h"
#include "transform.h"
typedef CSPI_CONPARAMS_DD SUPER_CONPARAMS;
//--------------------------------------------------------------------------
// return sizeof a CSPI_CONPARAMS-derived structure
inline size_t sizeof_conparams(CSPI_BITMASK flags) {
return flags & CSPI_CON_DEC ?
sizeof(CSPI_CONPARAMS_DD) : sizeof(CSPI_CONPARAMS);
}
//--------------------------------------------------------------------------
inline SUPER_CONPARAMS& ntoh(SUPER_CONPARAMS& obj)
{
typedef SUPER_CONPARAMS composite_type;
typedef uint32_t base_type;
return transform<composite_type,base_type>(obj, ntoh);
}
//--------------------------------------------------------------------------
inline SUPER_CONPARAMS& hton(SUPER_CONPARAMS& obj)
{
typedef SUPER_CONPARAMS composite_type;
typedef uint32_t base_type;
return transform<composite_type,base_type>(obj, hton);
}
//--------------------------------------------------------------------------
// return data_traits object for connection hcon
const basic_traits* mktraits(int mode)
{
if (CSPI_MODE_ADC == mode) {
static const data_traits<CSPI_ADC_ATOM, short> adc_traits;
return &adc_traits;
}
ASSERT(CSPI_MODE_DD == mode || CSPI_MODE_PM == mode);
static const data_traits<CSPI_DD_ATOM, int> dd_traits;
return &dd_traits;
}
#endif // _SRV_EBPP_H
// $Id: error.h,v 1.9 2006/03/06 14:21:58 miha Exp $
//! \file error.h
//! Declares error handling functions, classes and debugging macros
//! common to all application modules.
#if !defined(_ERROR_H)
#define _ERROR_H
#include <cerrno>
#include <string>
#include <exception>
#define SYS_ERROR(what) \
sys_error(what, __FILE__, __FUNCTION__, __LINE__)
#define PTHREAD_ERROR(what,retval) \
sys_error(what, __FILE__, __FUNCTION__, __LINE__, retval)
#define CSPI_ERROR(what) \
cspi_error(what, __FILE__, __FUNCTION__, __LINE__)
//--------------------------------------------------------------------------
// generic server errors start at SRV_E_FIRST to avoid conflicts with CSPI
enum {
SRV_E_FIRST = -128,
SRV_E_PROTO, // protocol mismatch
SRV_E_INVAL, // invalid argument
SRV_E_LAST
};
//--------------------------------------------------------------------------
// thrown to force program to terminate
struct force_exit {
explicit force_exit(int val) throw() : status(val) {}
~force_exit() throw() {}
int status;
};
//--------------------------------------------------------------------------
// thrown to terminate connection
class protocol_error : public std::exception
{
public:
protocol_error() throw() {}
~protocol_error() throw() {}
};
//--------------------------------------------------------------------------
// system call error, togehther with location in code
class sys_error : public std::exception
{
public:
explicit
sys_error(const char *what,
const char *file,
const char *function,
int line,
int retval = errno);
~sys_error() throw() {}
virtual const char* what() const throw() { return str.c_str(); }
private:
std::string str;
};
//--------------------------------------------------------------------------
// cspi error, together with location in code
class cspi_error : public std::exception
{
public:
explicit
cspi_error(int what,
const char *file,
const char *function,
int line);
~cspi_error() throw() {}
virtual const char* what() const throw() { return str.c_str(); }
private:
std::string str;
};
#endif // _ERROR_H
This diff is collapsed.
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