static drvM6802_taskConfig* make_taskConfig(char *taskName, uint16 vme_addr) { static uint16 boardcnt = 1; drvM6802_taskConfig *ptaskConfig = NULL; char task_name[60]; int i; strcpy(task_name, taskName); ptaskConfig = (drvM6802_taskConfig*) malloc(sizeof(drvM6802_taskConfig)); if(!ptaskConfig) return ptaskConfig; ptaskConfig->BoardID = boardcnt; ptaskConfig->vme_addr = vme_addr; strcpy(ptaskConfig->taskName, task_name); ptaskConfig->taskLock = epicsMutexCreate(); ptaskConfig->bufferLock = epicsMutexCreate(); scanIoInit(&ptaskConfig->ioScanPvt); /* ptaskConfig->masterMode = 0; */ ptaskConfig->masterMode = ( ptaskConfig->BoardID == 1 ) ? 1 : 0; ptaskConfig->samplingRate = INIT_SAMPLING; ptaskConfig->appSampleRate = INIT_SAMPLING; ptaskConfig->channelMask = INIT_CH_MASK; ptaskConfig->clockSource = (ptaskConfig->BoardID == 1) ? 0 : 1; /* default 0 : internal clock , 1: external*/ /* ptaskConfig->msgFPDP = 0; */ ptaskConfig->cnt_DMAcallback = 0; ptaskConfig->nTrigPolarity = INIT_TRIG_POLARITY; /* ptaskConfig->pcallback = (CALLBACK*) taskCallback; */ ptaskConfig->fT0 = 1.; ptaskConfig->fT1 = 2.; boardcnt++; ptaskConfig->pcontrolThreadConfig = NULL; ptaskConfig->pfpdpThreadConfig = NULL; for( i=0; i< 16 ; i++) ptaskConfig->register_m6802[i] = DUMMY_DATA; ptaskConfig->adjTime_smplRate_Usec = 0.; ptaskConfig->adjTime_Gain_Usec = 0.; ptaskConfig->adjCount_smplRate = 0; ptaskConfig->adjCount_Gain = 0; ptaskConfig->pchannelConfig = (ELLLIST*) malloc(sizeof(ELLLIST)); if(!ptaskConfig->pchannelConfig) return NULL; else ellInit(ptaskConfig->pchannelConfig); ptaskConfig->taskStatus = TASK_NOT_INIT; return ptaskConfig; }
static TagInfo *new_TagInfo(const char *string_tag, size_t elements) { TagInfo *info = (TagInfo *) calloc(sizeof(TagInfo), 1); if (!info) return 0; info->string_tag = EIP_strdup(string_tag); if (! info->string_tag) return 0; info->tag = EIP_parse_tag(string_tag); if (! info->tag) { EIP_printf(2, "new_TagInfo: failed to parse tag '%s'\n", string_tag); return 0; } info->elements = elements; info->data_lock = epicsMutexCreate(); if (! info->data_lock) { EIP_printf(0, "new_TagInfo (%s): Cannot create data lock\n", string_tag); return 0; } DLL_init(&info->callbacks); return info; }
/** Constructor for NDPluginFile; all parameters are simply passed to NDPluginDriver::NDPluginDriver. * \param[in] portName The name of the asyn port driver to be created. * \param[in] queueSize The number of NDArrays that the input queue for this plugin can hold when * NDPluginDriverBlockingCallbacks=0. Larger queues can decrease the number of dropped arrays, * at the expense of more NDArray buffers being allocated from the underlying driver's NDArrayPool. * \param[in] blockingCallbacks Initial setting for the NDPluginDriverBlockingCallbacks flag. * 0=callbacks are queued and executed by the callback thread; 1 callbacks execute in the thread * of the driver doing the callbacks. * \param[in] NDArrayPort Name of asyn port driver for initial source of NDArray callbacks. * \param[in] NDArrayAddr asyn port driver address for initial source of NDArray callbacks. * \param[in] maxAddr The maximum number of asyn addr addresses this driver supports. 1 is minimum. * \param[in] maxBuffers The maximum number of NDArray buffers that the NDArrayPool for this driver is * allowed to allocate. Set this to 0 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 0 to allow an unlimited amount of memory. * \param[in] interfaceMask Bit mask defining the asyn interfaces that this driver supports. * \param[in] interruptMask Bit mask definining the asyn interfaces that can generate interrupts (callbacks) * \param[in] asynFlags Flags when creating the asyn port driver; includes ASYN_CANBLOCK and ASYN_MULTIDEVICE. * \param[in] autoConnect The autoConnect flag for the asyn port driver. * \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. * \param[in] maxThreads The maximum number of threads this driver is allowed to use. If 0 then 1 will be used. */ NDPluginFile::NDPluginFile(const char *portName, int queueSize, int blockingCallbacks, const char *NDArrayPort, int NDArrayAddr, int maxAddr, int maxBuffers, size_t maxMemory, int interfaceMask, int interruptMask, int asynFlags, int autoConnect, int priority, int stackSize, int maxThreads) /* Invoke the base class constructor. * We allocate 1 NDArray of unlimited size in the NDArray pool. * This driver can block (because writing a file can be slow), and it is not multi-device. * Set autoconnect to 1. priority and stacksize can be 0, which will use defaults. */ : NDPluginDriver(portName, queueSize, blockingCallbacks, NDArrayPort, NDArrayAddr, maxAddr, maxBuffers, maxMemory, asynGenericPointerMask, asynGenericPointerMask, asynFlags, autoConnect, priority, stackSize, maxThreads), pCapture(NULL), captureBufferSize(0) { //static const char *functionName = "NDPluginFile"; this->ndArrayInfoInit = NULL; this->lazyOpen = false; this->useAttrFilePrefix = false; this->fileMutexId = epicsMutexCreate(); /* Set the plugin type string */ setStringParam(NDPluginDriverPluginType, "NDPluginFile"); // Disable ArrayCallbacks. // This plugin currently does not do array callbacks, so make the setting reflect the behavior setIntegerParam(NDArrayCallbacks, 0); /* Try to connect to the NDArray port */ connectToArrayPort(); }
int enable_CA() { Channel *chan; Connector *conp; if( processFlag == 0 ) processFlag = epicsMutexCreate(); epicsMutexLock( processFlag); startupFlag = 0; for( chan=reProcessList; chan; chan = chan->next_proc) { chan->reprocess = 0; /* * update the data values */ for( conp=chan->first_connector; conp ; conp=conp->next_chan) { if( conp->newState) (*conp->newState)(conp); DEBUGP printf("Calling function %p\n", conp->update); if( conp->update) conp->update(conp); } } epicsMutexUnlock(processFlag); return 0; }
void epicsConnectLock() { if( processFlag == 0) processFlag = epicsMutexCreate(); epicsMutexLock( processFlag); }
int acqRegisterOutputHandler( acqMaster_t *master, acqKey_t key, struct eventDataHandler *edh) { int i; /* * don't register null arguments */ if( key == NULL || edh == NULL) return -1; /* * don't re-register an existing key, as this would cause duplicate calls for the * same key resulting in mass confusion and rioting in the streets. If a duplicate * key is entered, then the event handler list is updated. */ for(i=0; i < master->numOutputHandler; i++) { if( key == master->outputKeys[i]) { master->outputHandler[i] = edh; return 0; } } i = master->numOutputHandler++; master->outputHandler = (eventDataHandler_t **)realloc(master->outputHandler, (master->numOutputHandler)*sizeof (eventDataHandler_t *) ); master->outputKeys = (void *) realloc( master->outputKeys, (master->numOutputHandler)* sizeof (void *)); master->handlerLock = (epicsMutexId *) realloc( master->handlerLock, (master->numOutputHandler) * sizeof (epicsMutexId)); master->outputHandler[i] = edh; master->outputKeys[i] = key; master->handlerLock[i] = epicsMutexCreate(); return 0; }
/** Constructor for NDPluginFile; all parameters are simply passed to NDPluginDriver::NDPluginDriver. * \param[in] portName The name of the asyn port driver to be created. * \param[in] queueSize The number of NDArrays that the input queue for this plugin can hold when * NDPluginDriverBlockingCallbacks=0. Larger queues can decrease the number of dropped arrays, * at the expense of more NDArray buffers being allocated from the underlying driver's NDArrayPool. * \param[in] blockingCallbacks Initial setting for the NDPluginDriverBlockingCallbacks flag. * 0=callbacks are queued and executed by the callback thread; 1 callbacks execute in the thread * of the driver doing the callbacks. * \param[in] NDArrayPort Name of asyn port driver for initial source of NDArray callbacks. * \param[in] NDArrayAddr asyn port driver address for initial source of NDArray callbacks. * \param[in] maxAddr The maximum number of asyn addr addresses this driver supports. 1 is minimum. * \param[in] numParams The number of parameters supported by the derived class calling this constructor. * \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] interfaceMask Bit mask defining the asyn interfaces that this driver supports. * \param[in] interruptMask Bit mask definining the asyn interfaces that can generate interrupts (callbacks) * \param[in] asynFlags Flags when creating the asyn port driver; includes ASYN_CANBLOCK and ASYN_MULTIDEVICE. * \param[in] autoConnect The autoConnect flag for the asyn port driver. * \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. */ NDPluginFile::NDPluginFile(const char *portName, int queueSize, int blockingCallbacks, const char *NDArrayPort, int NDArrayAddr, int maxAddr, int numParams, int maxBuffers, size_t maxMemory, int interfaceMask, int interruptMask, int asynFlags, int autoConnect, int priority, int stackSize) /* Invoke the base class constructor. * We allocate 1 NDArray of unlimited size in the NDArray pool. * This driver can block (because writing a file can be slow), and it is not multi-device. * Set autoconnect to 1. priority and stacksize can be 0, which will use defaults. */ : NDPluginDriver(portName, queueSize, blockingCallbacks, NDArrayPort, NDArrayAddr, maxAddr, numParams+NUM_NDPLUGIN_FILE_PARAMS, maxBuffers, maxMemory, asynGenericPointerMask, asynGenericPointerMask, asynFlags, autoConnect, priority, stackSize), pCapture(NULL), captureBufferSize(0) { //const char *functionName = "NDPluginFile"; this->useAttrFilePrefix = false; this->fileMutexId = epicsMutexCreate(); /* Set the plugin type string */ setStringParam(NDPluginDriverPluginType, "NDPluginFile"); /* Try to connect to the NDArray port */ connectToArrayPort(); }
int sharedDevPCIInit(void) { sharedGuard = epicsMutexCreate(); if(sharedGuard) return 0; return S_dev_internal; }
static long init_i2cbus(int phase) { if(phase == 0) { if (!mutex) mutex = epicsMutexCreate(); i2c_init(); } return(0); }
void drvEtherIP_init () { if (drvEtherIP_private.lock) { EIP_printf (0, "drvEtherIP_init called more than once!\n"); return; } drvEtherIP_private.lock = epicsMutexCreate(); if (! drvEtherIP_private.lock) EIP_printf (0, "drvEtherIP_init cannot create mutex!\n"); DLL_init (&drvEtherIP_private.PLCs); drvEtherIP_Register(); }
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); }
epicsShareFunc int testPmacAsynIPPort(const char *portName, int readTimeout) { myData *pPvt; asynUser *pasynUser; asynStatus status; int addr=0; asynInterface *pasynInterface; pPvt = (myData *)callocMustSucceed(1, sizeof(myData), "testPmacAsynIPPort"); pPvt->mutexId = epicsMutexCreate(); pPvt->portName = epicsStrDup(portName); pasynUser = pasynManager->createAsynUser(0,0); pasynUser->userPvt = pPvt; status = pasynManager->connectDevice(pasynUser,portName,addr); if(status!=asynSuccess) { printf("testPmacAsynIPPort: can't connect to port %s: %s\n", portName, pasynUser->errorMessage); return -1; } pasynInterface = pasynManager->findInterface( pasynUser,asynOctetType,1); if(!pasynInterface) { printf("testPmacAsynIPPort: %s driver not supported\n",asynOctetType); return -1; } if (readTimeout == 0) pPvt->readTimeout = READ_TIMEOUT; else pPvt->readTimeout = (double)readTimeout; pPvt->pasynOctet = (asynOctet *)pasynInterface->pinterface; pPvt->octetPvt = pasynInterface->drvPvt; status = pPvt->pasynOctet->registerInterruptUser( pPvt->octetPvt, pasynUser, connectionCallback,pPvt,&pPvt->registrarPvt); if(status!=asynSuccess) { printf("testPmacAsynIPPort: devAsynOctet registerInterruptUser %s\n", pasynUser->errorMessage); return -1; } asynPrint(pasynUser,ASYN_TRACE_FLOW, "Done testPmacAsynIPPort OK\n"); testHandler(pPvt); return 0; }
epicsShareFunc QUEUE seqQueueCreate(size_t numElems, size_t elemSize) { QUEUE q = new(struct seqQueue); if (!q) { errlogSevPrintf(errlogFatal, "seqQueueCreate: out of memory\n"); return 0; } /* check arguments to establish invariants */ if (numElems == 0) { errlogSevPrintf(errlogFatal, "seqQueueCreate: numElems must be positive\n"); free(q); return 0; } if (elemSize == 0) { errlogSevPrintf(errlogFatal, "seqQueueCreate: elemSize must be positive\n"); free(q); return 0; } if (numElems > seqQueueMaxNumElems) { errlogSevPrintf(errlogFatal, "seqQueueCreate: numElems too large\n"); free(q); return 0; } DEBUG("%s:%d:calloc(%u,%u)\n",__FILE__,__LINE__,numElems, elemSize); q->buffer = (char *)calloc(numElems, elemSize); if (!q->buffer) { errlogSevPrintf(errlogFatal, "seqQueueCreate: out of memory\n"); free(q); return 0; } q->mutex = epicsMutexCreate(); if (!q->mutex) { errlogSevPrintf(errlogFatal, "seqQueueCreate: out of memory\n"); free(q->buffer); free(q); return 0; } q->elemSize = elemSize; q->numElems = numElems; q->overflow = FALSE; q->rd = q->wr = 0; return q; }
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; }
/* * start channel access */ static int init_CA_common(int flag) { int stat; struct ca_client_context *context; stat = ca_context_create(flag?ca_enable_preemptive_callback:ca_disable_preemptive_callback); /* ECA_NOTTHREADED indicates that this thread is recognized as * part of an existing context, and the application will have to * trust the callbacks being made. */ if( stat != ECA_NORMAL && stat != ECA_NOTTHREADED) { printf("Can't start channel access (%d)\n", stat); return -1; } if( processFlag == 0) processFlag = epicsMutexCreate(); context = ca_current_context(); epicsConnectAddContext( context, flag); return 0; }
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 PLC *new_PLC(const char *name) { PLC *plc = (PLC *) calloc(1, sizeof(PLC)); if (! plc) return 0; plc->name = EIP_strdup(name); if (! plc->name) return 0; DLL_init (&plc->scanlists); plc->lock = epicsMutexCreate(); if (! plc->lock) { EIP_printf (0, "new_PLC (%s): Cannot create mutex\n", name); return 0; } plc->connection = EIP_init(); if (! plc->connection) { EIP_printf (0, "new_PLC (%s): EIP_init failed\n", name); return 0; } return plc; }
long snmp_Init(void *precord) { snmpRecord *psnmp = (snmpRecord *)precord; /* psnmp->dpvt = (SNMP_INFO*)gsnmpInfo; */ printf("snmpInit()****** Message: %s, version: %s, ip: %s, name: %s, authpass: %s, privpass: %s\n",snmpinfo->msg, snmpinfo->version, snmpinfo->hostaddr, snmpinfo->username, snmpinfo->authpass, snmpinfo->privpass); if(recGblInitConstantLink(&psnmp->inp,DBF_DOUBLE,&psnmp->val)) psnmp->udf = FALSE; devSNMPPvt *pdev = (devSNMPPvt *)malloc(sizeof (devSNMPPvt)); if(pdev == NULL) return -1; pdev->mutexId = epicsMutexCreate(); scanIoInit(&pdev->ioScanPvt); psnmp->dpvt = pdev; pdev->prec = (dbCommon*)precord; ellAdd(&devSNMPList, &(((devSNMPPvt*)psnmp->dpvt)->devSNMPNode)); initialize(psnmp); return(0); }
static long initCommon(dbCommon *pr, DBLINK *plink, userCallback processCallback,interruptCallbackInt32 interruptCallback) { devInt32Pvt *pPvt; asynStatus status; asynUser *pasynUser; asynInterface *pasynInterface; epicsUInt32 mask=0; int nbits; pPvt = callocMustSucceed(1, sizeof(*pPvt), "devAsynInt32::initCommon"); pr->dpvt = pPvt; pPvt->pr = pr; /* Create asynUser */ pasynUser = pasynManager->createAsynUser(processCallback, 0); pasynUser->userPvt = pPvt; pPvt->pasynUser = pasynUser; pPvt->mutexId = epicsMutexCreate(); /* Parse the link to get addr and port */ /* We accept 2 different link syntax (@asyn(...) and @asynMask(...) * If parseLink returns an error then try parseLinkMask. */ status = pasynEpicsUtils->parseLink(pasynUser, plink, &pPvt->portName, &pPvt->addr, &pPvt->userParam); if (status != asynSuccess) { status = pasynEpicsUtils->parseLinkMask(pasynUser, plink, &pPvt->portName, &pPvt->addr, &mask, &pPvt->userParam); } if (status != asynSuccess) { printf("%s devAsynInt32::initCommon %s\n", pr->name, pasynUser->errorMessage); goto bad; } /* Parse nbits if it was specified */ nbits = (int)mask; if (nbits) { if (nbits < 0) { nbits = -nbits; pPvt->bipolar = 1; } pPvt->signBit = (epicsInt32) ldexp(1.0, nbits-1); pPvt->mask = pPvt->signBit*2 - 1; if (pPvt->bipolar) { pPvt->deviceLow = ~(pPvt->mask/2)+1; pPvt->deviceHigh = (pPvt->mask/2); } else { pPvt->deviceLow = 0; pPvt->deviceHigh = pPvt->mask; } } /* Connect to device */ status = pasynManager->connectDevice(pasynUser, pPvt->portName, pPvt->addr); if (status != asynSuccess) { printf("%s devAsynInt32::initCommon connectDevice failed %s\n", pr->name, pasynUser->errorMessage); goto bad; } status = pasynManager->canBlock(pPvt->pasynUser, &pPvt->canBlock); if (status != asynSuccess) { printf("%s devAsynInt32::initCommon canBlock failed %s\n", pr->name, pasynUser->errorMessage); goto bad; } /*call drvUserCreate*/ pasynInterface = pasynManager->findInterface(pasynUser,asynDrvUserType,1); if(pasynInterface && pPvt->userParam) { asynDrvUser *pasynDrvUser; void *drvPvt; pasynDrvUser = (asynDrvUser *)pasynInterface->pinterface; drvPvt = pasynInterface->drvPvt; status = pasynDrvUser->create(drvPvt,pasynUser,pPvt->userParam,0,0); if(status!=asynSuccess) { printf("%s devAsynInt32::initCommon drvUserCreate %s\n", pr->name, pasynUser->errorMessage); goto bad; } } /* Get interface asynInt32 */ pasynInterface = pasynManager->findInterface(pasynUser, asynInt32Type, 1); if (!pasynInterface) { printf("%s devAsynInt32::initCommon findInterface asynInt32Type %s\n", pr->name,pasynUser->errorMessage); goto bad; } pPvt->pint32 = pasynInterface->pinterface; pPvt->int32Pvt = pasynInterface->drvPvt; scanIoInit(&pPvt->ioScanPvt); pPvt->interruptCallback = interruptCallback; /* Initialize synchronous interface */ status = pasynInt32SyncIO->connect(pPvt->portName, pPvt->addr, &pPvt->pasynUserSync, pPvt->userParam); if (status != asynSuccess) { printf("%s devAsynInt32::initCommon Int32SyncIO->connect failed %s\n", pr->name, pPvt->pasynUserSync->errorMessage); goto bad; } return 0; bad: pr->pact=1; return -1; }
/** NDArrayPool constructor * \param[in] maxBuffers Maximum number of NDArray objects that the pool is allowed to contain; 0=unlimited. * \param[in] maxMemory Maxiumum number of bytes of memory the the pool is allowed to use, summed over * all of the NDArray objects; 0=unlimited. */ NDArrayPool::NDArrayPool(int maxBuffers, size_t maxMemory) : maxBuffers_(maxBuffers), numBuffers_(0), maxMemory_(maxMemory), memorySize_(0), numFree_(0) { ellInit(&freeList_); listLock_ = epicsMutexCreate(); }
/*Constructor */ drvSIS3801::drvSIS3801(const char *portName, int baseAddress, int interruptVector, int interruptLevel, int maxChans, int maxSignals) : drvSIS38XX(portName, maxChans, maxSignals) { int status; epicsUInt32 controlStatusReg; epicsUInt32 moduleID; static const char* functionName="SIS3801"; setIntegerParam(SIS38XXModel_, MODEL_SIS3801); /* Call devLib to get the system address that corresponds to the VME * base address of the board. */ status = devRegisterAddress("drvSIS3801", SIS3801_ADDRESS_TYPE, (size_t)baseAddress, SIS3801_BOARD_SIZE, (volatile void **)®isters_); if (status) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: %s, Can't register VME address %p\n", driverName, functionName, portName, baseAddress); return; } asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: Registered VME address: 0x%lX to local address: %p size: 0x%X\n", driverName, functionName, (long)baseAddress, registers_, SIS3801_BOARD_SIZE); /* Probe VME bus to see if card is there */ status = devReadProbe(4, (char *) ®isters_->csr_reg, (char *) &controlStatusReg); if (status) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: devReadProbe failure = %d\n", driverName, functionName, status); return; } /* Get the module info from the card */ moduleID = (registers_->irq_reg & 0xFFFF0000) >> 16; asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: module ID=%x\n", driverName, functionName, moduleID); firmwareVersion_ = (registers_->irq_reg & 0x0000F000) >> 12; setIntegerParam(SIS38XXFirmware_, firmwareVersion_); asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: firmware=%d\n", driverName, functionName, firmwareVersion_); // Create the mutex used to lock access to the FIFO fifoLockId_ = epicsMutexCreate(); /* Reset card */ asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: resetting port %s\n", driverName, functionName, portName); registers_->key_reset_reg = 1; /* Clear FIFO */ asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: clearing FIFO\n", driverName, functionName); resetFIFO(); setControlStatusReg(); /* Initialize board in MCS mode */ setAcquireMode(ACQUIRE_MODE_MCS); /* Set number of readout channels to maxSignals * Assumes that the lower channels will be used first, and the only unused * channels will be at the upper end of the channel range. * Create a mask with zeros in the rightmost maxSignals bits, * 1 in all higher order bits. */ registers_->copy_disable_reg = 0xffffffff<<maxSignals_; asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: setting copy disable register=0x%08x\n", driverName, functionName, 0xffffffff<<maxSignals_); /* Set up the interrupt service routine */ asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: interruptServiceRoutine pointer %p\n", driverName, functionName, intFuncC); status = devConnectInterruptVME(interruptVector, intFuncC, this); if (status) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Can't connect to vector % d\n", driverName, functionName, interruptVector); return; } asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: Connected interrupt vector: %d\n\n", driverName, functionName, interruptVector); /* Write interrupt level to hardware */ asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: irq before setting IntLevel= 0x%x\n", driverName, functionName, registers_->irq_reg); registers_->irq_reg |= (interruptLevel << 8); asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: irq after setting IntLevel= 0x%x\n", driverName, functionName, registers_->irq_reg); registers_->irq_reg |= interruptVector; asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "m%s:%s: irq config register after setting interrupt vector = 0x%08x\n", driverName, functionName, registers_->irq_reg); /* Create the thread that reads the FIFO */ if (epicsThreadCreate("SIS3801FIFOThread", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)readFIFOThreadC, this) == NULL) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: epicsThreadCreate failure\n", driverName, functionName); return; } else asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: epicsThreadCreate success\n", driverName, functionName); erase(); /* Enable interrupts in hardware */ asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: irq before enabling interrupts= 0x%08x\n", driverName, functionName, registers_->irq_reg); enableInterrupts(); /* Enable interrupt level in EPICS */ status = devEnableInterruptLevel(intVME, interruptLevel); if (status) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Can't enable enterrupt level %d\n", driverName, functionName, interruptLevel); return; } exists_ = true; return; }
/* * create_client () */ struct client * create_client ( SOCKET sock, int proto ) { struct client *client; int spaceAvailOnFreeList; size_t spaceNeeded; /* * stop further use of server if memory becomes scarse */ spaceAvailOnFreeList = freeListItemsAvail ( rsrvClientFreeList ) > 0 && freeListItemsAvail ( rsrvSmallBufFreeListTCP ) > 0; spaceNeeded = sizeof (struct client) + MAX_TCP; if ( ! ( osiSufficentSpaceInPool(spaceNeeded) || spaceAvailOnFreeList ) ) { epicsSocketDestroy ( sock ); epicsPrintf ("CAS: no space in pool for a new client (below max block thresh)\n"); return NULL; } client = freeListCalloc ( rsrvClientFreeList ); if ( ! client ) { epicsSocketDestroy ( sock ); epicsPrintf ("CAS: no space in pool for a new client (alloc failed)\n"); return NULL; } client->sock = sock; client->proto = proto; client->blockSem = epicsEventCreate ( epicsEventEmpty ); client->lock = epicsMutexCreate(); client->putNotifyLock = epicsMutexCreate(); client->chanListLock = epicsMutexCreate(); client->eventqLock = epicsMutexCreate(); if ( ! client->blockSem || ! client->lock || ! client->putNotifyLock || ! client->chanListLock || ! client->eventqLock ) { destroy_client ( client ); return NULL; } client->pUserName = NULL; client->pHostName = NULL; ellInit ( & client->chanList ); ellInit ( & client->chanPendingUpdateARList ); ellInit ( & client->putNotifyQue ); memset ( (char *)&client->addr, 0, sizeof (client->addr) ); client->tid = 0; if ( proto == IPPROTO_TCP ) { client->send.buf = (char *) freeListCalloc ( rsrvSmallBufFreeListTCP ); client->send.maxstk = MAX_TCP; client->send.type = mbtSmallTCP; client->recv.buf = (char *) freeListCalloc ( rsrvSmallBufFreeListTCP ); client->recv.maxstk = MAX_TCP; client->recv.type = mbtSmallTCP; } else if ( proto == IPPROTO_UDP ) { client->send.buf = malloc ( MAX_UDP_SEND ); client->send.maxstk = MAX_UDP_SEND; client->send.type = mbtUDP; client->recv.buf = malloc ( MAX_UDP_RECV ); client->recv.maxstk = MAX_UDP_RECV; client->recv.type = mbtUDP; } if ( ! client->send.buf || ! client->recv.buf ) { destroy_client ( client ); return NULL; } client->send.stk = 0u; client->send.cnt = 0u; client->recv.stk = 0u; client->recv.cnt = 0u; client->evuser = NULL; client->priority = CA_PROTO_PRIORITY_MIN; client->disconnect = FALSE; epicsTimeGetCurrent ( &client->time_at_last_send ); epicsTimeGetCurrent ( &client->time_at_last_recv ); client->minor_version_number = CA_UKN_MINOR_VERSION; client->recvBytesToDrain = 0u; return client; }
/* * 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; }
/* The constructor for this class */ NDFileHDF5XML::NDFileHDF5XML(const char *portName, int queueSize, int blockingCallbacks, const char *NDArrayPort, int NDArrayAddr, int priority, int stackSize) : NDPluginFile(portName, queueSize, blockingCallbacks, NDArrayPort, NDArrayAddr, 1, NDFileHDF5XML::num_params, 10, -1, asynGenericPointerMask, asynGenericPointerMask, ASYN_CANBLOCK, 1, priority, stackSize), is_file_open(false), lf("HDF5XMLPlug_log.txt") { int i; static const char *functionName = "NDFileHDF5XML"; int dims[3]; dims[0]=10; dims[1]=10; char mesg[256]; //dummyArray=pNDArrayPool->alloc(2, dims, NDInt16, 0, NULL); /* paramStrings[0] = new param_type_str(&NDFileHDF5XML_threshold, asynParamInt32, "NDFileHDF5XML_threshold"); paramStrings[1] = new param_type_str(&NDFileHDF5XML_is_recapture, asynParamInt32, "NDFileHDF5XML_is_recapture"); paramStrings[2] = new param_type_str(&NDFileHDF5XML_templatefile, asynParamOctet, "TEMPLATE_FILE_NAME"); paramStrings[3] = new param_type_str(&NDFileHDF5XML_templatepath, asynParamOctet, "TEMPLATE_FILE_PATH"); paramStrings[4] = new param_type_str(&NDFileHDF5XML_TemplateValid, asynParamInt32, "TEMPLATE_FILE_VALID"); */ lf.enablePrintf(true); lf.log("NDFileHDF5XML constructing"); sprintf(mesg,"Compile date %s, Time %s",__DATE__,__TIME__); lf.log(mesg); createParam("NDFileHDF5XML_threshold",asynParamInt32,&NDFileHDF5XML_threshold); createParam("NDFileHDF5XML_is_recapture",asynParamInt32,&NDFileHDF5XML_is_recapture); createParam("TEMPLATE_FILE_NAME",asynParamOctet,&NDFileHDF5XML_templatefile); createParam("TEMPLATE_FILE_PATH",asynParamOctet,&NDFileHDF5XML_templatepath); createParam("TEMPLATE_FILE_VALID",asynParamInt32,&NDFileHDF5XML_TemplateValid); createParam("EZ_is_makedirs",asynParamInt32,&NDFileHDF5XML_createDirs); this->supportsMultipleArrays = 1; this->pAttributeId = NULL; this->configFileMutex = epicsMutexCreate(); if (!this->configFileMutex) { printf("%s::%s ERROR: epicsMutexCreate failure\n", driverName, functionName); return; } hdfSetup = new TiXMLhdf5SetupNew(); hdf5Writer = new TiXMLhdf5WriteData(); hdf5Closer = new TiXMLhdf5Shutdown(); configDoc = new TiXmlDocument(); hdf_interface = new epics2hdf(this->pasynUserSelf); hdfSetup->setEpicsInterface(hdf_interface); hdf5Writer->setEpicsInterface(hdf_interface); hdf5Closer->setEpicsInterface(hdf_interface); num_bad_fpgaheads = 0; last_filenumber = 0; //hits capture START on fileclose setIntegerParam(NDFileHDF5XML_is_recapture, 0); capture_trig = 0; filenum_kludge = 0; }
static long initCommon(dbCommon *pr, DBLINK *plink, userCallback processCallback,interruptCallbackFloat64 interruptCallback) { devPvt *pPvt; asynStatus status; asynUser *pasynUser; asynInterface *pasynInterface; pPvt = callocMustSucceed(1, sizeof(*pPvt), "devAsynFloat64::initCommon"); pr->dpvt = pPvt; pPvt->pr = pr; /* Create asynUser */ pasynUser = pasynManager->createAsynUser(processCallback, 0); pasynUser->userPvt = pPvt; pPvt->pasynUser = pasynUser; pPvt->ringBufferLock = epicsMutexCreate(); /* Parse the link to get addr and port */ status = pasynEpicsUtils->parseLink(pasynUser, plink, &pPvt->portName, &pPvt->addr,&pPvt->userParam); if (status != asynSuccess) { printf("%s devAsynFloat64::initCommon %s\n", pr->name, pasynUser->errorMessage); goto bad; } /* Connect to device */ status = pasynManager->connectDevice(pasynUser, pPvt->portName, pPvt->addr); if (status != asynSuccess) { printf("%s devAsynFloat64::initCommon connectDevice failed %s\n", pr->name, pasynUser->errorMessage); goto bad; } status = pasynManager->canBlock(pPvt->pasynUser, &pPvt->canBlock); if (status != asynSuccess) { printf("%s devAsynFloat64::initCommon canBlock failed %s\n", pr->name, pasynUser->errorMessage); goto bad; } /*call drvUserCreate*/ pasynInterface = pasynManager->findInterface(pasynUser,asynDrvUserType,1); if(pasynInterface && pPvt->userParam) { asynDrvUser *pasynDrvUser; void *drvPvt; pasynDrvUser = (asynDrvUser *)pasynInterface->pinterface; drvPvt = pasynInterface->drvPvt; status = pasynDrvUser->create(drvPvt,pasynUser,pPvt->userParam,0,0); if(status!=asynSuccess) { printf("%s devAsynFloat64::initCommon drvUserCreate %s\n", pr->name, pasynUser->errorMessage); goto bad; } } /* Get interface asynFloat64 */ pasynInterface = pasynManager->findInterface(pasynUser, asynFloat64Type, 1); if (!pasynInterface) { printf("%s devAsynFloat64::initCommon findInterface asynFloat64Type %s\n", pr->name,pasynUser->errorMessage); goto bad; } pPvt->pfloat64 = pasynInterface->pinterface; pPvt->float64Pvt = pasynInterface->drvPvt; /* Initialize synchronous interface */ status = pasynFloat64SyncIO->connect(pPvt->portName, pPvt->addr, &pPvt->pasynUserSync, pPvt->userParam); if (status != asynSuccess) { printf("%s devAsynFloat64::initCommon Float64SyncIO->connect failed %s\n", pr->name, pPvt->pasynUserSync->errorMessage); goto bad; } scanIoInit(&pPvt->ioScanPvt); pPvt->interruptCallback = interruptCallback; /* If the info field "asyn:READBACK" is 1 and interruptCallback is not NULL * then register for callbacks on output records */ if (interruptCallback) { int enableCallbacks=0; const char *callbackString; DBENTRY *pdbentry = dbAllocEntry(pdbbase); status = dbFindRecord(pdbentry, pr->name); if (status) { asynPrint(pPvt->pasynUser, ASYN_TRACE_ERROR, "%s devAsynFloat64::initCommon error finding record\n", pr->name); goto bad; } callbackString = dbGetInfo(pdbentry, "asyn:READBACK"); if (callbackString) enableCallbacks = atoi(callbackString); if (enableCallbacks) { status = createRingBuffer(pr); if (status!=asynSuccess) goto bad; status = pPvt->pfloat64->registerInterruptUser( pPvt->float64Pvt,pPvt->pasynUser, pPvt->interruptCallback,pPvt,&pPvt->registrarPvt); if(status!=asynSuccess) { printf("%s devAsynFloat64::initRecord error calling registerInterruptUser %s\n", pr->name,pPvt->pasynUser->errorMessage); } } } return INIT_OK; bad: recGblSetSevr(pr,LINK_ALARM,INVALID_ALARM); pr->pact=1; return INIT_ERROR; }
struct gretTap *gretTapConnect(char *addr, int position, unsigned int typeMask) { struct sockaddr_in adr_srvr; /* AF_INET */ struct hostent *hp; struct gretTap *retval; int numrec, firstret[2]; unsigned int outbuf[2]; int numsent; gretTapClientError = GTC_NOERROR; retval = (struct gretTap *) calloc(1, sizeof(struct gretTap)); retval->connectionMutex = epicsMutexCreate(); if (!retval->connectionMutex) { gretTapClientError = GTC_M_CREATE; free(retval); return 0; } memset(&adr_srvr,0,sizeof adr_srvr); adr_srvr.sin_family = AF_INET; adr_srvr.sin_port = htons(GRETTAP_PORT); hp = gethostbyname(addr); if (!hp) { gretTapClientError = GTC_HOSTNAME; free(retval); return 0; } adr_srvr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *) (hp->h_addr_list[0])))); if ( adr_srvr.sin_addr.s_addr == INADDR_NONE ) { gretTapClientError = GTC_INADDR; free(retval); return 0; } retval->inSock = socket(AF_INET, SOCK_STREAM, 0); if (retval->inSock == -1) { gretTapClientError = GTC_INSOCK; free(retval); return 0; } if (connect(retval->inSock, (struct sockaddr *)&adr_srvr, sizeof(adr_srvr)) < 0) { gretTapClientError = GTC_TAPCONN; close(retval->inSock); free(retval); return 0; } /* send two ints: type and position */ outbuf[0] = typeMask; outbuf[1] = position; numsent = fdWrite(retval->inSock, outbuf, 2 * sizeof(unsigned int)); if (numsent != 2 * sizeof(unsigned int)){ gretTapClientError = GTC_INITWRITE; close(retval->inSock); free(retval); return 0; } numrec = fdRead(retval->inSock, firstret, TAP_HEADER_LEN); if (numrec != TAP_HEADER_LEN) { gretTapClientError = GTC_INITREAD; close(retval->inSock); free(retval); return 0; } if (firstret[0] != TAP_ACK) { switch (firstret[0]) { case TAP_NOT_FOUND: gretTapClientError = GTC_NOT_FOUND; break; case TAP_NOT_RUNNING: gretTapClientError = GTC_NOT_RUNNING; break; default: gretTapClientError = GTC_UNKNOWN; } close(retval->inSock); free(retval); return 0; } return (retval); }
static long initCommon(dbCommon *pr, DBLINK *plink, userCallback processCallback,interruptCallbackUInt32Digital interruptCallback, interruptCallbackEnum callbackEnum, int maxEnums, char *pFirstString, int *pFirstValue, epicsEnum16 *pFirstSeverity) { devPvt *pPvt; asynStatus status; asynUser *pasynUser; asynInterface *pasynInterface; pPvt = callocMustSucceed(1, sizeof(*pPvt), "devAsynUInt32Digital::initCommon"); pr->dpvt = pPvt; pPvt->pr = pr; /* Create asynUser */ pasynUser = pasynManager->createAsynUser(processCallback, 0); pasynUser->userPvt = pPvt; pPvt->pasynUser = pasynUser; pPvt->ringBufferLock = epicsMutexCreate(); /* Parse the link to get addr and port */ status = pasynEpicsUtils->parseLinkMask(pasynUser, plink, &pPvt->portName, &pPvt->addr, &pPvt->mask,&pPvt->userParam); if (status != asynSuccess) { printf("%s devAsynUInt32Digital::initCommon %s\n", pr->name, pasynUser->errorMessage); goto bad; } /* Connect to device */ status = pasynManager->connectDevice(pasynUser, pPvt->portName, pPvt->addr); if (status != asynSuccess) { printf("%s devAsynUInt32Digital::initCommon connectDevice failed %s\n", pr->name, pasynUser->errorMessage); goto bad; } status = pasynManager->canBlock(pPvt->pasynUser, &pPvt->canBlock); if (status != asynSuccess) { printf("%s devAsynUInt32Digital::initCommon canBlock failed %s\n", pr->name, pasynUser->errorMessage); goto bad; } /*call drvUserCreate*/ pasynInterface = pasynManager->findInterface(pasynUser,asynDrvUserType,1); if(pasynInterface && pPvt->userParam) { asynDrvUser *pasynDrvUser; void *drvPvt; pasynDrvUser = (asynDrvUser *)pasynInterface->pinterface; drvPvt = pasynInterface->drvPvt; status = pasynDrvUser->create(drvPvt,pasynUser,pPvt->userParam,0,0); if(status!=asynSuccess) { printf("%s devAsynUInt32Digital::initCommon drvUserCreate %s\n", pr->name, pasynUser->errorMessage); goto bad; } } /* Get interface asynUInt32Digital */ pasynInterface = pasynManager->findInterface(pasynUser, asynUInt32DigitalType, 1); if (!pasynInterface) { printf("%s devAsynUInt32Digital::initCommon " "findInterface asynUInt32DigitalType %s\n", pr->name,pasynUser->errorMessage); goto bad; } pPvt->puint32 = pasynInterface->pinterface; pPvt->uint32Pvt = pasynInterface->drvPvt; /* Initialize synchronous interface */ status = pasynUInt32DigitalSyncIO->connect(pPvt->portName, pPvt->addr, &pPvt->pasynUserSync, pPvt->userParam); if (status != asynSuccess) { printf("%s devAsynUInt32Digital::initCommon UInt32DigitalSyncIO->connect failed %s\n", pr->name, pPvt->pasynUserSync->errorMessage); goto bad; } pPvt->interruptCallback = interruptCallback; scanIoInit(&pPvt->ioScanPvt); /* Initialize asynEnum interfaces */ pasynInterface = pasynManager->findInterface(pPvt->pasynUser,asynEnumType,1); if (pasynInterface && (maxEnums > 0)) { size_t numRead; asynEnum *pasynEnum = pasynInterface->pinterface; void *registrarPvt; status = pasynEnumSyncIO->connect(pPvt->portName, pPvt->addr, &pPvt->pasynUserEnumSync, pPvt->userParam); if (status != asynSuccess) { printf("%s devAsynUInt32Digital::initCommon EnumSyncIO->connect failed %s\n", pr->name, pPvt->pasynUserEnumSync->errorMessage); goto bad; } status = pasynEnumSyncIO->read(pPvt->pasynUserEnumSync, pPvt->enumStrings, pPvt->enumValues, pPvt->enumSeverities, maxEnums, &numRead, pPvt->pasynUser->timeout); if (status == asynSuccess) { setEnums(pFirstString, pFirstValue, pFirstSeverity, pPvt->enumStrings, pPvt->enumValues, pPvt->enumSeverities, numRead, maxEnums); } status = pasynEnum->registerInterruptUser( pasynInterface->drvPvt, pPvt->pasynUser, callbackEnum, pPvt, ®istrarPvt); if(status!=asynSuccess) { printf("%s devAsynUInt32Digital enum registerInterruptUser %s\n", pr->name,pPvt->pasynUser->errorMessage); } } /* If the info field "asyn:READBACK" is 1 and interruptCallback is not NULL * then register for callbacks on output records */ if (interruptCallback) { int enableCallbacks=0; const char *callbackString; DBENTRY *pdbentry = dbAllocEntry(pdbbase); status = dbFindRecord(pdbentry, pr->name); if (status) { asynPrint(pPvt->pasynUser, ASYN_TRACE_ERROR, "%s devAsynUInt32Digital::initCommon error finding record\n", pr->name); goto bad; } callbackString = dbGetInfo(pdbentry, "asyn:READBACK"); if (callbackString) enableCallbacks = atoi(callbackString); if (enableCallbacks) { status = createRingBuffer(pr); if (status!=asynSuccess) goto bad; status = pPvt->puint32->registerInterruptUser( pPvt->uint32Pvt,pPvt->pasynUser, pPvt->interruptCallback,pPvt,pPvt->mask, &pPvt->registrarPvt); if(status!=asynSuccess) { printf("%s devAsynUInt32Digital::initRecord error calling registerInterruptUser %s\n", pr->name,pPvt->pasynUser->errorMessage); } } } return INIT_OK; bad: recGblSetSevr(pr,LINK_ALARM,INVALID_ALARM); pr->pact=1; return INIT_ERROR; }
static long drvMK80S_init(char *portName, double devTimeout, double cbTimeout, double scanInterval) { static int firstTime = 1; char port_name[40]; drvMK80SConfig *pdrvMK80SConfig = NULL; MK80S_read *pMK80S_read = NULL; asynUser *pasynMK80SUser = NULL; asynMK80SUserData *pasynMK80SUserData = NULL; asynInterface *pasynMK80SInterface= NULL; asynStatus asynMK80SStatus; if(firstTime) { firstTime = 0; epicsThreadCreate("drvMK80SScanTask", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackSmall), (EPICSTHREADFUNC) drvMK80S_scanTask, 0); } strcpy(port_name,portName); if(!pdrvMK80S_ellList) { pdrvMK80S_ellList = (ELLLIST *) malloc(sizeof(ELLLIST)); ellInit(pdrvMK80S_ellList); } if(!pdrvMK80SBitInputList) { pdrvMK80SBitInputList = (drvMK80SInputList *) calloc(1, sizeof(drvMK80SInputList)); pdrvMK80SBitInputList->num = 0; } if(!pdrvMK80SWordInputList) { pdrvMK80SWordInputList = (drvMK80SInputList *) calloc(1, sizeof(drvMK80SInputList)); pdrvMK80SWordInputList->num = 0; } if(drvMK80S_find(port_name)) return 0; /* driver was intialized alrady, nothing to do */ pdrvMK80SConfig = (drvMK80SConfig*) malloc(sizeof(drvMK80SConfig)); pMK80S_read = (MK80S_read*) malloc(sizeof(MK80S_read)); pasynMK80SUserData = (asynMK80SUserData*) malloc(sizeof(asynMK80SUserData)); if(!pdrvMK80SConfig || !pMK80S_read || !pasynMK80SUserData) return 0; pdrvMK80SConfig->devTimeout = devTimeout; pdrvMK80SConfig->cbTimeout = cbTimeout; pdrvMK80SConfig->scanInterval = scanInterval; strcpy(pdrvMK80SConfig->port_name, port_name); pdrvMK80SConfig->cbCount = 0; pdrvMK80SConfig->timeoutCount = 0; memset (pMK80S_read, 0x00, sizeof(MK80S_read)); pasynMK80SUserData->pdrvMK80SConfig = (void*) pdrvMK80SConfig; pasynMK80SUser = pasynManager->createAsynUser(drvMK80S_queueCallback, drvMK80S_timeoutCallback); pasynMK80SUser->timeout = pdrvMK80SConfig->devTimeout; pasynMK80SUser->userPvt = pasynMK80SUserData; asynMK80SStatus = pasynManager->connectDevice(pasynMK80SUser, port_name, 0); if(asynMK80SStatus != asynSuccess) { goto end; } pasynMK80SInterface = pasynManager->findInterface(pasynMK80SUser, asynOctetType, 1); if(!pasynMK80SInterface){ goto end; } pasynMK80SUserData->pasynMK80SOctet = (asynOctet*)pasynMK80SInterface->pinterface; // set EOS(end of string) of receive message pasynMK80SUserData->pasynMK80SOctet->setInputEos(pasynMK80SInterface->drvPvt, pasynMK80SUser, ETX_STR, 1); pasynMK80SUserData->pdrvPvt = pasynMK80SInterface->drvPvt; pdrvMK80SConfig->lock = epicsMutexCreate(); scanIoInit(&pdrvMK80SConfig->ioScanPvt); pdrvMK80SConfig->pMK80S_read = pMK80S_read; pdrvMK80SConfig->pasynMK80SUser = pasynMK80SUser; pdrvMK80SConfig->pasynMK80SUserData = pasynMK80SUserData; pdrvMK80SConfig->status = MK80SSTATUS_TIMEOUT_MASK; ellAdd(pdrvMK80S_ellList, &pdrvMK80SConfig->node); return 0; end: /* relase allocated memory and asynInterface */ kuDebug (kuERR, "[drvMK80S_init] init failed for %s!!!\n", port_name); return 0; }
static int motorSimCreateAxis( motorSim_t * pDrv, int card, int axis, double lowLimit, double hiLimit, double home, double start ) { AXIS_HDL pAxis; AXIS_HDL * ppLast = &(pDrv->pFirst); start=0; for ( pAxis = pDrv->pFirst; pAxis != NULL && ! ((pAxis->card == card) && (pAxis->axis == axis)); pAxis = pAxis->pNext ) { ppLast = &(pAxis->pNext); } if ( pAxis == NULL) { pAxis = (AXIS_HDL) calloc( 1, sizeof(motorAxis) ); if (pAxis != NULL) { route_pars_t pars; pAxis->pDrv = pDrv; pars.numRoutedAxes = 1; pars.routedAxisList[0] = 1; pars.Tsync = 0.0; pars.Tcoast = 0.0; pars.axis[0].Amax = 1.0; pars.axis[0].Vmax = 1.0; pAxis->endpoint.T = 0; pAxis->endpoint.axis[0].p = start; pAxis->endpoint.axis[0].v = 0; pAxis->nextpoint.axis[0].p = start; if ((pAxis->route = routeNew( &(pAxis->endpoint), &pars )) != NULL && (pAxis->params = motorParam->create( 0, MOTOR_AXIS_NUM_PARAMS )) != NULL && (pAxis->axisMutex = epicsMutexCreate( )) != NULL ) { pAxis->card = card; pAxis->axis = axis; pAxis->hiHardLimit = hiLimit; pAxis->lowHardLimit = lowLimit; pAxis->home = home; pAxis->print = motorSimLogMsg; pAxis->logParam = NULL; motorParam->setDouble(pAxis->params, motorAxisPosition, start); *ppLast = pAxis; pAxis->print( pAxis->logParam, TRACE_FLOW, "Created motor for card %d, signal %d OK", card, axis ); } else { if (pAxis->route != NULL) routeDelete( pAxis->route ); if (pAxis->params != NULL) motorParam->destroy( pAxis->params ); if (pAxis->axisMutex != NULL) epicsMutexDestroy( pAxis->axisMutex ); free ( pAxis ); pAxis = NULL; } } else { free ( pAxis ); pAxis = NULL; } } else { pAxis->print( pAxis->logParam, TRACE_ERROR, "Motor for card %d, signal %d already exists", card, axis ); return MOTOR_AXIS_ERROR; } if (pAxis == NULL) { pAxis->print( pAxis->logParam, TRACE_ERROR, "Cannot create motor for card %d, signal %d", card, axis ); return MOTOR_AXIS_ERROR; } return MOTOR_AXIS_OK; }
epicsThreadPool* epicsThreadPoolCreate(epicsThreadPoolConfig *opts) { size_t i; epicsThreadPool *pool; /* caller likely didn't initialize the options structure */ if (opts && opts->maxThreads == 0) { errlogMessage("Error: epicsThreadPoolCreate() options provided, but not initialized"); return NULL; } pool = calloc(1, sizeof(*pool)); if (!pool) return NULL; if (opts) memcpy(&pool->conf, opts, sizeof(*opts)); else epicsThreadPoolConfigDefaults(&pool->conf); if (pool->conf.initialThreads > pool->conf.maxThreads) pool->conf.initialThreads = pool->conf.maxThreads; pool->workerWakeup = epicsEventCreate(epicsEventEmpty); pool->shutdownEvent = epicsEventCreate(epicsEventEmpty); pool->observerWakeup = epicsEventCreate(epicsEventEmpty); pool->guard = epicsMutexCreate(); if (!pool->workerWakeup || !pool->shutdownEvent || !pool->observerWakeup || !pool->guard) goto cleanup; ellInit(&pool->jobs); ellInit(&pool->owned); epicsMutexMustLock(pool->guard); for (i = 0; i < pool->conf.initialThreads; i++) { createPoolThread(pool); } if (pool->threadsRunning == 0 && pool->conf.initialThreads != 0) { epicsMutexUnlock(pool->guard); errlogPrintf("Error: Unable to create any threads for thread pool\n"); goto cleanup; } else if (pool->threadsRunning < pool->conf.initialThreads) { errlogPrintf("Warning: Unable to create all threads for thread pool (%u/%u)\n", pool->threadsRunning, pool->conf.initialThreads); } epicsMutexUnlock(pool->guard); return pool; cleanup: if (pool->workerWakeup) epicsEventDestroy(pool->workerWakeup); if (pool->shutdownEvent) epicsEventDestroy(pool->shutdownEvent); if (pool->observerWakeup) epicsEventDestroy(pool->observerWakeup); if (pool->guard) epicsMutexDestroy(pool->guard); free(pool); return NULL; }