原始版本
This commit is contained in:
160
RT_Thread/components/fal/inc/fal.h
Normal file
160
RT_Thread/components/fal/inc/fal.h
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-17 armink the first version
|
||||
*/
|
||||
|
||||
#ifndef _FAL_H_
|
||||
#define _FAL_H_
|
||||
|
||||
#include <rtconfig.h>
|
||||
#include <fal_cfg.h>
|
||||
#include "fal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* FAL (Flash Abstraction Layer) initialization.
|
||||
* It will initialize all flash device and all flash partition.
|
||||
*
|
||||
* @return >= 0: partitions total number
|
||||
*/
|
||||
int fal_init(void);
|
||||
|
||||
/* =============== flash device operator API =============== */
|
||||
/**
|
||||
* find flash device by name
|
||||
*
|
||||
* @param name flash device name
|
||||
*
|
||||
* @return != NULL: flash device
|
||||
* NULL: not found
|
||||
*/
|
||||
const struct fal_flash_dev *fal_flash_device_find(const char *name);
|
||||
|
||||
/* =============== partition operator API =============== */
|
||||
/**
|
||||
* find the partition by name
|
||||
*
|
||||
* @param name partition name
|
||||
*
|
||||
* @return != NULL: partition
|
||||
* NULL: not found
|
||||
*/
|
||||
const struct fal_partition *fal_partition_find(const char *name);
|
||||
|
||||
/**
|
||||
* get the partition table
|
||||
*
|
||||
* @param len return the partition table length
|
||||
*
|
||||
* @return partition table
|
||||
*/
|
||||
const struct fal_partition *fal_get_partition_table(rt_size_t *len);
|
||||
|
||||
/**
|
||||
* set partition table temporarily
|
||||
* This setting will modify the partition table temporarily, the setting will be lost after restart.
|
||||
*
|
||||
* @param table partition table
|
||||
* @param len partition table length
|
||||
*/
|
||||
void fal_set_partition_table_temp(struct fal_partition *table, rt_size_t len);
|
||||
|
||||
/**
|
||||
* read data from partition
|
||||
*
|
||||
* @param part partition
|
||||
* @param addr relative address for partition
|
||||
* @param buf read buffer
|
||||
* @param size read size
|
||||
*
|
||||
* @return >= 0: successful read data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_read(const struct fal_partition *part, rt_uint32_t addr, rt_uint8_t *buf, rt_size_t size);
|
||||
|
||||
/**
|
||||
* write data to partition
|
||||
*
|
||||
* @param part partition
|
||||
* @param addr relative address for partition
|
||||
* @param buf write buffer
|
||||
* @param size write size
|
||||
*
|
||||
* @return >= 0: successful write data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_write(const struct fal_partition *part, rt_uint32_t addr, const rt_uint8_t *buf, rt_size_t size);
|
||||
|
||||
/**
|
||||
* erase partition data
|
||||
*
|
||||
* @param part partition
|
||||
* @param addr relative address for partition
|
||||
* @param size erase size
|
||||
*
|
||||
* @return >= 0: successful erased data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_erase(const struct fal_partition *part, rt_uint32_t addr, rt_size_t size);
|
||||
|
||||
/**
|
||||
* erase partition all data
|
||||
*
|
||||
* @param part partition
|
||||
*
|
||||
* @return >= 0: successful erased data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_erase_all(const struct fal_partition *part);
|
||||
|
||||
/**
|
||||
* print the partition table
|
||||
*/
|
||||
void fal_show_part_table(void);
|
||||
|
||||
/* =============== API provided to RT-Thread =============== */
|
||||
/**
|
||||
* create RT-Thread block device by specified partition
|
||||
*
|
||||
* @param parition_name partition name
|
||||
*
|
||||
* @return != NULL: created block device
|
||||
* NULL: created failed
|
||||
*/
|
||||
struct rt_device *fal_blk_device_create(const char *parition_name);
|
||||
|
||||
#if defined(RT_USING_MTD_NOR)
|
||||
/**
|
||||
* create RT-Thread MTD NOR device by specified partition
|
||||
*
|
||||
* @param parition_name partition name
|
||||
*
|
||||
* @return != NULL: created MTD NOR device
|
||||
* NULL: created failed
|
||||
*/
|
||||
struct rt_device *fal_mtd_nor_device_create(const char *parition_name);
|
||||
#endif /* defined(RT_USING_MTD_NOR) */
|
||||
|
||||
/**
|
||||
* create RT-Thread char device by specified partition
|
||||
*
|
||||
* @param parition_name partition name
|
||||
*
|
||||
* @return != NULL: created char device
|
||||
* NULL: created failed
|
||||
*/
|
||||
struct rt_device *fal_char_device_create(const char *parition_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FAL_H_ */
|
||||
77
RT_Thread/components/fal/inc/fal_def.h
Normal file
77
RT_Thread/components/fal/inc/fal_def.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-17 armink the first version
|
||||
*/
|
||||
|
||||
#ifndef _FAL_DEF_H_
|
||||
#define _FAL_DEF_H_
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* FAL flash and partition device name max length */
|
||||
#ifndef FAL_DEV_NAME_MAX
|
||||
#define FAL_DEV_NAME_MAX 24
|
||||
#endif
|
||||
|
||||
#ifndef FAL_DEV_BLK_MAX
|
||||
#define FAL_DEV_BLK_MAX 6
|
||||
#endif
|
||||
|
||||
struct flash_blk
|
||||
{
|
||||
rt_size_t size;
|
||||
rt_size_t count;
|
||||
};
|
||||
|
||||
struct fal_flash_dev
|
||||
{
|
||||
char name[FAL_DEV_NAME_MAX];
|
||||
|
||||
/* flash device start address and len */
|
||||
rt_uint32_t addr;
|
||||
rt_size_t len;
|
||||
/* the block size in the flash for erase minimum granularity */
|
||||
rt_size_t blk_size;
|
||||
|
||||
struct
|
||||
{
|
||||
int (*init)(void);
|
||||
int (*read)(long offset, rt_uint8_t *buf, rt_size_t size);
|
||||
int (*write)(long offset, const rt_uint8_t *buf, rt_size_t size);
|
||||
int (*erase)(long offset, rt_size_t size);
|
||||
} ops;
|
||||
|
||||
/* write minimum granularity, unit: bit.
|
||||
1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
|
||||
0 will not take effect. */
|
||||
rt_size_t write_gran;
|
||||
struct flash_blk blocks[FAL_DEV_BLK_MAX];
|
||||
};
|
||||
typedef struct fal_flash_dev *fal_flash_dev_t;
|
||||
|
||||
/**
|
||||
* FAL partition
|
||||
*/
|
||||
struct fal_partition
|
||||
{
|
||||
rt_uint32_t magic_word;
|
||||
|
||||
/* partition name */
|
||||
char name[FAL_DEV_NAME_MAX];
|
||||
/* flash device name for partition */
|
||||
char flash_name[FAL_DEV_NAME_MAX];
|
||||
|
||||
/* partition offset address on flash device */
|
||||
long offset;
|
||||
rt_size_t len;
|
||||
|
||||
rt_uint32_t reserved;
|
||||
};
|
||||
typedef struct fal_partition *fal_partition_t;
|
||||
|
||||
#endif /* _FAL_DEF_H_ */
|
||||
Reference in New Issue
Block a user