fs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /*******************************************************************************
  29. * @file fs.h
  30. * @brief Contains all functions support for spi driver
  31. * @version 0.0
  32. * @date 18. Oct. 2017
  33. * @author
  34. *
  35. * Copyright(C) 2016, PhyPlus Semiconductor
  36. * All rights reserved.
  37. *
  38. *******************************************************************************/
  39. #ifndef __FS_H__
  40. #define __FS_H__
  41. #include "types.h"
  42. /**************************************************************************************
  43. * @fn hal_fs_init
  44. *
  45. * @brief initialize fs.
  46. * if fs is new,use fs_start_address and sector_num to config fs.
  47. * if fs is not new,read fs every sector head data and check with fs_start_address and sector_num,
  48. * if same,the fs is valid,else is invalid.
  49. *
  50. * input parameters
  51. *
  52. * @param fs_start_address:
  53. * fs zone start address,4Kbyte align.
  54. * fs zone should not cover phy code and app code.
  55. *
  56. * sector_num:
  57. * fs zone sector number,one sector = 4Kbyte,its minimal size is 3.
  58. * fs zone should not cover phy code and app code.
  59. *
  60. * output parameters
  61. *
  62. * @param None.
  63. *
  64. * @return
  65. * PPlus_SUCCESS fs init success.
  66. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited.
  67. * PPlus_ERR_INVALID_PARAM parameter error,check your parameter.
  68. * PPlus_ERR_FS_CONTEXT fs has data but different with your parameter.
  69. * PPlus_ERR_FS_WRITE_FAILED flash cannot write.
  70. * PPlus_ERR_FS_RESERVED_ERROR reserved error.
  71. **************************************************************************************/
  72. int hal_fs_init(uint32_t fs_start_address,uint8_t sector_num);
  73. /**************************************************************************************
  74. * @fn hal_fs_item_read
  75. *
  76. * @brief read a file from fs.
  77. *
  78. * input parameters
  79. *
  80. * @param id:file id,it should be unique.
  81. *
  82. * buf:file buf to be read.
  83. *
  84. * buf_len:file buf len.
  85. *
  86. * len:*len is the file length after read from fs.
  87. *
  88. * output parameters
  89. *
  90. * @param None.
  91. *
  92. * @return
  93. * PPlus_SUCCESS file write success.
  94. * PPlus_ERR_FS_IN_INT write later beyond int processing.
  95. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited.
  96. * PPlus_ERR_FS_PARAMETER parameter error,check it.
  97. * PPlus_ERR_FS_BUFFER_TOO_SMALL buf is too small.
  98. * PPlus_ERR_FS_NOT_FIND_ID there is no this file in fs.
  99. **************************************************************************************/
  100. int hal_fs_item_read(uint16_t id,uint8_t* buf,uint16_t buf_len,uint16_t* len);
  101. /**************************************************************************************
  102. * @fn hal_fs_item_write
  103. *
  104. * @brief write a file to fs.
  105. *
  106. * input parameters
  107. *
  108. * @param id:file id,it should be unique.
  109. *
  110. * buf:file buf.
  111. *
  112. * len:file length.
  113. *
  114. * output parameters
  115. *
  116. * @param None.
  117. *
  118. * @return
  119. * PPlus_SUCCESS file write success
  120. * PPlus_ERR_FS_IN_INT write later beyond int processing
  121. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited
  122. * PPlus_ERR_FS_PARAMETER parameter error,check it
  123. * PPlus_ERR_FS_NOT_ENOUGH_SIZE there is not enouth size to write this file
  124. * PPlus_ERR_FATAL there is a same id file,when delete it,occur a error
  125. **************************************************************************************/
  126. int hal_fs_item_write(uint16_t id,uint8_t* buf,uint16_t len);
  127. /**************************************************************************************
  128. * @fn hal_fs_get_free_size
  129. *
  130. * @brief get fs free size.
  131. * just file data not include file head.
  132. * for example,16bytes=4byte+12byte,free size is 12byte.
  133. *
  134. * input parameters
  135. *
  136. * @param None.
  137. * output parameters
  138. *
  139. * @param None.
  140. *
  141. * @return
  142. * free size
  143. **************************************************************************************/
  144. uint32_t hal_fs_get_free_size(void);
  145. /**************************************************************************************
  146. * @fn hal_fs_get_garbage_size
  147. *
  148. * @brief get fs garbage size.
  149. * some deleted files is in garbage,its size is garbage sise.
  150. * only after garbage collect the garbage will be released to free.
  151. * just file data not include file head.
  152. * for example,16bytes=4byte+12byte,garbage size is 12byte.
  153. *
  154. * input parameters
  155. *
  156. * @param None.
  157. * output parameters
  158. *
  159. * @param garbage_file_num:deleted file number
  160. *
  161. * @return
  162. * garbage size
  163. **************************************************************************************/
  164. int hal_fs_get_garbage_size(uint32_t* garbage_file_num);
  165. /**************************************************************************************
  166. * @fn hal_fs_item_del
  167. *
  168. * @brief delete a file from fs.
  169. *
  170. * input parameters
  171. *
  172. * @param id:file id,it should be unique.
  173. * output parameters
  174. *
  175. * @param None.
  176. *
  177. * @return
  178. * PPlus_SUCCESS file delete success
  179. * PPlus_ERR_FS_IN_INT delete later beyond int processing
  180. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited
  181. * PPlus_ERR_FS_NOT_FIND_ID not find this file in fs
  182. **************************************************************************************/
  183. int hal_fs_item_del(uint16_t id);
  184. /**************************************************************************************
  185. * @fn hal_fs_garbage_collect
  186. *
  187. * @brief release all deleted file zone to free
  188. *
  189. * input parameters
  190. *
  191. * @param None.
  192. * output parameters
  193. *
  194. * @param None.
  195. *
  196. * @return
  197. * PPlus_SUCCESS collect success
  198. * PPlus_ERR_FS_IN_INT delete later beyond int processing
  199. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited
  200. * PPlus_ERR_FS_WRITE_FAILED flash cannot write.
  201. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited.
  202. * PPlus_ERR_FS_CONTEXT fs has data but different with your parameter.
  203. * PPlus_ERR_FS_RESERVED_ERROR reserved error.
  204. **************************************************************************************/
  205. int hal_fs_garbage_collect(void);
  206. /**************************************************************************************
  207. * @fn hal_fs_format
  208. *
  209. * @brief format fs.all fs data will be clean.
  210. *
  211. * input parameters
  212. *
  213. * @param fs_start_address:
  214. * fs zone start address,4Kbyte align.
  215. * fs zone should not cover phy code and app code.
  216. *
  217. * sector_num:
  218. * fs zone sector number,one sector = 4Kbyte,its minimal size is 3.
  219. * fs zone should not cover phy code and app code.
  220. *
  221. * output parameters
  222. *
  223. * @param None.
  224. *
  225. * @return
  226. * PPlus_SUCCESS fs format and init success.
  227. * PPlus_ERR_FS_IN_INT delete later beyond int processing
  228. * PPlus_ERR_FS_UNINITIALIZED fs has not been inited.
  229. * PPlus_ERR_INVALID_PARAM parameter error,check your parameter.
  230. * PPlus_ERR_FS_CONTEXT fs has data but different with your parameter.
  231. * PPlus_ERR_FS_WRITE_FAILED flash cannot write.
  232. * PPlus_ERR_FS_RESERVED_ERROR reserved error.
  233. **************************************************************************************/
  234. int hal_fs_format(uint32_t fs_start_address,uint8_t sector_num);
  235. /**************************************************************************************
  236. * @fn hal_fs_initialized
  237. *
  238. * @brief fs has been initialized or not.
  239. * if not,fs is disable,please use hal_fs_init to initialize it.
  240. *
  241. * input parameters
  242. *
  243. * @param none.
  244. *
  245. * output parameters
  246. *
  247. * @param None.
  248. *
  249. * @return
  250. * TRUE
  251. * FALSE
  252. **************************************************************************************/
  253. bool hal_fs_initialized(void);
  254. #endif