/* $Id: devAoBpmMpsThres.c,v 1.3 2012/11/29 00:43:54 strauman Exp $ */ #include #include #include #include #include #include #include #include #define NumberOfEls(arr) (sizeof(arr)/sizeof(arr[0])) static long report(int level) { epicsPrintf("devAoBpmMpsThres: write MPS thresholds from VAL to memory cache\n"); return 0; } static long init_record(struct aoRecord *pao) { char deflt = 'X'; char *p; int c,s; if ( VME_IO != pao->out.type ) { epicsPrintf("devAoBpmMpsThres: ERROR - OUT link is not of type VME_IO\n"); goto bail; } c = pao->out.value.vmeio.card; s = pao->out.value.vmeio.signal; if ( 0 > c || NumberOfEls(drvBpmMpsLolo) <= c ) { epicsPrintf("devAoBpmMpsThres: ERROR - OUT link 'card' # (%i) out of range\n", c); goto bail; } if ( 0 > s || NumberOfEls(drvBpmMpsLolo[0]) <= s ) { epicsPrintf("devAoBpmMpsThres: ERROR - OUT link 'signal' # (%i) out of range\n", s); goto bail; } if ( ! (p = pao->out.value.vmeio.parm) ) p = &deflt; switch (toupper((int)*p)) { default: epicsPrintf("devAoBpmMpsThres: ERROR - OUT link 'parm' needs to be 'Hi' or 'Lo'\n"); goto bail; case 'H': pao->dpvt = & drvBpmMpsHihi[c][s]; break; case 'L': pao->dpvt = & drvBpmMpsLolo[c][s]; break; } /* A paranoia check */ if ( sizeof(DrvBpmMpsThresVal) != sizeof(drvBpmMpsLolo[0][0]) ) { epicsPrintf("devAoBpmMpsThres: FATAL ERROR - SIZE MISMATCH\n"); errlogFlush(); abort(); } pao->udf = FALSE; return 2; /* No convert */ bail: pao->pact = TRUE; return -1; } static long write_ao(struct aoRecord *pao) { /* ASSUME: writes to 'double' (and reads) are ATOMIC * so that we don't need to bother with synchronization. * This should only be an issue if memory is misaligned * or the CPU operates with soft-float. * We assume neither of these apply and the access happens * with a single instruction. */ *(DrvBpmMpsThresVal*)pao->dpvt = pao->val; return 0; } static struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write; DEVSUPFUN special_linconv; } devAoBpmMpsThres = { 6, (DEVSUPFUN) report, 0, (DEVSUPFUN) init_record, 0, (DEVSUPFUN) write_ao, 0 }; epicsExportAddress(dset,devAoBpmMpsThres);