To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 1218
1217  |  1219
Subject: 
Re: Persistent globals
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sun, 16 Jul 2000 22:29:45 GMT
Viewed: 
1499 times
  
Whew, I've been writing here a lot. I guess now that things work, it's a
lot more enjoyable! :) Anyway, here goes....

I recall that with older versions of legOS, global variables were only
initialized once, when the program was downloaded. Afterwards, they were
preserved across runs and powerdowns until the program was reloaded from
the computer again. I'm now in a sitaution where that would be helpful to
me, and it looks as if legOS 0.2.3 eliminates it. Is this correct, or am I
seeing something totally different? If it is correct, is there a good way
now to store persistent data like that?

legOS 0.2.3 or 0.2.4 will load .strings and .rodata sections just like the
.text section. With this you can achive persistent data by storing your
variables into the .strings section. There are some nice features in gcc
to help with this.

Just insert __persistent between the variable name and equal sign followed
by a value. You need an initializer for the data, else it will not be put
into .strings, but into .bss

The sample code implements a persistent counter counting the runs of the
program starting with 0.

-- cut here --
#include <unistd.h>
#include <conio.h>

/*
* This is the real definition of __persistent, it could move
* into some header file...
*/
#define __persistent __attribute__ ((__section__ (".strings")))

/*
* This is how you declare the persistent data:
*/
static unsigned int counter __persistent = 0;

int
main(int argc, char **argv)
{
lcd_number(counter++, unsign, e0);
return 0;
}
-- cut here --

Hope this helps,
Eddie C. Dost
ecd@skynet.be



Message has 4 Replies:
  Re: Persistent globals
 
(...) [snip great gobs of neat info] (...) Assuming it works, it helps a lot! Thanks much. -- "Do not go gentle into that good night. Rage, rage against the dying of the light." - Dylan Thomas Mike Ash - (URL), <mailto:mail@mikeash.com> (24 years ago, 17-Jul-00, to lugnet.robotics.rcx.legos)
  Re: Persistent globals
 
(...) <example code> This worked great for us using legOS 0.2.4. Thanks Eddie! Regards Tobias (24 years ago, 18-Jul-00, to lugnet.robotics.rcx.legos)
  Re: Persistent globals
 
(...) Do you think that is possible to change the behavier of legOS loading to obtain the expected behavier for static data without the trick? Bye, Paolo. --- "Do not follow where the path my lead Go instead where there is no path and leave a (...) (24 years ago, 24-Jul-00, to lugnet.robotics.rcx.legos)
  Re: Persistent globals
 
(...) Hi again! I have found that this works with scalar variables. However, I need to make an array persistent. More specifically, I have a 100x100 matrix containing a population for use with genetic programming and I need to be able to keep this (...) (24 years ago, 31-Jul-00, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Persistent globals
 
Whew, I've been writing here a lot. I guess now that things work, it's a lot more enjoyable! :) Anyway, here goes.... I recall that with older versions of legOS, global variables were only initialized once, when the program was downloaded. (...) (24 years ago, 16-Jul-00, to lugnet.robotics.rcx.legos)

12 Messages in This Thread:






Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR