15.8.7 Example STM reading code

The following is some Java code which shows an example of STM Object reading. This could also be implemented in Jython.

In this case, the STMTraceReader object implements the ISTMObjectReceiver interface itself. This means that the code can pass the object to the STMChannelReader read method as the class to receive the STMObjects.

The example code creates an STMSourceMatcherRange object with a parameter set which matches against all Masters and Channels.

The STPv2 packet protocol outputs a SYNC packet which allows the decoder to synchronize the binary data stream to the start of a packet. When decoding arbitrary data streams, the decoder needs to synchronize to the stream before starting to decode the STPv2 packets. Once the stream is synchronized, there is no need to resynchronize, as long as contiguous data is being decoded.

The decoder has two ways to handle errors in the STPv2 packets stream:

/**
 * Class to read STM trace data and to get it processed into a
 * text stream.
 */
public class STMTraceReader implements ISTMObjectReceiver {
    /**
     * The trace device - ETB or DSTREAM or .....
     */
    private ITraceCapture traceDevice;
    /**
     * A list of STMObjects that gets generated for us
     */
    private List<STMObject> stmObjects;

[snip – other attribute declarations]

    public void decodeSTMTrace() {
        STMSourceMatcherRange stmSourceMatcher = new STMSourceMatcherRange(0, 128, 0, 65535);
        STMChannelReader stmChannelReader = new STMChannelReader(
            "STM Example",
            this.traceDevice,
            stmSourceMatcher);
        ISourceReader reader = this.traceDevice.borrowSourceReader(
            "STM Reader", this.stmStreamID);
        if (reader != null) {
            try {
[snip - code to figure out if trace is contiguous from last read.]
                if (!traceDataIsContiguous) {
                    stmChannelReader.reSync();
                }
[snip - code to figure out how much trace to read and from where. Also assign values to nextPos[] and readSize.]
                this.stmObjects.clear();
                try {
                    stmChannelReader.read(nextPos[0], readSize, this, nextPos, reader);
                } catch (DTSLException e) {
                    System.out.println("Caught DTSLException during STPv2 decode:");
                    System.out.println(e.getLocalizedMessage());
                    stmChannelReader.reSync();
                }
            }
            catch (DTSLException e) {
                System.out.println("DTSLException:");
                e.printStackTrace();
            }
            finally {
                /* Must return the trace reader to DTSL so that it knows we have finished reading
                 */
                this.traceDevice.returnSourceReader(reader);
            }
        }
    }
    
    /* (non-Javadoc)
     * @see com.arm.debug.dtsl.decoders.stm.stmobjects.ISTMObjectReceiver#write(com.arm.debug.dtsl.decoders.stm.stmobjects.STMObject)
     */
    @Override
    public boolean write(STMObject stmObject) {
        this.stmObjects.add(stmObject);
        return true;
    }		
Non-ConfidentialPDF file icon PDF versionARM DUI0446Z
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.