EmbeddedRelated.com
Forums

SRAM Battery Backup

Started by "rsp.blue" January 5, 2007
hi
i am using Dynamic C V8.01 & RCM 3200 Module

i have connected 3V lithium battery to VBat_Ext pin.
RTC is performing correct on power On/off. but SRAM is not maintaing
its data. i have used Xalloc for memory allocation.
code for data write is as follows
////////////////////////////////////////////////////////////////////
static char buffer1[1024]; // buffer
for data to write
static char buffer2[1024]; //
buffer to read data back into
static unsigned long physaddr; // physical
memory address to write to

physaddr = xalloc(1024); // physical memory
address (SRAM)
// clear buffer1
memset(buffer1, 0x55, 1024);

// write buffer1 to memory
printf("Writing buffer1 to memory\n");
root2xmem(physaddr, buffer1, 1024);//write data in SRAM
//////////////////////////////////////////////////////////
code for memory read is
/////////////////////////////////////////////////////
static char buffer1[1024]; //
buffer for data to write
static char buffer2[1024]; //
buffer to read data back into
static unsigned long physaddr; // physical
memory address to write to

physaddr = xalloc(1024); // physical memory
address (SRAM)
// clear buffer1
memset(buffer1, 0x55, 1024);

// write buffer1 to memory
// printf("Writing buffer1 to memory\n");
// root2xmem(physaddr, buffer1, 1024);
// return;
// read data from memory into buffer2
printf("Reading memory into buffer2\n");
xmem2root(buffer2, physaddr, 1024);

// compare the two buffers using string compare fcn strncmp
// strncmp returns 0 if strings are identical
if (strncmp(buffer1, buffer2, 1024))
printf("Error in write/read to XMEM\n");
else
printf("Buffers match\n\n");

////////////////////////////////////////////////////////////////
please help me for finding exact method for using battery backuped
Ram.

Thanks in Advance

********* r o h a n **********************************
Try to use this code:

static char buffer1[1024] ; //
buffer for data to write
static char buffer2[1024] ; //
buffer to read data back into
static unsigned long physaddr; // physical
memory address to write to

physaddr = xalloc(1024) ; // physical memory
address (SRAM)

// clear buffer1
memset(buffer1, 0x55, 1024);
memset(buffer2, '\0', 1024);

// write buffer1 to memory
printf("Writing buffer1 to memory\n");
root2xmem(physaddr, buffer1, 1024);
// read data from memory into buffer2
printf("Reading memory into buffer2\n");
xmem2root(buffer2, physaddr, 1024);
if (strncmp(buffer1, buffer2, 1024))
printf("Error in write/read to XMEM\n");
else
printf("Buffers match\n\n");

The xalloc will return different long values for
different firmwares, so once you used xalloc be sure
youll write to and read from xmem in the same
firmware.
--- "rsp.blue" escreveu:

