Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #24820

Re: What is your strategy to save non volatile data?

From Don Y <blockedofcourse@foo.invalid>
Newsgroups comp.arch.embedded
Subject Re: What is your strategy to save non volatile data?
Date 2016-08-11 15:30 -0700
Organization A noiseless patient Spider
Message-ID <noiuaf$au4$1@dont-email.me> (permalink)
References <nohs7p$ff3$1@dont-email.me> <noi142$ih$1@dont-email.me> <noi3gv$8qc$1@dont-email.me> <noipdo$nnv$1@dont-email.me> <noithu$8fa$2@dont-email.me>

Show all headers | View raw


On 8/11/2016 3:17 PM, pozz wrote:

[much elided]

> "Everything in one structure" means you have a global (as the scope in C)
> struct definition that is accessed by every piece of code in the project, even
> if they are very different section of the project.

No.  It only has to be *effectively* global.

E.g., you can have a global "update_parameter()" that takes a
"key" (name for a parameter -- this could be a literal string
*or* just a small integer) and a parameter value (or pointer to
a parameter value).  Update_parameter() then moves the "value"
into the referenced portion of the "parameters to be saved struct".

In this way, the definition of the struct can remain opaque.
The same sort of "accessor" can be used to retrieve those
parameters from the struct -- without exposing the struct
or the manner in which the individual parameters are "encoded" (!)
in the struct.

E.g., you can pack a bunch of (potentially unrelated) parameters
into a bitfield within that struct.  Data coming *into* it gets
massaged to manipulate the appropriate fields.  Likewise for data
coming *out*.

Finally, because this represents a monitor, of sorts, you can ensure
atomic operations on that "data to be preserved" -- up to and including
an action that automatically saves the struct to persistent store
when power is failing (the rest of the time, "updates" happen to
the "in-RAM" copy of the struct so you don't incur the costs of
updating FLASH more often than necessary)

> In the past I used this approach with a global struct container:
>    /* In one .h file */
>    struct settings_s {
>      uint8_t backlight_level;
>      enum DisplayTheme theme;
>      uint16_t psu_output_voltage_calibration;
>      char password[7];
>      ...
>    };
>    extern struct settings_s settings;
>
>    /* In one .c file */
>    struct settings_s settings;
>
>    /* In display module */
>    backligh_set(settings.backlight_level);
>
> Every module that manages one or more persistent parameters should know the
> presence of a global settings variable with an exposed type definition (struct
> settings_s).
> I think this is a bad approach that increase the coupling between modules
> instead of decreasing it as it should be.
>
>
>  >> [It's unclear what the OP is addressing]
>  >
>  > Indeed.
>
> Mainly I'm interested in saving configuration parameters/settings (color theme,
> calibration data, backlight level, and so on).
> They are parameters that are changed by the user not so frequent.

But, are they changed in a "configuration mode" or, rather, as part
of the normal use of the device?  E.g., if I change the time on my
clock, I don't really enter a special "configuration mode" to do so.
Nor if I change the time zone, alarm settings, etc.  The clock
continues to *be* a clock while these persistent changes are happening.

See my other example re: automobile audio system (and, think of the
similar situation for most other "digital appliances" -- your TV
remembers the channel, volume, picture settings, etc. WITHOUT you
ever having to enter "configuration mode")

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-11 14:48 +0200
  Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 06:27 -0700
  Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-11 16:12 +0200
    Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 07:53 -0700
      Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 08:27 -0700
        Re: What is your strategy to save non volatile data? bitrex <bitrex@de.lete.earthlink.net> - 2016-08-11 12:11 -0400
          Re: What is your strategy to save non volatile data? bitrex <bitrex@de.lete.earthlink.net> - 2016-08-11 12:12 -0400
            Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 11:35 -0700
              Re: What is your strategy to save non volatile data? bitrex <bitrex@de.lete.earthlink.net> - 2016-08-11 20:59 -0400
          Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 11:33 -0700
        Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-12 00:21 +0200
          Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 15:40 -0700
      Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-11 23:07 +0200
        Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-12 00:17 +0200
          Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 15:30 -0700
            Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-12 09:02 +0200
              Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-12 09:29 -0700
            Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-12 11:54 +0200
              Re: What is your strategy to save non volatile data? John Devereux <john@devereux.me.uk> - 2016-08-12 13:14 +0100
                Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-12 15:22 +0200
              Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-12 09:40 -0700
                Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-12 22:40 +0200
                Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-13 09:44 -0700
                Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-14 23:01 +0200
          Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-12 09:52 +0200
            Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-12 16:30 +0200
              Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-12 17:09 +0200
        Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 15:36 -0700
        Re: What is your strategy to save non volatile data? Paul <paul@pcserviceselectronics.co.uk> - 2016-08-12 03:21 +0100
    Re: What is your strategy to save non volatile data? bitrex <bitrex@de.lete.earthlink.net> - 2016-08-11 12:19 -0400
      Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-11 23:49 +0200
        Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-11 15:37 -0700
    Re: What is your strategy to save non volatile data? John Devereux <john@devereux.me.uk> - 2016-08-11 20:50 +0100
    Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-12 00:16 +0200
      Re: What is your strategy to save non volatile data? Paul <paul@pcserviceselectronics.co.uk> - 2016-08-12 03:34 +0100
      Re: What is your strategy to save non volatile data? David Brown <david.brown@hesbynett.no> - 2016-08-12 11:59 +0200
  Re: What is your strategy to save non volatile data? Paul Rubin <no.email@nospam.invalid> - 2016-08-11 11:29 -0700
  Re: What is your strategy to save non volatile data? Les Cargill <lcargill99@comcast.com> - 2016-08-12 12:15 -0500
  Re: What is your strategy to save non volatile data? Joe Chisolm <jchisolm6@earthlink.net> - 2016-08-12 12:10 -0500
    Re: What is your strategy to save non volatile data? Paul <paul@pcserviceselectronics.co.uk> - 2016-08-12 22:00 +0100
  Re: What is your strategy to save non volatile data? Tim Wescott <tim@seemywebsite.com> - 2016-08-13 12:06 -0500
    Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-13 23:42 +0200
      Re: What is your strategy to save non volatile data? Don Y <blockedofcourse@foo.invalid> - 2016-08-13 15:55 -0700
      Re: What is your strategy to save non volatile data? Paul <paul@pcserviceselectronics.co.uk> - 2016-08-14 00:08 +0100
      Re: What is your strategy to save non volatile data? Tim Wescott <tim@seemywebsite.com> - 2016-08-13 19:06 -0500
        Re: What is your strategy to save non volatile data? pozz <pozzugno@gmail.com> - 2016-08-22 09:46 +0200

csiph-web