9S12XS/XE Reading FAR Memory - Addressing issue in DataFlash

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

9S12XS/XE Reading FAR Memory - Addressing issue in DataFlash

3,028 Views
Heppell
Contributor II
Hi, I've written a dataflash "driver" which writes data into the DF, it also needs to read the dataflash and compare with the original data to be written in order to complete.

So the dataflash is being written, thats working fine, but I cannot get my read and verify code to work, I think it is an error in the way I am writing my code below, Could someone Help?


/* Verify Write Operation */
df_ptr = (UINT8 @far *)(0x100000u | dfInfo.saved.dfAddress);

while ((*df_ptr == *dfInfo.saved.ramAddress) && (dfInfo.saved.totalCount > 0u))
{
   df_ptr++;
   dfInfo.saved.ramAddress++;
   dfInfo.saved.totalCount--;
}
if (dfInfo.saved.totalCount > 0u) { ..error.. }

Thanks!
-Rene

Labels (1)
0 Kudos
7 Replies

694 Views
Heppell
Contributor II
UINT8 @far * df_ptr;

struct s_dfInfo
{
   CALLBACK callbackFn;
   UINT16 callbackParam;
   BOOL lastWriteStatus;
   BOOL bWriteDisable;
   UINT8 state;
   struct s_dfAddressInfo current;
   struct s_dfAddressInfo saved;
};

struct s_dfAddressInfo
{
   UINT16 totalCount;
   UINT16 dfAddress;
   UINT8* ramAddress;
};

struct s_dfInfo dfInfo;
0 Kudos

694 Views
Pedro_
Contributor III
After a quick experiment, something like this will work
 
static @far @eeprom word wBaseAddr @0x100000;
wValueInDFlash = *(&wBaseAddr + wOffset);
I hope it helps.
 
0 Kudos

694 Views
Heppell
Contributor II
I've changed the code as per your advice, and I still can't get this to work properly. I'm also not sure about the @eeprom flag, which I tried with or without, but with no luck.


   UINT8 @far * df_ptr;
   static @far UINT16 wBaseAddr @0x100000;

         df_ptr = (&wBaseAddr + dfInfo.saved.dfAddress);

         while ((*df_ptr == *dfInfo.saved.ramAddress) && (dfInfo.saved.totalCount > 0u))
         { ... is not satisfied, but should be ... }


0 Kudos

694 Views
Pedro_
Contributor III
Not having used the @eeprom modified, the compiler will not resolve the pointer assignement as you have coded.
@far data and @far @eeprom (dflash or eee) correspond to different sections of the memory map.
 
try something like this.
 
static @far @eeprom UINT8 wBaseAddr @0x100000

while(dfInfo.saved.totalCount > 0)
{
  if ( *(&wBaseAddr+Offset) != *(dfInfo.saved.ramAddress+Offset) )
  {
    /* doesnt match */
   break;
  }

  Offset
++;
  dfInfo
.saved.totalCount--;
}

The controller is able to access 16bit data, so you should probably use UINT16 for both the wBaseAddr and the ramAddress rather than UINT8

0 Kudos

694 Views
Heppell
Contributor II
Thanks for helping out Pedro!

I'm still having issues getting these two statements to match, heres my latest code attempt:

static @far @eeprom UINT16 wBaseAddr @0x100000;
...
if ( (UINT8)(*(&wBaseAddr+dfInfo.saved.dfAddress+Offset)) != (UINT8)(*(dfInfo.saved.ramAddress+Offset)) )
{ ...

Where:
dfInfo.saved.dfAddress = 0
dfInfo.saved.ramAddress = 0xffff4
Offset = 0

sizeof(dfInfo.saved.ramAddress) = 8 <-- has to be kept at UINT8
sizeof(Offset) = 16
sizeof(dfInfo.saved.dfAddress) = 16

Viewing memory at 0x100000 shows 48 65 6c 6c 6f...
Viewing memort at 0xffff4 shows 48 65 6c 6c 6f...

0 Kudos

694 Views
Heppell
Contributor II
Changing the line
static @far @eeprom UINT16 wBaseAddr @0x100000;
to
static @far @eeprom UINT8 wBaseAddr @0x100000;

Now fixes the code! Thanks alot for the help Pedro!
0 Kudos

694 Views
Pedro_
Contributor III
The problem might be related to the way you have declared the pointer
 
try
 
@far @eeprom char *df_ptr
 
what type is dfInfo.saved.ramAddress ?


Message Edited by Pedro_ on 2009-01-20 12:09 PM
0 Kudos