4.1 Error Handling

In order for the test modules to be as general as possible, a number of error handlers that can be configured by the user have been defined. Errors have been divided into critical and non-critical and have a default value for the error handlers.

Critical errors are those that cannot be handled, e.g., when the register that should return the result of the register self-diagnostic routine has a stuck bit. Critical errors hang the CPU by default, leaving it executing an infinite loop. This should lead to a watchdog reset and the actions to take, after a system reset issued by the watchdog timer (hereafter referred to as WDT), can be configured as well.

Non-critical errors are those that, even if they prevent the application from working correctly, still can be handled by the program. E.g., if the analog test fails, the program could still take some actions to put the system in a safe state. Non-critical errors set a global error flag by default. This flag is called classb_error and it can be used by the main application to put the system in a safe state. This is the approach followed in the examples.

In all the tests the classb_error flag is zero when there is no error and non-zero when an error has been found. The error flag is assigned the NO_INIT attribute, which prevents the memory it uses in SRAM to be overwritten with a default value at start-up. As long as the device does not lose power the value will be maintained.

The classb_error flag is in this library written to 1 when an error is found. This can be changed so that the error variable also contains information on what error has been found. The logic for doing so has not been implemented in the included tests as most error handling will be application dependent.