Re: Re: FAR data lost after reset or power off.

"'John Stanley' rizklyf02-O/[email protected] [rabbit-semi]" <[email protected]> Wed, 5 Aug 2015 00:04:33 -0500
Newsgroups gmane.comp.hardware.rabbit-semiconductor
Message-ID <[email protected]>
The MemBlockMarker_t you showed in your last msg is not what I said to do.
I didn't say anything about a structure with pointers to the start and end
of the block.  I said put specific data values IN the memory block.

Your recent code example shows 4 different memory blocks.  I'll show you
how to do 1.  You might want to toss this into a function and call it once
for each block.  It's up to you.

   // begin quasi pseudo-code...

   #define BLOCK_START ((long)0x3A8446F7)
   #define BLOCK_END     ((long)0x7F6448A3)

   long tempsz;
   far char * pMemBlock;
   far long * pStartMark;
   far long * pEndMark;

   // _xalloc the data block and calculate marker locations
   tempsz = (MAX_MEMBERS * sizeof(Member_t) + 8);
   tempsz += 2 * sizeof(long);  // add room for start/end markers
   pMemBlock = (far char *) _xalloc(&tempsz, 0, XALLOC_BB);
   if (pMemBlock == NULL)
   {
      do something to let the user know the _xalloc failed
      return or reboot
   }
   pStartMark = (far long *) pMemBlock;
   pEndMark   =(far long *) (pMemBlock + tempsz - sizeof(long));

   // Check to see if the block is initialized (look for the beginning and
ending markers).
   if ((*pStartMark != BLOCK_START) || (*pEndMark != BLOCK_END))
   {
      // zero the memory block
      _f_memset(pMemBlock, 0, tempsz);
      // put markers at start and end of the memory block
      *pStartMark = BLOCK_START;
      *pEndMark = BLOCK_END;
   }
   PtrToFamilyMemberFile = (far Member_t *)(pMemBlock + sizeof(long));

If you're going to have multiple data blocks, some people might put another
block-specific data value just after the start mark.  You could also simply
increment the quasi-random start and end marker data-values both by some
block-specific value and save yourself 4 ID bytes per block.

Good luck,
.... John L. Stanley

PS:  Not sure why you had the +8 in the calculation of the tempsz value.  I
left it in.  If you don't need it, feel free to remove it.


On Tue, Aug 4, 2015 at 11:01 PM, [email protected] [rabbit-semi]
rabbit-semi-at-yahoogroups.com |yahoo/Example Allow| <
biosvrdert-O/[email protected]> wrote:

>
>
> Thx for the information.  I think I was able to allocate enough memory but
> now I am not sure how to initialize the allocated memory.  Does anyone know
> how to initialize at startup. Any help would be very much appreciated. Thx.
>
>
> typedef struct
> {
>    unsigned int ID;
>    long * start;   //4 byte to identify starting address of the database
>    long * stop;   //4 byte to identify stop address of the database
> }MemBlockMarker_t;
>
>
> void main()
> {
>     MemBlockMarker_t MemBlockMarker[4];
>    long tempsz;
>    static far MemBlockMarker_t * Ptr_MemBlockMarker;
>
>    tempsz = sizeof(Member_t);
>
>
>    tempsz = (MAX_MEMBERS * sizeof(Member_t) + 8);
>    printf("\n Total Desired allocate byte = %ld \n",tempsz);
>    printf("\nBefore xAvail reports (Member) = %ld free\n", _xavail(NULL,
> 0, XALLOC_BB));
>    PtrToFamilyMemberFile = (far Member_t *) _xalloc(&tempsz, 0, XALLOC_BB);
>    printf("\nAfter xAvail reports (Member) = %ld free\n", _xavail(NULL, 0,
> XALLOC_BB));
>
>
> //===========================================================================
>    tempsz = (MAX_NODE * 5 * sizeof(Node_t) + 8);
>    printf("\n Total Desired allocate byte = %ld \n",tempsz);
>    printf("\nBefore xAvail reports (Node) = %ld free\n", _xavail(NULL, 0,
> XALLOC_BB));
>    PtrToNodeFile = (far Node_t *) _xalloc(&tempsz, 0, XALLOC_BB);
>    printf("\nAfter xAvail reports (Node) = %ld free\n", _xavail(NULL, 0,
> XALLOC_BB));
>
>
> //===========================================================================
>    tempsz = (DS_MAX * sizeof(din_t) + 8);
>    printf("\n Total Desired allocate byte = %ld \n",tempsz);
>    printf("\nxBefore Avail reports (Digital) = %ld free\n", _xavail(NULL,
> 0, XALLOC_BB));
>    PtrToDigitalSensorFile = (far din_t *) _xalloc(&tempsz, 0, XALLOC_BB);
>    printf("\nAfter xAvail reports (Digital) = %ld free\n", _xavail(NULL,
> 0, XALLOC_BB));
>
>
> //===========================================================================
>    tempsz = (AS_MAX * sizeof(ain_t) + 8);
>    printf("\n Total Desired allocate byte = %ld \n",tempsz);
>    printf("\nBefore xAvail reports (Analog) = %ld free\n", _xavail(NULL,
> 0, XALLOC_BB));
>    PtrToAnalogSensorFile = (far ain_t *) _xalloc(&tempsz, 0, XALLOC_BB);
>    printf("\nAfter xAvail reports (Analog) = %ld free\n", _xavail(NULL, 0,
> XALLOC_BB));
>
> }
>
>
> RESULT........................
>
>
>  Total Desired allocate byte =
> 6194
>
>
> Before xAvail reports (Member) = 450544
> free
>
>
> After xAvail reports (Member) = 450544
> free
>
>
>  Total Desired allocate byte =
> 18220
>
>
> Before xAvail reports (Node) = 450544
> free
>
>
> After xAvail reports (Node) = 432324
> free
>
>
>  Total Desired allocate byte =
> 464
>
>
> xBefore Avail reports (Digital) = 432324
> free
>
>
> After xAvail reports (Digital) = 432324
> free
>
>
>  Total Desired allocate byte =
> 376
>
>
> Before xAvail reports (Analog) = 432324
> free
>
>
> After xAvail reports (Analog) = 432324 free
>
> 
>