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.

Getting Local Variable Values in DSS Javascript



Hi everyone,

I am trying to build an interface on the DSS using javascript to access and write data on local variables. I tried to follow the online examples in the webinar but they've set a breakpoint on 'main' and halted in success.

My code is along these lines:

void main(void){

....

int x=0;

....

x+=1;

while(1){

...

}

}

- All i want to do is to connect with this code using JS embedded in a web based user interface that can should display the value of 'x' and user must be able to set the value of 'x'. Please provide a bare minimum code snipped in javascript.

Thanking in advance

  • Hi Shoaib,

    I am not sure about the javascript code, but you definitely are going to want to make 'x' into a global and volatile variable:

    volatile int16 x; //declare x outside of main

    void main void{

    ...

    x = 0; //initialize x inside main

    ...
    }
  • Hi David,

    Thank you for your prompt response. Actually what Im trying to do is to interface with the CSS's debugger through DSS apis. I want to do this in the Javscript so I can probe the local variable values in the CSS through DSS's layer. In this case i think the solution you posted will not serve my needs.
  • Hi Shoaib,

    Your question is a two part process:

    1. C Code

    As Devin already suggested before, you will want to make the variable you are probing global.

    2. DSS using JS

    Every opened instance of CCS has an active JS session available so you can try the JS code that probes the global variable in the scripting console. After you get that working, you will need that to be headless (doesn't require CCS to be opened). There are plenty of examples along with documentation for headless JS to the DSS in 'ccsvx/ccs_base/scripting'

  • Hi Frank,

    Thanks for your response. As you suggested (1) I've already made my variables of interest as volatile global. I went over the examples (2) but all i am looking for is those exact api calls for getting/setting my global variables. Personally, i found out the JS Api lacking documentation. If you can provide a simple working example snippet I'll really appreciate that.

    Have a nice day
  • Hi Shoaib,

    The API is Java not JS and you can find JavaDoc for the DSS API in "\ti\ccsvx\ccs_base\scripting\docs\DS_API\index.html".

    Also, you can find the getting started with DSS in "\ti\ccsvx\ccs_base\scripting\docs\GettingStarted.htm". The getting started is very helpful and explains how to interface with the DSS with not just JS but any scripting language that can call Java classes.

    When you open the scripting console in CCS, a debug server is already created and stored in the 'ds' variable.

    So with that, you call

    ds.setConfig('your_target_config_file.ccxml'); // This sets your target configuration file

    var debugSession = ds.openSession("*","C28xx_CPU1"); // This opens a session to the specified cpu. Note that openSession is an overloaded method and there are other ways to call it. You can find it in the API doc.

    debugSession.target.connect(); // This connects to the cpu that you opened the session to.

    var x_address = debugSession.symbol.getAddress("x"); // This retrieves the address of your global variable x.

    debugSession.memory.writeData(1, x_address, your_data, 16); // This writes your_data to the global variable x.

    debugSession.target.run(); // This runs your code.

    var x_result = debugSession.memory.readData(1,x_address,16, 1); // This reads your variable x after your code has run

    // Cleanup

    debugSession.target.disconnect();

    debugSession.terminate();

    Hope this helps.

  • Hi,

    Thanks for your detailed response. I've one more question about my global variables. Is that possible I can associate an event to my variable and trigger a callback function whenever
    the value of the variables changes.

    e.g.

    int my_var=0;

    void my_isr(){ // an interuppt service routine called in response to an internal timer

    my_var+=1;
    }

    //On Javascript side, Im looking for something this

    ds.ObserveValueChange("my_var",function(){

    //do something on my var as response
    my_var-=1;

    });
  • Hi Shoaib,

    I don't think the debug server fires a value change event directly but rather an onRefresh() event when something happens on the device which might not be what you are looking for. I have honestly never used the event part of the API so won't be of much help there. If that is something you require, you can post a separate thread with that specific question.