first
This commit is contained in:
121
apps/common/config/app_config.c
Normal file
121
apps/common/config/app_config.c
Normal file
@ -0,0 +1,121 @@
|
||||
#include "system/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "config/config_interface.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,
|
||||
115200,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
};
|
||||
|
||||
#if (TCFG_ONLINE_ENABLE || TCFG_CFG_TOOL_ENABLE)
|
||||
#if TCFG_COMM_TYPE == TCFG_UART_COMM
|
||||
void config_online_init()
|
||||
{
|
||||
log_info("-------online Config Start-------");
|
||||
config_layer_init(ci_transport_uart_instance(), &config);
|
||||
}
|
||||
__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");
|
||||
}
|
||||
|
||||
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);
|
||||
FILE *fp = NULL;
|
||||
u8 buf[16];
|
||||
u8 len;
|
||||
|
||||
fp = fopen(name, "r");
|
||||
if (!fp) {
|
||||
log_d("sdfile open file ERR!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = fread(fp, buf, sizeof(buf));
|
||||
|
||||
if (len != sizeof(buf)) {
|
||||
log_d("0-read file ERR!");
|
||||
goto _end;
|
||||
}
|
||||
|
||||
put_buf(buf, sizeof(buf));
|
||||
|
||||
fseek(fp, 16, SEEK_SET);
|
||||
|
||||
len = fread(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) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
216
apps/common/config/bt_profile_config.c
Normal file
216
apps/common/config/bt_profile_config.c
Normal file
@ -0,0 +1,216 @@
|
||||
#include "system/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "btcontroller_config.h"
|
||||
#include "btstack/bt_profile_config.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_DEMO_SELECT == DEF_BLE_DEMO_ADV)
|
||||
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
|
||||
|
||||
#else
|
||||
const int config_stack_modules = BT_BTSTACK_CLASSIC;
|
||||
#endif
|
||||
|
||||
#if (USER_SUPPORT_PROFILE_PNP==1)
|
||||
SDP_RECORD_HANDLER_REGISTER(pnp_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_pnp_service_data,
|
||||
.service_record_handle = 0x1000A,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if (USER_SUPPORT_PROFILE_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 (USER_SUPPORT_PROFILE_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 BT_SUPPORT_MUSIC_VOL_SYNC
|
||||
SDP_RECORD_HANDLER_REGISTER(arp_ta_sdp_record_item) = {
|
||||
.service_record = (u8 *)sdp_avctp_ta_service_data,
|
||||
.service_record_handle = 0x00010005,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
#if (USER_SUPPORT_PROFILE_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 (USER_SUPPORT_PROFILE_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 (USER_SUPPORT_PROFILE_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 (USER_SUPPORT_PROFILE_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 = 0x00010008,
|
||||
};
|
||||
#endif
|
||||
#if (USER_SUPPORT_PROFILE_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
|
||||
|
||||
/*注意hid_conn_depend_on_dev_company置1之后,安卓手机会默认断开HID连接 */
|
||||
/*注意hid_conn_depend_on_dev_company置2之后,默认不断开HID连接 */
|
||||
const u8 hid_conn_depend_on_dev_company = 1;
|
||||
const u8 sdp_get_remote_pnp_info = 0;
|
||||
|
||||
#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 (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_ADV)
|
||||
const u8 pbg_support_enable = 1;
|
||||
const u8 adt_profile_support = 1;
|
||||
#else
|
||||
const u8 pbg_support_enable = 0;
|
||||
const u8 adt_profile_support = 0;
|
||||
#endif
|
||||
|
||||
const u8 more_hfp_cmd_support = 1;
|
||||
|
||||
#endif
|
||||
|
||||
#if (TCFG_BD_NUM == 2)
|
||||
const u8 a2dp_mutual_support = 1;
|
||||
const u8 more_addr_reconnect_support = 1;
|
||||
#if USER_SUPPORT_DUAL_A2DP_SOURCE
|
||||
const u8 more_avctp_cmd_support = 0;
|
||||
#else
|
||||
const u8 more_avctp_cmd_support = 1;
|
||||
#endif
|
||||
#else
|
||||
const u8 a2dp_mutual_support = 0;
|
||||
const u8 more_addr_reconnect_support = 0;
|
||||
#if ((RCSP_ADV_EN || SMART_BOX_EN) && JL_EARPHONE_APP_EN)
|
||||
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 USER_SUPPORT_PROFILE_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 (USER_SUPPORT_PROFILE_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 (USER_SUPPORT_PROFILE_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 = 0x00010008,
|
||||
};
|
||||
#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 a2dp_mutual_support = 1;
|
||||
const u8 adt_profile_support = 0;
|
||||
const u8 pbg_support_enable = 0;
|
||||
#endif
|
||||
370
apps/common/config/ci_transport_uart.c
Normal file
370
apps/common/config/ci_transport_uart.c
Normal file
@ -0,0 +1,370 @@
|
||||
#include "system/includes.h"
|
||||
#include "config/config_interface.h"
|
||||
#include "system/event.h"
|
||||
#include "app_online_cfg.h"
|
||||
#include "asm/uart_dev.h"
|
||||
#include "app_config.h"
|
||||
#include "asm/crc16.h"
|
||||
|
||||
#define LOG_TAG "[CI-UART]"
|
||||
/* #define LOG_ERROR_ENABLE */
|
||||
/* #define LOG_INFO_ENABLE */
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#include "debug.h"
|
||||
|
||||
#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;
|
||||
|
||||
uart_bus_t *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;
|
||||
u8 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 0x100
|
||||
#define UART_TX_SIZE 0x30
|
||||
#define UART_DB_SIZE 0x100
|
||||
#define UART_BAUD_RATE 115200
|
||||
|
||||
#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;
|
||||
}
|
||||
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) {
|
||||
__this->data_length += __this->udev->read(&__this->pRxBuffer[__this->data_length], (UART_RX_SIZE - __this->data_length), 0);//串口读取buf剩余空间的长度,实际长度比buf长,导致越界改写问题
|
||||
}
|
||||
|
||||
/* 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 + 6) {
|
||||
crc16 = crc_get_16bit(&p_newtool->length, p_newtool->length + 1);
|
||||
/* log_info("CRC16 0x%x / 0x%x", crc16, p_newtool->crc16); */
|
||||
if (p_newtool->crc16 != crc16) {
|
||||
log_error("crc16 err\n");
|
||||
goto reset_buf;
|
||||
}
|
||||
/* log_info_hexdump(p_newtool, p_newtool->length + 6); */
|
||||
online_cfg_tool_data_deal(p_newtool, p_newtool->length + 6);
|
||||
} 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(void *ut_bus, u32 status)
|
||||
{
|
||||
if (status == UT_TX) {
|
||||
return ;
|
||||
}
|
||||
struct sys_event e;
|
||||
e.type = SYS_DEVICE_EVENT;
|
||||
e.arg = (void *)DEVICE_EVENT_FROM_CI_UART;
|
||||
e.u.dev.event = 0;
|
||||
e.u.dev.value = 0;
|
||||
sys_event_notify(&e);
|
||||
}
|
||||
|
||||
static int ci_uart_init()
|
||||
{
|
||||
struct uart_platform_data_t ut = {0};
|
||||
ut.tx_pin = TCFG_ONLINE_TX_PORT;
|
||||
ut.rx_pin = TCFG_ONLINE_RX_PORT;
|
||||
ut.baud = __this->config.baudrate;
|
||||
ut.rx_timeout = 1;
|
||||
ut.isr_cbfun = ci_uart_isr_cb;
|
||||
ut.rx_cbuf = devBuffer_static;
|
||||
ut.rx_cbuf_size = UART_DB_SIZE;
|
||||
ut.frame_length = UART_DB_SIZE;
|
||||
/* JL_CLOCK->CLK_CON1 |= BIT(11); */
|
||||
/* JL_CLOCK->CLK_CON1 &= ~BIT(10); */
|
||||
__this->dbuf = devBuffer_static;
|
||||
__this->data_length = 0;
|
||||
__this->udev = (uart_bus_t *)uart_dev_open(&ut);
|
||||
if (__this->udev == NULL) {
|
||||
log_error("open uart dev err\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ci_uart_putbyte(char a)
|
||||
{
|
||||
if (__this->udev) {
|
||||
__this->udev->putbyte(a);
|
||||
}
|
||||
}
|
||||
|
||||
void ci_uart_write(char *buf, u16 len)
|
||||
{
|
||||
if (__this->udev) {
|
||||
__this->udev->write(buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
static void dummy_handler(const u8 *packet, int size)
|
||||
{
|
||||
log_error("Dummy");
|
||||
}
|
||||
|
||||
static void clock_critical_enter(void)
|
||||
{
|
||||
|
||||
}
|
||||
static void clock_critical_exit(void)
|
||||
{
|
||||
if (__this->udev) {
|
||||
__this->udev->set_baud(__this->config.baudrate);
|
||||
}
|
||||
}
|
||||
CLOCK_CRITICAL_HANDLE_REG(ci, clock_critical_enter, clock_critical_exit)
|
||||
|
||||
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 = malloc(UART_RX_SIZE);
|
||||
ASSERT(__this->pRxBuffer, "Fatal error");
|
||||
|
||||
__this->pTxBuffer = malloc(UART_TX_SIZE);
|
||||
ASSERT(__this->pTxBuffer, "Fatal error");
|
||||
#else
|
||||
log_info("Static");
|
||||
__this->pRxBuffer = pRxBuffer_static;
|
||||
__this->pTxBuffer = pTxBuffer_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 = CRC16(p, UART_FORMAT_HEAD - 3) & 0xff;
|
||||
p->crc16 = CRC16(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(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
|
||||
|
||||
125
apps/common/config/include/bt_profile_cfg.h
Normal file
125
apps/common/config/include/bt_profile_cfg.h
Normal file
@ -0,0 +1,125 @@
|
||||
|
||||
#ifndef _BT_PROFILE_CFG_H_
|
||||
#define _BT_PROFILE_CFG_H_
|
||||
|
||||
#include "app_config.h"
|
||||
#include "btcontroller_modules.h"
|
||||
|
||||
|
||||
#if (TRANS_DATA_EN || RCSP_BTMATE_EN || RCSP_ADV_EN || SMART_BOX_EN || ANCS_CLIENT_EN || LL_SYNC_EN || 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 || AI_APP_PROTOCOL)
|
||||
#if (LL_SYNC_EN || TUYA_DEMO_EN)
|
||||
#undef USER_SUPPORT_PROFILE_SPP
|
||||
#define USER_SUPPORT_PROFILE_SPP 0
|
||||
#else
|
||||
#undef USER_SUPPORT_PROFILE_SPP
|
||||
#define USER_SUPPORT_PROFILE_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
|
||||
#define DEF_BLE_DEMO_HOGP 24
|
||||
|
||||
#define LE_AUDIO_EN 0 //DEF_LE_AUDIO_CENTRAL
|
||||
|
||||
//配置选择的demo
|
||||
#if TCFG_USER_BLE_ENABLE
|
||||
|
||||
#if (SMART_BOX_EN | RCSP_BTMATE_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_RCSP_DEMO
|
||||
|
||||
#elif TRANS_DATA_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_TRANS_DATA
|
||||
|
||||
#elif LL_SYNC_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_LL_SYNC
|
||||
|
||||
#elif TUYA_DEMO_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_TUYA
|
||||
|
||||
#elif RCSP_ADV_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_ADV_RCSP
|
||||
|
||||
#elif BLE_CLIENT_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_CLIENT
|
||||
|
||||
#elif TRANS_MULTI_BLE_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_MULTI
|
||||
|
||||
#elif ANCS_CLIENT_EN
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_ANCS_ADV
|
||||
|
||||
#elif AI_APP_PROTOCOL
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_NULL
|
||||
|
||||
#elif (BLE_WIRELESS_CLIENT_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_WIRELESS_MIC_CLIENT
|
||||
|
||||
#elif (BLE_WIRELESS_SERVER_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_WIRELESS_MIC_SERVER
|
||||
|
||||
#elif (BLE_WIRELESS_1T1_TX_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_WL_MIC_1T1_TX
|
||||
|
||||
#elif (BLE_WIRELESS_1T1_RX_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_WL_MIC_1T1_RX
|
||||
|
||||
#elif (BLE_WIRELESS_1TN_TX_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_WL_MIC_1TN_TX
|
||||
|
||||
#elif (BLE_WIRELESS_1TN_RX_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_WL_MIC_1TN_RX
|
||||
|
||||
#elif (LE_AUDIO_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT LE_AUDIO_EN
|
||||
|
||||
#elif (BLE_HID_EN)
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_HOGP
|
||||
|
||||
#else
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE5_DEMO
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define TCFG_BLE_DEMO_SELECT DEF_BLE_DEMO_NULL//ble is closed
|
||||
#endif
|
||||
|
||||
//delete 2021-09-24;删除公共配置,放到各个profile自己配置
|
||||
// #define TCFG_BLE_SECURITY_EN 0 /*是否发请求加密命令*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
242
apps/common/config/include/cfg_tool.h
Normal file
242
apps/common/config/include/cfg_tool.h
Normal file
@ -0,0 +1,242 @@
|
||||
#ifndef _APP_SOUND_BOX_
|
||||
#define _APP_SOUND_BOX_
|
||||
|
||||
#include "typedef.h"
|
||||
#include "sdfile.h"
|
||||
#include "fs.h"
|
||||
#include "asm/sfc_norflash_api.h"
|
||||
#include "event.h"
|
||||
|
||||
/*
|
||||
* 波特率默认为 115200
|
||||
* 对于物理串口,且是异步形式的协议,封包方式如下
|
||||
*
|
||||
* CRC是 CRC16(L + T + SQ + DATA)
|
||||
* 其中,L是指(T+SQ+DATA)的长度
|
||||
* DATA包含CMD与具体的数据流
|
||||
*
|
||||
* +----+----+----+--+--+---+---+----+---....---+
|
||||
* | 5A | AA | A5 | CRC | L | T | SQ | DATA |
|
||||
* +----+----+----+--+--+---+---+----+---....---+
|
||||
*
|
||||
* T 表示包的类型,其中
|
||||
* 0x00 -- 表示回复,其中SQ是对应需要回应的包的序号
|
||||
* 无论哪种模式下,回复包都用该种类型
|
||||
* 0x12 -- 表示配置文件通道,是主动发送数据
|
||||
* 例如,在配置工具中,PC往小机或者小机往PC主动发都用这个
|
||||
*/
|
||||
|
||||
/*T 表示包的类型*/
|
||||
#define REPLY_STYLE 0x00 //无论哪种模式下,回复包都用该种类型
|
||||
#define INITIATIVE_STYLE 0x12 //主动发送数据的包用该类型
|
||||
#define SLAVE_ATIVE_SEND 0x01 //小机主动上发给PC
|
||||
#define EFF_CONFIG_ID 0x11 //调音
|
||||
/*
|
||||
*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 //使用新模式
|
||||
#define PROTOCOL_VER_AT_OLD 0x0011 //使用旧模式
|
||||
|
||||
|
||||
/*该文件所属文件ID为0*/
|
||||
#define CFG_TOOL_FILEID 0x00000000
|
||||
|
||||
/*该文件所属文件ID为0*/
|
||||
#if ((defined CONFIG_NEW_CFG_TOOL_ENABLE) && ((defined CONFIG_SOUNDBOX) \
|
||||
|| (defined CONFIG_EARPHONE_CASE_ENABLE)))
|
||||
#define CFG_TOOL_FILE SDFILE_RES_ROOT_PATH"cfg_tool.bin"
|
||||
#else
|
||||
#define CFG_TOOL_FILE SDFILE_APP_ROOT_PATH"cfg_tool.bin"
|
||||
#endif
|
||||
|
||||
/*旧调音工具eq文件所属文件ID为1*/
|
||||
#define CFG_OLD_EQ_FILEID 0x00000001
|
||||
#define CFG_OLD_EQ_FILE SDFILE_RES_ROOT_PATH"eq_cfg_hw.bin"
|
||||
|
||||
/*旧调音工具混响文件所属文件ID为2*/
|
||||
#define CFG_OLD_EFFECT_FILEID 0x00000002
|
||||
#define CFG_OLD_EFFECT_FILE SDFILE_RES_ROOT_PATH"effects_cfg.bin"
|
||||
|
||||
/*新调音工具eq文件所属文件ID为3*/
|
||||
#define CFG_EQ_FILEID 0x00000003
|
||||
#define CFG_EQ_FILE SDFILE_RES_ROOT_PATH"eq_cfg_hw.bin"
|
||||
|
||||
/*****************************************************************/
|
||||
/****PC与小机使用到的CMD,CMD包含在DATA中,为DATA的第一个Byte*****/
|
||||
/*****************************************************************/
|
||||
|
||||
#define ONLINE_SUB_OP_QUERY_BASIC_INFO 0x00000023 //查询固件的基本信息
|
||||
#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 DEFAULT_ACTION 0x000000FF //其他工具的数据
|
||||
|
||||
/*****************************************************************/
|
||||
/*****小机接收PC的DATA,具体携带的数据,依据命令不同而不同**********/
|
||||
/*****************************************************************/
|
||||
|
||||
//查询固件的基本信息
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x23
|
||||
} R_QUERY_BASIC_INFO;
|
||||
|
||||
//查询文件大小
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x0B
|
||||
uint32_t file_id; //查询的文件的ID,配置文件的ID为0
|
||||
} R_QUERY_FILE_SIZE;
|
||||
|
||||
//读取文件内容
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x0C
|
||||
uint32_t file_id; //文件ID
|
||||
uint32_t offset; //偏移
|
||||
uint32_t size;
|
||||
} R_QUERY_FILE_CONTENT;
|
||||
|
||||
//准备写入文件
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x22
|
||||
uint32_t file_id; //文件ID
|
||||
uint32_t size; //文件大小
|
||||
} R_PREPARE_WRITE_FILE;
|
||||
|
||||
//读取地址范围内容
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x23
|
||||
uint32_t addr; //flash的物理地址
|
||||
uint32_t size; //读取的范围大小
|
||||
} R_READ_ADDR_RANGE;
|
||||
|
||||
//擦除地址范围内容
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x24
|
||||
uint32_t addr; //起始地址
|
||||
uint32_t size; //擦除大小
|
||||
} R_ERASE_ADDR_RANGE;
|
||||
|
||||
//写入地址范围内容
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x25
|
||||
uint32_t addr; //物理地址
|
||||
uint32_t size; //内容大小
|
||||
/*uint8_t body[0];*/ //具体内容,大小为size
|
||||
} R_WRITE_ADDR_RANGE;
|
||||
|
||||
//进入升级模式
|
||||
typedef struct {
|
||||
uint32_t cmd_id; //命令号,为0x26
|
||||
} R_ENTER_UPGRADE_MODE;
|
||||
|
||||
/*****************************************************************/
|
||||
/*******小机返回PC发送的DATA,具体的内容,依据命令不同而不同********/
|
||||
/*****************************************************************/
|
||||
|
||||
//(1)查询固件的基本信息
|
||||
typedef struct {
|
||||
uint16_t protocolVer; //协议版本,目前为1
|
||||
char progCrc[32]; //固件的CRC,返回字符串,\0 结尾
|
||||
char sdkName[32]; //SDK名字,\0 结尾
|
||||
char pid[16]; //PID,\0 结尾(注意最长是16字节,16字节的时候,末尾不需要0)
|
||||
char vid[16]; //VID,\0 结尾
|
||||
} S_QUERY_BASIC_INFO;
|
||||
|
||||
//(2)查询文件大小
|
||||
typedef struct {
|
||||
uint32_t 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 {
|
||||
uint32_t file_addr; //配置文件真实物理地址
|
||||
uint32_t file_size; //配置文件(cfg_tool.bin)本身的大小
|
||||
uint32_t earse_unit; //flash 擦除单元(如 4K 的时候,填 4096)
|
||||
} S_PREPARE_WRITE_FILE;
|
||||
|
||||
|
||||
//(5)读取地址范围内容
|
||||
/*
|
||||
* 返回:具体的文件内容,长度为命令中的size参数
|
||||
* 注:PC工具在获取配置文件的大小后,会自行决定拆分成几次命令读取
|
||||
*/
|
||||
|
||||
//(6)擦除地址范围内容
|
||||
/*
|
||||
*返回两个字节的内容,"FA"或者"OK",表示失败或者成功
|
||||
*/
|
||||
|
||||
//(7)写入地址范围内容
|
||||
/*
|
||||
*返回两个字节的内容,"FA"或者"OK",表示失败或者成功
|
||||
*/
|
||||
|
||||
//(8)进入升级模式
|
||||
/*
|
||||
*小机收到命令后,进入升级模式
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief usb或者串口收到的数据流通过这个接口传入进行数据解析
|
||||
*
|
||||
* @param buf 存储普通串口/USB收到的数据包
|
||||
* @param len buf的长度(byte)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void online_cfg_tool_data_deal(void *buf, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 设备组装数据包并发送给PC工具,支持普通串口/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);
|
||||
|
||||
int app_cfg_tool_event_handler(struct cfg_tool_event *cfg_tool_dev);
|
||||
|
||||
struct tool_interface {
|
||||
u8 id;//通道
|
||||
void (*tool_message_deal)(u8 *buf, u32 len);//数据处理接口
|
||||
};
|
||||
|
||||
#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
|
||||
|
||||
599
apps/common/config/new_cfg_tool.c
Normal file
599
apps/common/config/new_cfg_tool.c
Normal file
@ -0,0 +1,599 @@
|
||||
#include "cfg_tool.h"
|
||||
#include "event.h"
|
||||
#include "usb/device/cdc.h"
|
||||
#include "boot.h"
|
||||
#include "ioctl_cmds.h"
|
||||
#include "board_config.h"
|
||||
#include "app_online_cfg.h"
|
||||
#include "asm/crc16.h"
|
||||
#include "app_config.h"
|
||||
#include "config/config_target.h"
|
||||
#if APP_ONLINE_DEBUG
|
||||
#include "online_db_deal.h"
|
||||
#endif/*APP_ONLINE_DEBUG*/
|
||||
|
||||
/*
|
||||
*调音工具在线保存功能由协议接管,通道使用0x12,不分发给调音处理
|
||||
*配置工具通道为0x12,调音工具在线保存功能相关数据包通道必须设置为0x12
|
||||
*new_cfg_tool.c适用于新耳机/音箱配置工具和调音工具在线保存功能
|
||||
*支持异步协议和蓝牙SPP协议的数据解析与通信
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
struct cfg_tool_info {
|
||||
/*PC往小机发送的DATA*/
|
||||
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;
|
||||
|
||||
/*小机返回PC发送的DATA*/
|
||||
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 TEMP_BUF_SIZE 256
|
||||
|
||||
extern const char *sdk_version_info_get(void);
|
||||
extern u8 *sdfile_get_burn_code(u8 *len);
|
||||
extern int norflash_erase(u32 cmd, u32 addr);
|
||||
|
||||
static u8 local_packet[TEMP_BUF_SIZE];
|
||||
const char error_return[] = "FA"; //表示失败
|
||||
const char ok_return[] = "OK"; //表示成功
|
||||
const char er_return[] = "ER"; //表示不能识别的命令
|
||||
static u32 size_total_write = 0;
|
||||
|
||||
extern void doe(u16 k, void *pBuf, u32 lenIn, u32 addr);
|
||||
extern int norflash_erase(u32 cmd, u32 addr);
|
||||
|
||||
#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 cfg_tool_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;
|
||||
}
|
||||
|
||||
static u8 parse_seq = 0;
|
||||
static void ci_send_packet_new(u32 id, u8 *packet, int size)
|
||||
{
|
||||
#if APP_ONLINE_DEBUG
|
||||
app_online_db_ack(parse_seq, packet, size);
|
||||
#endif/*APP_ONLINE_DEBUG*/
|
||||
}
|
||||
|
||||
struct cfg_tool_event spp_packet;
|
||||
int cfg_tool_online_parse(u8 *buf, u32 len)
|
||||
{
|
||||
parse_seq = buf[2];
|
||||
u32 event = (buf[3] | (buf[4] << 8) | (buf[5] << 16) | (buf[6] << 24));
|
||||
spp_packet.event = event;
|
||||
spp_packet.packet = buf;
|
||||
spp_packet.size = len;
|
||||
return (app_cfg_tool_event_handler(&spp_packet));
|
||||
}
|
||||
|
||||
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 *)malloc(TEMP_BUF_SIZE);
|
||||
if (send_buf == NULL) {
|
||||
log_error("send_buf malloc err!");
|
||||
return;
|
||||
}
|
||||
|
||||
send_buf[0] = 0x5A;
|
||||
send_buf[1] = 0xAA;
|
||||
send_buf[2] = 0xA5;
|
||||
send_buf[5] = 2 + len;/*L*/
|
||||
send_buf[6] = id;/*T*/
|
||||
send_buf[7] = sq;/*SQ*/
|
||||
memcpy(send_buf + 8, buf, len);
|
||||
/*添加CRC16*/
|
||||
crc16_data = CRC16(&send_buf[5], len + 3);
|
||||
send_buf[3] = crc16_data & 0xff;
|
||||
send_buf[4] = (crc16_data >> 8) & 0xff;
|
||||
|
||||
/* printf_buf(send_buf, len + 8); */
|
||||
|
||||
#if (TCFG_CFG_TOOL_ENABLE || TCFG_ONLINE_ENABLE)
|
||||
#if (TCFG_COMM_TYPE == TCFG_SPP_COMM)
|
||||
ci_send_packet_new(INITIATIVE_STYLE, buf, len);
|
||||
#elif (TCFG_COMM_TYPE == TCFG_USB_COMM)
|
||||
cdc_write_data(0, send_buf, len + 8);
|
||||
#elif (TCFG_COMM_TYPE == TCFG_UART_COMM)
|
||||
ci_uart_write(send_buf, len + 8);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
free(send_buf);
|
||||
}
|
||||
|
||||
/*6个byte的校验码数组转为字符串*/
|
||||
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;
|
||||
}
|
||||
|
||||
FILE *cfg_open_file(u32 file_id)
|
||||
{
|
||||
FILE *cfg_fp = NULL;
|
||||
if (file_id <= CFG_EQ_FILEID) {
|
||||
if ((file_id == CFG_TOOL_FILEID)) {
|
||||
cfg_fp = fopen(CFG_TOOL_FILE, "r");
|
||||
log_info("open cfg_tool.bin\n");
|
||||
} else if ((file_id == CFG_OLD_EQ_FILEID)) {
|
||||
cfg_fp = fopen(CFG_OLD_EQ_FILE, "r");
|
||||
log_info("open old eq_cfg_hw.bin\n");
|
||||
} else if ((file_id == CFG_OLD_EFFECT_FILEID)) {
|
||||
cfg_fp = fopen(CFG_OLD_EFFECT_FILE, "r");
|
||||
log_info("open effects_cfg.bin\n");
|
||||
} else if ((file_id == CFG_EQ_FILEID)) {
|
||||
cfg_fp = fopen(CFG_EQ_FILE, "r");
|
||||
log_info("open eq_cfg_hw.bin\n");
|
||||
}
|
||||
}
|
||||
return cfg_fp;
|
||||
}
|
||||
|
||||
extern void nvram_set_boot_state(u32 state);
|
||||
extern void hw_mmu_disable(void);
|
||||
extern void ram_protect_close(void);
|
||||
AT(.volatile_ram_code)
|
||||
void cfg_tool_go_mask_usb_updata()
|
||||
{
|
||||
local_irq_disable();
|
||||
ram_protect_close();
|
||||
hw_mmu_disable();
|
||||
nvram_set_boot_state(2);
|
||||
|
||||
JL_CLOCK->PWR_CON |= (1 << 4);
|
||||
/* chip_reset(); */
|
||||
/* cpu_reset(); */
|
||||
while (1);
|
||||
}
|
||||
|
||||
/*延时复位防止工具升级进度条显示错误*/
|
||||
static void delay_cpu_reset(void *priv)
|
||||
{
|
||||
extern void cpu_reset();
|
||||
cpu_reset();
|
||||
}
|
||||
|
||||
int app_cfg_tool_event_handler(struct cfg_tool_event *cfg_tool_dev)
|
||||
{
|
||||
u8 *buf = NULL;
|
||||
u8 *buf_temp = NULL;
|
||||
u8 *buf_temp_0 = NULL;
|
||||
u8 valid_cmd;
|
||||
u32 erase_cmd;
|
||||
int write_len;
|
||||
int send_len;
|
||||
u8 crc_temp_len, sdkname_temp_len;
|
||||
char proCrc_fw[32] = {0};
|
||||
char sdkName_fw[32] = {0};
|
||||
const struct tool_interface *p;
|
||||
struct vfs_attr attr;
|
||||
FILE *cfg_fp = NULL;
|
||||
|
||||
/* printf_buf(cfg_tool_dev->packet, cfg_tool_dev->size); */
|
||||
|
||||
buf = (u8 *)malloc(TEMP_BUF_SIZE);
|
||||
if (buf == NULL) {
|
||||
log_error("buf malloc err!");
|
||||
return 0;
|
||||
}
|
||||
buf_temp_0 = (u8 *)malloc(TEMP_BUF_SIZE);
|
||||
if (buf_temp_0 == NULL) {
|
||||
free(buf);
|
||||
log_error("buf_temp_0 malloc err!");
|
||||
return 0;
|
||||
}
|
||||
buf_temp_0 = (u8 *)ALIGN(buf_temp_0, 4);
|
||||
memset(buf_temp_0, 0, TEMP_BUF_SIZE);
|
||||
memcpy(buf_temp_0 + 1, cfg_tool_dev->packet, cfg_tool_dev->size);
|
||||
|
||||
/*数据进行处理*/
|
||||
list_for_each_tool_interface(p) {
|
||||
if (p->id == cfg_tool_dev->packet[1]) {
|
||||
p->tool_message_deal(buf_temp_0 + 2, cfg_tool_dev->size - 1);
|
||||
free(buf_temp_0);
|
||||
free(buf);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
memset(buf, 0, TEMP_BUF_SIZE);
|
||||
|
||||
switch (cfg_tool_dev->event) {
|
||||
case ONLINE_SUB_OP_QUERY_BASIC_INFO:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_QUERY_BASIC_INFO\n"); */
|
||||
/*获取校验码*/
|
||||
u8 *p = sdfile_get_burn_code(&crc_temp_len);
|
||||
memcpy(info.s_basic_info.progCrc, p + 8, 6);
|
||||
/* printf_buf(info.s_basic_info.progCrc, 6); */
|
||||
hex2text(info.s_basic_info.progCrc, proCrc_fw);
|
||||
/* log_info("crc:%s\n", proCrc_fw); */
|
||||
|
||||
/*获取固件版本信息*/
|
||||
sdkname_temp_len = strlen(sdk_version_info_get());
|
||||
memcpy(info.s_basic_info.sdkName, sdk_version_info_get(), sdkname_temp_len);
|
||||
memcpy(sdkName_fw, info.s_basic_info.sdkName, sdkname_temp_len);
|
||||
/* log_info("version:%s\n", sdk_version_info_get()); */
|
||||
|
||||
struct flash_head flash_head_for_pid_vid;
|
||||
|
||||
for (u8 i = 0; i < 5; i++) {
|
||||
norflash_read(NULL, (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;
|
||||
}
|
||||
}
|
||||
|
||||
struct flash_head _head;
|
||||
struct flash_head *temp_p = &_head;
|
||||
memcpy(temp_p, &flash_head_for_pid_vid, 32);
|
||||
|
||||
memset(info.s_basic_info.pid, 0, sizeof(info.s_basic_info.pid));
|
||||
memcpy(info.s_basic_info.pid, temp_p->pid, sizeof(info.s_basic_info.pid));
|
||||
for (u8 i = 0; i < sizeof(info.s_basic_info.pid); i++) {
|
||||
if (~info.s_basic_info.pid[i] == 0x00) {
|
||||
info.s_basic_info.pid[i] = 0x00;
|
||||
}
|
||||
}
|
||||
/* printf_buf(info.s_basic_info.pid, 16); */
|
||||
|
||||
memset(info.s_basic_info.vid, 0, sizeof(info.s_basic_info.vid));
|
||||
memcpy(info.s_basic_info.vid, temp_p->vid, 4);
|
||||
/* printf_buf(info.s_basic_info.vid, 16); */
|
||||
|
||||
send_len = sizeof(info.s_basic_info.protocolVer) + sizeof(proCrc_fw) + sizeof(sdkName_fw) + 32;
|
||||
buf[0] = info.s_basic_info.protocolVer & 0xff;
|
||||
buf[1] = (info.s_basic_info.protocolVer >> 8) & 0xff;
|
||||
memcpy(buf + 2, proCrc_fw, sizeof(proCrc_fw));
|
||||
memcpy(buf + 2 + sizeof(proCrc_fw), sdkName_fw, sizeof(sdkName_fw));
|
||||
memcpy(buf + 2 + sizeof(proCrc_fw) + sizeof(sdkName_fw), info.s_basic_info.pid, 16);
|
||||
memcpy(buf + 2 + sizeof(proCrc_fw) + sizeof(sdkName_fw) + 16, info.s_basic_info.vid, 16);
|
||||
break;
|
||||
case ONLINE_SUB_OP_QUERY_FILE_SIZE:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_QUERY_FILE_SIZE\n"); */
|
||||
info.r_file_size.file_id = packet_combined(cfg_tool_dev->packet, 7);
|
||||
cfg_fp = cfg_open_file(info.r_file_size.file_id);
|
||||
|
||||
if (cfg_fp == NULL) {
|
||||
log_error("file open error!\n");
|
||||
goto _exit_;
|
||||
}
|
||||
fget_attrs(cfg_fp, &attr);
|
||||
|
||||
/* log_info("file addr:%x,file size:%d\n", attr.sclust, attr.fsize); */
|
||||
info.s_file_size.file_size = attr.fsize;
|
||||
|
||||
send_len = sizeof(info.s_file_size.file_size);//长度
|
||||
|
||||
/*小端格式*/
|
||||
buf[3] = (info.s_file_size.file_size >> 24) & 0xff;
|
||||
buf[2] = (info.s_file_size.file_size >> 16) & 0xff;
|
||||
buf[1] = (info.s_file_size.file_size >> 8) & 0xff;
|
||||
buf[0] = info.s_file_size.file_size & 0xff;
|
||||
|
||||
fclose(cfg_fp);
|
||||
break;
|
||||
case ONLINE_SUB_OP_QUERY_FILE_CONTENT:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_QUERY_FILE_CONTENT\n"); */
|
||||
info.r_file_content.file_id = packet_combined(cfg_tool_dev->packet, 7);
|
||||
info.r_file_content.offset = packet_combined(cfg_tool_dev->packet, 11);
|
||||
info.r_file_content.size = packet_combined(cfg_tool_dev->packet, 15);
|
||||
|
||||
cfg_fp = cfg_open_file(info.r_file_content.file_id);
|
||||
|
||||
if (cfg_fp == NULL) {
|
||||
log_error("file open error!\n");
|
||||
goto _exit_;
|
||||
}
|
||||
fget_attrs(cfg_fp, &attr);
|
||||
|
||||
/* log_info("file addr:%x,file size:%d\n", attr.sclust, attr.fsize); */
|
||||
if (info.r_file_content.size > attr.fsize) {
|
||||
fclose(cfg_fp);
|
||||
log_error("reading size more than actual size!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
/*逻辑地址转换成flash物理地址*/
|
||||
u32 flash_addr = sdfile_cpu_addr2flash_addr(attr.sclust);
|
||||
/* log_info("flash_addr:0x%x", flash_addr); */
|
||||
/*读取文件内容*/
|
||||
buf_temp = (char *)malloc(info.r_file_content.size);
|
||||
norflash_read(NULL, (void *)buf_temp, info.r_file_content.size, flash_addr + info.r_file_content.offset);
|
||||
/* printf_buf(buf_temp, info.r_file_content.size); */
|
||||
send_len = info.r_file_content.size;
|
||||
memcpy(buf, buf_temp, info.r_file_content.size);
|
||||
|
||||
if (buf_temp) {
|
||||
free(buf_temp);
|
||||
}
|
||||
fclose(cfg_fp);
|
||||
break;
|
||||
case ONLINE_SUB_OP_PREPARE_WRITE_FILE:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_PREPARE_WRITE_FILE\n"); */
|
||||
info.r_prepare_write_file.file_id = packet_combined(cfg_tool_dev->packet, 7);
|
||||
info.r_prepare_write_file.size = packet_combined(cfg_tool_dev->packet, 11);
|
||||
|
||||
cfg_fp = cfg_open_file(info.r_prepare_write_file.file_id);
|
||||
if (cfg_fp == NULL) {
|
||||
log_error("file open error!\n");
|
||||
break;
|
||||
}
|
||||
fget_attrs(cfg_fp, &attr);
|
||||
|
||||
/* log_info("file addr:%x,file size:%d\n", attr.sclust, attr.fsize); */
|
||||
if (info.r_prepare_write_file.size > attr.fsize) {
|
||||
//fclose(cfg_fp);
|
||||
//log_error("preparing to write size more than actual size!\n");
|
||||
//break;
|
||||
}
|
||||
|
||||
info.s_prepare_write_file.file_size = attr.fsize;
|
||||
info.s_prepare_write_file.file_addr = sdfile_cpu_addr2flash_addr(attr.sclust);
|
||||
info.s_prepare_write_file.earse_unit = boot_info.vm.align * 256;
|
||||
|
||||
send_len = sizeof(info.s_prepare_write_file.file_size) * 3;
|
||||
|
||||
buf[3] = (info.s_prepare_write_file.file_addr >> 24) & 0xff;
|
||||
buf[2] = (info.s_prepare_write_file.file_addr >> 16) & 0xff;
|
||||
buf[1] = (info.s_prepare_write_file.file_addr >> 8) & 0xff;
|
||||
buf[0] = info.s_prepare_write_file.file_addr & 0xff;
|
||||
|
||||
buf[7] = (info.s_prepare_write_file.file_size >> 24) & 0xff;
|
||||
buf[6] = (info.s_prepare_write_file.file_size >> 16) & 0xff;
|
||||
buf[5] = (info.s_prepare_write_file.file_size >> 8) & 0xff;
|
||||
buf[4] = info.s_prepare_write_file.file_size & 0xff;
|
||||
|
||||
buf[11] = (info.s_prepare_write_file.earse_unit >> 24) & 0xff;
|
||||
buf[10] = (info.s_prepare_write_file.earse_unit >> 16) & 0xff;
|
||||
buf[9] = (info.s_prepare_write_file.earse_unit >> 8) & 0xff;
|
||||
buf[8] = info.s_prepare_write_file.earse_unit & 0xff;
|
||||
|
||||
fclose(cfg_fp);
|
||||
break;
|
||||
case ONLINE_SUB_OP_READ_ADDR_RANGE:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_READ_ADDR_RANGE\n"); */
|
||||
info.r_read_addr_range.addr = packet_combined(cfg_tool_dev->packet, 7);
|
||||
/* log_info("reading flash addr:0x%x\n", info.r_read_addr_range.addr); */
|
||||
info.r_read_addr_range.size = packet_combined(cfg_tool_dev->packet, 11);
|
||||
/* log_info("reading size = %d\n", info.r_read_addr_range.size); */
|
||||
buf_temp = (char *)malloc(info.r_read_addr_range.size);
|
||||
norflash_read(NULL, (void *)buf_temp, info.r_read_addr_range.size, info.r_read_addr_range.addr);
|
||||
/* printf_buf(buf_temp, info.r_read_addr_range.size); */
|
||||
|
||||
send_len = info.r_read_addr_range.size;
|
||||
memcpy(buf, buf_temp, info.r_read_addr_range.size);
|
||||
|
||||
if (buf_temp) {
|
||||
free(buf_temp);
|
||||
}
|
||||
break;
|
||||
case ONLINE_SUB_OP_ERASE_ADDR_RANGE:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_ERASE_ADDR_RANGE\n"); */
|
||||
info.r_erase_addr_range.addr = packet_combined(cfg_tool_dev->packet, 7);
|
||||
/* log_info("erasing flash start addr:0x%x\n", info.r_erase_addr_range.addr); */
|
||||
/*要擦除的大小,会保证按earse_unit对齐,即总是erase_unit的倍数*/
|
||||
info.r_erase_addr_range.size = packet_combined(cfg_tool_dev->packet, 11);
|
||||
/* log_info("erasing size = %d\n", info.r_erase_addr_range.size); */
|
||||
/* log_info("earse_unit = %d\n", info.s_prepare_write_file.earse_unit); */
|
||||
switch (info.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;
|
||||
defualt:
|
||||
memcpy(buf, error_return, sizeof(error_return));
|
||||
log_error("erase error!");
|
||||
break;
|
||||
}
|
||||
|
||||
for (u8 i = 0; i < (info.r_erase_addr_range.size / info.s_prepare_write_file.earse_unit); i ++) {
|
||||
u8 ret = norflash_erase(erase_cmd, info.r_erase_addr_range.addr + (i * info.s_prepare_write_file.earse_unit));
|
||||
if (ret) {
|
||||
memcpy(buf, error_return, sizeof(error_return));
|
||||
log_error("erase error!");
|
||||
} else {
|
||||
memcpy(buf, ok_return, sizeof(ok_return));
|
||||
log_info("erase success");
|
||||
}
|
||||
}
|
||||
|
||||
send_len = sizeof(error_return);
|
||||
break;
|
||||
case ONLINE_SUB_OP_WRITE_ADDR_RANGE:
|
||||
valid_cmd = 1;
|
||||
/* log_info("event_ONLINE_SUB_OP_WRITE_ADDR_RANGE\n"); */
|
||||
info.r_write_addr_range.addr = packet_combined(cfg_tool_dev->packet, 7);
|
||||
info.r_write_addr_range.size = packet_combined(cfg_tool_dev->packet, 11);
|
||||
/* log_info("writing flash start addr:0x%x\n", info.r_write_addr_range.addr); */
|
||||
/* log_info("writing size = %d\n", info.r_write_addr_range.size); */
|
||||
buf_temp = (char *)malloc(info.r_write_addr_range.size);
|
||||
memcpy(buf_temp, cfg_tool_dev->packet + 15, info.r_write_addr_range.size);
|
||||
/* printf_buf(buf_temp, info.r_write_addr_range.size); */
|
||||
|
||||
cfg_tool_encode_data_by_user_key(boot_info.chip_id, buf_temp, info.r_write_addr_range.size, info.r_write_addr_range.addr - boot_info.sfc.sfc_base_addr, 0x20);
|
||||
|
||||
write_len = norflash_write(NULL, buf_temp, info.r_write_addr_range.size, info.r_write_addr_range.addr);
|
||||
|
||||
/* norflash_read(NULL, buf_temp, info.r_write_addr_range.size, info.r_write_addr_range.addr); */
|
||||
/* printf_buf(buf_temp, info.r_write_addr_range.size); */
|
||||
|
||||
if (write_len != info.r_write_addr_range.size) {
|
||||
memcpy(buf, error_return, sizeof(error_return));
|
||||
log_error("write error!");
|
||||
} else {
|
||||
memcpy(buf, ok_return, sizeof(ok_return));
|
||||
}
|
||||
send_len = sizeof(error_return);
|
||||
|
||||
if (buf_temp) {
|
||||
free(buf_temp);
|
||||
}
|
||||
|
||||
if (info.r_prepare_write_file.file_id == CFG_TOOL_FILEID) {
|
||||
size_total_write += info.r_write_addr_range.size;
|
||||
/* log_info("size_total_write = %d\n", size_total_write); */
|
||||
/* log_info("erasing size = %d\n", info.r_erase_addr_range.size); */
|
||||
if (size_total_write >= info.r_erase_addr_range.size) {
|
||||
size_total_write = 0;
|
||||
log_info("cpu_reset\n");
|
||||
extern u16 sys_timeout_add(void *priv, void (*func)(void *priv), u32 msec);
|
||||
sys_timeout_add(NULL, delay_cpu_reset, 500);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ONLINE_SUB_OP_ENTER_UPGRADE_MODE:
|
||||
valid_cmd = 1;
|
||||
log_info("event_ONLINE_SUB_OP_ENTER_UPGRADE_MODE\n");
|
||||
cfg_tool_go_mask_usb_updata();
|
||||
break;
|
||||
default:
|
||||
valid_cmd = 0;
|
||||
log_error("invalid data\n");
|
||||
memcpy(buf, er_return, sizeof(er_return));//不认识的命令返回ER
|
||||
send_len = sizeof(er_return);
|
||||
break;
|
||||
_exit_:
|
||||
memcpy(buf, error_return, sizeof(error_return));//文件打开失败返回FA
|
||||
send_len = sizeof(error_return);
|
||||
break;
|
||||
}
|
||||
|
||||
all_assemble_package_send_to_pc(REPLY_STYLE, cfg_tool_dev->packet[2], buf, send_len);
|
||||
|
||||
free(buf_temp_0);
|
||||
free(buf);
|
||||
return (valid_cmd);
|
||||
}
|
||||
|
||||
void cfg_tool_event_to_user(u8 *packet, u32 type, u8 event, u8 size)
|
||||
{
|
||||
struct sys_event e;
|
||||
e.type = SYS_DEVICE_EVENT;
|
||||
if (packet != NULL) {
|
||||
if (size > sizeof(local_packet)) {
|
||||
return;
|
||||
}
|
||||
e.u.cfg_tool.packet = local_packet;
|
||||
memcpy(e.u.cfg_tool.packet, packet, size);
|
||||
}
|
||||
e.arg = (void *)type;
|
||||
e.u.cfg_tool.event = event;
|
||||
e.u.cfg_tool.size = size;
|
||||
sys_event_notify(&e);
|
||||
}
|
||||
|
||||
void app_cfg_tool_message_deal(u8 *buf, u32 len)
|
||||
{
|
||||
u8 cmd = buf[8];
|
||||
switch (cmd) {
|
||||
case ONLINE_SUB_OP_QUERY_BASIC_INFO:
|
||||
case ONLINE_SUB_OP_QUERY_FILE_SIZE:
|
||||
case ONLINE_SUB_OP_QUERY_FILE_CONTENT:
|
||||
case ONLINE_SUB_OP_PREPARE_WRITE_FILE:
|
||||
case ONLINE_SUB_OP_READ_ADDR_RANGE:
|
||||
case ONLINE_SUB_OP_ERASE_ADDR_RANGE:
|
||||
case ONLINE_SUB_OP_WRITE_ADDR_RANGE:
|
||||
case ONLINE_SUB_OP_ENTER_UPGRADE_MODE:
|
||||
cfg_tool_event_to_user(&buf[5], DEVICE_EVENT_FROM_CFG_TOOL, cmd, buf[5] + 1);
|
||||
break;
|
||||
default:
|
||||
cfg_tool_event_to_user(&buf[5], DEVICE_EVENT_FROM_CFG_TOOL, DEFAULT_ACTION, buf[5] + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void online_cfg_tool_data_deal(void *buf, u32 len)
|
||||
{
|
||||
u8 *data_buf = buf;
|
||||
u16 crc16_data;
|
||||
|
||||
/* printf_buf(buf, len); */
|
||||
|
||||
/*DATA前的固定字节包括 (5A AA A5 CRC L T SQ)共8个字节 */
|
||||
if (len < 8) {
|
||||
log_error("Data length is too short, receive an invalid message!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data_buf[0] != 0x5a) || (data_buf[1] != 0xaa) || (data_buf[2] != 0xa5)) {
|
||||
log_error("Header check error, receive an invalid message!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*CRC16校验,CRC16校验码位于数据包的buf[3]和buf[4]*/
|
||||
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;
|
||||
}
|
||||
|
||||
app_cfg_tool_message_deal(buf, len);
|
||||
}
|
||||
Reference in New Issue
Block a user