Re: FAR data lost after reset or power off.

"'John Stanley' rizklyf02-O/[email protected] [rabbit-semi]" <[email protected]> Tue, 4 Aug 2015 03:24:05 -0500
Newsgroups gmane.comp.hardware.rabbit-semiconductor
Message-ID <[email protected]>
Four things you need to keep in mind:

1) You need to allocate your bbram memory block in your startup thread
BEFORE you start any multi-threading or you risk another thread (or the OS)
grabbing your memory out of sequence.  (See definition for "race
condition"...)
2) You need to use _xalloc, NOT xalloc to allocate bbram.  (Use XALLOC_BB
as the third parameter.)
3) Set specific semi-random (pre-selected) data values in ram before and
after your "database".  (Four bytes for each is usually enough.  Increase
your allocated block to accommodate these fence-post markers.)  Check these
after you allocate the memory block to see if the block has valid data or
needs to be initialized.  If you do initialize it, remember to add the
fence-post marker data-values to show it's been initialized.
4) Remember that your data space is 4 bytes after the start of the
allocated data block because you added the fenceposts in step 3.  Set your
public "database" pointer accordingly, once, and then forget about it.

Good luck.
.... John L. Stanley (Senior Software Engineer)




On Mon, Aug 3, 2015 at 10:22 PM, [email protected] [rabbit-semi]
rabbit-semi-at-yahoogroups.com |yahoo/Example Allow| <
biosvrdert-O/[email protected]> wrote:

>
>
> Hi,
> I declared array as follow:
>
> typedef struct{
>     unsigned char name[NAME_LEN+1];
>         unsigned int age;
>
> }Member_t;
>
>
> far  Member_t * PtrToFamilyMemberFile = 0;
> far  char  * FamilyMemberFilePtr = 0;
>
> void FamilyMember_Initalization(void)
> {
>     FamilyMemberFilePtr = (far char*) xalloc( sizeof(long) +
> 1L*MAX_MEMBERS*sizeof(Member_t) );
>     PtrToFamilyMemberFile = (far Member_t*)(FamilyMemberFilePtr + 4);
>     *((far long*)FamilyMemberFilePtr) = 1L*MAX_MEMBERS*sizeof(Member_t);
>  // Size of data section
>      _f_memset( PtrToFamilyMemberFile, 0, 1L*MAX_MEMBERS*sizeof(Member_t)
> );    // Clear data
> }
>
> Whenever I wish to store to any value, I would do the following:
>
> _f_strcpy(PtrToFamilyMemberFile[2].name,"Elizabeth");
> or
> PtrToFamilyMemberFile[2].age = 23;
>
> Whenever I want to retrieve any data, I would do the following:
>
> _f_strcpy(name,PtrToFamilyMemberFile[2].name);
> sprintf(ans1,"\"member\": \"%s\" ", name);
> printf("\n Name is %s", name);
>
> printf("\nAge is %d", name);
>
> Everything works fine but if I reset or remove power, all stored data are
> lost.  What am I doing wrong?
>
>
>
>
> 
>