#ifndef DRV_BPM_COMMON_H #define DRV_BPM_COMMON_H /* $Id: drvBpm.h,v 1.15 2013/03/12 14:44:01 strauman Exp $ */ #include #include #include #include #include #undef __STRICT_ANSI__ #include #ifdef __cplusplus extern "C" { #endif /* obtain last values */ #ifndef PI #define PI 3.1415926535897932385 #endif #define RAD ((PI)/180.0) /* We calculate single-precision for now */ typedef float BpmNumber; typedef epicsTimeStamp TimeStamp; #define BPM_NUM_VALS 4 #define NUM_DATA_KINDS 3 /* Error stati can be OREd */ #define BPM_AMPL_OK 0 /* Overrange detected */ #define BPM_AMPL_OVR(i) (1<<(i)) #define BPM_AMPL_OVR_MSK (((1<=0 ? (BPM_AMPL_OVR(0)<<(chnl)) : 0) \ | (chnl >=0 ? (BPM_AMPL_UDR(0)<<(chnl)) : 0) ) #define BPM_AMPL_TIMEDOUT (1<<(2*BPM_NUM_VALS + 0)) #define BPM_AMPL_INVALID (1<<(2*BPM_NUM_VALS + 1)) /* #define BPM_AMPL_SKIPPED (1<<(2*BPM_NUM_VALS + 2)) #define BPM_AMPL_OLD (2<<(2*BPM_NUM_VALS + 3)) #define BPM_AMPL_SEQMSK (3<<(2*BPM_NUM_VALS + 4)) */ typedef struct BpmRawAmplitudesRec_ { BpmNumber vals[BPM_NUM_VALS*2]; uint32_t status; TimeStamp timeStamp; uint8_t pad[(1<<6)-sizeof(TimeStamp) - 8*sizeof(BpmNumber) - sizeof(uint32_t)]; } BpmRawAmplitudesRec, *BpmRawAmplitudes; /* Do NOT access these buffers directly; only exported * so that the inline routine may operate on it. */ extern BpmRawAmplitudesRec ampBuffers[MAX_BPM]; #define BPM_PARM_UDR_THRESHOLD (drvBpmParms[0]) #define NUM_BPM_PARMS 1 extern BpmNumber drvBpmParms[NUM_BPM_PARMS][MAX_BPM]; static __inline__ BpmRawAmplitudes bpmRawAmplitudesAlloc(unsigned chnl) { return &Buffers[chnl]; } static __inline__ int bpmRawAmplitudesPut(unsigned channel, BpmRawAmplitudes a, int overwrite) { return 0; } void bpmWatchdog(int channel, int kind, void *closure); #define ENC_ST_SVR(st,svr) ((((st)&0xff)<<8) | ((svr)&0xff)) #define STAT_NO_CVT (1<<16) /* Return no_convert << 16 | (alarm << 8) | (severity) */ static __inline__ long drvBpm_map_status(uint32_t hw_stat, uint32_t omsk, uint32_t umsk) { long err = 0; /* map status bits into alarm */ if ( hw_stat ) { if ( hw_stat & BPM_AMPL_RNG_MSK(-1) ) { err = ENC_ST_SVR(READ_ALARM, INVALID_ALARM); } else if ( hw_stat & omsk ) { err = ENC_ST_SVR(HW_LIMIT_ALARM, MAJOR_ALARM); } else if ( hw_stat & umsk ) { err = ENC_ST_SVR(LOLO_ALARM, MAJOR_ALARM); } } return err; } /* * Return 0 on success, (epics_alarm<<8) | (epics_severity) on failure * or value < 0 in which case the record alarm/severity will be set * to READ_ALARM/INVALID_ALARM */ typedef long (*DrvBpm_read_raw_ai_cb)(aiRecord *pai, TimeStamp *pts, unsigned c, unsigned s); long drvBpm_read_raw_ai_helper(aiRecord *pai, DrvBpm_read_raw_ai_cb cb); long drvBpm_read_raw_ai(aiRecord *pai); typedef long (*DrvBpm_init_raw_ai_cb)(aiRecord *pai, unsigned c, unsigned s); long drvBpm_init_raw_ai_helper(aiRecord *pai, DrvBpm_init_raw_ai_cb cb); /* NULL callback doing nothing */ long drvBpm_init_raw_ai_generic(void *precord); long drvBpm_read_raw_stat(longinRecord *pli); long drvBpm_init_raw_stat(void *record_p); long drvBpm_init_raw_ai(aiRecord *pai); /* This is a kludge -- do NOT use these variables. * Have to find a way for stripline BPMs to access * this. */ extern BpmNumber bpmCosPsi[MAX_BPM]; /* calculate position from 'u', 'v', 't' and * store results in internal (hidden) buffer; * the 'quality/status' of the data are passed * in 'raw_status' which encodes a bit-set of * the BPM_AMPL_xxx stati defined above. * * RETURNS: zero on success; nonzero on error. */ long drvBpmCalcPos( unsigned chan, BpmNumber u, BpmNumber v, BpmNumber t, uint32_t raw_status, BpmNumber pinc, TimeStamp *p_ts ); /* Check for MPS violations during last cycle and * re-arm this check. This routine is intended to * be executed from the fiducial callback. */ uint32_t drvBpmMpsPoll(void); /* Throw away old, partially filled group container * and allocate a new one. * This routine is called by fiducial processing when * an overrun is detected (consequence of at least one channel * missing from a group so that it could not be sent). */ void drvBpmPurgeFcomGroup(void); #ifdef __cplusplus }; #endif #endif