#ifndef USER_FSD_H__ #define USER_FSD_H__ #include #include #include #include "define.h" #include "nrf_fstorage.h" #include "nrf_fstorage_sd.h" #ifndef FLASH_PAGE_SIZE #define FLASH_PAGE_SIZE 4096 #endif //页起始地址 #define USER_FLASH_START_ADDR FLASH_PAGE_SIZE*USER_FLASH_START_PAGE_NUM #define USER_FLASH_END_ADDR USER_FLASH_START_ADDR+FLASH_PAGE_SIZE typedef enum { FSTORAGE_NULL, FSTORAGE_WRITE, FSTORAGE_READ, FSTORAGE_ERASE } fstorage_work_type_t; typedef enum { FSTORAGE_FAIL, FSTORAGE_WRITE_OK, FSTORAGE_READ_OK, FSTORAGE_ERASE_OK } fstorage_stat_type_t; typedef void (*fsd_rec_func)(fstorage_stat_type_t stat); typedef struct { fsd_rec_func func; fstorage_work_type_t type; fstorage_work_type_t next_type; uint16_t data_len; uint8_t *data; } fstorage_work_s; /** * @brief fstorage event handler. * * @param[in] p_event Pointer to an fstorage event. The event structure is allocated on * the stack, so it is valid only within the context of * the event handler. */ //typedef void (* nrf_fstorage_event_handler_t)(nrf_fstorage_evt_t const * p_event); /******************************************************************* * Function Nume: flash_write_data * Descriptions : write data from flash * In Para : address: address to access(address must be word-aligned), length: length to be read(4 integer multiple) * In-Out Para : none * Out Para : data: data buffer to be read * Return Value : FLASH_SUCCESS: success, FLASH_ERROR_INVALID_ADDRESS: address error *******************************************************************/ ret_code_t flash_write_data(uint32_t address, uint8_t *data, uint16_t length); /******************************************************************* * Function Nume: flash_read_data * Descriptions : read data from flash * In Para : address: address to access(align=2), length: length to be read(4 integer multiple) * In-Out Para : none * Out Para : data: data buffer to be read * Return Value : FLASH_SUCCESS: success, FLASH_ERROR_INVALID_ADDRESS: address error *******************************************************************/ ret_code_t flash_read_data(uint32_t address, uint8_t *data, uint16_t length); /******************************************************************* * Function Nume: flash_erase_data * Descriptions : erase flash data * In Para : address: address to access(align=2), length: length to be erased(4 integer multiple) * In-Out Para : none * Out Para : none * Return Value : FLASH_SUCCESS: success, FLASH_ERROR_INVALID_ADDRESS: address error *******************************************************************/ ret_code_t flash_erase_data(uint32_t address, uint16_t length); ret_code_t flash_init(nrf_fstorage_api_t * p_fs_api); ret_code_t flash_uninit(nrf_fstorage_api_t * p_fs_api); void free_fsdwrarray(void); extern fstorage_work_s fstorage_work; #endif //USER_FSD_H__