#ifndef _BLDDATA_H_ #define _BLDDATA_H_ //#include "BLDMCast.h" /** * BLDData.h * * Definition of BLD data packets (header and payloads) */ #include #include #include #include #ifdef __cplusplus extern "C" { #endif typedef union Endianness { epicsUInt16 test; struct { epicsUInt8 little, big; } is; } Endianness; typedef epicsUInt32 __u32_a __attribute__((may_alias)); static __inline__ __u32_a __le32(__u32_a v) { Endianness endian = {test:1}; if ( endian.is.big ) { __u32_a m = 0x00ff00ff; v = ((v&m)<<8) | ((v>>8)&m); v = (v<<16) | (v>>16); } return v; } static __inline__ __u32_a __ld_le32(__u32_a *p) { __u32_a v; #ifdef __PPC__ Endianness endian = {test:1}; if ( endian.is.big ) { __asm__ __volatile__("lwbrx %0,%y1":"=r"(v):"Z"(*p)); } else #endif v = __le32(*p); return v; } static __inline__ void __st_le32(__u32_a *p, __u32_a v) { #ifdef __PPC__ Endianness endian = {test:1}; if ( endian.is.big ) { __asm__ __volatile__("stwbrx %1,%y0":"=Z"(*p):"r"(v)); } else #endif *p = __le32(v); } typedef union Flt64_LE_ { __u32_a u[2]; epicsFloat64 d; } Flt64_LE; typedef __u32_a Uint32_LE; /* This is optimized for PPC where FP registers * cannot be manipulated nor copied to integer registers * directly but must be written to memory first. * Hence, to byte-swap we must write the FP register * to memory first, read back into integer registers, * swap and write to memory again. */ static __inline__ void __st_le64(Flt64_LE *p, double v) { Endianness endian = {test:1}; p->d = v; if ( endian.is.big ) { __u32_a tmp; tmp = p->u[1]; __st_le32(p->u+1,p->u[0]); __st_le32(p->u, tmp); } } static __inline__ double __ld_le64(Flt64_LE *p) { Endianness endian = {test:1}; if ( endian.is.big ) { Flt64_LE tmp; __st_le32(tmp.u+1,p->u[0]); __st_le32(tmp.u ,p->u[1]); return tmp.d; } return p->d; } #ifdef __cplusplus } #endif /** * BLD Header */ /** * Structure defined in this document: * https://confluence.slac.stanford.edu/download/attachments/10256639/bldicd.pdf */ typedef struct BLDHeader { Uint32_LE tv_sec; Uint32_LE tv_nsec; Uint32_LE mbz1; /* must be zero */ Uint32_LE fiducialId; Uint32_LE mbz2; /* must be zero */ /* Xtc Section 1 */ Uint32_LE damage; Uint32_LE logicalId; /* source 1 */ Uint32_LE physicalId; /* source 2 */ Uint32_LE dataType; /* Contains - this is the version field */ Uint32_LE extentSize; /* Extent - size of data following Xtc Section 2 */ /* Xtc Section 2 */ Uint32_LE damage2; Uint32_LE logicalId2; Uint32_LE physicalId2; Uint32_LE dataType2; Uint32_LE extentSize2; /* Extent - size of data following Xtc Section 2 */ } BLDHeader; /** * EBeam Data */ typedef struct BLDEBeam { unsigned int uDamageMask; double ebeamCharge; /* in nC */ double ebeamL3Energy; /* in MeV */ double ebeamLTUPosX; /* in mm */ double ebeamLTUPosY; /* in mm */ double ebeamLTUAngX; /* in mrad */ double ebeamLTUAngY; /* in mrad */ double ebeamBC2Current; /* in Amps */ double ebeamBC2Energy; /* in mm */ double ebeamBC1Current; /* in Amps */ double ebeamBC1Energy; /* in mm */ double ebeamUndPosX; /* in mm */ double ebeamUndPosY; /* in mm */ double ebeamUndAngX; /* in mrad */ double ebeamUndAngY; /* in mrad */ double ebeamXTCAVAmpl; /* in MeV */ double ebeamXTCAVPhase; /* in deg */ double ebeamDMP502Charge; /* in Nel */ } BLDEBeam; /** * Phase Cavity Data */ typedef struct BLDPhaseCavity { double fitTime1; /* in pico-seconds */ double fitTime2; /* in pico-seconds */ double charge1; /* in pico-columbs */ double charge2; /* in pico-columbs */ } BLDPhaseCavity; /** * Gas Detector Data */ typedef struct BLDGasDetector { double f_11_ENRC; /* in mJ */ double f_12_ENRC; /* in mJ */ double f_21_ENRC; /* in mJ */ double f_22_ENRC; /* in mJ */ } BLDGasDetector; #endif