// runs once only for each process extern "C" void ca_init_client_context ( void * ) { caClientContextId = epicsThreadPrivateCreate (); if ( caClientContextId ) { epicsAtExit ( ca_client_exit_handler,0 ); } }
/// Constructor for the #NetShrVarDriver class. /// Calls constructor for the asynPortDriver base class and sets up driver parameters. /// /// @param[in] netvarint interface pointer created by NetShrVarConfigure() /// @param[in] poll_ms @copydoc initArg0 /// @param[in] portName @copydoc initArg3 NetShrVarDriver::NetShrVarDriver(NetShrVarInterface* netvarint, int poll_ms, const char *portName) : asynPortDriver(portName, 0, /* maxAddr */ static_cast<int>(netvarint->nParams()), asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat64ArrayMask | asynOctetMask | asynDrvUserMask, /* Interface mask */ asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat64ArrayMask | asynOctetMask, /* Interrupt mask */ ASYN_CANBLOCK, /* asynFlags. This driver can block but it is not multi-device */ 1, /* Autoconnect */ 0, /* Default priority */ 0), /* Default stack size*/ m_netvarint(netvarint), m_poll_ms(poll_ms), m_shutting_down(false) { const char *functionName = "NetShrVarDriver"; m_netvarint->createParams(this); if (poll_ms == 0) { std::cerr << "Warning: driver is not polling for buffered reads, only subscribers will see changes" << std::endl; } epicsAtExit(epicsExitFunc, this); // Create the thread for background tasks (not used at present, could be used for I/O intr scanning) if (epicsThreadCreate("NetShrVarDriverTask", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)NetShrVarTask, this) == 0) { printf("%s:%s: epicsThreadCreate failure\n", driverName, functionName); return; } }
static void QSRVHooks(initHookState state) { if(state!=initHookAfterCaServerInit) return; epicsAtExit(QSRVExit, NULL); qsrvStart(); }
static void cleanupPrep(initHookState state) { /* register a second time to better our chances of running * first on exit. eg. before cacExitHandler() */ if(state==initHookAfterInitDevSup) epicsAtExit(&cleanupPy, NULL); }
void dbCaLinkInitIsolated(void) { if (!workListLock) workListLock = epicsMutexMustCreate(); if (!workListEvent) workListEvent = epicsEventMustCreate(epicsEventEmpty); dbCaCtl = ctlExit; epicsAtExit(dbCaExit, NULL); }
void testHarness(void) { epicsThreadOnce(&onceFlag, testOnce, NULL); epicsAtExit(harnessExit, NULL); Harness = 1; Programs = 0; Tests = 0; ellInit(&faults); epicsTimeGetCurrent(&started); }
static void initDatabase(void) { dbChannelInit(); iterateRecords(doInitRecord0, NULL); iterateRecords(doResolveLinks, NULL); iterateRecords(doInitRecord1, NULL); epicsAtExit(exitDatabase, NULL); return; }
////////////////////////////////////////////////////////////////////////////////////////////////// // // // static void LeyboldSimPortDriverConfigure(const iocshArgBuf *args) // // // // Description: // // EPICS iocsh callable function to call constructor for the CLeyboldSimPortDriver class. // // // // Parameters: // // args - 3 arguments: // // numPumps - how many pumps will be attached? // // NoOfPZD - This will be 6 for older model pumps or // // 2 for the rear port of the MAG Drive Digital model. // // // ////////////////////////////////////////////////////////////////////////////////////////////////// void CLeyboldSimPortDriver::LeyboldSimPortDriverConfigure(const iocshArgBuf *args) { try { const char* asynPortName = args[0].sval; int numPumps = atoi(args[1].sval); int NoOfPZD = atoi(args[2].sval); CLeyboldSimPortDriver* Instance = new CLeyboldSimPortDriver(asynPortName, numPumps, NoOfPZD); epicsAtExit(LeyboldSimExitFunc, Instance); } catch(CLeyboldSimPortDriver::CException const&) { } }
static void inithooks(initHookState state) { epicsUInt8 lvl; switch(state) { case initHookAfterInterruptAccept: epicsAtExit(&evgShutdown, NULL); mrf::Object::visitObjects(&enableIRQ, 0); for(lvl=1; lvl<=7; ++lvl) { if (vme_level_mask&(1<<(lvl-1))) { if(devEnableInterruptLevelVME(lvl)) { printf("Failed to enable interrupt level %d\n",lvl); return; } } } break; /* * Enable interrupts after IOC has been started (this is need for cPCI version) * * Change by: tslejko * Reason: cPCI EVG support */ case initHookAtIocRun: epicsAtExit(&evgShutdown, NULL); mrf::Object::visitObjects(&enableIRQ, 0); break; /* * callback for updating SFP info gets called here for the first time. */ case initHookAfterCallbackInit: mrf::Object::visitObjects(&startSFPUpdate, 0); break; default: break; } }
static void dbndInitialize(void) { static int firstTime = 1; if (!firstTime) return; firstTime = 0; if (!myStructFreeList) freeListInitPvt(&myStructFreeList, sizeof(myStruct), 64); chfPluginRegister("dbnd", &pif, opts); epicsAtExit(dbndShutdown, NULL); }
static void ClockTime_InitOnce(void *pfirst) { *(int *) pfirst = 1; ClockTimePvt.loopEvent = epicsEventMustCreate(epicsEventEmpty); ClockTimePvt.lock = epicsMutexCreate(); epicsAtExit(ClockTime_Shutdown, NULL); /* Register the iocsh commands */ iocshRegister(&ReportFuncDef, ReportCallFunc); iocshRegister(&ShutdownFuncDef, ShutdownCallFunc); /* Register as a time provider */ generalTimeRegisterCurrentProvider("OS Clock", LAST_RESORT_PRIORITY, ClockTimeGetCurrent); }
/* * Create a command-line context */ static void osdReadlineBegin(struct readlineContext *context) { if (rlState == rlNone) { epicsAtExit(rlExit, NULL); rlState = rlIdle; } context->osd = &present; if (context->in == NULL) { long i = 50; envGetLongConfigParam(&IOCSH_HISTSIZE, &i); if (i < 0) i = 0; stifle_history(i); rl_bind_key('\t', rl_insert); } }
/// \param[in] configSection @copydoc initArg1 /// \param[in] configFile @copydoc initArg2 /// \param[in] options @copydoc initArg4 NetShrVarInterface::NetShrVarInterface(const char *configSection, const char* configFile, int options) : m_configSection(configSection), m_options(options) { epicsThreadOnce(&onceId, initCV, NULL); char* configFile_expanded = macEnvExpand(configFile); m_configFile = configFile_expanded; epicsAtExit(epicsExitFunc, this); pugi::xml_parse_result result = m_xmlconfig.load_file(configFile_expanded); free(configFile_expanded); if (result) { std::cerr << "Loaded XML config file \"" << m_configFile << "\" (expanded from \"" << configFile << "\")" << std::endl; } else { throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure: " + result.description()); } }
static void pySetupReg(void) { Py_InitializeEx(0); PyEval_InitThreads(); setupPyPath(); if(PyRun_SimpleString("import devsup\n" "devsup._init(iocMain=True)\n" )) { PyErr_Print(); PyErr_Clear(); } (void)PyEval_SaveThread(); /* register first time to ensure cleanupPy is run at least once */ epicsAtExit(&cleanupPy, NULL); initHookRegister(&cleanupPrep); }
static void twdInitOnce(void *arg) { epicsThreadId tid; tLock = epicsMutexMustCreate(); mLock = epicsMutexMustCreate(); fLock = epicsMutexMustCreate(); ellInit(&fList); VALGRIND_CREATE_MEMPOOL(&fList, 0, 0); twdCtl = twdctlRun; loopEvent = epicsEventMustCreate(epicsEventEmpty); exitEvent = epicsEventMustCreate(epicsEventEmpty); tid = epicsThreadCreate("taskwd", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackSmall), twdTask, NULL); if (tid == 0) cantProceed("Failed to spawn task watchdog thread\n"); epicsAtExit(twdShutdown, NULL); }
static void NTPTime_InitOnce(void *pprio) { struct timespec timespecNow; NTPTimePvt.synchronize = 1; NTPTimePvt.synchronized = 0; NTPTimePvt.loopEvent = epicsEventMustCreate(epicsEventEmpty); NTPTimePvt.syncsFailed = 0; NTPTimePvt.lock = epicsMutexCreate(); /* Initialize OS-dependent code */ osdNTPInit(); /* Try to sync with NTP server */ if (!osdNTPGet(×pecNow)) { NTPTimePvt.syncTick = osdTickGet(); if (timespecNow.tv_sec > POSIX_TIME_AT_EPICS_EPOCH && epicsTimeOK == epicsTimeFromTimespec(&NTPTimePvt.syncTime, ×pecNow)) { NTPTimePvt.clockTick = NTPTimePvt.syncTick; NTPTimePvt.clockTime = NTPTimePvt.syncTime; NTPTimePvt.synchronized = 1; } } /* Start the sync thread */ epicsThreadCreate("NTPTimeSync", epicsThreadPriorityHigh, epicsThreadGetStackSize(epicsThreadStackSmall), NTPTimeSync, NULL); epicsAtExit(NTPTime_Shutdown, NULL); /* Register the iocsh commands */ iocshRegister(&ReportFuncDef, ReportCallFunc); iocshRegister(&ShutdownFuncDef, ShutdownCallFunc); /* Finally register as a time provider */ generalTimeRegisterCurrentProvider("NTP", *(int *)pprio, NTPTimeGetCurrent); }
static void errlogThread(void) { listenerNode *plistenerNode; int noConsoleMessage; char *pmessage; epicsAtExit(errlogExitHandler,0); while (TRUE) { epicsEventMustWait(pvtData.waitForWork); while ((pmessage = msgbufGetSend(&noConsoleMessage))) { epicsMutexMustLock(pvtData.listenerLock); if (pvtData.toConsole && !noConsoleMessage) { fprintf(pvtData.console,"%s",pmessage); fflush(pvtData.console); } plistenerNode = (listenerNode *)ellFirst(&pvtData.listenerList); while (plistenerNode) { (*plistenerNode->listener)(plistenerNode->pPrivate, pmessage); plistenerNode = (listenerNode *)ellNext(&plistenerNode->node); } epicsMutexUnlock(pvtData.listenerLock); msgbufFreeSend(); } if (pvtData.atExit) break; if (epicsEventTryWait(pvtData.flush) != epicsEventWaitOK) continue; epicsThreadSleep(.2); /*just wait an extra .2 seconds*/ epicsEventSignal(pvtData.waitForFlush); } epicsEventSignal(pvtData.waitForExit); }
void omsMAXv::initialize(const char* portName, int numAxes, int cardNo, const char* initString, int prio, int stackSz, unsigned int vmeAddr, int intrVector, int level, epicsAddressType vmeAddrType, int paramCount) { const char* functionName = "initialize"; long status; void* probeAddr; Debug(32, "omsMAXv::initialize: start initialize\n" ); controllerType = epicsStrDup("MAXv"); // TODO check if cardNo has already been used this->cardNo = cardNo; if(cardNo < 0 || cardNo >= MAXv_NUM_CARDS){ printf("invalid cardNo: %d", cardNo); return; } epicsUInt8 *startAddr; epicsUInt8 *endAddr; epicsUInt32 boardAddrSize = 0; if (vmeAddrType == atVMEA16) boardAddrSize = 0x1000; else if (vmeAddrType == atVMEA24) boardAddrSize = 0x10000; else if (vmeAddrType == atVMEA32) boardAddrSize = 0x1000000; // if vmeAddr == 1 Setup/Config is used and not Config2 if (vmeAddr == 1) probeAddr = baseAddress + (cardNo * boardAddrSize); else probeAddr = (void*) vmeAddr; startAddr = (epicsUInt8 *) probeAddr; endAddr = startAddr + boardAddrSize; Debug(64, "motor_init: devNoResponseProbe() on addr %p\n", probeAddr); /* Scan memory space to assure card id */ while (startAddr < endAddr) { status = devNoResponseProbe(vmeAddrType, (size_t) startAddr, 2); if (status != S_dev_addressOverlap) { errlogPrintf("%s:%s:%s: Card NOT found in specified address range! \n", driverName, functionName, portName); enabled = false; return; } startAddr += (boardAddrSize / 10); } status = devRegisterAddress(controllerType, vmeAddrType, (size_t) probeAddr, boardAddrSize, (volatile void **) &pmotor); Debug(64, "motor_init: devRegisterAddress() status = %d\n", (int) status); if (status) { errlogPrintf("%s:%s:%s: Can't register address 0x%lx \n", driverName, functionName, portName, (long unsigned int) probeAddr); return; } Debug(64, "motor_init: pmotor = %p\n", pmotor); int loopCount=15; while (loopCount && (pmotor->firmware_status.Bits.initializing == 1)){ Debug(1, "MAXv port %s still initializing; status = 0x%x\n", portName, (unsigned int) pmotor->firmware_status.All); epicsThreadSleep(0.2); --loopCount; } Debug(64, "motor_init: check if card is ready\n"); if (pmotor->firmware_status.Bits.running == 0) errlogPrintf("MAXv port %s is NOT running; status = 0x%x\n", portName, (unsigned int) pmotor->firmware_status.All); Debug(64, "motor_init: init card\n"); FIRMWARE_STATUS fwStatus; fwStatus.All = pmotor->firmware_status.All; Debug(64, "motor_init: firmware status register: 0x%x\n", fwStatus.All); pmotor->IACK_vector = intrVector; pmotor->status1_flag.All = 0xFFFFFFFF; pmotor->status2_flag = 0xFFFFFFFF; /* Disable all interrupts */ pmotor->status1_irq_enable.All = 0; pmotor->status2_irq_enable = 0; Debug(64, "motor_init: clear all interrupt\n"); //sendOnly("IC"); Debug(64, "motor_init: firmware version\n"); /* get FirmwareVersion */ if(getFirmwareVersion() != asynSuccess) { errlogPrintf("%s:%s:%s: unable to talk to controller card %d\n", driverName, functionName, portName, cardNo); return; } if (fwMinor < 30 ){ errlogPrintf("%s:%s:%s: This Controllers Firmware Version %d.%d is not supported, version 1.30 or higher is mandatory\n", driverName, functionName, portName, fwMajor, fwMinor); } Debug(64, "motor_init: send init string\n"); if( Init(initString, 1) != asynSuccess) { errlogPrintf("%s:%s:%s: unable to send initstring to controller card %d\n", driverName, functionName, portName, cardNo); return; } useWatchdog = true; if (watchdogOK()) { Debug(64, "motor_init: enable interrupts ( vector=%d, level=%d) \n", intrVector, level); /* Enable interrupt-when-done if selected */ if (intrVector) motorIsrSetup((unsigned int)intrVector, level); } else return; if (epicsAtExit(&omsMAXv::resetOnExit, this)) errlogPrintf("%s:%s:%s: card %d, unable to register exit function\n", driverName, functionName, portName, cardNo); return; }
/* * Configure and register an IP socket from a hostInfo string */ epicsShareFunc int drvAsynIPPortConfigure(const char *portName, const char *hostInfo, unsigned int priority, int noAutoConnect, int userFlags) { ttyController_t *tty; asynInterface *pasynInterface; asynStatus status; char *cp; int nbytes; asynOctet *pasynOctet; int isCom = 0; static int firstTime = 1; /* * Check arguments */ if (portName == NULL) { printf("Port name missing.\n"); return -1; } if (hostInfo == NULL) { printf("TCP host information missing.\n"); return -1; } if (USERFLAG_RESERVED & userFlags) { printf("Reserved userFlags must be 0\n"); return -1; } /* * Perform some one-time-only initializations */ if (firstTime) { firstTime = 0; if (osiSockAttach() == 0) { printf("drvAsynIPPortConfigure: osiSockAttach failed\n"); return -1; } } /* * Create a driver */ nbytes = sizeof(*tty) + sizeof(asynOctet); tty = (ttyController_t *)callocMustSucceed(1, nbytes, "drvAsynIPPortConfigure()"); pasynOctet = (asynOctet *)(tty+1); tty->fd = INVALID_SOCKET; tty->flags = 0; tty->userFlags = userFlags; tty->IPDeviceName = epicsStrDup(hostInfo); tty->portName = epicsStrDup(portName); /* * Parse configuration parameters */ if (strncmp(tty->IPDeviceName, "unix://", 7) == 0) { # if defined(HAS_AF_UNIX) const char *cp = tty->IPDeviceName + 7; size_t l = strlen(cp); if ((l == 0) || (l >= sizeof(tty->farAddr.ua.sun_path)-1)) { printf("Path name \"%s\" invalid.\n", cp); ttyCleanup(tty); return -1; } tty->farAddr.ua.sun_family = AF_UNIX; strcpy(tty->farAddr.ua.sun_path, cp); tty->farAddrSize = sizeof(tty->farAddr.ua) - sizeof(tty->farAddr.ua.sun_path) + l + 1; tty->socketType = SOCK_STREAM; # else printf("AF_UNIX not available on this platform.\n"); ttyCleanup(tty); return -1; # endif } else { int port; int localPort = -1; char protocol[6]; char *secondColon, *blank; protocol[0] = '\0'; if ((cp = strchr(tty->IPDeviceName, ':')) == NULL) { printf("drvAsynIPPortConfigure: \"%s\" is not of the form \"<host>:<port>[:localPort] [protocol]\"\n", tty->IPDeviceName); ttyCleanup(tty); return -1; } *cp = '\0'; tty->IPHostName = epicsStrDup(tty->IPDeviceName); *cp = ':'; if (sscanf(cp, ":%d", &port) < 1) { printf("drvAsynIPPortConfigure: \"%s\" is not of the form \"<host>:<port>[:localPort] [protocol]\"\n", tty->IPDeviceName); ttyCleanup(tty); return -1; } if ((secondColon = strchr(cp+1, ':')) != NULL) { if (sscanf(secondColon, ":%d", &localPort) < 1) { printf("drvAsynIPPortConfigure: \"%s\" is not of the form \"<host>:<port>[:localPort] [protocol]\"\n", tty->IPDeviceName); ttyCleanup(tty); return -1; } tty->localAddr.ia.sin_family = AF_INET; tty->localAddr.ia.sin_port = htons(localPort); tty->localAddrSize = sizeof(tty->localAddr.ia); } if ((blank = strchr(cp, ' ')) != NULL) { sscanf(blank+1, "%5s", protocol); } tty->farAddr.oa.ia.sin_family = AF_INET; tty->farAddr.oa.ia.sin_port = htons(port); tty->farAddrSize = sizeof(tty->farAddr.oa.ia); tty->flags |= FLAG_NEED_LOOKUP; if ((protocol[0] == '\0') || (epicsStrCaseCmp(protocol, "tcp") == 0)) { tty->socketType = SOCK_STREAM; } else if (epicsStrCaseCmp(protocol, "com") == 0) { isCom = 1; tty->socketType = SOCK_STREAM; } else if (epicsStrCaseCmp(protocol, "http") == 0) { tty->socketType = SOCK_STREAM; tty->flags |= FLAG_CONNECT_PER_TRANSACTION; } else if (epicsStrCaseCmp(protocol, "udp") == 0) { tty->socketType = SOCK_DGRAM; } else if (epicsStrCaseCmp(protocol, "udp*") == 0) { tty->socketType = SOCK_DGRAM; tty->flags |= FLAG_BROADCAST; } else { printf("drvAsynIPPortConfigure: Unknown protocol \"%s\".\n", protocol); ttyCleanup(tty); return -1; } } /* * Link with higher level routines */ pasynInterface = (asynInterface *)callocMustSucceed(2, sizeof *pasynInterface, "drvAsynIPPortConfigure"); tty->common.interfaceType = asynCommonType; tty->common.pinterface = (void *)&drvAsynIPPortAsynCommon; tty->common.drvPvt = tty; if (pasynManager->registerPort(tty->portName, ASYN_CANBLOCK, !noAutoConnect, priority, 0) != asynSuccess) { printf("drvAsynIPPortConfigure: Can't register myself.\n"); ttyCleanup(tty); return -1; } status = pasynManager->registerInterface(tty->portName,&tty->common); if(status != asynSuccess) { printf("drvAsynIPPortConfigure: Can't register common.\n"); ttyCleanup(tty); return -1; } pasynOctet->read = readIt; pasynOctet->write = writeIt; pasynOctet->flush = flushIt; tty->octet.interfaceType = asynOctetType; tty->octet.pinterface = pasynOctet; tty->octet.drvPvt = tty; status = pasynOctetBase->initialize(tty->portName,&tty->octet, 0, 0, 1); if(status != asynSuccess) { printf("drvAsynIPPortConfigure: pasynOctetBase->initialize failed.\n"); ttyCleanup(tty); return -1; } if (isCom && (asynInterposeCOM(tty->portName) != 0)) { printf("drvAsynIPPortConfigure: asynInterposeCOM failed.\n"); ttyCleanup(tty); return -1; } if (!(tty->userFlags & USERFLAG_NO_PROCESS_EOS)) asynInterposeEosConfig(tty->portName, -1, 1, 1); tty->pasynUser = pasynManager->createAsynUser(0,0); status = pasynManager->connectDevice(tty->pasynUser,tty->portName,-1); if(status != asynSuccess) { printf("connectDevice failed %s\n",tty->pasynUser->errorMessage); ttyCleanup(tty); return -1; } /* * Register for socket cleanup */ epicsAtExit(cleanup, tty); return 0; }
static void epicsSingletonOnce ( void * ) { pSingletonBaseMutexEPICS = newEpicsMutex; epicsAtExit ( epicsSingletonCleanup,0 ); }
/** Constructor for FastCCD driver; most parameters are simply passed to ADDriver::ADDriver. * After calling the base class constructor this method creates a thread to collect the detector data, * and sets reasonable default values the parameters defined in this class, asynNDArrayDriver, and ADDriver. * \param[in] portName The name of the asyn port driver to be created. * \param[in] maxBuffers The maximum number of NDArray buffers that the NDArrayPool for this driver is * allowed to allocate. Set this to -1 to allow an unlimited number of buffers. * \param[in] maxMemory The maximum amount of memory that the NDArrayPool for this driver is * allowed to allocate. Set this to -1 to allow an unlimited amount of memory. * \param[in] priority The thread priority for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags. * \param[in] stackSize The stack size for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags. */ FastCCD::FastCCD(const char *portName, int maxBuffers, size_t maxMemory, int priority, int stackSize, int packetBuffer, int imageBuffer, const char *baseIP, const char *fabricIP, const char *fabricMAC) : ADDriver(portName, 1, NUM_FastCCD_DET_PARAMS, maxBuffers, maxMemory, asynUInt32DigitalMask, asynUInt32DigitalMask, ASYN_CANBLOCK, 1, priority, stackSize) { int status = asynSuccess; int sizeX, sizeY; static const char *functionName = "FastCCD"; /* Write the packet and frame buffer sizes */ cinPacketBuffer = packetBuffer; cinImageBuffer = imageBuffer; /* Store the network information */ strncpy(cinBaseIP, baseIP, 20); strncpy(cinFabricIP, fabricIP, 20); strncpy(cinFabricMAC, fabricMAC, 20); //Define the polling periods for the status thread. statusPollingPeriod = 20; //seconds dataStatsPollingPeriod = 0.1; //seconds // Assume we are in continuous mode framesRemaining = -1; /* Create an EPICS exit handler */ epicsAtExit(exitHandler, this); createParam(FastCCDPollingPeriodString, asynParamFloat64, &FastCCDPollingPeriod); createParam(FastCCDMux1String, asynParamInt32, &FastCCDMux1); createParam(FastCCDMux2String, asynParamInt32, &FastCCDMux2); createParam(FastCCDFirmwarePathString, asynParamOctet, &FastCCDFirmwarePath); createParam(FastCCDBiasPathString, asynParamOctet, &FastCCDBiasPath); createParam(FastCCDClockPathString, asynParamOctet, &FastCCDClockPath); createParam(FastCCDFCRICPathString, asynParamOctet, &FastCCDFCRICPath); createParam(FastCCDFirmwareUploadString, asynParamInt32, &FastCCDFirmwareUpload); createParam(FastCCDBiasUploadString, asynParamInt32, &FastCCDBiasUpload); createParam(FastCCDClockUploadString, asynParamInt32, &FastCCDClockUpload); createParam(FastCCDFCRICUploadString, asynParamInt32, &FastCCDFCRICUpload); createParam(FastCCDPowerString, asynParamInt32, &FastCCDPower); createParam(FastCCDFPPowerString, asynParamInt32, &FastCCDFPPower); createParam(FastCCDCameraPowerString, asynParamInt32, &FastCCDCameraPower); createParam(FastCCDBiasString, asynParamInt32, &FastCCDBias); createParam(FastCCDClocksString, asynParamInt32, &FastCCDClocks); createParam(FastCCDFPGAStatusString, asynParamUInt32Digital, &FastCCDFPGAStatus); createParam(FastCCDDCMStatusString, asynParamUInt32Digital, &FastCCDDCMStatus); createParam(FastCCDOverscanString, asynParamInt32, &FastCCDOverscan); createParam(FastCCDFclkString, asynParamInt32, &FastCCDFclk); createParam(FastCCDFCRICGainString, asynParamInt32, &FastCCDFCRICGain); createParam(FastCCDVBus12V0String, asynParamFloat64, &FastCCDVBus12V0); createParam(FastCCDVMgmt3v3String, asynParamFloat64, &FastCCDVMgmt3v3); createParam(FastCCDVMgmt2v5String, asynParamFloat64, &FastCCDVMgmt2v5); createParam(FastCCDVMgmt1v2String, asynParamFloat64, &FastCCDVMgmt1v2); createParam(FastCCDVEnet1v0String, asynParamFloat64, &FastCCDVEnet1v0); createParam(FastCCDVS3E3v3String, asynParamFloat64, &FastCCDVS3E3v3); createParam(FastCCDVGen3v3String, asynParamFloat64, &FastCCDVGen3v3); createParam(FastCCDVGen2v5String, asynParamFloat64, &FastCCDVGen2v5); createParam(FastCCDV60v9String, asynParamFloat64, &FastCCDV60v9); createParam(FastCCDV61v0String, asynParamFloat64, &FastCCDV61v0); createParam(FastCCDV62v5String, asynParamFloat64, &FastCCDV62v5); createParam(FastCCDVFpString, asynParamFloat64, &FastCCDVFp); createParam(FastCCDIBus12V0String, asynParamFloat64, &FastCCDIBus12V0); createParam(FastCCDIMgmt3v3String, asynParamFloat64, &FastCCDIMgmt3v3); createParam(FastCCDIMgmt2v5String, asynParamFloat64, &FastCCDIMgmt2v5); createParam(FastCCDIMgmt1v2String, asynParamFloat64, &FastCCDIMgmt1v2); createParam(FastCCDIEnet1v0String, asynParamFloat64, &FastCCDIEnet1v0); createParam(FastCCDIS3E3v3String, asynParamFloat64, &FastCCDIS3E3v3); createParam(FastCCDIGen3v3String, asynParamFloat64, &FastCCDIGen3v3); createParam(FastCCDIGen2v5String, asynParamFloat64, &FastCCDIGen2v5); createParam(FastCCDI60v9String, asynParamFloat64, &FastCCDI60v9); createParam(FastCCDI61v0String, asynParamFloat64, &FastCCDI61v0); createParam(FastCCDI62v5String, asynParamFloat64, &FastCCDI62v5); createParam(FastCCDIFpString, asynParamFloat64, &FastCCDIFp); createParam(FastCCDLibCinVersionString, asynParamOctet, &FastCCDLibCinVersion); createParam(FastCCDBoardIDString, asynParamInt32, &FastCCDBoardID); createParam(FastCCDSerialNumString, asynParamInt32, &FastCCDSerialNum); createParam(FastCCDFPGAVersionString, asynParamInt32, &FastCCDFPGAVersion); createParam(FastCCDStatusHBString, asynParamInt32, &FastCCDStatusHB); createParam(FastCCDBadPckString, asynParamInt32, &FastCCDBadPck); createParam(FastCCDDroppedPckString, asynParamInt32, &FastCCDDroppedPck); createParam(FastCCDLastFrameString, asynParamInt32, &FastCCDLastFrame); createParam(FastCCDResetStatsString, asynParamInt32, &FastCCDResetStats); createParam(FastCCDPacketBufferString, asynParamInt32, &FastCCDPacketBuffer); createParam(FastCCDFrameBufferString, asynParamInt32, &FastCCDFrameBuffer); createParam(FastCCDImageBufferString, asynParamInt32, &FastCCDImageBuffer); // Create the epicsEvent for signaling to the status task when parameters should have changed. // This will cause it to do a poll immediately, rather than wait for the poll time period. this->statusEvent = epicsEventMustCreate(epicsEventEmpty); if (!this->statusEvent) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Failed to create event for status task.\n", driverName, functionName); return; } this->dataStatsEvent = epicsEventMustCreate(epicsEventEmpty); if (!this->dataStatsEvent) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Failed to create event for data stats task.\n", driverName, functionName); return; } try { this->lock(); connectCamera(); this->unlock(); setStringParam(ADStatusMessage, "Initialized"); callParamCallbacks(); } catch (const std::string &e) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: %s\n", driverName, functionName, e.c_str()); return; } sizeX = CIN_DATA_MAX_FRAME_X; sizeY = CIN_DATA_MAX_FRAME_Y; /* Set some default values for parameters */ status = asynSuccess; status |= setDoubleParam(FastCCDPollingPeriod, statusPollingPeriod); status |= setStringParam(ADManufacturer, "Berkeley Laboratory"); status |= setStringParam(ADModel, "1k x 2k FastCCD"); status |= setIntegerParam(ADSizeX, sizeX); status |= setIntegerParam(ADSizeY, sizeY); status |= setIntegerParam(ADBinX, 1); status |= setIntegerParam(ADBinY, 1); status |= setIntegerParam(ADMinX, 0); status |= setIntegerParam(ADMinY, 0); status |= setIntegerParam(ADMaxSizeX, sizeX); status |= setIntegerParam(ADMaxSizeY, sizeY); status |= setIntegerParam(ADReverseX, 0); status |= setIntegerParam(ADReverseY, 0); status |= setIntegerParam(ADImageMode, ADImageSingle); status |= setIntegerParam(ADTriggerMode, 1); status |= setDoubleParam(ADAcquireTime, 0.005); status |= setDoubleParam(ADAcquirePeriod, 1.0); status |= setIntegerParam(ADNumImages, 1); status |= setIntegerParam(ADNumExposures, 1); status |= setIntegerParam(NDArraySizeX, sizeX); status |= setIntegerParam(NDArraySizeY, sizeY); status |= setIntegerParam(NDDataType, NDUInt16); status |= setIntegerParam(NDArraySize, sizeX*sizeY*sizeof(epicsUInt16)); status |= setDoubleParam(ADShutterOpenDelay, 0.); status |= setDoubleParam(ADShutterCloseDelay, 0.); status |= setIntegerParam(FastCCDFirmwareUpload, 0); status |= setIntegerParam(FastCCDClockUpload, 0); status |= setIntegerParam(FastCCDBiasUpload, 0); status |= setIntegerParam(FastCCDPower, 0); status |= setIntegerParam(FastCCDFPPower, 0); status |= setIntegerParam(FastCCDCameraPower, 0); status |= setIntegerParam(FastCCDBias, 0); status |= setIntegerParam(FastCCDClocks, 0); status |= setUIntDigitalParam(FastCCDFPGAStatus, 0x0, 0xFFFF); status |= setUIntDigitalParam(FastCCDDCMStatus, 0x0, 0xFFFF); status |= setIntegerParam(FastCCDMux1, 0); status |= setIntegerParam(FastCCDMux2, 0); status |= setStringParam(FastCCDFirmwarePath, ""); status |= setStringParam(FastCCDBiasPath, ""); status |= setStringParam(FastCCDClockPath, ""); status |= setStringParam(FastCCDFCRICPath, ""); status |= setIntegerParam(FastCCDOverscan, 2); status |= setIntegerParam(FastCCDFclk, 0); status |= setIntegerParam(FastCCDFCRICGain, 0); status |= setDoubleParam(FastCCDVBus12V0, 0); status |= setDoubleParam(FastCCDVMgmt3v3, 0); status |= setDoubleParam(FastCCDVMgmt2v5, 0); status |= setDoubleParam(FastCCDVMgmt1v2, 0); status |= setDoubleParam(FastCCDVEnet1v0, 0); status |= setDoubleParam(FastCCDVS3E3v3, 0); status |= setDoubleParam(FastCCDVGen3v3, 0); status |= setDoubleParam(FastCCDVGen2v5, 0); status |= setDoubleParam(FastCCDV60v9, 0); status |= setDoubleParam(FastCCDV61v0, 0); status |= setDoubleParam(FastCCDV62v5, 0); status |= setDoubleParam(FastCCDVFp, 0); status |= setDoubleParam(FastCCDIBus12V0, 0); status |= setDoubleParam(FastCCDIMgmt3v3, 0); status |= setDoubleParam(FastCCDIMgmt2v5, 0); status |= setDoubleParam(FastCCDIMgmt1v2, 0); status |= setDoubleParam(FastCCDIEnet1v0, 0); status |= setDoubleParam(FastCCDIS3E3v3, 0); status |= setDoubleParam(FastCCDIGen3v3, 0); status |= setDoubleParam(FastCCDIGen2v5, 0); status |= setDoubleParam(FastCCDI60v9, 0); status |= setDoubleParam(FastCCDI61v0, 0); status |= setDoubleParam(FastCCDI62v5, 0); status |= setDoubleParam(FastCCDIFp, 0); status |= setStringParam(FastCCDLibCinVersion, (char *)cin_build_version); callParamCallbacks(); // Signal the status thread to poll the detector epicsEventSignal(statusEvent); epicsEventSignal(dataStatsEvent); if (stackSize == 0) { stackSize = epicsThreadGetStackSize(epicsThreadStackMedium); } /* Create the thread that updates the detector status */ status = (epicsThreadCreate("FastCCDStatusTask", epicsThreadPriorityMedium, stackSize, (EPICSTHREADFUNC)FastCCDStatusTaskC, this) == NULL); if(status) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Failed to create status task.\n", driverName, functionName); return; } /* Create the thread that updates the data stats */ status = (epicsThreadCreate("FastCCDDataStatsTask", epicsThreadPriorityMedium, stackSize, (EPICSTHREADFUNC)FastCCDDataStatsTaskC, this) == NULL); if(status) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Failed to create data stats task.\n", driverName, functionName); return; } }
/*************************************************** * initialize all software and hardware * scalerVS_init() ****************************************************/ STATIC long scalerVS_init(int after) { volatile char *localAddr; unsigned long status; char *baseAddr; int card, card_type; uint32 probeValue = 0; Debug(2,"scalerVS_init(): entry, after = %d\n", after); if (after || (vs_num_cards == 0)) return(0); /* allocate scalerVS_state structures, array of pointers */ if (scalerVS_state == NULL) { scalerVS_state = (struct scalerVS_state **) calloc(1, vs_num_cards * sizeof(struct scalerVS_state *)); scalerVS_total_cards=0; for (card=0; card<vs_num_cards; card++) { scalerVS_state[card] = (struct scalerVS_state *) calloc(1, sizeof(struct scalerVS_state)); } } /* Check out the hardware. */ for (card=0; card<vs_num_cards; card++) { baseAddr = (char *)(vs_addrs + card*CARD_ADDRESS_SPACE); /* Can we reserve the required block of VME address space? */ status = devRegisterAddress(__FILE__, atVMEA16, (size_t)baseAddr, CARD_ADDRESS_SPACE, (volatile void **)&localAddr); if (!RTN_SUCCESS(status)) { errPrintf(status, __FILE__, __LINE__, "Can't register 2048-byte block in VME A16 at address %p\n", baseAddr); return (ERROR); } if (devReadProbe(4,(volatile void *)(localAddr+READ_XFER_REG_OFFSET),(void*)&probeValue)) { printf("scalerVS_init: no VSxx card at %p\n",localAddr); return(0); } /* Declare victory. */ Debug(2,"scalerVS_init: we own 2048 bytes in VME A16 starting at %p\n", localAddr); scalerVS_state[card]->localAddr = localAddr; scalerVS_total_cards++; /* reset this card */ /* any write to this address causes reset */ writeReg16(localAddr,MASTER_RESET_OFFSET,0); /* get this card's type and serial number */ scalerVS_state[card]->ident = readReg16(localAddr,ID_OFFSET); Debug(3,"scalerVS_init: Serial # = %d\n", scalerVS_state[card]->ident & 0x3FF); /* get this card's type */ card_type = scalerVS_state[card]->ident >> 10; if ((card_type > 22) || (card_type < 16)) { errPrintf(status, __FILE__, __LINE__, "unrecognized module\n"); scalerVS_state[card]->num_channels = 0; scalerVS_state[card]->card_exists = 0; /* * Something's wrong with this card, but we still count it in scalerVS_total_cards. * A bad card retains its address space; otherwise we can't talk to the next one. */ } else { scalerVS_state[card]->num_channels = VS_module_types[card_type-16].num_channels; scalerVS_state[card]->card_exists = 1; } Debug(3,"scalerVS_init: nchan = %d\n", scalerVS_state[card]->num_channels); } Debug(3,"scalerVS_init: Total cards = %d\n\n",scalerVS_total_cards); #ifdef vxWorks if (epicsAtExit(scalerVS_shutdown, 0) < 0) epicsPrintf ("scalerVS_init: epicsAtExit() failed\n"); #endif Debug(3,"%s", "scalerVS_init: scalers initialized\n"); return(0); }
LOCAL long drvM6802_init_driver(void) { drvM6802_taskConfig *ptaskConfig = NULL; /* drvM6802_taskConfig *ptaskConfigNext = NULL; */ drvM6802_channelConfig *pchannelConfig = NULL; FILE *fp; int temp=0; unsigned long long int a; if(!pdrvM6802Config) return 0; fp = fopen(FILE_NAME_RAWDATA, "wb"); if( fp != NULL ) { fwrite( &temp, 4, 1, fp); fclose(fp); } ptaskConfig = (drvM6802_taskConfig*) ellFirst(pdrvM6802Config->ptaskList); while(ptaskConfig) { if(ellCount(ptaskConfig->pchannelConfig)) { initDAQboard(ptaskConfig); pchannelConfig = (drvM6802_channelConfig*) ellFirst(ptaskConfig->pchannelConfig); while(pchannelConfig) { init_channelGain(pchannelConfig); pchannelConfig = (drvM6802_channelConfig*) ellNext(&pchannelConfig->node); } } ptaskConfig = (drvM6802_taskConfig*) ellNext(&ptaskConfig->node); } /* while(ptaskConfig) { */ /* ptaskConfig = (drvM6802_taskConfig*) ellFirst(pdrvM6802Config->ptaskList); while(ptaskConfig) { ptaskConfigNext = (drvM6802_taskConfig*) ellNext(&ptaskConfig->node); if( !ptaskConfigNext ) { ozSetTermEnable(ptaskConfig); epicsPrintf("\n>>> drvM6802_init_driver : Board %d : Termination Enabled\n", ptaskConfig->BoardID ); break; } else ptaskConfig = ptaskConfigNext; } */ ptaskConfig = (drvM6802_taskConfig*) ellLast(pdrvM6802Config->ptaskList); if(ptaskConfig) { ozSetTermEnable(ptaskConfig); epicsPrintf("\n>>> drvM6802_init_driver : Board %d : Termination Enabled\n", ptaskConfig->BoardID ); } else epicsPrintf("\n>>> drvM6802_init_driver : Board %d : Termination Error!\n", ptaskConfig->BoardID ); epicsAtExit((EPICSEXITFUNC) clearAllOzTasks, NULL); a = drvM6802_getCurrentUsec(); epicsThreadSleep(1.); pdrvM6802Config->one_sec_interval = drvM6802_getCurrentUsec() - a; epicsPrintf("drvM6802: measured one second time is %lf msec\n", 1.E-3 * (double)pdrvM6802Config->one_sec_interval); return 0; }
static void ipAddrToAsciiEngineGlobalMutexConstruct ( void * ) { ipAddrToAsciiEnginePrivate :: pGlobalMutex = newEpicsMutex; epicsAtExit ( ipAddrToAsciiEngineShutdownRequest, 0 ); }
/// \param[in] configSection @copydoc initArg1 /// \param[in] configFile @copydoc initArg2 /// \param[in] host @copydoc initArg3 /// \param[in] options @copydoc initArg4 /// \param[in] progid @copydoc initArg5 /// \param[in] username @copydoc initArg6 /// \param[in] password @copydoc initArg7 lvDCOMInterface::lvDCOMInterface(const char *configSection, const char* configFile, const char* host, int options, const char* progid, const char* username, const char* password) : m_configSection(configSection), m_pidentity(NULL), m_pxmldom(NULL), m_options(options), m_progid(progid != NULL? progid : ""), m_username(username != NULL? username : ""), m_password(password != NULL ? password : ""), m_mac_env(NULL) { epicsThreadOnce(&onceId, initCOM, NULL); if (host != NULL && host[0] != '\0') { m_host = host; } else { // char name_buffer[MAX_COMPUTERNAME_LENGTH + 1]; // DWORD name_size = MAX_COMPUTERNAME_LENGTH + 1; // if ( GetComputerNameEx(ComputerNameNetBIOS, name_buffer, &name_size) != 0 ) // { // m_host = name_buffer; // } // else // { // m_host = "localhost"; // } m_host = "localhost"; } if (macCreateHandle(&m_mac_env, NULL) != 0) { throw std::runtime_error("Cannot create mac handle"); } // load current environment into m_mac_env, this is so we can create a macEnvExpand() equivalent // but tied to the environment at a specific time. It is useful if we want to load the same // XML file twice but with a macro defined differently in each case for(char** cp = environ; *cp != NULL; ++cp) { char* str_tmp = strdup(*cp); char* equals_loc = strchr(str_tmp, '='); // split name=value string if (equals_loc != NULL) { *equals_loc = '\0'; macPutValue(m_mac_env, str_tmp, equals_loc + 1); } free(str_tmp); } // m_doc = new TiXmlDocument; // if ( !m_doc->LoadFile(configFile) ) // { // delete m_doc; // m_doc = NULL; // throw std::runtime_error("Cannot load " + std::string(configFile) + ": load failure"); // } // m_root = m_doc->RootElement(); DomFromCOM(); short sResult = FALSE; char* configFile_expanded = envExpand(configFile); m_configFile = configFile_expanded; HRESULT hr = m_pxmldom->load(_variant_t(configFile_expanded), &sResult); free(configFile_expanded); if(FAILED(hr)) { throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure"); } if (sResult != VARIANT_TRUE) { throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure"); } std::cerr << "Loaded XML config file \"" << m_configFile << "\" (expanded from \"" << configFile << "\")" << std::endl; m_extint = doPath("/lvinput/extint/@path").c_str(); epicsAtExit(epicsExitFunc, this); if (m_progid.size() > 0) { if ( CLSIDFromProgID(CT2W(m_progid.c_str()), &m_clsid) != S_OK ) { throw std::runtime_error("Cannot find progId " + m_progid); } } else { m_clsid = LabVIEW::CLSID_Application; wchar_t* progid_str = NULL; if ( ProgIDFromCLSID(m_clsid, &progid_str) == S_OK ) { m_progid = CW2CT(progid_str); CoTaskMemFree(progid_str); } else { m_progid = "LabVIEW.Application"; } } wchar_t* clsid_str = NULL; if ( StringFromCLSID(m_clsid, &clsid_str) == S_OK ) { std::cerr << "Using ProgID \"" << m_progid << "\" CLSID " << CW2CT(clsid_str) << std::endl; CoTaskMemFree(clsid_str); } else { std::cerr << "Using ProgID \"" << m_progid << "\" but StringFromCLSID() failed" << std::endl; } }
/*************************************************** * initialize all software and hardware * scaler_init() ****************************************************/ STATIC long scaler_init(int after) { volatile char *localAddr; unsigned long status; void *baseAddr; int card, i; uint32 probeValue = 0; Debug(2,"scaler_init(): entry, after = %d\n", after); if (after || (vsc_num_cards == 0)) return(0); /* allocate scaler_state structures, array of pointers */ if (scaler_state == NULL) { scaler_state = (struct scaler_state **) calloc(1, vsc_num_cards * sizeof(struct scaler_state *)); scaler_total_cards=0; for (card=0; card<vsc_num_cards; card++) { scaler_state[card] = (struct scaler_state *) calloc(1, sizeof(struct scaler_state)); } } /* Check out the hardware. */ for (card=0; card<vsc_num_cards; card++) { baseAddr = (void *)(vsc_addrs + card*CARD_ADDRESS_SPACE); /* Can we reserve the required block of VME address space? */ status = devRegisterAddress(__FILE__, atVMEA32, (size_t)baseAddr, CARD_ADDRESS_SPACE, (volatile void **)&localAddr); if (!RTN_SUCCESS(status)) { errPrintf(status, __FILE__, __LINE__, "Can't register 0x%x-byte block at address %p\n", CARD_ADDRESS_SPACE, baseAddr); return (ERROR); } if (devReadProbe(4,(volatile void *)(localAddr+DATA_0_OFFSET),(void*)&probeValue)) { printf("no VSC card at %p\n",localAddr); return(0); } /* Declare victory. */ Debug(2,"scaler_init: we own 256 bytes starting at %p\n",localAddr); scaler_state[card]->localAddr = localAddr; scaler_total_cards++; /* reset this card */ writeReg16(localAddr,RESET_OFFSET,0); /* get this card's identification */ scaler_state[card]->ident = readReg16(localAddr,REV_SERIAL_NO_OFFSET); Debug(3,"scaler_init: Serial # = %d\n", scaler_state[card]->ident); scaler_state[card]->card_exists = 1; /* get this card's type (8 or 16 channels?) */ Debug(2,"scaler_init:Base Address=0x%8.8x\n",(int)baseAddr); Debug(2,"scaler_init:Local Address=0x%8.8x\n",(int)localAddr); scaler_state[card]->num_channels = readReg16(localAddr,MODULE_TYPE_OFFSET) & 0x18; Debug(3,"scaler_init: nchan = %d\n", scaler_state[card]->num_channels); if (scaler_state[card]->num_channels < 8) { scaler_state[card]->card_exists = 0; continue; } for (i=0; i<MAX_SCALER_CHANNELS; i++) { scaler_state[card]->preset[i] = 0; } } Debug(3,"scaler_init: Total cards = %d\n\n",scaler_total_cards); #ifdef vxWorks if (epicsAtExit(scaler_shutdown, 0) < 0) epicsPrintf ("scaler_init: epicsAtExit() failed\n"); #endif Debug(3, "%s", "scaler_init: scalers initialized\n"); return(0); }
/* * logClientCreate() */ logClientId epicsShareAPI logClientCreate ( struct in_addr server_addr, unsigned short server_port) { epicsTimeStamp begin, current; logClient *pClient; double diff; pClient = calloc (1, sizeof (*pClient)); if (pClient==NULL) { return NULL; } pClient->addr.sin_family = AF_INET; pClient->addr.sin_addr = server_addr; pClient->addr.sin_port = htons(server_port); ipAddrToDottedIP (&pClient->addr, pClient->name, sizeof(pClient->name)); pClient->mutex = epicsMutexCreate (); if ( ! pClient->mutex ) { free ( pClient ); return NULL; } pClient->sock = INVALID_SOCKET; pClient->connected = 0u; pClient->connFailStatus = 0; pClient->shutdown = 0; pClient->shutdownConfirm = 0; epicsAtExit (logClientDestroy, (void*) pClient); pClient->stateChangeNotify = epicsEventCreate (epicsEventEmpty); if ( ! pClient->stateChangeNotify ) { epicsMutexDestroy ( pClient->mutex ); free ( pClient ); return NULL; } pClient->restartThreadId = epicsThreadCreate ( "logRestart", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackSmall), logClientRestart, pClient ); if ( pClient->restartThreadId == NULL ) { epicsMutexDestroy ( pClient->mutex ); epicsEventDestroy ( pClient->stateChangeNotify ); free (pClient); fprintf(stderr, "log client: unable to start log client connection watch dog thread\n"); return NULL; } /* * attempt to synchronize with circuit connect */ epicsTimeGetCurrent ( & begin ); epicsMutexMustLock ( pClient->mutex ); do { epicsMutexUnlock ( pClient->mutex ); epicsEventWaitWithTimeout ( pClient->stateChangeNotify, LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT / 10.0 ); epicsTimeGetCurrent ( & current ); diff = epicsTimeDiffInSeconds ( & current, & begin ); epicsMutexMustLock ( pClient->mutex ); } while ( ! pClient->connected && diff < LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT ); epicsMutexUnlock ( pClient->mutex ); if ( ! pClient->connected ) { fprintf (stderr, "log client create: timed out synchronizing with circuit connect to \"%s\" after %.1f seconds\n", pClient->name, LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT ); } return (void *) pClient; }
void NiPci6220MainThread(void *arg) { int i; int ret; char szFile[256]; DaqQueueData pDAQData; ret = NiPci6220Config(); epicsAtExit((EPICSEXITFUNC) NiPci6220Exit, NULL); if(ret > 0) { epicsPrintf("NiPci6220 Initialize Error\n"); return; } epicsPrintf("NiPci6220 Initialize OK\n"); while(1) { epicsMessageQueueReceive(daq6220pvt.DaqQueueId, (void *)&pDAQData, sizeof(DaqQueueData)); switch(pDAQData.opcode) { case OP_CODE_DAQ_RUN: if(daq6220pvt.status == DAQ_STATUS_STOP) { system("rm -f /tmp/nidaq_6220.dat"); daq6220pvt.status = DAQ_STATUS_RUN; epicsPrintf("NI6220 : OP_CODE_DAQ_RUN\n"); for(i=0; i < 16; i++) { if(daq6220pvt.mdsput[i] == 1 && daq6220pvt.fp[i] == NULL) { sprintf(szFile, "/tmp/%s_%d.dat", daq6220pvt.fileName, i); daq6220pvt.fp[i] = fopen(szFile, "w+"); } } ret = SetDaqStart(&daq6220pvt); } break; case OP_CODE_DAQ_STOP: /* Stop Task */ if(daq6220pvt.status == DAQ_STATUS_RUN) { daq6220pvt.status = DAQ_STATUS_STOP; epicsPrintf("NI6220 : OP_CODE_DAQ_STOP\n"); } break; case OP_CODE_DAQ_CONFIG: if(daq6220pvt.status != DAQ_STATUS_RUN) { SetDaqAbort(&daq6220pvt); NiPci6220Config(); } break; case OP_CODE_DAQ_ABORT: /* Task clear and Initialize */ if(daq6220pvt.status == DAQ_STATUS_RUN) { epicsPrintf("NI6220 : Abort\n"); SetDaqAbort(&daq6220pvt); NiPci6220Config(); } break; case OP_CODE_DAQ_MDSPLUS: /* MDSPlus Data Write */ epicsPrintf("**** NI6220 MDSPlus Write ****\n"); daq6220pvt.status = DAQ_STATUS_DONE; break; } epicsThreadSleep(0.1); } }
/** Constructor for the drvQuadEM class. * Calls constructor for the asynPortDriver base class. * \param[in] portName The name of the asyn port driver to be created. * \param[in] numParams The number of driver-specific parameters for the derived class * \param[in] ringBufferSize The number of samples to hold in the input ring buffer. * This should be large enough to hold all the samples between reads of the * device, e.g. 1 ms SampleTime and 1 second read rate = 1000 samples. * If 0 then default of 2048 is used. */ drvQuadEM::drvQuadEM(const char *portName, int numParams, int ringBufferSize) : asynNDArrayDriver(portName, QE_MAX_DATA+1, /* maxAddr */ NUM_QE_PARAMS + numParams, 0, 0, /* maxBuffers, maxMemory, no limits */ asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynGenericPointerMask | asynDrvUserMask, /* Interface mask */ asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynGenericPointerMask, /* Interrupt mask */ ASYN_CANBLOCK | ASYN_MULTIDEVICE, /* asynFlags. This driver blocks it is multi-device */ 1, /* Autoconnect */ 0, /* Default priority */ 0) /* Default stack size*/ { int i; int status; const char *functionName = "drvQuadEM"; asynUser *pasynUser; createParam(P_AcquireString, asynParamInt32, &P_Acquire); createParam(P_AcquireModeString, asynParamInt32, &P_AcquireMode); createParam(P_CurrentOffsetString, asynParamFloat64, &P_CurrentOffset); createParam(P_CurrentScaleString, asynParamFloat64, &P_CurrentScale); createParam(P_PositionOffsetString, asynParamFloat64, &P_PositionOffset); createParam(P_PositionScaleString, asynParamFloat64, &P_PositionScale); createParam(P_GeometryString, asynParamInt32, &P_Geometry); createParam(P_DoubleDataString, asynParamFloat64, &P_DoubleData); createParam(P_IntArrayDataString, asynParamInt32Array, &P_IntArrayData); createParam(P_RingOverflowsString, asynParamInt32, &P_RingOverflows); createParam(P_ReadDataString, asynParamInt32, &P_ReadData); createParam(P_PingPongString, asynParamInt32, &P_PingPong); createParam(P_IntegrationTimeString, asynParamFloat64, &P_IntegrationTime); createParam(P_SampleTimeString, asynParamFloat64, &P_SampleTime); createParam(P_RangeString, asynParamInt32, &P_Range); createParam(P_ResetString, asynParamInt32, &P_Reset); createParam(P_TriggerModeString, asynParamInt32, &P_TriggerMode); createParam(P_NumChannelsString, asynParamInt32, &P_NumChannels); createParam(P_BiasStateString, asynParamInt32, &P_BiasState); createParam(P_BiasVoltageString, asynParamFloat64, &P_BiasVoltage); createParam(P_BiasInterlockString, asynParamInt32, &P_BiasInterlock); createParam(P_HVSReadbackString, asynParamInt32, &P_HVSReadback); createParam(P_HVVReadbackString, asynParamFloat64, &P_HVVReadback); createParam(P_HVIReadbackString, asynParamFloat64, &P_HVIReadback); createParam(P_TemperatureString, asynParamFloat64, &P_Temperature); createParam(P_ReadStatusString, asynParamInt32, &P_ReadStatus); createParam(P_ResolutionString, asynParamInt32, &P_Resolution); createParam(P_ValuesPerReadString, asynParamInt32, &P_ValuesPerRead); createParam(P_NumAcquireString, asynParamInt32, &P_NumAcquire); createParam(P_NumAcquiredString, asynParamInt32, &P_NumAcquired); createParam(P_ReadFormatString, asynParamInt32, &P_ReadFormat); createParam(P_AveragingTimeString, asynParamFloat64, &P_AveragingTime); createParam(P_NumAverageString, asynParamInt32, &P_NumAverage); createParam(P_NumAveragedString, asynParamInt32, &P_NumAveraged); createParam(P_ModelString, asynParamInt32, &P_Model); createParam(P_FirmwareString, asynParamOctet, &P_Firmware); setIntegerParam(P_Acquire, 0); setIntegerParam(P_RingOverflows, 0); setIntegerParam(P_PingPong, 0); setDoubleParam(P_IntegrationTime, 0.); setIntegerParam(P_Range, 0); setIntegerParam(P_TriggerMode, 0); setIntegerParam(P_NumChannels, 4); numChannels_ = 4; setIntegerParam(P_BiasState, 0); setDoubleParam(P_BiasVoltage, 0.); setIntegerParam(P_Resolution, 16); setIntegerParam(P_ValuesPerRead, 1); setIntegerParam(P_ReadFormat, 0); for (i=0; i<QE_MAX_DATA; i++) { setDoubleParam(i, P_DoubleData, 0.0); } valuesPerRead_ = 1; if (ringBufferSize <= 0) ringBufferSize = QE_DEFAULT_RING_BUFFER_SIZE; ringBuffer_ = epicsRingBytesCreate(ringBufferSize * QE_MAX_DATA * sizeof(epicsFloat64)); ringEvent_ = epicsEventCreate(epicsEventEmpty); /* Create the thread that does callbacks when the ring buffer has numAverage samples */ status = (asynStatus)(epicsThreadCreate("drvQuadEMCallbackTask", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)::callbackTaskC, this) == NULL); if (status) { printf("%s:%s: epicsThreadCreate failure, status=%d\n", driverName, functionName, status); return; } // This driver supports QE_MAX_DATA+1 addresses = 0-11 with autoConnect=1. But there are only records // connected to addresses 0-3, so addresses 4-11 never show as "connected" since nothing ever calls // pasynManager->queueRequest. So we do an exceptionConnect to each address so asynManager will show // them as connected. Note that this is NOT necessary for the driver to function correctly, the // NDPlugins will still get called even for addresses that are not "connected". It is just to // avoid confusion. for (i=0; i<QE_MAX_DATA+1; i++) { pasynUser = pasynManager->createAsynUser(0,0); pasynManager->connectDevice(pasynUser, portName, i); pasynManager->exceptionConnect(pasynUser); } epicsAtExit(exitHandlerC, this); }