user_fsd.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef USER_FSD_H__
  2. #define USER_FSD_H__
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include "define.h"
  7. #include "nrf_fstorage.h"
  8. #include "nrf_fstorage_sd.h"
  9. #ifndef FLASH_PAGE_SIZE
  10. #define FLASH_PAGE_SIZE 4096
  11. #endif
  12. //页起始地址
  13. #define USER_FLASH_START_ADDR FLASH_PAGE_SIZE*USER_FLASH_START_PAGE_NUM
  14. #define USER_FLASH_END_ADDR USER_FLASH_START_ADDR+FLASH_PAGE_SIZE
  15. typedef enum
  16. {
  17. FSTORAGE_NULL,
  18. FSTORAGE_WRITE,
  19. FSTORAGE_READ,
  20. FSTORAGE_ERASE
  21. } fstorage_work_type_t;
  22. typedef enum
  23. {
  24. FSTORAGE_FAIL,
  25. FSTORAGE_WRITE_OK,
  26. FSTORAGE_READ_OK,
  27. FSTORAGE_ERASE_OK
  28. } fstorage_stat_type_t;
  29. typedef void (*fsd_rec_func)(fstorage_stat_type_t stat);
  30. typedef struct
  31. {
  32. fsd_rec_func func;
  33. fstorage_work_type_t type;
  34. fstorage_work_type_t next_type;
  35. uint16_t data_len;
  36. uint8_t *data;
  37. } fstorage_work_s;
  38. /**
  39. * @brief fstorage event handler.
  40. *
  41. * @param[in] p_event Pointer to an fstorage event. The event structure is allocated on
  42. * the stack, so it is valid only within the context of
  43. * the event handler.
  44. */
  45. //typedef void (* nrf_fstorage_event_handler_t)(nrf_fstorage_evt_t const * p_event);
  46. /*******************************************************************
  47. * Function Nume: flash_write_data
  48. * Descriptions : write data from flash
  49. * In Para : address: address to access(address must be word-aligned), length: length to be read(4 integer multiple)
  50. * In-Out Para : none
  51. * Out Para : data: data buffer to be read
  52. * Return Value : FLASH_SUCCESS: success, FLASH_ERROR_INVALID_ADDRESS: address error
  53. *******************************************************************/
  54. ret_code_t flash_write_data(uint32_t address, uint8_t *data, uint16_t length);
  55. /*******************************************************************
  56. * Function Nume: flash_read_data
  57. * Descriptions : read data from flash
  58. * In Para : address: address to access(align=2), length: length to be read(4 integer multiple)
  59. * In-Out Para : none
  60. * Out Para : data: data buffer to be read
  61. * Return Value : FLASH_SUCCESS: success, FLASH_ERROR_INVALID_ADDRESS: address error
  62. *******************************************************************/
  63. ret_code_t flash_read_data(uint32_t address, uint8_t *data, uint16_t length);
  64. /*******************************************************************
  65. * Function Nume: flash_erase_data
  66. * Descriptions : erase flash data
  67. * In Para : address: address to access(align=2), length: length to be erased(4 integer multiple)
  68. * In-Out Para : none
  69. * Out Para : none
  70. * Return Value : FLASH_SUCCESS: success, FLASH_ERROR_INVALID_ADDRESS: address error
  71. *******************************************************************/
  72. ret_code_t flash_erase_data(uint32_t address, uint16_t length);
  73. ret_code_t flash_init(nrf_fstorage_api_t * p_fs_api);
  74. ret_code_t flash_uninit(nrf_fstorage_api_t * p_fs_api);
  75. void free_fsdwrarray(void);
  76. extern fstorage_work_s fstorage_work;
  77. #endif //USER_FSD_H__