fs.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief Contains all functions support for spi driver
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. /*******************************************************************************
  11. * @file fs.h
  12. * @brief Contains all functions support for spi driver
  13. * @version 0.0
  14. * @date 18. Oct. 2017
  15. * @author
  16. *
  17. *
  18. *******************************************************************************/
  19. #ifndef __FS_H__
  20. #define __FS_H__
  21. #include "types.h"
  22. /**************************************************************************************
  23. * @fn hal_fs_init
  24. *
  25. * @brief initialize fs.
  26. * if fs is new,use fs_start_address and sector_num to config fs.
  27. * if fs is not new,read fs every sector head data and check with fs_start_address and sector_num,
  28. * if same,the fs is valid,else is invalid.
  29. *
  30. * input parameters
  31. *
  32. * @param fs_start_address:
  33. * fs zone start address,4Kbyte align.
  34. *
  35. * sector_num:
  36. * fs zone sector number,one sector = 4Kbyte,its minimal size is 2.
  37. *
  38. * output parameters
  39. *
  40. * @param None.
  41. *
  42. * @return
  43. * ERR_NONE fs init success.
  44. * ERR_FS_UNINITIALIZED fs has not been inited.
  45. * ERR_INVALID_PARAM parameter error,check your parameter.
  46. * ERR_FS_CONTEXT fs has data but different with your parameter.
  47. * ERR_FS_WRITE_FAILED flash cannot write.
  48. * ERR_FS_RESERVED_ERROR reserved error.
  49. **************************************************************************************/
  50. int hal_fs_init(uint32_t fs_start_address,uint8_t sector_num);
  51. /**************************************************************************************
  52. * @fn hal_fs_item_read
  53. *
  54. * @brief read a file from fs.
  55. *
  56. * input parameters
  57. *
  58. * @param id:file id,it should be unique.
  59. *
  60. * buf:file buf to be read.
  61. *
  62. * buf_len:file buf len.
  63. *
  64. * len:*len is the file length after read from fs.
  65. *
  66. * output parameters
  67. *
  68. * @param None.
  69. *
  70. * @return
  71. * ERR_NONE file write success.
  72. * ERR_FS_IN_INT write later beyond int processing.
  73. * ERR_FS_UNINITIALIZED fs has not been inited.
  74. * ERR_FS_PARAMETER parameter error,check it.
  75. * ERR_FS_BUFFER_TOO_SMALL buf is too small.
  76. * ERR_FS_NOT_FIND_ID there is no this file in fs.
  77. **************************************************************************************/
  78. int hal_fs_item_read(uint16_t id,uint8_t* buf,uint16_t buf_len,uint16_t* len);
  79. /**************************************************************************************
  80. * @fn hal_fs_item_write
  81. *
  82. * @brief write a file to fs.
  83. *
  84. * input parameters
  85. *
  86. * @param id:file id,it should be unique.
  87. *
  88. * buf:file buf.
  89. *
  90. * len:file length.
  91. *
  92. * output parameters
  93. *
  94. * @param None.
  95. *
  96. * @return
  97. * ERR_NONE file write success
  98. * ERR_FS_IN_INT write later beyond int processing
  99. * ERR_FS_UNINITIALIZED fs has not been inited
  100. * ERR_FS_PARAMETER parameter error,check it
  101. * ERR_FS_NOT_ENOUGH_SIZE there is not enouth size to write this file
  102. * ERR_FATAL there is a same id file,when delete it,occur a error
  103. **************************************************************************************/
  104. int hal_fs_item_write(uint16_t id,uint8_t* buf,uint16_t len);
  105. /**************************************************************************************
  106. * @fn hal_fs_get_free_size
  107. *
  108. * @brief get fs free size.
  109. * just file data not include file head.
  110. * for example,16bytes=4byte+12byte,free size is 12byte.
  111. *
  112. * input parameters
  113. *
  114. * @param None.
  115. * output parameters
  116. *
  117. * @param None.
  118. *
  119. * @return
  120. * free size
  121. **************************************************************************************/
  122. uint32_t hal_fs_get_free_size(void);
  123. /**************************************************************************************
  124. * @fn hal_fs_get_garbage_size
  125. *
  126. * @brief get fs garbage size.
  127. * some deleted files is in garbage,its size is garbage sise.
  128. * only after garbage collect the garbage will be released to free.
  129. * just file data not include file head.
  130. * for example,16bytes=4byte+12byte,garbage size is 12byte.
  131. *
  132. * input parameters
  133. *
  134. * @param None.
  135. * output parameters
  136. *
  137. * @param garbage_file_num:deleted file number
  138. *
  139. * @return
  140. * garbage size
  141. **************************************************************************************/
  142. int hal_fs_get_garbage_size(uint32_t* garbage_file_num);
  143. /**************************************************************************************
  144. * @fn hal_fs_item_del
  145. *
  146. * @brief delete a file from fs.
  147. *
  148. * input parameters
  149. *
  150. * @param id:file id,it should be unique.
  151. * output parameters
  152. *
  153. * @param None.
  154. *
  155. * @return
  156. * ERR_NONE file delete success
  157. * ERR_FS_IN_INT delete later beyond int processing
  158. * ERR_FS_UNINITIALIZED fs has not been inited
  159. * ERR_FS_NOT_FIND_ID not find this file in fs
  160. **************************************************************************************/
  161. int hal_fs_item_del(uint16_t id);
  162. /**************************************************************************************
  163. * @fn hal_fs_garbage_collect
  164. *
  165. * @brief release all deleted file zone to free
  166. *
  167. * input parameters
  168. *
  169. * @param None.
  170. * output parameters
  171. *
  172. * @param None.
  173. *
  174. * @return
  175. * ERR_NONE collect success
  176. * ERR_FS_IN_INT delete later beyond int processing
  177. * ERR_FS_UNINITIALIZED fs has not been inited
  178. * ERR_FS_WRITE_FAILED flash cannot write.
  179. * ERR_FS_UNINITIALIZED fs has not been inited.
  180. * ERR_FS_CONTEXT fs has data but different with your parameter.
  181. * ERR_FS_RESERVED_ERROR reserved error.
  182. **************************************************************************************/
  183. int hal_fs_garbage_collect(void);
  184. /**************************************************************************************
  185. * @fn hal_fs_format
  186. *
  187. * @brief format fs.all fs data will be clean.
  188. *
  189. * input parameters
  190. *
  191. * @param fs_start_address:
  192. * fs zone start address,4Kbyte align.
  193. *
  194. * sector_num:
  195. * fs zone sector number,one sector = 4Kbyte,its minimal size is 3.
  196. *
  197. * output parameters
  198. *
  199. * @param None.
  200. *
  201. * @return
  202. * ERR_NONE fs format and init success.
  203. * ERR_FS_IN_INT delete later beyond int processing
  204. * ERR_FS_UNINITIALIZED fs has not been inited.
  205. * ERR_INVALID_PARAM parameter error,check your parameter.
  206. * ERR_FS_CONTEXT fs has data but different with your parameter.
  207. * ERR_FS_WRITE_FAILED flash cannot write.
  208. * ERR_FS_RESERVED_ERROR reserved error.
  209. **************************************************************************************/
  210. int hal_fs_format(uint32_t fs_start_address,uint8_t sector_num);
  211. /**************************************************************************************
  212. * @fn hal_fs_initialized
  213. *
  214. * @brief fs has been initialized or not.
  215. * if not,fs is disable,please use hal_fs_init to initialize it.
  216. *
  217. * input parameters
  218. *
  219. * @param none.
  220. *
  221. * output parameters
  222. *
  223. * @param None.
  224. *
  225. * @return
  226. * TRUE
  227. * FALSE
  228. **************************************************************************************/
  229. bool hal_fs_initialized(void);
  230. #endif