EmbeddedRelated.com
Forums

how variables can retain their value across power up.

Started by Sabio Bucci November 12, 2004

Hi, i read somewhere that:

- as variables are assigned fixed locations at compile time;

- having battery-backed RAM;

-since Dynamic C doesn't implicitly initialize any variables (unlike most C compilers that zero static variables)

It follows that  all global and local static variables in Dynamic C programs are non-volatile. Once a value is assigned to a variable, this value is retained (until it is assigned another).

 

I  tried with an example (i'm not talking about xalloc, root2xmem etc): used an uninitialized

global var i, whose starting value  makes three leds blinking in a certain sequence . (suppose

1->2->3->1, circularly)

Suppose that after a power-off/power-on they start blinking this way:  2->3->1->2->3->1.

Stopping things now, powering down and up, I expected the new sequence to be: 2->3->1...

But it was another one.I made several attempts.

WHATEVER was the last led blinking before i powered off, at power up leds always started to blink in the  SAME sequence, starting from the same led.

I considered (via tcp-ip) the starting value of i, and in all cases it was the same,  as if  i  was initialized (but 16384 is a strange value to be initialized to for an unsigned int ).

 

So, the only way to make vars to retain their values accross power up is is xalloc, root2xmem etc... ? those things i read misunderstood ?

 

 




Wich controler are you using? Most of them should do that. I know
that RCM32XX and RCM33XX will not do that. With those you have to
compile in flash and run in RAM and add "bbram" in front of your var. --- In rabbit-semi@rabb..., "Sabio Bucci" <s.bucci@u...>
wrote:
> Hi, i read somewhere that:
>
> - as variables are assigned fixed locations at compile time;
>
> - having battery-backed RAM;
>
> -since Dynamic C doesn't implicitly initialize any variables
(unlike most C compilers that zero static variables)
>
> It follows that all global and local static variables in Dynamic
C programs are non-volatile. Once a value is assigned to a variable,
this value is retained (until it is assigned another).
> I tried with an example (i'm not talking about xalloc, root2xmem
etc): used an uninitialized
>
> global var i, whose starting value makes three leds blinking in a
certain sequence . (suppose
>
> 1->2->3->1, circularly)
>
> Suppose that after a power-off/power-on they start blinking this
way: 2->3->1->2->3->1.
>
> Stopping things now, powering down and up, I expected the new
sequence to be: 2->3->1...
>
> But it was another one.I made several attempts.
>
> WHATEVER was the last led blinking before i powered off, at power
up leds always started to blink in the SAME sequence, starting from
the same led.
>
> I considered (via tcp-ip) the starting value of i, and in all
cases it was the same, as if i was initialized (but 16384 is a
strange value to be initialized to for an unsigned int ).
> So, the only way to make vars to retain their values accross power
up is is xalloc, root2xmem etc... ? those things i read
misunderstood ?
>
>
> Questa email stata verificata dal sistema centralizzato
antivirus della UniPlan Software




RCM3200.
I also have 3000. I'll try...

//-------------------------
> Wich controler are you using? Most of them should do that. I know
> that RCM32XX and RCM33XX will not do that. With those you have to
> compile in flash and run in RAM and add "bbram" in front of your
var.
>
>
> --- In rabbit-semi@rabb..., "Sabio Bucci" <s.bucci@u...>
> wrote:
> > Hi, i read somewhere that:
> >
> > - as variables are assigned fixed locations at compile time;
> >
> > - having battery-backed RAM;
> >
> > -since Dynamic C doesn't implicitly initialize any variables
> (unlike most C compilers that zero static variables)
> >
> > It follows that all global and local static variables in
Dynamic
> C programs are non-volatile. Once a value is assigned to a
variable,
> this value is retained (until it is assigned another).
> >
> >
> >
> > I tried with an example (i'm not talking about xalloc,
root2xmem
> etc): used an uninitialized
> >
> > global var i, whose starting value makes three leds blinking in
a
> certain sequence . (suppose
> >
> > 1->2->3->1, circularly)
> >
> > Suppose that after a power-off/power-on they start blinking this
> way: 2->3->1->2->3->1.
> >
> > Stopping things now, powering down and up, I expected the new
> sequence to be: 2->3->1...
> >
> > But it was another one.I made several attempts.
> >
> > WHATEVER was the last led blinking before i powered off, at
power
> up leds always started to blink in the SAME sequence, starting
from
> the same led.
> >
> > I considered (via tcp-ip) the starting value of i, and in all
> cases it was the same, as if i was initialized (but 16384 is a
> strange value to be initialized to for an unsigned int ).
> >
> >
> >
> > So, the only way to make vars to retain their values accross
power
> up is is xalloc, root2xmem etc... ? those things i read
> misunderstood ?
> >
> >
> >
> >
> >
> > Questa email stata verificata dal sistema centralizzato
> antivirus della UniPlan Software