53 lines
2.0 KiB
C
53 lines
2.0 KiB
C
/**
|
|
* @file storage.h
|
|
* @author xushenghao
|
|
* @date 2024-11-15 15:57:02
|
|
* @brief 一个存储库,不支持平衡擦写
|
|
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
|
|
*/
|
|
#ifndef __STORAGE_H__
|
|
#define __STORAGE_H__
|
|
|
|
#include "lib.h"
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t index;
|
|
uint16_t size;
|
|
uint32_t address;
|
|
} storage_node_t;
|
|
|
|
typedef struct
|
|
{
|
|
clist_node_t *head;
|
|
struct
|
|
{
|
|
uint32_t base_addr; ///< 存储器基地址
|
|
uint16_t page_size; ///< 存储器页大小
|
|
uint16_t variable_count; ///< 存储器变量数量
|
|
uint16_t variable_size; ///< 存储器变量占用大小,如果变量大小不够一页剩余部分则写入下一页,上一页剩余字节计入变量占用大小
|
|
uint16_t page_count; ///< 变量占用存储器页数
|
|
} params;
|
|
|
|
struct
|
|
{
|
|
BOOL(*read)
|
|
(uint32_t addr, uint8_t *buf, uint16_t size);
|
|
BOOL(*write)
|
|
(uint32_t addr, uint8_t * buf, uint16_t size);
|
|
BOOL(*erase_page)
|
|
(uint32_t page);
|
|
} ops;
|
|
} storage_t;
|
|
|
|
storage_t *storage_init(uint32_t base_addr, uint16_t page_size); ///< 初始化存储器
|
|
void storage_destroy(storage_t *storage); ///< 销毁存储器
|
|
void storage_add_node(storage_t *storage, uint16_t index, uint16_t size); ///< 添加存储节点
|
|
BOOL storage_write(storage_t *storage, uint16_t index, const uint8_t *buf); ///< 存储数据
|
|
BOOL storage_read(storage_t *storage, uint16_t index, uint8_t *buf); ///< 读取数据
|
|
BOOL storage_write_all(storage_t *storage, const uint8_t *buf); ///< 存储所有数据
|
|
BOOL storage_read_all(storage_t *storage, uint8_t *buf); ///< 读取所有数据
|
|
BOOL storage_check(storage_t *storage, uint16_t index, uint8_t *buf); ///< 检查存储数据
|
|
BOOL storage_check_all(storage_t *storage, uint8_t *buf); ///< 检查所有存储数据
|
|
#endif // __STORAGE_H__
|