AnsweredAssumed Answered

Error using macros with structures

Question asked by kbrafford on Apr 13, 2010
Latest reply on Apr 15, 2010 by kbrafford

I am trying to use the <cycle_count.h> facilities in my application.  In my C file I have a static structure that I use to hold all of the data use in the module:

 

static struct driver_data {

   unsigned short int                 channel_number;

   union {

      cycle_t           cycles_64;

      unsigned long int cycles_32[2];

   }                                  final_count;

   cycle_t                            start_count;

} mb_self;

 

Early in my application I want to initilize my mb_self.start_count field, so I do this:

 

START_CYCLE_COUNT(mb_self.start_count);

 

However this causes an exception with the very first [P1] write, even though it appears that the compiler correctly has P1 pointing to a point 10 bytes into the mb_self structure.  That is, mb_self is located at 0xFF805560, and the assembly for the START_CYCLE_COUNT looks like this:

 

P1.L = 0x556A

P1.H = 0xFF80

R2 = CYCLES

R1 = CYCLES2

[P1] = R2                ; // BOOM, ROASTED here

[P1 + 0x04] = R1

 

However, if I take my cycle counter variable out of the structure:

 

static struct driver_data {
   unsigned short int                 channel_number;
} mb_self;

 

union {
   cycle_t           cycles_64;
   unsigned long int cycles_32[2];
}                                     g_final_count;
cycle_t                               g_start_count;

 

    ...

    START_CYCLE_COUNT(g_start_count);

    ...

 

the START_CYCLE_COUNT macro seems to work.

 

The same problem then still exists for my union.  If I use g_final_count.cycles_64, it fails.  But if I make g_final_count be its own global cycles_t type, then the macro doesn't except.

 

Why is that?

 

--Keith Brafford

Outcomes