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.

CCS/MSP430FR2355: Is it possible to run Java code as a initialization script in the debugger? Or as a prebuild step? OR have Javascript call java code from the initialization script of the debugger?

Part Number: MSP430FR2355

Tool/software: Code Composer Studio

 I have a piece of Java code I've written that takes program memory and parses it into another format I need. 

Goal: I would like to run this Java code as a initialization script in the debugger or a pre-build command in the build step. 

Question: Is this possible? Could you point me to any resources available detailing how to do this? I know the DSS runs on Java commands and I have gotten some of the functionality I need using JavaScript commands.  Could anyone point me to some documentation or give a step by step guide on how this might be accomplished? 

I've included my java code below. It functions as designed, but I would like to have it run as a script when the debug button is pressed, or have a script call it. 

Thank you for your help making this more clear. 



//IMPORT STATEMENTS
import com.ti.ccstudio.scripting.environment.*;
import com.ti.debug.engine.scripting.*;
import java.io.*;




/* VARIABLE DECLARATIONS */

// SEE README FOR INSTRUCTIONS ON OPERATING THIS CODE


/*
* Main Program Goal: Automate the creation of VHD MEMORY.
*
* Details of class functions:
*
* This class takes advantage of the DSS SCRIPTING ENVIRONMENT of Code Composer Studio.
* The code here was written to act as an Initialization Script in the Debug Configurations of the IDE Code Composer Studio.
*
* Program Flow:
* */
public class VHD_MEMORY_AUTOMATION {

public static void hex_Parse() {
System.out.println("HEXPARSE!");

int start = 32768;
int first = 0;


try (BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\blake\\Internship\\src\\META-INF\\program_memory.vhd",true))) {

System.out.println("FIRSTWRITE!");
bw.write("library IEEE;\n" +
"use IEEE.std_logic_1164.all;\n" +
"use IEEE.numeric_std.all;\n" +
"\n" +
"\n" +
"entity program_memory is\n" +
" port ( clock\t: in\tstd_logic;\n" +
"\t MAB\t\t: in\tstd_logic_vector(15 downto 0);\n" +
"\t MDB_in \t: out\tstd_logic_vector(15 downto 0);\n" +
"\t MDB_out \t: in\tstd_logic_vector(15 downto 0);\n" +
"\t write\t : in\tstd_logic);\n" +
"end entity;\n" +
"\n" +
"architecture program_memory_arch of program_memory is\n" +
"\n" +
" type rom_type is array (32768 to 65535) of std_logic_vector(7 downto 0); -- this is MAB: x8000 to xFFFF\n" +
"\n" +
" constant ROM : rom_type :=(");
bw.flush();
bw.close();


} catch (IOException e) {
e.printStackTrace();
}
System.gc();

try{
System.out.println("SECONDWRITE!");
BufferedWriter ZW = new BufferedWriter(new FileWriter("C:\\Users\\blake\\Internship\\src\\META-INF\\program_memory.vhd",true));


BufferedReader reader = new BufferedReader(new FileReader(
"C:\\ti\\hex_output.txt"));
String line = reader.readLine();

while (line != null) {
if (line.compareTo("0xFFFF") != 0) {
System.out.println(line);
System.out.println("COMPARE FFFF");
System.out.println( line.compareTo("0xFFFF") != 0);

switch (first) {

//Ignore first line
case 0:
System.out.println("IGNORE! "+line);
first = 1;
break;

//Special Case first line needs unique spacing
case 1:
System.out.println("FIRST LINE!"+line);
System.out.println(line.charAt(0));
System.out.println(line.charAt(1));
System.out.println(line.charAt(2));
System.out.println(line.charAt(3));
System.out.println(line.charAt(4));
System.out.println(line.charAt(5));


first = 2;
line = line.replace("\n", "");
ZW.write(start + " => x"+ "\"");
ZW.write(line.charAt(4));
ZW.write(line.charAt(5));
ZW.write( "\""+"," +"\n");

start++;

ZW.write(" ");
ZW.write(start + " => x\"" + line.charAt(2) );
ZW.write(line.charAt(3) + "\"" + ',' +'\n');



start++;
break;
// all other cases fall into this category.
case 2:
System.out.println("SECOND LINE! "+line);
line = line.replace("\n", "");

ZW.write(" ");
ZW.write(start + " => x\"" + line.charAt(4));
ZW.write(line.charAt(5) + "\"" + ',' +'\n');

start++;
ZW.write(" ");
ZW.write(start + " => x\"" + line.charAt(2));
ZW.write(line.charAt(3) + "\"" + ',' +'\n');

start++;



break;
default:
throw new IllegalStateException("Unexpected value: " + first);

}
line = reader.readLine();
}else break;




}
System.out.println("LASTWRITE!");
ZW.write(" -- IRQ Vectors\n" +
" 65534 => x\"00\", -- Reset Vector = xFFFE:xFFFF\n" +
" 65535 => x\"80\", -- Startup Value = x8000\n" +
"\n" +
" others => x\"00\");\t\n" +
"\n" +
" signal EN : std_logic;\n" +
"\n" +
" begin\n" +
" -- Note 1: The bus system uses a 16-bit Address (MAB)\n" +
" -- This address size can access locations from x0000 to xFFFF\n" +
" -- But our array is only defined from x8000 to xFFFF and\n" +
" -- if we try to access it with any other address, it will crash.\n" +
" -- So the first thing we need to do is create a local enable that\n" +
" -- will only assert when MAB is within x8000 to xFFFF.\n" +
" \n" +
" LOCAL_EN : process (MAB) \n" +
" begin\n" +
" if ( (to_integer(unsigned(MAB)) >= 32768) and (to_integer(unsigned(MAB)) <= 65535)) then\n" +
" EN <= '1';\n" +
" else \n" +
" EN <= '0';\n" +
" end if;\n" +
" end process;\n" +
"\n" +
"\n" +
" -- Note 2: The bus system uses a 16-bit Address (MAB)\n" +
" -- The MDB_out is also provided as a 16-bit word\n" +
" -- However, the memory array is actually built as 8-bit bytes.\n" +
" -- So for a given 16-bit MAB, we give MDB_out = HB : LB\n" +
" -- or = ROM(MAB+1) : ROM(MAB)\n" +
"\n" +
" MEMORY_ROM : process (clock) \n" +
" begin\n" +
" if (rising_edge(clock)) then\n" +
" if (EN='1' and write='0') then \n" +
" MDB_in <= ROM(to_integer(unsigned(MAB)) + 1 ) & ROM(to_integer(unsigned(MAB))); \n" +
" end if;\n" +
" end if;\n" +
" end process;\n" +
"\n" +
"\n" +
"end architecture;");

reader.close();
ZW.close();




} catch (IOException e) {

e.printStackTrace();
}



public static void main(String[] args) {

int IOMEMORY_HEX = 1;
int PAGE_PROGRAM = 0;

// Create our scripting environment object - which is the main entry point into any script and
// the factory for creating other Scriptable servers and Sessions

ScriptingEnvironment scriptEnv = ScriptingEnvironment.instance();


try {

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

scriptEnv.traceBegin("VHD_MEMORY_LOG.xml");
DebugServer debugServer = null;
DebugSession debugSession = null;

// Log everything
scriptEnv.traceSetConsoleLevel(TraceLevel.ALL);
scriptEnv.traceSetFileLevel(TraceLevel.ALL);

debugServer = (DebugServer) scriptEnv.getServer("DebugServer.1");
debugServer.setConfig("C:/Users/blake/ti/CCSTargetConfigurations/NewTargetConfiguration.ccxml");

debugSession = debugServer.openSession(".*");

debugSession.target.connect();

//Set our TimeOut
scriptEnv.setScriptTimeout(15000);

debugSession.memory.loadProgram("C:\\Users\\blake\\workspace_v10\\Asm_AddrMode3_Absolute\\Debug\\Asm_AddrMode3_Absolute.out");

debugSession.memory.saveData(PAGE_PROGRAM,0x8000,"C:\\ti\\hex_output.txt",0x800,IOMEMORY_HEX,false);

hex_Parse();




} catch (ScriptingException e) {
scriptEnv.traceWrite("ERROR");
e.printStackTrace();
}
}
}