150
K
A
DAK
Advanced Topics
13.2 User Error ProcedureMost AMX procedures return error status to the caller. The error status is a signed
integer.
AEREROK = 0 No error
AERxxx > 0 Warning: possible fault
AERxxx < 0 Error: may be unrecoverable
The defined error codes are summarized in Appendix B.
AMX allows you to provide a User Error Procedure to trap all errors generated by calls to
AMX functions. You do so by specifying the name of your procedure in your System
Configuration Module (see Chapter 14.5).
Before returning an error or warning condition to the caller, AMX calls your User Error
Procedure, if one has been provided. The User Error Procedure receives the AMX error
code and the task id of the task executing at the time of the error. The task id will be 0 if
the error occurred in an ISP call to AMX.
Upon entry to your User Error Procedure, interrupts are disabled to prohibit device
interrupt, clock ISP and higher priority task activity until you have had an opportunity to
examine the error condition. Your procedure should not enable interrupts without first
disabling or resetting all interrupt sources. In all but the simplest of systems this may be
impossible to do.
The User Error Procedure executes in the context of the task, ISP, Ti mer Procedure,
Restart Procedure or Exit Procedure which made the errant AMX call. The User Error
Procedure can only make AMX calls which an ISP is allowed to make.
In general, there is little that the User Error Procedure can do. It can, however, be
extremely useful for locating faults in your application during initial testing. It is also
useful for locating infrequently occurring error conditions which are not being checked
by your code and hence are going undetected in an otherwise working system.
Your User Error Procedure can be coded as a Large model C procedure with formal
parameters as illustrated in the following example.
#include "amx831cf.h" /* AMX C Interface Header */
void cdecl userror(
int error, /* AMX error code AERxxxx */
AMXID taskid) /* Task id of current task */
/* (0 if error occurred in ISP) */
{:
Interpret the error code
Interpret the task id
:
}