/* $Id: devMbboOnln.c,v 1.1.1.1 2010/05/03 22:15:26 khkim Exp $ */ /*============================================================================= Name: devMbboOnln.c Abs: Onln Device support for Bo. Auth: 10-oct-2006, Till Straumann (TSS) Rev: -----------------------------------------------------------------------------*/ #if 0 #include "copyright_SLAC.h" /* SLAC copyright comments */ #endif /*----------------------------------------------------------------------------- Mod: (see CVS log) =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #define CPU_Get_timebase_low( _value ) \ asm volatile( "mftb %0" : "=r" (_value) ) #define DEVSUPNAM "devMbboOnln" /* 11/21/8 Writing errors (level 2) has become too invasive to the processor w.r.t. processing the incoming data streams. Set this to 0 */ #ifdef DEBUG_PRINT int devMbboOnlnFlag = 0; #endif static long report(int interest) { epicsPrintf(DEVSUPNAM": Onln device support for mbbo\n"); epicsPrintf(" (switch data stream from PAD on/off)\n"); return 0; } static long init_record(void *record_p) { mbboRecord *mbbo_ps = record_p; unsigned c; if ( VME_IO != mbbo_ps->out.type ) { epicsPrintf(DEVSUPNAM": Invalid link type; must be VMEIO\n"); mbbo_ps->pact = 1; return -1; } c = mbbo_ps->out.value.vmeio.card; if ( c >= MAX_BPM ) { epicsPrintf(DEVSUPNAM": Invalid card/PAD #%u; must < %i\n", c, MAX_BPM); mbbo_ps->pact = 1; return -1; } return 0; } static long write_mbbo(void *record_p) { mbboRecord *mbbo_ps = record_p; unsigned c = mbbo_ps->out.value.vmeio.card; long rval; unsigned start, stop; unsigned start1,stop1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devMbboOnlnFlag, (DEVSUPNAM": write_mbbo: record %s val: %i\n", mbbo_ps->name, mbbo_ps->val)); #endif CPU_Get_timebase_low(start1); epicsThreadSleep(1.); CPU_Get_timebase_low(stop1); CPU_Get_timebase_low(start); if ( mbbo_ps->rval ) { if ( drvPadUdpCommStrmSetNSamples(c, 6) && (rval = drvPadUdpCommStrmStartReq( c )) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devMbboOnlnFlag, (DEVSUPNAM": write_mbbo: record %s Starting\n", mbbo_ps->name)); #endif } } else { if ( (rval = drvPadUdpCommStrmStopReq( c )) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devMbboOnlnFlag, (DEVSUPNAM": write_mbbo: record %s Stopping\n", mbbo_ps->name)); #endif } } CPU_Get_timebase_low(stop); printf("Delay %lfusec\n", (double)(stop-start)/(double)(stop1-start1)*1.E+6); if ( rval ) { epicsPrintf(" PAD stream (#%i) failed: %s\n", c, strerror(-rval)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devMbboOnlnFlag, (DEVSUPNAM": write_mbbo: record %s PAD stream (#%i) failed: %s\n", mbbo_ps->name, c, strerror(-rval))); #endif #if 0 /* don't set severity (won'd be cleared when the device eventually comes online. This is a work-around... */ recGblSetSevr((dbCommon*)record_p, WRITE_ALARM, MAJOR_ALARM); #endif /* stream command will still be re-send; don't restore * the old status for now. */ #if 0 mbbo_ps->rbv = mbbo_ps->orbv; mbbo_ps->rval = mbbo_ps->oraw; mbbo_ps->val = mbbo_ps->mlst; #endif } mbbo_ps->rbv = mbbo_ps->val; return rval; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write; } devMbboOnln = { 5, report, 0, init_record, 0, write_mbbo }; epicsExportAddress(dset, devMbboOnln);