How to redirect printing functions via XSCOPE

  • version

    1.0.0

  • scope

    Example.

    This code is provided as example code for a user to base their code on.

  • description

    How to redirect printing functions via XSCOPE

  • boards

    Unless otherwise specified, this example runs on the SliceKIT Core Board, but can easily be run on any XMOS device by using a different XN file.

XSCOPE is fully supported on hardware platforms which provide an XMOS link between the target device and the XSYS development connector.

View the document (XSCOPE overview) for further information on tracing data from XMOS applications.

This example provides a demonstration of redirecting the standard printing routines available in the xTIMEcomposer tools via the XSCOPE trace system. Redirecting printing over XSCOPE provides a streaming print capability that does not stop the xCORE device when a print message is issued. The allows printing to be done from applications which have real time constraints providing a valuable debugging tool for the developer.

In this case the standard printf() call is redirected via XSCOPE.

This example assumes you are familiar with creating a run configuration and enabling the associated XSCOPE options in that run configuration in xTIMEcomposer Studio or using the command line tools.

In order to use XSCOPE the correct header file must be included in the application

#include <xscope.h>

Using the XSCOPE constructor which gets called automatically by the XSCOPE system provide the following call to xscope_register().

The xscope_config_io() function is used to configure the I/O mode within XSCOPE. In this case it is set to just pass the message to the host without additional information.

void xscope_user_init(void) {
   xscope_register(0, 0, "", 0, "");
   xscope_config_io(XSCOPE_IO_BASIC);
}

Once this code has been added to an application all standard print routines which are supported will transmit to the host machine via XSCOPE.