⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trglib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* set all the trigger parameters */    trgId->eventId = event;    trgId->conditional = conditional;    if (conditional == 1)        {        trgId->condType = condType;        /* FIXME: I think this should just be a pointer and not an union           I am not changing it right now, since I do not want to make           too many changes at the same time         */        switch (condType)	    {	    case TRIGGER_COND_VAR:                trgId->condEx1 = condEx1;	        break;	    case TRIGGER_COND_FUNC:                trgId->condEx1 = condEx1;	        break;            case TRIGGER_COND_LIB:                trgId->condEx1 = condEx1;	        break;	    }        trgId->condOp = condOp;        trgId->condEx2 = condEx2;        }    else        {        trgId->condType = -1;        trgId->condEx1 = (void *)(-1);        trgId->condOp = -1;        trgId->condEx2 = -1;        }    trgId->objId = objId;    trgId->contextType = contextType;    trgId->contextId = contextId;     trgId->disable = disable;    trgId->chain = chain;    trgId->actionType = actionType;    trgId->actionDef = actionDef;    trgId->actionFunc = actionFunc;    trgId->actionArg = actionArg;    trgId->status = status;    trgId->hitCnt = 0;    trgId->next = NULL;    if ( actionDef  && !trgActionDefStarted ) 	trgActionDefStart();    if ( status == TRG_ENABLE )        trgCnt++;    index = trgEvtToIndex(event);    TRG_EVTCLASS_SET(trgClassList[index]);#if 0	printf ("index is %d, class is %x\n", index , trgClassList[index]);	printf ("pTrg NULL: trList[%d] is %p\n", index , trgList[index]);#endif    pTrg = trgList[index];    /* add the trigger to the list */   if (trgList[index] == NULL)       {       trgList[index] = trgId;       }   else       {       while (pTrg->next != NULL)           pTrg = pTrg->next;       pTrg->next = trgId;       }    return(trgId);    }/********************************************************************************* trgDelete - delete a trigger from the trigger list** This routine deletes a trigger by removing it from the trigger list.  It* also checks that no other triggers are still active.  If there are no* active triggers and triggering is still on, it turns triggering off.** RETURNS: OK, or ERROR if the trigger is not found.** SEE ALSO: trgAdd()*/STATUS trgDelete    (    TRIGGER_ID trgId    )    {    int index;    TRIGGER_ID  pTrg;    /* if the id is NULL, exit */    if (trgId == NULL)	return(ERROR);    /* Verify the trigger exists */    if (OBJ_VERIFY (trgId, trgClassId) != OK) {        return(ERROR);    }    /* if the trigger was still enabled then decrease the counter      * and if the counter goes to zero, then turn the instrumentation off     */    if ( (trgId->status == TRG_ENABLE) && (--trgCnt == 0))            trgOff();    objCoreTerminate(&trgId->objCore);    /* first, let's find the list where the trigger should be */    index = trgEvtToIndex(trgId->eventId);    pTrg = trgList[index];    /* if it is empty, then there is some mistake: where did the trigger go? */    if (pTrg == NULL)        return (ERROR);    if (pTrg == trgId)	{    	pTrg = pTrg->next;	trgId->next = NULL;	objFree(trgClassId, (char *)trgId);        trgList[index] = pTrg;	/* if this is the last in the list we should also reset 	 * the trgEvtClass 	 */	if (pTrg == NULL)	    {	    TRG_EVTCLASS_UNSET(trgClassList[index]);            if ( TRG_EVTCLASS_IS_SET (CLASS_NONE) )                trgOff();	    }	return(OK);	}    while (pTrg->next != NULL)        {        if ( pTrg->next != trgId)            pTrg = pTrg->next;        else            break;           }    /* if it is not NULL, then it is the one we are looking for */    if (pTrg->next != NULL)        {        pTrg->next = pTrg->next->next;	trgId->next = NULL;	objFree(trgClassId, (char *)trgId);	return(OK);        }     return(ERROR); /* if we are here, then we did not found it! */    }/********************************************************************************* trgOn - set triggering on** This routine activates triggering.  From this time on, any time an event* point is hit, a check for the presence of possible triggers is performed.* Start triggering only when needed since some overhead is introduced.** NOTE* If trgOn() is called when there are no triggers in the trigger list, it* immediately sets triggering off again.  If trgOn() is called with at least* one trigger in the list, triggering begins.  Triggers should not be * added to the list while triggering is on since this can create* instability.** RETURNS: OK or ERROR.** SEE ALSO: trgOff()*/STATUS trgOn (void)    {    int level;     if ( (! TRG_ACTION_IS_SET) &&  (! TRG_EVTCLASS_IS_EMPTY) )        {        if ((!trgLibInstalled) && (trgLibInit () != OK))            return (ERROR);                                 level = intLock();	TRG_ACTION_SET;        intUnlock(level);	return (OK);	}    return (ERROR);    }/********************************************************************************* trgOff - set triggering off** This routine turns triggering off. From this time on, when an event point * is hit, no search on triggers is performed.** RETURNS: N/A** SEE ALSO: trgOn()*/void trgOff (void)    {    int level;    if (TRG_ACTION_IS_SET)	{        level = intLock();        /* reset the variable */        TRG_ACTION_UNSET;        intUnlock(level);	}    }/********************************************************************************* trgEnable - enable a trigger** This routine enables a trigger that has been created with trgAdd(). A counter* is incremented to keep track of the total number of enabled triggers so that * trgDisable() knows when to set triggering off. If the maximum number of * enabled triggers is reached, an error is returned. ** RETURNS: OK, or ERROR if the trigger ID is not found or if the maximum* number of triggers has already been enabled.** SEE ALSO: trgDisable()*/STATUS trgEnable    (    TRIGGER_ID trgId    )    {    if (trgId == NULL)        return(ERROR);    if ( trgId->status != TRG_ENABLE )	{        trgCnt++;        trgId->status = TRG_ENABLE;	}    return(OK);    }/********************************************************************************* trgDisable - turn a trigger off** This routine disables a trigger. It also checks to see if there are triggers* still active.  If this is the last active trigger it sets triggering off.** RETURNS: OK, or ERROR if the trigger ID is not found.** SEE ALSO: trgEnable()*/STATUS trgDisable    (    TRIGGER_ID trgId    )    {    int level;    if (trgId == NULL)        return(ERROR);    level = intLock();    if ( trgId->status != TRG_DISABLE )	{        trgId->status = TRG_DISABLE;	intUnlock(level);        if ( (--trgCnt == 0) && TRG_ACTION_IS_SET )            trgOff();	}    else	{	intUnlock(level);	return(ERROR);	}    return(OK);    }/********************************************************************************* trgChainSet - chains two triggers** This routine chains two triggers together.  When the first trigger fires, it* calls trgEnable() for the second trigger.  The second trigger must be created* disabled in order to maintain the correct sequence.** RETURNS: OK or ERROR.** SEE ALSO: trgEnable()*/STATUS trgChainSet    (    TRIGGER_ID fromId,    TRIGGER_ID toId    )    {    if ( fromId == NULL )	return(ERROR);    if ( fromId->chain != NULL && toId != NULL )	return(ERROR);    fromId->chain = toId;    return (OK);    }/********************************************************************************* trgContextMatch - show the trigger list** INTERNAL* FIXME** RETURNS:* SEE ALSO: FIXME()* NOMANUAL*/BOOL trgContextMatch    (    TRIGGER_ID pTrg    )    {	switch ( pTrg->contextType )	    {	    case TRG_CTX_ANY:		return (TRUE);	    case TRG_CTX_SYSTEM:		return(kernelState); 	    case TRG_CTX_TASK:		return ( (!kernelState) && (!INT_CONTEXT ()) &&		     ((WIND_TCB *)(pTrg->contextId) == taskIdCurrent) );	    case TRG_CTX_ANY_TASK:		return ((!kernelState) && (!INT_CONTEXT ()));	    case TRG_CTX_ISR:	    case TRG_CTX_ANY_ISR:		return (INT_CONTEXT ());	    default:		return(FALSE);	    }	return(FALSE);    }/********************************************************************************* trgCondTest - show the trigger list** INTERNAL* FIXME** RETURNS:* SEE ALSO: FIXME()* NOMANUAL*/BOOL trgCondTest    (    TRIGGER_ID pTrg,    int        objId    )    {    BOOL retval;    int level = intLock();	switch (pTrg->condOp)	    {	    case TRIGGER_EQ: 	        switch (pTrg->condType)	        {	        case TRIGGER_COND_VAR:                        retval = ((* ((BOOL *)pTrg->condEx1) == pTrg->condEx2));                       intUnlock(level);                       return(retval);	        case TRIGGER_COND_FUNC:		       retval = (((* ((FUNCPTR)pTrg->condEx1)) () == pTrg->condEx2));                       intUnlock(level);                       return(retval);                case TRIGGER_COND_LIB:		       retval = (*((FUNCPTR)pTrg->condEx1)) (objId,pTrg->condEx2);                       intUnlock(level);                       return(retval);	        default:                    intUnlock(level);		    return(FALSE);	        }	    case TRIGGER_NEQ: 	       switch (pTrg->condType)	           {	           case TRIGGER_COND_VAR:                        retval = ((* ((BOOL *)pTrg->condEx1) != pTrg->condEx2));                       intUnlock(level);                       return(retval);	           case TRIGGER_COND_FUNC:		       retval = (((* ((FUNCPTR)pTrg->condEx1)) () != pTrg->condEx2));                       intUnlock(level);                       return(retval);	           default:                       intUnlock(level);		       return(FALSE);	           }	    case TRIGGER_GRT: 	       switch (pTrg->condType)	           {	           case TRIGGER_COND_VAR:                        retval = ((* ((BOOL *)pTrg->condEx1) > pTrg->condEx2));                       intUnlock(level);                       return(retval);	           case TRIGGER_COND_FUNC:		       retval = (((* ((FUNCPTR)pTrg->condEx1)) () > pTrg->condEx2));                       intUnlock(level);                       return(retval);	           default:                       intUnlock(level);		       return(FALSE);	           }	    case TRIGGER_LSS: 	       switch (pTrg->condType)	           {	           case TRIGGER_COND_VAR:                        retval = ((* ((BOOL *)pTrg->condEx1) < pTrg->condEx2));                       intUnlock(level);                       return(retval);	           case TRIGGER_COND_FUNC:		       retval = (((* ((FUNCPTR)pTrg->condEx1)) () < pTrg->condEx2));                       intUnlock(level);                       return(retval);	           default:                       intUnlock(level);		       return(FALSE);	           }	    case TRIGGER_GEQ: 	       switch (pTrg->condType)	           {	           case TRIGGER_COND_VAR:                        retval = ((* ((BOOL *)pTrg->condEx1) >= pTrg->condEx2));                       intUnlock(level);                       return(retval);	           case TRIGGER_COND_FUNC:		       retval = (((* ((FUNCPTR)pTrg->condEx1)) () >= pTrg->condEx2));                       intUnlock(level);                       return(retval);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -