/*============================================================================= Name: devBoPll.c Abs: Device support for LCLS Phase locked loop module (Arcturus Coldfire 5282 processor with LTC2208 ADC) binary out records. Derived from $EPICS/base/src/rec/boRecord.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, Robert Steele: Adaptation for LLRF PLL =============================================================================*/ #include #include #include #include "alarm.h" #include "dbDefs.h" #include "dbAccess.h" #include "recGbl.h" #include "recSup.h" #include "devLib.h" #include "devSup.h" #include "boRecord.h" #include "epicsExport.h" #include #include "pllChannel.hxx" #include typedef struct boPll_s { int routine; } boPll_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write; } BODSET; #ifdef DEBUG_PRINT int devBoPllFlag = DP_ERROR; #endif LOCAL long init_bo(); LOCAL long write_bo(); BODSET devBoPll = { 5, NULL, NULL, init_bo, NULL, write_bo }; epicsExportAddress(dset,devBoPll); static long init_bo(boRecord *pbo) { boPll_t *pbop; long rc =0; /* Allocate the memory for this records private data structure */ pbop = (boPll_t *) malloc(sizeof(boPll_t)); if (pbop == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devBoPllFlag, ("init_longout: %s: out of memory\n", pbo->name)); #endif return S_dev_noMemory; } DEBUGPRINT(DP_INFO, devBoPllFlag, ("init_bo: %s: has initial value: %d\n", pbo->name, pbo->val)); /* Read the DBLINK "out" field to get the routine */ DEBUGPRINT(DP_INFO, devBoPllFlag, ("init_bo: %s: has parm: %s\n", pbo->name, pbo->out.value.instio.string)); sscanf(pbo->out.value.instio.string, "%d", &(pbop->routine)); DEBUGPRINT(DP_INFO, devBoPllFlag, ("init_bo: %s's dpvt has routine: %d\n", pbo->name, pbop->routine)); /* Tell the record about its private data structure */ pbo->dpvt = pbop; /* dont convert */ rc=2; return rc; } static long write_bo(boRecord *pbo) { long rc = 0; boPll_t *pbop; /* Set this to facilitate easy access to index field */ if (pbo->dpvt == NULL) { DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: dpvt is NULL\n", pbo->name)); return ERROR; } pbop = (boPll_t *)pbo->dpvt; switch (pbop->routine) { case 0: /* routine 0 disables/enables interrupts when val is 0/1 */ switch (pbo->val) { case 0: rc = pllDisableIntr(); DEBUGPRINT(DP_INFO, devBoPllFlag, ("write_bo: %s: disabling interrupts\n", pbo->name)); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: unable to disable interrupts\n", pbo->name)); } /*pbo->sevr = INVALID; or something */ break; case 1: rc = pllEnableIntr(); DEBUGPRINT(DP_INFO, devBoPllFlag, ("write_bo: %s: enabling interrupts\n", pbo->name)); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: unable to enable interrupts\n", pbo->name)); /* pbo->sevr = INVALID; or something */ } break; default: rc = ERROR; DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: unrecognized value in bo record: %d\n", pbo->name, (int) pbo->val)); /* pbo->sevr = INVALID; or something */ break; } break; case 1: pllSoftTrigger(); DEBUGPRINT(DP_INFO, devBoPllFlag, ("write_bo: %s: triggering software interrupt\n", pbo->name)); break; case 2: switch (pbo->val) { case 0: break; case 1: pllRawWaveformRequest(); pbo->val = 0; break; default: rc = ERROR; DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: unrecognized value in bo record: %d\n", pbo->name, (int) pbo->val)); /* pbo->sevr = INVALID; or something */ } break; case 3: switch (pbo->val) { case 0: DEBUGPRINT(DP_INFO, devBoPllFlag, ("write_bo: %s: buffer request cleared\n", pbo->name)); break; case 1: pllBufferRequest(); DEBUGPRINT(DP_INFO, devBoPllFlag, ("write_bo: %s: buffer request set\n", pbo->name)); pbo->val = 0; break; default: rc = ERROR; DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: unrecognized value in bo record: %d\n", pbo->name, (int) pbo->val)); /* pbo->sevr = INVALID; or something */ } case 4: if ( pbo->val == 1 ) { printf( "REBOOTING by request\n" ); rtems_shutdown_executive( 0 ); /* return should not happen */ } break; case 5: /* hardware print */ pllhw_print(); break; default: rc = ERROR; DEBUGPRINT(DP_ERROR, devBoPllFlag, ("write_bo: %s: unrecognized routine in bo record: %d\n", pbo->name, (int) pbop->routine)); break; } return rc; }