This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DSS scripting in CCSv6 versus CCSv5 - Trace API's

Other Parts Discussed in Thread: 66AK2H14, CCSTUDIO

Hi Champs,

it seems that the the DSS scripting API's changed moving from CCSv5 versus CCSv6. Are there some migration hints or at least a document noting the changes?

Especially when it comes to Trace configuration ...

Kind regards,

one and zero

  • Hi,

    My understanding is that DSS should be fully compatible going from CCSv5 to CCSv6.

    What specifically did you noticed has changed in the DSS APIs?

    Thanks,
    Ricky
  • Hi Ricky,

    thanks for your reply. Being more specific. Coming from CCSv5.3 and now running the script in conjunction with CCSv6.1 ...

    That's the script-command not working anymore:

     
    traceChannel.setupTraceChannel(channelXMLFile);

    channelXMLFile=’ /tmp/traceChannelConfig.xml’:



    <?xml version="1.0" encoding="UTF-8"?>

    <!-- This file defines the XDS Pro Trace receiver channel settings. -->

    <CHANNEL-SETUP>

                    <RCVRNAME>Pro Trace</RCVRNAME>

                    <GLOBAL_OPTS_PATH></GLOBAL_OPTS_PATH>

                    <CALIBRATION_PATH></CALIBRATION_PATH>

                    <NUM_DATA_PINS>10</NUM_DATA_PINS>

                    <PIN_MAP>3,13,12,11,10,9,8,7,6,5,4</PIN_MAP>

                    <IS_STOP_ON_FULL>true</IS_STOP_ON_FULL>

                    <IS_SYNC>true</IS_SYNC>

                    <BUFSIZE_CURRENT>5</BUFSIZE_CURRENT>

                    <XMTR_TYPE>dsp</XMTR_TYPE>

                    <XMTR_VER>1.0</XMTR_VER>

                    <FREQUENCY_MAX>-1</FREQUENCY_MAX>

                    <FREQUENCY_INDEX>5</FREQUENCY_INDEX>

                    <EXTRA_LOGGING>false</EXTRA_LOGGING>

                    <VERIFY_CALIBRATION>true</VERIFY_CALIBRATION>

                    <VERIFY_PATTERNS>false</VERIFY_PATTERNS>

                    <PATTERN>-1</PATTERN>

                    <USE_PAUSE_MODE>false</USE_PAUSE_MODE>

                    <USE_RUN_MAX>false</USE_RUN_MAX>

                    <TRACE_PROGRAM_FLOW>true</TRACE_PROGRAM_FLOW>

                    <TRACE_TIMING>true</TRACE_TIMING>

                    <TRACE_MEMORY_READS>false</TRACE_MEMORY_READS>

                    <TRACE_MEMORY_WRITES>false</TRACE_MEMORY_WRITES>

                    <TRACE_REAL_TIME_INTERRUPTS>true</TRACE_REAL_TIME_INTERRUPTS>

                    <TRACE_TIME_OF_EMULATION_HALTS>false</TRACE_TIME_OF_EMULATION_HALTS>

                    <STALL_CPU>true</STALL_CPU>

                    <STALL_DURING_DBGM>true</STALL_DURING_DBGM>

                    <STALL_DURING_HPI>true</STALL_DURING_HPI>

                    <USE_SMALL_FRAME_SIZE>true</USE_SMALL_FRAME_SIZE>

                    <ARM_STALL_CPU>true</ARM_STALL_CPU>

                    <ARM_MONITOR_CPRT>false</ARM_MONITOR_CPRT>

                    <ARM_NO_DATA_TRACE_ON_FIFO_FULL>false</ARM_NO_DATA_TRACE_ON_FIFO_FULL>

                    <ARM_CYCLE_ACCURATE_TRACE>true</ARM_CYCLE_ACCURATE_TRACE>

                    <ARM_EXPORT_FRAMESIZE>0</ARM_EXPORT_FRAMESIZE>

                    <BIN_FILE></BIN_FILE>

                    <TRACE_TYPE>4294967295</TRACE_TYPE>

    </CHANNEL-SETUP>

    After invoking that command the follwing messages appear:

     
    Waiting for client
    Client connected

    After that only kind of random output ...


    Thanks and kind regards,

    one and zero

  • One and zero,

    Can you post the random output you are seeing?  There should have been no trace API changes made between ccsv5 and ccsv6.

    Thanks,

    Mark

  • Hi Mark,

    here's the output seen:

    >>>> %$v#00 <<<< $OK01000000#00 >>>> %$c18000000sd560v2e@192.168.255.211#00 <<<< $OK#00 >>>> %$E?#00 <<<< $OK00#00 >>>> %$m010000000100000000000006adde0000#00 <<<< $OK01000000000000060b140000#00 ...

    Kind regards,
    one and zero
  • One and zero,

    The output you are seeing is a low-level communication between the 560v2 and the host PC.  This is a bug that is slated to be fixed for the next TI Emulators release but should be harmless in terms of functionality.  Apart from the random output, does the trace scripting work at all in your environment?

    Thanks,

    Mark

  • Hi Mark,

    in principle the trace scripting is working. However, using breakpoints to trigger the start of PC trace collection is not functioning anymore. Instead PC trace collection starts immediately.

    Kind regards,

    one and zero

  • One and zero,

    What device is this? Can you post a snippet of the scripting that configures trace to start on a BP?

    Thanks,
    Mark
  • Hi Mark,

    the device is 66AK2H14.

    This is beginnig from AutomaticTrace.js script



    // Import the DSS packages into our namespace to save on typing

    importPackage(Packages.com.ti.debug.engine.scripting)

    importPackage(Packages.com.ti.ccstudio.scripting.environment)

    importPackage(Packages.java.lang)

    importPackage(Packages.java.net)

    importPackage(Packages.java.util)

    importPackage(Packages.java.text)

    importPackage(Packages.java.scripting)

    importPackage(Packages.com.ti.ctoolstrace.scripting)

    importPackage(Packages.java.io)



    var dateFormatter = new SimpleDateFormat("HH:mm:ss:SSS dd/MM/yyyy");

    var deviceCCXMLFile = "";

    var channelXMLFile = "";

    var symbolFile = "";

    var breakpointFile = "";

    var receiverName = "Pro Trace"

    var socketPort = 5002;

    var socketTimeOut = 2* 60 * 1000;

    var traceFile = "/tmp/autotrace/output_files/trace.bin"

    var scriptTimeout = 30 * 1000

    var actTraceOnBreakpoint = false;

    var traceRecordingTimeout = 30000;



    // Create our scripting environment object - which is the main entry point into any script and

    // the factory for creating other Scriptable ervers and Sessions

    var script = ScriptingEnvironment.instance();

    // wait for every call to ccs max scriptTimeout (at the moment 30s)

    myEcho("Setting script timeout to: " + scriptTimeout + "ms");

    script.setScriptTimeout(scriptTimeout);

    //Create a log file in the current directory to log script execution

    script.traceBegin("/tmp/AutomaticTraceLog.xml", "DefaultStylesheet.xsl");

    script.traceSetConsoleLevel(TraceLevel.OFF);

    script.traceSetFileLevel(TraceLevel.ALL);

    parseArguments(arguments);

    myEcho("Setting trace recording timeout to: " + traceRecordingTimeout + "s");



    // Create a debug server

    var debugServer = script.getServer("DebugServer.1");



    // Set the device ccxml

    debugServer.setConfig(deviceCCXMLFile);

    var cpuList = debugServer.getListOfCPUs();

    var cpuName = cpuList[fetchLastDigit(symbolFile)];

    myEcho("Using cpuName: " + cpuName);



    // Open a debug session

    debugSession = debugServer.openSession(cpuName);

    debugSession.options.setBoolean("AllowInterruptsWhenHalted", true);

    debugSession.options.setBoolean("PoliteRealtimeMode", true);



    debugSession.target.connect();

    myEcho("Target connected");

    myEcho("Loading symbols");

    debugSession.symbol.load(symbolFile);



    // Create a ctool trace server.

    myEcho("Creating trace server");

    var ts = new CToolsTraceServer();

    // Initialize the newly create trace server object

    ts.initialize();

    myEcho("Creating trace channel");

    var traceChannel = ts.createChannel(receiverName);

    myEcho("Adding target");

    stringArray = java.lang.reflect.Array.newInstance(java.lang.String, 1)

    stringArray[0] = new java.lang.String(cpuName);

    traceChannel.addTraceTargets(stringArray);

    traceChannel.setupTraceChannel(channelXMLFile);

    var channelStatus = traceChannel.getStatus();

    myEcho("Channel status: " + channelStatus.description());

    if (!channelStatus.isEnabled()) {

    myEcho("Channel is not enabled, quitting!");

    terminateSession();

    throw "exit";

    }

    myEcho("Removing old breakpoints");

    debugSession.breakpoint.removeAll();

    communicateReadyToTrace();

    myEcho("Everything is set up, waiting for triggering");

    waitOnTraceTriggering();



    Kind regards,
    one and zero
  • Hi Mark,

    any ideas? Do you need more info?

    Kind regards,

    one and zero

  • One and zero,

    I don't see where the actual break point to trigger trace is being set. Can you post the source for the full working example?

    Thanks,

    Mark

  • Hi Mark,

    it's attached. Renamed from .js to .txt

    Kind regards,

    one and zero

    // Import the DSS packages into our namespace to save on typing
    importPackage(Packages.com.ti.debug.engine.scripting)
    importPackage(Packages.com.ti.ccstudio.scripting.environment)
    importPackage(Packages.java.lang)
    importPackage(Packages.java.net)
    importPackage(Packages.java.util)
    importPackage(Packages.java.text)
    importPackage(Packages.java.scripting)
    importPackage(Packages.com.ti.ctoolstrace.scripting)
    importPackage(Packages.java.io)
    
    var dateFormatter = new SimpleDateFormat("HH:mm:ss:SSS dd/MM/yyyy");
    var deviceCCXMLFile = "";
    var channelXMLFile = "";
    var symbolFile = "";
    var breakpointFile = "";
    var receiverName = "Pro Trace"
    var socketPort = 5002;
    var socketTimeOut = 2* 60 * 1000;
    var traceFile = "/tmp/autotrace/output_files/trace.bin"
    var scriptTimeout = 30 * 1000
    var actTraceOnBreakpoint = false;
    var traceRecordingTimeout = 30000; 
    
    // Create our scripting environment object - which is the main entry point into any script and
    // the factory for creating other Scriptable ervers and Sessions
    var script = ScriptingEnvironment.instance();
    // wait for every call to ccs max scriptTimeout (at the moment 30s)
    myEcho("Setting script timeout to: " + scriptTimeout + "ms");
    script.setScriptTimeout(scriptTimeout);
    //Create a log file in the current directory to log script execution
    script.traceBegin("/tmp/AutomaticTraceLog.xml", "DefaultStylesheet.xsl");
    script.traceSetConsoleLevel(TraceLevel.OFF);
    script.traceSetFileLevel(TraceLevel.ALL);
    parseArguments(arguments);
    myEcho("Setting trace recording timeout to: " + traceRecordingTimeout + "s");
    
    // Create a debug server
    var debugServer = script.getServer("DebugServer.1");
    
    // Set the device ccxml 
    debugServer.setConfig(deviceCCXMLFile);
    var cpuList = debugServer.getListOfCPUs();
    var cpuName = cpuList[fetchLastDigit(symbolFile)];
    myEcho("Using cpuName: " + cpuName);
    
    // Open a debug session
    debugSession = debugServer.openSession(cpuName);
    debugSession.options.setBoolean("AllowInterruptsWhenHalted", true);
    debugSession.options.setBoolean("PoliteRealtimeMode", true);
    
    debugSession.target.connect();
    myEcho("Target connected");
    myEcho("Loading symbols");
    debugSession.symbol.load(symbolFile);
    
    // Create a ctool trace server.
    myEcho("Creating trace server");
    var ts = new CToolsTraceServer();
    // Initialize the newly create trace server object
    ts.initialize();
    myEcho("Creating trace channel");
    var traceChannel = ts.createChannel(receiverName);
    myEcho("Adding target");
    stringArray = java.lang.reflect.Array.newInstance(java.lang.String, 1)
    stringArray[0] = new java.lang.String(cpuName);
    traceChannel.addTraceTargets(stringArray);
    traceChannel.setupTraceChannel(channelXMLFile);
    var channelStatus = traceChannel.getStatus();
    myEcho("Channel status: " + channelStatus.description());
    if (!channelStatus.isEnabled()) {
    	myEcho("Channel is not enabled, quitting!");
    	terminateSession();
    	throw "exit";
    }
    myEcho("Removing old breakpoints");
    debugSession.breakpoint.removeAll();
    communicateReadyToTrace();
    myEcho("Everything is set up, waiting for triggering");
    waitOnTraceTriggering();
    
    if (cpuName.indexOf("C66") !== -1) {
    	myEcho("Nyquist environment detected, addind Mfence workaround");
        var mfenceWorkaround = mfenceWorkaround();
    	debugSession.breakpoint.add(mfenceWorkaround);
    }
    
    if (breakpointFile !== "") {
    	myEcho("Loading breakpoint from file: " + breakpointFile);
    	var bkpt = debugSession.breakpoint.loadConfig(breakpointFile);
    	if (actTraceOnBreakpoint) {
    		activateTraceOnBreakpoint();
    	}
    } else {
    	activateTraceOnBreakpoint();
    }
    
    myEcho("Recording");
    var recordingRoundsCounter = 0;
    while (!channelStatus.isRecordingStopped()) {
    	Thread.sleep(1000);
        	channelStatus = traceChannel.getStatus();
    	if (recordingRoundsCounter >= traceRecordingTimeout) {
    		traceChannel.stopTraceRecording();
    		terminateSession();
    		throw "Max recording time " + traceRecordingTimeout + "s exceeded!";
    	}
    	recordingRoundsCounter = recordingRoundsCounter + 1;
    }
    myEcho("Saving trace data to file: " + traceFile);
    traceChannel.getBinaryTraceData(traceFile);
    myEcho("All done, completed successfully");
    terminateSession();
    
    function activateTraceOnBreakpoint() {
    	myEcho("Creating trace on breakpoint");
    	var bkpPropTraceOn = createTraceOnBreakpoint();
    	var res = debugSession.breakpoint.add(bkpPropTraceOn);
    }
    
    function createTraceOnBreakpoint()
    {
    	var traceOnBkpProperties = debugSession.breakpoint.createProperties(1);
    	traceOnBkpProperties.setString("Hardware Configuration.Type", "Trace");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Trace Type", "Standard");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Actions",
    				  	"Trace On");
    	traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Program Address",
    					true);
    	traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Time Stamp", true);
    	traceOnBkpProperties.setString("Miscellaneous.Group", "Default Group");
    	traceOnBkpProperties.setString("Miscellaneous.Name", "OnTrace");
    	return traceOnBkpProperties;
    }
    
    function mfenceWorkaround() {
        //  Trace MFENCE bug workaround
        var ignoreMarks = debugSession.breakpoint.createProperties(1); // 1 = AET breakpoint
        ignoreMarks.setString("Hardware Configuration.Type", "Trace");
        ignoreMarks.setString("Hardware Configuration.Type.Trace Type", "Standard");
        ignoreMarks.setString("Hardware Configuration.Type.Actions", "Don't Store Sample");
        ignoreMarks.setString("Hardware Configuration.Type.Trigger Type", "Event");
        ignoreMarks.setString("Hardware Configuration.Type.Trigger Type.Event Category", "System");
        ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction", true);
        ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 0", true);
        ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 1", false);
        ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 2", false);
        ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 3", false);
        ignoreMarks.setBoolean("Hardware Configuration.Type.What to Not Store.Program Address", true); // requires emupack SR M5 to be installed in CCS
        ignoreMarks.setBoolean("Hardware Configuration.Type.What to Not Store.Time Stamp", false); // requires emupack SR M5 to be installed in CCS
        return ignoreMarks;
    }
    
    function createHandleMacUserSetupReqBreakpoint()
    {
    	traceOnBkpProperties = debugSession.breakpoint.createProperties(1);
    	traceOnBkpProperties.setString("Hardware Configuration.Type", "Trace");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Trace Type", "Standard");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Actions",
    				  	"Start Trace");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Trigger Type",
    				  	"PC");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Trigger Type.Location Type",
    				  	"Point");
    	traceOnBkpProperties.setString("Hardware Configuration.Type.Trigger Type.Location Type.Location",
    				  	"handleMacUserSetupReq")
    	traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Program Address",
    					true);
    	traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Time Stamp", true);
    	traceOnBkpProperties.setString("Miscellaneous.Group", "Default Group");
    	traceOnBkpProperties.setString("Miscellaneous.Name", "handleMacUserSetupReq");
    	return traceOnBkpProperties;
    }
    
    function myEcho(msg) {
    	var str = "[" + dateFormatter.format(new Date()) + "]\t" + msg;
    	System.out.println(str);
    	script.traceWrite(msg);
    }
    
    function usage() {
    	var str = "\nAutomaticTrace.js\n";
    	str += "    Mandatory parameters:\n";
    	str += "        -o=<Full path to debug symbols file>\n";
    	str += "           Example: -o=/home/sct/RobotTests/dspbin/OUT/DlUlDspNyCpu2.out\n";
    	str += "        -d=<Full path to device configuration ccxml file>\n";
    	str += "            Example: -d=/tmp/traceDeviceConfig.ccxml\n";
    	str += "        -c=<Full path to trace channel configuration xml file>\n";
    	str += "           Example: -c=/tmp/traceChannelConfig.xml\n";
    	str += "    Optional parameters:\n";
    	str += "        -b=<Full path to breakpoint xml file>\n";
    	str += "           Example: -b=/tmp/traceFunctionBreakpoint.xml\n";
    	str += "        -a=<Activate trace on breakpoint in addition to given breakpoint xml>\n";
    	str += "           Example: -a=True\n";
    	str += "        -t=<Time (in seconds) to wait for trace start command from keyword, default value=120s>\n";
    	str += "           Example: -t=120\n";
    	myEcho(str);
    }
    
    function parseArguments(arguments) {
    
    	for each( var arg in arguments )
      	{
      		if( arg.indexOf( "-" ) == 0 )
        		{
    			opt = arg.split( "=" )[0];
    			switch (opt)
    			{
    				case '-d':
    					deviceCCXMLFile = arg.split( "=" )[1];
            				myEcho("Using device CCXML file: " + deviceCCXMLFile);
    					chekIfFileExists(deviceCCXMLFile);
    					break;
    				case '-c':
    					channelXMLFile = arg.split( "=" )[1];
            				myEcho("Using channel XML file: " + channelXMLFile);
    					chekIfFileExists(channelXMLFile);
    					break;
    				case '-o':
    					symbolFile = arg.split( "=" )[1];
    					myEcho("Using .out file: " + symbolFile);
    					chekIfFileExists(symbolFile);
    					break;
    				case '-b':
    					breakpointFile = arg.split( "=" )[1];
    					myEcho("Using break point file: " + breakpointFile);
    					chekIfFileExists(breakpointFile);
    					break;
    				case '-a':
    					actTraceOnBreakpoint = true;
    					myEcho("Activating trace on breakpoint in addition to given breakpoint xml");
    					break;
    				case '-t':
    					socketTimeOut = arg.split( "=" )[1];
            			        myEcho("Using trace start timeout: " + socketTimeOut + "s");
            			        socketTimeOut = socketTimeOut * 1000;	
    					break;
    				default:
    					myEcho("Unknown option: " + opt);
    			}
        		}
      		else
    			myEcho("Invalid parameter: " + arg + ". Please check your input parameters");
        			continue;
      		}
    
    	if( deviceCCXMLFile == null || channelXMLFile == null || symbolFile == null )
      	{
    		usage();
    		throw IllegalArgumentException( "Mandatory parameter(s) missing!");
      	}
    }
    
    function communicateReadyToTrace() {
    	myEcho("Ready to trace, communicating readiness");
    	try {
    		var client = new Socket("localhost", socketPort);
    		client.close();
        	}
        	catch (err) {
            	myEcho("Can't connect to server, quit!");
    		terminateSession();
    		throw "exit";
    	}
    }
    
    function waitOnTraceTriggering() {
    	try {
    		var serverSocket = new ServerSocket(socketPort);
            	serverSocket.setSoTimeout(socketTimeOut);
    		var socket = serverSocket.accept();
    		myEcho("Client connected");
         	} 
    	catch (ste) {
    	myEcho("Socket timeout, quitting!");
    	terminateSession();
        	throw "exit";
    	}
    }
    
    function fetchLastDigit(outFile) {
    	if (outFile.indexOf(".out") !== -1) {
    		var index = outFile.lastIndexOf(".out");
    		var digit = "" + outFile.charAt(index - 1);
    		return Integer.parseInt(digit);
    	} else {
    		throw ("Could not find the .out-suffix in given String: "+ outFile);
    	}
    }
    
    function terminateSession() {
    	myEcho("Terminating session");
    	debugSession.terminate();
    	debugServer.stop();
    	script.traceEnd();
    }
    
    function chekIfFileExists(fileName) {
    	var f = new java.io.File(fileName)
    	if (!f.exists() || f.isDirectory()) {
    	myEcho("File not found or is not a file: \"" + fileName + "\" Quitting!");
    	throw "exit";
    	}
    
    }