static bool reportCard(mrf::Object* obj, void* arg) { // this function is called by Object::visitObjects // it must return 'true' in order for the Object::visitObjects to continue searching for objects. // if false is returned, Object::visitObjects stops int *level=(int*)arg; evgMrm *evg=dynamic_cast<evgMrm*>(obj); if(!evg){ return true; } epicsPrintf("EVG: %s \n", evg->getId().c_str()); epicsPrintf("\tFPGA Version: %08x (firmware: %x)\n", evg->getFwVersion(), evg->getFwVersionID()); epicsPrintf("\tForm factor: %s\n", evg->getFormFactorStr().c_str()); bus_configuration *bus = evg->getBusConfiguration(); if(bus->busType == busType_vme){ struct VMECSRID vmeDev; vmeDev.board = 0; vmeDev.revision = 0; vmeDev.vendor = 0; volatile unsigned char* csrAddr = devCSRTestSlot(vmeEvgIDs, bus->vme.slot, &vmeDev); if(csrAddr){ epicsUInt32 ader = CSRRead32(csrAddr + CSR_FN_ADER(1)); epicsPrintf("\tVME configured slot: %d\n", bus->vme.slot); epicsPrintf("\tVME configured A24 address 0x%08x\n", bus->vme.address); epicsPrintf("\tVME ADER: base address=0x%x\taddress modifier=0x%x\n", ader>>8, (ader&0xFF)>>2); epicsPrintf("\tVME IRQ Level %x (configured to %x)\n", CSRRead8(csrAddr + UCSR_DEFAULT_OFFSET + UCSR_IRQ_LEVEL), bus->vme.irqLevel); epicsPrintf("\tVME IRQ Vector %x (configured to %x)\n", CSRRead8(csrAddr + UCSR_DEFAULT_OFFSET + UCSR_IRQ_VECTOR), bus->vme.irqVector); if(*level>1) epicsPrintf("\tVME card vendor: 0x%08x\n", vmeDev.vendor); if(*level>1) epicsPrintf("\tVME card board: 0x%08x\n", vmeDev.board); if(*level>1) epicsPrintf("\tVME card revision: 0x%08x\n", vmeDev.revision); if(*level>1) epicsPrintf("\tVME CSR address: %p\n", csrAddr); }else{ epicsPrintf("\tCard not detected in configured slot %d\n", bus->vme.slot); } }
/*************************************************** * 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); }
static int initDAQboard(drvM6802_taskConfig *ptaskConfig) { if( !ozSetGlobalReset( ptaskConfig ) ) { epicsPrintf("\n>>> ID:%d initDAQboard : ozSetGlobalReset...failed! \n", ptaskConfig->BoardID); return ERROR; } epicsPrintf("\n>>> ID:%d, 0x%4X initDAQboard : ozSetGlobalReset ok\n", ptaskConfig->BoardID,ptaskConfig->vme_addr ); epicsThreadSleep(0.5); #ifdef DEBUG epicsPrintf("initDAQboard: %s addr:0x%X\n", ptaskConfig->taskName, ptaskConfig->vme_addr); #endif /* DEBUG */ #if 1 if( ptaskConfig->masterMode ) { if( !ozSetADsFIFOreset( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetADsFIFOreset...failed! \n", ptaskConfig->BoardID); return ERROR; } /* if( !ozSetTriggerReset( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetTriggerReset...failed! \n", ptaskConfig->BoardID); return ERROR; } */ } if( !ozSetTermDisable( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetTermDisable...failed! \n", ptaskConfig->BoardID); return ERROR; } if( !ozSetSampleClkDivider( ptaskConfig, 1 ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetSampleClkDivider...failed! \n", ptaskConfig->BoardID); return ERROR; } #endif if( !ozSetSamplingRate( ptaskConfig, ptaskConfig->samplingRate) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetSamplingRate...failed! \n", ptaskConfig->BoardID); return ERROR; } if( !ozSetTriggerPolarity( ptaskConfig) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetTriggerPolarity...failed! \n", ptaskConfig->BoardID); return ERROR; } #if 1 if( !ozSetMasterOrSlave( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetMasterOrSlave...failed! \n", ptaskConfig->BoardID); return ERROR; } #endif if( !ozSetClockInterExter( ptaskConfig) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetClockInterExter...failed! \n", ptaskConfig->BoardID); return ERROR; } if( !ozSetChannelMask( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetChannelMask...failed! \n", ptaskConfig->BoardID); return ERROR; } if( !ozSetBoardIDBit( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetBoardIDBit...failed! \n", ptaskConfig->BoardID); return ERROR; } if( !ozSetStrobeTTL( ptaskConfig ) ) { epicsPrintf("\n>>> id:%d initDAQboard : ozSetStrobeTTL...failed! \n", ptaskConfig->BoardID); return ERROR; } ptaskConfig->taskStatus |= TASK_INITIALIZED; return OK; }
/* * 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; }
int main(int argc,char **argv) { int i; char *outFilename; char *pext; FILE *outFile; dbMenu *pdbMenu; dbRecordType *pdbRecordType; dbFldDes *pdbFldDes; char *plastSlash; int strip; char *path = NULL; char *sub = NULL; int pathLength = 0; int subLength = 0; char **pstr; char *psep; int *len; long status; static char *pathSep = OSI_PATH_LIST_SEPARATOR; static char *subSep = ","; /*Look for options*/ if(argc<2) { fprintf(stderr,"usage: dbToDoxygen -Idir -Idir file.dbd [outfile]\n"); exit(0); } while((strncmp(argv[1],"-I",2)==0)||(strncmp(argv[1],"-S",2)==0)) { if(strncmp(argv[1],"-I",2)==0) { pstr = &path; psep = pathSep; len = &pathLength; } else { pstr = ⊂ psep = subSep; len = &subLength; } if(strlen(argv[1])==2) { dbCatString(pstr,len,argv[2],psep); strip = 2; } else { dbCatString(pstr,len,argv[1]+2,psep); strip = 1; } argc -= strip; for(i=1; i<argc; i++) argv[i] = argv[i + strip]; } if(argc<2 || (strncmp(argv[1],"-",1)==0)) { fprintf(stderr,"usage: dbToRecordtypeH -Idir -Idir file.dbd [outfile]\n"); exit(0); } if(argc==2){ /*remove path so that outFile is created where program is executed*/ plastSlash = strrchr(argv[1],'/'); if(!plastSlash) plastSlash = strrchr(argv[1],'\\'); plastSlash = (plastSlash ? plastSlash+1 : argv[1]); outFilename = (char*)dbCalloc(1,strlen(plastSlash)+1); strcpy(outFilename,plastSlash); pext = strstr(outFilename,".dbd"); if(!pext) { fprintf(stderr,"Input file MUST have .dbd extension\n"); exit(-1); } strcpy(pext,".h"); }else { outFilename = (char*)dbCalloc(1,strlen(argv[2])+1); strcpy(outFilename,argv[2]); } pdbbase = dbAllocBase(); pdbbase->ignoreMissingMenus = TRUE; pdbbase->loadCdefs = TRUE; status = dbReadDatabase(&pdbbase,argv[1],path,sub); if(status) { errlogFlush(); fprintf(stderr, "dbToMenuH: Input errors, no output generated\n"); exit(1); } outFile = fopen(outFilename,"wt"); if(!outFile) { epicsPrintf("Error creating output file \"%s\"\n", outFilename); exit(1); } fprintf(outFile,"/// @file\n/// EPICS DB record definitions\n\n"); pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList); while(pdbMenu) { fprintf(outFile,"/// %s EPICS DB menu\n",pdbMenu->name); fprintf(outFile,"enum %s\n{\n", pdbMenu->name); for(i=0; i<pdbMenu->nChoice; i++) { fprintf(outFile,"\t%s",pdbMenu->papChoiceName[i]); if(i < (pdbMenu->nChoice - 1)) fprintf(outFile,","); fprintf(outFile,"\t///< %s", pdbMenu->papChoiceValue[i]); fprintf(outFile,"\n"); } fprintf(outFile,"};\n\n"); pdbMenu = (dbMenu *)ellNext(&pdbMenu->node); } pdbRecordType = (dbRecordType *)ellFirst(&pdbbase->recordTypeList); while(pdbRecordType) { fprintf(outFile,"/// %s EPICS DB record\n",pdbRecordType->name); fprintf(outFile,"struct %s\n{\n",pdbRecordType->name); for(i=0; i<pdbRecordType->no_fields; i++) { char name[256]; int j; pdbFldDes = pdbRecordType->papFldDes[i]; for(j=0; j< (int)strlen(pdbFldDes->name); j++) name[j] = pdbFldDes->name[j]; name[strlen(pdbFldDes->name)] = 0; switch(pdbFldDes->field_type) { case DBF_STRING : fprintf(outFile, "\tchar\t\t%s[%d];\t///< %s\n", name, pdbFldDes->size, pdbFldDes->prompt); break; case DBF_CHAR : fprintf(outFile, "\tepicsInt8\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_UCHAR : fprintf(outFile, "\tepicsUInt8\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_SHORT : fprintf(outFile, "\tepicsInt16\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_USHORT : fprintf(outFile, "\tepicsUInt16\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_LONG : fprintf(outFile, "\tepicsInt32\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_ULONG : fprintf(outFile, "\tepicsUInt32\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_FLOAT : fprintf(outFile, "\tepicsFloat32\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_DOUBLE : fprintf(outFile, "\tepicsFloat64\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_MENU : pdbMenu = (dbMenu*)pdbFldDes->ftPvt; if (pdbMenu != NULL) { fprintf(outFile, "\t%s\t%s;\t///< %s\n", pdbMenu->name, name, pdbFldDes->prompt); } else { fprintf(outFile, "\tepicsEnum16\t%s;\t///< %s\n", name, pdbFldDes->prompt); } break; case DBF_ENUM : case DBF_DEVICE : fprintf(outFile, "\tepicsEnum16\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_INLINK : case DBF_OUTLINK : case DBF_FWDLINK : fprintf(outFile, "\tDBLINK\t\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_NOACCESS: break; default: fprintf(outFile,"ILLEGAL FIELD TYPE\n"); } } fprintf(outFile,"};\n"); pdbRecordType = (dbRecordType *)ellNext(&pdbRecordType->node); if(pdbRecordType) fprintf(outFile,"\n"); } fclose(outFile); free((void *)outFilename); return(0); }
void threadFunc_user_RingBuf(void *param) { int i, ellCnt; /* int show_info = 0; */ ST_STD_device *pSTDdev = (ST_STD_device*) param; // ST_threadCfg *pST_BufThread; ST_User_Buff_node queueData; ST_buf_node *pbufferNode; ST_ACQ196 *pAcq196; // while( !pSTDdev->pST_BuffThread) epicsThreadSleep(.1); // pST_BufThread = (ST_threadCfg*) pSTDdev->pST_BuffThread; pAcq196 = (ST_ACQ196 *)pSTDdev->pUser; #if PRINT_DAQ_DEBUG epicsPrintf("\n %s: pSTDdev: %p, pAcq196: %p , pST_BuffThread: %p\n",pSTDdev->taskName, pSTDdev, pAcq196, pSTDdev->ST_RingBufThread ); #endif /* epicsPrintf("\n >>> %s has threadQueueId: %d\n", pST_BufThread->threadName, pSTDdev->ST_RingBufThread.threadQueueId ); */ for(i = 0; i< MAX_RING_BUF_NUM; i++) { ST_buf_node *pbufferNode1 = NULL; pbufferNode1 = (ST_buf_node*) malloc(sizeof(ST_buf_node)); if(!pbufferNode1) { epicsPrintf("\n>>> threadFunc_user_RingBuf: malloc(sizeof(ST_buf_node))... fail\n"); return; } ellAdd(pSTDdev->pList_BufferNode, &pbufferNode1->node); } epicsPrintf(" %s: create %d node (size:%dKB)\n", pSTDdev->ST_RingBufThread.threadName, MAX_RING_BUF_NUM, sizeof(ST_buf_node)/1024 ); /* epicsPrintf("task launching: %s thread for %s task\n",pringThreadConfig->threadName, pSTDdev->taskName); */ #if 0 epicsPrintf(">>> %s, ellCnt:%d\n", pringThreadConfig->threadName, ellCount(pAcq196->pdrvBufferConfig->pbufferList)); #endif while(TRUE) { epicsMessageQueueReceive(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buff_node)); if( queueData.opcode & QUEUE_OPCODE_CLOSE_FILE) { #if PRINT_DMA_NUM printf(">>> [3]%s: got msg \"%s\" close\n", pSTDdev->taskName, pAcq196->dataFileName); #endif #if USE_FILE_POINTER if( pAcq196->fpRaw != NULL ) fclose(pAcq196->fpRaw); pAcq196->fpRaw = NULL; #else close(pAcq196->R_file); pAcq196->R_file = -1; #endif #if PRINT_DMA_NUM printf(">>> [4]%s: DAQ stopted!(0x%X) \n", pSTDdev->taskName, pSTDdev->StatusDev); #endif /* trig_stop = wf_getCurrentUsec(); trig_interval = wf_intervalUSec(trig_start, trig_stop); */ #if PRINT_DMA_NUM /* printf(">>> [5]%s: Trig ON time is %lf sec\n", pSTDdev->taskName, (1.E-3 * (double)trig_interval)/1000.0 ); */ #endif /* it will have possible problem when Mater mode with internal clock */ if( (pAcq196->nCardMode != CARD_MODE_MASTER) && (pAcq196->clockSource == CLOCK_INTERNAL) ) /* this is single op mode */ { acq196_setDIO_falling(pSTDdev); } pSTDdev->StatusDev &= ~DEV_CMD_DAQ_STOPED; } /* when opcode is file close command */ else { pbufferNode = queueData.pNode; if( pSTDdev->StatusDev & TASK_WAIT_FOR_TRIGGER ) { pSTDdev->StatusDev |= TASK_IN_PROGRESS; pSTDdev->StatusDev &= ~TASK_WAIT_FOR_TRIGGER; scanIoRequest(pSTDdev->ioScanPvt_status); notify_refresh_master_status(); } #if USE_FILE_POINTER fwrite( pbufferNode->data, queueData.size, 1, pAcq196->fpRaw ); #else write(pAcq196->R_file, pbufferNode->data, queueData.size); #endif ellAdd(pSTDdev->pList_BufferNode, &pbufferNode->node); ellCnt = ellCount(pSTDdev->pList_BufferNode); #if 0 if( pSTDdev->ST_Base.nSamplingRate >= 200000) { if( (queueData.u32Cnt % 8 )==0 ) show_info = 1; } else if( pSTDdev->ST_Base.nSamplingRate >= 100000) { if( (queueData.u32Cnt % 5 )==0 ) show_info = 1; } else if( pSTDdev->ST_Base.nSamplingRate >= 50000) { if( (queueData.u32Cnt % 3 )==0 ) show_info = 1; } else { show_info = 1; } if( show_info){ /* printf("*%s, %dMB, %d, rcv:%lu\n", pringThreadConfig->threadName, queueData.size/1024/1024, ellCnt, queueData.u32Cnt ); */ pAcq196->daqing_cnt++; scanIoRequest(pSTDdev->ioScanPvt_userCall); show_info = 0; } #endif pAcq196->daqing_cnt++; scanIoRequest(pSTDdev->ioScanPvt_userCall); if( ellCnt < MAX_CUTOFF_BUF_NODE) { printf("!!! %s, Danger! DMA must be Stopped !! >> Ell Counter: %d\n", pSTDdev->ST_RingBufThread.threadName, ellCnt); /* pSTDdev->StatusDev &= ~STATUS_SYS_RUN; drvDPIO2_set_DMAstop ( pAcq196); */ } } /* whenever get a Data node */ } /* while(TRUE) */ return; }
/* * rsrv_init () */ int rsrv_init (void) { epicsThreadBooleanStatus tbs; unsigned priorityOfConnectDaemon; epicsThreadId tid; long maxBytesAsALong; long status; clientQlock = epicsMutexMustCreate(); ellInit ( &clientQ ); freeListInitPvt ( &rsrvClientFreeList, sizeof(struct client), 8 ); freeListInitPvt ( &rsrvChanFreeList, sizeof(struct channel_in_use), 512 ); freeListInitPvt ( &rsrvEventFreeList, sizeof(struct event_ext), 512 ); freeListInitPvt ( &rsrvSmallBufFreeListTCP, MAX_TCP, 16 ); initializePutNotifyFreeList (); status = envGetLongConfigParam ( &EPICS_CA_MAX_ARRAY_BYTES, &maxBytesAsALong ); if ( status || maxBytesAsALong < 0 ) { errlogPrintf ( "CAS: EPICS_CA_MAX_ARRAY_BYTES was not a positive integer\n" ); rsrvSizeofLargeBufTCP = MAX_TCP; } else { /* allow room for the protocol header so that they get the array size they requested */ static const unsigned headerSize = sizeof ( caHdr ) + 2 * sizeof ( ca_uint32_t ); ca_uint32_t maxBytes = ( unsigned ) maxBytesAsALong; if ( maxBytes < 0xffffffff - headerSize ) { maxBytes += headerSize; } else { maxBytes = 0xffffffff; } if ( maxBytes < MAX_TCP ) { errlogPrintf ( "CAS: EPICS_CA_MAX_ARRAY_BYTES was rounded up to %u\n", MAX_TCP ); rsrvSizeofLargeBufTCP = MAX_TCP; } else { rsrvSizeofLargeBufTCP = maxBytes; } } freeListInitPvt ( &rsrvLargeBufFreeListTCP, rsrvSizeofLargeBufTCP, 1 ); ellInit ( &beaconAddrList ); prsrv_cast_client = NULL; pCaBucket = NULL; castcp_startStopEvent = epicsEventMustCreate(epicsEventEmpty); castcp_ctl = ctlPause; /* * go down two levels so that we are below * the TCP and event threads started on behalf * of individual clients */ tbs = epicsThreadHighestPriorityLevelBelow ( epicsThreadPriorityCAServerLow, &priorityOfConnectDaemon ); if ( tbs == epicsThreadBooleanStatusSuccess ) { tbs = epicsThreadHighestPriorityLevelBelow ( priorityOfConnectDaemon, &priorityOfConnectDaemon ); if ( tbs != epicsThreadBooleanStatusSuccess ) { priorityOfConnectDaemon = epicsThreadPriorityCAServerLow; } } else { priorityOfConnectDaemon = epicsThreadPriorityCAServerLow; } tid = epicsThreadCreate ( "CAS-TCP", priorityOfConnectDaemon, epicsThreadGetStackSize(epicsThreadStackMedium), req_server, 0); if ( tid == 0 ) { epicsPrintf ( "CAS: unable to start connection request thread\n" ); } epicsEventMustWait(castcp_startStopEvent); return RSRV_OK; }
static long devAoXXX_write_ao(aoRecord *precord) { ST_dpvt *pDpvt = (ST_dpvt*) precord->dpvt; ST_STD_device *pSTDdev; ST_XXX *pXXX; ST_threadCfg *pControlThreadConfig; ST_threadQueueData qData; if(!pDpvt || precord->udf == TRUE) { precord->pact = TRUE; return -1; } pSTDdev = pDpvt->pSTDdev; pControlThreadConfig = pSTDdev->pST_stdCtrlThread; qData.param.pSTDdev = pSTDdev; qData.param.precord = (struct dbCommon *)precord; qData.param.setValue = precord->val; pXXX = (ST_XXX*)pSTDdev->pUser; /* db processing: phase I */ if(precord->pact == FALSE) { precord->pact = TRUE; #if PRINT_DBPRO_PHASE_INFO epicsPrintf("db processing: phase I %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pDpvt->ind) { case AO_TEST_1: qData.pFunc = devAoXXX_AO_TEST_1; break; case AO_TEST_2: qData.pFunc = devAoXXX_AO_TEST_2; qData.param.n32Arg0 = pDpvt->n32Arg0; /* channel id */ qData.param.n32Arg1 = pDpvt->n32Arg1; /* section id */ break; default: break; } epicsMessageQueueSend(pControlThreadConfig->threadQueueId, (void*) &qData, sizeof(ST_threadQueueData)); return 0; /*(0)=>(success ) */ } /* db processing: phase II -post processing */ if(precord->pact == TRUE) { #if PRINT_DBPRO_PHASE_INFO epicsPrintf("db processing: phase II %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pDpvt->ind) { case AO_TEST_1: /*do something */ break; case AO_TEST_2: /*do something */ break; default: break; } precord->pact = FALSE; precord->udf = FALSE; return 0; /*(0)=>(success ) */ } return -1; }
static long dbReadCOM(DBBASE **ppdbbase,const char *filename, FILE *fp, const char *path,const char *substitutions) { long status; inputFile *pinputFile = NULL; char *penv; char **macPairs; if(*ppdbbase == 0) *ppdbbase = dbAllocBase(); pdbbase = *ppdbbase; if(path && strlen(path)>0) { dbPath(pdbbase,path); } else { penv = getenv("EPICS_DB_INCLUDE_PATH"); if(penv) { dbPath(pdbbase,penv); } else { dbPath(pdbbase,"."); } } my_buffer = dbCalloc(MY_BUFFER_SIZE,sizeof(char)); freeListInitPvt(&freeListPvt,sizeof(tempListNode),100); if(substitutions) { if(macCreateHandle(&macHandle,NULL)) { epicsPrintf("macCreateHandle error\n"); status = -1; goto cleanup; } macParseDefns(macHandle,(char *)substitutions,&macPairs); if(macPairs ==NULL) { macDeleteHandle(macHandle); macHandle = NULL; } else { macInstallMacros(macHandle,macPairs); free((void *)macPairs); mac_input_buffer = dbCalloc(MY_BUFFER_SIZE,sizeof(char)); } } pinputFile = dbCalloc(1,sizeof(inputFile)); if(filename) { pinputFile->filename = macEnvExpand(filename); } if(!fp) { FILE *fp1; if(pinputFile->filename) pinputFile->path = dbOpenFile(pdbbase,pinputFile->filename,&fp1); if(!pinputFile->filename || !fp1) { errPrintf(0,__FILE__, __LINE__, "dbRead opening file %s",pinputFile->filename); free((void *)pinputFile->filename); free((void *)pinputFile); status = -1; goto cleanup; } pinputFile->fp = fp1; } else { pinputFile->fp = fp; } pinputFile->line_num = 0; pinputFileNow = pinputFile; my_buffer[0] = '\0'; my_buffer_ptr = my_buffer; ellAdd(&inputFileList,&pinputFile->node); status = pvt_yy_parse(); dbFreePath(pdbbase); if(!status) { /*add RTYP and VERS as an attribute */ DBENTRY dbEntry; DBENTRY *pdbEntry = &dbEntry; long localStatus; dbInitEntry(pdbbase,pdbEntry); localStatus = dbFirstRecordType(pdbEntry); while(!localStatus) { localStatus = dbPutRecordAttribute(pdbEntry,"RTYP", dbGetRecordTypeName(pdbEntry)); if(!localStatus) { localStatus = dbPutRecordAttribute(pdbEntry,"VERS", "none specified"); } if(localStatus) { fprintf(stderr,"dbPutRecordAttribute status %ld\n",status); } else { localStatus = dbNextRecordType(pdbEntry); } } dbFinishEntry(pdbEntry); } cleanup: if(macHandle) macDeleteHandle(macHandle); macHandle = NULL; if(mac_input_buffer) free((void *)mac_input_buffer); mac_input_buffer = NULL; if(freeListPvt) freeListCleanup(freeListPvt); freeListPvt = NULL; if(my_buffer) free((void *)my_buffer); my_buffer = NULL; freeInputFileList(); return(status); }
static void devAoXXX_AO_TEST_2(ST_execParam *pParam) { struct dbCommon *precord = pParam->precord; epicsPrintf("%s ( %d )\n", precord->name, (int)pParam->setValue); }
static long devBoXXX_write_bo(boRecord *precord) { ST_dpvt *pDpvt = (ST_dpvt*) precord->dpvt; ST_STD_device *pSTDdev; ST_threadCfg *pControlThreadConfig; ST_threadQueueData qData; if(!pDpvt || precord->udf == TRUE) { precord->pact = TRUE; return 0; } pSTDdev = pDpvt->pSTDdev; pControlThreadConfig = pSTDdev->pST_stdCtrlThread; qData.param.pSTDdev = pSTDdev; qData.param.precord = (struct dbCommon *)precord; qData.param.setValue = (double)precord->val; qData.param.n32Arg0 = pDpvt->n32Arg0; /* db processing: phase I */ if(precord->pact == FALSE) { precord->pact = TRUE; #if PRINT_DBPRO_PHASE_INFO epicsPrintf("db processing: phase I %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pDpvt->ind) { case BO_TEST_1: qData.pFunc = devBoXXX_BO_TEST_1; break; case BO_TEST_2: qData.pFunc = devBoXXX_BO_TEST_2; break; default: break; } epicsMessageQueueSend(pControlThreadConfig->threadQueueId, (void*) &qData, sizeof(ST_threadQueueData)); return 0; } /* db processing: phase II -post processing */ if(precord->pact == TRUE) { #if PRINT_DBPRO_PHASE_INFO epicsPrintf("db processing: phase II %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif precord->pact = FALSE; precord->udf = FALSE; switch(pDpvt->ind) { case BO_TEST_1: /*do something */ /*precord->val = 0; */ break; case BO_TEST_2: /*do something */ /*precord->val = 0; */ break; default: break; } return 0; /*returns: (-1,0)=>(failure,success)*/ } return -1; }
void threadFunc_RTcore_RingBuf(void *param) { int i, ellCnt; epicsThreadId pthreadInfo; ST_STD_device *pSTDdev = (ST_STD_device*) param; ST_User_Buf_node queueData; ST_buf_node *pbufferNode; ST_RTcore *pRTcore; pRTcore = (ST_RTcore *)pSTDdev->pUser; #if 0 epicsPrintf("\n %s: pSTDdev: %p, p16aiss8ao4: %p , pST_BuffThread: %p\n",pSTDdev->taskName, pSTDdev, p16aiss8ao4, pST_BufThread ); #endif for(i = 0; i< MAX_RING_BUF_NUM; i++) { ST_buf_node *pbufferNode1 = NULL; pbufferNode1 = (ST_buf_node*) malloc(sizeof(ST_buf_node)); if(!pbufferNode1) { epicsPrintf("\n>>> threadFunc_user_RingBuf: malloc(sizeof(ST_buf_node))... fail\n"); return; } ellAdd(pSTDdev->pList_BufferNode, &pbufferNode1->node); } epicsPrintf(" %s: create %d node (size:%dKB)\n", pSTDdev->ST_RingBufThread.threadName, MAX_RING_BUF_NUM, sizeof(ST_buf_node)/1024 ); #if 0 epicsPrintf(">>> %s, ellCnt:%d\n", pringThreadConfig->threadName, ellCount(p16aiss8ao4->pdrvBufferConfig->pbufferList)); #endif #if USE_CPU_AFFINITY_RT pthreadInfo = epicsThreadGetIdSelf(); /* printf("%s: EPICS ID %p, pthreadID %lu\n", pthreadInfo->name, (void *)pthreadInfo, (unsigned long)pthreadInfo->tid); */ epicsThreadSetCPUAffinity( pthreadInfo, AFFINITY_RTCORE_RING); epicsThreadSetPosixPriority(pthreadInfo, PRIOTY_RTCORE_RING, "SCHED_FIFO"); #endif while(TRUE) { epicsMessageQueueReceive(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buf_node)); pbufferNode = queueData.pNode; /* fwrite( pbufferNode->data, sizeof(unsigned int), LOOP_CNT*LOOP_ELM, pRTcore->fp_raw); */ ellAdd(pSTDdev->pList_BufferNode, &pbufferNode->node); ellCnt = ellCount(pSTDdev->pList_BufferNode); /* printf("RTcore_RingBuf, ellCnt: %d\n", ellCnt); */ } /* while(TRUE) */ return; }
static long devAoRfm5565_write_ao(aoRecord *precord) { ST_dpvt *pDpvt = (ST_dpvt*) precord->dpvt; ST_STD_device *pSTDdev; ST_RFM5565* pRFM5565; ST_threadCfg *pControlThreadConfig; ST_threadQueueData qData; RFM2G_STATUS result; RFM2G_UINT32 buffer; if(!pDpvt || precord->udf == TRUE) { precord->pact = TRUE; return -1; } pSTDdev = pDpvt->pSTDdev; pRFM5565 = (ST_RFM5565 *)pSTDdev->pUser; pControlThreadConfig = pSTDdev->pST_stdCtrlThread; qData.param.precord = (struct dbCommon *)precord; qData.param.setValue = precord->val; /* db processing: phase I */ if(precord->pact == FALSE) { precord->pact = TRUE; #if 0 epicsPrintf("db processing: phase I %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pDpvt->ind) { case AO_SET_READ_OFFSET: pRFM5565->Offset = (RFM2G_UINT32)precord->val; precord->pact = FALSE; precord->udf = FALSE; return 0; /*(0)=>(success ) */ case AO_RFM_WRITE_VALUE: buffer = (RFM2G_UINT32)precord->val; result = RFM2gWrite( pRFM5565->Handle, pRFM5565->Offset, &buffer, sizeof(RFM2G_UINT32)*1 ); if( result != RFM2G_SUCCESS ) { printf( "ERROR: Could not write data to Reflective Memory.\n" ); RFM2gClose( &pRFM5565->Handle ); return(-1); } precord->pact = FALSE; precord->udf = FALSE; return 0; /*(0)=>(success ) */ default: break; } epicsMessageQueueSend(pControlThreadConfig->threadQueueId, (void*) &qData, sizeof(ST_threadQueueData)); return 0; /*(0)=>(success ) */ } /* db processing: phase II -post processing */ if(precord->pact == TRUE) { #if 0 epicsPrintf("db processing: phase II %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pDpvt->ind) { // case AO_SET_READ_OFFSET: precord->val = pRFM5565->Offset ; break; default: break; } precord->pact = FALSE; precord->udf = FALSE; return 0; /*(0)=>(success ) */ } return -1; }
/* * RSRV_ONLINE_NOTIFY_TASK */ void rsrv_online_notify_task(void *pParm) { unsigned priorityOfSelf = epicsThreadGetPrioritySelf (); osiSockAddrNode *pNode; double delay; double maxdelay; long longStatus; double maxPeriod; caHdr msg; int status; SOCKET sock; int intTrue = TRUE; unsigned short port; ca_uint32_t beaconCounter = 0; char * pStr; int autoBeaconAddr; ELLLIST autoAddrList; char buf[16]; unsigned priorityOfUDP; epicsThreadBooleanStatus tbs; epicsThreadId tid; taskwdInsert (epicsThreadGetIdSelf(),NULL,NULL); if ( envGetConfigParamPtr ( & EPICS_CAS_BEACON_PERIOD ) ) { longStatus = envGetDoubleConfigParam ( & EPICS_CAS_BEACON_PERIOD, & maxPeriod ); } else { longStatus = envGetDoubleConfigParam ( & EPICS_CA_BEACON_PERIOD, & maxPeriod ); } if (longStatus || maxPeriod<=0.0) { maxPeriod = 15.0; epicsPrintf ("EPICS \"%s\" float fetch failed\n", EPICS_CAS_BEACON_PERIOD.name); epicsPrintf ("Setting \"%s\" = %f\n", EPICS_CAS_BEACON_PERIOD.name, maxPeriod); } delay = 0.02; /* initial beacon period in sec */ maxdelay = maxPeriod; /* * Open the socket. * Use ARPA Internet address format and datagram socket. * Format described in <sys/socket.h>. */ if ( (sock = epicsSocketCreate (AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) { errlogPrintf ("CAS: online socket creation error\n"); epicsThreadSuspendSelf (); } status = setsockopt (sock, SOL_SOCKET, SO_BROADCAST, (char *)&intTrue, sizeof(intTrue)); if (status<0) { errlogPrintf ("CAS: online socket set up error\n"); epicsThreadSuspendSelf (); } { /* * this connect is to supress a warning message on Linux * when we shutdown the read side of the socket. If it * fails (and it will on old ip kernels) we just ignore * the failure. */ osiSockAddr sockAddr; sockAddr.ia.sin_family = AF_UNSPEC; sockAddr.ia.sin_port = htons ( 0 ); sockAddr.ia.sin_addr.s_addr = htonl (0); connect ( sock, & sockAddr.sa, sizeof ( sockAddr.sa ) ); shutdown ( sock, SHUT_RD ); } memset((char *)&msg, 0, sizeof msg); msg.m_cmmd = htons (CA_PROTO_RSRV_IS_UP); msg.m_count = htons (ca_server_port); msg.m_dataType = htons (CA_MINOR_PROTOCOL_REVISION); ellInit ( & beaconAddrList ); ellInit ( & autoAddrList ); pStr = envGetConfigParam(&EPICS_CAS_AUTO_BEACON_ADDR_LIST, sizeof(buf), buf); if ( ! pStr ) { pStr = envGetConfigParam(&EPICS_CA_AUTO_ADDR_LIST, sizeof(buf), buf); } if (pStr) { if (strstr(pStr,"no")||strstr(pStr,"NO")) { autoBeaconAddr = FALSE; } else if (strstr(pStr,"yes")||strstr(pStr,"YES")) { autoBeaconAddr = TRUE; } else { fprintf(stderr, "CAS: EPICS_CA(S)_AUTO_ADDR_LIST = \"%s\"? Assuming \"YES\"\n", pStr); autoBeaconAddr = TRUE; } } else { autoBeaconAddr = TRUE; } /* * load user and auto configured * broadcast address list */ if (envGetConfigParamPtr(&EPICS_CAS_BEACON_PORT)) { port = envGetInetPortConfigParam (&EPICS_CAS_BEACON_PORT, (unsigned short) CA_REPEATER_PORT ); } else { port = envGetInetPortConfigParam (&EPICS_CA_REPEATER_PORT, (unsigned short) CA_REPEATER_PORT ); } /* * discover beacon addresses associated with this interface */ if ( autoBeaconAddr ) { osiSockAddr addr; ELLLIST tmpList; ellInit ( &tmpList ); addr.ia.sin_family = AF_UNSPEC; osiSockDiscoverBroadcastAddresses (&tmpList, sock, &addr); forcePort ( &tmpList, port ); removeDuplicateAddresses ( &autoAddrList, &tmpList, 1 ); } /* * by default use EPICS_CA_ADDR_LIST for the * beacon address list */ { const ENV_PARAM *pParam; if (envGetConfigParamPtr(&EPICS_CAS_INTF_ADDR_LIST) || envGetConfigParamPtr(&EPICS_CAS_BEACON_ADDR_LIST)) { pParam = &EPICS_CAS_BEACON_ADDR_LIST; } else { pParam = &EPICS_CA_ADDR_LIST; } /* * add in the configured addresses */ addAddrToChannelAccessAddressList ( &autoAddrList, pParam, port, pParam == &EPICS_CA_ADDR_LIST ); } removeDuplicateAddresses ( &beaconAddrList, &autoAddrList, 0 ); if ( ellCount ( &beaconAddrList ) == 0 ) { errlogPrintf ("The CA server's beacon address list was empty after initialization?\n"); } # ifdef DEBUG printChannelAccessAddressList (&beaconAddrList); # endif tbs = epicsThreadHighestPriorityLevelBelow ( priorityOfSelf, &priorityOfUDP ); if ( tbs != epicsThreadBooleanStatusSuccess ) { priorityOfUDP = priorityOfSelf; } casudp_startStopEvent = epicsEventMustCreate(epicsEventEmpty); casudp_ctl = ctlPause; tid = epicsThreadCreate ( "CAS-UDP", priorityOfUDP, epicsThreadGetStackSize (epicsThreadStackMedium), cast_server, 0 ); if ( tid == 0 ) { epicsPrintf ( "CAS: unable to start UDP daemon thread\n" ); } epicsEventMustWait(casudp_startStopEvent); epicsEventSignal(beacon_startStopEvent); while (TRUE) { pNode = (osiSockAddrNode *) ellFirst (&beaconAddrList); while (pNode) { char buf[64]; status = connect (sock, &pNode->addr.sa, sizeof(pNode->addr.sa)); if (status<0) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); ipAddrToDottedIP (&pNode->addr.ia, buf, sizeof(buf)); errlogPrintf ( "%s: CA beacon routing (connect to \"%s\") error was \"%s\"\n", __FILE__, buf, sockErrBuf); } else { struct sockaddr_in if_addr; osiSocklen_t size = sizeof (if_addr); status = getsockname (sock, (struct sockaddr *) &if_addr, &size); if (status<0) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf ( "%s: CA beacon routing (getsockname) error was \"%s\"\n", __FILE__, sockErrBuf); } else if (if_addr.sin_family==AF_INET) { msg.m_available = if_addr.sin_addr.s_addr; msg.m_cid = htonl ( beaconCounter ); status = send (sock, (char *)&msg, sizeof(msg), 0); if (status < 0) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); ipAddrToDottedIP (&pNode->addr.ia, buf, sizeof(buf)); errlogPrintf ( "%s: CA beacon (send to \"%s\") error was \"%s\"\n", __FILE__, buf, sockErrBuf); } else { assert (status == sizeof(msg)); } } } pNode = (osiSockAddrNode *) pNode->node.next; } epicsThreadSleep(delay); if (delay<maxdelay) { delay *= 2.0; if (delay>maxdelay) { delay = maxdelay; } } beaconCounter++; /* expected to overflow */ while (beacon_ctl == ctlPause) { epicsThreadSleep(0.1); delay = 0.02; /* Restart beacon timing if paused */ } } }
int acq196_htstream(ST_STD_device *pSTDdev) { int next = BUFFERA; int timeouts = 0; /*#define FD (ST_ACQ196*)(pSTDdev->pUser)->drv_bufAB[BUFFERA].fd */ int started = 0; int rc=0; unsigned long int syscalls = 0; ST_ACQ196 *pAcq196; pAcq196 = (ST_ACQ196 *)pSTDdev->pUser; #define FD pAcq196->drv_bufAB[BUFFERA].fd ST_User_Buff_node queueData; ST_buf_node *pbufferNode = NULL; // ST_threadCfg *pDAQST_threadConfig=NULL; // pDAQST_threadConfig = (ST_threadCfg*) pSTDdev.ST_BuffThread; // if( !pDAQST_threadConfig ) { // printf("ERROR! %s can't recive Buff Thread\n", pSTDdev->taskName ); // return WR_ERROR; // } if( acq196_initMapping(pAcq196->drv_bufAB+0, (int)pAcq196->slot) == WR_ERROR ) printf("ERROR! acq196_initMapping() buf 0\n"); if( acq196_initMapping(pAcq196->drv_bufAB+1, (int)pAcq196->slot) == WR_ERROR ) printf("ERROR! acq196_initMapping() buf 1\n"); #if PRINT_DAQ_DEBUG epicsPrintf("\n %s: pSTDdev: %p, pAcq196: %p , pST_BuffThread: %p\n",pSTDdev->taskName, pSTDdev, pAcq196, pSTDdev->ST_RingBufThread ); #endif if( acq196_setDIO_rising(pSTDdev) == WR_ERROR ) { printf("\n>>> drvACQ196_RUN_start: acq196_setDIO_rising()... ERROR" ); acq196_closeMapping(pAcq196->drv_bufAB+0); acq196_closeMapping(pAcq196->drv_bufAB+1); return WR_ERROR; } while( pSTDdev->StatusDev & DEV_IN_LOOP_HTSTREAM ) { #if DEBUG_PRINT_HTSTREAM printf("\n>>> acq196_htstream: call ioctl(xxx)...stopmsg:%d, %p. ", pAcq196->gotDAQstopMsg, pAcq196); rc = ioctl(FD, ACQ200_BUFFER_AB_IOWR, &(pAcq196->drv_ops) ); printf("return(%d)... msg:%d, %p \n", rc, pAcq196->gotDAQstopMsg, pAcq196); #else rc = ioctl(FD, ACQ200_BUFFER_AB_IOWR, &(pAcq196->drv_ops) ); #endif if (rc >= 0) { if (acq200_debug && timeouts != 0){ printf("acq200_debug && timeouts != 0\n"); } timeouts = 0; started = 1; } else if (rc == -ETIMEDOUT){ if (acq200_debug){ fputc('.', stderr); fflush(stderr); } if (started && ++timeouts >= MAXTO){ perror("TIMEOUT?"); acq196_closeMapping(pAcq196->drv_bufAB+0); acq196_closeMapping(pAcq196->drv_bufAB+1); #if USE_FILE_POINTER fclose(pAcq196->fpRaw); #else close(pAcq196->R_file); #endif return rc; }else{ continue; } } else { perror("ERROR ioctl(ACQ200_BUFFER_AB_IOWR)"); acq196_closeMapping(pAcq196->drv_bufAB+0); acq196_closeMapping(pAcq196->drv_bufAB+1); #if USE_FILE_POINTER fclose(pAcq196->fpRaw); #else close(pAcq196->R_file); #endif return rc; } pAcq196->drv_ops.ci.recycle = 0; /* queueData.u32Cnt = syscalls; */ if (pAcq196->drv_ops.ds.full&BUFFER_FLAG_LUT[next]) { pAcq196->rawDataSize += pAcq196->drv_ops.ds.len[next]; #if DEBUG_PRINT_HTSTREAM printf("1N:%d %8d %8d :", next, pAcq196->drv_ops.ds.sid[next], pAcq196->drv_ops.ds.len[next]); #endif pAcq196->drv_ops.ci.recycle |= BUFFER_FLAG_LUT[next]; pbufferNode = (ST_buf_node *)ellFirst(pSTDdev->pList_BufferNode); ellDelete(pSTDdev->pList_BufferNode, &pbufferNode->node); memcpy( pbufferNode->data, pAcq196->drv_bufAB[next].pbuf, pAcq196->drv_ops.ds.len[next]); queueData.pNode = pbufferNode; queueData.size = pAcq196->drv_ops.ds.len[next]; queueData.opcode = QUEUE_OPCODE_NORMAL; epicsMessageQueueSend(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buff_node)); if( pAcq196->gotDAQstopMsg ) { if( pAcq196->rawDataSize >= pAcq196->needDataSize ) { queueData.pNode = NULL; queueData.opcode = QUEUE_OPCODE_CLOSE_FILE; /* if there is some data in next buffer, then do not send EOB message */ if( !(pAcq196->drv_ops.ds.full&BUFFER_FLAG_LUT[!next]) ) { pSTDdev->StatusDev &= ~DEV_IN_LOOP_HTSTREAM; #if PRINT_DMA_NUM printf("\n>>> [2.1]%s: send EOB message.\n", pSTDdev->taskName); #endif epicsMessageQueueSend(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buff_node)); pAcq196->gotDAQstopMsg = 0; } else { printf("\n>>> %s: got Stop Msg in FirstBuffer. will be passed to next buffer.\n", pSTDdev->taskName); } } #if 0 else{ printf(">>> %s required:%d, acq: %d\n", pSTDdev->taskName, pAcq196->needDataSize, pAcq196->rawDataSize ); } #endif } /* write(pSTDdev->R_file, pSTDdev->drv_bufAB[next].pbuf, pSTDdev->drv_ops.ds.len[next]); */ /* printf("index %d len %d\n", next, pSTDdev->drv_ops.ds.len[next]); */ next = !next; if (pAcq196->drv_ops.ds.full&BUFFER_FLAG_LUT[next]) { pAcq196->rawDataSize += pAcq196->drv_ops.ds.len[next]; #if DEBUG_PRINT_HTSTREAM printf("2N:%d %8d %8d :", next, pAcq196->drv_ops.ds.sid[next], pAcq196->drv_ops.ds.len[next]); #endif pAcq196->drv_ops.ci.recycle |= BUFFER_FLAG_LUT[next]; pbufferNode = (ST_buf_node *)ellFirst(pSTDdev->pList_BufferNode); ellDelete(pSTDdev->pList_BufferNode, &pbufferNode->node); memcpy( pbufferNode->data, pAcq196->drv_bufAB[next].pbuf, pAcq196->drv_ops.ds.len[next]); queueData.pNode = pbufferNode; queueData.size = pAcq196->drv_ops.ds.len[next]; queueData.opcode = QUEUE_OPCODE_NORMAL; epicsMessageQueueSend(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buff_node)); if( pAcq196->gotDAQstopMsg ) { if( pAcq196->rawDataSize >= pAcq196->needDataSize ) { pSTDdev->StatusDev &= ~DEV_IN_LOOP_HTSTREAM; queueData.pNode = NULL; queueData.opcode = QUEUE_OPCODE_CLOSE_FILE; #if PRINT_DMA_NUM printf("\n>>> [2.2]%s: send EOB message.\n", pSTDdev->taskName); #endif epicsMessageQueueSend(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buff_node)); pAcq196->gotDAQstopMsg = 0; } #if 0 else{ printf(">>> %s required:%d, acq: %d\n", pSTDdev->taskName, pAcq196->needDataSize, pAcq196->rawDataSize ); } #endif } /* write(pSTDdev->R_file, pSTDdev->drv_bufAB[next].pbuf, pSTDdev->drv_ops.ds.len[next]); */ /* printf("index %d len %d\n", next, pSTDdev->drv_ops.ds.len[next]); */ next = !next; } /* second buffer task... */ } /* first buffer task... */ if (pAcq196->drv_ops.ds.full&FULL_EOF){ break; } /* if (pSTDdev->drv_ops.ds.full&FULL_EOF){ */ syscalls++; } /* while( pSTDdev->StatusDev & DEV_IN_LOOP_HTSTREAM ) */ /* move to ring buffer for waiting time consume process.. acq196_closeMapping(pSTDdev->drv_bufAB+0); acq196_closeMapping(pSTDdev->drv_bufAB+1); */ printf(">>> %s: Total/Need:: %.2f/%.2f MB Cnt:%lu\n", pSTDdev->taskName, (float)pAcq196->rawDataSize/1024.0/1024.0, pAcq196->needDataSize/1024.0/1024.0, syscalls); return WR_OK; }
// // udpiiu::udpiiu () // udpiiu::udpiiu ( epicsGuard < epicsMutex > & cacGuard, epicsTimerQueueActive & timerQueue, epicsMutex & cbMutexIn, epicsMutex & cacMutexIn, cacContextNotify & ctxNotifyIn, cac & cac, unsigned port, tsDLList < SearchDest > & searchDestListIn ) : recvThread ( *this, ctxNotifyIn, cbMutexIn, "CAC-UDP", epicsThreadGetStackSize ( epicsThreadStackMedium ), cac::lowestPriorityLevelAbove ( cac::lowestPriorityLevelAbove ( cac.getInitializingThreadsPriority () ) ) ), m_repeaterTimerNotify ( *this ), repeaterSubscribeTmr ( m_repeaterTimerNotify, timerQueue, cbMutexIn, ctxNotifyIn ), govTmr ( *this, timerQueue, cacMutexIn ), maxPeriod ( maxSearchPeriodDefault ), rtteMean ( minRoundTripEstimate ), rtteMeanDev ( 0 ), cacRef ( cac ), cbMutex ( cbMutexIn ), cacMutex ( cacMutexIn ), nBytesInXmitBuf ( 0 ), nTimers ( 0 ), beaconAnomalyTimerIndex ( 0 ), sequenceNumber ( 0 ), lastReceivedSeqNo ( 0 ), sock ( 0 ), repeaterPort ( 0 ), serverPort ( port ), localPort ( 0 ), shutdownCmd ( false ), lastReceivedSeqNoIsValid ( false ) { cacGuard.assertIdenticalMutex ( cacMutex ); if ( envGetConfigParamPtr ( & EPICS_CA_MAX_SEARCH_PERIOD ) ) { long longStatus = envGetDoubleConfigParam ( & EPICS_CA_MAX_SEARCH_PERIOD, & this->maxPeriod ); if ( ! longStatus ) { if ( this->maxPeriod < maxSearchPeriodLowerLimit ) { epicsPrintf ( "\"%s\" out of range (low)\n", EPICS_CA_MAX_SEARCH_PERIOD.name ); this->maxPeriod = maxSearchPeriodLowerLimit; epicsPrintf ( "Setting \"%s\" = %f seconds\n", EPICS_CA_MAX_SEARCH_PERIOD.name, this->maxPeriod ); } } else { epicsPrintf ( "EPICS \"%s\" wasnt a real number\n", EPICS_CA_MAX_SEARCH_PERIOD.name ); epicsPrintf ( "Setting \"%s\" = %f seconds\n", EPICS_CA_MAX_SEARCH_PERIOD.name, this->maxPeriod ); } } double powerOfTwo = log ( this->maxPeriod / minRoundTripEstimate ) / log ( 2.0 ); this->nTimers = static_cast < unsigned > ( powerOfTwo + 1.0 ); if ( this->nTimers > channelNode::getMaxSearchTimerCount () ) { this->nTimers = channelNode::getMaxSearchTimerCount (); epicsPrintf ( "\"%s\" out of range (high)\n", EPICS_CA_MAX_SEARCH_PERIOD.name ); epicsPrintf ( "Setting \"%s\" = %f seconds\n", EPICS_CA_MAX_SEARCH_PERIOD.name, (1<<(this->nTimers-1)) * minRoundTripEstimate ); } powerOfTwo = log ( beaconAnomalySearchPeriod / minRoundTripEstimate ) / log ( 2.0 ); this->beaconAnomalyTimerIndex = static_cast < unsigned > ( powerOfTwo + 1.0 ); if ( this->beaconAnomalyTimerIndex >= this->nTimers ) { this->beaconAnomalyTimerIndex = this->nTimers - 1; } this->ppSearchTmr.reset ( new epics_auto_ptr < class searchTimer > [ this->nTimers ] ); for ( unsigned i = 0; i < this->nTimers; i++ ) { this->ppSearchTmr[i].reset ( new searchTimer ( *this, timerQueue, i, cacMutexIn, i > this->beaconAnomalyTimerIndex ) ); } this->repeaterPort = envGetInetPortConfigParam ( &EPICS_CA_REPEATER_PORT, static_cast <unsigned short> (CA_REPEATER_PORT) ); this->sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); if ( this->sock == INVALID_SOCKET ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf ("CAC: unable to create datagram socket because = \"%s\"\n", sockErrBuf ); throwWithLocation ( noSocket () ); } int boolValue = true; int status = setsockopt ( this->sock, SOL_SOCKET, SO_BROADCAST, (char *) &boolValue, sizeof ( boolValue ) ); if ( status < 0 ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf ("CAC: IP broadcasting enable failed because = \"%s\"\n", sockErrBuf ); } #if 0 { /* * some concern that vxWorks will run out of mBuf's * if this change is made joh 11-10-98 * * bump up the UDP recv buffer */ int size = 1u<<15u; status = setsockopt ( this->sock, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof (size) ); if (status<0) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf ( "CAC: unable to set socket option SO_RCVBUF because \"%s\"\n", sockErrBuf ); } } #endif // force a bind to an unconstrained address so we can obtain // the local port number below static const unsigned short PORT_ANY = 0u; osiSockAddr addr; memset ( (char *)&addr, 0 , sizeof (addr) ); addr.ia.sin_family = AF_INET; addr.ia.sin_addr.s_addr = htonl ( INADDR_ANY ); addr.ia.sin_port = htons ( PORT_ANY ); status = bind (this->sock, &addr.sa, sizeof (addr) ); if ( status < 0 ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); epicsSocketDestroy (this->sock); errlogPrintf ( "CAC: unable to bind to an unconstrained address because = \"%s\"\n", sockErrBuf ); throwWithLocation ( noSocket () ); } { osiSockAddr tmpAddr; osiSocklen_t saddr_length = sizeof ( tmpAddr ); status = getsockname ( this->sock, &tmpAddr.sa, &saddr_length ); if ( status < 0 ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); epicsSocketDestroy ( this->sock ); errlogPrintf ( "CAC: getsockname () error was \"%s\"\n", sockErrBuf ); throwWithLocation ( noSocket () ); } if ( tmpAddr.sa.sa_family != AF_INET) { epicsSocketDestroy ( this->sock ); errlogPrintf ( "CAC: UDP socket was not inet addr family\n" ); throwWithLocation ( noSocket () ); } this->localPort = ntohs ( tmpAddr.ia.sin_port ); } /* * load user and auto configured * broadcast address list */ ELLLIST dest; ellInit ( & dest ); configureChannelAccessAddressList ( & dest, this->sock, this->serverPort ); while ( osiSockAddrNode * pNode = reinterpret_cast < osiSockAddrNode * > ( ellGet ( & dest ) ) ) { SearchDestUDP & searchDest = * new SearchDestUDP ( pNode->addr, *this ); _searchDestList.add ( searchDest ); free ( pNode ); } /* add list of tcp name service addresses */ _searchDestList.add ( searchDestListIn ); caStartRepeaterIfNotInstalled ( this->repeaterPort ); this->pushVersionMsg (); // start timers and receive thread for ( unsigned j =0; j < this->nTimers; j++ ) { this->ppSearchTmr[j]->start ( cacGuard ); } this->govTmr.start (); this->repeaterSubscribeTmr.start (); this->recvThread.start (); }
void func_acq196_SYS_ARMING(void *pArg, double arg1, double arg2) { ST_STD_device* pSTDdev = (ST_STD_device *)pArg; if( (int)arg1 == 1 ) /* in case of arming */ { if( check_dev_arming_condition(pSTDdev) == WR_ERROR) return; /* direct call to sub-device.. for status notify immediately */ // while(pSTDdev) // { if( drvACQ196_openFile(pSTDdev) == WR_ERROR) { printf("\n>>> %s: drvACQ196_openFile() ERROR", pSTDdev->taskName); return ; } pSTDdev->StatusDev &= ~DEV_STORAGE_FINISH; /* 2009. 10. 16 : storage status clear for check end of saving signal...*/ // pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node); // } // pSTDdev = (ST_STD_device*) ellFirst(pMaster->pList_DeviceTask); // while(pSTDdev) // { if( drvACQ196_ARM_enable( pSTDdev ) == WR_ERROR ) { epicsPrintf("\n>>> dev_BO_SYS_ARMING : drvACQ196_ARM_enable... failed\n"); return ; } printf("\"%s\" armed.\n", pSTDdev->taskName ); epicsThreadSleep(TIME_GAP_ARMING); flush_STDdev_to_MDSfetch( pSTDdev ); // scanIoRequest(pSTDdev->ioScanPvt_status); drvACQ196_reset_cnt(pSTDdev); scanIoRequest(pSTDdev->ioScanPvt_userCall); // pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node); // } } else /* release arming condition */ { if( check_dev_release_condition(pSTDdev) == WR_ERROR) return; // while(pSTDdev) // { ST_ACQ196 *pAcq196=NULL; pAcq196 = (ST_ACQ196 *)pSTDdev->pUser; if( pAcq196->fpRaw != NULL ) fclose(pAcq196->fpRaw); pAcq196->fpRaw = NULL; acq196_set_ABORT(pSTDdev); printf("\"%s\" arm disabled.\n", pSTDdev->taskName ); pSTDdev->StatusDev &= ~TASK_ARM_ENABLED; pSTDdev->StatusDev |= TASK_SYSTEM_IDLE; // scanIoRequest(pSTDdev->ioScanPvt_status); // pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node); // } } scanIoRequest(pSTDdev->ioScanPvt_status); }
static void devAdmin_BO_SYS_RESET(ST_execParam *pParam) { ST_ADMIN *pAdminCfg = drvAdmin_get_AdminPtr(); struct dbCommon *precord = pParam->precord; ST_STD_device *pSTDdev = (ST_STD_device*) ellFirst(pAdminCfg->pList_DeviceTask); ST_NI6123_dev *pNI6123 = NULL; if(pParam->setValue) { pAdminCfg->ST_Base.opMode = OPMODE_INIT; pAdminCfg->n8EscapeWhile = 0; while(pSTDdev) { /************************************************* user edit **************************************************/ if(!strcmp(pSTDdev->devType, "NI6123")) { pNI6123 = pSTDdev->pUser; if(pNI6123->taskHandle != 0) { //Remove TG DAQmxTaskControl(pNI6123->taskHandle, DAQmx_Val_Task_Abort); DAQmxStopTask (pNI6123->taskHandle); NI_err_message(DAQmxClearTask(pNI6123->taskHandle)); pNI6123->taskHandle = NULL; if(pNI6123->auto_run_flag == 1) { epicsEventSignal(pSTDdev->epicsEvent_DAQthread); pNI6123->auto_run_flag = 0; } epicsPrintf("Clear Task %s\n", pSTDdev->taskName); } } pSTDdev->StatusDev = TASK_NOT_INIT; pSTDdev->StatusDev = TASK_SYSTEM_IDLE; /************************************************* user edit **************************************************/ pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node); } pAdminCfg->n8EscapeWhile = 1; DBproc_put("SXR_DC_SUPPLY1_CH1_ON", "0"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY1_CH2_ON", "0"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY2_CH1_ON", "0"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY2_CH2_ON", "0"); epicsThreadSleep(2); admin_all_taskStatus_reset(); notify_refresh_admin_status(); scanIoRequest(pAdminCfg->ioScanPvt_status); DBproc_put("SXR_RESET", "0"); epicsPrintf("%s: %s: %d \n", pAdminCfg->taskName, precord->name, pAdminCfg->n8EscapeWhile); } }
int main(int argc,char **argv) { dbMenu *pdbMenu; char *outFilename; char *pext; FILE *outFile; char *plastSlash; int i; int strip; char *path = NULL; char *sub = NULL; int pathLength = 0; int subLength = 0; char **pstr; char *psep; int *len; long status; static char *pathSep = OSI_PATH_LIST_SEPARATOR; static char *subSep = ","; /*Look for options*/ if(argc<2) { fprintf(stderr,"usage: dbToMenu -Idir -Idir file.dbd [outfile]\n"); exit(0); } while((strncmp(argv[1],"-I",2)==0)||(strncmp(argv[1],"-S",2)==0)) { if(strncmp(argv[1],"-I",2)==0) { pstr = &path; psep = pathSep; len = &pathLength; } else { pstr = ⊂ psep = subSep; len = &subLength; } if(strlen(argv[1])==2) { dbCatString(pstr,len,argv[2],psep); strip = 2; } else { dbCatString(pstr,len,argv[1]+2,psep); strip = 1; } argc -= strip; for(i=1; i<argc; i++) argv[i] = argv[i + strip]; } if(argc<2 || (strncmp(argv[1],"-",1)==0)) { fprintf(stderr,"usage: dbToMenu -Idir -Idir file.dbd [outfile]\n"); exit(0); } if (argc==2) { /*remove path so that outFile is created where program is executed*/ plastSlash = strrchr(argv[1],'/'); if(!plastSlash) plastSlash = strrchr(argv[1],'\\'); plastSlash = (plastSlash ? plastSlash+1 : argv[1]); outFilename = dbCalloc(1,strlen(plastSlash)+1); strcpy(outFilename,plastSlash); pext = strstr(outFilename,".dbd"); if (!pext) { fprintf(stderr,"Input file MUST have .dbd extension\n"); exit(-1); } strcpy(pext,".h"); } else { outFilename = dbCalloc(1,strlen(argv[2])+1); strcpy(outFilename,argv[2]); } pdbbase = dbAllocBase(); pdbbase->ignoreMissingMenus = TRUE; status = dbReadDatabase(&pdbbase,argv[1],path,sub); if (status) { errlogFlush(); fprintf(stderr, "dbToMenuH: Input errors, no output generated\n"); exit(1); } outFile = fopen(outFilename, "w"); if (!outFile) { epicsPrintf("Error creating output file \"%s\"\n", outFilename); exit(1); } pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList); while(pdbMenu) { fprintf(outFile,"#ifndef INC%sH\n",pdbMenu->name); fprintf(outFile,"#define INC%sH\n",pdbMenu->name); fprintf(outFile,"typedef enum {\n"); for(i=0; i<pdbMenu->nChoice; i++) { fprintf(outFile,"\t%s",pdbMenu->papChoiceName[i]); if(i < (pdbMenu->nChoice - 1)) fprintf(outFile,","); fprintf(outFile,"\n"); } fprintf(outFile,"}%s;\n",pdbMenu->name); fprintf(outFile,"#endif /*INC%sH*/\n",pdbMenu->name); pdbMenu = (dbMenu *)ellNext(&pdbMenu->node); } fclose(outFile); free((void *)outFilename); return(0); }
static void devAdmin_BO_SYS_ARMING(ST_execParam *pParam) { ST_ADMIN *pAdminCfg = drvAdmin_get_AdminPtr(); struct dbCommon *precord = pParam->precord; ST_STD_device *pSTDdev = (ST_STD_device*) ellFirst(pAdminCfg->pList_DeviceTask); /* ST_NI6123_dev *pNI6123 = NULL; */ char strBuf[24], mkdirbuf[255]; memset(strBuf, 0, sizeof(strBuf)); memset(mkdirbuf, 0, sizeof(mkdirbuf)); /********************************************** user add here modified code. ***********************************************/ if( (int)pParam->setValue == 1 ) /* in case of arming */ { if( admin_check_Arming_condition() == WR_ERROR) return; /* direct call to sub-device.. for status notify immediately */ DBproc_get("SXR_LTU_T0_SEC", strBuf); pAdminCfg->ST_Base.dT0[0] = atof(strBuf); epicsPrintf("Admin ST_Base.dT0 : %f\n", pAdminCfg->ST_Base.dT0[0]); while(pSTDdev) { pSTDdev->StatusDev &= ~TASK_SYSTEM_IDLE; pSTDdev->StatusDev |= TASK_ARM_ENABLED; pSTDdev->ST_Base.dT0[0]= pAdminCfg->ST_Base.dT0[0]; pSTDdev->ST_mds_fetch.dT0[0] = pAdminCfg->ST_Base.dT0[0]; flush_STDdev_to_MDSfetch(pSTDdev); flush_STDdev_to_mdsplus(pSTDdev); pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node); } DBproc_put("SXR_DC_SUPPLY1_CH1_ON", "1"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY1_CH2_ON", "1"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY2_CH1_ON", "1"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY2_CH2_ON", "1"); epicsThreadSleep(2); sprintf(mkdirbuf, "%s%d", STR_LOCAL_DATA_DIR, (int)pAdminCfg->ST_Base.shotNumber); mkdir(mkdirbuf,NULL); } else /* release arming condition */ { if( admin_check_Release_condition() == WR_ERROR) return; while(pSTDdev) { printf("\"%s\" arm disabled.\n", pSTDdev->taskName ); pSTDdev->StatusDev &= ~TASK_ARM_ENABLED; pSTDdev->StatusDev |= TASK_SYSTEM_IDLE; scanIoRequest(pSTDdev->ioScanPvt_status); pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node); } DBproc_put("SXR_DC_SUPPLY1_CH1_ON", "0"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY1_CH2_ON", "0"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY2_CH1_ON", "0"); epicsThreadSleep(2); DBproc_put("SXR_DC_SUPPLY2_CH2_ON", "0"); epicsThreadSleep(2); } notify_refresh_admin_status(); epicsPrintf("%s: %s: %d \n", pAdminCfg->taskName, precord->name, (int)pParam->setValue); }
/* * * req_server() * * CA server task * * Waits for connections at the CA port and spawns a task to * handle each of them * */ static void req_server (void *pParm) { unsigned priorityOfSelf = epicsThreadGetPrioritySelf (); unsigned priorityOfBeacons; epicsThreadBooleanStatus tbs; struct sockaddr_in serverAddr; /* server's address */ osiSocklen_t addrSize; int status; SOCKET clientSock; epicsThreadId tid; int portChange; epicsSignalInstallSigPipeIgnore (); taskwdInsert ( epicsThreadGetIdSelf (), NULL, NULL ); rsrvCurrentClient = epicsThreadPrivateCreate (); if ( envGetConfigParamPtr ( &EPICS_CAS_SERVER_PORT ) ) { ca_server_port = envGetInetPortConfigParam ( &EPICS_CAS_SERVER_PORT, (unsigned short) CA_SERVER_PORT ); } else { ca_server_port = envGetInetPortConfigParam ( &EPICS_CA_SERVER_PORT, (unsigned short) CA_SERVER_PORT ); } if (IOC_sock != 0 && IOC_sock != INVALID_SOCKET) { epicsSocketDestroy ( IOC_sock ); } /* * Open the socket. Use ARPA Internet address format and stream * sockets. Format described in <sys/socket.h>. */ if ( ( IOC_sock = epicsSocketCreate (AF_INET, SOCK_STREAM, 0) ) == INVALID_SOCKET ) { errlogPrintf ("CAS: Socket creation error\n"); epicsThreadSuspendSelf (); } epicsSocketEnableAddressReuseDuringTimeWaitState ( IOC_sock ); /* Zero the sock_addr structure */ memset ( (void *) &serverAddr, 0, sizeof ( serverAddr ) ); serverAddr.sin_family = AF_INET; serverAddr.sin_addr.s_addr = htonl (INADDR_ANY); serverAddr.sin_port = htons ( ca_server_port ); /* get server's Internet address */ status = bind ( IOC_sock, (struct sockaddr *) &serverAddr, sizeof ( serverAddr ) ); if ( status < 0 ) { if ( SOCKERRNO == SOCK_EADDRINUSE ) { /* * enable assignment of a default port * (so the getsockname() call below will * work correctly) */ serverAddr.sin_port = ntohs (0); status = bind ( IOC_sock, (struct sockaddr *) &serverAddr, sizeof ( serverAddr ) ); } if ( status < 0 ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf ( "CAS: Socket bind error was \"%s\"\n", sockErrBuf ); epicsThreadSuspendSelf (); } portChange = 1; } else { portChange = 0; } addrSize = ( osiSocklen_t ) sizeof ( serverAddr ); status = getsockname ( IOC_sock, (struct sockaddr *)&serverAddr, &addrSize); if ( status ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf ( "CAS: getsockname() error %s\n", sockErrBuf ); epicsThreadSuspendSelf (); } ca_server_port = ntohs (serverAddr.sin_port); if ( portChange ) { errlogPrintf ( "cas warning: Configured TCP port was unavailable.\n"); errlogPrintf ( "cas warning: Using dynamically assigned TCP port %hu,\n", ca_server_port ); errlogPrintf ( "cas warning: but now two or more servers share the same UDP port.\n"); errlogPrintf ( "cas warning: Depending on your IP kernel this server may not be\n" ); errlogPrintf ( "cas warning: reachable with UDP unicast (a host's IP in EPICS_CA_ADDR_LIST)\n" ); } /* listen and accept new connections */ if ( listen ( IOC_sock, 20 ) < 0 ) { errlogPrintf ("CAS: Listen error\n"); epicsSocketDestroy (IOC_sock); epicsThreadSuspendSelf (); } tbs = epicsThreadHighestPriorityLevelBelow ( priorityOfSelf, &priorityOfBeacons ); if ( tbs != epicsThreadBooleanStatusSuccess ) { priorityOfBeacons = priorityOfSelf; } beacon_startStopEvent = epicsEventMustCreate(epicsEventEmpty); beacon_ctl = ctlPause; tid = epicsThreadCreate ( "CAS-beacon", priorityOfBeacons, epicsThreadGetStackSize (epicsThreadStackSmall), rsrv_online_notify_task, 0 ); if ( tid == 0 ) { epicsPrintf ( "CAS: unable to start beacon thread\n" ); } epicsEventMustWait(beacon_startStopEvent); epicsEventSignal(castcp_startStopEvent); while (TRUE) { struct sockaddr sockAddr; osiSocklen_t addLen = sizeof(sockAddr); while (castcp_ctl == ctlPause) { epicsThreadSleep(0.1); } clientSock = epicsSocketAccept ( IOC_sock, &sockAddr, &addLen ); if ( clientSock == INVALID_SOCKET ) { char sockErrBuf[64]; epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); errlogPrintf("CAS: Client accept error was \"%s\"\n", sockErrBuf ); epicsThreadSleep(15.0); continue; } else { epicsThreadId id; struct client *pClient; /* socket passed in is closed if unsuccessful here */ pClient = create_tcp_client ( clientSock ); if ( ! pClient ) { epicsThreadSleep ( 15.0 ); continue; } LOCK_CLIENTQ; ellAdd ( &clientQ, &pClient->node ); UNLOCK_CLIENTQ; id = epicsThreadCreate ( "CAS-client", epicsThreadPriorityCAServerLow, epicsThreadGetStackSize ( epicsThreadStackBig ), camsgtask, pClient ); if ( id == 0 ) { LOCK_CLIENTQ; ellDelete ( &clientQ, &pClient->node ); UNLOCK_CLIENTQ; destroy_tcp_client ( pClient ); errlogPrintf ( "CAS: task creation for new client failed\n" ); epicsThreadSleep ( 15.0 ); continue; } } } }
static long devBoAdmin_init_record(boRecord *precord) { ST_devAdmin_dpvt *pdevAdmin_dpvt = (ST_devAdmin_dpvt*) malloc(sizeof(ST_devAdmin_dpvt)); int nval; switch(precord->out.type) { case INST_IO: strcpy(pdevAdmin_dpvt->recordName, precord->name); nval = sscanf(precord->out.value.instio.string, "%s", pdevAdmin_dpvt->arg0); #if PRINT_DEV_SUPPORT_ARG printf("devBoAdmin arg num: %d: %s\n", nval, pdevAdmin_dpvt->arg0); #endif pdevAdmin_dpvt->ptaskConfig = drvAdmin_get_AdminPtr(); if(!pdevAdmin_dpvt->ptaskConfig) { recGblRecordError(S_db_badField, (void*) precord, "devBoAdmin (init_record) Illegal OUT field: task_name"); free(pdevAdmin_dpvt); precord->udf = TRUE; precord->dpvt = NULL; return S_db_badField; } break; default: recGblRecordError(S_db_badField,(void*) precord, "devBoAdmin (init_record) Illegal OUT field"); free(pdevAdmin_dpvt); precord->udf = TRUE; precord->dpvt = NULL; return S_db_badField; } if(!strcmp(pdevAdmin_dpvt->arg0, BO_AUTO_SAVE_STR)) { pdevAdmin_dpvt->ind = BO_AUTO_SAVE; } else if(!strcmp(pdevAdmin_dpvt->arg0, BO_SYS_ARMING_STR)) { pdevAdmin_dpvt->ind = BO_SYS_ARMING; } else if(!strcmp(pdevAdmin_dpvt->arg0, BO_SYS_RUN_STR)) { pdevAdmin_dpvt->ind = BO_SYS_RUN; } else if(!strcmp(pdevAdmin_dpvt->arg0, BO_DATA_SEND_STR)) { pdevAdmin_dpvt->ind = BO_DATA_SEND; } else if(!strcmp(pdevAdmin_dpvt->arg0, BO_SYS_RESET_STR )) { pdevAdmin_dpvt->ind = BO_SYS_RESET; } else if(!strcmp(pdevAdmin_dpvt->arg0, BO_BOARD_SETUP_STR )) { pdevAdmin_dpvt->ind = BO_BOARD_SETUP; } else { pdevAdmin_dpvt->ind = -1; epicsPrintf("ERROR! devBoAdmin_init_record: arg0 \"%s\" \n", pdevAdmin_dpvt->arg0 ); } precord->udf = FALSE; precord->dpvt = (void*) pdevAdmin_dpvt; return 2; /*returns:(0,2)=>(success,success no convert*/ }
/* * create_tcp_client () */ struct client *create_tcp_client ( SOCKET sock ) { int status; struct client *client; int intTrue = TRUE; osiSocklen_t addrSize; unsigned priorityOfEvents; /* socket passed in is destroyed here if unsuccessful */ client = create_client ( sock, IPPROTO_TCP ); if ( ! client ) { return NULL; } /* * see TCP(4P) this seems to make unsolicited single events much * faster. I take care of queue up as load increases. */ status = setsockopt ( sock, IPPROTO_TCP, TCP_NODELAY, (char *) &intTrue, sizeof (intTrue) ); if (status < 0) { errlogPrintf ( "CAS: TCP_NODELAY option set failed\n" ); destroy_client ( client ); return NULL; } /* * turn on KEEPALIVE so if the client crashes * this task will find out and exit */ status = setsockopt ( sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &intTrue, sizeof (intTrue) ); if ( status < 0 ) { errlogPrintf ( "CAS: SO_KEEPALIVE option set failed\n" ); destroy_client ( client ); return NULL; } /* * some concern that vxWorks will run out of mBuf's * if this change is made * * joh 11-10-98 */ #if 0 /* * set TCP buffer sizes to be synergistic * with CA internal buffering */ i = MAX_MSG_SIZE; status = setsockopt ( sock, SOL_SOCKET, SO_SNDBUF, (char *) &i, sizeof (i) ); if (status < 0) { errlogPrintf ( "CAS: SO_SNDBUF set failed\n" ); destroy_client ( client ); return NULL; } i = MAX_MSG_SIZE; status = setsockopt ( sock, SOL_SOCKET, SO_RCVBUF, (char *) &i, sizeof (i) ); if (status < 0) { errlogPrintf ( "CAS: SO_RCVBUF set failed\n" ); destroy_client ( client ); return NULL; } #endif addrSize = sizeof ( client->addr ); status = getpeername ( sock, (struct sockaddr *)&client->addr, &addrSize ); if ( status < 0 ) { epicsPrintf ("CAS: peer address fetch failed\n"); destroy_tcp_client (client); return NULL; } client->evuser = (struct event_user *) db_init_events (); if ( ! client->evuser ) { errlogPrintf ("CAS: unable to init the event facility\n"); destroy_tcp_client (client); return NULL; } status = db_add_extra_labor_event ( client->evuser, rsrv_extra_labor, client ); if (status != DB_EVENT_OK) { errlogPrintf("CAS: unable to setup the event facility\n"); destroy_tcp_client (client); return NULL; } { epicsThreadBooleanStatus tbs; tbs = epicsThreadHighestPriorityLevelBelow ( epicsThreadPriorityCAServerLow, &priorityOfEvents ); if ( tbs != epicsThreadBooleanStatusSuccess ) { priorityOfEvents = epicsThreadPriorityCAServerLow; } } status = db_start_events ( client->evuser, "CAS-event", NULL, NULL, priorityOfEvents ); if ( status != DB_EVENT_OK ) { errlogPrintf ( "CAS: unable to start the event facility\n" ); destroy_tcp_client ( client ); return NULL; } /* * add first version message should it be needed */ rsrv_version_reply ( client ); if ( CASDEBUG > 0 ) { char buf[64]; ipAddrToDottedIP ( &client->addr, buf, sizeof(buf) ); errlogPrintf ( "CAS: conn req from %s\n", buf ); } return client; }
static long devBoAdmin_write_bo(boRecord *precord) { ST_devAdmin_dpvt *pdevAdmin_dpvt = (ST_devAdmin_dpvt*) precord->dpvt; ST_ADMIN *pAdminCfg; ST_threadCfg *pControlThreadConfig; ST_threadQueueData qData; if(!pdevAdmin_dpvt || precord->udf == TRUE) { precord->pact = TRUE; return -1; } pAdminCfg = pdevAdmin_dpvt->ptaskConfig; pControlThreadConfig = pAdminCfg->pST_adminCtrlThread; qData.param.precord = (struct dbCommon *)precord; qData.param.setValue = (double)precord->val; /* db processing: phase I */ if(precord->pact == FALSE) { precord->pact = TRUE; #if PRINT_PHASE_INFO epicsPrintf("db processing: phase I %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pdevAdmin_dpvt->ind) { case BO_AUTO_SAVE: qData.pFunc = devAdmin_BO_AUTO_SAVE; break; case BO_SYS_ARMING: qData.pFunc = devAdmin_BO_SYS_ARMING; break; case BO_SYS_RUN: qData.pFunc = devAdmin_BO_SYS_RUN; break; case BO_DATA_SEND: qData.pFunc = devAdmin_BO_DATA_SEND; break; case BO_SYS_RESET: qData.pFunc = devAdmin_BO_SYS_RESET; break; case BO_BOARD_SETUP: qData.pFunc = devAdmin_BO_BOARD_SETUP; break; default: break; } epicsMessageQueueSend(pControlThreadConfig->threadQueueId, (void*) &qData, sizeof(ST_threadQueueData)); return 0; /*returns: (-1,0)=>(failure,success)*/ } /* db processing: phase II -post processing */ if(precord->pact == TRUE) { #if PRINT_PHASE_INFO epicsPrintf("db processing: phase II %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif precord->pact = FALSE; precord->udf = FALSE; switch(pdevAdmin_dpvt->ind) { case BO_SYS_ARMING: if( pAdminCfg->StatusAdmin & TASK_ARM_ENABLED ) precord->val = 1; else precord->val = 0; break; case BO_SYS_RUN: if( pAdminCfg->StatusAdmin & TASK_DAQ_STARTED) precord->val = 1; else precord->val = 0; break; case BO_DATA_SEND: if( pAdminCfg->StatusAdmin & TASK_DATA_PUT_STORAGE) precord->val = 1; else precord->val = 0; break; default: break; } return 0; /*returns: (-1,0)=>(failure,success)*/ } return -1; }
int epicsShareAPI logAlarmsInit ( ) { DBENTRY dbentry; DBENTRY *pdbentry=&dbentry; long status; int numRecords=0; int tid[MSG_TASK_NUM], btid, ctid, rtid; int normalRangeSize, overRangeSize; struct sockaddr_in *psin; int node; char string[32]; char *pstring, *serverList, *ptok, *pheader; int i; if (initialized) { errlogPrintf ("logAlarmsInit: already initialized\n"); return ERROR; } clkRate = sysClkRateGet(); tickInitWait = (unsigned long)(clkRate * INIT_DELAY_SEC + 0.5); tickMaxSilent = (unsigned long)(clkRate * BEACON_IDLE_SEC + 0.5); tickBeaconPeriod = (unsigned long)(clkRate * BEACON_PERIOD_SEC + 0.5); tickBeaconReplyTmo = (unsigned long)(clkRate * BEACON_REPLY_TMO_SEC + 0.5); tickMessageReplyTmo = (unsigned long)(clkRate * MESSAGE_REPLY_TMO_SEC + 0.5); /* wait time between retrying to send messages (>= 1 tick) */ tickMsgRetryWait = (unsigned long)(clkRate * MESSAGE_RETRY_WAIT_SEC + 0.5); if (tickMsgRetryWait == 0UL) tickMsgRetryWait = 1UL; if(!pdbbase) { errlogPrintf ("logAlarmsInit: No database has been loaded\n"); return ERROR; } serverList = getenv ("EPICS_ALARM_SERVER_INET"); if (!serverList) { errlogPrintf ("logAlarmsInit: EPICS_ALARM_SERVER_INET env not defined\n"); return ERROR; } pstring = getenv ("EPICS_ALARM_MESSAGE_PORT"); if (!pstring) msg_port = DEFAULT_MSG_PORT; else { msg_port = (unsigned short) atoi (pstring); if (msg_port < 1024) { msg_port = DEFAULT_MSG_PORT; errlogPrintf ("Port number EPICS_ALARM_MESSAGE_PORT is wrong\n"); } } pstring = getenv ("EPICS_ALARM_COMMAND_PORT"); if (!pstring) cmd_port = DEFAULT_CMD_PORT; else { cmd_port = (unsigned short) atoi (pstring); if (cmd_port < 1024) { cmd_port = DEFAULT_CMD_PORT; errlogPrintf ("Port number EPICS_ALARM_COMMAND_PORT is wrong\n"); } } /* if allAcceptOption is set, commands are accepted from all servers */ pstring = getenv ("EPICS_ALARM_COMMAND_ACCEPT_ALL"); if (strcmp (pstring, "YES") == 0) allAcceptOption = TRUE; psin = &msgServerAddr[0]; node = 0; ptok = strtok_r (serverList, " ", &pstring); while (ptok && node < SERVERS_MAX && aToIPAddr (ptok, msg_port, psin) == 0) { node++; psin++; ptok = strtok_r (NULL, " ", &pstring); } numServersConfigured = node; if (numServersConfigured == 0) { errlogPrintf ( "logAlarmsInit: No server correctly defined in EPICS_ALARM_SERVER_INET\n"); } wakeupSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY); if (!wakeupSem) { errlogPrintf ("logAlarmsInit: Reader wakeup semaphore could not be created\n"); return ERROR; } bucketSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); if (!bucketSem) { errlogPrintf ("logAlarmsInit: Hash facility mutex could not be created\n"); cleanup (1); return ERROR; } ringSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); if (!ringSem) { errlogPrintf ("logAlarmsInit: Ring r/w mutex could not be created\n"); cleanup (2); return ERROR; } ringWriteSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); if (!ringWriteSem) { errlogPrintf ("logAlarmsInit: Ring (write) mutex could not be created\n"); cleanup (3); return ERROR; } msgSockSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); if (!msgSockSem) { errlogPrintf ("logAlarmsInit: MsgSocket mutex could not be created\n"); cleanup (4); return ERROR; } dbInitEntry(pdbbase,pdbentry); status = dbFirstRecordType(pdbentry); while(!status) { int numRecordsType; numRecordsType = dbGetNRecords(pdbentry); DEBUG2(4,"There are %d records of type %s\n", numRecordsType, dbGetRecordTypeName(pdbentry)) numRecords += numRecordsType; status = dbNextRecordType(pdbentry); } dbFinishEntry(pdbentry); normalRangeSize = (int)(numRecords * RING_NORMAL_MULTI) + 1; overRangeSize = numRecords + numRecords / RING_OVER_DIVI + 1; ringSize = normalRangeSize + overRangeSize; pRingBottom = (msgBuffer_t *)calloc (ringSize, sizeof(msgBuffer_t)); if (!pRingBottom) { errlogPrintf ("logAlarmsInit: Ring buffer could not be created\n"); cleanup (5); return ERROR; } pRingTop = pRingBottom + ringSize; DEBUG2(2,"pRingBottom:%lu pRingTop:%lu\n", (unsigned long)pRingBottom, (unsigned long)pRingTop) ringHighWater = normalRangeSize; DEBUG2(2,"Ring buffer size:%d highwater:%d\n",ringSize,ringHighWater) pRingRead = pRingBottom; pRingWrite = pRingBottom; msgLost = 0; pbuck = bucketCreate (numRecords); if (!pbuck) { errlogPrintf ("logAlarmsInit: Hash table could not be initalized\n"); cleanup (6); return ERROR; } serverSelected = -1; serverSelectedLast = -1; queueAllRecords(); /* spawn alarm beacon task */ btid = taskSpawn ("Al'Beacon", BEACON_TASK_PRIO, BEACON_TASK_OPTIONS, BEACON_TASK_STACK, (FUNCPTR)alarmBeaconTask,0,0,0,0,0,0,0,0,0,0); if (!btid) { errlogPrintf ("logAlarmsInit: Beacon task could not be spawned\n"); cleanup (7); return ERROR; } DEBUG1(1,"alarmBeaconTask started. Task-ID = 0x%x\n", btid); msg_soc = socket (AF_INET, SOCK_DGRAM, 0); if (msg_soc < 0) { errlogPrintf ("Message socket create failed\n"); cleanup (7); return ERROR; } bzero ((char *) &msgReplyInAddr, sockAddrSize); msgReplyInAddr.sin_port = htons(msg_port); msgReplyInAddr.sin_family = AF_INET; msgReplyInAddr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind (msg_soc, (struct sockaddr*)&msgReplyInAddr, sockAddrSize) < 0 ) { errlogPrintf ("Message socket bind failed\n"); cleanup (8); return ERROR; } cmd_soc = socket (AF_INET, SOCK_DGRAM, 0); if (cmd_soc < 0) { errlogPrintf ("Command socket create failed\n"); cleanup (8); return ERROR; } bzero ((char *) &cmdServerAddr, sockAddrSize); cmdServerAddr.sin_port = htons(cmd_port); cmdServerAddr.sin_family = AF_INET; cmdServerAddr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind (cmd_soc, (struct sockaddr*)&cmdServerAddr, sockAddrSize) < 0 ) { errlogPrintf ("Command socket bind failed\n"); cleanup (9); return ERROR; } /* spawn alarm message tasks */ for (i=0; i<MSG_TASK_NUM; i++) { sprintf (string, "Al'Msg%d", i+1); tid[i] = taskSpawn (string, CLIENT_TASK_PRIO, CLIENT_TASK_OPTIONS, CLIENT_TASK_STACK, (FUNCPTR)alarmMessageTask,i+1,0,0,0,0,0,0,0,0,0); if (!tid[i]) { errlogPrintf ( "logAlarmsInit: Message task %d could not be spawned\n"); cleanup (9); while (i > 0) taskDelete (tid[--i]); taskDelete (btid); return ERROR; } } /* spawn alarm log control (command receiver) server task */ ctid = taskSpawn ("Al'Command", CONTROL_TASK_PRIO, CONTROL_TASK_OPTIONS, CONTROL_TASK_STACK, (FUNCPTR)alarmCommandTask,0,0,0,0,0,0,0,0,0,0); if (!ctid) { errlogPrintf ("logAlarmsInit: Control task could not be spawned\n"); cleanup (9); taskDelete (btid); for (i=0; i<MSG_TASK_NUM; i++) taskDelete (tid[i]); return ERROR; } /* spawn message reply receiver task */ rtid = taskSpawn ("Al'ReplyRx", REPLY_TASK_PRIO, REPLY_TASK_OPTIONS, REPLY_TASK_STACK, (FUNCPTR)replyReceiveTask,0,0,0,0,0,0,0,0,0,0); if (!rtid) { errlogPrintf ("logAlarmsInit: Reply receiver task could not be spawned\n"); cleanup (9); taskDelete (btid); taskDelete (ctid); for (i=0; i<MSG_TASK_NUM; i++) taskDelete (tid[i]); return ERROR; } pheader = messageHeader; pstring = getenv ("EPICS_IOC_NAME"); if (pstring) /* given IOC name */ pheader = messageHeader + sprintf (messageHeader, "HOST=%s;", pstring); pheader += sprintf (pheader, "HOST-PHYS=%s;APPLICATION=logAlarms;", gethostname (string, sizeof(string)) ? "TOO_LONG" : string); pstring = getenv ("EPICS_FACILITY"); if (pstring) /* name of application facility */ pheader += sprintf (pheader, "FACILITY=%s;", pstring); /* calculate the remaining space in the message string */ textMsgSize = MAX_MESSAGE_LENGTH - (pheader-messageHeader); epicsPrintf("logAlarms started\n"); recGblAlarmHook = (RECGBL_ALARM_HOOK_ROUTINE)logEvent; DEBUG1(3,"recGblAlarmHook = 0x%lx\n",(unsigned long)recGblAlarmHook) initialized = TRUE; return OK; }
static long devAoAdmin_init_record(aoRecord *precord) { ST_devAdmin_dpvt *pdevAdmin_dpvt = (ST_devAdmin_dpvt*) malloc(sizeof(ST_devAdmin_dpvt)); int nval; switch(precord->out.type) { case INST_IO: strcpy(pdevAdmin_dpvt->recordName, precord->name); nval = sscanf(precord->out.value.instio.string, "%s %s", pdevAdmin_dpvt->arg0, pdevAdmin_dpvt->arg1); #if PRINT_DEV_SUPPORT_ARG printf("devAoAdmin arg num: %d: %s %s\n", nval, pdevAdmin_dpvt->arg0, pdevAdmin_dpvt->arg1); #endif pdevAdmin_dpvt->ptaskConfig = drvAdmin_get_AdminPtr(); if(!pdevAdmin_dpvt->ptaskConfig) { recGblRecordError(S_db_badField, (void*) precord, "devAoAdmin (init_record) Illegal OUT field: task_name"); free(pdevAdmin_dpvt); precord->udf = TRUE; precord->dpvt = NULL; return S_db_badField; } break; default: recGblRecordError(S_db_badField,(void*) precord, "devAoAdmin (init_record) Illegal OUT field"); free(pdevAdmin_dpvt); precord->udf = TRUE; precord->dpvt = NULL; return S_db_badField; } if (!strcmp(pdevAdmin_dpvt->arg0, AO_SHOT_NUMBER_STR)) { pdevAdmin_dpvt->ind = AO_SHOT_NUMBER; } else if (!strcmp(pdevAdmin_dpvt->arg0, AO_OP_MODE_STR)) { pdevAdmin_dpvt->ind = AO_OP_MODE; } else if (!strcmp(pdevAdmin_dpvt->arg0, AO_SET_BLIP_STR)) { pdevAdmin_dpvt->ind = AO_SET_BLIP; } else if (!strcmp(pdevAdmin_dpvt->arg0, AO_CREATE_LOCAL_SHOT_STR)) { pdevAdmin_dpvt->ind = AO_CREATE_LOCAL_SHOT; } else if (!strcmp(pdevAdmin_dpvt->arg0, AO_SAMPLING_RATE_STR)) { pdevAdmin_dpvt->ind = AO_SAMPLING_RATE; } else if (!strcmp(pdevAdmin_dpvt->arg0, AO_START_T0_STR)) { pdevAdmin_dpvt->ind = AO_START_T0; } else if (!strcmp(pdevAdmin_dpvt->arg0, AO_STOP_T1_STR)) { pdevAdmin_dpvt->ind = AO_STOP_T1; } else { pdevAdmin_dpvt->ind = -1; epicsPrintf("ERROR! devAoAdmin_init_record: arg0 \"%s\" \n", pdevAdmin_dpvt->arg0 ); } precord->udf = FALSE; precord->dpvt = (void*) pdevAdmin_dpvt; return 2; /*returns: (0,2)=>(success,success no convert)*/ }
int drvM6802_set_DAQstart(drvM6802_taskConfig *ptaskConfig) { drvM6802_taskConfig *ptaskAll = (drvM6802_taskConfig*) ellFirst(pdrvM6802Config->ptaskList); if( ptaskConfig->taskStatus & TASK_ADC_STARTED ) { epicsPrintf("\n>>> ozStartADC : Already Started!\n"); return ERROR; } ptaskConfig->cnt_DMAcallback=0; dmaToggle = 1; while(ptaskAll) { ozSetArmOut(ptaskAll); /* epicsThreadSleep(0.1); */ ptaskAll = (drvM6802_taskConfig*) ellNext(&ptaskAll->node); } /* epicsPrintf("\n>>> startAcqProcess : taskStatus 0x%X\n", ptaskConfig->taskStatus); */ ozSetTriggerRelease(ptaskConfig); /* epicsThreadSleep(0.1); */ if( ptaskConfig->taskStatus & TASK_INITIALIZED ) { if ( !ozSetADsFIFOrun( ptaskConfig) ) { epicsPrintf("\n>>> ozStartADC : ozSetADsFIFOrun...failed! \n"); return ERROR; } ptaskConfig->taskStatus &= ~TASK_ADC_STOPED; ptaskConfig->taskStatus |= TASK_ADC_STARTED; } else { epicsPrintf("\n>>> ozStartADC : not ready to run! \n"); return ERROR; } #if 0 /* TG.Lee Enable 20081111 */ epicsPrintf("set DaqStart Func Time Register Address TG.Lee\n"); epicsPrintf("ozWriteRegister(MM_CNTRL_REG_1): 0x%X\n", ptaskConfig->register_m6802[MM_CNTRL_REG_1] ); epicsPrintf("ozWriteRegister(MM_CNTRL_REG_2): 0x%X\n", ptaskConfig->register_m6802[MM_CNTRL_REG_2] ); epicsPrintf(">>> MM_PGA_ARRAY_1 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_1] ); epicsPrintf(">>> MM_PGA_ARRAY_2 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_2] ); epicsPrintf(">>> MM_PGA_ARRAY_3 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_3] ); epicsPrintf(">>> MM_PGA_ARRAY_4 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_4] ); epicsPrintf(">>> MM_ADC_HPFE : 0x%X\n", ptaskConfig->register_m6802[MM_ADC_HPFE] ); epicsPrintf(">>> MM_ADC_ZCAL : 0x%X\n", ptaskConfig->register_m6802[MM_ADC_ZCAL] ); #endif return OK; }
static long devAoAdmin_write_ao(aoRecord *precord) { ST_devAdmin_dpvt *pdevAdmin_dpvt = (ST_devAdmin_dpvt*) precord->dpvt; ST_ADMIN *pAdminCfg; ST_threadCfg *pControlThreadConfig; ST_threadQueueData qData; if(!pdevAdmin_dpvt || precord->udf == TRUE) { precord->pact = TRUE; return -1; } pAdminCfg = pdevAdmin_dpvt->ptaskConfig; pControlThreadConfig = pAdminCfg->pST_adminCtrlThread; qData.param.precord = (struct dbCommon *)precord; qData.param.setValue = precord->val; /* db processing: phase I */ if(precord->pact == FALSE) { precord->pact = TRUE; #if PRINT_PHASE_INFO epicsPrintf("db processing: phase I %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif switch(pdevAdmin_dpvt->ind) { case AO_SHOT_NUMBER: qData.pFunc = devAdmin_AO_SHOT_NUMBER; break; case AO_OP_MODE: qData.pFunc = devAdmin_AO_OP_MODE; break; case AO_SET_BLIP: qData.pFunc = devAdmin_AO_SET_BLIP; break; case AO_CREATE_LOCAL_SHOT: qData.pFunc = devAdmin_AO_CREATE_LOCAL_SHOT; break; case AO_SAMPLING_RATE: qData.pFunc = devAdmin_AO_CLOCK; break; case AO_START_T0: qData.pFunc = devAdmin_AO_T0; qData.param.n32Arg0 = strtoul(pdevAdmin_dpvt->arg1, NULL, 0); break; case AO_STOP_T1: qData.pFunc = devAdmin_AO_T1; qData.param.n32Arg0 = strtoul(pdevAdmin_dpvt->arg1, NULL, 0); break; default: break; } epicsMessageQueueSend(pControlThreadConfig->threadQueueId, (void*) &qData, sizeof(ST_threadQueueData)); return 0; /*(0)=>(success ) */ } /* db processing: phase II -post processing */ if(precord->pact == TRUE) { #if PRINT_PHASE_INFO epicsPrintf("db processing: phase II %s (%s)\n", precord->name, epicsThreadGetNameSelf()); #endif precord->pact = FALSE; precord->udf = FALSE; switch(pdevAdmin_dpvt->ind) { case AO_OP_MODE: precord->val = pAdminCfg->ST_Base.opMode; break; default: break; } return 0; /*(0)=>(success ) */ } return -1; }
static void RingThreadFunc(void *param) { int i,j,ss; /* unsigned long long int start, stop,currentCal; uint32 shotNu; */ drvM6802_taskConfig *ptaskConfig = (drvM6802_taskConfig*) param; drvM6802_controlThreadConfig *pringThreadConfig; bufferingThreadQueueData queueData; drvBufferConfig_Node *pbufferNode; while( !ptaskConfig->pringThreadConfig ) epicsThreadSleep(.1); pringThreadConfig = (drvM6802_controlThreadConfig*) ptaskConfig->pringThreadConfig; for(i = 0; i< 30; i++) { drvBufferConfig_Node *pbufferNode = NULL; pbufferNode = (drvBufferConfig_Node*) malloc(sizeof(drvBufferConfig_Node)); if(!pbufferNode) { epicsPrintf("\n>>> malloc(sizeof(drvBufferConfig_Node))... fail\n"); return; } ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node); } epicsPrintf("ellCount: %d <init task launching> \n", ellCount(pdrvBufferConfig->pbufferList) ); epicsPrintf("task launching: %s thread for %s task\n",pringThreadConfig->threadName, ptaskConfig->taskName); i = INIT_CH_MASK; ss = 0; while(TRUE) { epicsMessageQueueReceive(bufferingQueueID, (void*) &queueData, sizeof(bufferingThreadQueueData)); /* epicsThreadSleep(.5); */ #if 0 epicsPrintf(">>> rcv ID: %d, dma cnt: %d, stop: %d\n", bufferingQueueID, queueData.cnt_DMAcallback, queueData.nStop); #endif pbufferNode = queueData.pNode; if(pbufferNode) { if( pbufferNode->nStop ) { /* if( queueData.nStop) { */ /* epicsPrintf(">>> rcv ID: %d, dma cnt: %d, stop: %d\n", bufferingQueueID, queueData.cnt_DMAcallback, queueData.nStop); */ fwrite( &i, 4, 1, fpRaw ); /* number of used channel = whole channel */ fwrite( &dmaSize, 4, 1, fpRaw ); fwrite( &pbufferNode->nCnt, 4, 1, fpRaw ); fclose(fpRaw); fpRaw = NULL; /* nDMAcnt = 0; */ /* epicsPrintf("last ell count before : %d \n", ellCount(pdrvBufferConfig->pbufferList) ); */ ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node); epicsPrintf("ellCount: %d <end> \n", ellCount(pdrvBufferConfig->pbufferList) ); ss = ellCount(pdrvBufferConfig->pbufferList); if(ss<30){ for(j = ss; j <= 29; j++) { ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node); } epicsPrintf("Ell Buffer lack add Complated : ellCnt %d \n", ellCount(pdrvBufferConfig->pbufferList) ); } } else { #if 0 /* TG.Lee Enable 20081111 */ epicsPrintf("RingThreadFunc Time Register Address TG.Lee\n"); epicsPrintf(">>> MM_CNTRL_REG_1 : 0x%X\n", ptaskConfig->register_m6802[MM_CNTRL_REG_1] ); epicsPrintf(">>> MM_CNTRL_REG_2 : 0x%X\n", ptaskConfig->register_m6802[MM_CNTRL_REG_2] ); epicsPrintf(">>> MM_PGA_ARRAY_1 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_1] ); epicsPrintf(">>> MM_PGA_ARRAY_2 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_2] ); epicsPrintf(">>> MM_PGA_ARRAY_3 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_3] ); epicsPrintf(">>> MM_PGA_ARRAY_4 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_4] ); epicsPrintf(">>> MM_ADC_HPFE : 0x%X\n", ptaskConfig->register_m6802[MM_ADC_HPFE] ); epicsPrintf(">>> MM_ADC_ZCAL : 0x%X\n", ptaskConfig->register_m6802[MM_ADC_ZCAL] ); #endif /* epicsPrintf(">>> rcv ID: %d, dma cnt: %d, stop: %d\n", bufferingQueueID, queueData.cnt_DMAcallback, queueData.nStop); */ /* if( nDMAcnt != pbufferNode->nCnt ) epicsPrintf("\n>>> RingThreadFunc : Get Message order error! cnt(%d) \n", pbufferNode->nCnt); */ fwrite( pbufferNode->data, dmaSize, 1, fpRaw ); /* nDMAcnt = queueData.cnt_DMAcallback +1; */ /* epicsPrintf("ell count before : %d \n", ellCount(pdrvBufferConfig->pbufferList) ); */ ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node); epicsPrintf("ellCount :ellCnt %d <first> \n", ellCount(pdrvBufferConfig->pbufferList) ); } /* epicsPrintf("Wait Ring ?? %d \n", ss++); */ /* if (ptaskConfig->eceCalMode) { start = drvM6802_getCurrentUsec(); drvM6802_set_DAQstop(ptaskConfig); epicsThreadSleep(0.1); drvM6802_set_DAQclear(ptaskConfig); epicsThreadSleep(0.1); dataChannelizationAndSendData(ptaskConfig->shotNumber, 3); epicsThreadSleep(0.1); shotNu = ptaskConfig->shotNumber; ptaskConfig->shotNumber = shotNu + 1; epicsPrintf("Local Mode - ECE Calibration => shot Number : %d \n",ptaskConfig->shotNumber); pbufferNode->nStop = 1; epicsThreadSleep(0.1); drvM6802_set_DAQready(ptaskConfig); epicsThreadSleep(0.1); drvM6802_set_DAQstart(ptaskConfig); epicsThreadSleep(0.1); stop = drvM6802_getCurrentUsec(); currentCal = drvM6802_intervalUSec(start, stop); epicsPrintf("\nECE Calibration Cycle time is %lf msec\n", 1.E-3 * (double)currentCal); } */ /* pbufferNode = (drvBufferConfig_Node*) ellNext(&pbufferNode->node); */ } else epicsPrintf("\n>>> RingThreadFunc : no ellFirst node \n"); } return; }
epicsStatus mrmEvgSetupPCI ( const char* id, // Card Identifier int b, // Bus number int d, // Device number int f, // Function number bool ignoreVersion) // Ignore errors due to kernel module and firmware version checks { deviceInfoT deviceInfo; deviceInfo.bus.busType = busType_pci; deviceInfo.bus.pci.bus = b; deviceInfo.bus.pci.device = d; deviceInfo.bus.pci.function = f; deviceInfo.series = series_unknown; try { if (mrf::Object::getObject(id)) { errlogPrintf("ID %s already in use\n", id); return -1; } if(checkUIOVersion(1) > 0) { // check if kernel version is successfully read and is as expected or higher, and if it can be read at all. if(ignoreVersion){ epicsPrintf("Ignoring kernel module error.\n"); } else{ return -1; } } /* Find PCI device from devLib2 */ const epicsPCIDevice *cur = 0; if (devPCIFindBDF(mrmevgs, b, d, f, &cur, 0)) { errlogPrintf("PCI Device not found on %x:%x.%x\n", b, d, f); return -1; } epicsPrintf("Device %s %x:%x.%x\n", id, cur->bus, cur->device, cur->function); epicsPrintf("Using IRQ %u\n", cur->irq); /* MMap BAR0(plx) and BAR2(EVG)*/ volatile epicsUInt8 *BAR_plx, *BAR_evg; // base addressed for plx/evg bars if (devPCIToLocalAddr(cur, 0, (volatile void**) (void *) &BAR_plx, 0) || devPCIToLocalAddr(cur, 2, (volatile void**) (void *) &BAR_evg, 0)) { errlogPrintf("Failed to map BARs 0 and 2\n"); return -1; } if (!BAR_plx || !BAR_evg) { errlogPrintf("BARs mapped to zero? (%08lx,%08lx)\n", (unsigned long) BAR_plx, (unsigned long) BAR_evg); return -1; } //Set LE mode on PLX bridge //TODO: this limits cPCI EVG device support to LE architectures // At this point in time we do not have any BE PCI systems at hand so this is left as // unsported until we HW to test it on... epicsUInt32 plxCtrl = LE_READ32(BAR_plx,LAS0BRD); plxCtrl = plxCtrl & ~LAS0BRD_ENDIAN; LE_WRITE32(BAR_plx,LAS0BRD,plxCtrl); epicsUInt32 version = checkVersion(BAR_evg, 0x3); epicsPrintf("Firmware version: %08x\n", version); if(version == 0) { if(ignoreVersion) { epicsPrintf("Ignoring version error.\n"); } else { return -1; } } evgMrm* evg = new evgMrm(id, deviceInfo, BAR_evg, 0, cur); evg->getSeqRamMgr()->getSeqRam(0)->disable(); evg->getSeqRamMgr()->getSeqRam(1)->disable(); /*Disable the interrupts and enable them at the end of iocInit via initHooks*/ WRITE32(BAR_evg, IrqFlag, READ32(BAR_evg, IrqFlag)); WRITE32(BAR_evg, IrqEnable, 0); /* * Enable active high interrupt1 through the PLX to the PCI bus. */ // LE_WRITE16(BAR_plx, INTCSR, INTCSR_INT1_Enable| INTCSR_INT1_Polarity| INTCSR_PCI_Enable); if(ignoreVersion){ epicsPrintf("Not enabling interrupts.\n"); } else { if(devPCIEnableInterrupt(cur)) { errlogPrintf("Failed to enable interrupt\n"); return -1; } } #ifdef __linux__ evg->isrLinuxPvt = (void*) cur; #endif /*Connect Interrupt handler to isr thread*/ if(ignoreVersion){ epicsPrintf("Not connecting interrupts.\n"); } else { if (devPCIConnectInterrupt(cur, &evgMrm::isr_pci, (void*) evg, 0)) {//devConnectInterruptVME(irqVector & 0xff, &evgMrm::isr, evg)){ errlogPrintf("ERROR:Failed to connect PCI interrupt\n"); delete evg; return -1; } else { epicsPrintf("PCI interrupt connected!\n"); } } } catch (std::exception& e) { errlogPrintf("Error: %s\n", e.what()); errlogFlush(); return -1; } return 0; } //mrmEvgSetupPCI