Problem with setting a external memory location.

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

Problem with setting a external memory location.

3,418 Views
NZ_Design
Contributor I
I have a structure in my external ram. I can set a byte in one line and the next line does not work.

typedef struct
{
  volatile unsigned bOutFired:1;
  volatile uchar    cOutExit;
  volatile uchar    cBatchExit;
  volatile uchar    cLabelPoint;
  volatile uchar    cFruitSize;
  volatile uint     iFruitWeight;
}BED;


BEDFruitBed[16][512];

uint iLoadcellPoint;            //   Gloabal variable  located at 0x225C42'G
uint cTstOut;                     //   Global variable    located at 0x301A


cLane is uchar passed into the routine.
cOutPointer is uchar decleared in the routine.

FruitBed[cLane][iLoadcellPoint].cOutExit = cTstOut;               // Store outlet to exit in bed
          // This line loads the cTstExit into the memory location correctly every time.
          // This line is put in to test the next line. As this line works in another piece of code.

FruitBed[cLane][iLoadcellPoint].cOutExit = cOutPointer;         // Store outlet to exit in bed
          // This line does nothing this is the line that needs to work.

I have tried to declear cOutPointer as a volatile uchar. With no change.

Does anyone have any clues or have a rule for declearing data as I have found Codeworrier to be quite finiky about home data is decleared.



Labels (1)
0 Kudos
Reply
5 Replies

862 Views
Lundin
Senior Contributor IV
Spontaneously, I would say the problem is likely caused by the non-standard bitfield that is your struct. How that struct behaves when it comes to memory alignment, msb/lsb, big/little endian and struct padding is all completely undefined by the C standard. It might very well be a padding byte that is written to.

So how that particular code behaves is entirely up to the non-standard parts of the specific version of Codewarrior that you have.

The best solution to this is to get rid of bitfields entirely and use bit masks and the bitwise operators instead.
0 Kudos
Reply

862 Views
bigmac
Specialist III
Hello,
 
If Lundin's theory is correct, making the bit field the last element of the structure might have some effect   Perhaps it needs to be declared as unsigned int.
 
Regards,
Mac
 
0 Kudos
Reply

862 Views
CrasyCat
Specialist III
Hello
 
- Which CPU are you targeting (HC08, HC12, Coldfire, ..)
- Which version of CodeWarrior are you using?
To retrieve that info:
- Start CodeWarrior
- Select Help -> About Freescale CodeWarrior
- Click on "Install Products"
- CodeWarrior version used is displayed on top in the Installed Products dialog.
 
CrasyCat
0 Kudos
Reply

862 Views
NZ_Design
Contributor I
To answer crasyCat.
   MC9S12XDP512MAG is the processor with
   CodeWarrier IDE 5.7
   Freescale HC12,HC12x,HCS12x version 4.5

To Answer Lundin reply. Yes have thought of the bit field and therefore changed it to a uchar as it would use that amount of visical memory anyway.

This had no effect.

To perplex it even further if cOutPointer is decleared at 0x281A then the code works but if it is at location 0x36A2 it dosnt work.

Removing the volatile as the whole structure is decleared volatile seemed to allow a memory location of 0x36A2 to work as well also the bit field is deleared as an unsigned char unsigned int is no different.

I shell try and set it up with bit masks and see what happens.

Thanks for your surgestions

0 Kudos
Reply

862 Views
NZ_Design
Contributor I
After a days work converting the bit fields over it is looking like it works.

Thanks
0 Kudos
Reply