📄 trglib.c
字号:
/* trgLib.c - trigger events control library *//* Copyright 1994-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01x,21mar02,tcr Fix SPR 7446501w,11oct01,tcr Fix SPR 70133 - trigger action routine cannot take zero-valued argument01v,02mar99,dgp removed reference to e() from trgEvent()01u,11sep98,cjtc deferred action queue for triggering modified01t,28aug98,dgp FCS man page edit01s,28may98,dgp final doc editing for WV 2.0 beta01r,07may98,dgp clean up man pages for WV 2.0 beta release01q,08apr98,pr added some comments and some cleanup01p,25mar98,pr deleted portWorkQAdd1 (see rBuffLib.c)01p,25mar98,pr added trgEvent function01o,22mar98,pr replaced workQAdd1 with portable version 01n,21feb98,pr commented out hitCnt reset in trgOn. Fix obj enable in trgCheck.01m,22feb98,pr added hitCnt. Cleanup01l,13feb98,nps made trgDelete more defensive by verifying object exists.01k,12feb98,pr moved trgShow to trgShow.c. Added hitCnt support.01j,27jan98,nps Fix merge errors.01i,27jan98,nps modified switch so all current deferred actions are handled in the same way. incorporated support for library condition fns.01h,23jan98,pr moved _func_trgCheck initialization, replaced macro names.01g,16jan98,pr modified option for msgQSend. 01f,14dec97,pr moved declaration of some global variables into funcBind.c01e,14dec97,pr deleted reference to myCnt01d,13dec97,pr deleted some temporary variables. Reduced the number of arguments passed to trgCheck01c,20nov97,pr added the deferred execution of tasks, fixed some bugs added trgChainSet, trgAddTcl modified trgCondTest, added support for EVENT_ANY_EVENT01b,09oct97,pr modified the prototype: changed the structure in an obj replaced the list with an array modified the search algorithm01a,25jun97,pr written*//*DESCRIPTIONThis library provides the interface for triggering events. The routinesprovide tools for creating, deleting, and controlling triggers. However,in most cases it is preferable to use the GUI to create and managetriggers, since all order and dependency factors are automaticallyaccounted for there.The event types are defined as in WindView. Triggering and WindView sharethe same instrumentation points. Furthermore, one of the main uses oftriggering is to start and stop WindView instrumentation. Triggering isstarted by the routine trgOn(), which sets the shared variable 'evtAction'.Once the variable is set, when an instrumented point is hit, trgCheck() iscalled. The routine looks for triggers that apply to this event. Theroutine trgOff() stops triggering. The routine trgEnable() enables aspecific trigger that was previously disabled with trgDisable(). (Atcreation time all triggers are enabled by default.) This routine alsochecks the number of triggers currently enabled, and when this is zero, itturns triggering off.NOTE: It is important to create a trigger before calling trgOn(). trgOn()checks the trigger list to see if there is at least one trigger there, and ifnot, it exits without setting 'evtAction'.INCLUDE FILES: trgLibP.hSEE ALSO: .I WindView User's Guide*/#include "vxWorks.h"#include "intLib.h"#include "taskLib.h"#include "stdio.h"#include "logLib.h"#include "private/trgLibP.h"#include "private/kernelLibP.h"#include "private/windLibP.h"#include "private/workQLibP.h"/* extern */extern int trgCnt;int trgNone;extern VOIDFUNCPTR _func_trgCheck;#if (CPU_FAMILY == I80X86)extern void portWorkQAdd1();#endif /* CPU_FAMILY == I80X86 *//* global */UINT trgWorkQReader; /* work queue index */UINT trgWorkQWriter; /* work queue index */BOOL trgWorkQFullNotify; /* work queue full notification*/SEM_ID trgDefSem;OBJ_CLASS trgClass; /* trg object Class */CLASS_ID trgClassId = &trgClass; /* trg class ID */MSG_Q_ID trgActionDefMsgQId = NULL;UINT32 trgClassList[] = {TRG_CLASS_1, TRG_CLASS_2, TRG_CLASS_3, TRG_CLASS_4, TRG_CLASS_5, TRG_CLASS_6};/* local */TRIGGER_ID trgWorkQ[TRG_MAX_REQUESTS];TRIGGER_ID * trgList;LOCAL BOOL trgLibInstalled = FALSE; /* protect from multiple inits */LOCAL BOOL trgActionDefStarted = FALSE; /* protect from multiple inits */void trgCheck(event_t event, int index, int obj,int arg1,int arg2,int arg3,int arg4,int arg5);TRIGGER_ID trgAdd(event_t event, int status, int contextType, UINT32 contextId, OBJ_ID objId, int conditional, int condType, int * condEx1, int condOp, int condEx2, BOOL disable, TRIGGER_ID chain, int actionType, FUNCPTR actionFunc, BOOL actionDef, int arg);STATUS trgInit();STATUS trgDelete(TRIGGER_ID trgId);void trgOff();/********************************************************************************* trgLibInit - initialize the triggering library** This routine initializes the trigger class. Triggers are VxWorks objects * and therefore require a class to be initialized.** RETURNS: OK or ERROR.**/STATUS trgLibInit (void) { int index; if ((!trgLibInstalled) && (classInit (trgClassId, sizeof(TRIGGER), OFFSET(TRIGGER, objCore), (FUNCPTR) trgAdd, (FUNCPTR) trgInit, (FUNCPTR) trgDelete) == OK)) { trgList = (TRIGGER_ID *)malloc (sizeof(TRIGGER_ID)*TRG_MAX_REQUESTS ); if ( trgInit() != OK) return(ERROR); trgWorkQFullNotify = FALSE; trgWorkQReader = 0; trgWorkQWriter = 0; for (index = 0 ; index < TRG_MAX_REQUESTS ; index ++) trgWorkQ[index] = NULL; trgLibInstalled = TRUE; } return ((trgLibInstalled) ? OK : ERROR); }/********************************************************************************* trgInit - Initializes triggering list and function** initialize/reset the list and the _func_trgCheck pointer** NOMANUAL**/STATUS trgInit () { int index; if ( trgList == NULL ) return(ERROR); for (index = 0 ; index < TRG_MAX_REQUESTS ; index ++) trgList[index] = NULL; /* set the function for the event points */ _func_trgCheck = (VOIDFUNCPTR) trgCheck; return(OK); }/********************************************************************************* trgActionDefInit - Initializes the daemon for deferred execution of tasks** Tasks can be executed in deferred mode (this is the default). That is, if* they are in a critical part of the code (i.e. Kernel state) their execution* does not occur until they are out of the critical code.* This task will initialize the task for the deferred execution, * trgActionDefPerform.** NOMANUAL**/STATUS trgActionDefStart () { if ( trgActionDefStarted == TRUE) return (OK); if ((!trgLibInstalled) && (trgLibInit () != OK)) return (ERROR); taskSpawn ("trgActDef", TRG_ACT_PRIORITY, TRG_ACT_OPTIONS, TRG_ACT_SIZE, trgActionDefPerform, 0,0,0,0,0,0,0,0,0,0); trgActionDefStarted = TRUE; return (OK); }/********************************************************************************* trgWorkQReset - Resets the trigger work queue task and queue** When a trigger fires, if the assocated action requires a function to be called* in "safe" mode, a pointer to the required function will be placed on a queue* known as the "triggering work queue". A system task "tActDef" is spawned to* action these requests at task level. Should the user have need to reset this* work queue (e.g. if a called task causes an exception which causes the* trgActDef task to be SUSPENDED, or if the queue gets out of sync and becomes* unresponsive), trgWorkQReset() may be called.** Its effect is to delete the trigger work queue task and its associated * resources and then recreate them. Any entries pending on the triggering work* queue will be lost. Calling this function with triggering on will result in* triggering being turned off before the queue reset takes place. It is the* responsibility of the user to turn triggering back on.** RETURNS: OK, or ERROR if the triggering task and its associated resources* cannot be deleted and recreated.**/STATUS trgWorkQReset (void) { int index; if ((!trgLibInstalled) && (trgLibInit () != OK)) return (ERROR); if (TRG_ACTION_IS_SET) trgOff(); if (trgActionDefStarted != TRUE) return OK; if (taskDelete (taskNameToId ("trgActDef")) == ERROR) return ERROR; trgActionDefStarted = FALSE; if (semDelete (trgDefSem) == ERROR) return ERROR; /* re-initialise the work queue */ trgWorkQFullNotify = FALSE; trgWorkQReader = 0; trgWorkQWriter = 0; for (index = 0 ; index < TRG_MAX_REQUESTS ; index ++) trgWorkQ[index] = NULL; /* restart the work queue task */ return (trgActionDefStart ()); }/********************************************************************************* trgEvtToIndex - calculate the list the trigger belongs to given the event ID ** The routine returns the index of the list where the trigger belongs to. The* index are based on WindView event type classification.** NOMANUAL**/int trgEvtToIndex ( event_t event ) { if (event == EVENT_ANY_EVENT) return(TRG_ANY_EVENT_INDEX); if (IS_CLASS1_EVENT(event)) return(TRG_CLASS1_INDEX); if (IS_CLASS2_EVENT(event)) return(TRG_CLASS2_INDEX); if (IS_CLASS3_EVENT(event)) return(TRG_CLASS3_INDEX); if (IS_USER_EVENT(event)) return(TRG_USER_INDEX);/* this is probably never reached, since it is a subclass of class1 */ if (IS_INT_ENT_EVENT(event)) return(TRG_INT_ENT_INDEX); #if 0 if (IS_CONTROL_EVENT(event)) return(TRG_CONTROL_INDEX);#endif return(ERROR); }/********************************************************************************* trgAddTcl - calls trgAdd but accepts one single parameter** Since Tcl does not take more than 10 parameters, they have been saved in one* memory location. This routine retrieves the values and passes them to trgAdd.** NOMANUAL**/TRIGGER_ID trgAddTcl ( char * buff ) { int * buffIndex = (int *)buff; int event; int status; int conditional; int condType, contextType, actionType; int * condEx1, condOp, condEx2; int actionArg; UINT32 contextId; OBJ_ID objId; BOOL disable, actionDef; FUNCPTR actionFunc; TRIGGER *chain; event = (int) *buffIndex++; status = (int) *buffIndex++; contextType = (int) *buffIndex++; contextId = (UINT32) *buffIndex++; objId = (OBJ_ID) *buffIndex++; conditional = (int) *buffIndex++; condType = (int) *buffIndex++; condEx1 = (int *) *buffIndex++; condOp = (int) *buffIndex++; condEx2 = (int) *buffIndex++; disable = (BOOL) *buffIndex++; chain = (TRIGGER *) *buffIndex++; actionType = (int) *buffIndex++; actionFunc = (FUNCPTR) *buffIndex++; actionDef = (BOOL) *buffIndex++; actionArg = (int) *buffIndex;#if 0 printf ("event = %hd \n", (event_t)event); printf(" %d\n", status); printf(" %d \n", contextType); printf(" %d\n", contextId); printf(" %p\n", objId); printf(" %d\n", conditional); printf("%d \n", condType); printf(" %p\n", condEx1); printf(" %d\n", condOp); printf(" %d\n", condEx2); printf(" %d\n", disable); printf(" %p\n", chain); printf(" %d\n", actionType); printf(" %p\n", actionFunc); printf(" %d\n", actionDef); printf(" %d\n", actionArg);#endif return (trgAdd ( (event_t)event, status, contextType, contextId, objId, conditional, condType, condEx1, condOp, condEx2, disable, chain, actionType, actionFunc, actionDef, actionArg )); } /********************************************************************************* trgAdd - add a new trigger to the trigger list** This routine creates a new trigger and adds it to the proper trigger list. It* takes the following parameters:* .iP <event> 50* as defined in eventP.h for WindView, if given.* .iP <status>* the initial status of the trigger (enabled or disabled).* .iP <contextType>* the type of context where the event occurs.* .iP <contextId>* the ID (if any) of the context where the event occurs.* .iP <objectId>* if given and applicable.* .iP <conditional>* the indicator that there is a condition on the trigger.* .iP <condType>* the indicator that the condition is either a variable or a function.* .iP <condEx1>* the first element in the comparison.* .iP <condOp>* the type of operator (==, !=, <, <=, >, >=, |, &).* .iP <condEx2>* the second element in the comparison (a constant).* .iP <disable>* the indicator of whether the trigger must be disabled once it is hit.* .iP <chain>* a pointer to another trigger associated to this one (if any).* .iP <actionType>* the type of action associated with the trigger (none, func, lib).* .iP <actionFunc>* the action associated with the trigger (the function).* .iP <actionDef>* the indicator of whether the action can be deferred (deferred is the default).* .iP <actionArg>* the argument passed to the function, if any.* .LP** Attempting to call trgAdd whilst triggering is enabled is not allowed* and will return NULL.** RETURNS: TRIGGER_ID, or NULL if either the trigger ID can not be allocated,* or if called whilst triggering is enabled.** SEE ALSO: trgDelete()*/TRIGGER_ID trgAdd ( event_t event, int status, int contextType, UINT32 contextId, OBJ_ID objId, int conditional, int condType, int * condEx1, int condOp, int condEx2, BOOL disable, TRIGGER *chain, int actionType, FUNCPTR actionFunc, BOOL actionDef, int actionArg ) { TRIGGER_ID trgId, pTrg; int index; if ( TRG_ACTION_IS_SET ) return (NULL); if ((!trgLibInstalled) && (trgLibInit () != OK)) return (NULL); if ((trgId = (TRIGGER_ID)objAlloc(trgClassId)) == NULL) return(NULL); objCoreInit (&trgId->objCore, trgClassId);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -