/******************************************************************* * This sample script loads and runs a specified program on a * specified target. * * Usages: * dss runProgram.js myTargetConfig.ccxml myProgramFile.out * dss runProgram.js myTargetConfig.ccxml myProgramFile.out * dss runProgram.js myTargetConfig.ccxml myProgramFile.out * * Requirement: * \ccsv4\scripting\bin must be in your system path. * * You can copy and modify this script to suit your needs. ******************************************************************* * Copyright 2010-2015 The MathWorks, Inc. *******************************************************************/ // 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 boardName; // (user input) board to use (optional) var cpuName; // (user input) CPU to use (optional) var waitForHalt = 0; // 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; boardName = input.boardName; cpuName = input.cpuName; // Create/configure scripting object ------------- // Create the scripting environment object var script = ScriptingEnvironment.instance(); // Set the time out to 180 seconds // (comment this if you want to wait indefinitely) script.setScriptTimeout(180000); // Set up logging ------------------------------- if (enableLogging) { // Create a log file in the current directory to log script execution script.traceBegin(logFile, "DefaultStylesheet.xsl"); // Log everything script.traceSetConsoleLevel(TraceLevel.ALL); script.traceSetFileLevel(TraceLevel.ALL); } // Set up the debug session ---------------------- print("\n*** Starting debug session..."); // Get the Debug Server debugServer = script.getServer("DebugServer.1"); debugServer.setConfig(targetConfig); // Start a Debug Session try { debugSession = debugServer.openSession(boardName, cpuName); } catch (ex) { print("*** Cannot create a valid debug session for Board/CPU=" + boardName + "/" + cpuName + ".\n" + " Make sure this matches only one board and one CPU.\n" + " Exiting...\n"); exitScript(); } print("*** Debug Session Name: " + debugSession.getName()); print("*** Board Name: " + debugSession.getBoardName()); print("*** CPU Name: " + debugSession.getCPUName()); // Connect to the target ------------------------- try { print("\n*** Connecting to target...") debugSession.target.connect(); } catch (ex) { // ignore if connect() fails - it may not be supported } // Reset the target ------------------------------- debugSession.target.reset(); // Load the program ------------------------------- print("\n*** Loading the program to the target...") debugSession.memory.loadProgram(programName); // Restart the program ---------------------------- debugSession.target.restart(); // Run the program -------------------------------- // runAsynch() returns control immediately - it does not wait for program to halt debugSession.target.runAsynch(); if (debugSession.target.isHalted()) { print("\n*** Program failed to run. Exiting..."); exitScript(); } else { print("*** Program is running."); } // Wait for the program to halt ------------------- if (waitForHalt) { print("\n*** Waiting for program to halt..."); // Wait for the program to halt debugSession.target.waitForHalt(); if (debugSession.target.isHalted()) { print("\n*** Program is now halted."); } } // Disconnect from target -------------------------- try { print("\n*** Disconnecting from target..."); debugSession.target.disconnect(); } catch (ex) { // ignore if disconnect() fails - it may not be supported } // All done ----------------------------- print("\n*** Terminating debug session..."); debugSession.terminate(); debugServer.stop(); print("\n*** LOAD & RUN DONE."); exitScript(); /************************************** * Get arguments from the command-line. **************************************/ function getArgs() { var args = {}; var arguments = this.arguments; if ((arguments.length<2) && (arguments.length>4)) { print( "ERROR: You did not specify the correct number of arguments.\n" + "Usage: dss runProgram.js \n" + "Usage: dss runProgram.js \n" + "Usage: dss runProgram.js \n"); delete args; java.lang.System.exit(0); } // Required inputs args.targetConfig = arguments[0]; args.programName = arguments[1]; print("\n*** User inputs: "); print(" Target Configuration: " + args.targetConfig); print(" Program Name: " + args.programName); if (arguments.length >= 3) { args.boardName = arguments[2]; print(" Board Name: " + args.boardName); } else { args.boardName = "*"; // first board print(" Board Name: unspecified (connect to first board)"); } if (arguments.length == 4) { args.cpuName = arguments[3]; print(" CPU Name: " + args.cpuName); } else { args.cpuName = "*"; // first CPU on first board print(" CPU Name: unspecified (connect to first CPU)"); } return args; } /************************************** * Exit the script **************************************/ function exitScript() { if (enableLogging) { script.traceSetConsoleLevel(TraceLevel.INFO); script.traceEnd(); // stop logging } java.lang.System.exit(0); }