xt-sdk 文档
v1.0.3
xt-sdk 嵌入式 SDK API 参考
Toggle main menu visibility
载入中...
搜索中...
未找到
xt_fal.h
浏览该文件的文档.
1
12
13
#ifndef __XT_FAL_H__
14
#define __XT_FAL_H__
15
16
/* ==================== [Includes] ========================================== */
17
18
#include "
xt_error.h
"
19
20
#ifdef __cplusplus
21
extern
"C"
{
22
#endif
23
30
31
/* ==================== [Defines] =========================================== */
32
33
/* fal_id 编码: 高 4 位为 flash_id (0-15),低 4 位为分区索引 (0-15) */
34
#define XT_FAL_INVALID_ID (0xFF)
35
36
/* fal_id 操作宏 */
37
#define XT_FAL_GET_FLASH_ID(fal_id) (((fal_id) >> 4) & 0x0F)
38
#define XT_FAL_GET_PARTITION_IDX(fal_id) ((fal_id) & 0x0F)
39
#define XT_FAL_MAKE_ID(flash_id, part_idx) (((flash_id) << 4) | ((part_idx) & 0x0F))
40
41
/* flash 控制命令 */
42
#define XT_FAL_CTRL_INIT (0x00000001)
43
#define XT_FAL_CTRL_DEINIT (0x00000002)
44
45
/* 最大 Flash 设备数量(fal_id 高 4 位,最多 16 个) */
46
#ifndef XT_FAL_MAX_FLASH_COUNT
47
#define XT_FAL_MAX_FLASH_COUNT 16
48
#endif
49
50
/* 名字字符数 */
51
#ifndef XT_FAL_NAME_MAX
52
#define XT_FAL_NAME_MAX 16
53
#endif
54
55
/* ==================== [Typedefs] ========================================== */
56
57
#if !defined(XT_FAL_SIZE_T)
58
typedef
uint32_t
xt_fal_size_t
;
59
#else
60
typedef
XT_FAL_SIZE_T
xt_fal_size_t
;
61
#endif
62
63
struct
xt_fal_flash_ops
{
64
void (*
ctrl
)(uint32_t cmd,
void
*arg);
65
int32_t (*
read
)(
xt_fal_size_t
offset,
void
*dst,
xt_fal_size_t
size);
66
int32_t (*
write
)(
xt_fal_size_t
offset,
const
void
*src,
xt_fal_size_t
size);
67
int32_t (*
erase
)(
xt_fal_size_t
offset,
xt_fal_size_t
size);
68
};
69
70
struct
xt_fal_flash
{
71
char
name
[
XT_FAL_NAME_MAX
];
72
xt_fal_size_t
addr
;
73
xt_fal_size_t
size
;
74
xt_fal_size_t
block_size
;
75
xt_fal_size_t
io_size
;
76
struct
xt_fal_flash_ops
ops
;
77
};
78
79
struct
xt_fal_partition
{
80
char
name
[
XT_FAL_NAME_MAX
];
81
xt_fal_size_t
addr
;
83
xt_fal_size_t
size
;
84
xt_fal_size_t
flags
;
85
};
86
87
/* ==================== [Global Prototypes] ================================= */
88
97
uint8_t
xt_fal_register
(
const
struct
xt_fal_flash
*flash,
98
const
struct
xt_fal_partition
*part_table,
99
uint32_t part_count);
100
109
xt_err_t
xt_fal_unregister
(uint8_t flash_id,
110
const
struct
xt_fal_flash
**out_flash,
111
const
struct
xt_fal_partition
**out_part_table,
112
uint32_t *out_part_count);
113
118
xt_err_t
xt_fal_init
(
void
);
119
124
xt_err_t
xt_fal_deinit
(
void
);
125
131
uint8_t
xt_fal_get_flash_id_by_name
(
const
char
*flash_name);
132
138
uint8_t
xt_fal_get_id_by_name
(
const
char
*part_name);
139
145
const
struct
xt_fal_partition
*
xt_fal_get_partition_by_id
(uint8_t fal_id);
146
152
const
struct
xt_fal_flash
*
xt_fal_get_flash_by_id
(uint8_t fal_id);
153
162
int32_t
xt_fal_partition_read
(uint8_t fal_id,
xt_fal_size_t
offset,
void
*dst,
xt_fal_size_t
size
);
163
172
int32_t
xt_fal_partition_write
(uint8_t fal_id,
xt_fal_size_t
offset,
const
void
*src,
xt_fal_size_t
size
);
173
181
int32_t
xt_fal_partition_erase
(uint8_t fal_id,
xt_fal_size_t
offset,
xt_fal_size_t
size
);
182
183
/* ==================== [Macros] ============================================ */
184
/* xt_fal */
186
187
#ifdef __cplusplus
188
}
/* extern "C" */
189
#endif
190
191
#endif
/* __XT_FAL_H__ */
xt_err_t
int32_t xt_err_t
错误码类型
定义
xt_error.h:38
xt_fal_partition_read
int32_t xt_fal_partition_read(uint8_t fal_id, xt_fal_size_t offset, void *dst, xt_fal_size_t size)
读取分区数据
xt_fal_init
xt_err_t xt_fal_init(void)
初始化所有已注册的 Flash 设备
xt_fal_get_id_by_name
uint8_t xt_fal_get_id_by_name(const char *part_name)
通过分区名称获取 fal_id
xt_fal_get_flash_by_id
const struct xt_fal_flash * xt_fal_get_flash_by_id(uint8_t fal_id)
通过 fal_id 获取 Flash 设备指针
xt_fal_size_t
uint32_t xt_fal_size_t
定义
xt_fal.h:58
xt_fal_unregister
xt_err_t xt_fal_unregister(uint8_t flash_id, const struct xt_fal_flash **out_flash, const struct xt_fal_partition **out_part_table, uint32_t *out_part_count)
反注册 Flash 设备
xt_fal_get_flash_id_by_name
uint8_t xt_fal_get_flash_id_by_name(const char *flash_name)
通过名称获取 flash_id
xt_fal_deinit
xt_err_t xt_fal_deinit(void)
反初始化所有 Flash 设备
xt_fal_get_partition_by_id
const struct xt_fal_partition * xt_fal_get_partition_by_id(uint8_t fal_id)
通过 fal_id 获取分区指针
xt_fal_partition_write
int32_t xt_fal_partition_write(uint8_t fal_id, xt_fal_size_t offset, const void *src, xt_fal_size_t size)
写入分区数据
xt_fal_partition_erase
int32_t xt_fal_partition_erase(uint8_t fal_id, xt_fal_size_t offset, xt_fal_size_t size)
擦除分区
XT_FAL_NAME_MAX
#define XT_FAL_NAME_MAX
定义
xt_fal.h:52
xt_fal_register
uint8_t xt_fal_register(const struct xt_fal_flash *flash, const struct xt_fal_partition *part_table, uint32_t part_count)
注册 Flash 设备和分区表
xt_fal_flash_ops
定义
xt_fal.h:63
xt_fal_flash_ops::read
int32_t(* read)(xt_fal_size_t offset, void *dst, xt_fal_size_t size)
定义
xt_fal.h:65
xt_fal_flash_ops::write
int32_t(* write)(xt_fal_size_t offset, const void *src, xt_fal_size_t size)
定义
xt_fal.h:66
xt_fal_flash_ops::ctrl
void(* ctrl)(uint32_t cmd, void *arg)
定义
xt_fal.h:64
xt_fal_flash_ops::erase
int32_t(* erase)(xt_fal_size_t offset, xt_fal_size_t size)
定义
xt_fal.h:67
xt_fal_flash
定义
xt_fal.h:70
xt_fal_flash::ops
struct xt_fal_flash_ops ops
定义
xt_fal.h:76
xt_fal_flash::addr
xt_fal_size_t addr
定义
xt_fal.h:72
xt_fal_flash::block_size
xt_fal_size_t block_size
定义
xt_fal.h:74
xt_fal_flash::size
xt_fal_size_t size
定义
xt_fal.h:73
xt_fal_flash::name
char name[16]
定义
xt_fal.h:71
xt_fal_flash::io_size
xt_fal_size_t io_size
定义
xt_fal.h:75
xt_fal_partition
定义
xt_fal.h:79
xt_fal_partition::size
xt_fal_size_t size
定义
xt_fal.h:83
xt_fal_partition::addr
xt_fal_size_t addr
定义
xt_fal.h:81
xt_fal_partition::name
char name[16]
定义
xt_fal.h:80
xt_fal_partition::flags
xt_fal_size_t flags
定义
xt_fal.h:84
xt_error.h
XTINY 错误码定义
components
xt_fal
xt_fal.h
生成于
, 为 xt-sdk 文档使用
1.17.0