User trap handler installation
A trap handler runs with supervisor privileges within the kernel + trap installer task context. Only one task can register the handler! In this case, the user should keep in mind that when a different task (than the installer task) causes a trap, the memory protection unit will not be set for the violating task.
The PxTrapInstallHandler() function is used for trap handler installation. The task that installs trap handlers must have these access rights: PXACCESS_HANDLERS and PXACCESS_INSTALL_HANDLERS.
PxError_t PxTrapInstallHandler(PxUInt_t trapno,
PxBool_t(* traphandler)(PxTrapTin_t, PxUInt_t, PxUInt_t,
PxUInt_t, PxUInt_t *,TC_CSA_t *),
PxUInt_t arg);
Parameters:
-
trapno — number of trap class (described in Trap descriptions)
-
traphandler — trap handler function (detailed description in User Trap Handler Definition)
-
arg — traphandler`s user argument
Code 1. Example installation of a class 1 handler in Init task
PxBool_t Trap_Hnd_01(PxTrapTin_t trapTin, PxUInt_t hnd_arg, PxUInt_t runtaskId,
PxUInt_t dstr, PxUInt_t *deadd, TC_CSA_t *csa)
{
/* implementation */
}
void InitTask_Func(PxTask_t myID, PxMbx_t myMailbox, PxEvents_t myActivationEvents)
{
...
PxError_t err;
err = PxTrapInstallHandler(1, Trap_Hnd_01, 0); /* No user argument passed */
if (err != PXERR_NOERROR)
PxPanic();