This is a group for folks designing and programming embedded systems using the Rabbit Semiconductor C-programmable microcontroller. Rabbit Semi is a spin-off from Z-World who makes a variety of embedded modules and tools. This group is not affiliated with either Rabbit or Z-World, but is a user forum for sharing ideas, asking questions,
flaunting knowledge, and other typical user group stuff. The Rabbit is a powerful uC, supported by a full-featured C-compiler.
persistent local variables without static declaration. - Julian Higginson - Jun 23 20:52:42 2009
Hey all,
I've been investigating some weirdness in a piece of code for a DC based
product, where the front panel access gets locked out in some circumstances.
Anyway - key reading section of the code is pretty simple. there's a
cofunction that runs every 60ms, and this calls a function that reads the
key matrix. So in this case, I guess I can either have a problem with the
cofunction (it's the first cofunction in the code, out of 4, but everything
else I can see via serial port access commands runs fine) or I have a
problem with the keypress reading function, or a problem with the function
that responds to key presses..
looking through the key reading function, there's a persistent (local)
variable that is set to indicate if a particular button (not responding in
fault mode) is pressed on a button read, but nothing is done with this
information until the function runs, and doesn't detect the button pressed,
but sees the persistent variable asserted.. In that case it passes the bit
flag for that button back to the rest of the code.
Anyway. This variable is not declared static. But it is initialised with a
#GLOBAL_INIT section.
This kind of surprises me that a persistent local variable isn't declared
static, and that it could ever work... But then looking through the DC
manual, their own example of using #GLOBAL_INIT shows it being used in a
function to fill variables (a local array of longs) that aren't static
either.
SO - does anyone have much experience with using local variables of
functions in DC as persistent storage? Is it possible this could work
sometimes, but then maybe after running for a while, it might stop working?
The only other thing I can think is if things are getting into a state
where _GLOBAL_INIT() is getting called regularly somehow? The code doesn't
have much in the way of #GLOBAL_INIT declarations, and I'm pretty sure it
could run with no major problems other than what I've seen even if
_GLOBAL_INIT() was going off regularly. So I suppose that's a possibility..
Another option is that memory is getting stomped by something really bad
that I don't know about - but in this case I'd expect a lot more than just
the key access to stop working. and this particular local variable is
sitting in the memory map alongside a bunch of pretty important other
things.
Thanks,
Julian
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
Re: persistent local variables without static declaration. - Scott Henion - Jun 23 21:38:03 2009
Julian Higginson wrote:
>
>
> Anyway. This variable is not declared static. But it is initialised
> with a #GLOBAL_INIT section.
>
>
>
> This kind of surprises me that a persistent local variable isn’t
> declared static, and that it could ever work….. But then looking
> through the DC manual, their own example of using #GLOBAL_INIT shows
> it being used in a function to fill variables (a local array of
> longs) that aren’t static either.
>
>
>
> SO – does anyone have much experience with using local variables of
> functions in DC as persistent storage? Is it possible this could work
> sometimes, but then maybe after running for a while, it might stop
> working?
>
>
>
>
>
> The only other thing I can think is if things are getting into a
> state where _GLOBAL_INIT() is getting called regularly somehow? The
> code doesn’t have much in the way of #GLOBAL_INIT declarations, and
> I’m pretty sure it could run with no major problems other than what
> I’ve seen even if _GLOBAL_INIT() was going off regularly. So I suppose
> that’s a possibility..
>
>
>
> Another option is that memory is getting stomped by something really
> bad that I don’t know about – but in this case I’d expect a lot more
> than just the key access to stop working… and this particular local
> variable is sitting in the memory map alongside a bunch of pretty
> important other things.
>
>
>
Check the examples if they have
#class static
At the top. That would make local variables static by default. AT one
time, that was the default allocation in DC.
A #GLOBAL_INIT() on an auto variable is meanigless and should throw a
compiler error as the variable has an unknown address outside the
function (as GLOBAL_INIT() runs outside the function.) Besides, an auto
variable is trashed by the next call to any other function.
--
------------------------------------------
| Scott G. Henion| s...@shdesigns.org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesigns.org |
------------------------------------------
today's fortune
There is no likelihood man can ever tap the power of the atom.
-- Robert Millikan, Nobel Prize in Physics, 1923
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )RE: persistent local variables without static declaration. - Julian Higginson - Jun 23 22:25:38 2009
The example doesn't seem to have that directive there. But looking at the
manuals again, it seems to be from an older version of DC (premier) where
that was the default.
But more importantly the code I'm working on does specifically have #class
static up near the top of the main file, So - this means that every local
variable in every function in the application (unless explicitly declared
otherwise) is static?
Also, I guess with what you said about auto local variables always getting
trashed (Like I'd expect from a normal C compiler normally..) and the DC
compiler throwing an error on #GLOBAL_INIT-ing an auto local variable -
because the code is usually working, then the variable must be static.
Oh well - thanks for your help in clarifying this. Now - to try and find the
actual problem.
julian
From: r...@yahoogroups.com [mailto:r...@yahoogroups.com] On
Behalf Of Scott Henion
Sent: Wednesday, 24 June 2009 11:37 AM
To: r...@yahoogroups.com
Subject: Re: [rabbit-semi] persistent local variables without static
declaration.
Check the examples if they have
#class static
At the top. That would make local variables static by default. AT one time,
that was the default allocation in DC.
A #GLOBAL_INIT() on an auto variable is meanigless and should throw a
compiler error as the variable has an unknown address outside the function
(as GLOBAL_INIT() runs outside the function.) Besides, an auto variable is
trashed by the next call to any other function.
--
------------------------------------------
| Scott G. Henion| s...@shdesigns.org |
| Consultant | Stone Mountain, GA |
| SHDesigns http://www.shdesigns.org |
------------------------------------------
today's fortune
There is no likelihood man can ever tap the power of the atom.
-- Robert Millikan, Nobel Prize in Physics, 1923

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
Re: persistent local variables without static declaration. - jmsardon01 - Jun 24 13:05:35 2009
I sugest that use #class static always because DC has some problems with auto variables,
by example, in costates.
Juan
--- In r...@yahoogroups.com, "Julian Higginson"
wrote:
>
> The example doesn't seem to have that directive there. But looking at the
> manuals again, it seems to be from an older version of DC (premier) where
> that was the default.
>
>
>
> But more importantly the code I'm working on does specifically have #class
> static up near the top of the main file, So - this means that every local
> variable in every function in the application (unless explicitly declared
> otherwise) is static?
>
>
>
> Also, I guess with what you said about auto local variables always getting
> trashed (Like I'd expect from a normal C compiler normally..) and the DC
> compiler throwing an error on #GLOBAL_INIT-ing an auto local variable -
> because the code is usually working, then the variable must be static.
>
>
>
> Oh well - thanks for your help in clarifying this. Now - to try and find the
> actual problem.
>
>
>
>
>
>
>
> julian
>
>
>
>
>
> From: r...@yahoogroups.com [mailto:r...@yahoogroups.com] On
> Behalf Of Scott Henion
> Sent: Wednesday, 24 June 2009 11:37 AM
> To: r...@yahoogroups.com
> Subject: Re: [rabbit-semi] persistent local variables without static
> declaration.
>
>
>
> Check the examples if they have
>
> #class static
>
> At the top. That would make local variables static by default. AT one time,
> that was the default allocation in DC.
>
> A #GLOBAL_INIT() on an auto variable is meanigless and should throw a
> compiler error as the variable has an unknown address outside the function
> (as GLOBAL_INIT() runs outside the function.) Besides, an auto variable is
> trashed by the next call to any other function.
> --
> ------------------------------------------
> | Scott G. Henion| shenion@... |
> | Consultant | Stone Mountain, GA |
> | SHDesigns http://www.shdesigns.org |
> ------------------------------------------
>
> today's fortune
> There is no likelihood man can ever tap the power of the atom.
> -- Robert Millikan, Nobel Prize in Physics, 1923
>
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )