Esempio n. 1
0
static void
setThreadInfo (rtems_id tid, const char *name, EPICSTHREADFUNC funptr,void *parm)
{
    struct taskVar *v;
    uint32_t note;
    rtems_status_code sc;

    v = mallocMustSucceed (sizeof *v, "epicsThreadCreate_vars");
    v->name = epicsStrDup(name);
    v->id = tid;
    v->funptr = funptr;
    v->parm = parm;
    v->threadVariableCapacity = 0;
    v->threadVariables = NULL;
    note = (uint32_t)v;
    rtems_task_set_note (tid, RTEMS_NOTEPAD_TASKVAR, note);
    taskVarLock ();
    v->forw = taskVarHead;
    v->back = NULL;
    if (v->forw)
        v->forw->back = v;
    taskVarHead = v;
    taskVarUnlock ();
    if (funptr) {
        sc = rtems_task_start (tid, threadWrapper, (rtems_task_argument)v);
        if (sc !=  RTEMS_SUCCESSFUL)
            errlogPrintf ("setThreadInfo:  Can't start  %s: %s\n",name, rtems_status_text (sc));
    }
}
Esempio n. 2
0
int ipmIntConnect (
	int carrier, 
	int slot, 
	int vecNum, 
	void (*routine)(int parameter), 
	int parameter
) {
    if (carrier < 0 ||
	carrier >= carriers.number ||
	slot < 0 ||
	vecNum < 0 ||
	vecNum > 0xff) {
	return S_IPAC_badAddress;
    }

    /* If the carrier driver doesn't provide a suitable routine... */
    if (carriers.info[carrier].driver->intConnect == NULL) {
#ifdef vxWorks
	/* We know casting int <--> void* works */
	return devConnectInterrupt(intVME, vecNum, (void (*)(void *))routine,
				      (void *)parameter);
#else
	struct intData *pisr = (struct intData *) mallocMustSucceed(
		sizeof(struct intData), "ipmIntConnect");
	pisr->routine = routine;
	pisr->parameter = parameter;
	return devConnectInterrupt(intVME, vecNum, intShim, (void *)pisr);
#endif
    }

    return carriers.info[carrier].driver->intConnect(
		carriers.info[carrier].cPrivate, slot, vecNum, 
		routine, parameter);
}
/// expand epics environment strings using previously saved environment  
/// based on EPICS macEnvExpand()
char* lvDCOMInterface::envExpand(const char *str)
{
    long destCapacity = 128;
    char *dest = NULL;
    int n;
    do {
        destCapacity *= 2;
        /*
         * Use free/malloc rather than realloc since there's no need to
         * keep the original contents.
         */
        free(dest);
        dest = static_cast<char*>(mallocMustSucceed(destCapacity, "lvDCOMInterface::envExpand"));
        n = macExpandString(m_mac_env, str, dest, destCapacity);
    } while (n >= (destCapacity - 1));
    if (n < 0) {
        free(dest);
        dest = NULL;
    } else {
        size_t unused = destCapacity - ++n;

        if (unused >= 20)
            dest = static_cast<char*>(realloc(dest, n));
    }
    return dest;
}
Esempio n. 4
0
/*
 * Set the value of an environment variable
 * Leaks memory, but the assumption is that this routine won't be
 * called often enough for the leak to be a problem.
 */
epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *value)
{
    char *cp;

	cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet");
	strcpy (cp, name);
	strcat (cp, "=");
	strcat (cp, value);
	if (putenv (cp) < 0) {
		errPrintf(
                -1L,
                __FILE__,
                __LINE__,
                "Failed to set environment parameter \"%s\" to \"%s\": %s\n",
                name,
                value,
                strerror (errno));
        free (cp);
	}
}
Esempio n. 5
0
static asynStatus parseLink(asynUser *pasynUser, DBLINK *plink,
                            char **port, int *addr, char **userParam)
{
    struct vmeio *pvmeio;
    struct instio *pinstio;
    size_t len;
    char *p;
    char *endp;
    char *pnext;

    assert(addr && port && userParam);
    *addr=0;
    *port=NULL;
    *userParam=NULL;
    switch (plink->type) {
    case VME_IO:
        pvmeio=(struct vmeio*)&(plink->value);
        *addr = pvmeio->signal;
        p = pvmeio->parm;
        p = skipWhite(p,0);
        for(len=0; *p && !isspace((int)*p) && *p!=','  ; len++, p++) {}
        /* first field of parm is always the asyn port name */
        if(len==0) {
            epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                          "parm is null. Must be <port> <addr> ...");
            return(asynError);
        }
        *port = mallocMustSucceed(len+1,"asynEpicsUtils:parseLink");
        (*port)[len] = 0;
        strncpy(*port,pvmeio->parm,len);
        *userParam = 0; /*initialize to null string*/
        if(*p) {
            p = skipWhite(p,0);
            if(*p) {
                len = strlen(p);
                *userParam = mallocMustSucceed(len+1,"asynEpicsUtils:parseLink");
                strncpy(*userParam,p,len);
                (*userParam)[len] = 0;
            }
        }
        break;
    case INST_IO:
        pinstio=(struct instio*)&(plink->value);
        p = pinstio->string;
        pnext = strstr(p,"asyn(");
        if(!pnext) goto error;
        pnext+=5;
        pnext = skipWhite(pnext,0);
        p = pnext;
        for(len=0; *p && !isspace((int)*p) && (*p!=',') && (*p!=')')  ; len++, p++) {}
        if(*p==0) goto error;
        *port = mallocMustSucceed(len+1,"asynEpicsUtils:parseLink");
        (*port)[len] = 0;
        strncpy(*port,pnext,len);
        /*next is addr*/
        pnext = p;
        pnext = skipWhite(pnext,1);
        if(*pnext==0) goto error;
        if(*pnext==')') {
            *addr = 0;
            pasynUser->timeout = 1.0;
            goto userParams;
        }
        errno = 0;
        *addr = strtol(pnext,&endp,0);
        if(errno) goto error;
        /*next is timeout*/
        pnext = endp;
        pnext = skipWhite(pnext,1);
        if(*pnext==0) goto error;
        if(*pnext==')') {
            pasynUser->timeout = 1.0;
            goto userParams;
        }
        errno = 0;
        pasynUser->timeout = strtod(pnext,&endp);
        if(errno) goto error;
        pnext = endp;
        pnext = skipWhite(pnext,0);
        if(*pnext!=')') goto error;
userParams:
        if(userParam) *userParam = 0; /*initialize to null string*/
        pnext++; /*skip over )*/
        p = pnext;
        if(*p) {
            p = skipWhite(p,0);
            if(userParam&& *p) {
                len = strlen(p);
                *userParam = mallocMustSucceed(len+1,"asynEpicsUtils:parseLink");
                strncpy(*userParam,p,len);
                (*userParam)[len] = 0;
            }
        }
        break;
error:
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                      "invalid INST_IO Must be asyn(<port> <addr> <timeout>)userParams");
        return(asynError);
    default:
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                      "Link must be INST_IO or VME_IO");
        return(asynError);
    }
    return(asynSuccess);
}
Esempio n. 6
0
static asynStatus parseLinkMask(asynUser *pasynUser, DBLINK *plink,
                                char **port, int *addr, epicsUInt32 *mask,char **userParam)
{
    struct instio *pinstio;
    size_t len;
    char *p;
    char *endp;
    char *pnext;

    assert(addr && port && userParam);
    *addr=0;
    *port=NULL;
    *userParam=NULL;
    if(plink->type!=INST_IO) {
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                      "Link must be INST_IO");
        return(asynError);
    }
    pinstio=(struct instio*)&(plink->value);
    p = pinstio->string;
    pnext = strstr(p,"asynMask(");
    if(!pnext) goto error;
    pnext+=9;
    pnext = skipWhite(pnext,0);
    p = pnext;
    for(len=0; *p && !isspace((int)*p) && (*p!=',') && (*p!=')')  ; len++, p++) {}
    if(*p==0) goto error;
    *port = mallocMustSucceed(len+1,"asynEpicsUtils:parseLink");
    (*port)[len] = 0;
    strncpy(*port,pnext,len);
    /*next is addr*/
    pnext = p;
    pnext = skipWhite(pnext,1);
    if(*pnext==0 || *pnext==')') goto error;
    errno = 0;
    *addr = strtol(pnext,&endp,0);
    if(errno) goto error;
    /*next is mask*/
    pnext = endp;
    pnext = skipWhite(pnext,1);
    if(*pnext==0 || *pnext==')') goto error;
    errno = 0;
    *mask = strtoul(pnext,&endp,0);
    if(errno) goto error;
    /*next is timeout*/
    pnext = endp;
    pnext = skipWhite(pnext,1);
    if(*pnext==0) goto error;
    if(*pnext==')') {
        pasynUser->timeout = 1.0;
        goto userParams;
    }
    errno = 0;
    pasynUser->timeout = strtod(pnext,&endp);
    if(errno) goto error;
    pnext = endp;
    pnext = skipWhite(pnext,0);
    if(*pnext!=')') goto error;
userParams:
    if(userParam) *userParam = 0; /*initialize to null string*/
    pnext++; /*skip over )*/
    p = pnext;
    if(*p) {
        p = skipWhite(p,0);
        if(userParam&& *p) {
            len = strlen(p);
            *userParam = mallocMustSucceed(len+1,"asynEpicsUtils:parseLink");
            strncpy(*userParam,p,len);
            (*userParam)[len] = 0;
        }
    }
    return(asynSuccess);
error:
    epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                  "invalid INST_IO Must be asynMask(<port> <addr> <mask> <timeout>)userParams");
    return(asynError);
}