初版
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".app_config.data.bss")
|
||||
#pragma data_seg(".app_config.data")
|
||||
#pragma const_seg(".app_config.text.const")
|
||||
#pragma code_seg(".app_config.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "config/config_interface.h"
|
||||
#include "fs/resfile.h"
|
||||
|
||||
#define LOG_TAG "[APP-CONFIG]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
extern void dec_eq_test();
|
||||
static int sdfile_test(const char *name);
|
||||
int jl_cfg_dec_test(void);
|
||||
|
||||
ci_transport_config_uart_t config = {
|
||||
CI_TRANSPORT_CONFIG_UART,
|
||||
#if (defined(TCFG_CFG_TOOL_ENABLE)&&TCFG_CFG_TOOL_ENABLE)
|
||||
1000000,
|
||||
#else
|
||||
115200,
|
||||
#endif
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
};
|
||||
|
||||
#if (TCFG_ONLINE_ENABLE || TCFG_CFG_TOOL_ENABLE)
|
||||
#if (TCFG_COMM_TYPE == TCFG_UART_COMM)
|
||||
int config_online_init()
|
||||
{
|
||||
log_info("-------online Config Start-------");
|
||||
config_layer_init(ci_transport_uart_instance(), &config);
|
||||
return 0;
|
||||
}
|
||||
__initcall(config_online_init);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void config_test(void)
|
||||
{
|
||||
|
||||
#if 1
|
||||
log_info("-------EQ online Config Start-------");
|
||||
|
||||
/* sys_clk_set(SYS_48M); */
|
||||
|
||||
//Setup dev input
|
||||
config_layer_init(ci_transport_uart_instance(), &config);
|
||||
|
||||
dec_eq_test();
|
||||
while (1) {
|
||||
extern void clr_wdt();
|
||||
clr_wdt();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
log_info("-------SDFile test Start------");
|
||||
|
||||
#ifdef SDFILE_DEV
|
||||
|
||||
#define SDFILE_NAME1 SDFILE_ROOT_PATH"xx.bin"
|
||||
|
||||
void *mnt = mount(SDFILE_DEV, SDFILE_MOUNT_PATH, "jlfs", 0, NULL);
|
||||
if (mnt == NULL) {
|
||||
log_error("mount jlfs failed");
|
||||
return;
|
||||
}
|
||||
|
||||
sdfile_test(SDFILE_NAME1);
|
||||
|
||||
#endif /*SDFILE_DEV*/
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
log_info("--------JL CFG test Start------");
|
||||
|
||||
jl_cfg_dec_test();
|
||||
#endif
|
||||
while (1);
|
||||
}
|
||||
|
||||
static int sdfile_test(const char *name)
|
||||
{
|
||||
log_d("SDFILE file path: %s", name);
|
||||
RESFILE *fp = NULL;
|
||||
u8 buf[16];
|
||||
u8 len;
|
||||
|
||||
fp = resfile_open(name);
|
||||
if (!fp) {
|
||||
log_d("sdfile open file ERR!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = resfile_read(fp, buf, sizeof(buf));
|
||||
|
||||
if (len != sizeof(buf)) {
|
||||
log_d("0-read file ERR!");
|
||||
goto _end;
|
||||
}
|
||||
|
||||
put_buf(buf, sizeof(buf));
|
||||
|
||||
resfile_seek(fp, 16, RESFILE_SEEK_SET);
|
||||
|
||||
len = resfile_read(fp, buf, sizeof(buf));
|
||||
|
||||
if (len != sizeof(buf)) {
|
||||
log_d("1-read file ERR!");
|
||||
goto _end;
|
||||
}
|
||||
|
||||
put_buf(buf, sizeof(buf));
|
||||
|
||||
log_d("SDFILE ok!");
|
||||
|
||||
_end:
|
||||
if (fp) {
|
||||
resfile_close(fp);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_name_parse.data.bss")
|
||||
#pragma data_seg(".bt_name_parse.data")
|
||||
#pragma const_seg(".bt_name_parse.text.const")
|
||||
#pragma code_seg(".bt_name_parse.text")
|
||||
#endif
|
||||
#include "syscfg_id.h"
|
||||
#include "gpio_config.h"
|
||||
#include "gpadc.h"
|
||||
#include "os/os_api.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
struct bt_name_config {
|
||||
u8 len;
|
||||
char name[32];
|
||||
u16 value;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
int adc_get_ch_voltage(u8 adc_ch)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_name_config_parse(char *bt_name)
|
||||
{
|
||||
if (bt_name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 buf[512];
|
||||
struct bt_name_config *config;
|
||||
|
||||
int len = syscfg_read(CFG_ID_BT_NAME_SELECT, buf, 512);
|
||||
if (len < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gpio = uuid2gpio((buf[2] << 8) | buf[1]);
|
||||
if (gpio == 0xff) {
|
||||
return 0;
|
||||
}
|
||||
gpio_set_mode(IO_PORT_SPILT(gpio), PORT_HIGHZ);
|
||||
|
||||
u32 adc_ch = adc_io2ch(gpio);
|
||||
ASSERT(adc_ch != 0xff);
|
||||
|
||||
int adc_value = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
adc_value += adc_get_value_blocking(adc_ch);
|
||||
}
|
||||
adc_value /= 4;
|
||||
printf("bt_name_adc_value: %d\n", adc_value);
|
||||
|
||||
int match = 0;
|
||||
|
||||
for (int i = buf[0] + 1; i < len; i += sizeof(*config)) {
|
||||
if (i + sizeof(*config) > len) {
|
||||
break;
|
||||
}
|
||||
|
||||
config = (struct bt_name_config *)(buf + i);
|
||||
put_buf((u8 *)config, sizeof(*config));
|
||||
printf("i:%d %s %d\n", i, config->name, config->value);
|
||||
if (adc_value > config->value) {
|
||||
memcpy(bt_name, config->name, 32);
|
||||
match = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
gpio_set_mode(IO_PORT_SPILT(gpio), PORT_HIGHZ);
|
||||
return match;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef BT_NAME_PARSE_H
|
||||
#define BT_NAME_PARSE_H
|
||||
|
||||
|
||||
int bt_name_config_parse(char *bt_name);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,246 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_profile_config.data.bss")
|
||||
#pragma data_seg(".bt_profile_config.data")
|
||||
#pragma const_seg(".bt_profile_config.text.const")
|
||||
#pragma code_seg(".bt_profile_config.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "btcontroller_config.h"
|
||||
#include "btstack/btstack_typedef.h"
|
||||
#include "bt_common.h"
|
||||
|
||||
#define LOG_TAG "[BT-CFG]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
typedef struct {
|
||||
// linked list - assert: first field
|
||||
void *offset_item;
|
||||
|
||||
// data is contained in same memory
|
||||
u32 service_record_handle;
|
||||
u8 *service_record;
|
||||
} service_record_item_t;
|
||||
|
||||
extern const u8 sdp_pnp_service_data[];
|
||||
extern const u8 sdp_a2dp_service_data[];
|
||||
extern const u8 sdp_avctp_ct_service_data[];
|
||||
extern const u8 sdp_avctp_ta_service_data[];
|
||||
extern const u8 sdp_hfp_service_data[];
|
||||
extern const u8 sdp_spp_service_data[];
|
||||
extern const u8 sdp_hid_service_data[];
|
||||
extern service_record_item_t sdp_record_item_begin[];
|
||||
extern service_record_item_t sdp_record_item_end[];
|
||||
|
||||
#define SDP_RECORD_HANDLER_REGISTER(handler) \
|
||||
const service_record_item_t handler \
|
||||
sec(.sdp_record_item)
|
||||
|
||||
#if TCFG_USER_BLE_ENABLE
|
||||
|
||||
#if TCFG_BLE_AUDIO_TEST_EN
|
||||
const int config_stack_modules = BT_BTSTACK_LE;
|
||||
#else /* TCFG_BLE_AUDIO_TEST_EN */
|
||||
|
||||
#if ((BT_AI_SEL_PROTOCOL==0)&&TCFG_USER_BLE_ENABLE)
|
||||
const int config_stack_modules = (BT_BTSTACK_CLASSIC | BT_BTSTACK_LE_ADV);
|
||||
#else
|
||||
const int config_stack_modules = BT_BTSTACK_CLASSIC | BT_BTSTACK_LE;
|
||||
#endif
|
||||
|
||||
#endif /* TCFG_BLE_AUDIO_TEST_EN */
|
||||
|
||||
#else
|
||||
const int config_stack_modules = BT_BTSTACK_CLASSIC;
|
||||
#endif
|
||||
|
||||
#if (TCFG_BT_SUPPORT_PNP==1)
|
||||
SDP_RECORD_HANDLER_REGISTER(pnp_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_pnp_service_data,
|
||||
.service_record_handle = 0x1000A,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if (TCFG_BT_SUPPORT_A2DP==1)
|
||||
u8 a2dp_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(a2dp_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_a2dp_service_data,
|
||||
.service_record_handle = 0x00010001,
|
||||
};
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_AVCTP==1)
|
||||
u8 acp_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(arp_ct_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_avctp_ct_service_data,
|
||||
.service_record_handle = 0x00010002,
|
||||
};
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
SDP_RECORD_HANDLER_REGISTER(arp_ta_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_avctp_ta_service_data,
|
||||
.service_record_handle = 0x00010005,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_HFP==1)
|
||||
u8 hfp_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(hfp_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_hfp_service_data,
|
||||
.service_record_handle = 0x00010003,
|
||||
};
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_SPP==1)
|
||||
|
||||
u8 spp_up_profile_support = 1;
|
||||
//FE010000-1234-5678-ABCD-00805F9B34FB
|
||||
/* const u8 sdp_user_spp_service_data[96] = { */
|
||||
/* 0x36, 0x00, 0x5B, 0x09, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x11, 0x09, 0x00, 0x01, 0x36, 0x00, */
|
||||
/* 0x11, 0x1C, 0xfe, 0x01, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0xab, 0xcd, 0x00, 0x80, 0x5F, 0x9b, */
|
||||
/* 0x34, 0xfb, 0x09, 0x00, 0x04, 0x36, 0x00, 0x0E, 0x36, 0x00, 0x03, 0x19, 0x01, 0x00, 0x36, 0x00, */
|
||||
/* 0x05, 0x19, 0x00, 0x03, 0x08, 0x0a, 0x09, 0x00, 0x09, 0x36, 0x00, 0x17, 0x36, 0x00, 0x14, 0x1C, */
|
||||
/* 0xfe, 0x01, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0xab, 0xcd, 0x00, 0x80, 0x5F, 0x9b, 0x34, 0xfb, */
|
||||
/* 0x09, 0x01, 0x00, 0x09, 0x01, 0x00, 0x25, 0x06, 0x4A, 0x4C, 0x5F, 0x53, 0x50, 0x50, 0x00, 0x00, */
|
||||
/* }; */
|
||||
/* SDP_RECORD_HANDLER_REGISTER(spp_user_sdp_record_item) = { */
|
||||
/* .service_record = (u8 *)sdp_user_spp_service_data, */
|
||||
/* .service_record_handle = 0x00010011, */
|
||||
/* }; */
|
||||
|
||||
u8 spp_profile_support = 1;
|
||||
/* SDP_RECORD_HANDLER_REGISTER(spp_sdp_record_item) = { */
|
||||
/* .service_record = (u8 *)sdp_spp_service_data, */
|
||||
/* .service_record_handle = 0x00010004, */
|
||||
/* }; */
|
||||
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_HID==1)
|
||||
u8 hid_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(hid_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_hid_service_data,
|
||||
.service_record_handle = 0x00010006,
|
||||
};
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_PBAP==1)
|
||||
extern const u8 sdp_pbap_service_data[];
|
||||
u8 pbap_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(pbap_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_pbap_service_data,
|
||||
.service_record_handle = 0x00010007,
|
||||
};
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_OPP==1)
|
||||
extern const u8 sdp_opp_service_data[];
|
||||
u8 opp_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(opp_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_opp_service_data,
|
||||
.service_record_handle = 0x00010008,
|
||||
};
|
||||
#endif
|
||||
#if (TCFG_BT_SUPPORT_MAP==1)
|
||||
extern const u8 sdp_map_mce_service_data[];
|
||||
u8 map_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(map_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_map_mce_service_data,
|
||||
.service_record_handle = 0x00010009,
|
||||
};
|
||||
#endif
|
||||
#if (defined USER_SUPPORT_PROFILE_PAN && (USER_SUPPORT_PROFILE_PAN==1))
|
||||
extern const u8 sdp_pan_service_data[200];
|
||||
u8 pan_profile_support = 1;
|
||||
const int ntp_get_time_init = 0;
|
||||
SDP_RECORD_HANDLER_REGISTER(pan_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_pan_service_data,
|
||||
.service_record_handle = 0x0001000E,
|
||||
};
|
||||
#endif
|
||||
/*注意hid_conn_depend_on_dev_company置1之后,安卓手机会默认断开HID连接 */
|
||||
/*注意hid_conn_depend_on_dev_company置2之后,默认不断开HID连接 */
|
||||
/* 注意!!!同地址情况下,鸿蒙手机开启edr hid会出现手机回连ble的情况 */
|
||||
const u8 hid_conn_depend_on_dev_company = 1;
|
||||
const u8 sdp_get_remote_pnp_info = 0;
|
||||
const int CONFIG_BTSTACK_SUPPORT_FUN = 0;//HFP_UPDATE_BATTERY;
|
||||
|
||||
#ifdef CONFIG_256K_FLASH
|
||||
const u8 pbg_support_enable = 0;
|
||||
const u8 adt_profile_support = 0;
|
||||
const u8 more_hfp_cmd_support = 0;
|
||||
#else
|
||||
|
||||
#if ((BT_AI_SEL_PROTOCOL==0)&&TCFG_USER_BLE_ENABLE)
|
||||
const u8 pbg_support_enable = 1;
|
||||
const u8 adt_profile_support = 1;
|
||||
#else
|
||||
const u8 pbg_support_enable = 0;
|
||||
#if WECHAT_SPORT_ENABLE
|
||||
const u8 adt_profile_support = 1;
|
||||
#else
|
||||
const u8 adt_profile_support = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const u8 more_hfp_cmd_support = 1;
|
||||
|
||||
#endif
|
||||
|
||||
#if TCFG_BT_DUAL_CONN_ENABLE
|
||||
#if USER_SUPPORT_DUAL_A2DP_SOURCE
|
||||
const u8 more_avctp_cmd_support = 0;
|
||||
#else
|
||||
const u8 more_avctp_cmd_support = 1;
|
||||
#endif
|
||||
#else
|
||||
#if (RCSP_MODE == RCSP_MODE_EARPHONE) || TCFG_BT_MUSIC_INFO_ENABLE
|
||||
const u8 more_avctp_cmd_support = 1;
|
||||
#else
|
||||
const u8 more_avctp_cmd_support = 0;
|
||||
#endif
|
||||
#endif
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
const u8 hci_inquiry_support = 1;
|
||||
const u8 btstack_emitter_support = 1; /*定义用于优化代码编译*/
|
||||
|
||||
#if TCFG_BT_SUPPORT_A2DP
|
||||
const u8 emitter_hfp_hf_support = 0; /*置1时做发射器连接手机时只支持hfp*/
|
||||
#else
|
||||
const u8 emitter_hfp_hf_support = 1; /*置1时做发射器连接手机时只支持hfp*/
|
||||
#endif
|
||||
|
||||
extern const u8 sdp_a2dp_source_service_data[];
|
||||
|
||||
#if (TCFG_BT_SUPPORT_A2DP==0)
|
||||
u8 a2dp_profile_support = 2;
|
||||
#endif
|
||||
|
||||
SDP_RECORD_HANDLER_REGISTER(a2dp_src_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_a2dp_source_service_data,
|
||||
.service_record_handle = 0x0001000B,
|
||||
};
|
||||
#if (TCFG_BT_SUPPORT_HFP_AG==1)
|
||||
extern const u8 sdp_hfp_ag_service_data[];
|
||||
u8 hfp_ag_profile_support = 1;
|
||||
SDP_RECORD_HANDLER_REGISTER(hfp_ag_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_hfp_ag_service_data,
|
||||
.service_record_handle = 0x0001000C,
|
||||
};
|
||||
#endif
|
||||
#else
|
||||
const u8 hci_inquiry_support = 0;
|
||||
const u8 btstack_emitter_support = 0; /*定义用于优化代码编译*/
|
||||
#endif
|
||||
/*u8 l2cap_debug_enable = 0xf0;
|
||||
u8 rfcomm_debug_enable = 0xf;
|
||||
u8 profile_debug_enable = 0xff;
|
||||
u8 ble_debug_enable = 0xff;
|
||||
u8 btstack_tws_debug_enable = 0xf;*/
|
||||
|
||||
#else
|
||||
const u8 btstack_emitter_support = 1; /*定义用于优化代码编译*/
|
||||
const u8 adt_profile_support = 0;
|
||||
const u8 pbg_support_enable = 0;
|
||||
const int config_stack_modules = 0;
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".cfg_tool_cdc.data.bss")
|
||||
#pragma data_seg(".cfg_tool_cdc.data")
|
||||
#pragma const_seg(".cfg_tool_cdc.text.const")
|
||||
#pragma code_seg(".cfg_tool_cdc.text")
|
||||
#endif
|
||||
#include "cfg_tool_cdc.h"
|
||||
#include "app_config.h"
|
||||
#include "cfg_tool.h"
|
||||
#if TCFG_USB_SLAVE_CDC_ENABLE
|
||||
#include "usb/device/cdc.h"
|
||||
#endif
|
||||
|
||||
#if TCFG_CFG_TOOL_ENABLE && (TCFG_COMM_TYPE == TCFG_USB_COMM)
|
||||
|
||||
#define CFG_TOOL_PROTOCOL_HEAD_SIZE 7
|
||||
|
||||
static u16 rx_len_count = 0;
|
||||
static u16 tool_buf_total_len = 0;
|
||||
static u8 *buf_rx = NULL;
|
||||
|
||||
/**
|
||||
* @brief 获取工具cdc最大支持的协议包大小
|
||||
*/
|
||||
u16 cfg_tool_cdc_rx_max_mtu()
|
||||
{
|
||||
return 1024 * 4 + 22;
|
||||
}
|
||||
|
||||
static void reset_rx_resource()
|
||||
{
|
||||
if (buf_rx) {
|
||||
free(buf_rx);
|
||||
buf_rx = NULL;
|
||||
}
|
||||
rx_len_count = 0;
|
||||
tool_buf_total_len = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取cdc的配置/调音工具相关数据
|
||||
*/
|
||||
void cfg_tool_data_from_cdc(u8 *buf, u32 rlen) // in irq
|
||||
{
|
||||
/* printf("cfg_tool cdc rx:\n"); */
|
||||
/* put_buf(buf, rlen); */
|
||||
|
||||
if ((buf[0] == 0x5A) && (buf[1] == 0xAA) && (buf[2] == 0xA5)) {
|
||||
reset_rx_resource();
|
||||
tool_buf_total_len = CFG_TOOL_READ_LIT_U16(buf + 5);
|
||||
buf_rx = zalloc(CFG_TOOL_PROTOCOL_HEAD_SIZE + tool_buf_total_len);
|
||||
ASSERT(buf_rx);
|
||||
memcpy(buf_rx, buf, rlen);
|
||||
/* printf("cfg_tool cdc need total len1 = %d\n", tool_buf_total_len); */
|
||||
/* printf("cfg_tool cdc rx len1 = %d\n", rlen); */
|
||||
if ((CFG_TOOL_PROTOCOL_HEAD_SIZE + tool_buf_total_len) == rlen) {
|
||||
/* printf("cfg_tool cdc rx1:\n"); */
|
||||
/* put_buf(buf_rx, rlen); */
|
||||
online_cfg_tool_data_deal(buf_rx, rlen);
|
||||
reset_rx_resource();
|
||||
} else {
|
||||
rx_len_count += rlen;
|
||||
}
|
||||
} else {
|
||||
if (!buf_rx) {
|
||||
printf("%s, buf_rx null!\n", __FUNCTION__);
|
||||
reset_rx_resource();
|
||||
return;
|
||||
}
|
||||
if ((rx_len_count + rlen) > (CFG_TOOL_PROTOCOL_HEAD_SIZE + tool_buf_total_len)) {
|
||||
reset_rx_resource();
|
||||
return;
|
||||
}
|
||||
memcpy(buf_rx + rx_len_count, buf, rlen);
|
||||
/* printf("cfg_tool cdc need total len2 = %d\n", tool_buf_total_len); */
|
||||
/* printf("cfg_tool cdc rx len2 = %d\n", rlen + rx_len_count); */
|
||||
if ((tool_buf_total_len + CFG_TOOL_PROTOCOL_HEAD_SIZE) == (rx_len_count + rlen)) {
|
||||
/* printf("cfg_tool cdc rx2:\n"); */
|
||||
/* put_buf(buf_rx, rx_len_count + rlen); */
|
||||
online_cfg_tool_data_deal(buf_rx, rx_len_count + rlen);
|
||||
reset_rx_resource();
|
||||
} else {
|
||||
rx_len_count += rlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".cfg_tool_statistics.data.bss")
|
||||
#pragma data_seg(".cfg_tool_statistics.data")
|
||||
#pragma const_seg(".cfg_tool_statistics.text.const")
|
||||
#pragma code_seg(".cfg_tool_statistics.text")
|
||||
#endif
|
||||
#include "cfg_tool.h"
|
||||
#include "app_config.h"
|
||||
|
||||
#if CFG_TOOL_VER == CFG_TOOL_VER_VISUAL
|
||||
#include "system/malloc.h"
|
||||
#include "system/task.h"
|
||||
#include "cpu.h"
|
||||
|
||||
/* #if (defined CONFIG_CPU_BR27) */
|
||||
/* #include "asm/cache.h" */
|
||||
/* #endif */
|
||||
|
||||
#endif
|
||||
|
||||
#define TEMP_BUF_SIZE 256
|
||||
#define TASK_INFO_NUM_MAX_SIZE 5
|
||||
#define MAX_TASKS_INFO_LIST_NUM 32
|
||||
|
||||
#if TCFG_CFG_TOOL_ENABLE && (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
|
||||
static SIMPLE_TASK_INFO *_simple_task_info_list = NULL;
|
||||
static u16 _simple_task_info_list_valid_len;
|
||||
static CACHE_INFO *_cache_info_list = NULL; // (cpu's icache) + dcache
|
||||
|
||||
static void cfg_tool_statistics_callback(u8 *packet, u32 size)
|
||||
{
|
||||
u32 send_len = 0;
|
||||
u8 *buf = NULL;
|
||||
|
||||
u32 cmd = packet_combined(packet, 2);
|
||||
|
||||
switch (cmd) {
|
||||
case ONLINE_SUB_OP_REFRESH_TASK_INFO_LIST:
|
||||
if (_simple_task_info_list == NULL) {
|
||||
_simple_task_info_list = malloc(sizeof(SIMPLE_TASK_INFO) * MAX_TASKS_INFO_LIST_NUM);
|
||||
if (!_simple_task_info_list) {
|
||||
printf("_simple_task_info_list malloc err!\n");
|
||||
send_len = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_simple_task_info_list_valid_len = simple_task_info_list_get(_simple_task_info_list, MAX_TASKS_INFO_LIST_NUM);
|
||||
send_len = sizeof(_simple_task_info_list_valid_len);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, (void *)&_simple_task_info_list_valid_len, send_len);
|
||||
break;
|
||||
case ONLINE_SUB_OP_GET_TASK_INFO_LIST:
|
||||
u32 index = packet_combined(packet, 6);
|
||||
if (index < _simple_task_info_list_valid_len) {
|
||||
u32 task_info_num = 0;
|
||||
u32 task_info_size = sizeof(SIMPLE_TASK_INFO);
|
||||
send_len += sizeof(u32);
|
||||
for (u32 _index = index; (_index < _simple_task_info_list_valid_len) && (task_info_num < TASK_INFO_NUM_MAX_SIZE); _index++, task_info_num++) {
|
||||
send_len += task_info_size;
|
||||
}
|
||||
task_info_num = 0;
|
||||
buf = send_buf_malloc(send_len);
|
||||
for (u32 _index = index; (_index < _simple_task_info_list_valid_len) && (task_info_num < TASK_INFO_NUM_MAX_SIZE); _index++, task_info_num++) {
|
||||
memcpy(buf + sizeof(u32) + task_info_size * task_info_num, &_simple_task_info_list[_index], task_info_size);
|
||||
}
|
||||
memcpy(buf, &task_info_num, sizeof(u32));
|
||||
} else {
|
||||
send_len = 0;
|
||||
}
|
||||
break;
|
||||
case ONLINE_SUB_OP_GET_CACHE_INFO_LIST:
|
||||
#if (defined CONFIG_CPU_BR27)
|
||||
u32 cache_list_len = (CPU_CORE_NUM + 1);
|
||||
u32 cache_info_size = sizeof(CACHE_INFO);
|
||||
if (_cache_info_list == NULL) {
|
||||
_cache_info_list = malloc(cache_info_size * cache_list_len); // (cpu's icache) + dcache
|
||||
if (!_cache_info_list) {
|
||||
printf("_cache_info_list malloc err!\n");
|
||||
send_len = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cache_info_list_get(_cache_info_list, cache_list_len);
|
||||
send_len += sizeof(u32);
|
||||
send_len += cache_info_size * cache_list_len;
|
||||
buf = send_buf_malloc(send_len);
|
||||
for (u32 i = 0; i < cache_list_len; i++) {
|
||||
memcpy(buf + sizeof(u32) + cache_info_size * i, &_cache_info_list[i], cache_info_size);
|
||||
}
|
||||
memcpy(buf, &cache_list_len, sizeof(u32));
|
||||
#else
|
||||
send_len = 0;
|
||||
#endif
|
||||
break;
|
||||
default: // DEFAULT_ACTION
|
||||
if (buf != NULL) {
|
||||
free(buf);
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
if (buf != NULL) {
|
||||
all_assemble_package_send_to_pc(REPLY_STYLE, packet[1], buf, send_len);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_DETECT_TARGET(cfg_tool_statistics_target) = {
|
||||
.id = VISUAL_CFG_TOOL_CHANNEL_STYLE,
|
||||
.tool_message_deal = cfg_tool_statistics_callback,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 清理配置工具的统计资源
|
||||
*/
|
||||
void cfg_tool_statistics_resource_release()
|
||||
{
|
||||
if (_simple_task_info_list) {
|
||||
free(_simple_task_info_list);
|
||||
}
|
||||
if (_cache_info_list) {
|
||||
free(_cache_info_list);
|
||||
}
|
||||
_simple_task_info_list = NULL;
|
||||
_cache_info_list = NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,398 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".ci_transport_uart.data.bss")
|
||||
#pragma data_seg(".ci_transport_uart.data")
|
||||
#pragma const_seg(".ci_transport_uart.text.const")
|
||||
#pragma code_seg(".ci_transport_uart.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "config/config_interface.h"
|
||||
#include "system/event.h"
|
||||
#include "app_online_cfg.h"
|
||||
#include "uart.h"
|
||||
#include "app_config.h"
|
||||
#include "asm/crc16.h"
|
||||
#include "cfg_tool.h"
|
||||
#include "app_msg.h"
|
||||
|
||||
#define LOG_TAG "[CI-UART]"
|
||||
/* #define LOG_ERROR_ENABLE */
|
||||
/* #define LOG_INFO_ENABLE */
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#include "debug.h"
|
||||
|
||||
extern u16 crc_get_16bit(const void *src, u32 len);
|
||||
|
||||
#if (TCFG_ONLINE_ENABLE || TCFG_CFG_TOOL_ENABLE)
|
||||
struct config_uart {
|
||||
u32 baudrate;
|
||||
int flowcontrol;
|
||||
const char *dev_name;
|
||||
};
|
||||
|
||||
struct uart_hdl {
|
||||
|
||||
struct config_uart config;
|
||||
|
||||
int udev;
|
||||
void *dbuf;
|
||||
|
||||
void *pRxBuffer;
|
||||
|
||||
u8 ucRxIndex;
|
||||
u8 rx_type;
|
||||
|
||||
u16 data_length;
|
||||
|
||||
void *pTxBuffer;
|
||||
|
||||
void (*packet_handler)(const u8 *packet, int size);
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
//head
|
||||
u16 preamble;
|
||||
u8 type;
|
||||
u16 length;
|
||||
u8 crc8;
|
||||
u16 crc16;
|
||||
u8 payload[0];
|
||||
} _GNU_PACKED_ uart_packet_t;
|
||||
|
||||
#define UART_FORMAT_HEAD sizeof(uart_packet_t)
|
||||
|
||||
typedef struct {
|
||||
//head
|
||||
u16 preamble0;
|
||||
u8 preamble1;
|
||||
u16 crc16;
|
||||
u16 length;
|
||||
u8 type;
|
||||
u8 sq;
|
||||
u8 payload[0];
|
||||
} _GNU_PACKED_ uart_tool_packet_t;
|
||||
|
||||
#define UART_TOOL_FORMAT_HEAD sizeof(uart_tool_packet_t)
|
||||
|
||||
static void dummy_handler(const u8 *packet, int size);
|
||||
|
||||
#define UART_PREAMBLE 0xBED6
|
||||
#define UART_NEW_TOOL_PREAMBLE0 0xAA5A
|
||||
#define UART_NEW_TOOL_PREAMBLE1 0xA5
|
||||
|
||||
#define UART_RX_SIZE 0x500
|
||||
#define UART_TX_SIZE 0x30
|
||||
#define UART_DB_SIZE 0x500
|
||||
#define UART_BAUD_RATE 115200
|
||||
|
||||
/* #define HAVE_MALLOC */
|
||||
#ifdef HAVE_MALLOC
|
||||
static struct uart_hdl *hdl;
|
||||
#define __this (hdl)
|
||||
#else
|
||||
static struct uart_hdl hdl;
|
||||
#define __this (&hdl)
|
||||
|
||||
static u8 pRxBuffer_static[UART_RX_SIZE] __attribute__((aligned(4))); //rx memory
|
||||
static u8 pTxBuffer_static[UART_TX_SIZE] __attribute__((aligned(4))); //tx memory
|
||||
static u8 devBuffer_static[UART_DB_SIZE] __attribute__((aligned(4))); //dev DMA memory
|
||||
#endif
|
||||
|
||||
s16 get_ci_tx_size()
|
||||
{
|
||||
return UART_TX_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取工具串口最大支持的协议包大小
|
||||
*/
|
||||
u16 get_ci_rx_size()
|
||||
{
|
||||
return UART_RX_SIZE;
|
||||
}
|
||||
|
||||
static u8 procotol = 0;
|
||||
void ci_data_rx_handler(u8 type)
|
||||
{
|
||||
u16 crc16;
|
||||
uart_tool_packet_t *p_newtool;
|
||||
uart_packet_t *p;
|
||||
|
||||
__this->rx_type = type;
|
||||
|
||||
if (type == CI_UART && __this->udev) {
|
||||
int bytes_read = uart_recv_bytes(__this->udev, &__this->pRxBuffer[__this->data_length], (UART_RX_SIZE - __this->data_length)); //串口读取buf剩余空间的长度,实际长度比buf长,导致越界改写问题
|
||||
if (bytes_read > 0) {
|
||||
__this->data_length += bytes_read;
|
||||
}
|
||||
}
|
||||
|
||||
/* log_info("Rx : %d", __this->data_length); */
|
||||
/* log_info_hexdump(__this->pRxBuffer, __this->data_length); */
|
||||
if (__this->data_length > UART_RX_SIZE) {
|
||||
log_error("Wired");
|
||||
}
|
||||
|
||||
u8 *tmp_buf = NULL;
|
||||
tmp_buf = __this->pRxBuffer;
|
||||
if (__this->data_length >= 2) {
|
||||
unsigned i = 0;
|
||||
for (i = 0; i < __this->data_length - 1; ++i) {
|
||||
if ((tmp_buf[i] == 0x5A) && (tmp_buf[i + 1] == 0xAA) && (tmp_buf[i + 2] == 0xA5)) {
|
||||
procotol = 1;
|
||||
break;
|
||||
} else if (tmp_buf[i] == 0xD6 && tmp_buf[i + 1] == 0xBE) {
|
||||
procotol = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i != 0) {
|
||||
__this->data_length -= i;
|
||||
/* printf("__this->data_length %d i %d\n", __this->data_length, i); */
|
||||
if (__this->data_length > 0) {
|
||||
memmove(&__this->pRxBuffer[0], &tmp_buf[i], __this->data_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (procotol) {
|
||||
if (__this->data_length <= UART_TOOL_FORMAT_HEAD) {
|
||||
return;
|
||||
}
|
||||
p_newtool = __this->pRxBuffer;
|
||||
|
||||
if ((p_newtool->preamble0 != UART_NEW_TOOL_PREAMBLE0) || (p_newtool->preamble1 != UART_NEW_TOOL_PREAMBLE1)) {
|
||||
log_error("preamble err\n");
|
||||
log_info_hexdump(__this->pRxBuffer, __this->data_length);
|
||||
goto reset_buf;
|
||||
}
|
||||
|
||||
if (__this->data_length >= (p_newtool->length + 7)) {
|
||||
// crc校验统一放到业务层处理
|
||||
/* crc16 = crc_get_16bit(&p_newtool->length, p_newtool->length + 2); */
|
||||
/* log_info("CRC16 0x%x / 0x%x", crc16, p_newtool->crc16); */
|
||||
/* if (p_newtool->crc16 != crc16) { */
|
||||
/* log_error("crc16 err\n"); */
|
||||
/* goto reset_buf; */
|
||||
/* } */
|
||||
/* printf("cfg_tool rx:\n"); */
|
||||
/* log_info_hexdump((u8 *)p_newtool, p_newtool->length + 7); */
|
||||
online_cfg_tool_data_deal(p_newtool, p_newtool->length + 7);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (__this->data_length <= UART_FORMAT_HEAD) {
|
||||
return;
|
||||
}
|
||||
p = __this->pRxBuffer;
|
||||
|
||||
if (p->preamble != UART_PREAMBLE) {
|
||||
log_info("preamble err\n");
|
||||
log_info_hexdump(__this->pRxBuffer, __this->data_length);
|
||||
goto reset_buf;
|
||||
}
|
||||
|
||||
crc16 = crc_get_16bit(__this->pRxBuffer, UART_FORMAT_HEAD - 3);
|
||||
/* log_info("CRC8 0x%x / 0x%x", crc16, p->crc8); */
|
||||
if (p->crc8 != (crc16 & 0xff)) {
|
||||
log_info("crc8 err\n");
|
||||
goto reset_buf;
|
||||
}
|
||||
if (__this->data_length >= p->length + UART_FORMAT_HEAD) {
|
||||
/* log_info("Total length : 0x%x / Rx length : 0x%x", __this->data_length, p->length + CI_FORMAT_HEAD); */
|
||||
crc16 = crc_get_16bit(p->payload, p->length);
|
||||
/* log_info("CRC16 0x%x / 0x%x", crc16, p->crc16); */
|
||||
if (p->crc16 != crc16) {
|
||||
log_info("crc16 err\n");
|
||||
goto reset_buf;
|
||||
}
|
||||
__this->packet_handler(p->payload, p->length);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reset_buf:
|
||||
__this->data_length = 0;
|
||||
}
|
||||
|
||||
static void ci_uart_isr_cb(int uart_num, enum uart_event event)
|
||||
{
|
||||
|
||||
os_taskq_post_type("app_core", MSG_FROM_CI_UART, 0, NULL);
|
||||
}
|
||||
|
||||
static int ci_data_rx_handler_entry(int *msg)
|
||||
{
|
||||
ci_data_rx_handler(CI_UART);
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(ci_uart_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_CI_UART,
|
||||
.handler = ci_data_rx_handler_entry,
|
||||
};
|
||||
|
||||
static int ci_uart_init()
|
||||
{
|
||||
/* JL_CLOCK->CLK_CON1 |= BIT(11); */
|
||||
/* JL_CLOCK->CLK_CON1 &= ~BIT(10); */
|
||||
__this->data_length = 0;
|
||||
|
||||
struct uart_config config = {
|
||||
.baud_rate = __this->config.baudrate,
|
||||
.tx_pin = TCFG_ONLINE_TX_PORT,
|
||||
.rx_pin = TCFG_ONLINE_RX_PORT,
|
||||
};
|
||||
struct uart_dma_config dma = {
|
||||
.rx_timeout_thresh = 1000,
|
||||
.frame_size = UART_DB_SIZE,
|
||||
.event_mask = UART_EVENT_RX_DATA | UART_EVENT_RX_TIMEOUT | UART_EVENT_RX_FIFO_OVF,
|
||||
.irq_callback = ci_uart_isr_cb,
|
||||
.rx_cbuffer = __this->dbuf,
|
||||
.rx_cbuffer_size = UART_DB_SIZE,
|
||||
};
|
||||
__this->udev = uart_init(-1, &config);
|
||||
if (__this->udev < 0) {
|
||||
log_error("open uart dev err\n");
|
||||
__this->udev = -1;
|
||||
return -1;
|
||||
}
|
||||
uart_dma_init(__this->udev, &dma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ci_uart_putbyte(char a)
|
||||
{
|
||||
if (__this->udev != -1) {
|
||||
uart_putbyte(__this->udev, a);
|
||||
}
|
||||
}
|
||||
|
||||
void ci_uart_write(u8 *buf, u16 len)
|
||||
{
|
||||
if (__this->udev != -1) {
|
||||
uart_send_bytes(__this->udev, buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
static void dummy_handler(const u8 *packet, int size)
|
||||
{
|
||||
log_error("Dummy");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void ci_dev_init(const void *config)
|
||||
{
|
||||
#ifdef HAVE_MALLOC
|
||||
__this = malloc(sizeof(struct uart_hdl));
|
||||
ASSERT(__this, "Fatal error");
|
||||
|
||||
memset(__this, 0x0, sizeof(struct uart_hdl));
|
||||
|
||||
__this->pRxBuffer = dma_malloc(UART_RX_SIZE);
|
||||
ASSERT(__this->pRxBuffer, "Fatal error");
|
||||
|
||||
__this->pTxBuffer = dma_malloc(UART_TX_SIZE);
|
||||
ASSERT(__this->pTxBuffer, "Fatal error");
|
||||
|
||||
__this->dbuf = dma_malloc(UART_DB_SIZE);
|
||||
ASSERT(__this->dbuf, "Fatal error");
|
||||
#else
|
||||
log_info("Static");
|
||||
__this->pRxBuffer = pRxBuffer_static;
|
||||
__this->pTxBuffer = pTxBuffer_static;
|
||||
__this->dbuf = devBuffer_static;
|
||||
#endif
|
||||
|
||||
__this->packet_handler = dummy_handler;
|
||||
|
||||
ci_transport_config_uart_t *ci_config_uart = (ci_transport_config_uart_t *)config;
|
||||
|
||||
__this->config.baudrate = ci_config_uart->baudrate_init;
|
||||
__this->config.flowcontrol = ci_config_uart->flowcontrol;
|
||||
__this->config.dev_name = ci_config_uart->device_name;
|
||||
|
||||
log_info("baudrate : %d", __this->config.baudrate);
|
||||
log_info("flowcontrol: %d", __this->config.flowcontrol);
|
||||
}
|
||||
|
||||
static int ci_dev_open(void)
|
||||
{
|
||||
ci_uart_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_dev_close(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ci_dev_register_packet_handler(void (*handler)(const u8 *packet, int size))
|
||||
{
|
||||
__this->packet_handler = handler;
|
||||
}
|
||||
|
||||
static int ci_dev_send_packet(const u8 *packet, int size)
|
||||
{
|
||||
/* dev_stream_out(); */
|
||||
int i = 0;
|
||||
uart_packet_t *p = (uart_packet_t *)__this->pTxBuffer;
|
||||
|
||||
p->preamble = UART_PREAMBLE;
|
||||
p->type = 0;
|
||||
p->length = size;
|
||||
p->crc8 = crc_get_16bit(p, UART_FORMAT_HEAD - 3) & 0xff;
|
||||
p->crc16 = crc_get_16bit(packet, size);
|
||||
|
||||
size += UART_FORMAT_HEAD;
|
||||
/* ASSERT(size <= UART_TX_SIZE, "Fatal Error"); */
|
||||
if (size > UART_TX_SIZE) {
|
||||
log_e("Fatal Error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(p->payload, packet, size);
|
||||
|
||||
/* log_info("Tx : %d", size); */
|
||||
/* log_info_hexdump(p, size); */
|
||||
if (__this->rx_type == CI_UART) {
|
||||
#if 0
|
||||
while (size--) {
|
||||
ci_uart_putbyte(((char *)p)[i++]);
|
||||
}
|
||||
#else
|
||||
ci_uart_write((u8 *)p, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_dev_can_send_packet_now(uint8_t packet_type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get dev api skeletons
|
||||
static const ci_transport_t ci_transport_uart = {
|
||||
/* const char * name; */ "CI_UART",
|
||||
/* void (*init) (const void *transport_config); */ &ci_dev_init,
|
||||
/* int (*open)(void); */ &ci_dev_open,
|
||||
/* int (*close)(void); */ &ci_dev_close,
|
||||
/* void (*register_packet_handler)(void (*handler)(...); */ &ci_dev_register_packet_handler,
|
||||
/* int (*can_send_packet_now)(uint8_t packet_type); */ &ci_dev_can_send_packet_now,
|
||||
/* int (*send_packet)(...); */ &ci_dev_send_packet,
|
||||
};
|
||||
|
||||
const ci_transport_t *ci_transport_uart_instance(void)
|
||||
{
|
||||
return &ci_transport_uart;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
|
||||
#ifndef _BT_PROFILE_CFG_H_
|
||||
#define _BT_PROFILE_CFG_H_
|
||||
|
||||
#include "app_config.h"
|
||||
#include "btcontroller_modules.h"
|
||||
|
||||
|
||||
#if ((BT_AI_SEL_PROTOCOL & TRANS_DATA_EN) || (BT_AI_SEL_PROTOCOL & RCSP_MODE_EN) || (BT_AI_SEL_PROTOCOL & ANCS_CLIENT_EN) || (BT_AI_SEL_PROTOCOL & LL_SYNC_EN) || (BT_AI_SEL_PROTOCOL & TUYA_DEMO_EN))
|
||||
#ifndef BT_FOR_APP_EN
|
||||
#define BT_FOR_APP_EN 1
|
||||
#endif
|
||||
#else
|
||||
#ifndef BT_FOR_APP_EN
|
||||
#define BT_FOR_APP_EN 0
|
||||
#endif
|
||||
// #ifndef AI_APP_PROTOCOL
|
||||
// #define AI_APP_PROTOCOL 0
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
|
||||
///---sdp service record profile- 用户选择支持协议--///
|
||||
#if (BT_FOR_APP_EN \
|
||||
|| APP_ONLINE_DEBUG \
|
||||
|| (BT_AI_SEL_PROTOCOL & (GFPS_EN | REALME_EN | TME_EN | DMA_EN | GMA_EN | MMA_EN | FMNA_EN | ONLINE_DEBUG_EN | CUSTOM_DEMO_EN)))
|
||||
#if ((BT_AI_SEL_PROTOCOL & LL_SYNC_EN) || (BT_AI_SEL_PROTOCOL & TUYA_DEMO_EN))
|
||||
#undef TCFG_BT_SUPPORT_SPP
|
||||
#define TCFG_BT_SUPPORT_SPP 0
|
||||
#else
|
||||
#undef TCFG_BT_SUPPORT_SPP
|
||||
#define TCFG_BT_SUPPORT_SPP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//ble demo的例子
|
||||
#define DEF_BLE_DEMO_NULL 0 //ble 没有使能
|
||||
#define DEF_BLE_DEMO_ADV 1 //only adv,can't connect
|
||||
#define DEF_BLE_DEMO_TRANS_DATA 2 //
|
||||
#define DEF_BLE_DEMO_RCSP_DEMO 4 //
|
||||
#define DEF_BLE_DEMO_ADV_RCSP 5
|
||||
#define DEF_BLE_DEMO_CLIENT 7 //
|
||||
#define DEF_BLE_ANCS_ADV 9
|
||||
#define DEF_BLE_DEMO_MULTI 11 //
|
||||
#define DEF_BLE_DEMO_LL_SYNC 13 //
|
||||
#define DEF_BLE_DEMO_WIRELESS_MIC_SERVER 14 //
|
||||
#define DEF_BLE_DEMO_WIRELESS_MIC_CLIENT 15 //
|
||||
#define DEF_BLE_DEMO_TUYA 16 //
|
||||
#define DEF_BLE_WL_MIC_1T1_TX 17
|
||||
#define DEF_BLE_WL_MIC_1T1_RX 18
|
||||
#define DEF_BLE_WL_MIC_1TN_TX 19
|
||||
#define DEF_BLE_WL_MIC_1TN_RX 20
|
||||
#define DEF_LE_AUDIO_CENTRAL 21
|
||||
#define DEF_LE_AUDIO_PERIPHERAL 22
|
||||
#define DEF_LE_AUDIO_BROADCASTER 23
|
||||
|
||||
//delete 2021-09-24;删除公共配置,放到各个profile自己配置
|
||||
// #define TCFG_BLE_SECURITY_EN 0 /*是否发请求加密命令*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,298 @@
|
||||
#ifndef _APP_CFG_TOOL_
|
||||
#define _APP_CFG_TOOL_
|
||||
|
||||
#include "typedef.h"
|
||||
#include "fs/resfile.h"
|
||||
#include "fs/sdfile.h"
|
||||
#include "tzflash_api.h"
|
||||
#include "app_config.h"
|
||||
|
||||
//====================可视化配置工具版本定义===========================
|
||||
#define CFG_TOOL_VER_NEW (1) // 新配置工具,zhenyu提供
|
||||
#define CFG_TOOL_VER_VISUAL (2) // 可视化配置工具,senhua提供
|
||||
//=====================================================================
|
||||
|
||||
// 设置可视化配置工具版本
|
||||
#define CFG_TOOL_VER CFG_TOOL_VER_VISUAL
|
||||
|
||||
#define SPP_DATA_USED_LVT 0 //1:旧调音lvt 0:可视化配置工具55 aa a5
|
||||
|
||||
/*支持的工具通道 SPP*/
|
||||
#define SPP_CFG_CH 0x12
|
||||
#define SPP_OLD_EQ_CH 0x11
|
||||
#define SPP_NEW_EQ_CH 0x05
|
||||
|
||||
/*T 表示包的类型*/
|
||||
#define REPLY_STYLE 0x00 //无论哪种模式下,回复包都用该种类型
|
||||
#define SLAVE_ATIVE_SEND 0x01 //小机主动上发给PC,如日志
|
||||
#define INITIATIVE_STYLE 0x12 //主动发送数据的包用该类型
|
||||
#define VISUAL_CFG_TOOL_CHANNEL_STYLE 0x21 //新配置工具使用通道
|
||||
|
||||
/*
|
||||
*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| VERSION |AT| X| X| X| X| X| X| X| X| X| X| X|
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*/
|
||||
#define PROTOCOL_VER_AT_NEW 0x0001 //使用新模式(BR23, ATK 0x11)
|
||||
#define PROTOCOL_VER_AT_OLD 0x0011 //使用旧模式(BR25, EQ 0x05, 音效 0x06)
|
||||
|
||||
|
||||
/*新配置工具/可视化配置工具文件所属文件ID为0*/
|
||||
#define CFG_TOOL_FILEID 0x00000000
|
||||
|
||||
#if (defined CONFIG_NEW_CFG_TOOL_ENABLE)
|
||||
#define CFG_TOOL_FILE FLASH_RES_PATH"cfg_tool.bin"
|
||||
#else
|
||||
#define CFG_TOOL_FILE FLASH_APP_PATH"cfg_tool.bin"
|
||||
#endif
|
||||
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_NEW)
|
||||
|
||||
/*旧调音工具eq文件所属文件ID为1*/
|
||||
#define CFG_OLD_EQ_FILEID 0x00000001
|
||||
#define CFG_OLD_EQ_FILE FLASH_RES_PATH"eq_cfg_hw.bin"
|
||||
|
||||
/*旧调音工具混响文件所属文件ID为2*/
|
||||
#define CFG_OLD_EFFECT_FILEID 0x00000002
|
||||
#define CFG_OLD_EFFECT_FILE FLASH_RES_PATH"effects_cfg.bin"
|
||||
|
||||
/*新调音工具eq文件所属文件ID为3*/
|
||||
#define CFG_EQ_FILEID 0x00000003
|
||||
#define CFG_EQ_FILE FLASH_RES_PATH"eq_cfg_hw.bin"
|
||||
|
||||
#else
|
||||
|
||||
/*可视化配置工具stream.bin文件所属文件ID为1*/
|
||||
#define CFG_STREAM_FILEID 0x00000001
|
||||
#define CFG_STREAM_FILE FLASH_RES_PATH"stream.bin"
|
||||
|
||||
/*可视化配置工具effects_cfg.bin文件所属文件ID为2*/
|
||||
#define CFG_EFFECT_CFG_FILEID 0x00000002
|
||||
#define CFG_EFFECT_CFG_FILE FLASH_RES_PATH"effect_cfg.bin"
|
||||
|
||||
#endif
|
||||
|
||||
#define CFG_TOOL_READ_LIT_U16(a) (*((u8*)(a)) + (*((u8*)(a)+1)<<8))
|
||||
#define CFG_TOOL_WRITE_LIT_U16(a,src) {*((u8*)(a)+1) = (u8)(src>>8); *((u8*)(a)+0) = (u8)(src&0xff); }
|
||||
|
||||
/*****************************************************************/
|
||||
/****PC与小机使用到的CMD,CMD包含在DATA中,为DATA的前4个Byte******/
|
||||
/*****************************************************************/
|
||||
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
#define ONLINE_SUB_OP_QUERY_BASIC_INFO 0x00000400 //查询固件的基本信息
|
||||
#else
|
||||
#define ONLINE_SUB_OP_QUERY_BASIC_INFO 0x00000023 //查询固件的基本信息
|
||||
#endif
|
||||
#define ONLINE_SUB_OP_QUERY_FILE_SIZE 0x0000000B //查询文件大小
|
||||
#define ONLINE_SUB_OP_QUERY_FILE_CONTENT 0x0000000C //读取文件内容
|
||||
#define ONLINE_SUB_OP_PREPARE_WRITE_FILE 0x00000022 //准备写入文件
|
||||
#define ONLINE_SUB_OP_READ_ADDR_RANGE 0x00000027 //读取地址范围内容
|
||||
#define ONLINE_SUB_OP_ERASE_ADDR_RANGE 0x00000024 //擦除地址范围内容
|
||||
#define ONLINE_SUB_OP_WRITE_ADDR_RANGE 0x00000025 //写入地址范围内容
|
||||
#define ONLINE_SUB_OP_ENTER_UPGRADE_MODE 0x00000026 //进入升级模式
|
||||
#define ONLINE_SUB_OP_ONLINE_INSPECTION 0x00000401 //在线检测
|
||||
#define ONLINE_SUB_OP_REFRESH_TASK_INFO_LIST 0x00000402 //刷新任务堆栈信息列表缓存
|
||||
#define ONLINE_SUB_OP_GET_TASK_INFO_LIST 0x00000403 //获取任务堆栈信息列表缓存
|
||||
#define ONLINE_SUB_OP_GET_CACHE_INFO_LIST 0x00000405 //获取cache效率列表缓存
|
||||
#define ONLINE_SUB_OP_CPU_RESET 0x00000505 //设备重启
|
||||
#define DEFAULT_ACTION 0x000000FF //其他工具的数据
|
||||
|
||||
/*****************************************************************/
|
||||
/*****小机接收PC的DATA,具体携带的数据,依据命令不同而不同**********/
|
||||
/*****************************************************************/
|
||||
|
||||
struct cfg_tool_event {
|
||||
u32 event;
|
||||
u8 *packet;
|
||||
u16 size;
|
||||
};
|
||||
|
||||
// 系统信息
|
||||
typedef struct {
|
||||
u32 use_mem;
|
||||
u32 total_mem; // 内存相关
|
||||
u32 cpu_use_ratio; // CPU占用
|
||||
u32 task_num; // 任务总数
|
||||
} R_QUERY_SYS_INFO;
|
||||
|
||||
//查询固件的基本信息
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x23
|
||||
} R_QUERY_BASIC_INFO;
|
||||
|
||||
//查询文件大小
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x0B
|
||||
u32 file_id; //查询的文件的ID,配置文件的ID为0
|
||||
} R_QUERY_FILE_SIZE;
|
||||
|
||||
//读取文件内容
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x0C
|
||||
u32 file_id; //文件ID
|
||||
u32 offset; //偏移
|
||||
u32 size;
|
||||
} R_QUERY_FILE_CONTENT;
|
||||
|
||||
//准备写入文件
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x22
|
||||
u32 file_id; //文件ID
|
||||
u32 size; //文件大小
|
||||
} R_PREPARE_WRITE_FILE;
|
||||
|
||||
//读取地址范围内容
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x23
|
||||
u32 addr; //flash的物理地址
|
||||
u32 size; //读取的范围大小
|
||||
} R_READ_ADDR_RANGE;
|
||||
|
||||
//擦除地址范围内容
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x24
|
||||
u32 addr; //起始地址
|
||||
u32 size; //擦除大小
|
||||
} R_ERASE_ADDR_RANGE;
|
||||
|
||||
//写入地址范围内容
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x25
|
||||
u32 addr; //物理地址
|
||||
u32 size; //内容大小
|
||||
/*uint8_t body[0];*/ //具体内容,大小为size
|
||||
} R_WRITE_ADDR_RANGE;
|
||||
|
||||
//进入升级模式
|
||||
typedef struct {
|
||||
u32 cmd_id; //命令号,为0x26
|
||||
} R_ENTER_UPGRADE_MODE;
|
||||
|
||||
/*****************************************************************/
|
||||
/*******小机返回PC发送的DATA,具体的内容,依据命令不同而不同********/
|
||||
/*****************************************************************/
|
||||
|
||||
//(1)查询固件的基本信息
|
||||
typedef struct {
|
||||
u16 protocolVer; //协议版本,目前为1
|
||||
u8 progCrc[32]; //固件的CRC,返回字符串,\0 结尾
|
||||
u8 sdkName[32]; //SDK名字,\0 结尾
|
||||
u8 pid[16]; //PID,\0 结尾(注意最长是16字节,16字节的时候,末尾不需要0)
|
||||
u8 vid[16]; //VID,\0 结尾
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
u16 max_buffer_size; // 每一包协议的总大小最大支持多少
|
||||
#endif
|
||||
} S_QUERY_BASIC_INFO;
|
||||
|
||||
//(2)查询文件大小
|
||||
typedef struct {
|
||||
u32 file_size; //文件大小
|
||||
} S_QUERY_FILE_SIZE;
|
||||
|
||||
//(3)读取文件内容
|
||||
/*
|
||||
* 返回:具体的文件内容,长度为命令中的size参数
|
||||
* 注:PC工具在获取配置文件的大小后,会自行决定拆分成几次命令读取
|
||||
*/
|
||||
|
||||
//(4)准备写入文件
|
||||
/*
|
||||
* 例如,cfg_tool.bin 本身的物理地址可能是 100,而擦除单元是 4K(4096),cfg_tool.bin 本身大小是 3999 字节,则
|
||||
* file_addr = 100, file_size = 3999, earse_unit = 4096。
|
||||
* 注意,接下来,PC 端会读取```[0, 8192)```这个范围的内容,修改掉```[100,4099]```的内容,然后再通过其他命令,
|
||||
* 把```[0,8192)```这范围的内容写回去。
|
||||
*/
|
||||
typedef struct {
|
||||
u32 file_addr; //配置文件真实物理地址
|
||||
u32 file_size; //配置文件(cfg_tool.bin)本身的大小
|
||||
u32 earse_unit; //flash 擦除单元(如 4K 的时候,填 4096)
|
||||
} S_PREPARE_WRITE_FILE;
|
||||
|
||||
|
||||
//(5)读取地址范围内容
|
||||
/*
|
||||
* 返回:具体的文件内容,长度为命令中的size参数
|
||||
* 注:PC工具在获取配置文件的大小后,会自行决定拆分成几次命令读取
|
||||
*/
|
||||
|
||||
//(6)擦除地址范围内容
|
||||
/*
|
||||
*返回两个字节的内容,"FA"或者"OK",表示失败或者成功
|
||||
*/
|
||||
|
||||
//(7)写入地址范围内容
|
||||
/*
|
||||
*返回两个字节的内容,"FA"或者"OK",表示失败或者成功
|
||||
*/
|
||||
|
||||
//(8)进入升级模式
|
||||
/*
|
||||
*小机收到命令后,进入升级模式
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief uart/usb/spp收到的数据流通过这个接口传入进行数据解析
|
||||
*
|
||||
* @param buf 存储uart/usb/spp收到的数据包
|
||||
* @param len buf的长度(byte)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u8 online_cfg_tool_data_deal(void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 设备组装数据包并发送给PC工具,支持uart/usb/spp返回
|
||||
*
|
||||
* @param id 表示包的类型(不同的数据通道)
|
||||
* @param sq 对应需要回应的包的序号
|
||||
* @param buf 要发送的数据包DATA部分
|
||||
* @param len buf的长度(byte)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void all_assemble_package_send_to_pc(u8 id, u8 sq, u8 *buf, u32 len);
|
||||
|
||||
// 发送buf malloc
|
||||
u8 *send_buf_malloc(u32 send_buf_size);
|
||||
|
||||
// 4bytes大小端转换
|
||||
u32 packet_combined(u8 *packet, u8 num);
|
||||
|
||||
// 可视化配置工具在线状态
|
||||
typedef enum {
|
||||
CFG_TOOL_ONLINE_STATUS_OFFLINE = 0x00,
|
||||
CFG_TOOL_ONLINE_STATUS_ONLINE = 0x01,
|
||||
} CFG_TOOL_ONLINE_STATUS;
|
||||
/**
|
||||
* @brief 设置可视化配置工具在线检测
|
||||
*/
|
||||
void device_online_timeout_check();
|
||||
/**
|
||||
* @brief 获取可视化配置工具在线状态
|
||||
*/
|
||||
CFG_TOOL_ONLINE_STATUS cfg_tool_online_status();
|
||||
|
||||
|
||||
struct tool_interface {
|
||||
u8 id;//通道
|
||||
void (*tool_message_deal)(u8 *buf, u32 len);//数据处理接口
|
||||
};
|
||||
|
||||
//注册通道及数据处理接口,支持uart/usb/spp的数据流分发
|
||||
#define REGISTER_DETECT_TARGET(interface) \
|
||||
static struct tool_interface interface sec(.tool_interface)
|
||||
|
||||
extern struct tool_interface tool_interface_begin[];
|
||||
extern struct tool_interface tool_interface_end[];
|
||||
|
||||
#define list_for_each_tool_interface(p) \
|
||||
for (p = tool_interface_begin; p < tool_interface_end; p++)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef _APP_CFG_TOOL_CDC_
|
||||
#define _APP_CFG_TOOL_CDC_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
/**
|
||||
* @brief 获取工具cdc最大支持的协议包大小
|
||||
*/
|
||||
u16 cfg_tool_cdc_rx_max_mtu();
|
||||
|
||||
/**
|
||||
* @brief 获取cdc的配置/调音工具相关数据
|
||||
*/
|
||||
void cfg_tool_data_from_cdc(u8 *buf, u32 rlen);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef _APP_CFG_TOOL_STATISTICS_
|
||||
#define _APP_CFG_TOOL_STATISTICS_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
/**
|
||||
* @brief 清理配置工具的统计资源
|
||||
*/
|
||||
void cfg_tool_statistics_resource_release();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,748 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".new_cfg_tool.data.bss")
|
||||
#pragma data_seg(".new_cfg_tool.data")
|
||||
#pragma const_seg(".new_cfg_tool.text.const")
|
||||
#pragma code_seg(".new_cfg_tool.text")
|
||||
#endif
|
||||
#include "cfg_tool.h"
|
||||
#include "boot.h"
|
||||
#include "ioctl_cmds.h"
|
||||
#include "app_online_cfg.h"
|
||||
#include "asm/crc16.h"
|
||||
#include "asm/cpu.h"
|
||||
#include "app_config.h"
|
||||
#include "online_db_deal.h"
|
||||
#include "init.h"
|
||||
#include "usb/device/cdc.h"
|
||||
#include "app_msg.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "bt_tws.h"
|
||||
#include "timer.h"
|
||||
#include "sniff.h"
|
||||
|
||||
#if CFG_TOOL_VER == CFG_TOOL_VER_VISUAL
|
||||
#include "system/malloc.h"
|
||||
#include "system/task.h"
|
||||
#include "cfg_tool_statistics.h"
|
||||
#include "cfg_tool_cdc.h"
|
||||
#endif
|
||||
|
||||
#define LOG_TAG_CONST APP_CFG_TOOL
|
||||
#define LOG_TAG "[APP_CFG_TOOL]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#if TCFG_CFG_TOOL_ENABLE
|
||||
|
||||
#if (TCFG_COMM_TYPE == TCFG_UART_COMM) && (TCFG_ONLINE_TX_PORT == IO_PORT_DP || TCFG_ONLINE_RX_PORT == IO_PORT_DM) && \
|
||||
(TCFG_USB_HOST_ENABLE || TCFG_PC_ENABLE)
|
||||
#error "online config tool select DP/DM but usb module is enable"
|
||||
#endif
|
||||
|
||||
struct cfg_tool_info {
|
||||
R_QUERY_BASIC_INFO r_basic_info;
|
||||
R_QUERY_FILE_SIZE r_file_size;
|
||||
R_QUERY_FILE_CONTENT r_file_content;
|
||||
R_PREPARE_WRITE_FILE r_prepare_write_file;
|
||||
R_READ_ADDR_RANGE r_read_addr_range;
|
||||
R_ERASE_ADDR_RANGE r_erase_addr_range;
|
||||
R_WRITE_ADDR_RANGE r_write_addr_range;
|
||||
R_ENTER_UPGRADE_MODE r_enter_upgrade_mode;
|
||||
|
||||
S_QUERY_BASIC_INFO s_basic_info;
|
||||
S_QUERY_FILE_SIZE s_file_size;
|
||||
S_PREPARE_WRITE_FILE s_prepare_write_file;
|
||||
};
|
||||
|
||||
static struct cfg_tool_info info = {
|
||||
.s_basic_info.protocolVer = PROTOCOL_VER_AT_OLD,
|
||||
};
|
||||
|
||||
#define __this (&info)
|
||||
#if (TCFG_USER_TWS_ENABLE || (TCFG_COMM_TYPE == TCFG_USB_COMM) || (TCFG_COMM_TYPE == TCFG_UART_COMM))
|
||||
static u8 *local_packet = NULL;
|
||||
u8 *local_packet_malloc(u16 size)
|
||||
{
|
||||
if ((local_packet == NULL) && (size > 0)) {
|
||||
local_packet = (u8 *)malloc(size);
|
||||
if (local_packet == NULL) {
|
||||
ASSERT(0, "local_packet malloc err!");
|
||||
}
|
||||
} else {
|
||||
ASSERT(0, "local_packet already allocated!");
|
||||
}
|
||||
return local_packet;
|
||||
}
|
||||
void local_packet_free()
|
||||
{
|
||||
if (local_packet != NULL) {
|
||||
free(local_packet);
|
||||
local_packet = NULL;
|
||||
}
|
||||
/* mem_stats(); */
|
||||
}
|
||||
#endif
|
||||
|
||||
extern const char *sdk_version_info_get(void);
|
||||
extern u8 *sdfile_get_burn_code(u8 *len);
|
||||
extern int sfc_norflash_erase(u32 cmd, u32 addr);
|
||||
extern void doe(u16 k, void *pBuf, u32 lenIn, u32 addr);
|
||||
extern void go_mask_usb_updata();
|
||||
static void tws_sync_cfg_tool_data(struct cfg_tool_event *cfg_tool_dev);
|
||||
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
const char fa_return[] = "ER"; //失败
|
||||
#else
|
||||
const char fa_return[] = "FA"; //失败
|
||||
#endif
|
||||
const char ok_return[] = "OK"; //成功
|
||||
const char er_return[] = "ER"; //不能识别的命令
|
||||
static u32 size_total_write = 0;
|
||||
static u8 parse_seq = 0;
|
||||
struct cfg_tool_event cfg_packet;
|
||||
#define TWS_FUNC_ID_CFGTOOL_SYNC TWS_FUNC_ID('C', 'F', 'G', 'S')
|
||||
|
||||
#ifdef ALIGN
|
||||
#undef ALIGN
|
||||
#endif
|
||||
#define ALIGN(a, b) \
|
||||
({ \
|
||||
int m = (u32)(a) & ((b)-1); \
|
||||
int ret = (u32)(a) + (m?((b)-m):0); \
|
||||
ret;\
|
||||
})
|
||||
|
||||
static u32 encode_data_by_user_key(u16 key, u8 *buff, u16 size, u32 dec_addr, u8 dec_len)
|
||||
{
|
||||
u16 key_addr;
|
||||
u16 r_len;
|
||||
|
||||
while (size) {
|
||||
r_len = (size > dec_len) ? dec_len : size;
|
||||
key_addr = (dec_addr >> 2)^key;
|
||||
doe(key_addr, buff, r_len, 0);
|
||||
buff += r_len;
|
||||
dec_addr += r_len;
|
||||
size -= r_len;
|
||||
}
|
||||
return dec_addr;
|
||||
}
|
||||
|
||||
void hex2text(u8 *buf, u8 *out)
|
||||
{
|
||||
//sprintf(out, "%02x%02x-%02x%02x%02x%02x", buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]);
|
||||
}
|
||||
|
||||
u32 packet_combined(u8 *packet, u8 num)
|
||||
{
|
||||
u32 _packet = 0;
|
||||
_packet = (packet[num] | (packet[num + 1] << 8) | (packet[num + 2] << 16) | (packet[num + 3] << 24));
|
||||
return _packet;
|
||||
}
|
||||
|
||||
/*延时复位防止工具升级进度条显示错误*/
|
||||
static void delay_cpu_reset(void *priv)
|
||||
{
|
||||
cpu_reset();
|
||||
}
|
||||
|
||||
RESFILE *cfg_open_file(u32 file_id)
|
||||
{
|
||||
RESFILE *cfg_fp = NULL;
|
||||
if (file_id == CFG_TOOL_FILEID) {
|
||||
cfg_fp = resfile_open(CFG_TOOL_FILE);
|
||||
#if (CFG_TOOL_VER != CFG_TOOL_VER_VISUAL)
|
||||
} else if (file_id == CFG_OLD_EQ_FILEID) {
|
||||
cfg_fp = resfile_open(CFG_OLD_EQ_FILE);
|
||||
} else if (file_id == CFG_OLD_EFFECT_FILEID) {
|
||||
cfg_fp = resfile_open(CFG_OLD_EFFECT_FILE);
|
||||
} else if (file_id == CFG_EQ_FILEID) {
|
||||
cfg_fp = resfile_open(CFG_EQ_FILE);
|
||||
#else
|
||||
} else if (file_id == CFG_STREAM_FILEID) {
|
||||
cfg_fp = resfile_open(CFG_STREAM_FILE);
|
||||
} else if (file_id == CFG_EFFECT_CFG_FILEID) {
|
||||
cfg_fp = resfile_open(CFG_EFFECT_CFG_FILE);
|
||||
#endif
|
||||
}
|
||||
return cfg_fp;
|
||||
}
|
||||
|
||||
void all_assemble_package_send_to_pc(u8 id, u8 sq, u8 *buf, u32 len)
|
||||
{
|
||||
u8 *send_buf = NULL;
|
||||
u16 crc16_data;
|
||||
send_buf = (u8 *)dma_malloc(len + 9); // 串口发数据需要使用dma_malloc
|
||||
if (send_buf == NULL) {
|
||||
log_error("send_buf malloc err!");
|
||||
return;
|
||||
}
|
||||
|
||||
send_buf[0] = 0x5A;
|
||||
send_buf[1] = 0xAA;
|
||||
send_buf[2] = 0xA5;
|
||||
CFG_TOOL_WRITE_LIT_U16(send_buf + 5, (2 + len)); /*L*/
|
||||
send_buf[7] = id;/*T*/
|
||||
send_buf[8] = sq;/*SQ*/
|
||||
memcpy(send_buf + 9, buf, len);
|
||||
crc16_data = CRC16(&send_buf[5], len + 4);
|
||||
send_buf[3] = crc16_data & 0xff;
|
||||
send_buf[4] = (crc16_data >> 8) & 0xff;
|
||||
|
||||
/* printf("cfg_tool tx:\n"); */
|
||||
/* printf_buf(send_buf, len + 9); */
|
||||
|
||||
#if (TCFG_COMM_TYPE == TCFG_UART_COMM)
|
||||
ci_uart_write(send_buf, len + 9);
|
||||
#elif (TCFG_COMM_TYPE == TCFG_USB_COMM)
|
||||
cdc_write_data(0, send_buf, len + 9);
|
||||
#elif (TCFG_COMM_TYPE == TCFG_SPP_COMM)
|
||||
#if SPP_DATA_USED_LVT
|
||||
app_online_db_ack(parse_seq, buf, len);
|
||||
#else
|
||||
app_online_db_ack(0xff, send_buf, len + 9);
|
||||
#endif
|
||||
#endif
|
||||
dma_free(send_buf);
|
||||
}
|
||||
|
||||
void app_cfg_tool_event_handler(struct cfg_tool_event *cfg_tool_dev)
|
||||
{
|
||||
u8 *buf = NULL;
|
||||
buf = (u8 *)malloc(cfg_tool_dev->size);
|
||||
if (buf == NULL) {
|
||||
ASSERT(0, "buf malloc err!");
|
||||
return;
|
||||
}
|
||||
|
||||
buf = (u8 *)ALIGN(buf, 4);
|
||||
memset(buf, 0, cfg_tool_dev->size);
|
||||
/* printf_buf(cfg_tool_dev->packet, cfg_tool_dev->size); */
|
||||
memcpy(buf, cfg_tool_dev->packet, cfg_tool_dev->size);
|
||||
|
||||
const struct tool_interface *p;
|
||||
list_for_each_tool_interface(p) {
|
||||
if (p->id == cfg_tool_dev->packet[2]) {
|
||||
p->tool_message_deal(buf + 2, cfg_tool_dev->size - 2);
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
u8 online_cfg_tool_data_deal(void *buf, u32 len)
|
||||
{
|
||||
u8 *data_buf = (u8 *)buf;
|
||||
u16 crc16_data;
|
||||
|
||||
/* printf("cfg_tool rx:\n"); */
|
||||
/* printf_buf(buf, len); */
|
||||
if ((data_buf[0] != 0x5a) || (data_buf[1] != 0xaa) || (data_buf[2] != 0xa5)) {
|
||||
/* log_error("Header check error, receive an invalid message!\n"); */
|
||||
return 1;
|
||||
}
|
||||
crc16_data = (data_buf[4] << 8) | data_buf[3];
|
||||
if (crc16_data != CRC16(data_buf + 5, len - 5)) {
|
||||
log_error("CRC16 check error, receive an invalid message!\n");
|
||||
return 1;
|
||||
}
|
||||
device_online_timeout_check();
|
||||
|
||||
u32 cmd = packet_combined(data_buf, 9);
|
||||
|
||||
cfg_packet.event = cmd;
|
||||
cfg_packet.size = CFG_TOOL_READ_LIT_U16(data_buf + 5) + 2;
|
||||
#if ((TCFG_COMM_TYPE == TCFG_UART_COMM) || (TCFG_COMM_TYPE == TCFG_SPP_COMM))
|
||||
cfg_packet.packet = &data_buf[5];
|
||||
#if (TCFG_USER_TWS_ENABLE && (TCFG_COMM_TYPE == TCFG_UART_COMM))
|
||||
tws_sync_cfg_tool_data(&cfg_packet);
|
||||
#endif
|
||||
app_cfg_tool_event_handler(&cfg_packet);
|
||||
#elif (TCFG_COMM_TYPE == TCFG_USB_COMM)//in irq
|
||||
if (local_packet != NULL) {
|
||||
local_packet_free();
|
||||
}
|
||||
local_packet = local_packet_malloc(cfg_packet.size);
|
||||
if (local_packet == NULL) {
|
||||
return 1;
|
||||
}
|
||||
cfg_packet.packet = local_packet;
|
||||
memcpy(cfg_packet.packet, &data_buf[5], cfg_packet.size);
|
||||
if (OS_NO_ERR != os_taskq_post_type("app_core", MSG_FROM_CDC, 0, NULL)) {
|
||||
local_packet_free();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (TCFG_COMM_TYPE == TCFG_SPP_COMM && SPP_DATA_USED_LVT)
|
||||
int cfg_tool_spp_rx_data(u8 *packet, u8 size, u8 *ext_data, u16 ext_size)
|
||||
{
|
||||
u8 *rx_buf = NULL;
|
||||
rx_buf = (u8 *)malloc(size + ext_size + 1);
|
||||
if (rx_buf == NULL) {
|
||||
log_error("rx_buf malloc err!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rx_buf[0] = size + 1;
|
||||
memcpy(rx_buf + 1, ext_data, ext_size);
|
||||
memcpy(rx_buf + 1 + ext_size, packet, size);
|
||||
|
||||
parse_seq = rx_buf[2];
|
||||
u32 event = (rx_buf[3] | (rx_buf[4] << 8) | (rx_buf[5] << 16) | (rx_buf[6] << 24));
|
||||
cfg_packet.event = event;
|
||||
cfg_packet.packet = rx_buf;
|
||||
cfg_packet.size = size + ext_size + 1;
|
||||
app_cfg_tool_event_handler(&cfg_packet);
|
||||
free(rx_buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cfg_tool_spp_init(void)
|
||||
{
|
||||
app_online_db_register_handle(SPP_NEW_EQ_CH, cfg_tool_spp_rx_data);
|
||||
app_online_db_register_handle(SPP_OLD_EQ_CH, cfg_tool_spp_rx_data);
|
||||
app_online_db_register_handle(SPP_CFG_CH, cfg_tool_spp_rx_data);
|
||||
return 0;
|
||||
}
|
||||
early_initcall(cfg_tool_spp_init);
|
||||
#endif //#if (TCFG_COMM_TYPE == TCFG_SPP_COMM && SPP_DATA_USED_LVT)
|
||||
|
||||
#if (TCFG_COMM_TYPE == TCFG_USB_COMM)
|
||||
static int cfg_tool_cdc_rx_data(int *msg)
|
||||
{
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
tws_sync_cfg_tool_data(&cfg_packet);
|
||||
#endif
|
||||
app_cfg_tool_event_handler(&cfg_packet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(cdc_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_CDC,
|
||||
.handler = cfg_tool_cdc_rx_data,
|
||||
};
|
||||
#endif//#if (TCFG_COMM_TYPE == TCFG_USB_COMM)
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
static void tws_sync_cfg_tool_data(struct cfg_tool_event *cfg_tool_dev)
|
||||
{
|
||||
if (cfg_tool_dev != NULL) {
|
||||
tws_api_send_data_to_sibling(cfg_tool_dev->packet, cfg_tool_dev->size, TWS_FUNC_ID_CFGTOOL_SYNC);
|
||||
}
|
||||
}
|
||||
|
||||
static void online_cfg_tool_tws_sibling_data_deal(void *_data, u16 len, bool rx)
|
||||
{
|
||||
if (rx) {
|
||||
cfg_packet.event = DEFAULT_ACTION;
|
||||
cfg_packet.size = len;
|
||||
if (local_packet != NULL) {
|
||||
local_packet_free();
|
||||
}
|
||||
local_packet = local_packet_malloc(cfg_packet.size);
|
||||
if (local_packet == NULL) {
|
||||
return;
|
||||
}
|
||||
cfg_packet.packet = local_packet;
|
||||
memcpy(cfg_packet.packet, (u8 *)_data, cfg_packet.size);
|
||||
if (OS_NO_ERR != os_taskq_post_type("app_core", MSG_FROM_CFGTOOL_TWS_SYNC, 0, NULL)) {
|
||||
local_packet_free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int cfg_tool_tws_sync_rx_data(int *msg)
|
||||
{
|
||||
app_cfg_tool_event_handler(&cfg_packet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGISTER_TWS_FUNC_STUB(cfg_tool_stub) = {
|
||||
.func_id = TWS_FUNC_ID_CFGTOOL_SYNC,
|
||||
.func = online_cfg_tool_tws_sibling_data_deal,
|
||||
};
|
||||
|
||||
APP_MSG_HANDLER(tws_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_CFGTOOL_TWS_SYNC,
|
||||
.handler = cfg_tool_tws_sync_rx_data,
|
||||
};
|
||||
#endif//#if TCFG_USER_TWS_ENABLE
|
||||
|
||||
#if CFG_TOOL_VER == CFG_TOOL_VER_VISUAL
|
||||
// 在线检测设备
|
||||
static u32 _device_online_timeout = 0;
|
||||
static u16 _timer_id = 0;
|
||||
static CFG_TOOL_ONLINE_STATUS _cfg_tool_online_status = CFG_TOOL_ONLINE_STATUS_OFFLINE;
|
||||
static void device_online_timeout_task(void *priv)
|
||||
{
|
||||
_device_online_timeout++;
|
||||
if (_device_online_timeout >= 3) {
|
||||
if (_timer_id) {
|
||||
sys_timer_del(_timer_id);
|
||||
_timer_id = 0;
|
||||
#if (TCFG_COMM_TYPE == TCFG_SPP_COMM)
|
||||
bt_sniff_enable();
|
||||
#endif
|
||||
}
|
||||
_cfg_tool_online_status = CFG_TOOL_ONLINE_STATUS_OFFLINE;
|
||||
// 清理任务统计的资源
|
||||
cfg_tool_statistics_resource_release();
|
||||
/* log_info("cfg tool is offline!\n"); */
|
||||
}
|
||||
}
|
||||
|
||||
void device_online_timeout_check()
|
||||
{
|
||||
_device_online_timeout = 0;
|
||||
_cfg_tool_online_status = CFG_TOOL_ONLINE_STATUS_ONLINE;
|
||||
#if (TCFG_COMM_TYPE == TCFG_SPP_COMM)
|
||||
bt_sniff_disable();
|
||||
#endif
|
||||
if (!_timer_id) {
|
||||
/* log_info("cfg tool online sys timer add!\n"); */
|
||||
_timer_id = sys_timer_add(NULL, device_online_timeout_task, 1000);
|
||||
}
|
||||
}
|
||||
CFG_TOOL_ONLINE_STATUS cfg_tool_online_status()
|
||||
{
|
||||
return _cfg_tool_online_status;
|
||||
}
|
||||
#else
|
||||
CFG_TOOL_ONLINE_STATUS cfg_tool_online_status()
|
||||
{
|
||||
return CFG_TOOL_ONLINE_STATUS_ONLINE;
|
||||
}
|
||||
#endif
|
||||
|
||||
// 发送buf malloc
|
||||
u8 *send_buf_malloc(u32 send_buf_size)
|
||||
{
|
||||
u8 *buf = (u8 *)malloc(send_buf_size);
|
||||
if (buf == NULL) {
|
||||
ASSERT(0, "send buf malloc err!");
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void cfg_tool_callback(u8 *packet, u32 size)
|
||||
{
|
||||
u32 erase_cmd = 0;
|
||||
u32 write_len = 0;
|
||||
u32 send_len = 0;
|
||||
u8 crc_temp_len, sdkname_temp_len;
|
||||
u8 *buf = NULL;
|
||||
u8 *buf_temp = NULL;
|
||||
struct resfile_attrs attr;
|
||||
RESFILE *cfg_fp = NULL;
|
||||
|
||||
switch (cfg_packet.event) {
|
||||
case ONLINE_SUB_OP_QUERY_BASIC_INFO:
|
||||
memset(&__this->s_basic_info, 0, sizeof(__this->s_basic_info));
|
||||
u8 *p = sdfile_get_burn_code(&crc_temp_len);
|
||||
if (p != NULL) {
|
||||
memcpy(__this->s_basic_info.progCrc, p + 8, 6);
|
||||
hex2text(__this->s_basic_info.progCrc, __this->s_basic_info.progCrc);
|
||||
sdkname_temp_len = strlen(sdk_version_info_get());
|
||||
memcpy(__this->s_basic_info.sdkName, sdk_version_info_get(), sdkname_temp_len);
|
||||
|
||||
struct flash_head flash_head_for_pid_vid;
|
||||
for (u8 i = 0; i < 5; i++) {
|
||||
tzflash_read((u8 *)&flash_head_for_pid_vid, 32, 0x1000 * i);
|
||||
doe(0xffff, (u8 *)&flash_head_for_pid_vid, 32, 0);
|
||||
if (flash_head_for_pid_vid.crc == 0xffff) {
|
||||
continue;
|
||||
} else {
|
||||
log_info("flash head addr = 0x%x\n", 0x1000 * i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flash_head_for_pid_vid.crc == 0xffff) {
|
||||
log_error("Can't find flash head addr");
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(__this->s_basic_info.pid, &(flash_head_for_pid_vid.pid), sizeof(flash_head_for_pid_vid.pid));
|
||||
memcpy(__this->s_basic_info.vid, &(flash_head_for_pid_vid.vid), sizeof(flash_head_for_pid_vid.vid));
|
||||
for (u8 i = 0; i < sizeof(__this->s_basic_info.pid); i++) {
|
||||
if (__this->s_basic_info.pid[i] == 0xff) {
|
||||
__this->s_basic_info.pid[i] = 0x00;
|
||||
}
|
||||
}
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
#if TCFG_COMM_TYPE == TCFG_USB_COMM
|
||||
__this->s_basic_info.max_buffer_size = cfg_tool_cdc_rx_max_mtu();
|
||||
#elif TCFG_COMM_TYPE == TCFG_UART_COMM
|
||||
extern u16 get_ci_rx_size();
|
||||
__this->s_basic_info.max_buffer_size = get_ci_rx_size();
|
||||
#else
|
||||
extern u16 l2cap_max_mtu(void);
|
||||
__this->s_basic_info.max_buffer_size = 256;//l2cap_max_mtu();
|
||||
#endif
|
||||
printf("cfg_tool max_buffer_size:%d\n", __this->s_basic_info.max_buffer_size);
|
||||
#endif
|
||||
send_len = sizeof(__this->s_basic_info);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, &(__this->s_basic_info), send_len);
|
||||
}
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_CPU_RESET:
|
||||
send_len = 2;
|
||||
u8 cpu_reset_ret[] = "OK";
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, cpu_reset_ret, send_len);
|
||||
sys_timeout_add(NULL, delay_cpu_reset, 500);
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_QUERY_FILE_SIZE:
|
||||
__this->r_file_size.file_id = packet_combined(cfg_packet.packet, 8);
|
||||
cfg_fp = cfg_open_file(__this->r_file_size.file_id);
|
||||
if (cfg_fp == NULL) {
|
||||
log_error("file open error!\n");
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
resfile_get_attrs(cfg_fp, &attr);
|
||||
__this->s_file_size.file_size = attr.fsize;
|
||||
send_len = sizeof(__this->s_file_size.file_size);//长度
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, &(__this->s_file_size.file_size), send_len);
|
||||
resfile_close(cfg_fp);
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_QUERY_FILE_CONTENT:
|
||||
__this->r_file_content.file_id = packet_combined(cfg_packet.packet, 8);
|
||||
__this->r_file_content.offset = packet_combined(cfg_packet.packet, 12);
|
||||
__this->r_file_content.size = packet_combined(cfg_packet.packet, 16);
|
||||
|
||||
cfg_fp = cfg_open_file(__this->r_file_content.file_id);
|
||||
if (cfg_fp == NULL) {
|
||||
log_error("file open error!\n");
|
||||
goto _exit_;
|
||||
}
|
||||
resfile_get_attrs(cfg_fp, &attr);
|
||||
if (__this->r_file_content.size > attr.fsize) {
|
||||
resfile_close(cfg_fp);
|
||||
log_error("reading size more than actual size!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
u32 flash_addr = sdfile_cpu_addr2flash_addr(attr.sclust);
|
||||
buf_temp = (u8 *)malloc(__this->r_file_content.size);
|
||||
if (buf_temp == NULL) {
|
||||
log_error("buf_temp malloc err!");
|
||||
goto _exit_;
|
||||
}
|
||||
tzflash_read((void *)buf_temp, __this->r_file_content.size, flash_addr + __this->r_file_content.offset);
|
||||
send_len = __this->r_file_content.size;
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, buf_temp, __this->r_file_content.size);
|
||||
free(buf_temp);
|
||||
resfile_close(cfg_fp);
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_PREPARE_WRITE_FILE:
|
||||
__this->r_prepare_write_file.file_id = packet_combined(cfg_packet.packet, 8);
|
||||
__this->r_prepare_write_file.size = packet_combined(cfg_packet.packet, 12);
|
||||
|
||||
cfg_fp = cfg_open_file(__this->r_prepare_write_file.file_id);
|
||||
if (cfg_fp == NULL) {
|
||||
log_error("file open error!\n");
|
||||
break;
|
||||
}
|
||||
resfile_get_attrs(cfg_fp, &attr);
|
||||
|
||||
__this->s_prepare_write_file.file_size = attr.fsize;
|
||||
__this->s_prepare_write_file.file_addr = sdfile_cpu_addr2flash_addr(attr.sclust);
|
||||
__this->s_prepare_write_file.earse_unit = boot_info.vm.align * 256;
|
||||
send_len = sizeof(__this->s_prepare_write_file);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, &(__this->s_prepare_write_file), send_len);
|
||||
resfile_close(cfg_fp);
|
||||
|
||||
if (__this->r_prepare_write_file.file_id == CFG_STREAM_FILEID) {
|
||||
app_send_message(APP_MSG_WRITE_RESFILE_START, (int)"stream.bin");
|
||||
}
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_READ_ADDR_RANGE:
|
||||
__this->r_read_addr_range.addr = packet_combined(cfg_packet.packet, 8);
|
||||
__this->r_read_addr_range.size = packet_combined(cfg_packet.packet, 12);
|
||||
buf_temp = (u8 *)malloc(__this->r_read_addr_range.size);
|
||||
if (buf_temp == NULL) {
|
||||
log_error("buf_temp malloc err!");
|
||||
goto _exit_;
|
||||
}
|
||||
tzflash_read((void *)buf_temp, __this->r_read_addr_range.size, __this->r_read_addr_range.addr);
|
||||
send_len = __this->r_read_addr_range.size;
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, buf_temp, __this->r_read_addr_range.size);
|
||||
free(buf_temp);
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_ERASE_ADDR_RANGE:
|
||||
__this->r_erase_addr_range.addr = packet_combined(cfg_packet.packet, 8);
|
||||
__this->r_erase_addr_range.size = packet_combined(cfg_packet.packet, 12);
|
||||
|
||||
switch (__this->s_prepare_write_file.earse_unit) {
|
||||
case 256:
|
||||
erase_cmd = IOCTL_ERASE_PAGE;
|
||||
break;
|
||||
case (4*1024):
|
||||
erase_cmd = IOCTL_ERASE_SECTOR;
|
||||
break;
|
||||
case (64*1024):
|
||||
erase_cmd = IOCTL_ERASE_BLOCK;
|
||||
break;
|
||||
default:
|
||||
send_len = sizeof(fa_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, fa_return, send_len);
|
||||
log_error("erase error!");
|
||||
break;
|
||||
}
|
||||
|
||||
for (u8 i = 0; i < (__this->r_erase_addr_range.size / __this->s_prepare_write_file.earse_unit); i ++) {
|
||||
/* u8 ret = sfc_norflash_erase(erase_cmd, __this->r_erase_addr_range.addr + (i * __this->s_prepare_write_file.earse_unit)); */
|
||||
int ret = tzflash_ioctl(erase_cmd, __this->r_erase_addr_range.addr + (i * __this->s_prepare_write_file.earse_unit));
|
||||
if (ret) {
|
||||
send_len = sizeof(fa_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, fa_return, send_len);
|
||||
log_error("erase error!");
|
||||
break;
|
||||
} else {
|
||||
send_len = sizeof(ok_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, ok_return, send_len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ONLINE_SUB_OP_WRITE_ADDR_RANGE:
|
||||
__this->r_write_addr_range.addr = packet_combined(cfg_packet.packet, 8);
|
||||
__this->r_write_addr_range.size = packet_combined(cfg_packet.packet, 12);
|
||||
buf_temp = (u8 *)malloc(__this->r_write_addr_range.size);
|
||||
if (buf_temp == NULL) {
|
||||
log_error("buf_temp malloc err!");
|
||||
goto _exit_;
|
||||
}
|
||||
memcpy(buf_temp, cfg_packet.packet + 16, __this->r_write_addr_range.size);
|
||||
encode_data_by_user_key(boot_info.chip_id, buf_temp, __this->r_write_addr_range.size, __this->r_write_addr_range.addr - boot_info.sfc.sfc_base_addr, 0x20);
|
||||
write_len = tzflash_write(buf_temp, __this->r_write_addr_range.size, __this->r_write_addr_range.addr);
|
||||
|
||||
if (write_len != __this->r_write_addr_range.size) {
|
||||
send_len = sizeof(fa_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, fa_return, send_len);
|
||||
log_error("write error!");
|
||||
} else {
|
||||
send_len = sizeof(ok_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, ok_return, send_len);
|
||||
}
|
||||
if (buf_temp) {
|
||||
free(buf_temp);
|
||||
}
|
||||
|
||||
#if (CFG_TOOL_VER != CFG_TOOL_VER_VISUAL)
|
||||
if (__this->r_prepare_write_file.file_id == CFG_TOOL_FILEID) {
|
||||
size_total_write += __this->r_write_addr_range.size;
|
||||
if (size_total_write >= __this->r_erase_addr_range.size) {
|
||||
size_total_write = 0;
|
||||
log_info("cpu_reset\n");
|
||||
sys_timeout_add(NULL, delay_cpu_reset, 500);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
int a = __this->r_write_addr_range.addr + __this->r_write_addr_range.size;
|
||||
int b = __this->s_prepare_write_file.file_addr + __this->s_prepare_write_file.file_size;
|
||||
if (__this->r_prepare_write_file.file_id == CFG_STREAM_FILEID) {
|
||||
if (a >= b) {
|
||||
app_send_message(APP_MSG_WRITE_RESFILE_STOP, (int)"stream.bin");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
#if TCFG_COMM_TYPE == TCFG_USB_COMM
|
||||
case ONLINE_SUB_OP_ENTER_UPGRADE_MODE:
|
||||
log_info("event_ONLINE_SUB_OP_ENTER_UPGRADE_MODE\n");
|
||||
go_mask_usb_updata();
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ONLINE_SUB_OP_ONLINE_INSPECTION:
|
||||
R_QUERY_SYS_INFO upload_param = {0};
|
||||
upload_param.use_mem = memory_get_size(P_MEMORY_USED);//使用的mem;
|
||||
upload_param.total_mem = memory_get_size(P_MEMORY_TOTAL);//总的mem
|
||||
int cpu_use[2] = {0};
|
||||
os_cpu_usage(NULL, cpu_use);
|
||||
int cpu_usage = (cpu_use[0] + cpu_use[1]) / CPU_CORE_NUM;
|
||||
upload_param.cpu_use_ratio = cpu_usage;
|
||||
upload_param.task_num = get_task_info_list_num();
|
||||
send_len = sizeof(upload_param);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, &upload_param, send_len);
|
||||
break;
|
||||
|
||||
default: // DEFAULT_ACTION
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
if (buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
return;
|
||||
#else
|
||||
log_error("invalid data\n");
|
||||
send_len = sizeof(er_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, er_return, sizeof(er_return));//不认识的命令返回ER
|
||||
#endif
|
||||
break;
|
||||
_exit_:
|
||||
send_len = sizeof(fa_return);
|
||||
buf = send_buf_malloc(send_len);
|
||||
memcpy(buf, fa_return, sizeof(fa_return));//文件打开失败返回FA
|
||||
break;
|
||||
}
|
||||
|
||||
all_assemble_package_send_to_pc(REPLY_STYLE, cfg_packet.packet[3], buf, send_len);
|
||||
if (buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if (CFG_TOOL_VER == CFG_TOOL_VER_VISUAL)
|
||||
REGISTER_DETECT_TARGET(cfg_tool_target) = {
|
||||
.id = VISUAL_CFG_TOOL_CHANNEL_STYLE,
|
||||
.tool_message_deal = cfg_tool_callback,
|
||||
};
|
||||
#else
|
||||
REGISTER_DETECT_TARGET(cfg_tool_target) = {
|
||||
.id = INITIATIVE_STYLE,
|
||||
.tool_message_deal = cfg_tool_callback,
|
||||
};
|
||||
#endif
|
||||
|
||||
//在线调试不进power down
|
||||
static u8 cfg_tool_idle_query(void)
|
||||
{
|
||||
return !cfg_tool_online_status();
|
||||
}
|
||||
|
||||
REGISTER_LP_TARGET(cfg_tool_lp_target) = {
|
||||
.name = "new_cfg_tool",
|
||||
.is_idle = cfg_tool_idle_query,
|
||||
};
|
||||
|
||||
#endif // TCFG_CFG_TOOL_ENABLE
|
||||
|
||||
Reference in New Issue
Block a user