> hi
> i am using Dynamic C V8.01 & RCM 3200 Module
>
> i have connected 3V lithium battery to VBat_Ext pin.
> RTC is performing correct on power On/off. but SRAM
> is not maintaing
> its data. i have used Xalloc for memory allocation.
> code for data write is as follows
>
////////////////////////////////////////////////////////////////////
> static char buffer1[1024]; // buffer
> for data to write
> static char buffer2[1024]; //
> buffer to read data back into
> static unsigned long physaddr; // physical
> memory address to write to
>
> physaddr = xalloc(1024); // physical memory
> address (SRAM)
> // clear buffer1
> memset(buffer1, 0x55, 1024);
>
> // write buffer1 to memory
> printf("Writing buffer1 to memory\n");
> root2xmem(physaddr, buffer1, 1024);//write data in
> SRAM
//////////////////////////////////////////////////////////
> code for memory read is
>
/////////////////////////////////////////////////////
> static char buffer1[1024]; //
> buffer for data to write
> static char buffer2[1024]; //
> buffer to read data back into
> static unsigned long physaddr; // physical
> memory address to write to
>
> physaddr = xalloc(1024); // physical memory
> address (SRAM)
> // clear buffer1
> memset(buffer1, 0x55, 1024);
>
> // write buffer1 to memory
> // printf("Writing buffer1 to memory\n");
> // root2xmem(physaddr, buffer1, 1024);
> // return;
> // read data from memory into buffer2
> printf("Reading memory into buffer2\n");
> xmem2root(buffer2, physaddr, 1024);
>
> // compare the two buffers using string compare fcn
> strncmp
> // strncmp returns 0 if strings are identical
> if (strncmp(buffer1, buffer2, 1024))
> printf("Error in write/read to XMEM\n");
> else
> printf("Buffers match\n\n");
////////////////////////////////////////////////////////////////
> please help me for finding exact method for using
> battery backuped
> Ram.
>
> Thanks in Advance
>
> ********* r o h a n
> **********************************
>
__________________________________________________
Fale com seus amigos de gra com o novo Yahoo! Messenger
http://br.messenger.yahoo.com/
thanks for reply..
i tried this code but how can i test that memory has retained its value after power off. There should be power off betwwen write & read. So i have written different codes for reading & writing. But its reading garbage valus after power off.Battery is connected properly beacuse RTC is working properly between power cycles.
----- Original Message ----
From: Alexandre Kremer
To: r...
Sent: Friday, January 5, 2007 11:43:55 PM
Subject: Re: [rabbit-semi] SRAM Battery Backup

Try to use this code:

static char buffer1[1024] ; //
buffer for data to write
static char buffer2[1024] ; //
buffer to read data back into
static unsigned long physaddr; // physical
memory address to write to

physaddr = xalloc(1024) ; // physical memory
address (SRAM)

// clear buffer1
memset(buffer1, 0x55, 1024);
memset(buffer2, '\0', 1024);

// write buffer1 to memory
printf("Writing buffer1 to memory\n");
root2xmem(physaddr, buffer1, 1024);
// read data from memory into buffer2
printf("Reading memory into buffer2\n");
xmem2root(buffer2, physaddr, 1024);
if (strncmp(buffer1, buffer2, 1024))
printf("Error in write/read to XMEM\n");
else
printf("Buffers match\n\n");

The xalloc will return different long values for
different firmwares, so once you used xalloc be sure
youll write to and read from xmem in the same
firmware.
--- "rsp.blue" escreveu:

> hi
> i am using Dynamic C V8.01 & RCM 3200 Module
>
> i have connected 3V lithium battery to VBat_Ext pin.
> RTC is performing correct on power On/off. but SRAM
> is not maintaing
> its data. i have used Xalloc for memory allocation.
> code for data write is as follows
>
//////////// ///////// ///////// ///////// ///////// ///////// ///////// //
> static char buffer1[1024] ; // buffer
> for data to write
> static char buffer2[1024] ; //
> buffer to read data back into
> static unsigned long physaddr; // physical
> memory address to write to
>
> physaddr = xalloc(1024) ; // physical memory
> address (SRAM)
> // clear buffer1
> memset(buffer1, 0x55, 1024);
>
> // write buffer1 to memory
> printf("Writing buffer1 to memory\n");
> root2xmem(physaddr, buffer1, 1024);//write data in
> SRAM
//////////// ///////// ///////// ///////// ///////// ///////// /
> code for memory read is
>
//////////// ///////// ///////// ///////// ///////// /////
> static char buffer1[1024] ; //
> buffer for data to write
> static char buffer2[1024] ; //
> buffer to read data back into
> static unsigned long physaddr; // physical
> memory address to write to
>
> physaddr = xalloc(1024) ; // physical memory
> address (SRAM)
> // clear buffer1
> memset(buffer1, 0x55, 1024);
>
> // write buffer1 to memory
> // printf("Writing buffer1 to memory\n");
> // root2xmem(physaddr, buffer1, 1024);
> // return;
> // read data from memory into buffer2
> printf("Reading memory into buffer2\n");
> xmem2root(buffer2, physaddr, 1024);
>
> // compare the two buffers using string compare fcn
> strncmp
> // strncmp returns 0 if strings are identical
> if (strncmp(buffer1, buffer2, 1024))
> printf("Error in write/read to XMEM\n");
> else
> printf("Buffers match\n\n");
//////////// ///////// ///////// ///////// ///////// ///////// ///////
> please help me for finding exact method for using
> battery backuped
> Ram.
>
> Thanks in Advance
>
> ********* r o h a n
> ************ ********* ********* ****
>

