EmbeddedRelated.com
Forums
The 2026 Embedded Online Conference

Declare variables as FAR but variable lost after reset or power off

Started by tcousins August 4, 2015
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 this value, I would do the following:

_f_strcpy(PtrToFamilyMemberFile[2].name,"Elizabeth");   
or 
PtrToFamilyMemberFile[2].age = 23;

Everything works fine but if I reset or remove power, all stored data are
lost.  What am I doing wrong?




---------------------------------------
Posted through http://www.EmbeddedRelated.com
On 2015-08-04, tcousins <107614@EmbeddedRelated> wrote:
> > Whenever I wish to store to this value, I would do the following: > > _f_strcpy(PtrToFamilyMemberFile[2].name,"Elizabeth"); > or > PtrToFamilyMemberFile[2].age = 23; > > Everything works fine but if I reset or remove power, all stored data are > lost. What am I doing wrong? >
You have told us nothng about the hardware in use or why you think declaring something as far is enough to guarantee persistent memory. IOW, you need to provide a _lot_ more information than you currently have done. :-) Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world
On Tue, 4 Aug 2015 15:17:21 +0000 (UTC), Simon Clubley
<clubley@remove_me.eisner.decus.org-Earth.UFP> wrote:

>On 2015-08-04, tcousins <107614@EmbeddedRelated> wrote: >> >> Whenever I wish to store to this value, I would do the following: >> >> _f_strcpy(PtrToFamilyMemberFile[2].name,"Elizabeth"); >> or >> PtrToFamilyMemberFile[2].age = 23; >> >> Everything works fine but if I reset or remove power, all stored data are >> lost. What am I doing wrong? >> > >You have told us nothng about the hardware in use or why you think >declaring something as far is enough to guarantee persistent memory. > >IOW, you need to provide a _lot_ more information than you currently >have done. :-) > >Simon.
Also check all your include files, in case "far" has been defined as an empty string on most architectures. Of course, if this is some 8086 architecture...
On 8/4/2015 6:31 AM, tcousins wrote:

> Everything works fine but if I reset or remove power, all stored data are > lost. What am I doing wrong?
**SPECIFICALLY**, what makes you think the data should NOT be lost?
On Tue, 04 Aug 2015 08:31:17 -0500, tcousins 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 this value, I would do the following: > > _f_strcpy(PtrToFamilyMemberFile[2].name,"Elizabeth"); > or PtrToFamilyMemberFile[2].age = 23; > > Everything works fine but if I reset or remove power, all stored data > are lost. What am I doing wrong?
First, you're tossing a bunch of obviously proprietary function calls at us without telling us what tool set or processor you're using. This is like asking how many cylinders your car has without telling us make & model. Second, in tool sets where "far" is recognized at all, it's a way of addressing "big" RAM memories, not a way of addressing non-volatile memory. So: * Tell us what the processor is * Tell us what the tool chain is * Tell us where you expect things to be stored on power-down ("I don't know" is a valid answer to this question). Perhaps we can help from there. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
The 2026 Embedded Online Conference