Datasheet
At compile time, this will resolve to the following structure:
You will also need to provide names for each field, regardless of WHETHER you have enabled naming support
via STATS_NAMES or not:
At compile time, this will resolve to the following structure:
Accessing the Stats in Your Code
You will need to declare a global variable somewhere to holds the stats data, using the model below:
If the global definition is is another file and you are referencing it elsewhere, you would declare this in the file where
you will modify locally:
Initializing the Stats
Before your stats can be used or accessed, they need to be initialised and registered.
You can initialise your stats entry as follows:
STATS_SECT_START(my_stat_section)
STATS_SECT_ENTRY(attempt_stat)
STATS_SECT_ENTRY(error_stat)
STATS_SECT_END
struct stats_my_stat_section {
struct stats_hdr s_hdr;
uint32_t sattempt_stat;
uint32_t serror_stat;
};
Note that the field names need to match between the STATS_SECT_ENTRY name above and the
STATS_NAME entry below!
/* Define a few stats for querying */
STATS_NAME_START(my_stat_section)
STATS_NAME(my_stat_section, attempt_stat)
STATS_NAME(my_stat_section, error_stat)
STATS_NAME_END(my_stat_section)
struct stats_name_map g_stats_map_my_stat_section[] = {
{ __builtin_offsetof (struct stats_my_stat_section, sattempt_stat), "attempt_stat" },
{ __builtin_offsetof (struct stats_my_stat_section, serror_stat), "error_stat" },
};
STATS_SECT_DECL(my_stat_section) g_mystat;
extern STATS_SECT_DECL(my_stat_section) g_mystat;
© Adafruit Industries https://learn.adafruit.com/adafruit-nrf52-pro-feather Page 63 of 87










