/*============================================================================= Name: devLonginPll.c Abs: Device support for LCLS Phase locked loop module (Arcturus Coldfire 5282 processor with LTC2208 ADC) longin records. Derived from $EPICS/base/src/rec/longinRecord.c Auth: 16-nov-2005, Dayle Kotturi (dayle): Initial version for LLRF PAD -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 28-jan-2008, Dayle Kotturi: Adaptation for LLRF PLL 14-feb-2008, Dayle Kotturi: New routines to do more stuff =============================================================================*/ #include #include #include #include "alarm.h" #include "cvtTable.h" #include "dbDefs.h" #include "devLib.h" #include "dbAccess.h" #include "recSup.h" #include "callback.h" #include "devSup.h" #include "dbScan.h" /* for SCAN_IO_EVENT */ #include "link.h" #include "longinRecord.h" /* for longinRecord structure */ #include "epicsExport.h"/* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "drvPll.h" /* for pll* */ #include "pllChannel.hxx" typedef struct liPll_s { int routine; int channel; int sample; } liPll_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_write; } LONGDSET; #ifdef DEBUG_PRINT int devLonginPllFlag = 2; #endif LOCAL long init_longin(); LOCAL long longin_ioinfo(); LOCAL long read_longin(); LONGDSET devLonginPll = {5, NULL, NULL, init_longin, longin_ioinfo, read_longin}; epicsExportAddress(dset, devLonginPll); /* these are used to locate where the initdata and bss sections have loaded */ int known_initdata = 12; /* force data to init data */ int known_bss; /* allow to go to bss */ LOCAL long init_longin(struct longinRecord *plongin) { liPll_t *plip; /* Allocate the memory for this records private data structure */ plip = (liPll_t *) malloc(sizeof(liPll_t)); if (plip == NULL) { DEBUGPRINT(DP_ERROR, devLonginPllFlag, ("init_longin: %s: out of memory\n", plongin->name)); return S_dev_noMemory; } /* Tell the record about its private data structure */ plongin->dpvt = plip; switch(plongin->inp.type) { case(INST_IO): DEBUGPRINT(DP_INFO, devLonginPllFlag, ("init_longin: %s: has parm: %s\n", plongin->name, plongin->inp.value.instio.string)); sscanf(plongin->inp.value.instio.string, "%d %d %d", &(plip->routine), &(plip->channel), &(plip->sample)); /* NB: "sample" is read in for all longin records, but only used for PAD_BPH. Doing it this way, means the same PVs for the sample size and offset can be use regardless of the number of samples actually in use. */ DEBUGPRINT(DP_INFO, devLonginPllFlag, ("init_longin: %s's dpvt has routine: %d and channel: %d\n", plongin->name, plip->routine, plip->channel)); break; default: DEBUGPRINT(DP_ERROR, devLonginPllFlag, ("init_longin: %s: illegal INP field: %d\n", plongin->name, (int) plongin->inp.type)); break; } return 0; } LOCAL long longin_ioinfo( int cmd, struct longinRecord *plongin, IOSCANPVT *ppvt ) { *ppvt = pllGetIoScanPvt(); return 0; } LOCAL long read_longin(struct longinRecord *plongin) { liPll_t *plip; /* Set this to facilitate easy access to routine field */ plip = (liPll_t *)plongin->dpvt; switch(plip->routine) { case 0: plongin->val = pllGetAverageTrackingError(); break; case 1: plongin->val = pllGetCoarseTracking(); break; case 2: plongin->val = pllGetAverageSampleError(); break; case 3: plongin->val = pllGetSampleVariance(); break; case 6: plongin->val = pllGetIntrCount(); break; case 7: plongin->val = pllGetScanIOCount(); break; case 10: plongin->val = (long) &known_initdata; break; case 11: plongin->val = (long) &known_bss; break; case 12: plongin->val = pllGetSerialNumber(); break; default: plongin->udf = 1; return ERROR; } DEBUGPRINT(DP_INFO, devLonginPllFlag, ("read_longin: %s: val is: %d\n", plongin->name, (int) plongin->val)); return OK; }