初版
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="AC707N_ble_ota" />
|
||||
<Option compiler="pi32v2_r3_lto_compiler" />
|
||||
<Build>
|
||||
<Target title="Release">
|
||||
<Option output="cpu/br35/output/ota_loader.elf" prefix_auto="0" extension_auto="0" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="pi32v2_r3_lto_compiler" />
|
||||
<Compiler>
|
||||
<Add option="-integrated-as" />
|
||||
<Add option="-fallow-pointer-null" />
|
||||
<Add option="-fno-common" />
|
||||
<Add option="-flto" />
|
||||
<Add option="-g" />
|
||||
<Add option="-Oz" />
|
||||
<Add option="-mllvm -pi32v2-large-program=true" />
|
||||
<Add option="-D__GCC_PI32V2__" />
|
||||
<Add option="-Wno-format" />
|
||||
<Add option="-Wno-unused-value" />
|
||||
<Add option="-Wno-unused-function" />
|
||||
<Add option="-Wno-unused-comparison" />
|
||||
<Add option="-Wno-parentheses" />
|
||||
<Add option="-Wno-tautological-compare" />
|
||||
<Add option="-Wno-incompatible-library-redeclaration" />
|
||||
<Add option="-Wno-invalid-noreturn" />
|
||||
<Add option="-Wno-visibility" />
|
||||
<Add option="-Wno-integer-overflow" />
|
||||
<Add option="-fms-extensions" />
|
||||
<Add option="-Wno-shift-negative-value" />
|
||||
<Add option="-DCONFIG_CPU_BR35" />
|
||||
<Add option="-DOTA_LOADER_TYPE=ble_ota" />
|
||||
<Add option="-D__APP_IS_OTA" />
|
||||
<Add option="-D__DEBUG" />
|
||||
<Add option="-D__ST_DEBUG" />
|
||||
<Add option="-D__NOR_DEBUG" />
|
||||
<Add option="-D__JLFS_DEBUG" />
|
||||
<Add option="-D__UP_DEBUG" />
|
||||
<Add option="-DCONFIG_BTCTRLE_V2_ENABLE" />
|
||||
<Add option="-DBLE_UPDATA_SUPPORT_CONNECT" />
|
||||
<Add option="-DCONFIG_BT_NAME=\"BR35_BLE_UPDATE\"" />
|
||||
<Add option="-D__USE_MASK_API__" />
|
||||
<Add option="-D__MASK_LZ4" />
|
||||
<Add option="-DCONFIG_NEW_BREDR_ENABLE" />
|
||||
<Add option="-DCONFIG_NEW_MODEM_ENABLE" />
|
||||
<Add option="-D__USE_MASK_INI_DEC" />
|
||||
<Add option="-D__FLASH_SUPPORT_4BIT_MODE" />
|
||||
<Add option="-D__FLASH_SUPPORT_CONTINUE_READ_MODE" />
|
||||
<Add option="-D__UPDATE_RUN_RAM" />
|
||||
<Add directory="app" />
|
||||
<Add directory="app/inc" />
|
||||
<Add directory="app/inc/cpu/br35" />
|
||||
<Add directory="cpu" />
|
||||
<Add directory="cpu/br35" />
|
||||
<Add directory="include_lib" />
|
||||
<Add directory="include_lib/common" />
|
||||
<Add directory="include_lib/driver" />
|
||||
<Add directory="include_lib/driver/common" />
|
||||
<Add directory="include_lib/driver/cpu" />
|
||||
<Add directory="include_lib/driver/cpu/br35" />
|
||||
<Add directory="include_lib/driver/cpu/br35/power" />
|
||||
<Add directory="include_lib/driver/device" />
|
||||
<Add directory="include_lib/driver/device/dev_mg" />
|
||||
<Add directory="include_lib/driver/device/eeprom" />
|
||||
<Add directory="include_lib/driver/device/norflash" />
|
||||
<Add directory="include_lib/driver/device/sdmmc" />
|
||||
<Add directory="include_lib/driver/device/usb" />
|
||||
<Add directory="include_lib/driver/jlfs" />
|
||||
<Add directory="include_lib/driver/jlup" />
|
||||
<Add directory="include_lib/system" />
|
||||
<Add directory="include_lib/system/common" />
|
||||
<Add directory="include_lib/system/cpu" />
|
||||
<Add directory="include_lib/system/cpu/br35" />
|
||||
<Add directory="include_lib/system/cpu/br35/asm" />
|
||||
<Add directory="include_lib/system/cpu/br35/asm/power" />
|
||||
<Add directory="include_lib/system/fs" />
|
||||
<Add directory="include_lib/system/os" />
|
||||
<Add directory="include_lib/system/generic" />
|
||||
<Add directory="include_lib/system/fs/lite_file_sys" />
|
||||
<Add directory="include_lib/update" />
|
||||
<Add directory="include_lib/jl_rcsp" />
|
||||
<Add directory="include_lib/lib_mutual_loader" />
|
||||
<Add directory="interface/btctrler" />
|
||||
<Add directory="interface/btctrler/port/br35" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="--gc-sections" />
|
||||
<Add option="--plugin-opt=-dont-used-symbol-list=malloc,free,sprintf,printf,puts,putchar,perror,vprintf,printi,fopen,fread,fwrite,fseek,strlen,memset,memcpy,strcpy,memmove,strcmp" />
|
||||
<Add option="-M=cpu/br35/output/map.txt" />
|
||||
<Add option="-Tcpu/br35/output/ram.ld" />
|
||||
<Add option="--plugin-opt=-inline-threshold=5" />
|
||||
<Add option="--plugin-opt=-enable-ipra=true" />
|
||||
<Add option="--plugin-opt=-pi32v2-always-use-itblock" />
|
||||
<Add option="--plugin-opt=-pi32v2-merge-max-offset=64" />
|
||||
<Add option="--plugin-opt=-global-merge-on-const" />
|
||||
<Add option="--plugin-opt=-pi32v2-enable-simd=true" />
|
||||
<Add option="--plugin-opt=-pi32v2-enable-rep-memop=true" />
|
||||
<Add option="--plugin-opt=mcpu=r3" />
|
||||
<Add option="--plugin-opt=save-temps" />
|
||||
<Add option="--plugin-opt=-pi32v2-large-program=true" />
|
||||
<Add option="--start-group" />
|
||||
<Add option="--whole-archive" />
|
||||
<Add option="include_lib/liba/br35/ota_loader_driver.a" />
|
||||
<Add option="include_lib/liba/br35/system.a" />
|
||||
<Add option="include_lib/liba/br35/update.a" />
|
||||
<Add option="--no-whole-archive" />
|
||||
<Add option="--end-group" />
|
||||
<Add option="--start-group " />
|
||||
<Add option="include_lib/liba/br35/bt_protocol.a" />
|
||||
<Add option="--end-group " />
|
||||
<Add option="include_lib/liba/br35/btctrler_v2.a" />
|
||||
<Add library="C:\JL\pi32\pi32v2-lib\r3\libm.a" />
|
||||
</Linker>
|
||||
<ExtraCommands>
|
||||
<Add before="$compiler $options $includes -D__LD__ -E -P cpu\br35\output\ram_ld.c -o cpu\br35\output\ram.ld" />
|
||||
<Mode before="always" />
|
||||
<Add after="cpu\br35\output\download.bat ota_loader" />
|
||||
<Mode after="always" />
|
||||
</ExtraCommands>
|
||||
</Target>
|
||||
</Build>
|
||||
<Unit filename="app/inc/ble_rcsp_server.h" />
|
||||
<Unit filename="app/inc/custom_cfg.h" />
|
||||
<Unit filename="app/inc/le_common.h" />
|
||||
<Unit filename="app/inc/testbox_update.h" />
|
||||
<Unit filename="app/src/common/cbuf.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/common/lbuf.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/common/msg.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/common/sys_timer.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/common/version.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/le_module/le_server_moudle.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/lib_btctrler_config.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/loader_main.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/log_config.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/update/testbox_ble_update.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="app/src/update/update_main.c"><Option compilerVer="CC"/></Unit>
|
||||
<Unit filename="include_lib/btstack/ble_api.h" />
|
||||
<Unit filename="include_lib/btstack/bluetooth.h" />
|
||||
<Unit filename="include_lib/btstack/bt_profile_config.h" />
|
||||
<Unit filename="include_lib/btstack/le_user.h" />
|
||||
<Unit filename="include_lib/driver/common/dec.h" />
|
||||
<Unit filename="include_lib/driver/common/printf.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/clock.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/crc.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/csfr.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/delay.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/gpio.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/io_imap.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/io_omap.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/irq.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/mask_api.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/maskrom.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/power/p33.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/power/p33_app.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/power/p33_sfr.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/sfr.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/timer.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/uart.h" />
|
||||
<Unit filename="include_lib/driver/cpu/br35/wdt.h" />
|
||||
<Unit filename="include_lib/driver/device/dev_mg/device_errno.h" />
|
||||
<Unit filename="include_lib/driver/device/norflash/norflash.h" />
|
||||
<Unit filename="include_lib/driver/jlfs/jlfs.h" />
|
||||
<Unit filename="include_lib/driver/jlup/upgrade.h" />
|
||||
<Unit filename="include_lib/driver/power/power_reset.h" />
|
||||
<Unit filename="include_lib/lib_include.h" />
|
||||
<Unit filename="include_lib/system/cpu/br35/asm/cpu.h" />
|
||||
<Unit filename="include_lib/system/cpu/br35/asm/exception.h" />
|
||||
<Unit filename="include_lib/system/fs/lite_file_sys/diskio.h" />
|
||||
<Unit filename="include_lib/system/fs/lite_file_sys/tff.h" />
|
||||
<Unit filename="include_lib/system/generic/circular_buf.h" />
|
||||
<Unit filename="include_lib/system/generic/common.h" />
|
||||
<Unit filename="include_lib/system/generic/debug.h" />
|
||||
<Unit filename="include_lib/system/generic/errno-base.h" />
|
||||
<Unit filename="include_lib/system/generic/jiffies.h" />
|
||||
<Unit filename="include_lib/system/generic/lbuf.h" />
|
||||
<Unit filename="include_lib/system/generic/list.h" />
|
||||
<Unit filename="include_lib/system/generic/log.h" />
|
||||
<Unit filename="include_lib/system/generic/msg.h" />
|
||||
<Unit filename="include_lib/system/generic/sys_timer.h" />
|
||||
<Unit filename="include_lib/system/generic/typedef.h" />
|
||||
<Unit filename="include_lib/system/malloc.h" />
|
||||
<Unit filename="include_lib/system/os/os_cpu.h" />
|
||||
<Unit filename="include_lib/system/spinlock.h" />
|
||||
<Unit filename="include_lib/update/update_main.h" />
|
||||
<Unit filename="interface/btctrler/ble/hci_ll.h" />
|
||||
<Unit filename="interface/btctrler/ble/ll_config.h" />
|
||||
<Unit filename="interface/btctrler/btcontroller_mode.h" />
|
||||
<Unit filename="interface/btctrler/btcontroller_modules.h" />
|
||||
<Unit filename="interface/btctrler/btctrler_api_for_update.h" />
|
||||
<Unit filename="interface/btctrler/classic/hci_lmp.h" />
|
||||
<Unit filename="interface/btctrler/classic/lmp_config.h" />
|
||||
<Unit filename="interface/btctrler/hci_transport.h" />
|
||||
<Unit filename="interface/btctrler/port/br35/btcontroller_config.h" />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
@@ -0,0 +1,333 @@
|
||||
|
||||
# make 编译并下载
|
||||
# make VERBOSE=1 显示编译详细过程
|
||||
# make clean 清除编译临时文件
|
||||
#
|
||||
# 注意: Linux 下编译方式:
|
||||
# 1. 从 http://pkgman.jieliapp.com/doc/all 处找到下载链接
|
||||
# 2. 下载后,解压到 /opt/jieli 目录下,保证
|
||||
# /opt/jieli/common/bin/clang 存在(注意目录层次)
|
||||
# 3. 确认 ulimit -n 的结果足够大(建议大于8096),否则链接可能会因为打开文件太多而失败
|
||||
# 可以通过 ulimit -n 8096 来设置一个较大的值
|
||||
#
|
||||
|
||||
# 工具路径设置
|
||||
ifeq ($(OS), Windows_NT)
|
||||
# Windows 下工具链位置
|
||||
TOOL_DIR := C:/JL/pi32/bin
|
||||
CC := clang.exe
|
||||
CXX := clang.exe
|
||||
LD := pi32v2-lto-wrapper.exe
|
||||
AR := llvm-ar.exe
|
||||
MKDIR := mkdir_win -p
|
||||
RM := rm -rf
|
||||
|
||||
SYS_LIB_DIR := C:/JL/pi32/pi32v2-lib/r3
|
||||
SYS_INC_DIR := C:/JL/pi32/pi32v2-include
|
||||
EXT_CFLAGS := # Windows 下不需要 -D__SHELL__
|
||||
export PATH:=$(TOOL_DIR);$(PATH)
|
||||
|
||||
## 后处理脚本
|
||||
POST_SCRIPT := cpu/br35/output/download.bat
|
||||
RUN_POST_SCRIPT := cpu\br35\output\download.bat
|
||||
else
|
||||
# Linux 下工具链位置
|
||||
TOOL_DIR := /opt/jieli/pi32v2/bin
|
||||
CC := clang
|
||||
CXX := clang
|
||||
LD := lto-wrapper
|
||||
AR := lto-ar
|
||||
MKDIR := mkdir -p
|
||||
RM := rm -rf
|
||||
export OBJDUMP := $(TOOL_DIR)/objdump
|
||||
export OBJCOPY := $(TOOL_DIR)/objcopy
|
||||
export OBJSIZEDUMP := $(TOOL_DIR)/objsizedump
|
||||
|
||||
SYS_LIB_DIR := $(TOOL_DIR)/../lib/r3
|
||||
SYS_INC_DIR := $(TOOL_DIR)/../include
|
||||
EXT_CFLAGS := -D__SHELL__ # Linux 下需要这个保证正确处理 download.c
|
||||
export PATH:=$(TOOL_DIR):$(PATH)
|
||||
|
||||
## 后处理脚本
|
||||
POST_SCRIPT := cpu/br35/output/download.sh
|
||||
RUN_POST_SCRIPT := bash $(POST_SCRIPT)
|
||||
endif
|
||||
|
||||
CC := $(TOOL_DIR)/$(CC)
|
||||
CXX := $(TOOL_DIR)/$(CXX)
|
||||
LD := $(TOOL_DIR)/$(LD)
|
||||
AR := $(TOOL_DIR)/$(AR)
|
||||
# 输出文件设置
|
||||
OUT_ELF := cpu/br35/output/ota_loader.elf
|
||||
OBJ_FILE := $(OUT_ELF).objs.txt
|
||||
# 编译路径设置
|
||||
BUILD_DIR := objs
|
||||
|
||||
# 编译参数设置
|
||||
CFLAGS := \
|
||||
-target pi32v2 \
|
||||
-mcpu=r3 \
|
||||
-integrated-as \
|
||||
-flto \
|
||||
-integrated-as \
|
||||
-fallow-pointer-null \
|
||||
-fno-common \
|
||||
-flto \
|
||||
-g \
|
||||
-Oz \
|
||||
-mllvm -pi32v2-large-program=true \
|
||||
-Wno-format \
|
||||
-Wno-unused-value \
|
||||
-Wno-unused-function \
|
||||
-Wno-unused-comparison \
|
||||
-Wno-parentheses \
|
||||
-Wno-tautological-compare \
|
||||
-Wno-incompatible-library-redeclaration \
|
||||
-Wno-invalid-noreturn \
|
||||
-Wno-visibility \
|
||||
-Wno-integer-overflow \
|
||||
-fms-extensions \
|
||||
-Wno-shift-negative-value \
|
||||
|
||||
|
||||
# C++额外的编译参数
|
||||
CXXFLAGS :=
|
||||
|
||||
|
||||
# 宏定义
|
||||
DEFINES := \
|
||||
-D__GCC_PI32V2__ \
|
||||
-DCONFIG_CPU_BR35 \
|
||||
-DOTA_LOADER_TYPE=ble_ota \
|
||||
-D__APP_IS_OTA \
|
||||
-D__DEBUG \
|
||||
-D__ST_DEBUG \
|
||||
-D__NOR_DEBUG \
|
||||
-D__JLFS_DEBUG \
|
||||
-D__UP_DEBUG \
|
||||
-DCONFIG_BTCTRLE_V2_ENABLE \
|
||||
-DBLE_UPDATA_SUPPORT_CONNECT \
|
||||
-DCONFIG_BT_NAME=\"BR35_BLE_UPDATE\" \
|
||||
-D__USE_MASK_API__ \
|
||||
-D__MASK_LZ4 \
|
||||
-DCONFIG_NEW_BREDR_ENABLE \
|
||||
-DCONFIG_NEW_MODEM_ENABLE \
|
||||
-D__USE_MASK_INI_DEC \
|
||||
-D__FLASH_SUPPORT_4BIT_MODE \
|
||||
-D__FLASH_SUPPORT_CONTINUE_READ_MODE \
|
||||
-D__UPDATE_RUN_RAM \
|
||||
|
||||
|
||||
DEFINES += $(EXT_CFLAGS) # 额外的一些定义
|
||||
|
||||
# 头文件搜索路径
|
||||
INCLUDES := \
|
||||
-Iapp \
|
||||
-Iapp/inc \
|
||||
-Iapp/inc/cpu/br35 \
|
||||
-Icpu \
|
||||
-Icpu/br35 \
|
||||
-Iinclude_lib \
|
||||
-Iinclude_lib/common \
|
||||
-Iinclude_lib/driver \
|
||||
-Iinclude_lib/driver/common \
|
||||
-Iinclude_lib/driver/cpu \
|
||||
-Iinclude_lib/driver/cpu/br35 \
|
||||
-Iinclude_lib/driver/cpu/br35/power \
|
||||
-Iinclude_lib/driver/device \
|
||||
-Iinclude_lib/driver/device/dev_mg \
|
||||
-Iinclude_lib/driver/device/eeprom \
|
||||
-Iinclude_lib/driver/device/norflash \
|
||||
-Iinclude_lib/driver/device/sdmmc \
|
||||
-Iinclude_lib/driver/device/usb \
|
||||
-Iinclude_lib/driver/jlfs \
|
||||
-Iinclude_lib/driver/jlup \
|
||||
-Iinclude_lib/system \
|
||||
-Iinclude_lib/system/common \
|
||||
-Iinclude_lib/system/cpu \
|
||||
-Iinclude_lib/system/cpu/br35 \
|
||||
-Iinclude_lib/system/cpu/br35/asm \
|
||||
-Iinclude_lib/system/cpu/br35/asm/power \
|
||||
-Iinclude_lib/system/fs \
|
||||
-Iinclude_lib/system/os \
|
||||
-Iinclude_lib/system/generic \
|
||||
-Iinclude_lib/system/fs/lite_file_sys \
|
||||
-Iinclude_lib/update \
|
||||
-Iinclude_lib/jl_rcsp \
|
||||
-Iinclude_lib/lib_mutual_loader \
|
||||
-Iinterface/btctrler \
|
||||
-Iinterface/btctrler/port/br35 \
|
||||
-I$(SYS_INC_DIR) \
|
||||
|
||||
|
||||
# 需要编译的 .c 文件
|
||||
c_SRC_FILES := \
|
||||
app/src/common/cbuf.c \
|
||||
app/src/common/lbuf.c \
|
||||
app/src/common/msg.c \
|
||||
app/src/common/sys_timer.c \
|
||||
app/src/common/version.c \
|
||||
app/src/le_module/le_server_moudle.c \
|
||||
app/src/lib_btctrler_config.c \
|
||||
app/src/loader_main.c \
|
||||
app/src/log_config.c \
|
||||
app/src/update/testbox_ble_update.c \
|
||||
app/src/update/update_main.c \
|
||||
|
||||
|
||||
# 需要编译的 .S 文件
|
||||
S_SRC_FILES :=
|
||||
|
||||
|
||||
# 需要编译的 .s 文件
|
||||
s_SRC_FILES :=
|
||||
|
||||
|
||||
# 需要编译的 .cpp 文件
|
||||
cpp_SRC_FILES :=
|
||||
|
||||
|
||||
# 需要编译的 .cc 文件
|
||||
cc_SRC_FILES :=
|
||||
|
||||
|
||||
# 需要编译的 .cxx 文件
|
||||
cxx_SRC_FILES :=
|
||||
|
||||
|
||||
# 链接参数
|
||||
LFLAGS := \
|
||||
--gc-sections \
|
||||
--plugin-opt=-dont-used-symbol-list=malloc,free,sprintf,printf,puts,putchar,perror,vprintf,printi,fopen,fread,fwrite,fseek,strlen,memset,memcpy,strcpy,memmove,strcmp \
|
||||
-M=cpu/br35/output/map.txt \
|
||||
-Tcpu/br35/output/ram.ld \
|
||||
--plugin-opt=-inline-threshold=5 \
|
||||
--plugin-opt=-enable-ipra=true \
|
||||
--plugin-opt=-pi32v2-always-use-itblock \
|
||||
--plugin-opt=-pi32v2-merge-max-offset=64 \
|
||||
--plugin-opt=-global-merge-on-const \
|
||||
--plugin-opt=-pi32v2-enable-simd=true \
|
||||
--plugin-opt=-pi32v2-enable-rep-memop=true \
|
||||
--plugin-opt=mcpu=r3 \
|
||||
--plugin-opt=save-temps \
|
||||
--plugin-opt=-pi32v2-large-program=true \
|
||||
--start-group \
|
||||
--whole-archive \
|
||||
include_lib/liba/br35/ota_loader_driver.a \
|
||||
include_lib/liba/br35/system.a \
|
||||
include_lib/liba/br35/update.a \
|
||||
--no-whole-archive \
|
||||
--end-group \
|
||||
--start-group \
|
||||
include_lib/liba/br35/bt_protocol.a \
|
||||
--end-group \
|
||||
include_lib/liba/br35/btctrler_v2.a \
|
||||
--plugin-opt=mcpu=r3 \
|
||||
--plugin-opt=-mattr=+fprev1 \
|
||||
|
||||
|
||||
LIBPATHS := \
|
||||
-L$(SYS_LIB_DIR) \
|
||||
|
||||
|
||||
LIBS := \
|
||||
$(SYS_LIB_DIR)/libm.a \
|
||||
$(SYS_LIB_DIR)/libc.a \
|
||||
$(SYS_LIB_DIR)/libm.a \
|
||||
$(SYS_LIB_DIR)/libcompiler-rt.a \
|
||||
|
||||
|
||||
|
||||
c_OBJS := $(c_SRC_FILES:%.c=%.c.o)
|
||||
S_OBJS := $(S_SRC_FILES:%.S=%.S.o)
|
||||
s_OBJS := $(s_SRC_FILES:%.s=%.s.o)
|
||||
cpp_OBJS := $(cpp_SRC_FILES:%.cpp=%.cpp.o)
|
||||
cxx_OBJS := $(cxx_SRC_FILES:%.cxx=%.cxx.o)
|
||||
cc_OBJS := $(cc_SRC_FILES:%.cc=%.cc.o)
|
||||
|
||||
OBJS := $(c_OBJS) $(S_OBJS) $(s_OBJS) $(cpp_OBJS) $(cxx_OBJS) $(cc_OBJS)
|
||||
DEP_FILES := $(OBJS:%.o=%.d)
|
||||
|
||||
|
||||
OBJS := $(addprefix $(BUILD_DIR)/, $(OBJS))
|
||||
DEP_FILES := $(addprefix $(BUILD_DIR)/, $(DEP_FILES))
|
||||
|
||||
|
||||
VERBOSE ?= 0
|
||||
ifeq ($(VERBOSE), 1)
|
||||
QUITE :=
|
||||
else
|
||||
QUITE := @
|
||||
endif
|
||||
|
||||
# 一些旧的 make 不支持 file 函数,需要 make 的时候指定 LINK_AT=0 make
|
||||
LINK_AT ?= 1
|
||||
|
||||
# 表示下面的不是一个文件的名字,无论是否存在 all, clean, pre_build 这样的文件
|
||||
# 还是要执行命令
|
||||
# see: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
|
||||
.PHONY: all clean pre_build
|
||||
|
||||
# 不要使用 make 预设置的规则
|
||||
# see: https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html
|
||||
.SUFFIXES:
|
||||
|
||||
all: pre_build $(OUT_ELF)
|
||||
$(info +POST-BUILD)
|
||||
$(QUITE) $(RUN_POST_SCRIPT) ota_loader
|
||||
|
||||
pre_build:
|
||||
$(info +PRE-BUILD)
|
||||
$(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -D__LD__ -E -P cpu/br35/output/ram_ld.c -o cpu/br35/output/ram.ld
|
||||
|
||||
clean:
|
||||
$(QUITE) $(RM) $(OUT_ELF)
|
||||
$(QUITE) $(RM) $(BUILD_DIR)
|
||||
|
||||
|
||||
|
||||
ifeq ($(LINK_AT), 1)
|
||||
$(OUT_ELF): $(OBJS)
|
||||
$(info +LINK $@)
|
||||
$(shell $(MKDIR) $(@D))
|
||||
$(file >$(OBJ_FILE), $(OBJS))
|
||||
$(QUITE) $(LD) -o $(OUT_ELF) @$(OBJ_FILE) $(LFLAGS) $(LIBPATHS) $(LIBS)
|
||||
else
|
||||
$(OUT_ELF): $(OBJS)
|
||||
$(info +LINK $@)
|
||||
$(shell $(MKDIR) $(@D))
|
||||
$(QUITE) $(LD) -o $(OUT_ELF) $(OBJS) $(LFLAGS) $(LIBPATHS) $(LIBS)
|
||||
endif
|
||||
|
||||
|
||||
$(BUILD_DIR)/%.c.o : %.c
|
||||
$(info +CC $<)
|
||||
$(QUITE) $(MKDIR) $(@D)
|
||||
$(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MMD -MF $(@:.o=.d) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.S.o : %.S
|
||||
$(info +AS $<)
|
||||
$(QUITE) $(MKDIR) $(@D)
|
||||
$(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MMD -MF $(@:.o=.d) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.s.o : %.s
|
||||
$(info +AS $<)
|
||||
$(QUITE) $(MKDIR) $(@D)
|
||||
$(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MMD -MF $(@:.o=.d) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.cpp.o : %.cpp
|
||||
$(info +CXX $<)
|
||||
$(QUITE) $(MKDIR) $(@D)
|
||||
$(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -MMD -MF $(@:.o=.d) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.cxx.o : %.cxx
|
||||
$(info +CXX $<)
|
||||
$(QUITE) $(MKDIR) $(@D)
|
||||
$(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -MMD -MF $(@:.o=.d) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.cc.o : %.cc
|
||||
$(info +CXX $<)
|
||||
$(QUITE) $(MKDIR) $(@D)
|
||||
$(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -MMD -MF $(@:.o=.d) -c $< -o $@
|
||||
|
||||
-include $(DEP_FILES)
|
||||
@@ -0,0 +1,84 @@
|
||||
#ifndef _BLE_RCSP_SERVER_H_
|
||||
#define _BLE_RCSP_SERVER_H_
|
||||
|
||||
static const uint8_t profile_data[] = {
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// 0x0001 PRIMARY_SERVICE 1800
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18,
|
||||
|
||||
/* CHARACTERISTIC, 2a00, READ | WRITE | DYNAMIC, */
|
||||
// 0x0002 CHARACTERISTIC 2a00 READ | WRITE | DYNAMIC
|
||||
0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x0a, 0x03, 0x00, 0x00, 0x2a,
|
||||
// 0x0003 VALUE 2a00 READ | WRITE | DYNAMIC
|
||||
0x08, 0x00, 0x0a, 0x01, 0x03, 0x00, 0x00, 0x2a,
|
||||
|
||||
#if 1
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// 0x0004 PRIMARY_SERVICE ae00
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
0x0a, 0x00, 0x02, 0x00, 0x80, 0x00, 0x00, 0x28, 0x00, 0xae,
|
||||
|
||||
/* CHARACTERISTIC, ae01, WRITE_WITHOUT_RESPONSE | DYNAMIC, */
|
||||
// 0x0040 CHARACTERISTIC ae01 WRITE_WITHOUT_RESPONSE | DYNAMIC
|
||||
0x0d, 0x00, 0x02, 0x00, 0x81, 0x00, 0x03, 0x28, 0x04, 0x82, 0x00, 0x01, 0xae,
|
||||
// 0x0041 VALUE ae01 WRITE_WITHOUT_RESPONSE | DYNAMIC
|
||||
0x08, 0x00, 0x04, 0x01, 0x82, 0x00, 0x01, 0xae,
|
||||
|
||||
/* CHARACTERISTIC, ae02, NOTIFY, */
|
||||
// 0x0042 CHARACTERISTIC ae02 NOTIFY
|
||||
0x0d, 0x00, 0x02, 0x00, 0x83, 0x00, 0x03, 0x28, 0x10, 0x84, 0x00, 0x02, 0xae,
|
||||
// 0x0043 VALUE ae02 NOTIFY
|
||||
0x08, 0x00, 0x10, 0x00, 0x84, 0x00, 0x02, 0xae,
|
||||
// 0x0044 CLIENT_CHARACTERISTIC_CONFIGURATION
|
||||
0x0a, 0x00, 0x0a, 0x01, 0x85, 0x00, 0x02, 0x29, 0x00, 0x00,
|
||||
#else
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// 0x0007 PRIMARY_SERVICE 66F0
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
0x0a, 0x00, 0x02, 0x00, 0x07, 0x00, 0x00, 0x28, 0xf0, 0x66,
|
||||
|
||||
/* CHARACTERISTIC, 66F1, WRITE_WITHOUT_RESPONSE | DYNAMIC */
|
||||
// 0x0008 CHARACTERISTIC 66F1 WRITE_WITHOUT_RESPONSE | DYNAMIC
|
||||
0x0d, 0x00, 0x02, 0x00, 0x08, 0x00, 0x03, 0x28, 0x04, 0x09, 0x00, 0xf1, 0x66,
|
||||
// 0x0009 VALUE 66F1 WRITE_WITHOUT_RESPONSE | DYNAMIC
|
||||
0x08, 0x00, 0x04, 0x01, 0x09, 0x00, 0xf1, 0x66,
|
||||
|
||||
/* CHARACTERISTIC, 66F2, NOTIFY | DYNAMIC */
|
||||
// 0x000a CHARACTERISTIC 66F2 NOTIFY | DYNAMIC
|
||||
0x0d, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x03, 0x28, 0x10, 0x0b, 0x00, 0xf2, 0x66,
|
||||
// 0x000b VALUE 66F2 NOTIFY | DYNAMIC
|
||||
0x08, 0x00, 0x10, 0x01, 0x0b, 0x00, 0xf2, 0x66,
|
||||
// 0x000c CLIENT_CHARACTERISTIC_CONFIGURATION
|
||||
0x0a, 0x00, 0x0a, 0x01, 0x0c, 0x00, 0x02, 0x29, 0x00, 0x00,
|
||||
#endif
|
||||
// END
|
||||
0x00, 0x00,
|
||||
};
|
||||
//
|
||||
// characteristics <--> handles
|
||||
//
|
||||
#if 1
|
||||
#define ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE 0x0082
|
||||
#define ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE 0x0084
|
||||
#define ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE 0x0085
|
||||
#else
|
||||
#define ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE 0x0009
|
||||
#define ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE 0x000b
|
||||
#define ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE 0x000c
|
||||
#endif
|
||||
|
||||
#define ATT_CHARACTERISTIC_2a00_01_VALUE_HANDLE 0x0003
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#ifndef _CUSTOM_CFG_
|
||||
#define _CUSTOM_CFG_
|
||||
|
||||
#define VER_INFO_EXT_CONUNT 2
|
||||
#define VER_INFO_EXT_MAX_LEN 24
|
||||
|
||||
//是否支持鸿巨昌客户HID方案的配置
|
||||
#define CUSTOM_CFG_SUPPORT_HJC_HID_CASE_EN 1
|
||||
|
||||
enum {
|
||||
EX_CFG_ERR_NONE = 0,
|
||||
EX_CFG_INDEX_ERR,
|
||||
EX_CFG_LEN_OVER_TEMP_BUF_LEN_ERR,
|
||||
EX_CFG_CRC_ERR,
|
||||
EX_CFG_TMP_BUF_ERR,
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_ITEM_ADV_IND = 0,
|
||||
CFG_ITEM_SCAN_RSP,
|
||||
CFG_ITEM_BLE_NAME,
|
||||
CFG_ITEM_BT_ADDR,
|
||||
|
||||
CFG_ITEM_BT_NAME,
|
||||
CFG_ITEM_PIN_CODE,
|
||||
CFG_ITEM_VER_INFO,
|
||||
CFG_ITEM_LOWPOWER_VOLTAGE,
|
||||
|
||||
CFG_ITEM_EDR_ADDR,
|
||||
CFG_ITEM_BLE_ADDR,
|
||||
CFG_ITEM_GATT_PROFILE,
|
||||
CFG_ITEM_RESET_IO_INFO,
|
||||
|
||||
CFG_ITEM_PILOT_LAMP_IO_INFO,
|
||||
CFG_ITEM_LINK_KEY_INFO,
|
||||
CFG_ITEM_POWER_IO_OFF,
|
||||
CFG_ITEM_LAST_DEVICE_CONNECT_LINKKEY_INFO,
|
||||
|
||||
CFG_ITEM_BLE_READ_WRITE_UUID_INFO = 16,
|
||||
#if VER_INFO_EXT_CONUNT
|
||||
CFG_ITEM_VER_INFO_AUTHKEY,
|
||||
CFG_ITEM_VER_INFO_PROCODE,
|
||||
#endif
|
||||
CFG_ITEM_PVID,
|
||||
CFG_ITEM_MD5,
|
||||
CFG_ITEM_SDK_TYPE,
|
||||
};
|
||||
|
||||
typedef struct _update_file_id {
|
||||
u8 vid[2];
|
||||
u8 pid[2];
|
||||
u8 ver[2];
|
||||
u8 len[4];
|
||||
u8 reserve[4];
|
||||
u8 crc[2];
|
||||
} update_file_id_t;
|
||||
|
||||
typedef struct _update_file_ext_id {
|
||||
update_file_id_t update_file_id_info;
|
||||
#if VER_INFO_EXT_CONUNT
|
||||
u8 ext[VER_INFO_EXT_CONUNT * (VER_INFO_EXT_MAX_LEN + 1)];
|
||||
#endif
|
||||
} update_file_ext_id_t;
|
||||
|
||||
enum {
|
||||
GET_VID_FROM_CFG = 0,
|
||||
GET_PID_FROM_CFG,
|
||||
GET_VER_FROM_CFG,
|
||||
};
|
||||
|
||||
void ex_cfg_start_addr_set(u32 addr);
|
||||
u32 ex_cfg_get_content_api(u8 cfg_index, u8 *data, u16 len);
|
||||
u16 ex_cfg_get_local_version_info(u8 type);
|
||||
#if 0
|
||||
u16 ex_cfg_get_local_version_info(void);
|
||||
u16 ex_cfg_get_local_pid_info(void);
|
||||
u16 ex_cfg_get_local_vid_info(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : le_counter.h
|
||||
|
||||
* Description :
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2017-01-17 15:17
|
||||
|
||||
* Copyright:(c)JIELI 2011-2016 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
|
||||
#ifndef __LE_COMMON_H_
|
||||
#define __LE_COMMON_H_
|
||||
|
||||
typedef enum {
|
||||
BLE_ST_NULL = 0,
|
||||
BLE_ST_INIT_OK, //init ok
|
||||
BLE_ST_IDLE,
|
||||
BLE_ST_ADV,
|
||||
BLE_ST_CONNECT,
|
||||
BLE_ST_SEND_DISCONN,
|
||||
BLE_ST_NOTIFY_IDICATE,//server ok
|
||||
BLE_ST_SCAN,
|
||||
BLE_ST_SEARCH_COMPLETE,//client ok
|
||||
} ble_state_e;
|
||||
|
||||
|
||||
enum {
|
||||
APP_BLE_NO_ERROR = 0,
|
||||
APP_BLE_BUFF_ERROR = 1,
|
||||
APP_BLE_BUFF_FULL = 2,
|
||||
APP_BLE_OPERATION_ERROR = 3,
|
||||
APP_BLE_IS_DISCONN = 4,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
HCI_EIR_DATATYPE_FLAGS = 0x01,
|
||||
HCI_EIR_DATATYPE_MORE_16BIT_SERVICE_UUIDS = 0x02,
|
||||
HCI_EIR_DATATYPE_COMPLETE_16BIT_SERVICE_UUIDS = 0x03,
|
||||
HCI_EIR_DATATYPE_MORE_32BIT_SERVICE_UUIDS = 0x04,
|
||||
HCI_EIR_DATATYPE_COMPLETE_32BIT_SERVICE_UUIDS = 0x05,
|
||||
HCI_EIR_DATATYPE_MORE_128BIT_SERVICE_UUIDS = 0x06,
|
||||
HCI_EIR_DATATYPE_COMPLETE_128BIT_SERVICE_UUIDS = 0x07,
|
||||
HCI_EIR_DATATYPE_SHORTENED_LOCAL_NAME = 0x08,
|
||||
HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME = 0x09,
|
||||
HCI_EIR_DATATYPE_TX_POWER_LEVEL = 0x0A,
|
||||
HCI_EIR_DATATYPE_CLASS_OF_DEVICE = 0x0D,
|
||||
HCI_EIR_DATATYPE_SIMPLE_PAIRING_HASH_C = 0x0E,
|
||||
HCI_EIR_DATATYPE_SIMPLE_PAIRING_RANDOMIZER_R = 0x0F,
|
||||
HCI_EIR_DATATYPE_SECURITY_MANAGER_TK_VALUE = 0x10,
|
||||
HCI_EIR_DATATYPE_SECURITY_MANAGER_OOB_FLAGS = 0x11,
|
||||
HCI_EIR_DATATYPE_SLAVE_CONNECTION_INTERVAL_RANGE = 0x12,
|
||||
HCI_EIR_DATATYPE_16BIT_SERVICE_SOLICITATION_UUIDS = 0x14,
|
||||
HCI_EIR_DATATYPE_128BIT_SERVICE_SOLICITATION_UUIDS = 0x15,
|
||||
HCI_EIR_DATATYPE_SERVICE_DATA = 0x16,
|
||||
HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF
|
||||
} HCI_EIR_datatype_t;
|
||||
|
||||
#define ADV_RSP_PACKET_MAX 31
|
||||
|
||||
static inline u8 make_eir_packet_val(u8 *buf, u16 offset, u8 data_type, u32 val, u8 val_size)
|
||||
{
|
||||
if (ADV_RSP_PACKET_MAX - offset < val_size + 2) {
|
||||
return offset + val_size + 2;
|
||||
}
|
||||
|
||||
buf[0] = val_size + 1;
|
||||
buf[1] = data_type;
|
||||
memcpy(buf + 2, &val, val_size);
|
||||
return val_size + 2;
|
||||
}
|
||||
|
||||
static inline u8 make_eir_packet_data(u8 *buf, u16 offset, u8 data_type, u8 *data, u8 data_len)
|
||||
{
|
||||
if (ADV_RSP_PACKET_MAX - offset < data_len + 2) {
|
||||
return offset + data_len + 2;
|
||||
}
|
||||
|
||||
buf[0] = data_len + 1;
|
||||
buf[1] = data_type;
|
||||
memcpy(buf + 2, data, data_len);
|
||||
return data_len + 2;
|
||||
}
|
||||
#if 0
|
||||
#include "typedef.h"
|
||||
#include <stdint.h>
|
||||
|
||||
//--------------------------------------------
|
||||
|
||||
|
||||
struct conn_param_t {
|
||||
u16 interval;
|
||||
u16 latency;
|
||||
u16 timeout;
|
||||
};
|
||||
|
||||
// #define NOTIFY_TYPE 1
|
||||
// #define INDICATION_TYPE 2
|
||||
// Minimum/default MTU
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
BLE_ST_NULL = 0,
|
||||
BLE_ST_INIT_OK, //init ok
|
||||
BLE_ST_IDLE,
|
||||
BLE_ST_ADV,
|
||||
BLE_ST_CONNECT,
|
||||
BLE_ST_SEND_DISCONN,
|
||||
BLE_ST_NOTIFY_IDICATE,//server ok
|
||||
BLE_ST_SCAN,
|
||||
BLE_ST_SEARCH_COMPLETE,//client ok
|
||||
} ble_state_e;
|
||||
|
||||
|
||||
enum {
|
||||
APP_BLE_NO_ERROR = 0,
|
||||
APP_BLE_BUFF_ERROR = 1,
|
||||
APP_BLE_BUFF_FULL = 2,
|
||||
APP_BLE_OPERATION_ERROR = 3,
|
||||
APP_BLE_IS_DISCONN = 4,
|
||||
};
|
||||
|
||||
struct ble_server_operation_t {
|
||||
int(*adv_enable)(void *priv, u32 enable);
|
||||
int(*disconnect)(void *priv);
|
||||
int(*get_buffer_vaild)(void *priv);
|
||||
int(*send_data)(void *priv, void *buf, u16 len);
|
||||
int(*regist_wakeup_send)(void *priv, void *cbk);
|
||||
int(*regist_recieve_cbk)(void *priv, void *cbk);
|
||||
int(*regist_state_cbk)(void *priv, void *cbk);
|
||||
};
|
||||
void ble_get_server_operation_table(struct ble_server_operation_t **interface_pt);
|
||||
|
||||
|
||||
struct ble_client_operation_t {
|
||||
int(*scan_enable)(void *priv, u32 enable);
|
||||
int(*disconnect)(void *priv);
|
||||
int(*get_buffer_vaild)(void *priv);
|
||||
int(*write_data)(void *priv, void *buf, u16 len);
|
||||
int(*read_do)(void *priv);
|
||||
int(*regist_wakeup_send)(void *priv, void *cbk);
|
||||
int(*regist_recieve_cbk)(void *priv, void *cbk);
|
||||
int(*regist_state_cbk)(void *priv, void *cbk);
|
||||
};
|
||||
void ble_get_client_operation_table(struct ble_client_operation_t **interface_pt);
|
||||
|
||||
|
||||
extern void le_l2cap_register_packet_handler(void (*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef __TESTBOX_UPDATE_H__
|
||||
#define __TESTBOX_UPDATE_H__
|
||||
|
||||
enum {
|
||||
UPDATA_STOP = 0,
|
||||
UPDATA_OPEN,
|
||||
UPDATA_SEEK,
|
||||
UPDATA_READ,
|
||||
UPDATA_READ_OFFSIZE,
|
||||
UPDATA_STOP_KEYERR,
|
||||
UPDATA_ACCEPT_OK,
|
||||
UPDATA_WAIT_REBOOT,
|
||||
};
|
||||
|
||||
/* updata status */
|
||||
typedef enum {
|
||||
#ifdef EDR_UPDATA_SUPPORT_CONNECT
|
||||
UPDATA_START = 0x00,
|
||||
#else
|
||||
UPDATA_START = 0x01,
|
||||
#endif
|
||||
UPDATA_REV_DATA,
|
||||
} UPDATA_BIT_FLAG;
|
||||
|
||||
enum {
|
||||
BT_SEEK_SET = 0x01,
|
||||
BT_SEEK_CUR = 0x02,
|
||||
|
||||
BT_SEEK_TYPE_UPDATE_LEN = 0x10,
|
||||
};
|
||||
|
||||
typedef struct _testbox_update_info {
|
||||
u8 seek_type;
|
||||
u8 bt_reinit;
|
||||
volatile u8 state;
|
||||
volatile u32 file_offset; //文件偏移
|
||||
volatile u32 bt_time_timeout;
|
||||
u8 *read_buf;
|
||||
u32 data_len; //实际读取到的长度
|
||||
u32 need_rx_len;
|
||||
u32 mutil_ufw_offset; //多芯片升级方式
|
||||
} testbox_update_info;
|
||||
|
||||
#define UPDATE_CMD_WAIT_TIMEOUT (400UL) //unit:10ms 等待测试盒回复超时时间
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,199 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".cbuf.data.bss")
|
||||
#pragma data_seg(".cbuf.data")
|
||||
#pragma const_seg(".cbuf.text.const")
|
||||
#pragma code_seg(".cbuf.text")
|
||||
#endif
|
||||
#include "lib_include.h"
|
||||
#include "circular_buf.h"
|
||||
#if 1
|
||||
#define CPU_SR_ALLOC()
|
||||
|
||||
//#pragma code_seg(".cbuf_code")
|
||||
|
||||
u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len)
|
||||
{
|
||||
CPU_SR_ALLOC();
|
||||
u32 r_len = len;
|
||||
u32 copy_len;
|
||||
|
||||
if (!cbuffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((u32)cbuffer->read_ptr >= (u32)cbuffer->end) {
|
||||
cbuffer->read_ptr = (u8 *)cbuffer->begin;
|
||||
}
|
||||
|
||||
if (cbuffer->data_len < len) {
|
||||
/* memset(buf, 0, len); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
copy_len = (u32)cbuffer->end - (u32)cbuffer->read_ptr;
|
||||
if (copy_len > len) {
|
||||
copy_len = len;
|
||||
}
|
||||
len -= copy_len;
|
||||
|
||||
memcpy(buf, cbuffer->read_ptr, copy_len);
|
||||
//printf_data(cbuffer->read_ptr,copy_len) ;
|
||||
|
||||
if (len == 0) {
|
||||
cbuffer->read_ptr += copy_len;
|
||||
} else {
|
||||
memcpy((u8 *)buf + copy_len, cbuffer->begin, len);
|
||||
//printf_data(cbuffer->begin,len);
|
||||
cbuffer->read_ptr = cbuffer->begin + len;
|
||||
}
|
||||
|
||||
local_irq_disable();
|
||||
cbuffer->tmp_len = cbuffer->data_len -= r_len;
|
||||
|
||||
cbuffer->tmp_len = cbuffer->data_len;
|
||||
|
||||
local_irq_enable();
|
||||
|
||||
return r_len;
|
||||
}
|
||||
|
||||
u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len)
|
||||
{
|
||||
u32 w_len;
|
||||
|
||||
if (!cbuffer) {
|
||||
return 0;
|
||||
}
|
||||
w_len = cbuffer->total_len - cbuffer->data_len;
|
||||
if (w_len < len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return w_len;
|
||||
}
|
||||
|
||||
|
||||
u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len)
|
||||
{
|
||||
CPU_SR_ALLOC();
|
||||
u32 length;
|
||||
u32 remain_len;
|
||||
|
||||
if (!cbuffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((cbuffer->total_len - cbuffer->data_len) < len) {
|
||||
len = cbuffer->total_len - cbuffer->data_len ;
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
length = (u32)cbuffer->end - (u32)cbuffer->write_ptr;
|
||||
if (length >= len) {
|
||||
memcpy(cbuffer->write_ptr, buf, len);
|
||||
cbuffer->write_ptr += len;
|
||||
} else {
|
||||
remain_len = len - length;
|
||||
memcpy(cbuffer->write_ptr, buf, length);
|
||||
memcpy(cbuffer->begin, ((u8 *)buf) + length, remain_len);
|
||||
cbuffer->write_ptr = (u8 *)cbuffer->begin + remain_len;
|
||||
}
|
||||
|
||||
local_irq_disable();
|
||||
cbuffer->data_len += len;
|
||||
cbuffer->tmp_len = cbuffer->data_len ;
|
||||
cbuffer->tmp_ptr = cbuffer->write_ptr ;
|
||||
local_irq_enable();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size)
|
||||
{
|
||||
cbuffer->data_len = 0;
|
||||
cbuffer->tmp_len = 0 ;
|
||||
cbuffer->begin = buf;
|
||||
cbuffer->read_ptr = buf;
|
||||
cbuffer->write_ptr = buf;
|
||||
cbuffer->tmp_ptr = buf;
|
||||
cbuffer->end = (u8 *)buf + size;
|
||||
cbuffer->total_len = size;
|
||||
}
|
||||
|
||||
void cbuf_clear(cbuffer_t *cbuffer)
|
||||
{
|
||||
CPU_SR_ALLOC();
|
||||
local_irq_disable();
|
||||
cbuffer->read_ptr = cbuffer->begin;
|
||||
cbuffer->tmp_ptr = cbuffer->write_ptr = cbuffer->begin;
|
||||
cbuffer->data_len = 0;
|
||||
cbuffer->tmp_len = 0 ;
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
u32 cbuf_get_data_size(cbuffer_t *cbuffer)
|
||||
{
|
||||
//printf(">>cbuf_dat_len:%x\n",cbuffer->data_len);
|
||||
return cbuffer->data_len;
|
||||
}
|
||||
|
||||
#define CBUF_ENTER_CRITICAL local_irq_disable
|
||||
#define CBUF_EXIT_CRITICAL local_irq_enable
|
||||
|
||||
void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len)
|
||||
{
|
||||
CBUF_ENTER_CRITICAL();
|
||||
|
||||
cbuffer->read_ptr += len;
|
||||
if ((u32)cbuffer->read_ptr >= (u32)cbuffer->end) {
|
||||
cbuffer->read_ptr = (u8 *)cbuffer->begin + ((u32)cbuffer->read_ptr - (u32)cbuffer->end);
|
||||
}
|
||||
|
||||
cbuffer->tmp_len = cbuffer->data_len -= len;
|
||||
|
||||
CBUF_EXIT_CRITICAL();
|
||||
}
|
||||
u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len)
|
||||
{
|
||||
u32 r_len = len;
|
||||
u32 copy_len;
|
||||
|
||||
if (!cbuffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((u32)cbuffer->read_ptr >= (u32)cbuffer->end) {
|
||||
cbuffer->read_ptr = (u8 *)cbuffer->begin;
|
||||
}
|
||||
|
||||
if (cbuffer->data_len < len) {
|
||||
/* memset(buf, 0, len); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
copy_len = (u32)cbuffer->end - (u32)cbuffer->read_ptr;
|
||||
if (copy_len > len) {
|
||||
copy_len = len;
|
||||
}
|
||||
len -= copy_len;
|
||||
|
||||
memcpy(buf, cbuffer->read_ptr, copy_len);
|
||||
//printf_data(cbuffer->read_ptr,copy_len) ;
|
||||
|
||||
if (len == 0) {
|
||||
/* cbuffer->read_ptr += copy_len; */
|
||||
} else {
|
||||
memcpy((u8 *)buf + copy_len, cbuffer->begin, len);
|
||||
//printf_data(cbuffer->begin,len);
|
||||
/* cbuffer->read_ptr = cbuffer->begin + len; */
|
||||
}
|
||||
|
||||
return r_len;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,606 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".lbuf.data.bss")
|
||||
#pragma data_seg(".lbuf.data")
|
||||
#pragma const_seg(".lbuf.text.const")
|
||||
#pragma code_seg(".lbuf.text")
|
||||
#endif
|
||||
/* ******************************************
|
||||
*
|
||||
* |offset| hentry | priv | data|
|
||||
* | ret |
|
||||
* | |
|
||||
* |---------align--------|
|
||||
*
|
||||
* *****************************************/
|
||||
|
||||
#include "lbuf.h"
|
||||
#include "common.h"
|
||||
|
||||
#define LOG_TAG_CONST LBUF
|
||||
#define LOG_TAG "[LBUF]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#ifdef ALIGN
|
||||
#undef ALIGN
|
||||
#endif
|
||||
|
||||
#define ALIGN(a, b) \
|
||||
({ \
|
||||
int m = (u32)(a) & ((b)-1); \
|
||||
int ret = (u32)(a) + (m?((b)-m):0); \
|
||||
ret;\
|
||||
})
|
||||
|
||||
//计算数据包的最小长度和hentry管理结构体放一起后要对齐的偏移,lbuf管理结构体的默认对齐是4,但数据包的对齐可以任意指定所以需要进行对齐偏移计算
|
||||
#define LBUF_OFFSET(head) \
|
||||
({ \
|
||||
int m = (sizeof(struct hentry)+head->priv_len) & (head->align-1); \
|
||||
m?(head->align-m):0;\
|
||||
})
|
||||
|
||||
|
||||
//根据hentry结构体大小得到hentry结构体地址
|
||||
#define __get_entry(lbuf) \
|
||||
(struct hentry *)((u8 *)lbuf - sizeof(struct hentry))
|
||||
|
||||
#if LBUF_DEBUG
|
||||
|
||||
#define lbuf_entry_check0(head, entry,rets) \
|
||||
do { \
|
||||
ASSERT(entry->magic_a == 0x12345678 && entry->magic_b == 0x23456789, \
|
||||
"%d,%x,%x,%x\n", __LINE__, entry->magic_a, entry->magic_b,rets); \
|
||||
ASSERT(head->magic_a == 0x87654321 && head->magic_b == 0x98765432, \
|
||||
"%d,%p,%x,%x,%x,%x\n", __LINE__, head, head->total_size, head->magic_a, head->magic_b,rets); \
|
||||
} while(0)
|
||||
|
||||
#define lbuf_entry_check(head, entry) \
|
||||
do { \
|
||||
ASSERT(entry->magic_a == 0x12345678 && entry->magic_b == 0x23456789, \
|
||||
"%d,%x,%x\n", __LINE__, entry->magic_a, entry->magic_b); \
|
||||
ASSERT(head->magic_a == 0x87654321 && head->magic_b == 0x98765432, \
|
||||
"%d,%p,%x,%x,%x\n", __LINE__, head, head->total_size, head->magic_a, head->magic_b); \
|
||||
} while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define lbuf_entry_check0(head, entry,rets) do { } while (0)
|
||||
#define lbuf_entry_check(head, entry) do { } while (0)
|
||||
|
||||
#endif
|
||||
|
||||
struct hfree {
|
||||
struct list_head entry;
|
||||
u32 len;
|
||||
};
|
||||
|
||||
struct hentry {
|
||||
#if LBUF_DEBUG
|
||||
int magic_a;
|
||||
#endif
|
||||
struct list_head entry;
|
||||
#ifdef LBUFF_MALLOC_LARGE_MEM
|
||||
u32 len;
|
||||
///hentry结构体与lbuf_head结构体的头地址的偏移
|
||||
u32 offset;
|
||||
#else
|
||||
u16 len;
|
||||
///hentry结构体与lbuf_head结构体的头地址的偏移
|
||||
u16 offset;
|
||||
#endif
|
||||
///需要被读的次数
|
||||
u8 ref;
|
||||
///需要映射的通道
|
||||
u8 channel_map;
|
||||
#if LBUF_DEBUG
|
||||
int magic_b;
|
||||
#endif
|
||||
int rets;
|
||||
};
|
||||
|
||||
|
||||
struct lbuff_head *lbuf_init(void *buf, u32 len, int align, int priv_head_len)
|
||||
{
|
||||
struct hfree *free;
|
||||
//首地址4对齐
|
||||
struct lbuff_head *head = (struct lbuff_head *)ALIGN(buf, 4);
|
||||
//用户使用的地址按照用户的需求进行对齐
|
||||
free = (struct hfree *)ALIGN(head + 1, align);
|
||||
free->len = len - ((u8 *)free - (u8 *)buf);
|
||||
|
||||
head->align = align;
|
||||
head->priv_len = priv_head_len;
|
||||
head->last_addr = 0;
|
||||
#if LBUF_DEBUG
|
||||
head->magic_a = 0x87654321;
|
||||
head->magic_b = 0x98765432;
|
||||
#endif
|
||||
head->total_size = len;
|
||||
|
||||
spin_lock_init(&head->lock);
|
||||
INIT_LIST_HEAD(&head->head);
|
||||
INIT_LIST_HEAD(&head->free);
|
||||
|
||||
list_add_tail(&free->entry, &head->free);
|
||||
|
||||
//log_info("0000000000000000lbuf_init: %p,%x\n", head, (u32)head + len);
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
int lbuf_avaliable(struct lbuff_head *head, int size)
|
||||
{
|
||||
struct hfree *p;
|
||||
int avaliable = 0;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
int offset = LBUF_OFFSET(head);
|
||||
size = ALIGN(sizeof(struct hentry) + head->priv_len + offset + size, head->align);
|
||||
|
||||
list_for_each_entry(p, &head->free, entry) {
|
||||
avaliable += p->len / size;
|
||||
}
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
|
||||
return avaliable;
|
||||
}
|
||||
|
||||
void lbuf_state(struct lbuff_head *head, struct lbuff_state *state)
|
||||
{
|
||||
struct hfree *p, *max = NULL;
|
||||
|
||||
state->num = 0;
|
||||
state->fragment = 0;
|
||||
state->avaliable = 0 ;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
list_for_each_entry(p, &head->free, entry) {
|
||||
state->fragment ++;
|
||||
state->avaliable += p->len;
|
||||
state->num++;
|
||||
// log_info("lbuf_state: %x, %x\n", p, p->len);
|
||||
if (!max || max->len < p->len) {
|
||||
max = p;
|
||||
}
|
||||
}
|
||||
|
||||
if (!max) {
|
||||
state->max_continue_len = 0;
|
||||
} else {
|
||||
int offset = LBUF_OFFSET(head);
|
||||
state->max_continue_len = max->len -
|
||||
sizeof(struct hentry) - head->priv_len - offset;
|
||||
}
|
||||
spin_unlock(&head->lock);
|
||||
}
|
||||
|
||||
|
||||
void lbuf_dump(struct lbuff_head *head)
|
||||
{
|
||||
int total_size = 0;
|
||||
struct hfree *p, *n;
|
||||
struct hentry *h;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
list_for_each_entry_safe(p, n, &head->free, entry) {
|
||||
/* log_info("fragment: %x, %x\n", (u32)p, p->len); */
|
||||
total_size += p->len;
|
||||
}
|
||||
|
||||
list_for_each_entry(h, &head->head, entry) {
|
||||
/* log_info("alloc: %x, %x, call_from: %x\n", h, h->len, h->rets); */
|
||||
}
|
||||
|
||||
log_info("lbuf_state:%x,%x\n", head->total_size, total_size);
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
}
|
||||
|
||||
u32 lbuf_free_space(struct lbuff_head *head)
|
||||
{
|
||||
int max_len = 0;
|
||||
struct hfree *p;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
///找到最大的内存块
|
||||
list_for_each_entry(p, &head->free, entry) {
|
||||
if (max_len < p->len) {
|
||||
max_len = p->len;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
|
||||
int len = sizeof(struct hentry) + LBUF_OFFSET(head) + head->priv_len;
|
||||
if (max_len >= len) {
|
||||
max_len -= len;
|
||||
max_len &= ~(head->align - 1);
|
||||
return max_len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *lbuf_alloc(struct lbuff_head *head, u32 len)
|
||||
{
|
||||
int offset;
|
||||
int max_len = 0;
|
||||
void *ret = NULL;
|
||||
struct hfree *p;
|
||||
struct hfree *new;
|
||||
struct hfree *free = NULL, *free_0 = NULL;
|
||||
struct hentry *entry;
|
||||
u32 rets_addr;
|
||||
__asm__ volatile("%0 = rets ;" : "=r"(rets_addr));
|
||||
/* printf("lbuf_alloc:0x%x %d\n", rets_addr, len); */
|
||||
|
||||
//计算数据包的最小长度和hentry管理结构体放一起后要对齐的偏移
|
||||
offset = LBUF_OFFSET(head);
|
||||
//申请的内存需要对齐的长度
|
||||
len = ALIGN(sizeof(*entry) + head->priv_len + offset + len, head->align);
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
list_for_each_entry(p, &head->free, entry) {
|
||||
//长度越界检查
|
||||
if ((u8 *)p <= (u8 *)head || (u8 *)p > (u8 *)head + head->total_size) {
|
||||
asm("trigger");
|
||||
log_info("alloc-er1: %x, %x, %x\n", (u32)head->free.next, (u32)p, p->len);
|
||||
}
|
||||
//在hfree管理块中寻找一块足够长度的内存块
|
||||
if (p->len < len) {
|
||||
continue;
|
||||
}
|
||||
//找到了
|
||||
if (!free || free->len > p->len) {
|
||||
free = p;
|
||||
}
|
||||
//尽量找一块是在上一次内存分割后面的内存块,避免内存碎片
|
||||
if ((u32)p > head->last_addr && !free_0) {
|
||||
free_0 = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p = free_0 ? free_0 : free;
|
||||
|
||||
if (p) {
|
||||
head->last_addr = (u32)p;
|
||||
|
||||
//剩余的长度可以进行hfree结构体管理的内存分配
|
||||
if (p->len > len + sizeof(struct hfree)) {
|
||||
new = (struct hfree *)((u8 *)p + len);
|
||||
new->len = p->len - len;
|
||||
//hfree管理的内存进行分割
|
||||
__list_add(&new->entry, p->entry.prev, p->entry.next);
|
||||
} else {
|
||||
len = p->len;
|
||||
__list_del_entry(&p->entry);
|
||||
}
|
||||
|
||||
//进行hentry结构体管理的内存分配
|
||||
entry = (struct hentry *)((u8 *)p + offset);
|
||||
entry->len = len;
|
||||
entry->offset = (u8 *)entry - (u8 *)head;
|
||||
entry->channel_map = 0;
|
||||
entry->ref = 1;
|
||||
#if LBUF_DEBUG
|
||||
entry->magic_a = 0x12345678;
|
||||
entry->magic_b = 0x23456789;
|
||||
#endif
|
||||
INIT_LIST_HEAD(&entry->entry);
|
||||
|
||||
//返回hentry结构体后面的地址进行存储数据包
|
||||
ret = entry + 1;
|
||||
}
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
|
||||
if (ret == NULL) {
|
||||
/*log_info("alloc-err: %x\n", len);*/
|
||||
/*putchar('#');*/
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lbuf_remain_space(struct lbuff_head *head)
|
||||
{
|
||||
int max_len = 0;
|
||||
struct hfree *p;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
list_for_each_entry(p, &head->free, entry) {
|
||||
max_len += p->len;
|
||||
}
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
|
||||
return max_len;
|
||||
}
|
||||
|
||||
void *lbuf_realloc(void *lbuf, int size)
|
||||
{
|
||||
int len;
|
||||
int offset;
|
||||
int head_len;
|
||||
struct hentry *new;
|
||||
struct hentry *entry = __get_entry(lbuf);
|
||||
struct lbuff_head *head = (struct lbuff_head *)((u8 *)entry - entry->offset);
|
||||
|
||||
lbuf_entry_check(head, entry);
|
||||
// log_info("realloc: %x, %x\n", entry->len, size);
|
||||
|
||||
///把size变成align的倍数
|
||||
size = ALIGN(size, head->align);
|
||||
|
||||
ASSERT(size <= entry->len);
|
||||
///不能大于原来的len
|
||||
if (size >= entry->len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
offset = LBUF_OFFSET(head);
|
||||
|
||||
|
||||
///计算一个数据包的头结构的偏移长度
|
||||
head_len = offset + sizeof(*entry) + head->priv_len;
|
||||
|
||||
///是否能放下两个最小的数据头
|
||||
if (entry->len - size < 2 * head_len) {
|
||||
return lbuf;
|
||||
}
|
||||
///是否能够放下hfree结构体
|
||||
if (entry->len - size < sizeof(struct hfree)) {
|
||||
return lbuf;
|
||||
}
|
||||
|
||||
len = entry->len;
|
||||
///实际的长度为数据头长度+分配的长度
|
||||
entry->len = head_len + size;
|
||||
|
||||
new = (struct hentry *)((u8 *)lbuf + head->priv_len + size + offset);
|
||||
new->channel_map = 0;
|
||||
new->ref = 1;
|
||||
new->len = len - entry->len;
|
||||
new->offset = (u8 *)new - (u8 *)head;
|
||||
#if LBUF_DEBUG
|
||||
new->magic_a = 0x12345678;
|
||||
new->magic_b = 0x23456789;
|
||||
#endif
|
||||
//初始化hentry的内核链表结构体
|
||||
INIT_LIST_HEAD(&new->entry);
|
||||
|
||||
///释放new指向的内存空间,即释放重新分配size大小空间后的剩余的空间
|
||||
lbuf_free(new + 1);
|
||||
|
||||
return lbuf;
|
||||
}
|
||||
|
||||
|
||||
int lbuf_empty(struct lbuff_head *head)
|
||||
{
|
||||
if (list_empty(&head->head)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void lbuf_clear(struct lbuff_head *head)
|
||||
{
|
||||
struct hentry *p, *n;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
list_for_each_entry_safe(p, n, &head->head, entry) {
|
||||
lbuf_free(p + 1);
|
||||
}
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
}
|
||||
|
||||
int lbuf_real_size(void *lbuf)
|
||||
{
|
||||
struct hentry *entry = __get_entry(lbuf);
|
||||
|
||||
return entry->len;
|
||||
}
|
||||
|
||||
void lbuf_inc_ref(void *lbuf)
|
||||
{
|
||||
struct hentry *entry = __get_entry(lbuf);
|
||||
|
||||
entry->ref++;
|
||||
}
|
||||
|
||||
void lbuf_push(void *lbuf, u8 channel_map)
|
||||
{
|
||||
int i;
|
||||
//根据hentry结构体大小得到hentry结构体地址
|
||||
struct hentry *p = __get_entry(lbuf);
|
||||
//根据offset得到head结构体地址
|
||||
struct lbuff_head *head = (struct lbuff_head *)((u8 *)p - p->offset);
|
||||
|
||||
lbuf_entry_check(head, p);
|
||||
ASSERT(channel_map != 0);
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
///检测需要被读的次数
|
||||
p->ref = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (channel_map & BIT(i)) {
|
||||
p->ref++;
|
||||
}
|
||||
}
|
||||
p->channel_map = channel_map;
|
||||
///检测hentry管理结构体的内存是否被破坏
|
||||
if (list_empty(&p->entry)) {
|
||||
lbuf_entry_check(head, p);
|
||||
|
||||
ASSERT(((u32)p->entry.next & 0x03) == 0, "%p,%p", head, p->entry.next);
|
||||
ASSERT(((u32)p->entry.prev & 0x03) == 0, "%p,%p", head, p->entry.prev);
|
||||
ASSERT(((u32)head->head.prev & 0x03) == 0, "%p,%x,%p", head, head->total_size, head->head.prev);
|
||||
ASSERT(((u32)head->head.next & 0x03) == 0, "%p,%x,%p", head, head->total_size, head->head.next);
|
||||
///把hentry链表添加到lbuf_head结构体
|
||||
list_add_tail(&p->entry, &head->head);
|
||||
}
|
||||
lbuf_entry_check(head, p);
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
}
|
||||
|
||||
int lbuf_traversal(struct lbuff_head *head)
|
||||
{
|
||||
struct hentry *p;
|
||||
int num = 0;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
list_for_each_entry(p, &head->head, entry) {
|
||||
num++;
|
||||
}
|
||||
spin_unlock(&head->lock);
|
||||
return num;
|
||||
}
|
||||
|
||||
void *lbuf_pop(struct lbuff_head *head, u8 channel)
|
||||
{
|
||||
struct hentry *p;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
//从头进行查找符合通道映射值的hentry内存块
|
||||
list_for_each_entry(p, &head->head, entry) {
|
||||
if (p->channel_map & channel) {
|
||||
//对应的通道映射值置0
|
||||
p->channel_map &= ~channel;
|
||||
spin_unlock(&head->lock);
|
||||
lbuf_entry_check(head, p);
|
||||
return p + 1;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&head->lock);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void lbuf_free_check(void *lbuf, u32 rets)
|
||||
{
|
||||
struct hentry *entry;
|
||||
struct lbuff_head *head;
|
||||
|
||||
if (lbuf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
entry = __get_entry(lbuf);
|
||||
head = (struct lbuff_head *)((u8 *)entry - entry->offset);
|
||||
|
||||
lbuf_entry_check0(head, entry, rets);
|
||||
}
|
||||
|
||||
|
||||
int lbuf_free(void *lbuf)
|
||||
{
|
||||
int ret = 0;
|
||||
int offset;
|
||||
struct hfree *p;
|
||||
struct hfree *new;
|
||||
struct hfree *prev = NULL;
|
||||
struct hfree *next;
|
||||
struct hentry *entry;
|
||||
struct lbuff_head *head;
|
||||
u32 rets_addr;
|
||||
__asm__ volatile("%0 = rets ;" : "=r"(rets_addr));
|
||||
|
||||
if (lbuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
///得到hentry
|
||||
entry = __get_entry(lbuf);
|
||||
///得到lbuf_head
|
||||
head = (struct lbuff_head *)((u8 *)entry - entry->offset);
|
||||
|
||||
lbuf_entry_check0(head, entry, rets_addr);
|
||||
|
||||
offset = LBUF_OFFSET(head);
|
||||
///得到hfree入口地址并初始化
|
||||
new = (struct hfree *)((u8 *)entry - offset);
|
||||
int len = entry->len;
|
||||
|
||||
spin_lock(&head->lock);
|
||||
|
||||
///异常!该数据包的通道映射还没有被读完,ref--后返回
|
||||
if (--entry->ref > 0) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
#if LBUF_DEBUG
|
||||
entry->magic_a = 0x01234567;
|
||||
#endif
|
||||
|
||||
///删除lbuf_head的hentry
|
||||
__list_del_entry(&entry->entry);
|
||||
new->len = len;
|
||||
|
||||
///hfree轮询
|
||||
list_for_each_entry(p, &head->free, entry) {
|
||||
///地址越界检查
|
||||
if ((u8 *)p <= (u8 *)head || (u8 *)p > (u8 *)head + head->total_size) {
|
||||
asm("trigger");
|
||||
log_info("free-err1: %x, %x, %x, %x, %x, %x %x\n", rets_addr, (u32)lbuf, new->len, head, head->free.next, (u32)p, p->len, rets_addr);
|
||||
goto _exit;
|
||||
}
|
||||
if ((p <= new) && ((u8 *)p + p->len > (u8 *)new)) {
|
||||
asm("trigger");
|
||||
log_info("free-err: %x, %x, %x, %x %x\n", (u32)lbuf, new->len, (u32)p, p->len, rets_addr);
|
||||
goto _exit;
|
||||
}
|
||||
//按地址高低进行排序,把释放的内存块放入hfree链表
|
||||
if (p > new) {
|
||||
__list_add(&new->entry, p->entry.prev, &p->entry);
|
||||
goto __free;
|
||||
}
|
||||
}
|
||||
///加入hfree链表尾部
|
||||
list_add_tail(&new->entry, &head->free);
|
||||
|
||||
__free:
|
||||
///得到hfree结构体
|
||||
prev = list_entry(new->entry.prev, struct hfree, entry);
|
||||
next = list_entry(new->entry.next, struct hfree, entry);
|
||||
///两块紧挨的内存块进行合并
|
||||
if ((u32)prev + prev->len == (u32)new) {
|
||||
prev->len += new->len;
|
||||
__list_del_entry(&new->entry);
|
||||
new = prev;
|
||||
}
|
||||
if ((u32)new + new->len == (u32)next) {
|
||||
new->len += next->len;
|
||||
__list_del_entry(&next->entry);
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
_exit:
|
||||
spin_unlock(&head->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".msg.data.bss")
|
||||
#pragma data_seg(".msg.data")
|
||||
#pragma const_seg(".msg.text.const")
|
||||
#pragma code_seg(".msg.text")
|
||||
#endif
|
||||
#include "msg.h"
|
||||
#include "circular_buf.h"
|
||||
#include "common.h"
|
||||
#include "printf.h"
|
||||
#include "os/os_cpu.h"
|
||||
#include "wdt.h"
|
||||
|
||||
static cbuffer_t msg_cbuf;
|
||||
static u32 msg_pool[MAX_POOL];
|
||||
|
||||
void sys_nop_delay(void)
|
||||
{
|
||||
//__builtin_pi32v2_nop();
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
|
||||
int task_get_msg(u16 timeout, int len, int *msg)
|
||||
{
|
||||
int msg_value = 0;
|
||||
u8 param_len = 0;
|
||||
int i = 0;
|
||||
int param;
|
||||
u32 event, event_to_msg;
|
||||
//debug
|
||||
for (i = 0; i < len; i++) {
|
||||
msg[i] = 0xffff;
|
||||
}
|
||||
|
||||
//get_msg
|
||||
wdt_clear();
|
||||
CPU_SR_ALLOC();
|
||||
OS_ENTER_CRITICAL();
|
||||
#if USE_EVENT_EN
|
||||
event = get_event();
|
||||
if (event != NO_EVENT) {
|
||||
clear_one_event(event);
|
||||
event_to_msg = evnet2msg[event];
|
||||
msg[0] = event_to_msg;
|
||||
//printf("event_mag %d\n ", event_to_msg);
|
||||
OS_EXIT_CRITICAL();
|
||||
return MSG_NO_ERROR;
|
||||
}
|
||||
#endif
|
||||
if (2 != cbuf_read(&msg_cbuf, (void *)&msg_value, 2)) {
|
||||
/* memset(msg, NO_MSG, len); */
|
||||
OS_EXIT_CRITICAL();
|
||||
|
||||
/*get no msg,cpu enter idle*/
|
||||
sys_nop_delay();
|
||||
|
||||
return MSG_NO_ERROR;
|
||||
}
|
||||
//msg[0] = msg_value;
|
||||
//param_len = msg_value >> 12;
|
||||
param_len = msg_value;
|
||||
for (i = 0 ; i < param_len; i++) {
|
||||
cbuf_read(&msg_cbuf, (void *)¶m, 4);
|
||||
if (i < len) {
|
||||
msg[i] = param;
|
||||
}
|
||||
}
|
||||
if (i >= len) {
|
||||
puts("msg_buf_not_enc\n");
|
||||
OS_EXIT_CRITICAL();
|
||||
return MSG_BUF_NOT_ENOUGH;
|
||||
}
|
||||
OS_EXIT_CRITICAL();
|
||||
return MSG_NO_ERROR;
|
||||
}
|
||||
|
||||
#if USB_HID_MODULE_CONTROL
|
||||
extern void rcsp_hid_loop_resume(void);
|
||||
#else
|
||||
extern void stack_run_loop_resume();
|
||||
#endif
|
||||
int task_post_msg_base(const char *name, int argc, int cmd, int *argv)
|
||||
{
|
||||
u16 msg_value = 0x0fff;
|
||||
int i = 0;
|
||||
int param_len = 0;
|
||||
int param = 0;
|
||||
|
||||
if (0xff == cmd) {
|
||||
printf("cmd == 0xff\n");
|
||||
#if USB_HID_MODULE_CONTROL
|
||||
rcsp_hid_loop_resume();
|
||||
#else
|
||||
stack_run_loop_resume();
|
||||
#endif
|
||||
return MSG_NO_ERROR;
|
||||
}
|
||||
|
||||
CPU_SR_ALLOC();
|
||||
OS_ENTER_CRITICAL();
|
||||
//va_list argptr;
|
||||
//va_start(argptr, argc);
|
||||
/* printf("msg:cnt:%x\n", argc); */
|
||||
for (i = 0; i < argc + 1; ++i) {
|
||||
if (i == 0) {
|
||||
param_len = argc;
|
||||
msg_value = param_len & 0xffff;
|
||||
/* printf("msg[0]:%x\n",msg_value); */
|
||||
if (cbuf_write(&msg_cbuf, (void *)&msg_value, 2) != 2) {
|
||||
ASSERT(0, "stack message full! %d\n", __LINE__);
|
||||
}
|
||||
|
||||
} else {
|
||||
//param = va_arg(argptr, int);
|
||||
if (i == 1) {
|
||||
param = cmd;
|
||||
} else {
|
||||
param = argv[i - 2];
|
||||
}
|
||||
/* printf("msg[%d]:%x\n", i, param); */
|
||||
if (cbuf_write(&msg_cbuf, (void *)¶m, 4) != 4) {
|
||||
ASSERT(0, "stack message full! %d\n", __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
//va_end(argptr);
|
||||
OS_EXIT_CRITICAL();
|
||||
#if USB_HID_MODULE_CONTROL
|
||||
rcsp_hid_loop_resume();
|
||||
#else
|
||||
stack_run_loop_resume();
|
||||
#endif
|
||||
return MSG_NO_ERROR;
|
||||
}
|
||||
int task_post_msg(char *name, int argc, ...)
|
||||
{
|
||||
int argv[8];
|
||||
va_list argptr;
|
||||
|
||||
ASSERT(argc <= 8);
|
||||
|
||||
va_start(argptr, argc);
|
||||
|
||||
u8 i;
|
||||
for (i = 0; i < argc; i++) {
|
||||
argv[i] = va_arg(argptr, int);
|
||||
}
|
||||
|
||||
va_end(argptr);
|
||||
|
||||
//puts("msg_push:\n");
|
||||
//put_buf((u8 *)argv,argc*4);
|
||||
return task_post_msg_base(name, argc, argv[0], &argv[1]);
|
||||
}
|
||||
void task_clear_all_message(void)
|
||||
{
|
||||
cbuf_clear(&msg_cbuf);
|
||||
}
|
||||
|
||||
void task_message_init(void)
|
||||
{
|
||||
cbuf_init(&msg_cbuf, msg_pool, sizeof(msg_pool));
|
||||
cbuf_clear(&msg_cbuf);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,475 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".sys_timer.data.bss")
|
||||
#pragma data_seg(".sys_timer.data")
|
||||
#pragma const_seg(".sys_timer.text.const")
|
||||
#pragma code_seg(".sys_timer.text")
|
||||
#endif
|
||||
#include "sys_timer.h"
|
||||
#include "timer.h"
|
||||
#include "jiffies.h"
|
||||
#include "spinlock.h"
|
||||
//#include "cpu.h"
|
||||
|
||||
#define TIMER_US_ENABLE 0
|
||||
|
||||
void (*sys_timer_delay_handler)();
|
||||
struct list_head timer_head;
|
||||
struct list_head timer_us_head;
|
||||
/* volatile unsigned long jiffies; */
|
||||
volatile unsigned long jiffies_us;
|
||||
|
||||
|
||||
void *get_sys_timer_head()
|
||||
{
|
||||
return &timer_head;
|
||||
}
|
||||
|
||||
u32 get_jiffies(u8 mode, u32 timer_ms)
|
||||
{
|
||||
if (mode == 1) {
|
||||
jiffies += timer_ms / 10;
|
||||
|
||||
}
|
||||
return jiffies;
|
||||
}
|
||||
|
||||
bool __timer_find(struct sys_timer *timer)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
if (p == timer) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if TIMER_US_ENABLE
|
||||
bool __timer_us_find(struct sys_timer *timer)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
|
||||
list_for_each_entry(p, &timer_us_head, entry) {
|
||||
if (p == timer) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void __timer_insert(struct sys_timer *timer)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
if (p == timer) {
|
||||
list_del(&p->entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
if (p->jiffies > timer->jiffies) {
|
||||
__list_add(&timer->entry, p->entry.prev, &p->entry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
list_add_tail((struct list_head *)&timer->entry, (struct list_head *)&timer_head);
|
||||
}
|
||||
|
||||
#if TIMER_US_ENABLE
|
||||
void __timer_us_insert(struct sys_timer *timer)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
list_for_each_entry(p, &timer_us_head, entry) {
|
||||
if (p == timer) {
|
||||
list_del(&p->entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
list_for_each_entry(p, &timer_us_head, entry) {
|
||||
if (p->jiffies > timer->jiffies) {
|
||||
__list_add(&timer->entry, p->entry.prev, &p->entry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
list_add_tail((struct list_head *)&timer->entry, (struct list_head *)&timer_us_head);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TIMER_US_ENABLE
|
||||
void sys_timer_us_register(struct sys_timer *timer, u32 us_sec,
|
||||
void (*fun)(struct sys_timer *timer), u8 delay_do)
|
||||
{
|
||||
local_irq_disable();
|
||||
|
||||
timer->loop = 0;
|
||||
timer->delay_do = delay_do;
|
||||
timer->fun = fun;
|
||||
timer->jiffies = jiffies_us + msecs_to_jiffies_10(us_sec);
|
||||
//printf("timer->jiffies=%d,%d\n", jiffies_us, timer->jiffies);
|
||||
__timer_us_insert(timer);
|
||||
|
||||
local_irq_enable();
|
||||
}
|
||||
#endif
|
||||
|
||||
void sys_hi_timer_schedule()
|
||||
{
|
||||
struct sys_timer *p, *n;
|
||||
|
||||
local_irq_disable();
|
||||
|
||||
/* jiffies++; */
|
||||
list_for_each_entry_safe(p, n, &timer_head, entry) {
|
||||
if (time_before(jiffies, p->jiffies)) {
|
||||
break;
|
||||
}
|
||||
//putchar('s');
|
||||
if (sys_timer_delay_handler) {
|
||||
sys_timer_delay_handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
#if TIMER_US_ENABLE
|
||||
static void sys_timer_us_schedule()
|
||||
{
|
||||
struct sys_timer *p, *n;
|
||||
u8 do_fun_flag = 0;
|
||||
|
||||
local_irq_disable();
|
||||
|
||||
jiffies_us++;
|
||||
list_for_each_entry_safe(p, n, &timer_us_head, entry) {
|
||||
if (time_before(jiffies_us, p->jiffies)) {
|
||||
break;
|
||||
}
|
||||
if (sys_timer_delay_handler) {
|
||||
sys_timer_delay_handler();
|
||||
}
|
||||
}
|
||||
local_irq_enable();
|
||||
}
|
||||
void loop_timer_us_schedule()
|
||||
{
|
||||
struct sys_timer *p, *n;
|
||||
u8 do_fun_flag = 0;
|
||||
|
||||
local_irq_disable();
|
||||
|
||||
list_for_each_entry_safe(p, n, &timer_us_head, entry) {
|
||||
if (time_before(jiffies_us, p->jiffies)) {
|
||||
break;
|
||||
}
|
||||
sys_timer_us_remove(p);
|
||||
do_fun_flag = 0xaa;
|
||||
break;
|
||||
}
|
||||
|
||||
local_irq_enable();
|
||||
if (do_fun_flag == 0xaa) {
|
||||
ASSERT(p->fun != NULL);
|
||||
p->fun(p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static DEFINE_SPINLOCK(lock);
|
||||
#if (defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)) && defined(BLE_APP_LOW_RAM_USED) // bd47 内存紧缺
|
||||
#define TIMER_POOL_NUM_CONFIG 5
|
||||
#else
|
||||
#define TIMER_POOL_NUM_CONFIG 10
|
||||
#endif
|
||||
static struct sys_timer timer_pool[TIMER_POOL_NUM_CONFIG] = {0};
|
||||
static u16 global_id = 0;
|
||||
|
||||
|
||||
static struct sys_timer *__sys_timer_get(void *priv, void (*func)(void *priv),
|
||||
u32 msec, int timeout)
|
||||
{
|
||||
struct sys_timer *t = NULL;
|
||||
|
||||
spin_lock(&lock);
|
||||
int i;
|
||||
for (i = 0; i < ARRAY_SIZE(timer_pool); i++) {
|
||||
if (timer_pool[i].used == 0) {
|
||||
timer_pool[i].used = 1;
|
||||
t = &timer_pool[i];
|
||||
spin_unlock(&lock);
|
||||
goto __next;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&lock);
|
||||
if (i == ARRAY_SIZE(timer_pool)) {
|
||||
/* puts("<<<tiemr pool full>>>\n"); */
|
||||
}
|
||||
|
||||
__next:
|
||||
t->priv = priv;
|
||||
t->func = func;
|
||||
t->msec = msec;
|
||||
t->del = 0;
|
||||
//t->posting = 0;
|
||||
t->timeout = timeout;
|
||||
t->jiffies = jiffies + msecs_to_jiffies(msec);
|
||||
|
||||
t->id = ++global_id;
|
||||
if (t->id == 0) {
|
||||
t->id = (u16)func;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static int __timer_put(struct sys_timer *timer)
|
||||
{
|
||||
if (timer >= timer_pool && timer < timer_pool + ARRAY_SIZE(timer_pool)) {
|
||||
timer->used = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __id_check(struct sys_timer *t, struct list_head *head)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
|
||||
__again:
|
||||
list_for_each_entry(p, head, entry) {
|
||||
if (t->id == p->id) {
|
||||
t->id++;
|
||||
goto __again;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static u16 __sys_timer_add(void *priv, void (*func)(void *priv), u32 msec, int timeout)
|
||||
{
|
||||
struct sys_timer *t;
|
||||
|
||||
t = __sys_timer_get(priv, func, msec, timeout);
|
||||
if (!t) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
spin_lock(&lock);
|
||||
|
||||
__id_check(t, &timer_head);
|
||||
|
||||
struct sys_timer *p;
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
//printf("p->jiffies:%x t->jiffies:%x\n",p-jiffies,t->jiffies);
|
||||
if (p->jiffies > t->jiffies) {
|
||||
__list_add(&t->entry, p->entry.prev, &p->entry);
|
||||
goto _LOOP_RET;
|
||||
}
|
||||
}
|
||||
|
||||
list_add_tail(&t->entry, &timer_head);
|
||||
_LOOP_RET:
|
||||
spin_unlock(&lock);
|
||||
|
||||
/* if(func == lmp_connection_timeout){ */
|
||||
/* mpu_set(0, (u32)t + sizeof(struct list_head), (u32)t + sizeof(struct list_head) + 4 - 1, 0, "Cxr"); */
|
||||
/* } */
|
||||
//log_debug("add id : %d", t->id);
|
||||
|
||||
//os_sem_post(&sys_timer_sem);
|
||||
|
||||
return t->id;
|
||||
}
|
||||
static void __timer_del(struct sys_timer *timer)
|
||||
{
|
||||
spin_lock(&lock);
|
||||
|
||||
__list_del_entry(&timer->entry);
|
||||
|
||||
int ret = __timer_put(timer);
|
||||
|
||||
spin_unlock(&lock);
|
||||
|
||||
/* if (!ret) {
|
||||
free(timer);
|
||||
} */
|
||||
}
|
||||
|
||||
static void __sys_timer_del(struct list_head *head, u16 id)
|
||||
{
|
||||
const char *task;
|
||||
struct sys_timer *p;
|
||||
|
||||
spin_lock(&lock);
|
||||
|
||||
list_for_each_entry(p, head, entry) {
|
||||
if (p->id == id) {
|
||||
__list_del_entry(&p->entry);
|
||||
__timer_put(p);
|
||||
//p->del = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&lock);
|
||||
}
|
||||
|
||||
u16 sys_timer_add(void *priv, void (*func)(void *priv), u32 msec)
|
||||
{
|
||||
int rets;
|
||||
__asm__ volatile("%0 = rets" :"=r"(rets));
|
||||
/* printf("add rts : 0x%x / %d", rets, msec); */
|
||||
return __sys_timer_add(priv, func, msec, 0);
|
||||
}
|
||||
|
||||
u16 sys_timeout_add(void *priv, void (*func)(void *priv), u32 msec)
|
||||
{
|
||||
int rets;
|
||||
__asm__ volatile("%0 = rets" :"=r"(rets));
|
||||
/* printf("add ot rts : 0x%x / %d", rets, msec); */
|
||||
return __sys_timer_add(priv, func, msec, 1);
|
||||
}
|
||||
|
||||
void sys_timer_del(u16 t)
|
||||
{
|
||||
__sys_timer_del(&timer_head, t);
|
||||
}
|
||||
|
||||
void sys_timeout_del(u16 t)
|
||||
{
|
||||
__sys_timer_del(&timer_head, t);
|
||||
}
|
||||
|
||||
int sys_timer_modify(u16 id, u32 msec)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
|
||||
spin_lock(&lock);
|
||||
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
if (p->id == id) {
|
||||
p->msec = msec;
|
||||
p->jiffies = jiffies + msecs_to_jiffies(msec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&lock);
|
||||
|
||||
//os_sem_post(&sys_timer_sem);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void sys_timer_set_user_data(u16 id, void *priv)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
|
||||
spin_lock(&lock);
|
||||
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
if (p->id == id) {
|
||||
p->priv = priv;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&lock);
|
||||
}
|
||||
|
||||
sys_timer sys_timer_register(u32 msec, void (*callback)(void *))
|
||||
{
|
||||
return sys_timeout_add(NULL, callback, msec);
|
||||
}
|
||||
|
||||
void sys_timer_change_period(sys_timer timer, u32 msec)
|
||||
{
|
||||
sys_timer_modify(timer, msec);
|
||||
}
|
||||
|
||||
void sys_timer_set_context(sys_timer timer, void *context)
|
||||
{
|
||||
sys_timer_set_user_data(timer, context);
|
||||
}
|
||||
|
||||
sys_timer sys_timer_register_periodic(u32 msec, void (*callback)(void *))
|
||||
{
|
||||
return sys_timer_add(NULL, callback, msec);
|
||||
}
|
||||
|
||||
void sys_timer_re_run(u16 id)
|
||||
{
|
||||
struct sys_timer *p;
|
||||
|
||||
spin_lock(&lock);
|
||||
|
||||
list_for_each_entry(p, &timer_head, entry) {
|
||||
if (p->id == id) {
|
||||
p->jiffies = jiffies + msecs_to_jiffies(p->msec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&lock);
|
||||
|
||||
//os_sem_post(&sys_timer_sem);
|
||||
}
|
||||
|
||||
void sys_timer_reset(sys_timer timer)
|
||||
{
|
||||
sys_timer_re_run(timer);
|
||||
}
|
||||
|
||||
void sys_timer_remove(sys_timer timer)
|
||||
{
|
||||
sys_timeout_del(timer);
|
||||
}
|
||||
|
||||
|
||||
void sys_timer_schedule()
|
||||
{
|
||||
struct sys_timer *p, *n;
|
||||
u8 do_fun_flag = 0;
|
||||
|
||||
#if TIMER_US_ENABLE
|
||||
loop_timer_us_schedule();
|
||||
#endif
|
||||
|
||||
/* jiffies++; */
|
||||
spin_lock(&lock);
|
||||
list_for_each_entry_safe(p, n, &timer_head, entry) {
|
||||
if (time_after(jiffies, p->jiffies)) {
|
||||
spin_unlock(&lock);
|
||||
if (p->func) {
|
||||
p->func(p->priv);
|
||||
}
|
||||
|
||||
spin_lock(&lock);
|
||||
if (p->timeout) {
|
||||
spin_unlock(&lock);
|
||||
__timer_del(p);
|
||||
spin_lock(&lock);
|
||||
} else {
|
||||
p->jiffies = jiffies + msecs_to_jiffies(p->msec);
|
||||
}
|
||||
}
|
||||
}
|
||||
spin_unlock(&lock);
|
||||
}
|
||||
|
||||
void sys_timer_init()
|
||||
{
|
||||
INIT_LIST_HEAD(&timer_head);
|
||||
#if TIMER_US_ENABLE
|
||||
INIT_LIST_HEAD(&timer_us_head);
|
||||
#endif
|
||||
|
||||
sys_tmr_init(sys_timer_schedule);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".version.data.bss")
|
||||
#pragma data_seg(".version.data")
|
||||
#pragma const_seg(".version.text.const")
|
||||
#pragma code_seg(".version.text")
|
||||
#endif
|
||||
#include "lib_include.h"
|
||||
|
||||
__attribute__((section(".version_tag1"), used))
|
||||
#if defined(EDR_UPDATA_SUPPORT_CONNECT)
|
||||
static const char version_type_tag[] = "edr_ota2";
|
||||
#elif defined(BLE_UPDATA_SUPPORT_CONNECT)
|
||||
static const char version_type_tag[] = "ble_ota";
|
||||
#elif (1 == USB_HOST_MODULE_CONTROL)
|
||||
|
||||
//二级loader修改
|
||||
#if defined(CONFIG_CPU_BR25) || defined(CONFIG_CPU_BR27)
|
||||
static const char version_type_tag[] = "usb_update2/usb_sec_ota";
|
||||
#else
|
||||
static const char version_type_tag[] = "usb_update2";
|
||||
#endif
|
||||
|
||||
#elif (1 == SD_MODULE_CONTROL)
|
||||
//二级loader修改
|
||||
#if defined(CONFIG_CPU_BR25) || defined(CONFIG_CPU_BR27)
|
||||
static const char version_type_tag[] = "sd_update2/sd_sec_ota";
|
||||
#else
|
||||
static const char version_type_tag[] = "sd_update2";
|
||||
#endif
|
||||
|
||||
#elif (1 == BLE_GATT_UPDATA_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "ble_app_ota";
|
||||
#elif (1 == SPP_UPDATA_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "spp_app_ota";
|
||||
#elif (1 == UART_UPDATA_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "uart_update";
|
||||
#elif (1 == UART_UPDATA_USER_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "user_uart_update";
|
||||
#elif defined(EX_FLASH_UPDATE_SUPPORT_EN)
|
||||
static const char version_type_tag[] = "nor_ota";
|
||||
#elif (1 == USER_LC_FLASH_UPDATA_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "lcflash_ota";
|
||||
#elif (1 == USB_HID_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "usb_hid_ota";
|
||||
#elif (1 == DEV_NORFLASH_UPDATA_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "dev_nor_ota";
|
||||
#elif (1 == NET_UPDATA_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "net_ota";
|
||||
#elif (1 == USB_HID_MODULE_CONTROL)
|
||||
static const char version_type_tag[] = "usb_hid_ota";
|
||||
#endif
|
||||
|
||||
__attribute__((section(".version_tag2"), used))
|
||||
static const char version_date_tag[] = __DATE__;
|
||||
|
||||
__attribute__((section(".version_tag3"), used))
|
||||
static const char version_time_tag[] = __TIME__;
|
||||
|
||||
@@ -0,0 +1,787 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".le_server_moudle.data.bss")
|
||||
#pragma data_seg(".le_server_moudle.data")
|
||||
#pragma const_seg(".le_server_moudle.text.const")
|
||||
#pragma code_seg(".le_server_moudle.text")
|
||||
#endif
|
||||
/*********************************************************************************************
|
||||
* Filename : le_server_module.c
|
||||
|
||||
* Description :
|
||||
|
||||
* Author :
|
||||
|
||||
* Email : zh-jieli.com
|
||||
|
||||
* Last modifiled : 2017-01-17 11:14
|
||||
|
||||
* Copyright:(c)JIELI 2011-2016 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
|
||||
// *****************************************************************************
|
||||
/* EXAMPLE_START(le_counter): LE Peripheral - Heartbeat Counter over GATT
|
||||
*
|
||||
* @text All newer operating systems provide GATT Client functionality.
|
||||
* The LE Counter examples demonstrates how to specify a minimal GATT Database
|
||||
* with a custom GATT Service and a custom Characteristic that sends periodic
|
||||
* notifications.
|
||||
*/
|
||||
// *****************************************************************************
|
||||
#include "lib_include.h"
|
||||
#include "btstack/ble_api.h"
|
||||
#include "btstack/le_user.h"
|
||||
#include "btstack/bluetooth.h"
|
||||
/* #include "custom_cfg.h" */
|
||||
/* #include "platform_config.h" */
|
||||
|
||||
|
||||
#define TCFG_BLE_SECURITY_EN 0
|
||||
|
||||
#include "ble_rcsp_server.h"
|
||||
#include "le_common.h"
|
||||
#include "custom_cfg.h"
|
||||
|
||||
#define LOG_TAG_CONST RCSP
|
||||
#define LOG_TAG "[RCSP]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_DUMP_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
|
||||
/*--------------------------extern api start -----------------------------*/
|
||||
|
||||
/*--------------------------extern api end -------------------------------*/
|
||||
|
||||
//------
|
||||
#define ATT_CTRL_BLOCK_SIZE (80) //note: fixed
|
||||
#define ATT_LOCAL_PAYLOAD_SIZE (247)//(200) //note: need >= 20
|
||||
|
||||
#if (defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)) && defined(BLE_APP_LOW_RAM_USED) // bd47 内存紧缺
|
||||
#define ATT_SEND_CBUF_SIZE (256) //note: need >= 20,缓存大小,可修改
|
||||
#else
|
||||
#define ATT_SEND_CBUF_SIZE (512) //note: need >= 20,缓存大小,可修改
|
||||
#endif
|
||||
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_PAYLOAD_SIZE + ATT_SEND_CBUF_SIZE) //note:
|
||||
static u8 att_ram_buffer[ATT_RAM_BUFSIZE] __attribute__((aligned(4)));
|
||||
//---------------
|
||||
|
||||
//---------------
|
||||
#define ADV_INTERVAL_MIN (32)
|
||||
|
||||
static hci_con_handle_t con_handle;
|
||||
|
||||
//加密设置
|
||||
static const uint8_t sm_min_key_size = 7;
|
||||
static const uint8_t sm_encryption_flag = 0; ///0--not encrypt, 1--encrypt
|
||||
|
||||
//连接参数设置
|
||||
static const uint8_t connection_update_enable = 1; ///0--disable, 1--enable
|
||||
static uint8_t connection_update_cnt = 0; ///0--disable, 1--enable
|
||||
static const struct conn_update_param_t connection_param_table[] = {
|
||||
{6, 12, 0, 400},
|
||||
{16, 24, 0, 600},//11
|
||||
{12, 28, 0, 600},//3.7
|
||||
{8, 20, 0, 600},
|
||||
};
|
||||
#define CONN_PARAM_TABLE_CNT (sizeof(connection_param_table)/sizeof(struct conn_update_param_t))
|
||||
|
||||
// 广播包内容
|
||||
/* static u8 adv_data[ADV_RSP_PACKET_MAX];//max is 31 */
|
||||
// scan_rsp 内容
|
||||
/* static u8 scan_rsp_data[ADV_RSP_PACKET_MAX];//max is 31 */
|
||||
|
||||
#if (ATT_RAM_BUFSIZE < 64)
|
||||
#error "adv_data & rsp_data buffer error!!!!!!!!!!!!"
|
||||
#endif
|
||||
|
||||
#define adv_data &att_ram_buffer[0]
|
||||
#define scan_rsp_data &att_ram_buffer[32]
|
||||
|
||||
static char *gap_device_name = "br22_ble_test";
|
||||
static u8 gap_device_name_len = 0;
|
||||
static u8 ble_work_state = 0;
|
||||
static u8 test_read_write_buf[4];
|
||||
|
||||
static void (*app_recieve_callback)(void *priv, void *buf, u16 len) = NULL;
|
||||
static void (*app_ble_state_callback)(void *priv, ble_state_e state) = NULL;
|
||||
static void (*ble_resume_send_wakeup)(void) = NULL;
|
||||
static u32 channel_priv;
|
||||
|
||||
static int app_send_user_data_check(u16 len);
|
||||
static int app_send_user_data_do(void *priv, u8 *data, u16 len);
|
||||
static int app_send_user_data(u16 handle, u8 *data, u16 len, u8 handle_type);
|
||||
|
||||
// Complete Local Name 默认的蓝牙名字
|
||||
|
||||
//------------------------------------------------------
|
||||
//广播参数设置
|
||||
static void advertisements_setup_init();
|
||||
extern const char *bt_get_local_name();
|
||||
static int set_adv_enable(void *priv, u32 en);
|
||||
static int get_buffer_vaild_len(void *priv);
|
||||
//------------------------------------------------------
|
||||
static void send_request_connect_parameter(u8 table_index)
|
||||
{
|
||||
struct conn_update_param_t *param = (void *)&connection_param_table[table_index];//static ram
|
||||
|
||||
log_info("update_request:-%d-%d-%d-%d-\n", param->interval_min, param->interval_max, param->latency, param->timeout);
|
||||
if (con_handle) {
|
||||
ble_user_cmd_prepare(BLE_CMD_REQ_CONN_PARAM_UPDATE, 2, con_handle, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void check_connetion_updata_deal(void)
|
||||
{
|
||||
if (connection_update_enable) {
|
||||
if (connection_update_cnt < CONN_PARAM_TABLE_CNT) {
|
||||
send_request_connect_parameter(connection_update_cnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ble_upgrade_speed(void)
|
||||
{
|
||||
send_request_connect_parameter(0);
|
||||
}
|
||||
|
||||
static void connection_update_complete_success(u8 *packet)
|
||||
{
|
||||
int con_handle, conn_interval, conn_latency, conn_timeout;
|
||||
|
||||
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
||||
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||
conn_latency = hci_subevent_le_connection_update_complete_get_conn_latency(packet);
|
||||
conn_timeout = hci_subevent_le_connection_update_complete_get_supervision_timeout(packet);
|
||||
|
||||
log_info("conn_interval = %d\n", conn_interval);
|
||||
log_info("conn_latency = %d\n", conn_latency);
|
||||
log_info("conn_timeout = %d\n", conn_timeout);
|
||||
}
|
||||
|
||||
|
||||
static void set_ble_work_state(ble_state_e state)
|
||||
{
|
||||
if (1) {//state != ble_work_state) {
|
||||
log_info("ble_work_st:%x->%x\n", ble_work_state, state);
|
||||
ble_work_state = state;
|
||||
if (app_ble_state_callback) {
|
||||
app_ble_state_callback((void *)channel_priv, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ble_state_e get_ble_work_state(void)
|
||||
{
|
||||
return ble_work_state;
|
||||
}
|
||||
|
||||
u16 get_ble_update_work_state(void)
|
||||
{
|
||||
return con_handle;
|
||||
}
|
||||
|
||||
static void cbk_sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
|
||||
{
|
||||
sm_just_event_t *event = (void *)packet;
|
||||
u32 tmp32;
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case SM_EVENT_JUST_WORKS_REQUEST:
|
||||
sm_just_works_confirm(sm_event_just_works_request_get_handle(packet));
|
||||
log_info("Just Works Confirmed.\n");
|
||||
break;
|
||||
case SM_EVENT_PASSKEY_DISPLAY_NUMBER:
|
||||
log_info_hexdump(packet, size);
|
||||
memcpy(&tmp32, event->data, 4);
|
||||
log_info("Passkey display: %06u.\n", tmp32);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void can_send_now_wakeup(void)
|
||||
{
|
||||
//putchar('E');
|
||||
if (ble_resume_send_wakeup) {
|
||||
ble_resume_send_wakeup();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @section Packet Handler
|
||||
*
|
||||
* @text The packet handler is used to:
|
||||
* - stop the counter after a disconnect
|
||||
* - send a notification when the requested ATT_EVENT_CAN_SEND_NOW is received
|
||||
*/
|
||||
|
||||
/* LISTING_START(packetHandler): Packet Handler */
|
||||
static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
|
||||
{
|
||||
int mtu;
|
||||
u32 tmp;
|
||||
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
|
||||
/* case DAEMON_EVENT_HCI_PACKET_SENT: */
|
||||
/* break; */
|
||||
case ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE:
|
||||
log_info("ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE\n");
|
||||
case ATT_EVENT_CAN_SEND_NOW:
|
||||
can_send_now_wakeup();
|
||||
break;
|
||||
|
||||
case HCI_EVENT_LE_META:
|
||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: {
|
||||
con_handle = little_endian_read_16(packet, 4);
|
||||
log_info("HCI_SUBEVENT_LE_CONNECTION_COMPLETE: %0x\n", con_handle);
|
||||
connection_update_complete_success(packet + 8);
|
||||
#ifdef BLE_GATT_UPDATA_MODULE_CONTROL
|
||||
ble_user_cmd_prepare(BLE_CMD_ATT_SEND_INIT, 4, con_handle, att_ram_buffer, ATT_RAM_BUFSIZE, ATT_LOCAL_PAYLOAD_SIZE);
|
||||
/* ble_upgrade_speed(); */
|
||||
#endif
|
||||
set_ble_work_state(BLE_ST_CONNECT);
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||
connection_update_complete_success(packet);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
log_info("HCI_EVENT_DISCONNECTION_COMPLETE: %0x\n", packet[5]);
|
||||
con_handle = 0;
|
||||
#ifdef BLE_GATT_UPDATA_MODULE_CONTROL
|
||||
ble_user_cmd_prepare(BLE_CMD_ATT_SEND_INIT, 4, con_handle, 0, 0, 0);
|
||||
#endif
|
||||
set_ble_work_state(BLE_ST_IDLE);
|
||||
set_adv_enable(0, 1);
|
||||
connection_update_cnt = 0;
|
||||
break;
|
||||
|
||||
case ATT_EVENT_MTU_EXCHANGE_COMPLETE:
|
||||
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
|
||||
log_info("ATT MTU = %u\n", mtu);
|
||||
#ifdef BLE_GATT_UPDATA_MODULE_CONTROL
|
||||
ble_user_cmd_prepare(BLE_CMD_ATT_MTU_SIZE, 1, mtu);
|
||||
ble_upgrade_speed();
|
||||
#endif
|
||||
break;
|
||||
|
||||
/* case BTSTACK_EVENT_STATE: */
|
||||
/* switch (btstack_event_state_get_state(packet)) { */
|
||||
/* case HCI_STATE_WORKING: */
|
||||
/* log_info("ble_stack init complete\n"); */
|
||||
/* set_ble_work_state(BLE_ST_INIT_OK); */
|
||||
/* set_adv_enable(0, 1); */
|
||||
/* break; */
|
||||
/* case HCI_STATE_OFF: */
|
||||
/* log_info("ble_stack exit complete\n"); */
|
||||
/* set_ble_work_state(BLE_ST_NULL); */
|
||||
/* break; */
|
||||
/* } */
|
||||
/* break; */
|
||||
|
||||
case HCI_EVENT_VENDOR_REMOTE_TEST:
|
||||
log_info("--- HCI_EVENT_VENDOR_REMOTE_TEST\n");
|
||||
break;
|
||||
|
||||
case L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE:
|
||||
tmp = little_endian_read_16(packet, 4);
|
||||
log_info("-update_rsp: %02x\n", tmp);
|
||||
if (tmp) {
|
||||
connection_update_cnt++;
|
||||
log_info("remoter reject!!!\n");
|
||||
check_connetion_updata_deal();
|
||||
} else {
|
||||
connection_update_cnt = CONN_PARAM_TABLE_CNT;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_ENCRYPTION_CHANGE:
|
||||
log_info("HCI_EVENT_ENCRYPTION_CHANGE= %d\n", packet[2]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* LISTING_END */
|
||||
|
||||
/*
|
||||
* @section ATT Read
|
||||
*
|
||||
* @text The ATT Server handles all reads to constant data. For dynamic data like the custom characteristic, the registered
|
||||
* att_read_callback is called. To handle long characteristics and long reads, the att_read_callback is first called
|
||||
* with buffer == NULL, to request the total value length. Then it will be called again requesting a chunk of the value.
|
||||
* See Listing attRead.
|
||||
*/
|
||||
|
||||
/* LISTING_START(attRead): ATT Read */
|
||||
|
||||
// ATT Client Read Callback for Dynamic Data
|
||||
// - if buffer == NULL, don't copy data, just return size of value
|
||||
// - if buffer != NULL, copy data and return number bytes copied
|
||||
// @param offset defines start of attribute value
|
||||
static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size)
|
||||
{
|
||||
|
||||
uint16_t att_value_len = 0;
|
||||
uint16_t handle = att_handle;
|
||||
|
||||
log_info("read_callback, handle= 0x%04x,buffer= %08x\n", handle, (u32)buffer);
|
||||
|
||||
switch (handle) {
|
||||
case ATT_CHARACTERISTIC_2a00_01_VALUE_HANDLE:
|
||||
att_value_len = gap_device_name_len;
|
||||
|
||||
if ((offset >= att_value_len) || (offset + buffer_size) > att_value_len) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
memcpy(buffer, &gap_device_name[offset], buffer_size);
|
||||
att_value_len = buffer_size;
|
||||
log_info("\n------read gap_name: %s \n", gap_device_name);
|
||||
}
|
||||
break;
|
||||
|
||||
case ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE:
|
||||
if (buffer) {
|
||||
buffer[0] = att_get_ccc_config(handle);
|
||||
buffer[1] = 0;
|
||||
}
|
||||
att_value_len = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
log_info("att_value_len= %d\n", att_value_len);
|
||||
return att_value_len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* LISTING_END */
|
||||
/*
|
||||
* @section ATT Write
|
||||
*
|
||||
* @text The only valid ATT write in this example is to the Client Characteristic Configuration, which configures notification
|
||||
* and indication. If the ATT handle matches the client configuration handle, the new configuration value is stored and used
|
||||
* in the heartbeat handler to decide if a new value should be sent. See Listing attWrite.
|
||||
*/
|
||||
|
||||
/* LISTING_START(attWrite): ATT Write */
|
||||
static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size)
|
||||
{
|
||||
int result = 0;
|
||||
u16 tmp16;
|
||||
|
||||
u16 handle = att_handle;
|
||||
|
||||
|
||||
switch (handle) {
|
||||
|
||||
case ATT_CHARACTERISTIC_2a00_01_VALUE_HANDLE:
|
||||
break;
|
||||
|
||||
case ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE:
|
||||
set_ble_work_state(BLE_ST_NOTIFY_IDICATE);
|
||||
//check_connetion_updata_deal();
|
||||
log_info("\n------write ccc:%04x,%02x\n", handle, buffer[0]);
|
||||
att_set_ccc_config(handle, buffer[0]);
|
||||
break;
|
||||
|
||||
case ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE:
|
||||
log_info("\n-ae01_rx(%d):", buffer_size);
|
||||
u32 deg_len = (buffer_size > 0x20) ? 0x20 : buffer_size;
|
||||
//printf_buf(buffer, deg_len);
|
||||
if (app_recieve_callback) {
|
||||
app_recieve_callback((void *)channel_priv, buffer, buffer_size);
|
||||
}
|
||||
//收发测试,自动发送收到的数据;for test
|
||||
///app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, buffer, buffer_size, ATT_OP_AUTO_READ_CCC);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int app_send_user_data(u16 handle, u8 *data, u16 len, u8 handle_type)
|
||||
{
|
||||
u32 ret = APP_BLE_NO_ERROR;
|
||||
|
||||
if (!con_handle) {
|
||||
return APP_BLE_OPERATION_ERROR;
|
||||
}
|
||||
|
||||
//log_info("usr_send:%x\n", len);
|
||||
//log_info_hexdump(data, len);
|
||||
ret = ble_user_cmd_prepare(BLE_CMD_ATT_SEND_DATA, 4, handle, data, len, handle_type);
|
||||
if (ret == BLE_BUFFER_FULL) {
|
||||
ret = APP_BLE_BUFF_FULL;
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
log_info("app_send_fail:%d !!!!!!\n", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define AD_TYPE_FLAGS 0x01
|
||||
#define AD_TYPE_UUID_16 0x03
|
||||
#define AD_TYPE_COMPLETE_LOCAL_NAME 0x09
|
||||
#define AD_TYPE_MANUFACTURER_SPEC_DATA 0xff
|
||||
/// Advertising Data
|
||||
// Flags
|
||||
#define FLAGS_LE_LIMITED_DISCOVER_MODE BIT(0)
|
||||
#define FLAGS_LE_GENERAL_DISCOVER_MODE BIT(1)
|
||||
#define FLAGS_BREDR_NOT_SUPPORTED BIT(2)
|
||||
#define FLAGS_SIMULTANEOUS_DUAL_CONTROLLER BIT(3)
|
||||
#define FLAGS_SIMULTANEOUS_DUAL_HOST BIT(4)
|
||||
#define HID_SERVER_FLAGS (FLAGS_LE_GENERAL_DISCOVER_MODE|FLAGS_BREDR_NOT_SUPPORTED)
|
||||
// Complete List of 16-bit Service Class UUIDs
|
||||
#define HID_SERVER_UUID16 0x12,0x18
|
||||
// Complete Default Name
|
||||
|
||||
/* #define BLE_DEV_NAME_LEN 11 */
|
||||
/* #define BLE_DEV_NAME 'R', 'A', 'P','O', 'O', ' ', 'V', 'X', '3', '5', '0' */
|
||||
|
||||
|
||||
/* #if defined(CONFIG_CPU_BR22) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '3','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR23) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '5','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR26) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '4','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR18) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '8', '0', '0','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR21) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '2','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BD29) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '3', '0','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR25) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '6','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR30) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '7','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR34) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '9', '8','X','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BD19) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME '6', '3', '2','N','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR36) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME 'B', 'R', '3','6','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #elif defined(CONFIG_CPU_BR28) */
|
||||
/* #define BLE_DEV_NAME_LEN 14 */
|
||||
/* #define BLE_DEV_NAME 'B', 'R', '2','8','_','L','E','_','U', 'P', 'D', 'A', 'T','E' */
|
||||
/* #endif */
|
||||
|
||||
#define BLE_DEV_NAME_LEN 14
|
||||
#define BLE_DEV_NAME 'J', 'L', 'B','T','_','L','E','_','U', 'P', 'D', 'A', 'T','E'
|
||||
|
||||
#define JL_MANUFACTURER_DATA 0x8f,0x03,0x08,0x00,'J','L','B','T','S','D','K'
|
||||
|
||||
static const u8 manufactureer_data[] = {JL_MANUFACTURER_DATA};
|
||||
|
||||
static u8 adv_ind_data[] = {
|
||||
// len---------------------AD Type-------------------------Value
|
||||
0x02, AD_TYPE_FLAGS, 0x06,//HID_SERVER_FLAGS,
|
||||
0x03, AD_TYPE_UUID_16, 0x0a, 0x18, //HID_SERVER_UUID16,
|
||||
/* BLE_DEV_NAME_LEN + 1, AD_TYPE_COMPLETE_LOCAL_NAME, BLE_DEV_NAME, */
|
||||
};
|
||||
|
||||
static u8 scan_rsp_array[] = {
|
||||
// len---------------------AD Type-------------------------Value
|
||||
//BLE_DEV_NAME_LEN + 1, AD_TYPE_COMPLETE_LOCAL_NAME, BLE_DEV_NAME,
|
||||
sizeof(manufactureer_data) + 1, AD_TYPE_MANUFACTURER_SPEC_DATA, JL_MANUFACTURER_DATA,
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
static int make_set_adv_data(void)
|
||||
{
|
||||
u8 offset = 0;
|
||||
u8 *buf = adv_data;
|
||||
|
||||
memset(buf, 0, ADV_RSP_PACKET_MAX);
|
||||
#ifdef BLE_GATT_UPDATA_MODULE_CONTROL
|
||||
if (EX_CFG_ERR_NONE == ex_cfg_get_content_api(CFG_ITEM_ADV_IND, buf, 31)) {
|
||||
offset = 31;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
memcpy(buf, adv_ind_data, sizeof(adv_ind_data));
|
||||
offset = sizeof(adv_ind_data);
|
||||
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME, (void *)CONFIG_BT_NAME, sizeof(CONFIG_BT_NAME));
|
||||
}
|
||||
log_info("adv_data(%d):", offset);
|
||||
log_info_hexdump(buf, offset);
|
||||
ble_user_cmd_prepare(BLE_CMD_ADV_DATA, 2, offset, buf);
|
||||
|
||||
if (offset > ADV_RSP_PACKET_MAX) {
|
||||
puts("***adv_data overflow!!!!!!\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int make_set_rsp_data(void)
|
||||
{
|
||||
|
||||
u8 offset = 0;
|
||||
u8 *buf = scan_rsp_data;
|
||||
memset(buf, 0, ADV_RSP_PACKET_MAX);
|
||||
#ifdef BLE_GATT_UPDATA_MODULE_CONTROL
|
||||
if (EX_CFG_ERR_NONE == ex_cfg_get_content_api(CFG_ITEM_SCAN_RSP, buf, 31)) {
|
||||
offset = 31;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
memcpy(buf, scan_rsp_array, sizeof(scan_rsp_array));
|
||||
offset = sizeof(scan_rsp_array);
|
||||
}
|
||||
log_info("rsp_data(%d):", offset);
|
||||
log_info_hexdump(buf, offset);
|
||||
ble_user_cmd_prepare(BLE_CMD_RSP_DATA, 2, offset, buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//广播参数设置
|
||||
static void advertisements_setup_init()
|
||||
{
|
||||
uint8_t adv_type = 0;
|
||||
uint8_t adv_channel = 7;
|
||||
int ret = 0;
|
||||
|
||||
ble_user_cmd_prepare(BLE_CMD_ADV_PARAM, 3, ADV_INTERVAL_MIN, adv_type, adv_channel);
|
||||
|
||||
ret |= make_set_adv_data();
|
||||
ret |= make_set_rsp_data();
|
||||
|
||||
if (ret) {
|
||||
puts("advertisements_setup_init fail !!!!!!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ble_sm_setup_init(io_capability_t io_type, u8 auth_req, uint8_t min_key_size, u8 security_en)
|
||||
{
|
||||
//setup SM: Display only
|
||||
sm_init();
|
||||
sm_set_io_capabilities(io_type);
|
||||
sm_set_authentication_requirements(auth_req);
|
||||
sm_set_encryption_key_size_range(min_key_size, 16);
|
||||
sm_set_request_security(security_en);
|
||||
//sm_event_callback_set(&cbk_sm_packet_handler);
|
||||
}
|
||||
|
||||
|
||||
extern void le_device_db_init(void);
|
||||
extern void le_l2cap_register_packet_handler(void (*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
|
||||
u8 gatt_profile_data[0x200] = {0};
|
||||
void ble_profile_init(void)
|
||||
{
|
||||
log_info("ble profile init\n");
|
||||
/* setup ATT server */
|
||||
|
||||
#ifdef BLE_GATT_UPDATA_MODULE_CONTROL
|
||||
le_device_db_init();
|
||||
ble_sm_setup_init(IO_CAPABILITY_NO_INPUT_NO_OUTPUT, SM_AUTHREQ_BONDING, 7, TCFG_BLE_SECURITY_EN);
|
||||
#if 0
|
||||
if (EX_CFG_ERR_NONE == ex_cfg_get_content_api(CFG_ITEM_GATT_PROFILE, gatt_profile_data, 0x200)) {
|
||||
att_server_init(gatt_profile_data, NULL, att_write_callback);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
att_server_init(profile_data, NULL, att_write_callback);
|
||||
}
|
||||
|
||||
att_server_register_packet_handler(cbk_packet_handler);
|
||||
le_l2cap_register_packet_handler(&cbk_packet_handler);
|
||||
#endif
|
||||
|
||||
|
||||
/* gatt_client_register_packet_handler(packet_cbk); */
|
||||
|
||||
// register for HCI events
|
||||
hci_event_callback_set(&cbk_packet_handler);
|
||||
/* ble_l2cap_register_packet_handler(packet_cbk); */
|
||||
/* sm_event_packet_handler_register(packet_cbk); */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int set_adv_enable(void *priv, u32 en)
|
||||
{
|
||||
ble_state_e next_state, cur_state;
|
||||
|
||||
if (con_handle) {
|
||||
return APP_BLE_OPERATION_ERROR;
|
||||
}
|
||||
|
||||
if (en) {
|
||||
next_state = BLE_ST_ADV;
|
||||
} else {
|
||||
next_state = BLE_ST_IDLE;
|
||||
}
|
||||
|
||||
cur_state = get_ble_work_state();
|
||||
switch (cur_state) {
|
||||
case BLE_ST_ADV:
|
||||
case BLE_ST_IDLE:
|
||||
case BLE_ST_INIT_OK:
|
||||
case BLE_ST_NULL:
|
||||
break;
|
||||
default:
|
||||
return APP_BLE_OPERATION_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (cur_state == next_state) {
|
||||
return APP_BLE_NO_ERROR;
|
||||
}
|
||||
log_info(">>>>>>adv_en:%d\n", en);
|
||||
set_ble_work_state(next_state);
|
||||
if (en) {
|
||||
advertisements_setup_init();
|
||||
}
|
||||
ble_user_cmd_prepare(BLE_CMD_ADV_ENABLE, 1, en);
|
||||
return APP_BLE_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static int ble_disconnect(void *priv)
|
||||
{
|
||||
if (con_handle) {
|
||||
set_ble_work_state(BLE_ST_SEND_DISCONN);
|
||||
ble_user_cmd_prepare(BLE_CMD_DISCONNECT, 1, con_handle);
|
||||
return APP_BLE_NO_ERROR;
|
||||
} else {
|
||||
return APP_BLE_OPERATION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_buffer_vaild_len(void *priv)
|
||||
{
|
||||
u32 vaild_len = 0;
|
||||
ble_user_cmd_prepare(BLE_CMD_ATT_VAILD_LEN, 1, &vaild_len);
|
||||
return vaild_len;
|
||||
}
|
||||
|
||||
static int app_send_user_data_do(void *priv, u8 *data, u16 len)
|
||||
{
|
||||
#if PRINT_DMA_DATA_EN
|
||||
if (len < 128) {
|
||||
log_info("-le_tx(%d):");
|
||||
log_info_hexdump(data, len);
|
||||
} else {
|
||||
putchar('L');
|
||||
}
|
||||
#endif
|
||||
return app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, len, ATT_OP_AUTO_READ_CCC);
|
||||
}
|
||||
|
||||
static int app_send_user_data_check(u16 len)
|
||||
{
|
||||
u32 buf_space = get_buffer_vaild_len(0);
|
||||
if (len <= buf_space) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int regiest_wakeup_send(void *priv, void *cbk)
|
||||
{
|
||||
ble_resume_send_wakeup = cbk;
|
||||
return APP_BLE_NO_ERROR;
|
||||
}
|
||||
|
||||
static int regiest_recieve_cbk(void *priv, void *cbk)
|
||||
{
|
||||
channel_priv = (u32)priv;
|
||||
app_recieve_callback = cbk;
|
||||
log_info("--------------%s %d\n", __func__, __LINE__);
|
||||
return APP_BLE_NO_ERROR;
|
||||
}
|
||||
|
||||
int regiest_state_cbk(void *priv, void *cbk)
|
||||
{
|
||||
channel_priv = (u32)priv;
|
||||
app_ble_state_callback = cbk;
|
||||
return APP_BLE_NO_ERROR;
|
||||
}
|
||||
|
||||
void bt_ble_adv_enable(u8 enable)
|
||||
{
|
||||
set_adv_enable(0, enable);
|
||||
}
|
||||
|
||||
u8 check_ble_is_disconnect(void)
|
||||
{
|
||||
return con_handle;
|
||||
}
|
||||
|
||||
void bt_ble_init(void)
|
||||
{
|
||||
log_info("***** ble_init_rcsp******\n");
|
||||
|
||||
set_ble_work_state(BLE_ST_INIT_OK);
|
||||
set_adv_enable(0, 1);
|
||||
}
|
||||
|
||||
void bt_ble_exit(void)
|
||||
{
|
||||
log_info("***** ble_exit******\n");
|
||||
set_adv_enable(0, 0);
|
||||
}
|
||||
|
||||
static const struct ble_server_operation_t rcsp_ble_operation = {
|
||||
.adv_enable = set_adv_enable,
|
||||
.disconnect = ble_disconnect,
|
||||
.get_buffer_vaild = get_buffer_vaild_len,
|
||||
.send_data = (void *)app_send_user_data_do,
|
||||
.regist_wakeup_send = regiest_wakeup_send,
|
||||
.regist_recieve_cbk = regiest_recieve_cbk,
|
||||
.regist_state_cbk = regiest_state_cbk,
|
||||
};
|
||||
|
||||
|
||||
void ble_get_server_operation_table(struct ble_server_operation_t **interface_pt)
|
||||
{
|
||||
*interface_pt = (void *)&rcsp_ble_operation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".lib_btctrler_config.data.bss")
|
||||
#pragma data_seg(".lib_btctrler_config.data")
|
||||
#pragma const_seg(".lib_btctrler_config.text.const")
|
||||
#pragma code_seg(".lib_btctrler_config.text")
|
||||
#endif
|
||||
//#include "system/includes.h"
|
||||
#include "btcontroller_config.h"
|
||||
#include "btstack/bt_profile_config.h"
|
||||
#include "printf.h"
|
||||
|
||||
|
||||
const int config_stack_modules = BT_BTSTACK_LE;
|
||||
|
||||
#ifdef EDR_UPDATA_SUPPORT_CONNECT
|
||||
const int config_btctler_modules = BT_MODULE_CLASSIC;
|
||||
#elif defined (BLE_UPDATA_SUPPORT_CONNECT) || defined (BLE_GATT_UPDATA_MODULE_CONTROL)
|
||||
const int config_btctler_modules = BT_MODULE_LE;
|
||||
#else
|
||||
const int config_btctler_modules = 0;
|
||||
#endif
|
||||
|
||||
const int config_rf_slot_unit = 625;
|
||||
|
||||
const int config_btctler_le_tws = 0;
|
||||
const int CONFIG_BTCTLER_TWS_ENABLE = 0;
|
||||
const int config_btctler_mode = BT_NORMAL;
|
||||
const int config_btctler_hci_standard = 0;
|
||||
const int CONFIG_BLE_SYNC_WORD_BIT = 30;
|
||||
|
||||
const int clock_tree_auto_disable_all_pll = 0;
|
||||
#ifdef BLE_UPDATA_SUPPORT_CONNECT
|
||||
const int config_btctler_single_carrier_en = 1;
|
||||
#else
|
||||
const int config_btctler_single_carrier_en = 0;
|
||||
#endif
|
||||
const u8 ble_debug_enable = 0x00;
|
||||
const u8 rx_fre_offset_adjust_enable = 1;
|
||||
|
||||
const int CONFIG_PAGE_POWER = 4;
|
||||
const int CONFIG_PAGE_SCAN_POWER = 7;
|
||||
const int CONFIG_INQUIRY_POWER = 7;
|
||||
const int CONFIG_INQUIRY_SCAN_POWER = 7;
|
||||
|
||||
const int CONFIG_TEST_DUT_CODE = 0;
|
||||
const int CONFIG_TEST_FCC_CODE = 0;
|
||||
const int CONFIG_TEST_DUT_ONLY_BOX_CODE = 0;
|
||||
|
||||
#if defined (BLE_GATT_UPDATA_MODULE_CONTROL)
|
||||
const uint64_t config_btctler_le_features = LE_2M_PHY | LE_DATA_PACKET_LENGTH_EXTENSION;//(LE_ENCRYPTION);
|
||||
#else
|
||||
const uint64_t config_btctler_le_features = LE_DATA_PACKET_LENGTH_EXTENSION;
|
||||
#endif
|
||||
|
||||
const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
|
||||
|
||||
//固定使用正常发射功率的等级:0-使用不同模式的各自等级;1~10-固定发射功率等级
|
||||
const int config_force_bt_pwr_tab_using_normal_level = 0;
|
||||
|
||||
const int config_btctler_eir_version_info_len = 21;
|
||||
|
||||
const int CONFIG_WIFI_DETECT_ENABLE = 0;
|
||||
|
||||
const int config_btctler_le_afh_en = 0;
|
||||
const int config_btctler_le_rx_nums = 8;
|
||||
const int config_btctler_le_acl_packet_length = 251;
|
||||
const int config_btctler_le_acl_total_nums = 3;
|
||||
const int config_btctler_le_hw_nums = 1;
|
||||
|
||||
const int config_update_mode = 0xff;
|
||||
|
||||
//BT
|
||||
const int IRQ_BT_TIMEBASE_IP = 6;
|
||||
const int IRQ_BLE_EVENT_IP = 5;
|
||||
const int IRQ_BLE_RX_IP = 5;
|
||||
const int IRQ_BREDR_IP = 4;
|
||||
const int IRQ_BT_RXMCH_IP = 4;
|
||||
|
||||
const int config_rf_oob = 0;
|
||||
#if defined (BLE_GATT_UPDATA_MODULE_CONTROL) || defined (BLE_UPDATA_SUPPORT_CONNECT)
|
||||
#if defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)
|
||||
#if defined(BLE_APP_LOW_RAM_USED) // bd47内存紧缺
|
||||
static u8 app_le_pool[800] __attribute__((aligned(4)));
|
||||
#else
|
||||
static u8 app_le_pool[1300] __attribute__((aligned(4)));
|
||||
#endif
|
||||
#else
|
||||
static u8 app_le_pool[1820] __attribute__((aligned(4)));
|
||||
#endif
|
||||
extern u16 get_le_pool_len(void);
|
||||
u8 *get_le_pool_addr(void)
|
||||
{
|
||||
u16 len = 0;
|
||||
|
||||
len = get_le_pool_len();
|
||||
printf("le pool len %d\n", len);
|
||||
if (len > sizeof(app_le_pool)) {
|
||||
ASSERT(0, "le_pool is small\n");
|
||||
}
|
||||
|
||||
return &app_le_pool;
|
||||
}
|
||||
#endif
|
||||
|
||||
const u32 __VERSION_BEGIN = 0;
|
||||
|
||||
const char log_tag_const_v_Analog = 0;
|
||||
const char log_tag_const_i_Analog = 0;
|
||||
const char log_tag_const_w_Analog = 0;
|
||||
const char log_tag_const_d_Analog = 0;
|
||||
const char log_tag_const_e_Analog = 0;
|
||||
|
||||
const char log_tag_const_v_LL_ISO = 0;
|
||||
const char log_tag_const_i_LL_ISO = 0;
|
||||
const char log_tag_const_d_LL_ISO = 0;
|
||||
const char log_tag_const_w_LL_ISO = 0;
|
||||
const char log_tag_const_e_LL_ISO = 0;
|
||||
|
||||
const char log_tag_const_i_LL_EXT_ADV = 0;
|
||||
const char log_tag_const_e_LL_EXT_ADV = 0;
|
||||
const char log_tag_const_d_LL_EXT_ADV = 0;
|
||||
|
||||
const char log_tag_const_i_LL_PADV = 0;
|
||||
|
||||
const char log_tag_const_i_AES = 0;
|
||||
|
||||
const int config_btctler_dual_a2dp = 0;
|
||||
const int CONFIG_LMP_NAME_REQ_ENABLE = 0;
|
||||
const int CONFIG_BREDR_INQUIRY = 0;
|
||||
const int config_bredr_afh_user = 0;
|
||||
const int CONFIG_LMP_MASTER_ESCO_ENABLE = 0;
|
||||
const int config_bt_security_vulnerability = 0;
|
||||
const int CONFIG_BTCTLER_FAST_CONNECT_ENABLE = 0;
|
||||
const int config_btctler_bredr_master = 0;
|
||||
const int CONFIG_A2DP_MAX_BUF_SIZE = 0;
|
||||
const u32 config_vendor_le_bb = 0;
|
||||
// Master multi-link
|
||||
const int config_btctler_le_master_multilink = 0;
|
||||
const int ble_disable_wait_enable = 1;
|
||||
|
||||
const int config_btctler_le_slave_conn_update_winden = 2500;//range:100 to 2500
|
||||
const int config_le_sm_support_enable = 1; //是否支持加密配对
|
||||
const int config_btctler_le_iso_tx = 1024;
|
||||
const int config_btctler_le_iso_rx = 0;
|
||||
const int config_bb_optimized_ctrl = 0;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".loader_main.data.bss")
|
||||
#pragma data_seg(".loader_main.data")
|
||||
#pragma const_seg(".loader_main.text.const")
|
||||
#pragma code_seg(".loader_main.text")
|
||||
#endif
|
||||
#include "common.h"
|
||||
#include "clock.h"
|
||||
#include "irq.h"
|
||||
#include "wdt.h"
|
||||
#include "uart.h"
|
||||
#include "printf.h"
|
||||
#include "dec.h"
|
||||
#include "jlfs.h"
|
||||
#include "delay.h"
|
||||
#include "upgrade.h"
|
||||
#include "sys_timer.h"
|
||||
#include "exception.h"
|
||||
#include "update_main.h"
|
||||
#include "norflash.h"
|
||||
#include "mask_api.h"
|
||||
|
||||
#if (UPDIFF_FLASH_UPDATE_SUPPORT_EN||COMBAK_FLASH_UPDATE_SUPPORT_EN) && \
|
||||
(defined(CONFIG_CPU_BR52))
|
||||
#include "charge_hw.h"
|
||||
#endif
|
||||
|
||||
#define LOG_TAG_CONST LOADER_MAIN
|
||||
#define LOG_TAG "[LOADER_MAIN]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
/* #define IO_N 3 */
|
||||
/* void test_io(int x) */
|
||||
/* { */
|
||||
/* JL_PORTB->DIR &= ~BIT(IO_N); */
|
||||
/* #<{(| mdelay(20); |)}># */
|
||||
/* for (int i = 0; i < x; i++) */
|
||||
/* { */
|
||||
/* JL_PORTB->OUT ^= BIT(IO_N); */
|
||||
/* } */
|
||||
/* JL_PORTB->OUT |= BIT(IO_N); */
|
||||
/* } */
|
||||
|
||||
|
||||
#include "power/p33.h"
|
||||
#include "gpio.h"
|
||||
extern u32 get_power_pin_multi(u32 *gpio, u8 *level, u32 cnt);
|
||||
#define PP_N 3//最多记录power_pin脚数
|
||||
typedef struct {
|
||||
u32 gpio[PP_N];
|
||||
u8 level[PP_N];
|
||||
} PowerPin;
|
||||
static PowerPin pp_handle = {0};
|
||||
|
||||
//================================================//
|
||||
// 不可屏蔽中断使能配置(UNMASK_IRQ) //
|
||||
// Only For AC701N //
|
||||
//================================================//
|
||||
const int CONFIG_CPU_UNMASK_IRQ_ENABLE = 0;
|
||||
|
||||
struct flash_platform_data inside_flash_pdata;
|
||||
|
||||
void soft_irq_handler(void)
|
||||
{
|
||||
printf("%s\n", __func__);
|
||||
}
|
||||
|
||||
u32 stack_magic[4] sec(.stack_magic);
|
||||
u32 stack_magic0[4] sec(.stack_magic0);
|
||||
extern void flash_fs_v2_update_init(void);
|
||||
extern void p33_pinr_tmr_restart(void);
|
||||
extern u8 p33_get_reset_pin(void);
|
||||
void exception_analyze(unsigned int *sp);
|
||||
void exception_irq_handler(void);
|
||||
void port_init();
|
||||
|
||||
int norflash_dev_open(struct dev_node *node, struct device **device, void *arg);
|
||||
int norflash_no_sr_mode_write_protect(u8 sr_mode, u8 wr_en_mode, u32 sr1, u32 sr2);
|
||||
|
||||
__attribute__((weak))
|
||||
void save_sfr_before_soft_reset(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
u8 val[16];
|
||||
u8 pll_scr = 0;
|
||||
|
||||
save_sfr_before_soft_reset();
|
||||
|
||||
#if defined(CONFIG_CPU_BD49) || defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BD45) || defined(CONFIG_CPU_SH58)
|
||||
mask_api_init(putchar, exception_analyze);
|
||||
#else
|
||||
mask_api_init(putchar, NULL);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CPU_WL83)
|
||||
switch_sysclk(HSB_SEL_PLL_96M);
|
||||
#else
|
||||
/* JL_CLOCK->CLK_CON0 |= BIT(8); //OSC24M -> STD24M */
|
||||
uart_init("PA05", 2000000); //debug串口
|
||||
/* uart_init("PC05", 2000000); //debug串口 */
|
||||
#endif
|
||||
|
||||
printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
|
||||
|
||||
memset((u8 *)&inside_flash_pdata, 0, sizeof(struct flash_platform_data));
|
||||
inside_flash_pdata.spi_pdata.width = 2;
|
||||
inside_flash_pdata.spi_pdata.clk_div = 3;
|
||||
inside_flash_pdata.read_mode = 0;
|
||||
#if defined(CONFIG_CPU_BR35)
|
||||
inside_flash_pdata.spi_pdata.port = !!(JL_SFC_IOMC->IOMC0 & BIT(1));
|
||||
#endif
|
||||
|
||||
inside_flash_pdata.flash_type = DEV_FLASH_INTERNAL_NORFLASH;
|
||||
void *device;
|
||||
norflash_dev_open(NULL, (void *)&device, &inside_flash_pdata);
|
||||
/* norflash_init(&inside_flash_pdata); */
|
||||
|
||||
// by xuebo
|
||||
#if !defined(CONFIG_CPU_WL83)
|
||||
sys_clk_init(OSC_FREQ, SYS_CLK);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CPU_SH58) && USB_HOST_MODULE_CONTROL
|
||||
set_sys_clk(96000000); //SH58 U盘升级需要提高系统时钟
|
||||
#endif
|
||||
|
||||
printf(">>>[test]:+++++++++++++\n");
|
||||
|
||||
#if (UPDIFF_FLASH_UPDATE_SUPPORT_EN||COMBAK_FLASH_UPDATE_SUPPORT_EN) && \
|
||||
(defined(CONFIG_CPU_BR52) || defined(CONFIG_CPU_BR56) || defined(CONFIG_CPU_BR50))
|
||||
asm("btbclr");
|
||||
q32DSP(0)->PMU_CON1 &= ~BIT(8); //open bpu
|
||||
SFR(JL_HSBCLK->HSB_SEL, 0, 3, 6);//sys 96MHz
|
||||
#endif
|
||||
|
||||
flash_fs_v2_update_init(); //存在偏移情况,先提前获取。
|
||||
|
||||
#ifdef __DEBUG
|
||||
#if !defined(CONFIG_CPU_WL83)
|
||||
u8 *ptr = jlfs_get_isd_cfg_ptr();
|
||||
memset(val, 0, sizeof(val));
|
||||
dec_isd_cfg_ini("PLL_SRC", val, ptr);
|
||||
if (strcmp((char *)val, "LRC") == 0) {
|
||||
pll_scr = 2;
|
||||
}
|
||||
u32 ut_buad = 0;
|
||||
char uttx[8] = {0};
|
||||
memset(uttx, 0, sizeof(uttx));
|
||||
dec_isd_cfg_ini("UTTX", uttx, ptr);
|
||||
dec_isd_cfg_ini("UTBD", &ut_buad, ptr);
|
||||
|
||||
uart_init(uttx, ut_buad);
|
||||
|
||||
/* reset_source_dump(); */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (UPDIFF_FLASH_UPDATE_SUPPORT_EN||COMBAK_FLASH_UPDATE_SUPPORT_EN) && \
|
||||
(defined(CONFIG_CPU_BR52))
|
||||
loader_charge_init();
|
||||
#endif
|
||||
/* uart_init("USBDP", 1000000); //debug串口 */
|
||||
log_info("\n****************** Hello Ota loader DATE:%s TIME:%s *****************\n\n", __DATE__, __TIME__);
|
||||
|
||||
#if defined(CONFIG_CPU_BD49) || defined(CONFIG_CPU_SH58)
|
||||
power_early_init(NULL);
|
||||
#endif
|
||||
|
||||
|
||||
//解除写保护
|
||||
norflash_no_sr_mode_write_protect(0, 0, 0, 0);
|
||||
|
||||
//关闭长按复位,打印复位寄存器值方便查看 2023_10_07 by phewlee
|
||||
p33_get_reset_pin();
|
||||
reset_pin_close();
|
||||
p33_get_reset_pin();
|
||||
|
||||
extern void lrc_init(void);
|
||||
lrc_init();
|
||||
|
||||
wdt_init(WDT_4s);
|
||||
|
||||
|
||||
|
||||
/*初始化异常中断*/
|
||||
request_irq(IRQ_EXCEPTION_IDX, 2, exception_irq_handler, 0);
|
||||
debug_init();
|
||||
|
||||
/* request_irq(IRQ_SOFT0_IDX, 2, soft_irq_handler, 0); */
|
||||
/* */
|
||||
/* irq_set_pending(IRQ_SOFT0_IDX); */
|
||||
/* while(1); */
|
||||
/*初始化sys_timer*/
|
||||
sys_timer_init();
|
||||
|
||||
//ldoin长按复位功能如果开启,定时出现启动
|
||||
#if !defined(CONFIG_CPU_BD49) && !defined(CONFIG_CPU_BD47) && !defined(CONFIG_CPU_BD45)
|
||||
sys_timer_add(NULL, (void *)p33_pinr_tmr_restart, 500);
|
||||
#endif
|
||||
|
||||
|
||||
//获取POWER_PIN参数, 防止部分触摸ic掉电一半再上电状态异常
|
||||
#if (0 == UART_UPDATE_ONLY_TEST_MODE && UPDATE_GET_POWER_PIN)
|
||||
if (get_power_pin_multi(&pp_handle.gpio[0], &pp_handle.level[0], PP_N)) {
|
||||
for (int i = 0; i < PP_N; i++) {
|
||||
printf(">>>[test]:gpio[%d] = %d\n", i, pp_handle.gpio[i]);
|
||||
if (pp_handle.gpio[i] == 0) {
|
||||
break;
|
||||
}
|
||||
gpio_set_direction(pp_handle.gpio[i], 0);
|
||||
gpio_set_die(pp_handle.gpio[i], 1);
|
||||
//先输出低是为了释放该io的电容的电,达到快速拉低目的,防止部分触摸ic掉电一半再上电状态异常;
|
||||
gpio_set_output_value(pp_handle.gpio[i], 0);
|
||||
udelay(100);
|
||||
gpio_set_output_value(pp_handle.gpio[i], pp_handle.level[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
update_main();
|
||||
|
||||
while (1) {
|
||||
putchar('o');
|
||||
udelay(1000 * 1000);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".log_config.data.bss")
|
||||
#pragma data_seg(".log_config.data")
|
||||
#pragma const_seg(".log_config.text.const")
|
||||
#pragma code_seg(".log_config.text")
|
||||
#endif
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
#ifdef __SUPPORT_OUTSIDE_FLASH
|
||||
const u8 support_operat_outside_flash = 1;
|
||||
#else
|
||||
const u8 support_operat_outside_flash = 0;
|
||||
#endif
|
||||
|
||||
#ifdef __FLASH_SUPPORT_CONTINUE_READ_MODE
|
||||
const u8 flash_support_continue_read_mode = 1;
|
||||
#else
|
||||
const u8 flash_support_continue_read_mode = 0;
|
||||
#endif
|
||||
|
||||
#ifdef __FLASH_SUPPORT_4BIT_MODE
|
||||
const u8 flash_support_4bit_mode = 1;
|
||||
#else
|
||||
const u8 flash_support_4bit_mode = 0;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __DEBUG
|
||||
const char libs_debug AT(.LOG_TAG_CONST) = TRUE; //打印总开关
|
||||
#else
|
||||
const char libs_debug AT(.LOG_TAG_CONST) = FALSE; //打印总开关
|
||||
#endif
|
||||
|
||||
#define CONFIG_DEBUG_LIBS(X) (X & libs_debug)
|
||||
|
||||
|
||||
const char log_tag_const_i_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_DEBUG AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_DEBUG AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_DEBUG AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
#if defined(CONFIG_CPU_SH58) || (defined(CONFIG_CPU_BR29) && defined(BLE_APP_LOW_RAM_USED))
|
||||
const char log_tag_const_i_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
#else
|
||||
const char log_tag_const_i_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
#endif
|
||||
|
||||
const char log_tag_const_i_EFUSE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_EFUSE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_EFUSE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
#if defined(CONFIG_CPU_SH58)
|
||||
const char log_tag_const_i_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
#else
|
||||
const char log_tag_const_i_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
#endif
|
||||
|
||||
const char log_tag_const_i_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
#if defined(CONFIG_CPU_SH58)
|
||||
const char log_tag_const_i_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
#else
|
||||
const char log_tag_const_i_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
#endif
|
||||
|
||||
const char log_tag_const_i_LOADER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_LOADER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_LOADER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_LOADER_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_LOADER_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_LOADER_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_APP_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_APP_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_APP_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_RCSP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_RCSP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_RCSP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_USER_LC_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_USER_LC_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_USER_LC_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_EX_NOR_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_EX_NOR_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_EX_NOR_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_USB_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_USB_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_USB_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_UT_ANALYZE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_UT_ANALYZE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_UT_ANALYZE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_BT_CFG_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_BT_CFG_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_BT_CFG_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_UT_UPDATE_DRIVER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_UT_UPDATE_DRIVER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_UT_UPDATE_DRIVER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_UT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_UT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_UT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_BT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_BT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_BT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_UPDATE_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_UPDATE_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_UPDATE_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_UPDATE_AREA AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_UPDATE_AREA AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_UPDATE_AREA AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_HCI_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_HCI_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_HCI_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_HCI_STD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_HCI_STD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_HCI_STD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LBUF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LBUF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LBUF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_MISC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_MISC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_MISC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_BDMGR AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_BDMGR AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_BDMGR AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_RF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_RF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_RF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LE_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LE_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LE_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LE5_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LE5_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LE5_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_Thread AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_Thread AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_Thread AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_E AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_E AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_E AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_S AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_S AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_S AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_PHY AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_PHY AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_PHY AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_ADV AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_ADV AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_ADV AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_SCAN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_SCAN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_SCAN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_INIT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_INIT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_INIT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_LL_AFH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_LL_AFH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_LL_AFH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_HCI_LL5 AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_HCI_LL5 AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_HCI_LL5 AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_HCI_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_HCI_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_HCI_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_BLE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_BLE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_BLE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_RESERVED_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_RESERVED_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_RESERVED_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_EX_API_CODE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_EX_API_CODE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_EX_API_CODE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_RESET AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_RESET AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_RESET AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_DECOM AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_DECOM AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_DECOM AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_COMBAK_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_COMBAK_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_COMBAK_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_UPDIFF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_UPDIFF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_UPDIFF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
const char log_tag_const_i_UPDIFF_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_d_UPDIFF_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
const char log_tag_const_e_UPDIFF_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
|
||||
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".testbox_ble_update.data.bss")
|
||||
#pragma data_seg(".testbox_ble_update.data")
|
||||
#pragma const_seg(".testbox_ble_update.text.const")
|
||||
#pragma code_seg(".testbox_ble_update.text")
|
||||
#endif
|
||||
#include "update_main.h"
|
||||
#include "power/p33.h"
|
||||
#include "common.h"
|
||||
#include "msg.h"
|
||||
#include "sys_timer.h"
|
||||
#include "btctrler_api_for_update.h"
|
||||
#include "testbox_update.h"
|
||||
#include "timer.h"
|
||||
#include "delay.h"
|
||||
#include "uart.h"
|
||||
#include "wdt.h"
|
||||
#include "clock.h"
|
||||
|
||||
#define LOG_TAG_CONST BLE_UPDATE
|
||||
#define LOG_TAG "[BLE_UPDATE]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_DUMP_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------extern start-------------------------------//
|
||||
extern int le_controller_set_mac(void *addr);
|
||||
extern void bt_ble_init(void);
|
||||
extern void btstack_init(void);
|
||||
extern void dynamic_mem_init(void *malloc_pool, int malloc_size);
|
||||
extern void ble_rx_update_handle_register(void (* handle)(void *, u8 *, u32));
|
||||
extern void ll_vendor_update_req_handle_register(void (*handle)(u8 *data, u16 len));
|
||||
extern void ll_update_send_data_handle(u8 btupdate_sw, u16 len, u8 seek_type, u32 seek_offsize);
|
||||
extern void update_set_trim_info(u8 *trim);
|
||||
extern void register_ll_update_handle(void (*rx_handler)(void *, u8 *, u32), void (*hook)(void *));
|
||||
//-----------------------------extern end--------------------------------//
|
||||
|
||||
//-----------------------------local start--------------------------------//
|
||||
static u16 ble_f_open(void);
|
||||
static u16 ble_f_read(void *fp, u8 *buf, u16 len);
|
||||
static int ble_f_seek(void *fp, u8 type, u32 offset);
|
||||
static u16 ble_send_update_len(u32 update_len);
|
||||
static void ble_update_state_cbk(u32 status, void *priv);
|
||||
|
||||
static testbox_update_info update_info = {
|
||||
.mutil_ufw_offset = 0,
|
||||
};
|
||||
#define __this (&update_info)
|
||||
|
||||
#ifdef CONFIG_BTCTRLE_V2_ENABLE
|
||||
#if defined(CONFIG_CPU_BD47)
|
||||
#define MALLOC_POOL_SIZE ((1024 + 308) * 4)
|
||||
#else
|
||||
#define MALLOC_POOL_SIZE ((1024 + 308) * 6)
|
||||
#endif
|
||||
#else
|
||||
#define MALLOC_POOL_SIZE ((1024 + 308) * 4)
|
||||
#endif
|
||||
u32 malloc_pool[MALLOC_POOL_SIZE / 4];
|
||||
u32 malloc_pool_size = MALLOC_POOL_SIZE;
|
||||
|
||||
update_op_api_t ble_op_api = {
|
||||
.f_open = ble_f_open,
|
||||
.f_read = ble_f_read,
|
||||
.f_seek = ble_f_seek,
|
||||
.notify_update_content_size = ble_send_update_len,
|
||||
};
|
||||
|
||||
update_mode_info_t update_mode_info = {
|
||||
.type = BLE_TEST_UPDATA,
|
||||
.state_cbk = ble_update_state_cbk,
|
||||
.file_op = &ble_op_api,
|
||||
};
|
||||
|
||||
//-----------------------------local end--------------------------------//
|
||||
|
||||
static void ble_update_control(u8 btupdata_sw, u16 len, u8 seek_type, u32 seek_offsize)
|
||||
{
|
||||
ll_update_send_data_handle(btupdata_sw, len, seek_type, seek_offsize);
|
||||
}
|
||||
|
||||
//ble升级数据回调
|
||||
static int ble_updata_handle(void *priv, void *buf, int len)
|
||||
{
|
||||
if (__this->read_buf && (__this->state == UPDATA_REV_DATA)) {
|
||||
if (__this->need_rx_len >= __this->data_len + len) {
|
||||
memcpy(__this->read_buf + __this->data_len, buf, len);
|
||||
__this->data_len += len;
|
||||
}
|
||||
|
||||
if (__this->need_rx_len == __this->data_len) {
|
||||
__this->state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16 ble_f_open(void)
|
||||
{
|
||||
log_info("---------UPDATA_OPEN----------\n");
|
||||
__this->file_offset = 0;
|
||||
__this->seek_type = SEEK_SET;
|
||||
ble_update_control(UPDATA_OPEN, 0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16 ble_f_read(void *fp, u8 *buff, u16 len)
|
||||
{
|
||||
__this->state = UPDATA_REV_DATA;
|
||||
__this->need_rx_len = len;
|
||||
__this->data_len = 0;
|
||||
__this->read_buf = buff;
|
||||
|
||||
ble_update_control(UPDATA_READ_OFFSIZE, len, __this->seek_type, __this->file_offset);
|
||||
|
||||
__this->bt_time_timeout = 0;
|
||||
|
||||
while (__this->state && __this->bt_time_timeout < UPDATE_CMD_WAIT_TIMEOUT);
|
||||
|
||||
if (__this->data_len == len) {
|
||||
__this->file_offset += len;
|
||||
return len;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;//FR_OK;
|
||||
}
|
||||
|
||||
int ble_f_seek(void *fp, u8 type, u32 offset)
|
||||
{
|
||||
if (type == SEEK_SET) {
|
||||
offset += __this->mutil_ufw_offset;
|
||||
__this->file_offset = offset;
|
||||
} else if (type == SEEK_CUR) {
|
||||
__this->file_offset += offset;
|
||||
}
|
||||
|
||||
__this->seek_type = type;
|
||||
|
||||
return 0;//FR_OK;
|
||||
}
|
||||
|
||||
//ufw嵌套ufw格式处理
|
||||
void mutil_cpu_set_offset(u32 offset)
|
||||
{
|
||||
__this->mutil_ufw_offset = offset;
|
||||
__this->file_offset = __this->mutil_ufw_offset; //预先设置好偏移
|
||||
}
|
||||
|
||||
u16 ble_f_stop(u8 err)
|
||||
{
|
||||
log_info("---------bt_f_stop <<---------- 0x%x\n", err);
|
||||
if (BT_UPDATE_OVER == err) {
|
||||
ble_update_control(UPDATA_STOP, 0, 0, 0);
|
||||
} else if (BT_UPDATE_KEY_ERR == err) {
|
||||
ble_update_control(UPDATA_STOP_KEYERR, 0, 0, 0);
|
||||
} else {
|
||||
ble_update_control(UPDATA_STOP, err, 0, 0);
|
||||
}
|
||||
ble_rx_update_handle_register(NULL);
|
||||
/* delay_2ms(500); */
|
||||
mdelay(1000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
u16 ble_send_update_len(u32 update_len)
|
||||
{
|
||||
log_info("---------send_update_len:%x----------\n", update_len);
|
||||
ble_update_control(UPDATA_SEEK, 0, BT_SEEK_TYPE_UPDATE_LEN, update_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ble_update_result_report(u8 err)
|
||||
{
|
||||
u8 res;
|
||||
switch (err) {
|
||||
case UPDATE_ERR_NONE:
|
||||
res = BT_UPDATE_OVER;
|
||||
break;
|
||||
|
||||
case UPDATE_ERR_KEY_ERR:
|
||||
res = BT_UPDATE_KEY_ERR;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = fs_update_result_transition(err);
|
||||
break;
|
||||
}
|
||||
|
||||
log_info("f_stop:%x\n", res);
|
||||
ble_f_stop(res);
|
||||
}
|
||||
|
||||
static void update_test_user_handler(u8 *data, u16 len)
|
||||
{
|
||||
log_info("--set update handle--\n");
|
||||
ble_rx_update_handle_register(ble_updata_handle);
|
||||
register_ll_update_handle(ble_updata_handle, NULL);
|
||||
__this->state = UPDATA_START;
|
||||
}
|
||||
|
||||
void ble_updata_init()
|
||||
{
|
||||
dynamic_mem_init(malloc_pool, malloc_pool_size);
|
||||
ll_vendor_update_req_handle_register(update_test_user_handler);
|
||||
task_message_init();
|
||||
btstack_init();
|
||||
bt_ble_init();
|
||||
sys_timer_add(NULL, stack_run_loop_resume, 5);
|
||||
init_soft_interrupt(); //btstack loop软中断初始化
|
||||
}
|
||||
|
||||
void bt_update_timeout(void *priv)
|
||||
{
|
||||
__this->bt_time_timeout ++;
|
||||
}
|
||||
|
||||
static u32 ble_connect_check_time = 0;
|
||||
static void ble_update_connect_check(void *priv)
|
||||
{
|
||||
ble_connect_check_time ++;
|
||||
while (__this->state == UPDATA_START) { //wait testbox start update
|
||||
ble_connect_check_time = 0;
|
||||
}
|
||||
if (ble_connect_check_time > 10) {
|
||||
#if OTA_LOADER_RECORD_RST_INFO_CONFIG
|
||||
ota_loader_record_rst_info();
|
||||
#endif
|
||||
update_reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ble_update_state_cbk(u32 status, void *priv)
|
||||
{
|
||||
UPDATA_PARM *p = priv;
|
||||
switch (status) {
|
||||
case UPDATE_PARM: //升级需要的参数
|
||||
log_info("ble_mac_addr:\n");
|
||||
log_info_hexdump(p->parm_priv, 6);
|
||||
le_controller_set_mac(p->parm_priv);//BLE广播地址
|
||||
#ifdef CONFIG_BTCTRLE_V2_ENABLE
|
||||
update_set_trim_info(update_param_ext_get(priv, EXT_LDO_TRIM_RES));
|
||||
#endif
|
||||
u8 *wla_data = update_param_ext_get(priv, EXT_BT_WLA_INFO);
|
||||
if (wla_data) {
|
||||
u32 wla_con[3];
|
||||
printf("wla data:\n");
|
||||
printf_buf(wla_data, 12);
|
||||
memcpy((u8 *)wla_con, wla_data, sizeof(wla_con));
|
||||
btosc_upgrade_cfg(wla_con);
|
||||
}
|
||||
break;
|
||||
case UPDATE_START:
|
||||
log_info("BT_UPDATE_START...\n");
|
||||
ble_updata_init();
|
||||
sys_timer_add(NULL, bt_update_timeout, 10);
|
||||
sys_timer_add(NULL, ble_update_connect_check, 60000);
|
||||
while (__this->state != UPDATA_START) { //wait testbox start update
|
||||
wdt_clear();//清看门狗
|
||||
}
|
||||
break;
|
||||
|
||||
case UPDATE_END: //升级结束需要保存结果到Ram给SDK获取,并回复主机升级结果
|
||||
log_info("UPDATE_END\n");
|
||||
if (*((u8 *)priv) == UPDATE_ERR_NONE) {
|
||||
set_updata_result(BLE_TEST_UPDATA, UPDATA_SUCCESSFULLY);
|
||||
} else {
|
||||
set_updata_result(BLE_TEST_UPDATA, UPDATA_DEV_ERR);
|
||||
}
|
||||
ble_update_result_report(*((u8 *)priv));
|
||||
/* cpu_reset(); */
|
||||
update_reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS_APP
|
||||
#pragma bss_seg(".update_main.data.bss")
|
||||
#pragma data_seg(".update_main.data")
|
||||
#pragma const_seg(".update_main.text.const")
|
||||
#pragma code_seg(".update_main.text")
|
||||
#endif
|
||||
#include "common.h"
|
||||
#include "crc.h"
|
||||
#include "update_main.h"
|
||||
#include "lib_include.h"
|
||||
#include "power/p33.h"
|
||||
#include "dec.h"
|
||||
#include "jlfs.h"
|
||||
|
||||
#include "gpio.h"
|
||||
#include "power/power_reset.h"
|
||||
|
||||
|
||||
#define LOG_TAG_CONST UPDATE_MAIN
|
||||
#define LOG_TAG "[UPDATE_MAIN]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_DUMP_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
extern update_mode_info_t update_mode_info;
|
||||
extern void update_get_record_form_flash(u8 *ram);
|
||||
extern void update_get_record_form_flash_v2(u8 **p);
|
||||
extern u8 *update_param_ext_get(UPDATA_PARM *p, u8 ext_type);
|
||||
extern int update_loop(update_op_api_t *update_op);
|
||||
extern void user_api_special_handle_info_set(UPDATA_PARM *p);
|
||||
|
||||
void ram_protect_close(void);
|
||||
void bredr_bd_close();
|
||||
void ll_hci_destory(void);
|
||||
void update_enter_jump_maskrom(void);
|
||||
void latch_reset(void);
|
||||
static u8 latch_flag = 0;
|
||||
void jump_mode_check(u8 *p);
|
||||
extern void latch_unlock(void);
|
||||
extern void reserved_area_update_file_disable(void);
|
||||
|
||||
#define __this (&update_mode_info)
|
||||
|
||||
// 从扩展升级参数中取出信息,判断是否不升级升级预留区域
|
||||
static u8 reserved_update_check(u8 *p)
|
||||
{
|
||||
u8 *reserved_zone_update_flag = update_param_ext_get((UPDATA_PARM *)p, EXT_RESERVED_UPDATE);
|
||||
if (reserved_zone_update_flag && reserved_zone_update_flag[0]) {
|
||||
reserved_area_update_file_disable();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 new_sdk_update_again_flag_get(u8 *p)
|
||||
{
|
||||
u8 *update_again_flag = update_param_ext_get((UPDATA_PARM *)p, EXT_NEW_SDK_UPD_AGAIN);
|
||||
if (update_again_flag && update_again_flag[0]) {
|
||||
return update_again_flag[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//检查ram里的update信息
|
||||
bool update_check(void)
|
||||
{
|
||||
u16 crc_cal;
|
||||
//check_updata_parm is valid
|
||||
UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR; //定位到ram1最后地址
|
||||
log_info("update param:");
|
||||
log_info_hexdump((u8 *)p, sizeof(UPDATA_PARM));
|
||||
log_info("update param priv:");
|
||||
log_info_hexdump(p->parm_priv, 32);
|
||||
crc_cal = chip_crc16(((u8 *)p) + 2, sizeof(UPDATA_PARM) - 2);
|
||||
if (crc_cal && crc_cal == p->parm_crc) {
|
||||
if ((NON_DEV_UPDATA != p->parm_type) && (UPDATA_READY == p->parm_result)) {
|
||||
log_info("update_check ture\n");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#define SDK_JUMP_FLAG "SDKJUMP"
|
||||
#define OTA_JUMP_FLAG "OTAJUMP"
|
||||
UPDATE_MODE uart_update_judge_startup_mode(void)
|
||||
{
|
||||
#if defined(UART_USE_SEC_MODE) && UART_USE_SEC_MODE
|
||||
// 由一级loader跳转
|
||||
if (strcmp((const char *)UART_UPDATE_FLAG_ADDR, OTA_JUMP_FLAG) == 0)
|
||||
#else
|
||||
// 由SDK跳转
|
||||
if (strcmp((const char *)UART_UPDATE_FLAG_ADDR, SDK_JUMP_FLAG) == 0)
|
||||
#endif
|
||||
{
|
||||
memset((u8 *)UART_UPDATE_FLAG_ADDR, 0, 4);
|
||||
return UPDATE_JUMP;
|
||||
}
|
||||
|
||||
return UPDATE_POWERON; // 复位或者断电重启
|
||||
}
|
||||
|
||||
//写升级标志到ram to SDK, 通知SDK升级结果
|
||||
void set_updata_result(u16 type, u16 result)
|
||||
{
|
||||
UPDATA_PARM *p;
|
||||
|
||||
log_info("set update result :0x%x 0x%x\n", type, result);
|
||||
p = (UPDATA_PARM *)UPDATE_FLAG_ADDR;
|
||||
memset(p, 0x0, sizeof(UPDATA_PARM));
|
||||
p->parm_result = result;
|
||||
p->magic = type;
|
||||
p->parm_crc = chip_crc16(((u8 *)p) + 2, sizeof(UPDATA_PARM) - 2);
|
||||
}
|
||||
|
||||
#define LATCH_IO_NUM 10
|
||||
/* static u32 latch_io[LATCH_IO_NUM] = {0}; */
|
||||
static u8 val[LATCH_IO_NUM * 7 + 1] = {0};
|
||||
//格式为PB01&0_PB02&1 &0\1表示输出低或者高
|
||||
|
||||
#if UPDATE_COMPATIBILITY_EN
|
||||
static void mutual_get_update_latch_io(u8 *pos)
|
||||
{
|
||||
if (!pos) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
u32 keep_io = get_gpio(&pos[i * 5]);
|
||||
printf(" latch_io[%d] = %d, %s\n", i, keep_io, &pos[i * 5]);
|
||||
if (keep_io < IO_PORT_MAX) {
|
||||
gpio_set_direction(keep_io, 0);
|
||||
gpio_set_output_value(keep_io, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static u32 update_set_latch_io(void)
|
||||
{
|
||||
u8 *ptr = jlfs_get_isd_cfg_ptr();
|
||||
#if UPDATE_COMPATIBILITY_EN
|
||||
if (dec_isd_cfg_ini("SD_LATCH_IO", (void *)val, ptr)) {
|
||||
u8 *pos = &val[0];
|
||||
mutual_get_update_latch_io(pos);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (dec_isd_cfg_ini("LATCH_IO", (void *)val, ptr)) {
|
||||
put_buf(val, sizeof(val));
|
||||
int len = strlen((const char *)val);
|
||||
|
||||
int i = 0;
|
||||
u8 *val_s = &val[0];
|
||||
char *pos = (char *)&val[0];
|
||||
u8 io_arg[10];
|
||||
while (1) {
|
||||
if (len < i * 7) {
|
||||
break;
|
||||
}
|
||||
//获取‘&’的位置,获取高低电平设置
|
||||
char *level = strchr((const char *)pos, '&');
|
||||
#if UPDATE_COMPATIBILITY_EN
|
||||
if (level == NULL) {
|
||||
mutual_get_update_latch_io(pos);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
u8 value = (u8)(level[1] - '0');
|
||||
|
||||
//获取IO的字符串,传给gpio();
|
||||
u32 io_len = (u32)(level - pos);
|
||||
memset(io_arg, 0, sizeof(io_arg));
|
||||
memcpy(io_arg, pos, io_len);
|
||||
u32 keep_io = get_gpio((const char *)io_arg);
|
||||
|
||||
//设置IO状态
|
||||
printf(" latch_io[%d] = %d, %s, value = %d\n", i, keep_io, io_arg, value);
|
||||
#ifdef IO_PORT_USB_MASK
|
||||
if (keep_io == IO_PORT_DP || keep_io == IO_PORT_DM) {
|
||||
gpio_set_direction(keep_io, 1);
|
||||
gpio_set_pull_up(keep_io, value);
|
||||
gpio_set_pull_down(keep_io, !value);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
gpio_set_direction(keep_io, 0);
|
||||
gpio_set_output_value(keep_io, value);
|
||||
}
|
||||
|
||||
//基指针偏移
|
||||
pos = strchr((const char *)pos, '_');
|
||||
if (pos == NULL) {
|
||||
break;
|
||||
}
|
||||
pos ++;
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void update_set_latch()
|
||||
{
|
||||
if (update_set_latch_io() != -1) {
|
||||
latch_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_CPU_BD49)
|
||||
struct boot_soft_flag_t boot_flag = {0};
|
||||
#endif
|
||||
|
||||
void update_main()
|
||||
{
|
||||
UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR;
|
||||
UPDATE_MODE mode = UPDATE_JUMP;
|
||||
UPDATA_RESULT result = UPDATA_RESULT_FAIL;
|
||||
|
||||
#if !UART_UPDATE_ONLY_TEST_MODE
|
||||
//update_check
|
||||
if (update_check() == FALSE) { //RAM中的结构体不存在, 判断为断电重新上电
|
||||
log_info("Ota Start PowerOn\n");
|
||||
mode = UPDATE_POWERON;
|
||||
} else {
|
||||
#if (UART_UPDATA_MODULE_CONTROL || UART_UPDATA_USER_MODULE_CONTROL)
|
||||
mode = uart_update_judge_startup_mode();
|
||||
#endif
|
||||
}
|
||||
log_info("mode : %d\n", mode);
|
||||
|
||||
#if UPDIFF_FLASH_UPDATE_SUPPORT_EN
|
||||
update_get_record_form_flash_v2(&p); //从flash里把参数读出来,遍历整个flash
|
||||
#else
|
||||
|
||||
update_get_record_form_flash((u8 *)&p); //从flash里把参数读出来
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* TODO */
|
||||
u8 *data = update_param_ext_get(p, EXT_RF_PA_INFO);
|
||||
put_buf(data, 3);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
jump_mode_check((u8 *)p);
|
||||
|
||||
if (latch_flag) {
|
||||
#if defined(CONFIG_CPU_BD49)
|
||||
memset(&boot_flag, 0, sizeof(struct boot_soft_flag_t));
|
||||
u8 *romio_info = update_param_ext_get((UPDATA_PARM *)p, EXT_KEEP_ROMIO_INFO);
|
||||
if (romio_info) {
|
||||
memcpy(&boot_flag, romio_info, sizeof(struct boot_soft_flag_t));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
reserved_update_check((u8 *)p);
|
||||
|
||||
user_api_special_handle_info_set(p);
|
||||
|
||||
#if defined(CONFIG_CPU_BR35)
|
||||
u16 type = p->parm_type;
|
||||
u8 update_again_flag = new_sdk_update_again_flag_get(p);
|
||||
#endif
|
||||
|
||||
#if (defined(CONFIG_CPU_BR35) && (USER_LC_FLASH_UPDATA_MODULE_CONTROL || EX_FLASH_UPDATE_SUPPORT_EN))
|
||||
extern void ota_get_sys_clk(u8 * param);
|
||||
u8 *tmp_buf = update_param_ext_get((UPDATA_PARM *)p, EXT_SYS_CLK_PARAM);
|
||||
if (tmp_buf) {
|
||||
ota_get_sys_clk(tmp_buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
update_set_latch(); //升级前解除latch,处理SD卡和外置flash这种需要动IO的升级方式
|
||||
|
||||
/* mode = UPDATE_POWERON; */
|
||||
//给各升级模块传递参数
|
||||
log_info(">>>[test]:UPDATE_STEP: SET UPDATE_PARM\n");
|
||||
__this->state_cbk(UPDATE_PARM, p);
|
||||
|
||||
log_info(">>>[test]:UPDATE_STEP: UPDATE_START, mode = 0x%x\n", mode);
|
||||
__this->state_cbk(UPDATE_START, &mode);
|
||||
|
||||
#if !UART_UPDATE_ONLY_TEST_MODE
|
||||
//loop
|
||||
log_info(">>>[test]:UPDATE_STEP: update_loop\n");
|
||||
result = update_loop((update_op_api_t *)__this->file_op);
|
||||
|
||||
log_info(">>>[test]:UPDATE_STEP: UPDATE_END, result = 0x%x\n", result);
|
||||
//end
|
||||
#if (defined(CONFIG_CPU_BR35) && (defined(EDR_UPDATA_SUPPORT_CONNECT) || defined(BLE_UPDATA_SUPPORT_CONNECT)))
|
||||
if (update_again_flag) {
|
||||
set_updata_result(type, UPDATA_DEV_ERR);
|
||||
update_reset();
|
||||
}
|
||||
#endif
|
||||
__this->state_cbk(UPDATE_END, &result); //不同升级完成之后可能需要执行不同操作
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
u8 *get_isd_cfg_ptr(void)
|
||||
{
|
||||
return jlfs_get_isd_cfg_ptr();
|
||||
}
|
||||
|
||||
u32 get_update_jump_flag()
|
||||
{
|
||||
u8 *ptr = jlfs_get_isd_cfg_ptr();
|
||||
u32 u32Val;
|
||||
u8 val[16] = {0};
|
||||
printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
|
||||
if (dec_isd_cfg_ini("UPDATE_JUMP", (void *)val, ptr)) {
|
||||
put_buf(val, 16);
|
||||
/* u32Val = (u32) (((u8 *)val)[0] - '0'); */
|
||||
u32Val = (u32)val[0];
|
||||
printf("update_jump = %d, vol[0] = %d\n", u32Val, val[0]);
|
||||
return u32Val;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void jump_mode_check(u8 *p)
|
||||
{
|
||||
u8 *p_latch_flag = NULL;
|
||||
if (latch_flag == 0) {
|
||||
p_latch_flag = update_param_ext_get((UPDATA_PARM *)p, EXT_JUMP_FLAG);
|
||||
if (p_latch_flag) {
|
||||
latch_flag = p_latch_flag[0];
|
||||
}
|
||||
}
|
||||
printf(">>>[test]:latch_flag = %d\n", latch_flag);
|
||||
}
|
||||
|
||||
u32 update_get_lrc_hz(void)
|
||||
{
|
||||
u32 lrc_hz = 0;
|
||||
UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR;
|
||||
memcpy(&lrc_hz, &p->parm_priv[sizeof(p->parm_priv) - sizeof(lrc_hz)], sizeof(lrc_hz));
|
||||
return lrc_hz;
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
void system_reset(enum RESET_FLAG flag)
|
||||
{
|
||||
cpu_reset();
|
||||
}
|
||||
|
||||
void update_reset(void)
|
||||
{
|
||||
printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
|
||||
/* 寄存器不会复位 */
|
||||
#if (0 == UART_UPDATE_ONLY_TEST_MODE)
|
||||
/* u8 *p = NULL; */
|
||||
/* UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR; */
|
||||
/* update_get_record_form_flash((u8 *)&p); //从flash里把参数读出来 */
|
||||
/* jump_mode_check((u8 *)p); */
|
||||
if (latch_flag) {
|
||||
puts("latch reset...\n");
|
||||
void latch_reset(void);
|
||||
latch_reset();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
printf(">>>[test]:cpu_reset\n");
|
||||
system_reset(UPDATE_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_CPU_BD49)
|
||||
struct boot_soft_flag_t *latch_info_get(void)
|
||||
{
|
||||
int k = 0;
|
||||
int len = sizeof(struct boot_soft_flag_t);
|
||||
u8 *romio_info = NULL;
|
||||
u8 *p = &boot_flag;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (p[i] != 0) {
|
||||
k = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (k) {
|
||||
romio_info = &boot_flag;
|
||||
}
|
||||
return (struct boot_soft_flag_t *)romio_info;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
@echo off
|
||||
|
||||
@echo ********************************************************************************
|
||||
@echo BR35 OTA LOADER
|
||||
@echo ********************************************************************************
|
||||
@echo %date%
|
||||
|
||||
cd /d %~dp0
|
||||
|
||||
set OBJDUMP=C:\JL\pi32\bin\llvm-objdump.exe
|
||||
set OBJCOPY=C:\JL\pi32\bin\llvm-objcopy.exe
|
||||
set TARGET_ELF=ota_loader.elf
|
||||
|
||||
set OTA_LOADER_PACKER=ota_loader.exe
|
||||
set UBOOT_PACKER=uboot_package.exe
|
||||
|
||||
echo %TARGET_ELF%
|
||||
|
||||
set PROJECT_TYPE=ble_ota
|
||||
|
||||
%OBJCOPY% -O binary -j .text %TARGET_ELF% %PROJECT_TYPE%_bank0.bin
|
||||
%OBJCOPY% -O binary -j .ver_tag %TARGET_ELF% ota_loader_ver.bin
|
||||
%OBJCOPY% -O binary -j .version %TARGET_ELF% ota_loader.version
|
||||
%OBJDUMP% -D -address-mask=0x7ffffff -print-imm-hex -print-dbg -mcpu=r3 %TARGET_ELF% > ota_loader.lst
|
||||
%OBJDUMP% -section-headers -address-mask=0x7ffffff %TARGET_ELF%
|
||||
REM %OBJDUMP% -t %TARGET_ELF% > symbol_tbl.txt
|
||||
|
||||
echo %PROJECT_TYPE%
|
||||
|
||||
copy %PROJECT_TYPE%_bank0.bin %PROJECT_TYPE%.bin
|
||||
|
||||
%OTA_LOADER_PACKER% 0x10c800 %PROJECT_TYPE%.bin compression ram
|
||||
|
||||
%UBOOT_PACKER% --info ota_loader.version --uboot ota.bin --output ota.bin
|
||||
Binary file not shown.
@@ -0,0 +1,173 @@
|
||||
// *INDENT-OFF*
|
||||
/*
|
||||
#-------------------------------------------------------+
|
||||
# br35 RAM mapping |
|
||||
#-------------------------------------------0x137000 ---| _RAM_LIMIT_H
|
||||
# |
|
||||
# |
|
||||
# ota-loader (194K:0x30A00) |
|
||||
# |
|
||||
# |
|
||||
#-------------------------------------------0x106600 ---|
|
||||
# |
|
||||
# uboot (16K:0x4000) |
|
||||
# |
|
||||
#-------------------------------------------0x102600 ---|
|
||||
# |
|
||||
# | ---------> user_api.bin end (0x10054c + 32K)
|
||||
#-------------------------------------------0x10054c ---| ---------> user_api.bin start(0x10054c)
|
||||
# Maskrom_export_RAM (0x34c) |
|
||||
#-------------------------------------------0x100200 ---|
|
||||
# |
|
||||
#-------------------------------------------0x100000 ---| _RAM_LIMIT_L
|
||||
*/
|
||||
|
||||
#include "maskrom_stubs.ld"
|
||||
|
||||
//from mask export
|
||||
ISR_BASE = _IRQ_MEM_ADDR;
|
||||
|
||||
UPDATA_SIZE = 0x200;
|
||||
|
||||
UPDATE_BEG = _RAM_LIMIT_H - UPDATA_SIZE;
|
||||
|
||||
UPDATA_BREDR_BASE_BEG = 0x137000 - 0x1000;
|
||||
|
||||
EX_CODE_BEGIN = 0x10054c; /*用户自定义UI代码的地址,根据不同CPU来配置*/
|
||||
EX_CODE_SIZE = 0xc2b4;
|
||||
|
||||
#if defined(DEV_UPDATE_MINI) && DEV_UPDATE_MINI
|
||||
SEC_OTA_CODE_BEGIN = 0x106600; /*第二级loader RAM地址*/
|
||||
OTA_CODE_BEGIN = 0x137000 - 0x6000; /*注意不要和uboot重叠*/
|
||||
/* OTA_CODE_BEGIN = 0x175000; #<{(|uart 测试盒串口升级开debug时修改|)}># */
|
||||
OTA_CODE_SIZE = 24K;
|
||||
|
||||
#else
|
||||
|
||||
OTA_CODE_BEGIN = EX_CODE_BEGIN + EX_CODE_SIZE; /*注意不要和uboot重叠*/
|
||||
OTA_CODE_SIZE = UPDATA_BREDR_BASE_BEG - OTA_CODE_BEGIN;
|
||||
#endif
|
||||
|
||||
// EX_CODE_BEGIN = 0x104000; /*用户自定义UI代码的地址,根据不同CPU来配置*/
|
||||
// EX_CODE_SIZE = 460K;
|
||||
|
||||
MEMORY
|
||||
{
|
||||
text_ram : ORIGIN = OTA_CODE_BEGIN, LENGTH = OTA_CODE_SIZE
|
||||
#if !defined(DEV_UPDATE_MINI) || (!DEV_UPDATE_MINI)
|
||||
bt_ram : ORIGIN = UPDATA_BREDR_BASE_BEG, LENGTH = 0x1000
|
||||
/* ex_code : ORIGIN = EX_CODE_BEGIN, LENGTH = EX_CODE_SIZE */
|
||||
reserved : ORIGIN = 0x0, LENGTH = 0x100
|
||||
version_ram :ORIGIN = 0x8000000, LENGTH = 128
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
ENTRY(_start);
|
||||
EXTERN(
|
||||
lib_ota_loader_version
|
||||
#if (EX_FLASH_UPDATE_SUPPORT_EN)
|
||||
device_table
|
||||
#endif
|
||||
);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ORIGIN(text_ram);
|
||||
.text :
|
||||
{
|
||||
*(.start*)
|
||||
*(.text*)
|
||||
*(.*.text)
|
||||
*(.data*)
|
||||
*(.*.data)
|
||||
*(.rodata*)
|
||||
*(.*.text.const)
|
||||
#if !defined(DEV_UPDATE_MINI) || (!DEV_UPDATE_MINI)
|
||||
*(.bredr_irq_code)
|
||||
*(.frame_irq_code)
|
||||
*(.classic_irq_code)
|
||||
*(.classic_irq_const)
|
||||
*(.volatile_ram_code)
|
||||
#endif
|
||||
. = ALIGN(32);
|
||||
|
||||
#if (EX_FLASH_UPDATE_SUPPORT_EN)
|
||||
_device_node_begin = .;
|
||||
PROVIDE(device_node_begin = .);
|
||||
*(.device)
|
||||
_device_node_end = .;
|
||||
PROVIDE(device_node_end = .);
|
||||
. = ALIGN(32);
|
||||
#endif
|
||||
} > text_ram
|
||||
|
||||
.bss ALIGN(32) (NOLOAD):
|
||||
{
|
||||
_cpu0_sstack_begin = .;
|
||||
*(.stack*)
|
||||
_cpu0_sstack_end = .;
|
||||
_cpu0_ustack_begin = .;
|
||||
*(.ustack*)
|
||||
_cpu0_ustack_end = .;
|
||||
|
||||
*(.bss)
|
||||
*(.*.data.bss)
|
||||
*(.usb_ep0)
|
||||
*(.usb_config_var)
|
||||
*(.update_buf)
|
||||
*(.bredr_rxtx_bulk)
|
||||
. = ALIGN(32);
|
||||
} > text_ram
|
||||
|
||||
.bss_noinit ALIGN(32) (NOLOAD):
|
||||
{
|
||||
*(.bss_noinit)
|
||||
. = ALIGN(32);
|
||||
} > text_ram
|
||||
|
||||
#if !defined(DEV_UPDATE_MINI) || (!DEV_UPDATE_MINI)
|
||||
. = ORIGIN(bt_ram);
|
||||
.bt_bss (NOLOAD) :SUBALIGN(4)
|
||||
{
|
||||
*(.bd_base)
|
||||
*(.comm_rf_para)
|
||||
*(.bd_base1)
|
||||
} > bt_ram
|
||||
|
||||
// . = ORIGIN(ex_code);
|
||||
// .ex_code (NOLOAD) :SUBALIGN(4)
|
||||
// {
|
||||
// . = LENGTH(ex_code);
|
||||
// } > ex_code
|
||||
|
||||
. = ORIGIN(reserved);
|
||||
.ver_tag ALIGN(4):
|
||||
{
|
||||
KEEP(*(.version_tag1))
|
||||
KEEP(*(.version_tag2))
|
||||
KEEP(*(.version_tag3))
|
||||
. = ALIGN(4);
|
||||
} > reserved
|
||||
|
||||
. = ORIGIN(version_ram);
|
||||
.version ALIGN(32):
|
||||
{
|
||||
*(.ota_loader.version)
|
||||
. = ALIGN(32);
|
||||
} > version_ram
|
||||
|
||||
|
||||
bt_ram_begin = ADDR(.bt_bss);
|
||||
bt_ram_size = SIZEOF(.bt_bss);
|
||||
#endif
|
||||
}
|
||||
|
||||
//================== Section Info Export ====================//
|
||||
text_begin = ADDR(.text);
|
||||
text_size = SIZEOF(.text);
|
||||
text_end = text_begin + text_size;
|
||||
|
||||
bss_begin = ADDR(.bss);
|
||||
bss_size = SIZEOF(.bss);
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,141 @@
|
||||
#ifndef __BLE_API_H__
|
||||
#define __BLE_API_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
///***注意:该文件的枚举与库编译密切相关,主要是给用户提供调用所用。用户不能自己在中间添加值。*/
|
||||
////----user (command) codes----////
|
||||
|
||||
/**
|
||||
* @brief hci connection handle type
|
||||
*/
|
||||
typedef uint16_t hci_con_handle_t;
|
||||
|
||||
typedef enum {
|
||||
/*
|
||||
*/
|
||||
BLE_CMD_ADV_ENABLE = 1,
|
||||
BLE_CMD_ADV_PARAM,
|
||||
BLE_CMD_ADV_DATA,
|
||||
BLE_CMD_RSP_DATA,
|
||||
BLE_CMD_DISCONNECT,
|
||||
BLE_CMD_REGIEST_THREAD,
|
||||
BLE_CMD_ATT_SEND_INIT,
|
||||
BLE_CMD_ATT_MTU_SIZE,
|
||||
BLE_CMD_ATT_VAILD_LEN,
|
||||
BLE_CMD_ATT_SEND_DATA,
|
||||
BLE_CMD_REQ_CONN_PARAM_UPDATE,
|
||||
|
||||
BLE_CMD_SCAN_ENABLE,
|
||||
BLE_CMD_SCAN_PARAM,
|
||||
BLE_CMD_STACK_EXIT,
|
||||
BLE_CMD_CREATE_CONN,
|
||||
BLE_CMD_CREATE_CONN_CANCEL,
|
||||
BLE_CMD_ADV_PARAM_EXT,
|
||||
BLE_CMD_SEND_TEST_KEY_NUM,
|
||||
//client
|
||||
BLE_CMD_SEARCH_PROFILE = 0x80,
|
||||
BLE_CMD_WRITE_CCC,
|
||||
} ble_cmd_type_e;
|
||||
|
||||
typedef enum {
|
||||
BLE_CMD_RET_SUCESS = 0, //
|
||||
BLE_CMD_RET_BUSY = -100, //
|
||||
BLE_CMD_PARAM_OVERFLOW, //
|
||||
BLE_CMD_OPT_FAIL, //
|
||||
BLE_BUFFER_FULL, //
|
||||
BLE_BUFFER_ERROR, //
|
||||
BLE_CMD_PARAM_ERROR, //
|
||||
BLE_CMD_STACK_NOT_RUN,
|
||||
} ble_cmd_ret_e;
|
||||
|
||||
//--------------------------------------------
|
||||
enum {
|
||||
ATT_OP_AUTO_READ_CCC = 0,
|
||||
ATT_OP_NOTIFY = 1,
|
||||
ATT_OP_INDICATE = 2,
|
||||
ATT_OP_READ,
|
||||
ATT_OP_READ_LONG,
|
||||
ATT_OP_WRITE,
|
||||
ATT_OP_WRITE_WITHOUT_RESPOND,
|
||||
//add here
|
||||
|
||||
ATT_OP_CMD_MAX = 15,
|
||||
};
|
||||
extern ble_cmd_ret_e ble_user_cmd_prepare(ble_cmd_type_e cmd, int argc, ...);
|
||||
|
||||
struct conn_update_param_t {
|
||||
u16 interval_min;
|
||||
u16 interval_max;
|
||||
u16 latency;
|
||||
u16 timeout;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
PFL_SERVER_UUID16 = 1,
|
||||
PFL_SERVER_UUID128,
|
||||
PFL_SERVER_ALL,
|
||||
} search_profile_type_e;
|
||||
|
||||
//------
|
||||
typedef struct {
|
||||
uint16_t start_group_handle;
|
||||
uint16_t end_group_handle;
|
||||
uint16_t uuid16;
|
||||
uint8_t uuid128[16];
|
||||
} service_report_t; //==le_service_t
|
||||
|
||||
typedef struct {
|
||||
uint16_t start_handle;
|
||||
uint16_t value_handle;
|
||||
uint16_t end_handle;
|
||||
uint16_t properties;
|
||||
uint16_t uuid16;
|
||||
uint8_t uuid128[16];
|
||||
} charact_report_t; //==le_characteristic_t
|
||||
|
||||
|
||||
typedef struct {
|
||||
service_report_t services;
|
||||
charact_report_t characteristic;
|
||||
u16 service_index;
|
||||
u16 characteristic_index;
|
||||
} search_result_t;
|
||||
|
||||
//------
|
||||
struct create_conn_param_t {
|
||||
u16 conn_interval;
|
||||
u16 conn_latency;
|
||||
u16 supervision_timeout;
|
||||
u8 peer_address_type;
|
||||
u8 peer_address[6];
|
||||
} _GNU_PACKED_;
|
||||
|
||||
typedef struct {
|
||||
u8 event_type;
|
||||
u8 address_type;
|
||||
u8 address[6];
|
||||
u8 reserve;
|
||||
u8 length;
|
||||
u8 data[0];
|
||||
} adv_report_t;
|
||||
|
||||
typedef struct {
|
||||
u16 packet_type;
|
||||
u16 value_handle;
|
||||
u16 value_offset;
|
||||
u16 blob_length;
|
||||
u8 *blob;
|
||||
} att_data_report_t;
|
||||
|
||||
|
||||
|
||||
//---------------
|
||||
void ble_set_gap_role(u8 role);
|
||||
void att_ccc_config_init(void);
|
||||
void att_set_ccc_config(uint16_t handle, uint16_t cfg);
|
||||
uint16_t att_get_ccc_config(uint16_t handle);
|
||||
void user_client_init(u16 handle, u8 *buffer, u16 buffer_size);
|
||||
#endif
|
||||
@@ -0,0 +1,541 @@
|
||||
#ifndef _BLUETOOTH_H_
|
||||
#define _BLUETOOTH_H_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
//LE
|
||||
|
||||
#define ISO_SDU_DTAT_LENGTH 0x032c //812byte
|
||||
#define ISO_PDU_DTAT_LENGTH 251 //251byte
|
||||
#define ISO_PDU_INTERVAL_M_S 0x4e20 //20ms
|
||||
#define ISO_PDU_INTERVAL_S_M 0x4e20 //20ms
|
||||
#define HCI_ISO_DATA_PACKET 0x05
|
||||
|
||||
#define HCI_COMMAND_DATA_PACKET 0x01
|
||||
#define HCI_ACL_DATA_PACKET 0x02
|
||||
#define HCI_SCO_DATA_PACKET 0x03
|
||||
#define HCI_EVENT_PACKET 0x04
|
||||
|
||||
// OGFs
|
||||
#define OGF_LINK_CONTROL 0x01
|
||||
#define OGF_LINK_POLICY 0x02
|
||||
#define OGF_CONTROLLER_BASEBAND 0x03
|
||||
#define OGF_INFORMATIONAL_PARAMETERS 0x04
|
||||
#define OGF_STATUS_PARAMETERS 0x05
|
||||
#define OGF_TESTING 0x06
|
||||
#define OGF_LE_CONTROLLER 0x08
|
||||
#define OGF_VENDOR_LE_CONTROLLER 0x3e
|
||||
#define OGF_VENDOR 0x3f
|
||||
|
||||
|
||||
// Events from host controller to host
|
||||
|
||||
/**
|
||||
* @format 1
|
||||
* @param status
|
||||
*/
|
||||
#define HCI_EVENT_INQUIRY_COMPLETE 0x01
|
||||
|
||||
/**
|
||||
* @format 1B11132
|
||||
* @param num_responses
|
||||
* @param bd_addr
|
||||
* @param page_scan_repetition_mode
|
||||
* @param reserved1
|
||||
* @param reserved2
|
||||
* @param class_of_device
|
||||
* @param clock_offset
|
||||
*/
|
||||
#define HCI_EVENT_INQUIRY_RESULT 0x02
|
||||
|
||||
/**
|
||||
* @format 12B11
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param bd_addr
|
||||
* @param link_type
|
||||
* @param encryption_enabled
|
||||
*/
|
||||
#define HCI_EVENT_CONNECTION_COMPLETE 0x03
|
||||
/**
|
||||
* @format B31
|
||||
* @param bd_addr
|
||||
* @param class_of_device
|
||||
* @param link_type
|
||||
*/
|
||||
#define HCI_EVENT_CONNECTION_REQUEST 0x04
|
||||
/**
|
||||
* @format 121
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param reason
|
||||
*/
|
||||
#define HCI_EVENT_DISCONNECTION_COMPLETE 0x05
|
||||
/**
|
||||
* @format 12
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
*/
|
||||
#define HCI_EVENT_AUTHENTICATION_COMPLETE 0x06
|
||||
/**
|
||||
* @format 1BN
|
||||
* @param status
|
||||
* @param bd_addr
|
||||
* @param remote_name
|
||||
*/
|
||||
#define HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07
|
||||
/**
|
||||
* @format 121
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param encryption_enabled
|
||||
*/
|
||||
#define HCI_EVENT_ENCRYPTION_CHANGE 0x08
|
||||
/**
|
||||
* @format 12
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
*/
|
||||
#define HCI_EVENT_CHANGE_CONNECTION_LINK_KEY_COMPLETE 0x09
|
||||
/**
|
||||
* @format 121
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param key_flag
|
||||
*/
|
||||
#define HCI_EVENT_MASTER_LINK_KEY_COMPLETE 0x0A
|
||||
|
||||
#define HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE 0x0B
|
||||
|
||||
#define HCI_EVENT_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
|
||||
|
||||
#define HCI_EVENT_QOS_SETUP_COMPLETE 0x0D
|
||||
|
||||
/**
|
||||
* @format 12R
|
||||
* @param num_hci_command_packets
|
||||
* @param command_opcode
|
||||
* @param return_parameters
|
||||
*/
|
||||
#define HCI_EVENT_COMMAND_COMPLETE 0x0E
|
||||
/**
|
||||
* @format 112
|
||||
* @param status
|
||||
* @param num_hci_command_packets
|
||||
* @param command_opcode
|
||||
*/
|
||||
#define HCI_EVENT_COMMAND_STATUS 0x0F
|
||||
|
||||
/**
|
||||
* @format 1
|
||||
* @param hardware_code
|
||||
*/
|
||||
#define HCI_EVENT_HARDWARE_ERROR 0x10
|
||||
|
||||
#define HCI_EVENT_FLUSH_OCCURRED 0x11
|
||||
|
||||
/**
|
||||
* @format 1B1
|
||||
* @param status
|
||||
* @param bd_addr
|
||||
* @param role
|
||||
*/
|
||||
#define HCI_EVENT_ROLE_CHANGE 0x12
|
||||
|
||||
// TODO: number_of_handles 1, connection_handle[H*i], hc_num_of_completed_packets[2*i]
|
||||
#define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13
|
||||
|
||||
/**
|
||||
* @format 1H12
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param mode
|
||||
* @param interval
|
||||
*/
|
||||
#define HCI_EVENT_MODE_CHANGE_EVENT 0x14
|
||||
|
||||
// TODO: num_keys, bd_addr[B*i], link_key[16 octets * i]
|
||||
#define HCI_EVENT_RETURN_LINK_KEYS 0x15
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_PIN_CODE_REQUEST 0x16
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_LINK_KEY_REQUEST 0x17
|
||||
|
||||
// TODO: bd_addr B, link_key 16octets, key_type 1
|
||||
#define HCI_EVENT_LINK_KEY_NOTIFICATION 0x18
|
||||
|
||||
/**
|
||||
* @format 1
|
||||
* @param link_type
|
||||
*/
|
||||
#define HCI_EVENT_DATA_BUFFER_OVERFLOW 0x1A
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param lmp_max_slots
|
||||
*/
|
||||
#define HCI_EVENT_MAX_SLOTS_CHANGED 0x1B
|
||||
|
||||
/**
|
||||
* @format 1H2
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param clock_offset
|
||||
*/
|
||||
#define HCI_EVENT_READ_CLOCK_OFFSET_COMPLETE 0x1C
|
||||
|
||||
/**
|
||||
* @format 1H2
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param packet_types
|
||||
* @pnote packet_type is in plural to avoid clash with Java binding Packet.getPacketType()
|
||||
*/
|
||||
#define HCI_EVENT_CONNECTION_PACKET_TYPE_CHANGED 0x1D
|
||||
|
||||
#define HCI_EVENT_PAGE_SCAN_REPETITION_MODE_CHANGE 0x20
|
||||
/**
|
||||
* @format 1B11321
|
||||
* @param num_responses
|
||||
* @param bd_addr
|
||||
* @param page_scan_repetition_mode
|
||||
* @param reserved
|
||||
* @param class_of_device
|
||||
* @param clock_offset
|
||||
* @param rssi
|
||||
*/
|
||||
#define HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22
|
||||
|
||||
#define HCI_EVENT_READ_REMOTE_EXTERNED_FEATURES_COMPLETE 0x23
|
||||
/**
|
||||
* @format 1HB111221
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param bd_addr
|
||||
* @param link_type
|
||||
* @param transmission_interval
|
||||
* @param retransmission_interval
|
||||
* @param rx_packet_length
|
||||
* @param tx_packet_length
|
||||
* @param air_mode
|
||||
*/
|
||||
#define HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE 0x2C
|
||||
|
||||
// TODO: serialize extended_inquiry_response and provide parser
|
||||
/**
|
||||
* @format 1B11321
|
||||
* @param num_responses
|
||||
* @param bd_addr
|
||||
* @param page_scan_repetition_mode
|
||||
* @param reserved
|
||||
* @param class_of_device
|
||||
* @param clock_offset
|
||||
* @param rssi
|
||||
*/
|
||||
#define HCI_EVENT_EXTENDED_INQUIRY_RESPONSE 0x2F
|
||||
#define HCI_EVENT_EXTENDED_INQUIRY_RESULT 0x2F
|
||||
|
||||
/**
|
||||
* @format 1H
|
||||
* @param status
|
||||
* @param handle
|
||||
*/
|
||||
#define HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30
|
||||
|
||||
#define HCI_EVENT_IO_CAPABILITY_REQUEST 0x31
|
||||
#define HCI_EVENT_IO_CAPABILITY_RESPONSE 0x32
|
||||
|
||||
/**
|
||||
* @format B4
|
||||
* @param bd_addr
|
||||
* @param numeric_value
|
||||
*/
|
||||
#define HCI_EVENT_USER_CONFIRMATION_REQUEST 0x33
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_USER_PASSKEY_REQUEST 0x34
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_REMOTE_OOB_DATA_REQUEST 0x35
|
||||
|
||||
/**
|
||||
* @format 1B
|
||||
* @param status
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_SIMPLE_PAIRING_COMPLETE 0x36
|
||||
#define HCI_EVENT_LINK_SUPPERVISION_TIMEOUT_CHANGE_EVENT 0x38
|
||||
|
||||
#define HCI_EVENT_USER_PRESSKEY_NOTIFICATION 0x3B
|
||||
#define HCI_EVENT_REMOTE_KEYPRESS_NOTIFICATION 0x3C
|
||||
#define HCI_EVENT_REMOTE_SUPPORTED_FEATURES_NOTIFICATION 0x3D
|
||||
#define HCI_EVENT_LE_META 0x3E
|
||||
|
||||
// last used HCI_EVENT in 2.1 is 0x3d
|
||||
// last used HCI_EVENT in 4.1 is 0x57
|
||||
|
||||
#define HCI_EVENT_VENDOR_SETUP_COMPLETE 0xF9
|
||||
#define HCI_EVENT_VENDOR_DUT 0xFA
|
||||
#define HCI_EVENT_VENDOR_OSC_INTERNAL 0xFB
|
||||
#define HCI_EVENT_VENDOR_FAST_TEST 0xFC
|
||||
#define HCI_EVENT_VENDOR_REMOTE_UPDATE 0xFD
|
||||
#define HCI_EVENT_VENDOR_REMOTE_TEST 0xFE
|
||||
#define HCI_EVENT_VENDOR_SPECIFIC 0xFF
|
||||
|
||||
/**
|
||||
* @format 11H11B2221
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param role
|
||||
* @param peer_address_type
|
||||
* @param peer_address
|
||||
* @param conn_interval
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout
|
||||
* @param master_clock_accuracy
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_CONNECTION_COMPLETE 0x01
|
||||
|
||||
// array of advertisements, not handled by event accessor generator
|
||||
#define HCI_SUBEVENT_LE_ADVERTISING_REPORT 0x02
|
||||
|
||||
/**
|
||||
* @format 11H222
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param conn_interval
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE 0x03
|
||||
|
||||
/**
|
||||
* @format 1HD2
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param random_number
|
||||
* @param encryption_diversifier
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04
|
||||
|
||||
/**
|
||||
* @format 1HD2
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param random_number
|
||||
* @param encryption_diversifier
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST 0x05
|
||||
|
||||
/**
|
||||
* @format 1H2222
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param interval_min
|
||||
* @param interval_max
|
||||
* @param latency
|
||||
* @param timeout
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_REMOTE_CONNECTION_PARAMETER_REQUEST 0x06
|
||||
|
||||
/**
|
||||
* @format 1H2222
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param max_tx_octets
|
||||
* @param max_tx_time
|
||||
* @param max_rx_octets
|
||||
* @param max_rx_time
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE 0x07
|
||||
|
||||
/**
|
||||
* @format 11QQ
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param dhkey_x x coordinate of P256 public key
|
||||
* @param dhkey_y y coordinate of P256 public key
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE 0x08
|
||||
/**
|
||||
* @format 11Q
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param dhkey Diffie-Hellman key
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_GENERATE_DHKEY_COMPLETE 0x09
|
||||
|
||||
/**
|
||||
* @format 11H11BBB2221
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param role
|
||||
* @param peer_address_type
|
||||
* @param perr_addresss
|
||||
* @param local_resolvable_private_addres
|
||||
* @param peer_resolvable_private_addres
|
||||
* @param conn_interval
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout
|
||||
* @param master_clock_accuracy
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE 0x0A
|
||||
|
||||
// array of advertisements, not handled by event accessor generator
|
||||
#define HCI_SUBEVENT_LE_DIRECT_ADVERTISING_REPORT 0x0B
|
||||
|
||||
/**
|
||||
* @format 11211
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param TX_PHY
|
||||
* @param RX_PHY
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE 0x0C
|
||||
|
||||
// array of advertisements, not handled by event accessor generator
|
||||
#define HCI_SUBEVENT_LE_EXTENDED_ADVERTISING_REPORT 0x0D
|
||||
|
||||
#define HCI_SUBEVENT_LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED 0x0E
|
||||
|
||||
/**
|
||||
* @format 1211111B
|
||||
* @param subevent_code
|
||||
* @param sync_handle
|
||||
* @param tx_power
|
||||
* @param rssi
|
||||
* @param unused
|
||||
* @param data_status
|
||||
* @param data_length
|
||||
* @param data
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_PERIODIC_ADVERTISING_REPORT 0x0F
|
||||
|
||||
/**
|
||||
* @format 2
|
||||
* @param sync_handle
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_PERIODIC_ADVERTISING_SYNC_LOST 0x10
|
||||
|
||||
/**
|
||||
* @format
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_SCAN_TIMEOUT 0x11
|
||||
|
||||
/**
|
||||
* @format 1121
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param advertising_handle
|
||||
* @param connection_handle
|
||||
* @param num_completed_extended_advertising_events
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_ADVERTISING_SET_TERMINATED 0x12
|
||||
|
||||
/**
|
||||
* @format 1116
|
||||
* @param subevent_code
|
||||
* @param advertising_handle
|
||||
* @param scanner_address_type
|
||||
* @param scanner_address
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_SCAN_REQUEST_RECEIVED 0x13
|
||||
|
||||
/**
|
||||
* @format 21
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param channel_selection_algorithm
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_CHANNEL_SELECTION_ALGORITHM 0x14
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* compact HCI Command packet description
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t opcode;
|
||||
const char *format;
|
||||
} hci_cmd_t;
|
||||
|
||||
int hci_send_cmd(const hci_cmd_t *cmd, ...);
|
||||
|
||||
|
||||
extern const hci_cmd_t hci_reset;
|
||||
extern const hci_cmd_t hci_read_bd_addr;
|
||||
extern const hci_cmd_t hci_read_local_supported_features;
|
||||
extern const hci_cmd_t hci_read_buffer_size;
|
||||
extern const hci_cmd_t hci_read_local_supported_commands;
|
||||
extern const hci_cmd_t hci_read_local_version_information;
|
||||
extern const hci_cmd_t hci_read_le_host_supported;
|
||||
extern const hci_cmd_t hci_read_local_name;
|
||||
extern const hci_cmd_t hci_write_class_of_device;
|
||||
extern const hci_cmd_t hci_write_local_name;
|
||||
extern const hci_cmd_t hci_write_scan_enable;
|
||||
extern const hci_cmd_t hci_set_event_mask;
|
||||
extern const hci_cmd_t hci_le_add_device_to_white_list;
|
||||
extern const hci_cmd_t hci_le_clear_white_list;
|
||||
extern const hci_cmd_t hci_le_connection_update;
|
||||
extern const hci_cmd_t hci_le_create_connection;
|
||||
extern const hci_cmd_t hci_le_create_connection_cancel;
|
||||
extern const hci_cmd_t hci_le_encrypt;
|
||||
extern const hci_cmd_t hci_le_generate_dhkey;
|
||||
extern const hci_cmd_t hci_le_long_term_key_negative_reply;
|
||||
extern const hci_cmd_t hci_le_long_term_key_request_reply;
|
||||
extern const hci_cmd_t hci_le_rand;
|
||||
extern const hci_cmd_t hci_le_read_advertising_channel_tx_power;
|
||||
extern const hci_cmd_t hci_le_read_buffer_size;
|
||||
extern const hci_cmd_t hci_le_read_channel_map;
|
||||
extern const hci_cmd_t hci_le_read_local_p256_public_key;
|
||||
extern const hci_cmd_t hci_le_read_maximum_data_length;
|
||||
extern const hci_cmd_t hci_le_read_remote_used_features;
|
||||
extern const hci_cmd_t hci_le_read_suggested_default_data_length;
|
||||
extern const hci_cmd_t hci_le_read_supported_features;
|
||||
extern const hci_cmd_t hci_le_read_supported_states;
|
||||
extern const hci_cmd_t hci_le_read_white_list_size;
|
||||
extern const hci_cmd_t hci_le_receiver_test;
|
||||
extern const hci_cmd_t hci_le_remove_device_from_white_list;
|
||||
extern const hci_cmd_t hci_le_set_advertise_enable;
|
||||
extern const hci_cmd_t hci_le_set_advertising_data;
|
||||
extern const hci_cmd_t hci_le_set_advertising_parameters;
|
||||
extern const hci_cmd_t hci_le_set_data_length;
|
||||
extern const hci_cmd_t hci_le_set_event_mask;
|
||||
extern const hci_cmd_t hci_le_set_host_channel_classification;
|
||||
extern const hci_cmd_t hci_le_set_random_address;
|
||||
extern const hci_cmd_t hci_le_set_scan_enable;
|
||||
extern const hci_cmd_t hci_le_set_scan_parameters;
|
||||
extern const hci_cmd_t hci_le_set_scan_response_data;
|
||||
extern const hci_cmd_t hci_le_start_encryption;
|
||||
extern const hci_cmd_t hci_le_test_end;
|
||||
extern const hci_cmd_t hci_le_transmitter_test;
|
||||
extern const hci_cmd_t hci_le_write_suggested_default_data_length;
|
||||
extern const hci_cmd_t hci_le_set_phy;
|
||||
|
||||
extern const hci_cmd_t hci_le_set_ext_advertising_parameters;
|
||||
extern const hci_cmd_t hci_le_set_ext_advertising_data;
|
||||
extern const hci_cmd_t hci_le_set_ext_advertise_enable;
|
||||
extern const hci_cmd_t hci_le_set_ext_scan_parameters;
|
||||
extern const hci_cmd_t hci_le_set_ext_scan_enable;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef BT_PROFILE_H
|
||||
#define BT_PROFILE_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define BT_BTSTACK_CLASSIC BIT(0)
|
||||
#define BT_BTSTACK_LE_ADV BIT(1)
|
||||
#define BT_BTSTACK_LE BIT(2)
|
||||
|
||||
extern const int config_stack_modules;
|
||||
#define STACK_MODULES_IS_SUPPORT(x) (config_stack_modules & (x))
|
||||
|
||||
|
||||
|
||||
extern u8 app_bredr_pool[];
|
||||
extern u8 app_le_pool[];
|
||||
extern u8 app_l2cap_pool[];
|
||||
extern u8 app_bredr_profile[];
|
||||
|
||||
extern u16 get_bredr_pool_len(void);
|
||||
extern u16 get_le_pool_len(void);
|
||||
extern u16 get_l2cap_stack_len(void);
|
||||
extern u16 get_profile_pool_len(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,250 @@
|
||||
|
||||
#ifndef _LE_USER_H_
|
||||
#define _LE_USER_H_
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "btstack/ble_api.h"
|
||||
|
||||
|
||||
typedef void (*btstack_packet_handler_t)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
typedef int (*sm_stack_packet_handler_t)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
|
||||
typedef void (*ble_cbk_handler_t)(void);
|
||||
|
||||
// Minimum/default MTU
|
||||
#define ATT_DEFAULT_MTU 23
|
||||
#define BT_NAME_LEN_MAX 29
|
||||
#define ADV_RSP_PACKET_MAX 31
|
||||
|
||||
// hci con handles (12 bit): 0x0000..0x0fff
|
||||
#define HCI_CON_HANDLE_INVALID 0xffff
|
||||
|
||||
#define BTSTACK_EVENT_STATE 0x60
|
||||
#define L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE 0x77
|
||||
|
||||
#define ATT_EVENT_MTU_EXCHANGE_COMPLETE 0xB5
|
||||
#define ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE 0xB6
|
||||
#define ATT_EVENT_CAN_SEND_NOW 0xB7
|
||||
|
||||
#define SM_EVENT_JUST_WORKS_REQUEST 0xD0
|
||||
#define SM_EVENT_PASSKEY_DISPLAY_NUMBER 0xD2
|
||||
|
||||
|
||||
#define ATT_TRANSACTION_MODE_NONE 0x0
|
||||
#define ATT_TRANSACTION_MODE_ACTIVE 0x1
|
||||
#define ATT_TRANSACTION_MODE_EXECUTE 0x2
|
||||
#define ATT_TRANSACTION_MODE_CANCEL 0x3
|
||||
#define ATT_TRANSACTION_MODE_VALIDATE 0x4
|
||||
|
||||
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONE 0
|
||||
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1
|
||||
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 2
|
||||
|
||||
#define ATT_PROPERTY_BROADCAST 0x01
|
||||
#define ATT_PROPERTY_READ 0x02
|
||||
#define ATT_PROPERTY_WRITE_WITHOUT_RESPONSE 0x04
|
||||
#define ATT_PROPERTY_WRITE 0x08
|
||||
#define ATT_PROPERTY_NOTIFY 0x10
|
||||
#define ATT_PROPERTY_INDICATE 0x20
|
||||
|
||||
|
||||
#define GATT_EVENT_NOTIFICATION 0xA7
|
||||
#define GATT_EVENT_INDICATION 0xA8
|
||||
#define GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA5
|
||||
#define GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA6
|
||||
// #define GATT_EVENT_SERVICE_QUERY_RESULT 0xA1
|
||||
// #define GATT_EVENT_CHARACTERISTIC_QUERY_RESULT 0xA2
|
||||
// #define GATT_EVENT_QUERY_COMPLETE 0xA0
|
||||
#define GAP_EVENT_ADVERTISING_REPORT 0xE2
|
||||
|
||||
// Authentication requirement flags
|
||||
#define SM_AUTHREQ_NO_BONDING 0x00
|
||||
#define SM_AUTHREQ_BONDING 0x01
|
||||
#define SM_AUTHREQ_MITM_PROTECTION 0x04
|
||||
#define SM_AUTHREQ_SECURE_CONNECTION 0x08
|
||||
#define SM_AUTHREQ_KEYPRESS 0x10
|
||||
|
||||
|
||||
#define L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE 0x77
|
||||
|
||||
|
||||
#define BT_OP_SUCCESS 0x00
|
||||
#define BT_ERR_ADVERTISING_TIMEOUT 0x3C
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
enum {
|
||||
HCI_STATE_OFF = 0,
|
||||
HCI_STATE_INITIALIZING,
|
||||
HCI_STATE_WORKING,
|
||||
HCI_STATE_HALTING,
|
||||
HCI_STATE_SLEEPING,
|
||||
HCI_STATE_FALLING_ASLEEP
|
||||
} ;
|
||||
|
||||
|
||||
// IO Capability Values
|
||||
typedef enum {
|
||||
IO_CAPABILITY_DISPLAY_ONLY = 0,
|
||||
IO_CAPABILITY_DISPLAY_YES_NO,
|
||||
IO_CAPABILITY_KEYBOARD_ONLY,
|
||||
IO_CAPABILITY_NO_INPUT_NO_OUTPUT,
|
||||
IO_CAPABILITY_KEYBOARD_DISPLAY, // not used by secure simple pairing
|
||||
} io_capability_t;
|
||||
|
||||
|
||||
struct ble_server_operation_t {
|
||||
int(*adv_enable)(void *priv, u32 enable);
|
||||
int(*disconnect)(void *priv);
|
||||
int(*get_buffer_vaild)(void *priv);
|
||||
int(*send_data)(void *priv, void *buf, u16 len);
|
||||
int(*regist_wakeup_send)(void *priv, void *cbk);
|
||||
int(*regist_recieve_cbk)(void *priv, void *cbk);
|
||||
int(*regist_state_cbk)(void *priv, void *cbk);
|
||||
int(*latency_enable)(void *priv, u32 enable);
|
||||
};
|
||||
void ble_get_server_operation_table(struct ble_server_operation_t **interface_pt);
|
||||
|
||||
|
||||
struct ble_client_operation_t {
|
||||
int(*scan_enable)(void *priv, u32 enable);
|
||||
int(*disconnect)(void *priv);
|
||||
int(*get_buffer_vaild)(void *priv);
|
||||
int(*write_data)(void *priv, void *buf, u16 len);
|
||||
int(*read_do)(void *priv);
|
||||
int(*regist_wakeup_send)(void *priv, void *cbk);
|
||||
int(*regist_recieve_cbk)(void *priv, void *cbk);
|
||||
int(*regist_state_cbk)(void *priv, void *cbk);
|
||||
};
|
||||
void ble_get_client_operation_table(struct ble_client_operation_t **interface_pt);
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
//base info
|
||||
uint8_t type; ///< See <btstack/hci_cmds.h> SM_...
|
||||
uint8_t size;
|
||||
hci_con_handle_t con_handle;
|
||||
uint8_t addr_type;
|
||||
uint8_t address[6];
|
||||
//extend info
|
||||
uint8_t data[4];
|
||||
} sm_just_event_t;
|
||||
|
||||
|
||||
static inline uint32_t ble_min(uint32_t a, uint32_t b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ATT Client Read Callback for Dynamic Data
|
||||
// - if buffer == NULL, don't copy data, just return size of value
|
||||
// - if buffer != NULL, copy data and return number bytes copied
|
||||
// @param con_handle of hci le connection
|
||||
// @param attribute_handle to be read
|
||||
// @param offset defines start of attribute value
|
||||
// @param buffer
|
||||
// @param buffer_size
|
||||
typedef uint16_t (*att_read_callback_t)(uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
||||
|
||||
// ATT Client Write Callback for Dynamic Data
|
||||
// @param con_handle of hci le connection
|
||||
// @param attribute_handle to be written
|
||||
// @param transaction - ATT_TRANSACTION_MODE_NONE for regular writes, ATT_TRANSACTION_MODE_ACTIVE for prepared writes and ATT_TRANSACTION_MODE_EXECUTE
|
||||
// @param offset into the value - used for queued writes and long attributes
|
||||
// @param buffer
|
||||
// @param buffer_size
|
||||
// @param signature used for signed write commmands
|
||||
// @returns 0 if write was ok, ATT_ERROR_PREPARE_QUEUE_FULL if no space in queue, ATT_ERROR_INVALID_OFFSET if offset is larger than max buffer
|
||||
typedef int (*att_write_callback_t)(uint16_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
||||
|
||||
//----------------------------------------
|
||||
extern uint16_t little_endian_read_16(const uint8_t *buffer, int pos);
|
||||
extern uint32_t little_endian_read_24(const uint8_t *buffer, int pos);
|
||||
extern uint32_t little_endian_read_32(const uint8_t *buffer, int pos);
|
||||
|
||||
//----------------------------------------
|
||||
//--------------------------------------
|
||||
static inline hci_con_handle_t hci_subevent_le_connection_update_complete_get_connection_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 4);
|
||||
}
|
||||
|
||||
static inline uint16_t hci_subevent_le_connection_update_complete_get_conn_interval(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 6);
|
||||
}
|
||||
static inline uint16_t hci_subevent_le_connection_update_complete_get_conn_latency(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 8);
|
||||
}
|
||||
static inline uint16_t hci_subevent_le_connection_update_complete_get_supervision_timeout(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 10);
|
||||
}
|
||||
|
||||
static inline uint8_t hci_event_packet_get_type(const uint8_t *event)
|
||||
{
|
||||
return event[0];
|
||||
}
|
||||
|
||||
static inline uint8_t hci_event_le_meta_get_subevent_code(const uint8_t *event)
|
||||
{
|
||||
return event[2];
|
||||
}
|
||||
static inline uint16_t att_event_mtu_exchange_complete_get_MTU(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 4);
|
||||
}
|
||||
|
||||
static inline uint8_t btstack_event_state_get_state(const uint8_t *event)
|
||||
{
|
||||
return event[2];
|
||||
}
|
||||
|
||||
static inline uint16_t hci_event_disconnection_complete_get_connection_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 3);
|
||||
}
|
||||
|
||||
static inline hci_con_handle_t hci_subevent_le_connection_complete_get_connection_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 4);
|
||||
}
|
||||
|
||||
static inline uint16_t hci_subevent_le_connection_complete_get_conn_interval(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 14);
|
||||
}
|
||||
|
||||
static inline hci_con_handle_t att_event_mtu_exchange_complete_get_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 2);
|
||||
}
|
||||
static inline hci_con_handle_t sm_event_just_works_request_get_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 2);
|
||||
}
|
||||
|
||||
|
||||
extern void ble_sm_setup_init(io_capability_t io_type, u8 auth_req, uint8_t min_key_size, u8 security_en);
|
||||
extern void sm_just_works_confirm(hci_con_handle_t con_handle);
|
||||
extern void sm_init(void);
|
||||
extern void sm_set_io_capabilities(io_capability_t io_capability);
|
||||
extern void sm_set_authentication_requirements(uint8_t auth_req);
|
||||
extern void sm_set_encryption_key_size_range(uint8_t min_size, uint8_t max_size);
|
||||
extern void sm_set_request_security(int enable);
|
||||
extern void sm_event_callback_set(void(*cbk_sm_ph)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
extern void att_server_init(uint8_t const *db, att_read_callback_t read_callback, att_write_callback_t write_callback);
|
||||
extern void att_server_register_packet_handler(btstack_packet_handler_t handler);
|
||||
extern void hci_event_callback_set(void(*cbk_ph)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
extern void ll_hci_connection_updata(u8 *data);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef __DEC_H__
|
||||
#define __DEC_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
void doe(u16 k, void *pBuf, u32 lenIn, u32 addr);
|
||||
|
||||
u16 doe_continue(u16 k, void *pBuf, u32 lenIn, u8 init_flag);
|
||||
|
||||
void decode(u16 key, u8 *buf, u32 len, u32 offset);
|
||||
|
||||
u8 dec_isd_cfg_ini(const char *cfg, void *value, const u8 *ptr);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "typedef.h"
|
||||
//#define NOFLOAT
|
||||
|
||||
// #ifdef __DEBUG
|
||||
|
||||
void put_u4hex(u8 dat);
|
||||
void put_u8hex(unsigned char dat);
|
||||
void put_u16hex(unsigned short dat);
|
||||
void put_u32hex(unsigned int dat);
|
||||
void put_buf(const u8 *buf, u32 len);
|
||||
void printf_buf(u8 *buf, u32 len);
|
||||
|
||||
|
||||
#ifdef __DEBUG
|
||||
int printf(const char *format, ...);
|
||||
int puts(const char *out);
|
||||
|
||||
#else
|
||||
|
||||
// #define put_u4hex(x)
|
||||
// #define put_u8hex(x)
|
||||
// #define put_u16hex(x)
|
||||
// #define put_u32hex(x)
|
||||
// #define put_buf(a, b)
|
||||
// #define printf_buf(a, b)
|
||||
#define printf(...)
|
||||
#define puts(x)
|
||||
|
||||
#endif
|
||||
|
||||
int lib_putchar(int c);
|
||||
extern int putchar(int a);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef __CLOCK_H__
|
||||
#define __CLOCK_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
#define MHz (1000000L)
|
||||
|
||||
#define OSC_FREQ 24000000
|
||||
|
||||
#define SYS_CLK 48000000
|
||||
|
||||
|
||||
enum {
|
||||
UART_CLOCK_IN_DISABLE = 0,
|
||||
UART_CLOCK_IN_STD48M,
|
||||
UART_CLOCK_IN_STD24M,
|
||||
UART_CLOCK_IN_EXT,
|
||||
UART_CLOCK_IN_LSB,
|
||||
};
|
||||
#define UART_CLOCK_IN(x) SFR(JL_LSBCLK->PRP_CON0, 12, 3, x)
|
||||
|
||||
#define BT_CLOCK_IN(x) //SFR(JL_CLOCK->CLK_CON1, 14, 2, x)
|
||||
//for MACRO - BT_CLOCK_IN
|
||||
enum {
|
||||
BT_CLOCK_IN_PLL48M = 0,
|
||||
BT_CLOCK_IN_HSB,
|
||||
BT_CLOCK_IN_LSB,
|
||||
BT_CLOCK_IN_DISABLE,
|
||||
};
|
||||
|
||||
void lrc_init(void);
|
||||
|
||||
void sys_clk_init(u32 osc_freq, u32 sys_clk);
|
||||
|
||||
void btosc_upgrade_cfg(void *cfg);
|
||||
|
||||
void sys_clk_reinit(void *clk_argv);
|
||||
|
||||
u32 clk_get(const char *clk);
|
||||
|
||||
|
||||
#define CLR_DVDD_POR_PND() JL_HSBCLK->PWR_CON |= BIT(11)
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __CRC_H__
|
||||
#define __CRC_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
u16 chip_crc16(void *ptr, u32 len);
|
||||
|
||||
u16 chip_crc16_with_init(void *ptr, u32 len, u16 init);
|
||||
|
||||
void CrcDecode(void *buf, u16 len);
|
||||
|
||||
void crc_encode(void *buf, u32 len, const u8 *crckey, u32 offset);
|
||||
|
||||
|
||||
#define CRC16(x,y) chip_crc16(x,y)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
//*********************************************************************************//
|
||||
// Module name : csfr.h //
|
||||
// Description : q32DSP core sfr define //
|
||||
// By Designer : zequan_liu //
|
||||
// Dat changed : //
|
||||
//*********************************************************************************//
|
||||
|
||||
#ifndef __Q32DSP_CSFR__
|
||||
#define __Q32DSP_CSFR__
|
||||
|
||||
#define __RW volatile // read write
|
||||
#define __RO volatile const // only read
|
||||
#define __WO volatile // only write
|
||||
|
||||
#define __u8 unsigned int // u8 to u32 special for struct
|
||||
#define __u16 unsigned int // u16 to u32 special for struct
|
||||
#define __u32 unsigned int
|
||||
|
||||
#define csfr_base 0xff0000
|
||||
|
||||
//*********************************************************************************
|
||||
//
|
||||
// hcore_sfr
|
||||
//
|
||||
//*********************************************************************************
|
||||
|
||||
//............. 0x0000 - 0x00ff............
|
||||
typedef struct {
|
||||
__RW __u32 CON0;
|
||||
__RW __u32 FTMAX;
|
||||
} JL_CMNG_TypeDef;
|
||||
|
||||
#define JL_CMNG_BASE (csfr_base + map_adr(0x00, 0x00))
|
||||
#define JL_CMNG ((JL_CMNG_TypeDef *)JL_CMNG_BASE)
|
||||
|
||||
//............. 0x0100 - 0x01ff............
|
||||
//typedef struct {
|
||||
// __RW __u32 CON;
|
||||
// __RW __u32 KEY;
|
||||
//} JL_SDTAP_TypeDef;
|
||||
|
||||
//#define JL_SDTAP_BASE (csfr_base + map_adr(0x01, 0x00))
|
||||
//#define JL_SDTAP ((JL_SDTAP_TypeDef *)JL_SDTAP_BASE)
|
||||
|
||||
//............. 0x0200 - 0x02ff............
|
||||
typedef struct {
|
||||
__RW __u32 WREN;
|
||||
__RW __u32 CON0;
|
||||
__RW __u32 CON1;
|
||||
__RW __u32 CON2;
|
||||
__RW __u32 CON3;
|
||||
__RW __u32 MSG0;
|
||||
__RW __u32 MSG1;
|
||||
__RW __u32 MSG2;
|
||||
__RW __u32 MSG3;
|
||||
__RO __u32 ID;
|
||||
} JL_CEMU_TypeDef;
|
||||
|
||||
#define JL_CEMU_BASE (csfr_base + map_adr(0x02, 0x00))
|
||||
#define JL_CEMU ((JL_CEMU_TypeDef *)JL_CEMU_BASE)
|
||||
|
||||
//............. 0x0300 - 0x03ff............
|
||||
|
||||
#define MPU_INV (1<<31)
|
||||
#define MPU_PWEN (1<<16)
|
||||
#define MPU_PREN (1<<8)
|
||||
#define MPU_PEN (MPU_PWEN | MPU_PREN)
|
||||
#define MPU_XEN (1<<2)
|
||||
#define MPU_WEN (1<<1)
|
||||
#define MPU_REN (1<<0)
|
||||
|
||||
#define MPU_IDx_cfg(n, id) (id<<(n*8))
|
||||
#define MPU_IDx_pen(n, pr, pw) ((pr<<(9+n)) | (pw<<(17+n)))
|
||||
|
||||
typedef struct {
|
||||
__RW __u32 CON[15]; // 0-1 used in br35
|
||||
__RO __u32 REV0;
|
||||
__RW __u32 CID[15]; // 0-1 used in br35
|
||||
__RO __u32 REV1;
|
||||
__RW __u32 BEG[15]; // 0-1 used in br35
|
||||
__RO __u32 REV2;
|
||||
__RW __u32 END[15]; // 0-1 used in br35
|
||||
__RW __u32 WREN;
|
||||
} JL_MPU_TypeDef;
|
||||
|
||||
#define JL_MPU_BASE (csfr_base + map_adr(0x03, 0x00))
|
||||
#define JL_MPU ((JL_MPU_TypeDef *)JL_MPU_BASE)
|
||||
|
||||
//............. 0x0400 - 0x04ff............
|
||||
|
||||
typedef struct {
|
||||
__RW __u32 CON;
|
||||
__RW __u32 TLB1_BEG;
|
||||
__RW __u32 TLB1_END;
|
||||
} JL_MMU_TypeDef;
|
||||
|
||||
#define JL_MMU_BASE (csfr_base + map_adr(0x04, 0x00))
|
||||
#define JL_MMU ((JL_MMU_TypeDef *)JL_MMU_BASE)
|
||||
|
||||
typedef struct {
|
||||
short page: 14;
|
||||
short vld: 1;
|
||||
} JL_MMU_TLB1_TypeDef;
|
||||
|
||||
#define JL_MMU_TLB1 ((JL_MMU_TLB1_TypeDef *)(JL_MMU->TLB1_BEG))
|
||||
|
||||
//............. 0x0500 - 0x05ff............
|
||||
//#define JL_TypeDef_L1P JL_TypeDef_q32DSP_ICU
|
||||
#define JL_TypeDef_L1P JL_TypeDef_q32DSP_DCU
|
||||
#define JL_L1P_BASE (csfr_base + map_adr(0x05, 0x00))
|
||||
#define JL_L1P ((JL_TypeDef_L1P *)JL_L1P_BASE)
|
||||
|
||||
//............. 0x0600 - 0x06ff............
|
||||
#define JL_TypeDef_L2I JL_TypeDef_q32DSP_ICU
|
||||
#define JL_L2I_BASE (csfr_base + map_adr(0x06, 0x00))
|
||||
#define JL_L2I ((JL_TypeDef_L2I *)JL_L2I_BASE)
|
||||
|
||||
//............. 0x0700 - 0x07ff............
|
||||
#define JL_TypeDef_L2D JL_TypeDef_q32DSP_DCU
|
||||
#define JL_L2D_BASE (csfr_base + map_adr(0x07, 0x00))
|
||||
#define JL_L2D ((JL_TypeDef_L2D *)JL_L2D_BASE)
|
||||
|
||||
//............. 0x0800 - 0x08ff............
|
||||
typedef struct {
|
||||
__RO __u32 CHIP_ID;
|
||||
__RO __u32 CHIP_VER;
|
||||
} JL_SYSTEM_TypeDef;
|
||||
|
||||
#define JL_SYSTEM_BASE (csfr_base + map_adr(0x08, 0x00))
|
||||
#define JL_SYSTEM ((JL_SYSTEM_TypeDef *)JL_SYSTEM_BASE)
|
||||
|
||||
//............. 0x0900 - 0x09ff............
|
||||
typedef struct {
|
||||
__RW __u32 CON;
|
||||
__RW __u32 BEG;
|
||||
__RW __u32 END;
|
||||
__RW __u32 DAT_VLD0;
|
||||
__RW __u32 DAT_VLD1;
|
||||
__RW __u32 DAT_VLD2;
|
||||
__RW __u32 DAT_VLD3;
|
||||
__RO __u32 ROM_CRC;
|
||||
__RW __u32 MCFG0_SEL;
|
||||
__RW __u32 MCFG1_SEL;
|
||||
__RW __u32 MCFG0_RF1P;
|
||||
__RW __u32 MCFG0_RF2P;
|
||||
__RW __u32 MCFG0_RM1P;
|
||||
__RW __u32 MCFG0_RM2P;
|
||||
__RW __u32 MCFG0_VROM;
|
||||
__RW __u32 MCFG1_RM1P;
|
||||
__RW __u32 MCFG0_CON[2];
|
||||
__RW __u32 MCFG1_CON[2];
|
||||
} JL_MBIST_TypeDef;
|
||||
|
||||
#define JL_MBIST_BASE (csfr_base + map_adr(0x09, 0x00))
|
||||
#define JL_MBIST ((JL_MBIST_TypeDef *)JL_MBIST_BASE)
|
||||
|
||||
//............. 0x0a00 - 0x0aff............
|
||||
//typedef struct {
|
||||
// __RW __u32 CON;
|
||||
// __RW __u32 CADR;
|
||||
// __RW __u32 ACC0L;
|
||||
// __RW __u32 ACC0H;
|
||||
// __RW __u32 ACC1L;
|
||||
// __RW __u32 ACC1H;
|
||||
// __RW __u32 CONST;
|
||||
// __RW __u32 TEST1;
|
||||
//} JL_FFT_TypeDef;
|
||||
//
|
||||
//#define JL_FFT_BASE (csfr_base + map_adr(0x0a, 0x00))
|
||||
//#define JL_FFT ((JL_FFT_TypeDef *)JL_FFT_BASE)
|
||||
|
||||
//............. 0x0b00 - 0x0bff............
|
||||
//typedef struct {
|
||||
///* 00 */ __RW __u32 CON0;
|
||||
///* 01 */ __RW __u32 LPEN_CON;
|
||||
///* 02 */ __RW __u32 LSEN_CON;
|
||||
///* 03 */ __RO __u32 LS_PND;
|
||||
///* 04 */ __RO __u32 CE_PND;
|
||||
///* 05 */ __RW __u32 LS_PRD_32K;
|
||||
///* 06 */ __RW __u32 CE_PRD_32K;
|
||||
///* 07 */ __RW __u32 LS_PRD_64K;
|
||||
///* 08 */ __RW __u32 CE_PRD_64K;
|
||||
///* 09 */ __RW __u32 LS_PRD_ROM;
|
||||
///* 0a */ __RW __u32 CE_PRD_ROM;
|
||||
//} JL_ATOLP_TypeDef;
|
||||
|
||||
//#define JL_ATOLP_BASE (csfr_base + map_adr(0x0b, 0x00))
|
||||
//#define JL_ATOLP ((JL_ATOLP_TypeDef *)JL_ATOLP_BASE)
|
||||
|
||||
//*********************************************************************************
|
||||
//
|
||||
// q32DSP_sfr
|
||||
//
|
||||
//*********************************************************************************
|
||||
|
||||
//---------------------------------------------//
|
||||
// q32DSP define
|
||||
//---------------------------------------------//
|
||||
|
||||
#define q32DSP_sfr_offset 0x000800
|
||||
#define q32DSP_sfr_base (csfr_base + 0xe000)
|
||||
|
||||
#define q32DSP_cpu_base (q32DSP_sfr_base + 0x0000)
|
||||
#define q32DSP_icu_base (q32DSP_sfr_base + 0x0400)
|
||||
|
||||
#define q32DSP(n) ((JL_TypeDef_q32DSP *)(q32DSP_sfr_base + q32DSP_sfr_offset*n))
|
||||
#define q32DSP_icu(n) ((JL_TypeDef_q32DSP_ICU *)(q32DSP_icu_base + q32DSP_sfr_offset*n))
|
||||
|
||||
//---------------------------------------------//
|
||||
// q32DSP core sfr
|
||||
//---------------------------------------------//
|
||||
|
||||
typedef struct {
|
||||
/* 00 */ __RO __u32 DR00;
|
||||
/* 01 */ __RO __u32 DR01;
|
||||
/* 02 */ __RO __u32 DR02;
|
||||
/* 03 */ __RO __u32 DR03;
|
||||
/* 04 */ __RO __u32 DR04;
|
||||
/* 05 */ __RO __u32 DR05;
|
||||
/* 06 */ __RO __u32 DR06;
|
||||
/* 07 */ __RO __u32 DR07;
|
||||
/* 08 */ __RO __u32 DR08;
|
||||
/* 09 */ __RO __u32 DR09;
|
||||
/* 0a */ __RO __u32 DR10;
|
||||
/* 0b */ __RO __u32 DR11;
|
||||
/* 0c */ __RO __u32 DR12;
|
||||
/* 0d */ __RO __u32 DR13;
|
||||
/* 0e */ __RO __u32 DR14;
|
||||
/* 0f */ __RO __u32 DR15;
|
||||
|
||||
/* 10 */ __RO __u32 RETI;
|
||||
/* 11 */ __RO __u32 RETE;
|
||||
/* 12 */ __RO __u32 RETX;
|
||||
/* 13 */ __RO __u32 RETS;
|
||||
/* 14 */ __RO __u32 SR04;
|
||||
/* 15 */ __RO __u32 PSR;
|
||||
/* 16 */ __RO __u32 CNUM;
|
||||
/* 17 */ __RO __u32 SR07;
|
||||
/* 18 */ __RO __u32 SR08;
|
||||
/* 19 */ __RO __u32 SR09;
|
||||
/* 1a */ __RO __u32 SR10;
|
||||
/* 1b */ __RO __u32 ICFG;
|
||||
/* 1c */ __RO __u32 USP;
|
||||
/* 1d */ __RO __u32 SSP;
|
||||
/* 1e */ __RO __u32 SP;
|
||||
/* 1f */ __RO __u32 PCRS;
|
||||
|
||||
/* 20 */ __RW __u32 BPCON;
|
||||
/* 21 */ __RW __u32 BSP;
|
||||
/* 22 */ __RW __u32 BP0;
|
||||
/* 23 */ __RW __u32 BP1;
|
||||
/* 24 */ __RW __u32 BP2;
|
||||
/* 25 */ __RW __u32 BP3;
|
||||
/* 26 */ __WO __u32 CMD_PAUSE;
|
||||
/* 27 */ __RW __u32 BP4;
|
||||
/* 28 */ __RW __u32 BP5;
|
||||
/* 29 */ __RW __u32 BP6;
|
||||
/* 2a */ __RW __u32 BP7;
|
||||
/* */ __RO __u32 REV2a[0x30 - 0x2a - 1];
|
||||
|
||||
/* 30 */ __RW __u32 PMU_CON0;
|
||||
/* 31 */ __RW __u32 PMU_CON1;
|
||||
/* 32 */ __RO __u32 RST_ADDR;
|
||||
/* */ __RO __u32 REV32[0x3b - 0x32 - 1];
|
||||
/* 3b */ __RW __u8 TTMR_CON;
|
||||
/* 3c */ __RW __u32 TTMR_CNT;
|
||||
/* 3d */ __RW __u32 TTMR_PRD;
|
||||
/* */ __RO __u32 REV3d[0x40 - 0x3d - 1];
|
||||
|
||||
/* 40 */ __RW __u32 ICFG00;
|
||||
/* 41 */ __RW __u32 ICFG01;
|
||||
/* 42 */ __RW __u32 ICFG02;
|
||||
/* 43 */ __RW __u32 ICFG03;
|
||||
/* 44 */ __RW __u32 ICFG04;
|
||||
/* 45 */ __RW __u32 ICFG05;
|
||||
/* 46 */ __RW __u32 ICFG06;
|
||||
/* 47 */ __RW __u32 ICFG07;
|
||||
/* 48 */ __RW __u32 ICFG08;
|
||||
/* 49 */ __RW __u32 ICFG09;
|
||||
/* 4a */ __RW __u32 ICFG10;
|
||||
/* 4b */ __RW __u32 ICFG11;
|
||||
/* 4c */ __RW __u32 ICFG12;
|
||||
/* 4d */ __RW __u32 ICFG13;
|
||||
/* 4e */ __RW __u32 ICFG14;
|
||||
/* 4f */ __RW __u32 ICFG15;
|
||||
|
||||
/* 50 */ __RW __u32 ICFG16;
|
||||
/* 51 */ __RW __u32 ICFG17;
|
||||
/* 52 */ __RW __u32 ICFG18;
|
||||
/* 53 */ __RW __u32 ICFG19;
|
||||
/* 54 */ __RW __u32 ICFG20;
|
||||
/* 55 */ __RW __u32 ICFG21;
|
||||
/* 56 */ __RW __u32 ICFG22;
|
||||
/* 57 */ __RW __u32 ICFG23;
|
||||
/* 58 */ __RW __u32 ICFG24;
|
||||
/* 59 */ __RW __u32 ICFG25;
|
||||
/* 5a */ __RW __u32 ICFG26;
|
||||
/* 5b */ __RW __u32 ICFG27;
|
||||
/* 5c */ __RW __u32 ICFG28;
|
||||
/* 5d */ __RW __u32 ICFG29;
|
||||
/* 5e */ __RW __u32 ICFG30;
|
||||
/* 5f */ __RW __u32 ICFG31;
|
||||
|
||||
/* 60 */ __RO __u32 IPND0;
|
||||
/* 61 */ __RO __u32 IPND1;
|
||||
/* 62 */ __RO __u32 IPND2;
|
||||
/* 63 */ __RO __u32 IPND3;
|
||||
/* 64 */ __RO __u32 IPND4;
|
||||
/* 65 */ __RO __u32 IPND5;
|
||||
/* 66 */ __RO __u32 IPND6;
|
||||
/* 67 */ __RO __u32 IPND7;
|
||||
/* 68 */ __WO __u32 ILAT_SET;
|
||||
/* 69 */ __WO __u32 ILAT_CLR;
|
||||
/* 6a */ __RW __u32 IPMASK;
|
||||
/* 6b */ __RW __u32 GIEMASK;
|
||||
/* 6c */ __RW __u32 IWKUP_NUM;
|
||||
/* */ __RO __u32 REV6c[0x70 - 0x6c - 1];
|
||||
|
||||
/* 70 */ __RW __u32 ETM_CON;
|
||||
/* 71 */ __RO __u32 ETM_PC0;
|
||||
/* 72 */ __RO __u32 ETM_PC1;
|
||||
/* 73 */ __RO __u32 ETM_PC2;
|
||||
/* 74 */ __RO __u32 ETM_PC3;
|
||||
/* 75 */ __RW __u32 WP0_ADRH;
|
||||
/* 76 */ __RW __u32 WP0_ADRL;
|
||||
/* 77 */ __RW __u32 WP0_DATH;
|
||||
/* 78 */ __RW __u32 WP0_DATL;
|
||||
/* 79 */ __RO __u32 WP0_PC;
|
||||
/* 7a */ __RO __u32 WP0_AMSG;
|
||||
/* */ __RO __u32 REV7b[0x80 - 0x7a - 1];
|
||||
|
||||
/* 80 */ __RW __u32 EMU_CON;
|
||||
/* 81 */ __RW __u32 EMU_MSG;
|
||||
/* 82 */ __RW __u32 EMU_SSP_H;
|
||||
/* 83 */ __RW __u32 EMU_SSP_L;
|
||||
/* 84 */ __RW __u32 EMU_USP_H;
|
||||
/* 85 */ __RW __u32 EMU_USP_L;
|
||||
/* 86 */ __RW __u32 LIM_PC0_H;
|
||||
/* 87 */ __RW __u32 LIM_PC0_L;
|
||||
/* 88 */ __RW __u32 LIM_PC1_H;
|
||||
/* 89 */ __RW __u32 LIM_PC1_L;
|
||||
/* 8a */ __RW __u32 LIM_PC2_H;
|
||||
/* 8b */ __RW __u32 LIM_PC2_L;
|
||||
/* */ __RO __u32 REV8b[0x90 - 0x8b - 1];
|
||||
|
||||
/* 90 */ __RW __u32 ESU_CON;
|
||||
/* 91 */ __RO __u32 CNT_CHIT;
|
||||
/* 92 */ __RO __u32 CNT_CMIS;
|
||||
/* 93 */ __RO __u32 CNT_FILL;
|
||||
/* 94 */ __RO __u32 CNT_IHIT;
|
||||
/* 95 */ __RO __u32 CNT_IMIS;
|
||||
/* 96 */ __RO __u32 CNT_RHIT;
|
||||
/* 97 */ __RO __u32 CNT_RMIS;
|
||||
/* 98 */ __RO __u32 CNT_WHIT;
|
||||
/* 99 */ __RO __u32 CNT_WMIS;
|
||||
} JL_TypeDef_q32DSP;
|
||||
|
||||
//---------------------------------------------//
|
||||
// q32DSP icache sfr
|
||||
//---------------------------------------------//
|
||||
|
||||
typedef struct {
|
||||
__RW __u32 CON;
|
||||
__RW __u32 EMU_CON;
|
||||
__RW __u32 EMU_MSG;
|
||||
__RW __u32 EMU_ID;
|
||||
__RW __u32 CMD_CON;
|
||||
__RW __u32 CMD_BEG;
|
||||
__RW __u32 CMD_END;
|
||||
__RW __u32 CNT_RACK;
|
||||
__RW __u32 CNT_RNAK;
|
||||
__RW __u32 MBIST_SEL;
|
||||
__RW __u32 MCFG0_CON[2];
|
||||
} JL_TypeDef_q32DSP_ICU;
|
||||
|
||||
//---------------------------------------------//
|
||||
// q32DSP dcache sfr
|
||||
//---------------------------------------------//
|
||||
|
||||
typedef struct {
|
||||
__RW __u32 CON;
|
||||
__RW __u32 EMU_CON;
|
||||
__RW __u32 EMU_MSG;
|
||||
__RW __u32 EMU_ID;
|
||||
__RW __u32 CNT_WACK;
|
||||
__RW __u32 CNT_WNAK;
|
||||
__RW __u32 CNT_RACK;
|
||||
__RW __u32 CNT_RNAK;
|
||||
__RW __u32 CMD_CON[4];
|
||||
__RW __u32 CMD_BEG[4];
|
||||
__RW __u32 CMD_END[4];
|
||||
__RW __u32 MBIST_SEL;
|
||||
__RW __u32 MCFG0_CON[2];
|
||||
__RO __u32 REV1[0x20 - 0x16 - 1];
|
||||
__WO __u32 CMO[32];
|
||||
} JL_TypeDef_q32DSP_DCU;
|
||||
|
||||
#undef __RW
|
||||
#undef __RO
|
||||
#undef __WO
|
||||
|
||||
#undef __u8
|
||||
#undef __u16
|
||||
#undef __u32
|
||||
|
||||
//*********************************************************************************//
|
||||
// //
|
||||
// end of this module //
|
||||
// //
|
||||
//*********************************************************************************//
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef __DELAY_H__
|
||||
#define __DELAY_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
void udelay(u32 usec);
|
||||
|
||||
void mdelay(u32 msec);
|
||||
|
||||
void delay(volatile u32 t);
|
||||
|
||||
void rc_udelay(u32 usec);
|
||||
|
||||
void rc_mdelay(u32 msec);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,788 @@
|
||||
/**
|
||||
* @file gpio.h
|
||||
* @brief
|
||||
* @author @zh-jieli.com
|
||||
* @version 1.0.0
|
||||
* @date 2018-10-11
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GPIO_H__
|
||||
#define __GPIO_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#define IO_GROUP_NUM 16
|
||||
|
||||
|
||||
#define IO_PORTA_00 (IO_GROUP_NUM * 0 + 0)
|
||||
#define IO_PORTA_01 (IO_GROUP_NUM * 0 + 1)
|
||||
#define IO_PORTA_02 (IO_GROUP_NUM * 0 + 2)
|
||||
#define IO_PORTA_03 (IO_GROUP_NUM * 0 + 3)
|
||||
#define IO_PORTA_04 (IO_GROUP_NUM * 0 + 4)
|
||||
#define IO_PORTA_05 (IO_GROUP_NUM * 0 + 5)
|
||||
#define IO_PORTA_06 (IO_GROUP_NUM * 0 + 6)
|
||||
#define IO_PORTA_07 (IO_GROUP_NUM * 0 + 7)
|
||||
#define IO_PORTA_08 (IO_GROUP_NUM * 0 + 8)
|
||||
#define IO_PORTA_09 (IO_GROUP_NUM * 0 + 9)
|
||||
#define IO_PORTA_10 (IO_GROUP_NUM * 0 + 10)
|
||||
#define IO_PORTA_11 (IO_GROUP_NUM * 0 + 11)
|
||||
#define IO_PORTA_12 (IO_GROUP_NUM * 0 + 12)
|
||||
#define IO_PORTA_13 (IO_GROUP_NUM * 0 + 13)
|
||||
#define IO_PORT_PA_MASK 0x3fff
|
||||
|
||||
#define IO_PORTB_00 (IO_GROUP_NUM * 1 + 0)
|
||||
#define IO_PORTB_01 (IO_GROUP_NUM * 1 + 1)
|
||||
#define IO_PORTB_02 (IO_GROUP_NUM * 1 + 2)
|
||||
#define IO_PORTB_03 (IO_GROUP_NUM * 1 + 3)
|
||||
#define IO_PORTB_04 (IO_GROUP_NUM * 1 + 4)
|
||||
#define IO_PORTB_05 (IO_GROUP_NUM * 1 + 5)
|
||||
#define IO_PORTB_06 (IO_GROUP_NUM * 1 + 6)
|
||||
#define IO_PORTB_07 (IO_GROUP_NUM * 1 + 7)
|
||||
#define IO_PORTB_08 (IO_GROUP_NUM * 1 + 8)
|
||||
#define IO_PORT_PB_MASK 0x01ff
|
||||
|
||||
#define IO_PORTC_00 (IO_GROUP_NUM * 2 + 0)
|
||||
#define IO_PORTC_01 (IO_GROUP_NUM * 2 + 1)
|
||||
#define IO_PORTC_02 (IO_GROUP_NUM * 2 + 2)
|
||||
#define IO_PORTC_03 (IO_GROUP_NUM * 2 + 3)
|
||||
#define IO_PORTC_04 (IO_GROUP_NUM * 2 + 4)
|
||||
#define IO_PORTC_05 (IO_GROUP_NUM * 2 + 5)
|
||||
#define IO_PORTC_06 (IO_GROUP_NUM * 2 + 6)
|
||||
#define IO_PORTC_07 (IO_GROUP_NUM * 2 + 7)
|
||||
#define IO_PORTC_08 (IO_GROUP_NUM * 2 + 8)
|
||||
#define IO_PORTC_09 (IO_GROUP_NUM * 2 + 9)
|
||||
#define IO_PORTC_10 (IO_GROUP_NUM * 2 + 10)
|
||||
#define IO_PORTC_11 (IO_GROUP_NUM * 2 + 11)
|
||||
#define IO_PORT_PC_MASK 0x0fff
|
||||
|
||||
#define IO_PORTF_00 (IO_GROUP_NUM * 3 + 0)
|
||||
#define IO_PORTF_01 (IO_GROUP_NUM * 3 + 1)
|
||||
#define IO_PORTF_02 (IO_GROUP_NUM * 3 + 2)
|
||||
#define IO_PORTF_03 (IO_GROUP_NUM * 3 + 3)
|
||||
#define IO_PORTF_04 (IO_GROUP_NUM * 3 + 4)
|
||||
#define IO_PORTF_05 (IO_GROUP_NUM * 3 + 5)
|
||||
#define IO_PORT_PF_MASK 0x003f
|
||||
|
||||
#define IO_PORTP_00 (IO_GROUP_NUM * 4 + 0)
|
||||
#define IO_PORT_PP_MASK 0x0001
|
||||
|
||||
#define IO_PORT_LDOIN IO_PORTP_00
|
||||
|
||||
#define IO_MAX_NUM (IO_PORTP_00 + 1)
|
||||
|
||||
#define IO_PORT_DP (IO_GROUP_NUM * 5 + 0)
|
||||
#define IO_PORT_DM (IO_GROUP_NUM * 5 + 1)
|
||||
#define IO_PORT_USB_MASK 0x03
|
||||
#define IS_PORT_USB(x) (x <= IO_PORT_DM)//无usb赋0
|
||||
|
||||
//br50无pr
|
||||
// #define IO_PORT_PR_00 (IO_GROUP_NUM * 15 + 0)//pr固定15
|
||||
// #define IO_PORT_PR_01 (IO_GROUP_NUM * 15 + 1)
|
||||
// #define IO_PORT_PR_MASK 0x03
|
||||
|
||||
#define IO_PORT_MAX (IO_PORT_DM + 1)
|
||||
|
||||
#define P33_IO_OFFSET 0
|
||||
#define IO_CHGFL_DET (IO_PORT_MAX + P33_IO_OFFSET + 0)
|
||||
#define IO_VBGOK_DET (IO_PORT_MAX + P33_IO_OFFSET + 1)
|
||||
#define IO_VBTCH_DET (IO_PORT_MAX + P33_IO_OFFSET + 2)
|
||||
#define IO_LDOIN_DET (IO_PORT_MAX + P33_IO_OFFSET + 3)
|
||||
#define IO_VBATDT_DET (IO_PORT_MAX + P33_IO_OFFSET + 4)
|
||||
|
||||
#define PG_IO_OFFSET 5
|
||||
#define IO_LCD_PG (IO_PORT_MAX + PG_IO_OFFSET + 0)
|
||||
#define IO_MT_PG (IO_PORT_MAX + PG_IO_OFFSET + 1)
|
||||
#define IO_FS_PG2 (IO_PORT_MAX + PG_IO_OFFSET + 2)
|
||||
|
||||
|
||||
#define GPIOA (IO_GROUP_NUM * 0)
|
||||
#define GPIOB (IO_GROUP_NUM * 1)
|
||||
#define GPIOC (IO_GROUP_NUM * 2)
|
||||
#define GPIOF (IO_GROUP_NUM * 3)
|
||||
#define GPIOP (IO_GROUP_NUM * 4)
|
||||
#define GPIOUSB (IO_GROUP_NUM * 5)
|
||||
// #define GPIOR (IO_GROUP_NUM * 15) //br50 no pr
|
||||
#define GPIOP33 (IO_PORT_MAX + P33_IO_OFFSET)
|
||||
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
INPUT_CH0,
|
||||
INPUT_CH1,
|
||||
INPUT_CH2,
|
||||
INPUT_CH3,
|
||||
};
|
||||
|
||||
enum {
|
||||
LOW_POWER_FREE = 0,
|
||||
LOW_POWER_KEEP = 1,
|
||||
};
|
||||
enum gpio_op_mode {
|
||||
GPIO_SET = 1,
|
||||
GPIO_AND,
|
||||
GPIO_OR,
|
||||
GPIO_XOR,
|
||||
};
|
||||
enum gpio_direction {
|
||||
GPIO_OUT = 0,
|
||||
GPIO_IN = 1,
|
||||
};
|
||||
struct gpio_reg {
|
||||
volatile unsigned int in;
|
||||
volatile unsigned int out;
|
||||
volatile unsigned int dir;
|
||||
volatile unsigned int die;
|
||||
volatile unsigned int dieh;
|
||||
volatile unsigned int pu0;
|
||||
volatile unsigned int pu1;
|
||||
volatile unsigned int pd0;
|
||||
volatile unsigned int pd1;
|
||||
volatile unsigned int hd0;
|
||||
volatile unsigned int hd1;
|
||||
volatile unsigned int spl;
|
||||
volatile unsigned int con;
|
||||
};
|
||||
|
||||
struct gpio_platform_data {
|
||||
unsigned int gpio;
|
||||
};
|
||||
|
||||
#define GPIO_PLATFORM_DATA_BEGIN(data) \
|
||||
static const struct gpio_platform_data data = { \
|
||||
|
||||
|
||||
#define GPIO_PLATFORM_DATA_END() \
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb_iomode
|
||||
*
|
||||
* @param enable 1,使能;0,关闭
|
||||
*/
|
||||
void usb_iomode(u32 enable);
|
||||
/**
|
||||
* @brief gpio_direction_input
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param dir 1,输入;0,输出
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_set_direction(u32 gpio, u32 dir);
|
||||
|
||||
|
||||
/**
|
||||
* @brief gpio_direction_input
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,输出1, 0,输出0
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_set_output_value(u32 gpio, u32 dir);
|
||||
|
||||
/**
|
||||
* @brief gpio_dir
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
* @param start [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param len [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param dat 1,输入;0,输出
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_dir(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
|
||||
/**
|
||||
* @brief gpio_direction_output
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,输出1;0,输出0
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_direction_output(u32 gpio, int value);
|
||||
|
||||
/**
|
||||
* @brief gpio_out
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
* @param start [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param len [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param dat 1,输入;0,输出
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_out(u32 gpio, u32 start, u32 len, u32 dat);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_pull_up
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,上拉;0,不上拉
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_set_pull_up(u32 gpio, int value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief gpio_set_pu
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
* @param start [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param len [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param dat 1,上拉;0,不上拉
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_set_pu0(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
u32 gpio_set_pu1(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_pull_down
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,下拉;0,不下拉
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_set_pull_down(u32 gpio, int value);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_pd
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
* @param start [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param len [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param dat 1,下拉;0,不下拉
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_set_pd0(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
u32 gpio_set_pd1(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
|
||||
enum GPIO_HDRIVE {
|
||||
GPIO_HDRIVE_2_4_MA = 0, //2.4mA
|
||||
GPIO_HDRIVE_8_MA, //8mA
|
||||
GPIO_HDRIVE_26_4_MA, //26.4mA
|
||||
GPIO_HDRIVE_40_MA, //40mA
|
||||
};
|
||||
/**
|
||||
* @brief gpio_set_hd
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value see enum GPIO_HDRIVE
|
||||
*
|
||||
* @return 0:ok, <0:fail
|
||||
*/
|
||||
int gpio_set_hd(u32 gpio, int value);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_die
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,IO普通输入;0,IO模拟输入
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_set_die(u32 gpio, int value);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_dieh
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,IO普通输入;0,IO模拟输入
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_set_dieh(u32 gpio, u32 value);
|
||||
|
||||
/**
|
||||
* @brief gpio_die
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
* @param start [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param len [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param dat 1,IO普通输入;0,IO模拟输入
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_die(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
|
||||
/**
|
||||
* @brief gpio_dieh
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
* @param start [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param len [0-15],GPIOR[0-3],GPIOUSB[0-1]
|
||||
* @param dat 1,IO普通输入;0,IO模拟输入
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_dieh(u32 gpio, u32 start, u32 len, u32 dat, enum gpio_op_mode op);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_output_channle
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param clk 参考枚举CHx_UTx_TX,如CH0_UT0_TX
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_output_channle(u32 gpio, u32 clk);
|
||||
|
||||
/**
|
||||
* @brief gpio_read
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int gpio_read(u32 gpio);
|
||||
|
||||
/**
|
||||
* @brief gpio_in
|
||||
*
|
||||
* @param gpio [GPIOA GPIOB GPIOC GPIOD GPIOR GPIOUSB]
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_in(u32 gpio);
|
||||
/**
|
||||
* @brief gpio_write
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
* @param value 1,输出1;0,输出0
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_write(u32 gpio, u32 value);
|
||||
|
||||
/**
|
||||
* @brief gpio_wakeup0 use IN_CHNL0_SEL
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_wakeup0(u32 gpio);
|
||||
|
||||
/**
|
||||
* @brief gpio_irflt_in use IN_CHNL1_SEL
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_irflt_in(u32 gpio);
|
||||
|
||||
/**
|
||||
* @brief gpio_cap_mux use IN_CHNL2_SEL
|
||||
*
|
||||
* @param gpio 参考宏IO_PORTx_xx,如IO_PORTA_00
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_cap_mux(u32 gpio);
|
||||
|
||||
|
||||
/**
|
||||
* @brief gpio_uart_rx_input
|
||||
*
|
||||
* @param gpio
|
||||
* @param ut
|
||||
* @param ch
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_uart_rx_input(u32 gpio, u32 ut, u32 ch);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_close_uart0(void);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_close_uart1(void);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_close_uart2(void);
|
||||
|
||||
/**
|
||||
* @brief gpio_set_uart0
|
||||
*
|
||||
* @param ch 0:3 选择对应IO br22
|
||||
* |ch|tx|rx|
|
||||
* |- |- |- |
|
||||
* |0|PA5_TX|PA6_RX|
|
||||
* |1|PB7_TX|PB8_RX|
|
||||
* |2|PA7_TX|PA8_RX|
|
||||
* |3|预留|预留|
|
||||
* |-1|关闭对应的IO口串口功能|no|
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_set_uart0(u32 ch);
|
||||
/**
|
||||
* @brief gpio_set_uart1
|
||||
*
|
||||
* @param ch 0:3 选择对应IO br22
|
||||
* |ch|tx|rx|
|
||||
* |- |- |- |
|
||||
* |0|PB5_TX|PB6_RX|
|
||||
* |1|预留|预留|
|
||||
* |2|PA1_TX|PA2_RX|
|
||||
* |3|USBDP |USBDM |
|
||||
* |-1|关闭对应的IO口串口功能|no|
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_set_uart1(u32 ch);
|
||||
/**
|
||||
* @brief gpio_set_uart2
|
||||
*
|
||||
* @param ch 0:3 选择对应IO br22
|
||||
* |ch|tx|rx|
|
||||
* |- |- |- |
|
||||
* |0|PA3_TX|PA4_RX|
|
||||
* |1|预留|预留|
|
||||
* |2|预留|预留|
|
||||
* |3|PA9_TX|PA10_RX|
|
||||
* |-1|关闭对应的IO口串口功能|no|
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_set_uart2(u32 ch);
|
||||
|
||||
enum {
|
||||
IRFLT_LSB,
|
||||
// IRFLT_LSB,
|
||||
IRFLT_STD12M = 2,
|
||||
IRFLT_STD24M,
|
||||
};
|
||||
enum {
|
||||
IRFLT_DIV1,
|
||||
IRFLT_DIV2,
|
||||
IRFLT_DIV4,
|
||||
IRFLT_DIV8,
|
||||
IRFLT_DIV16,
|
||||
IRFLT_DIV32,
|
||||
IRFLT_DIV64,
|
||||
IRFLT_DIV128,
|
||||
IRFLT_DIV256,
|
||||
IRFLT_DIV512,
|
||||
IRFLT_DIV1024,
|
||||
IRFLT_DIV2048,
|
||||
IRFLT_DIV4096,
|
||||
IRFLT_DIV8192,
|
||||
IRFLT_DIV16384,
|
||||
IRFLT_DIV32768,
|
||||
};
|
||||
/* u32 irflt_config(u32 osc, u32 div); */
|
||||
|
||||
/**
|
||||
* @brief gpio_irflt_to_timer
|
||||
*
|
||||
* @param t: [0-3]
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
u32 gpio_irflt_to_timer(u32 t);
|
||||
|
||||
|
||||
u32 get_gpio(const char *p);
|
||||
const char *gpio_get_name(u32 gpio);
|
||||
|
||||
//===================================================//
|
||||
// BR50 Crossbar API
|
||||
//===================================================//
|
||||
enum PFI_TABLE {
|
||||
PFI_GP_ICH0 = ((u32)(&(JL_IMAP->FI_GP_ICH0))),
|
||||
PFI_GP_ICH1 = ((u32)(&(JL_IMAP->FI_GP_ICH1))),
|
||||
PFI_GP_ICH2 = ((u32)(&(JL_IMAP->FI_GP_ICH2))),
|
||||
PFI_GP_ICH3 = ((u32)(&(JL_IMAP->FI_GP_ICH3))),
|
||||
PFI_GP_ICH4 = ((u32)(&(JL_IMAP->FI_GP_ICH4))),
|
||||
PFI_GP_ICH5 = ((u32)(&(JL_IMAP->FI_GP_ICH5))),
|
||||
PFI_SD0_CMD = ((u32)(&(JL_IMAP->FI_SD0_CMD))),
|
||||
PFI_SD0_DA0 = ((u32)(&(JL_IMAP->FI_SD0_DA0))),
|
||||
PFI_SD0_DA1 = ((u32)(&(JL_IMAP->FI_SD0_DA1))),
|
||||
PFI_SD0_DA2 = ((u32)(&(JL_IMAP->FI_SD0_DA2))),
|
||||
PFI_SD0_DA3 = ((u32)(&(JL_IMAP->FI_SD0_DA3))),
|
||||
|
||||
// PFI_SPI0_CLK = ((u32)(&(JL_IMAP->FI_SPI0_CLK))),
|
||||
// PFI_SPI0_DA0 = ((u32)(&(JL_IMAP->FI_SPI0_DA0))),
|
||||
// PFI_SPI0_DA1 = ((u32)(&(JL_IMAP->FI_SPI0_DA1))),
|
||||
// PFI_SPI0_DA2 = ((u32)(&(JL_IMAP->FI_SPI0_DA2))),
|
||||
// PFI_SPI0_DA3 = ((u32)(&(JL_IMAP->FI_SPI0_DA3))),
|
||||
PFI_SPI1_CLK = ((u32)(&(JL_IMAP->FI_SPI1_CLK))),
|
||||
PFI_SPI1_DA0 = ((u32)(&(JL_IMAP->FI_SPI1_DA0))),
|
||||
PFI_SPI1_DA1 = ((u32)(&(JL_IMAP->FI_SPI1_DA1))),
|
||||
PFI_SPI1_DA2 = ((u32)(&(JL_IMAP->FI_SPI1_DA2))),
|
||||
PFI_SPI1_DA3 = ((u32)(&(JL_IMAP->FI_SPI1_DA3))),
|
||||
PFI_SPI2_CLK = ((u32)(&(JL_IMAP->FI_SPI2_CLK))),
|
||||
PFI_SPI2_DA0 = ((u32)(&(JL_IMAP->FI_SPI2_DA0))),
|
||||
PFI_SPI2_DA1 = ((u32)(&(JL_IMAP->FI_SPI2_DA1))),
|
||||
|
||||
// PFI_SD0_DA1 = ((u32)(&(JL_IMAP->FI_SD0_DA1))),
|
||||
// PFI_SD0_DA2 = ((u32)(&(JL_IMAP->FI_SD0_DA2))),
|
||||
// PFI_SD0_DA3 = ((u32)(&(JL_IMAP->FI_SD0_DA3))),
|
||||
PFI_IIC0_SCL = ((u32)(&(JL_IMAP->FI_IIC0_SCL))),
|
||||
PFI_IIC0_SDA = ((u32)(&(JL_IMAP->FI_IIC0_SDA))),
|
||||
PFI_UART0_RX = ((u32)(&(JL_IMAP->FI_UART0_RX))),
|
||||
|
||||
PFI_UART1_RX = ((u32)(&(JL_IMAP->FI_UART1_RX))),
|
||||
|
||||
// PFI_UART1_CTS = ((u32)(&(JL_IMAP->FI_UART1_CTS))),
|
||||
PFI_UART2_RX = ((u32)(&(JL_IMAP->FI_UART2_RX))),
|
||||
// PFI_TDM_S_WCK = ((u32)(&(JL_IMAP->FI_TDM_S_WCK))),
|
||||
// PFI_TDM_S_BCK = ((u32)(&(JL_IMAP->FI_TDM_S_BCK))),
|
||||
// PFI_TDM_M_DA = ((u32)(&(JL_IMAP->FI_TDM_M_DA))),
|
||||
// PFI_RDEC0_DAT0 = ((u32)(&(JL_IMAP->FI_RDEC0_DAT0))),
|
||||
// PFI_RDEC0_DAT1 = ((u32)(&(JL_IMAP->FI_RDEC0_DAT1))),
|
||||
// PFI_RDEC1_DAT0 = ((u32)(&(JL_IMAP->FI_RDEC1_DAT0))),
|
||||
// PFI_RDEC1_DAT1 = ((u32)(&(JL_IMAP->FI_RDEC1_DAT1))),
|
||||
// PFI_RDEC2_DAT0 = ((u32)(&(JL_IMAP->FI_RDEC2_DAT0))),
|
||||
// PFI_RDEC2_DAT1 = ((u32)(&(JL_IMAP->FI_RDEC2_DAT1))),
|
||||
//PFI_ALNK0_MCLK = ((u32)(&(JL_IMAP->FI_ALNK0_MCLK))),
|
||||
//PFI_ALNK0_LRCK = ((u32)(&(JL_IMAP->FI_ALNK0_LRCK))),
|
||||
//PFI_ALNK0_SCLK = ((u32)(&(JL_IMAP->FI_ALNK0_SCLK))),
|
||||
//PFI_ALNK0_DAT0 = ((u32)(&(JL_IMAP->FI_ALNK0_DAT0))),
|
||||
//PFI_ALNK0_DAT1 = ((u32)(&(JL_IMAP->FI_ALNK0_DAT1))),
|
||||
//PFI_ALNK0_DAT2 = ((u32)(&(JL_IMAP->FI_ALNK0_DAT2))),
|
||||
//PFI_ALNK0_DAT3 = ((u32)(&(JL_IMAP->FI_ALNK0_DAT3))),
|
||||
//PFI_SPDIF_DIA = ((u32)(&(JL_IMAP->FI_SPDIF_DIA))),
|
||||
//PFI_SPDIF_DIB = ((u32)(&(JL_IMAP->FI_SPDIF_DIB))),
|
||||
//PFI_SPDIF_DIC = ((u32)(&(JL_IMAP->FI_SPDIF_DIC))),
|
||||
//PFI_SPDIF_DID = ((u32)(&(JL_IMAP->FI_SPDIF_DID))),
|
||||
//PFI_PLNK_DAT0 = ((u32)(&(JL_IMAP->FI_PLNK_DAT0))),
|
||||
//PFI_PLNK_DAT1 = ((u32)(&(JL_IMAP->FI_PLNK_DAT1))),
|
||||
//PFI_CAN_RX = ((u32)(&(JL_IMAP->FI_CAN_RX))),
|
||||
PFI_QDEC0_A = ((u32)(&(JL_IMAP->FI_QDEC0_A))),
|
||||
PFI_QDEC0_B = ((u32)(&(JL_IMAP->FI_QDEC0_B))),
|
||||
PFI_CHAIN_IN0 = ((u32)(&(JL_IMAP->FI_CHAIN_IN0))),
|
||||
PFI_CHAIN_IN1 = ((u32)(&(JL_IMAP->FI_CHAIN_IN1))),
|
||||
PFI_CHAIN_IN2 = ((u32)(&(JL_IMAP->FI_CHAIN_IN2))),
|
||||
PFI_CHAIN_IN3 = ((u32)(&(JL_IMAP->FI_CHAIN_IN3))),
|
||||
PFI_CHAIN_RST = ((u32)(&(JL_IMAP->FI_CHAIN_RST))),
|
||||
PFI_TOTAl = ((u32)(&(JL_IMAP->FI_TOTAL))),
|
||||
};
|
||||
|
||||
enum OUTPUT_CH_SIGNAL {
|
||||
OUTPUT_CH_SIGNAL_TIMER0_PWM,//8
|
||||
OUTPUT_CH_SIGNAL_TIMER1_PWM,
|
||||
OUTPUT_CH_SIGNAL_TIMER2_PWM,
|
||||
OUTPUT_CH_SIGNAL_TIMER3_PWM,
|
||||
OUTPUT_CH_SIGNAL_TIMER4_PWM,
|
||||
OUTPUT_CH_SIGNAL_TIMER5_PWM,
|
||||
OUTPUT_CH_SIGNAL_MCPWM0_H,
|
||||
OUTPUT_CH_SIGNAL_MCPWM0_L,
|
||||
OUTPUT_CH_SIGNAL_MCPWM1_H,
|
||||
OUTPUT_CH_SIGNAL_MCPWM1_L,
|
||||
OUTPUT_CH_SIGNAL_UART1_RTS,
|
||||
OUTPUT_CH_SIGNAL_CLOCK_OUT0,
|
||||
OUTPUT_CH_SIGNAL_CLOCK_OUT1,//br50无clk out1
|
||||
OUTPUT_CH_SIGNAL_CLOCK_OUT2,
|
||||
OUTPUT_CH_SIGNAL_GP_ICH0,
|
||||
OUTPUT_CH_SIGNAL_GP_ICH1,
|
||||
|
||||
OUTPUT_CH_SIGNAL_LEDC0_OUT = 32,
|
||||
OUTPUT_CH_SIGNAL_LEDC1_OUT = 33,
|
||||
};
|
||||
|
||||
enum INPUT_CH_TYPE {
|
||||
INPUT_CH_TYPE_GP_ICH = 0,
|
||||
INPUT_CH_TYPE_TIME2_PWM = 6,
|
||||
INPUT_CH_TYPE_TIME3_PWM,
|
||||
INPUT_CH_TYPE_MAX = 8,
|
||||
};
|
||||
|
||||
enum INPUT_CH_SIGNAL {
|
||||
//ICH_CON0
|
||||
INPUT_CH_SIGNAL_TIMER0_CIN = 0,//5
|
||||
INPUT_CH_SIGNAL_TIMER1_CIN,
|
||||
INPUT_CH_SIGNAL_TIMER2_CIN,
|
||||
INPUT_CH_SIGNAL_TIMER3_CIN,
|
||||
INPUT_CH_SIGNAL_TIMER4_CIN,
|
||||
INPUT_CH_SIGNAL_TIMER5_CIN,
|
||||
//ICH_CON1
|
||||
INPUT_CH_SIGNAL_TIMER0_CAPTURE,
|
||||
INPUT_CH_SIGNAL_TIMER1_CAPTURE,
|
||||
INPUT_CH_SIGNAL_TIMER2_CAPTURE,
|
||||
INPUT_CH_SIGNAL_TIMER3_CAPTURE,
|
||||
INPUT_CH_SIGNAL_TIMER4_CAPTURE,
|
||||
INPUT_CH_SIGNAL_TIMER5_CAPTURE,
|
||||
//ICH_CON2
|
||||
INPUT_CH_SIGNAL_MCPWM0_CK,
|
||||
INPUT_CH_SIGNAL_MCPWM1_CK,
|
||||
INPUT_CH_SIGNAL_MCPWM0_FP,
|
||||
INPUT_CH_SIGNAL_MCPWM1_FP,
|
||||
INPUT_CH_SIGNAL_IRFLT,
|
||||
INPUT_CH_SIGNAL_UART1_CTS,
|
||||
//ICH_CON3
|
||||
INPUT_CH_SIGNAL_QDEC_SIN0,
|
||||
INPUT_CH_SIGNAL_QDEC_SIN1,
|
||||
INPUT_CH_SIGNAL_WLC_EXT_ACT,
|
||||
INPUT_CH_SIGNAL_CAP,
|
||||
INPUT_CH_SIGNAL_CLK_PIN,
|
||||
INPUT_CH_SIGNAL_EXT_CLK,
|
||||
//ICH_CON4
|
||||
INPUT_CH_SIGNAL_AUD_DBG_DATI,
|
||||
INPUT_CH_SIGNAL_RESERVE0,
|
||||
INPUT_CH_SIGNAL_RESERVE1,
|
||||
INPUT_CH_SIGNAL_RESERVE2,
|
||||
INPUT_CH_SIGNAL_RESERVE3,
|
||||
INPUT_CH_SIGNAL_RESERVE4,
|
||||
};
|
||||
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: CrossBar 获取某IO的输出映射寄存器
|
||||
//@input:
|
||||
// gpio: 需要输出外设信号的IO口; 如IO_PORTA_00
|
||||
//@return:
|
||||
// 输出映射寄存器地址; 如&(JL_OMAP->PA0_OUT)
|
||||
//=================================================================================//
|
||||
u32 *gpio2crossbar_outreg(u32 gpio);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: CrossBar 获取某IO的输入映射序号
|
||||
//@input:
|
||||
// gpio: 需要输出外设信号的IO口; 如IO_PORTA_00
|
||||
//@return:
|
||||
// 输出映射序号; 如PA0_IN
|
||||
//=================================================================================//
|
||||
u32 gpio2crossbar_inport(u32 gpio);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: CrossBar 输出设置 API, 将指定IO口设置为某个外设的输出
|
||||
//@input:
|
||||
// gpio: 需要输出外设信号的IO口;
|
||||
// fun_index: 需要输出到指定IO口的外设信号, 可以输出外设信号列表请查看io_omap.h文件;
|
||||
// dir_ctl: IO口方向由外设控制使能, 常设为1;
|
||||
// data_ctl: IO口电平状态由外设控制使能, 常设为1;
|
||||
// low_power_mode: 低功耗状态是否保持io功能;
|
||||
//@return:
|
||||
// 1)0: 执行正确;
|
||||
// 2)-EINVAL: 传参出错;
|
||||
//@note: 所映射的IO需要在设置IO状态为输出配置;
|
||||
//@example: 将UART0的Tx信号输出到IO_PORTA_05口:
|
||||
// gpio_direction_output(IO_PORTA_05, 1); //设置IO为输出状态
|
||||
// gpio_set_fun_output_port(IO_PORTA_05, FO_UART0_TX, 1, 1); //将UART0的Tx信号输出到IO_PORTA_05口
|
||||
//=================================================================================//
|
||||
int gpio_set_fun_output_port(u32 gpio, u32 fun_index, u8 dir_ctl, u8 data_ctl, u8 low_power_mode);
|
||||
|
||||
u32 gpio_get_ompap_low_power_mode(u32 offset);
|
||||
//=================================================================================//
|
||||
//@brief: CrossBar 输出设置 API, 将指定IO释放外设控制, 变为普通IO;
|
||||
//@input:
|
||||
// gpio: 需要释放外设控制IO口, 释放后变为普通IO模式;
|
||||
//@return:
|
||||
// 1)0: 执行正确;
|
||||
// 2)-EINVAL: 传参出错;
|
||||
//@note:
|
||||
//@example: 将IO_PORTA_05口被某一外设控制状态释放:
|
||||
// gpio_disable_fun_output_port(IO_PORTA_05);
|
||||
//=================================================================================//
|
||||
int gpio_disable_fun_output_port(u32 gpio);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: CrossBar 输入设置 API, 将某个外设的输入设置为从某个IO输入
|
||||
//@input:
|
||||
// gpio: 需要输入外设信号的IO口;
|
||||
// pfun: 需要从指定IO输入的外设信号, 可以输入的外设信号列表请查看gpio.h文件enum PFI_TABLE枚举项;
|
||||
// low_power_mode: 低功耗状态是否保持io功能;
|
||||
//@return:
|
||||
// 1)0: 执行正确;
|
||||
// 2)-EINVAL: 传参出错;
|
||||
//@note: 所映射的IO需要在设置IO状态为输入配置;
|
||||
//@example: 将UART0的Rx信号设置为IO_PORTA_05口输入:
|
||||
// gpio_set_die(IO_PORTA_05, 1); //数字输入使能
|
||||
// gpio_set_pull_up(IO_PORTA_05, 1); //上拉输入使能
|
||||
// gpio_direction_input(IO_PORTA_05); //设置IO为输入状态
|
||||
// gpio_set_fun_input_port(IO_PORTA_05, PFI_UART0_RX); //将UART0的Rx信号设置为IO_PORTA_05口输入
|
||||
//=================================================================================//
|
||||
int gpio_set_fun_input_port(u32 gpio, enum PFI_TABLE pfun, u32 low_power_mode);
|
||||
u32 gpio_get_impap_low_power_mode(u32 offset);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: CrossBar 输入设置 API, 将某个外设信号释放IO口控制, 变为普通IO;
|
||||
//@input:
|
||||
// pfun: 需要释放由某个IO口输入的外设信号, 外设信号列表请查看gpio.h文件enum PFI_TABLE枚举项;
|
||||
//@return: 默认为0, 无出错处理;
|
||||
//@note:
|
||||
//@example: 将外设信号PFI_UART0_RX释放由某个IO输入:
|
||||
// gpio_disable_fun_input_port(PFI_UART0_RX);
|
||||
//=================================================================================//
|
||||
int gpio_disable_fun_input_port(enum PFI_TABLE pfun);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: Output Channel输出设置 API, 将指定IO口设置为某个外设的输出
|
||||
//@input:
|
||||
// gpio: 需要输出外设信号的IO口;
|
||||
// signal: 将enum OUTPUT_CH_SIGNAL列表中需要输出到指定IO口的外设信号, 可以输出的外设信号列表请查看gpio.h文件的enum OUTPUT_CH_SIGNAL枚举项;
|
||||
//@return: 默认为0, 出错内部触发ASSERT;
|
||||
//@note: 所映射的IO需要在设置IO状态为输出配置;
|
||||
//@example: 将OUTPUT_CH_SIGNAL_MC_PWM0_H的Tx信号输出到IO_PORTA_05口:
|
||||
// gpio_direction_output(IO_PORTA_05, 1); //设置IO为输出状态
|
||||
// gpio_och_sel_output_signal(IO_PORTA_05, OUTPUT_CH_SIGNAL_MC_PWM0_H); //将OUTPUT_CH_SIGNAL_MC_PWM0_H信号输出到IO_PORTA_05口
|
||||
//=================================================================================//
|
||||
int gpio_och_sel_output_signal(u32 gpio, enum OUTPUT_CH_SIGNAL signal);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: Output Channel 输出设置 API, 将指定IO释放外设控制, 变为普通IO;
|
||||
//@input:
|
||||
// gpio: 需要释放外设控制IO口, 释放后变为普通IO模式;
|
||||
// signal: 将enum OUTPUT_CH_SIGNAL列表中需要取消输出的外设信号, 外设信号列表请查看gpio.h文件的enum OUTPUT_CH_SIGNAL枚举项;;
|
||||
//@return: 默认为0, 无出错处理;
|
||||
//@note:
|
||||
//@example: 将OUTPUT_CH_SIGNAL_MC_PWM0_H取消输出IO_PORTA_05:
|
||||
// gpio_och_disable_output_signal(IO_PORTA_05, OUTPUT_CH_SIGNAL_MC_PWM0_H);
|
||||
//=================================================================================//
|
||||
int gpio_och_disable_output_signal(u32 gpio, enum OUTPUT_CH_SIGNAL signal);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: Input Channel 输入设置 API, 将某个外设的输入设置为从某个IO输入
|
||||
//@input:
|
||||
// gpio: 需要输入外设信号的IO口;
|
||||
// signal: 需要从指定IO输入的外设信号, 可以输入的外设信号列表请查看gpio.h文件enum INPUT_CH_SIGNAL枚举项;
|
||||
// type: INPUT_CH 类型, 常设为INPUT_CH_TYPE_GP_ICH;
|
||||
//@return: 默认为0, 出错内部触发ASSERT;
|
||||
//@note: 所映射的IO需要在设置IO状态为输入配置;
|
||||
//@example: 将INPUT_CH_SIGNAL_TIMER0_CIN信号设置为IO_PORTA_05口输入:
|
||||
// gpio_set_die(IO_PORTA_05, 1); //数字输入使能
|
||||
// gpio_set_pull_up(IO_PORTA_05, 1); //上拉输入使能
|
||||
// gpio_direction_input(IO_PORTA_05); //设置IO为输入状态
|
||||
// gpio_ich_sel_input_signal(IO_PORTA_05, INPUT_CH_SIGNAL_TIMER0_CIN, INPUT_CH_TYPE_GP_ICH); //将INPUT_CH_SIGNAL_TIMER0_CIN信号设置为IO_PORTA_05口输入
|
||||
//=================================================================================//
|
||||
int gpio_ich_sel_input_signal(u32 gpio, enum INPUT_CH_SIGNAL signal, enum INPUT_CH_TYPE type);
|
||||
|
||||
//=================================================================================//
|
||||
//@brief: Input Channel 输入设置 API, 将某个外设信号释放IO口控制, 变为普通IO;
|
||||
//@input:
|
||||
// gpio: 需要取消输入外设信号的IO口;
|
||||
// signal: 需要取消输入的外设信号, 外设信号列表请查看gpio.h文件enum INPUT_CH_SIGNAL枚举项;
|
||||
// type: INPUT_CH 类型, 常设为INPUT_CH_TYPE_GP_ICH;
|
||||
//@return: 默认为0, 无出错处理;
|
||||
//@note:
|
||||
//@example: 将外设信号INPUT_CH_SIGNAL_TIMER0_CIN释放由某个IO输入:
|
||||
// gpio_ich_disable_input_signal(IO_PORTA_05, INPUT_CH_SIGNAL_TIMER0_CIN, INPUT_CH_TYPE_GP_ICH);
|
||||
//=================================================================================//
|
||||
int gpio_ich_disable_input_signal(u32 gpio, enum INPUT_CH_SIGNAL signal, enum INPUT_CH_TYPE type);
|
||||
|
||||
#endif /*GPIO_H*/
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
|
||||
//===============================================================================//
|
||||
//
|
||||
// input IO define
|
||||
//
|
||||
//===============================================================================//
|
||||
#define PA0_IN 1
|
||||
#define PA1_IN 2
|
||||
#define PA2_IN 3
|
||||
#define PA3_IN 4
|
||||
#define PA4_IN 5
|
||||
#define PA5_IN 6
|
||||
#define PA6_IN 7
|
||||
#define PA7_IN 8
|
||||
#define PA8_IN 9
|
||||
#define PA9_IN 10
|
||||
#define PA10_IN 11
|
||||
#define PA11_IN 12
|
||||
#define PA12_IN 13
|
||||
#define PA13_IN 14
|
||||
#define PB0_IN 15
|
||||
#define PB1_IN 16
|
||||
#define PB2_IN 17
|
||||
#define PB3_IN 18
|
||||
#define PB4_IN 19
|
||||
#define PB5_IN 20
|
||||
#define PB6_IN 21
|
||||
#define PB7_IN 22
|
||||
#define PB8_IN 23
|
||||
#define PC0_IN 24
|
||||
#define PC1_IN 25
|
||||
#define PC2_IN 26
|
||||
#define PC3_IN 27
|
||||
#define PC4_IN 28
|
||||
#define PC5_IN 29
|
||||
#define PC6_IN 30
|
||||
#define PC7_IN 31
|
||||
#define PC8_IN 32
|
||||
#define PC9_IN 33
|
||||
#define PC10_IN 34
|
||||
#define PC11_IN 35
|
||||
#define USBDP_IN 36
|
||||
#define USBDM_IN 37
|
||||
#define PP0_IN 38
|
||||
|
||||
//===============================================================================//
|
||||
//
|
||||
// function input select sfr
|
||||
//
|
||||
//===============================================================================//
|
||||
typedef struct {
|
||||
__RW __u8 FI_GP_ICH0;
|
||||
__RW __u8 FI_GP_ICH1;
|
||||
__RW __u8 FI_GP_ICH2;
|
||||
__RW __u8 FI_GP_ICH3;
|
||||
__RW __u8 FI_GP_ICH4;
|
||||
__RW __u8 FI_GP_ICH5;
|
||||
__RW __u8 FI_SD0_CMD;
|
||||
__RW __u8 FI_SD0_DA0;
|
||||
__RW __u8 FI_SD0_DA1;
|
||||
__RW __u8 FI_SD0_DA2;
|
||||
__RW __u8 FI_SD0_DA3;
|
||||
__RW __u8 FI_SPI1_CLK;
|
||||
__RW __u8 FI_SPI1_DA0;
|
||||
__RW __u8 FI_SPI1_DA1;
|
||||
__RW __u8 FI_SPI1_DA2;
|
||||
__RW __u8 FI_SPI1_DA3;
|
||||
__RW __u8 FI_SPI2_CLK;
|
||||
__RW __u8 FI_SPI2_DA0;
|
||||
__RW __u8 FI_SPI2_DA1;
|
||||
__RW __u8 FI_SPI2_DA2;
|
||||
__RW __u8 FI_SPI2_DA3;
|
||||
__RW __u8 FI_IIC0_SCL;
|
||||
__RW __u8 FI_IIC0_SDA;
|
||||
__RW __u8 FI_UART0_RX;
|
||||
__RW __u8 FI_UART1_RX;
|
||||
__RW __u8 FI_UART2_RX;
|
||||
__RW __u8 FI_QDEC0_A;
|
||||
__RW __u8 FI_QDEC0_B;
|
||||
__RW __u8 FI_CHAIN_IN0;
|
||||
__RW __u8 FI_CHAIN_IN1;
|
||||
__RW __u8 FI_CHAIN_IN2;
|
||||
__RW __u8 FI_CHAIN_IN3;
|
||||
__RW __u8 FI_CHAIN_RST;
|
||||
__RW __u8 FI_TOTAL;
|
||||
} JL_IMAP_TypeDef;
|
||||
|
||||
#define JL_IMAP_BASE (ls_base + map_adr(0x3a, 0x00))
|
||||
#define JL_IMAP ((JL_IMAP_TypeDef *)JL_IMAP_BASE)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
|
||||
//===============================================================================//
|
||||
//
|
||||
// output function define
|
||||
//
|
||||
//===============================================================================//
|
||||
#define FO_GP_OCH0 ((0 << 2)|BIT(1))
|
||||
#define FO_GP_OCH1 ((1 << 2)|BIT(1))
|
||||
#define FO_GP_OCH2 ((2 << 2)|BIT(1))
|
||||
#define FO_GP_OCH3 ((3 << 2)|BIT(1))
|
||||
#define FO_GP_OCH4 ((4 << 2)|BIT(1))
|
||||
#define FO_GP_OCH5 ((5 << 2)|BIT(1))
|
||||
#define FO_GP_OCH6 ((6 << 2)|BIT(1))
|
||||
#define FO_GP_OCH7 ((7 << 2)|BIT(1))
|
||||
#define FO_SD0_CLK ((8 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SD0_CMD ((9 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SD0_DA0 ((10 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SD0_DA1 ((11 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SD0_DA2 ((12 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SD0_DA3 ((13 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI1_CLK ((14 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI1_DA0 ((15 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI1_DA1 ((16 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI1_DA2 ((17 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI1_DA3 ((18 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI2_CLK ((19 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI2_DA0 ((20 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI2_DA1 ((21 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI2_DA2 ((22 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_SPI2_DA3 ((23 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_IIC0_SCL ((24 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_IIC0_SDA ((25 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_UART0_TX ((26 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_UART1_TX ((27 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_UART2_TX ((28 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_MCPWM0_H ((29 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_MCPWM1_H ((30 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_MCPWM0_L ((31 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_MCPWM1_L ((32 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_CHAIN_OUT0 ((33 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_CHAIN_OUT1 ((34 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_CHAIN_OUT2 ((35 << 2)|BIT(1)|BIT(0))
|
||||
#define FO_CHAIN_OUT3 ((36 << 2)|BIT(1)|BIT(0))
|
||||
|
||||
//===============================================================================//
|
||||
//
|
||||
// IO output select sfr
|
||||
//
|
||||
//===============================================================================//
|
||||
typedef struct {
|
||||
__RW __u8 PA0_OUT;
|
||||
__RW __u8 PA1_OUT;
|
||||
__RW __u8 PA2_OUT;
|
||||
__RW __u8 PA3_OUT;
|
||||
__RW __u8 PA4_OUT;
|
||||
__RW __u8 PA5_OUT;
|
||||
__RW __u8 PA6_OUT;
|
||||
__RW __u8 PA7_OUT;
|
||||
__RW __u8 PA8_OUT;
|
||||
__RW __u8 PA9_OUT;
|
||||
__RW __u8 PA10_OUT;
|
||||
__RW __u8 PA11_OUT;
|
||||
__RW __u8 PA12_OUT;
|
||||
__RW __u8 PA13_OUT;
|
||||
__RW __u8 PB0_OUT;
|
||||
__RW __u8 PB1_OUT;
|
||||
__RW __u8 PB2_OUT;
|
||||
__RW __u8 PB3_OUT;
|
||||
__RW __u8 PB4_OUT;
|
||||
__RW __u8 PB5_OUT;
|
||||
__RW __u8 PB6_OUT;
|
||||
__RW __u8 PB7_OUT;
|
||||
__RW __u8 PB8_OUT;
|
||||
__RW __u8 PC0_OUT;
|
||||
__RW __u8 PC1_OUT;
|
||||
__RW __u8 PC2_OUT;
|
||||
__RW __u8 PC3_OUT;
|
||||
__RW __u8 PC4_OUT;
|
||||
__RW __u8 PC5_OUT;
|
||||
__RW __u8 PC6_OUT;
|
||||
__RW __u8 PC7_OUT;
|
||||
__RW __u8 PC8_OUT;
|
||||
__RW __u8 PC9_OUT;
|
||||
__RW __u8 PC10_OUT;
|
||||
__RW __u8 PC11_OUT;
|
||||
__RW __u8 USBDP_OUT;
|
||||
__RW __u8 USBDM_OUT;
|
||||
__RW __u8 PP0_OUT;
|
||||
} JL_OMAP_TypeDef;
|
||||
|
||||
#define JL_OMAP_BASE (ls_base + map_adr(0x36, 0x00))
|
||||
#define JL_OMAP ((JL_OMAP_TypeDef *)JL_OMAP_BASE)
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
#ifndef __IRQ_H__
|
||||
#define __IRQ_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
//=================================================
|
||||
#define IRQ_EMUEXCPT_IDX 0
|
||||
#define IRQ_EXCEPTION_IDX 1
|
||||
#define IRQ_SYSCALL_IDX 2
|
||||
#define IRQ_TICK_TMR_IDX 3
|
||||
#define IRQ_TIME0_IDX 4
|
||||
#define IRQ_TIME1_IDX 5
|
||||
#define IRQ_TIME2_IDX 6
|
||||
#define IRQ_UART0_IDX 7
|
||||
#define IRQ_UART1_IDX 8
|
||||
|
||||
#define IRQ_SPI1_IDX 10
|
||||
#define IRQ_IIC0_IDX 11
|
||||
#define IRQ_PORT_IDX 12
|
||||
#define IRQ_GPADC_IDX 13
|
||||
#define IRQ_UART2_IDX 14
|
||||
#define IRQ_LRCT_IDX 15
|
||||
|
||||
#define IRQ_GPCNT0_IDX 16
|
||||
#define IRQ_QDEC0_IDX 17
|
||||
#define IRQ_SD0_IDX 18
|
||||
#define IRQ_USB_SOF_IDX 19
|
||||
#define IRQ_USB_CTRL_IDX 20
|
||||
|
||||
#define IRQ_TIME3_IDX 22
|
||||
#define IRQ_LED_IDX 23
|
||||
#define IRQ_SD0_BRK_IDX 24
|
||||
#define IRQ_MCPWM_TMR_IDX 25
|
||||
#define IRQ_MCPWM_CHX_IDX 26
|
||||
#define IRQ_PMU_TMR0_IDX 27
|
||||
#define IRQ_PMU_TMR1_IDX 28
|
||||
|
||||
#define IRQ_SPI2_IDX 31
|
||||
|
||||
#define IRQ_P33_IDX 33
|
||||
#define IRQ_PINR_IDX 34
|
||||
#define IRQ_PMU_SOFT0_IDX 35
|
||||
#define IRQ_PMU_SOFT1_IDX 36
|
||||
#define IRQ_PMU_SOFT2_IDX 37
|
||||
#define IRQ_PMU_SOFT3_IDX 38
|
||||
|
||||
#define IRQ_PMU_TMR2_IDX 40
|
||||
#define IRQ_PMU_TMR3_IDX 41
|
||||
|
||||
#define IRQ_SRC0_IDX 66
|
||||
#define IRQ_SPI0_IDX 68
|
||||
|
||||
#define IRQ_DCP_IDX 70
|
||||
|
||||
#define IRQ_IMD_IDX 72
|
||||
#define IRQ_JPG_IDX 73
|
||||
#define IRQ_GPU_IDX 74
|
||||
|
||||
#define IRQ_ADC_IDX 88
|
||||
#define IRQ_AUDIO_IDX 89
|
||||
|
||||
#define IRQ_BT_TIMEBASE_IDX 100
|
||||
#define IRQ_BLE_RX_IDX 101
|
||||
#define IRQ_BLE_EVENT_IDX 102
|
||||
#define IRQ_BT_CLKN_IDX 103
|
||||
#define IRQ_BREDR_IDX 104
|
||||
#define IRQ_BT_RXMCH 105
|
||||
#define IRQ_SYNC_IDX 106
|
||||
|
||||
#define IRQ_SOFT0_IDX 120
|
||||
#define IRQ_SOFT1_IDX 121
|
||||
#define IRQ_SOFT2_IDX 122
|
||||
#define IRQ_SOFT3_IDX 123
|
||||
#define IRQ_SOFT4_IDX 124
|
||||
#define IRQ_SOFT5_IDX 125
|
||||
#define IRQ_SOFT6_IDX 126
|
||||
#define IRQ_SOFT7_IDX 127
|
||||
|
||||
#define MAX_IRQ_ENTRY_NUM 128
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern u32 _IRQ_MEM_ADDR[];
|
||||
#define IRQ_MEM_ADDR (_IRQ_MEM_ADDR)
|
||||
|
||||
extern int ISR_BASE;
|
||||
#define ISR_ENTRY (u32)&ISR_BASE
|
||||
|
||||
|
||||
|
||||
void interrupt_init();
|
||||
|
||||
|
||||
//---------------------------------------------//
|
||||
// interrupt cli/sti
|
||||
//---------------------------------------------//
|
||||
static inline int int_cli(void)
|
||||
{
|
||||
int msg;
|
||||
asm volatile("cli %0" : "=r"(msg) :);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static inline void int_sti(int msg)
|
||||
{
|
||||
asm volatile("sti %0" :: "r"(msg));
|
||||
}
|
||||
|
||||
void irq_common_handler(u32 irq_idx);
|
||||
void irq_set_pending(u32 irq_idx);
|
||||
//---------------------------------------------//
|
||||
// low power waiting
|
||||
//---------------------------------------------//
|
||||
__attribute__((always_inline))
|
||||
static inline void lp_waiting(int *ptr, int pnd, int cpd, char inum)
|
||||
{
|
||||
#if 0
|
||||
q32DSP(core_num())->IWKUP_NUM = inum;
|
||||
while (!(*ptr & pnd)) {
|
||||
asm volatile("idle");
|
||||
}
|
||||
*ptr |= cpd;
|
||||
#else
|
||||
int con;
|
||||
q32DSP(core_num())->IWKUP_NUM = inum;
|
||||
asm volatile(
|
||||
" goto 2f \n\t"
|
||||
" 1: \n\t"
|
||||
" idle \n\t"
|
||||
" 2: \n\t"
|
||||
" %0 = [%1] \n\t"
|
||||
" rep 1 { \n\t" // disable_bpu
|
||||
" if((%0 & %2)==0) goto 1b \n\t"
|
||||
" } \n\t"
|
||||
:"=&r"(con)
|
||||
:"r"(ptr), "r"(pnd), "0"(con)
|
||||
:
|
||||
);
|
||||
*ptr = con | cpd;
|
||||
#endif
|
||||
}
|
||||
|
||||
// void irq_unmask_set(u8 index, u8 priority, u8 cpu_id);
|
||||
// bool irq_read(u32 index);
|
||||
|
||||
|
||||
|
||||
void bit_clr_ie(unsigned char index);
|
||||
void bit_set_ie(unsigned char index);
|
||||
void request_irq(u8 index, u8 priority, void (*handler)(void), u8 cpu_id);
|
||||
void unrequest_irq(u8 index);
|
||||
|
||||
void HWI_Install(unsigned int index, unsigned int isr, unsigned int priority);
|
||||
void reg_set_ip(unsigned char index, unsigned char priority, u8 cpu_id);
|
||||
void irq_init();
|
||||
void irq_set_pending(u32 irq_idx);
|
||||
void irq_common_handler(u32 irq_idx);
|
||||
|
||||
|
||||
void ENABLE_INT(void);
|
||||
#define enable_int ENABLE_INT
|
||||
|
||||
void DISABLE_INT(void);
|
||||
#define disable_int DISABLE_INT
|
||||
|
||||
void local_irq_disable();
|
||||
|
||||
void local_irq_enable();
|
||||
|
||||
|
||||
#ifdef IRQ_TIME_COUNT_EN
|
||||
|
||||
void irq_handler_enter(int irq);
|
||||
void irq_handler_exit(int irq);
|
||||
void irq_handler_times_dump();
|
||||
|
||||
#else
|
||||
|
||||
#define irq_handler_enter(irq) do { }while(0)
|
||||
#define irq_handler_exit(irq) do { }while(0)
|
||||
#define irq_handler_times_dump() do { }while(0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __MASK_API_H__
|
||||
#define __MASK_API_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#include "maskrom.h"
|
||||
|
||||
void exception_analyze(u32 *sp);
|
||||
|
||||
static void mask_api_init(void *pchar, void *exp_hook)
|
||||
{
|
||||
struct maskrom_argv table;
|
||||
memset((void *)&table, 0, sizeof(struct maskrom_argv));
|
||||
table.exp_hook = exp_hook;
|
||||
table.pchar = pchar;
|
||||
mask_init(&table);
|
||||
}
|
||||
|
||||
#endif /*MASK_API_H*/
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef __MASKROM_H__
|
||||
#define __MASKROM_H__
|
||||
|
||||
struct os_argv_table {
|
||||
void *f;
|
||||
void *m;
|
||||
void *stack_free;
|
||||
void *stack_malloc;
|
||||
void *log_e;
|
||||
void *enter_critical;
|
||||
void *exit_critical;
|
||||
void *get_ms;
|
||||
void *cpu_task_sw;
|
||||
int (*cpu_irq_disabled)(void);
|
||||
void *jiffies_addr;
|
||||
void *jiffies_unit_addr;
|
||||
void *task_info_update_runtime;
|
||||
|
||||
struct xbuf_lock_api {
|
||||
void *lock_init;
|
||||
void *lock;
|
||||
void *unlock;
|
||||
} lock;
|
||||
|
||||
};
|
||||
|
||||
struct maskrom_argv {
|
||||
void (*pchar)(char);
|
||||
void (*exp_hook)(u32 *);
|
||||
void (*local_irq_enable)();
|
||||
void (*local_irq_disable)();
|
||||
|
||||
char *(*flt)(char **str, char *end, double num, int size, int precision, char fmt, int flags);
|
||||
struct os_argv_table os_argv;
|
||||
};
|
||||
|
||||
void mask_init(const struct maskrom_argv *argv);
|
||||
|
||||
#endif /*MASKROM_H*/
|
||||
@@ -0,0 +1,209 @@
|
||||
__local_irq_enable = ABSOLUTE(0xffd5c);
|
||||
__local_irq_disable = ABSOLUTE(0xffd60);
|
||||
request_irq = ABSOLUTE(0xffd64);
|
||||
lp_signature_set = ABSOLUTE(0xffd68);
|
||||
memcpy = ABSOLUTE(0xffd6c);
|
||||
memmove = ABSOLUTE(0xffd70);
|
||||
memcmp = ABSOLUTE(0xffd74);
|
||||
memset = ABSOLUTE(0xffd78);
|
||||
memchr = ABSOLUTE(0xffd7c);
|
||||
strcmp = ABSOLUTE(0xffd80);
|
||||
strcpy = ABSOLUTE(0xffd84);
|
||||
strncpy = ABSOLUTE(0xffd88);
|
||||
strlen = ABSOLUTE(0xffd8c);
|
||||
strncmp = ABSOLUTE(0xffd90);
|
||||
strstr = ABSOLUTE(0xffd94);
|
||||
strchr = ABSOLUTE(0xffd98);
|
||||
strrchr = ABSOLUTE(0xffd9c);
|
||||
strcat = ABSOLUTE(0xffda0);
|
||||
__divdi3 = ABSOLUTE(0xffda4);
|
||||
__umoddi3 = ABSOLUTE(0xffda8);
|
||||
__muldi3 = ABSOLUTE(0xffdac);
|
||||
__udivdi3 = ABSOLUTE(0xffdb0);
|
||||
__udivmoddi4 = ABSOLUTE(0xffdb4);
|
||||
ic_pll_init = ABSOLUTE(0xffdb8);
|
||||
sfc_suspend = ABSOLUTE(0xffdbc);
|
||||
sfc_resume = ABSOLUTE(0xffdc0);
|
||||
sfc_drop_cache = ABSOLUTE(0xffdc4);
|
||||
sfc_boot = ABSOLUTE(0xffdc8);
|
||||
sfc_entry_continue_mode = ABSOLUTE(0xffdcc);
|
||||
ota_jump_mode = ABSOLUTE(0xffdd0);
|
||||
DcuInitial = ABSOLUTE(0xffdd4);
|
||||
DcuFlushinvAll = ABSOLUTE(0xffdd8);
|
||||
DcuWaitIdle = ABSOLUTE(0xffddc);
|
||||
IcuInitial = ABSOLUTE(0xffde0);
|
||||
IcuFlushinvAll = ABSOLUTE(0xffde4);
|
||||
IcuWaitIdle = ABSOLUTE(0xffde8);
|
||||
DcuEnable = ABSOLUTE(0xffdec);
|
||||
DcuFlushRegion = ABSOLUTE(0xffdf0);
|
||||
chip_crc16 = ABSOLUTE(0xffdf4);
|
||||
CrcDecode = ABSOLUTE(0xffdf8);
|
||||
mask_init = ABSOLUTE(0xffdfc);
|
||||
wdt_clear = ABSOLUTE(0xffe00);
|
||||
nvram_set_boot_state = ABSOLUTE(0xffe04);
|
||||
chip_reset = ABSOLUTE(0xffe08);
|
||||
flash_poweron = ABSOLUTE(0xffe0c);
|
||||
flash_poweron_base = ABSOLUTE(0xffe10);
|
||||
flash_poweroff = ABSOLUTE(0xffe14);
|
||||
flash_poweroff_base = ABSOLUTE(0xffe18);
|
||||
spi_io_mount = ABSOLUTE(0xffe1c);
|
||||
spi_io_unmount = ABSOLUTE(0xffe20);
|
||||
get_sfc_read_mode = ABSOLUTE(0xffe24);
|
||||
spi_port_io_init = ABSOLUTE(0xffe28);
|
||||
spi_port_io_uninit = ABSOLUTE(0xffe2c);
|
||||
usb_slave_mode = ABSOLUTE(0xffe30);
|
||||
uart_set_dma_dir = ABSOLUTE(0xffe34);
|
||||
doe = ABSOLUTE(0xffe38);
|
||||
LZ4_setStreamDecode = ABSOLUTE(0xffe3c);
|
||||
LZ4_decompress_safe_continue = ABSOLUTE(0xffe40);
|
||||
LZ4_decompress_generic = ABSOLUTE(0xffe44);
|
||||
LZ4_decompress_safe_usingDict = ABSOLUTE(0xffe48);
|
||||
dec_isd_cfg_ini = ABSOLUTE(0xffe4c);
|
||||
rom_nand_flash_get_features = ABSOLUTE(0xffe50);
|
||||
rom_nand_flash_set_features = ABSOLUTE(0xffe54);
|
||||
pcTaskName = ABSOLUTE(0xffe58);
|
||||
uxTaskStack = ABSOLUTE(0xffe5c);
|
||||
uxTaskStackDepth = ABSOLUTE(0xffe60);
|
||||
OSCtxSw2 = ABSOLUTE(0xffe64);
|
||||
OSCtxSw = ABSOLUTE(0xffe68);
|
||||
os_init = ABSOLUTE(0xffe6c);
|
||||
os_current_task_prio = ABSOLUTE(0xffe70);
|
||||
os_current_task_stask_size = ABSOLUTE(0xffe74);
|
||||
os_time_get = ABSOLUTE(0xffe78);
|
||||
os_task_create_static = ABSOLUTE(0xffe7c);
|
||||
os_task_coreaffinityset = ABSOLUTE(0xffe80);
|
||||
os_task_create_affinity_core = ABSOLUTE(0xffe84);
|
||||
os_task_create = ABSOLUTE(0xffe88);
|
||||
os_time_dly = ABSOLUTE(0xffe8c);
|
||||
os_task_del_req = ABSOLUTE(0xffe90);
|
||||
os_task_del_res = ABSOLUTE(0xffe94);
|
||||
os_task_del = ABSOLUTE(0xffe98);
|
||||
os_taskq_post = ABSOLUTE(0xffe9c);
|
||||
os_taskq_accept = ABSOLUTE(0xffea0);
|
||||
__os_taskq_pend = ABSOLUTE(0xffea4);
|
||||
os_sem_create = ABSOLUTE(0xffea8);
|
||||
os_sem_del = ABSOLUTE(0xffeac);
|
||||
os_sem_pend = ABSOLUTE(0xffeb0);
|
||||
os_sem_post = ABSOLUTE(0xffeb4);
|
||||
os_sem_set = ABSOLUTE(0xffeb8);
|
||||
os_sem_query = ABSOLUTE(0xffebc);
|
||||
os_sem_valid = ABSOLUTE(0xffec0);
|
||||
os_mutex_create = ABSOLUTE(0xffec4);
|
||||
os_mutex_del = ABSOLUTE(0xffec8);
|
||||
os_mutex_pend = ABSOLUTE(0xffecc);
|
||||
os_mutex_post = ABSOLUTE(0xffed0);
|
||||
os_mutex_valid = ABSOLUTE(0xffed4);
|
||||
os_q_create = ABSOLUTE(0xffed8);
|
||||
os_q_del = ABSOLUTE(0xffedc);
|
||||
os_q_flush = ABSOLUTE(0xffee0);
|
||||
os_taskq_flush = ABSOLUTE(0xffee4);
|
||||
os_q_pend = ABSOLUTE(0xffee8);
|
||||
os_q_recv = ABSOLUTE(0xffeec);
|
||||
os_q_peek = ABSOLUTE(0xffef0);
|
||||
os_q_post = ABSOLUTE(0xffef4);
|
||||
os_q_post_to_back = ABSOLUTE(0xffef8);
|
||||
os_q_post_to_front = ABSOLUTE(0xffefc);
|
||||
os_q_query = ABSOLUTE(0xfff00);
|
||||
os_q_valid = ABSOLUTE(0xfff04);
|
||||
os_task_get_handle = ABSOLUTE(0xfff08);
|
||||
OSInit = ABSOLUTE(0xfff0c);
|
||||
OSSchedLock = ABSOLUTE(0xfff10);
|
||||
OSSchedUnlock = ABSOLUTE(0xfff14);
|
||||
OSIdleOtherCore = ABSOLUTE(0xfff18);
|
||||
OSResumOtherCore = ABSOLUTE(0xfff1c);
|
||||
os_time_tick = ABSOLUTE(0xfff20);
|
||||
OS_SchedRoundRobin = ABSOLUTE(0xfff24);
|
||||
OS_EventTaskRdy = ABSOLUTE(0xfff28);
|
||||
OS_EventTaskWait = ABSOLUTE(0xfff2c);
|
||||
OS_EventTO = ABSOLUTE(0xfff30);
|
||||
OS_Sched = ABSOLUTE(0xfff34);
|
||||
OSUpdateIdleTime = ABSOLUTE(0xfff38);
|
||||
prvGetExpectedIdleTime = ABSOLUTE(0xfff3c);
|
||||
os_taskq_post_msg = ABSOLUTE(0xfff40);
|
||||
os_taskq_post_event = ABSOLUTE(0xfff44);
|
||||
os_taskq_post_type = ABSOLUTE(0xfff48);
|
||||
task_queue_post_event = ABSOLUTE(0xfff4c);
|
||||
task_queue_post_msg = ABSOLUTE(0xfff50);
|
||||
task_queue_post = ABSOLUTE(0xfff54);
|
||||
OSTaskQFlush = ABSOLUTE(0xfff58);
|
||||
__OSTaskQFlushMsg = ABSOLUTE(0xfff5c);
|
||||
os_taskq_pend = ABSOLUTE(0xfff60);
|
||||
os_taskq_pend_timeout = ABSOLUTE(0xfff64);
|
||||
os_current_task_rom = ABSOLUTE(0xfff68);
|
||||
OSTimeDly = ABSOLUTE(0xfff6c);
|
||||
OSTimeDlyResume = ABSOLUTE(0xfff70);
|
||||
OSTimeGet = ABSOLUTE(0xfff74);
|
||||
OSTimeSet = ABSOLUTE(0xfff78);
|
||||
OSTCBCur = ABSOLUTE(0x100328);
|
||||
OSRunning = ABSOLUTE(0x100320);
|
||||
OSRdyTbl = ABSOLUTE(0x10031c);
|
||||
OSIdleCtr = ABSOLUTE(0x100318);
|
||||
OSTCBHighRdy = ABSOLUTE(0x100324);
|
||||
OSTCBPrioTbl = ABSOLUTE(0x10032c);
|
||||
idle_tcb = ABSOLUTE(0x100430);
|
||||
OSLockNesting = ABSOLUTE(0x100314);
|
||||
OSNextTaskUnblockTime = ABSOLUTE(0x10042c);
|
||||
cpu1_run_flag = ABSOLUTE(0x10048c);
|
||||
OS_Affinity_Enable = ABSOLUTE(0x1002d2);
|
||||
MASK_CONFIG_CPU_UNMASK_IRQ_ENABLE = ABSOLUTE(0x1002d0);
|
||||
OS_Sw_Sf_Irq_Num = ABSOLUTE(0x1002d1);
|
||||
OSTaskCreate = ABSOLUTE(0xfff7c);
|
||||
os_taskq_del_type = ABSOLUTE(0xfff80);
|
||||
pmalloc_init = ABSOLUTE(0xfff84);
|
||||
pmalloc = ABSOLUTE(0xfff88);
|
||||
pfree = ABSOLUTE(0xfff8c);
|
||||
pmalloc_get_unused_pages = ABSOLUTE(0xfff90);
|
||||
get_physic_address = ABSOLUTE(0xfff94);
|
||||
pmalloc_get_hdl = ABSOLUTE(0xfff98);
|
||||
vmm_init_ = ABSOLUTE(0xfff9c);
|
||||
vmalloc_ = ABSOLUTE(0xfffa0);
|
||||
vfree_ = ABSOLUTE(0xfffa4);
|
||||
vmem_get_phy_adr = ABSOLUTE(0xfffa8);
|
||||
vmem_start = ABSOLUTE(0xfffac);
|
||||
vmem_end = ABSOLUTE(0xfffb0);
|
||||
vmalloc_get_hdl = ABSOLUTE(0xfffb4);
|
||||
vmalloc_v2 = ABSOLUTE(0xfffb8);
|
||||
vfree_v2 = ABSOLUTE(0xfffbc);
|
||||
vcopy_ = ABSOLUTE(0xfffc0);
|
||||
lock_vir_mem = ABSOLUTE(0xfffc4);
|
||||
unlock_vir_mem = ABSOLUTE(0xfffc8);
|
||||
hw_mmu_disable = ABSOLUTE(0xfffcc);
|
||||
get_sbc_frame_info = ABSOLUTE(0xfffd0);
|
||||
get_sbc_dec_ops = ABSOLUTE(0xfffd4);
|
||||
sbc_dec_loop_u = ABSOLUTE(0xfffd8);
|
||||
sbc_unpack_frame_u = ABSOLUTE(0xfffdc);
|
||||
sbc_synthesize_audio_u = ABSOLUTE(0xfffe0);
|
||||
sbc_oput_deal_normal = ABSOLUTE(0xfffe4);
|
||||
sbc_oput_deal_To_ch2 = ABSOLUTE(0xfffe8);
|
||||
sbc_bit_offset4 = ABSOLUTE(0xf88c0);
|
||||
sbc_bit_offset8 = ABSOLUTE(0xf8900);
|
||||
sbc_proto4_m0 = ABSOLUTE(0xf8980);
|
||||
sbc_proto4_m1 = ABSOLUTE(0xf89d0);
|
||||
sbc_proto8_m0 = ABSOLUTE(0xf8a20);
|
||||
sbc_proto8_m1 = ABSOLUTE(0xf8ac0);
|
||||
syn_matrix4 = ABSOLUTE(0xf8b60);
|
||||
syn_matrix8 = ABSOLUTE(0xf8be0);
|
||||
crc8_table = ABSOLUTE(0xf87c0);
|
||||
sbc_div_new_table = ABSOLUTE(0xf8de0);
|
||||
need_fix_iir_filter_buf = ABSOLUTE(0xfffec);
|
||||
fix_iir_filter_init = ABSOLUTE(0xffff0);
|
||||
fix_iir_filter_update = ABSOLUTE(0xffff4);
|
||||
fix_iir_filter_run = ABSOLUTE(0xffff8);
|
||||
fix_iir_filter_clear_mem = ABSOLUTE(0xffffc);
|
||||
_SFC_MEMORY_START_ADDR = ABSOLUTE(0xc000000);
|
||||
_IRQ_MEM_ADDR = ABSOLUTE(0x100000);
|
||||
_RAM_LIMIT_L = ABSOLUTE(0x100000);
|
||||
_RAM_LIMIT_H = ABSOLUTE(0x137000);
|
||||
_MASK_USED_MEM_END = ABSOLUTE(0x101310);
|
||||
_MASK_EXPORT_MEM_BEGIN = ABSOLUTE(0x100200);
|
||||
_MASK_EXPORT_MEM_SIZE = ABSOLUTE(0x34c);
|
||||
_UBOOT_LOADER_RAM_START = ABSOLUTE(0x102600);
|
||||
_UBOOT_LOADER_RAM_END = ABSOLUTE(0x137000);
|
||||
_UBOOT_LOADER_RAM_SIZE = ABSOLUTE(0x34a00);
|
||||
g_boot_soft_flag = ABSOLUTE(0x100204);
|
||||
irq_lock_cnt = ABSOLUTE(0x1002b8);
|
||||
efuse_page0 = ABSOLUTE(0x1002ac);
|
||||
efuse_page1 = ABSOLUTE(0x1002b0);
|
||||
efuse_page2 = ABSOLUTE(0x1002b4);
|
||||
nvram_list = ABSOLUTE(0x100214);
|
||||
/* exception_irq_handler = ABSOLUTE(0xf8004); */
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef __P33_H__
|
||||
#define __P33_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#include "p33_sfr.h"
|
||||
|
||||
#include "p33_app.h"
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// lvd
|
||||
//
|
||||
//
|
||||
//
|
||||
/****************************************************************/
|
||||
typedef enum {
|
||||
LVD_RESET_MODE, //复位模式
|
||||
LVD_EXCEPTION_MODE, //异常模式,进入异常中断
|
||||
LVD_WAKEUP_MODE, //唤醒模式,进入唤醒中断,callback参数为回调函数
|
||||
} LVD_MODE;
|
||||
|
||||
typedef enum {
|
||||
VLVD_SEL_166V = 0,
|
||||
VLVD_SEL_177V,
|
||||
VLVD_SEL_188V,
|
||||
VLVD_SEL_199V,
|
||||
VLVD_SEL_210V,
|
||||
VLVD_SEL_221V,
|
||||
VLVD_SEL_232V,
|
||||
VLVD_SEL_243V,
|
||||
VLVD_SEL_254V,
|
||||
VLVD_SEL_265V,
|
||||
VLVD_SEL_276V,
|
||||
VLVD_SEL_287V,
|
||||
VLVD_SEL_298V,
|
||||
VLVD_SEL_309V,
|
||||
VLVD_SEL_320V,
|
||||
VLVD_SEL_331V,
|
||||
} LVD_VOL;
|
||||
|
||||
void lvd_config(LVD_VOL vol, u8 expin_en, LVD_MODE mode, void (*callback));
|
||||
void reset_pin_open(void);
|
||||
void reset_pin_close(void);
|
||||
void reset_pin_init(u32 pin, u32 level, u32 time);
|
||||
void reset_pin1_init(u32 pin, u32 level, u32 time);
|
||||
|
||||
void chip_reset();
|
||||
|
||||
void set_vddio_level(u8 level);
|
||||
|
||||
void set_dvdd_leve(u8 level);
|
||||
|
||||
void set_dcvdd_leve(u8 level);
|
||||
|
||||
void p33_soft_reset(void);
|
||||
|
||||
void latch_reset(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,825 @@
|
||||
#ifndef __P33_APP_H__
|
||||
#define __P33_APP_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#include "p33_sfr.h"
|
||||
|
||||
|
||||
//=============================================================//
|
||||
// P33 SFR //
|
||||
//=============================================================//
|
||||
|
||||
//ROM
|
||||
u8 p33_buf(u8 buf);
|
||||
|
||||
#define p33_xor_1byte(addr, data0) (*((volatile u8 *)&addr + 0x300*4) = data0); asm volatile ("csync")
|
||||
//#define p33_xor_1byte(addr, data0) (*((volatile u8 *)&addr + 0x300*4) = data0)
|
||||
// #define p33_xor_1byte(addr, data0) addr ^= (data0)
|
||||
|
||||
#define p33_or_1byte(addr, data0) (*((volatile u8 *)&addr + 0x200*4) = data0); asm volatile ("csync")
|
||||
//#define p33_or_1byte(addr, data0) (*((volatile u8 *)&addr + 0x200*4) = data0)
|
||||
// #define p33_or_1byte(addr, data0) addr |= (data0)
|
||||
|
||||
#define p33_and_1byte(addr, data0) (*((volatile u8 *)&addr + 0x100*4) = (data0)); asm volatile ("csync")
|
||||
//#define p33_and_1byte(addr, data0) (*((volatile u8 *)&addr + 0x100*4) = (data0))
|
||||
//#define p33_and_1byte(addr, data0) addr &= (data0)
|
||||
|
||||
// void p33_tx_1byte(u16 addr, u8 data0);
|
||||
#define p33_tx_1byte(addr, data0) addr = data0
|
||||
|
||||
// u8 p33_rx_1byte(u16 addr);
|
||||
#define p33_rx_1byte(addr) addr
|
||||
|
||||
#define P33_CON_SET(sfr, start, len, data) (sfr = (sfr & ~((~(0xffffffff << (len))) << (start))) | \
|
||||
(((data) & (~(0xffffffff << (len)))) << (start)))
|
||||
|
||||
#define P33_CON_GET(sfr) (sfr)
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
#define p33_fast_access(reg, data, en) \
|
||||
{ \
|
||||
if (en) { \
|
||||
p33_or_1byte(reg, (data)); \
|
||||
} else { \
|
||||
p33_and_1byte(reg, ~(data)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define p33_fast_access(reg, data, en) \
|
||||
{ \
|
||||
if (en) { \
|
||||
reg |= (data); \
|
||||
} else { \
|
||||
reg &= ~(data); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// for p33_analog
|
||||
//
|
||||
//
|
||||
//
|
||||
/************************P3_PSW_CON0*****************************/
|
||||
#define DVD2SVD_SHORT_EN(en) p33_fast_access(P3_PSW_CON0, BIT(6), en)
|
||||
|
||||
#define SVD2RVD2_SHORT_EN(en) p33_fast_access(P3_PSW_CON0, BIT(5), en)
|
||||
|
||||
#define SVD2RVD_SHORT_EN(en) p33_fast_access(P3_PSW_CON0, BIT(4), en)
|
||||
#define RVDD2_CAP_EN(en) p33_fast_access(P3_PSW_CON0, BIT(3), en)
|
||||
#define RVD2_EN(en) p33_fast_access(P3_PSW_CON0, BIT(2), en)
|
||||
|
||||
#define RVDD_CAP_EN(en) p33_fast_access(P3_PSW_CON0, BIT(1), en)
|
||||
|
||||
#define RVD_EN(en) p33_fast_access(P3_PSW_CON0, BIT(0), en)
|
||||
|
||||
#define NVD2IO_SHORT_EN(en) p33_fast_access(P3_PSW_CON1, BIT(7), en)
|
||||
|
||||
#define DVDD2_IFULL_EN(en) p33_fast_access(P3_PSW_CON1, BIT(6), en)
|
||||
#define DVDD2_BYPASS_EN(en) p33_fast_access(P3_PSW_CON1, BIT(5), en)
|
||||
#define DVDD2_EN(en) p33_fast_access(P3_PSW_CON1, BIT(4), en)
|
||||
|
||||
#define RVDD2_BYPASS_EN(en) p33_fast_access(P3_PSW_CON1, BIT(3), en)
|
||||
|
||||
#define RVDD_BYPASS_EN(en) p33_fast_access(P3_PSW_CON1, BIT(2), en)
|
||||
#define WVD2SVD_SHORT_EN(en) p33_fast_access(P3_PSW_CON1, BIT(1), en)
|
||||
#define WVDD_EN(en) p33_fast_access(P3_PSW_CON1, BIT(0), en)
|
||||
#define WVDD_PDOWN_ENTER() P33_CON_SET(P3_PSW_CON1, 0, 2, 0x03); P33_CON_SET(P3_PSW_CON0, 4, 3, 0x7)
|
||||
|
||||
#define WVDD_POFF_ENTER() P33_CON_SET(P3_PSW_CON1, 0, 2, 0x03); P33_CON_SET(P3_PSW_CON0, 4, 3, 0x1)
|
||||
|
||||
#define WVDD_PDOWN_POFF_EXIT() P33_CON_SET(P3_PSW_CON0, 4, 3, 0x07); P33_CON_SET(P3_PSW_CON1, 1, 1, 0x00)
|
||||
|
||||
/************************P3_PSW_CON2*****************************/
|
||||
//SS: soft start of VPQS
|
||||
#define VQPS_SS_EN(en) p33_fast_access(P3_PSW_CON2, BIT(1), en)
|
||||
|
||||
#define VQPS_EN(en) p33_fast_access(P3_PSW_CON2, BIT(0), en)
|
||||
|
||||
/************************P3_ANA_CON*****************************/
|
||||
//#define EVDD_IFULL_EN(en) p33_fast_access(P3_ANA_CON, BIT(0), en)
|
||||
|
||||
//DS: decrease undershoot and overshoot
|
||||
//#define DVD_DS_EN(en) p33_fast_access(P3_ANA_CON, BIT(1), en)
|
||||
|
||||
//#define RVD_DS_EN(en) p33_fast_access(P3_ANA_CON, BIT(2), en)
|
||||
|
||||
/************************P3_PMU_ADC0*****************************/
|
||||
enum {
|
||||
VBG_TEST_SEL_WBG04,
|
||||
VBG_TEST_SEL_MBG04,
|
||||
VBG_TEST_SEL_MBG08,
|
||||
VBG_TEST_SEL_LVDBG,
|
||||
};
|
||||
#define VBG_TEST_SEL(sel) P33_CON_SET(P3_PMU_ADC0, 4, 2, sel)
|
||||
|
||||
#define VBG_TEST_EN(en) p33_fast_access(P3_PMU_ADC0, BIT(3), en)
|
||||
|
||||
#define VBG_BUFFER_EN(en) p33_fast_access(P3_PMU_ADC0, BIT(2), en)
|
||||
|
||||
#define PMU_TOADC_OE(en) p33_fast_access(P3_PMU_ADC0, BIT(1), en)
|
||||
|
||||
#define PMU_TOADC_EN(en) p33_fast_access(P3_PMU_ADC0, BIT(0), en)
|
||||
|
||||
/************************P3_PMU_ADC1*****************************/
|
||||
#define ADC_CHANNEL_SEL(ch) P33_CON_SET(P3_PMU_ADC1, 0, 4, ch)
|
||||
|
||||
/************************P3_VBG_CON0*****************************/
|
||||
#define MVBG_SEL(sel) P33_CON_SET(P3_VBG_CON0, 0, 4, sel)
|
||||
|
||||
#define WVBG_SEL(sel) P33_CON_SET(P3_VBG_CON0, 4, 4, sel)
|
||||
|
||||
/************************P3_IOV_CON0*****************************/
|
||||
|
||||
#define VDDIOW_VOL_SEL(lev) P33_CON_SET(P3_IOV_CON0, 4, 4, lev)
|
||||
|
||||
#define GET_VDDIOW_VOL_SEL() (P33_CON_GET(P3_IOV_CON0)>>4 & 0xf)
|
||||
|
||||
//vddiom_lev
|
||||
|
||||
#define VDDIOM_VOL_SEL(lev) P33_CON_SET(P3_IOV_CON0, 0, 4, lev)
|
||||
|
||||
#define GET_VDDIOM_VOL_SEL() (P33_CON_GET(P3_IOV_CON0) & 0xf)
|
||||
|
||||
/************************P3_IOV_CON1*****************************/
|
||||
#define VDDIO_HD_SEL(hd) P33_CON_SET(P3_IOV_CON1, 0, 2, hd)
|
||||
|
||||
/************************P3_DCV_CON0*****************************/
|
||||
#define DCVD_DEOVSHOT_EN(en) p33_fast_access(P3_DCV_CON0, BIT(7), en)
|
||||
|
||||
#define DCVD_CAP_EN(en) p33_fast_access(P3_DCV_CON0, BIT(6), en)
|
||||
|
||||
#define DCVD_HD_SEL(sel) P33_CON_SET(P3_DCV_CON0, 4, 2, sel)
|
||||
|
||||
|
||||
#define DCVDD_DEFAULT_VOL DCVDD_VOL_SEL_120V
|
||||
|
||||
#define GET_DCVDD_VOL_SEL() (P33_CON_GET(P3_DCV_CON0) & 0xf)
|
||||
|
||||
#define DCVDD_VOL_SEL(sel) P33_CON_SET(P3_DCV_CON0, 0, 4, sel)
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
*-------------------P3_DCV_CON0
|
||||
*/
|
||||
enum {
|
||||
DCVDD_VOL_SEL_100V = 0,
|
||||
DCVDD_VOL_SEL_1025V,
|
||||
DCVDD_VOL_SEL_105V,
|
||||
DCVDD_VOL_SEL_1075V,
|
||||
DCVDD_VOL_SEL_110V,
|
||||
DCVDD_VOL_SEL_1125V,
|
||||
DCVDD_VOL_SEL_115V,
|
||||
DCVDD_VOL_SEL_1175V,
|
||||
DCVDD_VOL_SEL_120V,
|
||||
DCVDD_VOL_SEL_1225V,
|
||||
DCVDD_VOL_SEL_125V,
|
||||
DCVDD_VOL_SEL_1275V,
|
||||
DCVDD_VOL_SEL_130V,
|
||||
DCVDD_VOL_SEL_1325V,
|
||||
DCVDD_VOL_SEL_135V,
|
||||
DCVDD_VOL_SEL_1375V,
|
||||
};
|
||||
|
||||
#define DCVD_SEL(sel) P3_DCV_CON0 = (P3_DCV_CON0 & (~0xf)) | sel
|
||||
#define DCVDD_DEFAULT_VOL DCVDD_VOL_SEL_120V
|
||||
|
||||
/************************P3_DCD_CON0*****************************/
|
||||
enum {
|
||||
BTDCDC_OSC_SEL0520KHz = 0,
|
||||
BTDCDC_OSC_SEL0762KHz,
|
||||
BTDCDC_OSC_SEL0997KHz,
|
||||
BTDCDC_OSC_SEL1220KHz,
|
||||
BTDCDC_OSC_SEL1640KHz,
|
||||
BTDCDC_OSC_SEL1840KHz,
|
||||
BTDCDC_OSC_SEL2040KHz,
|
||||
BTDCDC_OSC_SEL2220MHz,
|
||||
};
|
||||
|
||||
#define BTDCDC_OSC_SEL(sel) P33_CON_SET(P3_DCD_CON0, 5, 3, sel)
|
||||
|
||||
#define BTDCDC_DUTY_SEL(sel) P33_CON_SET(P3_DCD_CON0, 3, 2, sel)
|
||||
|
||||
#define BTDCDC_V17_TEST_OE(en) p33_fast_access(P3_DCD_CON0, BIT(2), en);
|
||||
|
||||
#define BTDCDC_RAMP_SHORT(en) p33_fast_access(P3_DCD_CON0, BIT(1), en)
|
||||
|
||||
#define BTDCDC_PFM_MODE(en) p33_fast_access(P3_DCD_CON0, BIT(0), en)
|
||||
|
||||
#define GET_BTDCDC_PFM_MODE() (P33_CON_GET(P3_DCD_CON0) & BIT(0) ? 1 : 0)
|
||||
|
||||
/************************P3_DCD_CON1*****************************/
|
||||
#define BTDCDC_COMP_HD(sel) P33_CON_SET(P3_DCD_CON1, 6, 2, sel)
|
||||
|
||||
#define BTDCDC_ISENSE_HD(sel) P33_CON_SET(P3_DCD_CON1, 4, 2, sel)
|
||||
|
||||
#define BTDCDC_DT_S(sel) P33_CON_SET(P3_DCD_CON1, 2, 2, sel)
|
||||
|
||||
#define BTDCDC_V21_RES_S(sel) P33_CON_SET(P3_DCD_CON1, 0, 2, sel)
|
||||
|
||||
/************************P3_DCD_CON2*****************************/
|
||||
#define BTDCDC_PMOS_S(sel) P33_CON_SET(P3_DCD_CON2, 5, 3, sel)
|
||||
|
||||
#define BTDCDC_NMOS_S(sel) P33_CON_SET(P3_DCD_CON2, 1, 3, sel)
|
||||
|
||||
/************************P3_DCD_CON3*****************************/
|
||||
#define BTDCDC_OSC_TEST_OE(en) p33_fast_access(P3_DCD_CON3, BIT(7), en)
|
||||
|
||||
#define BTDCDC_HD_BIAS_SEL(sel) P33_CON_SET(P3_DCD_CON3, 5, 2, sel)
|
||||
|
||||
#define BTDCDC_CLK_SEL(sel) p33_fast_access(P3_DCD_CON3, BIT(4), sel)
|
||||
|
||||
#define GET_BTDCDC_CLK_SEL() ((P33_CON_GET(P3_DCD_CON3) & BIT(4) ? 1 : 0))
|
||||
|
||||
#define BTDCDC_ZCD_RES(sel) P33_CON_SET(P3_DCD_CON3, 2, 2, sel)
|
||||
|
||||
#define BTDCDC_ZCD_EN(en) p33_fast_access(P3_DCD_CON3, BIT(0), en)
|
||||
|
||||
/************************P3_DCD_CON4*****************************/
|
||||
#define BTDCDC_VHH_SEL(sel) P33_CON_SET(P3_DCD_CON4, 4, 3, sel)
|
||||
|
||||
#define BTDCDC_PFM_HYS_SEL(sel) P33_CON_SET(P3_DCD_CON4, 0, 2, sel)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
*-------------------P3_DVD_CON0
|
||||
*/
|
||||
enum {
|
||||
DVDD_VOL_SEL_0725V = 0,
|
||||
DVDD_VOL_SEL_075V,
|
||||
DVDD_VOL_SEL_0775V,
|
||||
DVDD_VOL_SEL_080V,
|
||||
DVDD_VOL_SEL_0825V,
|
||||
DVDD_VOL_SEL_0850V,
|
||||
DVDD_VOL_SEL_0875V,
|
||||
DVDD_VOL_SEL_090V,
|
||||
DVDD_VOL_SEL_0925V,
|
||||
DVDD_VOL_SEL_0950V,
|
||||
DVDD_VOL_SEL_0975V,
|
||||
DVDD_VOL_SEL_100V,
|
||||
DVDD_VOL_SEL_1025V,
|
||||
DVDD_VOL_SEL_105V,
|
||||
DVDD_VOL_SEL_1075V,
|
||||
DVDD_VOL_SEL_110V,
|
||||
};
|
||||
|
||||
/************************P3_DVD_CON0*****************************/
|
||||
|
||||
#define DVDD_DEFAULT_VOL DVDD_VOL_SEL_090V
|
||||
|
||||
#define DVDD_VOL_SEL(sel) P33_CON_SET(P3_DVD_CON0, 0, 4, sel)
|
||||
|
||||
#define GET_DVDD_VOL_SEL() (P33_CON_GET(P3_DVD_CON0) & 0xf)
|
||||
|
||||
#define DVDD_HD_SEL(sel) P33_CON_SET(P3_DVD_CON0, 4, 2, sel)
|
||||
|
||||
#define DVDD_CAP_EN(en) p33_fast_access(P3_DVD_CON0, BIT(6), en)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
*-------------------P3_RVD_CON0
|
||||
*/
|
||||
enum {
|
||||
RVDD_VOL_SEL_0725V = 0,
|
||||
RVDD_VOL_SEL_075V,
|
||||
RVDD_VOL_SEL_0775V,
|
||||
RVDD_VOL_SEL_080V,
|
||||
RVDD_VOL_SEL_0825V,
|
||||
RVDD_VOL_SEL_0850V,
|
||||
RVDD_VOL_SEL_0875V,
|
||||
RVDD_VOL_SEL_090V,
|
||||
RVDD_VOL_SEL_0925V,
|
||||
RVDD_VOL_SEL_0950V,
|
||||
RVDD_VOL_SEL_0975V,
|
||||
RVDD_VOL_SEL_100V,
|
||||
RVDD_VOL_SEL_1025V,
|
||||
RVDD_VOL_SEL_105V,
|
||||
RVDD_VOL_SEL_1075V,
|
||||
RVDD_VOL_SEL_110V,
|
||||
};
|
||||
|
||||
|
||||
#define RVDD_VOL_SEL(sel) P33_CON_SET(P3_RVD_CON0, 0, 4, sel)
|
||||
|
||||
#define RVDD_DEFAULT_VOL RVDD_VOL_SEL_090V
|
||||
|
||||
#define GET_RVDD_VOL_SEL() (P33_CON_GET(P3_RVD_CON0) & 0xf)
|
||||
|
||||
#define RVDD_HD_SEL(en) P33_CON_SET(P3_RVD_CON0, 4, 2, en)
|
||||
|
||||
/************************P3_RVD_CON1*****************************/
|
||||
#define RVDD_CMP_EN(en) p33_fast_access(P3_RVD_CON1, BIT(4), en)
|
||||
|
||||
#define PVDD_DCDC_LEV_SEL(sel) P33_CON_SET(P3_RVD_CON1, 0, 4, sel)
|
||||
|
||||
#define GET_PVDD_DCDC_LEV_SEL() (P33_CON_GET(P3_RVD_CON1) & 0xf)
|
||||
|
||||
/************************P3_WVD_CON0*****************************/
|
||||
#define WVDD_LOAD_EN(en) p33_fast_access(P3_WVD_CON0, BIT(4), en)
|
||||
|
||||
#define WVDD_VOL_SEL(sel) P33_CON_SET(P3_WVD_CON0, 0, 4, sel)
|
||||
|
||||
|
||||
/************************P3_PVD_CON0*****************************/
|
||||
#define PVD_DEUDSHT_EN(en) p33_fast_access(P3_PVD_CON0, BIT(3), en)
|
||||
|
||||
#define GET_PVD_DEUDST_EN() ((P33_CON_GET(P3_PVD_CON0) & BIT(3)) ? 1:0)
|
||||
|
||||
#define PVDD_HD_SEL(sel) P33_CON_SET(P3_PVD_CON0, 0, 3, sel)
|
||||
|
||||
#define GET_PVDD_HD_SEL() (P33_CON_GET(P3_PVD_CON0) & 0x7)
|
||||
|
||||
/************************P3_EVD_CON0*****************************/
|
||||
enum {
|
||||
EVD_VOL_SEL_100V = 0,
|
||||
EVD_VOL_SEL_105V,
|
||||
EVD_VOL_SEL_110V,
|
||||
EVD_VOL_SEL_115V,
|
||||
};
|
||||
|
||||
#define EVD_CAP_EN(en) p33_fast_access(P3_EVD_CON0, BIT(4), en)
|
||||
|
||||
#define EVD_HD_SEL(sel) P33_CON_SET(P3_EVD_CON0, 2, 2, sel)
|
||||
|
||||
#define EVD_VOL_SEL(sel) P33_CON_SET(P3_EVD_CON0, 0, 2, sel)
|
||||
|
||||
#define RVD_DEUDSHT_EN(en) p33_fast_access(P3_ANA_MFIX, BIT(2), en)
|
||||
#define DVD_DEUDSHT_EN(en) p33_fast_access(P3_ANA_MFIX, BIT(1), en)
|
||||
#define EVD_ILMT_EN(en) p33_fast_access(P3_ANA_MFIX, BIT(0), en)
|
||||
|
||||
/************************P3_CHG_CON0*****************************/
|
||||
#define LRC_Hz_DEFAULT (200 * 1000L)
|
||||
|
||||
#define LRC_CON0_INIT \
|
||||
/* */ (0 << 7) |\
|
||||
/* */ (0 << 6) |\
|
||||
/*RC32K_RPPS_S1_33v */ (1 << 5) |\
|
||||
/*RC32K_RPPS_S0_33v */ (1 << 4) |\
|
||||
/* */ (0 << 3) |\
|
||||
/* */ (0 << 2) |\
|
||||
/*RC32K_RN_TRIM_33v */ (1 << 1) |\
|
||||
/*RC32K_EN_33v */ (1 << 0)
|
||||
|
||||
#define LRC_CON1_INIT \
|
||||
/* */ (0 << 7) |\
|
||||
/*RC32K_CAP_S2_33v */ (0 << 6) |\
|
||||
/*RC32K_CAP_S1_33v */ (1 << 5) |\
|
||||
/*RC32K_CAP_S0_33v */ (1 << 4) |\
|
||||
/* 2bit */ (0 << 2) |\
|
||||
/*RC32K_RNPS_S1_33v */ (1 << 1) |\
|
||||
/*RC32K_RNPS_S0_33v */ (0 << 0)
|
||||
/************************P3_LRC_CON0*****************************/
|
||||
|
||||
#define LRC32K_RPPS_SEL(sel) P33_CON_SET(P3_LRC_CON0, 4, 2, sel)
|
||||
|
||||
#define LRC32K_RN_TRIM(en) p33_fast_access(P3_LRC_CON0, BIT(1), en)
|
||||
|
||||
#define LRC_EN(en) p33_fast_access(P3_LRC_CON0, BIT(0), en);\
|
||||
p33_fast_access(P3_LRC_CON0, BIT(1), en)
|
||||
|
||||
/************************P3_LRC_CON1*****************************/
|
||||
#define LRC32K_CAP_SEL(sel) P33_CON_SET(P3_LRC_CON1, 4, 3, sel)
|
||||
|
||||
#define LRC32K_PNPS_SEL(sel) P33_CON_SET(P3_LRC_CON1, 0, 2, sel)
|
||||
|
||||
#define CLOSE_LRC() p33_tx_1byte(P3_LRC_CON0, 0);\
|
||||
p33_tx_1byte(P3_LRC_CON1, 0)
|
||||
|
||||
/*******************************************************************/
|
||||
/************************P3_VLVD_CON0*****************************/
|
||||
#define VLVD_PND() ((P33_CON_GET(P3_VLVD_CON0) & BIT(7)) ? 1 : 0)
|
||||
|
||||
#define VLVD_PND_CLR() p33_fast_access(P3_VLVD_CON0, BIT(6), 1)
|
||||
|
||||
#define P33_VLVD_PS(en) p33_fast_access(P3_VLVD_CON0, BIT(2), en)
|
||||
|
||||
#define P33_VLVD_OE(en) p33_fast_access(P3_VLVD_CON0, BIT(1), en)
|
||||
|
||||
#define P33_VLVD_EN(en) p33_fast_access(P3_VLVD_CON0, BIT(0), en)
|
||||
|
||||
#define GET_P33_VLVD_EN() ((P33_CON_GET(P3_VLVD_CON0) & BIT(0)) ? 1:0)
|
||||
|
||||
/************************P3_VLVD_FLT*****************************/
|
||||
#define VLVD_FLT(sel) P33_CON_SET(P3_VLVD_FLT, 0, 2, sel);
|
||||
|
||||
/************************P3_RST_CON0*****************************/
|
||||
#define PVDDOK_OE(en) p33_fast_access(P3_RST_CON0, BIT(7), en)
|
||||
|
||||
#define DVDDOK2_OE(en) p33_fast_access(P3_RST_CON0, BIT(6), en)
|
||||
|
||||
#define DVDDOK_OE(en) p33_fast_access(P3_RST_CON0, BIT(5), en)
|
||||
|
||||
#define PPOR_MASK(en) p33_fast_access(P3_RST_CON0, BIT(4), en)
|
||||
|
||||
#define DPOR2_MASK(en) p33_fast_access(P3_RST_CON0, BIT(3), en)
|
||||
|
||||
#define DPOR_MASK(en) p33_fast_access(P3_RST_CON0, BIT(2), en)
|
||||
|
||||
#define P11_TO_P33_RST_MASK(en) p33_fast_access(P3_RST_CON0, BIT(1), en)
|
||||
|
||||
#define FAST_PU_SYS(en) p33_fast_access(P3_RST_CON0, BIT(0), en)
|
||||
|
||||
/************************P3_RST_CON1*****************************/
|
||||
#define IS_VCM_DET_EN() ((P33_CON_GET(P3_RST_CON1) & BIT(0)) ? 1: 0 )
|
||||
#define DVD2_DRST_MASK(en) p33_fast_access(P3_RST_CON1, BIT(5), en)
|
||||
#define DVD_DRST_MASK(en) p33_fast_access(P3_RST_CON1, BIT(4), en)
|
||||
#define VLVD_WKUP_EN(en) p33_fast_access(P3_RST_CON1, BIT(3), en)
|
||||
#define VLVD_RST_EN(en) p33_fast_access(P3_RST_CON1, BIT(2), en)
|
||||
#define VLVD_EXPT_EN(en) p33_fast_access(P3_RST_CON1, BIT(1), en)
|
||||
|
||||
#define VCM_DET_EN(en) p33_fast_access(P3_RST_CON1, BIT(0), en)
|
||||
|
||||
/************************P3_CLK_CON0*****************************/
|
||||
#define RC_250K_EN(a) p33_fast_access(P3_CLK_CON0, BIT(0), a)
|
||||
|
||||
/************************P3_VLD_KEEP*****************************/
|
||||
#define RTC_WKUP_KEEP(a) p33_fast_access(P3_VLD_KEEP, BIT(1), a)
|
||||
|
||||
#define P33_WKUP_P11_EN(a) p33_fast_access(P3_VLD_KEEP, BIT(2), a)
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// for pmu flow
|
||||
//
|
||||
//
|
||||
//
|
||||
/************************P3_P11_CPU*****************************/
|
||||
#define P11_CPU_BRANCH_POWEROFF(en) p33_fast_access(P3_P11_CPU, BIT(1), en)
|
||||
|
||||
#define P11_CPU_RELEASE(en) p33_fast_access(P3_P11_CPU, BIT(0), en)
|
||||
|
||||
/************************P3_LP_CTL*****************************/
|
||||
//控制p11的低功耗
|
||||
#define LP_FLOW_EN(en) p33_fast_access(P3_LP_CTL, BIT(0), en)
|
||||
|
||||
#define LP_FLOW_CPND() p33_fast_access(P3_LP_CTL, BIT(6), 1)
|
||||
|
||||
#define POWER_ON_END() ((P33_CON_GET(P3_LP_CTL) & BIT(5)) ? 1: 0 )
|
||||
|
||||
|
||||
#define MBG_EN_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW0, BIT(7)); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW0, ~BIT(7)); \
|
||||
}
|
||||
|
||||
/************************P3_ANA_FLOW0*****************************/
|
||||
#define DVD_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(0), en)
|
||||
|
||||
|
||||
#define DCVD_TO_DIG_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(0)|BIT(1), en)
|
||||
|
||||
#define DCVD_LDO_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(2), en)
|
||||
|
||||
#define PAVD_LDO_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(3), en)
|
||||
|
||||
#define GET_DCVD_STA() ((P33_CON_GET(P3_ANA_FLOW0) & (BIT(2))) ? 1:0)
|
||||
|
||||
#define GET_PAVD_LDO_EN() ((P33_CON_GET(P3_ANA_FLOW0) & BIT(3)) ? 1:0)
|
||||
|
||||
#define PVDD_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(4), en)
|
||||
|
||||
#define MVIO_VBAT_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(5), en)
|
||||
|
||||
#define MVIO_VPWR_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(6), en)
|
||||
|
||||
#define PW_GATE_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(5)|BIT(6), en)
|
||||
|
||||
#define MBG_EN(en) p33_fast_access(P3_ANA_FLOW0, BIT(7), en)
|
||||
|
||||
#define MVIO_PVDD_MVBG_ONLY() p33_tx_1byte(P3_ANA_FLOW0, BIT(4) | BIT(5) | BIT(6) | BIT(7))
|
||||
|
||||
#define PVDD_MVBG_ONLY() p33_tx_1byte(P3_ANA_FLOW0, BIT(4) | BIT(7))
|
||||
|
||||
#define PVDD_ONLY() p33_tx_1byte(P3_ANA_FLOW0, BIT(4))
|
||||
|
||||
/************************P3_ANA_FLOW1*****************************/
|
||||
#define MIOV_VLMT_EN(en) p33_fast_access(P3_ANA_FLOW1, BIT(4), en)
|
||||
|
||||
#define MIOV_IFULL_EN(en) p33_fast_access(P3_ANA_FLOW1, BIT(3), en)
|
||||
|
||||
#define PAVD_IFULL_EN(en) p33_fast_access(P3_ANA_FLOW1, BIT(2), en)
|
||||
|
||||
#define DCVD_IFULL_EN(en) p33_fast_access(P3_ANA_FLOW1, BIT(1), en)
|
||||
|
||||
|
||||
#define DVD_IFULL_EN(en) p33_fast_access(P3_ANA_FLOW1, BIT(0), en)
|
||||
|
||||
/************************P3_ANA_FLOW2*****************************/
|
||||
#define NVD2PVD_WSHORT_EN(en) p33_fast_access(P3_ANA_FLOW2, BIT(1), en)
|
||||
|
||||
#define NVD2PVD_SHORT_EN(en) p33_fast_access(P3_ANA_FLOW2, BIT(0), en)
|
||||
|
||||
|
||||
/************************P3_NVRAM_PWR*****************************/
|
||||
#define NVRAM_PWR_MODE(sel) P33_CON_SET(P3_NVRAM_PWR, 4, 2, sel)
|
||||
|
||||
|
||||
/************************P3_PVDD0_AUTO*****************************/
|
||||
|
||||
#define PVDD_AUTO_PRD(sel) P33_CON_SET(P3_PVDD0_AUTO, 5, 3, sel);
|
||||
|
||||
#define PVDD_LEVEL_AUTO(en) p33_fast_access(P3_PVDD0_AUTO, BIT(4), en);
|
||||
|
||||
#define PVDD_LEVEL_LOW(sel) P33_CON_SET(P3_PVDD0_AUTO, 0, 4, sel);
|
||||
|
||||
|
||||
/************************P3_PVDD1_AUTO*****************************/
|
||||
#define PVDD_LEVEL_HIGH_NOW(sel) p33_tx_1byte(P3_PVDD1_AUTO, (sel<<4)|sel);
|
||||
|
||||
#define PVDD_LEVEL_HIGH(sel) P33_CON_SET(P3_PVDD1_AUTO, 4, 4, sel)
|
||||
|
||||
#define PVDD_LEVEL_NOW(sel) P33_CON_SET(P3_PVDD1_AUTO, 0, 4, sel)
|
||||
|
||||
#define GET_PVDD_LEVEL_NOW() (P33_CON_GET(P3_PVDD1_AUTO) & 0x0f)
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// for ANA_control
|
||||
//
|
||||
//
|
||||
/////
|
||||
/*******************************************************************/
|
||||
/************************P3_LS_XX*****************************/
|
||||
enum PWR_LAT {
|
||||
DVDDLS_LAT,
|
||||
PVDDLS_LAT,
|
||||
};
|
||||
|
||||
#define DVDDLS_OR_BIT(a) \
|
||||
p33_or_1byte(P3_LS_IO_USR , BIT(a)); \
|
||||
p33_or_1byte(P3_LS_IO_ROM , BIT(a));
|
||||
|
||||
#define SHALS_OR_BIT(a) \
|
||||
p33_or_1byte(P3_LS_IO_SHA , BIT(a)); \
|
||||
p33_or_1byte(P3_LS_IO_PINR , BIT(a));
|
||||
|
||||
#define PVDDLS_OR_BIT(a) \
|
||||
p33_or_1byte(P3_LS_CTMU , BIT(a)); \
|
||||
p33_or_1byte(P3_LS_P11 , BIT(a));
|
||||
|
||||
#define DVDDLS_AND_NBIT(a) \
|
||||
p33_and_1byte(P3_LS_IO_USR , (u8)~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_IO_ROM , (u8)~BIT(a));
|
||||
|
||||
#define SHALS_AND_NBIT(a) \
|
||||
p33_and_1byte(P3_LS_IO_SHA , (u8)~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_IO_PINR , (u8)~BIT(a));
|
||||
|
||||
#define PVDDLS_AND_NBIT(a) \
|
||||
p33_and_1byte(P3_LS_CTMU , (u8)~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_P11 , (u8)~BIT(a));
|
||||
|
||||
#define DVDDLS_TX_BYTE(a) \
|
||||
p33_tx_1byte(P3_LS_IO_USR , a); \
|
||||
p33_tx_1byte(P3_LS_IO_ROM , a);
|
||||
|
||||
#define SHALS_TX_BYTE(a) \
|
||||
p33_tx_1byte(P3_LS_IO_SHA , a); \
|
||||
p33_tx_1byte(P3_LS_IO_PINR , a);
|
||||
|
||||
#define PVDDLS_TX_BYTE(a) \
|
||||
p33_tx_1byte(P3_LS_CTMU , a); \
|
||||
p33_tx_1byte(P3_LS_P11 , a);
|
||||
|
||||
#define DVDDLS_ANA_NBIT(a) \
|
||||
p33_and_1byte(P3_LS_IO_USR , ~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_IO_ROM , ~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_IO_SHA , ~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_CTMU , ~BIT(a)); \
|
||||
|
||||
#define SHALS_ANA_NBIT(a) \
|
||||
p33_and_1byte(P3_LS_IO_SHA , (u8)~BIT(a)); \
|
||||
p33_and_1byte(P3_LS_CTMU , (u8)~BIT(a)); \
|
||||
|
||||
#define PVDDLS_ANA_NBIT(a) \
|
||||
p33_and_1byte(P3_LS_P11 , ~BIT(a));
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// for reset_source
|
||||
//
|
||||
//
|
||||
//
|
||||
/************************P3_PR_PWR*****************************/
|
||||
#define P3_SOFT_RESET() P33_CON_SET(P3_PR_PWR, 4, 1, 1)
|
||||
|
||||
/************************P3_IVS_CLR*****************************/
|
||||
#define PWVLD(a) \
|
||||
if (a) { \
|
||||
p33_tx_1byte(P3_IVS_SET, BIT(7)); \
|
||||
} else { \
|
||||
p33_tx_1byte(P3_IVS_CLR, BIT(7)); \
|
||||
}
|
||||
|
||||
#define P33_SF_KICK_START() P33_CON_SET(P3_IVS_CLR, 0, 8, 0b00101010)
|
||||
|
||||
#define PWR_BY_SOFTWARE(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_RST_CON1, BIT(6)); \
|
||||
p33_tx_1byte(P3_ANA_KEEP0, 0xff); \
|
||||
p33_tx_1byte(P3_ANA_KEEP1, 0xff); \
|
||||
PWVLD(0); \
|
||||
} else { \
|
||||
PWVLD(1); \
|
||||
p33_and_1byte(P3_RST_CON1, ~BIT(6)); \
|
||||
}
|
||||
|
||||
|
||||
/************************P3_RST_SRC*****************************/
|
||||
#define GET_P33_SYS_RST_SRC() P33_CON_GET(P3_RST_SRC)
|
||||
|
||||
/************************P3_RST_FLAG*****************************/
|
||||
#define GET_P33_SYS_POWER_FLAG() ((P33_CON_GET(P3_RST_FLAG) & BIT(3)) ? 1 : 0)
|
||||
|
||||
#define GET_P33_SYS_RST_LEVEL2() ((P33_CON_GET(P3_RST_FLAG) & BIT(3)) ? 1 : 0)
|
||||
#define GET_P33_SYS_RST_LEVEL1() ((P33_CON_GET(P3_RST_FLAG) & BIT(5)) ? 1 : 0)
|
||||
#define GET_P33_SYS_RST_LEVEL0() ((P33_CON_GET(P3_RST_FLAG) & BIT(7)) ? 1 : 0)
|
||||
|
||||
#define P33_LV2_RST_FLAG_CLR() (p33_fast_access(P3_RST_FLAG, BIT(2), 1))
|
||||
#define P33_LV1_RST_FLAG_CLR() (p33_fast_access(P3_RST_FLAG, BIT(4), 1))
|
||||
#define P33_LV0_RST_FLAG_CLR() (p33_fast_access(P3_RST_FLAG, BIT(6), 1))
|
||||
|
||||
|
||||
//-----special operation----------
|
||||
#define P33_WKUP_ENABLE() \
|
||||
p33_or_1byte(P3_VLD_KEEP , BIT(2))
|
||||
|
||||
#define P33_WKUP_DISABLE() \
|
||||
p33_and_1byte(P3_VLD_KEEP , ~BIT(2))
|
||||
|
||||
#define P33_IE_ENABLE() \
|
||||
bit_set_ie(IRQ_P33_IDX)
|
||||
|
||||
#define P33_IE_DISABLE() \
|
||||
bit_clr_ie(IRQ_P33_IDX)
|
||||
|
||||
#define IS_CHARGE_EN_NOW() (P3_CHG_CON0 & BIT(0))
|
||||
|
||||
/*
|
||||
*-------------------P3_ANA_FLOW0
|
||||
*/
|
||||
|
||||
|
||||
#define DCVDD_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW0, BIT(2)); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW0, ~BIT(2)); \
|
||||
}
|
||||
|
||||
#define DCDC13_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW0, BIT(3)); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW0, ~BIT(3)); \
|
||||
}
|
||||
|
||||
#define IS_DCDC13_EN() ((P3_ANA_FLOW0 & BIT(3)) ? 1: 0 )
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*-------------------P3_ANA_FLOW1
|
||||
*/
|
||||
|
||||
#define IOVD_IFULL_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW1, (BIT(0) | BIT(1))); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW1, ~(BIT(0) | BIT(1))); \
|
||||
}
|
||||
|
||||
#define IOVD_VLMT_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW1, (BIT(2) | BIT(3))); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW1, ~(BIT(2) | BIT(3))); \
|
||||
}
|
||||
|
||||
|
||||
#define DVD_POR_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW1, BIT(6)); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW1, ~BIT(6)); \
|
||||
}
|
||||
|
||||
#define PVD_POR_EN(a) \
|
||||
if (a) { \
|
||||
p33_or_1byte(P3_ANA_FLOW1, BIT(7)); \
|
||||
} else { \
|
||||
p33_and_1byte(P3_ANA_FLOW1, ~BIT(7)); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
*-------------------P3_VLVD_CON1
|
||||
*/
|
||||
#define VLVD_SEL(a) P3_VLVD_CON1 = (P3_VLVD_CON1 & (~0xf)) | a
|
||||
//macro for VLVD_SEL
|
||||
enum {
|
||||
VLVD_sel_16V = 0,
|
||||
VLVD_sel_17V,
|
||||
VLVD_sel_18V,
|
||||
VLVD_sel_19V,
|
||||
VLVD_sel_20V,
|
||||
VLVD_sel_21V,
|
||||
VLVD_sel_22V,
|
||||
VLVD_sel_23V,
|
||||
VLVD_sel_24V,
|
||||
VLVD_sel_25V,
|
||||
VLVD_sel_26V,
|
||||
VLVD_sel_27V,
|
||||
VLVD_sel_28V,
|
||||
VLVD_sel_29V,
|
||||
VLVD_sel_30V,
|
||||
VLVD_sel_31V,
|
||||
};
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
*-------------------P3_IOV_CON0
|
||||
*/
|
||||
//vddiom_lev
|
||||
enum {
|
||||
VDDIOM_VOL_21V = 0,
|
||||
VDDIOM_VOL_22V,
|
||||
VDDIOM_VOL_23V,
|
||||
VDDIOM_VOL_24V,
|
||||
VDDIOM_VOL_25V,
|
||||
VDDIOM_VOL_26V,
|
||||
VDDIOM_VOL_27V,
|
||||
VDDIOM_VOL_28V,
|
||||
VDDIOM_VOL_29V,
|
||||
VDDIOM_VOL_30V,
|
||||
VDDIOM_VOL_31V,
|
||||
VDDIOM_VOL_32V,
|
||||
VDDIOM_VOL_33V,
|
||||
VDDIOM_VOL_34V,
|
||||
VDDIOM_VOL_35V,
|
||||
VDDIOM_VOL_36V,
|
||||
};
|
||||
|
||||
#define GET_MVIO_SEL() (P3_IOV_CON0 & 0xf)
|
||||
|
||||
#define MVIO_SEL(a) P3_IOV_CON0 = (P3_IOV_CON0 & (~0xf)) | a
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* *-------------------P3_RST_FLAG
|
||||
* */
|
||||
#define P33_SYS_POWERUP_CLEAR() p33_or_1byte(P3_RST_FLAG, BIT(2)|BIT(4)|BIT(6))
|
||||
|
||||
|
||||
|
||||
|
||||
//need 1mS to recorver
|
||||
//P3_ANA_KEEP0 = 0; \
|
||||
//P3_ANA_KEEP1 = 0;
|
||||
|
||||
//while(POWER_ON_END());
|
||||
//P3_ANA_KEEP0 = 0; \
|
||||
//P3_ANA_KEEP1 = 0;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
#ifndef __P33_SFR_H__
|
||||
#define __P33_SFR_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#ifdef PMU_SYSTEM
|
||||
#define P33_ACCESS(x) (*(volatile u32 *)(0xc000 + x*4))
|
||||
#else
|
||||
#define P33_ACCESS(x) (*(volatile u32 *)(0xf20000 + 0xc000 + x*4))
|
||||
#endif
|
||||
|
||||
#ifdef PMU_SYSTEM
|
||||
#define RTC_ACCESS(x) (*(volatile u32 *)(0xd000 + x*4))
|
||||
#else
|
||||
#define RTC_ACCESS(x) (*(volatile u32 *)(0xf20000 + 0xd000 + x*4))
|
||||
#endif
|
||||
|
||||
//===========
|
||||
//===============================================================================//
|
||||
//
|
||||
//
|
||||
//
|
||||
//===============================================================================//
|
||||
//............. 0x0000 - 0x000f............
|
||||
//#define P3_VLMT_CON P33_ACCESS(0x01)
|
||||
//#define P3_POR_CON P33_ACCESS(0x02)
|
||||
#define P3_VLVD_CON0 P33_ACCESS(0x03)
|
||||
#define P3_VLVD_CON1 P33_ACCESS(0x04)
|
||||
#define P3_VLVD_FLT P33_ACCESS(0x05)
|
||||
#define P3_WDT_CON P33_ACCESS(0x06)
|
||||
#define P3_OCP_CON0 P33_ACCESS(0x07)
|
||||
|
||||
#define P3_ANA_FLOW0 P33_ACCESS(0x08)
|
||||
#define P3_ANA_FLOW1 P33_ACCESS(0x09)
|
||||
#define P3_ANA_FLOW2 P33_ACCESS(0x0a)
|
||||
|
||||
#define P3_ANA_KEEP0 P33_ACCESS(0x0c)
|
||||
#define P3_ANA_KEEP1 P33_ACCESS(0x0d)
|
||||
#define P3_ANA_KEEP2 P33_ACCESS(0x0e)
|
||||
|
||||
//............. 0X0010 - 0X001F.........for analog others
|
||||
#define P3_OSL_CON P33_ACCESS(0x10)
|
||||
#define P3_RST_FLAG P33_ACCESS(0x11)
|
||||
#define P3_VBAT_TYPE P33_ACCESS(0x12)
|
||||
#define P3_LRC_CON0 P33_ACCESS(0x13)
|
||||
#define P3_LRC_CON1 P33_ACCESS(0x14)
|
||||
#define P3_RST_CON0 P33_ACCESS(0x15)
|
||||
#define P3_RST_CON1 P33_ACCESS(0x16)
|
||||
#define P3_RST_CON2 P33_ACCESS(0x17)
|
||||
#define P3_VLD_KEEP P33_ACCESS(0x18)
|
||||
#define P3_CLK_CON0 P33_ACCESS(0x19)
|
||||
#define P3_ANA_READ P33_ACCESS(0x1a)
|
||||
#define P3_CHG_CON0 P33_ACCESS(0x1b)
|
||||
#define P3_CHG_CON1 P33_ACCESS(0x1c)
|
||||
#define P3_CHG_CON2 P33_ACCESS(0x1d)
|
||||
#define P3_CHG_CON3 P33_ACCESS(0x1e)
|
||||
#define P3_CHG_CON4 P33_ACCESS(0x1f)
|
||||
|
||||
//............. 0X0020 - 0X002F............ for buck circuit
|
||||
//#define P3_BUCK1_CON0 P33_ACCESS(0x20)
|
||||
//#define P3_BUCK1_CON1 P33_ACCESS(0x21)
|
||||
//#define P3_BUCK1_CON2 P33_ACCESS(0x22)
|
||||
//#define P3_BUCK1_CON3 P33_ACCESS(0x23)
|
||||
//#define P3_BUCK1_CON4 P33_ACCESS(0x24)
|
||||
//#define P3_BUCK1_CON5 P33_ACCESS(0x25)
|
||||
//#define P3_BUCK1_CON6 P33_ACCESS(0x26)
|
||||
//#define P3_BUCK1_CON7 P33_ACCESS(0x27)
|
||||
#define P3_BUCK2_CON0 P33_ACCESS(0x20)
|
||||
#define P3_BUCK2_CON1 P33_ACCESS(0x21)
|
||||
#define P3_BUCK2_CON2 P33_ACCESS(0x22)
|
||||
#define P3_BUCK2_CON3 P33_ACCESS(0x23)
|
||||
#define P3_BUCK2_CON4 P33_ACCESS(0x24)
|
||||
#define P3_BUCK2_CON5 P33_ACCESS(0x25)
|
||||
#define P3_BUCK2_CON6 P33_ACCESS(0x26)
|
||||
#define P3_BUCK2_CON7 P33_ACCESS(0x27)
|
||||
//#define P3_BUCK3_CON0 P33_ACCESS(0x28)
|
||||
//#define P3_BUCK3_CON1 P33_ACCESS(0x29)
|
||||
//#define P3_BUCK3_CON2 P33_ACCESS(0x2a)
|
||||
//#define P3_BUCK3_CON3 P33_ACCESS(0x2b)
|
||||
//#define P3_BUCK3_CON4 P33_ACCESS(0x2c)
|
||||
//#define P3_BUCK3_CON5 P33_ACCESS(0x2d)
|
||||
//#define P3_BUCK3_CON6 P33_ACCESS(0x2e)
|
||||
//#define P3_BUCK3_CON7 P33_ACCESS(0x2f)
|
||||
|
||||
//............. 0X0030 - 0X003F............ for PMU manager
|
||||
#define P3_SFLAG0 P33_ACCESS(0x30)
|
||||
#define P3_SFLAG1 P33_ACCESS(0x31)
|
||||
#define P3_SFLAG2 P33_ACCESS(0x32)
|
||||
#define P3_SFLAG3 P33_ACCESS(0x33)
|
||||
#define P3_SFLAG4 P33_ACCESS(0x34)
|
||||
#define P3_SFLAG5 P33_ACCESS(0x35)
|
||||
#define P3_SFLAG6 P33_ACCESS(0x36)
|
||||
#define P3_SFLAG7 P33_ACCESS(0x37)
|
||||
#define P3_SFLAG8 P33_ACCESS(0x38)
|
||||
#define P3_SFLAG9 P33_ACCESS(0x39)
|
||||
#define P3_SFLAGA P33_ACCESS(0x3a)
|
||||
#define P3_SFLAGB P33_ACCESS(0x3b)
|
||||
|
||||
//............. 0X0040 - 0X004F............ for
|
||||
#define P3_IVS_RD P33_ACCESS(0x40)
|
||||
#define P3_IVS_SET P33_ACCESS(0x41)
|
||||
#define P3_IVS_CLR P33_ACCESS(0x42)
|
||||
#define P3_PVDD0_AUTO P33_ACCESS(0x43)
|
||||
#define P3_PVDD1_AUTO P33_ACCESS(0x44)
|
||||
#define P3_WKUP_DLY P33_ACCESS(0x45)
|
||||
|
||||
#define P3_PCNT_FLT P33_ACCESS(0x48)
|
||||
#define P3_PCNT_CON P33_ACCESS(0x49)
|
||||
#define P3_PCNT_SET0 P33_ACCESS(0x4a)
|
||||
#define P3_PCNT_SET1 P33_ACCESS(0x4b)
|
||||
#define P3_PCNT_DAT0 P33_ACCESS(0x4c)
|
||||
#define P3_PCNT_DAT1 P33_ACCESS(0x4d)
|
||||
|
||||
#define P3_P11_CPU P33_ACCESS(0x4f)
|
||||
|
||||
//............. 0X0050 - 0X005F............ for port wake up
|
||||
#define P3_WKUP_FLT_EN0 P33_ACCESS(0x50)
|
||||
#define P3_WKUP_P_IE0 P33_ACCESS(0x51)
|
||||
#define P3_WKUP_N_IE0 P33_ACCESS(0x52)
|
||||
#define P3_WKUP_LEVEL0 P33_ACCESS(0x53)
|
||||
#define P3_WKUP_P_CPND0 P33_ACCESS(0x54)
|
||||
#define P3_WKUP_N_CPND0 P33_ACCESS(0x55)
|
||||
#define P3_WKUP_P_PND0 P33_ACCESS(0x56)
|
||||
#define P3_WKUP_N_PND0 P33_ACCESS(0x57)
|
||||
#define P3_WKUP_FLT_EN1 P33_ACCESS(0x58)
|
||||
#define P3_WKUP_P_IE1 P33_ACCESS(0x59)
|
||||
#define P3_WKUP_N_IE1 P33_ACCESS(0x5a)
|
||||
#define P3_WKUP_LEVEL1 P33_ACCESS(0x5b)
|
||||
#define P3_WKUP_P_CPND1 P33_ACCESS(0x5c)
|
||||
#define P3_WKUP_N_CPND1 P33_ACCESS(0x5d)
|
||||
#define P3_WKUP_P_PND1 P33_ACCESS(0x5e)
|
||||
#define P3_WKUP_N_PND1 P33_ACCESS(0x5f)
|
||||
|
||||
//............. 0X0060 - 0X006F............ for analog wake up
|
||||
#define P3_AWKUP_FLT_EN P33_ACCESS(0x60)
|
||||
#define P3_AWKUP_P_IE P33_ACCESS(0x61)
|
||||
#define P3_AWKUP_N_IE P33_ACCESS(0x62)
|
||||
#define P3_AWKUP_LEVEL P33_ACCESS(0x63)
|
||||
#define P3_AWKUP_P_PND P33_ACCESS(0x64)
|
||||
#define P3_AWKUP_N_PND P33_ACCESS(0x65)
|
||||
#define P3_AWKUP_P_CPND P33_ACCESS(0x66)
|
||||
#define P3_AWKUP_N_CPND P33_ACCESS(0x67)
|
||||
#define P3_WKUP_CLK_SEL P33_ACCESS(0x68)
|
||||
#define P3_AWKUP_CLK_SEL P33_ACCESS(0x69)
|
||||
#define P3_SYS_PWR0 P33_ACCESS(0x6a)
|
||||
#define P3_SYS_PWR1 P33_ACCESS(0x6b)
|
||||
#define P3_SYS_PWR2 P33_ACCESS(0x6c)
|
||||
#define P3_SYS_PWR3 P33_ACCESS(0x6d)
|
||||
#define P3_SYS_PWR4 P33_ACCESS(0x6e)
|
||||
#define P3_SYS_PWR5 P33_ACCESS(0x6f)
|
||||
|
||||
//............. 0X0070 - 0X007F............ for
|
||||
#define P3_PGDR_CON0 P33_ACCESS(0x70)
|
||||
#define P3_PGDR_CON1 P33_ACCESS(0x71)
|
||||
#define P3_PGSD_CON P33_ACCESS(0x72)
|
||||
|
||||
#define P3_LP_CTL P33_ACCESS(0x74)
|
||||
#define P3_LP_CFG P33_ACCESS(0x75)
|
||||
#define P3_NVRAM_PWR P33_ACCESS(0x76)
|
||||
#define P3_WVD_CON0 P33_ACCESS(0x77)
|
||||
#define P3_PVD_CON0 P33_ACCESS(0x78)
|
||||
#define P3_EVD_CON0 P33_ACCESS(0x79)
|
||||
#define P3_PMU_CON0 P33_ACCESS(0x7a)
|
||||
|
||||
#define P3_PMU_CON4 P33_ACCESS(0x7e)
|
||||
#define P3_PMU_CON5 P33_ACCESS(0x7f)
|
||||
|
||||
//............. 0X0080 - 0X008F............ for
|
||||
#define P3_PINR_CON P33_ACCESS(0x80)
|
||||
#define P3_PINR_CON1 P33_ACCESS(0x81)
|
||||
#define P3_PINR_SAFE P33_ACCESS(0x82)
|
||||
#define P3_PINR_SAFE1 P33_ACCESS(0x83)
|
||||
#define P3_PINR_PND1 P33_ACCESS(0x84)
|
||||
|
||||
#define P3_RST_SRC0 P33_ACCESS(0x8e)
|
||||
#define P3_RST_SRC1 P33_ACCESS(0x8f)
|
||||
|
||||
//............. 0X0090 - 0X009F............ for
|
||||
#define P3_PSW_CON0 P33_ACCESS(0x90)
|
||||
#define P3_PSW_CON1 P33_ACCESS(0x91)
|
||||
#define P3_PSW_CON2 P33_ACCESS(0x92)
|
||||
#define P3_PMU_ADC0 P33_ACCESS(0x93)
|
||||
#define P3_PMU_ADC1 P33_ACCESS(0x94)
|
||||
#define P3_VBG_CON0 P33_ACCESS(0x95)
|
||||
#define P3_VBG_CON1 P33_ACCESS(0x96)
|
||||
#define P3_IOV_CON0 P33_ACCESS(0x97)
|
||||
#define P3_IOV_CON1 P33_ACCESS(0x98)
|
||||
#define P3_PAVD_CON0 P33_ACCESS(0x99)
|
||||
#define P3_DCV_CON0 P33_ACCESS(0x9a)
|
||||
#define P3_DVD_CON0 P33_ACCESS(0x9b)
|
||||
#define P3_DVD2_CON0 P33_ACCESS(0x9c)
|
||||
#define P3_RVD_CON0 P33_ACCESS(0x9d)
|
||||
#define P3_RVD_CON1 P33_ACCESS(0x9e)
|
||||
#define P3_RVD2_CON0 P33_ACCESS(0x9f)
|
||||
|
||||
//............. 0X00A0 - 0X00AF............
|
||||
#define P3_PR_PWR P33_ACCESS(0xa0)
|
||||
#define P3_VPWR_CON0 P33_ACCESS(0xa1)
|
||||
#define P3_VPWR_CON1 P33_ACCESS(0xa2)
|
||||
#define P3_RTC_ADC0 P33_ACCESS(0xa3)
|
||||
#define P3_LS_P11 P33_ACCESS(0xa4)
|
||||
#define P3_LS_EN P33_ACCESS(0xa5)
|
||||
|
||||
#define P3_EXT_EFUSE_CON P33_ACCESS(0xa6)
|
||||
|
||||
#define P3_WKUP_SRC P33_ACCESS(0xa8)
|
||||
#define P3_ANA_MFIX P33_ACCESS(0xa9)
|
||||
#define P3_DBG_CON0 P33_ACCESS(0xaa)
|
||||
#define P3_DBG_CON1 P33_ACCESS(0xab)
|
||||
#define P3_MFIX_OPT P33_ACCESS(0xac)
|
||||
|
||||
//............. 0X00B0 - 0X00BF............ for EFUSE
|
||||
#define P3_EFUSE_CON0 P33_ACCESS(0xb0)
|
||||
#define P3_EFUSE_CON1 P33_ACCESS(0xb1)
|
||||
#define P3_EFUSE_CON2 P33_ACCESS(0xb2)
|
||||
#define P3_EFUSE_RDAT P33_ACCESS(0xb3)
|
||||
#define P3_EFUSE_PU_DAT0 P33_ACCESS(0xb4)
|
||||
#define P3_EFUSE_PU_DAT1 P33_ACCESS(0xb5)
|
||||
#define P3_EFUSE_PU_DAT2 P33_ACCESS(0xb6)
|
||||
#define P3_EFUSE_PU_DAT3 P33_ACCESS(0xb7)
|
||||
|
||||
#define P3_FUNC_EN P33_ACCESS(0xb8)
|
||||
#define P3_FUNC_CTL0 P33_ACCESS(0xb9)
|
||||
#define P3_FUNC_CTL1 P33_ACCESS(0xba)
|
||||
#define P3_FUNC_CTL2 P33_ACCESS(0xbb)
|
||||
#define P3_EFUSE_ANA0 P33_ACCESS(0xbc)
|
||||
|
||||
//............. 0X00C0 - 0X00CF............ for port input select
|
||||
#define P3_PORT_SEL0 P33_ACCESS(0xc0)
|
||||
#define P3_PORT_SEL1 P33_ACCESS(0xc1)
|
||||
#define P3_PORT_SEL2 P33_ACCESS(0xc2)
|
||||
#define P3_PORT_SEL3 P33_ACCESS(0xc3)
|
||||
#define P3_PORT_SEL4 P33_ACCESS(0xc4)
|
||||
#define P3_PORT_SEL5 P33_ACCESS(0xc5)
|
||||
#define P3_PORT_SEL6 P33_ACCESS(0xc6)
|
||||
#define P3_PORT_SEL7 P33_ACCESS(0xc7)
|
||||
|
||||
//............. 0x00d0 - 0x00df............
|
||||
#define P3_LS_IO_USR P33_ACCESS(0xd0) //TODO: check sync with verilog head file chip_def.v LEVEL_SHIFTER
|
||||
#define P3_LS_IO_ROM P33_ACCESS(0xd1)
|
||||
#define P3_LS_IO_PINR P33_ACCESS(0xd2)
|
||||
#define P3_LS_CTMU P33_ACCESS(0xd3)
|
||||
#define P3_LS_IO_SHA P33_ACCESS(0xd4)
|
||||
#define P3_LS_LRC24M P33_ACCESS(0xd5)
|
||||
#define P3_LS_BT P33_ACCESS(0xd6)
|
||||
#define P3_LS_PLL P33_ACCESS(0xd7)
|
||||
|
||||
//............. 0X00E0 - 0X00FF............ for p33 lp timer
|
||||
#define P3_LP_RSC00 P33_ACCESS(0xe0)
|
||||
#define P3_LP_RSC01 P33_ACCESS(0xe1)
|
||||
#define P3_LP_RSC02 P33_ACCESS(0xe2)
|
||||
#define P3_LP_RSC03 P33_ACCESS(0xe3)
|
||||
#define P3_LP_PRD00 P33_ACCESS(0xe4)
|
||||
#define P3_LP_PRD01 P33_ACCESS(0xe5)
|
||||
#define P3_LP_PRD02 P33_ACCESS(0xe6)
|
||||
#define P3_LP_PRD03 P33_ACCESS(0xe7)
|
||||
#define P3_LP_RSC10 P33_ACCESS(0xe8)
|
||||
#define P3_LP_RSC11 P33_ACCESS(0xe9)
|
||||
#define P3_LP_RSC12 P33_ACCESS(0xea)
|
||||
#define P3_LP_RSC13 P33_ACCESS(0xeb)
|
||||
#define P3_LP_RSC14 P33_ACCESS(0xec)
|
||||
#define P3_LP_RSC15 P33_ACCESS(0xed)
|
||||
#define P3_LP_PRD10 P33_ACCESS(0xee)
|
||||
#define P3_LP_PRD11 P33_ACCESS(0xef)
|
||||
#define P3_LP_PRD12 P33_ACCESS(0xf0)
|
||||
#define P3_LP_PRD13 P33_ACCESS(0xf1)
|
||||
#define P3_LP_PRD14 P33_ACCESS(0xf2)
|
||||
#define P3_LP_PRD15 P33_ACCESS(0xf3)
|
||||
#define P3_LP_TMR0_CLK P33_ACCESS(0xf4)
|
||||
#define P3_LP_TMR1_CLK P33_ACCESS(0xf5)
|
||||
#define P3_LP_TMR0_CON P33_ACCESS(0xf6)
|
||||
#define P3_LP_TMR1_CON P33_ACCESS(0xf7)
|
||||
#define P3_LP_TMR_CFG P33_ACCESS(0xf8)
|
||||
#define P3_LP_CNTRD0 P33_ACCESS(0xf9)
|
||||
#define P3_LP_CNT0 P33_ACCESS(0xfa)
|
||||
#define P3_LP_CNT1 P33_ACCESS(0xfb)
|
||||
#define P3_LP_CNT2 P33_ACCESS(0xfc)
|
||||
#define P3_LP_CNT3 P33_ACCESS(0xfd)
|
||||
#define P3_LP_CNT4 P33_ACCESS(0xfe)
|
||||
#define P3_LP_CNT5 P33_ACCESS(0xff)
|
||||
|
||||
|
||||
|
||||
//===============================================================================//
|
||||
//
|
||||
// P33 RTCVDD
|
||||
//
|
||||
//===============================================================================//
|
||||
|
||||
//............. 0X0080 - 0X008F............ for RTC
|
||||
#define R3_ALM_CON RTC_ACCESS(0x80)
|
||||
|
||||
#define R3_RTC_CON0 RTC_ACCESS(0x84)
|
||||
#define R3_RTC_CON1 RTC_ACCESS(0x85)
|
||||
#define R3_RTC_DAT0 RTC_ACCESS(0x86)
|
||||
#define R3_RTC_DAT1 RTC_ACCESS(0x87)
|
||||
#define R3_RTC_DAT2 RTC_ACCESS(0x88)
|
||||
#define R3_RTC_DAT3 RTC_ACCESS(0x89)
|
||||
#define R3_RTC_DAT4 RTC_ACCESS(0x8a)
|
||||
#define R3_ALM_DAT0 RTC_ACCESS(0x8b)
|
||||
#define R3_ALM_DAT1 RTC_ACCESS(0x8c)
|
||||
#define R3_ALM_DAT2 RTC_ACCESS(0x8d)
|
||||
#define R3_ALM_DAT3 RTC_ACCESS(0x8e)
|
||||
#define R3_ALM_DAT4 RTC_ACCESS(0x8f)
|
||||
|
||||
//............. 0X0090 - 0X009F............ for wake up
|
||||
#define R3_WKUP_EN RTC_ACCESS(0x90)
|
||||
#define R3_WKUP_EDGE RTC_ACCESS(0x91)
|
||||
#define R3_WKUP_CPND RTC_ACCESS(0x92)
|
||||
#define R3_WKUP_PND RTC_ACCESS(0x93)
|
||||
#define R3_WKUP_LEVEL RTC_ACCESS(0x94)
|
||||
|
||||
//............. 0X00A0 - 0X00AF............ for system
|
||||
#define R3_TIME_CON RTC_ACCESS(0xa0)
|
||||
#define R3_TIME_CPND RTC_ACCESS(0xa1)
|
||||
#define R3_TIME_PND RTC_ACCESS(0xa2)
|
||||
|
||||
#define R3_ADC_CON RTC_ACCESS(0xa4)
|
||||
#define R3_OSL_CON RTC_ACCESS(0xa5)
|
||||
|
||||
#define R3_WKUP_SRC RTC_ACCESS(0xa8)
|
||||
#define R3_RST_SRC RTC_ACCESS(0xa9)
|
||||
|
||||
#define R3_RST_CON RTC_ACCESS(0xab)
|
||||
#define R3_CLK_CON RTC_ACCESS(0xac)
|
||||
|
||||
//............. 0X00B0 - 0X00BF............ for PORT control
|
||||
#define R3_PR_IN RTC_ACCESS(0xb0)
|
||||
#define R3_PR_OUT RTC_ACCESS(0xb1)
|
||||
#define R3_PR_DIR RTC_ACCESS(0xb2)
|
||||
#define R3_PR_DIE RTC_ACCESS(0xb3)
|
||||
#define R3_PR_PU0 RTC_ACCESS(0xb4)
|
||||
#define R3_PR_PU1 RTC_ACCESS(0xb5)
|
||||
#define R3_PR_PD0 RTC_ACCESS(0xb6)
|
||||
#define R3_PR_PD1 RTC_ACCESS(0xb7)
|
||||
#define R3_PR_HD0 RTC_ACCESS(0xb8)
|
||||
#define R3_PR_HD1 RTC_ACCESS(0xb9)
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
u32 tmr_2ms_cnt_get(void);
|
||||
|
||||
void sys_tmr_init(void (*cb)(void));
|
||||
|
||||
void sys_tmr_close(void);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef __UART_H__
|
||||
#define __UART_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
int putchar(int a);
|
||||
void uart_init(const char *tx_io, u32 baud);
|
||||
void uart_close(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef __WDT_H__
|
||||
#define __WDT_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
enum {
|
||||
WDT_1ms = 0,
|
||||
WDT_2ms,
|
||||
WDT_4ms,
|
||||
WDT_8ms,
|
||||
WDT_16ms,
|
||||
WDT_32ms,
|
||||
WDT_64ms,
|
||||
WDT_128ms,
|
||||
WDT_256ms,
|
||||
WDT_512ms,
|
||||
WDT_1s,
|
||||
WDT_2s,
|
||||
WDT_4s,
|
||||
WDT_8s,
|
||||
WDT_16s,
|
||||
WDT_32s,
|
||||
};
|
||||
|
||||
|
||||
void wdt_init(u32 level);
|
||||
|
||||
void wdt_clear();
|
||||
|
||||
|
||||
#endif /*WDT_H*/
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//设备错误代码:
|
||||
typedef enum dev_err {
|
||||
DEV_ERR_NONE = 0,
|
||||
DEV_ERR_NOT_MOUNT,
|
||||
DEV_ERR_OVER_CAPACITY,
|
||||
|
||||
DEV_ERR_UNKNOW_CLASS,
|
||||
|
||||
DEV_ERR_NOT_READY,//设备已经在线,但是没初始化完成
|
||||
DEV_ERR_LUN,
|
||||
|
||||
DEV_ERR_TIMEOUT,
|
||||
DEV_ERR_CMD_TIMEOUT,
|
||||
DEV_ERR_READ_TIMEOUT,//0x08
|
||||
DEV_ERR_WRITE_TIMEOUT,
|
||||
|
||||
DEV_ERR_OFFLINE,//0x0a
|
||||
|
||||
DEV_ERR_CRC,
|
||||
DEV_ERR_CMD_CRC,
|
||||
DEV_ERR_READ_CRC,
|
||||
DEV_ERR_WRITE_CRC,
|
||||
|
||||
DEV_ERR_CONTROL_STALL,
|
||||
DEV_ERR_RXSTALL,//0x10
|
||||
DEV_ERR_TXSTALL,
|
||||
DEV_ERR_CONTROL,
|
||||
|
||||
DEV_ERR_NOT_STORAGE,
|
||||
DEV_ERR_INVALID_PATH,
|
||||
DEV_ERR_INVALID_DATA,
|
||||
DEV_ERR_OUTOFMEMORY,
|
||||
DEV_ERR_HANDLE_FREE,
|
||||
DEV_ERR_INVALID_HANDLE,//24
|
||||
DEV_ERR_INVALID_BUF,
|
||||
DEV_ERR_INUSE,
|
||||
DEV_ERR_NO_READ,
|
||||
DEV_ERR_NO_WRITE,
|
||||
DEV_ERR_NO_IOCTL,
|
||||
DEV_ERR_NO_POWER,
|
||||
DEV_ERR_NOT_EXIST,
|
||||
DEV_ERR_UNKNOW,
|
||||
} DEV_ERR;
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
#ifndef __NORFLASH_H__
|
||||
#define __NORFLASH_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
//spi_width:
|
||||
#define SPI_MODE_UNIDIR_1BIT 0//半双工,do分时发送/接收
|
||||
#define SPI_MODE_BIDIR_1BIT 1//全双工,di接收,do发送
|
||||
#define SPI_MODE_UNIDIR_2BIT 2//半双工,di & do共2bit分时发送/接收
|
||||
#define SPI_MODE_UNIDIR_4BIT 4//半双工,di & do & wp & hold 共4bit分时发送/接收
|
||||
|
||||
|
||||
#define WINBOND_WRITE_ENABLE 0x06
|
||||
#define WINBOND_WRITE_SR_ENABLE 0x50
|
||||
#define WINBOND_JEDEC_ID 0x9F
|
||||
#define WINBOND_UUID 0x4B
|
||||
#define WINBOND_READ_SR1 0x05
|
||||
#define WINBOND_READ_SR2 0x35
|
||||
#define WINBOND_READ_SR3 0x15
|
||||
#define WINBOND_WRITE_SR1 0x01
|
||||
#define WINBOND_WRITE_SR2 0x31
|
||||
#define WINBOND_WRITE_SR3 0x11
|
||||
#define WINBOND_FAST_READ 0x0B
|
||||
#define WINBOND_FAST_READ_DUAL_OUTPUT 0x3B
|
||||
#define WINBOND_FAST_READ_QUAD_OUTPUT 0x6B
|
||||
#define WINBOND_FAST_READ_DUAL_IO 0xBB
|
||||
#define WINBOND_FAST_READ_QUAD_IO 0xEB
|
||||
#define WINBOND_CONTINUOUS_READ_NORMAL_MODE 0x00
|
||||
#define WINBOND_CONTINUOUS_READ_ENHANCE_MODE 0x20
|
||||
#define WINBOND_PAGE_PROGRAM 0x02
|
||||
#define WINBOND_PAGE_ERASE 0x81
|
||||
#define WINBOND_SECTOR_ERASE 0x20
|
||||
#define WINBOND_BLOCK_ERASE 0xD8
|
||||
#define WINBOND_CHIP_ERASE 0xC7
|
||||
#define WINBOND_POWER_DOWN 0xB9
|
||||
#define WINBOND_RELEASE 0xAB
|
||||
|
||||
|
||||
struct flash_info_t {
|
||||
u8 uuid[16];
|
||||
u32 id;
|
||||
u32 capacity;
|
||||
};
|
||||
|
||||
struct flash_wp_arg {
|
||||
u32 id;
|
||||
u8 split_mode: 1; //0 连续写,1,分开写
|
||||
u8 write_en_use_50h: 1; //0:06H 1:50H
|
||||
u8 res: 2;
|
||||
u8 numOfwp_array: 4; //写保护参数的个数
|
||||
struct {
|
||||
u8 sr1;
|
||||
u8 sr2;
|
||||
u16 wp_addr; //写保护结束地址,单位K
|
||||
} wp_array[15];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct custom_data_t {
|
||||
u16 u16crc;
|
||||
u16 len;
|
||||
u8 otp_mode;//0xa0:flash_mode 0xa1:otp mode
|
||||
union {
|
||||
struct {
|
||||
u8 wr_sr_cmd[2];//寄存器的写命令,当两个命令是一样的,就使用连续写模式
|
||||
u8 otp_lock_sr1;
|
||||
u8 otp_lock_sr1_mask;//mask ==0 就忽略此寄存器
|
||||
u8 otp_lock_sr2;
|
||||
u8 otp_lock_sr2_mask;//mask ==0 就忽略此寄存器
|
||||
|
||||
u16 otp_page_num;
|
||||
u16 otp_page_size;
|
||||
u32 otp_offset[5];
|
||||
} __attribute__((packed)) otp_info;
|
||||
u8 user_info_data[59];
|
||||
} __attribute__((packed)) u;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct spi_platform_data {
|
||||
u8 spi_idx;
|
||||
u8 width;
|
||||
u8 clk_div;
|
||||
u8 port;
|
||||
u8 cs_port;
|
||||
u8 clk_port;
|
||||
u8 do_port;
|
||||
u8 di_port;
|
||||
u8 d2_port;
|
||||
u8 d3_port;
|
||||
};
|
||||
|
||||
enum DEV_FLASH_TYPE {
|
||||
DEV_FLASH_INTERNAL_NORFLASH,
|
||||
DEV_FLASH_EXTERNAL_NORFLASH,
|
||||
DEV_FLASH_NANDFLASH,
|
||||
DEV_FLASH_NANDFLASH_FTL,
|
||||
};
|
||||
|
||||
struct flash_platform_data {
|
||||
enum DEV_FLASH_TYPE flash_type;
|
||||
u8 read_mode;
|
||||
u8 power_io;
|
||||
u8 power_io_level;
|
||||
u8 power_ldo_io;
|
||||
u8 power_ldo_io_level;
|
||||
u8 qe_position;
|
||||
struct spi_platform_data spi_pdata;
|
||||
};
|
||||
|
||||
struct flash_info_t *get_flash_info(void);
|
||||
|
||||
void flash_poweron_base(u32 port, u32 out0_time, u32 poweron_time, void (*custom_udelay)(u32), void (*custom_mdelay)(u32));
|
||||
void flash_poweroff_base(u32 port, u32 out0_time, u32 discharge_time, void (*custom_udelay)(u32), void (*custom_mdelay)(u32));
|
||||
|
||||
u8 get_flash_is4byte_mode(void);
|
||||
u32 get_flash_capacity(void);
|
||||
u32 norflash_get_id(void);
|
||||
void norflash_get_uuid(u8 *buffer);
|
||||
u16 norflash_cmd_custom(void);
|
||||
|
||||
void norflash_read_status_reg(u8 *status_reg1, u8 *status_reg2);
|
||||
u8 norflash_spi_write_sr_reg(u8 reg1, u8 reg2) ;
|
||||
int norflash_write_protect(u8 sr_mode, u8 wr_en_mode, u32 sr1, u32 sr2);
|
||||
int norflash_write_protect_config(u32 addr, const struct flash_wp_arg *p);
|
||||
|
||||
#define TZFLASH_STA_NUM 4
|
||||
struct flash_reg {
|
||||
u8 cmd[4];
|
||||
u8 sr_value[4];
|
||||
u8 sr_mask[4];
|
||||
u8 num_of_reg: 2;
|
||||
u8 wr_en_mode: 1;
|
||||
u8 continue_mode: 4;
|
||||
u8 rev: 1;
|
||||
};
|
||||
|
||||
struct flash_func_len {
|
||||
u16 all_len;
|
||||
u8 version;
|
||||
u8 func_len;//lb
|
||||
u8 sta_len;//lb
|
||||
u8 func_otp;//lb
|
||||
u8 func_dtr;
|
||||
u8 func_wp;//bp,tb,sec,cmp
|
||||
u8 func_wps;
|
||||
u8 func_wps_op;
|
||||
u8 func_qe;
|
||||
u8 func_srp;
|
||||
u8 func_sus;
|
||||
u8 func_dc;
|
||||
u8 func_drv;
|
||||
u8 func_mpm;//dp
|
||||
|
||||
u8 func_qpi;
|
||||
u8 func_init;
|
||||
u8 func_read_continue;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TZFLASH_STA_NUM 4
|
||||
struct flash_sta_cmd {
|
||||
u8 sta_cmd_r[TZFLASH_STA_NUM];
|
||||
u8 sta_cmd_w[TZFLASH_STA_NUM];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define FLASH_SUPPORT_MPM_FUNC 0
|
||||
struct flash_dev_sta_info {
|
||||
struct flash_func_len func_cfg;
|
||||
struct flash_sta_cmd sta_cfg;
|
||||
u8 *cfg_ptr;
|
||||
};
|
||||
|
||||
struct flash_otp_cfg {//flash otp信息
|
||||
u32 otp_offset[5];//otp page的偏移地址组数
|
||||
u16 otp_page_size;//otp的page大小
|
||||
u8 otp_NumberOfpage;//otp的page数量
|
||||
// struct flash_reg lock_cfg[2];//read,write
|
||||
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
|
||||
u8 sr_mask[TZFLASH_STA_NUM];
|
||||
u8 sr_value[TZFLASH_STA_NUM];//注意:锁定后不可擦写,sr的值也常是1
|
||||
} __attribute__((packed));
|
||||
|
||||
struct flash_wps_cfg {//flash wps信息
|
||||
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
|
||||
u8 sr_mask[TZFLASH_STA_NUM];
|
||||
u8 sr_value[TZFLASH_STA_NUM];
|
||||
// struct flash_reg r_reg_cfg;//read
|
||||
// struct flash_reg w_reg_cfg;//write
|
||||
} __attribute__((packed));
|
||||
|
||||
struct flash_wp_cfg { //写保护配置信息
|
||||
u8 numOfwp_array;//写保护参数的个数
|
||||
u8 wr_en_cmd;//0x50h:sr,06h:
|
||||
u8 sr_mask[TZFLASH_STA_NUM]; //sr要保留或修改的bit
|
||||
struct {
|
||||
u8 sr_value[TZFLASH_STA_NUM]; //写保护sr取值
|
||||
u16 wp_addr;//写保护结束地址,单位K
|
||||
} wp_array[0]; //写保护的组数,修改可变长
|
||||
} __attribute__((packed));
|
||||
|
||||
struct flash_dtr_cfg {
|
||||
s8 x1_dummy;//-1:使用默认值
|
||||
s8 x2_dummy;//-1:使用默认值
|
||||
s8 x4_dummy;//-1:使用默认值,-2:不支持
|
||||
} __attribute__((packed));
|
||||
|
||||
struct flash_reg_param {
|
||||
int reg_mask;//需配置的reg映射
|
||||
u8 sr_mask[TZFLASH_STA_NUM];
|
||||
u8 sr_value[TZFLASH_STA_NUM];
|
||||
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
|
||||
};
|
||||
|
||||
struct wps_addr_info {
|
||||
u8 lock_en;
|
||||
u32 wp_saddr;
|
||||
u32 wp_eaddr;
|
||||
};
|
||||
|
||||
int norflash_cfg_wpl(struct flash_wps_cfg *cfg);
|
||||
int norflash_set_wps_addr(u8 lock, u32 saddr, u32 eaddr);
|
||||
int norflash_params_v3_wp(u32 wp_addr, int index, struct flash_wp_cfg *cfg);
|
||||
int norflash_get_flash_v3_wp_func_value(u8 *cfg_buf);
|
||||
int norflash_get_flash_v3_dtr_func_value(u8 *cfg_buf);
|
||||
|
||||
void norflash_exit_continue_mode(void);
|
||||
#ifdef __SFC_DTR
|
||||
void __dtr_norflash_exit_continue_mode(void);
|
||||
#endif
|
||||
int norflash_read(u8 *buf, u32 addr, u32 len);
|
||||
int norflash_write(u8 *buf, u32 addr, u32 len);
|
||||
int norflash_write_async(u8 *buf, u32 offset, u32 len);
|
||||
u8 norflash_eraser(u32 eraser_cmd, u32 addr);
|
||||
|
||||
u8 norflash_read_otp_lb(void);
|
||||
u32 norflash_erase_otp(u32 page);
|
||||
u32 norflash_write_otp(u8 *buffer, u32 len, u32 page, u32 offset);
|
||||
void norflash_read_otp(u8 *buffer, u32 len, u32 page, u32 offset);
|
||||
|
||||
void norflash_read_otp_page(u8 *buffer, u32 len, u32 addr);
|
||||
|
||||
#ifdef BFLT_AUTH_BURN
|
||||
u32 bflt_norflash_read_otp(u8 *buffer, u32 len, u32 offset) ;
|
||||
u32 bflt_norflash_write_otp(u8 *buffer, u32 len, u32 offset) ;
|
||||
u32 bflt_norflash_erase_otp(u32 offset) ;
|
||||
u32 norflash_otp_lock(u8 *custom) ;
|
||||
#endif
|
||||
|
||||
void norflash_enter_powerdown(void);
|
||||
void norflash_powerdown_release(u32 delay);
|
||||
void norflash_soft_reset(u32 delay);
|
||||
|
||||
void norflash_init(struct flash_platform_data *pdata);
|
||||
|
||||
void norflash_read_bt_mac(u8 *mac);
|
||||
|
||||
int norflash_ioctl(u32 cmd, u32 arg);
|
||||
|
||||
void norflash_select_device(u32 index, u32 port);
|
||||
|
||||
u8 P25QXXH_flash_close_quad_page_mode();
|
||||
|
||||
extern const struct device_operations norflash_dev_ops;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef __JLFS_H__
|
||||
#define __JLFS_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
u32 addr; //flash里的绝对地址
|
||||
u32 size; //文件大小
|
||||
u32 pos; //操作的偏移量
|
||||
u32 res; //预留参数
|
||||
} JLFS_FILE;
|
||||
|
||||
struct jlfs_flash_head {
|
||||
u16 head_crc;
|
||||
u16 size4burner;
|
||||
char vid[4];
|
||||
u32 flash_size;
|
||||
u8 fs_version;
|
||||
u8 BlockAlignSize;
|
||||
u16 SpecialOptFlag;
|
||||
char pid[16];
|
||||
};
|
||||
|
||||
struct jlfs_file_head {
|
||||
u16 head_crc;
|
||||
u16 data_crc;
|
||||
u32 addr;
|
||||
u32 len;
|
||||
u8 attr;
|
||||
u8 res;
|
||||
u16 index;
|
||||
char name[16];
|
||||
};
|
||||
|
||||
struct jlfs_app_info_head {
|
||||
u16 head_crc;
|
||||
u16 data_crc;
|
||||
u16 encodedata_crc;
|
||||
u16 version;
|
||||
u32 len;
|
||||
u32 reserved;
|
||||
char name[16];
|
||||
};
|
||||
|
||||
|
||||
void *get_global_buffer(u32 size);
|
||||
|
||||
u32 jlfs_get_flash_align_size(void);
|
||||
u32 jlfs_get_flash_app_base_addr(void);
|
||||
u32 jlfs_get_flash_eoffset_size(void);
|
||||
u32 jlfs_get_app_entry_addr(void);
|
||||
u8 *jlfs_get_isd_cfg_ptr(void);
|
||||
u8 jlfs_read_isd_cfg_ini(const char *cfg, void *value);
|
||||
u8 jlfs_mount(void);
|
||||
u8 jlfs_fopen_by_addr(JLFS_FILE *file, u32 addr);
|
||||
u8 jlfs_fopen_by_name(JLFS_FILE *file, const char *name, u8 mode);
|
||||
u32 jlfs_fread(JLFS_FILE *file, u8 *buf, u32 len);
|
||||
u32 jlfs_erase(JLFS_FILE *file, u32 len);
|
||||
u32 jlfs_write(JLFS_FILE *file, u8 *buf, u32 len);
|
||||
void jlfs_fseek(JLFS_FILE *file, u32 offset);
|
||||
void jlfs_get_pid_vid(u8 *pid, u8 *vid);
|
||||
void jlfs_get_bt_mac(u8 *mac);
|
||||
u32 jlfs_get_flen_by_name(const char *name);
|
||||
u32 jlfs_get_idle_bank_info(JLFS_FILE *file, u32 mode);
|
||||
u32 jlfs_updata_dual_bank_info(JLFS_FILE *file, u16 data_crc);
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 选择哪个code跑,必须在 jlfs_mount() 前调用才有效
|
||||
*
|
||||
* @param code_index 0:code0 1:code1 -1:自动切换(原模式) >1的数值会被强制为code0
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void jlfs_dual_bank_choose_code(u8 code_index);
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef __UPGRADE_H__
|
||||
#define __UPGRADE_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
void *get_sdk_swap_addr();
|
||||
void goto_uart_upgrade(void);
|
||||
void goto_mask_usb_updata(void);
|
||||
u8 update_loop_run(u32 flash_ota_addr);
|
||||
u8 jl_check_upgrade(u8 jlfs_err);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef __POWER_RESET_H__
|
||||
#define __POWER_RESET_H__
|
||||
|
||||
enum RESET_FLAG {
|
||||
RESET_FLAG_RESERVE,
|
||||
EXCEPTION_FLAG,
|
||||
ASSERT_FLAG,
|
||||
UPDATE_FLAG,
|
||||
BT_FLAG,
|
||||
LP_OSC_UP_TO,
|
||||
};
|
||||
|
||||
void system_reset(enum RESET_FLAG flag);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,237 @@
|
||||
#ifndef __ALL_INCLUDE_H__
|
||||
#define __ALL_INCLUDE_H__
|
||||
|
||||
//#include <string.h>
|
||||
#include "typedef.h"
|
||||
#include "common.h"
|
||||
#include "printf.h"
|
||||
|
||||
#define UPDATE_GET_POWER_PIN 1 //获取power_pin脚
|
||||
#define MUTIL_CPU_ENABLE 1 //多芯片升级支持
|
||||
#define OTA_LOADER_RECORD_RST_INFO_CONFIG 1 //升级记录复位信息
|
||||
#define OSC_1PIN_STABLE_EN 1 //osc 单脚牵引
|
||||
|
||||
//控制起来省空间。
|
||||
#if defined(CONFIG_CPU_BR28) || defined(CONFIG_CPU_BR27) || defined(CONFIG_CPU_BR29) || defined(CONFIG_CPU_BR35)
|
||||
#define UPDATE_COMPATIBILITY_EN 1 //升级兼容性处理
|
||||
#else
|
||||
#define UPDATE_COMPATIBILITY_EN 0 //升级兼容性处理
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CPU_BD49) || defined(CONFIG_CPU_SH58)
|
||||
#undef UPDATE_GET_POWER_PIN
|
||||
#undef MUTIL_CPU_ENABLE
|
||||
#undef OTA_LOADER_RECORD_RST_INFO_CONFIG
|
||||
|
||||
#define UPDATE_GET_POWER_PIN 0 //获取power_pin脚
|
||||
#define MUTIL_CPU_ENABLE 0 //多芯片升级支持
|
||||
#define OTA_LOADER_RECORD_RST_INFO_CONFIG 0 //升级记录复位信息
|
||||
#endif
|
||||
|
||||
#if OTA_LOADER_RECORD_RST_INFO_CONFIG
|
||||
typedef struct {
|
||||
///////////reset info////////////
|
||||
u32 p3_rst_flag;
|
||||
u32 p3_rst_src;
|
||||
u32 p11_clock_pwr_con;
|
||||
u32 p11_closk_rst_src;
|
||||
u32 jl_lsbclk_pwr_con;
|
||||
u32 jl_lsbrst_rst_src;
|
||||
///////////exeception info////////////
|
||||
u32 rets;
|
||||
u32 reti;
|
||||
u32 icfg;
|
||||
u32 pc_trace5;
|
||||
u32 pc_trace4;
|
||||
u32 pc_trace3;
|
||||
u32 pc_trace2;
|
||||
u32 pc_trace1;
|
||||
u32 pc_trace0;
|
||||
u32 emu_msg;
|
||||
u32 cemu_msg0;
|
||||
u32 cemu_msg1;
|
||||
u32 cemu_msg2;
|
||||
u32 cemu_id;
|
||||
u32 hemu_msg0;
|
||||
u32 hemu_id;
|
||||
u32 lemu_msg0;
|
||||
u32 lemu_id;
|
||||
} RESET_INFO;
|
||||
|
||||
u8 ota_loader_record_rst_info();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*FPGA调试*/
|
||||
//#define FPGA_MODE_DEBUG
|
||||
|
||||
/*串口打印控制器IO口占据*/
|
||||
#define UART_ENABLE
|
||||
//br23 用dp,br30yong usbdp
|
||||
|
||||
#define UART_DEBUG_IO "PA05"
|
||||
#define UART_DEBUG_BAUD 1000000
|
||||
/*打印调试信息*/
|
||||
#if defined(CONFIG_CPU_BR22) || defined(CONFIG_CPU_BR26)
|
||||
#define UART_API_USING_MASKROM_EN 0
|
||||
#else
|
||||
#define UART_API_USING_MASKROM_EN 0
|
||||
#endif
|
||||
|
||||
/*升级设备在线检测使能位*/
|
||||
#define UPDATA_DEV_ONLINE_CHECK_EN 0
|
||||
#define UPDATA_FLASH_CONTROL 1//升级使能
|
||||
|
||||
#define BT_BREDR_EN BIT(0)
|
||||
#define BT_BLE_EN BIT(1)
|
||||
#define BT_NOMALE_POWER_CFG 0 //模拟正常配置
|
||||
#define BT_LOW_POWER_CFG 1 //模拟低功耗配置
|
||||
|
||||
#define BT_ANALOG_CFG BT_NOMALE_POWER_CFG //模拟配置
|
||||
|
||||
enum {
|
||||
BT_UPDATA_POWER_ON,
|
||||
BT_UPDATA_JUMP_APP,
|
||||
|
||||
};
|
||||
enum {
|
||||
REQUES_CHECK_DATA = 0,
|
||||
REQUES_READ_DATA = 1,
|
||||
REQUES_STOP_DATA = 2,
|
||||
};
|
||||
|
||||
|
||||
#ifdef BLE_UPDATA_SUPPORT_CONNECT
|
||||
// huayue add 2017/1/12
|
||||
#define BT_POWER_MODE_ENABLE 0
|
||||
#define BLE_ENCRYPT_ENABLE 0
|
||||
#define BLE_PRIVACY_ENABLE 0
|
||||
#define BLE_MASTER_ENABLE 0
|
||||
#define THREAD_DEBUG_EN 1
|
||||
#define BQB_RF_SET_DEBUG_EN 1
|
||||
#define BQB_SYS_TIMER_DEBYG_EN 1
|
||||
#define BLE_ATT_ENCRYPT_EN 0
|
||||
#else
|
||||
#define BT_POWER_MODE_ENABLE 0
|
||||
#define BLE_ENCRYPT_ENABLE 0
|
||||
#define BLE_PRIVACY_ENABLE 0
|
||||
#define BLE_MASTER_ENABLE 0
|
||||
#define THREAD_DEBUG_EN 0
|
||||
#define BQB_RF_SET_DEBUG_EN 0
|
||||
#define BQB_SYS_TIMER_DEBYG_EN 0
|
||||
#define BLE_ATT_ENCRYPT_EN 0
|
||||
|
||||
#endif
|
||||
|
||||
//配置是否支持uboot升级
|
||||
#if defined(CONFIG_CPU_BR22) || defined(CONFIG_CPU_BR21) || defined(CONFIG_CPU_BR18)
|
||||
#define ALL_FLASH_INCLUDE_UBOOT_UPDATE_EN 0
|
||||
#else //BR23/BR25/BR26/BR30/BD29
|
||||
#define ALL_FLASH_INCLUDE_UBOOT_UPDATE_EN 1
|
||||
#endif
|
||||
|
||||
//br18 & br22 origin version
|
||||
#define FLASH_FRAMEWORK_VERSION_V1_EN 0
|
||||
//br22 new flash framwork
|
||||
#define FLASH_FRAMEWORK_VERSION_V2_EN 1
|
||||
|
||||
|
||||
//配置单独配置升级采用什么格式
|
||||
#define FORMAT_BR22_NEW 0
|
||||
#define FORMAT_BR18_V2 1
|
||||
|
||||
#ifdef CONFIG_CPU_BR22
|
||||
#define CFG_TOOL_BIN_FORMAT_SEL FORMAT_BR22_NEW
|
||||
#else //BR18/BR26/BR23/BD29/BR21/BR25/BR30
|
||||
#define CFG_TOOL_BIN_FORMAT_SEL FORMAT_BR18_V2
|
||||
#endif
|
||||
|
||||
//配置是否支持外部用户接口
|
||||
#if defined(CONFIG_CPU_BR23) || defined(CONFIG_CPU_BR28) || defined(CONFIG_CPU_BR35)
|
||||
#define USER_API_CODE_SUPPORT_EN 1
|
||||
#else
|
||||
#define USER_API_CODE_SUPPORT_EN 0
|
||||
#endif
|
||||
|
||||
//是否SPI0只采用TEAM A;
|
||||
#define SPI0_PORT_TEAM_A_ONLY_EN 1
|
||||
|
||||
/*是否开启电量检测*/
|
||||
#define LOW_POWER_DET_EN 0
|
||||
|
||||
//是否支持升级外部DSP
|
||||
#if defined(CONFIG_CPU_BR22) && (EDR_UPDATA_SUPPORT_CONNECT)
|
||||
#define EX_DSP_UPDATE_SUPPORT_EN 0
|
||||
#else
|
||||
#define EX_DSP_UPDATE_SUPPORT_EN 0
|
||||
#endif
|
||||
|
||||
// #if defined(CONFIG_CPU_BR23)
|
||||
// #define EX_FLASH_UPDATE_SUPPORT_EN 1
|
||||
// #else
|
||||
// #define EX_FLASH_UPDATE_SUPPORT_EN 0
|
||||
// #endif
|
||||
|
||||
#if defined(CONFIG_CPU_BR23) && (EDR_UPDATA_SUPPORT_CONNECT)
|
||||
//配置:经典蓝牙升级速度优化方案
|
||||
//1.utilized the time waiting for rsp to program flash;
|
||||
#define OTA_UPDATE_SPEED_OPTIMIZE_METHOD_1 1
|
||||
//2.utilized the time waiting for programming to receive rsp data;
|
||||
#define OTA_UPDATE_SPEED_OPTIMIZE_METHOD_2 1
|
||||
#else
|
||||
//配置:经典蓝牙升级速度优化方案
|
||||
//1.utilized the time waiting for rsp to program flash;
|
||||
#define OTA_UPDATE_SPEED_OPTIMIZE_METHOD_1 0
|
||||
//2.utilized the time waiting for programming to receive rsp data;
|
||||
#define OTA_UPDATE_SPEED_OPTIMIZE_METHOD_2 0
|
||||
|
||||
#endif
|
||||
|
||||
//支持ANC配置和系数升级使能
|
||||
#if (defined(CONFIG_CPU_BR30) \
|
||||
|| defined(CONFIG_CPU_BR34) \
|
||||
|| defined(CONFIG_CPU_BR36) \
|
||||
|| defined(CONFIG_CPU_BR28) \
|
||||
|| defined(CONFIG_CPU_WL80)) \
|
||||
|| defined(CONFIG_CPU_BR50) \
|
||||
|| defined(CONFIG_CPU_BR35) \
|
||||
|| defined(CONFIG_CPU_BR52) \
|
||||
&& defined(EDR_UPDATA_SUPPORT_CONNECT) || defined(UART_UPDATA_MODULE_CONTROL)
|
||||
#define ANC_CFG_AND_COEF_UPDATE_EN 1
|
||||
#else
|
||||
#define ANC_CFG_AND_COEF_UPDATE_EN 0
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CPU_BR42) || defined(CONFIG_CPU_BR46)
|
||||
#define UPDATE_EFUSE 1
|
||||
#else
|
||||
#define UPDATE_EFUSE 0
|
||||
#endif
|
||||
|
||||
//配置:是否升级保留区域文件(anc param .ect)
|
||||
#if (CONFIG_CPU_BR30) || (CONFIG_CPU_BR34) || (CONFIG_CPU_BR36) || (CONFIG_CPU_BR28) || (CONFIG_CPU_BR50) || defined(CONFIG_CPU_BR35) || defined(CONFIG_CPU_BR52) || defined(CONFIG_CPU_BR56)
|
||||
#define RESERVED_FILE_UPDATE_EN 1
|
||||
#else
|
||||
#define RESERVED_FILE_UPDATE_EN 0
|
||||
#endif
|
||||
|
||||
//支持免晶振方案
|
||||
#if (SD_MODULE_CONTROL || USB_HOST_MODULE_CONTROL || UART_UPDATA_USER_MODULE_CONTROL) && (defined(CONFIG_CPU_BR23) || defined(CONFIG_CPU_BR25))
|
||||
#define CRYSTAL_FREE_EN 1
|
||||
#else
|
||||
#define CRYSTAL_FREE_EN 0
|
||||
#endif
|
||||
|
||||
//仅支持串口测试模式
|
||||
#define UART_UPDATE_ONLY_TEST_MODE 0
|
||||
|
||||
//蓝牙升级仅测试模式
|
||||
#define BT_UPDATE_ONLY_TEST_MODE 0
|
||||
//蓝牙测试模式是否不需要回连
|
||||
#define BT_UPDATE_ONLY_TEST_WITHOUT_RECONNECT 0
|
||||
|
||||
#if FLASH_FRAMEWORK_VERSION_V1_EN && FLASH_FRAMEWORK_VERSION_V2_EN
|
||||
#error "FLASH_FRAMEWORK_VERSION_1&2 NOT OPEN IN SAME TIME!!!\n"
|
||||
#endif
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,383 @@
|
||||
|
||||
#ifndef ASM_CPU_H
|
||||
#define ASM_CPU_H
|
||||
|
||||
|
||||
#include "sfr.h"
|
||||
#include "csfr.h"
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
typedef unsigned char u8, bool, BOOL;
|
||||
typedef char s8;
|
||||
typedef unsigned short u16;
|
||||
typedef signed short s16;
|
||||
typedef unsigned int u32;
|
||||
typedef signed int s32;
|
||||
typedef unsigned long long u64;
|
||||
typedef u32 FOURCC;
|
||||
typedef long long s64;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define ___trig __asm__ volatile ("trigger")
|
||||
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
#define BIG_ENDIAN 0x3021
|
||||
#endif
|
||||
#ifndef LITTLE_ENDIAN
|
||||
#define LITTLE_ENDIAN 0x4576
|
||||
#endif
|
||||
#define CPU_ENDIAN LITTLE_ENDIAN
|
||||
|
||||
#ifdef BT_DUT_INTERFERE
|
||||
#define CPU_CORE_NUM 1 //dut interfere
|
||||
#else
|
||||
#define CPU_CORE_NUM 1 //sdk
|
||||
#endif
|
||||
|
||||
#define OS_CORE_AFFINITY_ENABLE 1
|
||||
|
||||
|
||||
#define CPU_TASK_CLR(a)
|
||||
#define CPU_TASK_SW(a) \
|
||||
do { \
|
||||
q32DSP(a)->ILAT_SET |= BIT(3-a); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define CPU_INT_NESTING 2
|
||||
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#if CPU_CORE_NUM > 1
|
||||
__attribute__((always_inline))
|
||||
static int current_cpu_id()
|
||||
{
|
||||
unsigned id;
|
||||
asm volatile("%0 = cnum" : "=r"(id) ::);
|
||||
return id ;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static int core_num(void)
|
||||
{
|
||||
u32 num;
|
||||
asm volatile("%0 = cnum" : "=r"(num) :);
|
||||
return num;
|
||||
}
|
||||
|
||||
#else
|
||||
static inline int current_cpu_id()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int core_num(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int cpu_in_irq()
|
||||
{
|
||||
int flag;
|
||||
__asm__ volatile("%0 = icfg" : "=r"(flag));
|
||||
return flag & 0xff;
|
||||
}
|
||||
|
||||
static inline int cpu_irq_disabled()
|
||||
{
|
||||
int flag;
|
||||
__asm__ volatile("%0 = icfg" : "=r"(flag));
|
||||
return (flag & 0x300) != 0x300;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static inline int data_sat_s16(int ind)
|
||||
{
|
||||
if (ind > 32767) {
|
||||
ind = 32767;
|
||||
} else if (ind < -32768) {
|
||||
ind = -32768;
|
||||
}
|
||||
return ind;
|
||||
}
|
||||
|
||||
#else
|
||||
static inline int data_sat_s16(int ind)
|
||||
{
|
||||
__asm__ volatile(
|
||||
" %0 = sat16(%0)(s) \t\n"
|
||||
: "=&r"(ind)
|
||||
: "0"(ind)
|
||||
:);
|
||||
return ind;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static inline u32 reverse_u32(u32 data32)
|
||||
{
|
||||
#if 0
|
||||
u8 *dataptr = (u8 *)(&data32);
|
||||
data32 = (((u32)dataptr[0] << 24) | ((u32)dataptr[1] << 16) | ((u32)dataptr[2] << 8) | (u32)dataptr[3]);
|
||||
#else
|
||||
__asm__ volatile("%0 = rev8(%0) \t\n" : "=&r"(data32) : "0"(data32) :);
|
||||
#endif
|
||||
return data32;
|
||||
}
|
||||
|
||||
static inline u32 reverse_u16(u16 data16)
|
||||
{
|
||||
u32 retv;
|
||||
#if 0
|
||||
u8 *dataptr = (u8 *)(&data16);
|
||||
retv = (((u32)dataptr[0] << 8) | ((u32)dataptr[1]));
|
||||
#else
|
||||
retv = ((u32)data16) << 16;
|
||||
__asm__ volatile("%0 = rev8(%0) \t\n" : "=&r"(retv) : "0"(retv) :);
|
||||
#endif
|
||||
return retv;
|
||||
}
|
||||
|
||||
static inline u32 rand32()
|
||||
{
|
||||
return JL_RAND->R64L;
|
||||
}
|
||||
|
||||
#define __asm_sine(s64, precision) \
|
||||
({ \
|
||||
u64 ret; \
|
||||
u8 sel = 0; \
|
||||
__asm__ volatile ("%0 = copex(%1) (%2)" : "=r"(ret) : "r"(s64), "i"(sel)); \
|
||||
ret = ret>>32; \
|
||||
ret;\
|
||||
})
|
||||
|
||||
void p33_soft_reset(void);
|
||||
static inline void cpu_reset(void)
|
||||
{
|
||||
// JL_CLOCK->PWR_CON |= (1 << 4);
|
||||
p33_soft_reset();
|
||||
}
|
||||
|
||||
#define __asm_csync() \
|
||||
do { \
|
||||
asm volatile("csync;"); \
|
||||
} while (0)
|
||||
|
||||
#include "irq.h"
|
||||
#include "printf.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
#define arch_atomic_read(v) \
|
||||
({ \
|
||||
__asm_csync(); \
|
||||
(*(volatile int *)&(v)->counter); \
|
||||
})
|
||||
#if 0
|
||||
extern volatile int cpu_lock_cnt[];
|
||||
extern volatile int irq_lock_cnt[];
|
||||
|
||||
|
||||
static inline void local_irq_disable()
|
||||
{
|
||||
__builtin_pi32v2_cli();
|
||||
irq_lock_cnt[current_cpu_id()]++;
|
||||
}
|
||||
|
||||
|
||||
static inline void local_irq_enable()
|
||||
{
|
||||
if (--irq_lock_cnt[current_cpu_id()] == 0) {
|
||||
__builtin_pi32v2_sti();
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
extern void __local_irq_disable() ;
|
||||
|
||||
extern void __local_irq_enable() ;
|
||||
|
||||
extern void local_irq_disable();
|
||||
extern void local_irq_enable();
|
||||
|
||||
#endif
|
||||
|
||||
#if(0 )
|
||||
|
||||
#define arch_spin_trylock(lock) \
|
||||
do { \
|
||||
__asm_csync(); \
|
||||
while ((lock)->rwlock); \
|
||||
(lock)->rwlock = 1; \
|
||||
}while(0)
|
||||
|
||||
#define arch_spin_lock(lock) \
|
||||
do { \
|
||||
int ret = false; \
|
||||
__asm_csync(); \
|
||||
if (!(lock)->rwlock) { \
|
||||
ret = true; \
|
||||
(lock)->rwlock = 1; \
|
||||
} \
|
||||
if (ret) \
|
||||
break; \
|
||||
}while(1)
|
||||
|
||||
#define arch_spin_unlock(lock) \
|
||||
do { \
|
||||
(lock)->rwlock = 0; \
|
||||
}while(0)
|
||||
|
||||
#else
|
||||
|
||||
|
||||
|
||||
static inline void q32DSP_testset(u32 volatile *ptr)
|
||||
{
|
||||
asm volatile(
|
||||
" 1: \n\t "
|
||||
" testset b[%0] \n\t "
|
||||
" ifeq goto 1b \n\t "
|
||||
:
|
||||
: "p"(ptr)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
static inline void q32DSP_testclr(u32 volatile *ptr)
|
||||
{
|
||||
asm volatile(
|
||||
" b[%0] = %1 \n\t "
|
||||
:
|
||||
: "p"(ptr), "r"(0)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
#define arch_spin_trylock(lock) \
|
||||
do { \
|
||||
q32DSP_testset(&lock->rwlock);\
|
||||
}while(0)
|
||||
|
||||
|
||||
#define arch_spin_lock(lock) arch_spin_trylock(lock)
|
||||
|
||||
#define arch_spin_unlock(lock) \
|
||||
do{ \
|
||||
q32DSP_testclr(&lock->rwlock) ;\
|
||||
}while(0)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if 1 // CPU_CORE_NUM >1
|
||||
|
||||
extern volatile int cpu_lock_cnt[];
|
||||
extern volatile int irq_lock_cnt[];
|
||||
#if 0
|
||||
#define CPU_SR_ALLOC() \
|
||||
// int flags
|
||||
|
||||
|
||||
|
||||
|
||||
#define CPU_CRITICAL_ENTER() \
|
||||
do { extern u8 volatile cpulock;\
|
||||
local_irq_disable(); \
|
||||
if(cpu_lock_cnt[current_cpu_id()]++ == 0) \
|
||||
q32DSP_testset(&cpulock);\
|
||||
__asm_csync(); \
|
||||
}while(0)
|
||||
|
||||
// asm volatile("lockset;");
|
||||
|
||||
#define CPU_CRITICAL_EXIT() \
|
||||
do {extern u8 volatile cpulock; \
|
||||
if (--cpu_lock_cnt[current_cpu_id()] == 0) \
|
||||
q32DSP_testclr(&cpulock);\
|
||||
local_irq_enable();\
|
||||
}while(0)
|
||||
|
||||
#endif
|
||||
|
||||
static inline int get_random()
|
||||
{
|
||||
return JL_RAND->R64L;
|
||||
}
|
||||
|
||||
#define OS_SR_ALLOC()
|
||||
|
||||
#define OS_ENTER_CRITICAL() \
|
||||
CPU_CRITICAL_ENTER(); \
|
||||
|
||||
#define OS_EXIT_CRITICAL() \
|
||||
CPU_CRITICAL_EXIT()
|
||||
|
||||
#define CPU_SR_ALLOC() \
|
||||
// int flags
|
||||
|
||||
#define CPU_CRITICAL_ENTER() \
|
||||
do { \
|
||||
local_irq_disable(); \
|
||||
}while(0)
|
||||
|
||||
|
||||
#define CPU_CRITICAL_EXIT() \
|
||||
do { \
|
||||
local_irq_enable(); \
|
||||
}while(0)
|
||||
|
||||
// asm volatile("lockclr;");
|
||||
#else
|
||||
|
||||
|
||||
#define CPU_SR_ALLOC() \
|
||||
// int flags
|
||||
|
||||
#define CPU_CRITICAL_ENTER() \
|
||||
do { \
|
||||
local_irq_disable(); \
|
||||
__asm_csync(); \
|
||||
}while(0)
|
||||
|
||||
|
||||
#define CPU_CRITICAL_EXIT() \
|
||||
do { \
|
||||
local_irq_enable(); \
|
||||
}while(0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
extern void cpu_assert_debug();
|
||||
extern const int config_asser;
|
||||
#define ASSERT(a,...) \
|
||||
do { \
|
||||
if(1 /* config_asser */){\
|
||||
if(!(a)){ \
|
||||
printf("cpu %d file:%s, line:%d",current_cpu_id(), __FILE__, __LINE__); \
|
||||
printf("ASSERT-FAILD: "#a" "__VA_ARGS__); \
|
||||
cpu_assert_debug(); \
|
||||
} \
|
||||
}else {\
|
||||
if(!(a)){ \
|
||||
cpu_reset(); \
|
||||
}\
|
||||
}\
|
||||
}while(0);
|
||||
|
||||
|
||||
|
||||
#endif //__ASSEMBLY__
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
|
||||
|
||||
|
||||
#define CDBG_IDx(n, id) ((1<<(n+4)) | (id<<(n*8+8)))
|
||||
#define CDBG_INV (1<<7)
|
||||
#define CDBG_PEN (1<<3)
|
||||
#define CDBG_XEN (1<<2)
|
||||
#define CDBG_WEN (1<<1)
|
||||
#define CDBG_REN (1<<0)
|
||||
|
||||
void debug_init();
|
||||
void exception_analyze();
|
||||
|
||||
/********************************** DUBUG SFR *****************************************/
|
||||
|
||||
u32 get_dev_id(char *name);
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief Memory权限保护设置
|
||||
*
|
||||
* @param idx: 保护框索引, 范围: 0 ~ 3, 目前系统默认使用0和3, 用户可用1和2
|
||||
* @param begin: Memory开始地址
|
||||
* @param end: Memory结束地址
|
||||
* @param inv: 0: 保护框内, 1: 保护框外
|
||||
* @param format: "Cxwr0rw1rw2rw3rw", CPU:外设0:外设1:外设2:外设3,
|
||||
* @param ...: 外设ID号索引, 如: DBG_EQ, 见debug.h
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void mpu_set(int idx, u32 begin, u32 end, u32 inv, const char *format, ...);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief 取消指定框的mpu保护
|
||||
*
|
||||
* @param idx: 保护框索引号
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void mpu_disable_by_index(u8 idx);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief :取消所有保护框mpu保护
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void mpu_diasble(void);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief flash PC范围设置为Flash外区域, 调用该接口后调用flash里的函数将触发异常
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void flash_pc_limit_disable();
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief flash PC范围限制恢复为flash代码区域, 调用该接口后可调用flash里的函数
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void flash_pc_limit_enable();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*-----------------------------------------------------------------------
|
||||
/ Low level disk interface modlue include file R0.06 (C)ChaN, 2007
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO
|
||||
|
||||
|
||||
|
||||
// #include "logic_include.h"
|
||||
//#ifdef __ICC8051__
|
||||
/* Status of Disk Functions */
|
||||
typedef u8 DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
///#endif
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
//DSTATUS disk_initialize (BYTE);
|
||||
//DSTATUS disk_status (BYTE);
|
||||
//DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
|
||||
//#if _READONLY == 0
|
||||
//DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
|
||||
//#endif
|
||||
//DRESULT disk_ioctl (BYTE, BYTE, void*);
|
||||
//void disk_timerproc (void);
|
||||
|
||||
|
||||
#define _READONLY 0 /* 1: Read-only mode */
|
||||
#define _USE_IOCTL 1
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl() */
|
||||
|
||||
/* Generic command */
|
||||
#define CTRL_SYNC 0 /* Mandatory for read/write configuration */
|
||||
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
|
||||
#define GET_SECTOR_SIZE 2
|
||||
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
|
||||
#define CTRL_POWER 4
|
||||
#define CTRL_LOCK 5
|
||||
#define CTRL_EJECT 6
|
||||
/* MMC/SDC command */
|
||||
#define MMC_GET_TYPE 10
|
||||
#define MMC_GET_CSD 11
|
||||
#define MMC_GET_CID 12
|
||||
#define MMC_GET_OCR 13
|
||||
#define MMC_GET_SDSTAT 14
|
||||
/* ATA/CF command */
|
||||
#define ATA_GET_REV 20
|
||||
#define ATA_GET_MODEL 21
|
||||
#define ATA_GET_SN 22
|
||||
|
||||
|
||||
#define _DISKIO
|
||||
#endif
|
||||
@@ -0,0 +1,448 @@
|
||||
#ifndef _FATFS_H
|
||||
#define _FATFS_H
|
||||
|
||||
|
||||
#include "common.h"
|
||||
#include "diskio.h"
|
||||
// #include "logic_include.h"
|
||||
|
||||
|
||||
#define MAX_DEEPTH 2 /* 0~9 deepth of system */
|
||||
|
||||
#define LFN_MAX_SIZE 512 //不能超过512
|
||||
/*******************************************************/
|
||||
/********************驱动调试信息***********************/
|
||||
/*******************************************************/
|
||||
//#define FS_DEBUG
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
#define fs_deg printf
|
||||
#define fs_deg_puts printf
|
||||
#define fs_deg_buf printf_buf
|
||||
#define fs_deg_data printf_data
|
||||
#else
|
||||
#define fs_deg(...)
|
||||
#define fs_deg_puts(...)
|
||||
#define fs_deg_buf(...)
|
||||
#define fs_deg_data(...)
|
||||
#endif
|
||||
|
||||
#define FS_LD_WORD(p) ld_word_func(p)//(u16)(*(u16*)(u8*)(ptr))
|
||||
#define FS_LD_DWORD(p) ld_dword_func(p)//(u32)(*(u32*)(u8*)(ptr))
|
||||
|
||||
#define FS_ST_WORD(ptr,val) st_word_func((u8 *)(ptr),(u16)(val)) //(u16)(*(u16*)(u8*)(ptr))
|
||||
#define FS_ST_DWORD(ptr,val) st_dword_func((u8 *)(ptr),(u32)(val)) //(u32)(*(u32*)(u8*)(ptr))
|
||||
|
||||
|
||||
|
||||
|
||||
typedef u32 CLUST;
|
||||
|
||||
#define FS_WRITE_EN /* 是否允许写文件 */
|
||||
#ifdef FS_WRITE_EN
|
||||
#define FAT12_WRITE_EN
|
||||
//#define EXFAT_WRITE_EN
|
||||
#endif
|
||||
#define WIN_DATA_DIRTY 0x08
|
||||
/* File system API info */
|
||||
typedef struct _FSAPIMSG {
|
||||
u16 musicdir_counter; // 包含指定文件的文件夹序号
|
||||
u16 dir_counter; // 文件夹序号
|
||||
u16 file_total_indir; // 当前目录的根下有效文件的个数
|
||||
u16 file_total_outdir; // 当前目录前的文件总数,目录循环模式下,需要用它来计算文件序号
|
||||
u16 file_number; // 当前文件序号
|
||||
u16 file_counter; //用于搜索文件计数
|
||||
u8 deepth; // dir deepth for search
|
||||
} FSAPIMSG;
|
||||
|
||||
typedef struct _SWIN_BUF {
|
||||
u8 start[512];
|
||||
u32 sector;
|
||||
struct _FATFS *fs;
|
||||
u8 flag;
|
||||
} SWIN_BUF;
|
||||
/*
|
||||
#define FS_WIN_START fs->win->start
|
||||
#define FS_WIN_SECTOR fs->win->sector
|
||||
#define FS_WIN_FLAG fs->win->flag
|
||||
*/
|
||||
#define FS_WIN_START fs->win.start
|
||||
#define FS_WIN_SECTOR fs->win.sector
|
||||
#define FS_WIN_FLAG fs->win.flag
|
||||
|
||||
/* File system object structure */
|
||||
struct _FATFS {
|
||||
//SWIN_BUF *win; /* Disk access window for Directory/FAT/File */
|
||||
u32 fatbase; /* FAT start sector */
|
||||
u32 dirbase; /* Root directory start sector */
|
||||
u32 database; /* Data start sector */
|
||||
u32 n_fatent; /* Maximum cluster# + 1 */
|
||||
#ifdef FS_WRITE_EN
|
||||
u8 write_en; //文件系统是否允许写操作:只允许FAT16,FAT32并且sector size只能是512bytes
|
||||
u8 fsi_flag; /* fsinfo dirty flag (1:must be written back) */
|
||||
u32 last_clust; /* Last allocated cluster */
|
||||
u32 fsi_sector; /* fsinfo sector (FAT32) */
|
||||
#endif
|
||||
u32 boot_sect;
|
||||
u16 n_rootdir; /* Number of root directory entries */
|
||||
u16 total_file; /* 当前设备的匹配文件总数*/
|
||||
u8 s_size; /* sector size, 2 power n*/
|
||||
u8 csize; /* Number of sectors per cluster,2 power n */
|
||||
u8 fs_type; /* FAT sub type */
|
||||
u8 secotr_512size; /* size of per sector */
|
||||
u32(*disk_read)(u8 *buf, u32 lba); /* device read function */
|
||||
u32(*disk_write)(u8 *buf, u32 lba); /* device write function */
|
||||
u32 fat_time;
|
||||
// u8 *lfn; //长文件名buffer
|
||||
// u16 lfn_cnt;
|
||||
// char *tpath; //路径名称buffer
|
||||
void *hdev;
|
||||
SWIN_BUF win; /* Disk access window for Directory/FAT/File */
|
||||
u8 drive_cnt;
|
||||
//FSAPIMSG *fs_msg;
|
||||
};
|
||||
typedef struct _FATFS FATFS;
|
||||
|
||||
|
||||
struct _FS_NAME {
|
||||
char tpath[128]; //路径名称buffer
|
||||
char *lfn; //长文件名buffer
|
||||
u16 lfn_cnt;
|
||||
|
||||
};
|
||||
typedef struct _FS_NAME FS_NAME;
|
||||
|
||||
typedef u32(*disk_read)(u8 *buf, u32 lba);
|
||||
typedef u32(*disk_write)(u8 *buf, u32 lba);
|
||||
|
||||
|
||||
/* Directory object structure */
|
||||
typedef struct _DIR {
|
||||
u32 clust; /* Current cluster */
|
||||
u32 csect; /* Current sector */
|
||||
u32 sclust; /* Start cluster */
|
||||
u16 cindex; /* Current index */
|
||||
//u16 lfn_index; /* 长文件名index号 */
|
||||
} DIR;
|
||||
|
||||
/* DIR status structure */
|
||||
typedef struct _DIRINFO {
|
||||
DIR dj;
|
||||
u32 sclust; /* File start cluster */
|
||||
u32 fsize; /* Size */
|
||||
u8 fattrib; /* Attribute */
|
||||
char fname[12]; /* */
|
||||
} DIRINFO;
|
||||
|
||||
/* File object structure */
|
||||
/*
|
||||
typedef struct _FIL
|
||||
{
|
||||
u32 fptr; // File R/W pointer
|
||||
//u32 fsize; // File size
|
||||
u8 flag;
|
||||
SWIN_BUF *data_win;
|
||||
u32 csect; // Current sector
|
||||
u32 clust; // Current cluster
|
||||
//u32 sclust; // File start cluster
|
||||
#ifdef FS_WRITE_EN
|
||||
SWIN_BUF *dir_win;
|
||||
u8 dir_duty;
|
||||
#endif
|
||||
u32 start_clust;
|
||||
u32 end_clust;
|
||||
FATFS *fs;
|
||||
DIRINFO dir_info; //文件的目录项信息
|
||||
FSAPIMSG fs_msg;
|
||||
} FIL;
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef struct _FIL0 {
|
||||
u32 fptr; // File R/W pointer
|
||||
//u32 fsize; // File size
|
||||
u8 flag;
|
||||
SWIN_BUF data_win;
|
||||
u32 csect; // Current sector
|
||||
u32 clust; // Current cluster
|
||||
//u32 sclust; // File start cluster
|
||||
#ifdef FS_WRITE_EN
|
||||
SWIN_BUF dir_win;
|
||||
u8 dir_duty;
|
||||
#endif
|
||||
u32 start_clust;
|
||||
u32 end_clust;
|
||||
FATFS *fs;
|
||||
} FIL0;
|
||||
|
||||
typedef struct _FIL {
|
||||
FIL0 fil;
|
||||
DIRINFO dir_info; //文件的目录项信息
|
||||
FSAPIMSG fs_msg;
|
||||
//u8 filename[512];///<[1][512];
|
||||
//u8 path_name[128];///<128
|
||||
DIR f_dj[MAX_DEEPTH];
|
||||
FS_NAME fs_n;
|
||||
} FIL;
|
||||
|
||||
typedef struct _LDIR_INFO {
|
||||
u8 ldir_ord;
|
||||
u8 ldir_name1[10]; //文件的目录项信息
|
||||
u8 ldir_attr0;
|
||||
u8 ldir_type0;
|
||||
u8 ldir_chksum0;
|
||||
u8 ldir_name2[12];
|
||||
u16 ldir_fst_clus_lo;
|
||||
u8 ldir_name3[4];
|
||||
} LDIR_INFO;
|
||||
|
||||
|
||||
|
||||
|
||||
/* File access control and file status flags (FIL.flag) */
|
||||
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#ifdef FS_WRITE_EN
|
||||
#define FA_CREATE_HIDDEN 0x02
|
||||
#define FA_WRITE 0x04 //是否允许写文件
|
||||
#define FA_CREATE_NEW 0x08 //文件不存在时创建
|
||||
#define FA_CREATE_ALWAYS 0x10 //无论文件中否存在,均创建
|
||||
#endif
|
||||
|
||||
#define FA__ERROR 0x80 //文件错误
|
||||
#define FDISK__ERROR 0x40 //设备错误
|
||||
|
||||
|
||||
#define DDE 0xE5 /* Deleted directory entry mark in DIR_Name[0] */
|
||||
#define NDDE 0x05 /* Replacement of the character collides with DDE */
|
||||
|
||||
#define SZ_DIR 32
|
||||
|
||||
|
||||
//#ifdef __SMART_CPU__
|
||||
|
||||
//#endif
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
|
||||
#define _DF1S 1
|
||||
/* Character code support macros */
|
||||
|
||||
#define IsUpper(c) (((c)>='A')&&((c)<='Z'))
|
||||
#define IsLower(c) (((c)>='a')&&((c)<='z'))
|
||||
|
||||
#if _DF1S /* DBCS configuration */
|
||||
|
||||
#ifdef _DF2S /* Two 1st byte areas */
|
||||
#define IsDBCS1(c) (((u8)(c) >= _DF1S && (u8)(c) <= _DF1E) || ((u8)(c) >= _DF2S && (u8)(c) <= _DF2E))
|
||||
#else /* One 1st byte area */
|
||||
//#define IsDBCS1(c) ((u8)(c) >= _DF1S && (u8)(c) <= _DF1E)
|
||||
#define IsDBCS1(c) ((u8)(c) < ' ' && (u8)(c) > '~')
|
||||
#endif
|
||||
|
||||
#ifdef _DS3S /* Three 2nd byte areas */
|
||||
#define IsDBCS2(c) (((u8)(c) >= _DS1S && (u8)(c) <= _DS1E) || ((u8)(c) >= _DS2S && (u8)(c) <= _DS2E) || ((u8)(c) >= _DS3S && (u8)(c) <= _DS3E))
|
||||
#else /* Two 2nd byte areas */
|
||||
#define IsDBCS2(c) (((u8)(c) >= _DS1S && (u8)(c) <= _DS1E) || ((u8)(c) >= _DS2S && (u8)(c) <= _DS2E))
|
||||
#endif
|
||||
|
||||
#else /* SBCS configuration */
|
||||
|
||||
#define IsDBCS1(c) 0
|
||||
#define IsDBCS2(c) 0
|
||||
|
||||
#endif /* _DF1S */
|
||||
|
||||
/* FAT sub-type boundaries */
|
||||
/* Note that the FAT spec by Microsoft says 4085 but Windows works with 4087! */
|
||||
#define MIN_FAT16 4086 /* Minimum number of clusters for FAT16 */
|
||||
#define MIN_FAT32 65526 /* Minimum number of clusters for FAT32 */
|
||||
|
||||
|
||||
#define ROOT_DIR 0
|
||||
|
||||
/* FAT sub type */
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
|
||||
|
||||
/* File attribute bits for directory entry */
|
||||
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume label */
|
||||
#define AM_LFN 0x0F /* LFN entry */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_FCH 0x80 /* exFAT下,文件簇连续标志 */
|
||||
|
||||
|
||||
|
||||
/* Offset of FAT structure members */
|
||||
|
||||
#define BS_jmpBoot 0
|
||||
#define BS_OEMName 3
|
||||
#define BPB_BytsPerSec_l 11
|
||||
#define BPB_BytsPerSec_h 12
|
||||
#define BPB_SecPerClus 13
|
||||
#define BPB_RsvdSecCnt 14
|
||||
#define BPB_NumFATs 16
|
||||
#define BPB_RootEntCnt 17
|
||||
#define BPB_TotSec16 19
|
||||
#define BPB_Media 21
|
||||
#define BPB_FATSz16 22
|
||||
#define BPB_SecPerTrk 24
|
||||
#define BPB_NumHeads 26
|
||||
#define BPB_HiddSec 28
|
||||
#define BPB_TotSec32 32
|
||||
#define BS_55AA 510
|
||||
|
||||
#define BS_DrvNum 36
|
||||
#define BS_BootSig 38
|
||||
#define BS_VolID 39
|
||||
#define BS_VolLab 43
|
||||
#define BS_FilSysType 54
|
||||
|
||||
#define BPB_FATSz32 36
|
||||
#define BPB_ExtFlags 40
|
||||
#define BPB_FSVer 42
|
||||
#define BPB_RootClus 44
|
||||
#define BPB_FSInfo 48
|
||||
#define BPB_BkBootSec 50
|
||||
#define BS_DrvNum32 64
|
||||
#define BS_BootSig32 66
|
||||
#define BS_VolID32 67
|
||||
#define BS_VolLab32 71
|
||||
#define BS_FilSysType32 82
|
||||
#define BS_FileSysTypeexFAT 5
|
||||
#define BPB_FatOffset 80
|
||||
#define BPB_FatLength 84
|
||||
#define BPB_ClusterHeapOffset 88
|
||||
#define BPB_ClusterCount 92
|
||||
#define BPB_FirstClusterOfRootDirectory 96
|
||||
#define BPB_VolumeFlags 106
|
||||
#define BPB_BytesPerSectorShift 108
|
||||
#define BPB_SectorsPerClusterShift 109
|
||||
#define BPB_NumberOfFats 110
|
||||
#define MBR_Table 446
|
||||
#define FSI_LeadSig 0 /* FSI: Leading signature (4) */
|
||||
#define FSI_StrucSig 484 /* FSI: Structure signature (4) */
|
||||
#define FSI_Free_Count 488 /* FSI: Number of free clusters (4) */
|
||||
#define FSI_Nxt_Free 492 /* FSI: Last allocated cluster (4) */
|
||||
|
||||
///for FAT12/FAT16/FAT32
|
||||
#define DIR_Name 0 /* Short file name (11) */
|
||||
#define DIR_Attr 11 /* Attribute (1) */
|
||||
#define DIR_NTres 12 /* NT flag (1) */
|
||||
#define DIR_CrtTimeTenth 13 /* Created time sub-second (1) */
|
||||
#define DIR_CrtTime 14 /* Created time (2) */
|
||||
#define DIR_CrtDate 16 /* Created date (2) */
|
||||
#define DIR_LstAccDate 18 /* Last accessed date (2) */
|
||||
#define DIR_FstClusHI 20 /* Higher 16-bit of first cluster (2) */
|
||||
#define DIR_WrtTime 22 /* Modified time (2) */
|
||||
#define DIR_WrtDate 24 /* Modified date (2) */
|
||||
#define DIR_FstClusLO 26
|
||||
#define DIR_FileSize 28
|
||||
#define LDIR_Attr 11 /* LFN attribute (1) */
|
||||
#define LDIR_Type 12 /* LFN type (1) */
|
||||
#define LDIR_Chksum 13 /* Sum of corresponding SFN entry */
|
||||
////for exFAT
|
||||
#define DIR_FileChainFlags 1
|
||||
#define DIR_NameLen 3
|
||||
#define DIR_AttrexFAT 4
|
||||
#define DIR_FileSizeexFAT 8
|
||||
#define DIR_FstClustexFAT 20
|
||||
|
||||
|
||||
enum {
|
||||
SEEK_SET = 0x01,
|
||||
SEEK_CUR = 0x02,
|
||||
SEEK_END = 0x03
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0,
|
||||
FR_FIND_DIR = 0x80,
|
||||
FR_FIND_FILE,
|
||||
FR_DIR_END, //前面几个位置不能变
|
||||
FR_NO_FILE,
|
||||
FR_NO_PATH,
|
||||
FR_EXIST,
|
||||
FR_INVALID_NAME,
|
||||
FR_INVALID_DRIVE,
|
||||
FR_DENIED,
|
||||
FR_RW_ERROR,
|
||||
FR_WRITE_PROTECTED,
|
||||
FR_NO_FILESYSTEM,
|
||||
FR_DEEP_LIMIT,
|
||||
FR_END_PATH,
|
||||
FR_FILE_LIMIT,
|
||||
FR_END_FILE,
|
||||
FR_LFN_ERR,
|
||||
FR_MKFS_ABORTED,
|
||||
FR_DIR_DELETE,
|
||||
FR_DISK_ERROR,
|
||||
FR_FILE_END,
|
||||
FR_FILE_ERR,
|
||||
FR_NO_WINBUF,
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NO_SEL_DRIVE,
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------*/
|
||||
/* Tiny-FatFs module application interface */
|
||||
FRESULT f_seek(FIL *fp, u8 type, u32 offsize);
|
||||
u16 f_read(FIL *fp, u8 *buff, u16 btr);
|
||||
u32 f_read_bt_updata(FIL *fp, u8 *buff, u32 btr, u8 read_type, u8 type, u32 offsize);
|
||||
FRESULT f_readnextdir(FATFS *fs, DIR *dj, DIRINFO *dinfo, FS_NAME *fs_n);
|
||||
void f_opendir(FATFS *fs, DIR *dj) ;
|
||||
FRESULT f_mount(FATFS *fs, u32 bootsect, char drive_sel) ;
|
||||
FRESULT f_mount_api(FATFS *fs, u32 bootsect, char drive_sel);
|
||||
FRESULT f_open(FATFS *fs, FIL *fp, char *path, char *lfn_buf, u8 mode);
|
||||
u8 f_tell_status(FIL *fp);
|
||||
u16 f_write(FIL *fp, u8 *buff, u16 btw);
|
||||
FRESULT f_mkdir(FATFS *fs, char *path, u8 mode);
|
||||
FRESULT f_sync_fs(FIL *fp);
|
||||
FRESULT f_sync_file(FIL *fp);
|
||||
FRESULT f_unlink(FIL *fp);
|
||||
|
||||
|
||||
bool path_mem_cmp(char *src, char *dst, u8 len);
|
||||
bool my_mem_cmp(char *src, char *dst, u8 len);
|
||||
u8 get_powerof2(u8 n);
|
||||
u32 clust2sect(FATFS *fs, u32 clust);
|
||||
void st_clust(u8 *dir, u32 cl);
|
||||
FRESULT sync_window(SWIN_BUF *win_buf);
|
||||
FRESULT move_window(u32 sector, SWIN_BUF *win_buf);
|
||||
u32 get_fat(FATFS *fs, u32 clust, SWIN_BUF *win_buf);
|
||||
u32 get_cluster(FIL *fp, u32 clust, SWIN_BUF *win_buf);
|
||||
FRESULT put_fat(FATFS *fs, u32 clst, u32 val, SWIN_BUF *win_buf);
|
||||
u32 ld_clust(FATFS *fs, u8 *dir);
|
||||
bool dir_sdi(FATFS *fs, DIR *dj, u16 idx);
|
||||
FRESULT dir_alloc(FATFS *fs, DIR *dj, u8 nent);
|
||||
FRESULT dir_register(FATFS *fs, DIR *dj, char *fn);
|
||||
FRESULT sync_fs(FATFS *fs);
|
||||
u8 create_name(char *sfn, const char *path);
|
||||
FRESULT dir_find(FATFS *fs, DIR *dj, DIRINFO *dir_info, char *sfn, FS_NAME *lfn);
|
||||
FRESULT follow_path(FATFS *fs, DIR *dj, char *sfn, DIRINFO *dinfo, char *path, FS_NAME *lfn);
|
||||
FRESULT remove_chain(FATFS *fs, u32 clst);
|
||||
u32 create_chain(FATFS *fs, u32 clst, SWIN_BUF *win);
|
||||
FRESULT check_fs(FATFS *fs, u32 sec);
|
||||
void get_dir_info(const u8 *dir, DIRINFO *dinfo);
|
||||
bool dir_next(FATFS *fs, DIR *dj, bool stretch);
|
||||
u16 ld_word_func(u8 *p);
|
||||
u32 ld_dword_func(u8 *p);
|
||||
void st_word_func(u8 *ptr, u16 val);
|
||||
void st_dword_func(u8 *ptr, u32 val);
|
||||
|
||||
bool decode_lfn(char *p, char *sou_p, u16 max_copy);
|
||||
|
||||
#endif /* _FATFS */
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef CIRCULAR_BUF_INTERFACE_H
|
||||
#define CIRCULAR_BUF_INTERFACE_H
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
typedef struct _cbuffer {
|
||||
u8 *begin;
|
||||
u8 *end;
|
||||
u8 *read_ptr;
|
||||
u8 *write_ptr;
|
||||
u8 *tmp_ptr ;
|
||||
u32 tmp_len;
|
||||
u32 data_len;
|
||||
u32 total_len;
|
||||
} cbuffer_t;
|
||||
|
||||
extern void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size);
|
||||
|
||||
extern u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
extern u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
extern u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
extern void *cbuf_write_alloc(cbuffer_t *cbuffer, u32 *len);
|
||||
|
||||
extern void cbuf_write_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
void *cbuf_read_alloc(cbuffer_t *cbuffer, u32 *len);
|
||||
|
||||
void cbuf_read_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
void cbuf_clear(cbuffer_t *cbuffer);
|
||||
|
||||
u32 cbuf_rewrite(cbuffer_t *cbuffer, void *begin, void *buf, u32 len);
|
||||
|
||||
void cbuf_discard_prewrite(cbuffer_t *cbuffer);
|
||||
|
||||
void cbuf_updata_prewrite(cbuffer_t *cbuffer);
|
||||
|
||||
u32 cbuf_prewrite(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
u32 cbuf_get_data_size(cbuffer_t *cbuffer);
|
||||
|
||||
void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
#define cbuf_get_writeptr(a) (a)->write_ptr
|
||||
|
||||
#define cbuf_get_readptr(a ) (a)->read_ptr
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef __COMMON_H__
|
||||
#define __COMMON_H__
|
||||
|
||||
#include "asm/cpu.h"
|
||||
#include "csfr.h"
|
||||
#include "typedef.h"
|
||||
#include "device_errno.h"
|
||||
#include "wdt.h"
|
||||
//#include "printf.h"
|
||||
|
||||
|
||||
#define SFR(sfr, start, len, dat) (sfr = (sfr & ~((~(0xffffffff << (len))) << (start))) | (((dat) & (~(0xffffffff << (len)))) << (start)))
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __DEBUG
|
||||
#define APP_DEBUG 1
|
||||
#else
|
||||
#define APP_DEBUG 0
|
||||
#endif
|
||||
|
||||
// #if APP_DEBUG
|
||||
// #define log_info printf
|
||||
// #define log_error(...)
|
||||
// #define log_info_hexdump printf_buf
|
||||
// #else
|
||||
// #define log_info(...)
|
||||
// #define log_info_hexdump(a,b)
|
||||
// #endif
|
||||
|
||||
// void wdt_clear();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef _DEBUG_H_
|
||||
#define _DEBUG_H_
|
||||
|
||||
#include "printf.h"
|
||||
#include "asm/cpu.h"
|
||||
#include "generic/typedef.h"
|
||||
|
||||
#define RedBold "\033[31;1m" // 红色加粗
|
||||
#define RedBoldBlink "\033[31;1;5m" // 红色加粗、闪烁
|
||||
#define GreenBold "\033[32;1m" // 红色加粗
|
||||
#define GreenBoldBlink "\033[32;1;5m" // 红色加粗、闪烁
|
||||
#define YellowBold "\033[33;1m" // 红色加粗
|
||||
#define YellowBoldBlink "\033[33;1;5m" // 红色加粗、闪烁
|
||||
#define BlueBold "\033[34;1m" // 蓝色加粗
|
||||
#define BlueBoldBlink "\033[34;1;5m" // 蓝色加粗、闪烁
|
||||
#define PurpleBold "\033[35;1m" // 紫色加粗
|
||||
#define PurpleBoldBlink "\033[35;1;5m" // 紫色加粗、闪烁
|
||||
#define DGreenBold "\033[36;1m" // 红色加粗
|
||||
#define DGreenBoldBlink "\033[36;1;5m" // 红色加粗、闪烁
|
||||
#define WhiteBold "\033[37;1m" // 红色加粗
|
||||
#define WhiteBoldBlink "\033[37;1;5m" // 红色加粗、闪烁
|
||||
#define Reset "\033[0;25m" // 颜色复位
|
||||
|
||||
#define LOG_VERBOSE v
|
||||
#define LOG_INFO i
|
||||
#define LOG_DEBUG d
|
||||
#define LOG_WARN w
|
||||
#define LOG_ERROR e
|
||||
#define LOG_CHAR c
|
||||
|
||||
#define _STR(x) #x
|
||||
#define STR(x) "["_STR(x)"]"
|
||||
|
||||
|
||||
#define _LOG_TAG_CONST_DECLARE(level, name) extern const char log_tag_const_##level##_##name
|
||||
#define LOG_TAG_CONST_DECLARE(level, name) _LOG_TAG_CONST_DECLARE(level, name)
|
||||
|
||||
#define ___LOG_IS_ENABLE(level, name) (log_tag_const_##level##_##name)
|
||||
#define __LOG_IS_ENABLE(level, name) ___LOG_IS_ENABLE(level, name)
|
||||
#define _LOG_IS_ENABLE(level) __LOG_IS_ENABLE(level, LOG_TAG_CONST)
|
||||
|
||||
#ifdef LOG_TAG_CONST
|
||||
LOG_TAG_CONST_DECLARE(LOG_VERBOSE, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_INFO, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_DEBUG, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_WARN, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_ERROR, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_CHAR, LOG_TAG_CONST);
|
||||
|
||||
#define _LOG_TAG LOG_TAG
|
||||
#define LOG_IS_ENABLE(level) _LOG_IS_ENABLE(level)
|
||||
|
||||
#else
|
||||
#define _LOG_TAG "[NULL]"
|
||||
#define LOG_IS_ENABLE(x) 0
|
||||
#endif
|
||||
|
||||
#ifdef __DEBUG
|
||||
|
||||
#define log_print printf
|
||||
|
||||
#define log_info(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_INFO)) \
|
||||
log_print("[Info] " _LOG_TAG format "\r\n", ## __VA_ARGS__)
|
||||
|
||||
#define log_info_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_INFO)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
|
||||
#define log_debug(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_DEBUG)) \
|
||||
log_print("[Debug] " _LOG_TAG format "\r\n", ## __VA_ARGS__)
|
||||
|
||||
#define log_debug_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_DEBUG)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_error(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_ERROR)) \
|
||||
log_print("<Error> " _LOG_TAG format "\r\n", ## __VA_ARGS__)
|
||||
|
||||
#define log_error_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_ERROR)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_char(x) \
|
||||
if (LOG_IS_ENABLE(LOG_CHAR)) \
|
||||
putchar(x)
|
||||
|
||||
#else
|
||||
|
||||
#define log_info(format, ...)
|
||||
#define log_info_hexdump(x, y)
|
||||
#define log_debug(format, ...)
|
||||
#define log_debug_hexdump(x, y)
|
||||
#define log_error(format, ...)
|
||||
#define log_error_hexdump(x, y)
|
||||
#define log_char(x)
|
||||
|
||||
#endif
|
||||
|
||||
int printf_lite(const char *format, ...);
|
||||
void log_putbyte(char c);
|
||||
void put_buf_lite(void *_buf, u32 len);
|
||||
|
||||
|
||||
#endif//__DEBUG_H_
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef _ASM_GENERIC_ERRNO_BASE_H
|
||||
#define _ASM_GENERIC_ERRNO_BASE_H
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Argument list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define ETIMEDOUT 35 /* Connection timed out */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef JIFFIES_H
|
||||
#define JIFFIES_H
|
||||
|
||||
#define HZ 100L
|
||||
#define MSEC_PER_SEC 1000L
|
||||
#define USEC_PER_MSEC 1000L
|
||||
#define NSEC_PER_USEC 1000L
|
||||
#define NSEC_PER_MSEC 1000000L
|
||||
#define USEC_PER_SEC 1000000L
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
#define FSEC_PER_SEC 1000000000000000LL
|
||||
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
extern volatile unsigned long jiffies;
|
||||
extern unsigned long jiffies_msec();
|
||||
extern unsigned long jiffies_half_msec();
|
||||
#endif
|
||||
|
||||
#define maskrom_get_jiffies() jiffies
|
||||
#define maskrom_set_jiffies(n) jiffies = n
|
||||
|
||||
#define JIFFIES_CIRCLE 0x7FFFFFF
|
||||
|
||||
|
||||
#define msecs_to_jiffies_10(msec) ((msec)/10)
|
||||
#define jiffies_to_msecs(jiff) ((jiff)*10)
|
||||
#define msecs_to_jiffies(msec) ((msec)/10)
|
||||
#define time_after(a,b) ((long)(b) - (long)(a) <= 0)
|
||||
#define time_before(a,b) time_after(b, a)
|
||||
|
||||
int jiffies_msec2offset(unsigned long begin_msec, unsigned long end_msec);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
#ifndef LBUF_H
|
||||
#define LBUF_H
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
#include "list.h"
|
||||
#include "spinlock.h"
|
||||
|
||||
|
||||
#define LBUF_DEBUG 0
|
||||
|
||||
struct lbuff_head {
|
||||
#if LBUF_DEBUG
|
||||
int magic_a; /*!< 测试验证变量*/
|
||||
#endif
|
||||
struct list_head head; /*!< 指向hentry链表*/
|
||||
struct list_head free; /*!< 指向hfree链表*/
|
||||
spinlock_t lock; /*!< 混合自旋锁,单核是为开关临界区,多核是自旋锁.*/
|
||||
u8 align; /*!< 数据包字节对齐*/
|
||||
u16 priv_len; /*!< 数据包结构体的最小长度*/
|
||||
u32 total_size; /*!< 总大小*/
|
||||
u32 last_addr; /*!< 指向free链表中找到的足够长度的hfree结构体地址*/
|
||||
void *priv;
|
||||
|
||||
#if LBUF_DEBUG
|
||||
int magic_b; /*!< 测试验证变量*/
|
||||
#endif
|
||||
};
|
||||
|
||||
struct lbuff_state {
|
||||
u32 avaliable; /*!< 剩余空间的字节长度*/
|
||||
u32 fragment; /*!< lbuf内存碎片块数量*/
|
||||
u32 max_continue_len; /*!< 最大的剩余内存块的字节长度*/
|
||||
int num; /*!< 剩余内存块数量*/
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 链表buf初始化
|
||||
*
|
||||
* @param [in] buf 需要lbuf进行管理的内存
|
||||
* @param [in] len 内存长度
|
||||
* @param [in] align 输入对管理的内存进行对齐的参数,避免后续使用因地址不对齐产生碎片
|
||||
* @param [in] priv_head_len 要管理的一个数据包结构体的最小的长度
|
||||
*
|
||||
* @return lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
struct lbuff_head *lbuf_init(void *buf, u32 len, int align, int priv_head_len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 分配内存空间进行存储数据包
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] len 需要存入的数据包的长度
|
||||
*
|
||||
* @return 成功则返回进行存储数据包的地址,调用时候需要用户把该块内存的类型初始化为数据包结构体的类型。失败则返回NULL。
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_alloc(struct lbuff_head *head, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 重新分配lbuf_alloc()返回用于存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] size 需重新分配的空间的字节长度.注:size的大小只能比lbuf_alloc()中的len小,即只能重新分配更小的lbuf空间,不能扩大空间.
|
||||
*
|
||||
* @return 重新分配后用于存储数据包的地址。失败则返回空指针。注:重新分配最好使用lbuf_real_size()获取lbuf空间的长度确认是否分配成功
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_realloc(void *lbuf, int size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 判断lbuf空间内的内容是否为空
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 返回1则为空,0则不为空
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_empty(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 清空lbuf空间内进行已经分配给数据包的空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_clear(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 把数据包写入分配好的lbuf区域
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] channel_map 选择映射到哪个通道,最多8个通道,使用位映射的方式进行通道对应.
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_push(void *lbuf, u8 channel_map);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 读取对应的通道映射的lbuf区域存储的内容
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] channel 需要读取的通道值,一般使用BIT(n),n为需要读取的通道
|
||||
*
|
||||
* @return 成功则返回存储对应的通道映射的数据包的地址
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_pop(struct lbuff_head *head, u8 channel);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 释放存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*
|
||||
* @return 0则释放失败,存在地址越界操作或者通道还没有被读完,ref-1,读完后才能完全释放。1则释放成功。
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_free(void *lbuf);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 用于调试,检查是否可以释放存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] rets 调用lbuf_free_check()函数的返回地址rets,取值可参考lbuf_free()
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_free_check(void *lbuf, u32 rets);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回可分配的用来存储数据包的最大lbuf内存空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 可分配的最大lbuf内存空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u32 lbuf_free_space(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取lbuf空间的状态
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [out] state lbuff_state结构体
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_state(struct lbuff_head *head, struct lbuff_state *state);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief lbuf信息打印
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_dump(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取已经存入lbuf空间的数据包的数量
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return lbuf存储的数据包的数量
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_traversal(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回lbuf空间还可以被写入size大小数据包的数量
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] size 欲检测写入数据包的大小
|
||||
*
|
||||
* @return 可以写入的数量
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_avaliable(struct lbuff_head *head, int size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回给数据包分配的内存空间的大小
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*
|
||||
* @return 实际占用空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_real_size(void *lbuf);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 计算lbuf空间剩下多少剩余空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 剩余空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_remain_space(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 需要被重复释放的次数+1
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_inc_ref(void *lbuf);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#ifdef offsetof
|
||||
#undef offsetof
|
||||
#endif
|
||||
#ifdef container_of
|
||||
#undef container_of
|
||||
#endif
|
||||
|
||||
#define list_offsetof(type, memb) \
|
||||
((unsigned long)(&((type *)0)->memb))
|
||||
|
||||
#define container_of(ptr, type, memb) \
|
||||
((type *)((char *)ptr - list_offsetof(type, memb)))
|
||||
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
/* REF_LIST: spi.c */
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
/* REF_LIST: spi.c */
|
||||
static inline int list_empty(const struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *_new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = _new;
|
||||
_new->next = next;
|
||||
_new->prev = prev;
|
||||
prev->next = _new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
/* REF_LIST: spi.c */
|
||||
static inline void list_add_tail(struct list_head *_new, struct list_head *head)
|
||||
{
|
||||
__list_add(_new, head->prev, head);
|
||||
}
|
||||
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
if (prev == 0 || next == 0) {
|
||||
return;
|
||||
}
|
||||
//ASSERT(prev!=NULL || next!=NULL)
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
static inline void __list_del_entry(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
/* REF_LIST: spi.c */
|
||||
static inline void list_del(struct list_head *entry) //修改过的list_del,这里与list_del_init一样
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = entry;
|
||||
entry->prev = entry;
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del_entry(entry);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
static inline int list_is_head(struct list_head *head, struct list_head *member)
|
||||
{
|
||||
return head->next == member;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static inline void __list_splice(const struct list_head *list,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
|
||||
first->prev = prev;
|
||||
prev->next = first;
|
||||
|
||||
last->next = next;
|
||||
next->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail_init - join two lists and reinitialise the emptied list
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* Each of the lists is a queue.
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_tail_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head->prev, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_singular - tests whether a list has just one entry.
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_is_singular(const struct list_head *head)
|
||||
{
|
||||
return !list_empty(head) && (head->next == head->prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail - join two lists, each list being a queue
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head->prev, head);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
#ifndef __LOG_H
|
||||
#define __LOG_H
|
||||
|
||||
|
||||
#include "printf.h"
|
||||
|
||||
#define __LOG_VERB 0
|
||||
#define __LOG_DEBUG 1
|
||||
#define __LOG_INFO 2
|
||||
#define __LOG_WARN 3
|
||||
#define __LOG_ERROR 4
|
||||
#define __LOG_CHAR 5
|
||||
|
||||
#define __LOG_ENABLE
|
||||
|
||||
#ifndef __LOG_LEVEL
|
||||
#define __LOG_LEVEL 0
|
||||
#endif
|
||||
|
||||
#ifdef __DEBUG
|
||||
#else
|
||||
#define CONFIG_RELEASE_ENABLE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RELEASE_ENABLE
|
||||
#undef __LOG_LEVEL
|
||||
#define __LOG_LEVEL 0xff
|
||||
#endif
|
||||
|
||||
|
||||
#if __LOG_LEVEL > __LOG_VERB
|
||||
#define log_v(...) do {} while (0)
|
||||
#else
|
||||
#define log_v(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
#if __LOG_LEVEL > __LOG_DEBUG
|
||||
#define log_d(...) do {} while (0)
|
||||
#else
|
||||
#define log_d(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_INFO
|
||||
#define log_i(...) do {} while (0)
|
||||
#else
|
||||
#define log_i(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_WARN
|
||||
#define log_w(...) do {} while (0)
|
||||
#else
|
||||
#define log_w(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_ERROR
|
||||
#define log_e(...) do {} while (0)
|
||||
#else
|
||||
#define log_e(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_CHAR
|
||||
#define log_c(x) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_c(x) putchar(x)
|
||||
#else
|
||||
#define log_c(x)
|
||||
#endif
|
||||
|
||||
|
||||
#define r_printf(x, ...) log_i("\e[31m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define g_printf(x, ...) log_i("\e[32m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define y_printf(x, ...) log_i("\e[33m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define r_f_printf(x, ...) log_i("\e[31m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define g_f_printf(x, ...) log_i("\e[32m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define y_f_printf(x, ...) log_i("\e[33m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
|
||||
#ifndef __LOG_ENABLE
|
||||
|
||||
#define log_dump(a, b) do {} while(0)
|
||||
#define log_putchar() do {} while(0)
|
||||
#define log_early_init(a) do {} while(0)
|
||||
#define log_level(a) do {} while(0)
|
||||
|
||||
#else
|
||||
|
||||
struct logbuf {
|
||||
u16 len;
|
||||
u16 buf_len;
|
||||
char buf[0];
|
||||
};
|
||||
|
||||
int log_output_lock();
|
||||
|
||||
void log_output_unlock();
|
||||
|
||||
void log_print_time();
|
||||
|
||||
void log_early_init(int buf_size);
|
||||
|
||||
void log_level(int level);
|
||||
|
||||
// void log_print(int level, const char *tag, const char *format, ...);
|
||||
|
||||
void log_dump(const u8 *buf, int len);
|
||||
|
||||
struct logbuf *log_output_start(int len);
|
||||
|
||||
void log_output_end(struct logbuf *);
|
||||
|
||||
void log_putchar(struct logbuf *lb, char c);
|
||||
|
||||
void log_put_u8hex(struct logbuf *lb, unsigned char dat);
|
||||
|
||||
void log_putbyte(char);
|
||||
|
||||
void log_set_time_offset(int offset);
|
||||
|
||||
int log_get_time_offset();
|
||||
|
||||
#endif
|
||||
|
||||
void log_flush();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef _MSG_H_
|
||||
#define _MSG_H_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#if (defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)) && defined(BLE_APP_LOW_RAM_USED) // bd47 内存紧缺
|
||||
#define MAX_POOL 100
|
||||
#else
|
||||
#define MAX_POOL 128
|
||||
#endif
|
||||
|
||||
enum {
|
||||
MSG_NO_ERROR = 0,
|
||||
MSG_EVENT_EXIST = -1,
|
||||
MSG_NOT_EVENT = -2,
|
||||
MSG_EVENT_PARAM_ERROR = -3,
|
||||
MSG_BUF_NOT_ENOUGH = -4,
|
||||
};
|
||||
|
||||
#define Q_USER 0x400000
|
||||
enum {
|
||||
LMP_EVENT = Q_USER + 1,
|
||||
LMP_HCI_CMD,
|
||||
LMP_HCI_CMD_TO_CONN,
|
||||
HCI_COMMON_CMD,
|
||||
LL_EVENT,
|
||||
HCI_CMD_TO_LL,
|
||||
HCI_CMD_TO_LL_CONN,
|
||||
TWS_LMP_EVENT,
|
||||
|
||||
BTSTACK_HCI_EVENT,
|
||||
BTSTACK_HCI_ACL,
|
||||
|
||||
//MSG_BT_UPDATA_START = 0x80,
|
||||
//MSG_BT_UPDATE_LOADER_DOWNLOAD_START,
|
||||
MSG_JL_SPEECH_START_PREPARE = 0xB00,
|
||||
MSG_JL_SPEECH_START,
|
||||
MSG_JL_SPEECH_STOP,
|
||||
MSG_JL_GET_DEV_INFO,
|
||||
MSG_JL_GET_DEV_UPDATE_FILE_INFO_OFFSET,
|
||||
MSG_JL_INQUIRE_DEVEICE_IF_CAN_UPDATE,
|
||||
|
||||
MSG_JL_ENTER_UPDATE_MODE,
|
||||
MSG_JL_EXIT_UPDATE_MODE,
|
||||
MSG_JL_UPDATE_DISCONNECT,
|
||||
MSG_JL_UPDATE_REVICE_REBOOT,
|
||||
MSG_JL_SWITCH_CH_SPP,
|
||||
|
||||
MSG_JL_SUCCESS_STATUS_HANDLE,
|
||||
MSG_JL_ERR_STATUS_HANDLE,
|
||||
|
||||
MSG_JL_GET_PRIVATE_INFO,
|
||||
|
||||
MSG_UBOOT_SOFT_POWEROFF,
|
||||
|
||||
|
||||
};
|
||||
|
||||
void task_message_init(void);
|
||||
int task_post_msg(char *name, int argc, ...);
|
||||
int task_post_msg_base(const char *name, int argc, int cmd, int *argv);
|
||||
int task_get_msg(u16 timeout, int len, int *msg);
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
#define SYS_TIMER_H
|
||||
|
||||
|
||||
#include "generic/typedef.h"
|
||||
#include "list.h"
|
||||
|
||||
typedef int sys_timer;
|
||||
|
||||
struct sys_timer {
|
||||
struct list_head entry;
|
||||
void (*func)(void *priv);
|
||||
void *priv;
|
||||
u32 jiffies;
|
||||
u32 msec: 24;
|
||||
u32 del: 1;
|
||||
u32 timeout: 1;
|
||||
u16 id;
|
||||
u8 used;
|
||||
};
|
||||
|
||||
void sys_timer_init();
|
||||
bool __timer_find(struct sys_timer *timer);
|
||||
u16 sys_timer_add(void *priv, void (*func)(void *priv), u32 msec);
|
||||
void sys_timer_schedule(void);
|
||||
void sys_timer_delay_schedule(void);
|
||||
void sys_timer_set_user(struct sys_timer *timer, u32 user);
|
||||
u32 sys_timer_get_user(struct sys_timer *timer);
|
||||
void sys_timer_del_schedule(void);
|
||||
void loop_timer_schedule(void);
|
||||
void sys_timer_re_run(u16 id);
|
||||
void sys_timer_del(u16 t);
|
||||
int sys_timer_modify(u16 id, u32 msec);
|
||||
u16 sys_timeout_add(void *priv, void (*func)(void *priv), u32 msec);
|
||||
void sys_timeout_del(u16 t);
|
||||
/*
|
||||
* For Compatible
|
||||
*/
|
||||
#define sys_hi_timer_schedule()\
|
||||
usr_timer_schedule()
|
||||
|
||||
#define sys_hi_timer_add(a, b, c)\
|
||||
sys_timer_add(a, b, c)
|
||||
|
||||
#define sys_hi_timeout_add(a, b, c)\
|
||||
sys_timeout_add(a, b, c)
|
||||
// usr_timeout_add(a, b, c, 1)
|
||||
|
||||
#define sys_hi_timer_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_hi_timeout_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_hi_timer_del(a)\
|
||||
sys_timer_del(a)
|
||||
|
||||
#define sys_hi_timeout_del(a)\
|
||||
sys_timer_del(a)
|
||||
|
||||
#define sys_s_hi_timer_add(a, b, c)\
|
||||
sys_timer_add(a, b, c, 0)
|
||||
|
||||
#define sys_s_hi_timerout_add(a, b, c)\
|
||||
sys_timeout_add(a, b, c, 0)
|
||||
|
||||
#define sys_s_hi_timer_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_s_hi_timeout_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_s_hi_timer_del(a)\
|
||||
sys_timer_del(a)
|
||||
|
||||
#define sys_s_hi_timeout_del(a)\
|
||||
sys_timeout_del(a)
|
||||
@@ -0,0 +1,219 @@
|
||||
/*************************************************************
|
||||
File: typedef.h
|
||||
Author:Juntham
|
||||
Discriptor:
|
||||
数据类型重定义
|
||||
Version:
|
||||
Date:
|
||||
*************************************************************/
|
||||
#ifndef _typedef_h_
|
||||
#define _typedef_h_
|
||||
|
||||
|
||||
#include "asm/cpu.h"
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
|
||||
typedef unsigned char u8, bool, BOOL;
|
||||
typedef char s8;
|
||||
typedef signed short s16;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef signed int s32;
|
||||
typedef unsigned long long u64;
|
||||
typedef u32 FOURCC;
|
||||
typedef long long s64;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
#ifdef READ_BT_8
|
||||
#undef READ_BT_8
|
||||
#endif
|
||||
|
||||
#ifdef READ_BT_16
|
||||
#undef READ_BT_16
|
||||
#endif
|
||||
|
||||
#ifdef READ_BT_24
|
||||
#undef READ_BT_24
|
||||
#endif
|
||||
|
||||
#ifdef READ_BT_32
|
||||
#undef READ_BT_32
|
||||
#endif
|
||||
|
||||
#define READ_BT_8( buffer, pos) ( ((u8) buffer[pos]))
|
||||
#define READ_BT_16( buffer, pos) ( ((u16) buffer[pos]) | (((u16)buffer[pos+1]) << 8))
|
||||
#define READ_BT_24( buffer, pos) ( ((u32) buffer[pos]) | (((u32)buffer[pos+1]) << 8) | (((u32)buffer[pos+2]) << 16))
|
||||
#define READ_BT_32( buffer, pos) ( ((u32) buffer[pos]) | (((u32)buffer[pos+1]) << 8) | (((u32)buffer[pos+2]) << 16) | (((u32) buffer[pos+3])) << 24)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
///<locate code to x segment ever exist
|
||||
#define SEC_USED(x) __attribute__((section(#x),used))
|
||||
///<locate code to x segment optimized by dependency
|
||||
#define SEC(x) __attribute__((section(#x)))
|
||||
#define sec(x) __attribute__((section(#x),used))
|
||||
///<locate data to x segment
|
||||
#define AT(x) __attribute__((section(#x)))
|
||||
#define SET(x) __attribute__((x))
|
||||
#define ALIGNED(x) __attribute__((aligned(x)))
|
||||
#define _GNU_PACKED_ __attribute__((packed))
|
||||
#define _NOINLINE_ __attribute__((noinline))
|
||||
#define _INLINE_ __attribute__((always_inline))
|
||||
#define _WEAK_ __attribute__((weak))
|
||||
#define _WEAKREF_ __attribute__((weakref))
|
||||
#define _NORETURN_ __attribute__((noreturn))
|
||||
#define _NAKED_ __attribute__((naked))
|
||||
#define SET_INTERRUPT __attribute__((interrupt("")))
|
||||
#define ___interrupt __attribute__((interrupt("")))
|
||||
#else
|
||||
|
||||
#define SEC_USED(x)
|
||||
#define SEC(x)
|
||||
#define AT(x)
|
||||
#define SET(x)
|
||||
#define ALIGNED(x)
|
||||
#define _GNU_PACKED_
|
||||
#define _NOINLINE_
|
||||
#define _INLINE_
|
||||
#define _WEAK_
|
||||
#define _WEAKREF_
|
||||
#define _NORETURN_
|
||||
#define _NAKED_
|
||||
#endif
|
||||
|
||||
|
||||
#if CPU_ENDIAN == LITTLE_ENDIAN
|
||||
//#define ntohl(x) (u32)((x>>24)|((x>>8)&0xff00)|(x<<24)|((x&0xff00)<<8))
|
||||
//#define ntoh(x) (u16)((x>>8&0x00ff)|x<<8&0xff00)
|
||||
|
||||
//#define ntohl(x) (u32)((((u32)(x))>>24) | ((((u32)(x))>>8)&0xff00) | (((u32)(x))<<24) | ((((u32)(x))&0xff00)<<8))
|
||||
//#define ntoh(x) (u16)((((u32)(x))>>8&0x00ff) | (((u32)(x))<<8&0xff00))
|
||||
|
||||
//#define NTOH(x) (x) = ntoh(x)
|
||||
//#define NTOHL(x) (x) = ntohl(x)
|
||||
#define LD_WORD(ptr) (u16)(*(u16*)(u8*)(ptr))
|
||||
#define LD_DWORD(ptr) (u32)(*(u32*)(u8*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(u16*)(u8*)(ptr)=(u16)(val)
|
||||
#define ST_DWORD(ptr,val) *(u32*)(u8*)(ptr)=(u32)(val)
|
||||
#else
|
||||
#define ntohl(x) (x)
|
||||
#define ntoh(x) (x)
|
||||
#define NTOH(x) (x) = ntoh(x)
|
||||
#define NTOHL(x) (x) = ntohl(x)
|
||||
#endif
|
||||
|
||||
#if defined(__UPDATE_NEED_SFC) && defined(__APP_IS_OTA) && !defined(__UPDATE_RUN_RAM)
|
||||
#define SFC_MODE_EN
|
||||
#endif
|
||||
|
||||
#if defined(SFC_MODE_EN)
|
||||
#define AT_SPI_CODE AT(.vm_sfc.text.cache)
|
||||
#else
|
||||
#define AT_SPI_CODE
|
||||
#endif
|
||||
|
||||
|
||||
#undef FALSE
|
||||
#define FALSE 0
|
||||
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define BIT(n) (1UL << (n))
|
||||
#define BitSET(REG,POS) ((REG) |= (1L << (POS)))
|
||||
#define BitCLR(REG,POS) ((REG) &= (~(1L<< (POS))))
|
||||
#define BitXOR(REG,POS) ((REG) ^= (~(1L << (POS))))
|
||||
#define BitCHK_1(REG,POS) (((REG) & (1L << (POS))) == (1L << (POS)))
|
||||
#define BitCHK_0(REG,POS) (((REG) & (1L << (POS))) == 0x00)
|
||||
#define testBit(REG,POS) ((REG) & (1L << (POS)))
|
||||
|
||||
#define clrBit(x,y) (x) &= ~(1L << (y))
|
||||
#define setBit(x,y) (x) |= (1L << (y))
|
||||
|
||||
|
||||
#define readb(addr) *((volatile unsigned char*)(addr))
|
||||
#define readw(addr) *((volatile unsigned short *)(addr))
|
||||
#define readl(addr) *((volatile unsigned long*)(addr))
|
||||
|
||||
#define writeb(addr, val) *((volatile unsigned char*)(addr)) = (u8)(val)
|
||||
#define writew(addr, val) *((volatile unsigned short *)(addr)) = (u16)(val)
|
||||
#define writel(addr, val) *((volatile unsigned long*)(addr)) = (u32)(val)
|
||||
|
||||
#define ALIGN_4BYTE(size) ((size+3)&0xfffffffc)
|
||||
|
||||
#if CPU_ENDIAN == BIG_ENDIAN
|
||||
#define __cpu_u16(lo, hi) ((lo)|((hi)<<8))
|
||||
#elif CPU_ENDIAN == LITTLE_ENDIAN
|
||||
#define __cpu_u16(lo, hi) ((hi)|((lo)<<8))
|
||||
#else
|
||||
#error "undefine cpu eadin"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
|
||||
|
||||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
#define SFR(sfr, start, len, dat) \
|
||||
(sfr = (sfr & ~((~(0xffffffff << (len))) << (start))) | \
|
||||
(((dat) & (~(0xffffffff << (len)))) << (start)))
|
||||
|
||||
|
||||
#include "errno-base.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "malloc.h"
|
||||
#include "jiffies.h"
|
||||
|
||||
|
||||
#ifdef offsetof
|
||||
#undef offsetof
|
||||
#endif
|
||||
|
||||
#ifdef container_of
|
||||
#undef container_of
|
||||
#endif
|
||||
|
||||
#define offsetof(type, memb) \
|
||||
((unsigned long)(&((type *)0)->memb))
|
||||
|
||||
#define container_of(ptr, type, memb) \
|
||||
((type *)((char *)(ptr) - offsetof(type, memb)))
|
||||
|
||||
void delay(unsigned int);
|
||||
|
||||
void delay_us(unsigned int);
|
||||
|
||||
// 只适用32位以内数据比较
|
||||
#define LOOP_OVERTAKE(a, b, n) \
|
||||
((((a) - (b)) & ((1ULL << (n)) - 1)) < ((1UL << ((n) - 1))))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef _MEM_HEAP_H_
|
||||
#define _MEM_HEAP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void *malloc(unsigned long size);
|
||||
extern void *zalloc(unsigned long size);
|
||||
extern void *calloc(unsigned long count, unsigned long size);
|
||||
extern void *realloc(void *rmem, unsigned long newsize);
|
||||
extern void free(void *mem);
|
||||
|
||||
|
||||
extern void *kmalloc(unsigned long size, int flags);
|
||||
extern void *vmalloc(unsigned long size);
|
||||
extern void vfree(void *addr);
|
||||
extern void *kzalloc(unsigned int len, int a);
|
||||
extern void kfree(void *p);
|
||||
|
||||
extern void malloc_stats(void);
|
||||
|
||||
extern void malloc_dump();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _MEM_HEAP_H_ */
|
||||
@@ -0,0 +1,87 @@
|
||||
/***********************************Jieli tech************************************************
|
||||
File : os_cpu.h
|
||||
By : Juntham
|
||||
date : 2014-07-03 09:06
|
||||
********************************************************************************************/
|
||||
#ifndef _OS_CPU_H
|
||||
#define _OS_CPU_H
|
||||
|
||||
#include "asm/cpu.h"
|
||||
#include "jiffies.h"
|
||||
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
typedef unsigned short QS;
|
||||
typedef unsigned int OS_STK; /* Each stack entry is 32-bit wide*/
|
||||
typedef unsigned int OS_CPU_SR; /* Unsigned 32 bit quantity */
|
||||
typedef unsigned int OS_CPU_DATA; /* Unsigned 32 bit quantity */
|
||||
#endif
|
||||
|
||||
#define OS_CPU_EXT extern
|
||||
#define OS_CPU_CORE CPU_CORE_NUM
|
||||
|
||||
#define OS_CPU_ID current_cpu_id()
|
||||
#define OS_STK_GROWTH 1 /* Stack grows from HIGH to LOW memory*/
|
||||
|
||||
#define OS_CPU_MMU 0
|
||||
|
||||
#define OS_CPU_VIRTUAL_MEM 1 //临时定义:区别于OS_CPU_MMU
|
||||
|
||||
#define OS_TASK_CLR(a) CPU_TASK_CLR(a)
|
||||
#define OS_TASK_SW(a) CPU_TASK_SW(a) /* 任务级任务切换函数*/
|
||||
#define OS_INT_NESTING CPU_INT_NESTING
|
||||
|
||||
#define CPU_SR_ALLOC()
|
||||
|
||||
#define OS_SR_ALLOC()
|
||||
|
||||
#define OS_ENTER_CRITICAL() \
|
||||
CPU_CRITICAL_ENTER(); \
|
||||
|
||||
#define OS_EXIT_CRITICAL() \
|
||||
CPU_CRITICAL_EXIT()
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/*#include "system/spinlock.h"
|
||||
|
||||
extern spinlock_t os_lock;
|
||||
|
||||
#define OS_ENTER_CRITICAL() \
|
||||
spin_lock(&os_lock)
|
||||
|
||||
#define OS_EXIT_CRITICAL() \
|
||||
spin_unlock(&os_lock)*/
|
||||
|
||||
|
||||
void OSCtxSw(void);
|
||||
|
||||
extern void EnableOtherCpu(void) ;
|
||||
|
||||
#define os_ctx_sw OSCtxSw
|
||||
|
||||
void OSInitTick(u32 hz);
|
||||
|
||||
void InstallOSISR(void);
|
||||
|
||||
void os_task_dead(const char *task_name);
|
||||
#endif
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
* (Compiler Specific)
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#define OS_CRITICAL_METHOD 3
|
||||
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
|
||||
//#define CPU_SR_ALLOC() OS_CPU_SR cpu_sr
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*_OS_CPU_H */
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef SYS_SPINLOCK_H
|
||||
#define SYS_SPINLOCK_H
|
||||
|
||||
#include "typedef.h"
|
||||
//#include "cpu.h"
|
||||
//#include "irq.h"
|
||||
|
||||
struct __spinlock {
|
||||
volatile u32 rwlock;
|
||||
};
|
||||
|
||||
typedef struct __spinlock spinlock_t;
|
||||
|
||||
extern void local_irq_disable(void);
|
||||
extern void local_irq_enable(void);
|
||||
|
||||
|
||||
#define preempt_disable() \
|
||||
local_irq_disable()
|
||||
|
||||
#define preempt_enable() \
|
||||
local_irq_enable()
|
||||
|
||||
|
||||
#if CPU_CORE_NUM > 1
|
||||
|
||||
#define spin_acquire(lock) \
|
||||
do { \
|
||||
arch_spin_lock(lock); \
|
||||
}while(0)
|
||||
|
||||
#define spin_release(lock) \
|
||||
do { \
|
||||
arch_spin_unlock(lock); \
|
||||
}while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define spin_acquire(lock) \
|
||||
do { \
|
||||
}while(0)
|
||||
|
||||
|
||||
#define spin_release(lock) \
|
||||
do { \
|
||||
}while(0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define DEFINE_SPINLOCK(x) \
|
||||
spinlock_t x = { .rwlock = 0 }
|
||||
|
||||
|
||||
static inline void spin_lock_init(spinlock_t *lock)
|
||||
{
|
||||
lock->rwlock = 0;
|
||||
}
|
||||
|
||||
static inline void spin_lock(spinlock_t *lock)
|
||||
{
|
||||
preempt_disable();
|
||||
spin_acquire(lock);
|
||||
}
|
||||
|
||||
|
||||
static inline void spin_unlock(spinlock_t *lock)
|
||||
{
|
||||
spin_release(lock);
|
||||
preempt_enable();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
#ifndef __UPDATE_MAIN_H__
|
||||
#define __UPDATE_MAIN_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "tff.h"
|
||||
|
||||
extern u32 UPDATE_BEG;
|
||||
extern u32 UPDATA_SIZE;
|
||||
#define UART_UPDATE_FLAG_ADDR (u32)(&UPDATE_BEG)
|
||||
#define UPDATE_FLAG_ADDR ((u32)(&UPDATE_BEG) + 0x8)
|
||||
|
||||
#define UPDATE_PRIV_PARAM_LEN 32
|
||||
#define UPDATA_MAGIC (0x5A00) //防止CRC == 0 的情况
|
||||
|
||||
// #define SEEK_SET 0 #<{(| Seek from beginning of file. |)}>#
|
||||
// #define SEEK_CUR 1 #<{(| Seek from current position. |)}>#
|
||||
// #define SEEK_END 2 #<{(| Seek from end of file. |)}>#
|
||||
|
||||
|
||||
|
||||
|
||||
//给SDK的升级结果
|
||||
typedef enum {
|
||||
UPDATA_NON = UPDATA_MAGIC,
|
||||
UPDATA_READY,
|
||||
UPDATA_SUCCESSFULLY,
|
||||
UPDATA_PARM_ERR,
|
||||
UPDATA_DEV_ERR,
|
||||
UPDATA_KEY_ERR,
|
||||
} UPDATA_RESULT_TO_SDK;
|
||||
|
||||
//区分是否跳转还是断电重新上电进入loader
|
||||
typedef enum {
|
||||
UPDATE_JUMP = 0,
|
||||
UPDATE_POWERON,
|
||||
} UPDATE_MODE;
|
||||
|
||||
typedef enum {
|
||||
UPDATE_PARM,
|
||||
UPDATE_START,
|
||||
UPDATE_END,
|
||||
} UPDATE_STEP;
|
||||
|
||||
typedef enum {
|
||||
UPDATE_READ_TOUT_PARM = UPDATE_END + 1, // 根据远端ini文件的配合更新读超时时间
|
||||
UPDATE_SDK_BEGIN_PARM, // 开始升级
|
||||
} UPDATE_INI;
|
||||
|
||||
typedef enum {
|
||||
USB_UPDATA = UPDATA_MAGIC, //0x5A00
|
||||
SD0_UPDATA, //0x5A01
|
||||
SD1_UPDATA,
|
||||
PC_UPDATA,
|
||||
UART_UPDATA,
|
||||
BT_UPDATA,
|
||||
BLE_APP_UPDATA,
|
||||
SPP_APP_UPDATA,
|
||||
DUAL_BANK_UPDATA,
|
||||
BLE_TEST_UPDATA,
|
||||
NORFLASH_UPDATA,
|
||||
// BLE_UPDATA,
|
||||
USER_NORFLASH_UFW_UPDATA,
|
||||
USER_LC_FLASH_UFW_UPDATA,
|
||||
USB_HID_UPDATA,
|
||||
DEV_NORFLASH_UFW_UPDATA,
|
||||
NET_UFW_UPDATA,
|
||||
USER_NANDFLASH_UFW_UPDATA,
|
||||
TESTBOX_UART_UPDATA,
|
||||
UPDIFF_FLASH_UPDATA,
|
||||
COMBAK_FLASH_UPDATA,
|
||||
DEV_UPDATA_MAX,
|
||||
|
||||
|
||||
DEV_UPDATE = 0xFFFE,
|
||||
NON_DEV_UPDATA = 0xFFFF,
|
||||
} UPDATA_TYPE;
|
||||
|
||||
enum EXT_ARG_TYPE {
|
||||
EXT_LDO_TRIM_RES = 0,
|
||||
EXT_JUMP_FLAG,
|
||||
EXT_BT_MAC_ADDR,
|
||||
EXT_RF_PA_INFO,
|
||||
EXT_RESERVED_UPDATE, // 用于sdk传入参数控制是否升级预留区域
|
||||
EXT_RESET_TIME_WITHOUT_CONN, // 用于sdk传入未连接状态保持多久就重启的超时时间
|
||||
EXT_SD_IO_INFO,
|
||||
EXT_BT_WLA_INFO,
|
||||
EXT_MUTIL_UPDATE_NAME = 0x8,
|
||||
EXT_USER_API_BIN_INFO,
|
||||
EXT_NEW_SDK_UPD_AGAIN,
|
||||
EXT_NEW_FILENAME,
|
||||
EXT_KEEP_ROMIO_INFO = 0x10,
|
||||
EXT_NAND_PARAM = 0x11,
|
||||
EXT_SYS_CLK_PARAM = 0x12,
|
||||
EXT_TYPE_MAX = 0xff,
|
||||
};
|
||||
|
||||
|
||||
typedef enum _UPDATA_RESULT {
|
||||
UPDATA_RESULT_SUCC = 1,
|
||||
UPDATA_RESULT_FAIL,
|
||||
UPDATA_RESULT_KEY_ERR,
|
||||
} UPDATA_RESULT;
|
||||
|
||||
//回报给测试盒的?
|
||||
enum {
|
||||
BT_UPDATE_OVER = 0,
|
||||
BT_UPDATE_KEY_ERR,
|
||||
BT_UPDATE_CONNECT_ERR,
|
||||
};
|
||||
|
||||
enum {
|
||||
UPDATE_ERR_NONE = 0,
|
||||
UPDATE_ERR_UFW_HEAD_CRC_ERR,
|
||||
UPDATE_ERR_NOT_FIND_LOADER_FILE,
|
||||
UPDATE_ERR_NOT_FIND_TARGET_LOADER,
|
||||
|
||||
UPDATE_ERR_LOADER_HEAD_CRC_ERR = 4,
|
||||
UPDATE_ERR_MALLOC_ERR,
|
||||
UPDATE_ERR_LOADER_WRITE_ERR,
|
||||
UPDATE_ERR_FILE_HANDLE_ERR,
|
||||
|
||||
UPDATE_ERR_LOADER_VERIFY_ERR = 8,
|
||||
UPDATE_ERR_NOT_FIND_FLASH_BIN,
|
||||
UPDATE_ERR_FLASH_HEAD_CRC_ERR,
|
||||
UPDATE_ERR_NOT_FIND_TARGET_FILE,
|
||||
|
||||
UPDATE_ERR_KEY_ERR = 12,
|
||||
UPDATE_ERR_UBOOT_NOT_MATCH,
|
||||
UPDATE_ERR_READ_REMOTE_FILE_ERR,
|
||||
UPDATE_ERR_REMOTE_RES_FILE_CRC_ERR,
|
||||
|
||||
UPDATE_ERR_CODE_VERIFY_ERR = 16,
|
||||
UPDATE_ERR_RES0_VERIFY_ERR,
|
||||
UPDATE_ERR_NOT_FIND_RESERVE_DIR_FILE,
|
||||
UPDATE_ERR_LOCAL_FILE_HEAD_CRC_ERR,
|
||||
|
||||
UPDATE_ERR_LOCAL_FILE_DATA_CRC_ERR = 20,
|
||||
UPDATE_ERR_PARAM_ERR,
|
||||
UPDATE_ERR_BT_CFG_UPDATE_ERR,
|
||||
UPDATE_ERR_TONE_UPDATE_ERR,
|
||||
|
||||
UPDATE_ERR_RESERVED_CONFIG_UPDATE_ERR = 24,
|
||||
UPDATE_ERR_PRODUCT_ID_NOT_MATCH,
|
||||
UPDATE_ERR_EX_DSP_UPDATE_ERR,
|
||||
UPDATE_ERR_CONN_ERR,
|
||||
|
||||
UPDATE_ERR_ERASE_FAIL = 28,
|
||||
UPDATE_ERR_UPDATE_FILE_SIZE_ERR,
|
||||
UPDATE_ERR_ANC_CFG_UPDATE_ERR,
|
||||
UPDATE_ERR_ANC_COEF_UPDATE_ERR,
|
||||
|
||||
UPDATE_ERR_RESERVED_ZONE_UPDATE_ERR = 32,
|
||||
|
||||
// 可以把错误更加具体化
|
||||
UPDATE_ERR_FLASH_ID_ERR,
|
||||
UPDATE_ERR_CHIP_ID_ERR,
|
||||
UPDATE_ERR_EFUSE_OVERWRITE_ERR,
|
||||
UPDATE_ERR_EFUSE_BT_NAME_ERR,
|
||||
UPDATE_ERR_EFUSE_CHANNEL_ERR,
|
||||
UPDATE_ERR_ISD_CONFIG_ERR,
|
||||
UPDATE_ERR_LOCAL_EFUSE_CRC_ERR,
|
||||
UPDATE_ERR_LOCAL_EFUSE_WRITE_ERR,
|
||||
UPDATE_ERR_WRITE_P11_CODE_ERR,
|
||||
UPDATE_ERR_EFUSE_MASKROM_USE2_WRITE_ERR,
|
||||
|
||||
};
|
||||
|
||||
//for rcsp update
|
||||
enum {
|
||||
DEV_CONN_STATE_DISCONNECTED = 0,
|
||||
DEV_CONN_STATE_CONNECTED,
|
||||
DEV_CONN_STATE_READY_UPDATE,
|
||||
DEV_CONN_STATE_START_UPDATE,
|
||||
};
|
||||
|
||||
typedef struct _UPDATA_PARM {
|
||||
u16 parm_crc;
|
||||
u16 parm_type; //UPDATA_TYPE:sdk pass parm to uboot
|
||||
u16 parm_result; //UPDATA_TYPE:uboot return result to sdk
|
||||
u16 magic;
|
||||
u8 file_patch[32];
|
||||
u8 parm_priv[32];
|
||||
u32 ota_addr;
|
||||
u16 ext_arg_len;
|
||||
u16 ext_arg_crc;
|
||||
} UPDATA_PARM;
|
||||
|
||||
typedef struct _update_op_api_t {
|
||||
int (*ch_init)(void (*resume_hdl)(void *priv), int (*sleep_hdl)(void *priv));
|
||||
u16(*f_open)(void);
|
||||
u16(*f_read)(void *fp, u8 *buff, u32 len);
|
||||
int (*f_seek)(void *fp, u8 type, u32 offset);
|
||||
u16(*f_stop)(u8 err);
|
||||
int (*notify_update_content_size)(u32 size);
|
||||
void (*ch_exit)(void *priv);
|
||||
void *priv;
|
||||
} update_op_api_t;
|
||||
|
||||
typedef struct _update_mode_info_t {
|
||||
s32 type;
|
||||
void (*state_cbk)(u32 status, void *priv);
|
||||
const update_op_api_t *file_op;
|
||||
u8 task_en;
|
||||
} update_mode_info_t;
|
||||
|
||||
void update_main();
|
||||
void set_updata_result(u16 type, u16 result);
|
||||
u8 fs_update_result_transition(u8 err);
|
||||
extern u32 fs_dev_mount(u16 dev_type);
|
||||
void update_reset(void);
|
||||
u8 *update_param_ext_get(UPDATA_PARM *p, u8 ext_type);
|
||||
|
||||
void *dev_update_handle_get(void);
|
||||
void mutil_cpu_set_offset(u32 offset);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,610 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : hci_ll.h
|
||||
|
||||
* Description : 提供Vendor Host 直接调用Controller API LL Part
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2018-12-04 11:58
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _HCI_LL_H_
|
||||
#define _HCI_LL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#if 0
|
||||
// LE CONTROLLER COMMANDS
|
||||
#define HCI_LE_READ_ISO_TX_SYNC 0x0061
|
||||
#define HCI_LE_SET_CIG_PARAMS 0x0062
|
||||
#define HCI_LE_SETUP_ISO_DATA_PATH 0x006E
|
||||
#define HCI_LE_CREATE_BIG 0x0068
|
||||
|
||||
// LE EVENTS
|
||||
#define HCI_SUBEVENT_LE_BIG_INFO_ADV_REPORT_EVT 0x22
|
||||
#define HCI_SUBEVENT_LE_TERMINATE_BIG_CMPL_EVT 0x1C
|
||||
#define HCI_SUBEVENT_LE_BIG_SYNC_EST_EVT 0x1D
|
||||
#define HCI_SUBEVENT_LE_BIG_SYNC_LOST_EVT 0x1E
|
||||
#define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13
|
||||
#define HCI_SUBEVENT_LE_ADVERTISING_REPORT 0x02
|
||||
|
||||
#endif
|
||||
|
||||
#define HCI_LE_CIS_ESTABLISHED_EVENT 0x19
|
||||
#define HCI_LE_CIS_REQUEST_EVENT 0x1A
|
||||
#define HCI_LE_CREATE_BIG_COMPLETE_EVENT 0x1B
|
||||
#define HCI_LE_SET_EXTENDED_ADVERTISING_ENABLE 0x0039
|
||||
|
||||
// Controller Error Codes
|
||||
#define CONNECTION_TERMINATED_BY_LOCAL_HOST 0x16
|
||||
|
||||
enum {
|
||||
LL_EVENT_SUPERVISION_TIMEOUT,
|
||||
LL_EVENT_RX,
|
||||
LL_EVENT_ACL_TX_POST,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
u8 Own_Address_Type: 2;
|
||||
u8 Adv_Filter_Policy: 2;
|
||||
u8 Scan_Filter_Policy: 2;
|
||||
u8 initiator_filter_policy: 2;
|
||||
} hci_ll_param_t;
|
||||
|
||||
/*! \brief LE Advertising report event. */
|
||||
typedef enum {
|
||||
EVT_TYPE_ADV_IND,
|
||||
EVT_TYPE_ADV_DIRECT_IND,
|
||||
EVT_TYPE_ADV_SCAN_IND,
|
||||
EVT_TYPE_ADV_NONCONN_IND,
|
||||
EVT_TYPE_SCAN_RSP,
|
||||
} le_evt_type_e;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Subevent_Code;
|
||||
uint8_t Num_Reports;
|
||||
uint8_t Event_Type;
|
||||
uint8_t Address_Type;
|
||||
uint8_t Address[6];
|
||||
uint8_t Data_Length;
|
||||
uint8_t Data[0];
|
||||
} _GNU_PACKED_ le_adv_report_evt_t;
|
||||
|
||||
/*! \brief LE Extended Advertising report event. */
|
||||
typedef union {
|
||||
struct {
|
||||
uint16_t Connectable_advertising : 1,
|
||||
Scannable_advertising : 1,
|
||||
Directed_advertising : 1,
|
||||
Scan_response : 1,
|
||||
Legacy_adv_PDUs_used : 1,
|
||||
Data_status : 2,
|
||||
All_other_bits : 9;
|
||||
};
|
||||
|
||||
uint16_t event_type;
|
||||
} _GNU_PACKED_ le_evt_type_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Subevent_Code;
|
||||
uint8_t Num_Reports;
|
||||
le_evt_type_t Event_Type;
|
||||
uint8_t Address_Type;
|
||||
uint8_t Address[6];
|
||||
uint8_t Primary_PHY;
|
||||
uint8_t Secondary_PHY;
|
||||
uint8_t Advertising_SID;
|
||||
uint8_t Tx_Power;
|
||||
uint8_t RSSI;
|
||||
uint16_t Periodic_Advertising_Interval;
|
||||
uint8_t Direct_Address_Type;
|
||||
uint8_t Direct_Address[6];
|
||||
uint8_t Data_Length;
|
||||
uint8_t Data[0];
|
||||
} _GNU_PACKED_ le_ext_adv_report_evt_t;
|
||||
|
||||
struct __periodic_adv_report_event {
|
||||
u8 Subevent_Code;
|
||||
u16 Sync_Handle;
|
||||
u8 Tx_Power;
|
||||
u8 RSSI;
|
||||
u8 Unused;
|
||||
u8 Data_Status;
|
||||
u8 Data_Length;
|
||||
u8 Data[0];
|
||||
} _GNU_PACKED_ ;
|
||||
|
||||
struct __periodic_creat_sync {
|
||||
u8 Filter_Policy;
|
||||
u8 Advertising_SID;
|
||||
u8 Advertising_Address_Type;
|
||||
u8 Advertiser_Address[6];
|
||||
u8 Skip[2];
|
||||
u8 Sync_Timeout[2];
|
||||
u8 Unused;
|
||||
} _GNU_PACKED_;
|
||||
|
||||
/*! \brief LE Set Scan Parameters. */
|
||||
typedef struct {
|
||||
uint8_t LE_Scan_Type;
|
||||
uint16_t LE_Scan_Interval;
|
||||
uint16_t LE_Scan_Window;
|
||||
uint8_t Own_Address_Type;
|
||||
uint8_t Scanning_Filter_Policy;
|
||||
} _GNU_PACKED_ le_set_scan_param_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Own_Address_Type;
|
||||
uint8_t Scanning_Filter_Policy;
|
||||
uint8_t Scanning_PHYs;
|
||||
uint8_t Scan_Type;
|
||||
uint16_t Scan_Interval;
|
||||
uint16_t Scan_Window;
|
||||
} _GNU_PACKED_ le_ext_scan_param_lite_t;
|
||||
|
||||
struct __ext_scan_param {
|
||||
u8 Own_Address_Type;
|
||||
u8 Scanning_Filter_Policy;
|
||||
u8 Scanning_PHYs;
|
||||
struct __scan_phy_param {
|
||||
u8 Scan_Type;
|
||||
u16 Scan_Interval;
|
||||
u16 Scan_Window;
|
||||
} _GNU_PACKED_ scan_phy_param[0];
|
||||
} _GNU_PACKED_;
|
||||
|
||||
struct __ext_scan_enable {
|
||||
u8 Enable;
|
||||
u8 Filter_Duplicates;
|
||||
u16 Duration;
|
||||
u16 Period;
|
||||
} _GNU_PACKED_;
|
||||
|
||||
/*! \brief LE Set Extended Advertising Parameters. */
|
||||
typedef struct {
|
||||
uint8_t Advertising_Handle;
|
||||
uint16_t Advertising_Event_Properties;
|
||||
uint8_t Primary_Advertising_Interval_Min[3];
|
||||
uint8_t Primary_Advertising_Interval_Max[3];
|
||||
uint8_t Primary_Advertising_Channel_Map;
|
||||
uint8_t Own_Address_Type;
|
||||
uint8_t Peer_Address_Type;
|
||||
uint8_t Peer_Address[6];
|
||||
uint8_t Advertising_Filter_Policy;
|
||||
uint8_t Advertising_Tx_Power;
|
||||
uint8_t Primary_Advertising_PHY;
|
||||
uint8_t Secondary_Advertising_Max_Skip;
|
||||
uint8_t Secondary_Advertising_PHY;
|
||||
uint8_t Advertising_SID;
|
||||
uint8_t Scan_Request_Notification_Enable;
|
||||
} _GNU_PACKED_ le_set_ext_adv_param_t;
|
||||
|
||||
/*! \brief LE Set Extended Advertising Data. */
|
||||
typedef struct {
|
||||
uint8_t Advertising_Handle;
|
||||
uint8_t Operation;
|
||||
uint8_t Fragment_Preference;
|
||||
uint8_t Advertising_Data_Length;
|
||||
uint8_t Advertising_Data[31];
|
||||
} _GNU_PACKED_ le_set_ext_adv_data_t;
|
||||
|
||||
/*! \brief LE Set Extended Advertising Enable. */
|
||||
typedef struct {
|
||||
uint8_t Enable;
|
||||
uint8_t Number_of_Sets;
|
||||
uint8_t Advertising_Handle;
|
||||
uint16_t Duration;
|
||||
uint8_t Max_Extended_Advertising_Events;
|
||||
} _GNU_PACKED_ le_set_ext_adv_en_t;
|
||||
|
||||
struct periodic_advertising_param {
|
||||
u8 Advertising_Handle;
|
||||
u16 Periodic_Advertising_Interval_Min;
|
||||
u16 Periodic_Advertising_Interval_Max;
|
||||
u16 Periodic_Advertising_Properties;
|
||||
} _GNU_PACKED_;
|
||||
|
||||
struct periodic_advertising_data {
|
||||
u8 Advertising_Handle;
|
||||
u8 Operation;
|
||||
u8 Advertising_Data_Length;
|
||||
u8 Advertising_Data[31];
|
||||
} _GNU_PACKED_;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Advertising_Handle;
|
||||
uint8_t Operation;
|
||||
uint8_t Advertising_Data_Length; // 0 to 252
|
||||
uint8_t Advertising_Data[0];
|
||||
} _GNU_PACKED_ le_set_prd_adv_data_t;
|
||||
|
||||
struct periodic_advertising_enable {
|
||||
u8 Enable;
|
||||
u8 Advertising_Handle;
|
||||
} _GNU_PACKED_;
|
||||
|
||||
typedef struct {
|
||||
uint16_t Sync_Handle;
|
||||
} _GNU_PACKED_ periodic_adv_terminate_sync;
|
||||
|
||||
/*! \brief HCI ACL Data packets */
|
||||
typedef struct {
|
||||
uint16_t Handle : 12;
|
||||
uint16_t PB_Flag : 2;
|
||||
uint16_t BC_Flag : 2;
|
||||
uint16_t Data_Total_Length;
|
||||
|
||||
uint8_t Data[0];
|
||||
} _GNU_PACKED_ hci_acl_data_packets_t ;
|
||||
|
||||
/*! \brief LE Set CIG Parameters */
|
||||
typedef struct {
|
||||
uint8_t GIG_ID;
|
||||
uint8_t SDU_Interval_C_To_P[3];
|
||||
uint8_t SDU_Interval_P_To_C[3];
|
||||
uint8_t Worst_Case_SCA;
|
||||
uint8_t Packing;
|
||||
uint8_t Framing;
|
||||
uint16_t Max_Transport_Latency_C_To_P;
|
||||
uint16_t Max_Transport_Latency_P_To_C;
|
||||
uint8_t CIS_Count;
|
||||
struct le_cis_param_t {
|
||||
uint8_t CIS_ID;
|
||||
uint16_t Max_SDU_C_To_P;
|
||||
uint16_t Max_SDU_P_To_C;
|
||||
uint8_t PHY_C_To_P;
|
||||
uint8_t PHY_P_To_C;
|
||||
uint8_t RTN_C_To_P;
|
||||
uint8_t RTN_P_To_C;
|
||||
} _GNU_PACKED_ param[0];
|
||||
} _GNU_PACKED_ le_set_cig_param_t;
|
||||
|
||||
/*! \brief LE Create CIS */
|
||||
typedef struct {
|
||||
uint8_t CIS_Count;
|
||||
struct le_cis_hdl_t {
|
||||
uint16_t CIS_Connection_Handle;
|
||||
uint16_t ACL_Connection_Handle;
|
||||
} _GNU_PACKED_ param[0];
|
||||
} _GNU_PACKED_ le_create_cis_t;
|
||||
|
||||
/*! \brief LE Remove CIS */
|
||||
typedef struct {
|
||||
uint8_t CIG_ID;
|
||||
} _GNU_PACKED_ le_remove_cig_t;
|
||||
|
||||
/*! \brief LE Setup ISO Data Path */
|
||||
typedef struct {
|
||||
uint16_t Connection_Handle;
|
||||
uint8_t Data_Path_Direction;
|
||||
uint8_t Data_Path_ID;
|
||||
struct {
|
||||
uint8_t Coding_Format;
|
||||
uint16_t Company_Identifier;
|
||||
uint16_t Vendor_ID;
|
||||
} _GNU_PACKED_ Codec_ID;
|
||||
uint8_t Controller_Delay[3];
|
||||
uint8_t Codec_Configuratin_Length;
|
||||
uint8_t Codec_Configuratin[0];
|
||||
} _GNU_PACKED_ le_setup_iso_data_path_t;
|
||||
|
||||
/*! \brief LE Create BIG */
|
||||
typedef struct {
|
||||
uint8_t BIG_Handle;
|
||||
uint8_t Advertising_Handle;
|
||||
uint8_t Num_BIS;
|
||||
uint8_t SDU_Interval[3];
|
||||
uint16_t Max_SDU;
|
||||
uint16_t Max_Transport_Latency;
|
||||
uint8_t RTN;
|
||||
uint8_t PHY;
|
||||
uint8_t Packing;
|
||||
uint8_t Framing;
|
||||
uint8_t Encryption;
|
||||
uint8_t Broadcast_Code[16];
|
||||
} _GNU_PACKED_ le_create_big_t;
|
||||
|
||||
/*! \brief LE Terminate BIG */
|
||||
typedef struct {
|
||||
uint8_t BIG_Handle;
|
||||
uint8_t Reason;
|
||||
} _GNU_PACKED_ le_terminate_big_t;
|
||||
|
||||
/*! \brief LE BIG Create Sync */
|
||||
typedef struct {
|
||||
uint8_t BIG_Handle;
|
||||
uint16_t Sync_Handle;
|
||||
uint8_t Encryption;
|
||||
uint8_t Broadcast_Code[16];
|
||||
uint8_t MSE;
|
||||
uint16_t BIG_Sync_Timeout;
|
||||
uint8_t Num_BIS;
|
||||
uint8_t BIS[0];
|
||||
} _GNU_PACKED_ le_big_create_sync_t;
|
||||
|
||||
/*! \brief LE BIG Terminate Sync */
|
||||
typedef struct {
|
||||
uint8_t BIG_Handle;
|
||||
} _GNU_PACKED_ le_big_terminate_sync_t;
|
||||
|
||||
/*! \brief LE Read ISO TX Sync */
|
||||
typedef struct {
|
||||
uint16_t Connection_Handle;
|
||||
} _GNU_PACKED_ le_read_iso_tx_sync_t;
|
||||
|
||||
/*! \brief HCI ISO Data packets */
|
||||
typedef struct {
|
||||
uint32_t Connection_Handle : 12;
|
||||
uint32_t PB_Flag : 2;
|
||||
uint32_t TS_Flag : 1;
|
||||
uint32_t RFU : 1;
|
||||
uint32_t ISO_Data_Load_Length : 14;
|
||||
uint32_t RFU2 : 2;
|
||||
|
||||
uint32_t Time_Stamp;
|
||||
|
||||
uint32_t Packet_Sequence_Num : 16;
|
||||
uint32_t ISO_SDU_Length : 12;
|
||||
uint32_t RFU3 : 2;
|
||||
uint32_t Packet_Status_Flag : 2;
|
||||
|
||||
uint8_t ISO_SDU_Fragment[0];
|
||||
} _GNU_PACKED_ hci_iso_data_packets_t ;
|
||||
|
||||
typedef struct {
|
||||
u32 handle : 12;
|
||||
//0b00 frist fragment of a fragmented SDU
|
||||
//0b01 a continuation fragment of a fragmented SDU
|
||||
//0b10 a complete SDU
|
||||
//0b11 the last fragment of an SDU
|
||||
u32 pb_flag : 2;
|
||||
u32 ts_flag : 1;
|
||||
u32 rfu : 1;
|
||||
u32 iso_data_load_length : 14;
|
||||
u32 rfu2 : 2;
|
||||
|
||||
u32 time_stamp;
|
||||
|
||||
u32 packet_sequence_num : 16;
|
||||
u32 iso_sdu_length : 12;
|
||||
u32 rfu3 : 2;
|
||||
//0b00 Valid data. The complete ISO_SDU was received correctly.
|
||||
//0b01 Possibly invalid data. The contents of the ISO_SDU may contain errors or
|
||||
// part of the ISO_SDU may be missing. This is reported as "data with possible
|
||||
// errors".
|
||||
//0b10 Part(s) of the ISO_SDU were not received correctly. This is reported as
|
||||
// "lost data".
|
||||
u32 packet_status_flag : 2;
|
||||
|
||||
uint8_t *iso_sdu;
|
||||
} hci_iso_hdr_t;
|
||||
|
||||
/*! \brief LE BIGInfo Advertising report event */
|
||||
typedef struct {
|
||||
// uint8_t Subevent_Code;
|
||||
uint16_t Sync_Handle;
|
||||
uint8_t Num_BIS;
|
||||
uint8_t NSE;
|
||||
uint16_t ISO_Interval;
|
||||
uint8_t BN;
|
||||
uint8_t PTO;
|
||||
uint8_t IRC;
|
||||
uint16_t Max_PDU;
|
||||
uint8_t SDU_Interval[3];
|
||||
uint16_t Max_SDU;
|
||||
uint8_t PHY;
|
||||
uint8_t Framing;
|
||||
uint8_t Encryption;
|
||||
} _GNU_PACKED_ le_biginfo_adv_report_evt_t;
|
||||
|
||||
/*! \brief LE Create BIG Complete event */
|
||||
typedef struct {
|
||||
// uint8_t Subevent_Code;
|
||||
uint8_t Status;
|
||||
uint32_t BIG_Handle : 8,
|
||||
BIG_Sync_Delay : 24;
|
||||
uint32_t Transport_Latency_BIG : 24,
|
||||
PHY : 8;
|
||||
uint8_t NSE;
|
||||
uint8_t BN;
|
||||
uint8_t PTO;
|
||||
uint8_t IRC;
|
||||
uint16_t Max_PDU;
|
||||
uint16_t ISO_Interval;
|
||||
uint8_t Num_BIS;
|
||||
uint16_t Connection_Handle[0];
|
||||
} _GNU_PACKED_ le_create_big_complete_evt_t;
|
||||
|
||||
/*! \brief LE BIG Sync Established event */
|
||||
typedef struct {
|
||||
// uint8_t Subevent_Code;
|
||||
uint8_t Status;
|
||||
uint8_t BIG_Handle;
|
||||
uint32_t Transport_Latency_BIG : 24,
|
||||
NSE : 8;
|
||||
uint8_t BN;
|
||||
uint8_t PTO;
|
||||
uint8_t IRC;
|
||||
uint16_t Max_PDU;
|
||||
uint16_t ISO_Interval;
|
||||
uint8_t Num_BIS;
|
||||
uint16_t Connection_Handle[0];
|
||||
} _GNU_PACKED_ le_big_sync_established_evt_t;
|
||||
|
||||
/*! \brief LE Read ISO TX Sync Return Parameters */
|
||||
typedef struct {
|
||||
uint8_t Status;
|
||||
uint16_t Connection_Handle;
|
||||
uint16_t Paket_Sequence_Number;
|
||||
uint32_t TX_Time_Stamp;
|
||||
uint32_t Time_Offset : 24;
|
||||
} _GNU_PACKED_ le_read_iso_tx_sync_ret_t;
|
||||
|
||||
/*! \brief LE BIG Sync Lost event */
|
||||
typedef struct {
|
||||
uint8_t BIG_Handle;
|
||||
uint8_t Reason;
|
||||
} _GNU_PACKED_ le_big_sync_lost_evt_t;
|
||||
|
||||
/*! \brief LE CIS Request event */
|
||||
typedef struct {
|
||||
// uint8_t Subevent_Code;
|
||||
uint16_t ACL_Connection_Handle;
|
||||
uint16_t CIS_Connection_Handle;
|
||||
uint8_t CIG_ID;
|
||||
uint8_t CIS_ID;
|
||||
} _GNU_PACKED_ le_cis_request_evt_t;
|
||||
|
||||
/*! \brief LE CIS Established event */
|
||||
typedef struct {
|
||||
// uint8_t Subevent_Code;
|
||||
uint8_t Status;
|
||||
uint16_t Connection_Handle;
|
||||
uint8_t CIG_Sync_Delay[3];
|
||||
uint8_t CIS_Sync_Delay[3];
|
||||
uint8_t Transport_Latency_C_To_P[3];
|
||||
uint8_t Transport_Latency_P_To_C[3];
|
||||
uint8_t PHY_C_To_P;
|
||||
uint8_t PHY_P_To_C;
|
||||
uint8_t NSE;
|
||||
uint8_t BN_C_To_P;
|
||||
uint8_t BN_P_To_C;
|
||||
uint8_t FT_C_To_P;
|
||||
uint8_t FT_P_To_C;
|
||||
uint16_t Max_PDU_C_To_P;
|
||||
uint16_t Max_PDU_P_To_C;
|
||||
uint16_t ISO_Interval;
|
||||
} _GNU_PACKED_ le_cis_established_evt_t;
|
||||
|
||||
//Adjust Host part API
|
||||
void ll_hci_init(void);
|
||||
|
||||
void ll_hci_reset(void);
|
||||
|
||||
void ll_hci_destory(void);
|
||||
|
||||
void ll_hci_set_event_mask(const u8 *mask);
|
||||
|
||||
void ll_hci_set_name(const char *name);
|
||||
|
||||
void ll_hci_adv_set_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type,
|
||||
uint8_t direct_address_type, uint8_t *direct_address,
|
||||
uint8_t channel_map, uint8_t filter_policy);
|
||||
|
||||
void ll_hci_adv_set_data(uint8_t advertising_data_length, uint8_t *advertising_data);
|
||||
|
||||
void ll_hci_adv_scan_response_set_data(uint8_t scan_response_data_length, uint8_t *scan_response_data);
|
||||
|
||||
int ll_hci_adv_enable(bool enable);
|
||||
|
||||
void ll_hci_scan_set_params(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window);
|
||||
|
||||
int ll_hci_scan_enable(bool enable, u8 filter_duplicates);
|
||||
|
||||
int ll_hci_create_conn(u8 *conn_param, u8 *addr_param);
|
||||
int ll_hci_create_conn_ext(void *param);
|
||||
|
||||
int ll_hci_create_conn_cancel(void);
|
||||
|
||||
int ll_hci_vendor_send_key_num(u16 con_handle, u8 num);
|
||||
|
||||
int ll_vendor_latency_hold_cnt(u16 conn_handle, u16 hold_cnt);
|
||||
|
||||
int ll_hci_encryption(u8 *key, u8 *plaintext_data);
|
||||
|
||||
int ll_hci_get_le_rand(void);
|
||||
|
||||
|
||||
int ll_hci_start_encryption(u16 handle, u32 rand_low, u32 rand_high, u16 peer_ediv, u8 *ltk);
|
||||
|
||||
int ll_hci_long_term_key_request_reply(u16 handle, u8 *ltk);
|
||||
|
||||
int ll_hci_long_term_key_request_nagative_reply(u16 handle);
|
||||
|
||||
int ll_hci_connection_update(u16 handle, u16 conn_interval_min, u16 conn_interval_max,
|
||||
u16 conn_latency, u16 supervision_timeout,
|
||||
u16 minimum_ce_length, u16 maximum_ce_length);
|
||||
|
||||
u16 ll_hci_get_acl_data_len(void);
|
||||
|
||||
u16 ll_hci_get_acl_total_num(void);
|
||||
|
||||
void ll_hci_set_random_address(u8 *addr);
|
||||
|
||||
int ll_hci_disconnect(u16 handle, u8 reason);
|
||||
|
||||
int ll_hci_read_local_p256_pb_key(void);
|
||||
|
||||
int ll_hci_generate_dhkey(const u8 *data, u32 size);
|
||||
|
||||
//Adjust Controller part API
|
||||
void ll_hci_cmd_handler(int *cmd);
|
||||
|
||||
void ll_event_handler(int *msg);
|
||||
|
||||
void ll_hci_private_free_dma_rx(u8 *rx_head);
|
||||
|
||||
void ll_hci_set_data_length(u16 conn_handle, u16 tx_octets, u16 tx_time);
|
||||
|
||||
hci_ll_param_t *ll_hci_param_config_get(void);
|
||||
void hci_ll_get_device_address(uint8_t *addr_type, u8 *addr);
|
||||
void ll_hci_set_host_channel_classification(u8 *channel_map);
|
||||
|
||||
// ble5
|
||||
void ll_hci_set_ext_adv_params(u8 *data, u32 size);
|
||||
void ll_hci_set_ext_adv_data(u8 *data, u32 size);
|
||||
void ll_hci_set_ext_adv_enable(u8 *data, u32 size);
|
||||
void ll_hci_set_phy(u16 conn_handle, u8 all_phys, u8 tx_phy, u8 rx_phy, u16 phy_options);
|
||||
void ll_hci_set_ext_scan_params(u8 *data, u32 size);
|
||||
void ll_hci_set_ext_scan_enable(u8 *data, u32 size);
|
||||
void ll_hci_ext_create_conn(u8 *data, u32 size);
|
||||
void ll_hci_set_periodic_adv_params(u8 *data, u32 size);
|
||||
void ll_hci_set_periodic_adv_data(u8 *data, u32 size);
|
||||
void ll_hci_set_periodic_adv_enable(u8 *data, u32 size);
|
||||
void ll_hci_periodic_adv_creat_sync(u8 *data, u32 size);
|
||||
void ll_hci_periodic_adv_terminate_sync(u8 *data, u32 size);
|
||||
void ll_hci_periodic_adv_create_sync_cancel(void);
|
||||
void ll_hci_set_cig_params(uint8_t *data, size_t size);
|
||||
void ll_hci_create_cis(uint8_t *data, size_t size);
|
||||
void ll_hci_remove_cig(uint8_t *data, size_t size);
|
||||
void ll_hci_accept_cis_req(uint8_t *data, size_t size);
|
||||
void ll_hci_create_big(uint8_t *data, size_t size);
|
||||
void ll_hci_big_create_sync(uint8_t *data, size_t size);
|
||||
void ll_hci_big_terminate_sync(uint8_t *data, size_t size);
|
||||
void ll_hci_read_iso_tx_sync(uint8_t *data, size_t size);
|
||||
void ll_hci_setup_iso_data_path(uint8_t *data, size_t size);
|
||||
void ll_hci_read_iso_tx_sync(uint8_t *data, size_t size);
|
||||
|
||||
int le_controller_set_mac(void *addr);
|
||||
void hci_add_event_handler(void *callback_handler);
|
||||
void hci_remove_event_handler(void *callback_handler);
|
||||
|
||||
/* vendor */
|
||||
void hci_iso_receive_callback_register(void *callback);
|
||||
void ll_big_tx_align_callback_register(uint8_t big_handle, const void *callback);
|
||||
void ll_config_ctrler_clk(uint16_t handle, uint8_t sel);
|
||||
void ll_get_ctrler_clk(uint16_t hdl, uint16_t *us_1per12, uint32_t *ref_clk_us, uint32_t *evt);
|
||||
void ll_set_vendor_param(uint8_t *vendor_param, size_t size);
|
||||
void ll_cig_tx_align_callback_register(uint8_t cig_id, const void *callback);
|
||||
void ll_conn_rx_acl_callback_register(void (*callback)(uint8_t *packet, size_t size));
|
||||
void ll_set_scan_priority(uint8_t priority);
|
||||
void rf_mdm_con_ble_sync_word(int tws_esco);
|
||||
uint8_t ll_iso_unpack_hdr(const uint8_t *sdu, hci_iso_hdr_t *hdr);
|
||||
void access_addr_generate(u8 *aa);
|
||||
|
||||
typedef void (*timeout_callback_t)(void *priv);
|
||||
|
||||
void bb_le_timer_set(uint8_t idx, uint32_t usec, timeout_callback_t callback, void *priv);
|
||||
u32 bb_le_clk_get_time_us(void);
|
||||
uint8_t bb_le_timer_get(void);
|
||||
void bb_le_timer_reset(uint8_t idx, uint32_t usec);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : ll_config.h
|
||||
|
||||
* Description : Lto 优化Macro 定义
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2018-12-19 16:12
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _LL_CONFIG_H_
|
||||
#define _LL_CONFIG_H_
|
||||
#include <stdint.h> //for UINT64_C
|
||||
|
||||
/*
|
||||
*-------------------LE FEATURE SUPPORT
|
||||
* brief : 运行时优化(LTO)下,代码空间优化;
|
||||
*/
|
||||
|
||||
/* --- Core Spec 4.0 --- */
|
||||
#define LL_FEAT_ENCRYPTION (UINT64_C(1) << ( 0)) /*!< Encryption supported. */
|
||||
/* --- Core Spec 4.2 --- */
|
||||
#define LL_FEAT_CONN_PARAM_REQ_PROC (UINT64_C(1) << ( 1)) /*!< Connection Parameters Request Procedure supported. */
|
||||
#define LL_FEAT_EXT_REJECT_IND (UINT64_C(1) << ( 2)) /*!< Extended Reject Indication supported. */
|
||||
#define LL_FEAT_SLV_INIT_FEAT_EXCH (UINT64_C(1) << ( 3)) /*!< Slave-Initiated Features Exchange supported. */
|
||||
#define LL_FEAT_LE_PING (UINT64_C(1) << ( 4)) /*!< LE Ping supported. */
|
||||
#define LL_FEAT_DATA_LEN_EXT (UINT64_C(1) << ( 5)) /*!< Data Length Extension supported. */
|
||||
#define LL_FEAT_PRIVACY (UINT64_C(1) << ( 6)) /*!< LL Privacy supported. */
|
||||
#define LL_FEAT_EXT_SCAN_FILT_POLICY (UINT64_C(1) << ( 7)) /*!< Extended Scan Filter Policy supported. */
|
||||
/* --- Core Spec 5.0 --- */
|
||||
#define LL_FEAT_LE_2M_PHY (UINT64_C(1) << ( 8)) /*!< LE 2M PHY supported. */
|
||||
#define LL_FEAT_STABLE_MOD_IDX_TRANSMITTER (UINT64_C(1) << ( 9)) /*!< Stable Modulation Index - Transmitter supported. */
|
||||
#define LL_FEAT_STABLE_MOD_IDX_RECEIVER (UINT64_C(1) << (10)) /*!< Stable Modulation Index - Receiver supported. */
|
||||
#define LL_FEAT_LE_CODED_PHY (UINT64_C(1) << (11)) /*!< LE Coded PHY supported. */
|
||||
#define LL_FEAT_LE_EXT_ADV (UINT64_C(1) << (12)) /*!< LE Extended Advertising supported. */
|
||||
#define LL_FEAT_LE_PER_ADV (UINT64_C(1) << (13)) /*!< LE Periodic Advertising supported. */
|
||||
#define LL_FEAT_CH_SEL_2 (UINT64_C(1) << (14)) /*!< Channel Selection Algorithm #2 supported. */
|
||||
#define LL_FEAT_LE_POWER_CLASS_1 (UINT64_C(1) << (15)) /*!< LE Power Class 1 supported. */
|
||||
#define LL_FEAT_MIN_NUM_USED_CHAN (UINT64_C(1) << (16)) /*!< Minimum Number of Used Channels supported. */
|
||||
/* --- Core Spec 5.1 --- */
|
||||
#define LL_FEAT_CONN_CTE_REQ (UINT64_C(1) << (17)) /*!< Connection CTE Request supported */
|
||||
#define LL_FEAT_CONN_CTE_RSP (UINT64_C(1) << (18)) /*!< Connection CTE Response supported */
|
||||
#define LL_FEAT_CONNLESS_CTE_TRANS (UINT64_C(1) << (19)) /*!< Connectionless CTE Transmitter supported */
|
||||
#define LL_FEAT_CONNLESS_CTE_RECV (UINT64_C(1) << (20)) /*!< Connectionless CTE Receiver supported */
|
||||
#define LL_FEAT_ANTENNA_SWITCH_AOD (UINT64_C(1) << (21)) /*!< Anetenna Switching during CTE Transmission (AoD) supported */
|
||||
#define LL_FEAT_ANTENNA_SWITCH_AOA (UINT64_C(1) << (22)) /*!< Anetenna Switching during CTE Reception (AoA) supported */
|
||||
#define LL_FEAT_RECV_CTE (UINT64_C(1) << (23)) /*!< Receive Constant Tone Extension supported */
|
||||
#define LL_FEAT_PAST_SENDER (UINT64_C(1) << (24)) /*!< Periodic Advertising Sync Transfer – Sender supported. */
|
||||
#define LL_FEAT_PAST_RECIPIENT (UINT64_C(1) << (25)) /*!< Periodic Advertising Sync Transfer – Recipient supported. */
|
||||
#define LL_FEAT_SCA_UPDATE (UINT64_C(1) << (26)) /*!< Sleep Clock Accuracy Updates supported. */
|
||||
#define LL_FEAT_REMOTE_PUB_KEY_VALIDATION (UINT64_C(1) << (27)) /*!< Remote Public Key Validation supported. */
|
||||
/* --- Core Spec 5.2 --- */
|
||||
#define LL_FEAT_CIS_MASTER_ROLE (UINT64_C(1) << (28)) /*!< Connected Isochronous Stream Master Role supported. */
|
||||
#define LL_FEAT_CIS_SLAVE_ROLE (UINT64_C(1) << (29)) /*!< Connected Isochronous Stream Slave Role supported. */
|
||||
#define LL_FEAT_ISO_BROADCASTER (UINT64_C(1) << (30)) /*!< Isochronous Broadcaster Role supported. */
|
||||
#define LL_FEAT_ISO_SYNC (UINT64_C(1) << (31)) /*!< Isochronous Synchronizer Role supported. */
|
||||
#define LL_FEAT_ISO_HOST_SUPPORT (UINT64_C(1) << (32)) /*!< Host support for ISO Channels. */
|
||||
#define LL_FEAT_POWER_CONTROL_REQUEST (UINT64_C(1) << (33)) /*!< Power control requests supported. */
|
||||
#define LL_FEAT_POWER_CHANGE_IND (UINT64_C(1) << (34)) /*!< Power control power change indication supported. */
|
||||
#define LL_FEAT_PATH_LOSS_MONITOR (UINT64_C(1) << (35)) /*!< Path loss monitoring supported. */
|
||||
|
||||
#define LL_FEAT_PATH_LOSS_MONITOR (UINT64_C(1) << (35)) /*!< Path loss monitoring supported. */
|
||||
#define LL_FEAT_PERIODIC_ADV_ADI_SUPPORT (UINT64_C(1) << (36)) /*!< Periodic Advertising ADI supported. */
|
||||
#define LL_FEAT_CONN_SUBRATE (UINT64_C(1) << (37)) /*!< Connection subrating supported. */
|
||||
#define LL_FEAT_CONN_SUBRATE_HOST_SUPPORT (UINT64_C(1) << (38)) /*!< Connection subratingHost supported. */
|
||||
#define LL_FEAT_CHANNEL_CLASSIFICATION (UINT64_C(1) << (39)) /*!< Channel classification supported. */
|
||||
|
||||
#define LL_FEAT_VENDOR_BIG_SYNC_TRANSFER (UINT64_C(1) << (62)) /*!< Vendor BIG sync transfer. */
|
||||
#define LL_FEAT_VENDOR_BIG_TRANSFER (UINT64_C(1) << (63)) /*!< Vendor BIG transfer. */
|
||||
|
||||
#define LE_ENCRYPTION LL_FEAT_ENCRYPTION
|
||||
#define CONNECTION_PARAMETER_REQUEST LL_FEAT_CONN_PARAM_REQ_PROC
|
||||
#define EXTENDED_REJECT_INDICATION LL_FEAT_EXT_REJECT_IND
|
||||
#define LE_SLAVE_INIT_FEATURES_EXCHANGE LL_FEAT_SLV_INIT_FEAT_EXCH
|
||||
#define LE_PING LL_FEAT_LE_PING
|
||||
#define LE_DATA_PACKET_LENGTH_EXTENSION LL_FEAT_DATA_LEN_EXT
|
||||
#define LL_PRIVACY LL_FEAT_PRIVACY
|
||||
#define EXTENDED_SCANNER_FILTER_POLICIES LL_FEAT_EXT_SCAN_FILT_POLICY
|
||||
#define LE_2M_PHY LL_FEAT_LE_2M_PHY
|
||||
#define LE_CODED_PHY LL_FEAT_LE_CODED_PHY
|
||||
#define LE_EXTENDED_ADVERTISING LL_FEAT_LE_EXT_ADV
|
||||
#define LE_PERIODIC_ADVERTISING LL_FEAT_LE_PER_ADV
|
||||
#define CHANNEL_SELECTION_ALGORITHM_2 LL_FEAT_CH_SEL_2
|
||||
|
||||
|
||||
#define LE_CORE_V50_FEATURES \
|
||||
( \
|
||||
LE_2M_PHY | \
|
||||
LE_CODED_PHY | \
|
||||
LE_EXTENDED_ADVERTISING | \
|
||||
LE_PERIODIC_ADVERTISING | \
|
||||
CHANNEL_SELECTION_ALGORITHM_2 | \
|
||||
0 \
|
||||
)
|
||||
|
||||
#if (LE_CORE_V50_FEATURES & LE_PERIODIC_ADVERTISING)
|
||||
#if ((LE_CORE_V50_FEATURES & LE_EXTENDED_ADVERTISING) == 0)
|
||||
#error "enable <LE_PERIODIC_ADVERTISING> must enable <LE_EXTENDED_ADVERTISING> at the same time"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define LE_FEATURES_CONST_TONE (LL_FEAT_CONN_CTE_REQ | \
|
||||
LL_FEAT_CONN_CTE_RSP | \
|
||||
LL_FEAT_CONNLESS_CTE_TRANS | \
|
||||
LL_FEAT_CONNLESS_CTE_RECV | \
|
||||
LL_FEAT_ANTENNA_SWITCH_AOD | \
|
||||
LL_FEAT_ANTENNA_SWITCH_AOA | \
|
||||
LL_FEAT_RECV_CTE)
|
||||
|
||||
#define LE_FEATURES_PAST (LL_FEAT_PAST_SENDER | \
|
||||
LL_FEAT_PAST_RECIPIENT)
|
||||
|
||||
#define LE_FEATURES_CIS (LL_FEAT_CIS_MASTER_ROLE | \
|
||||
LL_FEAT_CIS_SLAVE_ROLE | \
|
||||
LL_FEAT_ISO_HOST_SUPPORT)
|
||||
|
||||
#define LE_FEATURES_BIS (LL_FEAT_ISO_BROADCASTER | \
|
||||
LL_FEAT_ISO_SYNC | \
|
||||
LL_FEAT_ISO_HOST_SUPPORT)
|
||||
|
||||
#define LE_FEATURES_ISO (LE_FEATURES_BIS|LE_FEATURES_CIS)
|
||||
|
||||
#define LE_FEATURES_POWER_CONTROL (LL_FEAT_POWER_CONTROL_REQUEST | \
|
||||
LL_FEAT_POWER_CHANGE_IND | \
|
||||
LL_FEAT_PATH_LOSS_MONITOR)
|
||||
|
||||
extern const uint64_t config_btctler_le_features;
|
||||
#define LE_FEATURES_IS_SUPPORT(x) (config_btctler_le_features & (x))
|
||||
|
||||
#define LE_FEATURES_IS_SUPPORT_OPTIMIZE(x) if (LE_FEATURES_IS_SUPPORT(x) == 0x0) return
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
*-------------------LE ROLES SUPPORT
|
||||
* brief : 运行时优化(LTO)下,代码空间优化;
|
||||
*/
|
||||
#define LE_MASTER BIT(0)
|
||||
#define LE_SLAVE BIT(1)
|
||||
#define LE_ADV BIT(2)
|
||||
#define LE_SCAN BIT(3)
|
||||
#define LE_INIT BIT(4)
|
||||
|
||||
/*! \brief Combination */
|
||||
#define LE_CONN (LE_MASTER|LE_SLAVE)
|
||||
|
||||
extern const int config_btctler_le_roles;
|
||||
#define LE_ROLES_IS_SUPPORT(x) (config_btctler_le_roles & x)
|
||||
|
||||
#define LE_ROLES_IS_SUPPORT_OPTIMIZE(x) if (LE_ROLES_IS_SUPPORT(x) == 0x0) return
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
extern const int config_btctler_le_tws;
|
||||
#define LE_TWS_IS_SUPPORT() (config_btctler_le_tws)
|
||||
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
extern const int config_btctler_le_afh_en;
|
||||
#define LE_AFH_IS_SUPPORT() (config_btctler_le_afh_en)
|
||||
|
||||
#define LE_AFH_IS_SUPPORT_OPTIMIZE(x) if (LE_AFH_IS_SUPPORT() == 0x0) return
|
||||
|
||||
/*
|
||||
*-------------------LE PARAM CHECK
|
||||
* brief : 运行时优化(LTO)下,代码空间优化;
|
||||
*/
|
||||
// extern const int config_btctler_le_param_check;
|
||||
#define LE_PARAM_IS_CHECK() TRUE//(config_btctler_le_param_check)
|
||||
/*
|
||||
*-------------------LE RAM CONTROL
|
||||
*
|
||||
*/
|
||||
extern const int config_btctler_le_hw_nums;
|
||||
extern const int config_btctler_le_rx_nums;
|
||||
extern const int config_btctler_le_acl_packet_length;
|
||||
extern const int config_btctler_le_acl_total_nums;
|
||||
extern const int config_btctler_le_slave_conn_update_winden;
|
||||
extern const int config_btctler_le_iso_tx;
|
||||
extern const int config_btctler_le_iso_rx;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
*-------------------LE Multi-link CONTROL
|
||||
*/
|
||||
extern const int config_btctler_le_master_multilink;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
*-------------------LE Vendor baseband CONTROL
|
||||
*/
|
||||
#define VENDOR_BB_PIS_EN BIT(0)
|
||||
#define VENDOR_BB_PIS_HB BIT(1)
|
||||
#define VENDOR_BB_PIS_HB_M BIT(2)
|
||||
#define VENDOR_BB_MD_CLOSE BIT(3)
|
||||
#define VENDOR_BB_CONNECT_SLOT BIT(4)
|
||||
#define VENDOR_BB_NEW_SCAN_STRATEGY BIT(5)
|
||||
#define VENDOR_BB_VENDOR_AFH BIT(5)
|
||||
#define VENDOR_BB_PIS_HB_R BIT(6)
|
||||
#define VENDOR_BB_WL_COEX_ROLE_EN BIT(6)
|
||||
#define VENDOR_BB_WL_COEX_ROLE BIT(7)
|
||||
#define VENDOR_BB_ADV_PDU_INT(x) ((x) << 8) /* 4bit */
|
||||
#define VENDOR_BB_EVT_HOLD_TRIGG(x) ((x) << 12) /* 6bit */
|
||||
#define VENDOR_BB_RX_PAYLOAD_LEN(x) ((x) << 18) /* 7bit */
|
||||
#define VENDOR_BB_PIS_TX_PAYLOAD_LEN(x) ((x) << 25) /* 7bit*/
|
||||
|
||||
extern const u32 config_vendor_le_bb;
|
||||
extern const int config_ble_adv_tx_pwr_level;
|
||||
extern const int config_rf_oob;
|
||||
extern const int config_bb_optimized_ctrl;
|
||||
|
||||
// config_bb_optimized_ctrl 控制变量说明
|
||||
#define LE_BB_OPT_FEAT_PKT_UNFILT BIT(0)
|
||||
#define LE_BB_OPT_FEAT_EXT_UPLOAD_EN BIT(1)
|
||||
#define LE_BB_OPT_FEAT_CC_CODE_EN BIT(2)
|
||||
#define LE_BB_OPT_FEAT_RESERVED0 BIT(3)
|
||||
#define LE_BB_OPT_FEAT_HARD_CMB_EN BIT(4)
|
||||
#define LE_BB_OPT_FEAT_RX_LOG_EN BIT(5) //only for big rx
|
||||
#define LE_BB_OPT_FEAT_RSSI_AFH_EN BIT(6)
|
||||
#define LE_BB_OPT_FEAT_PWR_CTRL_EN BIT(7)
|
||||
#define LE_BB_OPT_FEAT_RX_PRE_CLOSE BIT(8)
|
||||
#define LE_BB_OPT_FEAT_TX_PWR_LOW_SEL BIT(9) //only for br29
|
||||
#define LE_BB_OPT_FEAT_PER_AFH_EN BIT(10)
|
||||
#define LE_BB_OPT_FEAT_RESERVED1 BIT(11)|BIT(12)
|
||||
#define LE_BB_OPT_FEAT_CIG_ENC_DIS BIT(13)
|
||||
#define LE_BB_OPT_FEAT_CIG_SEVT_CLOSE BIT(14)
|
||||
#define LE_BB_OPT_FEAT_CIG_PACK_MODE BIT(16) //sequential or interleved
|
||||
#define LE_BB_OPT_FEAT_CODE_OPTIMIZED BIT(17)
|
||||
#define LE_BB_OPT_FEAT_CIG_RSSI_GET_EN BIT(18)
|
||||
#define LE_BB_OPT_FEAT_PKT_V3_EN BIT(18)
|
||||
#define LE_BB_OPT_FEAT_PKT_V3_DYNAMIC BIT(19) //only for rx
|
||||
#define LE_BB_OPT_FEAT_ISO_DIRECT_PUSH BIT(21)
|
||||
#define LE_BB_OPT_FEAT_BCTRL_DISABLE BIT(22)
|
||||
|
||||
#define LE_ADV_RSSI_AFH_EN() (config_bb_optimized_ctrl & BIT(6))
|
||||
#define LE_ADV_PER_AFH_EN() (config_bb_optimized_ctrl & BIT(10))
|
||||
#define LE_ADV_PWR_CTRL_EN() (config_bb_optimized_ctrl & BIT(7))
|
||||
#define LE_BIS_RX_PRE_CLOSE() (config_bb_optimized_ctrl & BIT(8))
|
||||
#define LE_VENDOR_API_EN() (config_bb_optimized_ctrl & BIT(31))
|
||||
|
||||
struct le_adv_link_param_cfg {
|
||||
u8 param1;
|
||||
s8 param2[2];
|
||||
s8 param3[2];
|
||||
u8 param4[2];
|
||||
u8 param5;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
*-------------------LE close wait
|
||||
*/
|
||||
extern const int ble_disable_wait_enable;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#endif //_LL_CONFIG_H_
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : btcontroller_modules.h
|
||||
|
||||
* Description : Lto 优化Macro 定义
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2018-12-19 16:38
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _BTCONTROLLER_MODE_H_
|
||||
#define _BTCONTROLLER_MODE_H_
|
||||
|
||||
/*
|
||||
ble 测试串口默认使用usb口,代码要确保usb口没有其他地方使用
|
||||
开启测试模式,uart0 key 等一些功能默认关闭,请看特殊情况
|
||||
自行处理
|
||||
|
||||
1、提供实验室测试rf bqb的时候配 BT_BQB
|
||||
|
||||
2、提供实验室测试rf fcc的时候配 BT_FCC
|
||||
|
||||
3、如果要定频测试配BT_FRE 频点:2402 , 发射功率最大
|
||||
|
||||
4、性能测试配BT_PER,使用仪器直接连接测试即可,测试完毕后
|
||||
需要复位或者上电开机才会恢复正常流程,不复位或上电的话只支持链接一个设备
|
||||
|
||||
量产测试性能可直接配BT_NORMAL 然后通过某个外部操作来
|
||||
调用 void bredr_set_dut_enble(u8 en,u8 phone )
|
||||
en 1 :使能 bredr dut 测试然后就可以使用仪器链接测试
|
||||
phone: 1 可以被手机连接,0 不可以被手机连接上
|
||||
|
||||
如果样机通过按键等操作进入dut测试调用bredr_set_dut_enble使能可以被仪器链接,
|
||||
同时调用下面函数,关闭耳机快速链接,开启可发现可链接
|
||||
tws_cancle_all_noconn() ;
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL);
|
||||
|
||||
|
||||
5、可以调用 void bt_fix_fre_api() 函数实现经典蓝牙定频测试,频点2402,发射功率最大,
|
||||
调用后不可恢复之前状态,只是用来量产测试,测试完需要复位或重新上电开机!
|
||||
|
||||
6、可以调用 void ble_fix_fre_api()函数实现ble定频测试,发射功率最大,
|
||||
|
||||
*/
|
||||
|
||||
#define BT_NORMAL 0x01
|
||||
#define BT_BQB 0x02
|
||||
#define BT_FCC 0x04
|
||||
#define BT_FRE 0x10
|
||||
#define BT_PER 0x20
|
||||
|
||||
|
||||
#define CONFIG_BT_MODE BT_NORMAL
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,290 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : btcontroller_modules.h
|
||||
|
||||
* Description : Lto 优化Macro 定义
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2018-12-19 16:38
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _BTCONTROLLER_H_
|
||||
#define _BTCONTROLLER_H_
|
||||
|
||||
#include "hci_transport.h"
|
||||
#include "btcontroller_mode.h"
|
||||
|
||||
#include "ble/hci_ll.h"
|
||||
|
||||
#include "classic/hci_lmp.h"
|
||||
|
||||
|
||||
/* app 层修改蓝牙版本,可在BT_STATUS_INIT_OK case
|
||||
调用 set_bt_version 函数更改蓝牙版本号
|
||||
*/
|
||||
#define BLUETOOTH_CORE_SPEC_42 0x08
|
||||
#define BLUETOOTH_CORE_SPEC_50 0x09
|
||||
#define BLUETOOTH_CORE_SPEC_51 0x0a
|
||||
#define BLUETOOTH_CORE_SPEC_52 0x0b
|
||||
extern void set_bt_version(u8 version);
|
||||
|
||||
|
||||
/*
|
||||
*-------------------Module SUPPORT
|
||||
* brief : 运行时优化(LTO)下,代码空间优化;
|
||||
*/
|
||||
#define BT_MODULE_CLASSIC BIT(0)
|
||||
#define BT_MODULE_LE BIT(1)
|
||||
|
||||
extern const int config_btctler_modules;
|
||||
#define BT_MODULES_IS_SUPPORT(x) (config_btctler_modules & (x))
|
||||
/*-----------------------------------------------------------*/
|
||||
extern const int config_stack_modules;
|
||||
#define STACK_MODULES_IS_SUPPORT(x) (config_stack_modules & (x))
|
||||
|
||||
/*
|
||||
*-------------------Mode SELECT
|
||||
* brief : 运行时优化(LTO)下,代码空间优化;
|
||||
*/
|
||||
extern const int config_btctler_mode;
|
||||
#define BT_MODE_IS(x) (config_btctler_mode & (x))
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
extern const int config_btctler_hci_standard;
|
||||
#define BT_HCI_STANDARD_IS_SUPPORT(x) (config_btctler_hci_standard)
|
||||
|
||||
|
||||
extern const int config_bt_function ;
|
||||
#define BT_ENCTRY_TASK BIT(0)
|
||||
#define BT_MASTER_AFH BIT(1)
|
||||
#define BT_MASTER_QOS BIT(2)
|
||||
|
||||
|
||||
#define BT_FUNCTION_IS(x) (config_bt_function & (x))
|
||||
|
||||
|
||||
/*---------------------- tws fun-------------------------------------*/
|
||||
|
||||
extern const int CONFIG_BTCTLER_TWS_FUN;
|
||||
#define TWS_ESCO_FORWARD BIT(0) ///tws 通话转发使能
|
||||
|
||||
|
||||
#define TWS_FUNCTION_IS(x) ( CONFIG_BTCTLER_TWS_FUN & (x))
|
||||
|
||||
/*---------------------- tws fun end -------------------------------------*/
|
||||
|
||||
|
||||
extern const int CONFIG_TEST_DUT_CODE;
|
||||
extern const int CONFIG_TEST_FCC_CODE;
|
||||
extern const int CONFIG_TEST_DUT_ONLY_BOX_CODE;
|
||||
extern const int CONFIG_BREDR_INQUIRY;
|
||||
|
||||
extern const int CONFIG_INQUIRY_PAGE_OFFSET_ADJUST ;
|
||||
|
||||
extern const int CONFIG_LMP_NAME_REQ_ENABLE ;
|
||||
extern const int CONFIG_LMP_PASSKEY_ENABLE ;
|
||||
extern const int CONFIG_LMP_MASTER_ESCO_ENABLE ;
|
||||
extern const int config_btctler_bredr_master ;
|
||||
extern const int config_bredr_afh_user ;
|
||||
extern const int config_bredr_master_afh ;
|
||||
extern const int CONFIG_ESCO_MUX_RX_BULK_ENABLE ;
|
||||
extern const int config_bt_temperature_pll_trim ;
|
||||
extern const int CONFIG_WIFI_DETECT_ENABLE;
|
||||
extern const int ESCO_FORWARD_ENABLE;
|
||||
/********************************************************************************/
|
||||
/*
|
||||
* API
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief rf_set_24g_hackable_coded
|
||||
*
|
||||
* @param coded 2.4G 配对码
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void rf_set_24g_hackable_coded(int coded);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bt_pll_para
|
||||
*
|
||||
* @param osc
|
||||
* @param sys
|
||||
* @param low_power
|
||||
* @param xosc
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bt_pll_para(u32 osc, u32 sys, u8 low_power, u8 xosc);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bt_production_test
|
||||
*
|
||||
* @param en
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bt_production_test(u8 en);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bt_set_rxtx_status_enable
|
||||
*
|
||||
* @param en
|
||||
*
|
||||
*
|
||||
|
||||
TX RX
|
||||
AI800x PA13 PA12
|
||||
AC692x PA13 PA12
|
||||
AC693x PA8 PA9
|
||||
AC695x PA9 PA10
|
||||
AC696x PC1 PC2
|
||||
AC694x PB1 PB2
|
||||
AC697x PC2 PC3
|
||||
AC631x PA7 PA8
|
||||
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bt_set_rxtx_status_enable(u8 en);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bt_osc_offset_ext_save
|
||||
*
|
||||
* @param offset
|
||||
*
|
||||
* 更新并且保存频偏
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bt_osc_offset_ext_save(s32 offset);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bt_osc_offset_ext_updata
|
||||
*
|
||||
* @param offset
|
||||
*
|
||||
* 更新频偏
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bt_osc_offset_ext_updata(s32 offset);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 初始化配置蓝牙发射功率最大值范围
|
||||
*
|
||||
* @param pwr edr 连接后发射功率(range:0~9)
|
||||
* @param pg_pwr edr page 可连接状态发射功率
|
||||
* @param iq_pwr edr inquiry 可发现状态发射功率
|
||||
* @param ble_pwr ble 发射功率
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
/*
|
||||
蓝牙TX发射功率档位, 参考功率值(dbm) ,超过等级范围默认设置为最高档
|
||||
BD29: rang(0~8) {-18.3, -14.6, -12.1, -8.5, -6.0, -4.1, -1.1, +1.1, +4.0, +6.1}
|
||||
BD19: rang(0~10) {-17.6, -14.0, -11.5, -9.6, -6.6, -4.4, -0.79, +1.12, +3.8, +5.65, +8.04}
|
||||
BR23: rang(0~9) {-15.7, -12.5, -10.0, -6.6, -4.4, -2.5, -0.1, +2.1, +4.6, +6.4}
|
||||
BR25: rang(0~9) {-15.7, -12.5, -10.0, -6.6, -4.4, -2.5, -0.1, +2.1, +4.6, +6.4}
|
||||
BR30: rang(0~8) {-17.48, -11.46, -7.96, -3.59, -0.79, +1.12, +3.8, +6.5, +8.44}
|
||||
BR34: rang(0~10) {-17.6, -14.0, -11.5, -9.6, -6.6, -4.4, -1.8, 0, +2.1, +4, +6.3}
|
||||
*/
|
||||
|
||||
void bt_max_pwr_set(u8 pwr, u8 pg_pwr, u8 iq_pwr, u8 ble_pwr);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bt_set_ldos
|
||||
*
|
||||
* @param mode
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bt_set_ldos(u8 mode);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief ble_set_fix_pwr
|
||||
*
|
||||
* @param fix (0~max)
|
||||
* 动态调整BLE的发射功率
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void ble_set_fix_pwr(u8 fix);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bredr_set_fix_pwr
|
||||
*
|
||||
* @param fix (0~max)
|
||||
* 动态调整EDR的发射功率
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void bredr_set_fix_pwr(u8 fix);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief ble_rf_vendor_fixed_channel
|
||||
*
|
||||
* @param channel_index: 指定信道定频: range 0~39 fixed freq, or 0xff --close fixed,default 37、38、39
|
||||
* @param pktcnt: adv方式,1次发包的个数: range 1~3
|
||||
* 配置ble 的 adv、scan、init 状态定频
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
bool ble_rf_vendor_fixed_channel(u8 channel_index, u8 pktcnt);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief bredr_get_rssi_for_address
|
||||
* 获取已连接设备的rssi
|
||||
*
|
||||
* @param address 对方mac地址
|
||||
* @return rssi 值,range(-127 ~ +127)
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
s8 bredr_get_rssi_for_address(u8 *address);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 配置tx 是否支持包类型, (sdk默认支持)
|
||||
*
|
||||
* @param packet_type
|
||||
* @param support_en 0 or 1
|
||||
* @return true or false
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
PKT_TYPE_2DH5_EU = 0,
|
||||
} pkt_type_eu;
|
||||
|
||||
bool bredr_link_vendor_support_packet_enable(pkt_type_eu packet_type, u8 support_en);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 配置ble 优先级锁定不低压ACL, (sdk 默认自动调节)
|
||||
*
|
||||
* @param role:0--master,1--slave
|
||||
* @param enalbe 0 or 1
|
||||
* @return null
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void ble_vendor_set_hold_prio(u8 role, u8 enable);
|
||||
|
||||
void set_bt_afh_classs_enc(u8 afh_class);
|
||||
void set_bt_enhanced_power_control(u8 en);
|
||||
void set_bt_data_rate_acl_3mbs_mode(u8 en);
|
||||
|
||||
void set_bt_full_name_event(u8 en);
|
||||
|
||||
/* coexist between bt chips */
|
||||
void bt_wl_coex_init(uint8_t state);
|
||||
void bt_wl_coex_enable(bool enable);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef __BTCTRLER_API_FOR_UPDATE_H__
|
||||
#define __BTCTRLER_API_FOR_UPDATE_H__
|
||||
|
||||
extern u32 bt_updata_get_flag(void);
|
||||
extern void bt_updata_clr_flag(u8 bit_flag);
|
||||
extern u16 bt_updata_control(u8 btupdata_sw, u16 len, u8 seek_type, u32 seek_offsize);
|
||||
extern struct lmp_connection *lmp_conn_for_address(u8 *address);
|
||||
extern void lmp_update_init(void);
|
||||
extern void bt_rf_init(void);
|
||||
extern void bredr_bd_init(void);
|
||||
extern void bredr_link_init(void);
|
||||
extern void lmp_init(void);
|
||||
extern int lmp_hci_write_scan_enable(u8 enable);
|
||||
extern void btctler_nv_memory_apply(void);
|
||||
extern int link_bulk_init(void);
|
||||
extern void stack_run_loop_resume(void);
|
||||
extern void init_soft_interrupt(void);
|
||||
extern void reg_revic_buf_addr(void *addr);
|
||||
extern void lmp_hci_write_local_name(const char *name);
|
||||
extern void lmp_hci_write_local_address(const u8 *addr);
|
||||
extern void lmp_hci_write_super_timeout(u16 timeout);
|
||||
extern void bt_max_pwr_set(u8 pwr, u8 pg_pwr, u8 iq_pwr, u8 ble_pwr);
|
||||
extern void hci_controller_destory(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,253 @@
|
||||
#ifndef LMP_API_H
|
||||
#define LMP_API_H
|
||||
|
||||
|
||||
#include "generic/typedef.h"
|
||||
|
||||
struct a2dp_media_frame {
|
||||
u8 *packet;
|
||||
u32 clkn;
|
||||
u8 coding_type;
|
||||
};
|
||||
|
||||
void lmp_private_a2dp_start(void *_conn);
|
||||
|
||||
void lmp_private_a2dp_stop(void *_conn);
|
||||
|
||||
int lmp_private_is_clearing_a2dp_packet(void *_conn);
|
||||
|
||||
int lmp_private_a2dp_channel_exist(void *_conn);
|
||||
|
||||
int lmp_private_get_sbc_remain_time(void *_conn, u8 include_tws);
|
||||
|
||||
void lmp_private_set_media_type(u8 *addr, u8 type);
|
||||
|
||||
u8 lmp_private_get_media_type(void *conn);
|
||||
|
||||
void *lmp_private_open_sbc_channel(u8 *addr);
|
||||
|
||||
void lmp_private_set_a2dp_rx_notify(void *_conn, void *priv, void (*notify)(void *));
|
||||
|
||||
void lmp_private_free_sbc_packet(void *_conn, void *packet);
|
||||
|
||||
int lmp_private_get_sbc_data_len(void *_conn);
|
||||
|
||||
int lmp_private_get_rx_buffer_size();
|
||||
|
||||
void lmp_private_set_max_rx_buf_persent(u8 *addr, int persent);
|
||||
|
||||
void *lmp_private_fetch_sbc_packet(void *_conn, int *len, void *_prev, int);
|
||||
|
||||
int lmp_private_get_sbc_packet_num(void *_conn);
|
||||
void lmp_private_close_sbc_channel(void *_conn);
|
||||
|
||||
void lmp_private_a2dp_mute(void *_conn);
|
||||
|
||||
void lmp_private_a2dp_unmute(void *_conn);
|
||||
|
||||
bool lmp_private_a2dp_is_mute(void *_conn);
|
||||
|
||||
int lmp_private_get_sbc_packet(void *_conn, struct a2dp_media_frame *frame, int block);
|
||||
|
||||
void lmp_private_put_sbc_packet(void *_conn, void *packet);
|
||||
|
||||
u8 *lmp_private_get_tx_packet_buffer(int size);
|
||||
|
||||
int lmp_private_clear_a2dp_packet(void *_conn, u16 seqn_number);
|
||||
|
||||
|
||||
int lmp_private_get_esco_packet_type();
|
||||
|
||||
void *lmp_private_get_esco_packet(int *len, u32 *hash);
|
||||
|
||||
void lmp_private_free_esco_packet(void *packet);
|
||||
|
||||
int lmp_private_send_esco_packet(void *priv, u8 *packet, int len);
|
||||
|
||||
int lmp_private_get_esco_tx_packet_num();
|
||||
|
||||
void lmp_esco_set_rx_notify(u8 *addr, void *priv, void (*notify)(void *));
|
||||
|
||||
u8 *lmp_private_remote_addr_for_handler(int handle);
|
||||
|
||||
u16 lmp_private_handler_for_remote_addr(u8 *addr, int link_type);
|
||||
|
||||
int lmp_private_get_rx_buffer_total_size(void *_conn);
|
||||
|
||||
int lmp_private_get_rx_buffer_remain_size(void *_conn);
|
||||
|
||||
void lmp_hci_private_hold_acl_packet(u8 *packet);
|
||||
|
||||
void lmp_hci_private_free_acl_packet(u8 *packet);
|
||||
|
||||
void lmp_hci_private_try_free_acl_packet(u8 *packet);
|
||||
|
||||
int lmp_hci_send_packet(u8 *packet, int len);
|
||||
|
||||
int lmp_hci_send_packet_standard(const u8 *packet, int len);
|
||||
|
||||
int lmp_hci_reset();
|
||||
|
||||
int lmp_hci_write_scan_enable(u8 enable);
|
||||
|
||||
void lmp_hci_write_class_of_device(int dev_class);
|
||||
|
||||
void lmp_hci_write_local_name(const char *name);
|
||||
void lmp_hci_write_local_priv_version(const char *ic_verson, const char *priv_version, u8 *tws_local_addr);
|
||||
|
||||
void lmp_hci_write_local_address(const u8 *addr);
|
||||
|
||||
void lmp_hci_write_simple_pairing_mode(u8 enable);
|
||||
|
||||
void lmp_hci_write_super_timeout(u16 timeout);
|
||||
void lmp_hci_write_page_timeout(u16 timeout);
|
||||
void lmp_hci_write_tws_internal_addr(u8 *internal_addr_local, u8 *internal_addr_remote);
|
||||
|
||||
void lmp_hci_write_link_supervision_timeout(u16 handle, int);
|
||||
|
||||
int lmp_hci_write_le_host_support(int features);
|
||||
|
||||
int lmp_hci_read_pin_type();
|
||||
|
||||
void lmp_hci_set_pin_code(const char *code, u8 len);
|
||||
|
||||
void lmp_hci_pin_code_request_reply(u8 *addr, u8 len, u8 *pin_code);
|
||||
|
||||
void lmp_hci_pin_code_request_negative_reply(u8 *addr);
|
||||
|
||||
int lmp_hci_write_pin_type(u8 type);
|
||||
|
||||
int lmp_hci_set_connection_encryption(u16 handle, int enable);
|
||||
|
||||
void lmp_hci_io_capability_request_reply(u8 *addr, u8 io_cap, u8 oob_data, u8 auth_req);
|
||||
|
||||
void lmp_hci_user_confirmation_request_reply(u8 *address);
|
||||
|
||||
void lmp_hci_user_confirmation_request_negative_reply(u8 *addr);
|
||||
|
||||
int lmp_hci_disconnect(u16 handle, u8 reason);
|
||||
int lmp_hci_test_key_cmd(u8 cmd, u16 handle);
|
||||
int lmp_hci_send_user_info_cmd(u32 info, u16 handle);
|
||||
|
||||
void lmp_hci_accept_connection_request(u8 *addr, u8 role);
|
||||
|
||||
void lmp_hci_accept_sco_connection_request(u8 *addr, u32 tx_bandwidth,
|
||||
u32 rx_bandwidth, u16 max_latency, u16 content_format,
|
||||
u8 retransmission, u16 packey_type);
|
||||
|
||||
void lmp_hci_reject_connection_request(u8 *addr, u8 reason);
|
||||
|
||||
void lmp_hci_switch_role_command(u8 *addr, u8 role);
|
||||
|
||||
void lmp_hci_authentication_requested(u16 handler);
|
||||
|
||||
void lmp_hci_link_key_request_reply(u8 *addr, u8 *link_key);
|
||||
|
||||
void lmp_hci_link_key_request_negative_reply(u8 *addr);
|
||||
|
||||
void lmp_hci_write_default_link_policy_settings(u16 setting);
|
||||
|
||||
void lmp_hci_release_packet(u8 *packet);
|
||||
|
||||
void lmp_hci_create_connection(const u8 *addr, u16 packet_type,
|
||||
u8 repetition_mode, u8 reserved,
|
||||
u16 clk_offset, u8 allow_role_switch);
|
||||
|
||||
void lmp_hci_connection_cancel(u8 *addr);;
|
||||
|
||||
void lmp_hci_cancel_page();
|
||||
void lmp_hci_inquiry(int lap, u8 length, u8 num);
|
||||
void lmp_hci_cancel_inquiry();
|
||||
void lmp_hci_sniff_mode_command(u16 handle, u16 max_interval, u16 min_interval, u16 attempt, u16 timeout);
|
||||
void lmp_hci_exit_sniff_mode_command(u16 handle);
|
||||
|
||||
void lmp_hci_host_num_of_completed_packets(u16 handle, u16 num_of_completed_packet);
|
||||
|
||||
int lmp_hci_read_remote_version_information(u16 handle);
|
||||
|
||||
void lmp_hci_read_remote_supported_features(u16 handle);
|
||||
|
||||
void lmp_hci_read_remote_extended_features(u16 handle);
|
||||
|
||||
void lmp_hci_role_discovery(u16 handle);
|
||||
|
||||
void lmp_hci_read_clock_offset(u16 handle);
|
||||
|
||||
void lmp_hci_read_link_policy_settings(u16 handle);
|
||||
void lmp_hci_write_link_policy_settings(u16 handle, u16 policy);
|
||||
|
||||
void lmp_hci_remote_name_request(u8 *addr, u8 page_scan_repetition_mode, u16 clk_offset);
|
||||
|
||||
void lmp_set_sniff_establish_by_remote(u8 enable);
|
||||
|
||||
void lmp_set_sniff_disable(void);
|
||||
|
||||
|
||||
u8 lmp_hci_read_local_supported_features(int octet);
|
||||
|
||||
void lmp_hci_write_local_supported_features(u8 features, int octet);
|
||||
|
||||
|
||||
u8 lmp_standard_connect_check(void);
|
||||
|
||||
void lmp_hci_send_keypress_notification(u8 *addr, u8 key);
|
||||
void lmp_hci_user_keypress_request_reply(u8 *addr, u32 key);
|
||||
void lmp_hci_user_keypress_request_negative_reply(u8 *addr, u8 key);
|
||||
|
||||
|
||||
void lmp_hci_set_role_switch_supported(bool enable);
|
||||
void lmp_hci_tx_channel_chassification(u8 *map);
|
||||
|
||||
|
||||
|
||||
u8 *get_tws_internal_addr(int channel);
|
||||
|
||||
extern int lmp_private_esco_suspend_resume(int flag);;
|
||||
|
||||
void user_set_tws_box_mode(u8 mode);
|
||||
|
||||
|
||||
void bt_set_tx_power(u8 txpower);
|
||||
|
||||
|
||||
void bredr_bulk_change(u8 mode);
|
||||
|
||||
|
||||
extern u8 get_bredr_link_state();
|
||||
|
||||
extern u32 get_bt_slot_time(u8 type, u32 time, int *ret_time, int (*local_us_time)(void));
|
||||
extern u32 get_sync_rec_instant_us_time();
|
||||
extern u8 tws_remote_state_check(void);
|
||||
extern void tws_remote_state_clear(void);
|
||||
extern void user_set_tws_box_mode(u8 mode);
|
||||
|
||||
|
||||
extern void bredr_fcc_init(u8 mode, u8 fre);
|
||||
extern void bredr_set_dut_enble(u8 en, u8 phone);
|
||||
|
||||
|
||||
|
||||
struct link_fix_rx_result {
|
||||
u32 rx_err_b; //接收到err bit
|
||||
u32 rx_sum_b; //接收到正确bit
|
||||
u32 rx_perr_p; //接收到crc 错误 包数
|
||||
u32 rx_herr_p; //接收到crc 以外其他错误包数
|
||||
u32 rx_invail_p; //接收到crc错误bit太多的包数,丢弃不统计到err bit中
|
||||
};
|
||||
|
||||
#define DH1_1 0
|
||||
#define DH3_1 1
|
||||
#define DH5_1 2
|
||||
#define DH1_2 3
|
||||
#define DH3_2 4
|
||||
#define DH5_2 5
|
||||
|
||||
int link_fix_tx_enable(u8 *remote_addr, u8 fre, u8 packet_type, u16 payload);
|
||||
int link_fix_rx_enable(u8 *remote_addr, u8 fre, u8 packet_type, u16 payload);
|
||||
void link_fix_txrx_disable();
|
||||
void link_fix_rx_update_result(struct link_fix_rx_result *result);
|
||||
void link_fix_rx_dump_result();
|
||||
|
||||
struct lmp_connection *lmp_conn_for_handle(int handle);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : lmp_config.h
|
||||
|
||||
* Description : Lto 优化Macro 定义
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2018-12-19 16:38
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _LMP_CONFIG_H_
|
||||
#define _LMP_CONFIG_H_
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : hci_transport.h
|
||||
|
||||
* Description :
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2017-01-17 15:14
|
||||
|
||||
* Copyright:(c)JIELI 2011-2016 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef __BTCONTROLLER_HCI_TRANSPORT_H
|
||||
#define __BTCONTROLLER_HCI_TRANSPORT_H
|
||||
|
||||
//#include <stdint.h>
|
||||
#include "generic/typedef.h"
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* API_START */
|
||||
typedef struct {
|
||||
uint32_t baudrate;
|
||||
int flowcontrol;
|
||||
const char *device_name;
|
||||
} btstack_uart_config_t;
|
||||
|
||||
typedef enum {
|
||||
// UART active, sleep off
|
||||
BTSTACK_UART_SLEEP_OFF = 0,
|
||||
// used for eHCILL
|
||||
BTSTACK_UART_SLEEP_RTS_HIGH_WAKE_ON_CTS_PULSE,
|
||||
// used for H5 and for eHCILL without support for wake on CTS pulse
|
||||
BTSTACK_UART_SLEEP_RTS_LOW_WAKE_ON_RX_EDGE,
|
||||
|
||||
} btstack_uart_sleep_mode_t;
|
||||
|
||||
typedef enum {
|
||||
BTSTACK_UART_SLEEP_MASK_RTS_HIGH_WAKE_ON_CTS_PULSE = 1 << BTSTACK_UART_SLEEP_RTS_HIGH_WAKE_ON_CTS_PULSE,
|
||||
BTSTACK_UART_SLEEP_MASK_RTS_LOW_WAKE_ON_RX_EDGE = 1 << BTSTACK_UART_SLEEP_RTS_LOW_WAKE_ON_RX_EDGE
|
||||
} btstack_uart_sleep_mode_mask_t;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* init transport
|
||||
* @param uart_config
|
||||
*/
|
||||
int (*init)(const btstack_uart_config_t *uart_config);
|
||||
|
||||
/**
|
||||
* open transport connection
|
||||
*/
|
||||
int (*open)(void);
|
||||
|
||||
/**
|
||||
* close transport connection
|
||||
*/
|
||||
int (*close)(void);
|
||||
|
||||
/**
|
||||
* set callback for block received. NULL disables callback
|
||||
*/
|
||||
void (*set_block_received)(void (*block_handler)(void));
|
||||
|
||||
/**
|
||||
* set callback for sent. NULL disables callback
|
||||
*/
|
||||
void (*set_block_sent)(void (*block_handler)(void));
|
||||
|
||||
/**
|
||||
* set baudrate
|
||||
*/
|
||||
int (*set_baudrate)(uint32_t baudrate);
|
||||
|
||||
/**
|
||||
* set parity
|
||||
*/
|
||||
int (*set_parity)(int parity);
|
||||
|
||||
/**
|
||||
* set flowcontrol
|
||||
*/
|
||||
int (*set_flowcontrol)(int flowcontrol);
|
||||
|
||||
/**
|
||||
* receive block
|
||||
*/
|
||||
void (*receive_block)(uint8_t *buffer, uint16_t len);
|
||||
|
||||
/**
|
||||
* send block
|
||||
*/
|
||||
void (*send_block)(const uint8_t *buffer, uint16_t length);
|
||||
|
||||
// support for sleep modes in TI's H4 eHCILL and H5
|
||||
|
||||
/**
|
||||
* query supported wakeup mechanisms
|
||||
* @return supported_sleep_modes mask
|
||||
*/
|
||||
int (*get_supported_sleep_modes)(void);
|
||||
|
||||
/**
|
||||
* set UART sleep mode - allows to turn off UART and it's clocks to save energy
|
||||
* Supported sleep modes:
|
||||
* - off: UART active, RTS low if receive_block was called and block not read yet
|
||||
* - RTS high, wake on CTS: RTS should be high. On CTS pulse, UART gets enabled again and RTS goes to low
|
||||
* - RTS low, wake on RX: data on RX will trigger UART enable, bytes might get lost
|
||||
*/
|
||||
void (*set_sleep)(btstack_uart_sleep_mode_t sleep_mode);
|
||||
|
||||
/**
|
||||
* set wakeup handler - needed to notify hci transport of wakeup requests by Bluetooth controller
|
||||
* Called upon CTS pulse or RX data. See sleep modes.
|
||||
*/
|
||||
void (*set_wakeup_handler)(void (*wakeup_handler)(void));
|
||||
|
||||
} btstack_uart_block_t;
|
||||
|
||||
// common implementations
|
||||
const btstack_uart_block_t *btstack_uart_block_posix_instance(void);
|
||||
const btstack_uart_block_t *btstack_uart_block_windows_instance(void);
|
||||
const btstack_uart_block_t *btstack_uart_block_embedded_instance(void);
|
||||
const btstack_uart_block_t *btstack_uart_block_freertos_instance(void);
|
||||
|
||||
/* HCI packet types */
|
||||
typedef struct {
|
||||
/**
|
||||
* transport name
|
||||
*/
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* init transport
|
||||
* @param transport_config
|
||||
*/
|
||||
void (*init)(const void *transport_config);
|
||||
|
||||
/**
|
||||
* open transport connection
|
||||
*/
|
||||
int (*open)(void);
|
||||
|
||||
/**
|
||||
* close transport connection
|
||||
*/
|
||||
int (*close)(void);
|
||||
|
||||
/**
|
||||
* register packet handler for HCI packets: ACL, SCO, and Events
|
||||
*/
|
||||
void (*register_packet_handler)(void (*handler)(int packet_type, const u8 *packet, int size));
|
||||
|
||||
/**
|
||||
* support async transport layers, e.g. IRQ driven without buffers
|
||||
*/
|
||||
int (*can_send_packet_now)(uint8_t packet_type);
|
||||
|
||||
/**
|
||||
* send packet
|
||||
*/
|
||||
int (*send_packet)(int packet_type, const u8 *packet, int size);
|
||||
|
||||
/**
|
||||
* extension for UART transport implementations
|
||||
*/
|
||||
int (*set_baudrate)(uint32_t baudrate);
|
||||
|
||||
/**
|
||||
* extension for UART H5 on CSR: reset BCSP/H5 Link
|
||||
*/
|
||||
void (*reset_link)(void);
|
||||
|
||||
/**
|
||||
* extension for USB transport implementations: config SCO connections
|
||||
*/
|
||||
void (*set_sco_config)(uint16_t voice_setting, int num_connections);
|
||||
|
||||
} hci_transport_t;
|
||||
|
||||
typedef enum {
|
||||
HCI_TRANSPORT_CONFIG_UART,
|
||||
HCI_TRANSPORT_CONFIG_USB
|
||||
} hci_transport_config_type_t;
|
||||
|
||||
typedef struct {
|
||||
hci_transport_config_type_t type;
|
||||
} hci_transport_config_t;
|
||||
|
||||
typedef struct {
|
||||
hci_transport_config_type_t type; // == HCI_TRANSPORT_CONFIG_UART
|
||||
uint32_t baudrate_init; // initial baud rate
|
||||
uint32_t baudrate_main; // = 0: same as initial baudrate
|
||||
int flowcontrol; //
|
||||
const char *device_name;
|
||||
} hci_transport_config_uart_t;
|
||||
|
||||
|
||||
// inline various hci_transport_X.h files
|
||||
|
||||
/*
|
||||
* @brief Setup H4 instance with uart_driver
|
||||
* @param uart_driver to use
|
||||
*/
|
||||
const hci_transport_t *hci_transport_h4_instance(const btstack_uart_block_t *uart_driver);
|
||||
|
||||
/*
|
||||
* @brief Setup H5 instance with uart_driver
|
||||
* @param uart_driver to use
|
||||
*/
|
||||
const hci_transport_t *hci_transport_h5_instance(const btstack_uart_block_t *uart_driver);
|
||||
|
||||
/*
|
||||
* @brief Enable H5 Low Power Mode: enter sleep mode after x ms of inactivity
|
||||
* @param inactivity_timeout_ms or 0 for off
|
||||
*/
|
||||
void hci_transport_h5_set_auto_sleep(uint16_t inactivity_timeout_ms);
|
||||
|
||||
/*
|
||||
* @brief Enable BSCP mode H5, by enabling event parity
|
||||
*/
|
||||
void hci_transport_h5_enable_bcsp_mode(void);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
const hci_transport_t *hci_transport_usb_instance(void);
|
||||
|
||||
const hci_transport_t *hci_transport_uart_instance(void);
|
||||
|
||||
const hci_transport_t *hci_transport_h4_controller_instance(void);
|
||||
|
||||
const hci_transport_t *hci_transport_h4_host_instance(void);
|
||||
/**
|
||||
* @brief Specify USB Bluetooth device via port numbers from root to device
|
||||
*/
|
||||
void hci_transport_usb_set_path(int len, uint8_t *port_numbers);
|
||||
|
||||
/* API_END */
|
||||
extern const hci_transport_t *hci_transport;
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __HCI_TRANSPORT_H
|
||||
@@ -0,0 +1,58 @@
|
||||
/*********************************************************************************************
|
||||
* Filename : btcontroller_config.h
|
||||
|
||||
* Description : 优化代码需要,libs 依赖app 定义变量,由app 定义变量值决定libs 优化
|
||||
|
||||
* Author : Bingquan
|
||||
|
||||
* Email : bingquan_cai@zh-jieli.com
|
||||
|
||||
* Last modifiled : 2018-12-19 16:10
|
||||
|
||||
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
|
||||
*********************************************************************************************/
|
||||
#ifndef _BTCONTROLLER_CONFIG_H_
|
||||
#define _BTCONTROLLER_CONFIG_H_
|
||||
|
||||
#include "btcontroller_modules.h"
|
||||
|
||||
#include "ble/ll_config.h"
|
||||
|
||||
// #define CONFIG_LE_FEATURES \
|
||||
(\
|
||||
LE_ENCRYPTION | \
|
||||
LE_CORE_V50_FEATURES \
|
||||
)
|
||||
|
||||
#define CONFIG_LE_FEATURES 0//(LE_ENCRYPTION)
|
||||
|
||||
// #define CONFIG_LE_ROLES (LE_ADV|LE_SCAN|LE_INIT|LE_SLAVE|LE_MASTER)
|
||||
// #define CONFIG_LE_ROLES (LE_ADV|LE_SCAN)
|
||||
#define CONFIG_LE_ROLES (LE_ADV)
|
||||
|
||||
#include "classic/lmp_config.h"
|
||||
|
||||
#define CONFIG_CL_FEATURES
|
||||
|
||||
#define CONFIG_CL_EX_FEATURES
|
||||
|
||||
|
||||
#define TWS_BLE_ESCO_CONNECT //通话过程进行连接使能
|
||||
|
||||
|
||||
/*
|
||||
*-------------------
|
||||
* 蓝牙基带运行的模式
|
||||
*/
|
||||
|
||||
struct lp_ws_t {
|
||||
u16 lrc_ws_inc;
|
||||
u16 lrc_ws_init;
|
||||
u16 bt_osc_ws_inc;
|
||||
u16 bt_osc_ws_init;
|
||||
u8 osc_change_mode;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
SET SCRIPT_PATH=%~dp0%
|
||||
set PATH=%SCRIPT_PATH%\utils;%PATH%
|
||||
cd ..
|
||||
cmd
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
set INDIR=%1%
|
||||
set MERGE=%2%
|
||||
set AROUT=%3%
|
||||
|
||||
echo %INDIR%
|
||||
echo %MERGE%
|
||||
echo %AROUT%
|
||||
|
||||
set FILES=
|
||||
|
||||
for /f "tokens=*" %%i in ('dir /b %INDIR%\*.a') DO SET FILES=!FILES! %INDIR%\%%i
|
||||
|
||||
echo %FILES%
|
||||
|
||||
%MERGE% --no-rewrite --output %AROUT% %FILES%
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user