____________ _________ _________ _________ _________ __
Fale com seus amigos de gra com o novo Yahoo! Messenger
http://br.messenger .yahoo.com/

__________________________________________________
rohan patil wrote:
> thanks for reply..
> i tried this code but how can i test that memory has retained its
> value after power off. There should be power off betwwen write & read.
> So i have written different codes for reading & writing. But its
> reading garbage valus after power off.Battery is connected properly
> beacuse RTC is working properly between power cycles.
The 3200 has 2 RAM's, one is battery backed, the other is not. xalloc()
will return addreses in the non-battery backed RAM by default.

There is another function something like _xalloc() that allows
specifying BB_RAM.

------
| Scott G. Henion| s...@shdesigns.org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesigns.org |
------
Rabbit libs: http://www.shdesigns.org/rabbit/
today's fortune
Question: Is it better to abide by the rules until they're changed or
help speed the change by breaking them?
At 11:40 PM 1/5/2007 -0800, you wrote:
>thanks for reply..
>i tried this code but how can i test that memory has retained its value
>after power off. There should be power off betwwen write & read. So i have
>written different codes for reading & writing. But its reading garbage
>valus after power off.Battery is connected properly beacuse RTC is working
>properly between power cycles.

Be aware that the 3200 has two different kinds of RAM, the fast ram that
the code executes from (copied from flash at startup) and the other RAM,
which has more wait states, which is why the code doesn't run from it. You
have to be in the slower RAM since the fast ram is not battery backed.

Take a look at the documentation for the BBRAM and PROTECTED keywords.

Also, if you maintain data between power cycles and need to verify
integrity, you should really put all that data in a struct, and checksum
the whole thing. We do this in our product and rarely have issues. The
only problem that happens is when the battery dies, and the checksum lets
the program know something is wrong, set safe default values, and alert the
user the battery is due for replacement.

-Mike
--
Mike vanMeeteren f...@fastec.com FASTechnologies Corp.
Track Hauler: 2001 F150 Track toy: 89 Mustang LX 351W 10.93 @ 122.5 MPH
Dear scot,

i tried with _xalloc function but it is giving following error

xmem allocation failed
i m making function call as follows

_xalloc(&sz,1,XALLOC_BB);

& _xavail function is returning 0.

( i m using DC v8.61 & RCM3200)

----- Original Message ----
From: Scott Henion
To: r...
Sent: Saturday, January 6, 2007 11:11:04 PM
Subject: Re: [rabbit-semi] SRAM Battery Backup

rohan patil wrote:
thanks for reply..
i tried this code but how can i test that memory has retained its value after power off. There should be power off betwwen write & read. So i have written different codes for reading & writing. But its reading garbage valus after power off.Battery is connected properly beacuse RTC is working properly between power cycles.

The 3200 has 2 RAM's, one is battery backed, the other is not. xalloc() will return addreses in the non-battery backed RAM by default.

There is another function something like _xalloc() that allows specifying BB_RAM.

------------ --------- --------- --------- ---
| Scott G. Henion| shenion@shdesigns. org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesign s.org |
------------ --------- --------- --------- ---
Rabbit libs: http://www.shdesign s.org/rabbit/
today's fortune
Question: Is it better to abide by the rules until they're changed or
help speed the change by breaking them?

__________________________________________________
rohan patil wrote:
> Dear scot,
>
> i tried with _xalloc function but it is giving following error
>
> xmem allocation failed
>
>
> i m making function call as follows
>
> _xalloc(&sz,1,XALLOC_BB);
>
> & _xavail function is returning 0.
>
> ( i m using DC v8.61 & RCM3200)
What was the value of sz before the call?

