static void serialBaseInit(void) { if(pserialBase) return; pserialBase = callocMustSucceed(1,sizeof(serialBase),"serialBaseInit"); pserialBase->timerQueue = epicsTimerQueueAllocate( 1,epicsThreadPriorityScanLow); }
/*internal methods */ static void gpibInit(void) { if(pgpibBase) return; pgpibBase = callocMustSucceed(1,sizeof(gpibPvt),"gpibInit"); ellInit(&pgpibBase->gpibPvtList); pgpibBase->timerQueue = epicsTimerQueueAllocate( 1,epicsThreadPriorityScanLow); }
void callbackInit(void) { int i; int j; char threadName[32]; if (callbackIsInit) { errlogMessage("Warning: callbackInit called again before callbackCleanup\n"); return; } callbackIsInit = 1; if(!startStopEvent) startStopEvent = epicsEventMustCreate(epicsEventEmpty); cbCtl = ctlRun; timerQueue = epicsTimerQueueAllocate(0, epicsThreadPriorityScanHigh); for (i = 0; i < NUM_CALLBACK_PRIORITIES; i++) { epicsThreadId tid; callbackQueue[i].semWakeUp = epicsEventMustCreate(epicsEventEmpty); callbackQueue[i].queue = epicsRingPointerLockedCreate(callbackQueueSize); if (callbackQueue[i].queue == 0) cantProceed("epicsRingPointerLockedCreate failed for %s\n", threadNamePrefix[i]); callbackQueue[i].queueOverflow = FALSE; if (callbackQueue[i].threadsConfigured == 0) callbackQueue[i].threadsConfigured = callbackThreadsDefault; for (j = 0; j < callbackQueue[i].threadsConfigured; j++) { if (callbackQueue[i].threadsConfigured > 1 ) sprintf(threadName, "%s-%d", threadNamePrefix[i], j); else strcpy(threadName, threadNamePrefix[i]); tid = epicsThreadCreate(threadName, threadPriority[i], epicsThreadGetStackSize(epicsThreadStackBig), (EPICSTHREADFUNC)callbackTask, &priorityValue[i]); if (tid == 0) { cantProceed("Failed to spawn callback thread %s\n", threadName); } else { epicsEventWait(startStopEvent); epicsAtomicIncrIntT(&callbackQueue[i].threadsRunning); } } } }
int simRegDevConfigure( const char* name, size_t size, int swapEndianFlag, int async) { regDevice* device; if (name == NULL) { printf("usage: simRegDevConfigure(\"name\", size, swapEndianFlag)\n"); printf("maps allocated memory block to device \"name\""); printf("\"name\" must be a unique string on this IOC\n"); return S_dev_success; } device = (regDevice*)calloc(sizeof(regDevice)+size-1,1); if (device == NULL) { errlogSevPrintf(errlogFatal, "simRegDevConfigure %s: out of memory\n", name); return errno; } device->magic = MAGIC; device->name = strdup(name); device->size = size; device->connected = 1; device->swap = swapEndianFlag; if (async) { int i; device->lock = epicsMutexCreate(); for (i = 0; i < NUM_CALLBACK_PRIORITIES; i++) { const unsigned int prio [3] = {epicsThreadPriorityLow, epicsThreadPriorityMedium, epicsThreadPriorityHigh}; device->queue[i] = epicsTimerQueueAllocate(FALSE, prio[i]); } } regDevRegisterDevice(name, &simRegDevSupport, device, size); scanIoInit(&device->ioscanpvt); return S_dev_success; }
/** Constructor for mar345 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 for the parameters defined in this class and ADDriver. * \param[in] portName The name of the asyn port driver to be created. * \param[in] serverPort The name of the asyn port driver previously created with drvAsynIPPortConfigure * connected to the mar345dtb program. * \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. * \param[in] stackSize The stack size for the asyn port driver thread. */ mar345::mar345(const char *portName, const char *serverPort, int maxBuffers, size_t maxMemory, int priority, int stackSize) : ADDriver(portName, 1, NUM_MAR345_PARAMS, maxBuffers, maxMemory, 0, 0, /* No interfaces beyond those set in ADDriver.cpp */ ASYN_CANBLOCK, 1, /* ASYN_CANBLOCK=1, ASYN_MULTIDEVICE=0, autoConnect=1 */ priority, stackSize), pData(NULL) { int status = asynSuccess; epicsTimerQueueId timerQ; const char *functionName = "mar345"; size_t dims[2]; createParam(mar345EraseString, asynParamInt32, &mar345Erase); createParam(mar345EraseModeString, asynParamInt32, &mar345EraseMode); createParam(mar345NumEraseString, asynParamInt32, &mar345NumErase); createParam(mar345NumErasedString, asynParamInt32, &mar345NumErased); createParam(mar345ChangeModeString,asynParamInt32, &mar345ChangeMode); createParam(mar345SizeString, asynParamInt32, &mar345Size); createParam(mar345ResString, asynParamInt32, &mar345Res); createParam(mar345AbortString, asynParamInt32, &mar345Abort); this->mode = mar345ModeIdle; /* Create the epicsEvents for signaling to the mar345 task when acquisition starts and stops */ this->startEventId = epicsEventCreate(epicsEventEmpty); if (!this->startEventId) { printf("%s:%s epicsEventCreate failure for start event\n", driverName, functionName); return; } this->stopEventId = epicsEventCreate(epicsEventEmpty); if (!this->stopEventId) { printf("%s:%s epicsEventCreate failure for stop event\n", driverName, functionName); return; } this->abortEventId = epicsEventCreate(epicsEventEmpty); if (!this->abortEventId) { printf("%s:%s epicsEventCreate failure for abort event\n", driverName, functionName); return; } /* Create the epicsTimerQueue for exposure time handling */ timerQ = epicsTimerQueueAllocate(1, epicsThreadPriorityScanHigh); this->timerId = epicsTimerQueueCreateTimer(timerQ, timerCallbackC, this); /* Connect to server */ status = pasynOctetSyncIO->connect(serverPort, 0, &this->pasynUserServer, NULL); dims[0] = 3450; dims[1] = 3450; /* Allocate the raw buffer we use to files. Only do this once */ setIntegerParam(ADMaxSizeX, (int)dims[0]); setIntegerParam(ADMaxSizeY, (int)dims[1]); this->pData = this->pNDArrayPool->alloc(2, dims, NDInt16, 0, NULL); /* Set some default values for parameters */ status = setStringParam (ADManufacturer, "MAR"); status |= setStringParam (ADModel, "345"); status |= setIntegerParam(NDDataType, NDInt16); status |= setIntegerParam(ADImageMode, ADImageSingle); status |= setIntegerParam(ADTriggerMode, TMInternal); status |= setDoubleParam (ADAcquireTime, 1.); status |= setDoubleParam (ADAcquirePeriod, 0.); status |= setIntegerParam(ADNumImages, 1); status |= setIntegerParam(mar345EraseMode, mar345EraseAfter); status |= setIntegerParam(mar345Size, mar345Size345); status |= setIntegerParam(mar345Res, mar345Res100); status |= setIntegerParam(mar345NumErase, 1); status |= setIntegerParam(mar345NumErased , 0); status |= setIntegerParam(mar345Erase, 0); status |= setIntegerParam(mar345Res, mar345Res100); if (status) { printf("%s: unable to set camera parameters\n", functionName); return; } /* Create the thread that collects the data */ status = (epicsThreadCreate("mar345Task", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)mar345TaskC, this) == NULL); if (status) { printf("%s:%s epicsThreadCreate failure for data collection task\n", driverName, functionName); return; } }
/* * Run timer task just below the low priority callback task and higher * than the default for the channel access tasks. Also, set okToShare to 0 * so that the task is dedicated to devIocStats. */ static void timerQCreate(void*unused) { timerQ = epicsTimerQueueAllocate(0, epicsThreadPriorityScanLow - 2); }
/** Constructor for BIS 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 for the parameters defined in this class, asynNDArrayDriver, and ADDriver. * \param[in] portName The name of the asyn port driver to be created. * \param[in] commandPort The name of the asyn port previously created with drvAsynIPPortConfigure to * send commands to BIS. * \param[in] statusPort The name of the asyn port previously created with drvAsynIPPortConfigure to * receive status information from BIS. * \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. */ BISDetector::BISDetector(const char *portName, const char *commandPort, const char *statusPort, int maxBuffers, size_t maxMemory, int priority, int stackSize) : ADDriver(portName, 1, NUM_BIS_PARAMS, maxBuffers, maxMemory, 0, 0, /* No interfaces beyond those set in ADDriver.cpp */ ASYN_CANBLOCK, 1, /* ASYN_CANBLOCK=1, ASYN_MULTIDEVICE=0, autoConnect=1 */ priority, stackSize) { int status = asynSuccess; epicsTimerQueueId timerQ; const char *functionName = "BISDetector"; createParam(BISSFRMTimeoutString, asynParamFloat64, &BISSFRMTimeout); createParam(BISNumDarksString, asynParamInt32, &BISNumDarks); createParam(BISStatusString, asynParamOctet, &BISStatus); /* Create the epicsEvents for signaling to the BIS task when acquisition starts and stops */ this->startEventId = epicsEventMustCreate(epicsEventEmpty); this->stopEventId = epicsEventMustCreate(epicsEventEmpty); this->readoutEventId = epicsEventMustCreate(epicsEventEmpty); /* Create the epicsTimerQueue for exposure time handling */ timerQ = epicsTimerQueueAllocate(1, epicsThreadPriorityScanHigh); this->timerId = epicsTimerQueueCreateTimer(timerQ, timerCallbackC, this); /* Connect to BIS */ status = pasynOctetSyncIO->connect(commandPort, 0, &this->pasynUserCommand, NULL); status = pasynOctetSyncIO->connect(statusPort, 0, &this->pasynUserStatus, NULL); /* Set some default values for parameters */ status = setStringParam (ADManufacturer, "Bruker"); status |= setStringParam (ADModel, "BIS"); status |= setIntegerParam(ADMaxSizeX, 4096); status |= setIntegerParam(ADMaxSizeY, 4096); status |= setIntegerParam(ADSizeX, 0); status |= setIntegerParam(ADSizeY, 0); status |= setIntegerParam(NDArraySizeX, 0); status |= setIntegerParam(NDArraySizeY, 0); status |= setIntegerParam(NDArraySize, 0); status |= setIntegerParam(NDDataType, NDUInt32); status |= setIntegerParam(ADImageMode, ADImageContinuous); if (status) { printf("%s: unable to set camera parameters\n", functionName); return; } /* Create the thread that updates the images */ status = (epicsThreadCreate("BISDetTask", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)BISTaskC, this) == NULL); if (status) { printf("%s:%s epicsThreadCreate failure for image task\n", driverName, functionName); return; } /* Create the thread that reads the status socket */ status = (epicsThreadCreate("BISStatusTask", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)statusTaskC, this) == NULL); if (status) { printf("%s:%s epicsThreadCreate failure for status task\n", driverName, functionName); return; } }