mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-21 10:25:54 +08:00
更新硬件SDK
This commit is contained in:
165
sdk/合宙/air780e/csdk/luatos-soc-2022/thirdparty/fal/inc/fal.h
vendored
Normal file
165
sdk/合宙/air780e/csdk/luatos-soc-2022/thirdparty/fal/inc/fal.h
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* File : fal.h
|
||||
* This file is part of FAL (Flash Abstraction Layer) package
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-17 armink the first version
|
||||
*/
|
||||
|
||||
#ifndef _FAL_H_
|
||||
#define _FAL_H_
|
||||
|
||||
#include <fal_cfg.h>
|
||||
#include "fal_def.h"
|
||||
|
||||
/**
|
||||
* 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(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, 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, uint32_t addr, uint8_t *buf, 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, uint32_t addr, const uint8_t *buf, 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, uint32_t addr, 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);
|
||||
|
||||
#endif /* _FAL_H_ */
|
||||
23
sdk/合宙/air780e/csdk/luatos-soc-2022/thirdparty/fal/inc/fal_cfg.h
vendored
Normal file
23
sdk/合宙/air780e/csdk/luatos-soc-2022/thirdparty/fal/inc/fal_cfg.h
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _FAL_CFG_H_
|
||||
#define _FAL_CFG_H_
|
||||
|
||||
#define FAL_PART_HAS_TABLE_CFG
|
||||
|
||||
// #define NOR_FLASH_DEV_NAME "spiflash"
|
||||
|
||||
/* ===================== Flash device Configuration ========================= */
|
||||
extern const struct fal_flash_dev onchip_flash;
|
||||
//extern struct fal_flash_dev spi_flash0;
|
||||
|
||||
/* flash device table */
|
||||
#define FAL_FLASH_DEV_TABLE \
|
||||
{ \
|
||||
&onchip_flash \
|
||||
}
|
||||
/* ====================== Partition Configuration ========================== */
|
||||
#define FAL_PART_TABLE \
|
||||
{ \
|
||||
{FAL_PART_MAGIC_WORD, "onchip_fdb", "onchip_flash", 0, 64*1024, 0} \
|
||||
}
|
||||
|
||||
#endif /* _FAL_CFG_H_ */
|
||||
162
sdk/合宙/air780e/csdk/luatos-soc-2022/thirdparty/fal/inc/fal_def.h
vendored
Normal file
162
sdk/合宙/air780e/csdk/luatos-soc-2022/thirdparty/fal/inc/fal_def.h
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* File : fal_def.h
|
||||
* This file is part of FAL (Flash Abstraction Layer) package
|
||||
* COPYRIGHT (C) 2006 - 2019, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-17 armink the first version
|
||||
*/
|
||||
|
||||
#ifndef _FAL_DEF_H_
|
||||
#define _FAL_DEF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common_api.h"
|
||||
|
||||
#define FAL_PRINTF DBG
|
||||
|
||||
#define FAL_SW_VERSION "0.5.0"
|
||||
|
||||
#ifndef FAL_MALLOC
|
||||
#define FAL_MALLOC malloc
|
||||
#endif
|
||||
|
||||
#ifndef FAL_CALLOC
|
||||
#define FAL_CALLOC calloc
|
||||
#endif
|
||||
|
||||
#ifndef FAL_REALLOC
|
||||
#define FAL_REALLOC realloc
|
||||
#endif
|
||||
|
||||
#ifndef FAL_FREE
|
||||
#define FAL_FREE free
|
||||
#endif
|
||||
|
||||
#ifndef FAL_DEBUG
|
||||
#define FAL_DEBUG 0
|
||||
#endif
|
||||
|
||||
#ifndef FAL_PRINTF
|
||||
#ifdef RT_VER_NUM
|
||||
/* for RT-Thread platform */
|
||||
extern void rt_kprintf(const char *fmt, ...);
|
||||
#define FAL_PRINTF rt_kprintf
|
||||
#else
|
||||
#define FAL_PRINTF printf
|
||||
#endif /* RT_VER_NUM */
|
||||
#endif /* FAL_PRINTF */
|
||||
|
||||
#if FAL_DEBUG
|
||||
#ifdef assert
|
||||
#undef assert
|
||||
#endif
|
||||
#define assert(EXPR) \
|
||||
if (!(EXPR)) \
|
||||
{ \
|
||||
FAL_PRINTF("(%s) has assert failed at %s.\n", #EXPR, __FUNCTION__); \
|
||||
while (1); \
|
||||
}
|
||||
|
||||
/* debug level log */
|
||||
#ifdef log_d
|
||||
#undef log_d
|
||||
#endif
|
||||
#define log_d(...) FAL_PRINTF(__VA_ARGS__);FAL_PRINTF("\n")
|
||||
|
||||
#else
|
||||
|
||||
#ifdef assert
|
||||
#undef assert
|
||||
#endif
|
||||
#define assert(EXPR) ((void)0);
|
||||
|
||||
/* debug level log */
|
||||
#ifdef log_d
|
||||
#undef log_d
|
||||
#endif
|
||||
#define log_d(...)
|
||||
#endif /* FAL_DEBUG */
|
||||
|
||||
/* error level log */
|
||||
#ifdef log_e
|
||||
#undef log_e
|
||||
#endif
|
||||
#define log_e(...) FAL_PRINTF(__VA_ARGS__);
|
||||
|
||||
/* info level log */
|
||||
#ifdef log_i
|
||||
#undef log_i
|
||||
#endif
|
||||
#define log_i(...) FAL_PRINTF(__VA_ARGS__);
|
||||
|
||||
/* FAL flash and partition device name max length */
|
||||
#ifndef FAL_DEV_NAME_MAX
|
||||
#define FAL_DEV_NAME_MAX 24
|
||||
#endif
|
||||
|
||||
struct fal_flash_dev
|
||||
{
|
||||
char name[FAL_DEV_NAME_MAX];
|
||||
|
||||
/* flash device start address and len */
|
||||
uint32_t addr;
|
||||
size_t len;
|
||||
/* the block size in the flash for erase minimum granularity */
|
||||
size_t blk_size;
|
||||
|
||||
struct
|
||||
{
|
||||
int (*init)(void);
|
||||
int (*read)(long offset, uint8_t *buf, size_t size);
|
||||
int (*write)(long offset, const uint8_t *buf, size_t size);
|
||||
int (*erase)(long offset, size_t size);
|
||||
} ops;
|
||||
|
||||
/* write minimum granularity, unit: bit.
|
||||
1(nor flash)/ 8(stm32f4)/ 32(stm32f1)/ 64(stm32l4)
|
||||
0 will not take effect. */
|
||||
size_t write_gran;
|
||||
};
|
||||
typedef struct fal_flash_dev *fal_flash_dev_t;
|
||||
|
||||
/**
|
||||
* FAL partition
|
||||
*/
|
||||
struct fal_partition
|
||||
{
|
||||
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;
|
||||
size_t len;
|
||||
|
||||
uint32_t reserved;
|
||||
};
|
||||
typedef struct fal_partition *fal_partition_t;
|
||||
|
||||
//#undef LUAT_LOG_TAG
|
||||
|
||||
#endif /* _FAL_DEF_H_ */
|
||||
Reference in New Issue
Block a user