Code Warrior 10.2 Structure Array problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code Warrior 10.2 Structure Array problem

Jump to solution
645 Views
chris2012
Contributor II

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

0 Kudos
1 Solution
478 Views
chris2012
Contributor II

Hi Martin,

I’m very new and green with Codewarrior and RTOS so generating an open memory map is not even something I understand.

I did stumble on something that seems to have fixed my problem. Maybe you can tell what is going on by knowing what I did to fix it.

I’m using the M52235EVB.

I was defining my tasks like this:

const TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */

{ 1, main_task, 2000, 20, "Main", MQX_AUTO_START_TASK, 0, 0 },

{ 2, udp_CntrlPort_RX_task, 2000, 10, "Udp_ControlPort_RX_task", 0, 0, 0 },

{ 3, Heartbeat_task, 2000, 19, "Heartbeat", 0, 0, 0 },

{ 4, QSPI_service_task, 2000, 15, "QSPI_service", 0, 0, 0 },

{ 5, udp_send_packet_task, 2000, 16, "Udp_send_packet", 0, 0, 0 },

{ 6, udp_TestPort_RX_task, 2000, 10, "Udp_TestPort_RX_task", 0, 0, 0 },

};

I noticed that I could not call any functions from tasks, or other tasks would never run. Everything would compile, but tasks weren’t all running correctly. Then I changed the stack sizes:

const TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */

{ 1, main_task, 500, 20, "Main", MQX_AUTO_START_TASK, 0, 0 },

{ 2, udp_CntrlPort_RX_task, 500, 10, "Udp_ControlPort_RX_task", 0, 0, 0 },

{ 3, Heartbeat_task, 500, 19, "Heartbeat", 0, 0, 0 },

{ 4, QSPI_service_task, 500, 15, "QSPI_service", 0, 0, 0 },

{ 5, udp_send_packet_task, 500, 16, "Udp_send_packet", 0, 0, 0 },

{ 6, udp_TestPort_RX_task, 500, 10, "Udp_TestPort_RX_task", 0, 0, 0 },

};

And now everything works, I can create the structure array in global memory and give it a size of 10 and call functions from my tasks and everything seems to be happy now.

Can you explain this to me more? I don’t really understand what drives the stack size requirement for each task and what the limits are and how that effects things.

Thanks,

Chris Stuart

Show Systems Development

Design & Engineering

Walt Disney World

christopher.stuart@disney.com<mailto:christopher.stuart@disney.com>

Office: (407) 938-1570

Cell: (407) 902-8134

View solution in original post

0 Kudos
2 Replies
478 Views
c0170
Senior Contributor III

Hello Chris Stuart,

what version of MQX do you use and what board/mcu? I have run Hello world example modified with your structure and editing some members, on CF 51JF board with MQX 4.0 without any problems.

Check where the structure residues in memory, generate and open memory map. More questions arise, like what does happen after writing to those members.

I found your post also in CW section, pls if it gets responded there, close this one as well.

Regards,

MartinK

479 Views
chris2012
Contributor II

Hi Martin,

I’m very new and green with Codewarrior and RTOS so generating an open memory map is not even something I understand.

I did stumble on something that seems to have fixed my problem. Maybe you can tell what is going on by knowing what I did to fix it.

I’m using the M52235EVB.

I was defining my tasks like this:

const TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */

{ 1, main_task, 2000, 20, "Main", MQX_AUTO_START_TASK, 0, 0 },

{ 2, udp_CntrlPort_RX_task, 2000, 10, "Udp_ControlPort_RX_task", 0, 0, 0 },

{ 3, Heartbeat_task, 2000, 19, "Heartbeat", 0, 0, 0 },

{ 4, QSPI_service_task, 2000, 15, "QSPI_service", 0, 0, 0 },

{ 5, udp_send_packet_task, 2000, 16, "Udp_send_packet", 0, 0, 0 },

{ 6, udp_TestPort_RX_task, 2000, 10, "Udp_TestPort_RX_task", 0, 0, 0 },

};

I noticed that I could not call any functions from tasks, or other tasks would never run. Everything would compile, but tasks weren’t all running correctly. Then I changed the stack sizes:

const TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */

{ 1, main_task, 500, 20, "Main", MQX_AUTO_START_TASK, 0, 0 },

{ 2, udp_CntrlPort_RX_task, 500, 10, "Udp_ControlPort_RX_task", 0, 0, 0 },

{ 3, Heartbeat_task, 500, 19, "Heartbeat", 0, 0, 0 },

{ 4, QSPI_service_task, 500, 15, "QSPI_service", 0, 0, 0 },

{ 5, udp_send_packet_task, 500, 16, "Udp_send_packet", 0, 0, 0 },

{ 6, udp_TestPort_RX_task, 500, 10, "Udp_TestPort_RX_task", 0, 0, 0 },

};

And now everything works, I can create the structure array in global memory and give it a size of 10 and call functions from my tasks and everything seems to be happy now.

Can you explain this to me more? I don’t really understand what drives the stack size requirement for each task and what the limits are and how that effects things.

Thanks,

Chris Stuart

Show Systems Development

Design & Engineering

Walt Disney World

christopher.stuart@disney.com<mailto:christopher.stuart@disney.com>

Office: (407) 938-1570

Cell: (407) 902-8134

0 Kudos