#include #include #include #include #include #include #include #include #include #include #include static long epics_quench_check(aSubRecord* prec) { short debug = (prec->tpro > 1) ? 1 : 0; short byp = *(short*)prec->a, rfctrl = *(short*)prec->d, rfmodectrl = *(short*)prec->e, ltch = *(short*)prec->h; double gfwd = *(double*)prec->b, /* gradient from forward power */ gcav = *(double*)prec->c, /* gradient from cavity amplitude */ thresh = *(double*)prec->f, /* ignore faults below this gradient */ coef = *(double*)prec->g; /* fault if gcav < coef*gfwd */ /* Real-time fault status, 0 = okay, 1 = fault */ short *fltstat = (short*)prec->vala; /* Links to trigger fault actions */ short *ltchgo = (short*)prec->valb, *offgo = (short*)prec->valc; if(prec->ftb!=menuFtypeDOUBLE || prec->ftc!=menuFtypeDOUBLE) { (void)recGblSetSevr(prec, COMM_ALARM, INVALID_ALARM); return 1; } epicsTimeStamp tgfwd, tgcav; double tdiff; if ( debug ) { printf("%s: Before timestamp check. Inputs: \n" " byp %i, rfctrl %i, rfmodectrl %i,\n" " gfwd %.2f, gcav %.2f, thresh %.2f\n" " coef %.2f, ltch %i\n", prec->name, byp, rfctrl, rfmodectrl, gfwd, gcav, thresh, coef, ltch); } dbGetTimeStamp(&prec->inpb, &tgfwd); dbGetTimeStamp(&prec->inpc, &tgcav); tdiff = epicsTimeDiffInSeconds(&tgfwd,&tgcav); if ( (0.0 != tdiff) ) { if ( debug ) { printf(" *****Gradients timestamps do not match, diff %.2f\n", tdiff); } return -1; } /* Initialize to real-time fault */ *fltstat = 1; if ( (rfctrl==0) || (rfmodectrl>3) || (gfwd ( gfwd*coef) ) ) { *fltstat = 0; if ( debug ) { printf(" *****No real-time fault\n"); } } /* Continue to process RF-off links if latched fault has not been reset * This is to mimic a real interlock: cannot recover RF until unlatched */ if ( byp || ((*fltstat == 0) && (ltch == 0)) ) { return -1; } if ( debug ) { printf(" *****Real-time or latched fault\n"); } *ltchgo = 1; *offgo = 0; return 0; } static registryFunctionRef rf_squench_asub_seq[] = { {"Software Quench Check", (REGISTRYFUNCTION) &epics_quench_check} };