AnsweredAssumed Answered

Code Warrior 10.2 Structure Array problem

Question asked by chris2012 on Feb 4, 2013
Latest reply on Feb 5, 2013 by chris2012

I have a question for whoever can possibly help me. I'm working with an embedded coldfire processor, using Code Warrior 10.2 and MQX RTOS.

 

As I mentioned, I’m using the MQX operating system which Im still very green with. I havnt worked with RTOS's before this project.

 

In my project right now I have about 8 different tasks set up including my “main” task. I have a number
of global variables declared, and each task has a few local variables declared
as well. Everything has worked fine to this point, but, for the first time, I just tried to declare
a simple structure array as a global variable:

 

//----------------------------------------------------------------

  

typedef struct {

     unsigned int Action;  
   unsigned int ActionID;   

      char FileName[50];    

      unsigned int Time;

 

}sAction;

 

sAction Actions[10];

//-------------------------------------------------------------------

  

The code compiles, but if I have a line in main that writes to a member of this structure array such as:

 

  Actions[0].ActionID = 0;

  

My code hangs up somewhere in the operating system kernel and nothing ever runs in any task. I started changing and testing
every variation that I could and simply got much more confused. For instance:

  

The line of code that assigns 0 to a member (above) does not even have to execute. If it is compiled into
the code, nothing runs. If I comment the line out, everything runs, but with it in, its under an “if” statement that isn’t even true.

  

If I change the number of elements in the structure array to be less than 6, My code runs and everything is fine.

 

I can take this structure array completely out and instead create a simple array like this:

//-------------------------------------------------------------

 

Unsigned int Test[300];

 

Test[0] = 0;

//-------------------------------------------------------------

 

And my code runs fine.. so I don’t think it’s a memory issue.

 

if I knock my structure down to simply be:

//-----------------------------------------------------------

 

typedef struct {

     unsigned int Action;  
  }sAction;

 

sAction Actions[30];

 

//---------------------------------------------

 

It runs fine. However, if I do this:

//---------------------------------------------

 

typedef struct {

     unsigned int Action;  
   unsigned int ActionID;   

     

}sAction;

 

sAction Actions[10];

//-----------------------------------------------------------------------------

 

it no longer works, unless, as I mentioned, I make the array less than 6 elements.

 

 

If I create the structure array inside of a task, everything is fine. I can make it a structure array of 200
and its still fine. This is only if I’m trying to make it global.

  

Any ideas? Could this be an optimization thing or a MQX thing? Am I missing something?

 

 

Thanks!

 

Chris

 

Outcomes