#include #include #include #include #include #include #include #include #include #include #include static long SUCCESS = 0; static long ERROR = -1; #undef DEBUG #define NCAVS 8 long asub_cryo_init(struct aSubRecord *asub_p) { if( asub_p == NULL) return ERROR; epicsUInt32 *inelm = &(asub_p->noa); epicsEnum16 *itype = &(asub_p->fta); epicsUInt32 *onelm = &(asub_p->nova); epicsEnum16 *otype = &(asub_p->ftva); int i; for ( i = 0 ; i < NCAVS ; i++ ) { if ( *inelm != 1 ) { epicsPrintf("%s asub_cryo_init: input %i allocated " "%i elements but should be 1\n", asub_p->name, i, *inelm); return ERROR; } if ( *itype != menuFtypeDOUBLE ) { epicsPrintf("%s asub_cryo_init: input %i type is %i " "but should be %i\n", asub_p->name, i, *itype, menuFtypeDOUBLE); return ERROR; } if ( *onelm != 1 ) { epicsPrintf("%s asub_cryo_init: output %i allocated " "%i elements but should be 1\n", asub_p->name, i, *onelm); return ERROR; } if ( *otype != menuFtypeDOUBLE ) { epicsPrintf("%s asub_cryo_init: output %i type is %i " "but should be %i\n", asub_p->name, i, *otype, menuFtypeDOUBLE); return ERROR; } inelm++; itype++; onelm++; otype++; } return SUCCESS; } long asub_cryo(struct aSubRecord *asub_p) { if( asub_p == NULL) return SUCCESS; /* if firmware watchdog fault, return ERROR */ /* gradient values, in, out, and last out */ double **in_p = (double **)&asub_p->a, **out_p = (double **)&asub_p->vala, **out_last_p = (double **)&asub_p->ovla; /* mask of valid gradient and heartbeat counters */ epicsUInt32 *valid = (epicsUInt32 *)asub_p->vali, *valid_last = (epicsUInt32 *)asub_p->ovli, *hb = (epicsUInt32 *)asub_p->valj, *hb_last = (epicsUInt32 *)asub_p->ovlj; /* read gradient severity */ DBLINK *link_p = (DBLINK *)&asub_p->inpa; epicsEnum16 sevr[NCAVS]; int i; short debug = (asub_p->tpro > 1) ? 1 : 0; int cnt, mask; /* manipulate heartbeat counter mask */ *valid = 0; /* Initialize to all invalid */ *hb = *hb_last; /* Initialize to previous heartbeat mask */ if ( debug ) { printf("%s asub_cryo:\n last valid mask 0x%x last heartbeat mask 0x%x\n", asub_p->name, *valid_last, *hb_last); } for ( i = 0; i < NCAVS; i++ ) { dbGetSevr(&link_p[i], &sevr[i]); if ( debug ) { printf(" cavity %i sevr %i gact %f\n", i + 1, sevr[i], *in_p[i]); } if ( sevr[i] != INVALID_ALARM ) { *out_p[i] = *in_p[i]; *valid |= 1<> (i*2); /* Last value */ cnt = (cnt >= 3)?0:cnt+1; /* Increment or roll over */ *hb &= ~mask; /* Clear value */ *hb |= (cnt)<<(i*2); if ( debug ) { printf(" valid gradient, last %f, in %f, out %f\n", *out_last_p[i], *in_p[i], *out_p[i]); printf(" mask 0x%x cnt 0x%x hb 0x%x\n", mask, cnt, *hb); } } } if ( debug ) { printf(" final valid mask 0x%x and heartbeat mask 0x%x\n", *valid, *hb); } return SUCCESS; } epicsRegisterFunction(asub_cryo_init); epicsRegisterFunction(asub_cryo);