初版
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
/*************************************************************/
|
||||
/** @file: usb_device.h
|
||||
@brief: USB 从机驱动重写,加入iAP协议
|
||||
@details:
|
||||
@author: Bingquan Cai
|
||||
@date: 2013-10-11,09:34
|
||||
@note:
|
||||
*/
|
||||
/*************************************************************/
|
||||
|
||||
#ifndef _IAP_H_
|
||||
#define _IAP_H_
|
||||
|
||||
#include "generic/typedef.h"
|
||||
// #include "string.h"
|
||||
// #include "usb/usb_slave_api.h"
|
||||
|
||||
#define IAP2_LINK_EN 1
|
||||
|
||||
#define IAP_USE_USB_HID_EN 1
|
||||
|
||||
//USB
|
||||
#define MAXP_SIZE_INTERRUPT_IN 0x40
|
||||
//IIC crack
|
||||
#define AUTHENTICATION_CONTROL_STATUS 0x10
|
||||
#define SIGNATURE_DATA_LENGTH 0x11
|
||||
#define SIGNATURE_DATA 0x12
|
||||
#define CHALLENGE_DATA_LENGTH 0x20
|
||||
#define CHALLENGE_DATA 0x21
|
||||
#define ACCESSORY_CERTIFICATE_DATA_LENGTH 0x30
|
||||
#define ACCESSORY_CERTIFICATE_DATA 0x31
|
||||
//iAP1 and iAP2 COMMON
|
||||
#define IAP2_VERSIONS 0x02
|
||||
#define IAP1_VERSIONS 0x01
|
||||
#define DEFAULT_SEQUENCE_NUM 0x0
|
||||
#define EXTRA_SEQUENCE_NUM 0x1
|
||||
//"Dock speaker"
|
||||
#define ACCESSORY_NAME 0x44, 0x6f, 0x63, 0x6b, 0x20, 0x73, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x00
|
||||
//"IPDLI13"
|
||||
#define ACCESSORY_MODEL_IDENTIFIER 0x49, 0x50, 0x44, 0x4c, 0x49, 0x31, 0x33, 0x00
|
||||
//"I want it"
|
||||
#define ACCESSORY_MANUFACTURER 0x49, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, 0x69, 0x74, 0x00
|
||||
//"iAP Interface"
|
||||
#define ACCESSORY_SERIALNUMBER 0x69, 0x41, 0x50, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x00
|
||||
|
||||
//< hid
|
||||
#define HID_PREV_FILE USB_AUDIO_PREFILE
|
||||
#define HID_NEXT_FILE USB_AUDIO_NEXTFILE
|
||||
#define HID_PP USB_AUDIO_PP
|
||||
#define HID_PLAY USB_AUDIO_PLAY
|
||||
#define HID_PAUSE USB_AUDIO_PAUSE
|
||||
#define HID_VOL_DOWN USB_AUDIO_VOLDOWN
|
||||
#define HID_VOL_UP USB_AUDIO_VOLUP
|
||||
|
||||
|
||||
//<iap printf
|
||||
#include "uart.h"
|
||||
#define IAP_CHIP_PRINTF
|
||||
|
||||
#ifdef IAP_CHIP_PRINTF
|
||||
#define iAP_deg_str(x) puts(x)
|
||||
#define iAP_printf printf
|
||||
#define iAP_printf_buf(x, y) put_buf(x, y)
|
||||
#define iAP_put_u8hex(x) put_u8hex(x)
|
||||
#define iAP_put_u16hex(x) put_u16hex(x)
|
||||
#define iAP_put_u32hex(x) put_u32hex(x)
|
||||
#else
|
||||
#define iAP_deg_str(x)
|
||||
#define iAP_printf(...)
|
||||
#define iAP_printf_buf(x, y)
|
||||
#define iAP_put_u8hex(x)
|
||||
#define iAP_put_u16hex(x)
|
||||
#define iAP_put_u32hex(x)
|
||||
#endif
|
||||
|
||||
#define _xdata
|
||||
// #define _data
|
||||
#define _root
|
||||
#define _no_init
|
||||
#define _banked_func
|
||||
|
||||
|
||||
///variable
|
||||
typedef enum {
|
||||
iAP_IDLE = 0,
|
||||
iAP_INTERRUPT,
|
||||
iAP_BULK_IN,
|
||||
iAP_BULE_OUT,
|
||||
} iAP_STATE;
|
||||
|
||||
|
||||
enum {
|
||||
NO_MFI_CHIP = 0,
|
||||
MFI_PROCESS_READY,
|
||||
MFI_PROCESS_STANDBY,
|
||||
MFI_PROCESS_PASS,
|
||||
|
||||
IAP1_LINK_ERR,
|
||||
IAP1_LINK_SUCC,
|
||||
IAP2_LINK_ERR,
|
||||
IAP2_LINK_SUCC,
|
||||
};
|
||||
|
||||
//extern var
|
||||
extern u8 chip_online_status;
|
||||
extern u8 mfi_pass_status;
|
||||
|
||||
#define apple_mfi_chip_online_lib() chip_online_status
|
||||
#define apple_link_disable() mfi_pass_status = MFI_PROCESS_STANDBY
|
||||
#define apple_link_init() mfi_pass_status = MFI_PROCESS_STANDBY
|
||||
#define apple_mfi_pass_ready_set_api() mfi_pass_status = MFI_PROCESS_READY
|
||||
|
||||
#define apple_hid_key_api(key) iap2_hid_key(key)
|
||||
|
||||
///outside call parameter
|
||||
extern u8 *iAP_var_pRxBuf ;
|
||||
extern u8 *iAP_var_pTxBuf ;
|
||||
extern u16 iAP_var_wLength;
|
||||
|
||||
extern u8 iAP_send_pkt_self[0x40] ;
|
||||
extern u8 iAP_receive_pkt_self[0x40] ;
|
||||
|
||||
///inside call
|
||||
// void my_code_memcpy(u8 *s1, const u8 *s2, u16 len);
|
||||
#define my_code_memcpy(x,y,z) memcpy(x,(u8 *)y,z)
|
||||
// u8 my_memcmp(u8 *s1, const u8 *s2, u8 len);
|
||||
#define my_code_memcmp(x,y,z) memcmp(x,(u8 *)y,z)
|
||||
|
||||
u8 iAP_support(void);
|
||||
|
||||
u8 apple_mfi_link(void *hdl);
|
||||
void apple_mfi_unlink(void);
|
||||
|
||||
// #define iAP_host_online() (get_usb_online_status() & BIT(0))
|
||||
// #define iAP_device_online() (get_usb_online_status() & BIT(1))
|
||||
|
||||
#define GET_U16L(x) (u8)(x)
|
||||
#define GET_U16H(x) (u8)((u16)(x)>>8)
|
||||
#define SW16(x) (((u16)(x) & 0x00ffU)<<8 | ((u16)(x) & 0xff00U)>>8)
|
||||
|
||||
#endif /* _IAP_H_ */
|
||||
@@ -0,0 +1,30 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : config_interface.h
|
||||
|
||||
* Description :
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2019-01-10 09:55
|
||||
|
||||
* Copyright:(c)JIELI 2011-2019 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _CONFIG_INTERFACE_H_
|
||||
#define _CONFIG_INTERFACE_H_
|
||||
|
||||
#include "config/config_transport.h"
|
||||
#include "config/config_target.h"
|
||||
|
||||
//配置工具 0:旧工具 1:新工具
|
||||
#define NEW_CONFIG_TOOL 1 //
|
||||
|
||||
void config_layer_init(const ci_transport_t *transport, void *config);
|
||||
|
||||
void *config_load(int id);
|
||||
|
||||
void ci_send_packet(u32 id, u8 *packet, int size);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : config_target.h
|
||||
|
||||
* Description :
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2019-01-09 19:28
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _CONFIG_TARGET_H_
|
||||
#define _CONFIG_TARGET_H_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
#define EQ_CONFIG_ID 0x0005
|
||||
#define EFFECTS_CONFIG_ID 0x0006
|
||||
#define AEC_CONFIG_ID 0x0008
|
||||
|
||||
|
||||
typedef void (*ci_packet_handler_t)(uint8_t *packet, uint16_t size);
|
||||
|
||||
struct config_target {
|
||||
u16 id;
|
||||
ci_packet_handler_t callback;
|
||||
};
|
||||
|
||||
#define REGISTER_CONFIG_TARGET(target) \
|
||||
const struct config_target target sec(.config_target)
|
||||
|
||||
|
||||
extern const struct config_target config_target_begin[];
|
||||
extern const struct config_target config_target_end[];
|
||||
|
||||
#define list_for_each_config_target(p) \
|
||||
for (p = config_target_begin; p < config_target_end; p++)
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : config_transport.h
|
||||
|
||||
* Description : Config Interface
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2019-01-07 14:33
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _CI_TRANSPORT_H
|
||||
#define _CI_TRANSPORT_H
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
/* CI packet types */
|
||||
typedef struct {
|
||||
/**
|
||||
* transport name
|
||||
*/
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* init transport
|
||||
* @param transport_config
|
||||
*/
|
||||
void (*init)(const void *transport_config);
|
||||
|
||||
/**
|
||||
* open transport connection
|
||||
*/
|
||||
int (*open)(void);
|
||||
|
||||
/**
|
||||
* close transport connection
|
||||
*/
|
||||
int (*close)(void);
|
||||
|
||||
/**
|
||||
* register packet handler for CI packets
|
||||
*/
|
||||
void (*register_packet_handler)(void (*handler)(const u8 *packet, int size));
|
||||
|
||||
/**
|
||||
* support async transport layers, e.g. IRQ driven without buffers
|
||||
*/
|
||||
int (*can_send_packet_now)(uint8_t packet_type);
|
||||
|
||||
/**
|
||||
* send packet
|
||||
*/
|
||||
int (*send_packet)(const u8 *packet, int size);
|
||||
|
||||
/**
|
||||
* extension for UART transport implementations
|
||||
*/
|
||||
int (*set_baudrate)(uint32_t baudrate);
|
||||
} ci_transport_t;
|
||||
|
||||
typedef enum {
|
||||
CI_TRANSPORT_CONFIG_UART,
|
||||
CI_TRANSPORT_CONFIG_USB,
|
||||
CI_TRANSPORT_CONFIG_BLE,
|
||||
} ci_transport_config_type_t;
|
||||
|
||||
typedef struct {
|
||||
ci_transport_config_type_t type;
|
||||
} ci_transport_config_t;
|
||||
|
||||
typedef struct {
|
||||
ci_transport_config_type_t type; // == CI_TRANSPORT_CONFIG_UART
|
||||
uint32_t baudrate_init; // initial baud rate
|
||||
uint32_t baudrate_main; // = 0: same as initial baudrate
|
||||
int flowcontrol; //
|
||||
const char *device_name;
|
||||
} ci_transport_config_uart_t;
|
||||
|
||||
typedef struct {
|
||||
//head
|
||||
u16 id;
|
||||
u16 length;
|
||||
|
||||
u8 payload[0];
|
||||
} _GNU_PACKED_ ci_packet_t;
|
||||
|
||||
#define CI_FORMAT_HEAD sizeof(ci_packet_t)
|
||||
|
||||
const ci_transport_t *ci_transport_uart_instance(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,181 @@
|
||||
#ifndef _DEBUG_H_
|
||||
#define _DEBUG_H_
|
||||
|
||||
#include "asm/cpu.h"
|
||||
#include "generic/typedef.h"
|
||||
|
||||
// -- output terminal color
|
||||
#define RedBold "\033[31;1m" // 红色加粗
|
||||
#define RedBoldBlink "\033[31;1;5m" // 红色加粗、闪烁
|
||||
#define GreenBold "\033[32;1m" // 红色加粗
|
||||
#define GreenBoldBlink "\033[32;1;5m" // 红色加粗、闪烁
|
||||
#define YellowBold "\033[33;1m" // 红色加粗
|
||||
#define YellowBoldBlink "\033[33;1;5m" // 红色加粗、闪烁
|
||||
#define BlueBold "\033[34;1m" // 蓝色加粗
|
||||
#define BlueBoldBlink "\033[34;1;5m" // 蓝色加粗、闪烁
|
||||
#define PurpleBold "\033[35;1m" // 紫色加粗
|
||||
#define PurpleBoldBlink "\033[35;1;5m" // 紫色加粗、闪烁
|
||||
#define DGreenBold "\033[36;1m" // 红色加粗
|
||||
#define DGreenBoldBlink "\033[36;1;5m" // 红色加粗、闪烁
|
||||
#define WhiteBold "\033[37;1m" // 红色加粗
|
||||
#define WhiteBoldBlink "\033[37;1;5m" // 红色加粗、闪烁
|
||||
#define Reset "\033[0;25m" // 颜色复位
|
||||
|
||||
#define LOG_ASSERT_ENABLE
|
||||
|
||||
void printf_buf(u8 *buf, u32 len);
|
||||
|
||||
#define PRINTF(format, ...) printf(format, ## __VA_ARGS__)
|
||||
|
||||
#define LOG_VERB v
|
||||
#define LOG_INFO i
|
||||
#define LOG_DEBUG d
|
||||
#define LOG_WARN w
|
||||
#define LOG_ERROR e
|
||||
#define LOG_CHAR c
|
||||
|
||||
#define _STR(x) #x
|
||||
#define STR(x) "["_STR(x)"]"
|
||||
|
||||
|
||||
#define _LOG_TAG_CONST_DECLARE(level, name) extern const char log_tag_const_##level##_##name
|
||||
#define LOG_TAG_CONST_DECLARE(level, name) _LOG_TAG_CONST_DECLARE(level, name)
|
||||
|
||||
#define ___LOG_IS_ENABLE(level, name) (log_tag_const_##level##_##name)
|
||||
#define __LOG_IS_ENABLE(level, name) ___LOG_IS_ENABLE(level, name)
|
||||
#define _LOG_IS_ENABLE(level) __LOG_IS_ENABLE(level, LOG_TAG_CONST)
|
||||
|
||||
#ifdef LOG_TAG_CONST
|
||||
LOG_TAG_CONST_DECLARE(LOG_VERB, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_INFO, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_DEBUG, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_WARN, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_ERROR, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_CHAR, LOG_TAG_CONST);
|
||||
#define _LOG_TAG STR(LOG_TAG_CONST)
|
||||
#define LOG_IS_ENABLE(level) _LOG_IS_ENABLE(level)
|
||||
|
||||
#else
|
||||
#define _LOG_TAG LOG_TAG
|
||||
#define LOG_IS_ENABLE(x) 1
|
||||
#endif
|
||||
|
||||
|
||||
#define LOG_BY_MACRO 1
|
||||
#define LOG_BY_CONST 2
|
||||
|
||||
// #define LOG_MODE LOG_BY_MACRO
|
||||
#define LOG_MODE LOG_BY_CONST
|
||||
|
||||
/*
|
||||
* LOG 通过宏控制
|
||||
*/
|
||||
#if (LOG_MODE == LOG_BY_MACRO)
|
||||
|
||||
#ifdef LOG_VERB_ENABLE
|
||||
#define log_verb(format, ...) PRINTF(_LOG_TAG format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_verb(...)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_INFO_ENABLE
|
||||
#define log_info(format, ...) PRINTF(_LOG_TAG format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_info(...)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_DEBUG_ENABLE
|
||||
#define log_debug(format, ...) PRINTF(_LOG_TAG format, ## __VA_ARGS__)
|
||||
#define log_debug_hexdump(x, y) printf_buf(x, y)
|
||||
#else
|
||||
#define log_debug(...)
|
||||
#define log_debug_hexdump(x, y)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_ERROR_ENABLE
|
||||
#define log_warn(format, ...) PRINTF("<warning>:" _LOG_TAG format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_warn(...)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_ERROR_ENABLE
|
||||
#define log_error(format, ...) PRINTF("<error>:" _LOG_TAG format, ## __VA_ARGS__)
|
||||
#define log_error_hexdump(x, y) printf_buf(x, y)
|
||||
#else
|
||||
#define log_error(...)
|
||||
#define log_error_hexdump(...)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_DUMP_ENABLE
|
||||
#define log_info_hexdump(x,y) printf_buf(x,y)
|
||||
#else
|
||||
#define log_info_hexdump(...)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_CHAR_ENABLE
|
||||
#define log_char(x) putchar(x)
|
||||
#else
|
||||
#define log_char(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* LOG 通过常量控制
|
||||
*/
|
||||
#elif (LOG_MODE == LOG_BY_CONST)
|
||||
|
||||
#define log_verb(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_VERB)) \
|
||||
log_print(__LOG_VERB, NULL, _LOG_TAG format, ## __VA_ARGS__)
|
||||
|
||||
#define log_info(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_INFO)) \
|
||||
log_print(__LOG_INFO, NULL, _LOG_TAG format, ## __VA_ARGS__)
|
||||
|
||||
#define log_info_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_INFO)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_debug(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_DEBUG)) \
|
||||
log_print(__LOG_DEBUG, NULL, _LOG_TAG format, ## __VA_ARGS__)
|
||||
|
||||
#define log_debug_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_DEBUG)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_warn(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_WARN)) \
|
||||
log_print(__LOG_WARN, NULL, "<warning> " _LOG_TAG format, ## __VA_ARGS__)
|
||||
|
||||
#define log_error(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_ERROR)) \
|
||||
log_print(__LOG_ERROR, NULL, "<error> " _LOG_TAG format, ## __VA_ARGS__)
|
||||
|
||||
#define log_error_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_ERROR)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_char(x) \
|
||||
if (LOG_IS_ENABLE(LOG_CHAR)) \
|
||||
putchar(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define traceSUPER_MODE() \
|
||||
|
||||
/*{int icfg, rets, reti; \
|
||||
__asm__ volatile("%0 = icfg" : "=r"(icfg)); \
|
||||
__asm__ volatile("%0 = rets" :"=r"(rets)); \
|
||||
__asm__ volatile("%0 = reti" :"=r"(reti)); \
|
||||
ASSERT(icfg & BIT(10), "icfg 0x%x/ rets 0x%x / reti 0x%x", icfg, rets, reti)}*/
|
||||
|
||||
int printf_cli(const char *format, ...);
|
||||
|
||||
#ifdef LOG_CLI_ENABLE
|
||||
#define log_cli(format, ...) printf_cli(format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_cli(...)
|
||||
#endif
|
||||
|
||||
#endif//__DEBUG_LOG_H_
|
||||
@@ -0,0 +1,79 @@
|
||||
#ifndef CHRDEV_H
|
||||
#define CHRDEV_H
|
||||
|
||||
#include "typedef.h"
|
||||
#include "generic/atomic.h"
|
||||
#include "device/ioctl_cmds.h"
|
||||
|
||||
|
||||
struct dev_node;
|
||||
struct device;
|
||||
|
||||
|
||||
/**@struct device_operations
|
||||
* @brief device_operations结构体 \n
|
||||
* otg设备执行哪种类型的操作
|
||||
*/
|
||||
struct device_operations {
|
||||
bool (*online)(const struct dev_node *node); ///<设备在线状态查询
|
||||
int (*init)(const struct dev_node *node, void *); ///<设备初始化
|
||||
int (*open)(const char *name, struct device **device, void *arg); ///<设备开启
|
||||
int (*read)(struct device *device, void *buf, u32 len, u32); ///<读操作
|
||||
int (*write)(struct device *device, void *buf, u32 len, u32); ///<写操作
|
||||
int (*seek)(struct device *device, u32 offset, int orig); ///<设备搜索
|
||||
int (*ioctl)(struct device *device, u32 cmd, u32 arg); ///<I/O控制
|
||||
int (*close)(struct device *device); ///<设备关闭
|
||||
};
|
||||
|
||||
struct dev_node {
|
||||
const char *name;
|
||||
const struct device_operations *ops;
|
||||
void *priv_data;
|
||||
};
|
||||
|
||||
|
||||
struct device {
|
||||
atomic_t ref;
|
||||
void *private_data;
|
||||
const struct device_operations *ops;
|
||||
void *platform_data;
|
||||
void *driver_data;
|
||||
};
|
||||
|
||||
|
||||
#define REGISTER_DEVICE(node) \
|
||||
const struct dev_node node sec(.device)
|
||||
|
||||
#define REGISTER_DEVICES(node) \
|
||||
const struct dev_node node[] sec(.device)
|
||||
|
||||
|
||||
int devices_init();
|
||||
|
||||
bool dev_online(const char *name);
|
||||
|
||||
void *dev_open(const char *name, void *arg);
|
||||
|
||||
|
||||
int dev_read(void *device, void *buf, u32 len);
|
||||
|
||||
|
||||
int dev_write(void *device, void *buf, u32 len);
|
||||
|
||||
|
||||
int dev_seek(void *device, u32 offset, int orig);
|
||||
|
||||
|
||||
int dev_ioctl(void *device, int cmd, u32 arg);
|
||||
|
||||
|
||||
int dev_close(void *device);
|
||||
|
||||
|
||||
int dev_bulk_read(void *_device, void *buf, u32 offset, u32 len);
|
||||
|
||||
int dev_bulk_write(void *_device, void *buf, u32 offset, u32 len);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
#ifndef __DEVICE_DRIVE_H__
|
||||
#define __DEVICE_DRIVE_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "errno-base.h"
|
||||
#include "ioctl.h"
|
||||
|
||||
#ifndef __UBOOT
|
||||
|
||||
#ifndef _MANGO_OS_
|
||||
#define _MANGO_OS_
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MANGO_OS_
|
||||
#include "os/os_api.h"
|
||||
#else
|
||||
|
||||
|
||||
#ifndef __UBOOT
|
||||
|
||||
#ifndef _WIN_DEBUG_
|
||||
#define _WIN_DEBUG_
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN_DEBUG_
|
||||
#include <pthread.h>
|
||||
typedef pthread_mutex_t OS_MUTEX;
|
||||
typedef u32 OS_ERR;
|
||||
#define OS_ERR_NONE 0
|
||||
|
||||
#else
|
||||
typedef u32 OS_MUTEX, OS_ERR;
|
||||
#define OS_ERR_NONE 0
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dev_mutex {
|
||||
OS_MUTEX *write_mutex;
|
||||
OS_MUTEX *read_mutex;
|
||||
};
|
||||
typedef enum _dev_type {
|
||||
|
||||
DEV_SDCRAD_0 = 0X10,
|
||||
DEV_SDCRAD_1,
|
||||
DEV_SDCRAD_2,
|
||||
|
||||
DEV_UDISK_H0,
|
||||
DEV_UDISK_H1,
|
||||
DEV_UDISK_F0,
|
||||
|
||||
DEV_NOR_FLASH,
|
||||
DEV_NAND_FLASH,
|
||||
|
||||
DEV_STORAGE = 0x100,
|
||||
DEV_LOGIC_DISK = 0x101,
|
||||
DEV_USB_SLAVE,
|
||||
DEV_USB_HOST,
|
||||
DEV_HID = 0x200,
|
||||
DEV_NET,
|
||||
DEV_AUDIO,
|
||||
DEV_ISP,
|
||||
} dev_type;
|
||||
|
||||
// struct partition_table
|
||||
// {
|
||||
// int partition_addr;
|
||||
// int partition_size;
|
||||
// };
|
||||
typedef struct DEV_IO {
|
||||
const char name[8];
|
||||
s32(*mount)(void *volatile parm);
|
||||
s32(*unmount)();
|
||||
s32(*read)(u8 *volatile buf, u32 addr, u32 len);
|
||||
s32(*write)(u8 *volatile buf, u32 addr, u32 len);
|
||||
s32(*ioctrl)(void *volatile parm, u32 cmd);
|
||||
s32(*power)(u32 mod);
|
||||
s32(*detect)(); //设备状态检测
|
||||
|
||||
struct dev_mutex *mutex;
|
||||
dev_type device_type;
|
||||
|
||||
void *private_data;//设备私有属性,用来提供额外接口或者存储一些设备的特性
|
||||
} dev_io_t;
|
||||
|
||||
|
||||
|
||||
//设备状态:
|
||||
typedef enum dev_sta {
|
||||
DEV_OFFLINE = 0, //--0 设备从在线切换到离线。
|
||||
DEV_ONLINE = 1, //---1 设备从离线切换到在线。
|
||||
DEV_HOLD = 2, //---2 其他值表示设备状态未改变。
|
||||
|
||||
DEV_POWER_ON = 0x10, // 0x10 – 开机
|
||||
DEV_POWER_OFF, // 0x11 -关机
|
||||
DEV_POWER_STANDBY, // 0x12 -待机
|
||||
DEV_POWER_WAKEUP, // 0x13- 唤醒
|
||||
} DEV_STA;
|
||||
//设备错误代码:
|
||||
typedef enum dev_err {
|
||||
DEV_ERR_NONE = 0,
|
||||
DEV_ERR_NOT_MOUNT,
|
||||
DEV_ERR_OVER_CAPACITY,
|
||||
|
||||
DEV_ERR_UNKNOW_CLASS,
|
||||
|
||||
DEV_ERR_NOT_READY,//设备已经在线,但是没初始化完成
|
||||
DEV_ERR_LUN,
|
||||
|
||||
DEV_ERR_TIMEOUT,
|
||||
DEV_ERR_CMD_TIMEOUT,
|
||||
DEV_ERR_READ_TIMEOUT,//0x08
|
||||
DEV_ERR_WRITE_TIMEOUT,
|
||||
|
||||
DEV_ERR_OFFLINE,//0x0a
|
||||
|
||||
DEV_ERR_CRC,
|
||||
DEV_ERR_CMD_CRC,
|
||||
DEV_ERR_READ_CRC,
|
||||
DEV_ERR_WRITE_CRC,
|
||||
|
||||
DEV_ERR_CONTROL_STALL,
|
||||
DEV_ERR_RXSTALL,//0x10
|
||||
DEV_ERR_TXSTALL,
|
||||
DEV_ERR_CONTROL,
|
||||
|
||||
DEV_ERR_NOT_STORAGE,
|
||||
DEV_ERR_INVALID_PATH,
|
||||
DEV_ERR_INVALID_DATA,
|
||||
DEV_ERR_OUTOFMEMORY,
|
||||
DEV_ERR_HANDLE_FREE,
|
||||
DEV_ERR_INVALID_HANDLE,//24
|
||||
DEV_ERR_INVALID_BUF,
|
||||
DEV_ERR_INUSE,
|
||||
DEV_ERR_NO_READ,
|
||||
DEV_ERR_NO_WRITE,
|
||||
DEV_ERR_NO_IOCTL,
|
||||
DEV_ERR_NO_POWER,
|
||||
DEV_ERR_NOT_EXIST,
|
||||
DEV_ERR_UNKNOW,
|
||||
} DEV_ERR;
|
||||
|
||||
|
||||
#define DEV_GENERAL_MAGIC 0xe0
|
||||
//每个设备必须支持的命令
|
||||
#define DEV_GET_STATUS _IOR(DEV_GENERAL_MAGIC,0xe0,u32) //获取设备状态,在线、离线、power_on、power_off、standby、……
|
||||
//设备不支持下面命令时返回 -ENOTTY
|
||||
#define DEV_GET_BLOCK_SIZE _IOR(DEV_GENERAL_MAGIC,0xe1,u32) //获取存储设备的块大小
|
||||
#define DEV_GET_BLOCK_NUM _IOR(DEV_GENERAL_MAGIC,0xe2,u32) //获取存储设备的块总数
|
||||
#define DEV_GET_DEV_ID _IOR(DEV_GENERAL_MAGIC,0xe3,u32) //获取设备的ID。SD/TF 卡返回“sdtf”(0x73647466)
|
||||
#define DEV_SECTOR_ERASE _IOW(DEV_GENERAL_MAGIC,0xe4,u32) //设备页擦除
|
||||
#define DEV_BLOCK_ERASE _IOW(DEV_GENERAL_MAGIC,0xe5,u32) //设备块擦除
|
||||
#define DEV_CHIP_ERASE _IOW(DEV_GENERAL_MAGIC,0xe6,u32) //设备擦除
|
||||
#define DEV_GET_TYPE _IOR(DEV_GENERAL_MAGIC,0xe7,u32) //返回设备的dev_type
|
||||
#define DEV_CHECK_WPSTA _IOR(DEV_GENERAL_MAGIC,0xe8,u32) //检测设备写保护状态,当参数为-1的时候返回设备的写包含状态,0的时候解除写保护,1的时候加上写保护
|
||||
|
||||
#define typecheck(type,x) \
|
||||
({ type __dummy; \
|
||||
typeof(x) __dummy2; \
|
||||
(void)(&__dummy == &__dummy2); \
|
||||
1; \
|
||||
})
|
||||
#ifndef time_after
|
||||
#define time_after(a,b) (typecheck(u32, a) && \
|
||||
typecheck(u32, b) && \
|
||||
((s32)(b) - (s32)(a) < 0))
|
||||
#endif
|
||||
|
||||
#ifndef time_before
|
||||
#define time_before(a,b) time_after(b,a)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef DEVICE_INCLUDES_H
|
||||
#define DEVICE_INCLUDES_H
|
||||
|
||||
|
||||
|
||||
|
||||
#include "device.h"
|
||||
#include "ioctl_cmds.h"
|
||||
|
||||
//#include "key_driver.h"
|
||||
//#include "iokey.h"
|
||||
//#include "irkey.h"
|
||||
//#include "adkey.h"
|
||||
//#include "slidekey.h"
|
||||
//#include "touch_key.h"
|
||||
//#include "rdec_key.h"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#ifndef IOCTL_INF_H
|
||||
#define IOCTL_INF_H
|
||||
|
||||
|
||||
|
||||
|
||||
#define IOCTL_SET_IRQ_NUM 1
|
||||
#define IOCTL_SET_PRIORITY 2
|
||||
#define IOCTL_SET_DATA_WIDTH 3
|
||||
#define IOCTL_SET_SPEED 4
|
||||
#define IOCTL_SET_DETECT_MODE 5
|
||||
#define IOCTL_SET_DETECT_FUNC 6
|
||||
#define IOCTL_SET_DETECT_TIME_INTERVAL 7
|
||||
#define IOCTL_SET_PORT 8
|
||||
#define IOCTL_SET_PORT_FUNC 9
|
||||
#define IOCTL_SET_CS_PORT_FUNC 10
|
||||
#define IOCTL_SET_READ_MODE 11
|
||||
#define IOCTL_SET_WRITE_MODE 12
|
||||
#define IOCTL_SET_WRITE_PROTECT 13
|
||||
#define IOCTL_SET_START_BIT 14
|
||||
#define IOCTL_SET_STOP_BIT 15
|
||||
#define IOCTL_FLUSH 16
|
||||
#define IOCTL_REGISTER_IRQ_HANDLER 17
|
||||
#define IOCTL_UNREGISTER_IRQ_HANDLER 18
|
||||
#define IOCTL_GET_SYS_TIME 19
|
||||
#define IOCTL_SET_SYS_TIME 20
|
||||
#define IOCTL_GET_ALARM 21
|
||||
#define IOCTL_SET_ALARM 22
|
||||
#define IOCTL_SET_CAP_LOWSPEED_CARD 23
|
||||
#define IOCTL_SET_VDD50_EN 30
|
||||
#define IOCTL_GET_WEEKDAY 32
|
||||
#define IOCTL_CLR_READ_MODE 33
|
||||
#define IOCTL_SET_READ_CRC 34
|
||||
#define IOCTL_GET_READ_CRC 35
|
||||
#define IOCTL_GET_VOLUME 36
|
||||
#define IOCTL_SET_VOLUME 37
|
||||
#define IOCTL_SET_ALARM_ENABLE 38
|
||||
#define IOCTL_CMD_RESUME 39
|
||||
#define IOCTL_CMD_SUSPEND 40
|
||||
#define IOCTL_SET_BASE_ADDR 41
|
||||
#define IOCTL_SET_ASYNC_MODE 42
|
||||
#define IOCTL_GET_SPEED 43
|
||||
#define IOCTL_SET_ACTIVE_STATUS 44
|
||||
#define IOCTL_POWER_RESUME 45
|
||||
#define IOCTL_POWER_SUSPEND 46
|
||||
#define IOCTL_SET_PROTECT_INFO 47
|
||||
|
||||
#define IOCTL_GET_UUID 99
|
||||
#define IOCTL_GET_ID 100
|
||||
#define IOCTL_GET_SECTOR_SIZE 101
|
||||
#define IOCTL_GET_BLOCK_SIZE 102
|
||||
#define IOCTL_GET_CAPACITY 103
|
||||
#define IOCTL_GET_WIDTH 104
|
||||
#define IOCTL_GET_HEIGHT 105
|
||||
#define IOCTL_GET_BLOCK_NUMBER 106
|
||||
#define IOCTL_CHECK_WRITE_PROTECT 107
|
||||
#define IOCTL_GET_STATUS 108
|
||||
#define IOCTL_GET_TYPE 109
|
||||
#define IOCTL_GET_MAX_LUN 110
|
||||
#define IOCTL_GET_CUR_LUN 111
|
||||
#define IOCTL_SET_CUR_LUN 112
|
||||
#define IOCTL_SET_FORCE_RESET 113
|
||||
#define IOCTL_SET_CAPACITY 114
|
||||
|
||||
#define IOCTL_CMD_WRITE_REG 115
|
||||
#define IOCTL_CMD_READ_REG 116
|
||||
#define IOCTL_CMD_UPDATE_REG 117
|
||||
|
||||
#define IOCTL_ERASE_SECTOR 200
|
||||
#define IOCTL_ERASE_BLOCK 201
|
||||
#define IOCTL_ERASE_CHIP 202
|
||||
#define IOCTL_SET_ENC_END 203
|
||||
#define IOCTL_ERASE_PAGE 204
|
||||
#define IOCTL_SDMMC_ERASE 205
|
||||
|
||||
#define IOCTL_CMD_FLASH_OP 250
|
||||
#define IOCTL_CMD_FLASH_SET_MPM_MODE 251
|
||||
#define IOCTL_CMD_FLASH_SET_OTP_LOCK 252
|
||||
#define IOCTL_CMD_FLASH_CFG_WPS 253
|
||||
#define IOCTL_CMD_FLASH_SET_WPS_LOCK 254
|
||||
#define IOCTL_CMD_FLASH_SET_DC 255
|
||||
#define IOCTL_CMD_FLASH_SET_QPI_MODE 256
|
||||
#define IOCTL_CMD_FLASH_SET_QPI_DUMMY 257
|
||||
|
||||
#define IOCTL_SET_DATA_CALLBACK 301
|
||||
|
||||
#define IOCTL_GET_PART_INFO 320
|
||||
|
||||
struct ioctl_irq_handler {
|
||||
void *priv;
|
||||
void *handler;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
#ifndef _VM_H_
|
||||
#define _VM_H_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#include "ioctl.h"
|
||||
|
||||
#define IOCTL_SET_VM_INFO _IOW('V', 1, u8)
|
||||
#define IOCTL_GET_VM_INFO _IOW('V', 2, u8)
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief VM Struct
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
typedef u16 vm_hdl;
|
||||
|
||||
struct vm_table {
|
||||
u16 index;
|
||||
u16 value_byte;
|
||||
int value; //cache value which value_byte <= 4
|
||||
};
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief VM Error Code
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
typedef enum _vm_err {
|
||||
VM_ERR_NONE = 0,
|
||||
VM_INDEX_ERR = -0x100,
|
||||
VM_INDEX_EXIST, //0xFF
|
||||
VM_DATA_LEN_ERR, //0xFE
|
||||
VM_READ_NO_INDEX, //0xFD
|
||||
VM_READ_DATA_ERR, //0xFC
|
||||
VM_WRITE_OVERFLOW, //0xFB
|
||||
VM_NOT_INIT,
|
||||
VM_INIT_ALREADY,
|
||||
VM_DEFRAG_ERR,
|
||||
VM_ERR_INIT,
|
||||
VM_ERR_PROTECT,
|
||||
VM_RAM_NOT_INIT, //vm_ram_storage_enable宏没有开启,没有初始化成功
|
||||
VM_RAM_MALLOC_ERR, // 申请内存失败
|
||||
VM_RAM2FLASH_WRITE_ERR, //ram的内容写到flash有错误,可能是ram的内容大于flash空间
|
||||
VM_RAM_FLUSH_NONE //没有配置项可以写到flash
|
||||
|
||||
} VM_ERR;
|
||||
|
||||
struct vm_manage_id {
|
||||
vm_hdl id;
|
||||
};
|
||||
|
||||
#define VM_MANAGE_ID_REG(name, hdl) \
|
||||
const struct vm_manage_id vm_##name \
|
||||
SEC_USED(.vm_manage_id_text) = {hdl};
|
||||
|
||||
extern struct vm_manage_id vm_reg_id_begin[];
|
||||
extern struct vm_manage_id vm_reg_id_end[];
|
||||
|
||||
#define list_for_each_vm_id(h) \
|
||||
for (h=vm_reg_id_begin; h<vm_reg_id_end; h++)
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief vm_open
|
||||
*
|
||||
* @param index
|
||||
*
|
||||
* @return handle
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
s32 vm_open(u16 index);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief vm_close
|
||||
*
|
||||
* @param hdl
|
||||
*
|
||||
* @return Error Code
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
VM_ERR vm_close(vm_hdl hdl);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief vm_eraser
|
||||
*
|
||||
* @return Error Code
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
VM_ERR vm_eraser(void);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief vm_check
|
||||
*
|
||||
* @param level
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void vm_check_all(u8 level); //level : default 0
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief vm_read
|
||||
*
|
||||
* @param hdl
|
||||
* @param data_buf
|
||||
* @param len
|
||||
*
|
||||
* @return len
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
s32 vm_read(vm_hdl hdl, void *data_buf, u16 len);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief vm_write
|
||||
*
|
||||
* @param hdl
|
||||
* @param data_buf
|
||||
* @param len
|
||||
*
|
||||
* @return len
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
s32 vm_write(vm_hdl hdl, const void *data_buf, u16 len);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief sfc_erase_zone
|
||||
*
|
||||
* @param addr
|
||||
* @param len
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
bool sfc_erase_zone(u32 addr, u32 len);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取当前vm_ram_storage是否开启
|
||||
*
|
||||
* @return true=开启 or false=关闭
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u8 get_vm_ram_storage_enable(void);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取当前vm_ram_storage_in_irq_enable是否开启
|
||||
*
|
||||
* @return true=开启 or false=关闭
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u8 get_vm_ram_storage_in_irq_enable(void);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取VM配置项暂存RAM的内存使用情况
|
||||
* @return 返回全部数据+管理结构体加起来的字节数总和
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int get_vm_ram_data_total_size(void);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 刷新vm_ram缓存到vm_flash。(该接口不允许在中断内调用)
|
||||
* @param off:是否关闭写vm到ram的功能
|
||||
* @return VM错误码
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
VM_ERR vm_flush2flash(u8 off);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 关闭写vm到ram功能,只有复位/重启才可重新写vm
|
||||
*
|
||||
* @return VM错误码
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
VM_ERR vm_write_ram_off(void);
|
||||
|
||||
void vm_api_write_mult(u16 start_id, u16 end_id, void *buf, u16 len, u32 delay);
|
||||
int vm_api_read_mult(u16 start_id, u16 end_id, void *buf, u16 len);
|
||||
|
||||
|
||||
#endif //_VM_H_
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#ifndef _FTL_API_H
|
||||
#define _FTL_API_H
|
||||
|
||||
#include "generic/typedef.h"
|
||||
|
||||
|
||||
enum ftl_error_t {
|
||||
FTL_ERR_NO = 0x00,
|
||||
FTL_ERR_1BIT_ECC = 0x01,
|
||||
FTL_ERR_READ = 0x02,
|
||||
FTL_ERR_WRITE = 0x04,
|
||||
FTL_ERR_NO_MEM = 0x08,
|
||||
FTL_ERR_NO_BLOCK = 0x10,
|
||||
FTL_ERR_INVALID = 0x20,
|
||||
FTL_ERR_ADDR_OVER = 0x40,
|
||||
};
|
||||
|
||||
struct ftl_nand_flash {
|
||||
u8 block_size_shift;
|
||||
u8 page_size_shift;
|
||||
u8 page_num; //每个block的page数量
|
||||
u16 block_begin; //需要管理的起始block
|
||||
u16 block_end; //需要管理的结束block(不包含)
|
||||
u16 logic_block_num; //虚拟出的逻辑block数量, 需要预留一定比例的坏块,
|
||||
//要比物理block数量少
|
||||
u16 page_size; //page大小(byte)
|
||||
u16 oob_user_offset[2]; //可以使用的oob地址偏移(相对于oob起始地址)
|
||||
u16 oob_user_size[2]; //可使用oob区域大小(byte)
|
||||
u16 oob_size; //oob区域大小(byte)
|
||||
u32 max_erase_cnt; //block的最大擦除次数
|
||||
u8 plane_number; //plane的数量
|
||||
enum ftl_error_t (*page_read)(u16 block, u8 page, u16 offset, u8 *buf, int len);
|
||||
enum ftl_error_t (*page_write)(u16 block, u8 page, u8 *buf, int len);
|
||||
enum ftl_error_t (*erase_block)(u32 addr);
|
||||
};
|
||||
|
||||
struct ftl_config {
|
||||
u8 page_buf_num; //page缓存数量,最少1个,影响读取和写入速度
|
||||
u16 delayed_write_msec; //写入数据没满一个page时,延时写入flash的时间,
|
||||
//0表示每次都直接写入
|
||||
};
|
||||
|
||||
int ftl_init(struct ftl_nand_flash *flash, struct ftl_config *config);
|
||||
|
||||
|
||||
int ftl_read_bytes(u32 addr, u8 *buf, u32 len, enum ftl_error_t *error);
|
||||
|
||||
|
||||
int ftl_write_bytes(u32 addr, u8 *buf, u32 len, enum ftl_error_t *error);
|
||||
|
||||
/*
|
||||
* 返回flash block size, 单位KByte
|
||||
*/
|
||||
int ftl_get_block_size();
|
||||
|
||||
/*
|
||||
* 返回flash容量, 单位KByte
|
||||
*/
|
||||
int ftl_get_capacity();
|
||||
|
||||
/*
|
||||
* 擦除逻辑地址, 地址要按block大小对齐
|
||||
*/
|
||||
int ftl_erase_lgc_addr(u32 addr);
|
||||
|
||||
int ftl_format();
|
||||
|
||||
/*
|
||||
* 释放掉ftl管理申请的memory和任务
|
||||
*/
|
||||
void ftl_uninit();
|
||||
/*
|
||||
* 返回擦除次数大于等于 check_erase_cnt 的block的数量
|
||||
*/
|
||||
int ftl_erase_cnt_check(int check_erase_cnt);
|
||||
/*
|
||||
* 打印block信息*debug使用
|
||||
*/
|
||||
void ftl_dump_block_info();
|
||||
/*
|
||||
低功耗释放缓存
|
||||
*/
|
||||
void ftl_free_page_buf();
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
#ifndef __FS_FILE_NAME_H__
|
||||
#define __FS_FILE_NAME_H__
|
||||
|
||||
#include "generic/typedef.h"
|
||||
|
||||
#define D_LFN_MAX_SIZE 512
|
||||
|
||||
#define LFN_MAX_SIZE D_LFN_MAX_SIZE //不能超过512 //必须4byte对齐
|
||||
|
||||
typedef struct _LONG_FILE_NAME {
|
||||
u16 lfn_cnt;
|
||||
char lfn[LFN_MAX_SIZE]; //长文件名buffer
|
||||
} LONG_FILE_NAME; //整理后的长文件名
|
||||
|
||||
typedef struct _FS_DIR_INFO {
|
||||
u32 sclust; //dir sclust
|
||||
u16 dir_type; // 0-folder,1-file
|
||||
u16 fn_type; // 0-sfn,1-lfn
|
||||
LONG_FILE_NAME lfn_buf; //long file name
|
||||
} FS_DIR_INFO;
|
||||
|
||||
typedef struct _FS_DISP_INFO {
|
||||
char tpath[128];
|
||||
LONG_FILE_NAME file_name;
|
||||
LONG_FILE_NAME dir_name;
|
||||
u8 update_flag;
|
||||
} FS_DISP_INFO;
|
||||
|
||||
typedef struct _FLASH_FAT_ADDRINFO {
|
||||
u32 saddr; //当前连续簇块文件起始实际物理地址
|
||||
u32 end_addr; //当前连续簇块结束位置
|
||||
u32 file_len; //文件长度,如 JL.res文件的
|
||||
} FLASH_FAT_ADDRINFO;
|
||||
#endif /* __FS_FILE_NAME_H__ */
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : resfile.h
|
||||
|
||||
* Description : 本文件存放访问系统资源文件的函数接口和数据结构声明
|
||||
|
||||
* Author : MoZhiYe
|
||||
|
||||
* Email : mozhiye@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2022-04-15 09:30
|
||||
|
||||
* Copyright:(c)JIELI 2022-2030 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef __RESFILE_H__
|
||||
#define __RESFILE_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
#define RESFILE_SEEK_SET 0 /* Seek from beginning of file. */
|
||||
#define RESFILE_SEEK_CUR 1 /* Seek from current position. */
|
||||
#define RESFILE_SEEK_END 2 /* Seek from end of file. */
|
||||
|
||||
//内置flash根路径声明:
|
||||
#define FLASH_ROOT "flash"
|
||||
#define FLASH_APP_PATH FLASH_ROOT"/app/"
|
||||
#define FLASH_RES_PATH FLASH_ROOT"/res/"
|
||||
|
||||
//外置flash根路径声明:
|
||||
//#define EXFLASH_ROOT "exflash"
|
||||
|
||||
typedef struct __resfile {
|
||||
void *ops;
|
||||
void *priv_data;
|
||||
} RESFILE;
|
||||
|
||||
struct resfile_attrs {
|
||||
u8 attr; //文件属性
|
||||
u32 fsize; //文件长度
|
||||
u32 sclust; //文件地址
|
||||
};
|
||||
|
||||
|
||||
enum resfile_err_code {
|
||||
RESFILE_ERR_NONE = 0,
|
||||
RESFILE_ERR_PATH = -1,
|
||||
RESFILE_ERR_NO_MEM = -2,
|
||||
RESFILE_ERR_OPS_NO_SUPPORT = -3,
|
||||
RESFILE_ERR_HANDLE = -4,
|
||||
};
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 资源文件打开接口
|
||||
*
|
||||
* @param path: 文件路径名, 如内置flash路径, FLASH_RES_PATH"file.txt"
|
||||
*
|
||||
* @return: 1) 非NULL, 文件打开成功, 返回文件句柄;
|
||||
2) NULL, 文件打开失败
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
RESFILE *resfile_open(const char *path);
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 资源文件读接口
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
* @param buf: 用于读取数据的buf
|
||||
* @param len: 读取数据长度
|
||||
*
|
||||
* @return: 1) >= 0: 实际成功读取的长度
|
||||
2) < 0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_read(RESFILE *fp, void *buf, u32 len);
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 特殊资源文件写接口, 该接口一般只用来写由用户分配的自定义
|
||||
预留区域的文件, 请误用来写只读的资源文件.
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
* @param buf: 用于写入数据的buf
|
||||
* @param len: 写入数据长度
|
||||
*
|
||||
* @return: 1) >= 0: 实际成功写入的长度
|
||||
2) < 0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_write(RESFILE *fp, void *buf, u32 len);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 设置资源文件读写指针偏移
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
* @param offset: 偏移量
|
||||
* @param fromwhere: 偏移方式:
|
||||
1)RESFILE_SEEK_SET: 从文件开头偏移;
|
||||
2)RESFILE_SEEK_CUR: 从文件当前读写指针偏移;
|
||||
3)RESFILE_SEEK_END: 从文件结束偏移;
|
||||
*
|
||||
* @return: 1) >=0: 当前文件读写指针位置
|
||||
2) < 0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_seek(RESFILE *fp, u32 offset, u32 fromwhere);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 获取资源文件名称
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
* @param name: 获取获取文件名的buf
|
||||
* @param len: buf长度
|
||||
*
|
||||
* @return: 1) >=0: 获取成功
|
||||
2) < 0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_get_name(RESFILE *fp, void *name, u32 len);
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 获取资源文件长度
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
*
|
||||
* @return: 1) >=0: 当前文件实际长度
|
||||
2)返回<0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_get_len(RESFILE *fp);
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 获取当前资源文件读写指针位置
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
*
|
||||
* @return: 1) >=0: 当前文件读写指针位置
|
||||
2) < 0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_get_pos(RESFILE *fp);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 获取当前资源文件的属性信息
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
* @param attrs: 用于获取属性信息的buf
|
||||
*
|
||||
* @return : 1)返回0: 获取成功
|
||||
2)返回<0: 错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_get_attrs(RESFILE *fp, struct resfile_attrs *attrs);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 关闭当前资源文件
|
||||
*
|
||||
* @param fp: 文件句柄
|
||||
*
|
||||
* @return : 1)返回0: 成功关闭
|
||||
2)返回<0: 关闭错误, 请查看本文件enum resfile_err_code
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int resfile_close(RESFILE *fp);
|
||||
|
||||
#endif /* #ifndef __RESFILE_H__ */
|
||||
@@ -0,0 +1,174 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : sdfile.h
|
||||
|
||||
* Description : 本文件存放内置flash文件系统(sdfile)的数据结构声明和接口声明
|
||||
|
||||
* Author : MoZhiYe
|
||||
|
||||
* Email : mozhiye@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2022-03-25 13:50
|
||||
|
||||
* Copyright:(c)JIELI 2022-2030 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef __SDFILE_H__
|
||||
#define __SDFILE_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "fs/fs.h"
|
||||
//*********************************************************************************//
|
||||
// SDFILE数据结构 //
|
||||
//*********************************************************************************//
|
||||
|
||||
#define SDFILE_NAME_LEN 16
|
||||
//================= 文件头:
|
||||
typedef struct sdfile_file_head {
|
||||
u16 head_crc;
|
||||
u16 data_crc;
|
||||
u32 addr;
|
||||
u32 len;
|
||||
u8 attr;
|
||||
u8 res;
|
||||
u16 index;
|
||||
char name[SDFILE_NAME_LEN];
|
||||
} SDFILE_FILE_HEAD;
|
||||
|
||||
|
||||
//================= 目录头:
|
||||
struct sdfile_dir {
|
||||
u16 file_num;
|
||||
struct sdfile_file_head head;
|
||||
};
|
||||
|
||||
//================= 错误表:
|
||||
enum SDFILE_ERR_TABLE {
|
||||
SDFILE_DIR_NOT_EXIST = -0xFF,
|
||||
SDFILE_FILE_NOT_EXIST,
|
||||
SDFILE_MALLOC_ERR,
|
||||
SDFILE_VM_NOT_FIND,
|
||||
SDFILE_DATA_CRC_ERR,
|
||||
SDFILE_WRITE_AREA_NEED_ERASE_ERR,
|
||||
SDFILE_SUSS = 0,
|
||||
SDFILE_END,
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define SDFILE_PART_APP 0x55
|
||||
#define SDFILE_PART_RES 0xAA
|
||||
|
||||
#define SDFILE_FILE_ATTR_UBOOT 0x00 //uboot代码文件
|
||||
#define SDFILE_FILE_ATTR_APP 0x01 //app代码文件
|
||||
#define SDFILE_FILE_ATTR_REG 0x02 //普通文件
|
||||
#define SDFILE_FILE_ATTR_DIR 0x03 //目录文件
|
||||
#define SDFILE_FILE_ATTR_RESERVED 0x10 //预留文件
|
||||
#define SDFILE_FILE_ATTR_CPMPRESS 0x40 //压缩文件
|
||||
#define SDFILE_FILE_ATTR_ENC 0x80 //加密文件
|
||||
|
||||
#define SDFILE_FILE_ATTR_TYPE_MASK 0x0F
|
||||
|
||||
#if (VFS_ENABLE == 1)
|
||||
|
||||
//*********************************************************************************//
|
||||
// Have VFS In System //
|
||||
//*********************************************************************************//
|
||||
|
||||
extern const int SDFILE_STORAGE_ENABLE; //sdfile做设备接入VFS,扫描功能使能
|
||||
#define SDFILE_MAX_DEEPTH 2
|
||||
|
||||
|
||||
struct sdfile_folder {
|
||||
u32 saddr;
|
||||
u32 addr;
|
||||
u32 len;
|
||||
};
|
||||
|
||||
struct sdfile_scn {
|
||||
u8 subpath;
|
||||
u8 cycle_mode;
|
||||
u8 attr;
|
||||
u8 deepth;
|
||||
u16 dirCounter;
|
||||
u16 fileCounter;
|
||||
u16 fileNumber; // 当前文件序号
|
||||
u16 totalFileNumber;
|
||||
u16 last_file_number;
|
||||
u16 fileTotalInDir; // 当前目录的根下有效文件的个数
|
||||
u16 fileTotalOutDir; // 当前目录前的文件总数,目录循环模式下,需要用它来计算文件序号
|
||||
u32 sclust_id;
|
||||
const char *ftypes;
|
||||
struct sdfile_file_head head;
|
||||
struct sdfile_folder folder[SDFILE_MAX_DEEPTH];
|
||||
};
|
||||
|
||||
typedef struct _SDFILE_FATFS {
|
||||
void *sdfile_fd;
|
||||
int(*read)(void *sdfile_fd, u8 *buf, u32 addr, u32 len);
|
||||
int(*write)(void *sdfile_fd, u8 *buf, u32 addr, u32 len);
|
||||
} SDFILE_FATFS;
|
||||
|
||||
//================= 文件指针:
|
||||
typedef struct sdfile_file_t {
|
||||
u32 fptr;
|
||||
struct sdfile_file_head head;
|
||||
struct sdfile_scn *pscn;
|
||||
SDFILE_FATFS *sdfs;
|
||||
} SDFILE;
|
||||
|
||||
#else /* #if (VFS_ENABLE == 1) */
|
||||
|
||||
//*********************************************************************************//
|
||||
// None VFS In System //
|
||||
//================= 文件指针:
|
||||
typedef struct sdfile_file_t {
|
||||
u32 fptr;
|
||||
struct sdfile_file_head head;
|
||||
} SDFILE;
|
||||
//*********************************************************************************//
|
||||
|
||||
#endif /* #if (VFS_ENABLE == 1) */
|
||||
|
||||
// int sdfile_delete_data(SDFILE *fp);
|
||||
// #define fdel_data sdfile_delete_data
|
||||
|
||||
//*********************************************************************************//
|
||||
// SDFILE路径声明 //
|
||||
//*********************************************************************************//
|
||||
#ifndef SDFILE_MOUNT_PATH
|
||||
#define SDFILE_MOUNT_PATH "flash"
|
||||
#endif /* #ifndef SDFILE_MOUNT_PATH */
|
||||
|
||||
#ifndef SDFILE_APP_ROOT_PATH
|
||||
#define SDFILE_APP_ROOT_PATH SDFILE_MOUNT_PATH"/app/" //app分区
|
||||
#endif /* #ifndef SDFILE_APP_ROOT_PATH */
|
||||
|
||||
#ifndef SDFILE_RES_ROOT_PATH
|
||||
#define SDFILE_RES_ROOT_PATH SDFILE_MOUNT_PATH"/res/" //资源文件分区
|
||||
#endif /* #ifndef SDFILE_RES_ROOT_PATH */
|
||||
|
||||
//*********************************************************************************//
|
||||
// SDFILE接口声明 //
|
||||
//*********************************************************************************//
|
||||
|
||||
//获取flash物理大小, 单位: Byte
|
||||
u32 sdfile_get_disk_capacity(void);
|
||||
//flash addr -> cpu addr
|
||||
u32 sdfile_flash_addr2cpu_addr(u32 offset);
|
||||
//cpu addr -> flash addr
|
||||
u32 sdfile_cpu_addr2flash_addr(u32 offset);
|
||||
|
||||
void sdfile_head_addr_get(char *name, u32 *addr, u32 *len);
|
||||
|
||||
int sdfile_init(void);
|
||||
int sdfile_early_init(void);
|
||||
void sdfile_get_ini_cfg_info(u32 *ini_cfg_addr, u32 *ini_cfg_len);
|
||||
|
||||
u8 *sdfile_get_burn_code(u8 *len);
|
||||
|
||||
SDFILE *sdfile_open(const char *path, const char *mode);
|
||||
int sdfile_read(SDFILE *fp, void *buf, u32 len);
|
||||
int sdfile_get_attrs(SDFILE *fp, struct vfs_attr *attr);
|
||||
int sdfile_close(SDFILE *fp);
|
||||
|
||||
#endif /* #ifndef __SDFILE_H__ */
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
#ifndef VIRTUAL_DISK_H
|
||||
#define VIRTUAL_DISK_H
|
||||
|
||||
#include "system/includes.h"
|
||||
|
||||
|
||||
#define VIR_FILE_TYPE_MP3 1
|
||||
#define VIR_FILE_TYPE_WAV 2
|
||||
|
||||
extern const struct device_operations virfat_flash_dev_ops;
|
||||
extern const struct device_operations private_sfc_dev_ops;
|
||||
|
||||
typedef enum {
|
||||
FS_FAT12 = 0x01,
|
||||
FS_FAT16 = 0x02,
|
||||
FS_FAT32 = 0x04,
|
||||
FS_EXFAT = 0x14,
|
||||
} FS_TYPE;
|
||||
|
||||
#define JLFAT_DIRINFO_ENABLE 0
|
||||
#if JLFAT_DIRINFO_ENABLE
|
||||
typedef struct jlfat_dirinfo {
|
||||
u8 name[12]; //文件名字
|
||||
int fsize; // 文件大小
|
||||
u16 fix_date; //修改日期
|
||||
u16 fix_time; //修改时间
|
||||
u8 attr; //文件属性
|
||||
int sclust; //文件起始簇
|
||||
} JLFAT_DIRINFO;
|
||||
#endif
|
||||
|
||||
typedef struct _virfat_flash_t {
|
||||
u32 fatbase;
|
||||
// u32 fatbase2;
|
||||
u16 fatsize;
|
||||
u32 dirbase;
|
||||
u32 database;
|
||||
u32 clustSize;
|
||||
u32 max_clust;
|
||||
u32 capacity;
|
||||
u8 csize;
|
||||
FS_TYPE fs_type;
|
||||
char re_devname[24];
|
||||
u32 flash_fatfs_addr;
|
||||
u32 fatfs_len;
|
||||
} virfat_flash_t;
|
||||
|
||||
typedef struct _dir_entry {
|
||||
u8 name[12];
|
||||
u32 fileSize;
|
||||
} dir_entry_t;
|
||||
|
||||
|
||||
#if 0
|
||||
extern void virfat_flash_rand_file_size();
|
||||
extern void virtual_disk_reduce_file_size(tu8 file_num);
|
||||
extern void virtual_disk_remove_files(tu8 file_type);
|
||||
extern void virtual_disk_reduce_file_size(tu8 file_num);
|
||||
extern u8 virfat_flash_init(void *buf_512, void (*fun_read_file)(u32, u32, u8 *, u32));
|
||||
#endif
|
||||
|
||||
#define MIN_FAT16 4086 /* Minimum number of clusters for FAT16 */
|
||||
#define MIN_FAT32 65526 /* Minimum number of clusters for FAT32 */
|
||||
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume label */
|
||||
#define AM_LFN 0x0F /* LFN entry */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_FCH 0x80 /* exFAT下,文件簇连续标志 */
|
||||
#define AM_FRG 0x40 /* exFAT下,文件簇BITMAP 有碎片 */
|
||||
#define AM_LFN0_START 0x1
|
||||
#define AM_LFN0_LEN 10
|
||||
#define AM_LFN1_START 0xE
|
||||
#define AM_LFN1_LEN 12
|
||||
#define AM_LFN2_START 0x1C
|
||||
#define AM_LFN2_LEN 4
|
||||
#define AM_LFN_LEN 26
|
||||
|
||||
#define AM_EX_DIR_STRETCHED 0x08
|
||||
|
||||
#define BS_jmpBoot 0
|
||||
#define BS_OEMName 3
|
||||
#define BPB_BytsPerSec_l 11
|
||||
#define BPB_BytsPerSec_h 12
|
||||
#define BPB_SecPerClus 13
|
||||
#define BPB_RsvdSecCnt 14
|
||||
#define BPB_NumFATs 16
|
||||
#define BPB_RootEntCnt 17
|
||||
#define BPB_TotSec16 19
|
||||
#define BPB_Media 21
|
||||
#define BPB_FATSz16 22
|
||||
#define BPB_SecPerTrk 24
|
||||
#define BPB_NumHeads 26
|
||||
#define BPB_HiddSec 28
|
||||
#define BPB_TotSec32 32
|
||||
#define BS_55AA 510
|
||||
|
||||
#define BS_DrvNum 36
|
||||
#define BS_BootSig 38
|
||||
#define BS_VolID 39
|
||||
#define BS_VolLab 43
|
||||
#define BS_FilSysType 54
|
||||
|
||||
#define BPB_FATSz32 36
|
||||
#define BPB_ExtFlags 40
|
||||
#define BPB_FSVer 42
|
||||
#define BPB_RootClus 44
|
||||
#define BPB_FSInfo 48
|
||||
#define BPB_BkBootSec 50
|
||||
#define BS_DrvNum32 64
|
||||
#define BS_BootSig32 66
|
||||
#define BS_VolID32 67
|
||||
#define BS_VolLab32 71
|
||||
#define BS_FilSysType32 82
|
||||
#define BS_FileSysTypeexFAT 5
|
||||
#define BPB_FatOffset 80
|
||||
#define BPB_FatLength 84
|
||||
#define BPB_ClusterHeapOffset 88
|
||||
#define BPB_ClusterCount 92
|
||||
#define BPB_FirstClusterOfRootDirectory 96
|
||||
#define BPB_VolumeFlags 106
|
||||
#define BPB_BytesPerSectorShift 108
|
||||
#define BPB_SectorsPerClusterShift 109
|
||||
#define BPB_NumberOfFats 110
|
||||
#define MBR_Table 446
|
||||
#define FSI_LeadSig 0 /* FSI: Leading signature (4) */
|
||||
#define FSI_StrucSig 484 /* FSI: Structure signature (4) */
|
||||
#define FSI_Free_Count 488 /* FSI: Number of free clusters (4) */
|
||||
#define FSI_Nxt_Free 492 /* FSI: Last allocated cluster (4) */
|
||||
|
||||
///for FAT12/FAT16/FAT32
|
||||
#define DIR_Name 0 /* Short file name (11) */
|
||||
#define DIR_Attr 11 /* Attribute (1) */
|
||||
#define DIR_NTres 12 /* NT flag (1) */
|
||||
#define DIR_CrtTimeTenth 13 /* Created time sub-second (1) */
|
||||
#define DIR_CrtTime 14 /* Created time (2) */
|
||||
#define DIR_CrtDate 16 /* Created date (2) */
|
||||
#define DIR_LstAccDate 18 /* Last accessed date (2) */
|
||||
#define DIR_FstClusHI 20 /* Higher 16-bit of first cluster (2) */
|
||||
#define DIR_WrtTime 22 /* Modified time (2) */
|
||||
#define DIR_WrtDate 24 /* Modified date (2) */
|
||||
#define DIR_FstClusLO 26
|
||||
#define DIR_FileSize 28
|
||||
#define LDIR_Attr 11 /* LFN attribute (1) */
|
||||
#define LDIR_Type 12 /* LFN type (1) */
|
||||
#define LDIR_Chksum 13 /* Sum of corresponding SFN entry */
|
||||
////for exFAT
|
||||
#define DIR_FileChainFlags 1
|
||||
#define DIR_NameLen 3
|
||||
#define DIR_AttrexFAT 4
|
||||
#define DIR_FileSizeexFAT 8
|
||||
#define DIR_FstClustexFAT 20
|
||||
#define DIR_FileSize2exFAT 24
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#ifndef ASCII_LIB_H
|
||||
#define ASCII_LIB_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 字母a-z转换为A-Z
|
||||
*
|
||||
* @param buf
|
||||
* @param len
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void ASCII_ToLower(void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 字母A-Z转换为a-z
|
||||
*
|
||||
* @param buf
|
||||
* @param len
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void ASCII_ToUpper(void *buf, u32 len);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 字符串匹配,文件名可以使用?来匹配
|
||||
*
|
||||
* @param src
|
||||
* @param dst
|
||||
* @param len
|
||||
*
|
||||
* @return 不匹配长度,0表示全匹配
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 ASCII_StrCmp(const char *src, const char *dst, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 字符串匹配,不区分大小写(不能使用?来匹配)
|
||||
*
|
||||
* @param src
|
||||
* @param dst
|
||||
* @param len
|
||||
*
|
||||
* @return 长度(单位:byte)
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
int ASCII_StrCmpNoCase(const char *src, const char *dst, int len);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief int转string
|
||||
*
|
||||
* @param pStr
|
||||
* @param intNum
|
||||
* @param strLen
|
||||
* @param bufLen
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void ASCII_IntToStr(void *pStr, u32 intNum, u32 strLen, u32 bufLen);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief string转int
|
||||
*
|
||||
* @param pStr
|
||||
* @param pRint
|
||||
* @param strLen
|
||||
*
|
||||
* @return 长度(单位:byte)
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 ASCII_StrToInt(const void *pStr, u32 *pRint, u32 strLen);
|
||||
|
||||
|
||||
u32 ASCII_StrToHex(const char *pStr);
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 字符串长度 (0表示结束符)
|
||||
*
|
||||
* @param str
|
||||
* @param len
|
||||
*
|
||||
* @return 长度(单位:byte)
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 ASCII_StrLen(void *str, u32 len);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 双字符串长度 (00表示结束符)
|
||||
*
|
||||
* @param str
|
||||
* @param len
|
||||
*
|
||||
* @return 长度(单位:byte)
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 ASCII_WStrLen(void *str, u32 len);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef ATOMIC_H
|
||||
#define ATOMIC_H
|
||||
|
||||
#include "cpu.h"
|
||||
#include "irq.h"
|
||||
|
||||
typedef struct {
|
||||
int counter;
|
||||
} atomic_t;
|
||||
|
||||
static inline int atomic_add_return(int i, atomic_t *v)
|
||||
{
|
||||
int val;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
|
||||
val = v->counter;
|
||||
v->counter = val += i;
|
||||
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
static inline int atomic_sub_return(int i, atomic_t *v)
|
||||
{
|
||||
int val;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
|
||||
val = v->counter;
|
||||
v->counter = val -= i;
|
||||
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline int atomic_set(atomic_t *v, int i)
|
||||
{
|
||||
int val = 0;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
|
||||
v->counter = i;
|
||||
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
#define DEFINE_ATOMIC(x) \
|
||||
atomic_t x = {.counter = 0}
|
||||
|
||||
#define atomic_add(i, v) atomic_add_return(i, v)
|
||||
#define atomic_sub(i, v) atomic_sub_return(i, v)
|
||||
|
||||
#define atomic_read(v) arch_atomic_read(v)
|
||||
/*#define atomic_set(v,i) (((v)->counter) = (i))*/
|
||||
|
||||
#define atomic_inc(v) atomic_add(1, v)
|
||||
#define atomic_dec(v) atomic_sub(1, v)
|
||||
|
||||
#define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
|
||||
#define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
|
||||
#define atomic_inc_return(v) (atomic_add_return(1, v))
|
||||
#define atomic_dec_return(v) (atomic_sub_return(1, v))
|
||||
#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
|
||||
|
||||
#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
#ifndef CIRCULAR_BUF_INTERFACE_H
|
||||
#define CIRCULAR_BUF_INTERFACE_H
|
||||
|
||||
#include "typedef.h"
|
||||
#include "system/spinlock.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef CONFIG_CBUF_IN_MASKROM
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief cbuffer结构体
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
typedef struct _cbuffer {
|
||||
u8 *begin;
|
||||
u8 *end;
|
||||
u8 *read_ptr;
|
||||
u8 *write_ptr;
|
||||
u8 *tmp_ptr ;
|
||||
u32 tmp_len;
|
||||
u32 data_len;
|
||||
u32 total_len;
|
||||
spinlock_t lock;
|
||||
} cbuffer_t;
|
||||
|
||||
#else /* #ifndef CONFIG_CBUF_IN_MASKROM */
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief cbuffer结构体
|
||||
* @note: 以下结构体成员不可修改
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
typedef struct _cbuffer {
|
||||
u8 *begin;
|
||||
u8 *end;
|
||||
u8 *read_ptr;
|
||||
u8 *write_ptr;
|
||||
u8 *tmp_ptr ;
|
||||
u32 tmp_len;
|
||||
u32 data_len;
|
||||
u32 total_len;
|
||||
// spinlock_t lock;
|
||||
u32 lock;
|
||||
} cbuffer_t;
|
||||
|
||||
#endif /* #ifndef CONFIG_CBUF_IN_MASKROM */
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief cbuffer初始化
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] buf 缓存空间
|
||||
* @param [in] size 缓存总大小
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:cb_memcpy管理
|
||||
* @brief 把cbuffer_t结构体管理的内存空间的数据拷贝到buf数组
|
||||
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [out] buf 指向用于存储读取内容的目标数组
|
||||
* @param [in] len 要读取的字节长度
|
||||
*
|
||||
* @return 成功读取的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:cb_memcpy管理
|
||||
* @brief 把buf数组数据拷贝cbuffer_t结构体管理的内存空间
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] buf 指向用于存储写入内容的目标数组
|
||||
* @param [in] len 要写入的字节长度
|
||||
*
|
||||
* @return 成功写入的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief 判断是否可写入len字节长度的数据
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] len len字节长度的数据
|
||||
*
|
||||
* @return 返回可以写入的len字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:外部内存管理
|
||||
* @brief 预分配待写入数据的空间,要和cbuf_write_updata()配套使用,更新cbuf管理handle数据。
|
||||
*
|
||||
* @param [in] cbuffer cbuffer句柄
|
||||
* @param [in] len 回传可以最多写入len字节长度的数据
|
||||
*
|
||||
* @return 当前写指针的地址
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void *cbuf_write_alloc(cbuffer_t *cbuffer, u32 *len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:外部内存管理
|
||||
* @brief 更新cbuf管理handle的写指针位置和数据长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer句柄
|
||||
* @param [in] len 在非cbuffer_t结构体包含的内存空间中写入的数据的实际字节长度
|
||||
*
|
||||
* @return 当前写指针的地址
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_write_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:外部内存管理
|
||||
* @brief 预分配待读取数据的空间,需要和cbuf_read_updata()配套使用,更新cbuf管理handle数据
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] len 回传可以最多读取len字节长度的数据
|
||||
*
|
||||
* @return 当前读指针的地址
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void *cbuf_read_alloc(cbuffer_t *cbuffer, u32 *len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:外部内存管理
|
||||
* @brief 更新cbuf管理handle的读指针位置和数据长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] len 在非cbuffer_t结构体包含的内存空间中读取的数据的实际字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_read_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:外部内存管理
|
||||
* @brief 清空cbuffer空间
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_clear(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:cb_memcpy管理。
|
||||
* @brief 指定位置进行数据重写
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] begin 指向需要重写内容的开始地址
|
||||
* @param [out] buf 指向用于存储重写内容的目标数组
|
||||
* @param [in] len 待重写内容的长度
|
||||
*
|
||||
* @return 成功重写的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_rewrite(cbuffer_t *cbuffer, void *begin, void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:cb_memcpy管理
|
||||
* @brief 更新指向上一次操作的指针为当前指针,并刷新数据长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_discard_prewrite(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:cb_memcpy管理
|
||||
* @brief 操作指针回退到上一次的操作位置,并刷新数据长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_updata_prewrite(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:cb_memcpy管理
|
||||
* @brief 回退写入内容,从上一次的操作的指针处进行覆盖填充
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [out] buf 指向用于覆盖写入内容的目标数组
|
||||
* @param [in] len 填充数据的字节长度
|
||||
*
|
||||
* @return 成功填充数据的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_prewrite(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief 获取指向写指针的地址
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
*
|
||||
* @return 写指针的地址
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void *cbuf_get_writeptr(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief 获取cbuffer存储的数据的字节长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer句柄
|
||||
*
|
||||
* @return 获取cbuffer存储的数据的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_get_data_size(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief 获取指向读指针的地址
|
||||
*
|
||||
* @param [in] cbuffer cbuffer句柄
|
||||
*
|
||||
* @return 读指针的地址
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void *cbuf_get_readptr(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief 读指针向后回退
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] len 要回退的字节长度
|
||||
*
|
||||
* @return 成功回退的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_read_goback(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:全局
|
||||
* @brief 获取存储数据的字节长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
*
|
||||
* @return 存储数据的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_get_data_len(cbuffer_t *cbuffer);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:memcpy管理+cbuf_read_alloc系列管理函数
|
||||
* @brief 预分配待读取数据的空间,并把读取到的数据存入buf数组
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [out] buf 存储读取的数据的目标buf数组
|
||||
* @param [in] len 要读取的数据的字节长度
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 适用范围:memcpy管理+cbuf_read_alloc系列管理函数
|
||||
* @brief 更新cbuf管理handle的读指针位置和数据长度
|
||||
*
|
||||
* @param [in] cbuffer cbuffer 句柄
|
||||
* @param [in] len 要更新的数据的字节长度
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
#ifndef LBUF_H
|
||||
#define LBUF_H
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
#include "list.h"
|
||||
#include "system/spinlock.h"
|
||||
|
||||
#ifndef CONFIG_LBUF_IN_MASKROM
|
||||
|
||||
#define LBUF_DEBUG 0
|
||||
|
||||
struct lbuff_head {
|
||||
#if LBUF_DEBUG
|
||||
int magic_a; /*!< 测试验证变量*/
|
||||
#endif
|
||||
struct list_head head; /*!< 指向hentry链表*/
|
||||
struct list_head free; /*!< 指向hfree链表*/
|
||||
spinlock_t lock; /*!< 混合自旋锁,单核是为开关临界区,多核是自旋锁.*/
|
||||
u8 align; /*!< 数据包字节对齐*/
|
||||
u16 priv_len; /*!< 数据包结构体的最小长度*/
|
||||
u32 total_size; /*!< 总大小*/
|
||||
u32 last_addr; /*!< 指向free链表中找到的足够长度的hfree结构体地址*/
|
||||
void *priv;
|
||||
|
||||
#if LBUF_DEBUG
|
||||
int magic_b; /*!< 测试验证变量*/
|
||||
#endif
|
||||
};
|
||||
|
||||
struct lbuff_state {
|
||||
u32 avaliable; /*!< 剩余空间的字节长度*/
|
||||
u32 fragment; /*!< lbuf内存碎片块数量*/
|
||||
u32 max_continue_len; /*!< 最大的剩余内存块的字节长度*/
|
||||
int num; /*!< 剩余内存块数量*/
|
||||
};
|
||||
|
||||
#else /* #ifndef CONFIG_LBUF_IN_MASKROM */
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief:
|
||||
* @note: 以下结构体成员不可修改
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
struct lbuff_head {
|
||||
#if 0 //LBUF_DEBUG
|
||||
int magic_a; /*!< 测试验证变量*/
|
||||
#endif
|
||||
struct list_head head; /*!< 指向hentry链表*/
|
||||
struct list_head free; /*!< 指向hfree链表*/
|
||||
//spinlock_t lock; /*!< 混合自旋锁,单核是为开关临界区,多核是自旋锁.*/
|
||||
u32 lock; /*!< 混合自旋锁,单核是为开关临界区,多核是自旋锁.*/
|
||||
u8 align; /*!< 数据包字节对齐*/
|
||||
u16 priv_len; /*!< 数据包结构体的最小长度*/
|
||||
u32 total_size; /*!< 总大小*/
|
||||
u32 last_addr; /*!< 指向free链表中找到的足够长度的hfree结构体地址*/
|
||||
void *priv;
|
||||
|
||||
#if 0 //LBUF_DEBUG
|
||||
int magic_b; /*!< 测试验证变量*/
|
||||
#endif
|
||||
};
|
||||
|
||||
struct lbuff_state {
|
||||
u32 avaliable; /*!< 剩余空间的字节长度*/
|
||||
u32 fragment; /*!< lbuf内存碎片块数量*/
|
||||
u32 max_continue_len; /*!< 最大的剩余内存块的字节长度*/
|
||||
int num; /*!< 剩余内存块数量*/
|
||||
};
|
||||
|
||||
#endif /* #ifndef CONFIG_LBUF_IN_MASKROM */
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 链表buf初始化
|
||||
*
|
||||
* @param [in] buf 需要lbuf进行管理的内存
|
||||
* @param [in] len 内存长度
|
||||
* @param [in] align 输入对管理的内存进行对齐的参数,避免后续使用因地址不对齐产生碎片
|
||||
* @param [in] priv_head_len 要管理的一个数据包结构体的最小的长度
|
||||
*
|
||||
* @return lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
struct lbuff_head *lbuf_init(void *buf, u32 len, int align, int priv_head_len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 分配内存空间进行存储数据包
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] len 需要存入的数据包的长度
|
||||
*
|
||||
* @return 成功则返回进行存储数据包的地址,调用时候需要用户把该块内存的类型初始化为数据包结构体的类型。失败则返回NULL。
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_alloc(struct lbuff_head *head, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 重新分配lbuf_alloc()返回用于存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] size 需重新分配的空间的字节长度.注:size的大小只能比lbuf_alloc()中的len小,即只能重新分配更小的lbuf空间,不能扩大空间.
|
||||
*
|
||||
* @return 重新分配后用于存储数据包的地址。失败则返回空指针。注:重新分配最好使用lbuf_real_size()获取lbuf空间的长度确认是否分配成功
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_realloc(void *lbuf, int size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 判断lbuf空间内的内容是否为空
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 返回1则为空,0则不为空
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_empty(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 清空lbuf空间内进行已经分配给数据包的空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_clear(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 把数据包写入分配好的lbuf区域
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] channel_map 选择映射到哪个通道,最多8个通道,使用位映射的方式进行通道对应.
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_push(void *lbuf, u8 channel_map);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 读取对应的通道映射的lbuf区域存储的内容
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] channel 需要读取的通道值,一般使用BIT(n),n为需要读取的通道
|
||||
*
|
||||
* @return 成功则返回存储对应的通道映射的数据包的地址
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_pop(struct lbuff_head *head, u8 channel);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 释放存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*
|
||||
* @return 0则释放失败,存在地址越界操作或者通道还没有被读完,ref-1,读完后才能完全释放。1则释放成功。
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_free(void *lbuf);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 用于调试,检查是否可以释放存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] rets 调用lbuf_free_check()函数的返回地址rets,取值可参考lbuf_free()
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_free_check(void *lbuf, u32 rets);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回可分配的用来存储数据包的最大lbuf内存空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 可分配的最大lbuf内存空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u32 lbuf_free_space(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取lbuf空间的状态
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [out] state lbuff_state结构体
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_state(struct lbuff_head *head, struct lbuff_state *state);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief lbuf信息打印
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_dump(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取已经存入lbuf空间的数据包的数量
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return lbuf存储的数据包的数量
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_traversal(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回lbuf空间还可以被写入size大小数据包的数量
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] size 欲检测写入数据包的大小
|
||||
*
|
||||
* @return 可以写入的数量
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_avaliable(struct lbuff_head *head, int size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回给数据包分配的内存空间的大小
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*
|
||||
* @return 实际占用空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_real_size(void *lbuf);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 计算lbuf空间剩下多少剩余空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 剩余空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_remain_space(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 需要被重复释放的次数+1
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_inc_ref(void *lbuf);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
#ifndef __LOG_H
|
||||
#define __LOG_H
|
||||
|
||||
|
||||
#include "generic/printf.h"
|
||||
|
||||
#define __LOG_VERB 0
|
||||
#define __LOG_DEBUG 1
|
||||
#define __LOG_INFO 2
|
||||
#define __LOG_WARN 3
|
||||
#define __LOG_ERROR 4
|
||||
#define __LOG_CHAR 5
|
||||
|
||||
struct logbuf {
|
||||
u16 len;
|
||||
u16 buf_len;
|
||||
char buf[0];
|
||||
};
|
||||
|
||||
#define __LOG_ENABLE
|
||||
|
||||
#ifndef __LOG_LEVEL
|
||||
#define __LOG_LEVEL 0
|
||||
#endif
|
||||
|
||||
/*#ifdef CONFIG_RELEASE_ENABLE
|
||||
#undef __LOG_LEVEL
|
||||
#define __LOG_LEVEL 0xff
|
||||
#endif*/
|
||||
|
||||
#if __LOG_LEVEL > __LOG_VERB
|
||||
#define log_v(...) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_v(...) log_print(__LOG_VERB, NULL, __VA_ARGS__)
|
||||
#else
|
||||
#define log_v(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if __LOG_LEVEL > __LOG_DEBUG
|
||||
#define log_d(...) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_d(...) log_print(__LOG_DEBUG, NULL, __VA_ARGS__);
|
||||
#else
|
||||
#define log_d(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_INFO
|
||||
#define log_i(...) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_i(...) log_print(__LOG_INFO, NULL, __VA_ARGS__);
|
||||
#else
|
||||
#define log_i(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_WARN
|
||||
#define log_w(...) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_w(...) log_print(__LOG_WARN, NULL, __VA_ARGS__);
|
||||
#else
|
||||
#define log_w(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_ERROR
|
||||
#define log_e(...) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_e(...) log_print(__LOG_ERROR, NULL, __VA_ARGS__);
|
||||
#else
|
||||
#define log_e(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_CHAR
|
||||
#define log_c(x) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_c(x) putchar(x)
|
||||
#else
|
||||
#define log_c(x)
|
||||
#endif
|
||||
|
||||
#define r_printf(x, ...) log_i("\e[31m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define g_printf(x, ...) log_i("\e[32m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define y_printf(x, ...) log_i("\e[33m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define b_printf(x, ...) log_i("\e[34m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define r_f_printf(x, ...) log_i("\e[31m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define g_f_printf(x, ...) log_i("\e[32m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define y_f_printf(x, ...) log_i("\e[33m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
|
||||
#ifndef __LOG_ENABLE
|
||||
#define log_dump(a, b) do {} while(0)
|
||||
#define log_putchar() do {} while(0)
|
||||
#define log_early_init(a) do {} while(0)
|
||||
#define log_level(a) do {} while(0)
|
||||
#else
|
||||
|
||||
int log_output_lock();
|
||||
|
||||
void log_output_unlock();
|
||||
|
||||
void log_print_time();
|
||||
|
||||
void log_early_init(int buf_size);
|
||||
|
||||
void log_level(int level);
|
||||
|
||||
void log_print(int level, const char *tag, const char *format, ...);
|
||||
|
||||
void log_dump(const u8 *buf, int len);
|
||||
|
||||
struct logbuf *log_output_start(int len);
|
||||
|
||||
void log_output_end(struct logbuf *);
|
||||
|
||||
void log_putchar(struct logbuf *lb, char c);
|
||||
|
||||
void log_put_u8hex(struct logbuf *lb, unsigned char dat);
|
||||
|
||||
void log_putbyte(char);
|
||||
|
||||
void log_set_time_offset(int offset);
|
||||
|
||||
int log_get_time_offset();
|
||||
|
||||
#endif
|
||||
|
||||
void log_flush();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef _PRINTF_H_
|
||||
#define _PRINTF_H_
|
||||
#define line_inf printf("%s %s %d \r\n" ,__FILE__, __func__ , __LINE__) ;
|
||||
#include <stdarg.h>
|
||||
#include "typedef.h"
|
||||
//#define NOFLOAT
|
||||
|
||||
extern int putchar(int a);
|
||||
extern int puts(const char *out);
|
||||
extern void put_float(double fv);
|
||||
void put_u4hex(unsigned char dat);
|
||||
void put_u8hex(unsigned char dat);
|
||||
void put_u16hex(unsigned short dat);
|
||||
void put_u32hex(unsigned int dat);
|
||||
void put_buf(const u8 *buf, int len);
|
||||
int printf(const char *format, ...);
|
||||
int assert_printf(const char *format, ...);
|
||||
int sprintf(char *out, const char *format, ...);
|
||||
int vprintf(const char *fmt, __builtin_va_list va);
|
||||
int vsnprintf(char *, unsigned long, const char *, __builtin_va_list);
|
||||
int snprintf(char *buf, unsigned long size, const char *fmt, ...);
|
||||
int print(char **out, char *end, const char *format, va_list args);
|
||||
//int snprintf(char *, unsigned long, const char *, ...);
|
||||
|
||||
int sscanf(const char *buf, const char *fmt, ...); //BUG: 多个参数? 最后又空格?
|
||||
|
||||
//int perror(const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef MATH_FAST_FUNCTION
|
||||
#define MATH_FAST_FUNCTION
|
||||
|
||||
struct data_q_struct {
|
||||
long data;
|
||||
char q;
|
||||
};
|
||||
|
||||
float add_float(float x, float y);
|
||||
float sub_float(float x, float y);
|
||||
long float_to_int(float x);
|
||||
float int_to_float(long x);
|
||||
long cos_fix(long x);
|
||||
float cos_float(float x);
|
||||
long sin_fix(long x);
|
||||
float sin_float(float x);
|
||||
struct data_q_struct complex_abs_fix(long x, long y);
|
||||
struct data_q_struct complex_dqdt_fix(long x, long y);
|
||||
float complex_abs_float(float x, float y);
|
||||
float complex_dqdt_float(float x, float y);
|
||||
struct data_q_struct root_fix(struct data_q_struct x);
|
||||
float root_float(float x);
|
||||
struct data_q_struct mul_fix(long x, long y);
|
||||
float mul_float(float x, float y);
|
||||
struct data_q_struct div_fix(long x, long y);
|
||||
float div_float(float x, float y);
|
||||
struct data_q_struct exp_fix(long x);
|
||||
float exp_float(float x);
|
||||
struct data_q_struct ln_fix(struct data_q_struct x);
|
||||
float ln_float(float x);
|
||||
struct data_q_struct angle_fix(long x, long y);
|
||||
float angle_float(float x, float y);
|
||||
struct data_q_struct atanh_fix(long x, long y);
|
||||
float atanh_float(float x, float y);
|
||||
long cosh_fix(long x);
|
||||
float cosh_float(float x);
|
||||
long sinh_fix(long x);
|
||||
float sinh_float(float x);
|
||||
struct data_q_struct log10_fix(struct data_q_struct x);
|
||||
float log10_float(float x);
|
||||
struct data_q_struct sigmoid_fix(float x);
|
||||
float sigmoid_float(float x);
|
||||
struct data_q_struct tanh_fix(float x);
|
||||
float tanh_float(float x);
|
||||
float dB_Convert_Mag(float x);
|
||||
|
||||
struct data_q_struct complex_dqdt_fix_limit(long x, long y);
|
||||
struct data_q_struct atanh_fix_limit(long x, long y);
|
||||
float complex_dqdt_float_limit(float x, float y);
|
||||
float atanh_float_limit(float x, float y);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef SYS_TIME_H
|
||||
#define SYS_TIME_H
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
struct sys_time {
|
||||
u16 year;
|
||||
u8 month;
|
||||
u8 day;
|
||||
u8 hour;
|
||||
u8 min;
|
||||
u8 sec;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
|
||||
#ifndef __JL_CFG_DEC_H__
|
||||
#define __JL_CFG_DEC_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "device/vm.h"
|
||||
#include "syscfg_votp_id.h"
|
||||
|
||||
struct btif_item {
|
||||
u16 id;
|
||||
u16 data_len;
|
||||
};
|
||||
|
||||
|
||||
struct syscfg_operataions {
|
||||
int (*init)(void);
|
||||
int (*early_init)(void);
|
||||
int (*check_id)(u16 item_id);
|
||||
int (*read)(u16 item_id, void *buf, u16 len);
|
||||
int (*early_read)(u16 item_id, void *buf, u16 len);
|
||||
int (*write)(u16 item_id, const void *buf, u16 len);
|
||||
int (*dma_write)(u16 item_id, const void *buf, u16 len);
|
||||
int (*read_string)(u16 item_id, u8 *buf, u16 len, u8 ver);
|
||||
u8 *(*ptr_read)(u16 item_id, u16 *len);
|
||||
};
|
||||
|
||||
#define REGISTER_SYSCFG_OPS(cfg, pri) \
|
||||
const struct syscfg_operataions cfg SEC_USED(.syscfg.pri.ops)
|
||||
|
||||
//=================================================================================//
|
||||
// 系统配置项(VM, BTIF, cfg_bin)读写接口 //
|
||||
//接口说明: //
|
||||
// 1.输入参数 //
|
||||
// 1)item_id: 配置项ID号, 由本文件统一分配; //
|
||||
// 2)buf: 用于存储read/write数据内容; //
|
||||
// 3)len: buf的长度(byte), buf长度必须大于等于read/write数据长度; //
|
||||
// 2.返回参数: //
|
||||
// 1)执行正确: 返回值等于实际上所读到的数据长度(大于0); //
|
||||
// 2)执行错误: 返回值小于等于0, 小于0表示相关错误码; //
|
||||
// 3.读写接口使用注意事项: //
|
||||
// 1)不能在中断里调用写(write)接口; //
|
||||
// 2)调用本读写接口时应该习惯性判断返回值来检查read/write动作是否执行正确; //
|
||||
//=================================================================================//
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 读取对应配置项的内容
|
||||
*
|
||||
* @param [in] item_id 配置项ID号
|
||||
* @param [out] buf 用于存储read数据内容
|
||||
* @param [in] len buf的长度(byte), buf长度必须大于等于read数据长度
|
||||
*
|
||||
* @return 1)执行正确: 返回值等于实际上所读到的数据长度(大于0);
|
||||
* 2)执行错误: 返回值小于等于0, 小于0表示相关错误码;
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int syscfg_read(u16 item_id, void *buf, u16 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 写入对应配置项的内容
|
||||
*
|
||||
* @param [in] item_id 配置项ID号
|
||||
* @param [in] buf 用于存储write数据内容
|
||||
* @param [in] len buf的长度(byte), buf长度必须大于等于write数据长度
|
||||
*
|
||||
* @return 1)执行正确: 返回值等于实际上所读到的数据长度(大于0);
|
||||
* 2)执行错误: 返回值小于等于0, 小于0表示相关错误码;
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int syscfg_write(u16 item_id, const void *buf, u16 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 以dma的方式写入对应配置项的内容, 请注意buf地址需要按照4byte对齐
|
||||
*
|
||||
* @param [in] item_id 配置项ID号
|
||||
* @param [in] buf 用于存储write数据内容
|
||||
* @param [in] len buf的长度(byte), buf长度必须大于等于write数据长度
|
||||
*
|
||||
* @return 1)执行正确: 返回值等于实际上所读到的数据长度(大于0);
|
||||
* 2)执行错误: 返回值小于等于0, 小于0表示相关错误码;
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int syscfg_dma_write(u16 item_id, const void *buf, u16 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 读取同一个配置项存在多份数据中的某一份数据, ver读取表示第几份数据, ver从 0 开始;
|
||||
* @brief 典型应用: 读取配置项CFG_BT_NAME中多个蓝牙名中的某一个蓝牙名;
|
||||
*
|
||||
* @param [in] item_id 配置项ID号
|
||||
* @param [in] buf 用于存储read数据内容
|
||||
* @param [in] len buf的长度(byte), buf长度必须大于等于read数据长度
|
||||
* @param [in] ver 读取表示第几份数据
|
||||
*
|
||||
* @return 1)执行正确: 返回值等于实际上所读到的数据长度(大于0);
|
||||
* 2)执行错误: 返回值小于等于0, 小于0表示相关错误码;
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int syscfg_read_string(u16 item_id, void *buf, u16 len, u8 ver);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取配置项的地址
|
||||
* @brief 注: 只支持cfg_tools.bin文件中的配置项读取
|
||||
* @param [in] item_id 配置项ID号
|
||||
* @param [out] len 配置项长度
|
||||
*
|
||||
* @return 配置项地址指针(可以用cpu直接访问);
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u8 *syscfg_ptr_read(u16 item_id, u16 *len);
|
||||
|
||||
|
||||
int syscfg_read_item(u16 cfg_id, u8 item, void *buf, u16 len);
|
||||
|
||||
int syscfg_tools_init(void);
|
||||
|
||||
int syscfg_tools_early_init(void);
|
||||
|
||||
int syscfg_early_read(u16 item_id, void *buf, u16 len);
|
||||
|
||||
//==================================================================================================//
|
||||
// 配置项ID分配说明 //
|
||||
// 1.配置项ID号根据存储区域进行分配; //
|
||||
// 2.存储区域有3个: 1)VM区域; 2)sys_cfg.bin; 3)BTIF区域 //
|
||||
// 3.配置项ID号分配如下: //
|
||||
// 0)[0]: 配置项ID号0为配置项工具保留ID号; //
|
||||
// 1)[ 1 ~ 49]: 共49项, 预留给用户自定义, 只存于VM区域; //
|
||||
// 2)[ 50 ~ 99]: 共50项, sdk相关配置项, 只存于VM区域; //
|
||||
// 3)[100 ~ 127]: 共28项, sdk相关配置项, 可以存于VM区域, sys_cfg.bin(作为默认值) 和 BTIF区域; //
|
||||
// 4)[512 ~ 700]: 共188项, sdk相关配置项, 只存于sys_cfg.bin; //
|
||||
//==================================================================================================//
|
||||
|
||||
//=================================================================================//
|
||||
// 用户自定义配置项[1 ~ 49] //
|
||||
//=================================================================================//
|
||||
#define CFG_USER_DEFINE_BEGIN 1
|
||||
/*用户请在 user_cfg_id.h 定义*/
|
||||
#define CFG_USER_DEFINE_END 49
|
||||
|
||||
//=================================================================================//
|
||||
// 只存VM配置项[50 ~ 99] //
|
||||
//=================================================================================//
|
||||
#define CFG_STORE_VM_ONLY_BEGIN 50
|
||||
#define AT_CHAR_DEV_NAME 51
|
||||
#define CFG_STORE_VM_ONLY_END 99
|
||||
|
||||
//=================================================================================//
|
||||
// 可以存于VM, sys_cfg.bin(默认值)和BTIF区域的配置项[100 ~ 127] //
|
||||
// (VM支持扩展到511) //
|
||||
//=================================================================================//
|
||||
#define CFG_STORE_VM_BIN_BTIF_BEGIN 100
|
||||
#define CFG_STORE_VM_BIN_BTIF_END (VM_ITEM_MAX_NUM - 1) //在app_cfg文件中配置128/256
|
||||
|
||||
//==================================================================================================//
|
||||
//ID号分配方案:
|
||||
// 1) 与APP CASE 相关的ID (0 ~ 50);
|
||||
// 3) lib库保留ID(蓝牙, trim 值) (范围: 61 ~ 127); //67项
|
||||
// 4) 与app_case 扩展ID号,需要更大的ram资源(128 ~ 511);
|
||||
//==================================================================================================//
|
||||
|
||||
//=================================================================================//
|
||||
// SDK库保留配置项[61 ~ 127] //
|
||||
//=================================================================================//
|
||||
#define CFG_REMOTE_DB_INFO 61
|
||||
#define CFG_REMOTE_DB_00 62
|
||||
#define CFG_REMOTE_DB_01 63
|
||||
#define CFG_REMOTE_DB_02 64
|
||||
#define CFG_REMOTE_DB_03 65
|
||||
#define CFG_REMOTE_DB_04 66
|
||||
#define CFG_REMOTE_DB_05 67
|
||||
#define CFG_REMOTE_DB_06 68
|
||||
#define CFG_REMOTE_DB_07 69
|
||||
#define CFG_REMOTE_DB_08 70
|
||||
#define CFG_REMOTE_DB_09 71
|
||||
#define CFG_REMOTE_DB_10 72
|
||||
#define CFG_REMOTE_DB_11 73
|
||||
#define CFG_REMOTE_DB_12 74
|
||||
#define CFG_REMOTE_DB_13 75
|
||||
#define CFG_REMOTE_DB_14 76
|
||||
#define CFG_REMOTE_DB_15 77
|
||||
#define CFG_REMOTE_DB_16 78
|
||||
#define CFG_REMOTE_DB_17 79
|
||||
#define CFG_REMOTE_DB_18 80
|
||||
#define CFG_REMOTE_DB_19 81
|
||||
#define CFG_DAC_TEST_VOLT 82
|
||||
#define CFG_BLE_MODE_INFO 83
|
||||
#define CFG_TWS_DUAL_CONFIG 84
|
||||
#define CFG_TWS_CONNECT_AA 85
|
||||
#define CFG_MUSIC_VOL 86
|
||||
#define CFG_CHARGESTORE_TWS_CHANNEL 87
|
||||
#define CFG_DAC_DTB 88
|
||||
#define CFG_MC_BIAS 89
|
||||
#define CFG_POR_FLAG 90
|
||||
#define CFG_MIC_LDO_VSEL 91
|
||||
#define CFG_DAC_TRIM_INFO 92
|
||||
#define CFG_BT_TRIM_INFO 93
|
||||
#define CFG_ANC_INFO 94
|
||||
#define CFG_TWS_LOCAL_ADDR 95
|
||||
#define CFG_TWS_REMOTE_ADDR 96
|
||||
#define CFG_TWS_COMMON_ADDR 97
|
||||
#define CFG_TWS_CHANNEL 98
|
||||
#define VM_PMU_VOLTAGE 99
|
||||
#define CFG_SYS_VOL 100
|
||||
|
||||
//=========== btif & cfg_tool.bin & vm ============//
|
||||
#define CFG_BT_NAME 101
|
||||
#define CFG_BT_MAC_ADDR 102
|
||||
#define VM_OLD_RTC_TIME 105
|
||||
#define VM_OLD_REAL_TIME 106
|
||||
#define VM_BLE_LOCAL_INFO 109
|
||||
#define CFG_BT_FRE_OFFSET 110
|
||||
#define VM_GMA_ALI_PARA 111
|
||||
#define VM_DMA_RAND 112
|
||||
#define VM_GMA_MAC 113
|
||||
#define VM_TME_AUTH_COOKIE 114
|
||||
#define VM_UPDATE_FLAG 115
|
||||
|
||||
#define VM_RTC_TRIM 116
|
||||
|
||||
#define VM_BLE_REMOTE_DB_INFO 117
|
||||
#define VM_BLE_REMOTE_DB_00 118
|
||||
#define VM_BLE_REMOTE_DB_01 119
|
||||
#define VM_BLE_REMOTE_DB_02 120
|
||||
#define VM_BLE_REMOTE_DB_03 121
|
||||
#define VM_BLE_REMOTE_DB_04 122
|
||||
#define VM_BLE_REMOTE_DB_05 123
|
||||
#define VM_BLE_REMOTE_DB_06 124
|
||||
#define VM_BLE_REMOTE_DB_07 125
|
||||
#define VM_BLE_REMOTE_DB_08 126
|
||||
#define VM_BLE_REMOTE_DB_09 127
|
||||
|
||||
|
||||
#define VM_CHARGE_CALIBRATION 128//用于存储充电校准值
|
||||
#define VM_ARCH_TRIM 129
|
||||
|
||||
#define VM_FM_BG_TRIM 130
|
||||
#define VM_FM_CBPF_TRIM 131
|
||||
|
||||
#define CFG_USB_BREAKPOINT0 132
|
||||
#define CFG_SD0_BREAKPOINT0 133
|
||||
#define CFG_SD1_BREAKPOINT0 134
|
||||
|
||||
#define VM_TWS_ROLE 135
|
||||
|
||||
|
||||
#define CFG_ONLINE_EQ_DRC_DATA_ID 136//在线调试保存参数的id
|
||||
#define CFG_ONLINE_SAVE_ID 137//在线保存文件大小的id
|
||||
|
||||
#define VM_VIR_RTC_TIME 138
|
||||
#define VM_VIR_RTC_ALM 139
|
||||
#define VM_VIR_RTC_CNT 140
|
||||
|
||||
#define VM_ID_XOSC_TRIM 141
|
||||
#define VM_ID_LRC24M_TRIM 142
|
||||
#define VM_ID_LRC200K_TRIM 143
|
||||
|
||||
//=================================================================================//
|
||||
// 只存于sys_cfg.bin的配置项[512 ~ 700] //
|
||||
//=================================================================================//
|
||||
#define CFG_STORE_BIN_ONLY_BEGIN 512
|
||||
//硬件类配置项[513 ~ 600]
|
||||
#define CFG_UART_ID 513
|
||||
#define CFG_HWI2C_ID 514
|
||||
#define CFG_SWI2C_ID 515
|
||||
#define CFG_HWSPI_ID 516
|
||||
#define CFG_SWSPI_ID 517
|
||||
#define CFG_SD_ID 518
|
||||
#define CFG_USB_ID 519
|
||||
#define CFG_LCD_ID 520
|
||||
#define CFG_TOUCH_ID 521
|
||||
#define CFG_IOKEY_ID 522
|
||||
#define CFG_ADKEY_ID 523
|
||||
#define CFG_AUDIO_ID 524
|
||||
#define CFG_VIDEO_ID 525
|
||||
#define CFG_WIFI_ID 526
|
||||
#define CFG_NIC_ID 527
|
||||
#define CFG_LED_ID 528
|
||||
#define CFG_BATTERY_CURVE_ID 529
|
||||
#define CFG_IRFLT_ID 530
|
||||
#define CFG_PLCNT_ID 531
|
||||
#define CFG_ID_LED_CTRL 532
|
||||
#define CFG_RDEC_ID 533
|
||||
#define CFG_CHARGE_STORE_ID 534
|
||||
#define CFG_CHARGE_ID 535
|
||||
#define CFG_LOWPOWER_V_ID 536
|
||||
#define CFG_MIC_TYPE_ID 537
|
||||
#define CFG_COMBINE_SYS_VOL_ID 538
|
||||
#define CFG_COMBINE_CALL_VOL_ID 539
|
||||
|
||||
|
||||
#define CFG_ID_IO_CFG_AT_POWERON 541
|
||||
#define CFG_ID_IO_CFG_AT_POWEROFF 542
|
||||
#define CFG_ID_IO_CTRL 543
|
||||
#define CFG_LP_TOUCH_KEY_ID 544
|
||||
#define CFG_LP_TOUCH_KEY_EARTCH_ID 545
|
||||
#define CFG_LP_TOUCH_KEY_DEBUG_ID 546
|
||||
|
||||
#define CFG_SPDIF_CFG_ID 547
|
||||
#define CFG_OPT_CFG_ID 548
|
||||
#define CFG_COAL_CFG_ID 549
|
||||
|
||||
#define CFG_AUDIO_DAC_ID 550
|
||||
|
||||
#define CFG_LINEIN_CFG_ID 551
|
||||
#define CFG_FM_INSIDE_CFG_ID 552
|
||||
#define CFG_FM_OUTSIDE_CFG_ID 553
|
||||
|
||||
//蓝牙类配置项[601 ~ 650]
|
||||
#define CFG_BT_RF_POWER_ID 601
|
||||
#define CFG_TWS_PAIR_CODE_ID 602
|
||||
#define CFG_AUTO_OFF_TIME_ID 603
|
||||
#define CFG_AEC_ID 604
|
||||
#define CFG_UI_TONE_STATUS_ID 605
|
||||
#define CFG_KEY_MSG_ID 606
|
||||
#define CFG_LRC_ID 607
|
||||
#define CFG_DMS_ID 609
|
||||
#define CFG_ANC_ID 610
|
||||
#define CFG_SMS_DNS_ID 612 //单mic神经网络降噪
|
||||
#define CFG_DMS_DNS_ID 613 //双mic神经网络降噪
|
||||
#define CFG_DMS_FLEXIBLE_ID 614 //灵活可变双mic降噪
|
||||
|
||||
#define CFG_ID_BT_NAME_SELECT 620
|
||||
|
||||
#define CFG_ID_ALINK0_ID 621
|
||||
#define CFG_ID_ALINK1_ID 622
|
||||
|
||||
//其它类配置项[651 ~ 700]
|
||||
#define CFG_STORE_BIN_ONLY_END 700
|
||||
|
||||
|
||||
// votp区域
|
||||
#define CFG_VOTP_CFG_GROUP_START (0xD00)
|
||||
#define CFG_VOTP_CFG_GROUP_END (0xE00 - 1)
|
||||
#define CFG_VOTP_GROUP_START (0xE00)
|
||||
#define CFG_VOTP_GROUP_END (0xF00 - 1)
|
||||
#define CFG_VOTP_EFUSE_GROUP_START (0xF00)
|
||||
#define CFG_VOTP_EFUSE_GROUP_END (0x1000 - 1)
|
||||
|
||||
#define VOTP_CFG_ITEM_ID(USER_ID) ((USER_ID & 0xFF) | CFG_VOTP_CFG_GROUP_START)
|
||||
#define VOTP_ITEM_ID(USER_ID) ((USER_ID & 0xFF) | CFG_VOTP_GROUP_START)
|
||||
#define VOTP_EFUSE_ITEM_ID(USER_ID) ((USER_ID & 0xFF) | CFG_VOTP_EFUSE_GROUP_START)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef __SYSCFG_VOTP_ID_H__
|
||||
#define __SYSCFG_VOTP_ID_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "device/vm.h"
|
||||
|
||||
|
||||
//==========================================//
|
||||
// votp 配置项ID分配说明 //
|
||||
//==========================================//
|
||||
//存储在虚拟VOTP区域
|
||||
enum votp_id {
|
||||
CFG_ID_VOTP_FLASH_INFO_V1 = 0,
|
||||
CFG_ID_VOTP_FLASH_INFO_V2 = 1,
|
||||
// CFG_ID_VOTP_CALIBRATION, //校准信息
|
||||
};
|
||||
#define CFG_ID_VOTP_LRC_TRIM_VALUE 0x3fe
|
||||
|
||||
|
||||
|
||||
|
||||
//==========================================//
|
||||
// OTP 配置项ID分配说明 //
|
||||
//==========================================//
|
||||
|
||||
#define CFG_ID_OTP_LRC_TRIM_VALUE 0x3fe
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
SECTIONS
|
||||
{
|
||||
.data : ALIGN(4)
|
||||
{
|
||||
utils_data_start = .;
|
||||
*(.utils_data)
|
||||
utils_data_end = .;
|
||||
. = ALIGN(4);
|
||||
|
||||
} > ram0
|
||||
|
||||
.bss (NOLOAD) :ALIGN(4)
|
||||
{
|
||||
utils_bss_start = .;
|
||||
*(.utils_bss)
|
||||
utils_bss_end = .;
|
||||
. = ALIGN(4);
|
||||
|
||||
} > ram0
|
||||
|
||||
.text : ALIGN(4)
|
||||
{
|
||||
utils_text_start = .;
|
||||
*(.utils_text)
|
||||
|
||||
. = ALIGN(4);
|
||||
vfs_ops_begin = .;
|
||||
KEEP(*(.vfs_operations))
|
||||
vfs_ops_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
_resfile_ops_begin = .;
|
||||
PROVIDE(resfile_ops_begin = .);
|
||||
KEEP(*(.resfile_ops))
|
||||
_resfile_ops_end = .;
|
||||
PROVIDE(resfile_ops_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
*(.utils_data_code)
|
||||
|
||||
utils_text_end = .;
|
||||
. = ALIGN(4);
|
||||
} > code0
|
||||
|
||||
.data_code ALIGN(4):
|
||||
{
|
||||
} > ram0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user