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.

Variables declared as static or global affects C6455 DSP User Created Routines



Hello,

I am currently experiencing the following problem with the use of static or global variables with the C6455 DSP

Working Example:  Using a single source file.

static int a;However, when I try to break the above into two source files and using extern, the code starts

static int b;

static int output;

 

void PerformTest(void)

{

   a = 1;

   b = 1;

   output = 0;

 

   if((a == 1) && (b==1))

   {

      output = Test(a, b);

   }

   cout << output;

}

The above example works as I get the correct output. 

behaving abnormally.

-------------------------------------------------------------------------------------------------

 

file1.c

 

int a;

int b;

int output;

void PerformTest(void)

{

   a = 1;

   b = 1; 

   output = 0;

   TestFromFile2();

}

-------------------------------------------------------------------------------------------------

file2.c

 

extern int a;

extern int b;

void TestFromFile2(void)

{

   if(a==1) && (b==1)

   {

     output = Test(a,b);

   }

   cout << output;

}

 

Using the code above, I get a different and incorrect output than from the first example where I have a single source file with static variables.  It appears when I try to make the variables global, and do an extern on them, there is some sort of discrepancy going on, and I can’t quite figure out where the problem is.  Any help is greatly appreciated.  I included the .map file for the non working case.  Hopefully this proves useful for someone more knowledgeable than me in this area.

Note: Test(int, int) is a vendor supplied function, I have no visibility into it aside from the inputs/outputs.

 

 

 

 

 

 

  •  

    Reposted for clarification.

    Hello,

    I am currently experiencing the following problem with the use of static or global variables with the C6455 DSP

    Working Example:  Using a single source file.

    static int a;

    static int b;

    static int output;

     

    void PerformTest(void)

    {

       a = 1;

       b = 1;

       output = 0;

     

       if((a == 1) && (b==1))

       {

          output = Test(a, b);

       }

       cout << output;

    }

    The above example works as I get the correct output.  However, when I try to break the above into two source files and using extern, the code starts 

    behaving abnormally.

    -------------------------------------------------------------------------------------------------

     

    file1.c

    int a;

    int b;

    int output;

    void PerformTest(void)

    {

       a = 1;

       b = 1; 

       output = 0;

       TestFromFile2();

    }

    -------------------------------------------------------------------------------------------------

    file2.c

    extern int a;

    extern int b;

    extrn int output;

    void TestFromFile2(void)

    {

       if(a==1) && (b==1)

       {

         output = Test(a,b);

       }

       cout << output;

    } 

    Using the code above, I get a different and incorrect output than from the first example where I have a single source file with static variables.  It appears when I try to make the variables global, and do an extern on them, there is some sort of discrepancy going on, and I can’t quite figure out where the problem is.  Any help is greatly appreciated.  I included the .map file for the non working case.  Hopefully this proves useful for someone more knowledgeable than me in this area.

    Note: Test(int, int) is a vendor supplied function, I have no visibility into it aside from the inputs/outputs.

  • What output do you get?  Have you single-stepped through the code looking at the variables of interest in the watch/memory window?

  • Hello,

    Due to the code being dependent on time and the fpga, single-stepping through the code breaks it.  What I did instead was capture the variables of interest through the LOG_printf( ) and the trace buffer real-time.  I have two baselines, the working and non working.  The only difference between the two are the declaration of global variables for one and externs, and the declaration of static variables for the other.  I've taken an in-depth look at the inputs/outputs for both baselines and they match up.  The main difference here is that I have the following while loop:

    while(output==success)

    {

       output = Test(a,b);

    }

    For the working baseline, output will get a "need_more_data" return from Test(a,b) and correctly exits the while loop.  For the non working load using global variables and externs, output is always a "success" and never runs into the "need_more_data" case.  As previously mentioned, Test(int,int) is a vendor supplied routine, thus I have no visibility into it.

    Any help is greatly appreciated.

  • I moved this to the compiler forum.

    • What compiler version are you using?
    • What compiler options are you using to build your code?

    One quick thing to try might be to declare "output" as volatile.

    Brad

  • Hi Brad,

    I am currently using Code Composer 3.3.80.11

    and I'm not doing anything strange with the compiler options, I am using the mem FAR model though, everything else is pretty much left unchecked (no optimization).  Pretty much all I have is:

     -d"_DEBUG" -mv6400+ --mem_model:data=far

    along with the include paths.  I've tried making the global variables volatile and this doesn't seem to affect anything.

    Thanks for your help.

  • Make sure you #include <iostream> .  I'm not sure what to expect if you leave it out.  But inexplicable differences seem likely.

    Thanks and regards,

    -George

  • Thanks for the suggestion, however I must ask, what does including iostream do for me?  None of my source files depend on it nor do I have any routine calls dependent on it.  Also, for whatever reason, when I try to include iostream, I get about 100 errors when compiling.

     

  • The source line

    cout << output;

    makes me think this is C++ code.  Is that right?  If you don't include iostream, then what is the definition of cout?  How does it work?

    Thanks and regards,

    -George