MPLAB REAL ICE In-Circuit Emulator Support

The compiler supports log and trace functions (instrumented trace) when using a Microchip MPLAB REAL ICE In-Circuit Emulator. See the emulator’s documentation for more information on the instrumented trace features.

Not all devices support instrumented trace and only native trace is currently supported by the compiler.

The log and trace macro calls need to be either added by hand to your source code or inserted by right-clicking on the appropriate location in MPLAB X IDE editor, as described by the emulator documentation. These macros should not be used in assembly code. The <xc.h> header must be included in any modules that use these macros.

The macros have the following form.

__TRACE(id);
__LOG(id, expression);

MPLAB X IDE will automatically substitute an appropriate value for id when you compile; however, you can specify these by hand if required. The trace id should be a constant in the range of 0x40 to 0x7F and the log id is a constant in the range of 0x0 to 0x7F. Each macro should be given a unique number so that it can be properly identified. The same number can be used for both trace and log macros.

Trace macros should be inserted in the C source code at the locations you wish to track. They will trigger information to be sent to the debugger and IDE when they are executed, recording that execution reached that location in the program.

The log expression can be any integer or 32-bit floating-point expression whose value will be recorded along with the program location. Typically, this expression is simply a variable name so the variable’s contents are logged.

Adding trace and log macros will increase the size of your code as they contribute to the program image that is downloaded to the device.

Here is an example of these macros that you might add.

#include <xc.h>
inpStatus = readUser();
if(inpStatus == 0) {
    __TRACE(id);
    recovery();
}
__LOG(id, inpStatus);