Unable to view variable data stepping through code with MQX on TWRK60N512

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

Unable to view variable data stepping through code with MQX on TWRK60N512

1,208 Views
khoanguyen
Contributor I

Hi,

I've modified the mutex example for MQX 3.8.1 to have 4 instances of the Print_task(). I'm trying to add a time delay to the task depending on

the "tag" I specified to be the first character of the string and depending on that value it would create a time delay for that instance before sending out.

Is this a code problem or is it a conceptual problem because I'm unable to see the variable data while stepping through the code for both "initial_data" and "tag" variables. I've attached some screenshots to show what I mean.

The reason I'm doing this is because I plan on creating a  code with GPIOS that send the data from each GPIO with a time delay depending on which GPIO it is coming from. Any advice on this subject would be greatly helpful in my project.

Thanks,

Khoa Nguyen

* $FileName: main.c$

* $Version : 3.8.11.0$

* $Date    : Oct-4-2011$

*

* Comments:

*

*   This file contains the source for the mutex example program.

*

*END************************************************************************/

#include <mqx.h>

#include <bsp.h>

#include <mutex.h>

#if ! BSPCFG_ENABLE_IO_SUBSYSTEM

#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option.

#endif

#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED

#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option.

#endif

#if ! MQX_HAS_TIME_SLICE

#error This application requires MQX_HAS_TIME_SLICE defined non-zero in user_config.h. Please recompile kernel with this option.

#endif

/* Task IDs */

#define MAIN_TASK     5

#define PRINT_TASK    6

extern void main_task(uint_32 initial_data);

extern void print_task(uint_32 initial_data);

const TASK_TEMPLATE_STRUCT  MQX_template_list[] =

{

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

    { MAIN_TASK,    main_task,  1000,   8,          "main",     MQX_AUTO_START_TASK, 0,     0 },

    { PRINT_TASK,   print_task, 1000,   9,          "print",    MQX_TIME_SLICE_TASK, 0,     3 },

    { 0 }

};

MUTEX_STRUCT   print_mutex;

/*TASK*--------------------------------------------------------

*

* Task Name : main_task

* Comments  : This task creates a mutex and then two

*             instances of the print task.

*END*--------------------------------------------------------*/

void main_task

   (

      uint_32 initial_data

   )

{

   MUTEX_ATTR_STRUCT mutexattr;

   char*             string1 = "1 ONE task\n";

   char*             string2 = "2 TWO task\n";

   char*             string3 = "3 THREE task\n";

   char*             string4 = "4 FOUR task\n";

   /* Initialize mutex attributes */

   if (_mutatr_init(&mutexattr) != MQX_OK) {

      printf("Initialize mutex attributes failed.\n");

      _task_block();

   }

  

   /* Initialize the mutex */

   if (_mutex_init(&print_mutex, &mutexattr) != MQX_OK) {

      printf("Initialize print mutex failed.\n");

      _task_block();

   }

   /* Create the print tasks */

   _task_create(0, PRINT_TASK, (uint_32)string1);

   _task_create(0, PRINT_TASK, (uint_32)string2);

   _task_create(0, PRINT_TASK, (uint_32)string3);

   _task_create(0, PRINT_TASK, (uint_32)string4);

   _task_block();

}  

/*TASK*--------------------------------------------------------

*

* Task Name : print_task

* Comments  : This task prints a message. It uses a mutex to

*             ensure I/O is not interleaved.

*END*--------------------------------------------------------*/

void print_task

   (

      uint_32 initial_data

   )

{

    int tag;

   

   while(TRUE) {

      if (_mutex_lock(&print_mutex) != MQX_OK) {

         printf("Mutex lock failed.\n");

         _task_block();

      }

     

      tag = (int)initial_data;       // <--------------------------------------------------------------------------------- unable to see tag or initial_data (in screenshots)

     

      switch(tag){

           case 5:

                 _time_delay(1000);

               break;

           case 2:

                 _time_delay(2000);

                 break;   

           case 3:

                 _time_delay(3000);

                 break;

           case 4:

              _time_delay(4000);

                 break;

                 }

     

      _io_puts((char *)initial_data);

      _mutex_unlock(&print_mutex);

   }

}

/* EOF */


0 Kudos
12 Replies

691 Views
DavidS
NXP Employee
NXP Employee

Hi Khoa,

Can you see the variable in the "Variables" tab/window which is two tabs to the left of your "Expressions" tab?