What does _xavail(NULL,1,XALLOC_BB) returrn?

That will return a long with the available size.

------
| Scott G. Henion| s...@shdesigns.org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesigns.org |
------
Rabbit libs: http://www.shdesigns.org/rabbit/
today's fortune
I bet the human brain is a kludge.
-- Marvin Minsky
Dear scott,

i tried this function
_xavail(NULL, 1,XALLOC_ BB)

it is returning 0. So sz value is not afecting the behaviour of _xalloc function ie. it is still giving same error

i m using compile to flash option

can it be 3200 hardware problem????

----- Original Message ----
From: Scott Henion
To: r...
Sent: Monday, January 8, 2007 8:08:34 AM
Subject: Re: [rabbit-semi] SRAM Battery Backup

rohan patil wrote:
Dear scot,

i tried with _xalloc function but it is giving following error

xmem allocation failed

i m making function call as follows

_xalloc(&sz,1,XALLOC_ BB);

& _xavail function is returning 0.

( i m using DC v8.61 & RCM3200)
What was the value of sz before the call?

What does _xavail(NULL, 1,XALLOC_ BB) returrn?

That will return a long with the available size.
------------ --------- --------- --------- ---
| Scott G. Henion| shenion@shdesigns. org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesign s.org |
------------ --------- --------- --------- ---
Rabbit libs: http://www.shdesign s.org/rabbit/
today's fortune
I bet the human brain is a kludge.
-- Marvin Minsky

__________________________________________________
rohan patil wrote:
> Dear scott,
>
> i tried this function
> _xavail(NULL, 1,XALLOC_ BB)
>
> it is returning 0. So sz value is not afecting the behaviour of
> _xalloc function ie. it is still giving same error
>
> i m using compile to flash option
>
> can it be 3200 hardware problem????
On the 3200, you must use Compile to flash, Run in RAM.

------
| Scott G. Henion| s...@shdesigns.org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesigns.org |
------
Rabbit libs: http://www.shdesigns.org/rabbit/
today's fortune
Men in their arrogance claim to understand the nature of creation,
and devise elaborate theories to describe its behavior. But always
they discover in the end that God was quite a bit more clever than
they thought.

-- Sister Miriam Godwinson,
"We Must Dissent"
heyyy... thanks everybody..
_xalloc function si working fine as i changed compilation option to Compile in flash run in Ram
beacause only in this option 256 k battery backup ram is mapped to address 80000-bffff for RCM3200
so i have to always use Compile in flash run in Ram option.

********* rohan *************************************

----- Original Message ----
From: rohan patil
To: r...
Sent: Monday, January 8, 2007 10:30:25 AM
Subject: Re: [rabbit-semi] SRAM Battery Backup

Dear scott,

i tried this function
_xavail(NULL, 1,XALLOC_ BB)

it is returning 0. So sz value is not afecting the behaviour of _xalloc function ie. it is still giving same error

i m using compile to flash option

can it be 3200 hardware problem????

----- Original Message ----
From: Scott Henion
To: rabbit-semi@ yahoogroups. com
Sent: Monday, January 8, 2007 8:08:34 AM
Subject: Re: [rabbit-semi] SRAM Battery Backup
rohan patil wrote:
Dear scot,

i tried with _xalloc function but it is giving following error

xmem allocation failed

i m making function call as follows

_xalloc(&sz,1,XALLOC_ BB);

& _xavail function is returning 0.

( i m using DC v8.61 & RCM3200)
What was the value of sz before the call?

What does _xavail(NULL, 1,XALLOC_ BB) returrn?

That will return a long with the available size.
------------ --------- --------- --------- ---
| Scott G. Henion| shenion@shdesigns. org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesign s.org |
------------ --------- --------- --------- ---
Rabbit libs: http://www.shdesign s.org/rabbit/
today's fortune
I bet the human brain is a kludge.
-- Marvin Minsky

____________ _________ _________ _________ _________ __