NVProperty generic key value store using the MCU flash area.
Dependents: Turtle_RadioShuttle
NVProperty_L4OTP.h
00001 /* 00002 * This is an unpublished work copyright 00003 * (c) 2019 Helmut Tschemernjak 00004 * 30826 Garbsen (Hannover) Germany 00005 * 00006 * 00007 * Use is granted to registered RadioShuttle licensees only. 00008 * Licensees must own a valid serial number and product code. 00009 * Details see: www.radioshuttle.de 00010 */ 00011 00012 #ifndef __NVPROPERTY_L4OTP__ 00013 #define __NVPROPERTY_L4OTP__ 00014 00015 class NVProperty_L4OTP : public NVPropertyProviderInterface { 00016 public: 00017 NVProperty_L4OTP(); 00018 ~NVProperty_L4OTP(); 00019 00020 virtual int GetProperty(int key); 00021 virtual int64_t GetProperty64(int key); 00022 virtual int GetPropertyBlob(int key, const void *blob, int *size); 00023 virtual const char *GetPropertyStr(int key); 00024 virtual int SetProperty(int key, int64_t value, int type); 00025 virtual int SetPropertyStr(int key, const char *value, int type); 00026 virtual int SetPropertyBlob(int key, const void *blob, int size, int type); 00027 virtual int EraseProperty(int key); 00028 virtual int ReorgProperties(void); 00029 virtual int OpenPropertyStore(bool forWrite = false); 00030 virtual int ClosePropertyStore(bool flush = false); 00031 00032 private: 00033 void _FlashInititalize(void); 00034 void _OTPWrite(uint8_t *address, const void *data, size_t length); 00035 00036 struct _flash_header { 00037 uint32_t magic; 00038 uint16_t version; 00039 uint16_t size; 00040 }; 00041 00042 static const int FLASH_ENTRY_MIN_SIZE = 8; 00043 static const int MAX_DATA_ENTRY = 256-FLASH_ENTRY_MIN_SIZE; 00044 static const int FLASH_PADDING_SIZE = 8; // writes sizes and alignment must be multiple of 64-bit, 00045 00046 struct _flashEntry { 00047 uint8_t key; // Property key 00048 struct { 00049 uint8_t deleted : 1; // this key has been deleted 00050 uint8_t t_bit : 1; // contains the bool value 00051 uint8_t reserv1 : 1; // 00052 uint8_t reserv2 : 1; // 00053 uint8_t type : 4; // NVPType 00054 } t; 00055 union { 00056 int16_t v_16bit; 00057 int8_t v_8bit; 00058 struct { 00059 uint8_t d_len; // data length 00060 uint8_t f_reserv1 : 8; 00061 } option; 00062 } u; 00063 union { 00064 int32_t v_32bit; 00065 int32_t v_64bit[2]; // use use 2 x 32-bit to avoid 64-bit struct padding 00066 char v_str[MAX_DATA_ENTRY]; 00067 uint8_t v_blob[MAX_DATA_ENTRY]; 00068 } data; 00069 }; 00070 00071 _flashEntry * _GetFlashEntry(int key, uint8_t *start = NULL); 00072 void _DumpAllEntires(void); 00073 int _GetFlashEntryLen(_flashEntry *k); 00074 int _GetFlashPaddingSize(int len); 00075 int _FlashReorgEntries(int minRequiredSpace); 00076 00077 _flashEntry *_lastEntry; 00078 uint8_t *_startAddress; 00079 uint8_t *_endAddress; 00080 bool _debug; 00081 int _propSize; 00082 00083 static const uint8_t _flashErasedValue = 0xff; 00084 static const int FLASH_PROP_MAGIC = 0x4c4f5450; // "LOTP" 00085 static const int FLASH_PROP_VERSION = 1; 00086 }; 00087 00088 #endif // __NVPROPERTY_L4OTP__
Generated on Tue Jul 12 2022 20:44:07 by 1.7.2