/******************************************************************* * This sample script loads and runs a specified program on a * specified target. * * Usage: * dss runDSP.js myTargetConfig.ccxml myProgramFile.out * *******************************************************************/ // Import the DSS packages into the namespace; importPackage(Packages.com.ti.debug.engine.scripting); importPackage(Packages.com.ti.ccstudio.scripting.environment); importPackage(Packages.java.lang); // Define parameters ---------------------------- var targetConfig; // (user input) target configuration file var programName; // (user input) program to load var waitForHalt = 1; // wait for program to halt before exiting var enableLogging = 0; // enable logging var logFile = "RunProgramLog.xml"; // file where trace info is stored // Get the input parameters --------------------- var input = getArgs(); programName = input.programName; targetConfig = input.targetConfig; print("Target Config is" + targetConfig); // Create/configure scripting object ------------- // Create the scripting environment object var script = ScriptingEnvironment.instance(); // Set up the debug session ---------------------- print("*** Starting debug session..."); // Get the Debug Server debugServer = script.getServer("DebugServer.1"); debugServer.setConfig(targetConfig); // Start a Debug Session debugSessionDSP = debugServer.openSession("Blackhawk XDS560v2-LAN System Trace Emulator_0/C674X_0"); print("*** Debug Session Name: " + debugSessionDSP.getName()); print("*** Board Name: " + debugSessionDSP.getBoardName()); print("*** CPU Name: " + debugSessionDSP.getCPUName()); // Connect to the target ------------------------- try { print("*** Connecting to DSP...") debugSessionDSP.target.connect(); } catch (ex) { print(" Fail to connect to DSP..."); exitFailScript(); } // Load the program ------------------------------- print("*** Loading the program to the target...") try{ debugSessionDSP.memory.loadProgram(programName); print("*** LoadED the program to the target...") } catch (ex){ print("** cannot load program ***"); exitFailScript(); } // Restart the program ---------------------------- debugSessionDSP.target.restart(); // Run the program -------------------------------- print("*** Run Program...") debugSessionDSP.beginCIOLogging("cio.txt"); try{ debugSessionDSP.target.runAsynch(); // Run program for 5s java.lang.Thread.sleep(5000); //halt program debugSessionDSP.target.halt(); } catch (ex){ print("** cannot run program **"); exitFailScript(); } // Read timing data and save to a file var timing_address = debugSessionDSP.symbol.getAddress("TimestampArray"); debugSessionDSP.memory.saveData(Memory.Page.PROGRAM, timing_address, "timing_data.dat",3000,Memory.IOFormat.HEX,false); print("*** Stop Logging."); // Disconnect from target -------------------------- try { print("*** Disconnecting from DSP..."); // debugSessionDSP.target.disconnect(); print("*** DSP disconnected..."); } catch (ex) { // ignore if disconnect() fails - it may not be supported print("*** FAILED Disconnecting from DSP..."); exitFailScript(); } debugSessionDSP.endCIOLogging(); // All done ----------------------------- print("*** Terminating debug session..."); debugSessionDSP.terminate(); debugServer.stop(); print("*** LOAD & RUN DONE."); exitScript(); /************************************** * Get arguments from the command-line. **************************************/ function getArgs() { var args = {}; var arguments = this.arguments; if (!(arguments.length == 2)) { print( "ERROR: You did not specify the required arguments.\n" + "Usage: dss runProgram.js \n"); delete args; java.lang.System.exit(0); } args.targetConfig = arguments[0]; args.programName = arguments[1]; return args; } /************************************** * Exit the script **************************************/ function exitScript() { //if (enableLogging) // { // script.traceSetConsoleLevel(TraceLevel.INFO); // script.traceEnd(); // stop logging // } //quit(); print("runProgram Success : Exit 0\n"); java.lang.System.exit(0); } function exitFailScript() { print("runProgram Failed : Exit -1\n"); java.lang.System.exit(-1); }