1 /* 2 * Copyright (c) 2021 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef RETAINED_H_ 8 #define RETAINED_H_ 9 10 #include <stdbool.h> 11 #include <stdint.h> 12 13 /* Example of validatable retained data. */ 14 struct retained_data { 15 /* The uptime from the current session the last time the 16 * retained data was updated. 17 */ 18 uint64_t uptime_latest; 19 20 /* Cumulative uptime from all previous sessions up through 21 * uptime_latest of this session. 22 */ 23 uint64_t uptime_sum; 24 25 /* Number of times the application has started. */ 26 uint32_t boots; 27 28 /* Number of times the application has gone into system off. */ 29 uint32_t off_count; 30 31 /* CRC used to validate the retained data. This must be 32 * stored little-endian, and covers everything up to but not 33 * including this field. 34 */ 35 uint32_t crc; 36 }; 37 38 /* For simplicity in the sample just allow anybody to see and 39 * manipulate the retained state. 40 */ 41 extern struct retained_data retained; 42 43 /* Check whether the retained data is valid, and if not reset it. 44 * 45 * @return true if and only if the data was valid and reflects state 46 * from previous sessions. 47 */ 48 bool retained_validate(void); 49 50 /* Update any generic retained state and recalculate its checksum so 51 * subsequent boots can verify the retained state. 52 */ 53 void retained_update(void); 54 55 #endif /* RETAINED_H_ */ 56