Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7879131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:50:00+00:00 2026-06-03T03:50:00+00:00

I’m in the process of designing a embedded C data storage module. It will

  • 0

I’m in the process of designing a embedded C data storage module. It will be included by files/modules who want access to this “shared” system-wide data. Multiple tasks aggregate dozens of inputs (GPIO, CAN, I2C/SPI/SSP data, etc) and stores those values off using the API. Then, other tasks can access the data safely through the API. The system is an embedded app with an RTOS, so mutexes are used to protect the data. These ideas will be used regardless of the implementation

I’ve designed something like this in the past, and I’m trying to improve upon it. I’m currently halfway through a new implementation and I’m running into a few hiccups and would really benefit from a fresh perspective.

Quick rundown of the requirements of this module:

  • Ideally, there would be one interface that can access the variables (one get, one set).
  • I’d like to return different variable types (floats, ints, etc). This means macros are probably needed.
  • I’m not pressed for code space, but it’s always a concern
  • Quick gets/sets are absolutely paramount (which means storing in strings ala xml/json is out)
  • No new variables need to be added during runtime. Everything is statically defined at boot

    The question is how would you go about designing something like this? Enumerations, structures, accessors, macros, etc? I’m not looking for code here, just discussing general overall design ideas. If there’s a solution on the internet that addresses these sorts of things, perhaps even just a link is sufficient.

    • 1 1 Answer
    • 0 Views
    • 0 Followers
    • 0
    Share
    • Facebook
    • Report

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    1 Answer

    • Voted
    • Oldest
    • Recent
    • Random
    1. Editorial Team
      Editorial Team
      2026-06-03T03:50:01+00:00Added an answer on June 3, 2026 at 3:50 am

      Figured I’d update one of my only unaccepted questions. Here’s my final implementation. Been using this for over a year and it works fantastic. Very easy to add variables to and very little overhead for the benefit it gives us.

      lib_data.h:

      #ifndef __LIB_DATA_H
      #define __LIB_DATA_H
      
      #include <type.h>
      
      /****************************************************************************************
       * Constant Definitions
       ***************************************************************************************/
      
      /* Varname, default value (uint32_t) */
      #define DATA_LIST                                                                       \
        DM(D_VAR1, 0)                                                                         \
        DM(D_VAR2, 1)                                                                         \
        DM(D_VAR3, 43)
      
      #define DM(y, z)    y,
      
      /* create data structure from the macro */
      typedef enum {
          DATA_LIST
          NUM_DATA_VARIABLES
      } dataNames_t;
      
      typedef struct {
          dataNames_t name;
          uint32_t value;
      } dataPair_t;
      
      /* the macro has to be undefined to allow the fault list to be reused without being
       * defined multiple times
       *
       * this requires:
       * a file specific lint option to suppress the rule for use of #undef
       */
      #undef DM
      
      /****************************************************************************************
       * Data Prototypes
       ***************************************************************************************/
      
      /****************************************************************************************
       * External Function Prototypes
       ***************************************************************************************/
      
      /**
       * Fetch a machine parameter
       *
       * \param dataName The variable from DATA_LIST that you want to fetch
       *
       * \return The value of the requested parameter
       *
       */
      uint32_t lib_data_Get(dataNames_t dataName);
      
      /**
       * Set a machine parameter
       *
       * \param dataName The variable from DATA_LIST that you want to set
       * \param dataVal The value you want to set the variable to
       *
       * \return void
       *
       */
      void lib_data_Set(dataNames_t dataName, uint32_t dataVal);
      
      #endif /* __LIB_DATA_H */
      

      lib_data.c:

      #include <type.h>
      #include "lib_data.h"
      
      /****************************************************************************************
       * Variable Declarations
      ***************************************************************************************/
      /* Used to initialize the data array with defaults ##U appends a 'U' to the bare
       * integer specified in the DM macro */
      
      #define DM(y, z)               \
          dataArray[y].name = y;     \
          dataArray[y].value = z##U;
      
      static bool_t dataInitialized = FALSE;
      static dataPair_t dataArray[NUM_DATA_VARIABLES];
      
      /****************************************************************************************
       * Private Function Prototypes
       ***************************************************************************************/
      static void lib_data_Init(void);
      
      /****************************************************************************************
       * Public Functions
       ***************************************************************************************/
      uint32_t lib_data_Get(dataNames_t dataName) {
          if(!dataInitialized) {
              lib_data_Init();
          }
      
          /* Should only be used on systems that do word-sized asm reads/writes.
           * If the lib gets extended to multi-word storage capabilities, a mutex
           * is necessary to protect against multi-threaded access */
          return dataArray[dataName].value;
      }
      
      void lib_data_Set(dataNames_t dataName, uint32_t dataVal) {
          if(!dataInitialized) {
              lib_data_Init();
          }
      
          /* Should only be used on systems that do word-sized asm reads/writes.
           * If the lib gets extended to multi-word storage capabilities, a mutex
           * is necessary to protect against multi-threaded access */
          dataArray[dataName].value = dataVal;
      }
      
      /****************************************************************************************
       * Private Functions
       ***************************************************************************************/
      
      /**
       * initialize the machine data tables
       *
       * \param none
       *
       * \return none
       *
       */
      static void lib_data_Init(void) {
          /* Invoke the macro to initialize dataArray */
          DATA_LIST
          dataInitialized = TRUE;
      }
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
    I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
    I want to construct a data frame in an Rcpp function, but when I
    I have thousands of HTML files to process using Groovy/Java and I need to
    I have some data like this: 1 2 3 4 5 9 2 6
    link Im having trouble converting the html entites into html characters, (&# 8217;) i
    I want to count how many characters a certain string has in PHP, but
    For some reason, after submitting a string like this Jack’s Spindle from a text
    this is what i have right now Drawing an RSS feed into the php,
    I have this code to decode numeric html entities to the UTF8 equivalent character.

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help
    • SEARCH

    Footer

    © 2021 The Archive Base. All Rights Reserved
    With Love by The Archive Base

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.