71 lines
2.1 KiB
C
71 lines
2.1 KiB
C
|
|
#ifndef __DRV_FLASH_H__
|
|||
|
|
#define __DRV_FLASH_H__
|
|||
|
|
|
|||
|
|
#include <stdint.h>
|
|||
|
|
#include <string.h>
|
|||
|
|
|
|||
|
|
enum flash_state {
|
|||
|
|
/* 数据无效帧头/帧尾,等于flash擦除后的值取反 */
|
|||
|
|
FLASH_NULL = 0x00,
|
|||
|
|
/* 数据可读帧头 */
|
|||
|
|
FLASH_READABLE_HEAD = 0xa5,
|
|||
|
|
/* 数据可读帧尾 */
|
|||
|
|
FLASH_READABLE_TAIL = 0x5a,
|
|||
|
|
/* 数据可写帧头/帧尾,等于flash擦除后的值 */
|
|||
|
|
FLASH_WRITABLE = 0xff,
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
typedef enum {
|
|||
|
|
/* 不覆写模式 */
|
|||
|
|
FLASH_NO_OVERWRITING_MODE = 0x00,
|
|||
|
|
/* 覆写模式, 即写入数据后将先前同类型数据置为无效 */
|
|||
|
|
FLASH_OVERWRITING_MODE,
|
|||
|
|
/* 读取不清空模式 */
|
|||
|
|
FLASH_NO_CLEAR_MODE,
|
|||
|
|
/* 读取清空模式,即读取数据所在的flash位置0 */
|
|||
|
|
FLASH_CLEAR_MODE,
|
|||
|
|
} flash_write_read_mode_t;
|
|||
|
|
|
|||
|
|
typedef struct {
|
|||
|
|
/* 可读表标志位,表示当前是否存在可读数据 */
|
|||
|
|
uint8_t state;
|
|||
|
|
/* 可读数据大小, 包含帧头帧尾 */
|
|||
|
|
uint16_t size;
|
|||
|
|
/* 可读数据起始地址, 包含帧头 */
|
|||
|
|
uint32_t addr;
|
|||
|
|
} type_readable_frame_t;
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
/* 地址对齐数, 1-2^5 */
|
|||
|
|
uint8_t align_num;
|
|||
|
|
/* flash写入模式 */
|
|||
|
|
flash_write_read_mode_t flash_write_mode;
|
|||
|
|
/* flashdu'q'b模式 */
|
|||
|
|
flash_write_read_mode_t flash_read_mode;
|
|||
|
|
/* 管理的flash起始地址,按扇区对齐 */
|
|||
|
|
uint32_t flash_start_address;
|
|||
|
|
/* 管理的flash扇区数量 */
|
|||
|
|
uint32_t manage_sector_num;
|
|||
|
|
/* flash的扇区大小 */
|
|||
|
|
uint32_t sector_size;
|
|||
|
|
|
|||
|
|
/* 开启flash */
|
|||
|
|
void (*open_flash)(void);
|
|||
|
|
/* 关闭flash */
|
|||
|
|
void (*close_flash)(void);
|
|||
|
|
/* 读flash */
|
|||
|
|
void (*read_flash)(uint8_t *pbuf, uint32_t addr, uint16_t datalen);
|
|||
|
|
/* 写flash */
|
|||
|
|
void (*write_flash)(uint8_t *pbuf, uint32_t addr, uint16_t datalen);
|
|||
|
|
/* 擦除flash */
|
|||
|
|
uint8_t (*erase_sector)(uint32_t addr);
|
|||
|
|
} flash_manage_t;
|
|||
|
|
|
|||
|
|
int8_t flash_manage_init(flash_manage_t *flash_manage);
|
|||
|
|
int8_t flash_manage_read(flash_manage_t *flash_manage, uint8_t *pbuf, uint8_t frame_type);
|
|||
|
|
int8_t flash_manage_write(flash_manage_t *flash_manage, uint8_t *pbuf, uint16_t size, uint8_t frame_type);
|
|||
|
|
|
|||
|
|
|
|||
|
|
#endif /* _FLASH_MANAGE_H__ */
|