Once the "Variables" window is displayed, if you want to see a global variable, right click in the window and select "Add Global Variables" and pick which one to view.

Regards,

David


0 Kudos

691 Views
khoanguyen
Contributor I

Hi David,

I forgot to include that I have tried this method but I'm still unable to locate the initial_data variable in either window. I've attached a screenshot of your method.

On a similar note, I also tried to view string variables where the initial_data came from but I wasn't able to see any of the strings in the variables or expressions window. Where is this data being stored since I'm unable to find the memory location for these using the aforementioned windows.

Thanks,

Khoa Nguyen

variable.PNG

0 Kudos

691 Views
c0170
Senior Contributor III

Hello Khoa Nguyen,

first of all, why is your concern the parameter? You copy it into tag variable which is in variables window and you can see it's value which is an address of an "array of char".

Your program creates one instance task print and it's input parameter is implicitly cast to uint32. It's pointer's address which points to an array of char which is casted. Therefore your label sentence switch does not work as you expected. If you want to pass a string and use it as an expression in switch, you can use atoi for example (for you string it would return 0). You would find out if you provided default label.

Regards.

MartinK

0 Kudos

691 Views
khoanguyen
Contributor I

So the initial_data is just an address to the array of characters, I understand that now.

I was trying to see the "array of characters" data so I could create a switch statement based on the first character.

For instance if the string was "1 data one" I wanted to create the switch statement based on the character "1." Further on in the code was "_io_puts((char*)initial_data" which prints off that array of characters, but isn't that just type casting the address of the array of characters? This was the part that confused me.

Am I supposed to write "(char *)initial_data" in the expressions window to see the active data? I tried that and it didn't work.

Again my goal is to use the variables/expressions window to view which data is being sent, not by task, but by something I can navigate to in memory.

Thanks,

Khoa Nguyen

0 Kudos

691 Views
DavidS
NXP Employee
NXP Employee

Hi Khoa,

Please try following:

unsigned char tag; 

// int tag;

tag = (unsigned char)initial_data; 

// tag = (int)initial_data;

switch((int)tag){

Regards,

David

0 Kudos

691 Views
khoanguyen
Contributor I

Hi,

I've tried that method and I'm still getting the "undefined identifier in expression" error. I've attached a couple screenshots. Could this watch expression problem be due to MQX and how it runs? The reason I ask is because I've tried adding code (just variable declarations and some if statements) but I'm unable to see any variable data in those windows.

Thanks,

Khoa Nguyen

Capture1.PNGCapture2.PNG

0 Kudos

691 Views
c0170
Senior Contributor III

Hello,

You do not use that variable and compiler might optimize it away. What is the target (debug/release) . Are optimizations on?

Anyway, this is CodeWarrior related question with expression tab error . Strange,in variables tab, the value of it is shown.

Regards,

MartinK

0 Kudos

691 Views
khoanguyen
Contributor I

Hi Martin,

I'll try posting this question in the codewarrior section. The reason I posted in the MQX forum is because I'm using MQX and I've ran C code without using MQX RTOS and the "watch expressions" window worked during debugging. Which optimizations are you referring to? I'm having trouble finding it, is the attached screenshot correct?

Capture.PNG

Thanks again for your help,

Khoa Nguyen

0 Kudos

691 Views
DavidS
NXP Employee
NXP Employee

Hi Khoa,

I'm not an expression expert but since the tag variable is in a register, maybe that is why the expression is not working?

Have you tried making tag a "volatile".

Regards,

David

0 Kudos

691 Views
khoanguyen
Contributor I

Hi,

Wouldn't the volatile method be unstable when declaring variables in MQX tasks?

Thanks,

Khoa Nguyen

0 Kudos

691 Views
DavidS
NXP Employee
NXP Employee

Hi Khoa,

I was only giving you something else to try. Volatile only ensures that a variable will be checked directly (think of accessing a UART register...the volatile forces the compiler code to access the register directly).

In your example the variable is always in a register and the "C" scope of the variable is short lived.

I'm just guessing when a variable is only contained in a register and not a memory location the expression doesn't work.

Regards,

David

0 Kudos

691 Views
khoanguyen
Contributor I

Hi David,

Yes I've tried the volatile method and still receiving the same result. Also, there seems to be several posts about turning optimizations on and off, was the way I was doing it correct? (from previous post)

Capture.PNG

Thanks,

Khoa Nguyen

0 Kudos