You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
932 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include "project_configs.h"
  3. #include "sdk/os/zos.hpp"
  4. #ifdef IFLYTOP_NVS_CONFIG_FLASH_SECTOR
  5. namespace iflytop {
  6. using namespace std;
  7. class ZNVS {
  8. typedef struct {
  9. const char* name;
  10. uint8_t* defaultval;
  11. size_t len;
  12. } cfg_index_t;
  13. #pragma pack(1)
  14. typedef struct {
  15. uint32_t config_start;
  16. uint32_t data_size;
  17. uint8_t data[];
  18. } config_t;
  19. #pragma pack()
  20. cfg_index_t m_index[20];
  21. int m_index_num = 0;
  22. bool inited = false;
  23. config_t* m_cfgcache = nullptr;
  24. size_t m_cfgcachesize = 0;
  25. public:
  26. static ZNVS& ins();
  27. void initialize();
  28. bool alloc_config(const char* key, uint8_t* data, size_t datalen);
  29. bool init_config();
  30. bool get_config(const char* key, uint8_t* data, size_t len);
  31. bool set_config(const char* key, uint8_t* data, size_t len);
  32. void flush();
  33. private:
  34. void flush_all_to_configcache();
  35. };
  36. #endif
  37. } // namespace iflytop