Exemplo n.º 1
0
static void *getLastTemp(void)
{
    tempListNode	*ptempListNode;

    ptempListNode = (tempListNode *)ellLast(&tempList);
    return(ptempListNode->item);
}
Exemplo n.º 2
0
static msgNode *msgbufGetNode(void)
{
    char *pbuffer = pvtData.pbuffer;
    char *pnextFree;
    msgNode *pnextSend;

    if (ellCount(&pvtData.msgQueue) == 0 ) {
        pnextFree = pbuffer;        /* Reset if empty */
    }
    else {
        msgNode *pfirst = (msgNode *)ellFirst(&pvtData.msgQueue);
        msgNode *plast = (msgNode *)ellLast(&pvtData.msgQueue);
        char *plimit = pbuffer + pvtData.buffersize;

        pnextFree = plast->message + adjustToWorstCaseAlignment(plast->length);
        if (pfirst > plast) {
            plimit = (char *)pfirst;
        }
        else if (pnextFree + pvtData.msgNeeded > plimit) {
            pnextFree = pbuffer;    /* Hit end, wrap to start */
            plimit = (char *)pfirst;
        }
        if (pnextFree + pvtData.msgNeeded > plimit) {
            return 0;               /* No room */
        }
    }

    pnextSend = (msgNode *)pnextFree;
    pnextSend->message = pnextFree + sizeof(msgNode);
    pnextSend->length = 0;
    return pnextSend;
}
Exemplo n.º 3
0
static void epicsExitCallAtExitsPvt(exitPvt *pep)
{
    exitNode *pexitNode;
    while ( ( pexitNode = (exitNode *) ellLast ( & pep->list ) ) ) {
        pexitNode->func ( pexitNode->arg );
        ellDelete ( & pep->list, & pexitNode->node );
        free ( pexitNode );
    }
}
Exemplo n.º 4
0
static void epicsExitCallAtExitsPvt(exitPvt *pep)
{
    exitNode *pexitNode;

    while ( ( pexitNode = (exitNode *) ellLast ( & pep->list ) ) ) {
        if (atExitDebug && pexitNode->name[0])
            fprintf(stderr, "atExit %s(%p)\n", pexitNode->name, pexitNode->arg);
        else if(atExitDebug)
            fprintf(stderr, "atExit %p(%p)\n", pexitNode->func, pexitNode->arg);
        pexitNode->func ( pexitNode->arg );
        ellDelete ( & pep->list, & pexitNode->node );
        free ( pexitNode );
    }
}
Exemplo n.º 5
0
static int db_yyinput(char *buf, int max_size)
{
    int		l,n;
    char	*fgetsRtn;
    
    if(yyAbort) return(0);
    if(*my_buffer_ptr==0) {
	while(TRUE) { /*until we get some input*/
	    if(macHandle) {
		fgetsRtn = fgets(mac_input_buffer,MY_BUFFER_SIZE,
			pinputFileNow->fp);
		if(fgetsRtn) {
		    n = macExpandString(macHandle,mac_input_buffer,
			my_buffer,MY_BUFFER_SIZE);
		    if(n<0) {
			errPrintf(0,__FILE__, __LINE__,
			"macExpandString failed for file %s",
			pinputFileNow->filename);
		    }
		}
	    } else {
		fgetsRtn = fgets(my_buffer,MY_BUFFER_SIZE,pinputFileNow->fp);
	    }
	    if(fgetsRtn) break;
	    if(fclose(pinputFileNow->fp)) 
		errPrintf(0,__FILE__, __LINE__,
			"Closing file %s",pinputFileNow->filename);
	    free((void *)pinputFileNow->filename);
	    ellDelete(&inputFileList,(ELLNODE *)pinputFileNow);
	    free((void *)pinputFileNow);
	    pinputFileNow = (inputFile *)ellLast(&inputFileList);
	    if(!pinputFileNow) return(0);
	}
	if(dbStaticDebug) fprintf(stderr,"%s",my_buffer);
	pinputFileNow->line_num++;
	my_buffer_ptr = &my_buffer[0];
    }
    l = strlen(my_buffer_ptr);
    n = (l<=max_size ? l : max_size);
    memcpy(buf,my_buffer_ptr,n);
    my_buffer_ptr += n;
    return(n);
}
Exemplo n.º 6
0
static int Is_All_Slave_DAQ_STOPED()
{
	int cnt = 0;
	int brd_cnt=0;
	ST_MASTER *pMaster = get_master();
	ST_STD_device*pSTDdev = (ST_STD_device*) ellLast(pMaster->pList_DeviceTask);
	while(pSTDdev) {
		if( drvACQ196_is_Master(pSTDdev) == WR_ERROR ) 
		{
			if( !(pSTDdev->StatusDev & TASK_IN_PROGRESS) ) {
/*				printf("%s daq stoped!\n", pSTDdev->taskName ); */
				cnt++;
			}
			brd_cnt++;
/*			printf("cnt: %d, brd_cnt: %d\n", cnt, brd_cnt); */
		}
		
		pSTDdev = (ST_STD_device*) ellPrevious(&pSTDdev->node);
	}

	if( cnt == brd_cnt ) return WR_OK; /* 1*/

	return WR_ERROR; /* 0 */
}
Exemplo n.º 7
0
LOCAL long drvM6802_init_driver(void)
{
	drvM6802_taskConfig *ptaskConfig = NULL;
/*	drvM6802_taskConfig *ptaskConfigNext = NULL; */
	drvM6802_channelConfig *pchannelConfig = NULL;
	FILE *fp;
	int temp=0;

	unsigned long long int a;

	if(!pdrvM6802Config)  return 0;

	fp = fopen(FILE_NAME_RAWDATA, "wb");
	if( fp != NULL ) {
		fwrite( &temp, 4, 1, fp);
		fclose(fp);
	}


	ptaskConfig = (drvM6802_taskConfig*) ellFirst(pdrvM6802Config->ptaskList);
	while(ptaskConfig) 
	{
		if(ellCount(ptaskConfig->pchannelConfig)) 
		{

			initDAQboard(ptaskConfig);

			pchannelConfig = (drvM6802_channelConfig*) ellFirst(ptaskConfig->pchannelConfig);
			while(pchannelConfig) {
				init_channelGain(pchannelConfig);
				pchannelConfig = (drvM6802_channelConfig*) ellNext(&pchannelConfig->node);
			}

		} 

		ptaskConfig = (drvM6802_taskConfig*) ellNext(&ptaskConfig->node);
	} /* while(ptaskConfig) { */
/*
	ptaskConfig = (drvM6802_taskConfig*) ellFirst(pdrvM6802Config->ptaskList);
	while(ptaskConfig) 
	{	
		ptaskConfigNext = (drvM6802_taskConfig*) ellNext(&ptaskConfig->node);
		if( !ptaskConfigNext ) {
			ozSetTermEnable(ptaskConfig);
			epicsPrintf("\n>>> drvM6802_init_driver : Board %d : Termination Enabled\n", ptaskConfig->BoardID );
			break;
		}
		else ptaskConfig = ptaskConfigNext;
	}
*/
	ptaskConfig = (drvM6802_taskConfig*) ellLast(pdrvM6802Config->ptaskList);
	if(ptaskConfig) 
	{
		ozSetTermEnable(ptaskConfig);
		epicsPrintf("\n>>> drvM6802_init_driver : Board %d : Termination Enabled\n", ptaskConfig->BoardID );
	} else 
		epicsPrintf("\n>>> drvM6802_init_driver : Board %d : Termination Error!\n", ptaskConfig->BoardID );


	epicsAtExit((EPICSEXITFUNC) clearAllOzTasks, NULL);

	a = drvM6802_getCurrentUsec();
	epicsThreadSleep(1.);
	pdrvM6802Config->one_sec_interval = drvM6802_getCurrentUsec() - a;

	epicsPrintf("drvM6802: measured one second time is %lf msec\n", 1.E-3 * (double)pdrvM6802Config->one_sec_interval);



	return 0;
}
Exemplo n.º 8
0
static
int linuxDevPCIInit(void)
{

    DIR* sysfsPci_dir=NULL;
    struct dirent* dir;
    int i;
    osdPCIDevice *osd=NULL;
    pciLock = epicsMutexMustCreate();
    int host_is_first = 0;

    pagesize=sysconf(_SC_PAGESIZE);
    if (pagesize==-1) {
        perror("Failed to get pagesize");
        goto fail;
    }

    sysfsPci_dir = opendir("/sys/bus/pci/devices");
    if (!sysfsPci_dir){
        fprintf(stderr, "Could not open /sys/bus/pci/devices!\n");
    	goto fail;
    }

    while ((dir=readdir(sysfsPci_dir))) {
        char* filename;
        FILE* file;
        int fail=0;
        int match;
        unsigned long long int start,stop,flags;
        char dname[80];

    	if (!dir->d_name || dir->d_name[0]=='.') continue; /* Skip invalid entries */

        osd=calloc(1, sizeof(osdPCIDevice));
        if (!osd) {
            errMessage(S_dev_noMemory, "Out of memory");
            goto fail;
        }
        osd->fd=-1;
        osd->cfd = -1;
        for ( i=0; i<sizeof(osd->rfd)/sizeof(osd->rfd[0]); i++ )
            osd->rfd[i] = -1;

        osd->dev.slot = DEVPCI_NO_SLOT;

        match = sscanf(dir->d_name,"%x:%x:%x.%x",
                       &osd->dev.domain,&osd->dev.bus,&osd->dev.device,&osd->dev.function);
        if (match != 4){
            fprintf(stderr, "Could not decode PCI device directory %s\n", dir->d_name);
        }
 
        osd->dev.id.vendor=read_sysfs(&fail, BUSBASE "vendor",
                             osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        osd->dev.id.device=read_sysfs(&fail, BUSBASE "device",
                             osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        osd->dev.id.sub_vendor=read_sysfs(&fail, BUSBASE "subsystem_vendor",
                             osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        osd->dev.id.sub_device=read_sysfs(&fail, BUSBASE "subsystem_device",
                             osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        osd->dev.id.pci_class=read_sysfs(&fail, BUSBASE "class",
                             osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        osd->dev.irq=read_sysfs(&fail, BUSBASE "irq",
                             osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        osd->dev.id.revision=0;

        if (fail) {
            fprintf(stderr, "Warning: Failed to read some attributes of PCI device %04x:%02x:%02x.%x\n"
                         "         This may cause some searches to fail\n",
                         osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
            fail=0;
        }

        if(devPCIDebug>=1) {
            fprintf(stderr, "linuxDevPCIInit found %04x:%02x:%02x.%x\n",
                         osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
            fprintf(stderr, " as pri %04x:%04x sub %04x:%04x cls %06x\n",
                         osd->dev.id.vendor, osd->dev.id.device,
                         osd->dev.id.sub_vendor, osd->dev.id.sub_device,
                         osd->dev.id.pci_class);
        }

        /* Read BAR info */

        /* Base address */
        
        filename = allocPrintf(BUSBASE "resource",
                         osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        if (!filename) {
            errMessage(S_dev_noMemory, "Out of memory");
            goto fail;
        }
        file=fopen(filename, "r");
        if (!file) {
            fprintf(stderr, "Could not open resource file %s!\n", filename);
            free(filename);
            continue;
        }
        for (i=0; i<PCIBARCOUNT; i++) { /* read 6 BARs */
            match = fscanf(file, "0x%16llx 0x%16llx 0x%16llx\n", &start, &stop, &flags);
        
            if (match != 3) {
                fprintf(stderr, "Could not parse line %i of %s\n", i+1, filename);
                continue;
            }

            osd->dev.bar[i].ioport = (flags & PCI_BASE_ADDRESS_SPACE)==PCI_BASE_ADDRESS_SPACE_IO;
            osd->dev.bar[i].below1M = !!(flags&PCI_BASE_ADDRESS_MEM_TYPE_1M);
            osd->dev.bar[i].addr64 = !!(flags&PCI_BASE_ADDRESS_MEM_TYPE_64);
            osd->displayBAR[i] = start;

            /* offset from start of page to start of BAR */
            osd->offset[i] = osd->displayBAR[i]&(pagesize-1);
            /* region length */
            osd->len[i] = (start || stop ) ? (stop - start + 1) : 0;
        }
        /* rom */
        match = fscanf(file, "%llx %llx %llx\n", &start, &stop, &flags);
        if (match != 3) {
            fprintf(stderr, "Could not parse line %i of %s\n", i+1, filename);
            start = 0;
            stop = 0;
        }

        osd->displayErom = start;
        osd->eromlen = (start || stop ) ? (stop - start + 1) : 0;
        
        fclose(file);
        free(filename);
        
        /* driver name */
        filename = allocPrintf(BUSBASE "driver",
                         osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function);
        if (!filename) {
            errMessage(S_dev_noMemory, "Out of memory");
            goto fail;
        }
        memset (dname, 0, sizeof(dname));
        if (readlink(filename, dname, sizeof(dname)-1) != -1)
            osd->dev.driver = epicsStrDup(basename(dname));
        free(filename);

        osd->devLock = epicsMutexMustCreate();

        if (!ellCount(&devices))
        {
            host_is_first = (osd->dev.bus == 0 && osd->dev.device == 0);
        }
        ellInsert(&devices,host_is_first?ellLast(&devices):NULL,&osd->node);
        osd=NULL;
    }
    if (sysfsPci_dir)
        closedir(sysfsPci_dir);

    sysfsPci_dir = opendir(linuxslotsdir);
    if (sysfsPci_dir){
        while ((dir=readdir(sysfsPci_dir))) {
            unsigned dom, B, D;
            char *fullname;
            FILE *fp;

            if (!dir->d_name || dir->d_name[0]=='.') continue; /* Skip invalid entries */
            if(devPCIDebug>4)
                fprintf(stderr, "examine /slots entry '%s'\n", dir->d_name);

            fullname = allocPrintf("%s/%s/address", linuxslotsdir, dir->d_name);
            if(!fullname) continue;

            if(devPCIDebug>3)
                fprintf(stderr, "found '%s'\n", fullname);

            if((fp=fopen(fullname, "r"))!=NULL) {

                if(fscanf(fp, "%x:%x:%x", &dom, &B, &D)==3) {
                    ELLNODE *cur;
                    if(devPCIDebug>2)
                        fprintf(stderr, "found slot %s with %04u:%02u:%02u.*\n", dir->d_name, dom, B, D);

                    for(cur=ellFirst(&devices); cur; cur=ellNext(cur)) {
                        osdPCIDevice *osd = CONTAINER(cur, osdPCIDevice, node);
                        if(osd->dev.domain!=dom || osd->dev.bus!=B || osd->dev.device!=D)
                            continue;
                        if(osd->dev.slot==DEVPCI_NO_SLOT) {
                            osd->dev.slot = strdup(dir->d_name); // return NULL would mean slot remains unlabeled
                        } else {
                            fprintf(stderr, "Duplicate slot address for %s\n", dir->d_name);
                        }
                    }
                }

                fclose(fp);
            }
            free(fullname);
        }
        closedir(sysfsPci_dir);
    } else if(devPCIDebug>0) {
        fprintf(stderr, "/sys does not provide PCI slots listing\n");
    }


    return 0;
fail:
    if (sysfsPci_dir)
        closedir(sysfsPci_dir);
    epicsMutexDestroy(pciLock);
    return S_dev_badInit;
}