ef_def.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * This file is part of the EasyFlash Library.
  3. *
  4. * Copyright (c) 2019-2020, Armink, <armink.ztl@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * 'Software'), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Function: It is the definitions head file for this library.
  26. * Created on: 2019-11-20
  27. */
  28. #ifndef EF_DEF_H_
  29. #define EF_DEF_H_
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* EasyFlash software version number */
  34. #define EF_SW_VERSION "4.1.99"
  35. #define EF_SW_VERSION_NUM 0x40199
  36. /*
  37. * ENV version number defined by user.
  38. * Please change it when your firmware add a new ENV to default_env_set.
  39. */
  40. #ifndef EF_ENV_VER_NUM
  41. #define EF_ENV_VER_NUM 0
  42. #endif
  43. /* the ENV max name length must less then it */
  44. #ifndef EF_ENV_NAME_MAX
  45. #define EF_ENV_NAME_MAX 32
  46. #endif
  47. /* EasyFlash debug print function. Must be implement by user. */
  48. #ifdef PRINT_DEBUG
  49. #define EF_DEBUG(...) \
  50. do { \
  51. printk("%s ", "[ELOG]"); \
  52. printk(__VA_ARGS__); \
  53. printk("\n"); \
  54. } while (0)
  55. #else
  56. #define EF_DEBUG(...)
  57. #endif
  58. /* EasyFlash routine print function. Must be implement by user. */
  59. #define EF_INFO(...) ef_log_info(__VA_ARGS__)
  60. /* EasyFlash assert for developer. */
  61. #define EF_ASSERT(EXPR) __ASSERT_NO_MSG(EXPR)
  62. typedef struct _ef_env {
  63. char *key;
  64. void *value;
  65. size_t value_len;
  66. } ef_env, *ef_env_t;
  67. /* EasyFlash error code */
  68. typedef enum {
  69. EF_NO_ERR,
  70. EF_ERASE_ERR,
  71. EF_READ_ERR,
  72. EF_WRITE_ERR,
  73. EF_ENV_NAME_ERR,
  74. EF_ENV_NAME_EXIST,
  75. EF_ENV_FULL,
  76. EF_ENV_INIT_FAILED,
  77. } EfErrCode;
  78. /* the flash sector current status */
  79. typedef enum {
  80. EF_SECTOR_EMPTY,
  81. EF_SECTOR_USING,
  82. EF_SECTOR_FULL,
  83. } EfSecrorStatus;
  84. enum env_status {
  85. ENV_UNUSED,
  86. ENV_PRE_WRITE,
  87. ENV_WRITE,
  88. ENV_PRE_DELETE,
  89. ENV_DELETED,
  90. ENV_ERR_HDR,
  91. ENV_STATUS_NUM,
  92. };
  93. typedef enum env_status env_status_t;
  94. struct env_node_obj {
  95. env_status_t status; /**< ENV node status, @see node_status_t */
  96. bool crc_is_ok; /**< ENV node CRC32 check is OK */
  97. uint8_t name_len; /**< name length */
  98. uint32_t magic; /**< magic word(`K`, `V`, `4`, `0`) */
  99. uint32_t len; /**< ENV node total length (header + name + value), must align by EF_WRITE_GRAN */
  100. uint32_t value_len; /**< value length */
  101. char name[EF_ENV_NAME_MAX]; /**< name */
  102. struct {
  103. uint32_t start; /**< ENV node start address */
  104. uint32_t value; /**< value start address */
  105. } addr;
  106. };
  107. typedef struct env_node_obj *env_node_obj_t;
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif /* EF_DEF_H_ */