Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
7638edbb5This file is pinned to the selected release. Download the original to open it in your design tool.
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef RETAINED_H_
#define RETAINED_H_
#include <inttypes.h>
/* Example of validatable retained data. */
struct retained_data {
/* The uptime from the current session the last time the
* retained data was updated.
*/
uint64_t uptime_latest;
/* Cumulative uptime from all previous sessions up through
* uptime_latest of this session.
*/
uint64_t uptime_sum;
/* Number of times the application has started. */
uint32_t boots;
/* Number of times the application has gone into system off. */
uint32_t off_count;
/* Application state indicating how button presses should be interpreted. */
uint32_t app_state;
/* Helper variable that survives device power-down. */
uint32_t current_selection;
/* CRC used to validate the retained data. This must be
* stored little-endian, and covers everything up to but not
* including this field.
*/
uint32_t crc;
};
/* For simplicity in the sample just allow anybody to see and
* manipulate the retained state.
*/
extern struct retained_data retained;
/* Check whether the retained data is valid, and if not reset it.
*
* @return true if and only if the data was valid and reflects state
* from previous sessions.
*/
bool retained_validate(void);
/* Update any generic retained state and recalculate its checksum so
* subsequent boots can verify the retained state.
*/
void retained_update(void);
#endif /* RETAINED_H_ */