From: p15692025051 <846603105@qq.com> Date: Mon, 21 Jul 2025 02:45:08 +0000 (+0800) Subject: 添加小核代码,编译后需要手动更新替换1.sdk\cpu\br28\tools\p11_code.bin文件 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=d294b08c66f271a7ee4d28d6b73d2703707fa570;p=mirrors%2F7PIN_V1_5_Jl_SDK.git 添加小核代码,编译后需要手动更新替换1.sdk\cpu\br28\tools\p11_code.bin文件 --- diff --git a/2.code/2.p11_code/AC701N_p11.cbp b/2.code/2.p11_code/AC701N_p11.cbp new file mode 100644 index 0000000..86ba3d6 --- /dev/null +++ b/2.code/2.p11_code/AC701N_p11.cbp @@ -0,0 +1,164 @@ + + + + + + diff --git a/2.code/2.p11_code/Makefile b/2.code/2.p11_code/Makefile new file mode 100644 index 0000000..00ce1bb --- /dev/null +++ b/2.code/2.p11_code/Makefile @@ -0,0 +1,310 @@ + +# 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 := q32s-lto-wrapper.exe +AR := llvm-ar.exe +MKDIR := mkdir_win -p +RM := rm -rf + +SYS_LIB_DIR := C:/JL/pi32/q32s-lib +SYS_INC_DIR := C:/JL/pi32/q32s-include +EXT_CFLAGS := # Windows 下不需要 -D__SHELL__ +export PATH:=$(TOOL_DIR);$(PATH) + +## 后处理脚本 +POST_SCRIPT := cpu/br28/post_build/download.bat +RUN_POST_SCRIPT := cpu\br28\post_build\download.bat +else +# Linux 下工具链位置 +TOOL_DIR := /opt/jieli/q32s/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 +SYS_INC_DIR := $(TOOL_DIR)/../include +EXT_CFLAGS := -D__SHELL__ # Linux 下需要这个保证正确处理 download.c +export PATH:=$(TOOL_DIR):$(PATH) + +## 后处理脚本 +POST_SCRIPT := cpu/br28/post_build/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/br28/post_build/p11.elf +OBJ_FILE := $(OUT_ELF).objs.txt +# 编译路径设置 +BUILD_DIR := objs + +# 编译参数设置 +CFLAGS := \ + -flto \ + -target q32s \ + -integrated-as \ + -fno-builtin \ + -mllvm -inline-threshold=5 \ + -Oz \ + -integrated-as \ + -g \ + -O0 \ + -flto \ + -Os \ + -Wcast-align \ + -w \ + -fallow-pointer-null \ + -Wincompatible-pointer-types \ + -fprefer-gnu-section \ + -Werror=undef \ + -Wframe-larger-than=32 \ + -Werror=incompatible-pointer-types \ + -Werror=return-type \ + -Werror=implicit-function-declaration \ + + +# C++额外的编译参数 +CXXFLAGS := + + +# 宏定义 +DEFINES := \ + -D__GCC_Q32S__ \ + -DPMU_SYSTEM \ + -DCONFIG_FPGA_ENABLE \ + + +DEFINES += $(EXT_CFLAGS) # 额外的一些定义 + +# 头文件搜索路径 +INCLUDES := \ + -Iinclude/cpu/br28 \ + -Iinclude/generic \ + -Iapps \ + -Iapps/common \ + -Iapps/common/sport \ + -Iapps/common/device \ + -Iinclude/device \ + -Iapps/common/device/hr_sensor/vchr02 \ + -Iapps/common/device/hr_sensor/vc11s \ + -Iapps/common/device/hr_sensor/hx3602 \ + -I$(SYS_INC_DIR) \ + + +# 需要编译的 .c 文件 +c_SRC_FILES := \ + apps/common/device/bmp280/bmp280.c \ + apps/common/device/gSensor/SC7A20.c \ + apps/common/device/gSensor/gSensor_algo.c \ + apps/common/device/gSensor/gSensor_manage.c \ + apps/common/device/gSensor/mir3da.c \ + apps/common/device/gSensor/msa310.c \ + apps/common/device/gSensor/msa310_function.c \ + apps/common/device/gSensor/msa31x.c \ + apps/common/device/gSensor/stk832x.c \ + apps/common/device/hr_sensor/hrSensor_manage.c \ + apps/common/device/hr_sensor/hrs3603.c \ + apps/common/device/hr_sensor/hx3602/hrs3602.c \ + apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c \ + apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c \ + apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c \ + apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c \ + apps/common/device/hr_sensor/vc11s/vcHr11Hci.c \ + apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c \ + apps/common/device/hr_sensor/vchr02/vcHr02Hci.c \ + apps/common/sport/sensor_api.c \ + apps/debug.c \ + apps/lib_config.c \ + apps/main.c \ + apps/msg.c \ + apps/timer.c \ + cpu/br28/common.c \ + cpu/br28/iic.c \ + cpu/br28/iic_soft.c \ + cpu/br28/spi.c \ + cpu/br28/test.c \ + cpu/br28/uart.c \ + cpu/br28/vad_api.c \ + cpu/br28/vad_develop.c \ + + +# 需要编译的 .S 文件 +S_SRC_FILES := + + +# 需要编译的 .s 文件 +s_SRC_FILES := + + +# 需要编译的 .cpp 文件 +cpp_SRC_FILES := + + +# 需要编译的 .cc 文件 +cc_SRC_FILES := + + +# 需要编译的 .cxx 文件 +cxx_SRC_FILES := + + +# 链接参数 +LFLAGS := \ + --plugin-opt=-inline-threshold=5 \ + --plugin-opt=save-temps \ + --plugin-opt=-inline-normal-into-special-section=true \ + --plugin-opt=-dont-used-symbol-list=malloc,free,sprintf,printf,puts,putchar \ + --sort-common \ + --plugin-opt=-warn-stack-size=32 \ + --start-group \ + cpu/br28/liba/cpu.a \ + cpu/br28/liba/printf.a \ + cpu/br28/liba/vad_algo.a \ + cpu/br28/liba/cbuf.a \ + cpu/br28/liba/lbuf.a \ + cpu/br28/liba/lbuf.a \ + cpu/br28/liba/bank_switch.a \ + cpu/br28/liba/algo_gsensor.a \ + --end-group \ + -Tcpu/br28/p11.ld \ + -M=cpu/br28/post_build/p11.map \ + -flto \ + --plugin-opt=-inline-threshold=5 \ + + +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) p11 + +pre_build: + $(info +PRE-BUILD) + $(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -D__LD__ -E -P cpu/br28/p11_ld.c -o cpu/br28/p11.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) -MM -MT $@ $< -o $(@:.o=.d) + $(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ + +$(BUILD_DIR)/%.S.o : %.S + $(info +AS $<) + $(QUITE) $(MKDIR) $(@D) + $(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MT $@ $< -o $(@:.o=.d) + $(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ + +$(BUILD_DIR)/%.s.o : %.s + $(info +AS $<) + $(QUITE) $(MKDIR) $(@D) + $(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MT $@ $< -o $(@:.o=.d) + $(QUITE) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ + +$(BUILD_DIR)/%.cpp.o : %.cpp + $(info +CXX $<) + $(QUITE) $(MKDIR) $(@D) + $(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MT $@ $< -o $(@:.o=.d) + $(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ + +$(BUILD_DIR)/%.cxx.o : %.cxx + $(info +CXX $<) + $(QUITE) $(MKDIR) $(@D) + $(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MT $@ $< -o $(@:.o=.d) + $(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ + +$(BUILD_DIR)/%.cc.o : %.cc + $(info +CXX $<) + $(QUITE) $(MKDIR) $(@D) + $(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MT $@ $< -o $(@:.o=.d) + $(QUITE) $(CXX) $(CXXFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ + +-include $(DEP_FILES) diff --git a/2.code/2.p11_code/apps/app_config.h b/2.code/2.p11_code/apps/app_config.h new file mode 100644 index 0000000..ee8b1f0 --- /dev/null +++ b/2.code/2.p11_code/apps/app_config.h @@ -0,0 +1,89 @@ +#ifndef __APP_CONFIG_H__ +#define __APP_CONFIG_H__ +/********************************************************************************************* + * Filename : app_config.h + + * Description : 本文用于配置功能工程的功能使能开关 + + * Author : MoZhiYe + + * Email : mozhiye@zh-jieli.com + + * Last modifiled : 2021-04-17 09:00 + + * Copyright:(c)JIELI 2021-2029 @ , All Rights Reserved. +*********************************************************************************************/ +#include "ram_share.h" + +//==========================================================// +// 串口打印使能开关 // +//==========================================================// +#define CONFIG_UART_DEBUG_ENABLE 0 + +//==========================================================// +// VAD使能开关 // +//==========================================================// +#define CONFIG_VAD_ENABLE 0 + +//==========================================================// +// LPCTMU使能开关 // +//==========================================================// +#define CONFIG_LPCTMU_ENABLE 0 + +//==========================================================// +// soft iic // +//==========================================================// +#define TCFG_SW_I2C0_CLK_PORT 0 //spft IIC CLK +#define TCFG_SW_I2C0_DAT_PORT 0 //spft IIC DAT +#define TCFG_SW_I2C0_DELAY_CNT 1 //软件IIC延时参数,影响通讯时钟频率 +//==========================================================// +// bmp280 // +//==========================================================// +#define TCFG_BMP280_DEV_ENABLE 0 +#define TCFG_BMP280_USER_IIC_TYPE 0 //0:软件IIC 1:硬件IIC + + +//==========================================================// +// sensor alg使能开关 // +//==========================================================// +#define CONFIG_SENSOR_ALG_ENABLE 0 + + + +//==========================================================// +// gSensor // +//==========================================================// +#define TCFG_GSENSOR_ENABLE 0 +#define TCFG_SC7A20_EN 0 +#define TCFG_SC7A20E_EN 0 +#define TCFG_SC7A20H_EN 0 +#define TCFG_MSA310_EN 0 +#define TCFG_MSA31X_EN 0 +#define TCFG_MIR3DA_EN 0 +#define TCFG_STK832X_EN 0 +#define TCFG_GSENOR_USER_IIC_TYPE 0 //0:软件IIC 1:硬件IIC + +//*********************************************************************************// +// hr-sensor配置 // +//*********************************************************************************// +#define TCFG_HR_SENSOR_ENABLE 0 //hrSensor使能 +#define TCFG_SPO2_SENSOR_ENABLE 0 //SPO2sensor使能 +//hx3602 +#define TCFG_HRS3602_DEV_ENABLE 0 +//hrs3603 +#define TCFG_HRS3603_DEV_ENABLE 0 +//vchr02 +#define TCFG_VCHR02_DEV_ENABLE 0//模块time不能停 +#define TCFG_VCHR02_P11_ALGO_ENABLE 0//algo 在sdk操作,这里不需要打开 +//vchr11s +#define TCFG_VCHR11S_DEV_ENABLE 0//模块time不能停 +//hrs3300 无 +#define TCFG_HRS3300_EN 0 +#define TCFG_HR_SENSOR_USE_IIC_TYPE 0 //0:软件IIC 1:硬件IIC + +#define TCFG_HR_SENSOR_READ_BY_INT 0 //0:定时器读数据 1:中断读数据 + + + + +#endif /* #ifndef __APP_CONFIG_H__ */ diff --git a/2.code/2.p11_code/apps/common/device/bmp280/bmp280.c b/2.code/2.p11_code/apps/common/device/bmp280/bmp280.c new file mode 100644 index 0000000..c60c0b0 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/bmp280/bmp280.c @@ -0,0 +1,415 @@ +/* #include "app_config.h" */ +#include "bmp280.h" +#include "includes.h" +#include "iic_api.h" + +#if defined(TCFG_BMP280_DEV_ENABLE) && TCFG_BMP280_DEV_ENABLE + +#ifndef log_error +#define log_error printf +#endif +#ifndef log_info +#define log_info printf +#endif + +struct _bmp280_dev_platform_data *bmp280_iic_info; + +#if TCFG_BMP280_USER_IIC_TYPE +#define iic_init(iic) hw_iic_init() +#define iic_close(iic) hw_iic_close() +#define iic_start(iic) hw_iic_start() +#define iic_stop(iic) hw_iic_stop() +#define iic_tx_byte(iic, byte) hw_iic_master_tx_byte(byte) +#define iic_rx_byte(iic, ack) hw_iic_master_rx_byte(ack) +#define iic_read_buf(iic, buf, len) hw_iic_master_read_buf(buf, len) +#define iic_write_buf(iic, buf, len) hw_iic_master_write_buf(buf, len) +/* #define iic_suspend(iic) hw_iic_suspend() */ +/* #define iic_resume(iic) hw_iic_resume() */ +#else +#define iic_init(iic) soft_iic_init(iic) +#define iic_close(iic) soft_iic_uninit(iic) +#define iic_start(iic) soft_iic_start(iic) +#define iic_stop(iic) soft_iic_stop(iic) +#define iic_tx_byte(iic, byte) soft_iic_tx_byte(iic, byte) +#define iic_rx_byte(iic, ack) soft_iic_rx_byte(iic, ack) +#define iic_read_buf(iic, buf, len) soft_iic_read_buf(iic, buf, len) +#define iic_write_buf(iic, buf, len) soft_iic_write_buf(iic, buf, len) +/* #define iic_suspend(iic) soft_iic_suspend(iic) */ +/* #define iic_resume(iic) soft_iic_resume(iic) */ +#endif +extern void delay(u32 cnt);// +static bool bmp280_read_buf(u8 reg, u8 *buf, u8 len) +{ + iic_start(bmp280_iic_info->iic_hdl); + if (0 == iic_tx_byte(bmp280_iic_info->iic_hdl, BMP280_I2C_ADDR << 1 | 0)) { + iic_stop(bmp280_iic_info->iic_hdl); + log_error("bmp280 read fail1!\n"); + return false; + } + delay(bmp280_iic_info->iic_delay); + if (0 == iic_tx_byte(bmp280_iic_info->iic_hdl, reg)) { + iic_stop(bmp280_iic_info->iic_hdl); + log_error("bmp280 read fail2!\n"); + return false; + } + delay(bmp280_iic_info->iic_delay); + iic_start(bmp280_iic_info->iic_hdl); + if (0 == iic_tx_byte(bmp280_iic_info->iic_hdl, BMP280_I2C_ADDR << 1 | 1)) { + iic_stop(bmp280_iic_info->iic_hdl); + log_error("bmp280 read fail3!\n"); + return false; + } + + for (u8 i = 0; i < len - 1; i++) { + buf[i] = iic_rx_byte(bmp280_iic_info->iic_hdl, 1); + delay(bmp280_iic_info->iic_delay); + } + buf[len - 1] = iic_rx_byte(bmp280_iic_info->iic_hdl, 0); + iic_stop(bmp280_iic_info->iic_hdl); + delay(bmp280_iic_info->iic_delay); + return true; +} + +static bool bmp280_write_byte(u8 reg, u8 data) +{ + iic_start(bmp280_iic_info->iic_hdl); + if (0 == iic_tx_byte(bmp280_iic_info->iic_hdl, BMP280_I2C_ADDR << 1)) { + iic_stop(bmp280_iic_info->iic_hdl); + log_error("bmp280 write fail1!\n"); + return false; + } + delay(bmp280_iic_info->iic_delay); + if (0 == iic_tx_byte(bmp280_iic_info->iic_hdl, reg)) { + iic_stop(bmp280_iic_info->iic_hdl); + log_error("bmp280 write fail2!\n"); + return false; + } + delay(bmp280_iic_info->iic_delay); + if (0 == iic_tx_byte(bmp280_iic_info->iic_hdl, data)) { + iic_stop(bmp280_iic_info->iic_hdl); + log_error("bmp280 write fail3!\n"); + return false; + } + iic_stop(bmp280_iic_info->iic_hdl); + delay(bmp280_iic_info->iic_delay); + return true; +} + +//设置BMP过采样因子 MODE +//BMP280_SLEEP_MODE||BMP280_FORCED_MODE||BMP280_NORMAL_MODE +bool bmp280_set_temoversamp(bmp_oversample_mode *oversample_mode) +{ + u8 regtmp; + regtmp = ((oversample_mode->t_osample) << 5) | + ((oversample_mode->p_osample) << 2) | + ((oversample_mode)->workmode); + /* log_info("init reg:%x\n",regtmp); */ + + return bmp280_write_byte(BMP280_CTRLMEAS_REG, regtmp); +} +//设置保持时间和滤波器分频因子 +bool bmp280_set_standby_filter(bmp_config *bmp_config) +{ + u8 regtmp; + regtmp = ((bmp_config->t_sb) << 5) | + ((bmp_config->filter_coefficient) << 2) | + ((bmp_config->spi_en)); + /* log_info("init config reg:%x\n",regtmp); */ + + return bmp280_write_byte(BMP280_CONFIG_REG, regtmp); +} +//设置bmp280工作模式 +void bmp280_set_work_mode(BMP280_WORK_MODE workmode) +{ + u8 ctrl_maes_data = 0; + bmp280_read_buf(BMP280_CTRLMEAS_REG, &ctrl_maes_data, 1); + /* log_info("old ctrl_maes_data:%x\n",ctrl_maes_data); */ + ctrl_maes_data &= ~(BIT(1) | BIT(0)); + ctrl_maes_data += (workmode << 0); + /* log_info("nem ctrl_maes_data:%x \n",ctrl_maes_data); */ + bmp280_write_byte(BMP280_CTRLMEAS_REG, ctrl_maes_data); +} +bool bmp280_check_id(void) +{ + u8 bmp280_id; + if (bmp280_read_buf(BMP280_CHIPID_REG, &bmp280_id, 1)) { + log_info("bmp280 id:%x\n", bmp280_id); + return true; + } else { + log_error("read bmp280 id fail!\n"); + return false; + } +} + +//bmp280 复位 +bool bmp280_reset() //return 1:ok; 0:fail +{ + return bmp280_write_byte(BMP280_RESET_REG, BMP280_RESET_VALUE); +} + +bmp280_params bmp280_par; +bool bmp280_init(void *priv) +{ + u8 bmp280_id; + if (priv == NULL) { + log_info("bmp280 init fail(no priv)\n"); + return false; + } + bmp280_iic_info = (struct _bmp280_dev_platform_data *)priv; + + if (bmp280_read_buf(BMP280_CHIPID_REG, &bmp280_id, 1)) { + log_info("bmp280 id:%x\n", bmp280_id); + } else { + log_error("read bmp280 id fail!\n"); + return false; + } + /********************读矫正参数*********************/ + u8 temp[24] = {0}; + bmp280_read_buf(BMP280_DIG_T1_LSB_REG, temp, 24); + //温度传感器的矫正值 + bmp280_par.t1 = (((u16)temp[1]) << 8) + temp[0]; + bmp280_par.t2 = (temp[3] << 8) + temp[2]; + bmp280_par.t3 = (temp[5] << 8) + temp[4]; + //大气压传感器的矫正值 + bmp280_par.p1 = (((u16)temp[7]) << 8) + temp[6]; + bmp280_par.p2 = (temp[9] << 8) + temp[8]; + bmp280_par.p3 = (temp[11] << 8) + temp[10]; + bmp280_par.p4 = (temp[13] << 8) + temp[12]; + bmp280_par.p5 = (temp[15] << 8) + temp[14]; + bmp280_par.p6 = (temp[17] << 8) + temp[16]; + bmp280_par.p7 = (temp[19] << 8) + temp[18]; + bmp280_par.p8 = (temp[21] << 8) + temp[20]; + bmp280_par.p9 = (temp[23] << 8) + temp[22]; + /* log_info("%d,%d,%d;%d,%d,%d,%d,%d,%d,%d,%d,%d\n",bmp280_par.t1,bmp280_par.t2,bmp280_par.t3,bmp280_par.p1,bmp280_par.p2,bmp280_par.p3,bmp280_par.p4,bmp280_par.p5,bmp280_par.p6,bmp280_par.p7,bmp280_par.p8,bmp280_par.p9); */ + + /******************************************************/ + if (!(bmp280_write_byte(BMP280_RESET_REG, BMP280_RESET_VALUE))) { //往复位寄存器写入给定值 + log_error("bmp280 reset error!\n"); + return false; + } + + bmp_config bmp_configstr; + bmp_configstr.t_sb = BMP280_T_SB1; + bmp_configstr.filter_coefficient = BMP280_FILTER_MODE_4; + bmp_configstr.spi_en = 0;//DISABLE; + if (!(bmp280_set_standby_filter(&bmp_configstr))) { + log_error("bmp280 init mode error!\n"); + return false; + } + + bmp_oversample_mode bmp_oversample_modestr; + bmp_oversample_modestr.t_osample = BMP280_T_MODE_1; + bmp_oversample_modestr.p_osample = BMP280_P_MODE_3; + bmp_oversample_modestr.workmode = BMP280_NORMAL_MODE; + if (!(bmp280_set_temoversamp(&bmp_oversample_modestr))) { + log_error("bmp280 init mode error!\n"); + return false; + } + + return true; +} + +/*****************算法*******************/ +/************计算补偿值***************/ +s32 t_fine; //用于计算补偿 +#if USE_FIXED_POINT_COMPENSATE //使用定点补偿 +// Returns temperature in DegC, resolution is 0.01 DegC. Output value of “5123” equals 51.23 DegC. +// t_fine carries fine temperature as global value +static s32 bmp280_compensate_t_int32(s32 adc_T) +{ + s32 var1, var2, T; + var1 = (((adc_T >> 3) - ((s32)bmp280_par.t1 << 1)) * ((s32)bmp280_par.t2)) >> 11; + var2 = (((((adc_T >> 4) - ((s32)bmp280_par.t1)) * ((adc_T >> 4) - ((s32)bmp280_par.t1))) >> 12) * ((s32)bmp280_par.t3)) >> 14; + t_fine = var1 + var2; + T = (t_fine * 5 + 128) >> 8; + return T; +} + +// Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits). +// Output value of “24674867” represents 24674867/256 = 96386.2 Pa = 963.862 hPa +static u32 bmp280_compensate_p_int64(s32 adc_P) +{ + s64 var1, var2, p; + var1 = ((s64)t_fine) - 128000; + var2 = var1 * var1 * (s64)bmp280_par.p6; + var2 = var2 + ((var1 * (s64)bmp280_par.p5) << 17); + var2 = var2 + (((s64)bmp280_par.p4) << 35); + var1 = ((var1 * var1 * (s64)bmp280_par.p3) >> 8) + ((var1 * (s64)bmp280_par.p2) << 12); + var1 = (((((s64)1) << 47) + var1)) * ((s64)bmp280_par.p1) >> 33; + if (var1 == 0) { + return 0; // avoid exception caused by division by zero + } + p = 1048576 - adc_P; + p = (((p << 31) - var2) * 3125) / var1; + var1 = (((s64)bmp280_par.p9) * (p >> 13) * (p >> 13)) >> 25; + var2 = (((s64)bmp280_par.p8) * p) >> 19; + p = ((p + var1 + var2) >> 8) + (((s64)bmp280_par.p7) << 4); + return (u32)p; +} + +#else //使用浮点补偿 +// Returns temperature in DegC, double precision. Output value of “51.23” equals 51.23 DegC. +// t_fine carries fine temperature as global value +static double bmp280_compensate_t_double(s32 adc_T) +{ + double var1, var2, T; + var1 = (((double)adc_T) / 16384.0 - ((double)bmp280_par.t1) / 1024.0) * ((double)bmp280_par.t2); + var2 = ((((double)adc_T) / 131072.0 - ((double)bmp280_par.t1) / 8192.0) * (((double)adc_T) / 131072.0 - ((double) bmp280_par.t1) / 8192.0)) * ((double)bmp280_par.t3); + t_fine = (s32)(var1 + var2); + T = (var1 + var2) / 5120.0; + return T; +} + +// Returns pressure in Pa as double. Output value of “96386.2” equals 96386.2 Pa = 963.862 hPa +static double bmp280_compensate_p_double(s32 adc_P) +{ + double var1, var2, p; + var1 = ((double)t_fine / 2.0) - 64000.0; + var2 = var1 * var1 * ((double)bmp280_par.p6) / 32768.0; + var2 = var2 + var1 * ((double)bmp280_par.p5) * 2.0; + var2 = (var2 / 4.0) + (((double)bmp280_par.p4) * 65536.0); + var1 = (((double)bmp280_par.p3) * var1 * var1 / 524288.0 + ((double)bmp280_par.p2) * var1) / 524288.0; + var1 = (1.0 + var1 / 32768.0) * ((double)bmp280_par.p1); + if (var1 == 0.0) { + return 0; // avoid exception caused by division by zero + } + p = 1048576.0 - (double)adc_P; + p = (p - (var2 / 4096.0)) * 6250.0 / var1; + var1 = ((double)bmp280_par.p9) * p * p / 2147483648.0; + var2 = p * ((double)bmp280_par.p8) / 32768.0; + p = p + (var1 + var2 + ((double)bmp280_par.p7)) / 16.0; + return p; +} +#endif + +//获取BMP当前状态 +//status_flag = BMP280_MEASURING +// BMP280_IM_UPDATE +static u8 bmp280_getstatus(u8 status_flag) +{ + u8 flag; + bmp280_read_buf(BMP280_STATUS_REG, &flag, 1); + if (flag & status_flag) { + return 1; + } else { + return 0; + } +} +//温度值-℃(实际值的100倍(定点法)或实际值(浮点法)) +static bmp_temperature_data bmp280_get_temperature(void) +{ + u8 tem_data[3] = {0}; + long signed bit32; + bmp280_read_buf(BMP280_TEMPERATURE_MSB_REG, tem_data, 3); + bit32 = ((long)(tem_data[0] << 12)) | ((long)(tem_data[1] << 4)) | (tem_data[2] >> 4); + /* log_info("tembit32:%ld\n",bit32); */ +#if USE_FIXED_POINT_COMPENSATE //使用定点补偿 + return bmp280_compensate_t_int32(bit32); +#else //使用浮点补偿 + return bmp280_compensate_t_double(bit32); +#endif +} +//获取大气压值-Pa(实际值的100倍(定点法)或实际值(浮点法)) +static bmp_pressure_data bmp280_get_pressure(void) +{ + u8 tem_data[3] = {0}; + long signed bit32; + bmp280_read_buf(BMP280_PRESSURE_MSB_REG, tem_data, 3); + bit32 = ((long)(tem_data[0] << 12)) | ((long)(tem_data[1] << 4)) | (tem_data[2] >> 4); + /* log_info("prebit32:%ld,t_fine:%d\n",bit32,t_fine); */ +#if USE_FIXED_POINT_COMPENSATE //使用定点补偿 + u32 pressure = bmp280_compensate_p_int64(bit32); + pressure = pressure * 100 / 256; +#else //使用浮点补偿 + double pressure = bmp280_compensate_p_double(bit32); +#endif + return pressure; +} +/* + * 仅在BMP280被设置为normal mode时, + * 可使用该接口直接读取温度和气压。 + * (实际值的100倍(定点法)或实际值(浮点法)) + */ +void bmp280_get_temperature_and_pressure(bmp_temperature_data *temperature, bmp_pressure_data *pressure) +{ + if (bmp280_check_id() == false) { + return ; + } + while (bmp280_getstatus(BMP280_MEASURING)); + while (bmp280_getstatus(BMP280_IM_UPDATE)); + *temperature = bmp280_get_temperature(); //必须先读温度再度气压 + *pressure = bmp280_get_pressure(); +} + +/** + * 当BMP280被设置为forced mode时, + * 可使用该接口直接读取温度和气压。 + * (实际值的100倍(定点法)或实际值(浮点法)) + */ +void bmp280_forced_mode_get_temperature_and_pressure(bmp_temperature_data *temperature, bmp_pressure_data *pressure) +{ + bmp280_set_work_mode(BMP280_FORCED_MODE); + bmp280_get_temperature_and_pressure(temperature, pressure); +} + +//计算高度, 返回海拔高度: (m) +#include "math.h" +#define SEA_LEVEL_PRESSURE 1013.23f +float bmp280_get_altitude(bmp_temperature_data temperature, bmp_pressure_data pressure) +{ + /* log_info("temperature:%d,pressure:%d\n",(s32)temperature,(u32)pressure); */ +#if USE_FIXED_POINT_COMPENSATE //使用定点补偿 + /* return 44330 * (1.0 - pow(pressure/10000 / SEA_LEVEL_PRESSURE, 0.1903)); */ + //计算公式温度用实际值,压强用实际值的百分之一 + return ((float)powf(SEA_LEVEL_PRESSURE / ((float)pressure / 10000.0), 0.190223f) - 1.0f) * ((float)temperature / 100.0 + 273.15f) / 0.0065f; // Calculate the altitude in metres +#else //使用浮点补偿 + /* return 44330 * (1.0 - pow(pressure/100 / SEA_LEVEL_PRESSURE, 0.1903)); */ + //计算公式温度用实际值,压强用实际值的百分之一 + return ((float)powf(SEA_LEVEL_PRESSURE / ((float)pressure / 100.0), 0.190223f) - 1.0f) * ((float)temperature + 273.15f) / 0.0065f; // Calculate the altitude in metres +#endif +} + +/*************************test*************************/ +#if 0 +static struct _bmp280_dev_platform_data bmp280_iic_info_test = { + .iic_hdl = 0, + .iic_delay = 0 +}; +#define _portio 0 +void bmp280_init_read_test() +{ + u16 i = 0, iii = 40; + bmp_pressure_data bmp_pressure; + bmp_temperature_data bmp_temperature; + float bmp280_altitude = 0; + /* JL_PORTA->DIR &= ~(BIT(0)|BIT(9)|BIT(10)); */ + /* JL_PORTA->OUT &= ~(BIT(0)|BIT(9)|BIT(10)); */ + iic_init(bmp280_iic_info_test.iic_hdl); + + log_info("bmp280 init***************************\n"); + if (bmp280_init(&bmp280_iic_info_test)) { + log_info("bmp280 init ok!***************************\n"); + while (iii--) { + bmp280_get_temperature_and_pressure(&bmp_temperature, &bmp_pressure); + /* bmp280_forced_mode_get_temperature_and_pressure(&bmp_temperature , &bmp_pressure); */ + bmp280_altitude = bmp280_get_altitude(bmp_temperature, bmp_pressure); +#if USE_FIXED_POINT_COMPENSATE //使用定点补偿 + + log_info("bmp280 fixed Pressure %ld.%02dpa,temperature:%d.%02dc,alti:%d.%02dm\n", bmp_pressure / 100, bmp_pressure % 100, bmp_temperature / 100, bmp_temperature % 100, (s32)bmp280_altitude, (u32)(((s32)(abs(bmp280_altitude * 100))) % 100)); +#else //使用浮点补偿 + + log_info("bmp280 float Pressure %d.%02dpa,temperature:%d.%02dc,alti:%d.%02dm\n", (s32)bmp_pressure, (s32)(bmp_pressure * 100) % 100, (s32)bmp_temperature, (s32)(bmp_temperature * 100) % 100, (s32)bmp280_altitude, (u32)((s32)(bmp280_altitude * 100) % 100)); +#endif + delay(500000); + } + } else { + log_error("bmp280 init fail!***************************\n"); + } + while (1); +} + +#endif + + + +#endif diff --git a/2.code/2.p11_code/apps/common/device/gSensor/SC7A20.c b/2.code/2.p11_code/apps/common/device/gSensor/SC7A20.c new file mode 100644 index 0000000..548ffb6 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/SC7A20.c @@ -0,0 +1,200 @@ +#include "app_config.h" +#include "gSensor_manage.h" +#include "SC7A20.h" +#include "includes.h" +#include "iic_api.h" +#include "math.h" +#include "bank_switch.h" +#include "gpio.h" +/* #pragma bss_seg(".gsport_dev_bss") */ +/* #pragma const_seg(".gsport_dev_const") */ +/* #pragma code_seg(".gsport_dev_code") */ +/* */ + + +#define BANK_NAME BANK_SENSOR_TAG + + +#if TCFG_SC7A20_EN + +#define LOG(fmt,...) printf("[dev] " fmt "\n",##__VA_ARGS__) + +#define SL_SC7A20H_FIFO_CTRL_REG (unsigned char)0X2E +#define SL_SC7A20H_FIFO_SRC_REG (unsigned char)0X2F +#define SL_SC7A20H_SPI_OUT_X_L (unsigned char)0X27 +#define SL_SC7A20H_IIC_OUT_X_L (unsigned char)0XA8 + +static unsigned char SL_SPI_IIC_INTERFACE = 0; + +/***使用驱动前请根据实际接线情况配置(7bit)IIC地址******/ +/**SC7A20的SDO 脚接地: 0x18****************/ +/**SC7A20的SDO 脚接电源: 0x19****************/ +#define SC7A20_W_ADDR (0x19U << 1 | 0x0) +#define SC7A20_R_ADDR (0x19U << 1 | 0x1) +/*******************************************************/ + +#define SL_SC7A20H_INIT_REG1_NUM 8 +static unsigned char SL_SC7A20H_INIT_REG1[SL_SC7A20H_INIT_REG1_NUM * 3] = { + 0x24, 0x80, 0x00, + 0x2E, 0x00, 0x00, + 0x1f, 0x00, 0x00, + 0x20, 0x37, 0x00, + 0x21, 0x70, 0x00, + 0x23, 0x10, 0x00, + 0x24, 0x40, 0x00, + 0x2E, 0x4F, 0x00, +}; + +static unsigned char SL_SC7A20H_I2c_Spi_Write(unsigned char sl_spi_iic, unsigned char reg, unsigned char data) +{ + return gravity_sensor_command(SC7A20_W_ADDR, reg, data); +} + +static unsigned char SL_SC7A20H_I2c_Spi_Read(unsigned char sl_spi_iic, unsigned char reg, unsigned char len, unsigned char *buf) +{ + return _gravity_sensor_get_ndata(SC7A20_R_ADDR, reg, buf, len); +} + +static unsigned char SL_SC7A20H_Check(void) +{ + unsigned char id1 = 0; + unsigned char id2 = 0; + + SL_SC7A20H_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x0f, 1, &id1); + SL_SC7A20H_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x70, 1, &id2); + + LOG("id1=0x%02x id2=%02x", id1, id2); + return id1 == 0x11 && (id2 == 0x28 || id2 == 0x11); +} + +static signed char SL_SC7A20H_Driver_Init(unsigned char Sl_spi_iic_init, unsigned char Sl_pull_up_mode) +{ + unsigned char i = 0; + + if (Sl_spi_iic_init == 0) { + SL_SPI_IIC_INTERFACE = 0; //spi + } else { + SL_SPI_IIC_INTERFACE = 1; //iic + } + + if (!SL_SC7A20H_Check()) { + return -1; + } + + SL_SC7A20H_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x57, Sl_pull_up_mode); + + for (i = 0; i < SL_SC7A20H_INIT_REG1_NUM; i++) { + SL_SC7A20H_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, SL_SC7A20H_INIT_REG1[3 * i], SL_SC7A20H_INIT_REG1[3 * i + 1]); + } + + for (i = 0; i < SL_SC7A20H_INIT_REG1_NUM; i++) { + SL_SC7A20H_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, SL_SC7A20H_INIT_REG1[3 * i], 1, &SL_SC7A20H_INIT_REG1[3 * i + 2]); + } + + for (i = 2; i < SL_SC7A20H_INIT_REG1_NUM; i++) { + if (SL_SC7A20H_INIT_REG1[3 * i + 1] != SL_SC7A20H_INIT_REG1[3 * i + 2]) { + break; + } + } + + if (i != SL_SC7A20H_INIT_REG1_NUM) { + if (SL_SPI_IIC_INTERFACE == 0) { + return -1; //reg write and read error by SPI + } else { + return -2; //reg write and read error by IIC + } + } + + return 0; +} + +static unsigned char SL_SC7A20H_Read_FIFO_Buf(axis_info_t *accel) +{ + unsigned char i = 0; + unsigned char sc7a20_data[7]; + unsigned char SL_FIFO_ACCEL_NUM; + short x, y, z; + + SL_SC7A20H_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, SL_SC7A20H_FIFO_SRC_REG, 1, &SL_FIFO_ACCEL_NUM); + + if (SL_FIFO_ACCEL_NUM & 0x40) { + SL_FIFO_ACCEL_NUM = 32; + } else { + SL_FIFO_ACCEL_NUM = SL_FIFO_ACCEL_NUM & 0x1f; + } + + for (i = 0; i < SL_FIFO_ACCEL_NUM; i++) { + if (SL_SPI_IIC_INTERFACE == 0) { + SL_SC7A20H_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, SL_SC7A20H_SPI_OUT_X_L, 7, &sc7a20_data[0]); + } else { + SL_SC7A20H_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, SL_SC7A20H_IIC_OUT_X_L, 6, &sc7a20_data[1]); + } + + x = (signed short int)(((unsigned char)sc7a20_data[2] * 256) + (unsigned char)sc7a20_data[1]); + y = (signed short int)(((unsigned char)sc7a20_data[4] * 256) + (unsigned char)sc7a20_data[3]); + z = (signed short int)(((unsigned char)sc7a20_data[6] * 256) + (unsigned char)sc7a20_data[5]); + + accel[i].x = y >> 3; + accel[i].y = x >> 3; + accel[i].z = z >> 3; + + LOG("\nxyz(%d,%d): %d %d %d", SL_FIFO_ACCEL_NUM, i, accel[i].x, accel[i].y, accel[i].z); + } + + SL_SC7A20H_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, SL_SC7A20H_FIFO_CTRL_REG, 0X00); + SL_SC7A20H_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, SL_SC7A20H_FIFO_CTRL_REG, 0X4F); + + return SL_FIFO_ACCEL_NUM; +} + +static unsigned char SL_SC7A20H_Init(void) +{ + return SL_SC7A20H_Driver_Init(1, 0); +} + +static unsigned char SL_SC7A20H_Disable(void) +{ + return SL_SC7A20H_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 20, 0); +} + + +s32 SL_SC7A20H_CTL(u8 cmd, void *arg) +{ + char res; + s32 ret = 0; + + switch (cmd) { + case GSENSOR_DISABLE: + res = SL_SC7A20H_Disable(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESET_INT: + res = SL_SC7A20H_Init(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESUME_INT: + break; + case GSENSOR_INT_DET: + break; + case READ_GSENSOR_DATA: + ret = SL_SC7A20H_Read_FIFO_Buf((axis_info_t *)arg); + break; + case SEARCH_SENSOR: + res = SL_SC7A20H_Check(); + memcpy(arg, &res, 1); + break; + default: + break; + } + return ret; +} + + +REGISTER_GRAVITY_SENSOR(gSensor) = { + .logo = "sc7a20", + .gravity_sensor_init = SL_SC7A20H_Init, + .gravity_sensor_check = NULL, + .gravity_sensor_ctl = SL_SC7A20H_CTL, +}; + +#endif \ No newline at end of file diff --git a/2.code/2.p11_code/apps/common/device/gSensor/gSensor_algo.c b/2.code/2.p11_code/apps/common/device/gSensor/gSensor_algo.c new file mode 100644 index 0000000..bfc5500 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/gSensor_algo.c @@ -0,0 +1,57 @@ +#include "app_config.h" +#include "includes.h" +#include "msg.h" +#include "p11_algo_api.h" + + +#define LOG(fmt,...) //printf("[dev_acc] %s " fmt "\n",__func__, ##__VA_ARGS__) + +void algo_event_response(u8 event) +{ + static u8 p11_algo_event; + + p11_algo_event = event; + u8 low_power_mode = MSYS_STATE_GET() != MSYS_STATE_NORMAL; + + if (p11_algo_event == ALGO_WRIST_DOWN && low_power_mode) { + return; + } + // algo_log("P11 algo event %d", event); + user_p11_post_to_main_system(P11_SYS_ALGO_EVENT, 1, &p11_algo_event, 0); //通知算法事件 + +} + +void gsensor_algo_run(void *accel, short point) +{ + // gpio_set_direction(IO_PORTB_09, 0); + // gpio_set_output_value(IO_PORTB_09, 1); + u8 algo_event = algo_gsensor_run((accel_data *)accel, point); + // gpio_set_output_value(IO_PORTB_09, 0); + + if (algo_event != ALGO_NOTHING) { + algo_event_response(algo_event); + } +} + + +void gsensor_algo_init(void) +{ + algo_type open_algo; + accel_config accel; + + open_algo.all = 0; + open_algo.wrist_up = 1; + open_algo.wrist_down = 1; + + accel.sps = 25; + accel.lsb_g = 1024; + algo_gsensor_init(open_algo, accel); + + LOG("sucess!"); +} + + +void gsensor_algo_uninit(void) +{ + LOG("sucess!"); +} \ No newline at end of file diff --git a/2.code/2.p11_code/apps/common/device/gSensor/gSensor_manage.c b/2.code/2.p11_code/apps/common/device/gSensor/gSensor_manage.c new file mode 100644 index 0000000..d118b6e --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/gSensor_manage.c @@ -0,0 +1,515 @@ +#include "gSensor_manage.h" +#include "app_config.h" +#include "circular_buf.h" +#include "gpio.h" +#include "sensor_gp_timer.h" +#include "gp_timer_api.h" +#include "sensor_api.h" +#include "msg.h" +#include "iic_soft.h" +#include "bank_switch.h" +#include "gSensor_algo.h" +/* #include "device/device.h" */ +/* #include "debug.h" */ +/* #include "key_event_deal.h" */ +/* #include "btstack/avctp_user.h" */ +/* #include "app_main.h" */ +/* #pragma bss_seg(".gsport_dev_bss") */ +/* #pragma const_seg(".gsport_dev_const") */ +/* #pragma code_seg(".gsport_dev_code") */ +/* */ + + +/* #if TCFG_GSENSOR_ENABLE */ + +#ifndef log_info +#define log_info(...) // printf +#endif +#ifndef log_e +#define log_e(...) printf(__VA_ARGS__) +#endif + +#define BANK_NAME BANK_SENSOR_TAG + + +static const struct gsensor_platform_data *platform_data; +G_SENSOR_INTERFACE *gSensor_hdl = NULL; +G_SENSOR_INFO __gSensor_info = {.iic_delay = 10}; +#define gSensor_info (&__gSensor_info) +#define BUF_POINT ((20+30)*3) //gsensorlen +/* #define BUF_POINT ((200+30)*3+7*1024+256) //gsensorlen */ +static cbuffer_t *data_w_cbuf; +static short data_buf[BUF_POINT]; +static u8 read_write_status = 0; +static u16 callback_len = sizeof(data_buf); + +#if TCFG_GSENOR_USER_IIC_TYPE +#define iic_init(iic) hw_iic_init() +#define iic_close(iic) hw_iic_close() +#define iic_start(iic) hw_iic_start() +#define iic_stop(iic) hw_iic_stop() +#define iic_tx_byte(iic, byte) hw_iic_master_tx_byte(byte) +#define iic_rx_byte(iic, ack) hw_iic_master_rx_byte(ack) +#define iic_read_buf(iic, buf, len) hw_iic_master_read_buf(buf, len) +#define iic_write_buf(iic, buf, len) hw_iic_master_write_buf(buf, len) +/* #define iic_suspend(iic) hw_iic_suspend() */ +/* #define iic_resume(iic) hw_iic_resume() */ +#else +#define iic_init(iic) soft_iic_init(iic) +#define iic_close(iic) soft_iic_uninit(iic) +#define iic_start(iic) soft_iic_start(iic) +#define iic_stop(iic) soft_iic_stop(iic) +#define iic_tx_byte(iic, byte) soft_iic_tx_byte(iic, byte) +#define iic_rx_byte(iic, ack) soft_iic_rx_byte(iic, ack) +#define iic_read_buf(iic, buf, len) soft_iic_read_buf(iic, buf, len) +#define iic_write_buf(iic, buf, len) soft_iic_write_buf(iic, buf, len) +/* #define iic_suspend(iic) soft_iic_suspend(iic) */ +/* #define iic_resume(iic) soft_iic_resume(iic) */ +#endif + + + + +//8 bit 地址 +int gravity_sensor_write(u8 w_chip_id, + u8 *data, u8 length) +{ + u8 ret; + iic_start(gSensor_info->iic_hdl); + if (0 == iic_tx_byte(gSensor_info->iic_hdl, w_chip_id)) { + ret = -1; + log_e("\n gsen iic wr err 0\n"); + goto __gcend; + } + delay(gSensor_info->iic_delay); + ret = iic_write_buf(gSensor_info->iic_hdl, data, length); + if (ret != length) { + ret = -1; + log_e("\n gsen iic wr err 1 %x %x\n", ret, length); + goto __gcend; + } +__gcend: + iic_stop(gSensor_info->iic_hdl); + return ret; +} + + + + + + + + + +u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command) +{ + /* putchar('['); */ + u8 ret = 1; + iic_start(gSensor_info->iic_hdl); + if (0 == iic_tx_byte(gSensor_info->iic_hdl, w_chip_id)) { + ret = 0; + log_e("\n gsen iic wr err 0\n"); + goto __gcend; + } + + delay(gSensor_info->iic_delay); + + if (0 == iic_tx_byte(gSensor_info->iic_hdl, register_address)) { + ret = 0; + log_e("\n gsen iic wr err 1\n"); + goto __gcend; + } + + delay(gSensor_info->iic_delay); + + if (0 == iic_tx_byte(gSensor_info->iic_hdl, function_command)) { + ret = 0; + log_e("\n gsen iic wr err 2\n"); + goto __gcend; + } + +__gcend: + iic_stop(gSensor_info->iic_hdl); + /* putchar(']'); */ + return ret; +} + +int _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, int data_len) +{ +// printf("%s",__func__); + /* putchar('{'); */ + u8 read_len = 0; + + iic_start(gSensor_info->iic_hdl); + if (0 == iic_tx_byte(gSensor_info->iic_hdl, r_chip_id - 1)) { + log_e("\n gsen iic rd err 0\n"); + read_len = 0; + goto __gdend; + } + + + delay(gSensor_info->iic_delay); + if (0 == iic_tx_byte(gSensor_info->iic_hdl, register_address)) { + log_e("\n gsen iic rd err 1\n"); + read_len = 0; + goto __gdend; + } + + iic_start(gSensor_info->iic_hdl); + if (0 == iic_tx_byte(gSensor_info->iic_hdl, r_chip_id)) { + log_e("\n gsen iic rd err 2\n"); + read_len = 0; + goto __gdend; + } + + delay(gSensor_info->iic_delay); + + for (; data_len > 1; data_len--) { + *buf++ = iic_rx_byte(gSensor_info->iic_hdl, 1); + read_len ++; + } + + *buf = iic_rx_byte(gSensor_info->iic_hdl, 0); + read_len ++; + +__gdend: + + iic_stop(gSensor_info->iic_hdl); + delay(gSensor_info->iic_delay); + return read_len; +} + + +void gSensor_int_io_detect(void *priv) +{ + u8 int_io_status = 0; + u8 det_result = 0; + int_io_status = gpio_read(platform_data->gSensor_int_io); + log_info("status %d\n", int_io_status); + gSensor_hdl->gravity_sensor_ctl(GSENSOR_INT_DET, &int_io_status); + if (gSensor_hdl->gravity_sensor_check == NULL) { + return; + } + det_result = gSensor_hdl->gravity_sensor_check(); + if (det_result == 1) { + log_info("GSENSOR_EVENT_CLICK\n"); + /* gSensor_event_to_user(KEY_EVENT_CLICK); */ + } else if (det_result == 2) { + log_info("GSENSOR_EVENT_DOUBLE_CLICK\n"); + /* gSensor_event_to_user(KEY_EVENT_DOUBLE_CLICK); */ + } else if (det_result == 3) { + log_info("GSENSOR_EVENT_THREE_CLICK\n"); + /* gSensor_event_to_user(KEY_EVENT_TRIPLE_CLICK); */ + } +} + + +int gSensor_read_data(u8 *buf, u8 buflen) +{ + if (buflen < 32) { + return 0; + } + axis_info_t accel_data[32]; + if (!gpio_read(platform_data->gSensor_int_io)) { + gSensor_hdl->gravity_sensor_ctl(READ_GSENSOR_DATA, accel_data); + } + memcpy(buf, accel_data, sizeof(accel_data)); + return sizeof(accel_data) / sizeof(axis_info_t); +} +//输出三轴数组和数据长度 +// +int get_gSensor_data(short *buf) +{ + axis_info_t accel_data[32]; + /* if (!gpio_read(platform_data->gSensor_int_io)) */ + { + gSensor_hdl->gravity_sensor_ctl(READ_GSENSOR_DATA, accel_data); + for (int i = 0; i < 29; i++) { + buf[i * 3] = accel_data[i].x; + buf[i * 3 + 1] = accel_data[i].y; + buf[i * 3 + 2] = accel_data[i].z; + // printf("cnt:%1d x:%5d y:%5d z:%5d\n", i, accel_data[i].x, accel_data[i].y, accel_data[i].z); + } + return sizeof(accel_data) / sizeof(axis_info_t); + } + return 0; +} + + +int read_gsensor_buf_check_len() +{ + return data_w_cbuf->data_len; +} + + +int gsensor_set_soft_irq_size(u16 size) +{ + + if (size <= sizeof(data_buf)) { + callback_len = size; + return true; + } + return false; +} + +int read_gsensor_nbuf(u8 *buf, short datalen) +{ + /* printf("%s %d\n",__func__,__LINE__); */ + if (data_w_cbuf == NULL) { + + //printf("%s %d\n", __func__, __LINE__); + return 0; + } + if (gSensor_info->init_flag == 1) { + // if (read_write_status == 0) { + // read_write_status = 1; + // return 0; + // } + if (data_w_cbuf->data_len >= datalen) { + cbuf_read(data_w_cbuf, buf, datalen); + return datalen; + } else { + /* printf("%s %d\n", __func__, __LINE__); */ + return 0; + } + } else { + printf("%s NOT ONLINE ", __func__); + return 0; + } +} + + +extern int user_main_post_to_p11_system(u8 cmd, u8 wait); +extern void hr_sensor_input_accel_data(void *data, u8 point); + +void gsensor_data_irq_handle(void) +{ + static u8 gsensor_err = 0; + + axis_info_t accel_data[32]; + if (data_w_cbuf == NULL) { + return ; + } + if (gSensor_info->init_flag == 1) { + /* if (!gpio_read(platform_data->gSensor_int_io)) */ + { + int point = gSensor_hdl->gravity_sensor_ctl(READ_GSENSOR_DATA, accel_data); + u32 wlen = -1; + if (point) { + gsensor_err = 0; + gsensor_algo_run(accel_data, point); + hr_sensor_input_accel_data(accel_data, point); + wlen = cbuf_write(data_w_cbuf, accel_data, point * 2 * 3); + } else { + //多次读gsensor数据为空,gsensor可能异常,对gsensor 进行复位 + gsensor_err++; + if (gsensor_err > 2) { + gSensor_hdl->gravity_sensor_ctl(GSENSOR_RESET_INT, NULL); + gsensor_err = 0; + } + } + if (wlen == 0) { + cbuf_clear(data_w_cbuf); + wlen = cbuf_write(data_w_cbuf, accel_data, point * 2 * 3); + user_p11_post_to_main_system(P11_SYS_GSENSOR_IRQ, 0, NULL, 0); + /* printf("data_w_cbuf_full %x %x %x\n", data_w_cbuf, data_w_cbuf->data_len, &(data_w_cbuf->data_len)); */ + dev_log("g_full p=%d l=%d t=%d\n", point, data_w_cbuf->data_len, data_w_cbuf->total_len); + } else { + if (cbuf_get_data_len(data_w_cbuf) >= callback_len) { + dev_log("<<%d p>>>", callback_len); + user_p11_post_to_main_system(P11_SYS_GSENSOR_IRQ, 0, NULL, 0); + } + } + } + } else { + //printf("%s ",__func__); + return ; + } +} +void write_gsensor_data_handle(void) +{ + //printf("%s", __func__); + sensorhub_irq_add(IRQ_GSENSOR_INDEX); + // putchar('R'); + user_main_post_to_p11_system(P11_SYS_KICK, 0); + return ; +} + + + +/* REGISTER_CODE_SEG(BANK_CODE_SENSOR_NORMAL_BANK_1) */ +int gsensor_io_ctl(u8 cmd, void *arg) +{ + //printf("%s cmd=%d\n", __func__, cmd); + return gSensor_hdl->gravity_sensor_ctl(cmd, arg); +} +//u8 gravity_sen_dev_cur; /*当前挂载的Gravity sensor*/ +extern G_SENSOR_INTERFACE gsensor_dev_begin[]; +extern G_SENSOR_INTERFACE gsensor_dev_end[]; + +/* REGISTER_CODE_SEG(BANK_CODE_SENSOR_INIT_BANK_0) */ +int gravity_sensor_init(void *_data, cbuffer_t *cbuffer) +{ + + gSensor_info->init_flag = 0; + + int retval = 0; + platform_data = (const struct gsensor_platform_data *)_data; + gSensor_info->iic_hdl = platform_data->iic; + retval = iic_init(gSensor_info->iic_hdl); + + log_e("\n gravity_sensor_init\n"); + + if (retval < 0) { + log_e("\n open iic for gsensor err\n"); + return retval; + } else { + log_info("\n iic open succ\n"); + } + + retval = -EINVAL; + list_for_each_gsensor(gSensor_hdl) { + if (!memcmp(gSensor_hdl->logo, platform_data->gSensor_name, strlen(platform_data->gSensor_name))) { + retval = 0; + break; + } + } + /* printf("gsensor_dev_begin:0x%x,gsensor_dev_end :0x%x\n", gsensor_dev_begin, gsensor_dev_end); */ + /* printf("gsensor_dev_begin:0x%x,gsensor_dev_end :0x%x,sizeof(struct):%d\n", gsensor_dev_begin, gsensor_dev_end, sizeof(G_SENSOR_INTERFACE)); */ + /* printf("gSensor_hdl:0x%x,2logo:%s, name:%s\n", gSensor_hdl, gSensor_hdl->logo, platform_data->gSensor_name); */ + + if (retval < 0) { + log_e(">>>gSensor_hdl logo err\n"); + return retval; + } + + if (gSensor_hdl->gravity_sensor_init()) { + log_e(">>>>gSensor_Int ERROR\n"); + } else { + log_info(">>>>gSensor_Int SUCC\n"); + gSensor_info->init_flag = 1; + if (cbuffer) { + data_w_cbuf = cbuffer; + } else { + ASSERT(0); + } + cbuf_init(data_w_cbuf, data_buf, BUF_POINT * sizeof(u16)); + printf("gsensor init ok!\n"); + if (platform_data->gSensor_int_io != -1) { + /* timer0_capture_init(platform_data->gSensor_int_io);//默认下降沿触发 */ + + + /* gp_timer_capture(P11_GPTMR0, platform_data->gSensor_int_io, GP_TIMER_CAPTURE_EDGE_DOWN, 0); */ + + /* gp_timer_register_irq(P11_GPTMR0, write_gsensor_data_handle); */ + + + } + } + return 0; +} + +int gsensor_disable(void) +{ + printf("\n%s\n", __func__); +// #if CONFIG_SENSOR_ALG_ENABLE +// soft_iic_uninit(0);//some sensor need wait iic idle little ms +// #endif + if (data_w_cbuf == NULL) { + return -1; + } else { + if (gSensor_info->init_flag == 1) { + int valid = 0; + gSensor_hdl->gravity_sensor_ctl(GSENSOR_DISABLE, &valid); + cbuf_clear(data_w_cbuf); + gsensor_algo_uninit(); + if (valid == 0) { + /* free(data_w_cbuf); */ + /* data_w_cbuf = NULL; */ + return 0; + } + } + } + return -1; +} + +int gsensor_enable(void) +{ + printf("\n%s\n", __func__); + //查找设备 + int valid = 0; + gSensor_hdl->gravity_sensor_ctl(SEARCH_SENSOR, &valid); + if (valid == 0) { + return -1; + } + //工作空间 + /* data_buf = zalloc(BUF_SIZE); */ + /* if (data_buf == NULL) { */ + /* printf("gsensor_cbuf_error!"); */ + /* return -1; */ + /* } */ + /* data_w_cbuf = zalloc(sizeof(cbuffer_t)); */ + /* if (data_w_cbuf == NULL) { */ + /* return -1; */ + /* } */ + /* cbuf_init(data_w_cbuf, data_buf, BUF_SIZE); */ + printf("cbuf_init"); + //设置参数 + valid = 0; + gSensor_hdl->gravity_sensor_ctl(GSENSOR_RESET_INT, &valid); + + if (valid == -1) { + return -1; + } + + gsensor_algo_init(); + printf("gsensor_reset_succeed\n"); + return 0; +} + + +/************************ gsensor read data test********************/ +#if 0 +void gSensor_read_sensor_data_test() +{ + axis_info_t accel_data[32]; + u8 temp1[10]; + temp1[0] = 0x03; + temp1[1] = 0xfc; + temp1[9] = 0x03; + temp1[8] = 0xfc; + if (!gpio_read(platform_data->gSensor_int_io)) { + gSensor_hdl->gravity_sensor_ctl(READ_GSENSOR_DATA, accel_data); + + for (u8 i = 0; i < 29; i++) { + /* temp1[3] = accel_data[i].x >> 8; */ + /* temp1[2] = accel_data[i].x; */ + /* temp1[5] = accel_data[i].y >> 8; */ + /* temp1[4] = accel_data[i].y; */ + /* temp1[7] = accel_data[i].z >> 8; */ + /* temp1[6] = accel_data[i].z; */ + /* for (u8 j = 0; j < 10; j++) { */ + /* putbyte(temp1[j]); */ + /* } */ + printf("cnt:%2d, x:%5d, y:%5d, z:%5d\n", i, accel_data[i].x, accel_data[i].y, accel_data[i].z); + } + } +} + +void gsensor_read_cbuf_test() +{ + short temp[96]; + u16 i = 0; + if (read_gsensor_nbuf(temp, 2 * 96)) { + for (i = 0; i < 96; i += 3) { + printf("x:%d,y:%d,z:%d\n", temp[i], temp[i + 1], temp[i + 2]); + } + printf("\n"); + } else { + printf("read cbuf fail!\n"); + } +} + + +#endif +/* #endif */ diff --git a/2.code/2.p11_code/apps/common/device/gSensor/mir3da.c b/2.code/2.p11_code/apps/common/device/gSensor/mir3da.c new file mode 100644 index 0000000..9b7f52e --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/mir3da.c @@ -0,0 +1,269 @@ +#include "app_config.h" +#include "gSensor_manage.h" +#include "includes.h" +#include "iic_api.h" +#include "bank_switch.h" +#include "gpio.h" +#include "mir3da.h" + +/* #pragma bss_seg(".gsport_dev_bss") */ +/* #pragma const_seg(".gsport_dev_const") */ +/* #pragma code_seg(".gsport_dev_code") */ +/* */ + + +#define BANK_NAME BANK_SENSOR_TAG + + +#ifdef TCFG_MIR3DA_EN && TCFG_MIR3DA_EN + +#define LOG(fmt,...) printf("[mir3da] " fmt "\n",##__VA_ARGS__) + + +/***使用驱动前请根据实际接线情况配置(7bit)IIC地址******/ +/**DA263的SAO 脚接浮空: 0x27****************/ +/**DA263的SAO 脚接地: 0x26****************/ +static u8 i2c_addr = 0x27; + +enum { + MIR3_DA263, + MIR3_DA267, +} sensor_model; + + +static s8 mir3da_register_read(u8 addr, u8 *data, u8 len) +{ + return !_gravity_sensor_get_ndata((i2c_addr << 1) | 0x01, addr, data, len); +} + + +static s8 mir3da_register_write(u8 addr, u8 data) +{ + return !gravity_sensor_command((i2c_addr << 1) | 0x00, addr, data); +} + + +static s8 mir3da_is_online(void) +{ + u8 data = 0; + + for (u8 i = 0; i < 3; i++) { + mir3da_register_read(NSA_REG_WHO_AM_I, &data, 1); + if (data == 0x13) { + break; + } + } + + LOG("device id=0x%02x", data); + return data == 0x13; +} + +static void mir3da_model_check(void) +{ + u8 data = 0; + mir3da_register_read(0x11, &data, 1); + if (data == 0x80) { + sensor_model = MIR3_DA267; //reg11 Default data: 0x80 + } else { + sensor_model = MIR3_DA263; //reg11 Default data: 0x9E + } + LOG("reg11=0x%02x model=%s", data, sensor_model == MIR3_DA267 ? "da267" : "da263"); +} + +static s8 mir3da_register_mask_write(unsigned char addr, unsigned char mask, unsigned char data) +{ + int res = 0; + unsigned char tmp_data; + + res = mir3da_register_read(addr, &tmp_data, 1); + if (res) { + return res; + } + + tmp_data &= ~mask; + tmp_data |= data & mask; + res = mir3da_register_write(addr, tmp_data); + + return res; +} + + +//Initialization +u8 mir3da_init(void) +{ + s8 res = 0; + u8 data = 0; + + if (!mir3da_is_online()) { + LOG("fail!"); + return -1; + } + + mir3da_register_mask_write(0x00, 0x24, 0x24); //soft reset + mdelay(50); + mir3da_model_check(); + mir3da_register_write(0x0F, 0x01); //+/-4G,14bit(MIR3_DA263) or 16bit(MIR3_DA267) + + if (sensor_model == MIR3_DA263) { + mir3da_register_write(0x10, 0x05); //ODR =31.25hz + mir3da_register_write(0x11, 0x14); //normal mode + //打开工程模式 + mir3da_register_write(NSA_REG_ENGINEERING_MODE, 0x83); + mir3da_register_write(NSA_REG_ENGINEERING_MODE, 0x69); + mir3da_register_write(NSA_REG_ENGINEERING_MODE, 0xBD); + mir3da_register_mask_write(NAS_REG_OSC_TRIM, 0xf0, 0x00); //ODR=25hz + } else if (sensor_model == MIR3_DA267) { + mir3da_register_write(0x10, 0x15); //ODR = 25hz + mir3da_register_write(0x11, 0x00); //normal mode + } + + + //Reduce power consumption + if (i2c_addr == 0x26) { + //关闭1脚上拉 + mir3da_register_mask_write(NSA_REG_SENS_COMP, 0x40, 0x00); + } + + mir3da_register_write(0x14, 0x80); //stream mode + return 0; +} + +s8 mir3da_set_enable(u8 enable) +{ + s8 res = 0; + u8 reg11 = sensor_model == MIR3_DA263 ? 0x14 : 0x00; + + if (enable) { + res = mir3da_register_write(NSA_REG_POWERMODE_BW, reg11); + } else { + res = mir3da_register_write(NSA_REG_POWERMODE_BW, 0x80); + } + + return !res; +} + + +//Read three axis data, 1024 LSB = 1 g +s8 mir3da_read_data(s16 *x, s16 *y, s16 *z) +{ + u8 tmp_data[6] = {0}; + + if (mir3da_register_read(NSA_REG_ACC_X_LSB, tmp_data, 6) != 0) { + return -1; + } + + *x = ((s16)(tmp_data[1] << 8 | tmp_data[0])) >> 3; + *y = ((s16)(tmp_data[3] << 8 | tmp_data[2])) >> 3; + *z = ((s16)(tmp_data[5] << 8 | tmp_data[4])) >> 3; + + if (*x == 0 && *y == 0 && *z == 0) { + return -1; + } + LOG("xyz:%d,%d,%d", *x, *y, *z); + return 0; +} + +int mir3da_open_full_fifo_int() +{ + int res = 0; + res = mir3da_register_write(0x14, 0x80); + res = mir3da_register_write(0x15, 0x04); + res = mir3da_register_write(0x1A, 0x04); + return res; +} + + +//num 1-31 +int mir3da_open_fifo_watermark_int(u8 num) +{ + int res = 0; + res = mir3da_register_write(0x14, 0x80 | num); + res = mir3da_register_write(0x15, 0x08); + res = mir3da_register_write(0x1A, 0x02); + return res; +} + +int mir3da_close_fifo_int(void) +{ + int res = 0; + res = mir3da_register_write(0x14, 0x00); + res = mir3da_register_write(0x15, 0x00); + res = mir3da_register_write(0x1A, 0x00); + return res; +} + + +int mir3da_read_full_fifo(short *x, short *y, short *z) +{ + u8 i = 0, tmp_data = 0; + + mir3da_register_read(0x08, &tmp_data, 1); + + if ((tmp_data & 0x40)) { + for (i = 0; i < 32; i++) { + mir3da_read_data(x + i, y + i, z + i); + } + } + + return 0; +} + +int mir3da_read_fifo(axis_info_t *accel) +{ + u8 fifo_len = 0; + + mir3da_register_read(0x08, &fifo_len, 1); + fifo_len &= 0x3f; + + LOG("fifo_len=%d", fifo_len); + + for (u8 i = 0; i < fifo_len; i++) { + if (mir3da_read_data(&accel[i].x, &accel[i].y, &accel[i].z) == -1) { + fifo_len = i; + } + } + + return fifo_len; +} + + +s32 mir3da_ctl(u8 cmd, void *arg) +{ + char res; + s32 ret = 0; + LOG("cmd=%d", cmd); + switch (cmd) { + case GSENSOR_DISABLE: + res = mir3da_set_enable(0); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESET_INT: + res = mir3da_init(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESUME_INT: + break; + case GSENSOR_INT_DET: + break; + case READ_GSENSOR_DATA: + ret = mir3da_read_fifo((axis_info_t *)arg); + break; + case SEARCH_SENSOR: + res = mir3da_is_online(); + memcpy(arg, &res, 1); + break; + default: + break; + } + return ret; +} + + +REGISTER_GRAVITY_SENSOR(gSensor) = { + .logo = "mir3da", + .gravity_sensor_init = mir3da_init, + .gravity_sensor_check = NULL, + .gravity_sensor_ctl = mir3da_ctl, +}; + +#endif diff --git a/2.code/2.p11_code/apps/common/device/gSensor/msa310.c b/2.code/2.p11_code/apps/common/device/gSensor/msa310.c new file mode 100644 index 0000000..58bbaa9 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/msa310.c @@ -0,0 +1,462 @@ +#include "app_config.h" +#include "gSensor_manage.h" +#include "includes.h" +#include "iic_api.h" +#include "math.h" +#include "bank_switch.h" +#include "gpio.h" +#include "msa310.h" +#include "msa310_function.h" +/* #pragma bss_seg(".gsport_dev_bss") */ +/* #pragma const_seg(".gsport_dev_const") */ +/* #pragma code_seg(".gsport_dev_code") */ +/* */ + + +#define BANK_NAME BANK_SENSOR_TAG + +#if TCFG_MSA310_EN + +#ifndef g_printf +#define g_printf //printf +#endif +#ifndef log_info +#define log_info printf +#endif +#ifndef log_error +#define log_error printf +#endif + + +#define INT_IO IO_PORTB_03 + +#define MSA310_W_ADDR (0x62 << 1 | 0x0) +#define MSA310_R_ADDR (0x62 << 1 | 0x1) + +uint8_t msa_id = 0; + +static unsigned int MSA_STEP = 0;//计步值 +static unsigned int MSA_LIGHT = 0;//抬手亮屏 +static unsigned char MSA_SWAY_STATUS = 0;//摇一摇拍照 +static unsigned char MSA_SLEEP = 0;//摇一摇拍照 +static uint8_t slee_cnt = 0;//睡眠变量 + + +#if 0 +#define abs(x) (((x) < 0) ? (-(x)) : (x)) +int16_t msa_sqrt(int32_t x) +{ + double a = 1.0; + while (abs(a * a - x) > 100) { + a = (a + x / a) / 2; + } + return (int16_t)a; +} +#endif +/*return value: 0: is ok -1:read is failed*/ +int32_t msa_register_read(uint8_t addr, uint8_t *data) +{ + int32_t res = 0; + + res = _gravity_sensor_get_ndata(MSA310_R_ADDR, addr, data, 1);//return:0:err, 1:ok + if (res) { + return 0; + } + return -1; +} + +/*return value: 0: is ok -2:write is failed*/ +int32_t msa_register_write(uint8_t addr, uint8_t data) +{ + int32_t res = 0; + + // ret = msa_WriteBytes(addr,data); + res = gravity_sensor_command(MSA310_W_ADDR, addr, data);//return:0:err, 1:ok + if (res) { + return 0; + } + return -2; +} + +//return:0:ok, -1:err +int32_t msa_register_read_continuously(uint8_t addr, uint8_t count, uint8_t *data) +{ + int32_t res = 0; + int32_t i = 0; + + for (i = 0; i < count; i++) { + res = msa_register_read(addr + i, data + i); + if (res) { + return res; + + } + } + return res;//ok +} + +//return:0:ok, -1/-2:err +int32_t msa_register_mask_write(uint8_t addr, uint8_t mask, uint8_t data) +{ + int32_t res = 0; + uint8_t tmp_data; + + res = msa_register_read(addr, &tmp_data); + if (res) { + return res; + } + + tmp_data &= ~mask; + tmp_data |= data & mask; + res = msa_register_write(addr, tmp_data); + + return res; +} + +/*return value: 0: is ok other: is failed*/ +int32_t msa_read_data(int16_t *x, int16_t *y, int16_t *z) +{ + uint8_t tmp_data[6] = {0}; + + if (msa_register_read_continuously(MSA_REG_ACC_X_LSB, 6, tmp_data) != 0) { + return -1; + } + + *x = ((short)(tmp_data[1] << 8 | tmp_data[0])) >> 4; + *y = ((short)(tmp_data[3] << 8 | tmp_data[2])) >> 4; + *z = ((short)(tmp_data[5] << 8 | tmp_data[4])) >> 4; + + return 0; +} + + +#if 1 + +int32_t msa_read_fifo(axis_info_t *raw_accel) +{ + int i = 0; + unsigned char data_count = 0; + uint8_t temp_buf[192];//32*6 + msa_register_read(0x0d, &data_count); + data_count = (data_count & 0x7F); + /* printf("data_count1 = %d \r\n",data_count); */ + if (data_count > 32) { + data_count = 32; + } + /* printf("data_count = %d \r\n",data_count); */ + _gravity_sensor_get_ndata(MSA310_R_ADDR, 0xff, temp_buf, data_count * 6); //return:0:err, acc_count*6:ok + + for (u8 i = 0; i < data_count; i++) { + raw_accel[i].x = ((short)(temp_buf[i * 6 + 1] << 8 | temp_buf[i * 6 + 0])) >> 4; + raw_accel[i].y = ((short)(temp_buf[i * 6 + 3] << 8 | temp_buf[i * 6 + 2])) >> 4; + raw_accel[i].z = ((short)(temp_buf[i * 6 + 5] << 8 | temp_buf[i * 6 + 4])) >> 4; + /* printf("%d: %d %d %d\r\n", data_count-i,raw_accel[i].x,raw_accel[i].y,raw_accel[i].z); */ + } + return data_count; +} +#else +int32_t msa_read_fifo(int16_t *xBuf, int16_t *yBuf, int16_t *zBuf, int len) +{ + int i = 0; + uint8_t temp_buf[384]; +#if 0 + +//#else + _gravity_sensor_get_ndata(MSA310_R_ADDR, 0xff, data, len * 6);//return:0:err, len * 6:ok + + for (i = 0; i < len; i++) { + xBuf[i] = ((short)(temp_buf[i * 6 + 1] << 8 | temp_buf[i * 6 + 0])) >> 4; + yBuf[i] = ((short)(temp_buf[i * 6 + 3] << 8 | temp_buf[i * 6 + 2])) >> 4; + zBuf[i] = ((short)(temp_buf[i * 6 + 5] << 8 | temp_buf[i * 6 + 4])) >> 4; + } +#endif + return TRUE; +} + +/* u8 MSA310_GetAccAxesRaw(axis_info_t* buff) */ +/* { */ +/* uint8_t tmp_data[6] = {0}; */ +/* if (msa_register_read_continuously(MSA_REG_ACC_X_LSB, 6, tmp_data) != 0) { */ +/* return -1; */ +/* } */ +/* */ +/* buff->y = ((short)(tmp_data[3] << 8 | tmp_data[2]))>> 4; */ +/* buff->x = ((short)(tmp_data[1] << 8 | tmp_data[0]))>> 4; */ +/* buff->z = ((short)(tmp_data[5] << 8 | tmp_data[4]))>> 4; */ +/* */ +/* return 0; */ +/* } */ +#endif + +/*return value: 0: is ok other: is failed*/ +/* REGISTER_CODE_SEG(BANK_CODE_SENSOR_INIT_BANK_0) */ +uint8_t msa310_init(void) +{ + int32_t res = 0; + uint8_t data = 0; + + msa_register_read(MSA_REG_WHO_AM_I, &msa_id); + if (msa_id != 0x13) { + log_error("read msa310 id error"); + return -1; + } + log_info("msa310 id:0x%x", msa_id); + + //reset + res = msa_register_mask_write(MSA_REG_SOFT_RESET, 0x24, 0x24); + + mdelay(10);//10ms + + res |= msa_register_mask_write(MSA_REG_G_RANGE, 0x03, 0x02);//0:2g, 1:4g, 2:8g, 3:16g + res |= msa_register_mask_write(MSA_REG_POWERMODE_BW, 0xFF, 0x5e);//low power mode, BW:500hz + /* res |= msa_register_mask_write(MSA_REG_ODR_AXIS_DISABLE, 0xFF, 0x04);//xyz enable, odr:15.63hz */ + /* res |= msa_register_mask_write(MSA_REG_POWERMODE_BW, 0xFF, 0x50);//low power mode, BW:125hz */ + /* res |= msa_register_mask_write(MSA_REG_POWERMODE_BW, 0xFF, 0x4e);//low power mode, BW:62.5hz */ + res |= msa_register_mask_write(MSA_REG_ODR_AXIS_DISABLE, 0xFF, 0x07);//xyz enable, odr:125hz + +//fifo config + // bit67:00: bypass mode, 01: FIFO mode, 10: stream mode, 11: trigger mode, WATERMARK_SAMPLES[5:0]:0x20(32) + res |= msa_register_mask_write(MSA_REG_FIFO_CTRL, 0xFF, 0xa0); + res |= msa_register_mask_write(MSA_REG_FIFO_CTRL1, 0x03, 0x00);//fifo enable xyz data + + //int config + res |= msa_register_mask_write(MSA_REG_INTERRUPT_SETTINGS2, 0x78, 0x60);//bit6:OVERRUN_INT_EN, bit5:WATERMARK_INT_EN, bit4:NEW_DATA_INT_EN, bit3:FREEFALL_INT_EN + res |= msa_register_mask_write(MSA_REG_INTERRUPT_MAPPING2, 0x07, 0x06);//bit2:OVERRUN_INT1, bit1:WATERMARK_INT1, bit0:NEW_DATA_INT1 + res |= msa_register_mask_write(MSA_REG_INT_PIN_CONFIG, 0x03, 0x00);//bit1:INT1 OD mode, bit0:INT1 LEVEL + res |= msa_register_mask_write(MSA_REG_INT_LATCH, 0x8f, 0x00);//non-latched + + msa_param_init(); + + /* if (!gpio_read(INT_IO)) { //低电平,说明上一次中断信息未处理 */ + /* printf("\nint need deal with\n"); */ + /* short tempbuf[32]; */ + /* get_gSensor_data(tempbuf); */ + /* } */ + /* printf("msa310 init ok!\n"); */ + return res; +} +/*return value: 0: is ok other: is failed*/ +uint8_t msa310_stop(void) +{ + int32_t res = 0; + + res |= msa_register_mask_write(MSA_REG_POWERMODE_BW, 0xFF, 0xDE);//lkk modify 0x5E + res |= msa_register_mask_write(MSA_REG_FIFO_CTRL, 0xFF, 0x00); + + return res; +} + + +//摇一摇拍照接口 +bool msa310_shake(short x, short y, short z) +{ +#if 1 + static u8 cnt = 0; + static axis_info_t xyz_axis[4]; + static short max_x, max_y, max_z; + static short min_x, min_y, min_z; + + xyz_axis[cnt].x = x; + xyz_axis[cnt].y = y; + xyz_axis[cnt].z = z; + + cnt++; + if (cnt == 4) { + cnt = 0; + max_x = min_x = xyz_axis[cnt].x; + max_y = min_y = xyz_axis[cnt].y; + max_z = min_z = xyz_axis[cnt].z; + for (u8 i = 0; i < 4; i++) { + if (xyz_axis[i].x > max_x) { + max_x = xyz_axis[i].x; + } + + if (xyz_axis[i].x < min_x) { + min_x = xyz_axis[i].x; + } + + if (xyz_axis[i].y > max_y) { + max_y = xyz_axis[i].y; + } + + if (xyz_axis[i].y < min_y) { + min_y = xyz_axis[i].y; + } + + if (xyz_axis[i].z > max_z) { + max_z = xyz_axis[i].z; + } + + if (xyz_axis[i].z < min_z) { + min_z = xyz_axis[i].z; + } + } + //co_printf("max_x:%d,min_x:%d\r\n",max_x,min_x); + //co_printf("max_y:%d,min_y:%d\r\n",max_y,min_y); + //co_printf("max_z:%d,min_z:%d\r\n",max_z,min_z); + + if (((max_x - min_x) > 400) || ((max_y - min_y) > 400) || ((max_z - min_z) > 400)) { + return true; + } else { + return false; + } + } + return false; +#endif +} + + +void MSA310_GetFiFOAccAxesRaw(void) +{ + uint8_t temp_buf[384] = {0}; + short x = 0, y = 0, z = 0; + int xyz = 0; + unsigned char data_count = 0; + char i; + char id; + + msa_register_read(0x0d, &data_count); + //printf("data_count1 = %d \r\n",data_count); + data_count = (data_count & 0x7F); + //printf("data_count = %d \r\n",data_count); + if (data_count > 32) { + data_count = 32; + } + + _gravity_sensor_get_ndata(MSA310_R_ADDR, 0xff, temp_buf, data_count * 6); //return:0:err, acc_count*6:ok + + for (i = 0; i < data_count; i++) { + x = ((short)(temp_buf[i * 6 + 1] << 8 | temp_buf[i * 6 + 0])) >> 4; + y = ((short)(temp_buf[i * 6 + 3] << 8 | temp_buf[i * 6 + 2])) >> 4; + z = ((short)(temp_buf[i * 6 + 5] << 8 | temp_buf[i * 6 + 4])) >> 4; + printf(" %d %d %d %d\r\n", x, y, z, data_count - i); + + + //计步 + MSA_STEP = msa_step(x, y, z); + //APP_LOG("MSA_STEP=%d\n",MSA_STEP); + + //抬手亮屏 + if ((MSA_LIGHT == 1) || (MSA_LIGHT == 2)) { //取到状态后就不用计算抬手亮屏了 + //APP_LOG("MSA_LIGHT=%d\n",MSA_LIGHT); + } else { + MSA_LIGHT = msa_light(x, y, z); //函数返回值: 1 : 亮屏 2:灭屏 0:无动作 + } + + if (i == (data_count - 1)) { + MSA_LIGHT = 0; + } + + + + //摇一摇拍照 + static u8 SWAY_STATUS_TEMP = 0; + if (1) { //(SmartBand_GetShakePicture())//摇一摇拍照 + /**this function will disable pedo function**/ + MSA_SWAY_STATUS = msa310_shake(x, y, z); //get sway value + /* if(MSA_SWAY_STATUS== 1 && MSA_SWAY_STATUS!= SWAY_STATUS_TEMP && !motor_is_running() && motor_delay_lock()) */ + if (MSA_SWAY_STATUS == 1 && MSA_SWAY_STATUS != SWAY_STATUS_TEMP) { + //APP_LOG("MSA motor_is_running : %d\r\n", motor_is_running()); + //SmartBand_ControlShakePicture();//拍照 + SWAY_STATUS_TEMP = 1; + } else if (MSA_SWAY_STATUS == 0 && MSA_SWAY_STATUS != SWAY_STATUS_TEMP) { + SWAY_STATUS_TEMP = 0; + } + //APP_LOG("MSA_SWAY_STATUS = %d\r\n",MSA_SWAY_STATUS); + } + + + //睡眠 + //手环睡眠状态:SmartBand_SleepStatus + //充电状态:!get_charging_state() + /* if(SmartBand_SleepStatus && !get_charging_state()) */ + if (1) { + int sleep_status = msa_sleep(x, y, z); //3S采样一次数据 +#if 0 + if (sleep_status == MSA_RESTLESS) { + MSA_SLEEP = SLEEP_STATUS_AWAKE; + } else if (sleep_status == MSA_ASLEEP) { + MSA_SLEEP = SLEEP_STATUS_LIGHT; + } else if (sleep_status == MSA_ONTABLE) { + MSA_SLEEP = SLEEP_STATUS_DEEP; + } else if (sleep_status == MSA_AWAKE) { + MSA_SLEEP = SLEEP_STATUS_GETUP; + } +#endif + //APP_LOG("SL_SLEEP:%d\n",SL_SLEEP); + } + } +} +int msa_get_step(void) +{ + return MSA_STEP; +} +int msa_get_light(void) +{ + return MSA_LIGHT; +} +bool is_msa310_chipid(void) +{ + if (msa_id == 0x13) { + return true; + } else { + return false; + } +} + +bool msa310_check(void) +{ + u8 msa310_d = 0; + msa_register_read(MSA_REG_WHO_AM_I, &msa310_d); + if (msa310_d == 0x13) { + return true; + } else { + return false; + } +} + + + + + +/* REGISTER_CODE_SEG(BANK_CODE_SENSOR_NORMAL_BANK_1) */ +int msa310_ctl(u8 cmd, void *arg) +{ + int res = -1; + switch (cmd) { + case GSENSOR_DISABLE: + res = msa310_stop(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESET_INT: + res = msa310_init(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESUME_INT: + break; + case GSENSOR_INT_DET: + /* msa310_int_io_detect(*(u8 *)arg); */ + res = 0; + break; + case READ_GSENSOR_DATA: + res = msa_read_fifo((axis_info_t *)arg); + break; + case SEARCH_SENSOR: + res = msa310_check(); + memcpy(arg, &res, 1); + break; + default: + + break; + } + return res;//>=0:ok,,<0:err +} + +REGISTER_GRAVITY_SENSOR(gSensor) = { + .logo = "msa310", + .gravity_sensor_init = msa310_init, + .gravity_sensor_check = NULL,//msa310_click_status, + .gravity_sensor_ctl = msa310_ctl, +}; + +#endif + diff --git a/2.code/2.p11_code/apps/common/device/gSensor/msa310_function.c b/2.code/2.p11_code/apps/common/device/gSensor/msa310_function.c new file mode 100644 index 0000000..08c66c4 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/msa310_function.c @@ -0,0 +1,775 @@ +/** + ****************************************************************************** + * @file msa300_app_fixpoint.c + * @author memsensing algorithm team + * @version V1.1.0 + * @date 16- 8 -2018 + * @brief This file provides pedometer function of G-sensor MSA30x application + ****************************************************************************** +**/ +#include "gSensor_manage.h" +#include "msa310_function.h" + +#if (TCFG_MSA310_EN) + +Step_Typedef Step_Structure; +Bright_Typedef Bright_Structure; +Sleep_Typedef Sleep_Structure; + +// void sum_Calculate(void); +// void A_Calculate(void); +// void sleep_Mode_Calculate(void); +// void isTurn_Judge(void); +void find_Turn(void); +void sleep_Para_Clear(void); + + +static int a1[7] = {16384, -79111, 170817, -209099, 152847, -63295, 11720}; +static int b1[7] = {805, -2623, 2884, 0, -2884, 2623, -806}; +static int a2[7] = {16384, -64148, 119340, -133733, 95028, -40165, 8056}; +static int b2[7] = {1630, -3977, 3285, 0, -3285, 3977, -1630}; +static int beforeFilter[7]; +static int afterFilter[7]; + +void msa_step_clear(void)//计步清零 +{ + Step_Structure.step_cnt = 0; + Step_Structure.step_sum = 0; + Step_Structure.timeCnt = 0; + Step_Structure.timeNow = 0; + Step_Structure.lastPeakTime = 0; + Step_Structure.thisPeakTime = 0; + Step_Structure.lastStepTime = 0; + Step_Structure.thisStepTime = 0; + Step_Structure.ThresholdCnt = 0; + Step_Structure.stepMode = 1; + Step_Structure.stepModeCnt = 0; + Step_Structure.staticModeCnt = 0; +} + +void msa_param_init(void) +{ + //Pedometer Structure initial + Step_Structure.thisDirectionUp = 0; + Step_Structure.timeInterval = 5; + Step_Structure.valueThreshold = 40; + Step_Structure.valueThresholdInitial = 25; + Step_Structure.stepMode = 1; + Step_Structure.stepModeCnt = 0; + + Bright_Structure.autoBrightFlag = 0; + Bright_Structure.accSquareSum[0] = 0; + Bright_Structure.accSquareSum[1] = 0; + Bright_Structure.accSquareMaxLimit = 98304; + Bright_Structure.accSquareMinLimit = 23909;//43909 + Bright_Structure.enableCnt = 0; + Bright_Structure.enableCntLimit = 4; + Bright_Structure.disableCnt = 0; + Bright_Structure.disableCntLimit = 12; + Bright_Structure.xzAngel = 0; + Bright_Structure.yzAngel = 0; + Bright_Structure.xzAngelLimitMax = 35; + Bright_Structure.xzAngelLimitMin = -35; + Bright_Structure.yzAngelLimitMax = 90; + Bright_Structure.yzAngelLimitMin = 5;//25 + Bright_Structure.lastStatus = 1; + Bright_Structure.isLevelRotationCnt = 0; + Bright_Structure.autoBrightFromLevelFlag = 0; + Bright_Structure.levelRotationEnableCntLimit = 4; + Bright_Structure.levelDisableCntLimit = 40; + Bright_Structure.isLevelCntLimit = 4; + + Sleep_Structure.Data_Cnt = 0; + Sleep_Structure.Minute_Cnt = 0; +} + +static int peak_Search(short int newData, short int oldData) +{ + Step_Structure.lastDirectionUp = Step_Structure.thisDirectionUp; + + if (newData > oldData) { + Step_Structure.thisDirectionUp = 1; + Step_Structure.thisDirectionUpCnt++; + } + + else if (newData < oldData) { + Step_Structure.lastDirectionUpCnt = Step_Structure.thisDirectionUpCnt; + Step_Structure.thisDirectionUpCnt = 0; + Step_Structure.thisDirectionUp = 0; + } + + if (!Step_Structure.thisDirectionUp && \ + Step_Structure.lastDirectionUp && \ + Step_Structure.lastDirectionUpCnt >= 2 && \ + oldData >= 0) { + Step_Structure.valuePeak = oldData; + return 1; + } else if (Step_Structure.thisDirectionUp && \ + !Step_Structure.lastDirectionUp) { + Step_Structure.valueValley = oldData; + return 0; + } else { + return 0; + } +} + +static void step_Count(void) +{ + Step_Structure.lastStepTime = Step_Structure.thisStepTime; + Step_Structure.thisStepTime = Step_Structure.timeCnt; + //2s + if (Step_Structure.thisStepTime - Step_Structure.lastStepTime <= 20) { //40 + if (Step_Structure.step_cnt < 20) { //12 + Step_Structure.step_cnt++; + } else if (Step_Structure.step_cnt == 20) { //12 + Step_Structure.step_cnt++; + Step_Structure.step_sum += Step_Structure.step_cnt; + Step_Structure.valueThresholdInitial = 20; + } else { + Step_Structure.step_sum++; + } + } else { + Step_Structure.step_cnt = 1; + Step_Structure.valueThresholdInitial = 40; + Step_Structure.valueThreshold = 40; + } +} + +static void valueThreshold_Refresh(void) +{ + short int average; + if (Step_Structure.ThresholdCnt < 4) { + Step_Structure.Threshold[Step_Structure.ThresholdCnt] = Step_Structure.valuePeak - Step_Structure.valueValley; + Step_Structure.ThresholdCnt++; + } else { + Step_Structure.Threshold[0] = Step_Structure.Threshold[1]; + Step_Structure.Threshold[1] = Step_Structure.Threshold[2]; + Step_Structure.Threshold[2] = Step_Structure.Threshold[3]; + Step_Structure.Threshold[3] = Step_Structure.valuePeak - Step_Structure.valueValley; + average = (Step_Structure.Threshold[0] + Step_Structure.Threshold[1] + \ + Step_Structure.Threshold[2] + Step_Structure.Threshold[3]); + + average /= 4; + + if (average > 150) { + Step_Structure.valueThreshold = 70; + } else if (average > 120) { + Step_Structure.valueThreshold = 55; + } else if (average > 90) { + Step_Structure.valueThreshold = 40; + } else if (average > 75) { + Step_Structure.valueThreshold = 30; + } else if (average > 60) { + Step_Structure.valueThreshold = 25; + } else { + Step_Structure.valueThreshold = 16; + } + } +} + +void USER_Pedometer(void) +{ + if (Step_Structure.valueOld == 0) { + Step_Structure.valueOld = Step_Structure.valueNew; + } else { + if (peak_Search(Step_Structure.valueNew, Step_Structure.valueOld)) { + Step_Structure.lastPeakTime = Step_Structure.thisPeakTime; + Step_Structure.timeNow = Step_Structure.timeCnt; + if (((Step_Structure.timeNow - Step_Structure.lastPeakTime) >= Step_Structure.timeInterval) && \ + ((Step_Structure.valuePeak - Step_Structure.valueValley) >= Step_Structure.valueThreshold)) { + Step_Structure.thisPeakTime = Step_Structure.timeNow; + step_Count(); + } + if (((Step_Structure.timeNow - Step_Structure.lastPeakTime) >= Step_Structure.timeInterval) && \ + ((Step_Structure.valuePeak - Step_Structure.valueValley) >= Step_Structure.valueThresholdInitial)) { + valueThreshold_Refresh(); + } + } + } + Step_Structure.valueOld = Step_Structure.valueNew; +} + + +static int msa_filterWalk(int data) +{ + + int ret = 0; + + beforeFilter[0] = data * 5; + + for (int i = 0; i < 7; i++) { + ret += b1[i] * beforeFilter[i]; + } + + for (int i = 1; i < 7; i++) { + ret -= a1[i] * afterFilter[i]; + } + + ret /= 16384; + + afterFilter[0] = ret; + + for (int i = 6; i > 0; i--) { + afterFilter[i] = afterFilter[i - 1]; + beforeFilter[i] = beforeFilter[i - 1]; + } + + return ret; +} + +static int msa_filterRun(int data) +{ + int ret = 0; + + beforeFilter[0] = data * 5; + + for (int i = 0; i < 7; i++) { + ret += b2[i] * beforeFilter[i]; + } + + for (int i = 1; i < 7; i++) { + ret -= a2[i] * afterFilter[i]; + } + + ret /= 16384; + + afterFilter[0] = ret; + + for (int i = 6; i > 0; i--) { + afterFilter[i] = afterFilter[i - 1]; + beforeFilter[i] = beforeFilter[i - 1]; + } + + return ret; +} + +//求sqrt +static int msa_sqrt(int val) +{ + int r = 0; + int shift; + + if (val < 0) { + return 0; + } + + for (shift = 0; shift < 32; shift += 2) { + int x = 0x40000000l >> shift; + if (x + r <= val) { + val -= x + r; + r = (r >> 1) | x; + } else { + r = r >> 1; + } + } + return r; +} + +/* + * 计步器函数,msa_step(),返回的为实际步数,15步开始计数,不满15步停止视为无效步数,不清零一直累加,需要手动清零。//msa_app.c , msa310.c +50毫秒的timer调用一次msa_get_step,关闭时停止timer。使用FIFO数据(数据长度与ODR相关)。 //未找到 添加到msa310.c +例如500MS,10组数据,就循环调用10次算法。 + */ +unsigned int msa_step(short int x, short int y, short int z) +{ + Step_Structure.timeCnt++; + Step_Structure.valueNew = msa_sqrt(x * x + y * y + z * z); + + if (Step_Structure.stepMode == 1 && Step_Structure.valueNew > 200 && Step_Structure.valueNew < 295) { + Step_Structure.staticModeCnt ++; + if (Step_Structure.staticModeCnt > 10) { + Step_Structure.stepMode = 0; + } + } else { + Step_Structure.staticModeCnt = 0; + } + + if (Step_Structure.stepMode == 0 && Step_Structure.valueNew > 295) { + Step_Structure.stepMode = 1; + } + + if (Step_Structure.stepMode == 1 && Step_Structure.valueNew > 620) { + if (Step_Structure.stepModeCnt == 0) { + Step_Structure.stepModeTimeCnt = Step_Structure.timeCnt; + } + Step_Structure.stepModeCnt ++; + + if (Step_Structure.stepModeCnt > 5) { + if ((Step_Structure.timeCnt - Step_Structure.stepModeTimeCnt) < 60) { + Step_Structure.stepMode = 2; + Step_Structure.stepModeCnt = 0; + } else { + Step_Structure.stepModeCnt = 0; + } + } + } + if (Step_Structure.stepMode == 2) { + if (Step_Structure.valueNew < 620) { + Step_Structure.stepModeCnt ++; + if (Step_Structure.stepModeCnt > 50) { + Step_Structure.stepMode = 1; + Step_Structure.stepModeCnt = 0; + } + } else { + Step_Structure.stepModeCnt = 0; + } + } + + if (Step_Structure.stepMode == 1) { + Step_Structure.valueNew = msa_filterWalk(Step_Structure.valueNew); + } else if (Step_Structure.stepMode == 2) { + Step_Structure.valueNew = msa_filterRun(Step_Structure.valueNew); + } + + if (Step_Structure.stepMode != 0) { + USER_Pedometer(); + } + return Step_Structure.step_sum; +} + +static unsigned char isStatic(int val) +{ + if (val < Bright_Structure.accSquareMaxLimit && \ + val > Bright_Structure.accSquareMinLimit) { + return 1; + } + + return 0; +} + +static unsigned char light_off_detect(short int x, short int y, short int z) +{ + if (Bright_Structure.lightOffTimeCnt) { + Bright_Structure.lightOffTimeCnt++; + if (Bright_Structure.lightOffTimeCnt >= 3) { + Bright_Structure.lightOffTimeCnt = 0; + Bright_Structure.lastStatus = 0; + return 2; + } + } + + if (Bright_Structure.lastStatus == 1) { +#ifdef KCT_GSETURE_WAKEUP + + if (isStatic(Bright_Structure.accSquareSum[0]) && \ + (ABS(x) > 110 || y < -80)) { + Bright_Structure.backlightOffCnt = 0; + + if (!Bright_Structure.lightOffTimeCnt) { + Bright_Structure.lightOffTimeCnt = 1; + } + //return 2; + } +#endif + + if (isStatic(Bright_Structure.accSquareSum[0]) && \ + ABS(x) > 162) { + Bright_Structure.backlightOffCnt = 0; + + if (!Bright_Structure.lightOffTimeCnt) { + Bright_Structure.lightOffTimeCnt = 1; + } + } + Bright_Structure.backlightOffCnt++; + + } + + return 0; +} + +static unsigned char isLevel_detect(short int x, short int y, short int z) +{ + if (ABS(x) < 76 && ABS(y) < 76 && z > 200 && z < 281) { + return 1; + } + + return 0; +} + +static int msa_atan(int x, int y) +{ + const int angle[] = {11520, 6801, 3593, 1824, 916, 458, 229, 115, 57, 29, 14, 7, 4, 2, 1}; + + int i = 0; + int x_new, y_new; + int angleSum = 0; + + x *= 1024; + y *= 1024; + + for (i = 0; i < 15; i++) { + if (y > 0) { + x_new = x + (y >> i); + y_new = y - (x >> i); + x = x_new; + y = y_new; + angleSum += angle[i]; + } else { + x_new = x - (y >> i); + y_new = y + (x >> i); + x = x_new; + y = y_new; + angleSum -= angle[i]; + } + } + return angleSum; +} + + + +static unsigned char light_on_detect(short int x, short int y, short int z) +{ +#ifdef KCT_GSETURE_WAKEUP + + if (Bright_Structure.lightOnTimeCnt) { + Bright_Structure.lightOnTimeCnt++; + if (Bright_Structure.lightOnTimeCnt >= 4) { + Bright_Structure.lightOnTimeCnt = 0; + Bright_Structure.lastStatus = 1; + return 1; + } + } + + if (Bright_Structure.autoBrightFromLevelFlag && \ + isStatic(Bright_Structure.accSquareSum[0]) && \ + (ABS(x) < 75 && y > 90 && y < 200 && z > 75) + ) { + Bright_Structure.levelRotationEnableCnt ++; + if (Bright_Structure.levelRotationEnableCnt >= Bright_Structure.levelRotationEnableCntLimit) { + Bright_Structure.levelDisableCnt = 0; + Bright_Structure.levelRotationEnableCnt = 0; + Bright_Structure.autoBrightFromLevelFlag = 0; + Bright_Structure.accSquareSum[1] = Bright_Structure.accSquareSum[0]; + if (!Bright_Structure.lightOnTimeCnt) { + Bright_Structure.lightOnTimeCnt = 1; + } + //return 1; + } + } else { + Bright_Structure.levelRotationEnableCnt = 0; + } + + Bright_Structure.levelDisableCnt++; + + if (Bright_Structure.levelDisableCnt >= Bright_Structure.levelDisableCntLimit) { + Bright_Structure.levelDisableCnt = 0; + Bright_Structure.autoBrightFromLevelFlag = 0; + } +#endif + +#ifdef KCT_GSETURE_WAKEUP + if (isLevel_detect(x, y, z)) { + Bright_Structure.isLevelCnt++; + if (Bright_Structure.isLevelCnt >= Bright_Structure.isLevelCntLimit) { + if (Bright_Structure.notLevelCnt >= 5) { + Bright_Structure.accSquareSum[1] = Bright_Structure.accSquareSum[0]; + Bright_Structure.lastStatus = 1; + Bright_Structure.isLevelCnt = 0; + Bright_Structure.notLevelCnt = 0; + Bright_Structure.lightOnTimeCnt = 1; + //return 1; + } else { + Bright_Structure.isLevelCnt = 0; + Bright_Structure.notLevelCnt = 0; + } + } + } else { + Bright_Structure.notLevelCnt++; + if (Bright_Structure.notLevelCnt > 20) { + Bright_Structure.notLevelCnt = 20; + } + Bright_Structure.isLevelCnt = 0; + } +#endif + + if (!isStatic(Bright_Structure.accSquareSum[0])) { + Bright_Structure.enableCnt = 0; + } + + if (isStatic(Bright_Structure.accSquareSum[0]) && \ + Bright_Structure.accSquareSum[1] > 0 && \ + !isStatic(Bright_Structure.accSquareSum[1])) { + Bright_Structure.autoBrightFlag = 1; + } + + if (Bright_Structure.autoBrightFlag) { + Bright_Structure.disableCnt ++; + } + if (Bright_Structure.disableCnt >= Bright_Structure.disableCntLimit) { + Bright_Structure.disableCnt = 0; + Bright_Structure.autoBrightFlag = 0; + } + + if (Bright_Structure.autoBrightFlag && y > 0 && z > 0 && \ + isStatic(Bright_Structure.accSquareSum[0])) { + Bright_Structure.enableCnt ++; + + if (Bright_Structure.enableCnt >= Bright_Structure.enableCntLimit) { + if (z == 0) { + z = 1 ; + } + Bright_Structure.xzAngel = msa_atan(z, x) / 256; + Bright_Structure.yzAngel = msa_atan(z, y) / 256; + + if (z >= 38) { + if (Bright_Structure.xzAngel > Bright_Structure.xzAngelLimitMin && \ + Bright_Structure.xzAngel < Bright_Structure.xzAngelLimitMax && \ + Bright_Structure.yzAngel > Bright_Structure.yzAngelLimitMin && \ + Bright_Structure.yzAngel < Bright_Structure.yzAngelLimitMax) { + Bright_Structure.enableCnt = 0; + Bright_Structure.disableCnt = 0; + Bright_Structure.autoBrightFlag = 0; + Bright_Structure.accSquareSum[1] = Bright_Structure.accSquareSum[0]; + Bright_Structure.lastStatus = 1; + return 1; + } + } else if (y > 212) { + Bright_Structure.enableCnt = 0; + Bright_Structure.disableCnt = 0; + Bright_Structure.autoBrightFlag = 0; + Bright_Structure.accSquareSum[1] = Bright_Structure.accSquareSum[0]; + Bright_Structure.lastStatus = 1; + return 1; + } + } + } else { + Bright_Structure.enableCnt = 0; + } + return 0; +} + + +/*50毫秒的timer调用一次msa_light,关闭时停止timer。 //msa_app.c , msa310.c + 函数返回值: 1 : 亮屏 2:灭屏 0:无动作 + 使用FIFO数据(数据长度与ODR相关)。 + 例如500MS,10组数据,识别有一次抬手动作,开启亮屏,其他无效。 +*/ +unsigned char msa_light(short int x, short int y, short int z) +{ + unsigned char ret; + Bright_Structure.accSquareSum[0] = x * x + y * y + z * z ; + +#ifdef KCT_GSETURE_WAKEUP + + if (!isLevel_detect(x, y, z) && Bright_Structure.isLevelRotationCnt > 9) { + Bright_Structure.autoBrightFromLevelFlag = 1; + } + +#endif + + ret = light_off_detect(x, y, z); + if (ret) { + return ret; + } + + ret = light_on_detect(x, y, z); + if (ret) { + return ret; + } + +#ifdef KCT_GSETURE_WAKEUP + if (isLevel_detect(x, y, z)) { + Bright_Structure.isLevelRotationCnt++; + if (Bright_Structure.isLevelRotationCnt++ > 20) { + Bright_Structure.isLevelRotationCnt = 20; + } + } else { + if (Bright_Structure.isLevelRotationCnt > 10) { + Bright_Structure.isLevelRotationCnt -= 5; + } else { + Bright_Structure.isLevelRotationCnt = 0; + } + } +#endif + + Bright_Structure.accSquareSum[1] = Bright_Structure.accSquareSum[0]; + return 0; +} + + + +static char m_cnt = 20; +static int sleep_time_cnt = 0; +static int sleep_this_status = -1; +static int sleep_ontable_cnt = 0; +static void sum_Calculate(void) +{ + int i = 0; + int SumX = 0; + int SumY = 0; + int SumZ = 0; + + if (Sleep_Structure.Minute_Cnt > 0) { + Sleep_Structure.SumX_Last = Sleep_Structure.SumX; + Sleep_Structure.SumY_Last = Sleep_Structure.SumY; + Sleep_Structure.SumZ_Last = Sleep_Structure.SumZ; + } + + for (i = 0; i < m_cnt; i++) { + SumX += Sleep_Structure.Acc[0][i]; + SumY += Sleep_Structure.Acc[1][i]; + SumZ += Sleep_Structure.Acc[2][i]; + } + + Sleep_Structure.SumX = SumX; + Sleep_Structure.SumY = SumY; + Sleep_Structure.SumZ = SumZ; +} + +static void isTurn_Judge(void) +{ + int P = 0; + int AvgX = 0; + int AvgY = 0; + int AvgZ = 0; + int Mx = 0; + int My = 0; + int Mz = 0; + int i = 0; + + sum_Calculate(); + + if (Sleep_Structure.Minute_Cnt > 0) { + P = ((Sleep_Structure.SumX - Sleep_Structure.SumX_Last) / m_cnt) * ((Sleep_Structure.SumX - Sleep_Structure.SumX_Last) / m_cnt) + \ + ((Sleep_Structure.SumY - Sleep_Structure.SumY_Last) / m_cnt) * ((Sleep_Structure.SumY - Sleep_Structure.SumY_Last) / m_cnt) + \ + ((Sleep_Structure.SumZ - Sleep_Structure.SumZ_Last) / m_cnt) * ((Sleep_Structure.SumZ - Sleep_Structure.SumZ_Last) / m_cnt); + + AvgX = Sleep_Structure.SumX / m_cnt; + AvgY = Sleep_Structure.SumY / m_cnt; + AvgZ = Sleep_Structure.SumZ / m_cnt; + for (i = 0; i < m_cnt; i++) { + Mx += ABS(Sleep_Structure.Acc[0][i] - AvgX); + My += ABS(Sleep_Structure.Acc[1][i] - AvgY); + Mz += ABS(Sleep_Structure.Acc[2][i] - AvgZ); + } + Mx /= m_cnt; + My /= m_cnt; + Mz /= m_cnt; + } + + if ((P > 7864) && ((Mx > 92) || (My > 92) || (Mz > 92))) { + sleep_time_cnt = 0; + } +} + +static void A_Calculate(void) +{ + int i = 0; + + for (i = 0; i < 4; i++) { + Sleep_Structure.A[i] = Sleep_Structure.A[i + 1]; + } + Sleep_Structure.A[4] = 0; + for (i = 0; i < m_cnt; i++) { + /* if(Sleep_Structure.accSquareSum[i] > 1386741 || \ + Sleep_Structure.accSquareSum[i] < 757596) + */ + if (Sleep_Structure.accSquareSum[i] > 1270000 || \ + Sleep_Structure.accSquareSum[i] < 840000) { + Sleep_Structure.A[4]++; + } + } + Sleep_Structure.A[4] *= 2; +} + +static void sleep_Mode_Calculate(void) +{ + int S = 0; + int P = 92; + int X1 = 6; + int X2 = 24; + int X3 = 100; + int X4 = 22; + int X5 = 4; + + S = (Sleep_Structure.A[0] * X1 + \ + Sleep_Structure.A[1] * X2 + \ + Sleep_Structure.A[2] * X3 + \ + Sleep_Structure.A[3] * X4 + \ + Sleep_Structure.A[4] * X5); + + S *= P; + if (S < 100000) { + sleep_time_cnt ++; + if (sleep_time_cnt > 2) { + sleep_this_status = MSA_RESTLESS; + } + if (sleep_time_cnt >= 15) { + sleep_this_status = MSA_ASLEEP; + } + } else { + sleep_time_cnt = 0; + sleep_this_status = MSA_AWAKE; + } + + if (S == 0) { + sleep_ontable_cnt ++; + if (sleep_ontable_cnt > 30) { + sleep_this_status = MSA_ONTABLE; + } + } else { + sleep_ontable_cnt = 0; + } + +} + +/* +3S采样一次数据给算法msa_sleep,1分钟统计一次数据。 + 开启睡眠检测,7分钟后,每一分中统计一次,7-15分钟浅睡,15分钟以后深睡,否则为清醒,具体参考算法。 + 如果检测到平放,并且超过半个小时,则认为未佩戴 + 函数返回值: -1: 睡眠采样阶段 0:睡眠质量差 1:睡眠质量一般 2:睡眠质量佳 3:未佩戴 +*/ +static int sleep_last_status = MSA_AWAKE; +int msa_sleep(short int x, short int y, short int z) +{ + x *= 4; + y *= 4; + z *= 4; + + Sleep_Structure.accSquareSum[Sleep_Structure.Data_Cnt] = x * x + y * y + z * z; + Sleep_Structure.Acc[0][Sleep_Structure.Data_Cnt] = x; + Sleep_Structure.Acc[1][Sleep_Structure.Data_Cnt] = y; + Sleep_Structure.Acc[2][Sleep_Structure.Data_Cnt] = z; + + if (Sleep_Structure.accSquareSum[Sleep_Structure.Data_Cnt] > 3397386) { + sleep_time_cnt = 0; + sleep_this_status = MSA_AWAKE; + return sleep_this_status; + } + + Sleep_Structure.Data_Cnt++; + + if (Sleep_Structure.Data_Cnt == m_cnt) { + Sleep_Structure.Data_Cnt = 0; + isTurn_Judge(); + A_Calculate(); + Sleep_Structure.Minute_Cnt++; + if (Sleep_Structure.Minute_Cnt >= 1000) { + Sleep_Structure.Minute_Cnt = 0; + } + + if (Sleep_Structure.Minute_Cnt > 4) { + sleep_last_status = sleep_this_status; + sleep_Mode_Calculate(); + if (sleep_last_status != sleep_this_status) { + return sleep_this_status; + } + } + } + return sleep_this_status; +} + + +void sleep_Para_Clear(void) +{ + Sleep_Structure.Sleep_End_Flag = 0; + Sleep_Structure.Data_Cnt = 0; + Sleep_Structure.Minute_Cnt = 0; + memset(Sleep_Structure.accSquareSum, 0, sizeof(Sleep_Structure.accSquareSum)); + memset(Sleep_Structure.A, 0, sizeof(Sleep_Structure.A)); + +} + +/************************ (C) COPYRIGHT MEMSENSING *****END OF FILE****/ +#endif + diff --git a/2.code/2.p11_code/apps/common/device/gSensor/msa31x.c b/2.code/2.p11_code/apps/common/device/gSensor/msa31x.c new file mode 100644 index 0000000..3c8b367 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/msa31x.c @@ -0,0 +1,183 @@ +#include "app_config.h" +#include "gSensor_manage.h" +#include "msa31x.h" + +#if TCFG_MSA31X_EN + +#define ADDR_R ((0x62<<1) | 1) +#define ADDR_W ((0x62<<1) | 0) + +u8 msa_register_read(u8 addr, u8 *data) +{ + return !_gravity_sensor_get_ndata(ADDR_R, addr, data, 1); +} + +u8 msa_register_write(u8 addr, u8 data) +{ + return !gravity_sensor_command(ADDR_W, addr, data); +} + +u8 msa_register_read_continuously(u8 addr, u8 count, u8 *data) +{ + return _gravity_sensor_get_ndata(ADDR_R, addr, data, count); +} + +u8 msa_register_mask_write(u8 addr, u8 mask, u8 data) +{ + u8 res = 0; + u8 tmp_data; + + res = msa_register_read(addr, &tmp_data); + if (res) { + return res; + } + + tmp_data &= ~mask; + tmp_data |= data & mask; + res = msa_register_write(addr, tmp_data); + + return res; +} + + +u8 msa_read_data(s16 *x, s16 *y, s16 *z) +{ + u8 tmp_data[6] = {0}; + + if (msa_register_read_continuously(MSA_REG_ACC_X_LSB, 6, tmp_data) < 6) { + return -1; + } + + *x = ((short)(tmp_data[1] << 8 | tmp_data[0])) >> 4; + *y = ((short)(tmp_data[3] << 8 | tmp_data[2])) >> 4; + *z = ((short)(tmp_data[5] << 8 | tmp_data[4])) >> 4; + + dev_log(" %d %d %d", *x, *y, *z); + + return 0; +} + + +u8 msa31x_check(void) +{ + u8 ret = 0; + u8 data = 0; + + msa_register_read(MSA_REG_WHO_AM_I, &data); + ret = (data == 0x13); + dev_log("id=0x%02x %s !", data, ret ? "ok" : "fail"); + return ret; +} + +u8 msa31x_disable(void) +{ + u8 res = 0; + + res = msa_register_write(MSA_REG_SPI_I2C, 0x24); //soft reset + mdelay(5); + res |= msa_register_write(MSA_REG_POWERMODE_BW, 0xDE); //suspend mode + + return !res; +} + + +u8 msa31x_init(void) +{ + u8 res = 0; + + if (msa31x_check() == 0) { + return -1; + } + + res = msa_register_write(0x00, 0x24); //soft reset + mdelay(5); + + res |= msa_register_write(0x0f, 0x01); //FS[1:0]: 00:+/-2g, 01:+/-4g, 10:+/-8g, 11:+/-16g + res |= msa_register_write(0x10, 0x04); //ODR[3:0]: 0100: 15.63Hz 0101: 31.25Hz 0110: 62.5Hz 0111: 125Hz + res |= msa_register_write(0x11, 0x7e); //0x0a: normal mode 0x7e: low power mode + res |= msa_register_write(0x14, 0x80 | 25); //fifo: stream mode watermark 25 + res |= msa_register_write(0x15, 0x00); //FIFO_DATA_SELECT[1:0]: 00: X+Y+Z 01: X only 10: Y only 11: Z only + res |= msa_register_write(0x17, 0x60); //enable overrun interrupt ?watermark interrupt + res |= msa_register_write(0x1a, 0x06); //overrun interrupt ?watermark interrupt to INT1 + + const u8 reg_addr[] = {0x0f, 0x10, 0x11, 0x14, 0x15, 0x17, 0x1a}; + u8 data = 0; + for (u8 i = 0; i < sizeof(reg_addr); i++) { + msa_register_read(reg_addr[i], &data); + dev_log("reg[0x%02x] = 0x%02x", reg_addr[i], data); + } + + return 0; +} + +void msa_set_fifo_mode(void) +{ + msa_register_write(0x14, 0x00 | 48); //fifo: stream mode watermark 25 + mdelay(5); + msa_register_write(0x14, 0x80 | 48); //fifo: stream mode watermark 25 +} + +s32 msa31x_read_fifo(axis_info_t *sl_accel) +{ + u8 len = 0; + u8 temp_buf[384]; + + msa_register_read(0x0d, &temp_buf[0]); //read fifo status + len = temp_buf[0] & 0x7f; + + dev_log("reg[0x%02x] = 0x%02x len=%d", 0x0d, temp_buf[0], len); + + msa_register_read_continuously(0xff, len * 6, temp_buf); + + for (u8 i = 0; i < len; i++) { + sl_accel[i].x = ((short)(temp_buf[i * 6 + 1] << 8 | temp_buf[i * 6 + 0])) >> 3; //lsb_g = 1024 + sl_accel[i].y = ((short)(temp_buf[i * 6 + 3] << 8 | temp_buf[i * 6 + 2])) >> 3; //lsb_g = 1024 + sl_accel[i].z = ((short)(temp_buf[i * 6 + 5] << 8 | temp_buf[i * 6 + 4])) >> 3; //lsb_g = 1024 + + dev_log(" %d %d %d", sl_accel[i].x, sl_accel[i].y, sl_accel[i].z); + } + + return len; +} + +s32 msa31x_ctl(u8 cmd, void *arg) +{ + char res; + s32 ret = 0; + + switch (cmd) { + case GSENSOR_DISABLE: + res = msa31x_disable(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESET_INT: + res = msa31x_init(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESUME_INT: + break; + case GSENSOR_INT_DET: + break; + case READ_GSENSOR_DATA: + ret = msa31x_read_fifo((axis_info_t *)arg); + break; + case SEARCH_SENSOR: + res = msa31x_check(); + memcpy(arg, &res, 1); + break; + default: + break; + } + return ret; +} + + +REGISTER_GRAVITY_SENSOR(gSensor) = { + .logo = "msa310", + .gravity_sensor_init = msa31x_init, + .gravity_sensor_check = NULL, + .gravity_sensor_ctl = msa31x_ctl, +}; + + +#endif diff --git a/2.code/2.p11_code/apps/common/device/gSensor/stk832x.c b/2.code/2.p11_code/apps/common/device/gSensor/stk832x.c new file mode 100644 index 0000000..2a61ede --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/gSensor/stk832x.c @@ -0,0 +1,160 @@ +#include "app_config.h" +#include "gSensor_manage.h" +#include "includes.h" +#include "iic_api.h" +#include "bank_switch.h" +#include "gpio.h" +#include "stk832x.h" + +/* #pragma bss_seg(".gsport_dev_bss") */ +/* #pragma const_seg(".gsport_dev_const") */ +/* #pragma code_seg(".gsport_dev_code") */ +/* */ + + +#define BANK_NAME BANK_SENSOR_TAG + +#ifdef TCFG_STK832X_EN && TCFG_STK832X_EN + +#define LOG(fmt,...) printf("[stk832x] " fmt "\n",##__VA_ARGS__) + +// #define STKI2C_ADDRESS 0x0F //Pin1 connected to GND +#define STKI2C_ADDRESS 0x1F //Pin1 connected to VDD + +static u8 chip_id = 0; + +static s8 stk832x_register_read(u8 addr, u8 *data, u8 len) +{ + return _gravity_sensor_get_ndata((STKI2C_ADDRESS << 1) | 0x01, addr, data, len); +} + +static s8 stk832x_register_write(u8 addr, u8 data) +{ + return gravity_sensor_command((STKI2C_ADDRESS << 1) | 0x00, addr, data); +} + +static void stk832x_software_reset(void) +{ + stk832x_register_write(0x14, 0xB6); + mdelay(50); +} + +static bool stk832x_check_chip_id(void) +{ + stk832x_software_reset(); + stk832x_register_read(STK_REG_CHIPID, &chip_id, 1); + + if (chip_id == STK8327_CHIPID_VAL || chip_id == STK8329_CHIPID_VAL || chip_id == STK832x_CHIPID_VAL) { + LOG("read stkchip id ok, chip_id = 0x%x\n", chip_id); + return true; + } + LOG("read stkchip id fail, chip_id = 0x%x\n", chip_id); + return false; +} + +static u8 stk832x_suspend_mode(void) +{ + return stk832x_register_write(STK_REG_POWMODE, STK_SUSPEND_MODE); +} + +static void stk832x_correction_hz(void) +{ + u8 temp = 0; + stk832x_register_read(0x45, &temp, 1); + LOG("before 0x45 = %d", temp); + temp += 0x20; + stk832x_register_write(0x45, temp); + mdelay(5); + LOG("after 0x45 = %d", temp); +} + +static void stk832x_set_odr(void) +{ + if (STK832x_CHIPID_VAL == chip_id) { + stk832x_correction_hz(); + stk832x_register_write(0x11, 0x74); //set low-power mode Duration (10ms) + stk832x_register_write(0x3E, 0xC8); //stream mode and store interval 4 (ODR=100 and FIFO ODR=100/4=25Hz) + } else { + stk832x_register_write(0x12, 0x08); // set es mode + stk832x_register_write(0x3E, 0xC0); // stream mode and store interval 1 + stk832x_register_write(0x11, 0x76); //25hz + } +} + +static u8 stk832x_init(void) +{ + if (!stk832x_check_chip_id()) { + LOG("init fail!"); + return -1; + } + + stk832x_software_reset(); + stk832x_register_write(STK832x_REG_RANGESEL, STK832x_RANGE_4G); + stk832x_register_write(0x5E, 0xC0); // eng mode for power saving + stk832x_register_write(0x34, 0x04); // enable watch dog + stk832x_register_write(0x10, 0x0D); // set bandwidth + stk832x_set_odr(); + return 0; +} + + +static int stk832x_read_fifo(axis_info_t *accel) +{ + u8 point = 0; + s8 value[6]; + + stk832x_register_read(0x0C, &point, 1); + point &= 0x1f; + + for (u8 i = 0; i < point; i++) { + stk832x_register_read(0x3F, value, 6); + accel[i].x = (short int)((((int)((char)value[1])) << 8) | (value[0] & 0xF0)) >> 3; //1024 lbs/g + accel[i].y = (short int)((((int)((char)value[3])) << 8) | (value[2] & 0xF0)) >> 3; //1024 lbs/g + accel[i].z = (short int)((((int)((char)value[5])) << 8) | (value[4] & 0xF0)) >> 3; //1024 lbs/g + LOG("xyz:%d,%d,%d", accel[i].x, accel[i].y, accel[i].z); + } + return point; +} + + + +static s32 stk832x_ctl(u8 cmd, void *arg) +{ + s8 res; + s32 ret = 0; + LOG("cmd=%d", cmd); + switch (cmd) { + case GSENSOR_DISABLE: + res = stk832x_suspend_mode(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESET_INT: + res = stk832x_init(); + memcpy(arg, &res, 1); + break; + case GSENSOR_RESUME_INT: + break; + case GSENSOR_INT_DET: + break; + case READ_GSENSOR_DATA: + ret = stk832x_read_fifo((axis_info_t *)arg); + break; + case SEARCH_SENSOR: + res = stk832x_check_chip_id(); + memcpy(arg, &res, 1); + break; + default: + break; + } + return ret; +} + + +REGISTER_GRAVITY_SENSOR(gSensor) = { + .logo = "stk832x", + .gravity_sensor_init = stk832x_init, + .gravity_sensor_check = NULL, + .gravity_sensor_ctl = stk832x_ctl, +}; + +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hrSensor_manage.c b/2.code/2.p11_code/apps/common/device/hr_sensor/hrSensor_manage.c new file mode 100644 index 0000000..6e394c6 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hrSensor_manage.c @@ -0,0 +1,240 @@ +#include "hrSensor_manage.h" +/* #include "hrs3300.h" */ +#include "iic_api.h" +#include "gpio.h" +#include "iic_soft.h" +#include "bank_switch.h" +#include "sensor_api.h" +#include "msg.h" + + +/* #pragma bss_seg(".sport_dev_bss") */ +/* #pragma const_seg(".sport_dev_const") */ +/* #pragma code_seg(".sport_dev_code") */ +/* */ + + +#define BANK_NAME BANK_SENSOR_TAG + +static const struct hrsensor_platform_data *platform_data; +HR_SENSOR_INTERFACE *hrSensor_hdl = NULL; +HR_SENSOR_INFO __hrsensor_info = {.iic_delay = 0}; +#define hrSensor_info (&__hrsensor_info) + + +#define t_printf printf + +/* OS_MUTEX SENSOR_IIC_MUTEX; */ +/* spinlock_t sensor_iic; */ +#if TCFG_HR_SENSOR_USE_IIC_TYPE +#define iic_init(iic) hw_iic_init() +#define iic_uninit(iic) hw_iic_close() +#define iic_start(iic) hw_iic_start() +#define iic_stop(iic) hw_iic_stop() +#define iic_tx_byte(iic, byte) hw_iic_master_tx_byte(byte) +#define iic_rx_byte(iic, ack) hw_iic_master_rx_byte(ack) +#define iic_read_buf(iic, buf, len) hw_iic_master_read_buf(buf, len) +#define iic_write_buf(iic, buf, len) hw_iic_master_write_buf(buf, len) +/* #define iic_suspend(iic) hw_iic_suspend(iic) */ +/* #define iic_resume(iic) hw_iic_resume(iic) */ +#else +#define iic_init(iic) soft_iic_init(iic) +#define iic_uninit(iic) soft_iic_uninit(iic) +#define iic_start(iic) soft_iic_start(iic) +#define iic_stop(iic) soft_iic_stop(iic) +#define iic_tx_byte(iic, byte) soft_iic_tx_byte(iic, byte) +#define iic_rx_byte(iic, ack) soft_iic_rx_byte(iic, ack) +#define iic_read_buf(iic, buf, len) soft_iic_read_buf(iic, buf, len) +#define iic_write_buf(iic, buf, len) soft_iic_write_buf(iic, buf, len) +/* #define iic_suspend(iic) soft_iic_suspend(iic) */ +/* #define iic_resume(iic) soft_iic_resume(iic) */ +#endif + +extern void delay(u32 cnt);//fm +u8 hrsensor_write_nbyte(u8 w_chip_id, u8 register_address, u8 *buf, u8 data_len) +{ + /* printf("%s %d",__func__,__LINE__); */ + /* putchar('('); */ + + u8 write_len = 0; + u8 i; + + iic_start(hrSensor_info->iic_hdl); + delay(hrSensor_info->iic_delay); + if (0 == iic_tx_byte(hrSensor_info->iic_hdl, w_chip_id)) { + write_len = 0; + t_printf("\n hrSensor iic w err 0\n"); + goto __wend; + } + + delay(hrSensor_info->iic_delay); + + if (0 == iic_tx_byte(hrSensor_info->iic_hdl, register_address)) { + write_len = 0; + t_printf("\n hrSensor iic w err 1\n"); + goto __wend; + } + + for (i = 0; i < data_len; i++) { + delay(hrSensor_info->iic_delay); + if (0 == iic_tx_byte(hrSensor_info->iic_hdl, buf[i])) { + write_len = 0; + t_printf("\n hrSensor iic w err 2\n"); + goto __wend; + } + write_len++; + } + delay(hrSensor_info->iic_delay); +__wend: + iic_stop(hrSensor_info->iic_hdl); + /* putchar(')'); */ + return write_len; +} + +u8 hrsensor_read_nbyte(u8 r_chip_id, u8 register_address, u8 *buf, u8 data_len) +{ + /* printf("%s %d",__func__,__LINE__); */ + u8 read_len = 0; + /* putchar('<'); */ + + iic_start(hrSensor_info->iic_hdl); + delay(hrSensor_info->iic_delay); + if (0 == iic_tx_byte(hrSensor_info->iic_hdl, r_chip_id - 1)) { + t_printf("\n hrSensor iic r err 0\n"); + read_len = 0; + goto __rend; + } + delay(hrSensor_info->iic_delay); + + if (0 == iic_tx_byte(hrSensor_info->iic_hdl, register_address)) { + t_printf("\n hrSensor iic r err 1\n"); + read_len = 0; + goto __rend; + } + delay(hrSensor_info->iic_delay); + iic_start(hrSensor_info->iic_hdl); + if (0 == iic_tx_byte(hrSensor_info->iic_hdl, r_chip_id)) { + t_printf("\n hrSensor iic r err 2\n"); + read_len = 0; + goto __rend; + } + + for (; data_len > 1; data_len--) { + delay(hrSensor_info->iic_delay); + *buf++ = iic_rx_byte(hrSensor_info->iic_hdl, 1); + read_len ++; + } + *buf = iic_rx_byte(hrSensor_info->iic_hdl, 0); + read_len ++; + delay(hrSensor_info->iic_delay); + +__rend: + iic_stop(hrSensor_info->iic_hdl); + /* putchar('>'); */ + return read_len; +} + + +REGISTER_CODE_SEG(BANK_CODE_SENSOR_NORMAL_BANK_1) +int hr_sensor_io_ctl(u8 cmd, void *arg) +{ + /* printf("%s %d",__func__,__LINE__); */ + if (!hrSensor_hdl) { + return 0; + } + return hrSensor_hdl->heart_rate_sensor_ctl(cmd, arg); +} + +void hr_sensor_input_accel_data(void *data, u8 point) +{ + /* printf("%s %d",__func__,__LINE__); */ + if (!hrSensor_hdl) { + return; + } + hrSensor_hdl->accel_data_input(data, point); +} + + +REGISTER_CODE_SEG(BANK_CODE_SENSOR_INIT_BANK_0) +int hr_sensor_init(void *_data, cbuffer_t *hrcbuf, cbuffer_t *spo2cbuf) +{ + /* printf("%s %d\n",__func__,__LINE__); */ + HR_SENSOR_INTERFACE *hd = NULL; + int retval = 0; + if (_data == NULL) { + t_printf("hr init fail(no _data)\n"); + return false; + } + platform_data = (const struct hrsensor_platform_data *)_data; + hrSensor_info->iic_hdl = platform_data->iic; + retval = iic_init(hrSensor_info->iic_hdl); + if (retval < 0) { + t_printf("\n open iic for hrSensor err\n"); + return retval; + } else { + t_printf("\n iic open succ\n"); + } + + retval = -EINVAL; + list_for_each_hrsensor(hd) { + t_printf("%s==%s", hd->logo, platform_data->hrSensor_name); + if (!memcmp(hd->logo, platform_data->hrSensor_name, strlen(platform_data->hrSensor_name))) { + retval = 0; + break; + } + } + + if (retval < 0) { + t_printf(">>>hrSensor_hdl logo err\n"); + return retval; + } + + if (hd->heart_rate_sensor_init(hrcbuf, spo2cbuf)) { + t_printf(">>>>hrSensor_Init SUCC"); + hrSensor_hdl = hd; + hrSensor_info->init_flag = 1; + /* if (platform_data->hrSensor_int_io != -1) {//sdk init */ + /* } */ + + } else { + t_printf(">>>>hrSensor_Init ERROR"); + } + + return 0; +} + +void hr_sensor_req_irq(void) +{ + //printf("%s", __func__); + sensorhub_irq_add(IRQ_HRSENSOR_INDEX); + user_main_post_to_p11_system(P11_SYS_KICK, 0); +} + +/***********************hrs3603 hr test********************/ +#if 0 +int temp_data[100]; +void hrs3603_hr_test() +{ +//hr + hr_sensor_io_ctl(HR_SENSOR_ENABLE, NULL); + mdelay(100); + while (1) { + hr_sensor_io_ctl(HR_SENSOR_READ_DATA, temp_data); + for (u8 i = 0; i < 3 * 25; i++) { + t_printf("hr: %d ", temp_data[i]); + if (i % 6 == 0) { + putchar('\n'); + } + } + delay(10000); + } + /* hr_sensor_io_ctl(HR_SENSOR_DISABLE, NULL); */ + /* delay(10000); */ + +//spo2 + /* hr_sensor_io_ctl(SPO2_SENSOR_ENABLE, NULL); */ + /* delay(100); */ + /* hr_sensor_io_ctl(SPO2_SENSOR_READ_DATA, temp_data); */ + /* for(u8 i=0;i<4*25;i++)t_printf("hr: %d ",temp_data[i]); */ +} +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hrs3603.c b/2.code/2.p11_code/apps/common/device/hr_sensor/hrs3603.c new file mode 100644 index 0000000..66ad173 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hrs3603.c @@ -0,0 +1,837 @@ +#include "app_config.h" +#include "includes.h" +#include "gpio.h" +#include "hrs3603.h" +#include "hrSensor_manage.h" +#include "iic_api.h" +#include "sensor_gp_timer.h" +#include "timer.h" +#include "sensor_api.h" +#include "msg.h" +#include "bank_switch.h" +#include "sensor_api.h" + +/* #pragma bss_seg(".sport_dev_bss") */ +/* #pragma const_seg(".sport_dev_const") */ +/* #pragma code_seg(".sport_dev_code") */ +/* */ + +#if defined(TCFG_HRS3603_DEV_ENABLE) && TCFG_HRS3603_DEV_ENABLE + + +#define BANK_NAME BANK_SENSOR_TAG + + +#define log_i(...) + +//hr3 通道 spo2 4通道,buf 复用25 hz +#define HR_SPO2_DATALEN ((25+5)*4)//需与大于单次传入算法的数据量 + +static u8 mode = 0; +static u8 timer_start = 0; +static u8 sensor_online = 0; +static cbuffer_t *data_w_cbuf[2]; +static u32 hrdata[HR_SPO2_DATALEN]; + + +void hrs3603_timers_start()//定时器轮询模式:开始血氧采集(初始化成功后调用) +{ + timer_start = 1; +} + +void hrs3603_timers_stop()//定时器轮询模式:开始血氧采集(初始化成功后调用) +{ + timer_start = 0; +} + +/****************************iic*****************************/ +bool Hrs3603_write_reg(u8 addr, u8 data) +{ + // 根据不同平台实现i2c, sucess: return 0; fail: retrun 1; + if (hrsensor_write_nbyte(HX3603_WADDR, addr, &data, 1) == 1) { + return 0; + } else { + return 1; + } +} +u8 Hrs3603_read_reg(u8 register_addr) +{ + uint8_t data_buf = 0; + + if (hrsensor_read_nbyte(HX3603_RADDR, register_addr, &data_buf, 1)) { + return data_buf; + } else { + return 0; + } +} + +/****************************hx3603*****************************/ +bool Hrs3603_chip_check_id() +{ + int i = 0 ; + uint8_t chip_id = 0; + + chip_id = Hrs3603_read_reg(0x00) ; + log_i("--hrs3603 id!0x%x\n", chip_id); + if (chip_id != 0x23) { + log_i("--------read hx3603 id error!"); + return false; + } + log_i("--------read hx3603 id ok!"); + + return true; +} + +void Hrs3603_chip_disable(void) +{ + /* printf("%s\n",__func__); */ + Hrs3603_write_reg(0x01, 0x01); + Hrs3603_write_reg(0x02, 0x01); + mdelay(50); + Hrs3603_write_reg(0x1a, 0x13); + mdelay(50); +} + +void hrs3603_disable(void)//关闭定时器 +{ + /* printf("%s",__func__); */ + hrs3603_timers_stop();//关闭定时器 + Hrs3603_chip_disable(); // 此时功耗在 1ua 以下 +} +void hrs3603_hr_enable(void) //从低功耗恢复 +{ + /* printf("%s\n",__func__); */ + mode = 0; + Hrs3603_chip_disable(); // 此时功耗在 1ua 以下 + Hrs3603_hr_alg_config();//重置寄存器 + hrs3603_timers_start();//开定时器 +} +void hrs3603_spo2_enable(void) +{ + /* printf("%s\n",__func__); */ + mode = 1; + Hrs3603_chip_disable(); // 此时功耗在 1ua 以下 + Hrs3603_spo2_alg_config(); + hrs3603_timers_start(); +} + + +REGISTER_CODE_SEG(BANK_CODE_SENSOR_INIT_BANK_0) +u8 hx3603_init(cbuffer_t *hrcbuf, cbuffer_t *spo2cbuf) +{ + /* printf("%s",__func__); */ + mdelay(40);//芯片上电请延时5ms + + if (!hrcbuf || !spo2cbuf) { + ASSERT(0); + } + data_w_cbuf[0] = hrcbuf; + data_w_cbuf[1] = spo2cbuf; + + cbuf_init(data_w_cbuf[0], hrdata, sizeof(hrdata)); + cbuf_init(data_w_cbuf[1], hrdata, sizeof(hrdata)); + + if (Hrs3603_chip_check_id()) { + /* hx3603_timer_init(); */ + log_i("%s1", __func__); + //hrs3603_spo2_enable(); + /* Hrs3603_hr_alg_config(); */ + hrs3603_timers_stop(); + /* hrs3603_disable();//先关灯; */ + // + // + sensor_online = 1; + return 1; + } + log_i("%s2", __func__); + return 0; +} +int hrs3603_alg_send_data_test(u32 als_raw_data, u32 infrared_data) +{ + /* printf("%s %d %d \n",__func__,als_raw_data,infrared_data); */ + static u8 send_data = 0x04; + static u8 hx_close = 0, hx_open = 0; + u8 wcnt = 0; + if (infrared_data > 30000) { + hx_open++; + if (hx_open == 2) { + hx_open--; + if ((als_raw_data > 450000) || (hx_close == 2)) { + send_data += 2; + if (send_data > 0x7a) { + send_data = 0x7a; + return true; + } + if (send_data == 0x06) { + /* printf("\n%s1\n",__func__); */ + wcnt += Hrs3603_write_reg(0x0d, 0x63); + wcnt += Hrs3603_write_reg(0x06, 0x0a); + wcnt += Hrs3603_write_reg(0x0b, 0x73); + wcnt += Hrs3603_write_reg(0x03, 0x0f); + } else { + wcnt += Hrs3603_write_reg(0x06, send_data); + } + } else if (als_raw_data < 200000) { + send_data -= 2; + if (send_data < 0x06) { + send_data = 0x06; + return true; + } + wcnt += Hrs3603_write_reg(0x06, send_data); + } + hx_close = 0; + } + } else { + hx_close++; + if (hx_close == 2) { + hx_open = 0; + send_data = 0x04; + /* printf("\n%s2 %d\n",__func__,infrared_data); */ + wcnt += Hrs3603_write_reg(0x03, 0x07); + } else if (hx_close == 3) { + hx_close--; + } + } + if (wcnt) { + return false; + } else { + return true; + } +} +hrs3603_spo2_msg_code_t hx3603_state = MSG_SPO2_ALG_NOT_OPEN; +int hrs3603_spo2_agc_test(u32 red_new_raw_data, u32 als_in_red_raw_data, u32 ir_new_raw_data, u32 als_in_ir_raw_data) +{ + static u8 red_on_state = 2, ir_on_state = 2; //默认刚开机 + static s16 red06_data = 0; + static s16 ir05_data = 0; + u8 wcnt = 0; + //先加减 + if (red_new_raw_data >= 450000) { + red06_data++; + if (red_on_state == 2) { + red_on_state = 1; + red06_data = 0x1f; + } + Hrs3603_read_reg(0x0d); + if (red06_data <= 0x7f) { + wcnt += Hrs3603_write_reg(0x06, red06_data); + } else { + red06_data = 0x7f; + } + } else if (red_new_raw_data <= 250000) { + red06_data--; + if (red_on_state == 2) { + red_on_state = 1; + red06_data = 0x1d; + } + Hrs3603_read_reg(0x0d); + if (red06_data >= 0x00) { + wcnt += Hrs3603_write_reg(0x06, red06_data); + } else { + red06_data = 0x00; + } + } + if (ir_new_raw_data >= 450000) { + ir05_data++; + if (ir_on_state == 2) { + ir_on_state = 1; + ir05_data = 0x1f; + } + Hrs3603_read_reg(0x0d); + if (ir05_data <= 0x7f) { + wcnt += Hrs3603_write_reg(0x05, ir05_data); + } else { + ir05_data = 0x7f; + } + } else if (ir_new_raw_data <= 250000) { + ir05_data--; + if (ir_on_state == 2) { + ir_on_state = 1; + ir05_data = 0x1d; + } + Hrs3603_read_reg(0x0d); + if (ir05_data >= 0x00) { + wcnt += Hrs3603_write_reg(0x05, ir05_data); + } else { + ir05_data = 0x00; + } + } + if (hx3603_state == MSG_SPO2_ALG_NOT_OPEN) { + hx3603_state = MSG_SPO2_PPG_LEN_TOO_SHORT; //3 + } + //开关机 + if (ir_new_raw_data - als_in_ir_raw_data < 100000) { //关机 + if (ir_on_state) { + wcnt += Hrs3603_write_reg(0x03, 0x07); + wcnt += Hrs3603_write_reg(0x05, 0x00); + wcnt += Hrs3603_write_reg(0x06, 0x00); + ir_on_state = 0; + red_on_state = 0; + red06_data = 0x00; + ir05_data = 0x00; + hx3603_state = MSG_SPO2_NO_TOUCH; //2 + } + } else { + if (ir_on_state == 0) { + wcnt += Hrs3603_write_reg(0x03, 0x0f); + ir_on_state = 2; //刚开机 + red_on_state = 2; //刚开机 + hx3603_state = MSG_SPO2_ALG_NOT_OPEN; //1 + } + } + if (wcnt) { + return false; + } else { + return true; + } +} + + + +/**********************数据处理*****************************/ + +bool Hrs3603_brust_read_reg(uint8_t register_addr, uint8_t *buf, uint8_t length) +{ + if (hrsensor_read_nbyte(HX3603_RADDR, register_addr, buf, length)) { + return true; + } else { + printf("\n%s\n", __func__); + return false; + } +} +bool Hrs3603_read_hrs(u32 *hrm_data, u32 *als_data) +{ +// log_i("%s",__func__); + uint8_t databuf[6] = {0}; + int32_t P0 = 0, P1 = 0; + + if (Hrs3603_brust_read_reg(0xa0, databuf, 6) == false) { + printf("\n%s\n", __func__); + return false; + } + + P0 = ((databuf[0]) | (databuf[1] << 8) | (databuf[2] << 16)); + P1 = ((databuf[3]) | (databuf[4] << 8) | (databuf[5] << 16)); + + if (P0 > P1) { + *hrm_data = P0 - P1; + } else { + *hrm_data = 0; + } + *als_data = P0; + + return true; +} +bool Hrs3603_read_ps1(u32 *infrared_data) +{ +// log_i("%s",__func__); + uint8_t databuf[6] = {0}; + int32_t P0 = 0, P1 = 0; + if (Hrs3603_brust_read_reg(0xa6, databuf, 6) == false) { + printf("\n%s\n", __func__); + return false; + } + P0 = ((databuf[0]) | (databuf[1] << 8) | (databuf[2] << 16)); + P1 = ((databuf[3]) | (databuf[4] << 8) | (databuf[5] << 16)); + if (P0 > P1) { + *infrared_data = P0 - P1; + } else { + *infrared_data = 0; + } + return true; +} +u8 Hrs3603_read_red_phase(u32 *red_raw_data, u32 *als_inred_data) +{ +// log_i("%s",__func__); + uint8_t databuf[6] = {0}; + u32 P0 = 0, P1 = 0; + if (Hrs3603_brust_read_reg(0xa0, databuf, 6) == false) { + printf("\n%s\n", __func__); + return false; + } + + P0 = ((databuf[0]) | (databuf[1] << 8) | (databuf[2] << 16)); + P1 = ((databuf[3]) | (databuf[4] << 8) | (databuf[5] << 16)); + + *red_raw_data = P0; + *als_inred_data = P1; + if ((P0 > 0x7FFFF) | (P1 > 0x7FFFF)) { + printf("P0=%d,%d %d %d", P0, databuf[0], databuf[1], databuf[2]); + printf("P1=%d,%d %d %d", P0, databuf[3], databuf[4], databuf[5]); + } + return true; +} + +u8 Hrs3603_read_ir_phase(u32 *ir_raw_data, u32 *als_inir_data) +{ +// log_i("%s",__func__); + uint8_t databuf[6] = {0}; + u32 P0 = 0, P1 = 0; + if (Hrs3603_brust_read_reg(0xa6, databuf, 6) == false) { + printf("\n%s\n", __func__); + return false; + } + P0 = ((databuf[0]) | (databuf[1] << 8) | (databuf[2] << 16)); + P1 = ((databuf[3]) | (databuf[4] << 8) | (databuf[5] << 16)); + + *ir_raw_data = P0; + *als_inir_data = P1; + if ((P0 > 0x7FFFF) | (P1 > 0x7FFFF)) { + printf("P0=%d,%d %d %d", P0, databuf[0], databuf[1], databuf[2]); + printf("P1=%d,%d %d %d", P0, databuf[3], databuf[4], databuf[5]); + } + + return true; +} + +void Hrs3603_hr_alg_config(void) +{ + /* printf("%s\n",__func__); */ + uint16_t sample_rate = 25; /*config the data rate of chip frog3,uint is Hz,GREEN-25,IR-800*/ + uint32_t prf_clk_num = 32000 / sample_rate; /*period in clk num, num=Fclk/fs*/ + uint16_t ps1_interval_i2c = 25; /*PS1 PRF间隔0-255* 0x1c, 25 mean 1s */ + /*********phase enable********/ + uint8_t hrs_enable = 1; /*heart rhythm society enable,1:enable 0:disable*/ + uint8_t ps0_enable = 0; /*ALS enable, 1:enable 0:disable*/ + uint8_t ps1_enable = 1; /*proximity sensor enable, 1:enable 0:disable*/ + uint8_t ts_enable = 0; + /********osr config********/ + uint16_t hrs_ps0_ts_osr = 3; /*TS/PS0/HRS OSR: 0:128 1:256 2:512 3:1023*/ + uint16_t ps1_osr = 3; /*PS1 OSR: 0:128 1:256 2:512 3:1023*/ + /***********cap *********/ + uint8_t hrs_ps0_ts_int_cap = 15; /*INTCAPSEL HRS/TS/PS0 0000 3.125pF, 1111 50pF liner*/ + uint8_t ps1_int_cap = 15; /*INTCAPSEL PS1 0000 3.125pF, 1111 50pF liner*/ + + /***********led open enable***********/ + uint8_t hrs_led_en = 1; /*PS0/HRS LED 1:enable 0:disable */ + uint8_t ps1_led_en = 1; /*PS1 LED 1:enable 0:disable */ + + uint8_t hrs_ckafe_en = 1; /*CKAFEINT 1:enable 0:disable */ + uint8_t ps1_ckafe_en = 1; + + uint8_t dccancel_hrs_idac = 0; /*offset DCCANCEL HRS/TS/PS0*/ + uint8_t dccancel_ps1_idac = 0; /*offset DCCANCEL PS1*/ + + uint8_t hrs_leddr_msb = 3; /* 0~7 , 1= 25ma , step = 25ma*/ + uint8_t ps1_leddr_msb = 7; /* 0~7 , 1= 25ma , step = 25ma*/ + uint8_t leddr_lsb = 7; /* 0~7 , 1= 3.125ma , step = 3.125ma*/ + + /**********led drive selsct**********/ + uint8_t force_ledsel_sel = 0; /*force_ledsel_sel 0:hrs 1:ps1*/ + uint8_t ledsel_ps1 = 2; /*LDR SEL 001:LDR0(green) 010:LDR1(IR) 100:LDR2(RED)*/ + uint8_t ledsel_hrs = 1; /*LDR SEL 001:LDR0(green) 010:LDR1(IR) 100:LDR2(RED)*/ + /***************************/ +// uint8_t pd_drive_sel=1; /*force_pddrive_sel*/ +// uint8_t pd_drive_ps1=1; + + uint8_t rfsel_hrs = 6; /* 0~7 , 0=10K, 1=20k, 2=40k, 3=80k, 4=160k, 5=320k, 6=640k, 7=1280K*/ + uint8_t rfsel_ps1 = 1; /* 0~7 , 0=10K, 1=20k, 2=40k, 3=80k, 4=160k, 5=320k, 6=640k, 7=1280K*/ + + uint8_t hrs_ckafe_cycle = 50; /*hrs ledontime, 0~255, led on time = 4*hrs_ckafe_cycle*0.382us */ + uint8_t ps1_ckafe_cycle = 50; /*ps ledontime, 0~255, led on time = 4*hrs_ckafe_cycle*0.382us */ + + /********tia or cap mode*******/ + uint8_t tia_hrs_en = 1; /*tia_hrs_en*/ + uint8_t tia_ps1_en = 1; /*tia_ps1_en*/ + /**********pd config*********/ + uint8_t ext_pd_sel = 1; /*EXT_PD_DSEL 1 VIP_EXT to PD negative pin; 0 VIN_ECT to PD negative pin*/ + uint8_t extpd_ps1_en = 1; /*extpd_ps1_en*/ + uint8_t extpd_hrs_en = 1; /*extpd_hrs_en*/ + + uint8_t reset_cycle = 5; /*3bit reset_cycle_sel (2^(reset_cycle+1))-1*/ + +// uint8_t en2rst_delay=128; /*6bit en2rst_delay*/ + + /************self test mode***********/ + uint8_t selftest_adc_afe = 0; /*self-test for AFE+ADC*/ + uint8_t selftest_adc = 0; /*self-test for ADC*/ + + uint8_t adc_data_clk_pol = 3; /*adc_data_clk_pol 1:neg 0:pos */ + + Hrs3603_write_reg(0x1e, 0x00); + + Hrs3603_write_reg(0x10, (uint8_t)(prf_clk_num & 0xff)); + Hrs3603_write_reg(0x11, (uint8_t)((prf_clk_num & 0x0f00) >> 8)); + + Hrs3603_write_reg(0x01, (ts_enable << 4) | (ps0_enable << 3) | (hrs_enable << 2) | hrs_ps0_ts_osr); + Hrs3603_write_reg(0x02, (ps1_enable << 2) | ps1_osr); + Hrs3603_write_reg(0x03, (hrs_led_en << 3) | (ps1_led_en << 2) | (hrs_ckafe_en << 1) | ps1_ckafe_en); + Hrs3603_write_reg(0x04, reset_cycle); + Hrs3603_write_reg(0x08, hrs_ckafe_cycle); + Hrs3603_write_reg(0x09, ps1_ckafe_cycle); + Hrs3603_write_reg(0x1c, ps1_interval_i2c); + Hrs3603_write_reg(0x05, dccancel_ps1_idac); + Hrs3603_write_reg(0x06, dccancel_hrs_idac); + Hrs3603_write_reg(0x07, (ledsel_ps1 << 4) | (force_ledsel_sel << 3) | ledsel_hrs); + Hrs3603_write_reg(0x0a, (ps1_int_cap << 4) | hrs_ps0_ts_int_cap); + + //Hrs3603_write_reg(0x0b,(pd_drive_sel<<3)|(pd_drive_ps1<<4)|((led_drive&0x38)>>3)); + Hrs3603_write_reg(0x0b, ((ps1_leddr_msb << 4) | hrs_leddr_msb) & 0x77); + + Hrs3603_write_reg(0xc4, (ext_pd_sel << 7) | ((leddr_lsb & 0x07) << 4) | 0x0f); + Hrs3603_write_reg(0x0d, (rfsel_hrs << 4) | (rfsel_ps1)); + Hrs3603_write_reg(0x0c, rfsel_ps1); + Hrs3603_write_reg(0x0f, 0x00); + Hrs3603_write_reg(0x0e, (extpd_ps1_en << 3) | (extpd_hrs_en << 2) | (tia_ps1_en << 1) | tia_hrs_en); + Hrs3603_write_reg(0x1b, 0x7f); + Hrs3603_write_reg(0xc2, 0x10 | (selftest_adc_afe << 7) | (selftest_adc << 6)); // test mode + Hrs3603_write_reg(0xc3, 0xff); + Hrs3603_write_reg(0x18, adc_data_clk_pol); + Hrs3603_write_reg(0x1a, 0x12); + Hrs3603_write_reg(0x13, 0x02); //enable hrs int + Hrs3603_write_reg(0x12, 0x50); // + Hrs3603_write_reg(0x20, 0x20); //close fifo int +} +void Hrs3603_spo2_alg_config(void) +{ + /* printf("%s\n",__func__); */ +// log_i("%s",__func__); + uint16_t sample_rate = 25; /*config the data rate of chip frog3,uint is Hz,GREEN-25,IR-800*/ + uint32_t prf_clk_num = 32000 / sample_rate; /*period in clk num, num=Fclk/fs*/ + uint16_t ps1_interval_i2c = 0; /*PS1 PRF间隔0-255* 0x1c, 25 mean 1s */ + + /*********phase enable********/ + uint8_t hrs_enable = 1; /*heart rhythm society enable,1:enable 0:disable*/ + uint8_t ps0_enable = 0; /*ALS enable, 1:enable 0:disable*/ + uint8_t ps1_enable = 1; /*proximity sensor enable, 1:enable 0:disable*/ + uint8_t ts_enable = 0; + /********osr config********/ + uint16_t hrs_ps0_ts_osr = 3; /*TS/PS0/HRS OSR: 0:128 1:256 2:512 3:1023*/ + uint16_t ps1_osr = 3; /*PS1 OSR: 0:128 1:256 2:512 3:1023*/ + /***********cap *********/ + uint8_t hrs_ps0_ts_int_cap = 15; /*INTCAPSEL HRS/TS/PS0 0000 3.125pF, 1111 50pF liner*/ + uint8_t ps1_int_cap = 15; /*INTCAPSEL PS1 0000 3.125pF, 1111 50pF liner*/ + + /***********led open enable***********/ + uint8_t hrs_led_en = 1; /*PS0/HRS LED 1:enable 0:disable */ + uint8_t ps1_led_en = 1; /*PS1 LED 1:enable 0:disable */ + + uint8_t hrs_ckafe_en = 1; /*CKAFEINT 1:enable 0:disable */ + uint8_t ps1_ckafe_en = 1; + + uint8_t dccancel_hrs_idac = 0; /*offset DCCANCEL HRS/TS/PS0*/ + uint8_t dccancel_ps1_idac = 0; /*offset DCCANCEL PS1*/ + + uint8_t hrs_leddr_msb = 6; /* 0~7 , 1= 25ma , step = 25ma*/ + uint8_t ps1_leddr_msb = 6; /* 0~7 , 1= 25ma , step = 25ma*/ + uint8_t leddr_lsb = 7; /* 0~7 , 1= 3.125ma , step = 3.125ma*/ + + /**********led drive selsct**********/ + uint8_t force_ledsel_sel = 0; /*force_ledsel_sel 0:hrs 1:ps1*/ + uint8_t ledsel_ps1 = 2; /*LDR SEL 001:LDR0(green) 010:LDR1(red) 100:LDR2(IR)*/ + uint8_t ledsel_hrs = 4; /*LDR SEL 001:LDR0(green) 010:LDR1(red) 100:LDR2(IR)*/ + /***************************/ +// uint8_t pd_drive_sel=1; /*force_pddrive_sel*/ +// uint8_t pd_drive_ps1=1; + + uint8_t rfsel_hrs = 7; /* 0~7 , 0=10K, 1=20k, 2=40k, 3=80k, 4=160k, 5=320k, 6=640k, 7=1280K*/ + uint8_t rfsel_ps1 = 7; /* 0~7 , 0=10K, 1=20k, 2=40k, 3=80k, 4=160k, 5=320k, 6=640k, 7=1280K*/ + + uint8_t hrs_ckafe_cycle = 255; /*hrs ledontime, 0~255, led on time = 4*hrs_ckafe_cycle*0.382us */ + uint8_t ps1_ckafe_cycle = 255; /*ps ledontime, 0~255, led on time = 4*hrs_ckafe_cycle*0.382us */ + + /********tia or cap mode*******/ + uint8_t tia_hrs_en = 1; /*tia_hrs_en*/ + uint8_t tia_ps1_en = 1; /*tia_ps1_en*/ + /**********pd config*********/ + uint8_t ext_pd_sel = 1; /*EXT_PD_DSEL 1 VIP_EXT to PD negative pin; 0 VIN_ECT to PD negative pin*/ + uint8_t extpd_ps1_en = 1; /*extpd_ps1_en*/ + uint8_t extpd_hrs_en = 1; /*extpd_hrs_en*/ + + uint8_t reset_cycle = 7; /*3bit reset_cycle_sel (2^(reset_cycle+1))-1*/ + +// uint8_t en2rst_delay=128; /*6bit en2rst_delay*/ + + /************self test mode***********/ + uint8_t selftest_adc_afe = 0; /*self-test for AFE+ADC*/ + uint8_t selftest_adc = 0; /*self-test for ADC*/ + + uint8_t adc_data_clk_pol = 3; /*adc_data_clk_pol 1:neg 0:pos */ + Hrs3603_write_reg(0x1e, 0x00); + Hrs3603_write_reg(0x10, (uint8_t)(prf_clk_num & 0xff)); + Hrs3603_write_reg(0x11, (uint8_t)((prf_clk_num & 0x0f00) >> 8)); + Hrs3603_write_reg(0x01, (ts_enable << 4) | (ps0_enable << 3) | (hrs_enable << 2) | hrs_ps0_ts_osr); + Hrs3603_write_reg(0x02, (ps1_enable << 2) | ps1_osr); + Hrs3603_write_reg(0x03, (hrs_led_en << 3) | (ps1_led_en << 2) | (hrs_ckafe_en << 1) | ps1_ckafe_en); + Hrs3603_write_reg(0x04, reset_cycle); + Hrs3603_write_reg(0x08, hrs_ckafe_cycle); + Hrs3603_write_reg(0x09, ps1_ckafe_cycle); + Hrs3603_write_reg(0x1c, ps1_interval_i2c); + Hrs3603_write_reg(0x05, dccancel_ps1_idac); + Hrs3603_write_reg(0x06, dccancel_hrs_idac); + Hrs3603_write_reg(0x07, (ledsel_ps1 << 4) | (force_ledsel_sel << 3) | ledsel_hrs); + Hrs3603_write_reg(0x0a, (ps1_int_cap << 4) | hrs_ps0_ts_int_cap); + //Hrs3603_write_reg(0x0b,(pd_drive_sel<<3)|(pd_drive_ps1<<4)|((led_drive&0x38)>>3)); + Hrs3603_write_reg(0x0b, ((ps1_leddr_msb << 4) | hrs_leddr_msb) & 0x77); + Hrs3603_write_reg(0xc4, (ext_pd_sel << 7) | ((leddr_lsb & 0x07) << 4) | 0x0f); + Hrs3603_write_reg(0x0d, (rfsel_hrs << 4) | (rfsel_ps1)); + Hrs3603_write_reg(0x0c, rfsel_ps1); + Hrs3603_write_reg(0x0f, 0x00); + Hrs3603_write_reg(0x0e, (extpd_ps1_en << 3) | (extpd_hrs_en << 2) | (tia_ps1_en << 1) | tia_hrs_en); + Hrs3603_write_reg(0x1b, 0x7f); + Hrs3603_write_reg(0xc2, 0x10 | (selftest_adc_afe << 7) | (selftest_adc << 6)); // test mode + Hrs3603_write_reg(0xc3, 0xff); + Hrs3603_write_reg(0x18, adc_data_clk_pol); + Hrs3603_write_reg(0x1a, 0x12); + Hrs3603_write_reg(0x0f, 0x00); // add ericy 20201106 + Hrs3603_write_reg(0x13, 0x01); //enable ps1 int + Hrs3603_write_reg(0x12, 0x50); // + Hrs3603_write_reg(0x20, 0x20); //close fifo int +} + + +/* static void mebug_io_1(u8 i) */ +/* { */ +/* P11_PORT->PB_SEL |= BIT(i); //P11 Control */ +/* P11_PORT->PB_DIR &= ~BIT(i); //dir output */ +/* P11_PORT->PB_OUT |= BIT(i); //output 1 */ +/* } */ +/* */ +/* */ +/* static void mebug_io_0(u8 i) */ +/* { */ +/* P11_PORT->PB_SEL |= BIT(i); //P11 Control */ +/* P11_PORT->PB_DIR &= ~BIT(i); //dir output */ +/* P11_PORT->PB_OUT &= ~BIT(i); //output 0 */ +/* } */ +/* */ + +static void Hrs3603_40ms_timer_Cb() +{ + /* printf("%s timer=%d mode=%d\n",__func__,timer_start,mode); */ + if (!timer_start) { + return; + } + /* mebug_io_1(9); */ + if (!mode) { + sensorhub_irq_add(IRQ_HRSENSOR_INDEX); + } else { + sensorhub_irq_add(IRQ_SPO2SENSOR_INDEX); + } + user_main_post_to_p11_system(P11_SYS_KICK, 0); + /* mebug_io_0(9); */ +} + + +void Hrs3603_Int_handle() +{ + if (!sensor_online) { + return; + } + + if (mode) { + return; + } + + u32 temp[3] = {0}; + + if ((Hrs3603_read_hrs(&temp[0], &temp[1]) == false) | (Hrs3603_read_ps1(&temp[2]) == false)) { + putchar('R'); + return ; + } + + if (hrs3603_alg_send_data_test(temp[1], temp[2]) == false) { + putchar('S'); + return; + } + + if (!cbuf_is_write_able(data_w_cbuf[0], sizeof(temp))) { + putchar('f'); + return; + } + + int wlen = cbuf_write(data_w_cbuf[0], temp, sizeof(temp)); + + if (wlen == 0) { + printf("hr data_w_cbuf_full\n"); + } + +} + +LOOP_DETECT_REGISTER(NULL, 40, Hrs3603_40ms_timer_Cb); + +int read_hrs3603_result(void *arg, u16 len) +{ +// log_i("%s",__func__); + + if (!sensor_online) { + return 0; + } + + if (mode) { + return 0; + } + + if (arg) { + return cbuf_read(data_w_cbuf[0], arg, len); + } + return cbuf_get_data_len(data_w_cbuf[0]); +} + +int Hrs3603_data_check_len() +{ + if (!sensor_online) { + return 0; + } + if (mode) { + return 0; + } + return cbuf_get_data_len(data_w_cbuf[0]); +} + + +int Hrs3603_spo2_data_check_len() +{ + if (!sensor_online) { + return 0; + } + if (!mode) { + return 0; + } + return cbuf_get_data_len(data_w_cbuf[1]); +} +void Hrs3603_spo2_Int_handle(void) +{ +// log_i("%s",__func__); + if (!sensor_online) { + return; + } + + if (!mode) { + return; + } + + + + u32 temp[4] = {0}; + + if ((Hrs3603_read_red_phase(&temp[0], &temp[1]) == false) | (Hrs3603_read_ir_phase(&temp[2], &temp[3]) == false)) { + putchar('r'); + return; + } + if (hrs3603_spo2_agc_test(temp[0], temp[1], temp[2], temp[3]) == false) { + putchar('t'); + return; + } + + if ((temp[0] > 0x7FFFF) | (temp[1] > 0x7FFFF) | (temp[2] > 0x7FFFF) | (temp[3] > 0x7FFFF)) { //19bit + return; + } + if (!cbuf_is_write_able(data_w_cbuf[1], sizeof(temp))) { + putchar('g'); + return; + } + + int wlen = cbuf_write(data_w_cbuf[1], temp, sizeof(temp)); + if (wlen == 0) { + printf("spo2 data_w_cbuf_full\n"); + } +} + +int read_hrs3603_spo2_result(void *arg, u16 len) +{ + /* log_i("%s",__func__); */ + if (!sensor_online) { + return 0; + } + if (!mode) { + return 0; + } + if (arg) { + return cbuf_read(data_w_cbuf[1], arg, len); + } + return cbuf_get_data_len(data_w_cbuf[1]); + +} + + + +REGISTER_CODE_SEG(BANK_CODE_SENSOR_NORMAL_BANK_1) +int Hrs3603_io_ctl(u8 cmd, void *arg) +{ + /* printf("%s cmd=%d\n",__func__,cmd); */ +// log_i("%s",__func__); + + int *data; + int *msg = (int *)arg; + int len; + int ret = 0; + + /* if (!sensor_online) { */ + /* return -1; */ + /* } */ + + switch (cmd) { + case HR_SENSOR_ENABLE: + hrs3603_hr_enable(); + break; + case HR_SENSOR_DISABLE: + hrs3603_disable(); + cbuf_clear(data_w_cbuf[0]); + cbuf_clear(data_w_cbuf[1]); + break; + case SPO2_SENSOR_ENABLE: + hrs3603_spo2_enable(); + break; + case SPO2_SENSOR_DISABLE: + hrs3603_disable(); + cbuf_clear(data_w_cbuf[0]); + cbuf_clear(data_w_cbuf[1]); + break; + case HR_SENSOR_CHECK_DATA: + return Hrs3603_data_check_len(); + break; + case HR_SENSOR_READ_DATA: + //返回心率传感器数据 + data = (void *)(msg[0]); + len = (int)(msg[1]); + ret = read_hrs3603_result(data, len); + break; + case SPO2_SENSOR_CHECK_DATA: + return Hrs3603_spo2_data_check_len(); + break; + case SPO2_SENSOR_READ_DATA: + //返回血氧传感器数据 + data = (void *)(msg[0]); + len = (int)(msg[1]); + ret = read_hrs3603_spo2_result(data, len); + break; + case HR_SEARCH_SENSOR: + if (Hrs3603_chip_check_id() == true) { + int valid = 1; + memcpy(arg, &valid, 4); + } else { + int valid = 0; + memcpy(arg, &valid, 4); + } + break; + case HR_SENSOR_IRQ: + Hrs3603_Int_handle(); + break; + case SPO2_SENSOR_IRQ: + Hrs3603_spo2_Int_handle(); + break; + + default: + break; + } + return ret; +} +REGISTER_HR_SENSOR(hrSensor) = { + .logo = "hrs3603", + .heart_rate_sensor_init = hx3603_init, + .heart_rate_sensor_check = NULL, + .heart_rate_sensor_ctl = Hrs3603_io_ctl, +} ; + +static u8 hrs3603_idle_query(void) +{ + return 1; +} + +/* REGISTER_LP_TARGET(hrs3603_lp_target) = { */ +/* .name = "hrs3603", */ +/* .is_idle = hrs3603_idle_query, */ +/* }; */ +#endif + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3600_reg_init.h b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3600_reg_init.h new file mode 100644 index 0000000..96be662 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3600_reg_init.h @@ -0,0 +1,29 @@ +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE + +#include + +const uint8_t init_register_array[][2] = { + + {0x01, 0x01}, // temper sensor enable, 0x03 dis + {0x02, 0x33}, // (0x77,0x66,0x55) enable and osr confid. 0x77 ps/hrs 1024 osr en; 0x66 ps/hrs 512 osr en; 0x55 ps/hrs 256 osr en; + {0x03, 0x8f}, // (0x8f,0x83) 0x8f enalbe ps/hrs led. 0x83 disable ps/hrs led + {0x04, 0x80}, // int time for hrs, 8btis. inttime=reg_data*4 + {0x05, 0x80}, // int time for ps, 8btis. inttime=reg_data*4 + {0x06, 0x50}, // intrupt set + {0x07, 0x01}, // intrupt enable + {0x09, 0x02}, // power down 0x03 ,power on 0x02 + {0x11, 0x04}, // reset time max 256; default=0x04,max 0x07 + {0x12, 0x1f}, // en2reset delay time max; default=0x1f,max 0x7f + {0x13, 0x00}, // PGA gain;0x00=0dB gain, 0x77=42dB,0x66=36dB,0x55=30dB,0x44=24dB,0x33=18dB,0x22=12dB,0x11=6dB,0x00=0dB + {0x14, 0x80}, // led select for ps. 0x40 for LDR0, 0x80 for LDR1 + {0x15, 0x40}, // led select for hrs. 0x40 for LDR0, 0x80 for LDR1 + {0x16, 0x00}, // ps idle, idle time = regdata*prf + {0xc0, 0x84}, // (0x86) led_dr <1:0> = bit<1:0> , 00=12.5mA ; 01=25mA ; 10=50mA ;11=100mA + {0xc1, 0x28}, // (0xb8 0x28 0x08) 0xb8 expd diff_adc test ; 0x28 internal pd diff_adc test; 0x08 internal pd single_adc test; + // pgacapsel{3:0}=bit[3:0] int cap set + {0xc2, 0x00}, // (0x20 0x40) self test config. 0x20 = adc only self test ; 0x40 = afe+adc self test + +}; + +#define INIT_ARRAY_SIZE (sizeof(init_register_array)/sizeof(init_register_array[0])) +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602.c b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602.c new file mode 100644 index 0000000..69118e7 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602.c @@ -0,0 +1,429 @@ +#include "app_config.h" +#include "includes.h" +#include "hrSensor_manage.h" +#include "gSensor_manage.h" +#include "usr_timer.h" +#include "hrs3602.h" +#include "hrs3600_reg_init.h" +#include "hrs3602_hrs_driv.h" + +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE + +/* 如果Gsensor数据读取代码已经添加,请将这个宏置1 */ +#define ACCLE_EN (1) + +typedef enum { + MODE_POWER_OFF = 0, + MODE_LPDETECTION = 1, + MODE_HRWORK = 2, + MMODE_SPO2WORK = 3, +} hrs3602_mode_t; + +#define PPG_BUF_MAX (25) +#define ACCLE_BUF_MAX (25) + +typedef struct { + u8 ppg_point; + u8 acc_point; + u8 wear_status; + u8 work_mode; + axis_info_t acc_buff[ACCLE_BUF_MAX]; + s32 ppg_buff[PPG_BUF_MAX]; +} hrs3602_raw_t; + + + +static hrs3602_raw_t hrs3602_raw; +static cbuffer_t *data_w_cbuf[2]; +static u8 cbuf_data[(4 + 6) * 25 * 2 + 100]; + +// sucess return 0 fail return 1 +bool Hrs3602_write_reg(u8 addr, u8 data) +{ + hrsensor_write_nbyte(0x88, addr, &data, 1); + return 0; +} + +u8 Hrs3602_read_reg(u8 addr) +{ + u8 data_buf = 0; + hrsensor_read_nbyte(0x89, addr, &data_buf, 1); + return data_buf; +} + +bool Hrs3602_brust_read_reg(u8 addr, u8 *buf, u8 length) +{ + hrsensor_read_nbyte(0x89, addr, buf, length); + return true; +} + + +void Hrs3602_read_data_packet() +{ + u8 databuf1[6] = {0}; + u8 databuf2[6] = {0}; + s32 P0 = 0, P1 = 0, P2 = 0, P3 = 0; + + Hrs3602_brust_read_reg(0xa0, databuf1, 6); + Hrs3602_brust_read_reg(0xa6, databuf2, 6); + + P0 = ((databuf1[0]) | (databuf1[1] << 8) | (databuf1[2] << 16)); + P1 = ((databuf1[3]) | (databuf1[4] << 8) | (databuf1[5] << 16)); + P2 = ((databuf2[0]) | (databuf2[1] << 8) | (databuf2[2] << 16)); + P3 = ((databuf2[3]) | (databuf2[4] << 8) | (databuf2[5] << 16)); + + Hrs3602_brust_read_reg(0xa0, databuf1, 6); + Hrs3602_brust_read_reg(0xa6, databuf2, 6); + //DEBUG_PRINTF("%d %d %d %d\r\n" ,P0,P1,P2,P3); + +} + +bool Hrs3602_read_hrs(s32 *hrm_data, s32 *als_data) +{ + u8 databuf[6] = {0}; + s32 P0 = 0, P1 = 0; + + Hrs3602_brust_read_reg(0xa0, databuf, 6); + + P0 = ((databuf[0]) | (databuf[1] << 8) | (databuf[2] << 16)); + P1 = ((databuf[3]) | (databuf[4] << 8) | (databuf[5] << 16)); + + //DEBUG_PRINTF(0," %d %d \r\n" , P0, P1); + if (P0 > P1) { + *hrm_data = P0 - P1; + } else { + *hrm_data = 0; + } + *als_data = P0; + + return true; +} + +bool Hrs3602_read_ps1(s32 *ppg_ir) +{ + u8 databuf[6] = {0}; + s32 P0 = 0, P1 = 0; + + Hrs3602_brust_read_reg(0xa6, databuf, 6); + + P0 = ((databuf[0]) | (databuf[1] << 8) | (databuf[2] << 16)); + P1 = ((databuf[3]) | (databuf[4] << 8) | (databuf[5] << 16)); + + if (P0 > P1) { + *ppg_ir = P0 - P1; + } else { + *ppg_ir = 0; + } + + return true; +} + +void Hrs3602_write_efuse() +{ + Hrs3602_write_reg(0x85, 0x20); + Hrs3602_write_reg(0x7f, 0x10); + Hrs3602_write_reg(0x80, 0x08); + Hrs3602_write_reg(0x81, 0x44); + Hrs3602_write_reg(0x82, 0x40); + Hrs3602_write_reg(0x85, 0x00); +} + + +void Hrs3602_chip_disable(void) +{ + Hrs3602_write_reg(0x09, 0x03); +} + +bool Hrs3602_check_chip_id(void) +{ + u8 chip_id = Hrs3602_read_reg(0x00); + + if (chip_id != 0x22) { + LOG("err =%d", chip_id); + return false; + } + LOG("sucess"); + return true; +} + +bool Hrs3602_chip_init() +{ + if (Hrs3602_check_chip_id() == false) { + LOG("chip id err!"); + return false; + } + + for (u16 i = 0; i < INIT_ARRAY_SIZE; i++) { + if (Hrs3602_write_reg(init_register_array[i][0], init_register_array[i][1]) != 0) { + return false; + } + } + + return true; +} + +void Hrs3602_alg_config(void) +{ + /*para init begin ....*/ + u32 prf_temp_clk_num = 0; /*temperatrue phase clk num in each prf */ + u32 prf_hrs_clk_num = 0; /*hrs phase clk num in each prf */ + u32 prf_ps_clk_num = 0; /*ps phase clk num in each prf */ + u32 prf_wait_clk_num = 0; /*wait time clk num in each prf */ + u32 en2rst_delay_clk_num = 0; /*en signal to first reset delay time clk num in each prf */ + u16 rst_clk_num = 0; + u16 hrs_ckafe_clk_num = 0; + u16 ps_ckafe_clk_num = 0; + + + /*para init end ....*/ + + /*chip config begin ....*/ + u16 sample_rate = 25; /*config the data rate of chip frog2 ,uint is Hz*/ + u32 prf_clk_num = 2620000 / sample_rate; /*period in clk num, num = Fclk/fs */ + + u8 temperature_enable = 0; /*temperature test function enable , 1 mean enable ; 0 mean disable */ + u8 hrs_enable = 1; /*hrs function enable , 1 mean enable ; 0 mean disable */ + u8 ps_enable = 1; /*ps function enable , 1 mean enable ; 0 mean disable */ + + u8 temperature_adc_osr = 0; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + u8 hrs_adc_osr = 3; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + u8 ps_adc_osr = 3; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + + u8 led_dr_cfg = 3 ; /* 0 = 12.5mA ; 1 = 25mA ; 2 =50mA(default) 3 = 100mA*/ + u8 tia_res = 2 ; /* 0 = 54k(default) ; 1 = 108k ; 2 =216k 3 = 432k */ + + en2rst_delay_clk_num = 64 ; /* 0 ~ 127 clk num config */ + rst_clk_num = 6 ; /* range from 0 to 7 ; 0=1 , 1=3, 2=7,....,7=255 */ + hrs_ckafe_clk_num = 128 ; /* hrm phase led on time : 0~ 255 , ʵ�ʿ���10λ������λĬ��Ϊ0*/ + ps_ckafe_clk_num = 4 ; /* ps phase led on time : 0~ 255 , ʵ�ʿ���10λ������λĬ��Ϊ0*/ + + + /*����PRF_WAIT��ʱ��*/ + if (temperature_enable == 1) { + prf_temp_clk_num = (en2rst_delay_clk_num + 10) + 2 * ((2 << rst_clk_num) - 1) + 2 * (128 << temperature_adc_osr); + } + + if (hrs_enable == 1) { + prf_hrs_clk_num = (en2rst_delay_clk_num + 10) + + 2 * (2 * ((2 << rst_clk_num) - 1) + (hrs_ckafe_clk_num << 4) + 10 + (128 << hrs_adc_osr)); + } + + if (ps_enable == 1) { + prf_ps_clk_num = (en2rst_delay_clk_num + 10) + + 2 * (2 * ((2 << rst_clk_num) - 1) + (ps_ckafe_clk_num << 4) + 10 + (128 << ps_adc_osr)); + } + + prf_wait_clk_num = prf_clk_num - prf_temp_clk_num - prf_hrs_clk_num - prf_ps_clk_num ; + /*����PRF_WAIT��ʱ��*/ + + Hrs3602_write_reg(0xc1, 0x08); // config external pd as input and cap mode enable + Hrs3602_write_reg(0x03, 0x8f); // all phase use same external pd + + /*register configration begin ....*/ + + Hrs3602_write_reg(0x01, (temperature_enable << 2) | temperature_adc_osr); + Hrs3602_write_reg(0x02, (hrs_enable << 2) | (hrs_adc_osr) | (ps_adc_osr << 4) | (ps_enable << 6)); + + //DEBUG_PRINTF(0," reg_0x02 is %x \r\n" , Hrs3602_read_reg(0x02)); + + + Hrs3602_write_reg(0x04, hrs_ckafe_clk_num); + Hrs3602_write_reg(0x05, ps_ckafe_clk_num); + + //DEBUG_PRINTF(0," %x %x \r\n" , Hrs3602_read_reg(0x04) , Hrs3602_read_reg(0x05)); + + Hrs3602_write_reg(0x0a, prf_wait_clk_num); + Hrs3602_write_reg(0x0b, prf_wait_clk_num >> 8); + Hrs3602_write_reg(0x0c, prf_wait_clk_num >> 16); + + Hrs3602_write_reg(0x11, rst_clk_num); + Hrs3602_write_reg(0x12, en2rst_delay_clk_num); + + //GPIO config + Hrs3602_write_reg(0xc0, (0x84 | led_dr_cfg)); /* led dr config , 0x84 = 12.5mA , 0x85 = 25mA ,0x86 = 50 mA ,0x87 = 100mA */ + Hrs3602_write_reg(0xc2, (0x00 | tia_res)); /* tia res config , 0x00 = 54K , 0x01 = 108K ,0x02 = 216K ,0x03 = 432K */ + /*register configration end ....*/ + Hrs3602_write_reg(0x09, 0x02); + +#ifdef IR_CHECK_TOUCH + Hrs3602_write_reg(0X14, 0x80); + Hrs3602_write_reg(0X15, 0x40); +#else + Hrs3602_write_reg(0X14, 0x40); + Hrs3602_write_reg(0X15, 0x40); +#endif + + Hrs3602_write_reg(0x08, 0x00); // self clear int +} + +void Hrs3602_int_clear() +{ + Hrs3602_write_reg(0x06, 0x7f); +} + +void Hrs3602_proess(void *priv); +void Hrs3602_timer_start(u8 enable) +{ + static u16 Hrs3602_timer = 0; + + if (enable && Hrs3602_timer == 0) { + Hrs3602_timer = usr_timer_add(NULL, Hrs3602_proess, 40, 0); + } else if ((!enable) && Hrs3602_timer > 0) { + usr_timer_del(Hrs3602_timer); + Hrs3602_timer = 0; + } +} + + +u8 Hrs3602_measure_start(void) +{ + if (Hrs3602_chip_init()) { + Hrs3602_alg_config(); + Hrs3602_driv_init(); + + hrs3602_raw.ppg_point = 0; + hrs3602_raw.acc_point = 0; + hrs3602_raw.wear_status = MSG_NO_TOUCH; + hrs3602_raw.work_mode = MODE_HRWORK; + + Hrs3602_timer_start(1); + return 0; + } + return -1; +} + +u8 Hrs3602_measure_stop(void) +{ + Hrs3602_timer_start(0); + Hrs3602_chip_disable(); + hrs3602_raw.work_mode = MODE_POWER_OFF; + return 0; +} + + +void Hrs3602_update_to_mater(void) +{ + LOG("point=%d %d wear=%d", hrs3602_raw.ppg_point, hrs3602_raw.acc_point, hrs3602_raw.wear_status); + //小核800ms写入一次,主核1000ms读取一次,比较坏的情况会小核写2次,主核读一次 + if (cbuf_get_data_len(data_w_cbuf[0]) >= 2 * sizeof(hrs3602_raw_t)) { + cbuf_clear(data_w_cbuf[0]); + LOG("full"); + } + cbuf_write(data_w_cbuf[0], &hrs3602_raw, sizeof(hrs3602_raw_t)); + // vcHr11DumpRawData(); + hrs3602_raw.ppg_point = 0; + hrs3602_raw.acc_point = 0; +} + +void Hrs3602_work_hr_mode(void) +{ + s32 ppg_green, ppg_env, ppg_ir; + hrs3602_wear_status_t wear_status = MSG_NO_TOUCH; + + Hrs3602_read_hrs(&ppg_green, &ppg_env); + Hrs3602_read_ps1(&ppg_ir); + + wear_status = Hrs3602_agc(ppg_env, ppg_ir); + LOG(" gr=%d, als=%d ir=%d status=%d \r\n", ppg_green, ppg_env, ppg_ir, wear_status); + + if (wear_status == MSG_TOUCH) { + if (hrs3602_raw.ppg_point < PPG_BUF_MAX) { + hrs3602_raw.ppg_buff[hrs3602_raw.ppg_point] = ppg_green; + hrs3602_raw.ppg_point++; + if (hrs3602_raw.ppg_point >= 25) { + Hrs3602_update_to_mater(); + } + } + } + + if (hrs3602_raw.wear_status != wear_status) { + hrs3602_raw.wear_status = wear_status; + if (wear_status == MSG_NO_TOUCH) { + hrs3602_raw.ppg_point = 0; + hrs3602_raw.acc_point = 0; + Hrs3602_update_to_mater(); + } + } + +} + +void Hrs3602_proess(void *priv) +{ + if (hrs3602_raw.work_mode == MODE_HRWORK) { + Hrs3602_work_hr_mode(); + } +} + +u8 Hrs3602_preInit(cbuffer_t *hrcbuf, cbuffer_t *spo2cbuf) +{ + if (!hrcbuf || !spo2cbuf) { + ASSERT(0); + } + data_w_cbuf[0] = hrcbuf; + data_w_cbuf[1] = spo2cbuf; + + cbuf_init(data_w_cbuf[0], cbuf_data, sizeof(cbuf_data)); + cbuf_init(data_w_cbuf[1], cbuf_data, sizeof(cbuf_data)); + + return Hrs3602_check_chip_id(); +} + + +void Hrs3602AccelDataInput(void *accel, u8 point) +{ + if (hrs3602_raw.work_mode == MODE_HRWORK) { + + if (accel != NULL && point > 0) { + s16 free_point = ACCLE_BUF_MAX - hrs3602_raw.acc_point; + if (free_point > 0) { + point = MIN(point, free_point); + memcpy(&hrs3602_raw.acc_buff[hrs3602_raw.acc_point], accel, point * sizeof(axis_info_t)); + hrs3602_raw.acc_point += point; + } + } else { + LOG("err: accel=%d point=%d", accel, point); + } + } +} + +s32 Hrs3602IoCtl(u8 cmd, void *arg) +{ + s32 len; + s32 ret = 0; + s32 *data; + s32 *msg = (s32 *)arg; + + // LOG("cmd=%d",cmd); + + switch (cmd) { + case HR_SENSOR_ENABLE: + Hrs3602_measure_start(); + break; + case HR_SENSOR_DISABLE: + Hrs3602_measure_stop(); + break; + case HR_SENSOR_LP_DETECTION: + break; + case HR_SENSOR_FACTORY_TEST: + break; + + case HR_SEARCH_SENSOR: { + int valid = Hrs3602_check_chip_id(); + memcpy(arg, &valid, 4); + break; + } + default: + break; + } + return ret; +} + +REGISTER_HR_SENSOR(hrSensor) = { + .logo = "hrs3602", + .heart_rate_sensor_init = Hrs3602_preInit, + .heart_rate_sensor_check = NULL, + .heart_rate_sensor_ctl = Hrs3602IoCtl, + .accel_data_input = Hrs3602AccelDataInput, +} ; + +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602.h b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602.h new file mode 100644 index 0000000..8039607 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602.h @@ -0,0 +1,77 @@ +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE +#ifndef _HRS3600_H_ +#define _HRS3600_H_ +#include +#include + +#define TIMER_READ_MODE + +#define HRS_ALG_LIB + +#define IR_CHECK_TOUCH + +#define CHECK_TOUCH_DIFF + +//#define TESTVEC + +#define TYHX_DEMO + +#define HRS_BLE_APP + +#define RTT_DEBUG + +#define GSENSER_DATA + +#define NEW_GSEN_SCHME + +#ifdef RTT_DEBUG +#define LOG(fmt,...) printf("[3602] %s " fmt "\n",__func__, ##__VA_ARGS__) +#define DEBUG_PRINTF(fmt,...) //printf("[3602] %s " fmt "\n",__func__, ##__VA_ARGS__) +#else +#define DEBUG_PRINTF(...) +#endif + +typedef struct { + int16_t AXIS_X; + int16_t AXIS_Y; + int16_t AXIS_Z; +} GsensorRaw_t; + + +void Hrs3602_chip_disable(void); +void Hrs3602_chip_enable(void); + +bool Hrs3602_chip_init(void); +void Hrs3602_chip_reset(void); +void heart_rate_meas_timeout_handler(void *p_context); +void Hrs3602_INT_init(void); +void Hrs3602_INT_enable(void); +void Hrs3602_INT_disable(void); + +bool Hrs3602_write_reg(uint8_t addr, uint8_t data); +uint8_t Hrs3602_read_reg(uint8_t addr); +bool Hrs3602_brust_read_reg(uint8_t addr, uint8_t *buf, uint8_t length); + +void Hrs3602_timeout_handler(void); +void Hrs3602_init_touch_mode(void); +void Hrs3602_Int_handle(void); +void Hrs3602_blood_presure_Int_handle(void); +void Hrs3602_chip_disable(void); +void Hrs3602_alg_config(void); +extern void Hrs3602_set_first_hr_mode(uint8_t mode); +extern void Hrs3602_set_dc_thres_low(int32_t value); + +void Hrs3602_bp_alg_config(void); // add ericy 20180625 + +bool Hrs3602_read_hrs(int32_t *hrm_data, int32_t *als_data); +bool Hrs3602_read_ps1(int32_t *infrared_data); +void Hrs3602_set_motion_status(uint16_t motion_status); + +uint32_t hrs3602_timers_start(void); +uint32_t hrs3602_timers_stop(void); +void Hrs3300_button_handler(void); +void read_data_packet(int32_t *ps_data); + +#endif // _HRS3600_H_ +#endif + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c new file mode 100644 index 0000000..57c3dca --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c @@ -0,0 +1,204 @@ + +#include +#include +#include +#include +#include +#include "app_config.h" +#include "hrs3602.h" +#include "hrs3602_hrs_driv.h" +// #include "tyhx_hrs_alg.h" + +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE +static hrs3602_wear_status_t wear_status = MSG_CHECK_INIT; +static hrs3602_wear_status_t wear_status_pre = MSG_CHECK_INIT; + +uint32_t hx3602_wear_thre_high = 5000; +uint32_t hx3602_wear_thre_low = 4000; +uint32_t hx3602_agc_adj_thre_high = 450000; +uint32_t hx3602_agc_adj_thre_low = 150000; + +static int32_t check_touch_data_min = 300000; +static int32_t check_touch_data_max = 0; +static int32_t check_touch_data_fifo[8] = {0}; + +uint8_t agc_cnt = 0; +uint8_t agc_offset = 0; +uint8_t check_touch_cnt = 0; + +void Hrs3602_driv_init(void) +{ + wear_status = MSG_CHECK_INIT; + wear_status_pre = MSG_CHECK_INIT; + agc_cnt = 0; + agc_offset = 0; + check_touch_cnt = 10; +} + +void Hrs3602_check_touch(int32_t infrared_data) +{ + if (infrared_data > hx3602_wear_thre_high) { + if (check_touch_cnt >= 20) { + check_touch_cnt = 20; + wear_status = MSG_TOUCH; + if (wear_status != wear_status_pre) { + Hrs3602_normal_power(); + // tyhx_hrs_alg_open_deep(); + } + } else { + check_touch_cnt++; + } + } else if (infrared_data < hx3602_wear_thre_low) { + if (check_touch_cnt <= 0) { + check_touch_cnt = 0; + wear_status = MSG_NO_TOUCH; + if (wear_status != wear_status_pre) { + Hrs3602_low_power(); + } + } else { + check_touch_cnt--; + } + } +} + +void Hrs3602_check_touch_diff(int32_t infrared_data) +{ + uint8_t ii = 0, jj = 0; + int32_t ir_data_temp = 0; + int32_t check_fifo[8]; + int32_t check_data_sum = 0; + int32_t check_data_ave = 0; + + for (ii = 0; ii < 7; ii++) { + check_touch_data_fifo[ii] = check_touch_data_fifo[ii + 1]; + check_fifo[ii] = check_touch_data_fifo[ii]; + check_data_sum = check_data_sum + check_touch_data_fifo[ii]; + } + check_touch_data_fifo[7] = infrared_data; + check_fifo[7] = check_touch_data_fifo[7]; + check_data_sum = check_data_sum + check_touch_data_fifo[7]; + + for (ii = 0; ii < 7; ii++) { + for (jj = 0; jj < 7 - ii; jj++) { + if (check_fifo[jj] > check_fifo[jj + 1]) { + ir_data_temp = check_fifo[jj]; + check_fifo[jj] = check_fifo[jj + 1]; + check_fifo[jj + 1] = ir_data_temp; + } + } + } + if (abs(check_fifo[7] - check_fifo[0]) < 4000 && check_fifo[0] > 0) { + check_data_ave = check_data_sum >> 3; + } + + if (check_data_ave < check_touch_data_min && check_data_ave > 0) { + check_touch_data_min = check_data_ave; + } + if (check_data_ave > check_touch_data_max && check_data_ave > 0) { + check_touch_data_max = check_data_ave; + } + + + if (check_touch_data_max > 0 && check_touch_data_min > 0 && check_touch_data_max > check_touch_data_min + hx3602_wear_thre_high) { + if (infrared_data > check_touch_data_min + hx3602_wear_thre_high) { + if (check_touch_cnt >= 20) { + check_touch_cnt = 20; + wear_status = MSG_TOUCH; + if (wear_status != wear_status_pre) { + Hrs3602_normal_power(); + // tyhx_hrs_alg_open_deep(); + } + } else { + check_touch_cnt++; + } + } else if (infrared_data < check_touch_data_min + hx3602_wear_thre_low) { + if (check_touch_cnt <= 0) { + check_touch_cnt = 0; + wear_status = MSG_NO_TOUCH; + if (wear_status != wear_status_pre) { + Hrs3602_low_power(); + } + } else { + check_touch_cnt--; + } + } + } else { + if (infrared_data > hx3602_wear_thre_high) { + if (check_touch_cnt >= 20) { + check_touch_cnt = 20; + wear_status = MSG_TOUCH; + if (wear_status != wear_status_pre) { + Hrs3602_normal_power(); + // tyhx_hrs_alg_open_deep(); + } + } else { + check_touch_cnt++; + } + } else if (infrared_data < hx3602_wear_thre_low) { + if (check_touch_cnt <= 0) { + check_touch_cnt = 0; + wear_status = MSG_NO_TOUCH; + if (wear_status != wear_status_pre) { + Hrs3602_low_power(); + } + } else { + check_touch_cnt--; + } + } + } +} + +hrs3602_wear_status_t Hrs3602_agc(int32_t als_raw_data, int32_t infrared_data) +{ +#ifdef CHECK_TOUCH_DIFF + Hrs3602_check_touch_diff(infrared_data); +#else + Hrs3602_check_touch(infrared_data); +#endif + + if (wear_status == MSG_TOUCH) { + if (als_raw_data > hx3602_agc_adj_thre_high) { + if (agc_cnt == 3) { + agc_cnt = 0; + if (agc_offset < 32) { + agc_offset++; + Hrs3602_write_reg(0x15, (0x40 | agc_offset)); + } + } else { + agc_cnt++; + } + } else if (als_raw_data < hx3602_agc_adj_thre_low) { + if (agc_cnt == 3) { + agc_cnt = 0; + if (agc_offset > 0) { + agc_offset--; + Hrs3602_write_reg(0x15, (0x40 | agc_offset)); + } + } else { + agc_cnt++; + } + } + } else { + agc_cnt = 0; + agc_offset = 0; + } + wear_status_pre = wear_status; + DEBUG_PRINTF("min=%d ir=%d status=%d offset=%d\r\n", check_touch_data_min, infrared_data, wear_status, agc_offset); + return wear_status; +} + +void Hrs3602_low_power(void) +{ + Hrs3602_write_reg(0x02, 0x70); + Hrs3602_write_reg(0x15, 0x40); + Hrs3602_write_reg(0xc0, 0x87); /* led dr config , 0x84 = 12.5mA , 0x85 = 25mA ,0x86 = 50 mA ,0x87 = 100mA */ + Hrs3602_write_reg(0x16, 0x31); // detect interval is 1s when loss +} + +void Hrs3602_normal_power(void) +{ + Hrs3602_write_reg(0x02, 0x77); + Hrs3602_write_reg(0xc0, 0x87); + Hrs3602_write_reg(0x16, 0x00); // detect interval is 40mS +} +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.h b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.h new file mode 100644 index 0000000..69c7e76 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.h @@ -0,0 +1,53 @@ +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE +#ifndef _HRS3600_DRIV_H_ +#define _HRS3600_DRIV_H_ + +#include + + +/* portable 8-bit unsigned integer */ +typedef unsigned char uint8_t; +/* portable 8-bit signed integer */ +typedef signed char int8_t; +/* portable 16-bit unsigned integer */ +typedef unsigned short int uint16_t; +/* portable 16-bit signed integer */ +typedef signed short int int16_t; +/* portable 32-bit unsigned integer */ +typedef unsigned int uint32_t; +/* portable 32-bit signed integer */ +typedef signed int int32_t; + +#ifndef bool +#define bool unsigned char +#endif + +#ifndef true +#define true 1 +#endif +#ifndef false +#define false 0 +#endif + +typedef enum { + MSG_NO_TOUCH, + MSG_TOUCH, + MSG_CHECK_INIT +} hrs3602_wear_status_t; + +typedef struct { + uint32_t data_cnt; + uint8_t highlight; + uint8_t no_touch_check_flg; + uint32_t no_touch_check_cnt; + uint32_t timer_notouch_check_cnt; + uint8_t no_touch_cnt; +} agc_data_t; + +void Hrs3602_driv_init(void); +void Hrs3602_low_power(void); +void Hrs3602_normal_power(void); +hrs3602_wear_status_t Hrs3602_agc(int32_t als_raw_data, int32_t infrared_data); + +#endif +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c new file mode 100644 index 0000000..3fc21b0 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c @@ -0,0 +1,279 @@ + +#include +#include +#include +#include +#include +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE + +#ifdef TYHX_DEMO +#include "SEGGER_RTT.h" +/* #include "nrf_delay.h" */ +#endif + +////////////////////////////// + +/* #include "nrf_delay.h" */ +#include "hrs3602.h" +#include "hx3602_factory_test.h" +extern void mdelay(int ms);//不准 +#define nrf_delay_ms mdelay +void hx3602_factory_ft_card_test_config()//灰卡10mm高度测试配置 +{ + /*para init begin ....*/ + uint32_t prf_temp_clk_num = 0; /*temperatrue phase clk num in each prf */ + uint32_t prf_hrs_clk_num = 0; /*hrs phase clk num in each prf */ + uint32_t prf_ps_clk_num = 0; /*ps phase clk num in each prf */ + uint32_t prf_wait_clk_num = 0; /*wait time clk num in each prf */ + uint32_t en2rst_delay_clk_num = 0; /*en signal to first reset delay time clk num in each prf */ + uint16_t rst_clk_num = 0; + uint16_t hrs_ckafe_clk_num = 0; + uint16_t ps_ckafe_clk_num = 0; + /*para init end ....*/ + + /*chip config begin ....*/ + uint16_t sample_rate = 25; /*config the data rate of chip frog2 ,uint is Hz*/ + uint32_t prf_clk_num = 2620000 / sample_rate; /*period in clk num, num = Fclk/fs */ + + uint8_t temperature_enable = 0; /*temperature test function enable , 1 mean enable ; 0 mean disable */ + uint8_t hrs_enable = 1; /*hrs function enable , 1 mean enable ; 0 mean disable */ + uint8_t ps_enable = 1; /*ps function enable , 1 mean enable ; 0 mean disable */ + uint8_t temperature_adc_osr = 0; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + uint8_t hrs_adc_osr = 3; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + uint8_t ps_adc_osr = 3; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + + uint8_t led_dr_cfg = 2; /* 0 = 12.5mA ; 1 = 25mA ; 2 =50mA(default) 3 = 100mA*/ + uint8_t tia_res = 2 ; /* 0 = 54k(default) ; 1 = 108k ; 2 =216k 3 = 432k */ + + en2rst_delay_clk_num = 64 ; /* 0 ~ 127 clk num config */ + rst_clk_num = 6 ; /* range from 0 to 7 ; 0=1 , 1=3, 2=7,....,7=255 */ + hrs_ckafe_clk_num = 64 ; /* hrm phase led on time : 0~ 255 */ + ps_ckafe_clk_num = 32 ; /* ps phase led on time : 0~ 255 */ + + if (temperature_enable == 1) { + prf_temp_clk_num = (en2rst_delay_clk_num + 10) + 2 * ((2 << rst_clk_num) - 1) + 2 * (128 << temperature_adc_osr); + } + + if (hrs_enable == 1) { + prf_hrs_clk_num = (en2rst_delay_clk_num + 10) + + 2 * (2 * ((2 << rst_clk_num) - 1) + (hrs_ckafe_clk_num << 4) + 10 + (128 << hrs_adc_osr)); + } + + if (ps_enable == 1) { + prf_ps_clk_num = (en2rst_delay_clk_num + 10) + + 2 * (2 * ((2 << rst_clk_num) - 1) + (ps_ckafe_clk_num << 4) + 10 + (128 << ps_adc_osr)); + } + + prf_wait_clk_num = prf_clk_num - prf_temp_clk_num - prf_hrs_clk_num - prf_ps_clk_num ; + + /*register configration begin ....*/ + + Hrs3602_write_reg(0x01, (temperature_enable << 2) | temperature_adc_osr); + Hrs3602_write_reg(0x02, (hrs_enable << 2) | (hrs_adc_osr) | (ps_adc_osr << 4) | (ps_enable << 6)); + + Hrs3602_write_reg(0xc1, 0x0f); // config external pd as input and tia mode enable + Hrs3602_write_reg(0x03, 0x8f); // all phase use same external pd + + Hrs3602_write_reg(0x04, hrs_ckafe_clk_num); + Hrs3602_write_reg(0x05, ps_ckafe_clk_num); + + Hrs3602_write_reg(0x0a, prf_wait_clk_num); + Hrs3602_write_reg(0x0b, prf_wait_clk_num >> 8); + Hrs3602_write_reg(0x0c, prf_wait_clk_num >> 16); + + Hrs3602_write_reg(0x11, rst_clk_num); + Hrs3602_write_reg(0x12, en2rst_delay_clk_num); + + //GPIO config + Hrs3602_write_reg(0xc0, (0x84 | led_dr_cfg)); /* led dr config , 0x84 = 12.5mA , 0x85 = 25mA ,0x86 = 50 mA ,0x87 = 100mA */ + Hrs3602_write_reg(0xc2, (0x00 | tia_res)); /* tia res config , 0x00 = 54K , 0x01 = 108K ,0x02 = 216K ,0x03 = 432K */ + /*register configration end ....*/ + Hrs3602_write_reg(0xc2, 0X00); + Hrs3602_write_reg(0x09, 0x02); + Hrs3602_write_reg(0x16, 0x00); + Hrs3602_write_reg(0x08, 0x00); // self clear int + + Hrs3602_write_reg(0x14, 0x80); //ps + Hrs3602_write_reg(0x15, 0x40); //hrs + + return ; +} + +void hx3602_factory_ft_leak_light_test_config()//漏光测试配置 +{ + /*para init begin ....*/ + uint32_t prf_temp_clk_num = 0; /*temperatrue phase clk num in each prf */ + uint32_t prf_hrs_clk_num = 0; /*hrs phase clk num in each prf */ + uint32_t prf_ps_clk_num = 0; /*ps phase clk num in each prf */ + uint32_t prf_wait_clk_num = 0; /*wait time clk num in each prf */ + uint32_t en2rst_delay_clk_num = 0; /*en signal to first reset delay time clk num in each prf */ + uint16_t rst_clk_num = 0; + uint16_t hrs_ckafe_clk_num = 0; + uint16_t ps_ckafe_clk_num = 0; + /*para init end ....*/ + + /*chip config begin ....*/ + uint16_t sample_rate = 25; /*config the data rate of chip frog2 ,uint is Hz*/ + uint32_t prf_clk_num = 2620000 / sample_rate; /*period in clk num, num = Fclk/fs */ + + uint8_t temperature_enable = 0; /*temperature test function enable , 1 mean enable ; 0 mean disable */ + uint8_t hrs_enable = 1; /*hrs function enable , 1 mean enable ; 0 mean disable */ + uint8_t ps_enable = 1; /*ps function enable , 1 mean enable ; 0 mean disable */ + + uint8_t temperature_adc_osr = 0; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + uint8_t hrs_adc_osr = 3; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + uint8_t ps_adc_osr = 3; /* 0 = 128 ; 1 = 256 ; 2 = 512 ; 3 = 1024 ;*/ + + uint8_t led_dr_cfg = 3 ; /* 0 = 12.5mA ; 1 = 25mA ; 2 =50mA(default) 3 = 100mA*/ + uint8_t tia_res = 3 ; /* 0 = 54k(default) ; 1 = 108k ; 2 =216k 3 = 432k */ + + en2rst_delay_clk_num = 64 ; /* 0 ~ 127 clk num config */ + rst_clk_num = 6 ; /* range from 0 to 7 ; 0=1 , 1=3, 2=7,....,7=255 */ + hrs_ckafe_clk_num = 128 ; /* hrm phase led on time : 0~ 255 , 实际宽度10位,低两位默认为0*/ + ps_ckafe_clk_num = 32 ; /* ps phase led on time : 0~ 255 , 实际宽度10位,低两位默认为0*/ + + + /*计算PRF_WAIT的时间*/ + if (temperature_enable == 1) { + prf_temp_clk_num = (en2rst_delay_clk_num + 10) + 2 * ((2 << rst_clk_num) - 1) + 2 * (128 << temperature_adc_osr); + } + + if (hrs_enable == 1) { + prf_hrs_clk_num = (en2rst_delay_clk_num + 10) + + 2 * (2 * ((2 << rst_clk_num) - 1) + (hrs_ckafe_clk_num << 4) + 10 + (128 << hrs_adc_osr)); + } + + if (ps_enable == 1) { + prf_ps_clk_num = (en2rst_delay_clk_num + 10) + + 2 * (2 * ((2 << rst_clk_num) - 1) + (ps_ckafe_clk_num << 4) + 10 + (128 << ps_adc_osr)); + } + + prf_wait_clk_num = prf_clk_num - prf_temp_clk_num - prf_hrs_clk_num - prf_ps_clk_num ; + /*计算PRF_WAIT的时间*/ + + Hrs3602_write_reg(0xc1, 0x0c); // config external pd as input and tia mode enable + Hrs3602_write_reg(0x03, 0x8f); // all phase use same external pd + + Hrs3602_write_reg(0x01, (temperature_enable << 2) | temperature_adc_osr); + Hrs3602_write_reg(0x02, (hrs_enable << 2) | (hrs_adc_osr) | (ps_adc_osr << 4) | (ps_enable << 6)); + + Hrs3602_write_reg(0x04, hrs_ckafe_clk_num); + Hrs3602_write_reg(0x05, ps_ckafe_clk_num); + + Hrs3602_write_reg(0x0a, prf_wait_clk_num); + Hrs3602_write_reg(0x0b, prf_wait_clk_num >> 8); + Hrs3602_write_reg(0x0c, prf_wait_clk_num >> 16); + + Hrs3602_write_reg(0x11, rst_clk_num); + Hrs3602_write_reg(0x12, en2rst_delay_clk_num); + + //GPIO config + Hrs3602_write_reg(0xc0, (0x84 | led_dr_cfg)); /* led dr config , 0x84 = 12.5mA , 0x85 = 25mA ,0x86 = 50 mA ,0x87 = 100mA */ + Hrs3602_write_reg(0xc2, (0x00 | tia_res)); /* tia res config , 0x00 = 54K , 0x01 = 108K ,0x02 = 216K ,0x03 = 432K */ + Hrs3602_write_reg(0x09, 0x02); + + Hrs3602_write_reg(0x14, 0x80); + Hrs3602_write_reg(0x15, 0x40); + Hrs3602_write_reg(0x08, 0x00); // self clear int + + return ; +} + + + +bool hx3602_factory_test_read(int32_t *phase_data) +{ + uint8_t databuf1[6] = {0}; + uint8_t databuf2[6] = {0}; + uint32_t P1 = 0, P2 = 0, P4 = 0, P3 = 0; + + Hrs3602_brust_read_reg(0xa0, databuf1, 6); + Hrs3602_brust_read_reg(0xa6, databuf2, 6); + + P1 = ((databuf1[0]) | (databuf1[1] << 8) | (databuf1[2] << 16)); + P2 = ((databuf1[3]) | (databuf1[4] << 8) | (databuf1[5] << 16)); + P3 = ((databuf2[0]) | (databuf2[1] << 8) | (databuf2[2] << 16)); + P4 = ((databuf2[3]) | (databuf2[4] << 8) | (databuf2[5] << 16)); + + phase_data[0] = P1 ; + phase_data[1] = P2 ; + phase_data[2] = P3 ; + phase_data[3] = P4 ; + DEBUG_PRINTF("%d %d %d %d\r\n", phase_data[0], phase_data[1], phase_data[2], phase_data[3]); + + return true; +} + + +bool hx3602_chip_check_id(void) +{ + uint8_t i = 0; + uint8_t chip_id = 0; + + Hrs3602_write_reg(0x09, 0x02); + nrf_delay_ms(5); + for (i = 0; i < 10; i++) { + chip_id = Hrs3602_read_reg(0x00); + if (chip_id == 0x22) { + return true; + } + } + return false; +} + +int32_t hx3602_sort_cal(int32_t *data) +{ + uint8_t ii, jj; + int32_t data_temp = 0; + int32_t data_final = 0; + for (ii = 0; ii < 3; ii++) { + for (jj = 0; jj < 3 - ii; jj++) { + if (data[jj] >= data[jj + 1]) { + data_temp = data[jj]; + data[jj] = data[jj + 1]; + data[jj + 1] = data_temp; + } + } + } + data_final = (data[1] + data[2]) >> 1; + return data_final; +} + +FT_RESULTS_t hx3602_factroy_test(TEST_MODE_t test_mode) +{ + FT_RESULTS_t ft_result = {0, 0}; + int32_t gr_buffer[4] = {0, 0, 0, 0}; + int32_t ir_buffer[4] = {0, 0, 0, 0}; + int32_t phase_data[4] = {0, 0, 0, 0}; + uint8_t ii = 0; + + if (hx3602_chip_check_id() == false) { + return ft_result; + } + switch (test_mode) { + case LEAK_LIGHT_TEST: + hx3602_factory_ft_leak_light_test_config(); + break; + + case GRAY_CARD_TEST: + hx3602_factory_ft_card_test_config(); + break; + + default: + break; + } + nrf_delay_ms(100); + + for (ii = 0; ii < 4; ii++) { //40ms read data + hx3602_factory_test_read(phase_data); + gr_buffer[ii] = phase_data[0] - phase_data[1]; + ir_buffer[ii] = phase_data[2] - phase_data[3]; + nrf_delay_ms(40); + } + ft_result.gr_data_final = hx3602_sort_cal(gr_buffer); + ft_result.ir_data_final = hx3602_sort_cal(ir_buffer); + DEBUG_PRINTF("%d %d %x %x\r\n", ft_result.gr_data_final, ft_result.ir_data_final, Hrs3602_read_reg(0x14), Hrs3602_read_reg(0x15)); + + return ft_result; +} +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.h b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.h new file mode 100644 index 0000000..c16becf --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.h @@ -0,0 +1,27 @@ + +#if defined(TCFG_HRS3602_DEV_ENABLE) && TCFG_HRS3602_DEV_ENABLE +#ifndef _hx3602_FACTORY_TEST_H_ +#define _hx3602_FACTORY_TEST_H_ + +#include +#include + +typedef enum { + LEAK_LIGHT_TEST = 1, + GRAY_CARD_TEST = 2, + +} TEST_MODE_t; + + +typedef struct { + int32_t gr_data_final; + int32_t ir_data_final; + +} FT_RESULTS_t; + +FT_RESULTS_t hx3602_factroy_test(TEST_MODE_t test_mode); + +#endif // _hx3600_FACTORY_TEST_H_ + +#endif + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c new file mode 100644 index 0000000..d93ea0c --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c @@ -0,0 +1,289 @@ + +/********************************************************************************************************* +* Copyright(c) 2018, Vcare Corporation. All rights reserved. +********************************************************************************************************** +* @file module_heart_vc.c +* @brief +* @details +* @author +* @date +* @version v1.6 +********************************************************************************************************* +*/ +#include "app_config.h" +#include "includes.h" +#include "hrSensor_manage.h" +#include "gSensor_manage.h" +#include "usr_timer.h" +#include "msg.h" +#include "vcHr11Hci.h" + +#if defined(TCFG_VCHR11S_DEV_ENABLE) && TCFG_VCHR11S_DEV_ENABLE + +#define LOG(...) //dev_log(__VA_ARGS__) + + + +#define DEV_W_ADDR (0x33<<1 | 0) +#define DEV_R_ADDR (0x33<<1 | 1) + +/* 如果Gsensor数据读取代码已经添加,请将这个宏置1 */ +#define ACCLE_EN (1) +#define ACCLE_BUF_MAX (25*2) + +const uint32_t mcuOscData = 30000; // Timer clock frequency Be used to adjust INT frequency +const uint16_t mcuI2cClock = 400; // MCU I2C clock frequency +const uint8_t vcHr11SampleRate = 25; // Heart rate sample frequency + +static bool vcHr11IRQFlag = 0; +static vcHr11_t vcHr11; + +static cbuffer_t *data_w_cbuf[2]; +static u8 hrdata[600 * 2]; + +typedef struct { + u8 workMode; + u8 wearState; + u8 maxLedCur; + u8 psValue; //PS Sample value. + u8 preValue[2]; //Environment Sample value. + u8 envValue[3]; //Environment Sample value. + u8 ppgLength; + u8 accelLength; + u16 ppgValue[ACCLE_BUF_MAX * 2]; //PPG sample value. + axis_info_t accel_buf[ACCLE_BUF_MAX]; +} vcHrData_t; + +static vcHrData_t vcHrData; + +vcHr11Ret_t vcHr11WriteRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len) +{ + hrsensor_write_nbyte(DEV_W_ADDR, startAddress, pRegisters, len); + return VCHR11RET_ISOK; +} + + +vcHr11Ret_t vcHr11ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len) +{ + hrsensor_read_nbyte(DEV_R_ADDR, startAddress, pRegisters, len); + return VCHR11RET_ISOK; +} + +u8 vcHr11CheckChipID(void) +{ + u8 id = 0; + + for (u8 i = 0; i < 5; i++) { + vcHr11ReadRegisters(VCREG0, &id, VCREG0_SIZE); + if (0x21 == id || 0x29 == id) { + LOG("ok!"); + return true; + } + mdelay(10); + } + + LOG("err! id=0x%02x", id); + return false; +} + + +void vcHr11Start(vcHr11Mode_t vcHr11WorkMode) +{ + vcHr11_t *pVcHr11 = &vcHr11; + + LOG("mode=%d", vcHr11WorkMode); + + vcHr11SoftReset(pVcHr11); + vcHr11StopSample(pVcHr11); + + memset(&vcHrData, 0, sizeof(vcHrData_t)); + vcHrData.workMode = vcHr11WorkMode; + + if (VCWORK_MODE_POWER_OFF != vcHr11WorkMode) { + + pVcHr11->vcSampleRate = vcHr11SampleRate; + pVcHr11->mcuOscValue = mcuOscData; + pVcHr11->mcuSclRate = mcuI2cClock; + pVcHr11->workMode = vcHr11WorkMode; + + vcHr11StartSample(pVcHr11); + } +} + +void vcHr11DumpRawData(void) +{ + u8 accLen = vcHrData.accelLength; + if (vcHr11.workMode == VCWORK_MODE_SPO2WORK) { + u8 ppgLen = vcHrData.ppgLength / 2; + u8 dumpLen = accLen > ppgLen ? accLen : ppgLen; + LOG("dumpLen=%d accLen=%d ppgLen=%d", dumpLen, accLen, ppgLen); + for (u8 i = 0; i < dumpLen; i++) { + LOG(" no%02d ppg: %d %d accel: %d %d %d", i + 1, vcHrData.ppgValue[i * 2], vcHrData.ppgValue[i * 2 + 1], + vcHrData.accel_buf[i].x, vcHrData.accel_buf[i].y, vcHrData.accel_buf[i].z); + } + } else { + u8 ppgLen = vcHrData.ppgLength; + u8 dumpLen = accLen > ppgLen ? accLen : ppgLen; + LOG("dumpLen=%d accLen=%d ppgLen=%d", dumpLen, accLen, ppgLen); + for (u8 i = 0; i < dumpLen; i++) { + LOG(" no%02d ppg: %d %d accel: %d %d %d", i + 1, vcHrData.ppgValue[i], 0, + vcHrData.accel_buf[i].x, vcHrData.accel_buf[i].y, vcHrData.accel_buf[i].z); + } + + } +} + +void vcHr11UpdateToMater(void) +{ + //小核800ms写入一次,主核1000ms读取一次,比较坏的情况会小核写2次,主核读一次 + if (cbuf_get_data_len(data_w_cbuf[0]) > sizeof(vcHrData_t)) { + cbuf_clear(data_w_cbuf[0]); + LOG("full"); + } + cbuf_write(data_w_cbuf[0], &vcHrData, sizeof(vcHrData_t)); + // vcHr11DumpRawData(); + vcHrData.ppgLength = 0; + vcHrData.accelLength = 0; +} + + +int vcHr11Process(u32 *buf) +{ + u16 buf_len = 0; + + // LOG("sr=%d",vcHr11.vcSampleRate); + if (vcHr11.vcSampleRate == vcHr11SampleRate) { + u8 ppgLength = 0; + vcHr11GetSampleValues(&vcHr11, &ppgLength); + LOG("oscFlg=%d ppgLength=%d readFlg=%d wearStatus=%d", vcHr11.oscCheckFinishFlag, ppgLength, vcHr11.vcFifoReadFlag, vcHr11.wearStatus); + + if (vcHr11.workMode == VCWORK_MODE_CROSSTALKTEST) { + if (vcHrData.maxLedCur != vcHr11.sampleData.maxLedCur || + vcHrData.preValue[0] != vcHr11.sampleData.preValue[0] || vcHrData.preValue[1] != vcHr11.sampleData.preValue[1]) { + vcHrData.maxLedCur = vcHr11.sampleData.maxLedCur; + vcHrData.preValue[0] = vcHr11.sampleData.preValue[0]; + vcHrData.preValue[1] = vcHr11.sampleData.preValue[1]; + LOG("CROSSTALKTEST: %d %d", vcHr11.sampleData.maxLedCur, vcHr11.sampleData.preValue[0]); + vcHr11UpdateToMater(); + } + } else if (vcHr11.vcFifoReadFlag && vcHr11.wearStatus) { + vcHr11.vcFifoReadFlag = 0; + + if (ppgLength > 0) { + memcpy(&vcHrData.ppgValue[vcHrData.ppgLength], vcHr11.sampleData.ppgValue, ppgLength * sizeof(u16)); + } + + vcHrData.wearState = vcHr11.wearStatus; + vcHrData.workMode = vcHr11.workMode; + vcHrData.ppgLength = vcHrData.ppgLength + ppgLength; + + if (vcHr11.workMode == VCWORK_MODE_HRWORK && vcHrData.ppgLength >= 20 || + vcHr11.workMode == VCWORK_MODE_SPO2WORK && vcHrData.ppgLength >= 40) { + vcHr11UpdateToMater(); + } + + } else if (vcHrData.wearState != vcHr11.wearStatus) { + vcHrData.wearState = vcHr11.wearStatus; + vcHrData.workMode = vcHr11.workMode; + vcHrData.ppgLength = 0; + vcHr11UpdateToMater(); + } + + + } + return buf_len; +} + + +void vcHr11AccelDataInput(void *accel, u8 point) +{ +#if ACCLE_EN + if (vcHr11.workMode == VCWORK_MODE_HRWORK || vcHr11.workMode == VCWORK_MODE_SPO2WORK) { + + LOG("point=%d", point); + u8 toal = vcHrData.accelLength + point; + + if (ACCLE_BUF_MAX > toal) { + memcpy(&vcHrData.accel_buf[vcHrData.accelLength], accel, point * sizeof(axis_info_t)); + vcHrData.accelLength = toal; + } + } +#endif +} + + +extern u32 get_lp_time_cnt; +uint32_t vcHr11GetRtcCountFromMCU(void) +{ + LOG("timer_cnt = %d", get_lp_time_cnt); + return get_lp_time_cnt; +} + + +u8 vcHr11PreInit(cbuffer_t *hrcbuf, cbuffer_t *spo2cbuf) +{ + if (!hrcbuf || !spo2cbuf) { + ASSERT(0); + } + data_w_cbuf[0] = hrcbuf; + data_w_cbuf[1] = spo2cbuf; + + cbuf_init(data_w_cbuf[0], hrdata, sizeof(hrdata)); + cbuf_init(data_w_cbuf[1], hrdata, sizeof(hrdata)); + + return vcHr11CheckChipID(); +} + +int vcHr11IoCtl(u8 cmd, void *arg) +{ + // LOG("cmd=%d",cmd); + + int *data; + int *msg = (int *)arg; + int len; + int ret = 0; + + switch (cmd) { + case HR_SENSOR_ENABLE: + vcHr11Start(VCWORK_MODE_HRWORK); + break; + case HR_SENSOR_DISABLE: + vcHr11Start(VCWORK_MODE_POWER_OFF); + break; + case SPO2_SENSOR_ENABLE: + vcHr11Start(VCWORK_MODE_SPO2WORK); + break; + case SPO2_SENSOR_DISABLE: + vcHr11Start(VCWORK_MODE_POWER_OFF); + break; + case HR_SENSOR_LP_DETECTION: + vcHr11Start(VCWORK_MODE_LPDETECTION); + break; + case HR_SENSOR_FACTORY_TEST: + vcHr11Start(VCWORK_MODE_CROSSTALKTEST); + break; + + case HR_SEARCH_SENSOR: { + int valid = vcHr11CheckChipID(); + memcpy(arg, &valid, 4); + break; + } + case HR_SENSOR_IRQ: + ret = vcHr11Process(arg); + break; + + default: + break; + } + return ret; +} + +REGISTER_HR_SENSOR(hrSensor) = { + .logo = "vchr11s", + .heart_rate_sensor_init = vcHr11PreInit, + .heart_rate_sensor_check = NULL, + .heart_rate_sensor_ctl = vcHr11IoCtl, + .accel_data_input = vcHr11AccelDataInput, +} ; + +#endif \ No newline at end of file diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c new file mode 100644 index 0000000..09baeda --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c @@ -0,0 +1,44 @@ +#if defined(DUG_VCXX_BLOOD_OXYGEN_SUPPORT)&&DUG_VCXX_BLOOD_OXYGEN_SUPPORT +vcxxSendDugBuff[algoCallNum * 18 + 0] = sampleData->ppgValue[2 * algoCallNum] >> 8 & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 1] = sampleData->ppgValue[2 * algoCallNum] & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 2] = sampleData->ppgValue[2 * algoCallNum + 1] >> 8 & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 3] = sampleData->ppgValue[2 * algoCallNum + 1] & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 4] = algoInputData.axes.x >> 8 & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 5] = algoInputData.axes.x & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 6] = algoInputData.axes.y >> 8 & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 7] = algoInputData.axes.y & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 8] = algoInputData.axes.z >> 8 & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 9] = algoInputData.axes.z & 0xff; +vcxxSendDugBuff[algoCallNum * 18 + 10] = systemParam.bloodOxygenValue; +vcxxSendDugBuff[algoCallNum * 18 + 11] = sampleData->pdResValue[1]; +vcxxSendDugBuff[algoCallNum * 18 + 12] = sampleData->pdResValue[2]; +vcxxSendDugBuff[algoCallNum * 18 + 13] = sampleData->currentValue[1]; +vcxxSendDugBuff[algoCallNum * 18 + 14] = sampleData->currentValue[2]; +vcxxSendDugBuff[algoCallNum * 18 + 15] = sampleData->psValue; +vcxxSendDugBuff[algoCallNum * 18 + 16] = vcSportFlag; +vcxxSendDugBuff[algoCallNum * 18 + 17] = vcxxDugIrgCnt; +vcxxDugIrgCnt++; +#endif + + + +#if defined(DUG_VCXX_HR_OXYGEN_SUPPORT)&&DUG_VCXX_HR_OXYGEN_SUPPORT +vcxxSendDugBuff[i * 15] = algoInputData.ppgSample >> 8 & 0xff; +vcxxSendDugBuff[i * 15 + 1] = algoInputData.ppgSample & 0xff; +vcxxSendDugBuff[i * 15 + 2] = algoInputData.axes.x >> 8 & 0xff; +vcxxSendDugBuff[i * 15 + 3] = algoInputData.axes.x & 0xff; +vcxxSendDugBuff[i * 15 + 4] = algoInputData.axes.y >> 8 & 0xff; +vcxxSendDugBuff[i * 15 + 5] = algoInputData.axes.y & 0xff; +vcxxSendDugBuff[i * 15 + 6] = algoInputData.axes.z >> 8 & 0xff; +vcxxSendDugBuff[i * 15 + 7] = algoInputData.axes.z & 0xff; +vcxxSendDugBuff[i * 15 + 8] = drvHeartVcxxGetValue() & 0xff; +vcxxSendDugBuff[i * 15 + 9] = sampleData->pdResValue[0]; +vcxxSendDugBuff[i * 15 + 10] = sampleData->currentValue[0]; +vcxxSendDugBuff[i * 15 + 11] = sampleData->envValue[2]; +vcxxSendDugBuff[i * 15 + 12] = sampleData->preValue[0]; +vcxxSendDugBuff[i * 15 + 13] = sampleData->psValue; +vcxxSendDugBuff[i * 15 + 14] = vcxxDugIrgCnt; +vcxxDugIrgCnt++; +#endif + + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c new file mode 100644 index 0000000..5e3e4f4 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c @@ -0,0 +1,1033 @@ +#include "app_config.h" +#include "vcHr11Hci.h" + +#if defined(TCFG_VCHR11S_DEV_ENABLE) && TCFG_VCHR11S_DEV_ENABLE + +static uint32_t lastRtcValue = 0; +static uint8_t ledCurrent[SLOTCHNU], ledMaxCurrent[SLOTCHNU] = {0x6f, 0x6f, 0x6f}; +static uint8_t pdRes[SLOTCHNU], pdResMax[SLOTCHNU] = {7, 7, 7}; +static uint8_t pdResSet[SLOTCHNU], ppgGain[SLOTCHNU]; +static uint8_t recordEnv[SLOTCHNU] = {0, 0, 0}, pdBias = 0; +static uint16_t count_pdRes[SLOTCHNU], count_QaPdRes[SLOTCHNU]; +static uint8_t adjustFlag[2][64], fifoRear = 0; +static uint8_t slotCount, sampleIndex, totalSlot = 0, readIndex = 0, readCnt = 0; +static uint8_t fifoWriteIndex = 0, fifoReadIndex = 0x80, fifoIntDiv = 0; +static uint8_t enFifo, enSlot[SLOTCHNU]; +static uint16_t oscCnt = 0, cntCalOsc = 0; +static uint32_t intDiffRtc[8] = {0}, intDiffAdj[8] = {0}; +static uint8_t oscDifSetting = 2; +static uint8_t fifoIntTim = (25 - 6); +static uint8_t PSIntTim = (24); /* (n+1)*40=1sec */ + +extern int HeartRateValue; + +#if SportMotionEn +int32_t gsensor_abs_xyz_sum_last_tick; +int32_t gsensor_abs_xyz_sum_current_tick; +int32_t gsensor_abs_xyz_diff_value; + +/* + * @brief + * + * + **/ +void green_led_off_state_gsensor_abs_sum_diff_init_func(void) +{ + gsensor_abs_xyz_sum_current_tick = 0; + gsensor_abs_xyz_sum_last_tick = 0; + gsensor_abs_xyz_diff_value = 0; +} + +/* + * @brief + * + * + **/ +void green_led_off_state_gsensor_abs_sum_diff_func(int32_t x_axis_value, int32_t y_axis_value, int32_t z_axis_value) +{ + int32_t x_axis_value_current = x_axis_value; + int32_t y_axis_value_current = y_axis_value; + int32_t z_axis_value_current = z_axis_value; + + gsensor_abs_xyz_sum_last_tick = gsensor_abs_xyz_sum_current_tick; + if (x_axis_value < 0) { + x_axis_value_current = -x_axis_value; // modify by Tatum + } + if (y_axis_value < 0) { + y_axis_value_current = -y_axis_value; + } + if (z_axis_value < 0) { + z_axis_value_current = -z_axis_value; + } + + gsensor_abs_xyz_sum_current_tick = x_axis_value_current + y_axis_value_current + z_axis_value_current; + if (gsensor_abs_xyz_sum_current_tick && gsensor_abs_xyz_sum_last_tick) { + gsensor_abs_xyz_diff_value = gsensor_abs_xyz_sum_last_tick - gsensor_abs_xyz_sum_current_tick; + } else { + gsensor_abs_xyz_diff_value = 0; + } + if (gsensor_abs_xyz_diff_value < 0) { + gsensor_abs_xyz_diff_value = -gsensor_abs_xyz_diff_value; + } +} +#endif + +/* + * @brief + * Function:Get the FifoIntDiv and slotNum Configuration + * + **/ +static void vcHr11ConfigInit(vcHr11_t *pvcHr11) +{ + fifoIntDiv = (pvcHr11->regConfig[3] & 0x3f); + enFifo = (fifoIntDiv != 0) ? 1 : 0; + enSlot[0] = pvcHr11->regConfig[0] & 0x01; // Get Slot0 Status. + enSlot[1] = (pvcHr11->regConfig[0] & 0x02) >> 1; // Get Slot1 Status. + totalSlot = (pvcHr11->regConfig[0] & 0x03) == 3 ? 2 : ((pvcHr11->regConfig[0] & 0x03) == 0 ? 0 : 1); + + pvcHr11->adjustInfo[0].step = 4; + pvcHr11->adjustInfo[0].directionLast = VCHR11ADJUSTDIRECTION_NULL; + pvcHr11->adjustInfo[0].direction = VCHR11ADJUSTDIRECTION_NULL; + + pvcHr11->wearStatus = VCHR11WEARST_ISWEAR; + + pvcHr11->vcPsFlag = 0; + pvcHr11->vcFifoReadFlag = 0; + fifoRear = (pvcHr11->devId == 0x29) ? 32 : 64; + + pvcHr11->unWearCnt = VCUNWEAR_CNT; + pvcHr11->isWearCnt = VCISWEAR_CNT; + if (pvcHr11->devId == 0x29) { + ledMaxCurrent[0] = 0x5f; + ledMaxCurrent[1] = 0x5f; + } else { + ledMaxCurrent[0] = 0x6f; + ledMaxCurrent[1] = 0x6f; + } + pdResMax[0] = 7; + pdResMax[1] = 7; + recordEnv[0] = 0; + recordEnv[1] = 0; +} + +/* + * @brief + * Function:Get the Dev ID And distinguish the chip version + * + **/ +static vcHr11Ret_t vcHr11ReadVerison(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint8_t chipVersion = 0; + uint8_t edition[17] = {0x84, 0x3F, 0x8A, 0x00, 0x07, 0xCF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x56, 0x16, 0x00}; + + ret |= vcHr11WriteRegisters(VCREG11, edition, 17); + + ret |= vcHr11ReadRegisters(VCREG0, (uint8_t *)&pvcHr11->devId, VCREG0_SIZE); + + ret |= vcHr11ReadRegisters(VCREG1, (uint8_t *)&chipVersion, VCREG1_SIZE); + + pvcHr11->version = ((chipVersion & 0x04) != 0) ? VERSION_A : VERSION_B; + + vcHr11SoftReset(pvcHr11); + return ret; +} + +/* + * @brief + * Function:Initialize vcHr11's register Settings + * + **/ +static vcHr11Ret_t vcHr11RegInit(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + uint8_t i = 0; + uint8_t regConfig[17] = {0x01, 0x27, 0x8A, 0x40, 0x03, 0x1F, 0x00, 0x00, 0x80, 0x4A, + 0x57, 0x37, 0x47, + 0x16, 0x56, 0x16, 0x00 + }; + fifoIntTim = pvcHr11->vcSampleRate - 6; + regConfig[3] = (fifoIntTim) | regConfig[3]; + switch (pvcHr11->workMode) { + case VCWORK_MODE_HRWORK: + regConfig[0] = 0x05; +#if HW_HALVE_POWER_CAP + regConfig[10] = 0x54; + regConfig[13] = 0x03; // + regConfig[16] = 0x01; +#endif + break; + + case VCWORK_MODE_SPO2WORK: + regConfig[0] = 0x07; + regConfig[1] = 0x2F; + regConfig[6] = 0; + regConfig[7] = 0x80; + regConfig[13] = 0x96; + regConfig[16] = 0x04; // OverSample + break; + + case VCWORK_MODE_CROSSTALKTEST: + regConfig[0] = 0x05; + regConfig[1] = 0x3F; +#if !HW_HALVE_POWER_CAP + regConfig[7] = 0xEF; + regConfig[10] = 0x77; +#else + regConfig[7] = 0xEF; // 0xDF; + regConfig[10] = 0x74; // 0x77; + regConfig[13] = 0x03; // 0x16 + regConfig[16] = 0x01; +#endif + break; + + case VCWORK_MODE_NOISEWORK: + regConfig[0] = 0x05; + regConfig[10] = 0x57; + regConfig[13] = 0x16; + regConfig[16] = 0x00; +#if HW_HALVE_POWER_CAP + regConfig[10] = 0x54; + regConfig[13] = 0x03; + regConfig[16] = 0x01; +#endif + break; + + case VCWORK_MODE_LPDETECTION: + regConfig[0] = 0x04; + regConfig[1] = 0x30; + regConfig[6] = PSIntTim; +#if HW_HALVE_POWER_CAP + regConfig[10] = 0x54; + regConfig[13] = 0x03; + regConfig[16] = 0x01; +#endif + break; + + default: + break; + } + + if (pvcHr11->devId == 0x29) { + // Since VC010 has only one PPG channel, the fifo depth is reduced from the original 64 sampling points to 32 sampling points. + // Set the B5 position of fifointdiv to 0 on the driver to reduce the depth of fifo. + regConfig[3] = 0xDF & regConfig[3]; // set B5 to 0 reduce the Fifo's length + regConfig[9] = 0x4A; + regConfig[10] = 0x5E; + regConfig[13] = 0x3C; +#if HW_HALVE_POWER_CAP + regConfig[10] = 0x57; + regConfig[13] = 0x16; + regConfig[16] = 0x01; +#endif + if (pvcHr11->workMode == VCWORK_MODE_CROSSTALKTEST) { + regConfig[7] = 0xDF; + } + /******************************* + * HW_LC09A_PROJ,20220915 + *******************************/ +#if HW_LC09A_PROJ + regConfig[9] = 0xD0;/* HS+0xD0(40mA) */ + regConfig[12] = 0x77; +#if 1 /* 100us */ + regConfig[10] = 0x57; + regConfig[13] = 0x96; +#else /* 200us */ + regConfig[10] = 0x5E; + regConfig[13] = 0xBC; +#endif + regConfig[16] = 0x00; +#endif + } + for (i = 0; i < 17; i++) { + pvcHr11->regConfig[i] = regConfig[i]; + DEBUG_LOG("regConfig[%d]=0x%2x", i, pvcHr11->regConfig[i]); + } + ret |= vcHr11WriteRegisters(VCREG11, pvcHr11->regConfig, 17); + pvcHr11->regConfig[0] = 0x80 | regConfig[0]; + ret |= vcHr11WriteRegisters(VCREG11, pvcHr11->regConfig, 1); + vcHr11ConfigInit(pvcHr11); + + return ret; +} + +/* + * @brief + * Function: + * + **/ +vcHr11Ret_t vcHr11StartSample(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + ret |= vcHr11ReadVerison(pvcHr11); + /* Add the delay */ + ret |= vcHr11RegInit(pvcHr11); + + return ret; +} + +/* + * @brief + * Function: shut down the logic channel + * workmode = sleepmode + * + **/ +vcHr11Ret_t vcHr11StopSample(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint8_t modeCtrl = 0x00; // Shut down all logic solt and goto sleep mode + ret |= vcHr11WriteRegisters(VCREG11, (uint8_t *)&modeCtrl, VCREG11_SIZE); + return ret; +} + +/* + * @brief + * Function: Added adjust flag when interrupt happend. + * Provides it for algorithmic processing. + * + **/ +static vcHr11Ret_t vcHr11AddAdjustFlag(uint8_t slotNum) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + /* If FIFOIntDiv equal to 0, FIFO Function isn't enabled */ + if (fifoIntDiv == 0) { + adjustFlag[slotNum][0] = 1; + } else { + ret |= vcHr11ReadRegisters(VCREG3, (uint8_t *)&fifoWriteIndex, VCREG3_SIZE); + sampleIndex = (fifoWriteIndex - 0x80) / 2 / totalSlot; + if (sampleIndex == 0) { + // sampleIndex = totalSlot == 1 ? 63 : 31; + sampleIndex = totalSlot == 1 ? fifoRear - 1 : (fifoRear / 2) - 1; + } else { + sampleIndex = sampleIndex - 1; + } + adjustFlag[slotNum][sampleIndex] = 1; + } + return ret; +} + +/* + * @brief + * Function: Read data from FIFO + * If there is an adjustment, an adjustment flag is added + * + **/ +static vcHr11Ret_t vcHr11OutPutPPGData(vcHr11_t *pvcHr11, uint8_t StartIndex, uint16_t StopIndex, uint8_t IndexFlag) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint16_t i = 0; + uint8_t dataLength = 0; + uint8_t sampleData[128]; + + dataLength = StopIndex - StartIndex; + ret |= vcHr11ReadRegisters(StartIndex, sampleData, dataLength); + + for (i = StartIndex; i < StopIndex; i = i + 2) { // If i set to uint8_t and i = 254,i will overflow + pvcHr11->sampleData.ppgValue[(i - StartIndex) / 2 + IndexFlag] = ((sampleData[(i - StartIndex)] << 8) | sampleData[(i - StartIndex) + 1]); + slotCount = ((i - 0x80) % (totalSlot * 2)) / 2; + sampleIndex = (i - 0x80) / (totalSlot * 2); + if (adjustFlag[slotCount][sampleIndex] == 1) { + pvcHr11->sampleData.ppgValue[(i - StartIndex) / 2 + IndexFlag] |= 0x1000; + adjustFlag[slotCount][sampleIndex] = 0; + } + } + return ret; +} + +/* + * @brief + * Function:Clock Calibration + * + **/ +uint16_t vcHr11CalculateOSCFreq(vcHr11_t *pvcHr11) +{ + + uint8_t clkAdjCnt[4] = {0}, newFreDiv[2] = {0}, i = 0; + // uint8_t vcAdj_Th,vcRtc_Th, + uint32_t rtcCount[2]; + uint16_t adjCount[2], freDiv[2] = {0}; + uint16_t newDiv, f20kOsc; + + bool diffCountIsOk = true; + bool diffIsOK; + + rtcCount[0] = vcHr11GetRtcCountFromMCU(); // Get McuRtcCount + vcHr11ReadRegisters(VCREG7, clkAdjCnt, 4); + rtcCount[1] = vcHr11GetRtcCountFromMCU(); // Get McuRtcCount + + adjCount[0] = clkAdjCnt[0] << 8 | clkAdjCnt[1]; + adjCount[1] = clkAdjCnt[2] << 8 | clkAdjCnt[3]; + + if (adjCount[1] < adjCount[0] || rtcCount[1] < rtcCount[0]) { + cntCalOsc = 0; + return 0; + } + + intDiffAdj[2 * cntCalOsc] = adjCount[0]; + intDiffAdj[2 * cntCalOsc + 1] = adjCount[1]; + + intDiffRtc[2 * cntCalOsc] = rtcCount[0]; + intDiffRtc[2 * cntCalOsc + 1] = rtcCount[1]; + + cntCalOsc += 1; + + if (cntCalOsc >= 3) { + cntCalOsc = 0; + for (i = 0; i < 2; i++) { + diffCountIsOk = (((intDiffRtc[2 * i + 2] - intDiffRtc[2 * i]) - (intDiffRtc[2 * i + 3] - intDiffRtc[2 * i + 1]) <= oscDifSetting) || ((intDiffRtc[2 * i + 3] - intDiffRtc[2 * i + 1]) - (intDiffRtc[2 * i + 2] - intDiffRtc[2 * i]) <= oscDifSetting)) && diffCountIsOk; + diffCountIsOk = (((intDiffAdj[2 * i + 2] - intDiffAdj[2 * i]) - (intDiffAdj[2 * i + 3] - intDiffAdj[2 * i + 1]) <= 2) || ((intDiffAdj[2 * i + 3] - intDiffAdj[2 * i + 1]) - (intDiffAdj[2 * i + 2] - intDiffAdj[2 * i]) <= 2)) && diffCountIsOk; + } + if (diffCountIsOk) { + for (i = 0; i < 2; i++) { + if (intDiffRtc[2 * i + 2] == intDiffRtc[2 * i]) { + cntCalOsc = 0; + return 0; + } + freDiv[i] = ((uint32_t)(intDiffAdj[2 * i + 2] - intDiffAdj[2 * i])) * pvcHr11->mcuOscValue / pvcHr11->vcSampleRate / ((uint32_t)(intDiffRtc[2 * i + 2] - intDiffRtc[2 * i])) - 1; + if (freDiv[i] < (20000 / pvcHr11->vcSampleRate * 0.75f) || freDiv[i] > (20000 / pvcHr11->vcSampleRate * 1.25f)) { + return 0; + } + } + + diffIsOK = (freDiv[1] - freDiv[0] <= 20) || (freDiv[0] - freDiv[1] <= 20); + if (diffIsOK) { + newDiv = (freDiv[1] + freDiv[0]) / 2; + f20kOsc = (newDiv + 1) * pvcHr11->vcSampleRate; + newFreDiv[0] = newDiv >> 8; + newFreDiv[1] = newDiv; + vcHr11WriteRegisters(VCREG15, newFreDiv, VCREG15_SIZE); + pvcHr11->oscCheckFinishFlag = 1; + oscCnt = 0; + } + } else { + return 0; + } + } + pvcHr11->oscCheckFinishFlag = 1; //强制校准通过 + return f20kOsc; +} + +/* + * @brief + * Function: Wear monitoring. + * + **/ +static vcHr11Ret_t vcHr11WearStatusDetection(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint8_t newSoltChNu = 0; + uint8_t enPs = (pvcHr11->regConfig[1] & 0xf0) | 0x10; + switch (pvcHr11->wearStatus) { + // Identify whether the wearing state needs to be switched + // Wear status from unWear to isWear + case VCHR11WEARST_UNWEAR: +#if SportMotionEn + if ((pvcHr11->sampleData.psValue >= VCPS_TH) && (pvcHr11->sampleData.envValue[2] < 3) && (gsensor_abs_xyz_diff_value > 20)) +#else + if ((pvcHr11->sampleData.psValue >= VCPS_TH) && (pvcHr11->sampleData.envValue[2] < 3)) +#endif + { + if (--pvcHr11->isWearCnt <= 0) { // Once time + pvcHr11->wearStatus = VCHR11WEARST_ISWEAR; + pvcHr11->unWearCnt = VCUNWEAR_CNT; + pvcHr11->isWearCnt = VCISWEAR_CNT; + + vcHr11SoftReset(pvcHr11); // Reset Reg to defult value + vcHr11RegInit(pvcHr11); // + ret |= VCHR11RET_UNWEARTOISWEAR; + lastRtcValue = vcHr11GetRtcCountFromMCU(); +#if SportMotionEn + green_led_off_state_gsensor_abs_sum_diff_init_func(); +#endif + } + } else { + pvcHr11->isWearCnt = VCISWEAR_CNT; + } + break; + + case VCHR11WEARST_ISWEAR: +#if BiometricEn + if ((pvcHr11->sampleData.psValue < VCPS_TH) || (pvcHr11->sampleData.envValue[2] > VCENV_TH) || (HeartRateValue == -1)) { + if (HeartRateValue == -1) { + pvcHr11->unWearCnt = 1; + } + if (--pvcHr11->unWearCnt <= 0) { // 3 times. + HeartRateValue = 0; + pvcHr11->wearStatus = VCHR11WEARST_UNWEAR; + pvcHr11->unWearCnt = VCUNWEAR_CNT; + pvcHr11->isWearCnt = VCISWEAR_CNT; + newSoltChNu = (pvcHr11->regConfig[0] & 0xF8) | 0x04; // Enable solt2,Disable solt0 and solt1; + pvcHr11->vcPsFlag = 1; + vcHr11WriteRegisters(VCREG16, (uint8_t *)&PSIntTim, VCREG16_SIZE); + vcHr11WriteRegisters(VCREG12, (uint8_t *)&enPs, VCREG12_SIZE); + pvcHr11->regConfig[1] |= 0x10; + ret |= vcHr11WriteRegisters(VCREG11, (uint8_t *)&newSoltChNu, VCREG11_SIZE); + ret |= VCHR11RET_ISWEARTOUNWEAR; + } + } +#else + if ((pvcHr11->sampleData.psValue < VCPS_TH) || (pvcHr11->sampleData.envValue[2] > VCENV_TH)) { + if (--pvcHr11->unWearCnt <= 0) { // 3 times. + pvcHr11->wearStatus = VCHR11WEARST_UNWEAR; + pvcHr11->unWearCnt = VCUNWEAR_CNT; + pvcHr11->isWearCnt = VCISWEAR_CNT; + newSoltChNu = (pvcHr11->regConfig[0] & 0xF8) | 0x04; // Enable solt2,Disable solt0 and solt1; + pvcHr11->vcPsFlag = 1; + vcHr11WriteRegisters(VCREG16, (uint8_t *)&PSIntTim, VCREG16_SIZE); + vcHr11WriteRegisters(VCREG12, (uint8_t *)&enPs, VCREG12_SIZE); + pvcHr11->regConfig[1] |= 0x10; + ret |= vcHr11WriteRegisters(VCREG11, (uint8_t *)&newSoltChNu, VCREG11_SIZE); + ret |= VCHR11RET_ISWEARTOUNWEAR; + } + } +#endif + else { + pvcHr11->vcPsFlag = 0; + pvcHr11->unWearCnt = VCUNWEAR_CNT; + } + break; + } + return ret; +} + +/* + * @brief + * Function: FIFO Read.(Or GetValue) + * + **/ +static vcHr11Ret_t vcHr11ReadFifo(vcHr11_t *pvcHr11, uint8_t *len) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint32_t rtcValue = 0; + uint8_t dateLength = 0; + uint8_t dataBias = 0; + uint8_t dataOverFlow = 0; + uint16_t fifoEnd = 0; + float cacheTime = 0; + + cacheTime = (pvcHr11->devId == 0x29) ? 32.0f : 64.0f; + + dataBias = (pvcHr11->devId == 0x29) ? 0x40 : 0x80; + + dataOverFlow = (pvcHr11->devId == 0x29) ? 0x20 : 0x40; + + fifoEnd = (pvcHr11->devId == 0x29) ? 192 : 256; + + ret |= vcHr11ReadRegisters(VCREG3, (uint8_t *)&fifoWriteIndex, VCREG3_SIZE); + + rtcValue = vcHr11GetRtcCountFromMCU(); + /* + uint32_t vcHr02TimeDiff; + rtcValue = vcHr02GetRtcCountFromMCU(); + if (rtcValue > lastRtcValue) + { + vcHr02TimeDiff = rtcValue - lastRtcValue; + } + else + { + vcHr02TimeDiff = (0xFFFFFF - lastRtcValue) + rtcValue; + } + if((vcHr02TimeDiff)>(((cacheTime/pvcHr02->vcSampleRate) *0.8f* pvcHr02->mcuOscValue)/ totalSlot)) + */ + if ((rtcValue - lastRtcValue) > (((cacheTime / pvcHr11->vcSampleRate) * 0.8f * pvcHr11->mcuOscValue) / totalSlot)) { + pvcHr11->vcFifoReadFlag = 0; + fifoWriteIndex = 0; + fifoReadIndex = 0x80; + lastRtcValue = rtcValue; + return VCHR11RET_FIFOISOVERFLOW; + } + + if (fifoIntDiv != 0) { // If fifoIntDiv equal to 0, FIFO Function is not enabled + if (fifoWriteIndex > fifoReadIndex) { + dateLength = (fifoWriteIndex - fifoReadIndex) / 2; + vcHr11OutPutPPGData(pvcHr11, fifoReadIndex, fifoWriteIndex, 0); + } else { + dateLength = (fifoWriteIndex + dataBias - fifoReadIndex) / 2; + + if (dateLength == dataOverFlow) { + dateLength = 0; + pvcHr11->vcFifoReadFlag = 0; + return VCHR11RET_ISERR; + } + vcHr11OutPutPPGData(pvcHr11, fifoReadIndex, fifoEnd, 0); + if (fifoWriteIndex != 0x80) { + vcHr11OutPutPPGData(pvcHr11, 0x80, fifoWriteIndex, (fifoEnd - fifoReadIndex) / 2); + } + /*if(pvcHr11->devId == 0x29) + { + DBG_DIRECT("INfifoReadIndex is: %d,INfifoWriteIndex is: %d\n", fifoReadIndex,fifoWriteIndex); + //vcHr11OutPutPPGData(pvcHr11,fifoReadIndex,fifoWriteIndex + dataBias,0); + vcHr11OutPutPPGData(pvcHr11,fifoReadIndex,192,0); + if(fifoWriteIndex != 0x80) + { + vcHr11OutPutPPGData(pvcHr11,0x80,fifoWriteIndex,(192-fifoReadIndex)/2); + } + } + else + { + vcHr11OutPutPPGData(pvcHr11,fifoReadIndex,256,0); + if(fifoWriteIndex != 0x80) + { + vcHr11OutPutPPGData(pvcHr11,0x80,fifoWriteIndex,(256-fifoReadIndex)/2); + } + }*/ + } + fifoReadIndex = fifoWriteIndex; + } else { + // Not use FIFO, the sampleData is storage in 0x80 + dateLength = totalSlot; + vcHr11OutPutPPGData(pvcHr11, fifoReadIndex, fifoReadIndex + totalSlot * 2, 0); + } + // Return the array length for data processing + *len = dateLength; + lastRtcValue = rtcValue; + return ret; +} + +/* + * @brief + * Function: Adjust PDRes Value and modify the PDResMax + * + **/ +static vcHr11Ret_t vcHr11EnvAdjust(vcHr11_t *pvcHr11, uint8_t slotNum) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + bool pdBiasFlag = false; + + if ((pvcHr11->sampleData.envValue[slotNum] > VCENV_TH) && enSlot[slotNum]) { + recordEnv[slotNum] = pvcHr11->sampleData.envValue[slotNum]; + if (pvcHr11->devId == 0x29) { + if (pdBias <= 15) { + pdBias += 1; + vcHr11AddAdjustFlag(slotNum); // Added logical adjustment flag bit + pdBiasFlag = true; + ret |= vcHr11WriteRegisters(VCREG28, (uint8_t *) & (pdBias), 1); + } + } + // If pdBias cannot resist ambient light, we can choose to sacrifice the skin level to reduce the pdRes + if (pdBiasFlag == false) { + if (pdRes[slotNum] != 0) { + pdRes[slotNum] = pdRes[slotNum] - 1; + pdResMax[slotNum] = pdRes[slotNum]; + vcHr11AddAdjustFlag(slotNum); // Added logical adjustment flag bit + pvcHr11->regConfig[slotNum + 10] = (pdRes[slotNum] << 4) | pdResSet[slotNum]; + ret |= vcHr11WriteRegisters((VCREG20 + slotNum), (uint8_t *) & (pvcHr11->regConfig[slotNum + 10]), 1); + } else { + return VCHR11RET_ENVCURRENTISLARGE; + } + } + } + if (pvcHr11->sampleData.envValue[2] > VCENV_TH) { + return VCHR11RET_PSENVCURRENTISLARGE; + } + return ret; +} + +/* + * @brief + * Function: Adjust Ledcurrent Value and modify the ledcurrentMax value + * + **/ +static vcHr11Ret_t vcHr11OvloadAdjust(vcHr11_t *pvcHr11, uint8_t slotNum) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint8_t overLoad = 0; + uint8_t ovload[SLOTCHNU]; + ret |= vcHr11ReadRegisters(VCREG1, (uint8_t *)&overLoad, VCREG1_SIZE); + // Get Slot0,Slot1 and Slot2's Overload status. + ovload[0] = overLoad & 0x01; + ovload[1] = (overLoad & 0x02) >> 1; + ovload[2] = (overLoad & 0x04) >> 2; + // Adjust led emitter and record max_led_emitter. + if ((overLoad & (pvcHr11->regConfig[0] & 0x07)) != 0) { + if (ovload[slotNum] && enSlot[slotNum]) { + if (ledCurrent[slotNum] != 0) { + ledCurrent[slotNum] = ledCurrent[slotNum] - 1; + ledMaxCurrent[slotNum] = ledCurrent[slotNum]; + vcHr11AddAdjustFlag(slotNum); + pvcHr11->regConfig[slotNum + 7] = (ledCurrent[slotNum] | ppgGain[slotNum]); + ret |= vcHr11WriteRegisters((VCREG17 + slotNum), (uint8_t *) & (pvcHr11->regConfig[slotNum + 7]), 1); + } else { + return VCHR11RET_SOLTISOVERLOAD; + } + } + if (ovload[2] && pvcHr11->version != VERSION_A) { // After the calibration of infrared channel parameters, the current and resistance will not be adjusted + return VCHR11RET_PSISOVERLOAD; + } + } + return ret; +} + +/* + * @brief + * Function: Adjust Ledcurrent Value and PDRes value + * + **/ +static vcHr11Ret_t vcHr11PPgLedCurAndPdResAdjust(vcHr11_t *pvcHr11, uint8_t slotNum, uint8_t ledcur, uint8_t pdres) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + uint8_t oldPdRes, oldLedCurrent; + uint8_t newPdRes, newLedCurrent; + + oldLedCurrent = ledCurrent[slotNum]; + newLedCurrent = oldLedCurrent; + oldPdRes = pdRes[slotNum]; + newPdRes = oldPdRes; + + if ((oldLedCurrent == ledcur) && (pvcHr11->workMode != VCWORK_MODE_NOISEWORK)) { + if (oldPdRes == pdres) { + newPdRes = oldPdRes; + return VCHR11RET_PPGCANNOTADJUSTABLE; + } else { + if (pvcHr11->adjustInfo[slotNum].direction == VCHR11ADJUSTDIRECTION_UP) { + newPdRes = (oldPdRes >= 7) ? 7 : (oldPdRes + 1); + } else { + newPdRes = (oldPdRes < 1) ? 0 : (oldPdRes - 1); + } + newLedCurrent = oldLedCurrent; + vcHr11AddAdjustFlag(slotNum); + } + } else { + if (pvcHr11->adjustInfo[slotNum].directionLast == VCHR11ADJUSTDIRECTION_NULL) { + pvcHr11->adjustInfo[slotNum].step *= 16; + } else if (pvcHr11->adjustInfo[slotNum].direction == pvcHr11->adjustInfo[slotNum].directionLast) { + if ((pvcHr11->adjustInfo[slotNum].step == 1) || (pvcHr11->adjustInfo[slotNum].step == 2)) { + pvcHr11->adjustInfo[slotNum].step = (pvcHr11->adjustInfo[slotNum].step + 1) * 16; + } else { + pvcHr11->adjustInfo[slotNum].step *= VCADJUST_INCREASE; + } + } else { + pvcHr11->adjustInfo[slotNum].step *= VCADJUST_DECREASE; + } + + pvcHr11->adjustInfo[slotNum].step = pvcHr11->adjustInfo[slotNum].step >> 4; + + pvcHr11->adjustInfo[slotNum].step = (pvcHr11->adjustInfo[slotNum].step <= VCADJUST_STEP_MIN) ? VCADJUST_STEP_MIN : pvcHr11->adjustInfo[slotNum].step; + pvcHr11->adjustInfo[slotNum].step = (pvcHr11->adjustInfo[slotNum].step >= VCADJUST_STEP_MAX) ? VCADJUST_STEP_MAX : pvcHr11->adjustInfo[slotNum].step; + + if (pvcHr11->adjustInfo[slotNum].direction == VCHR11ADJUSTDIRECTION_UP) { + newLedCurrent = ((oldLedCurrent + pvcHr11->adjustInfo[slotNum].step) > ledcur) ? ledcur : oldLedCurrent + pvcHr11->adjustInfo[slotNum].step; + } else { + newLedCurrent = (oldLedCurrent < pvcHr11->adjustInfo[slotNum].step) ? ledcur : oldLedCurrent - pvcHr11->adjustInfo[slotNum].step; + } + vcHr11AddAdjustFlag(slotNum); + newPdRes = oldPdRes; + pvcHr11->adjustInfo[slotNum].directionLast = pvcHr11->adjustInfo[slotNum].direction; + } + + ledCurrent[slotNum] = newLedCurrent; + pdRes[slotNum] = newPdRes; + + pvcHr11->regConfig[slotNum + 7] = ledCurrent[slotNum] | ppgGain[slotNum]; + ret |= vcHr11WriteRegisters((VCREG17 + slotNum), (uint8_t *) & (pvcHr11->regConfig[slotNum + 7]), 1); + pvcHr11->regConfig[slotNum + 10] = (pdRes[slotNum] << 4) | pdResSet[slotNum]; + ret |= vcHr11WriteRegisters((VCREG20 + slotNum), (uint8_t *) & (pvcHr11->regConfig[slotNum + 10]), 1); + + return ret; +} + +/* + * @brief + * Function: Get the PPG saturation direction + * + **/ +static vcHr11Ret_t vcHr11PpgAdjust(vcHr11_t *pvcHr11, uint8_t slotNum) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + uint8_t ppgDataAddress, ppgDataAddress_EnFifo; + uint8_t ppgDate[2]; + uint16_t ppgCurValue[2]; + uint8_t IndexGap; + // Get FIFOWriteIndex Value. + ret |= vcHr11ReadRegisters(VCREG3, (uint8_t *)&fifoWriteIndex, VCREG3_SIZE); + + if (totalSlot == 1) { + ppgDataAddress_EnFifo = fifoWriteIndex - totalSlot * 2; // Determine whether the FIFO is overflowing + ppgDataAddress_EnFifo = ppgDataAddress_EnFifo < 0x80 ? ppgDataAddress_EnFifo + 0x80 : ppgDataAddress_EnFifo; + ppgDataAddress = enFifo ? ppgDataAddress_EnFifo : 0x80; + } else { + ppgDataAddress_EnFifo = fifoWriteIndex - totalSlot * 2 + slotNum * 2; // Determine whether the FIFO is overflowing + ppgDataAddress_EnFifo = ppgDataAddress_EnFifo < 0x80 ? ppgDataAddress_EnFifo + 0x80 : ppgDataAddress_EnFifo; + ppgDataAddress = enFifo ? ppgDataAddress_EnFifo : 0x80 + slotNum * 2; + } + ret |= vcHr11ReadRegisters(ppgDataAddress, ppgDate, 2); + ppgCurValue[slotNum] = (ppgDate[0] << 8) | ppgDate[1]; + + if (fifoIntDiv != 0) { + IndexGap = (fifoWriteIndex > readIndex) ? (fifoWriteIndex - readIndex) : (fifoWriteIndex - readIndex + 0x80); + if (IndexGap != 2 * totalSlot) { + pvcHr11->adjustInfo[slotNum].directionLast = VCHR11ADJUSTDIRECTION_NULL; + } + readCnt += 1; + if (readCnt == totalSlot) { + readCnt = 0; + readIndex = fifoWriteIndex; + } + } + // PPG supersaturation + if (ppgCurValue[slotNum] > 4095 - VCPPG_TH * 32) { + // If the LED luminous current reaches the maximum current, + // it can only be adjusted by increasing the PD resistance + pvcHr11->adjustInfo[slotNum].direction = VCHR11ADJUSTDIRECTION_UP; + ret |= vcHr11PPgLedCurAndPdResAdjust(pvcHr11, slotNum, ledMaxCurrent[slotNum], pdResMax[slotNum]); + } + // Lower saturation + else if (ppgCurValue[slotNum] < VCPPG_TH * 32) { + pvcHr11->adjustInfo[slotNum].direction = VCHR11ADJUSTDIRECTION_DOWN; + ret |= vcHr11PPgLedCurAndPdResAdjust(pvcHr11, slotNum, 0, 0); + } + return ret; +} + +/* + * @briefs + * Function: Prejude the ENVvalue and modify the PD maximum resistance. + * Don't need to write to register + * + **/ +static vcHr11Ret_t vcHr11AdjustPDResMax(vcHr11_t *pvcHr11, uint8_t slotNum) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + uint8_t minEnv[SLOTCHNU]; + + if ((pdResMax[slotNum] == 7) && (pdBias == 0)) { + return VCHR11RET_PDRESISMAX; + } + minEnv[slotNum] = ((recordEnv[slotNum] / 2) < VCENV_TH) ? (recordEnv[slotNum] / 2) : VCENV_TH; + if (pvcHr11->sampleData.envValue[slotNum] < minEnv[slotNum]) { + if (pvcHr11->sampleData.envValue[slotNum] < 1) { + count_pdRes[slotNum] = 0; + count_QaPdRes[slotNum] = (count_QaPdRes[slotNum] == 30 * pvcHr11->vcSampleRate) ? 0 : count_QaPdRes[slotNum] + 1; + pdResMax[slotNum] = (count_QaPdRes[slotNum] == 30 * pvcHr11->vcSampleRate) ? 7 : pdResMax[slotNum]; + pdBias = (count_QaPdRes[slotNum] == 30 * pvcHr11->vcSampleRate) ? 0 : pdBias; + } else { + count_QaPdRes[slotNum] = 0; + count_pdRes[slotNum] += 1; + pdBias = (count_pdRes[slotNum] == 120 * pvcHr11->vcSampleRate) ? pdBias - 1 : pdBias; + pdResMax[slotNum] = (count_pdRes[slotNum] == 120 * pvcHr11->vcSampleRate) ? pdResMax[slotNum] + 1 : pdResMax[slotNum]; + } + } else { + count_QaPdRes[slotNum] = 0; + count_pdRes[slotNum] = 0; + } + return ret; +} + +/* + * @brief + * Function Before getsample value,prejude Status. + * + **/ +static vcHr11Ret_t vcHr11ReadStatus(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + pvcHr11->vcFifoReadFlag = 0; + uint8_t vcHr11SlotCnt = 0; + if (pvcHr11->vcHr11Status & VCREG1_CONFLICT) { + return VCHR11RET_ISCONFLICT; + } + if (pvcHr11->vcHr11Status & VCREG1_INSAMPLE) { + return VCHR11RET_ISINSAMPLE; + } +#if (VCWEAR_READ_FIFO_MODE == VCWEAR_READ_FIFO_BY_INT) //中断的方式需要判断中断原因 + if (pvcHr11->regConfig[1] & 0x10) { +#if (VCWEAR_STATUS_DETECTION_MODE != VCWEAR_STATUS_DETECTION_OFF) + if (pvcHr11->intReason & 0x10) { + ret |= vcHr11WearStatusDetection(pvcHr11); + } +#endif + } +#else //定时器的版本直接调用,因为可能PS中断原因被PPG采样清除掉 + ret |= vcHr11WearStatusDetection(pvcHr11); +#endif + if ((ret == VCHR11RET_UNWEARTOISWEAR) && (pvcHr11->wearStatus == VCHR11WEARST_ISWEAR)) { + // Set psflag to 1 when the state is switched (from unwear to iswear) + // to prevent psflag and fifoflag from being 0 at the same time + pvcHr11->vcPsFlag = 1; + } + if ((ret != VCHR11RET_UNWEARTOISWEAR) && (pvcHr11->wearStatus == VCHR11WEARST_ISWEAR)) { + // Clear the psflag that appears after the state switch (from unwear to iswear) + pvcHr11->vcPsFlag = 0; + } + for (vcHr11SlotCnt = 0; vcHr11SlotCnt < totalSlot; vcHr11SlotCnt++) { + slotCount = (totalSlot == 2) ? vcHr11SlotCnt : (enSlot[0] ? 0 : 1); + + vcHr11AdjustPDResMax(pvcHr11, slotCount); + + ledCurrent[slotCount] = pvcHr11->regConfig[7 + slotCount] & 0x7f; + ppgGain[slotCount] = pvcHr11->regConfig[7 + slotCount] & 0x80; + pdRes[slotCount] = (pvcHr11->regConfig[10 + slotCount] & 0x70) >> 4; + pdResSet[slotCount] = pvcHr11->regConfig[10 + slotCount] & 0x8F; + + if (pvcHr11->intReason & VCREG1_INTENV) { + ret |= vcHr11EnvAdjust(pvcHr11, slotCount); + } + if (pvcHr11->intReason & VCREG1_INTOV) { + ret |= vcHr11OvloadAdjust(pvcHr11, slotCount); + } + if (pvcHr11->intReason & VCREG1_INTPPG) { + ret |= vcHr11PpgAdjust(pvcHr11, slotCount); + } else { + pvcHr11->adjustInfo[slotCount].directionLast = VCHR11ADJUSTDIRECTION_NULL; + pvcHr11->adjustInfo[slotCount].direction = VCHR11ADJUSTDIRECTION_NULL; + } + } + if (pvcHr11->regConfig[1] & 0x04) { + if (pvcHr11->intReason & VCREG1_INTFIFO) { +#if (VCWEAR_STATUS_DETECTION_MODE != VCWEAR_STATUS_DETECTION_OFF) +#if (VCWEAR_READ_FIFO_MODE == VCWEAR_READ_FIFO_BY_INT) + ret |= vcHr11WearStatusDetection(pvcHr11); +#endif +#endif + pvcHr11->vcFifoReadFlag = 1; + } + } +#if VCWEAR_READ_FIFO_MODE == VCWEAR_READ_FIFO_BY_TIME + pvcHr11->vcFifoReadFlag = 1; +#endif + return ret; +} + +/* + * @brief + * Function: Read Pre and EnvValue + * + **/ +static vcHr11Ret_t vcHr11ReadReg(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + uint8_t vcRegisterValue[6] = {0}; + ret |= vcHr11ReadRegisters(VCREG1, vcRegisterValue, 6); + + pvcHr11->vcHr11Status = vcRegisterValue[0]; + pvcHr11->intReason = vcRegisterValue[1]; + + pvcHr11->sampleData.envValue[0] = vcRegisterValue[3] >> 4; + pvcHr11->sampleData.preValue[0] = vcRegisterValue[3] & 0x0F; + pvcHr11->sampleData.envValue[1] = vcRegisterValue[4] >> 4; + pvcHr11->sampleData.preValue[1] = vcRegisterValue[4] & 0x0F; + pvcHr11->sampleData.envValue[2] = vcRegisterValue[5] >> 4; + pvcHr11->sampleData.psValue = vcRegisterValue[5] & 0x0F; + DEBUG_LOG("env0=%d,env1=%d,env2=%d", pvcHr11->sampleData.envValue[0], pvcHr11->sampleData.envValue[1], pvcHr11->sampleData.envValue[2]); + DEBUG_LOG("pre0=%d,pre1=%d,psv2=%d", pvcHr11->sampleData.preValue[0], pvcHr11->sampleData.preValue[1], pvcHr11->sampleData.psValue); + + ret |= vcHr11ReadRegisters(VCREG17, vcRegisterValue, 6); + pvcHr11->sampleData.pdResValue[0] = (vcRegisterValue[3] >> 4) & 0x07; + pvcHr11->sampleData.currentValue[0] = vcRegisterValue[0] & 0x7F; + pvcHr11->sampleData.pdResValue[1] = (vcRegisterValue[4] >> 4) & 0x07; + pvcHr11->sampleData.currentValue[1] = vcRegisterValue[1] & 0x7F; + pvcHr11->sampleData.pdResValue[2] = (vcRegisterValue[5] >> 4) & 0x07; + pvcHr11->sampleData.currentValue[2] = vcRegisterValue[2] & 0x7F; + + return ret; +} + +/* + * @brief + * Function: 定时器或者中断版本,只通过宏去控制,此后的版本均通过 vcHr11GetSampleValues 该函数获取数据 + **/ +vcHr11Ret_t vcHr11GetSampleValues(vcHr11_t *pvcHr11, uint8_t *DataLen) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + int16_t secondCnt = pvcHr11->vcSampleRate * 180 / (fifoIntDiv + 1); // 3min + // int16_t secondCnt = pvcHr11->vcSampleRate*10/(fifoIntDiv+1);//10s + vcHr11ReadReg(pvcHr11); + + switch (pvcHr11->workMode) { + case VCWORK_MODE_HRWORK: + ret |= vcHr11ReadStatus(pvcHr11); + if (!pvcHr11->oscCheckFinishFlag) { + vcHr11CalculateOSCFreq(pvcHr11); // Consider the 20k Adjust to five mintures called. + } + if (pvcHr11->vcFifoReadFlag) { + oscCnt += 1; + if (oscCnt >= secondCnt) { + vcHr11CalculateOSCFreq(pvcHr11); // Consider the 20k Adjust to five mintures called. + } + if (pvcHr11->oscCheckFinishFlag) { + ret |= vcHr11ReadFifo(pvcHr11, DataLen); + } + } + break; + + case VCWORK_MODE_SPO2WORK: + ret |= vcHr11ReadStatus(pvcHr11); + if (!pvcHr11->oscCheckFinishFlag) { + vcHr11CalculateOSCFreq(pvcHr11); + } + if (pvcHr11->vcFifoReadFlag == 1) { + oscCnt += 1; + if (oscCnt >= secondCnt) { + /* Consider the 20k Adjust to three mintures called */ + vcHr11CalculateOSCFreq(pvcHr11); + } + if (pvcHr11->oscCheckFinishFlag) { + ret |= vcHr11ReadFifo(pvcHr11, DataLen); + } + } + break; + + case VCWORK_MODE_CROSSTALKTEST: + ledCurrent[0] = pvcHr11->regConfig[7] & 0x7f; + if (pvcHr11->intReason & VCREG1_INTOV) { + ret |= vcHr11OvloadAdjust(pvcHr11, 0); + } + pvcHr11->sampleData.maxLedCur = ledMaxCurrent[0]; + /* PASS??: */ + // ((pvcHr11->sampleData.maxLedCur >= 100) && (pvcHr11->sampleData.preValue[0] <= 2) + // /*Monitor ps Value*/ + // read pvcHr11->sampleData.psValue + break; + + case VCWORK_MODE_NOISEWORK: + ret |= vcHr11ReadStatus(pvcHr11); + if (pvcHr11->vcFifoReadFlag == 1) { + ret |= vcHr11ReadFifo(pvcHr11, DataLen); + } + break; + + case VCWORK_MODE_LPDETECTION: + if (!pvcHr11->oscCheckFinishFlag) { + vcHr11CalculateOSCFreq(pvcHr11); + } + oscCnt += 1; + if (oscCnt >= secondCnt) { + /* Consider the 20k Adjust to five mintures called */ + vcHr11CalculateOSCFreq(pvcHr11); + } +#if (VCWEAR_STATUS_DETECTION_MODE != VCWEAR_STATUS_DETECTION_OFF) + ret |= vcHr11WearStatusDetection(pvcHr11); +#endif + pvcHr11->vcPsFlag = 1; + break; + default: + break; + } + return ret; +} + +/* + * @brief + * Function: Soft reset to make all registor + * Write 8'h5A to 8'h3B cause soft reset. + **/ +vcHr11Ret_t vcHr11SoftReset(vcHr11_t *pvcHr11) +{ + vcHr11Ret_t ret = VCHR11RET_ISOK; + + uint8_t Reset = 0x5A; + ret |= vcHr11WriteRegisters(VCREG10, (uint8_t *)&Reset, VCREG10_SIZE); + oscCnt = 0; + pvcHr11->oscCheckFinishFlag = 0; + fifoWriteIndex = 0; + fifoReadIndex = 0x80; + return ret; +} + +#endif \ No newline at end of file diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11Hci.h b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11Hci.h new file mode 100644 index 0000000..f1b2f01 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vc11s/vcHr11Hci.h @@ -0,0 +1,291 @@ + +#ifndef LIB_vcHr11_HCI_vcHr11HCI_H_ +#define LIB_vcHr11_HCI_vcHr11HCI_H_ + +#include "stdint.h" +#include "app_config.h" +#include "includes.h" + + +#define Drive_Version V_1_9_4 + +#define HW_HALVE_POWER_CAP 1 //sample config param halve & oversample double + +/* HW_LC09A_PROJ(1), single green led + * HW_LC09A_PROJ(0), 10A/11S project + */ +#define HW_LC09A_PROJ 1 +/***************************************************************************** +* +* Register Address Declaration +* +******************************************************************************/ +/* Read Only */ +#define VCREG0 (0x00) +#define VCREG0_SIZE (1) +#define VCREG1 (0x01) +#define VCREG1_SIZE (1) +#define VCREG2 (0x02) +#define VCREG2_SIZE (1) +#define VCREG3 (0x03) +#define VCREG3_SIZE (1) +#define VCREG4 (0x04) +#define VCREG4_SIZE (1) +#define VCREG5 (0x05) +#define VCREG5_SIZE (1) +#define VCREG6 (0x06) +#define VCREG6_SIZE (1) +#define VCREG7 (0x07) +#define VCREG7_SIZE (2) +#define VCREG8 (0x09) +#define VCREG8_SIZE (2) +#define VCREG9 (0x80) +#define VCREG9_SIZE (128) + +/* Write Only */ +#define VCREG10 (0x3B) +#define VCREG10_SIZE (1) + +/* Read or Write */ +#define VCREG11 (0x10) +#define VCREG11_SIZE (1) +#define VCREG12 (0x11) +#define VCREG12_SIZE (1) +#define VCREG13 (0x12) +#define VCREG13_SIZE (1) +#define VCREG14 (0x13) +#define VCREG14_SIZE (1) +#define VCREG15 (0x14) +#define VCREG15_SIZE (2) +#define VCREG16 (0x16) +#define VCREG16_SIZE (1) +#define VCREG17 (0x17) +#define VCREG17_SIZE (1) +#define VCREG18 (0x18) +#define VCREG18_SIZE (1) +#define VCREG19 (0x19) +#define VCREG19_SIZE (1) +#define VCREG20 (0x1A) +#define VCREG20_SIZE (1) +#define VCREG21 (0x1B) +#define VCREG21_SIZE (1) +#define VCREG22 (0x1C) +#define VCREG22_SIZE (1) +#define VCREG23 (0x1D) +#define VCREG23_SIZE (1) +#define VCREG24 (0x1E) +#define VCREG24_SIZE (1) +#define VCREG25 (0x1F) +#define VCREG25_SIZE (1) +#define VCREG26 (0x20) +#define VCREG26_SIZE (1) +#define VCREG27 (0x21) +#define VCREG27_SIZE (1) +#define VCREG28 (0x22) +#define VCREG28_SIZE (1) + + +/* Bit fields for VCREG1s */ +#define VCREG1_CONFLICT (0x01 << 4) +#define VCREG1_INSAMPLE (0x01 << 3) +#define VCREG1_INTPS (0x01 << 4) +#define VCREG1_INTOV (0x01 << 3) +#define VCREG1_INTFIFO (0x01 << 2) +#define VCREG1_INTENV (0x01 << 1) +#define VCREG1_INTPPG (0x01 << 0) + +/* Threshold Settings */ +#define VCENV_TH 8 //Causes of ENV interruption +#define VCPPG_TH 10 //Causes of PPG interruption PPG_TH = 300 +#define VCPS_TH 4 +#define VCADJUST_INCREASE 22 // 1.4 << 4 = 22.4//1.4f +#define VCADJUST_DECREASE 11 // 0.7 << 4 = 11.2//0.7f +#define VCADJUST_STEP_MAX 32 +#define VCADJUST_STEP_MIN 1 + +#define VCUNWEAR_CNT 3 +#define VCISWEAR_CNT 1 + +#define SLOTCHNU 3 + +#define VCWEAR_STATUS_DETECTION_OFF 0 +#define VCWEAR_STATUS_DETECTION_ON 1 +#define VCWEAR_STATUS_DETECTION_MODE VCWEAR_STATUS_DETECTION_ON + +#define VCWEAR_READ_FIFO_BY_TIME (0) +#define VCWEAR_READ_FIFO_BY_INT (1) +#if TCFG_HR_SENSOR_READ_BY_INT +#define VCWEAR_READ_FIFO_MODE VCWEAR_READ_FIFO_BY_INT +#else +#define VCWEAR_READ_FIFO_MODE VCWEAR_READ_FIFO_BY_TIME +#endif + +#define SportMotionEn 0 +#define BiometricEn 0 + + +/***************************************************************************** +* +* Data Type Declaration +* +******************************************************************************/ +typedef enum { + VCWORK_MODE_HRWORK = 0, + VCWORK_MODE_CROSSTALKTEST = 1, + VCWORK_MODE_SPO2WORK = 2, + VCWORK_MODE_GSENSORWORK = 3, + VCWORK_MODE_TEMPWORK = 4, + VCWORK_MODE_NOISEWORK = 5, + VCWORK_MODE_LPDETECTION = 6, + VCWORK_MODE_POWER_OFF = 255, +} vcHr11Mode_t; + +typedef enum { + VCHR11ADJUSTDIRECTION_NULL = 0, + VCHR11ADJUSTDIRECTION_UP = 1, + VCHR11ADJUSTDIRECTION_DOWN = 2, +} vcHr11AdjustDirection; + +typedef enum { + VERSION_A = 0, + VERSION_B = 1, +} vcHr11Version_t; + +typedef struct { + vcHr11AdjustDirection direction; + vcHr11AdjustDirection directionLast; + uint16_t step; +} vcHr11AdjustInfo_t; + +typedef enum { + VCHR11WEARST_UNWEAR = 0, + VCHR11WEARST_ISWEAR = 1, +} vcHr11WearStatus_e; + +typedef enum { + VCHR11RET_ISOK = 0, + VCHR11RET_ISWEARTOUNWEAR = 1, + VCHR11RET_UNWEARTOISWEAR = 2, + VCHR11RET_ISERR = 4, + VCHR11RET_ISCONFLICT = 8, + VCHR11RET_ISINSAMPLE = 16, + VCHR11RET_SOLTISOVERLOAD = 32, + VCHR11RET_PSISOVERLOAD = 64, + VCHR11RET_ENVCURRENTISLARGE = 128, + VCHR11RET_PSENVCURRENTISLARGE = 256, + VCHR11RET_PPGCANNOTADJUSTABLE = 512, + VCHR11RET_FIFOISOVERFLOW = 1024, + VCHR11RET_PDRESISMAX = 2048, + VCHR11RET_PDRESCANNOTRELEASE = 4096, +} vcHr11Ret_t; + +typedef struct { + uint8_t maxLedCur; + uint8_t pdResValue[3]; + uint8_t currentValue[3]; + uint8_t psValue; //PS Sample value. + uint8_t preValue[2]; //Environment Sample value. + uint8_t envValue[3]; //Environment Sample value. + uint16_t ppgValue[128]; //PPG sample value. +} vcHr11SampleData_t; + +typedef struct { + bool isRunning; + bool vcFifoReadFlag; + bool vcPsFlag; + bool oscCheckFinishFlag; + + uint8_t regConfig[17]; + uint8_t unWearCnt; + uint8_t isWearCnt; + uint8_t vcHr11Status; + uint8_t intReason; + uint8_t devId; + vcHr11Mode_t workMode; + vcHr11Version_t version; + vcHr11WearStatus_e wearStatus; + + uint16_t vcSampleRate; + uint16_t mcuOscValue; + uint16_t mcuSclRate; + vcHr11AdjustInfo_t adjustInfo[2]; + vcHr11SampleData_t sampleData; + +} vcHr11_t; + + + +/***************************************************************************** +* Function Declaration +******************************************************************************/ +/* + * @brief + * Get sample datas from vcHr11. + * + **/ +vcHr11Ret_t vcHr11GetSampleValues(vcHr11_t *pvcHr11, uint8_t *DataLen); + +/* +* @brief +* Manual start sample of vcHr11. +* +**/ +vcHr11Ret_t vcHr11StartSample(vcHr11_t *pvcHr11); + +/* +* @brief +* Manual stop sample of vcHr11. +* +**/ +vcHr11Ret_t vcHr11StopSample(vcHr11_t *pvcHr11); + +/* +* @brief +* Manual SoftReset the vcHr11 +* +**/ +vcHr11Ret_t vcHr11SoftReset(vcHr11_t *pvcHr11); + +/* +* @brief +* init the vcHr11 +* +**/ +extern void vcHr11Init(vcHr11_t *pVcHr11, vcHr11Mode_t vcHr11WorkMode); + +/* + * @brief + * + **/ +extern vcHr11Ret_t vcHr11ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); + +/* + * @brief + * + * + **/ +extern vcHr11Ret_t vcHr11WriteRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); + +/* + * @brief + * Write Registers to vcHr11. This function needs to be implemented + * according to the MCU. + **/ +extern uint32_t vcHr11GetRtcCountFromMCU(void); + +/* + * @brief + * + * + **/ +extern void green_led_off_state_gsensor_abs_sum_diff_func(int32_t x_axis_value, int32_t y_axis_value, int32_t z_axis_value); + +typedef vcHr11Ret_t (* vcHr11_read_cb)(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); +typedef vcHr11Ret_t (* vcHr11_write_cb)(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); + + +#define DEBUG_LOG(fmt,...) //printf("[vchr] %s " fmt "\n",__func__, ##__VA_ARGS__) + + + +#endif diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/algo.h b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/algo.h new file mode 100644 index 0000000..1aea0db --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/algo.h @@ -0,0 +1,64 @@ +#ifndef APP_ALGO_ALGO_H +#define APP_ALGO_ALGO_H +#include "app_config.h" +#if TCFG_VCHR02_DEV_ENABLE +#include +#include + +typedef enum { + SPORT_TYPE_NORMAL = 0x00, // 日常 + SPORT_TYPE_RUNNING = 0x01, // 跑步 + SPORT_TYPE_RIDE_BIKE = 0X02, // 骑行 + SPORT_TYPE_JUMP_ROPE = 0X03, // 跳绳 + SPORT_TYPE_SWIMMING = 0X04, // 游泳 + SPORT_TYPE_BADMINTON = 0X05, // 羽毛球 + SPORT_TYPE_TABLE_TENNIS = 0X06, // 乒乓球 + SPORT_TYPE_TENNIS = 0X07, // 网球 + SPORT_TYPE_CLIMBING = 0X08, // 爬山 + SPORT_TYPE_WALKING = 0X09, // 徒步 + SPORT_TYPE_BASKETBALL = 0X0A, // 篮球 + SPORT_TYPE_FOOTBALL = 0X0B, // 足球 + SPORT_TYPE_BASEBALL = 0X0C, // 棒球 + SPORT_TYPE_VOLLEYBALL = 0X0D, // 排球 + SPORT_TYPE_CRICKET = 0X0E, // 板球 + SPORT_TYPE_RUGBY = 0X0F, // 橄榄球 + SPORT_TYPE_HOCKEY = 0X10, // 曲棍球 + SPORT_TYPE_DANCE = 0X11, // 跳舞 + SPORT_TYPE_SPINNING = 0X12, // 动感单车 + SPORT_TYPE_YOGA = 0X13, // 瑜伽 + SPORT_TYPE_SIT_UP = 0X14, // 仰卧起坐 + SPORT_TYPE_TREADMILL = 0X15, // 跑步机 + SPORT_TYPE_GYMNASTICS = 0X16, // 体操 + SPORT_TYPE_BOATING = 0X17, // 划船 + SPORT_TYPE_JUMPING_JACK = 0X18, // 开合跳 + SPORT_TYPE_FREE_TRAINING = 0X19,// 自由训练 +} AlgoSportMode; +//未出现在上表中的运动形式均先以跑步输入 + + +typedef struct { + int32_t x; + int32_t y; + int32_t z; +} AlgoAxesData_t; + +typedef struct { + int32_t hrData; + int32_t reliability; +} AlgoOutputData_t; + +typedef struct { + AlgoAxesData_t axes; + int32_t ppgSample; + int32_t envSample; +} AlgoInputData_t; + +void Algo_Init(void); +void Algo_Input(AlgoInputData_t *pInputData, int32_t gaptime, AlgoSportMode sportMode, int16_t surfaceRecogMode, int16_t opticalAidMode); +void Algo_Output(AlgoOutputData_t *pOutputData); + + + +#endif /*TCFG_VCHR02_DEV_ENABLE */ +#endif /* APP_ALGO_ALGO_H_ */ + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c new file mode 100644 index 0000000..379b0e1 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c @@ -0,0 +1,954 @@ + +#include "includes.h" +#include "iic_api.h" +#include "sensor_gp_timer.h" +#include "sensor_api.h" +#include "msg.h" +#include "bank_switch.h" +#include "algo.h" + +#include "app_config.h" +/* #include "os/os_api.h" */ +/* #include "asm/clock.h" */ +#include "timer.h" +/* #include "asm/cpu.h" */ +/* #include "typedef.h" */ +/* #include "generic/typedef.h" */ +#include "gpio.h" +/* #include "debug.h" */ +#include "hrSensor_manage.h" +/* #include "system/os/os_api.h" */ +/* #include "printf.h" */ +#include +#include + + +/********************************************************************************************************************* +* Copyright(c) 2020, Vcare Corporation. All rights reserved. +********************************************************************************************************************** +* @file module_heart_vc.c +* @brief Application example. +* @details + The resources needed to use this chip include an RTC or a general timer, an external interrupt line, + and an I2C interface. + First of all, confirm the count frequency of the RTC or the general timer, assign it to 'mcuOscData', + if the count frequency is 30kHz, mcuOscData = 30000; then confirm the frequency of the I2C clock, assign + it to 'mcuI2cClock', if the frequency of the I2C clock is 400kHz, mcuI2cClock = 400. + Add the code to get the RTC or the general timer count value in function 'vcHr02GetRtcCountFromMCU()', + add I2C read and write function code in 'vcHr02ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, + uint8_t len)' and 'vcHr02ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len)', but do + not change the name of the function. + How To Use The Chip: Call the program to initialize the peripherals of the main control chip first, + these peripherals include I2C, an external interrupt, RTC or general timer. Then the chip ID can be read + to verify whether the chip is working properly or whether I2C communication is normal, the register add- + ress is 0x00, if your chip is VC31B/VC32S/VC51B/VC52S, the chip ID is 0x21, but also need to verify whe- + ther your I2C supports continuous multi byte read and write, because the driver code involves continuous + multi byte read and write. After initializing the peripherals, call the chip initialization function + 'vcHr02Init(&vcHr02,vcMode)', the parameter 'vcHr02' is a defined heart rate data structure, 'vcMode' + is also defined variable which can be used to switch the chip working mode. After the initialization of + the chip is completed, the peripheral lights will be on, and the lights will be dimmed when the fingers + are close to the chip from far to near, the interrupt pin of the chip will have interrupt level. + About the function 'vcHr02_process(AlgoSportMode vcSportMode)': It can be used as an interrupt serv- + ice function or as an independent task, which is added to the task queue by the interrupt trigger, but + we strongly recommend the second one. The parameter 'vcSportMode' is a defined variable which can be us- + ed to switch the sport mode in heart rate mode. +*--------------------------------------------------------------------------------------------------------------------- +*--------------------------------------------------------------------------------------------------------------------- + 使用芯片需要的外设资源包括一个实时时钟源或者一个通用定时器(计数频率不得低于10K,最佳是在30K左右),一个外部 + 中断,一路I2C。 + 首先,确认实时时钟源或者通用定时器的计数频率,并将这个频率赋值给变量‘mcuOscData’,如果计数频率是30KHz,则 + mcuOscData = 30000;然后确认I2C的时钟频率,并将这个频率赋值给变量‘mcuI2cClock’,如果I2C的时钟频率是400KHz,则 + mcuI2cClock = 400。 + 在函数‘vcHr02GetRtcCountFromMCU()'’里添加获取实时时钟源或通用定时器的计数值的代码,注意不是返回差值(与VC31 + 和VC51不同),在函数‘vcHr02ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len)’添加I2C的读函 + 数的代码,在函数‘vcHr02ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len)’添加I2C的写函数的 + 代码,但不要改变函数名称。读函数中三个变量的意义分别是:寄存器地址、指向寄存器内容存储位置的指针(存寄存器里读 + 回来的数据的变量地址)、读的长度,写函数中三个变量的意义分别是:寄存器地址、指向要写入寄存器的内容的指针、写的 + 长度。 + 芯片使用:先调用初始化主控芯片外设的代码,初始化实时时钟源或通用定时器,I2C,外部中断,然后可以通过读芯片的 + ID来判断芯片是否正常工作或者I2C通讯是否正常,寄存器地址是0x00,如果使用的芯片是VC31B/VC32S/VC51B/VC52S,芯片的 + ID是0x21,但要确认I2C是否支持连续读写多个字节,因为驱动里涉及连续读写多个字节的操作。外设初始化完成之后,调用 + ‘vcHr02Init(&vcHr02,vcMode)’来初始化芯片,变量‘vcHr02’是已经定义的心率数据结构体,变量‘vcMode’也是已经定义的, + 可以通过改变这个变量的值,切换芯片的工作模式,初始化芯片之后,外围的等会亮,并且手指由远到近靠近时,灯会由亮到暗 + 调整,芯片的中断引脚也会有中断电平。 + 关于‘vcHr02_process(AlgoSportMode vcSportMode)’函数:可以作为中断服务函数,也可以作为独立任务,通过中断触发 + 将它添加到任务队列,但我们强烈推荐第二种方式。‘vcSportMode’是一个已经定义的在心率模式下切换运动模式的变量。 + + *若用户是用定时读取方式读取Gsensor数据,用于计步等功能,为了更好的动态心率性能,我们推荐按照我们的中断的时间间隔, + 在‘vcHr02_process(AlgoSportMode vcSportMode)’函数中对应位置,读取Gsensor数据,中断的时间间隔(佩戴状态下)可以 + 根据FIFO的长度可调(40ms整数倍)。如果用户心率非24小时连续测量方式,即进入心率测量功能界面测量心率,退出界面停止 + 心率测量或定时唤醒心率芯片测量心率方式,则调用‘vcHr02StopSample(vcHr02_t *pvcHr02)’函数让芯片进入休眠时,可以重新 + 使能定时器,定时读取Gsensor数据,因为调用上述函数使心率芯片休眠时,中断脚将不会有中断电平,‘vcHr02_process(AlgoS- + portMode_t vcSportMode)’函数将不会执行,如果用户是24小时连续心率测量,即不会休眠,可以忽略。若用户是按照Gsensor中 + 断触发读取Gsensor数据的方式,请将Gsensor读取的数据保存到buffer中,Gsensor每读一次数据就将buffer中的上一次数据用这 + 一次的数据覆盖,在‘vcHr02_process(AlgoSportMode vcSportMode)’函数中传入算法函数中。 + +* @author +* @date +* @version V1.9.7 +********************************************************************************************************************** +*/ +#include "vcHr02Hci.h" + +/* Include your INT,I2C,Timer header file */ +#include "iic_hw.h" +#include "iic_soft.h" +/* #include "asm/timer.h" */ + +#if TCFG_VCHR02_DEV_ENABLE +#define BANK_NAME BANK_SENSOR_TAG +#define log_info(format,...) printf("[vchr02]"format"\n",## __VA_ARGS__) +#define log_e(format,...) printf("[vchr02]"format"\n",## __VA_ARGS__) +#define log_error log_e + +/* extern spinlock_t sensor_iic; */ +#define MDELAY(n) mdelay(n) + +/* 如果Gsensor数据读取代码已经添加,请将这个宏置1 */ +#define GsensorEn 0 + +/* Heart rate value */ +int HeartRateValue = 0; + +//*******************************************************************************// +//定时器定时频率及变量mcuOscData iic频率及变量mcuI2cClock iic操作不可关定时器中断// +//*******************************************************************************// +/* Timer clock frequency + Be used to adjust INT frequency */ +const uint32_t mcuOscData = 22000; + +/* MCU I2C clock frequency */ +/* const uint16_t mcuI2cClock = 400; */ +const uint16_t mcuI2cClock = 150;//150k + +/* Heart rate sample frequency */ +const uint8_t vcHr02SampleRate = 25; +/*###############注意: 以上三值保证与sdk配置相同,且与实际值相同###################*/ +/*###############注意: mcuOscData提供的值vchr02_time_cnt不可被任何流程中断#############*/ +/* INT Flag */ +bool vcHr02IRQFlag = 0; + +#if VCHR02_SPO2_EN +/* Spo2 value */ +float vcSpo2Value = 0.0; +int real_spo = 0; + +/* Spo2 data */ +float vcRedPPG = 0.0; +float vcIrPPG = 0.0; +#endif + +uint16_t GsensorLength = 0; + +/* G-Sensor Data */ +int16_t xData[40] = {0}; +int16_t yData[40] = {0}; +int16_t zData[40] = {0}; + +/* The algorithm of hert rate data struct */ +AlgoInputData_t algoInputData; +AlgoOutputData_t algoOutputData; + +/* Heart rate data struct */ +vcHr02_t vcHr02; + +/* Heart rate mode */ +vcHr02Mode_t vcMode = VCWORK_MODE_HRWORK; + +/* Sport Mode In Heart Rate Mode */ +AlgoSportMode vcSportMode = SPORT_TYPE_NORMAL; + +struct vcHr02_send { + bool vcFifoReadFlag; + bool vcPsFlag; + vcHr02WearStatus_e wearStatus; + uint8_t sampleData_envValue[3]; + uint16_t sampleData_ppgValue[128]; + uint8_t ppgLength; + vcHr02Ret_t vcHr02Ret_status; +} vcHr02_sendbuf; +#define VCHR02_DATA_LEN sizeof(struct vcHr02_send) +u8 vchr02_buf[VCHR02_DATA_LEN * 5]; +static cbuffer_t *data_w_cbuf; +static u8 sensor_online = 0; +static u8 sensor_spo2_mode = 0; //1:spo2,0:hr +/* + * @brief Initialize the chip working mode and set some parameters. + * + * + **/ +void vcHr02Init(vcHr02_t *pVcHr02, vcHr02Mode_t vcHr02WorkMode) +{ + vcHr02StopSample(pVcHr02); + vcHr02SoftReset(pVcHr02); + /* vcSportMotionAlgoTerminate(); */ + pVcHr02->vcSampleRate = vcHr02SampleRate; + pVcHr02->mcuOscValue = mcuOscData; + pVcHr02->mcuSclRate = mcuI2cClock; + pVcHr02->workMode = vcHr02WorkMode; + vcHr02StartSample(pVcHr02); + /* HeartRate Mode */ + if (pVcHr02->workMode == VCWORK_MODE_HRWORK) { +#if TCFG_VCHR02_P11_ALGO_ENABLE + Algo_Init();//lib +#endif + } +#if VCHR02_SPO2_EN + /* Spo2 Mode */ + else if (pVcHr02->workMode == VCWORK_MODE_SPO2WORK) { +#if GsensorEn + vcSportMotionAlgoInit();//need gsensor +#endif +#if TCFG_VCHR02_P11_ALGO_ENABLE + vcSpo2AlgoInit();//lib +#endif + } +#endif + /* Light Crosstalk Test Mode */ + else if (pVcHr02->workMode == VCWORK_MODE_LPDETECTION) { +#if TCFG_VCHR02_P11_ALGO_ENABLE + Algo_Init();//lib +#endif + } + /* Light Crosstalk Test Mode */ + else if (pVcHr02->workMode == VCWORK_MODE_CROSSTALKTEST) { + } +} + + +/* + * @brief The processing flow under different working modes can be used as + * interrupt service function or as an independent task, but it is + * recommended to be treated as an independent task. + * + **/ +#if TCFG_VCHR02_P11_ALGO_ENABLE +void vcHr02_process(AlgoSportMode vcSportMode) +{ + /*{{{*/ + uint8_t algoCallNum = 0; + uint8_t ppgLength = 0; + uint8_t vcSportFlag = 0; + + if (vcHr02IRQFlag) { + vcHr02IRQFlag = false; + + if (vcHr02.workMode == VCWORK_MODE_HRWORK) { + if (VCHR02RET_UNWEARTOISWEAR == vcHr02GetSampleValues(&vcHr02, &ppgLength)) { + Algo_Init();//lib + } + + /* printf("ppgLength:%d\n", ppgLength); */ + if (vcHr02.vcFifoReadFlag || vcHr02.vcPsFlag) { +#if GsensorEn + + /* + Gsensor数据处理示例: + 1.此处Gsensor采样率为36Hz,定时读取方式; + 2.800mS(心率芯片FIFO长度为20,20×40ms)中断间隔时,定时方式读取Gsensor数据 + 长度众数(800ms读一次Gsensor数据,一段时间内读到29个数据的次数最多)是29; + 3.心率芯片的FIFO长度是20,所以也只要20组Gsensor数据,心率芯片FIFO长度为多少 + 就需要多少组Gsensor数据; + + */ + /* 在下一行添加读取Gsensor数据的代码 */ + /* ReadGsensorFIFO(+-4G11bit or +-8G12bit 256/g) */ + + if (GsensorLength >= 29) { + GsensorLength = 29; + } else if (GsensorLength >= 1) { + //小于29个数据补足29个; + for (uint8_t i = GsensorLength; i < 29; i++) { + xData[i] = xData[GsensorLength - 1]; + yData[i] = yData[GsensorLength - 1]; + zData[i] = zData[GsensorLength - 1]; + } + } + + for (uint8_t i = 0; i < 20; i++) { + //cash_num[20]数组为抽样数组;此处将29个数据抽成20个,匹配800mS中断的20个PPG + xData[i] = yData[cash_num[i]] >> 5; + yData[i] = xData[cash_num[i]] >> 5; + zData[i] = zData[cash_num[i]] >> 5; + } +#endif + if (vcHr02.vcFifoReadFlag) { + vcHr02.vcFifoReadFlag = 0; + if (vcHr02.wearStatus == VCHR02WEARST_ISWEAR) { +#if GsensorEn + if (GsensorLength < ppgLength) { //此处为了防止丢中断,保证每个PPG数据参与算法运算,丢中断的情况下,Gsensor数据个数补足到ppgLength; + for (uint8_t i = GsensorLength; i < ppgLength; i++) { + xData[i] = xData[GsensorLength - 1]; + yData[i] = yData[GsensorLength - 1]; + zData[i] = zData[GsensorLength - 1]; + } + } +#endif + algoInputData.envSample = vcHr02.sampleData.envValue[0]; + for (algoCallNum = 0; algoCallNum < ppgLength; algoCallNum++) { + algoInputData.ppgSample = vcHr02.sampleData.ppgValue[algoCallNum]; + algoInputData.axes.x = xData[algoCallNum];//The direction vertical with ARM. + algoInputData.axes.y = yData[algoCallNum];//The direction parallel with ARM. + algoInputData.axes.z = zData[algoCallNum];//The direction upside. + Algo_Input(&algoInputData, 1000 / vcHr02SampleRate, vcSportMode, 0, 0);//lib + } + + Algo_Output(&algoOutputData);//lib + HeartRateValue = algoOutputData.hrData; + /* printf("HeartRateValue :%d\n", HeartRateValue); */ + + if (HeartRateValue == -1) { + Algo_Init();//lib + } + } + } else { +#if SportMotionEn + green_led_off_state_gsensor_abs_sum_diff_func(xData[0], yData[0], zData[0]); +#endif + HeartRateValue = -2; + } + } + } +#if VCHR02_SPO2_EN + else if (vcHr02.workMode == VCWORK_MODE_SPO2WORK) { + if (VCHR02RET_UNWEARTOISWEAR == vcHr02GetSampleValues(&vcHr02, &ppgLength)) { + vcSpo2AlgoInit();//lib +#if GsensorEn + vcSportMotionAlgoInit();//need gsensor +#endif + } + /* printf("spo2ppgLength:%d\n", ppgLength); */ + if (vcHr02.vcFifoReadFlag || vcHr02.vcPsFlag) { +#if GsensorEn + /* ReadGsensorFIFO(+-4G11bit or +-8G12bit 256/g) */ + if (GsensorLength >= 29) { + GsensorLength = 29; + } else if (GsensorLength >= 1) { + for (uint8_t i = GsensorLength; i < 29; i++) { + xData[i] = xData[GsensorLength - 1]; + yData[i] = yData[GsensorLength - 1]; + zData[i] = zData[GsensorLength - 1]; + } + } + + for (uint8_t i = 0; i < 20; i++) { + xData[i] = yData[cash_num[i]] >> 5; + yData[i] = xData[cash_num[i]] >> 5; + zData[i] = zData[cash_num[i]] >> 5; + } +#endif + if (vcHr02.vcFifoReadFlag) { + vcHr02.vcFifoReadFlag = 0; + if (ppgLength <= 50) { + for (algoCallNum = 0; algoCallNum < ppgLength / 2; algoCallNum++) { + vcIrPPG = vcHr02.sampleData.ppgValue[algoCallNum * 2]; + vcRedPPG = vcHr02.sampleData.ppgValue[algoCallNum * 2 + 1]; + vcSpo2Value = vcSpo2Calculate(vcRedPPG, vcIrPPG);//lib +#if GsensorEn + vcSportFlag = vcSportMotionCalculate(xData[algoCallNum], yData[algoCallNum], zData[algoCallNum]); +#endif + if ((!vcSportFlag) && (vcSpo2Value > 0)) { + real_spo = vcSpo2Value; + /* printf("real_spo:%d\n", real_spo); */ + } + } + } + } else { +#if SportMotionEn + green_led_off_state_gsensor_abs_sum_diff_func(xData[0], yData[0], zData[0]); +#endif + } + } + } +#endif + else if (vcHr02.workMode == VCWORK_MODE_LPDETECTION) { + vcHr02GetSampleValues(&vcHr02, &ppgLength); + } else if (vcHr02.workMode == VCWORK_MODE_CROSSTALKTEST) { + vcHr02GetSampleValues(&vcHr02, &ppgLength); + /* If Pass: */ + if ((vcHr02.sampleData.maxLedCur >= 100) && (vcHr02.sampleData.preValue[0] <= 2)) { + //PASS: + //Display the value of vcHr02.sampleData.maxLedCur and vcHr02.sampleData.preValue[0] + } + } + } +}/*}}}*/ +#else //sdk + +void vcHr02_process(AlgoSportMode vcSportMode) +{ + uint8_t algoCallNum = 0; + uint8_t ppgLength = 0; + uint8_t vcSportFlag = 0; + if (!sensor_online) { + return ; + } + + if (vcHr02IRQFlag) { + vcHr02IRQFlag = false; + vcHr02_sendbuf.vcHr02Ret_status = vcHr02GetSampleValues(&vcHr02, &ppgLength); +#if TCFG_VCHR02_P11_ALGO_ENABLE +#else + vcHr02_sendbuf.ppgLength = ppgLength; + vcHr02_sendbuf.vcFifoReadFlag = vcHr02.vcFifoReadFlag; + vcHr02_sendbuf.vcPsFlag = vcHr02.vcPsFlag; + vcHr02_sendbuf.wearStatus = vcHr02.wearStatus; + memcpy(vcHr02_sendbuf.sampleData_envValue, vcHr02.sampleData.envValue, 3); + memcpy(vcHr02_sendbuf.sampleData_ppgValue, vcHr02.sampleData.ppgValue, 128); + /* log_info("readdata cbuf write:"); */ + if (cbuf_is_write_able(data_w_cbuf, sizeof(vcHr02_sendbuf))) { + int wlen = cbuf_write(data_w_cbuf, &vcHr02_sendbuf, sizeof(vcHr02_sendbuf)); + if (wlen == 0) { + printf("vchr02 data_w_cbuf_full\n"); + } + } else { + putchar('g');//vchr02 data_w_cbuf_full + /* return; */ + } +#endif + + if (vcHr02.workMode == VCWORK_MODE_HRWORK) { + if (VCHR02RET_UNWEARTOISWEAR == vcHr02_sendbuf.vcHr02Ret_status) { + log_error("need init algo_init()"); +#if TCFG_VCHR02_P11_ALGO_ENABLE + Algo_Init();//lib +#endif + } + + /* printf("ppgLength:%d\n", ppgLength); */ + if (vcHr02.vcFifoReadFlag || vcHr02.vcPsFlag) { +#if TCFG_VCHR02_P11_ALGO_ENABLE +#if GsensorEn/*{{{*/ + + /* + Gsensor数据处理示例: + 1.此处Gsensor采样率为36Hz,定时读取方式; + 2.800mS(心率芯片FIFO长度为20,20×40ms)中断间隔时,定时方式读取Gsensor数据 + 长度众数(800ms读一次Gsensor数据,一段时间内读到29个数据的次数最多)是29; + 3.心率芯片的FIFO长度是20,所以也只要20组Gsensor数据,心率芯片FIFO长度为多少 + 就需要多少组Gsensor数据; + + */ + /* 在下一行添加读取Gsensor数据的代码 */ + /* ReadGsensorFIFO(+-4G11bit or +-8G12bit 256/g) */ + + if (GsensorLength >= 29) { + GsensorLength = 29; + } else if (GsensorLength >= 1) { + //小于29个数据补足29个; + for (uint8_t i = GsensorLength; i < 29; i++) { + xData[i] = xData[GsensorLength - 1]; + yData[i] = yData[GsensorLength - 1]; + zData[i] = zData[GsensorLength - 1]; + } + } + + for (uint8_t i = 0; i < 20; i++) { + //cash_num[20]数组为抽样数组;此处将29个数据抽成20个,匹配800mS中断的20个PPG + xData[i] = yData[cash_num[i]] >> 5; + yData[i] = xData[cash_num[i]] >> 5; + zData[i] = zData[cash_num[i]] >> 5; + } +#endif/*}}}*/ +#endif + if (vcHr02.vcFifoReadFlag) { +#if TCFG_VCHR02_P11_ALGO_ENABLE + vcHr02.vcFifoReadFlag = 0; + if (vcHr02.wearStatus == VCHR02WEARST_ISWEAR) {/*{{{*/ +#if GsensorEn/*{{{*/ + if (GsensorLength < ppgLength) { //此处为了防止丢中断,保证每个PPG数据参与算法运算,丢中断的情况下,Gsensor数据个数补足到ppgLength; + for (uint8_t i = GsensorLength; i < ppgLength; i++) { + xData[i] = xData[GsensorLength - 1]; + yData[i] = yData[GsensorLength - 1]; + zData[i] = zData[GsensorLength - 1]; + } + } +#endif/*}}}*/ + algoInputData.envSample = vcHr02.sampleData.envValue[0]; + for (algoCallNum = 0; algoCallNum < ppgLength; algoCallNum++) { + algoInputData.ppgSample = vcHr02.sampleData.ppgValue[algoCallNum]; + algoInputData.axes.x = xData[algoCallNum];//The direction vertical with ARM. + algoInputData.axes.y = yData[algoCallNum];//The direction parallel with ARM. + algoInputData.axes.z = zData[algoCallNum];//The direction upside. + Algo_Input(&algoInputData, 1000 / vcHr02SampleRate, vcSportMode, 0, 0);//lib + } + + Algo_Output(&algoOutputData);//lib + HeartRateValue = algoOutputData.hrData; + /* printf("HeartRateValue :%d\n", HeartRateValue); */ + + if (HeartRateValue == -1) { + Algo_Init();//lib + } + }/*}}}*/ +#endif + } else { +#if SportMotionEn + green_led_off_state_gsensor_abs_sum_diff_func(xData[0], yData[0], zData[0]); +#endif + HeartRateValue = -2; + } + } + } +#if VCHR02_SPO2_EN + else if (vcHr02.workMode == VCWORK_MODE_SPO2WORK) { + if (VCHR02RET_UNWEARTOISWEAR == vcHr02_sendbuf.vcHr02Ret_status) { + log_error("need init vcSpo2AlgoInit()"); +#if TCFG_VCHR02_P11_ALGO_ENABLE + vcSpo2AlgoInit();//lib +#endif +#if GsensorEn + vcSportMotionAlgoInit();//need gsensor +#endif + } + /* printf("spo2ppgLength:%d\n", ppgLength); */ + if (vcHr02.vcFifoReadFlag || vcHr02.vcPsFlag) { +#if TCFG_VCHR02_P11_ALGO_ENABLE +#if GsensorEn/*{{{*/ + /* ReadGsensorFIFO(+-4G11bit or +-8G12bit 256/g) */ + if (GsensorLength >= 29) { + GsensorLength = 29; + } else if (GsensorLength >= 1) { + for (uint8_t i = GsensorLength; i < 29; i++) { + xData[i] = xData[GsensorLength - 1]; + yData[i] = yData[GsensorLength - 1]; + zData[i] = zData[GsensorLength - 1]; + } + } + + for (uint8_t i = 0; i < 20; i++) { + xData[i] = yData[cash_num[i]] >> 5; + yData[i] = xData[cash_num[i]] >> 5; + zData[i] = zData[cash_num[i]] >> 5; + } +#endif/*}}}*/ +#endif + if (vcHr02.vcFifoReadFlag) { +#if TCFG_VCHR02_P11_ALGO_ENABLE + vcHr02.vcFifoReadFlag = 0; + if (ppgLength <= 50) {/*{{{*/ + for (algoCallNum = 0; algoCallNum < ppgLength / 2; algoCallNum++) { + vcIrPPG = vcHr02.sampleData.ppgValue[algoCallNum * 2]; + vcRedPPG = vcHr02.sampleData.ppgValue[algoCallNum * 2 + 1]; + vcSpo2Value = vcSpo2Calculate(vcRedPPG, vcIrPPG);//lib +#if GsensorEn + vcSportFlag = vcSportMotionCalculate(xData[algoCallNum], yData[algoCallNum], zData[algoCallNum]); +#endif + if ((!vcSportFlag) && (vcSpo2Value > 0)) { + real_spo = vcSpo2Value; + /* printf("real_spo:%d\n", real_spo); */ + } + } + }/*}}}*/ +#endif + } else { +#if SportMotionEn + green_led_off_state_gsensor_abs_sum_diff_func(xData[0], yData[0], zData[0]); +#endif + } + } + } +#endif + else if (vcHr02.workMode == VCWORK_MODE_LPDETECTION) { + } else if (vcHr02.workMode == VCWORK_MODE_CROSSTALKTEST) { + /* If Pass: */ + if ((vcHr02.sampleData.maxLedCur >= 100) && (vcHr02.sampleData.preValue[0] <= 2)) { + //PASS: + //Display the value of vcHr02.sampleData.maxLedCur and vcHr02.sampleData.preValue[0] + } + } + } +} + +#endif +int read_vchr02_result(void *arg, u16 len) +{ + /* log_info("%s",__func__); */ + + if (!sensor_online) { + return 0; + } + + if (arg) { + return cbuf_read(data_w_cbuf, arg, len); + } + return cbuf_get_data_len(data_w_cbuf); +} +int vchr02_data_check_len() +{ + log_info("%s", __func__); + if (!sensor_online) { + return 0; + } + return cbuf_get_data_len(data_w_cbuf); +} +/****************************iic*****************************/ +/* #if TCFG_VCHR02_USE_IIC_TYPE */ +/* #define iic_init(iic) hw_iic_init(iic) */ +/* #define iic_uninit(iic) hw_iic_uninit(iic) */ +/* #define iic_start(iic) hw_iic_start(iic) */ +/* #define iic_stop(iic) hw_iic_stop(iic) */ +/* #define iic_tx_byte(iic, byte) hw_iic_tx_byte(iic, byte) */ +/* #define iic_rx_byte(iic, ack) hw_iic_rx_byte(iic, ack) */ +/* #define iic_read_buf(iic, buf, len) hw_iic_read_buf(iic, buf, len) */ +/* #define iic_write_buf(iic, buf, len) hw_iic_write_buf(iic, buf, len) */ +/* #define iic_suspend(iic) hw_iic_suspend(iic) */ +/* #define iic_resume(iic) hw_iic_resume(iic) */ +/* #else */ +/* #define iic_init(iic) soft_iic_init(iic) */ +/* #define iic_uninit(iic) soft_iic_uninit(iic) */ +/* #define iic_start(iic) soft_iic_start(iic) */ +/* #define iic_stop(iic) soft_iic_stop(iic) */ +/* #define iic_tx_byte(iic, byte) soft_iic_tx_byte(iic, byte) */ +/* #define iic_rx_byte(iic, ack) soft_iic_rx_byte(iic, ack) */ +/* #define iic_read_buf(iic, buf, len) soft_iic_read_buf(iic, buf, len) */ +/* #define iic_write_buf(iic, buf, len) soft_iic_write_buf(iic, buf, len) */ +/* #define iic_suspend(iic) soft_iic_suspend(iic) */ +/* #define iic_resume(iic) soft_iic_resume(iic) */ +/* #endif */ +/* static struct _vchr02_dev_platform_data *vchr02_iic_info; */ +/* */ +/* static u8 vchr02_write_reg(u8 vchr02_reg_addr, u8 *buf, u8 len) */ +/* { */ +/* #<{(| os_mutex_pend(&SENSOR_IIC_MUTEX,0); |)}># */ +/* #<{(| printf("%s",__func__); |)}># */ +/* #<{(| spin_lock(&sensor_iic); |)}># */ +/* iic_start(vchr02_iic_info->iic_hdl); */ +/* if (0 == iic_tx_byte(vchr02_iic_info->iic_hdl, VCHR02_WADDR)) { */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* log_e("vchr02 write fail1!\n"); */ +/* return false; */ +/* } */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* if (0 == iic_tx_byte(vchr02_iic_info->iic_hdl, vchr02_reg_addr)) { */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* log_e("vchr02 write fail2!\n"); */ +/* return false; */ +/* } */ +/* for (u8 i = 0; i < len; i++) { */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* if (0 == iic_tx_byte(vchr02_iic_info->iic_hdl, *(buf + i))) { */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* log_e("vchr02 write fail3!\n"); */ +/* return false; */ +/* } */ +/* } */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* #<{(| os_mutex_post(&SENSOR_IIC_MUTEX); |)}># */ +/* #<{(| spin_unlock(&sensor_iic); |)}># */ +/* return true; */ +/* } */ +/* AT(.volatile_ram_code) */ +/* static u8 vchr02_read_reg(u8 vchr02_reg_addr, u8 *read_data, u8 len) */ +/* { */ +/* #<{(| printf("%s",__func__); |)}># */ +/* #<{(| os_mutex_pend(&SENSOR_IIC_MUTEX,0); |)}># */ +/* #<{(| spin_lock(&sensor_iic); |)}># */ +/* iic_start(vchr02_iic_info->iic_hdl); */ +/* if (0 == iic_tx_byte(vchr02_iic_info->iic_hdl, VCHR02_WADDR)) { */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* log_e("vchr02 read fail1!\n"); */ +/* return false; */ +/* } */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* if (0 == iic_tx_byte(vchr02_iic_info->iic_hdl, vchr02_reg_addr)) { */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* log_e("vchr0vchr02 fail2!\n"); */ +/* return false; */ +/* } */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* iic_start(vchr02_iic_info->iic_hdl); */ +/* if (0 == iic_tx_byte(vchr02_iic_info->iic_hdl, VCHR02_RADDR)) { */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* log_e("vchr02 read fail3!\n"); */ +/* return false; */ +/* } */ +/* */ +/* for (u8 i = 0; i < len - 1; i++) { */ +/* read_data[i] = iic_rx_byte(vchr02_iic_info->iic_hdl, 1); */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* } */ +/* read_data[len - 1] = iic_rx_byte(vchr02_iic_info->iic_hdl, 0); */ +/* iic_stop(vchr02_iic_info->iic_hdl); */ +/* MDELAY(vchr02_iic_info->iic_delay); */ +/* #<{(| os_mutex_post(&SENSOR_IIC_MUTEX); |)}># */ +/* #<{(| spin_unlock(&sensor_iic); |)}># */ +/* return true; */ +/* } */ + +/* + * @brief MCU peripherals initialization. + **/ +/* void vcHr02PhyInit(void) */ +/* { */ +/***************************************************************************** +* 1.If Reset Pin of the chip is connected to MCU, initialize the corresponding +* pin on the MCU. +* +* 2.Initialize the I2C of MCU. +* +* 3.Initialize the external interrupt of MCU. +******************************************************************************/ +// hrSensor_manager.c +/* iic_init(vchr02_iic_info->iic_hdl); */ +/* #if (TCFG_VCHR02_P11_ALGO_ENABLE)//sdk wkup init */ +/* gpio_set_die(VCHR02_INT_IO, 1); */ +/* gpio_set_direction(VCHR02_INT_IO, 1); */ +/* gpio_set_pull_up(VCHR02_INT_IO, 1); */ +/* #endif */ +/* } */ + + + +/* + * @brief Register writing. + * + * + **/ +vcHr02Ret_t vcHr02WriteRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len) +{ + /********************************************************************************** + * @param + * startAddress:Register address. + * pRegisters :Point to the data to write. + * len :Byte to be transmitted. + * + * + * 7bit I2C own address:0x33 + * 8bit I2C own address:0x66(the least significant bit is the W/R control bit) + ************************************************************************************/ + hrsensor_write_nbyte(VCHR02_WADDR, startAddress, pRegisters, len); + return VCHR02RET_ISOK; +} + + +/* + * @brief Register reading. + * + * + **/ +vcHr02Ret_t vcHr02ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len) +{ + /*********************************************************************************** + * @param + * startAddress:Register address. + * pRegisters :Point to the location to save. + * len :Byte to be transmitted. + * + * + * 7bit I2C own address:0x33 + * 8bit I2C own address:0x67(the least significant bit is the W/R control bit) + ************************************************************************************/ + if (hrsensor_read_nbyte(VCHR02_RADDR, startAddress, pRegisters, len)) { + /* return VCHR02RET_ISOK; */ + } + return VCHR02RET_ISOK; +} + + +/* + * @brief Interrupt service function. + **/ +void vcHr02IRQHandler(void) +{ + if (!sensor_online) { + return ; + } + + vcHr02IRQFlag = true; + if (sensor_spo2_mode) { + sensorhub_irq_add(IRQ_SPO2SENSOR_INDEX); + } else { + sensorhub_irq_add(IRQ_HRSENSOR_INDEX); + } + putchar('V');//vchr02 data ready + user_main_post_to_p11_system(P11_SYS_KICK, 0); +} +bool vchr02_chip_check_id() +{ + int i = 0 ; + uint8_t chip_id = 0; + + if (vcHr02ReadRegisters(0x00, &chip_id, 1)) { + log_info("--vchr02 id!0x%x\n", chip_id); + if (chip_id != 0x21) { + log_error("--------read vchr02 id error!"); + return false; + } + } + log_info("--------read vchr02 id ok!"); + + return true; +} + +REGISTER_CODE_SEG(BANK_CODE_SENSOR_INIT_BANK_0) +u8 vcHr02DevInit(cbuffer_t *hrcbuf, cbuffer_t *spo2cbuf) +{ + if (!hrcbuf || !spo2cbuf) { + ASSERT(0); + } + data_w_cbuf = hrcbuf; + cbuf_init(data_w_cbuf, vchr02_buf, sizeof(vchr02_buf)); + printf("\nvchr02_buf size:%d,addr:0x%x,0x%x\n", sizeof(vchr02_buf), vchr02_buf, data_w_cbuf->begin); + + + if (vchr02_chip_check_id()) { + sensor_online = 1; + } else { + sensor_online = 0; + return false; + } + +#if (TCFG_VCHR02_P11_ALGO_ENABLE)//sdk wkup init +#ifdef CONFIG_CPU_BR23 + io_ext_interrupt_init(VCHR02_INT_IO, 1, vcHr02IRQHandler); +#elif defined(CONFIG_CPU_BR28)||defined(CONFIG_CPU_BR27) + // br28外部中断回调函数,按照现在的外部中断注册方式 + // io配置在板级,定义在板级头文件,这里只是注册回调函数 + port_edge_wkup_set_callback(vcHr02IRQHandler); +#endif +#endif + return true; +} +u8 vchr02_enable() +{ + if (!sensor_online) { + return false; + } + vcHr02Init(&vcHr02, vcMode); + return true; + +} + +REGISTER_CODE_SEG(BANK_CODE_SENSOR_NORMAL_BANK_1) +int vchr02_io_ctl(u8 cmd, void *arg) +{ + /* printf("%s cmd=%d\n",__func__,cmd); */ +// log_i("%s",__func__); + + int *data; + int *msg = (int *)arg; + int len; + int ret = 0; + + /* if (!sensor_online) { */ + /* return -1; */ + /* } */ + + switch (cmd) { + case HR_SENSOR_ENABLE: + vcMode = VCWORK_MODE_HRWORK; + vchr02_enable();//先init + printf("vchr02_enable"); + sensor_spo2_mode = 0; + //timer init + break; + case SPO2_SENSOR_ENABLE: + vcMode = VCWORK_MODE_SPO2WORK; + vchr02_enable();//先init + sensor_spo2_mode = 1; + break; + case HR_SENSOR_DISABLE: + case SPO2_SENSOR_DISABLE: + vcHr02StopSample(&vcHr02); + //close timer + cbuf_clear(data_w_cbuf); + break; + case HR_SENSOR_CHECK_DATA: + case SPO2_SENSOR_CHECK_DATA: + return vchr02_data_check_len(); + break; + case HR_SENSOR_READ_DATA: + case SPO2_SENSOR_READ_DATA: + //返回心率传感器数据 + //返回血氧传感器数据 + data = (void *)(msg[0]); + len = (int)(msg[1]); + ret = read_vchr02_result(data, len); + break; + case HR_SEARCH_SENSOR: + if (vchr02_chip_check_id() == true) { + char res = 1; + memcpy(arg, &res, 1); + } else { + char res = 0; + memcpy(arg, &res, 1); + } + break; + case HR_SENSOR_IRQ: + case SPO2_SENSOR_IRQ: + vcHr02_process(vcSportMode);//vcSportMode主机有效 + break; + + default: + break; + } + return ret; +} +REGISTER_HR_SENSOR(hrSensor) = { + .logo = "vchr02", + .heart_rate_sensor_init = vcHr02DevInit, + .heart_rate_sensor_check = NULL, + .heart_rate_sensor_ctl = vchr02_io_ctl, +} ; + + + +/****************************timer3*****************************/ + +/* + * @brief Get the count value of RTC or general timer of MCU. + * + * + **/ +extern volatile u32 vchr02_cur_time_tick;//set 20k +uint32_t vcHr02GetRtcCountFromMCU(void) +{ + /* return RTC_GetCounter(); */ + return vchr02_cur_time_tick; +} + + + +#if 0 +/* + * @brief main test. + **/ +static struct _vchr02_dev_platform_data vchr02_iic_info_test = { + .iic_hdl = 0, + .iic_delay = 0 +}; + +void vchr02_test() +{ + /*-----------INSERT BOARD HARDWARE AND SOFTWARE INITIAL FUNCTION------------*/ + /* accInit(); //Accelerometer initial +-8G 12bit */ + /* vcHr02PhyInit(); //vcHr02 board initial */ + /* vcHr02Init(&vcHr02,vcMode); */ + /* #ifdef CONFIG_CPU_BR23 */ + /* io_ext_interrupt_init(MPU9250_INT_IO, 1, vcHr02IRQHandler); */ + /* #elif defined(CONFIG_CPU_BR28)||defined(CONFIG_CPU_BR27) */ + /* // br28外部中断回调函数,按照现在的外部中断注册方式 */ + /* // io配置在板级,定义在板级头文件,这里只是注册回调函数 */ + /* port_edge_wkup_set_callback(vcHr02IRQHandler); */ + /* #endif */ + + /* vcMode = VCWORK_MODE_HRWORK; */ + vcMode = VCWORK_MODE_SPO2WORK; + if (vcHr02DevInit(NULL.NULL)) { + vchr02_enable(); + /* timerx_init(); */ + /* vchr02_chip_check_id();//read id */ + log_info("vchr02 init ok!"); + while (1) { + vcHr02_process(vcSportMode); + /* wdt_clear(); */ + } + } else { + log_info("vchr02 init fail!"); + } +} +#endif +#endif + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/spo2Algo.h b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/spo2Algo.h new file mode 100644 index 0000000..d904643 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/spo2Algo.h @@ -0,0 +1,59 @@ +/* + * File: main.h + * + * MATLAB Coder version : 3.3 + * C/C++ source code generated on : 09-Sep-2020 19:11:59 + */ + +/*************************************************************************/ +/* This automatically generated example C main file shows how to call */ +/* entry-point functions that MATLAB Coder generated. You must customize */ +/* this file for your application. Do not modify this file directly. */ +/* Instead, make a copy of this file, modify it, and integrate it into */ +/* your development environment. */ +/* */ +/* This file initializes entry-point function arguments to a default */ +/* size and value before calling the entry-point functions. It does */ +/* not store or use any values returned from the entry-point functions. */ +/* If necessary, it does pre-allocate memory for returned values. */ +/* You can use this file as a starting point for a main function that */ +/* you can deploy in your application. */ +/* */ +/* After you copy the file, and before you deploy it, you must make the */ +/* following changes: */ +/* * For variable-size function arguments, change the example sizes to */ +/* the sizes that your application requires. */ +/* * Change the example values of function arguments to the values that */ +/* your application requires. */ +/* * If the entry-point functions return values, store these values or */ +/* otherwise use them as required by your application. */ +/* */ +/*************************************************************************/ +#ifndef SPO2ALGO_H +#define SPO2ALGO_H + +#if TCFG_VCHR02_DEV_ENABLE +/* Include Files */ +#include +#include +#include +#include +#include +//#include "rt_nonfinite.h" +//#include "rtwtypes.h" +// #include "spo2_algo_interface_types.h" + +/* Function Declarations */ +extern float vcSpo2Calculate(float r_ppg, float ir_ppg); +extern void vcSpo2AlgoInit(void); +extern void vcSpo2AlgoTerminate(void); + +#endif +#endif + +/* + * File trailer for main.h + * + * [EOF] + */ + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c new file mode 100644 index 0000000..5644545 --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c @@ -0,0 +1,1096 @@ +/* #include "app_config.h" */ +/* #include "os/os_api.h" */ +/* #include "asm/clock.h" */ +/* #include "system/timer.h" */ +/* #include "asm/cpu.h" */ +/* #include "generic/typedef.h" */ +/* #include "generic/gpio.h" */ +/* #include "debug.h" */ +/* #include "hrs3603.h" */ +/* #include "hrSensor_manage.h" */ +/* #include "system/os/os_api.h" */ +#include "printf.h" +/* #include */ +/* #include */ + +#include "app_config.h" + +#if TCFG_VCHR02_DEV_ENABLE +/*************Betterlife ic debug***********/ +/* #undef LOG_TAG_CONST */ +/* #define LOG_TAG "[vchr02]" */ +/* #define LOG_ERROR_ENABLE */ +/* #define LOG_INFO_ENABLE */ +/* #include "debug.h" */ +/* */ +/* void delay(volatile u32 t); */ +/* void udelay(u32 us); */ +/* #define MDELAY(n) mdelay(n) */ + +/* struct data_sec { */ +/* u8 hrdatacnt; */ +/* u32 *hrdata; */ +/* OS_SEM hrsem; */ +/* } *datasec; */ +/* struct spo2_data { */ +/* u8 cnt; */ +/* u32 *spo2data; */ +/* OS_SEM spo2sem; */ +/* } *spo2secdata; */ + +#include "vcHr02Hci.h" +#define Drive_Version V_1_9_7 + +static uint32_t lastRtcValue = 0; +static uint8_t ledCurrent[SLOTCHNU], ledMaxCurrent[SLOTCHNU] = {0x6f, 0x6f, 0x6f}; +static uint8_t pdRes[SLOTCHNU], pdResMax[SLOTCHNU] = {7, 7, 7}; +static uint8_t pdResSet[SLOTCHNU], ppgGain[SLOTCHNU]; +static uint8_t recordEnv[SLOTCHNU] = {0, 0, 0}; +static uint16_t count_pdRes[SLOTCHNU], count_QaPdRes[SLOTCHNU]; +static uint8_t adjustFlag[2][64]; +static uint8_t slotCount, sampleIndex, totalSlot = 0, readIndex = 0, readCnt = 0; +static uint8_t fifoWriteIndex = 0, fifoReadIndex = 0x80, fifoIntDiv = 0; +static uint8_t enFifo, enSlot[SLOTCHNU]; +static uint16_t oscCnt = 0, cntCalOsc = 0; +static uint32_t intDiffRtc[8] = {0}, intDiffAdj[8] = {0}; +static uint8_t oscDifSetting = 2;//oscDifSetting = 2,mean diffrtc <= 2 +static bool slot0EnvIsExceedFlag, slot1EnvIsExceedFlag; +static uint8_t psBias = 0; +static bool psBiasReadInPdFlag = false; +extern int HeartRateValue; + +#if SportMotionEn +/* SportMotion */ +int32_t gsensor_abs_xyz_sum_last_tick; +int32_t gsensor_abs_xyz_sum_current_tick; +int32_t gsensor_abs_xyz_diff_value; + + +/* + * @brief + * + * + **/ +void green_led_off_state_gsensor_abs_sum_diff_init_func(void) +{ + gsensor_abs_xyz_sum_current_tick = 0; + gsensor_abs_xyz_sum_last_tick = 0; + gsensor_abs_xyz_diff_value = 0; +} + + +/* + * @brief + * + * + **/ +void green_led_off_state_gsensor_abs_sum_diff_func(int32_t x_axis_value, int32_t y_axis_value, int32_t z_axis_value) +{ + int32_t x_axis_value_current = x_axis_value; + int32_t y_axis_value_current = y_axis_value; + int32_t z_axis_value_current = z_axis_value; + + gsensor_abs_xyz_sum_last_tick = gsensor_abs_xyz_sum_current_tick; + if (x_axis_value < 0) { + x_axis_value_current = -x_axis_value;//modify by Tatum + } + if (y_axis_value < 0) { + y_axis_value_current = -y_axis_value; + } + if (z_axis_value < 0) { + z_axis_value_current = -z_axis_value; + } + + gsensor_abs_xyz_sum_current_tick = x_axis_value_current + y_axis_value_current + z_axis_value_current; + if (gsensor_abs_xyz_sum_current_tick && gsensor_abs_xyz_sum_last_tick) { + gsensor_abs_xyz_diff_value = gsensor_abs_xyz_sum_last_tick - gsensor_abs_xyz_sum_current_tick; + } else { + gsensor_abs_xyz_diff_value = 0; + } + if (gsensor_abs_xyz_diff_value < 0) { + gsensor_abs_xyz_diff_value = -gsensor_abs_xyz_diff_value; + } +} +#endif + + +/* + * @brief + * Get the fifoIntDiv and slotNum Configuration + * + **/ +static void vcHr02ConfigInit(vcHr02_t *pvcHr02) +{ + fifoIntDiv = (pvcHr02->regConfig[3] & 0x3f); + enFifo = (fifoIntDiv != 0) ? 1 : 0; + + /* Get Slot0 Status */ + enSlot[0] = pvcHr02->regConfig[0] & 0x01; + /* Get Slot1 Status */ + enSlot[1] = (pvcHr02->regConfig[0] & 0x02) >> 1; + + totalSlot = (pvcHr02->regConfig[0] & 0x03) == 3 ? 2 : ((pvcHr02->regConfig[0] & 0x03) == 0 ? 0 : 1); + + pvcHr02->adjustInfo[0].step = 4; + pvcHr02->adjustInfo[0].directionLast = VCHR02ADJUSTDIRECTION_NULL; + pvcHr02->adjustInfo[0].direction = VCHR02ADJUSTDIRECTION_NULL; + + pvcHr02->adjustInfo[1].step = 4; + pvcHr02->adjustInfo[1].directionLast = VCHR02ADJUSTDIRECTION_NULL; + pvcHr02->adjustInfo[1].direction = VCHR02ADJUSTDIRECTION_NULL; + + pvcHr02->wearStatus = VCHR02WEARST_ISWEAR; + pvcHr02->vcPsFlag = 0; + pvcHr02->vcFifoReadFlag = 0; + + pvcHr02->unWearCnt = VCUNWEAR_CNT; + pvcHr02->isWearCnt = VCISWEAR_CNT; + ledMaxCurrent[0] = 0x6f; + ledMaxCurrent[1] = 0x6f; + pdResMax[0] = 7; + pdResMax[1] = 7; + recordEnv[0] = 0; + recordEnv[1] = 0; +} + + +/* + * @brief + * Initialize vcHr02's register Settings + * + **/ +static vcHr02Ret_t vcHr02RegInit(vcHr02_t *pvcHr02) +{ + + uint8_t i = 0; + uint8_t regConfig[17] = {0x01, 0x3F, 0x8A, 0x40, 0x03, 0x1F, 0x00, 0x00, 0x80, 0x00, 0x57, 0x37, 0x07, 0x16, 0x56, 0x16, 0x00}; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + + + regConfig[3] = regConfig[3] | (pvcHr02->vcSampleRate - 6); + regConfig[6] = pvcHr02->vcSampleRate - 6; + +#if VCHR02ISVC31B + regConfig[9] = 0xE0; //CUR = 80mA//write Hs equal to 1 + regConfig[12] = 0x67; +#elif VCHR02ISVC32S + regConfig[9] = 0x50; //CUR = 40mA + regConfig[12] = 0x17; + +#elif VCHR02ISVC51B + regConfig[9] = 0x5A; //CUR = 60mA + regConfig[12] = 0x17; //PDRES = 0x17; +#elif VCHR02ISVC52S + regConfig[9] = 0x30; //CUR = 10mA + regConfig[12] = 0x17; //PDRES = 0x17; +#elif VCHR02ISVC52T + regConfig[9] = 0x50; //modify by Tatum,Using our demo for black testing 2020.04.12 + regConfig[12] = 0x37; //PDRES = 0x37; + +#else + regConfig[9] = 0x20; // CUR = 5mA + regConfig[12] = 0x17; // PDRES = 0x17; + +#endif + switch (pvcHr02->workMode) { + case VCWORK_MODE_HRWORK: + regConfig[0] = 0x45; + break; + + case VCWORK_MODE_SPO2WORK: + regConfig[0] = 0x47; + regConfig[1] = 0x2F; + regConfig[6] = 0; + regConfig[7] = 0x80; + regConfig[13] = 0x96; + regConfig[16] = 0x04; // OverSample + break; + + case VCWORK_MODE_CROSSTALKTEST: + regConfig[0] = 0x47; + regConfig[7] = 0xEF; //solt0 maxLedCur + regConfig[8] = 0xEF; //solt1 maxLedCur + regConfig[10] = 0x77; //solt0 PDResMax + regConfig[11] = 0x77; //solt1 PDResMax + break; + + case VCWORK_MODE_NOISEWORK: + regConfig[0] = 0x41; + regConfig[10] = 0x57; + regConfig[13] = 0x16; + regConfig[16] = 0x00; + break; + case VCWORK_MODE_LPDETECTION: + regConfig[0] = 0x44; + regConfig[1] = 0x30; + break; + default: + break; + } +#if VCHR02ISVC31B + if (psBiasReadInPdFlag == false) { + regConfig[0] = 0x04; + } +#endif + for (i = 0; i < 17; i++) { + pvcHr02->regConfig[i] = regConfig[i]; + } + ret |= vcHr02WriteRegisters(VCREG11, pvcHr02->regConfig, 17); + + pvcHr02->regConfig[0] = 0x80 | regConfig[0]; + ret |= vcHr02WriteRegisters(VCREG11, pvcHr02->regConfig, 1); + + vcHr02ConfigInit(pvcHr02); + + return ret; +} + + +/* + * @brief: + * + **/ +vcHr02Ret_t vcHr02StartSample(vcHr02_t *pvcHr02) +{ + vcHr02Ret_t ret = VCHR02RET_ISOK; + + ret |= vcHr02RegInit(pvcHr02); + + return ret; +} + + +/* + * @brief + * shut down the logic channel + * workmode = sleepmode + * + **/ +vcHr02Ret_t vcHr02StopSample(vcHr02_t *pvcHr02) +{ + /* Shut down all logic solt and goto sleep mode */ + uint8_t modeCtrl = 0x00; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + ret |= vcHr02WriteRegisters(VCREG11, (uint8_t *)&modeCtrl, VCREG11_SIZE); + + return ret; +} + + +/* + * @brief + * Function: Added adjust flag when interrupt happend. + * Provides it for algorithmic processing. + * + **/ +static vcHr02Ret_t vcHr02AddAdjustFlag(uint8_t slotNum) +{ + vcHr02Ret_t ret = VCHR02RET_ISOK; + + /* If fifoIntDiv is 0,FIFO Function disable */ + if (fifoIntDiv == 0) { + adjustFlag[slotNum][0] = 1; + } else { + ret |= vcHr02ReadRegisters(VCREG3, (uint8_t *)&fifoWriteIndex, VCREG3_SIZE); + sampleIndex = (fifoWriteIndex - 0x80) / 2 / totalSlot; + if (sampleIndex == 0) { + sampleIndex = totalSlot == 1 ? 63 : 31; + } else { + sampleIndex = sampleIndex - 1; + } + adjustFlag[slotNum][sampleIndex] = 1; + } + return ret; +} + + +/* +* @brief +* Read data from FIFO +* If there is an adjustment, an adjustment flag is added +* +**/ +static vcHr02Ret_t vcHr02OutPutPPGData(vcHr02_t *pvcHr02, uint8_t StartIndex, uint16_t StopIndex, uint8_t IndexFlag) +{ + uint16_t i = 0; + uint8_t dataLength = 0; + uint8_t sampleData[128]; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + dataLength = StopIndex - StartIndex; + ret |= vcHr02ReadRegisters(StartIndex, sampleData, dataLength); + + for (i = StartIndex; i < StopIndex; i = i + 2) { + pvcHr02->sampleData.ppgValue[(i - StartIndex) / 2 + IndexFlag] = ((sampleData[(i - StartIndex)] << 8) | sampleData[(i - StartIndex) + 1]); + slotCount = ((i - 0x80) % (totalSlot * 2)) / 2; + sampleIndex = (i - 0x80) / (totalSlot * 2); + if (adjustFlag[slotCount][sampleIndex] == 1) { + pvcHr02->sampleData.ppgValue[(i - StartIndex) / 2 + IndexFlag] |= 0x1000; + adjustFlag[slotCount][sampleIndex] = 0; + } + } + return ret; +} + + +/* + * @brief + * Clock Calibration + * + **/ +uint16_t vcHr02CalculateOSCFreq(vcHr02_t *pvcHr02) +{ + uint8_t clkAdjCnt[4] = {0}, newFreDiv[2] = {0}, i = 0; + uint32_t rtcCount[2]; + uint16_t adjCount[2], freDiv[2] = {0}; + uint16_t newDiv, f20kOsc = 0; + + bool diffCountIsOk = true; + bool diffIsOK; + + /* Get McuRtcCount */ + rtcCount[0] = vcHr02GetRtcCountFromMCU(); + vcHr02ReadRegisters(VCREG7, clkAdjCnt, 4); + /* Get McuRtcCount */ + rtcCount[1] = vcHr02GetRtcCountFromMCU(); + + adjCount[0] = clkAdjCnt[0] << 8 | clkAdjCnt[1]; + adjCount[1] = clkAdjCnt[2] << 8 | clkAdjCnt[3]; + if (adjCount[1] < adjCount[0] || rtcCount[1] < rtcCount[0]) { + cntCalOsc = 0; + return 0; + } + + intDiffAdj[2 * cntCalOsc] = adjCount[0]; + intDiffAdj[2 * cntCalOsc + 1] = adjCount[1]; + + intDiffRtc[2 * cntCalOsc] = rtcCount[0]; + intDiffRtc[2 * cntCalOsc + 1] = rtcCount[1]; + + cntCalOsc += 1; + + if (cntCalOsc >= 3) { + cntCalOsc = 0; + for (i = 0; i < 2; i++) { + diffCountIsOk = (((intDiffRtc[2 * i + 2] - intDiffRtc[2 * i]) - (intDiffRtc[2 * i + 3] - intDiffRtc[2 * i + 1]) <= oscDifSetting) || ((intDiffRtc[2 * i + 3] - intDiffRtc[2 * i + 1]) - (intDiffRtc[2 * i + 2] - intDiffRtc[2 * i]) <= oscDifSetting)) && diffCountIsOk; + diffCountIsOk = (((intDiffAdj[2 * i + 2] - intDiffAdj[2 * i]) - (intDiffAdj[2 * i + 3] - intDiffAdj[2 * i + 1]) <= 2) || ((intDiffAdj[2 * i + 3] - intDiffAdj[2 * i + 1]) - (intDiffAdj[2 * i + 2] - intDiffAdj[2 * i]) <= 2)) && diffCountIsOk; + } + /* printf("-----test-----:pvcHr02->vcSampleRate:%d\n",pvcHr02->vcSampleRate); */ + if (diffCountIsOk) { + for (i = 0; i < 2; i++) { + uint32_t temp_data = (uint32_t)(intDiffRtc[2 * i + 2] - intDiffRtc[2 * i]); + if (temp_data == 0) { + printf("-----test-----:intDiffRtc:%d\n", temp_data); + temp_data = 1; + } + freDiv[i] = ((uint32_t)(intDiffAdj[2 * i + 2] - intDiffAdj[2 * i])) * pvcHr02->mcuOscValue / pvcHr02->vcSampleRate / (temp_data) - 1; + if (freDiv[i] < (20000 / pvcHr02->vcSampleRate * 0.75f) || freDiv[i] > (20000 / pvcHr02->vcSampleRate * 1.25f)) { + return 0; + } + } + diffIsOK = (freDiv[1] - freDiv[0] <= 20) || (freDiv[0] - freDiv[1] <= 20); + if (diffIsOK) { + newDiv = (freDiv[1] + freDiv[0]) / 2; + f20kOsc = (newDiv + 1) * pvcHr02->vcSampleRate; + newFreDiv[0] = newDiv >> 8; + newFreDiv[1] = newDiv; + vcHr02WriteRegisters(VCREG15, newFreDiv, VCREG15_SIZE); + pvcHr02->oscCheckFinishFlag = 1; + oscCnt = 0; + } + } else { + return 0; + } + } + return f20kOsc; +} + + +/* + * @brief + * Wear monitoring. + * + **/ +static vcHr02Ret_t vcHr02WearStatusDetection(vcHr02_t *pvcHr02) +{ + uint8_t newSoltChNu = 0; + uint8_t psDiv1Hz = pvcHr02->regConfig[3] & 0x3f; + uint8_t enPs = (pvcHr02->regConfig[1] | 0x10) & 0xf0; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + switch (pvcHr02->wearStatus) { + /* Identify whether the wearing state needs to be switched, + Wear status from unWear to isWear */ + case VCHR02WEARST_UNWEAR: +#if SportMotionEn + if ((pvcHr02->sampleData.psValue >= VCPS_TH) && (pvcHr02->sampleData.envValue[2] < 3) && (gsensor_abs_xyz_diff_value > 20)) +#else + if ((pvcHr02->sampleData.psValue >= VCPS_TH) && (pvcHr02->sampleData.envValue[2] < 3)) +#endif + { + /* 1 time */ + if (--pvcHr02->isWearCnt <= 0) { + pvcHr02->wearStatus = VCHR02WEARST_ISWEAR; + pvcHr02->unWearCnt = VCUNWEAR_CNT; + pvcHr02->isWearCnt = VCISWEAR_CNT; + + /* Reset Reg to defult value */ + vcHr02SoftReset(pvcHr02); + + vcHr02RegInit(pvcHr02); + ret |= VCHR02RET_UNWEARTOISWEAR; + + lastRtcValue = vcHr02GetRtcCountFromMCU(); + + } + } else { + pvcHr02->isWearCnt = VCISWEAR_CNT; + } + break; + + case VCHR02WEARST_ISWEAR: +#if BiometricEn + if ((pvcHr02->sampleData.psValue < VCPS_TH) || (pvcHr02->sampleData.envValue[2] > VCENV_TH) || (HeartRateValue == -1)) { + if (HeartRateValue == -1) { + pvcHr02->unWearCnt = 1; + } + /* 3 times */ + if (--pvcHr02->unWearCnt <= 0) { + HeartRateValue = 0; + pvcHr02->wearStatus = VCHR02WEARST_UNWEAR; + pvcHr02->unWearCnt = VCUNWEAR_CNT; + pvcHr02->isWearCnt = VCISWEAR_CNT; + if (pvcHr02->workMode == VCWORK_MODE_SPO2WORK) { + vcHr02WriteRegisters(VCREG16, (uint8_t *)&psDiv1Hz, VCREG16_SIZE); + vcHr02WriteRegisters(VCREG12, (uint8_t *)&enPs, VCREG12_SIZE); + pvcHr02->regConfig[1] |= 0x10; + } + /* Enable solt2,Disable solt0 and solt1 */ + newSoltChNu = (pvcHr02->regConfig[0] & 0xF8) | 0x04; + + pvcHr02->vcPsFlag = 1; + ret |= vcHr02WriteRegisters(VCREG11, (uint8_t *)&newSoltChNu, VCREG11_SIZE); + ret |= VCHR02RET_ISWEARTOUNWEAR; +#if SportMotionEn + green_led_off_state_gsensor_abs_sum_diff_init_func(); //modify by Tatum +#endif + } + } +#else + if ((pvcHr02->sampleData.psValue < VCPS_TH) || (pvcHr02->sampleData.envValue[2] > VCENV_TH)) { + /* 3 times */ + if (--pvcHr02->unWearCnt <= 0) { + pvcHr02->wearStatus = VCHR02WEARST_UNWEAR; + pvcHr02->unWearCnt = VCUNWEAR_CNT; + pvcHr02->isWearCnt = VCISWEAR_CNT; + + if (pvcHr02->workMode == VCWORK_MODE_SPO2WORK) { + + vcHr02WriteRegisters(VCREG16, (uint8_t *)&psDiv1Hz, VCREG16_SIZE); + vcHr02WriteRegisters(VCREG12, (uint8_t *)&enPs, VCREG12_SIZE); + pvcHr02->regConfig[1] |= 0x10; + } + /* Enable solt2,Disable solt0 and solt1 */ + newSoltChNu = (pvcHr02->regConfig[0] & 0xF8) | 0x04; + + pvcHr02->vcPsFlag = 1; + ret |= vcHr02WriteRegisters(VCREG11, (uint8_t *)&newSoltChNu, VCREG11_SIZE); + ret |= VCHR02RET_ISWEARTOUNWEAR; + } + } +#endif + else { + pvcHr02->vcPsFlag = 0; + pvcHr02->unWearCnt = VCUNWEAR_CNT; + } + break; + } + return ret; +} + + +/* + * @brief + * FIFO Read.(Or GetValue) + * + **/ +static vcHr02Ret_t vcHr02ReadFifo(vcHr02_t *pvcHr02, uint8_t *len) +{ + uint32_t rtcValue = 0; + uint8_t dateLength = 0; + float cacheTime = 64.0f; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + ret |= vcHr02ReadRegisters(VCREG3, (uint8_t *)&fifoWriteIndex, VCREG3_SIZE); + + /* //解决计数值计满后校验不过问题(ppglength = 0) + uint32_t vcHr02TimeDiff; + rtcValue = vcHr02GetRtcCountFromMCU(); + if (rtcValue > lastRtcValue) + { + vcHr02TimeDiff = rtcValue - lastRtcValue; + } + else + { + vcHr02TimeDiff = (0xFFFFFFFF - lastRtcValue) + rtcValue; + } + if((vcHr02TimeDiff)>(((cacheTime/pvcHr02->vcSampleRate) *0.8f* pvcHr02->mcuOscValue)/ totalSlot)) + */ + rtcValue = vcHr02GetRtcCountFromMCU(); + if ((rtcValue - lastRtcValue) > (((cacheTime / pvcHr02->vcSampleRate) * 0.8f * pvcHr02->mcuOscValue) / totalSlot)) { + pvcHr02->vcFifoReadFlag = 0; + fifoWriteIndex = 0; + fifoReadIndex = 0x80; + lastRtcValue = rtcValue; + return VCHR02RET_FIFOISOVERFLOW; + } + + if (fifoWriteIndex < 0X80) { + pvcHr02->vcFifoReadFlag = 0; + fifoReadIndex = fifoReadIndex + (fifoIntDiv + 1) * 2; + if (fifoReadIndex < 128) { + fifoReadIndex += 0X80; + } + lastRtcValue = rtcValue; + return VCHR02RET_FIFOISOVERFLOW; + } + + if (fifoIntDiv != 0) { + if (fifoWriteIndex > fifoReadIndex) { + dateLength = (fifoWriteIndex - fifoReadIndex) / 2; + vcHr02OutPutPPGData(pvcHr02, fifoReadIndex, fifoWriteIndex, 0); + } else { + dateLength = (fifoWriteIndex + 0x80 - fifoReadIndex) / 2; + if (dateLength == 64) { + dateLength = 0; + pvcHr02->vcFifoReadFlag = 0; + return VCHR02RET_ISERR; + } + vcHr02OutPutPPGData(pvcHr02, fifoReadIndex, 256, 0); + if (fifoWriteIndex != 0x80) { + vcHr02OutPutPPGData(pvcHr02, 0x80, fifoWriteIndex, (256 - fifoReadIndex) / 2); + } + } + fifoReadIndex = fifoWriteIndex; + } else { + /* Not use FIFO, the sampleData is storage in 0x80 */ + dateLength = totalSlot; + vcHr02OutPutPPGData(pvcHr02, fifoReadIndex, fifoReadIndex + totalSlot * 2, 0); + } + + /* Return the array length for data processing */ + *len = dateLength; + lastRtcValue = rtcValue; + return ret; +} + + + +/* + * @brief + * Adjust PDRes Value and modify the PDResMax + * + **/ +static vcHr02Ret_t vcHr02EnvAdjust(vcHr02_t *pvcHr02, uint8_t slotNum) +{ + vcHr02Ret_t ret = VCHR02RET_ISOK; + + if ((pvcHr02->sampleData.envValue[slotNum] > VCENV_TH) && enSlot[slotNum]) { + recordEnv[slotNum] = pvcHr02->sampleData.envValue[slotNum]; + if (pdRes[slotNum] != 0) { + pdRes[slotNum] = pdRes[slotNum] - 1; + pdResMax[slotNum] = pdRes[slotNum]; + + /* Added logical adjustment flag bit */ + vcHr02AddAdjustFlag(slotNum); + + pvcHr02->regConfig[slotNum + 10] = (pdRes[slotNum] << 4) | pdResSet[slotNum]; + ret |= vcHr02WriteRegisters((VCREG20 + slotNum), (uint8_t *) & (pvcHr02->regConfig[slotNum + 10]), 1); + } else { + return VCHR02RET_ENVCURRENTISLARGE; + } + } + if (pvcHr02->sampleData.envValue[2] > VCENV_TH) { + return VCHR02RET_PSENVCURRENTISLARGE; + } + return ret; +} + + +/* + * @brief + * Adjust ledCurrent Value and modify the ledCurrentMax value + * + **/ +static vcHr02Ret_t vcHr02OvloadAdjust(vcHr02_t *pvcHr02, uint8_t slotNum) +{ + uint8_t overLoad = 0; + uint8_t ovload[SLOTCHNU]; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + ret |= vcHr02ReadRegisters(VCREG1, (uint8_t *)&overLoad, VCREG1_SIZE); + + /* Get Slot0,Slot1 and Slot2's Overload status */ + ovload[0] = overLoad & 0x01; + ovload[1] = (overLoad & 0x02) >> 1; + ovload[2] = (overLoad & 0x04) >> 2; + + /* Adjust led emitter and record max_led_emitter */ + if ((overLoad & (pvcHr02->regConfig[0] & 0x07)) != 0) { + if (ovload[slotNum] && enSlot[slotNum]) { + if (ledCurrent[slotNum] != 0) { + ledCurrent[slotNum] = ledCurrent[slotNum] - 1; + ledMaxCurrent[slotNum] = ledCurrent[slotNum]; + vcHr02AddAdjustFlag(slotNum); + pvcHr02->regConfig[slotNum + 7] = (ledCurrent[slotNum] | ppgGain[slotNum]); + ret |= vcHr02WriteRegisters((VCREG17 + slotNum), (uint8_t *) & (pvcHr02->regConfig[slotNum + 7]), 1); + } else { + return VCHR02RET_SOLTISOVERLOAD; + } + } + /* After the calibration of infrared channel parameters, + the current and resistance will not be adjusted */ + if (ovload[2]) { + return VCHR02RET_PSISOVERLOAD; + } + } + return ret; +} + + +/* + * @brief + * Adjust ledCurrent Value and PDRes value + * + **/ +static vcHr02Ret_t vcHr02PPgLedCurAndPdResAdjust(vcHr02_t *pvcHr02, uint8_t slotNum, uint8_t ledcur, uint8_t pdres) +{ + uint8_t oldPdRes, oldLedCurrent; + uint8_t newPdRes, newLedCurrent; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + oldLedCurrent = ledCurrent[slotNum]; + newLedCurrent = oldLedCurrent; + oldPdRes = pdRes[slotNum]; + newPdRes = oldPdRes; + + slot0EnvIsExceedFlag = false; + slot1EnvIsExceedFlag = false; + if ((oldLedCurrent == ledcur) && (pvcHr02->workMode != VCWORK_MODE_NOISEWORK)) { + if (oldPdRes == pdres) { + newPdRes = oldPdRes ; + slot0EnvIsExceedFlag = (slotNum == 0) ? true : false; + slot1EnvIsExceedFlag = (slotNum == 1) ? true : false; + return VCHR02RET_PPGCANNOTADJUSTABLE; + } else { + if (pvcHr02->adjustInfo[slotNum].direction == VCHR02ADJUSTDIRECTION_UP) { + newPdRes = (oldPdRes >= 7) ? 7 : (oldPdRes + 1); + } else { + newPdRes = (oldPdRes < 1) ? 0 : (oldPdRes - 1); + } + newLedCurrent = oldLedCurrent; + vcHr02AddAdjustFlag(slotNum); + } + } else { + if (pvcHr02->adjustInfo[slotNum].directionLast == VCHR02ADJUSTDIRECTION_NULL) { + pvcHr02->adjustInfo[slotNum].step *= 16; + } else if (pvcHr02->adjustInfo[slotNum].direction == pvcHr02->adjustInfo[slotNum].directionLast) { + if ((pvcHr02->adjustInfo[slotNum].step == 1) || (pvcHr02->adjustInfo[slotNum].step == 2)) { + pvcHr02->adjustInfo[slotNum].step = (pvcHr02->adjustInfo[slotNum].step + 1) * 16; + } else { + pvcHr02->adjustInfo[slotNum].step *= VCADJUST_INCREASE; + } + } else { + pvcHr02->adjustInfo[slotNum].step *= VCADJUST_DECREASE; + } + + pvcHr02->adjustInfo[slotNum].step = pvcHr02->adjustInfo[slotNum].step >> 4; + + pvcHr02->adjustInfo[slotNum].step = (pvcHr02->adjustInfo[slotNum].step <= VCADJUST_STEP_MIN) ? VCADJUST_STEP_MIN : pvcHr02->adjustInfo[slotNum].step; + pvcHr02->adjustInfo[slotNum].step = (pvcHr02->adjustInfo[slotNum].step >= VCADJUST_STEP_MAX) ? VCADJUST_STEP_MAX : pvcHr02->adjustInfo[slotNum].step; + + if (pvcHr02->adjustInfo[slotNum].direction == VCHR02ADJUSTDIRECTION_UP) { + newLedCurrent = ((oldLedCurrent + pvcHr02->adjustInfo[slotNum].step) > ledcur) ? ledcur : oldLedCurrent + pvcHr02->adjustInfo[slotNum].step; + } else { + newLedCurrent = (oldLedCurrent < pvcHr02->adjustInfo[slotNum].step) ? ledcur : oldLedCurrent - pvcHr02->adjustInfo[slotNum].step; + } + vcHr02AddAdjustFlag(slotNum); + newPdRes = oldPdRes; + pvcHr02->adjustInfo[slotNum].directionLast = pvcHr02->adjustInfo[slotNum].direction; + } + + ledCurrent[slotNum] = newLedCurrent; + pdRes[slotNum] = newPdRes; + + pvcHr02->regConfig[slotNum + 7] = ledCurrent[slotNum] | ppgGain[slotNum]; + ret |= vcHr02WriteRegisters((VCREG17 + slotNum), (uint8_t *) & (pvcHr02->regConfig[slotNum + 7]), 1); + pvcHr02->regConfig[slotNum + 10] = (pdRes[slotNum] << 4) | pdResSet[slotNum]; + ret |= vcHr02WriteRegisters((VCREG20 + slotNum), (uint8_t *) & (pvcHr02->regConfig[slotNum + 10]), 1); + + return ret; +} + + +/* + * @brief + * Get the PPG saturation direction + * + **/ +static vcHr02Ret_t vcHr02PpgAdjust(vcHr02_t *pvcHr02, uint8_t slotNum) +{ + uint8_t ppgDataAddress, ppgDataAddress_EnFifo; + uint8_t ppgDate[2]; + uint16_t ppgCurValue[2]; + uint8_t IndexGap; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + /* Get fifoWriteIndex Value */ + ret |= vcHr02ReadRegisters(VCREG3, (uint8_t *)&fifoWriteIndex, VCREG3_SIZE); + + if (totalSlot == 1) { + /* Determine whether the FIFO is overflowing */ + ppgDataAddress_EnFifo = fifoWriteIndex - totalSlot * 2; + ppgDataAddress_EnFifo = ppgDataAddress_EnFifo < 0x80 ? ppgDataAddress_EnFifo + 0x80 : ppgDataAddress_EnFifo; + ppgDataAddress = enFifo ? ppgDataAddress_EnFifo : 0x80; + } else { + /* Determine whether the FIFO is overflowing */ + ppgDataAddress_EnFifo = fifoWriteIndex - totalSlot * 2 + slotNum * 2; + ppgDataAddress_EnFifo = ppgDataAddress_EnFifo < 0x80 ? ppgDataAddress_EnFifo + 0x80 : ppgDataAddress_EnFifo; + ppgDataAddress = enFifo ? ppgDataAddress_EnFifo : 0x80 + slotNum * 2; + } + ret |= vcHr02ReadRegisters(ppgDataAddress, ppgDate, 2); + ppgCurValue[slotNum] = (ppgDate[0] << 8) | ppgDate[1]; + + if (fifoIntDiv != 0) { + IndexGap = (fifoWriteIndex > readIndex) ? (fifoWriteIndex - readIndex) : (fifoWriteIndex - readIndex + 0x80); + if (IndexGap != 2 * totalSlot) { + pvcHr02->adjustInfo[slotNum].directionLast = VCHR02ADJUSTDIRECTION_NULL; + } + readCnt += 1; + if (readCnt == totalSlot) { + readCnt = 0; + readIndex = fifoWriteIndex; + } + } + /* PPG supersaturation */ + if (ppgCurValue[slotNum] > 4095 - VCPPG_TH * 32) { + /* If the LED luminous current reaches the maximum current, + it can only be adjusted by increasing the PD resistance */ + pvcHr02->adjustInfo[slotNum].direction = VCHR02ADJUSTDIRECTION_UP; + ret |= vcHr02PPgLedCurAndPdResAdjust(pvcHr02, slotNum, ledMaxCurrent[slotNum], pdResMax[slotNum]); + } + /* Lower saturation */ + else if (ppgCurValue[slotNum] < VCPPG_TH * 32) { + pvcHr02->adjustInfo[slotNum].direction = VCHR02ADJUSTDIRECTION_DOWN; + ret |= vcHr02PPgLedCurAndPdResAdjust(pvcHr02, slotNum, 0, 0); + } + return ret; +} + + +/* + * @brief + * Prejude the ENVvalue and modify the PD maximum resistance. + * Don't need to write to register + * + **/ +static vcHr02Ret_t vcHr02AdjustPDResMax(vcHr02_t *pvcHr02, uint8_t slotNum) +{ + uint8_t minEnv[SLOTCHNU]; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + if (pdResMax[slotNum] == 7) { + return VCHR02RET_PDRESISMAX; + } + minEnv[slotNum] = ((recordEnv[slotNum] / 2) < VCENV_TH) ? (recordEnv[slotNum] / 2) : VCENV_TH; + if (pvcHr02->sampleData.envValue[slotNum] < minEnv[slotNum]) { + if (pvcHr02->sampleData.envValue[slotNum] < 1) { + count_pdRes[slotNum] = 0; + count_QaPdRes[slotNum] = (count_QaPdRes[slotNum] == 30 * pvcHr02->vcSampleRate) ? 0 : count_QaPdRes[slotNum] + 1; + pdResMax[slotNum] = (count_QaPdRes[slotNum] == 30 * pvcHr02->vcSampleRate) ? 7 : pdResMax[slotNum]; + } else { + count_QaPdRes[slotNum] = 0; + count_pdRes[slotNum] += 1; + pdResMax[slotNum] = (count_pdRes[slotNum] == 120 * pvcHr02->vcSampleRate) ? pdResMax[slotNum] + 1 : pdResMax[slotNum]; + } + } else { + count_QaPdRes[slotNum] = 0; + count_pdRes[slotNum] = 0; + } + return ret; +} + + +/* + * @brief + * Before getsample value,prejude Status. + * + **/ +static vcHr02Ret_t vcHr02ReadStatus(vcHr02_t *pvcHr02) +{ + uint8_t vcHr02SlotCnt = 0; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + /* Clear FifoReadFlag */ + pvcHr02->vcFifoReadFlag = 0; + + if (pvcHr02->vcHr02Status & VCREG1_CONFLICT) { + return VCHR02RET_ISCONFLICT; + } + if (pvcHr02->vcHr02Status & VCREG1_INSAMPLE) { + return VCHR02RET_ISINSAMPLE; + } + +#if (VCWEAR_STATUS_DETECTION_MODE != VCWEAR_STATUS_DETECTION_OFF) + if (pvcHr02->regConfig[1] & 0x10) { + if (pvcHr02->intReason & 0x10) { + ret |= vcHr02WearStatusDetection(pvcHr02); + } + } +#endif + + if ((ret == VCHR02RET_UNWEARTOISWEAR) && (pvcHr02->wearStatus == VCHR02WEARST_ISWEAR)) { + //Set psflag to 1 when the state is switched (from unwear to iswear) + //to prevent psflag and fifoflag from being 0 at the same time + pvcHr02->vcPsFlag = 1; + } + if ((ret != VCHR02RET_UNWEARTOISWEAR) && (pvcHr02->wearStatus == VCHR02WEARST_ISWEAR)) { + //Clear the psflag that appears after the state switch (from unwear to iswear) + pvcHr02->vcPsFlag = 0; + } + for (vcHr02SlotCnt = 0; vcHr02SlotCnt < totalSlot; vcHr02SlotCnt++) { + slotCount = (totalSlot == 2) ? vcHr02SlotCnt : (enSlot[0] ? 0 : 1); + vcHr02AdjustPDResMax(pvcHr02, slotCount); + ledCurrent[slotCount] = pvcHr02->regConfig[7 + slotCount] & 0x7f; + ppgGain[slotCount] = pvcHr02->regConfig[7 + slotCount] & 0x80; + pdRes[slotCount] = (pvcHr02->regConfig[10 + slotCount] & 0x70) >> 4; + pdResSet[slotCount] = pvcHr02->regConfig[10 + slotCount] & 0x8F; + + if (pvcHr02->intReason & VCREG1_INTENV) { + ret |= vcHr02EnvAdjust(pvcHr02, slotCount); + } + if (pvcHr02->intReason & VCREG1_INTOV) { + ret |= vcHr02OvloadAdjust(pvcHr02, slotCount); + } + if (pvcHr02->intReason & VCREG1_INTPPG) { + ret |= vcHr02PpgAdjust(pvcHr02, slotCount); + } else { + pvcHr02->adjustInfo[slotCount].directionLast = VCHR02ADJUSTDIRECTION_NULL; + pvcHr02->adjustInfo[slotCount].direction = VCHR02ADJUSTDIRECTION_NULL; + } + } + if (pvcHr02->intReason & VCREG1_INTFIFO) { //中断原因寄存器 + if (pvcHr02->workMode == VCWORK_MODE_SPO2WORK) { +#if (VCWEAR_STATUS_DETECTION_MODE != VCWEAR_STATUS_DETECTION_OFF) + ret |= vcHr02WearStatusDetection(pvcHr02); +#endif + } + pvcHr02->vcFifoReadFlag = 1; + } + return ret; +} + + +/* + * @brief + * Read Pre and EnvValue + * + **/ +static vcHr02Ret_t vcHr02ReadReg(vcHr02_t *pvcHr02) +{ + uint8_t vcRegisterValue[6] = {0}; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + ret |= vcHr02ReadRegisters(VCREG1, vcRegisterValue, 6); + + pvcHr02->vcHr02Status = vcRegisterValue[0]; + pvcHr02->intReason = vcRegisterValue[1]; + + pvcHr02->sampleData.envValue[0] = vcRegisterValue[3] >> 4; + pvcHr02->sampleData.preValue[0] = vcRegisterValue[3] & 0x0F; + pvcHr02->sampleData.envValue[1] = vcRegisterValue[4] >> 4; + pvcHr02->sampleData.preValue[1] = vcRegisterValue[4] & 0x0F; + pvcHr02->sampleData.envValue[2] = vcRegisterValue[5] >> 4; + pvcHr02->sampleData.psValue = vcRegisterValue[5] & 0x0F; + + ret |= vcHr02ReadRegisters(VCREG17, vcRegisterValue, 6); + pvcHr02->sampleData.pdResValue[0] = (vcRegisterValue[3] >> 4) & 0x07; + pvcHr02->sampleData.currentValue[0] = vcRegisterValue[0] & 0x7F; + pvcHr02->sampleData.pdResValue[1] = (vcRegisterValue[4] >> 4) & 0x07; + pvcHr02->sampleData.currentValue[1] = vcRegisterValue[1] & 0x7F; + pvcHr02->sampleData.pdResValue[2] = (vcRegisterValue[5] >> 4) & 0x07; + pvcHr02->sampleData.currentValue[2] = vcRegisterValue[2] & 0x7F; + +#if VCHR02ISVC31B + if ((!psBiasReadInPdFlag) && (pvcHr02->intReason & 0x10)) { + psBias = pvcHr02->sampleData.psValue / 2; + psBiasReadInPdFlag = true; + vcHr02SoftReset(pvcHr02); + vcHr02RegInit(pvcHr02); + + } + pvcHr02->sampleData.psValue = (pvcHr02->sampleData.psValue > psBias) ? (pvcHr02->sampleData.psValue - psBias) : 0; +#endif + + return ret; +} + + +/* + * @brief + * + * + **/ +vcHr02Ret_t vcHr02GetSampleValues(vcHr02_t *pvcHr02, uint8_t *DataLen) +{ + vcHr02Ret_t ret = VCHR02RET_ISOK; + + int16_t secondCnt = pvcHr02->vcSampleRate * 180 / (fifoIntDiv + 1); //3min + //int16_t secondCnt = pvcHr02->vcSampleRate*10/(fifoIntDiv+1);//10s + + vcHr02ReadReg(pvcHr02); + + switch (pvcHr02->workMode) { + case VCWORK_MODE_HRWORK: + ret |= vcHr02ReadStatus(pvcHr02); + + if (!pvcHr02->oscCheckFinishFlag) { + vcHr02CalculateOSCFreq(pvcHr02); + // pvcHr02->vcFifoReadFlag = 0; + } + if (pvcHr02->vcFifoReadFlag == 1) { + oscCnt += 1; + if (oscCnt >= secondCnt) { + /* Consider the 20k Adjust to three mintures called */ + vcHr02CalculateOSCFreq(pvcHr02); + } + if (pvcHr02->oscCheckFinishFlag) { +#if (VCWEAR_READ_FIFO_MODE == VCWEAR_READ_FIFO_BY_INT) + ret |= vcHr02ReadFifo(pvcHr02, DataLen); +#endif + } + } + break; + + case VCWORK_MODE_SPO2WORK: + ret |= vcHr02ReadStatus(pvcHr02); + if (!pvcHr02->oscCheckFinishFlag) { + vcHr02CalculateOSCFreq(pvcHr02); + // pvcHr02->vcFifoReadFlag = 0; + } + if (pvcHr02->vcFifoReadFlag == 1) { + oscCnt += 1; + if (oscCnt >= secondCnt) { + /* Consider the 20k Adjust to three mintures called */ + vcHr02CalculateOSCFreq(pvcHr02); + } + if (pvcHr02->oscCheckFinishFlag) { +#if (VCWEAR_READ_FIFO_MODE == VCWEAR_READ_FIFO_BY_INT) + ret |= vcHr02ReadFifo(pvcHr02, DataLen); +#endif + } + + } + break; + + case VCWORK_MODE_CROSSTALKTEST: + ledCurrent[0] = pvcHr02->regConfig[7] & 0x7f; + if (pvcHr02->intReason & VCREG1_INTOV) { + ret |= vcHr02OvloadAdjust(pvcHr02, 0); + } + pvcHr02->sampleData.maxLedCur = ledMaxCurrent[0]; + /* PASS条件: */ +// ((pvcHr02->sampleData.maxLedCur >= 100) && (pvcHr02->sampleData.preValue[0] <= 2) +// /*Monitor ps Value*/ +// read pvcHr02->sampleData.psValue + break; + + case VCWORK_MODE_NOISEWORK: + ret |= vcHr02ReadStatus(pvcHr02); +#if (VCWEAR_READ_FIFO_MODE == VCWEAR_READ_FIFO_BY_INT) + ret |= vcHr02ReadFifo(pvcHr02, DataLen); +#endif + break; + + case VCWORK_MODE_LPDETECTION: + if (!pvcHr02->oscCheckFinishFlag) { + vcHr02CalculateOSCFreq(pvcHr02); + } + oscCnt += 1; + if (oscCnt >= secondCnt) { + /* Consider the 20k Adjust to five mintures called */ + vcHr02CalculateOSCFreq(pvcHr02); + } + ret |= vcHr02WearStatusDetection(pvcHr02); + pvcHr02->vcPsFlag = 1; + break; + + default: + break; + } + return ret; +} + + +/* + * @brief + * + * + **/ +vcHr02Ret_t vcHr02TimeReadValues(vcHr02_t *pvcHr02, uint8_t *DataLen) +{ + vcHr02Ret_t ret = VCHR02RET_ISOK; + + /* Obtian the env and prevalue */ + vcHr02ReadReg(pvcHr02); + +#if (VCWEAR_STATUS_DETECTION_MODE != VCWEAR_STATUS_DETECTION_OFF) + ret |= vcHr02WearStatusDetection(pvcHr02); +#endif + + oscCnt += 1; + if (oscCnt >= 180) { + vcHr02CalculateOSCFreq(pvcHr02); + } + if (pvcHr02->oscCheckFinishFlag) { + ret |= vcHr02ReadFifo(pvcHr02, DataLen); + } + return ret; +} + + +/* + * @brief + * Soft reset to make all registor + * Write 8'h5A to 8'h3B cause soft reset. + **/ +vcHr02Ret_t vcHr02SoftReset(vcHr02_t *pvcHr02) +{ + uint8_t Reset = 0x5A; + vcHr02Ret_t ret = VCHR02RET_ISOK; + + ret |= vcHr02WriteRegisters(VCREG10, (uint8_t *)&Reset, VCREG10_SIZE); + oscCnt = 0; + pvcHr02->oscCheckFinishFlag = 0; + fifoWriteIndex = 0; + fifoReadIndex = 0x80; + return ret; +} + + + +/* REGISTER_HR_SENSOR(hrSensor) = { */ +/* .logo = "hrs3603", */ +/* .heart_rate_sensor_init = hx3603_init, */ +/* .heart_rate_sensor_check = NULL, */ +/* .heart_rate_sensor_ctl = Hrs3603_io_ctl, */ +/* } ; */ +/* */ +/* REGISTER_LP_TARGET(hrs3603_lp_target) = { */ +/* .name = "hrs3603", */ +/* .is_idle = hrs3603_idle_query, */ +/* }; */ +#endif + diff --git a/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/vcHr02Hci.h b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/vcHr02Hci.h new file mode 100644 index 0000000..ebc2c6a --- /dev/null +++ b/2.code/2.p11_code/apps/common/device/hr_sensor/vchr02/vcHr02Hci.h @@ -0,0 +1,361 @@ +#ifndef LIB_vcHr02_HCI_vcHr02HCI_H_ +#define LIB_vcHr02_HCI_vcHr02HCI_H_ + +#if TCFG_VCHR02_DEV_ENABLE +#include +#include + + +#define VCHR02_SPO2_EN 1 +#define VCHR02_INT_IO IO_PORTB_03//IO_PORTB_01 + +struct _vchr02_dev_platform_data { + uint8_t iic_hdl; + uint8_t iic_delay; //这个延时并非影响iic的时钟频率,而是2Byte数据之间的延时 +}; +#define VCHR02_ADDR 0x33 +#define VCHR02_RADDR 0x67 +#define VCHR02_WADDR 0x66 + + +#include "algo.h" +/* + If your chip is VC31B/VC51B, please comment out these two codes. + 如果用的芯片是VC31B/VC51B,请注释掉下面两句包含头文件的代码。 +*/ +#if VCHR02_SPO2_EN +#include "spo2Algo.h" +// #include "vcSportMotionAlgo.h" +#endif +/***************************************************************************** +* +* Register Address Declaration +* +******************************************************************************/ +#if 1 +// Chose your chip model // +/* Read Only */ // 选择芯片型号 // +#define VCHR02ISVC31B 0 +#define VCHR02ISVC32S 0 + +#define VCHR02ISVC51B 0 +#define VCHR02ISVC52S 0//1 +#define VCHR02ISVC52T 0 +#define VCHR02ISVC9201 1//0 + +#define VCREG0 (0x00) +#define VCREG0_SIZE (1) +#define VCREG1 (0x01) +#define VCREG1_SIZE (1) +#define VCREG2 (0x02) +#define VCREG2_SIZE (1) +#define VCREG3 (0x03) +#define VCREG3_SIZE (1) +#define VCREG4 (0x04) +#define VCREG4_SIZE (1) +#define VCREG5 (0x05) +#define VCREG5_SIZE (1) +#define VCREG6 (0x06) +#define VCREG6_SIZE (1) +#define VCREG7 (0x07) +#define VCREG7_SIZE (2) +#define VCREG8 (0x09) +#define VCREG8_SIZE (2) +#define VCREG9 (0x80) +#define VCREG9_SIZE (128) + +/* Write Only */ +#define VCREG10 (0x3B) +#define VCREG10_SIZE (1) + +/* Read or Write */ +#define VCREG11 (0x10) +#define VCREG11_SIZE (1) +#define VCREG12 (0x11) +#define VCREG12_SIZE (1) +#define VCREG13 (0x12) +#define VCREG13_SIZE (1) +#define VCREG14 (0x13) +#define VCREG14_SIZE (1) +#define VCREG15 (0x14) +#define VCREG15_SIZE (2) +#define VCREG16 (0x16) +#define VCREG16_SIZE (1) +#define VCREG17 (0x17) +#define VCREG17_SIZE (1) +#define VCREG18 (0x18) +#define VCREG18_SIZE (1) +#define VCREG19 (0x19) +#define VCREG19_SIZE (1) +#define VCREG20 (0x1A) +#define VCREG20_SIZE (1) +#define VCREG21 (0x1B) +#define VCREG21_SIZE (1) +#define VCREG22 (0x1C) +#define VCREG22_SIZE (1) +#define VCREG23 (0x1D) +#define VCREG23_SIZE (1) +#define VCREG24 (0x1E) +#define VCREG24_SIZE (1) +#define VCREG25 (0x1F) +#define VCREG25_SIZE (1) +#define VCREG26 (0x20) +#define VCREG26_SIZE (1) +#define VCREG27 (0x21) +#define VCREG27_SIZE (1) + +/* Bit fields for VCREG1s */ +#define VCREG1_CONFLICT (0x01 << 4) +#define VCREG1_INSAMPLE (0x01 << 3) +#define VCREG1_INTPS (0x01 << 4) +#define VCREG1_INTOV (0x01 << 3) +#define VCREG1_INTFIFO (0x01 << 2) +#define VCREG1_INTENV (0x01 << 1) +#define VCREG1_INTPPG (0x01 << 0) + +//Threshold Settings +#if VCHR02ISVC31B +#define VCPS_TH 6 +#elif VCHR02ISVC32S +#define VCPS_TH 5 +#elif VCHR02ISVC51B +#define VCPS_TH 5 +#elif VCHR02ISVC52S +#define VCPS_TH 7//10 modify by Tatum,Using our demo for black testing 2020.04.12 +#elif VCHR02ISVC52T +#define VCPS_TH 4//6 modify by Tatum,Using our demo for black testing 2020.04.12 +#elif VCHR02ISVC9201 +#define VCPS_TH 10 +#endif + +#define VCENV_TH 8 // Causes of ENV interruption +#define VCPPG_TH 10 // Causes of PPG interruption PPG_TH = 300 +#define VCADJUST_INCREASE 22 // 1.4 << 4 = 22.4//1.4f +#define VCADJUST_DECREASE 11 // 0.7 << 4 = 11.2//0.7f +#define VCADJUST_STEP_MAX 32 +#define VCADJUST_STEP_MIN 1 + +#define VCUNWEAR_CNT 3 +#define VCISWEAR_CNT 1 + +#define SLOTCHNU 3 + + +/* + Wear Detection Function + 佩戴检测功能开关,ON为开,OFF为关 +*/ +#define VCWEAR_STATUS_DETECTION_OFF 0 +#define VCWEAR_STATUS_DETECTION_ON 1 +#define VCWEAR_STATUS_DETECTION_MODE VCWEAR_STATUS_DETECTION_ON + +#define VCWEAR_READ_FIFO_BY_TIME 0 +#define VCWEAR_READ_FIFO_BY_INT 1 +#define VCWEAR_READ_FIFO_MODE VCWEAR_READ_FIFO_BY_INT + +#define SportMotionEn 0 +#define BiometricEn 0 + +/***************************************************************************** +* +* Data Type Declaration +* +******************************************************************************/ +typedef enum { + VCWORK_MODE_HRWORK = 0, // Heart Rate Mode 心率模式 // + VCWORK_MODE_CROSSTALKTEST = 1, // Light Leakage Detection Mode 漏光检测模式 // + VCWORK_MODE_SPO2WORK = 2, // Blood Oxygen Saturation 血样模式 // + VCWORK_MODE_GSENSORWORK = 3, + VCWORK_MODE_TEMPWORK = 4, + VCWORK_MODE_NOISEWORK = 5, + VCWORK_MODE_LPDETECTION = 6, //LowpowerDeteciton +} vcHr02Mode_t; + +typedef enum { + VCHR02ADJUSTDIRECTION_NULL = 0, + VCHR02ADJUSTDIRECTION_UP = 1, + VCHR02ADJUSTDIRECTION_DOWN = 2, +} vcHr02AdjustDirection; + +typedef struct { + vcHr02AdjustDirection direction; + vcHr02AdjustDirection directionLast; + uint16_t step; +} vcHr02AdjustInfo_t; + +typedef enum { + VCHR02WEARST_UNWEAR = 0, + VCHR02WEARST_ISWEAR = 1, +} vcHr02WearStatus_e; + +typedef enum { + VCHR02RET_ISOK = 0, + VCHR02RET_ISWEARTOUNWEAR = 1, + VCHR02RET_UNWEARTOISWEAR = 2, + VCHR02RET_ISERR = 4, + VCHR02RET_ISCONFLICT = 8, + VCHR02RET_ISINSAMPLE = 16, + VCHR02RET_SOLTISOVERLOAD = 32, + VCHR02RET_PSISOVERLOAD = 64, + VCHR02RET_ENVCURRENTISLARGE = 128, + VCHR02RET_PSENVCURRENTISLARGE = 256, + VCHR02RET_PPGCANNOTADJUSTABLE = 512, + VCHR02RET_FIFOISOVERFLOW = 1024, + VCHR02RET_PDRESISMAX = 2048, + VCHR02RET_PDRESCANNOTRELEASE = 4096, +} vcHr02Ret_t; + +typedef struct { + uint8_t maxLedCur; + uint8_t pdResValue[3]; + uint8_t currentValue[3]; + uint8_t psValue; //PS Sample value. + uint8_t preValue[2]; //Environment Sample value. + uint8_t envValue[3]; //Environment Sample value. + uint16_t ppgValue[128]; //PPG sample value. +} vcHr02SampleData_t; + +typedef struct { + bool isRunning; + bool vcFifoReadFlag; + bool vcPsFlag; + bool oscCheckFinishFlag; + + uint8_t regConfig[17]; + uint8_t unWearCnt; + uint8_t isWearCnt; + uint8_t vcHr02Status; + uint8_t intReason; + vcHr02Mode_t workMode; + vcHr02WearStatus_e wearStatus; + + uint16_t vcSampleRate; + uint16_t mcuOscValue; + uint16_t mcuSclRate; + vcHr02AdjustInfo_t adjustInfo[2]; + vcHr02SampleData_t sampleData; +} vcHr02_t; + +/***************************************************************************** +* +* Function Declaration +* +******************************************************************************/ + +/* + * @brief + * Get sample datas from vcHr02. + * + **/ +vcHr02Ret_t vcHr02GetSampleValues(vcHr02_t *pvcHr02, uint8_t *DataLen); + + +/* + * @brief + * Manual start sample of vcHr02. + * + **/ +vcHr02Ret_t vcHr02StartSample(vcHr02_t *pvcHr02); + + +/* + * @brief + * Manual stop sample of vcHr02. + * + **/ +vcHr02Ret_t vcHr02StopSample(vcHr02_t *pvcHr02); + + +/* + * @brief + * Manual SoftReset the vcHr02 + * + **/ +vcHr02Ret_t vcHr02SoftReset(vcHr02_t *pvcHr02); + + +/* + * @brief + * + * + **/ +vcHr02Ret_t vcHr02TimeReadValues(vcHr02_t *pvcHr02, uint8_t *DataLen); + + + +/***************************************************************************** +* +* External Function Declaration +* +******************************************************************************/ +/* + * @brief + * + * + **/ +extern void vcHr02Init(vcHr02_t *pVcHr02, vcHr02Mode_t vcHr02WorkMode); + +/* + * @brief + * + * + **/ +extern void vcHr02_process(AlgoSportMode vcSportMode); + + +/* + * @brief + * + * + **/ +extern void vcHr02PhyInit(void); + + +/* + * @brief + * + * + **/ +extern void vcHr02IRQHandler(void); + + +/* + * @brief + * + * + **/ +extern vcHr02Ret_t vcHr02ReadRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); + + +/* + * @brief + * + * + **/ +extern vcHr02Ret_t vcHr02WriteRegisters(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); + + +/* + * @brief + * + * + **/ +extern uint32_t vcHr02GetRtcCountFromMCU(void); + + +/* + * @brief + * + * + **/ +extern void green_led_off_state_gsensor_abs_sum_diff_func(int32_t x_axis_value, int32_t y_axis_value, int32_t z_axis_value); + + +typedef vcHr02Ret_t (* vcHr02_read_cb)(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); +typedef vcHr02Ret_t (* vcHr02_write_cb)(uint8_t startAddress, uint8_t *pRegisters, uint8_t len); +typedef uint32_t (* vc_gettime_cb)(void); + +#endif /* LIB_vcHr02_HCI_vcHr02HCI_H_ */ +#endif +#endif + diff --git a/2.code/2.p11_code/apps/common/sport/sensor_api.c b/2.code/2.p11_code/apps/common/sport/sensor_api.c new file mode 100644 index 0000000..5d9c6e4 --- /dev/null +++ b/2.code/2.p11_code/apps/common/sport/sensor_api.c @@ -0,0 +1,529 @@ +#include "includes.h" +#include "sensor_api.h" +#include "gSensor_manage.h" +#include "hrSensor_manage.h" +#include "msg.h" +#include "gpio.h" +#include "circular_buf.h" +#include "bank_switch.h" +#include "usr_timer.h" + +#ifndef log_info +#define log_info(...) // printf +#endif +#ifndef log_e +#define log_e(...) //printf +#endif +/* */ +/* #pragma bss_seg(".sensor_api_bss") */ +/* #pragma const_seg(".sensor_api_const") */ +/* #pragma code_seg(".sensor_api_code") */ +/* */ + + +#if CONFIG_SENSOR_ALG_ENABLE +static volatile u8 sensor_irq[3]; + +static struct SENSOR_SHARE_PORT sensor_port; + +int p33_wkup_takeover(u8 index, u8 gpio) +{ + /* printf("index %x,%x\n", index, gpio); */ + +#if 0 + if (gpio == IO_PORTB_03) {//gsensor + write_gsensor_data_handle(); + return true; + } +#endif /* #if */ +#if TCFG_HR_SENSOR_READ_BY_INT +#if TCFG_VCHR02_DEV_ENABLE || TCFG_VCHR11S_DEV_ENABLE + if (gpio == IO_PORTB_03) {//vchr02 + write_gsensor_data_handle(); + hr_sensor_req_irq(); + return true; + } +#endif /* #if */ +#endif + return false; +} + + + + + +//==========================================================// +// gSensor // +//==========================================================// +#if TCFG_GSENSOR_ENABLE +#if TCFG_SC7A20_EN +GSENSOR_PLATFORM_DATA_BEGIN(gSensor_data) +.iic = 0, + .gSensor_name = "sc7a20", + /* .gSensor_int_io = (-1),//IO_PORTB_03, */ + .gSensor_int_io = IO_PORTB_03, + GSENSOR_PLATFORM_DATA_END(); +#endif //end if TCFG_SC7A20_EN + +#if TCFG_SC7A20E_EN +GSENSOR_PLATFORM_DATA_BEGIN(gSensor_data) +.iic = 0, + .gSensor_name = "sc7a20e", + /* .gSensor_int_io = (-1),//IO_PORTB_03, */ + .gSensor_int_io = IO_PORTB_03, + GSENSOR_PLATFORM_DATA_END(); +#endif //end if TCFG_SC7A20E_EN + +#if TCFG_SC7A20H_EN +GSENSOR_PLATFORM_DATA_BEGIN(gSensor_data) +.iic = 0, + .gSensor_name = "sc7a20h", + /* .gSensor_int_io = (-1),//IO_PORTB_03, */ + .gSensor_int_io = IO_PORTB_03, + GSENSOR_PLATFORM_DATA_END(); +#endif //end if TCFG_SC7A20H_EN + +#if TCFG_MSA310_EN||TCFG_MSA31X_EN +GSENSOR_PLATFORM_DATA_BEGIN(gSensor_data) +.iic = 0, + .gSensor_name = "msa310", + .gSensor_int_io = IO_PORTB_03, + GSENSOR_PLATFORM_DATA_END(); +#endif //end if TCFG_MSA310_EN + +#if TCFG_MIR3DA_EN +GSENSOR_PLATFORM_DATA_BEGIN(gSensor_data) +.iic = 0, + .gSensor_name = "mir3da", + .gSensor_int_io = IO_PORTB_03, + GSENSOR_PLATFORM_DATA_END(); +#endif //end if TCFG_MIR3DA_EN + +#if TCFG_STK832X_EN +GSENSOR_PLATFORM_DATA_BEGIN(gSensor_data) +.iic = 0, + .gSensor_name = "stk832x", + .gSensor_int_io = IO_PORTB_03, + GSENSOR_PLATFORM_DATA_END(); +#endif //end if TCFG_STK832X_EN + +#endif //end if CONFIG_GSENSOR_ENABLE + + + +//==========================================================// +// hr_sensor // +//==========================================================// +#if (TCFG_HR_SENSOR_ENABLE||TCFG_SPO2_SENSOR_ENABLE) + +#if TCFG_HRS3300_EN +HRSENSOR_PLATFORM_DATA_BEGIN(hrSensor_data) +.iic = 0, + .hrSensor_name = "hrs3300", + HRSENSOR_PLATFORM_DATA_END() +#endif + +#if TCFG_HRS3602_DEV_ENABLE + HRSENSOR_PLATFORM_DATA_BEGIN(hrSensor_data) + .iic = 0, + .hrSensor_name = "hrs3602", + .hrSensor_int_io = -1,//IO_PORTB_00, + HRSENSOR_PLATFORM_DATA_END() +#endif//TCFG_HRS3603_EN +#if TCFG_HRS3603_DEV_ENABLE + HRSENSOR_PLATFORM_DATA_BEGIN(hrSensor_data) + .iic = 0, + .hrSensor_name = "hrs3603", + .hrSensor_int_io = -1,//IO_PORTB_00, + HRSENSOR_PLATFORM_DATA_END() +#endif//TCFG_HRS3603_EN + +#if TCFG_VCHR02_DEV_ENABLE + HRSENSOR_PLATFORM_DATA_BEGIN(hrSensor_data) + .iic = 0, + .hrSensor_name = "vchr02", + .hrSensor_int_io = IO_PORTB_03,//与gsensor分开,IO_PORTB_00, + HRSENSOR_PLATFORM_DATA_END() +#endif//TCFG_HRS3603_EN + +#if TCFG_VCHR11S_DEV_ENABLE + HRSENSOR_PLATFORM_DATA_BEGIN(hrSensor_data) + .iic = 0, + .hrSensor_name = "vchr11s", + .hrSensor_int_io = IO_PORTB_03,//与gsensor分开,IO_PORTB_00, + HRSENSOR_PLATFORM_DATA_END() +#endif//TCFG_HRS3603_EN + +#endif//TCFG_HR_SENSOR_ENABLE + + + void sensor_init() +{ + bank_code_switch(BANK_SENSOR_TAG, BANK_CODE_SENSOR_INIT_BANK_0); +#if TCFG_GSENSOR_ENABLE + + gravity_sensor_init((struct gsensor_platform_data *)&gSensor_data, (cbuffer_t *)sensor_port.sensor_hd[N_GSENSOR]); +#endif //end if CONFIG_GSENSOR_ENABLE + +#if (TCFG_HR_SENSOR_ENABLE||TCFG_SPO2_SENSOR_ENABLE) + hr_sensor_init((struct hrsensor_platform_data *)&hrSensor_data, (cbuffer_t *)sensor_port.sensor_hd[N_HR_SENSOR], (cbuffer_t *)sensor_port.sensor_hd[N_SPO2_SENSOR]); +#endif + + bank_code_switch(BANK_SENSOR_TAG, BANK_CODE_SENSOR_NORMAL_BANK_1); + int size = ((25 + 10) * 3 * 2); //设置超时唤醒 + //point 200 *3 *u16 + sensor_hub_ioctl(G_SENSOR_SET_IRQ_SIZE, sizeof(size), (u8 *)(&size)); + + int msg[2]; + msg[0] = sizeof(sensor_port.sensor_hd); + msg[1] = sensor_port.sensor_hd; + user_p11_post_to_main_system(1, sizeof(msg), (u8 *)msg, 1); //配置主核共享空间 + + sensor_hub_ioctl(HR_SENSORHUB_DISABLE, 0, NULL); + sensor_hub_gsensor_enable(0); + sensor_hub_spo2sensor_enable(0); +} + + + + + +void sensorhub_irq_add(u8 index) +{ + sensor_irq[index]++; +} + +void sensorhub_irq_del(u8 index) +{ + if (sensor_irq[index]) { + sensor_irq[index]--; + } +} + +u8 sensorhub_irq_check(u8 index) +{ + return sensor_irq[index]; +} + +void iic_host_check() +{ +#if CONFIG_SENSOR_ALG_ENABLE + /* 计算心率需要gSensor数据,所以应先读出gSensor数据 */ + if (sensorhub_irq_check(IRQ_GSENSOR_INDEX)) { + sensorhub_irq_del(IRQ_GSENSOR_INDEX); + gsensor_data_irq_handle(); + if (sensorhub_irq_check(IRQ_GSENSOR_INDEX)) { + printf("lost\n"); + } + } + + if (sensorhub_irq_check(IRQ_HRSENSOR_INDEX)) { + sensorhub_irq_del(IRQ_HRSENSOR_INDEX); + hr_sensor_io_ctl(HR_SENSOR_IRQ, 0); + if (sensorhub_irq_check(IRQ_HRSENSOR_INDEX)) { + printf("lost\n"); + } + } + + if (sensorhub_irq_check(IRQ_SPO2SENSOR_INDEX)) { + sensorhub_irq_del(IRQ_SPO2SENSOR_INDEX); + hr_sensor_io_ctl(SPO2_SENSOR_IRQ, 0); + if (sensorhub_irq_check(IRQ_SPO2SENSOR_INDEX)) { + printf("lost\n"); + } + } + +#endif +} + + + +#if 0 + + +#if 1 +#define iic_init(iic) hw_iic_init() +#define iic_close(iic) hw_iic_close() +#define iic_start(iic) hw_iic_start() +#define iic_stop(iic) hw_iic_stop() +#define iic_tx_byte(iic, byte) hw_iic_master_tx_byte(byte) +#define iic_rx_byte(iic, ack) hw_iic_master_rx_byte(ack) +#define iic_read_buf(iic, buf, len) hw_iic_master_read_buf(buf, len) +#define iic_write_buf(iic, buf, len) hw_iic_master_write_buf(buf, len) +/* #define iic_suspend(iic) hw_iic_suspend() */ +/* #define iic_resume(iic) hw_iic_resume() */ +#else +#define iic_init(iic) soft_iic_init(iic) +#define iic_close(iic) soft_iic_uninit(iic) +#define iic_start(iic) soft_iic_start(iic) +#define iic_stop(iic) soft_iic_stop(iic) +#define iic_tx_byte(iic, byte) soft_iic_tx_byte(iic, byte) +#define iic_rx_byte(iic, ack) soft_iic_rx_byte(iic, ack) +#define iic_read_buf(iic, buf, len) soft_iic_read_buf(iic, buf, len) +#define iic_write_buf(iic, buf, len) soft_iic_write_buf(iic, buf, len) +/* #define iic_suspend(iic) soft_iic_suspend(iic) */ +/* #define iic_resume(iic) soft_iic_resume(iic) */ +#endif + +#define DELAY_CNT (10) + +u8 sensor_iic0_write(u8 w_chip_id, u8 register_address, u8 function_command) +{ + u8 ret = 1; + iic_start(0); + if (0 == iic_tx_byte(0, w_chip_id)) { + ret = 0; + log_e("\n gsen iic wr err 0\n"); + goto __gcend; + } + delay(DELAY_CNT); + if (0 == iic_tx_byte(0, register_address)) { + ret = 0; + log_e("\n gsen iic wr err 1\n"); + goto __gcend; + } + delay(DELAY_CNT); + if (0 == iic_tx_byte(0, function_command)) { + ret = 0; + log_e("\n gsen iic wr err 2\n"); + goto __gcend; + } +__gcend: + iic_stop(0); + return ret; +} + +u16 sensor_iic0_read(u8 r_chip_id, u8 register_address, u8 *buf, u16 data_len) +{ + u16 read_len = 0; + + iic_start(0); + if (0 == iic_tx_byte(0, r_chip_id - 1)) { + log_e("\n gsen iic rd err 0\n"); + read_len = 0; + goto __gdend; + } + + delay(DELAY_CNT); + + if (0 == iic_tx_byte(0, register_address)) { + log_e("\n gsen iic rd err 1\n"); + read_len = 0; + goto __gdend; + } + + iic_start(0); + if (0 == iic_tx_byte(0, r_chip_id)) { + log_e("\n gsen iic rd err 2\n"); + read_len = 0; + goto __gdend; + } + + delay(DELAY_CNT); + + for (; data_len > 1; data_len--) { + *buf++ = iic_rx_byte(0, 1); + read_len ++; + } + + *buf = iic_rx_byte(0, 0); + read_len ++; + +__gdend: + iic_stop(0); + delay(DELAY_CNT); + return read_len; +} + + +int sensor_iic0_init() +{ + iic_init(0); + return 0; +} + +#endif + +static int case_gsensor_cmd(u8 means, u16 priv, u16 len, u8 *data) +{ + int ret = 0; + int size; + switch (means) { + case SENSOR_READ: + ret = read_gsensor_nbuf(data, len); + break; + case SENSOR_CHECK_READ_BUF: + ret = read_gsensor_buf_check_len(); + break; + case SENSOR_SET_IRQ_BUF_SIZE: + memcpy(&size, data, len); + ret = gsensor_set_soft_irq_size(size); + break; + } + return ret; +} + + + +static int case_hr_sensor_cmd(u8 means, u16 priv, u16 len, u8 *data) +{ + int ret = 0; + int size; + int msg[3]; + switch (means) { + case SENSOR_ENABLE: + hr_sensor_io_ctl(HR_SENSOR_ENABLE, 0); + break; + case SENSOR_DIASBLE: + hr_sensor_io_ctl(HR_SENSOR_DISABLE, 0); + break; + case SENSOR_CHECK_READ_BUF: + ret = hr_sensor_io_ctl(HR_SENSOR_CHECK_DATA, 0); + break; + case SENSOR_READ: + msg[0] = data; + msg[1] = len; + ret = hr_sensor_io_ctl(HR_SENSOR_READ_DATA, msg); + break; + } + return ret; +} + +int sensor_hub_ioctl(int cmd, u16 len, u8 *data) +{ + u8 type = CMD2TYPE(cmd); + u8 means = CMD2MEANS(cmd); + u16 user = CMD2USER(cmd); + switch (type) { + case SPO2_CMD: + + break; + case HR_SENSOR_CMD: + return case_hr_sensor_cmd(means, user, len, data); + break; + case G_SENSOR_CMD: + return case_gsensor_cmd(means, user, len, data); + break; + } + return len; +} + + + + + +int sensor_hub_gsensor_enable(u8 on) +{ + int ret = 0; + + if (on) { + ret = gsensor_enable(); + } else { + ret = gsensor_disable(); + } + + if (ret == 0) { + sensor_hub_timer_enable(on); + } + return ret; +} + + +int sensor_hub_gsensor_check_len() +{ + return read_gsensor_buf_check_len(); +} + +int sensor_hub_gsensor_read(u8 *data, u16 len) +{ + return read_gsensor_nbuf(data, len); +} + +int sensor_hub_hrsensor_low_power_detection(void) +{ + return hr_sensor_io_ctl(HR_SENSOR_LP_DETECTION, 0); +} + +int sensor_hub_hrsensor_factory_test(void) +{ + return hr_sensor_io_ctl(HR_SENSOR_FACTORY_TEST, 0); +} + +int sensor_hub_hrsensor_check_len() +{ + return hr_sensor_io_ctl(HR_SENSOR_CHECK_DATA, 0); +} + +int sensor_hub_hrsensor_read(u8 *data, u16 len) +{ + int msg[2]; + msg[0] = data; + msg[1] = len; + return hr_sensor_io_ctl(HR_SENSOR_READ_DATA, msg); +} + +int sensor_hub_hrsensor_enable(u8 on) +{ + if (on) { + return hr_sensor_io_ctl(HR_SENSOR_ENABLE, 0); + } else { + return hr_sensor_io_ctl(HR_SENSOR_DISABLE, 0); + } +} + + +int sensor_hub_spo2sensor_check_len() +{ + return 0; +} + +int sensor_hub_spo2ensor_read(u8 *data, u16 len) +{ + return 0; +} + +int sensor_hub_spo2sensor_enable(u8 on) +{ + if (on) { + return hr_sensor_io_ctl(SPO2_SENSOR_ENABLE, 0); + } else { + return hr_sensor_io_ctl(SPO2_SENSOR_DISABLE, 0); + } +} + +int sensor_hub_gsensor_search(u32 *valid) +{ + gsensor_io_ctl(SEARCH_SENSOR, valid); + return 0; +} +int sensor_hub_hrsensor_search(u32 *valid) +{ + hr_sensor_io_ctl(HR_SEARCH_SENSOR, valid); + return 0; + +} + + +static void sensor_hub_timer_handle(void *priv) +{ + write_gsensor_data_handle(); + +#if !TCFG_HR_SENSOR_READ_BY_INT + hr_sensor_req_irq(); +#endif +} + +int sensor_hub_timer_enable(u8 enable) +{ + static u16 sensor_hub_timer = 0; + + if (enable && sensor_hub_timer == 0) { + sensor_hub_timer = usr_timer_add(NULL, sensor_hub_timer_handle, 200, 0); + } else if ((!enable) && sensor_hub_timer > 0) { + usr_timer_del(sensor_hub_timer); + sensor_hub_timer = 0; + } + + return 0; +} +#endif /* #if TCFG_GSENSOR_ENABLE */ diff --git a/2.code/2.p11_code/apps/common/sport/sensor_api.h b/2.code/2.p11_code/apps/common/sport/sensor_api.h new file mode 100644 index 0000000..5edeb28 --- /dev/null +++ b/2.code/2.p11_code/apps/common/sport/sensor_api.h @@ -0,0 +1,101 @@ +#ifndef __SENSOR_API_H__ +#define __SENSOR_API_H__ + + +#define IRQ_GSENSOR_INDEX (0) +#define IRQ_HRSENSOR_INDEX (1) +#define IRQ_SPO2SENSOR_INDEX (2) + + +//类型和办法转变为 对应的cmd +#define SENSOR_TYPE(x) ((x) << 24) +#define SENSOR_MEANS(x) ((x) << 16) +#define SENSOR_USER(x) ((x)) + + +//cmd 转变为 对应的类型和办法 +#define CMD2TYPE(x) (((x)>>24)&0xff) +#define CMD2MEANS(x) (((x)>>16)&0xff) +#define CMD2USER(x) (((x))&0xffff) + + +//传感器类型,最大支持255 +#define SPO2_CMD (1) +#define HR_SENSOR_CMD (2) +#define G_SENSOR_CMD (3) + + + +//传感器办法,最大支持255 +#define SENSOR_DIASBLE (0) +#define SENSOR_ENABLE (1) +#define SENSOR_READ (2) +#define SENSOR_WRITE (3) +#define SENSOR_INIT (4) +#define SENSOR_CHECK_READ_BUF (5) +#define SENSOR_SET_IRQ_BUF_SIZE (6) + + +//用户需要自定义携带信息,16位,sdk暂时没有使用 +#define USER_PRIV_NULL 0 + + +//spo2 命令和办法 +#define SPO2_SENSORHUB_DISABLE (SENSOR_TYPE(SPO2_CMD)|SENSOR_MEANS(SENSOR_DIASBLE)|SENSOR_USER(0)) +#define SPO2_SENSORHUB_ENABLE (SENSOR_TYPE(SPO2_CMD)|SENSOR_MEANS(SENSOR_ENABLE)|SENSOR_USER(0)) +#define SPO2_SENSORHUB_READ_DATA (SENSOR_TYPE(SPO2_CMD)|SENSOR_MEANS(SENSOR_READ)|SENSOR_USER(0)) +#define SPO2_SENSORHUB_INIT (SENSOR_TYPE(SPO2_CMD)|SENSOR_MEANS(SENSOR_INIT)|SENSOR_USER(0)) + + +//心率模块 命令和办法 +#define HR_SENSORHUB_DISABLE (SENSOR_TYPE(HR_SENSOR_CMD)|SENSOR_MEANS(SENSOR_DIASBLE)|SENSOR_USER(0)) +#define HR_SENSORHUB_ENABLE (SENSOR_TYPE(HR_SENSOR_CMD)|SENSOR_MEANS(SENSOR_ENABLE)|SENSOR_USER(0)) +#define HR_SENSORHUB_READ_DATA (SENSOR_TYPE(HR_SENSOR_CMD)|SENSOR_MEANS(SENSOR_READ)|SENSOR_USER(0)) +#define HR_SENSORHUB_CHECK_LEN (SENSOR_TYPE(HR_SENSOR_CMD)|SENSOR_MEANS(SENSOR_CHECK_READ_BUF)|SENSOR_USER(0)) + + +//gsensor 模块 命令和办法 +#define G_SENSOR_DISABLE (SENSOR_TYPE(G_SENSOR_CMD)|SENSOR_MEANS(SENSOR_DIASBLE)|SENSOR_USER(0)) +#define G_SENSOR_ENABLE (SENSOR_TYPE(G_SENSOR_CMD)|SENSOR_MEANS(SENSOR_ENABLE)|SENSOR_USER(0)) +#define G_SENSOR_READ_DATA (SENSOR_TYPE(G_SENSOR_CMD)|SENSOR_MEANS(SENSOR_READ)|SENSOR_USER(0)) +#define G_SENSOR_READ_CHECK_LEN (SENSOR_TYPE(G_SENSOR_CMD)|SENSOR_MEANS(SENSOR_CHECK_READ_BUF)|SENSOR_USER(0)) +#define G_SENSOR_SET_IRQ_SIZE (SENSOR_TYPE(G_SENSOR_CMD)|SENSOR_MEANS(SENSOR_SET_IRQ_BUF_SIZE)|SENSOR_USER(0)) + + +extern int sensor_hub_timer_enable(u8 enable); + +extern int sensor_hub_ioctl(int cmd, u16 len, u8 *data); + +extern void sensorhub_irq_add(u8 index); + +extern void sensorhub_irq_del(u8 index); + +extern u8 sensorhub_irq_check(u8 index); + + +extern int sensor_hub_gsensor_enable(u8 on); + +extern int sensor_hub_gsensor_check_len(); + +extern int sensor_hub_gsensor_read(u8 *data, u16 len); + +extern int sensor_hub_hrsensor_low_power_detection(void); + +extern int sensor_hub_hrsensor_factory_test(void); + +extern int sensor_hub_hrsensor_check_len(); + +extern int sensor_hub_hrsensor_read(u8 *data, u16 len); + +extern int sensor_hub_hrsensor_enable(u8 on); + +extern int sensor_hub_spo2sensor_enable(u8 on); + +extern int sensor_hub_gsensor_search(u32 *valid); + +extern int sensor_hub_hrsensor_search(u32 *valid); + +extern void sensor_init(); + + +#endif diff --git a/2.code/2.p11_code/apps/debug.c b/2.code/2.p11_code/apps/debug.c new file mode 100644 index 0000000..7628dbd --- /dev/null +++ b/2.code/2.p11_code/apps/debug.c @@ -0,0 +1,31 @@ +#include "includes.h" +#include "app_config.h" + +#if (CONFIG_UART_DEBUG_ENABLE == 0) +void putchar(char a) +{ +} + +void putbyte(char a) +{ +} + +int puts(const char *out) +{ + return 0; +} + +void put_u32hex(unsigned int dat) +{ +} + +void put_buf(const u8 *buf, int len) +{ +} + +int printf(const char *format, ...) +{ + return 0; +} + +#endif /* #if (CONFIG_UART_DEBUG_ENABLE == 0) */ diff --git a/2.code/2.p11_code/apps/lib_config.c b/2.code/2.p11_code/apps/lib_config.c new file mode 100644 index 0000000..f5a803f --- /dev/null +++ b/2.code/2.p11_code/apps/lib_config.c @@ -0,0 +1,23 @@ +#include "app_config.h" +#include "gSensor_manage.h" +#include "hrSensor_manage.h" + +//==========================================================// +// VAD库使能开关 // +//==========================================================// +const int LIB_CONFIG_VAD_ENABLE = CONFIG_VAD_ENABLE; + +//==========================================================// +// LPCTMU库使能开关 // +//==========================================================// +const int LIB_CONFIG_LPCTMU_ENABLE = CONFIG_LPCTMU_ENABLE; + +//==========================================================// +// 异常函复位开关 // +//==========================================================// +const int LIB_CONFIG_EXCEPTION_RESET_ENABLE = !CONFIG_UART_DEBUG_ENABLE; + +//==========================================================// +// DVAD第三方算法使能开关 // +//==========================================================// +const int CONFIG_DVAD_DEVELOP_ENABLE = 0; diff --git a/2.code/2.p11_code/apps/main.c b/2.code/2.p11_code/apps/main.c new file mode 100644 index 0000000..6244782 --- /dev/null +++ b/2.code/2.p11_code/apps/main.c @@ -0,0 +1,287 @@ +/********************************************************************************************* + * Filename : main.c + + * Description : P11系统Main循环 + + * Author : MoZhiYe + + * Email : mozhiye@zh-jieli.com + + * Last modifiled : 2021-06-23 09:00 + + * Copyright:(c)JIELI 2021-2029 @ , All Rights Reserved. +*********************************************************************************************/ +#ifdef SUPPORT_MS_EXTENSIONS +#pragma bss_seg(".app.bss") +#pragma data_seg(".app.data") +#pragma const_seg(".app.const") +#pragma code_seg(".app.text") +#pragma str_literal_override(".app.text") +#endif /* #ifdef SUPPORT_MS_EXTENSIONS */ + +#include "includes.h" +#include "uart.h" +#include "debug.h" +#include "app_config.h" +#include "gpio.h" +#include "ram_share.h" + +#include "msg.h" +#include "timer.h" +#include "sensor_api.h" +#include "hrSensor_manage.h" + +#include "bank_switch.h" + +#include "gSensor_manage.h" +#include "lp_timer_api.h" + +#include "usr_timer.h" + +/* #pragma bss_seg(".main_bss") */ +/* #pragma const_seg(".main_const") */ +/* #pragma code_seg(".main_code") */ +/* */ + + +const struct bank_info bank_info_table[] = { + {BANK_DEMO_TAG, BANK_CODE_DEMO_BANK_MAX, (u32)overlay_demo_begin}, + {BANK_SENSOR_TAG, BANK_CODE_SENSOR_BANK_MAX, (u32)overlay_sensor_begin}, + {NULL, 0} +}; + + + +#if 0 +static void test_get_cur_500ms_tick() +{ + printf("\n tick \n"); + +} +LOOP_DETECT_REGISTER(NULL, 500, test_get_cur_500ms_tick); +#endif + + + + +void user_main_init() +{ +#if CONFIG_SENSOR_ALG_ENABLE + user_p11_p2m_post_init(); + task_message_init(); + timer_tick_init(); + sensor_init(); + extern int vir_p11_i2c_init(); + vir_p11_i2c_init(); +#endif +} + + + +extern void iic_host_check(); + + + +extern int sensor_hub_gsensor_enable(u8 on); + +extern int sensor_hub_gsensor_check_len(); + +extern int sensor_hub_gsensor_read(u8 *data, u16 len); + +extern int sensor_hub_hrsensor_check_len(); + +extern int sensor_hub_hrsensor_read(u8 *data, u16 len); + +extern int sensor_hub_hrsensor_enable(u8 on); + + +extern int sensor_hub_spo2sensor_enable(u8 on); + + +extern int gravity_sensor_write(u8 w_chip_id, u8 *data, u8 length); +extern int _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, int data_len); + + + +#if CONFIG_SENSOR_ALG_ENABLE + +volatile u8 vir_iic_m2p_wbuf[256]; + +int vir_p11_i2c_init() +{ + int msg[2]; + msg[0] = sizeof(vir_iic_m2p_wbuf); + msg[1] = vir_iic_m2p_wbuf; + user_p11_post_to_main_system(P11_SYS_IIC_INIT_SYNC, sizeof(msg), (u8 *)msg, 1); //配置主核共享空间 + return 0; +} + +//iic 地址是7bit地址 +int vir_p11_i2c_write_regs(u8 dev, u8 address, + u8 *data, size_t length) +{ + int ret = gravity_sensor_write(address << 1, data, length); + if (ret != length) { + return 0; + } + return length; +} + + + +//iic 地址是7bit地址 +int vir_p11_i2c_read_regs(u8 dev, u16 address, u8 reg, + u8 *data, u16 length) +{ + int ret; + ret = _gravity_sensor_get_ndata(((address << 1) | 1), reg, data, length); + return ret; +} + +#endif + + + +int user_run_loop() +{ + int msg = NO_MSG; + int error = MSG_NO_ERROR; + int data = 0; +#if CONFIG_SENSOR_ALG_ENABLE +__again: + while (1) { + error = task_get_msg(0, 1, &msg); + if (NO_MSG == msg) { + return 0; + } + switch (msg) { + case P11_SYS_KICK: + iic_host_check(); + break; + case P11_SYS_IIC_R_SYNC: + ASSERT(vir_iic_m2p_wbuf[0] & BIT(7)); + ASSERT((vir_iic_m2p_wbuf[0] & 3) == 1); //暂时读支持u8 寄存器 + vir_iic_m2p_wbuf[1] = vir_p11_i2c_read_regs(vir_iic_m2p_wbuf[1], vir_iic_m2p_wbuf[2], vir_iic_m2p_wbuf[4], (u8 *)&vir_iic_m2p_wbuf[5], vir_iic_m2p_wbuf[3]); + vir_iic_m2p_wbuf[0] = 0; + break; + case P11_SYS_IIC_W_SYNC: + ASSERT(vir_iic_m2p_wbuf[0] == BIT(6)); + vir_iic_m2p_wbuf[1] = vir_p11_i2c_write_regs(vir_iic_m2p_wbuf[1], vir_iic_m2p_wbuf[2], (u8 *)&vir_iic_m2p_wbuf[4], vir_iic_m2p_wbuf[3]); + vir_iic_m2p_wbuf[0] = 0; + break; + + + case P11_SYS_GSENSOR_START: + printf("P11_SYS_GSENSOR_START\n"); + sensor_hub_gsensor_enable(1); + break; + case P11_SYS_GSENSOR_STOP: + printf("P11_SYS_GSENSOR_STOP\n"); + sensor_hub_gsensor_enable(0); + break; + case P11_SYS_HRSENSOR_START: + printf("P11_SYS_HRSENSOR_START\n"); + sensor_hub_hrsensor_enable(1); + break; + case P11_SYS_HRSENSOR_STOP: + printf("P11_SYS_HRSENSOR_STOP\n"); + sensor_hub_hrsensor_enable(0); + break; + case P11_SYS_HRSENSOR_LP_DETECT: + printf("P11_SYS_HRSENSOR_LP_DETECT\n"); + sensor_hub_hrsensor_low_power_detection(); + break; + case P11_SYS_HRSENSOR_FACTORY_TEST: + printf("P11_SYS_HRSENSOR_FACTORY_TEST\n"); + sensor_hub_hrsensor_factory_test(); + break; + case P11_SYS_SPO2_START: + printf("P11_SYS_SPO2SENSOR_START\n"); + sensor_hub_spo2sensor_enable(1); + break; + case P11_SYS_SPO2_STOP: + printf("P11_SYS_SPO2SENSOR_STOP\n"); + sensor_hub_spo2sensor_enable(0); + break; + /* case P11_SYS_GSENSOR_SEARCH: */ + /* case P11_SYS_HRSENSOR_SEARCH: */ + /* printf("P11_SYS_SENSOR_SEARCH\n"); */ + /* break; */ + } + } + goto __again; +#endif + return 0; +} + + + +/*======================================================================== + * @brief: p11主循环 + * + * @param: + * @return: + ========================================================================*/ +static void p11_run_loop(void) +{ + while (1) { + p11_power_hw_manage(); + user_run_loop(); + } +} +/*======================================================================== + * @brief: Main函数 + * + * @param: + * @return: + ========================================================================*/ + +#include "iic_soft.h" + +static void usr_timer_test(void *priv) +{ + printf("fun:%s, %d\n", __FUNCTION__, __LINE__); +} + +int main(void) +{ + local_irq_disable(); + +#if CONFIG_UART_DEBUG_ENABLE + debug_uart_init(IO_PORTB_09); +#endif /* #if CONFIG_UART_DEBUG_ENABLE */ + + printf("\n============ Hello BR28 P11 ============ \n"); + + p11_q32s(0)->PMU_CON |= BIT(2); //P11 WKUP EN + printf("p11_q32s(0)->PMU_CON = 0x%x\n", p11_q32s(0)->PMU_CON); + + debug_init(); //异常检测初始化 + +#if CONFIG_SENSOR_ALG_ENABLE + soft_iic_init(0);//some sensor need wait iic idle little ms +#endif + usr_timer_init(); + + power_init(); + + iovdd2_bypass_iovdd(1); + + local_irq_enable(); + printf("[boot]Interrupt ready \n"); + + mdelay(100); + + //usr_timer_add(NULL, usr_timer_test, 100, 0); + + user_main_init(); + p11_run_loop(); + +} + + + + + + + diff --git a/2.code/2.p11_code/apps/msg.c b/2.code/2.p11_code/apps/msg.c new file mode 100644 index 0000000..12f7571 --- /dev/null +++ b/2.code/2.p11_code/apps/msg.c @@ -0,0 +1,331 @@ +#include "includes.h" +#include "ram_share.h" +#include "msg.h" +#include "sensor_api.h" +#include "app_config.h" +#include "circular_buf.h" +#include "sensor_api.h" +/* */ +/* #pragma bss_seg(".msg_bss") */ +/* #pragma const_seg(".msg_const") */ +/* #pragma code_seg(".msg_code") */ +/* */ + + +#define P11_USER_POST_TO_MSYS(x) (P11_SYSTEM->P2M_INT_SET |= BIT((x))) +#define P11_USER_P2M_ENABLE(x) (P11_SYSTEM->P2M_INT_IE |= BIT((x))) +#define P11_USER_P2M_DISABLE(x) (P11_SYSTEM->P2M_INT_IE &= ~BIT((x))) + + +#define MSYS_USER_POST_TO_P11(x) (P11_SYSTEM->M2P_INT_SET |= BIT((x))) + +#define USER_P2M_BASE_ADDR (P2M_USER_PEND) +#define USER_M2P_BASE_ADDR (M2P_USER_PEND) + +#define USER_MSG_PEND_BASE (0) +#define USER_MSG_TYPE_BASE (1) +#define USER_MSG_LEN_BASE (2) +#define USER_MSG_ADDR_BASE (4) + +static int send_ram[(256) / 4]; + +static cbuffer_t msg_cbuf; +static u32 msg_pool[64]; + + + + +void task_clear_all_message(void) +{ + cbuf_clear(&msg_cbuf); +} + +void task_message_init() +{ + cbuf_init(&msg_cbuf, msg_pool, sizeof(msg_pool)); + cbuf_clear(&msg_cbuf); +} + +int task_post_msg(char *name, int argc, ...) +{ + u16 msg_value = 0x0fff; + int i = 0; + int param_len = 0; + int param = 0; + ENTER_CRITICAL(); + va_list argptr; + va_start(argptr, argc); + for (i = 0; i < argc; ++i) { + if (i == 0) { + msg_value = 0x0fff & va_arg(argptr, int); + if (msg_value == MSG_CLEAN_ALL_MSG) { + cbuf_clear(&msg_cbuf); + va_end(argptr); + EXIT_CRITICAL(); + return 0; + } + param_len = argc - 1; + msg_value = (param_len << 12) | msg_value; + cbuf_write(&msg_cbuf, (void *)&msg_value, 2); + + } else { + param = va_arg(argptr, int); + cbuf_write(&msg_cbuf, (void *)¶m, 4); + } + } + va_end(argptr); + EXIT_CRITICAL(); + return 0; +} + +int task_get_msg(u16 timeout, int len, int *msg) +{ + u16 msg_value = 0x0fff; + u8 param_len = 0; + int i = 0; + int param; + u32 event, event_to_msg; + //debug + for (i = 0; i < len; i++) { + msg[i] = 0x0fff; + } + + + ENTER_CRITICAL(); + if (2 != cbuf_read(&msg_cbuf, (void *)&msg_value, 2)) { + /* memset(msg, NO_MSG, len); */ + EXIT_CRITICAL(); + return MSG_NO_ERROR; + } + + msg[0] = msg_value & 0x0fff; + param_len = msg_value >> 12; + for (i = 0 ; i < param_len; i++) { + cbuf_read(&msg_cbuf, (void *)¶m, 4); + if (i + 1 < len) { + msg[i + 1] = param; + } + } + if (i >= len) { + puts("msg_buf_not_enc\n"); + EXIT_CRITICAL(); + return MSG_BUF_NOT_ENOUGH; + } + EXIT_CRITICAL(); + return 0; +} + +__INLINE__ +void mdebug_io_1(u8 i) +{ + P11_PORT->PB_SEL |= BIT(i); //P11 Control + P11_PORT->PB_DIR &= ~BIT(i); //dir output + P11_PORT->PB_OUT |= BIT(i); //output 1 +} + + +__INLINE__ +void mdebug_io_0(u8 i) +{ + P11_PORT->PB_SEL |= BIT(i); //P11 Control + P11_PORT->PB_DIR &= ~BIT(i); //dir output + P11_PORT->PB_OUT &= ~BIT(i); //output 0 +} + + +/** + * @brief 用户小核发送数据到主核 + * + * @param [in] cmd 命令 + * @param [in] len 数据长度 + * * @param [in] data 数据地址 + * @param [in] wait 是否等待传输结束 + */ +void user_p11_post_to_main_system(u8 cmd, u16 len, u8 *data, u8 wait) +{ + u8 *pend = (u8 *) & (p2m_message[USER_P2M_BASE_ADDR + USER_MSG_PEND_BASE]); + int timer_out = 100000; + ENTER_CRITICAL(); + //do { + // asm("csync"); + // timer_out--; + //} while (timer_out && *pend); + + if (!timer_out || *pend) { + //*pend = 0; + EXIT_CRITICAL(); + printf("timer_out %d\n", __LINE__); + + /* while (1); */ + return; + } + + p2m_message[USER_P2M_BASE_ADDR + USER_MSG_PEND_BASE] = 1; + EXIT_CRITICAL(); + p2m_message[USER_P2M_BASE_ADDR + USER_MSG_TYPE_BASE] = cmd; + memcpy((u8 *)&p2m_message[USER_P2M_BASE_ADDR + USER_MSG_LEN_BASE], &len, sizeof(u16)); + memcpy((u8 *)&p2m_message[USER_P2M_BASE_ADDR + USER_MSG_ADDR_BASE], &data, sizeof(u8 *)); + /* printf("addr %x %x data%x pend %x len=%d\n",p2m_message,&p2m_message[USER_BASE_ADDR + USER_MSG_PEND_BASE],data,pend,len); */ + /* put_buf(data,len); */ + extern void __power_recover(void); + __power_recover(); + P11_USER_POST_TO_MSYS(P2M_USER_INDEX); + timer_out = 100000; + do { + asm("csync"); + timer_out --; + } while (wait && timer_out && *pend); + if (!timer_out) { + printf("timer_out %d\n", __LINE__); + while (1); + } + +} + +/** + * @brief 用户小核和主核数据交换区域初始化 + */ +void user_p11_p2m_post_init() +{ + p2m_message[USER_P2M_BASE_ADDR + USER_MSG_PEND_BASE] = 0; + m2p_message[USER_M2P_BASE_ADDR + USER_MSG_PEND_BASE] = 0; + P11_USER_P2M_ENABLE(P2M_USER_INDEX); + int msg[2]; + msg[0] = sizeof(send_ram); + msg[1] = send_ram; + user_p11_post_to_main_system(0, sizeof(msg), (u8 *)msg, 1); //配置主核共享空间 +} + +/** + * @brief 用户小核模拟主核数据,可以激活小核实现一个类似信号量的功能 + */ +int user_main_post_to_p11_system(u8 cmd, u8 wait) +{ + + return task_post_msg(NULL, 1, cmd); +#if 0 //很难这里保证不了和大核的绝对安全,使用其他办法同步 + u8 *pnd = (u8 *) & (m2p_message[USER_M2P_BASE_ADDR + USER_MSG_PEND_BASE]); + asm("csync"); + if (pnd[0]) { + printf("post to self fail \n"); + return -1; + } + + pnd[0] = 1; + pnd[1] = cmd; + pnd[2] = (u8)(0 & 0xff); + pnd[3] = (u8)(0 >> 8) & 0xff; + pnd[4] = (u8)(0) & 0xff; + pnd[5] = (u8)(0 >> 8) & 0xff; + pnd[6] = (u8)(0 >> 16) & 0xff; + pnd[7] = (u8)(0 >> 24) & 0xff; + MSYS_USER_POST_TO_P11(M2P_USER_INDEX); + int timer_out = 10000; + do { + asm("csync"); + timer_out --; + } while (wait && timer_out && pnd[0]); + if (!timer_out) { + printf("timer_out %d\n", __LINE__); + while (1); + } + return 0; +#endif +} + + + + + +void user_m2p11_irq() +{ + u8 cmd; + u8 type; + u16 len; + u8 *data; + u8 *pnd = (u8 *)(m2p_message + CONFIG_M2P_MESSAGE_SIZE - 8); + cmd = pnd[1]; + len = pnd[2] | (pnd[3] << 8); + data = (u8 *)((pnd[4] | (pnd[5] << 8) | (pnd[6] << 16) | (pnd[7] << 24))); + +#if CONFIG_SENSOR_ALG_ENABLE + switch (cmd) { + case P11_SYS_KICK: + pnd[0] = 0; + /* user_main_run(); */ + task_post_msg(NULL, 1, cmd); + break; + case P11_SYS_IIC_R_SYNC: + //让p11 备进入主线程状态 准备 + task_post_msg(NULL, 1, P11_SYS_IIC_R_SYNC); + break; + case P11_SYS_IIC_W_SYNC: + //让p11 备进入主线程状态 准备 + task_post_msg(NULL, 1, P11_SYS_IIC_W_SYNC); + break; + case P11_SYS_GSENSOR_START: + //printf("P11_SYS_GSENSOR_START\n"); + task_post_msg(NULL, 1, cmd); + /* sensor_hub_gsensor_enable(1); */ + break; + case P11_SYS_GSENSOR_STOP: + //printf("P11_SYS_GSENSOR_STOP\n"); + task_post_msg(NULL, 1, cmd); + /* sensor_hub_gsensor_enable(0); */ + break; + case P11_SYS_HRSENSOR_START: + //printf("P11_SYS_HRSENSOR_START\n"); + task_post_msg(NULL, 1, cmd); + /* sensor_hub_hrsensor_enable(1); */ + break; + case P11_SYS_HRSENSOR_STOP: + //printf("P11_SYS_HRSENSOR_STOP\n"); + task_post_msg(NULL, 1, cmd); + /* sensor_hub_hrsensor_enable(0); */ + break; + case P11_SYS_HRSENSOR_LP_DETECT: + case P11_SYS_HRSENSOR_FACTORY_TEST: + task_post_msg(NULL, 1, cmd); + break; + case P11_SYS_SPO2_START: + //printf("P11_SYS_SPO2SENSOR_START\n"); + task_post_msg(NULL, 1, cmd); + /* sensor_hub_spo2sensor_enable(1); */ + break; + case P11_SYS_SPO2_STOP: + //printf("P11_SYS_SPO2SENSOR_STOP\n"); + task_post_msg(NULL, 1, cmd); + /* sensor_hub_spo2sensor_enable(0); */ + break; + case P11_SYS_GSENSOR_SEARCH: + printf("P11_SYS_GSENSOR_SEARCH\n"); + task_post_msg(NULL, 1, cmd); + if (len) { //出于实时性考虑在此处理 + int valid = 0; + sensor_hub_gsensor_search(&valid); + printf("%s valid%d\n", __func__, valid); + memcpy(data, &valid, 4); + } + break; + case P11_SYS_HRSENSOR_SEARCH: + printf("P11_SYS_HRSENSOR_SEARCH\n"); + task_post_msg(NULL, 1, cmd); + if (len) { //出于实时性考虑在此处理 + int valid = 0; + sensor_hub_hrsensor_search(&valid); + printf("%s valid%d\n", __func__, valid); + memcpy(data, &valid, 4); + } + break; + } +#endif + //printf(">>>%s %d %x %x %x\n", __func__, __LINE__, cmd, len, data); + asm("csync"); + //if (len) { + //put_buf(data, len); + //} + pnd[0] = 0; +} + + + diff --git a/2.code/2.p11_code/apps/msg.h b/2.code/2.p11_code/apps/msg.h new file mode 100644 index 0000000..31f33ed --- /dev/null +++ b/2.code/2.p11_code/apps/msg.h @@ -0,0 +1,88 @@ +#ifndef __MSG_P11_H__ +#define __MSG_P11_H__ + + +extern void user_p11_p2m_post_init(); +extern void user_p11_post_to_main_system(u8 cmd, u16 len, u8 *data, u8 wait); +extern int user_main_post_to_p11_system(u8 cmd, u8 wait); + +enum P11_CMD_TABLE { + P11_SYS_RAM_INIT = 0, + P11_SYS_KICK = 1, + P11_SYS_TO_SELF = 2, + P11_SYS_GSENSOR_IRQ = 3, + P11_SYS_HR_SENSOR_IQR = 4, + P11_SYS_SPO2_SENSOR_IQR = 5, + P11_SYS_GSENSOR_START = 6, + P11_SYS_GSENSOR_STOP = 7, + P11_SYS_HRSENSOR_START = 8, + P11_SYS_HRSENSOR_STOP = 9, + P11_SYS_SPO2_START = 10, + P11_SYS_SPO2_STOP = 11, + P11_SYS_GSENSOR_SEARCH = 12, + P11_SYS_HRSENSOR_SEARCH = 13, + + + + + P11_SYS_IIC_INIT_SYNC = 14, + P11_SYS_IIC_R_SYNC = 15, + P11_SYS_IIC_W_SYNC = 16, + + P11_SYS_HRSENSOR_LP_DETECT = 30, + P11_SYS_HRSENSOR_FACTORY_TEST = 31, + + P11_SYS_ALGO_EVENT = 50, + + P11_SYS_WAKE = 0xff, +}; + + + +enum { + MSG_CLEAN_ALL_MSG = 0x0ffe, + NO_MSG = 0x0fff, +}; + +enum { + MSG_NO_ERROR = 0, + MSG_EVENT_EXIST = -1, + MSG_NOT_EVENT = -2, + MSG_EVENT_PARAM_ERROR = -3, + MSG_BUF_NOT_ENOUGH = -4, +}; + +//最大31 +enum P11_SENSOR_TABLE { + E_G_SENSOR_ONLINE = 0, + E_HR_SENSOR_ONLINE = 1, + E_SPO2_SENSOR_ONLINE = 2, + E_BAROMETER_SENSOR_ONLINE = 3, + E_SENSOR_WEAR_CHECK = 4, + + + + E_SENSOR_MAX = 32, +}; + +#define N_GSENSOR (0) +#define N_HR_SENSOR (1) +#define N_SPO2_SENSOR (2) + +#define N_SENSOR_NUM ((N_SPO2_SENSOR)+1) + +struct SENSOR_SHARE_PORT { + u32 event;//按bit为单位,支持32位的状态同步 + int sensor_hd[N_SENSOR_NUM][36 / 4]; //36是cbuf句柄的大小 +}; + + + +extern void task_clear_all_message(void); +extern void task_message_init(); +extern int task_post_msg(char *name, int argc, ...); +extern int task_get_msg(u16 timeout, int len, int *msg); + + + +#endif diff --git a/2.code/2.p11_code/apps/timer.c b/2.code/2.p11_code/apps/timer.c new file mode 100644 index 0000000..1e1e786 --- /dev/null +++ b/2.code/2.p11_code/apps/timer.c @@ -0,0 +1,278 @@ +#include "includes.h" +#include "timer.h" +#include "gp_timer_api.h" +#include "lp_timer_api.h" +#include "app_config.h" +#include "usr_timer.h" + +volatile u32 cur_time_tick = 0; +#if TCFG_VCHR02_DEV_ENABLE +volatile u32 vchr02_cur_time_tick = 0;//set 20k +#endif +/* */ +/* #pragma bss_seg(".timer_bss") */ +/* #pragma const_seg(".timer_const") */ +/* #pragma code_seg(".timer_code") */ +/* */ + +u32 get_cur_sys_tick(void) +{ + return cur_time_tick; +} + + +static void timer_isr_fun(void *priv) +{ + struct loop_detect_handler *detect; + list_for_each_loop_detect(detect) { + if ((cur_time_tick % detect->time) == 0) { + if (detect->fun) { + detect->fun(detect->priv); + } + } + } + cur_time_tick += 40; +#if TCFG_VCHR02_DEV_ENABLE + vchr02_cur_time_tick++; +#endif +} + +void timer_tick_init() +{ +#if 0 + lp_timer_init(P11_LPTMR3, 40 * 1000); + /* gp_timer_init(P11_GPTMR1, 10950 * 40); //10ms */ + /* gp_timer_register_irq(P11_GPTMR1, timer0_isr_fun); */ + lp_timer_register_irq(P11_LPTMR3, timer_isr_fun); +#else + + usr_timer_add(NULL, timer_isr_fun, 40, 0); + +#endif +} +//=========================== P11_LPTMRx->CON0 =============================// +#define USR_LP_TIMER_ENABLE(p, v) SFR(p->CON0, 0, 1, v) +#define USR_LP_TIMER_CONTINUE(p, v) SFR(p->CON0, 1, 1, v) +#define USR_LP_TIMER_P11_RESUME_WK_IE(p, v) SFR(p->CON0, 2, 1, v) +#define USR_LP_TIMER_P11_TIMEOUT_WK_IE(p, v) SFR(p->CON0, 3, 1, v) +#define USR_LP_TIMER_P11_RESUME_PENDING_CLR(p) (p->CON0 |= BIT(4)) +#define USR_LP_TIMER_P11_RESUME_PENDING_IS(p) (p->CON0 & BIT(5)) +#define USR_LP_TIMER_P11_TIMEOUT_PENDING_CLR(p) (p->CON0 |= BIT(6)) +#define USR_LP_TIMER_P11_TIMEOUT_PENDING_IS(p) (p->CON0 & BIT(7)) + +//======USR_===================== P11_LPTMRx->CON1 =============================// +#define USR_LP_TIMER_SOFT_KICK_START_ENABLE(p, v) SFR(p->CON1, 0, 1, v) +#define USR_LP_TIMER_HW_KICK_START_ENABLE(p, v) SFR(p->CON1, 1, 1, v) +#define USR_LP_TIMER_MSYS_RESUME_WK_IE(p, v) SFR(p->CON1, 2, 1, v) +#define USR_LP_TIMER_MSYS_TIMEOUT_WK_IE(p, v) SFR(p->CON1, 3, 1, v) +#define USR_LP_TIMER_MSYS_RESUME_PENDING_CLR(p) (p->CON1 |= BIT(4)) +#define USR_LP_TIMER_MSYS_RESUME_PENDING_IS(p) (p->CON1 & BIT(5)) +#define USR_LP_TIMER_MSYS_TIMEOUT_PENDING_CLR(p) (p->CON1 |= BIT(6)) +#define USR_LP_TIMER_MSYS_TIMEOUT_PENDING_IS(p) (p->CON1 & BIT(7)) + +//=========================== P11_LPTMRx->CON2 =============================// +enum USR_LP_TIMER_CLK_TABLE { + USR_LP_TIMER_CLK_RC250K, + USR_LP_TIMER_CLK_RC16M, + USR_LP_TIMER_CLK_BT_OSC, + USR_LP_TIMER_CLK_LRC_OSC, + USR_LP_TIMER_CLK_RTC_OSC, + USR_LP_TIMER_CLK_PAT_CLK, +}; +#define USR_LP_TIMER_CLOCK_SEL(p, v) SFR(p->CON2, 0, 4, v) + +enum USR_LP_TIMER_DIV_TABLE { + USR_LP_TIMER_DIV_1, + USR_LP_TIMER_DIV_4, + USR_LP_TIMER_DIV_16, + USR_LP_TIMER_DIV_64, +}; +#define USR_LP_TIMER_CLOCK_DIV_SEL(p, v) SFR(p->CON2, 4, 4, v) +#define USR_LP_TIMER_KICK_START_RUN(p) (p->CON2 |= BIT(8)) +#define USR_LP_TIMER_RUNNING_IS(p) (p->CON2 & BIT(9)) + + +//=========================== P11_LPTMRx->PRD =============================// +#define USR_LP_TIMER_PRD_SET(p, v) (p->PRD = v) + +//=========================== P11_LPTMRx->CNT =============================// +#define USR_LP_TIMER_CNT_SET(p, v) //(p->CNT = v) + +//=========================== P11_LPTMRx->RSC =============================// +#define USR_LP_TIMER_PRD_RSC(p, v) + +___interrupt +static void usr_lp_timer0_int(void) +{ + printf("%s: CON0 = 0x%x\n", __func__, P11_LPTMR0->CON0); + + if (USR_LP_TIMER_P11_TIMEOUT_PENDING_IS(P11_LPTMR0)) { + USR_LP_TIMER_P11_TIMEOUT_PENDING_CLR(P11_LPTMR0); + printf("p11 timer0 timerout\n"); + } +} + +/*======================================================================== + * @brief: + * + * @param: + * @return: + ========================================================================*/ +static void (*lp_timer3_irq_handler_hook)(void) = NULL; +extern volatile u8 user_test_flag; +u32 get_lp_time_cnt; +___interrupt +static void usr_lp_timer1_int(void) +{ + get_lp_time_cnt += 90; + + if (USR_LP_TIMER_P11_TIMEOUT_PENDING_IS(P11_LPTMR1)) { + USR_LP_TIMER_P11_TIMEOUT_PENDING_CLR(P11_LPTMR1); + } +} + +/*======================================================================== + * @brief: + * + * @param: + * @return: + ========================================================================*/ + +___interrupt +static void usr_lp_timer2_int(void) +{ + if (USR_LP_TIMER_P11_TIMEOUT_PENDING_IS(P11_LPTMR2)) { + USR_LP_TIMER_P11_TIMEOUT_PENDING_CLR(P11_LPTMR2); + } +} + +/*======================================================================== + * @brief: + * + * @param: + * @return: + ========================================================================*/ + +___interrupt +static void usr_lp_timer3_int(void) +{ + if (USR_LP_TIMER_P11_TIMEOUT_PENDING_IS(P11_LPTMR3)) { + USR_LP_TIMER_P11_TIMEOUT_PENDING_CLR(P11_LPTMR3); + + if (lp_timer3_irq_handler_hook) { + lp_timer3_irq_handler_hook(); + } + } +} + + +static void usr_lp_timer_config_dump(P11_LPTMR_TypeDef *lp_timer) +{ + printf("lp_timer->CON0 = 0x%x\n", lp_timer->CON0); + printf("lp_timer->CON1 = 0x%x\n", lp_timer->CON1); + printf("lp_timer->CON2 = 0x%x\n", lp_timer->CON2); + printf("lp_timer->PRD = 0x%x\n", lp_timer->PRD); + printf("lp_timer->RSC = 0x%x\n", lp_timer->RSC); + printf("lp_timer->CNT = 0x%x\n", lp_timer->CNT); +} + +const void *usr_usr_lp_timer_int_table[] = { + usr_lp_timer0_int, + usr_lp_timer1_int, + usr_lp_timer2_int, + usr_lp_timer3_int, +}; + +const void *usr_lp_timer_sfr_table[] = { + P11_LPTMR0, + P11_LPTMR1, + P11_LPTMR2, + P11_LPTMR3 +}; + +#define USR_LP_TIMER_CLK_FREQ (200000UL) + + +static const u32 timer_div[] = { + /*0000*/ 1, + /*0001*/ 4, + /*0010*/ 16, + /*0011*/ 64, +}; + + +void usr_lp_timer_init(P11_LPTMR_TypeDef *lp_timer, u32 us) +{ + u8 offset = 0; + + if (lp_timer == NULL) { + return; + } + for (offset = 0; offset < ARRAY_SIZE(usr_lp_timer_sfr_table); offset++) { + if (usr_lp_timer_sfr_table[offset] == lp_timer) { + break; + } + } + + if (offset >= ARRAY_SIZE(usr_lp_timer_sfr_table)) { + return; + } + + u8 offset1 = (u32)((u32)lp_timer - (u32)P11_LPTMR0) / ((u32)P11_LPTMR1_BASE - (u32)P11_LPTMR0_BASE); + + printf("offset = 0x%x\n", offset); + P11_CLOCK->WKUP_EN |= (1 << (offset + 9)); + INTALL_HWI(IRQ_LP_TMR0_IDX + offset, usr_usr_lp_timer_int_table[offset], 0); + + USR_LP_TIMER_CLOCK_SEL(lp_timer, USR_LP_TIMER_CLK_LRC_OSC); //200K + +// u32 MIN_TIME_CNT = 0x100; +// +// u32 MAX_TIME_CNT = 0xffff / 4 * 3;//49,151.25 +// u32 prd_cnt = 0xffff;//(us * (USR_LP_TIMER_CLK_FREQ / 1000)) / (1000000UL / 100);/// = + u32 prd_cnt = 600;//ÖжÏÖØ×°ÔØÖµ(us * (USR_LP_TIMER_CLK_FREQ / 1000)) / (1000000UL / 100);/// = + + USR_LP_TIMER_CLOCK_DIV_SEL(lp_timer, 0);///CON2 |????24BIT + + /* u32 prd = (us * (LP_TIMER_CLK_FREQ / 1000)) / (1000000UL / 100); */ + + USR_LP_TIMER_PRD_SET(lp_timer, prd_cnt);///PRD + USR_LP_TIMER_CNT_SET(lp_timer, 0);///PRD + + USR_LP_TIMER_P11_TIMEOUT_WK_IE(lp_timer, 1);///CON0 |????23BIT +//USR_LP_TIMER_P11_TIMEOUT_PENDING_CLR(lp_timer); + USR_LP_TIMER_SOFT_KICK_START_ENABLE(lp_timer, 1);///CON1 |????20bit + USR_LP_TIMER_HW_KICK_START_ENABLE(lp_timer, 0);///CON1|????21bit + + USR_LP_TIMER_CONTINUE(lp_timer, 1);///CON0 |????21bit + + USR_LP_TIMER_ENABLE(lp_timer, 1);///CON0|????20bit + + usr_lp_timer_config_dump(lp_timer); + + USR_LP_TIMER_KICK_START_RUN(lp_timer);///CON2 |????28 + return; +} + +static void timer3_isr_fun(void) +{ +// struct loop_detect_handler *detect; +// +// list_for_each_loop_detect(detect) { +// if ((cur_time_tick % detect->time) == 0) { +// if (detect->fun) { +// detect->fun(detect->priv); +// } +// } +// } +// printf("%d",P11_LPTMR3->CNT); + putchar('2'); +// p2m_message[39] += (32*1000); +} + + + +void user_lptime_init(void) +{ + usr_lp_timer_init(P11_LPTMR1, 40 * 1000); +} diff --git a/2.code/2.p11_code/apps/timer.h b/2.code/2.p11_code/apps/timer.h new file mode 100644 index 0000000..511dfcf --- /dev/null +++ b/2.code/2.p11_code/apps/timer.h @@ -0,0 +1,28 @@ +#ifndef __TIMER_TICK_H__ +#define __TIMER_TICK_H__ + +/*不同功能的循环检测功能统一用LOOP_DETECT_REGISTER注册,可搜索关键字看例子*/ +struct loop_detect_handler { + int time;/*TIMER周期的倍数。timer周期默认一般是2ms */ + int *priv; + void (*fun)(int *); +}; + +extern struct loop_detect_handler loop_detect_handler_begin[]; +extern struct loop_detect_handler loop_detect_handler_end[]; + +#define LOOP_DETECT_REGISTER( p, t, fn) \ + static const struct loop_detect_handler __event_handler_##fn SEC_USED(.loop_detect_region) = { \ + .time = (t), \ + .priv = (p), \ + .fun = (fn), \ + }\ + + +#define list_for_each_loop_detect(h) \ + for (h=loop_detect_handler_begin; hPB_OUT ^= BIT(1); + } +} + +#define P11_DEBUG_IO_INDEX 5 + +__INLINE__ +void debug_io_1(void) +{ + P11_PORT->PB_SEL |= BIT(P11_DEBUG_IO_INDEX); //P11 Control + P11_PORT->PB_DIR &= ~BIT(P11_DEBUG_IO_INDEX); //dir output + P11_PORT->PB_OUT |= BIT(P11_DEBUG_IO_INDEX); //output 1 +} + + +__INLINE__ +void debug_io_0(void) +{ + P11_PORT->PB_SEL |= BIT(P11_DEBUG_IO_INDEX); //P11 Control + P11_PORT->PB_DIR &= ~BIT(P11_DEBUG_IO_INDEX); //dir output + P11_PORT->PB_OUT &= ~BIT(P11_DEBUG_IO_INDEX); //output 0 +} + +void debug_io(void) +{ + while (1) { + debug_io_1(); + debug_io_0(); + } +} + diff --git a/2.code/2.p11_code/cpu/br28/iic.c b/2.code/2.p11_code/cpu/br28/iic.c new file mode 100644 index 0000000..2c6ba1e --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/iic.c @@ -0,0 +1,434 @@ +#ifdef SUPPORT_MS_EXTENSIONS +#pragma bss_seg(".iic.bss") +#pragma data_seg(".iic.data") +#pragma const_seg(".iic.const") +#pragma code_seg(".iic.text") +#pragma str_literal_override(".iic.text") +#endif /* #ifdef SUPPORT_MS_EXTENSIONS */ + +#include "includes.h" +#include "gpio.h" +#include "iic_hw.h" + +/* #pragma bss_seg(".iic") */ +/* #pragma const_seg(".iic") */ +/* #pragma code_seg(".iic") */ +/* */ + + +/**********************iic io config************************/ +#define IIC_SCL_IO IO_PORTB_04//PB组 +#define IIC_SDA_IO IO_PORTB_05//PB组 +/* #define iic_io_hdrive 0//p11 have no hd */ +#define iic_io_filt 1 +#define iic_io_pu 1//1:内部上拉 + +/**********************iic master config************************/ +#define iic_master_baud 200000//波特率, 单位:HZ +#define iic_role_slave_en 0//1:slave, 0:master + +/**********************iic slave config************************/ +#define IIC_SLAVE_ADDR 0b1010110 + +static u32 iic_get_clk_freq(void) +{ + return 10000000; +} + +//=========================================================================// +// IIC MASTER // +//=========================================================================// + +static void iic_slave_isr(void); +int hw_iic_init(void) +{ + u32 baud = 0; + IIC_CON0_CLEAR(); + IIC_CON1_CLEAR(); + if (iic_io_filt) { // + IIC_IO_FILTER_INPUT_ENABLE(1); + } else { + IIC_IO_FILTER_INPUT_ENABLE(0); + } + + //SCL: + gpio_set_die(IIC_SCL_IO, 1); + gpio_set_output_value(IIC_SCL_IO, 1); + gpio_set_fun_input_port(IIC_SCL_IO, PFI_IIC_SCL); + gpio_set_fun_output_port(IIC_SCL_IO, P11_FO_IIC_SCL, 1, 1); + //SDA: + gpio_set_die(IIC_SDA_IO, 1); + gpio_set_fun_output_port(IIC_SDA_IO, P11_FO_IIC_SDA, 1, 1); + gpio_set_fun_input_port(IIC_SDA_IO, PFI_IIC_SDA); + if (iic_io_pu) { + gpio_set_pull_up(IIC_SDA_IO, 1); + gpio_set_pull_down(IIC_SDA_IO, 0); + gpio_set_pull_up(IIC_SCL_IO, 1); + gpio_set_pull_down(IIC_SCL_IO, 0); + } else { + gpio_set_pull_up(IIC_SDA_IO, 0); + gpio_set_pull_down(IIC_SDA_IO, 0); + gpio_set_pull_up(IIC_SCL_IO, 0); + gpio_set_pull_down(IIC_SCL_IO, 0); + } + + if (iic_role_slave_en) { //slave + IIC_SLAVE_MODE(); + IIC_SLAVE_IGNORE_BUS_MODE(1); + IIC_SLAVE_ADDR_CONFIG(IIC_SLAVE_ADDR); + IIC_END_PENDING_INT_ENABLE(1); + //无byte & start pending int enable? + INTALL_HWI(IRQ_IIC_IDX, iic_slave_isr, IRQ_IIC_IP); + IIC_INT_ENABLE(1); + } else { + IIC_MASTER_MODE(); + baud = iic_get_clk_freq() / (iic_master_baud - 1) / 2 - 1; + IIC_MASTER_BAUD_CONFIG(baud); + } + + IIC_BYTE_PENDING_CLEAR(); + IIC_END_PENDING_CLEAR(); + IIC_START_PENDING_CLEAR(); + IIC_MODULE_ENABLE(1); + + if (iic_role_slave_en) { //slave + IIC_RECEIVE_ACK_SET(0); + IIC_DIR_RECEIVE(); + IIC_WRITE_BUF(0xFF); + delay(10); + IIC_CONFIG_DONE(); + } +#if 0 + printf("\nP11_IIC->CON0 = 0x%x\n", P11_IIC->CON0); + printf("P11_IIC->CON1 = 0x%x\n", P11_IIC->CON1); + printf("baud = 0x%x\n", baud); + printf("P11_IIC->BAUD = 0x%x\n", P11_IIC->BAUD); +#endif + return 0; +} + +void hw_iic_close(void) +{ + gpio_set_die(IIC_SCL_IO, 0); + gpio_set_pull_up(IIC_SCL_IO, 0); + gpio_set_die(IIC_SDA_IO, 0); + gpio_set_pull_up(IIC_SDA_IO, 0); + IIC_MODULE_ENABLE(0); +} + +void hw_iic_start(void) +{ + /* printf("%s\n", __func__); */ + IIC_MASTER_RESTART_SET(1); +} + +void hw_iic_stop(void) +{ + /* printf("%s\n", __func__); */ + IIC_MASTER_END_SET(1); + IIC_CONFIG_DONE(); + while (!(IIC_END_PENDING_IS())); + IIC_END_PENDING_CLEAR(); +} + + +u8 hw_iic_master_tx_byte(u8 data) +{ + int timeout = 10000; + local_irq_disable(); + + IIC_END_PENDING_CLEAR(); + IIC_BYTE_PENDING_CLEAR(); + + IIC_DIR_TRANSMIT(); + IIC_WRITE_BUF(data); + delay(1); + IIC_CONFIG_DONE(); + + do { + asm("csync"); + } while (--timeout && !(IIC_BYTE_PENDING_IS())); + + IIC_BYTE_PENDING_CLEAR(); + + IIC_MASTER_RESTART_SET(0); + IIC_MASTER_END_SET(0); + local_irq_enable(); + + if (!timeout) { + return 0; + } + return !(IIC_TRANSMIT_ACK_IS()); +} + +u8 hw_iic_master_rx_byte(u8 ack) +{ + int timeout = 10000; + local_irq_disable(); + IIC_END_PENDING_CLEAR(); + IIC_BYTE_PENDING_CLEAR(); + + if (ack) { + IIC_RECEIVE_ACK_SET(0); + } else { + IIC_RECEIVE_ACK_SET(1); + } + IIC_DIR_RECEIVE(); + IIC_WRITE_BUF(0xFF); + delay(1); + IIC_CONFIG_DONE(); + + while (--timeout && !(IIC_BYTE_PENDING_IS())); + IIC_BYTE_PENDING_CLEAR(); + local_irq_enable(); + if (!timeout) { + /* while(1); */ + putchar('N'); + return 0; + } + return IIC_READ_BUF(); +} +int hw_iic_master_read_buf(void *buf, int len) +{ + int i; + + if (!buf || !len) { + return -1; + } + IIC_DIR_RECEIVE(); + IIC_RECEIVE_ACK_SET(0); + for (i = 0; i < len; i++) { + if (i == len - 1) { + IIC_RECEIVE_ACK_SET(1); + } + IIC_WRITE_BUF(0xFF); + delay(1); + IIC_CONFIG_DONE(); + while (!(IIC_BYTE_PENDING_IS())); + IIC_BYTE_PENDING_CLEAR(); + + ((u8 *)buf)[i] = IIC_READ_BUF(); + } + return len; +} + +int hw_iic_master_write_buf(const void *buf, int len) +{ + int i = 0; + if (!buf || !len) { + return -1; + } + IIC_DIR_TRANSMIT(); + for (i = 0; i < len; i++) { + IIC_WRITE_BUF(((u8 *)buf)[i]); + delay(1); + IIC_CONFIG_DONE(); + + while (!(IIC_BYTE_PENDING_IS())); + IIC_BYTE_PENDING_CLEAR(); + if (IIC_TRANSMIT_ACK_IS()) { + break; + } + } + return i; +} + +//=========================================================================// +// IIC SLAVE // +//=========================================================================// +enum SLAVE_STATUS_TABLE { + SLAVE_STATUS_STOP = 0, + SLAVE_STATUS_START, + SLAVE_STATUS_READ, + SLAVE_STATUS_WRITE, +}; + +___interrupt +static void iic_slave_isr(void) +{ + static enum SLAVE_STATUS_TABLE slave_status = SLAVE_STATUS_STOP; + u8 data = 0; + u8 ack = 0; + static u8 read_cnt = 0; + static u8 write_cnt = 0; + + printf("\n%s\n", __func__); + if (IIC_START_PENDING_IS()) { + printf("\nstart pending\n"); + IIC_START_PENDING_CLEAR(); + slave_status = SLAVE_STATUS_START; + read_cnt = 0; + write_cnt = 0; + } + if (IIC_END_PENDING_IS()) { + printf("end pending\n"); + read_cnt = 0; + write_cnt = 0; + IIC_END_PENDING_CLEAR(); + slave_status = SLAVE_STATUS_STOP; + IIC_RECEIVE_ACK_SET(0); //ack + IIC_DIR_RECEIVE(); + IIC_CONFIG_DONE(); + } + + if (IIC_BYTE_PENDING_IS()) { + IIC_BYTE_PENDING_CLEAR(); + printf("byte pending\n"); + //拉住总线处理数据 + if (slave_status == SLAVE_STATUS_START) { + data = IIC_READ_BUF(); + printf("Slave Rx addr: 0x%x\n", data >> 1); + if (data & BIT(0)) { + slave_status = SLAVE_STATUS_READ; + printf("cmd: Master read\n"); + IIC_DIR_TRANSMIT(); + IIC_WRITE_BUF(0xAB); //准备数据, 等待下一包发送 + read_cnt = 1; + printf("Slave Tx: 0x%x\n", 0xAB); + IIC_CONFIG_DONE(); + } else { + slave_status = SLAVE_STATUS_WRITE; + printf("cmd: Master write\n"); + IIC_RECEIVE_ACK_SET(0); //ack + IIC_DIR_RECEIVE(); + IIC_WRITE_BUF(0xFF); + IIC_CONFIG_DONE(); //释放总线, 等待下一包接收 + } + } else if (slave_status == SLAVE_STATUS_STOP) { + printf("cmd: err status\n"); + } else if (slave_status == SLAVE_STATUS_READ) { + if (!(IIC_TRANSMIT_ACK_IS())) { + printf("Master Rx ack\n"); + } else { + printf("Master Rx nack\n"); + } + IIC_DIR_TRANSMIT(); + IIC_WRITE_BUF(0xAB); //准备数据, 等待下一包发送 + IIC_CONFIG_DONE(); + printf("Slave Tx: 0x%x\n", 0xAB); + + } else if (slave_status == SLAVE_STATUS_WRITE) { + write_cnt++; + data = IIC_READ_BUF(); + printf("Slave Rx: 0x%x\n", data); + if (write_cnt > 10) { + printf("noack set\n"); + IIC_RECEIVE_ACK_SET(1); //nack + } else { + printf("ack set\n"); + IIC_RECEIVE_ACK_SET(0); //ack + } + IIC_DIR_RECEIVE(); + IIC_WRITE_BUF(0xFF); + IIC_CONFIG_DONE(); + } + } +} + + + +//=========================================// +// IIC test code // +//=========================================// +#define P24C02A_EEPROM_DEVICE_ADDR 0b10100000 +#define DIR_WRITE 0 +#define DIR_READ BIT(0) +#define DATA_PAGE_SIZE 8 +#define DATA_PAGE_NUM 32 +void iic_master_eeprom_test(void) +{ + u8 ack = 0; + u8 cnt = 0; + u8 data = 0; + u8 page_num = 0; + u32 addr_base = 0; + hw_iic_init(); + //===========================// + // EEPROM WRITE // + //===========================// +__page_write: + addr_base = page_num * DATA_PAGE_SIZE; + printf("eeprom read write page: %d\n", page_num); + hw_iic_start(); + ack = hw_iic_master_tx_byte(P24C02A_EEPROM_DEVICE_ADDR | DIR_WRITE); + if (ack) { + printf("device id ack\n"); + //word addr: + ack = hw_iic_master_tx_byte(addr_base); + if (ack) { + printf("addr ack\n"); + } else { + printf("addr nack\n"); + goto __test_end; + } + //data: + for (cnt = 0; cnt < DATA_PAGE_SIZE; cnt++) { + ack = hw_iic_master_tx_byte(cnt); + if (ack) { + printf("addr: %d, data %d, ack\n", addr_base + cnt, cnt); + } else { + printf("data nack\n"); + goto __test_end; + } + + } + } else { + printf("device id nac\n"); + } + + hw_iic_stop(); + + delay(30000); //delay 10ms + //===========================// + // EEPROM READ // + //===========================// + printf("eeprom read start:\n"); + hw_iic_start(); + ack = hw_iic_master_tx_byte(P24C02A_EEPROM_DEVICE_ADDR | DIR_WRITE); + if (ack) { + printf("1.device id ack\n"); + } else { + printf("1.device id nack\n"); + goto __test_end; + } + //write addr + ack = hw_iic_master_tx_byte(addr_base); + if (ack) { + printf("addr ack\n"); + } else { + printf("addr nack\n"); + goto __test_end; + } + + hw_iic_start(); + ack = hw_iic_master_tx_byte(P24C02A_EEPROM_DEVICE_ADDR | DIR_READ); + if (ack) { + printf("2.device id ack\n"); + //data: + for (cnt = 0; cnt < DATA_PAGE_SIZE - 1; cnt++) { + data = hw_iic_master_rx_byte(1); + printf("addr: %d, Rx: %d\n", addr_base + cnt, data); + } + data = hw_iic_master_rx_byte(0); + printf("addr: %d, Rx: %d\n", addr_base + cnt, data); + } else { + printf("device id nac\n"); + } + if (++page_num < DATA_PAGE_NUM) { + hw_iic_stop(); + delay(30000); //delay 10ms + goto __page_write; + } + +__test_end: + hw_iic_stop(); + printf("test end\n"); + return; +} + + +void iic_slave_test(void) +{ + printf("%s\n", __func__); + hw_iic_init(); +} diff --git a/2.code/2.p11_code/cpu/br28/iic_soft.c b/2.code/2.p11_code/cpu/br28/iic_soft.c new file mode 100644 index 0000000..6dc81e0 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/iic_soft.c @@ -0,0 +1,366 @@ +#ifdef SUPPORT_MS_EXTENSIONS +#pragma bss_seg(".iic.bss") +#pragma data_seg(".iic.data") +#pragma const_seg(".iic.const") +#pragma code_seg(".iic.text") +#pragma str_literal_override(".iic.text") +#endif /* #ifdef SUPPORT_MS_EXTENSIONS */ + +#include "includes.h" +#include "gpio.h" +#include "iic_soft.h" +#include "app_config.h" + +#if 1 +const struct soft_iic_config soft_iic_cfg[] = { + //iic0 data + { + .scl = TCFG_SW_I2C0_CLK_PORT, //IIC CLK脚 + .sda = TCFG_SW_I2C0_DAT_PORT, //IIC DAT脚 + .delay = TCFG_SW_I2C0_DELAY_CNT, //软件IIC延时参数,影响通讯时钟频率 + .io_pu = 1, //是否打开上拉电阻,如果外部电路没有焊接上拉电阻需要置1 + }, +#if 0 + //iic1 data + { + .scl = IO_PORTA_14, + .sda = IO_PORTA_15, + .delay = 50, + .io_pu = 1, + }, +#endif +}; +#endif +#define IIC_SCL_DIR(scl, val) \ + gpio_set_direction(scl, val) + +#define IIC_SCL_SET_PU(scl, on) \ + gpio_set_pull_up(scl, on) + +#define IIC_SCL_SET_PD(scl, on) \ + gpio_set_pull_down(scl, on) + +#define IIC_SCL_SET_DIE(scl, on) \ + gpio_set_die(scl, on) + +#define IIC_SCL_H(scl) \ + gpio_set_output_value(scl, 1) + +#define IIC_SCL_L(scl) \ + gpio_set_output_value(scl, 0) + +#define IIC_SDA_DIR(sda, val) \ + gpio_set_direction(sda, val) + +#define IIC_SDA_SET_PU(sda, on) \ + gpio_set_pull_up(sda, on) + +#define IIC_SDA_SET_PD(sda, on) \ + gpio_set_pull_down(sda, on) + +#define IIC_SDA_SET_DIE(sda, on) \ + gpio_set_die(sda, on) + +#define IIC_SDA_H(sda) \ + gpio_set_output_value(sda, 1) + +#define IIC_SDA_L(sda) \ + gpio_set_output_value(sda, 0) + +#define IIC_SDA_READ(sda) \ + gpio_read(sda) + +#define iic_get_id(iic) (iic) + +static inline u32 iic_get_scl(soft_iic_dev iic) +{ + u8 id = iic_get_id(iic); + return soft_iic_cfg[id].scl; +} + +static inline u32 iic_get_sda(soft_iic_dev iic) +{ + u8 id = iic_get_id(iic); + return soft_iic_cfg[id].sda; +} + +static inline u32 iic_get_delay(soft_iic_dev iic) +{ + u8 id = iic_get_id(iic); + return soft_iic_cfg[id].delay; +} + +static inline u32 iic_get_io_pu(soft_iic_dev iic) +{ + u8 id = iic_get_id(iic); + return soft_iic_cfg[id].io_pu; +} + + +int soft_iic_init(soft_iic_dev iic) +{ + u32 scl, sda; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + + IIC_SCL_DIR(scl, 0); + IIC_SCL_SET_PD(scl, 0); + IIC_SCL_SET_DIE(scl, 1); + IIC_SCL_L(scl); + IIC_SDA_DIR(sda, 0); + IIC_SDA_SET_PD(sda, 0); + IIC_SDA_SET_DIE(sda, 1); + IIC_SDA_H(sda); + IIC_SCL_H(scl); + if (iic_get_io_pu(iic)) { + IIC_SCL_SET_PU(scl, 1); + IIC_SDA_SET_PU(sda, 1); + } else { + IIC_SCL_SET_PU(scl, 0); + IIC_SDA_SET_PU(sda, 0); + } + return 0; +} + +void soft_iic_uninit(soft_iic_dev iic) +{ + u32 scl, sda; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + + IIC_SCL_DIR(scl, 1); + IIC_SCL_SET_PU(scl, 0); + IIC_SCL_SET_PD(scl, 0); + IIC_SCL_SET_DIE(scl, 0); + IIC_SDA_DIR(sda, 1); + IIC_SDA_SET_PU(sda, 0); + IIC_SDA_SET_PD(sda, 0); + IIC_SDA_SET_DIE(sda, 0); +} + +void soft_iic_suspend(soft_iic_dev iic) +{ + u32 scl, sda; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + + IIC_SCL_SET_DIE(scl, 0); + IIC_SDA_SET_DIE(sda, 0); +} + +void soft_iic_resume(soft_iic_dev iic) +{ + u32 scl, sda; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + + IIC_SCL_SET_DIE(scl, 1); + IIC_SDA_SET_DIE(sda, 1); +} + +void soft_iic_start(soft_iic_dev iic) +{ + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SDA_H(sda); + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t * 2); + + IIC_SDA_L(sda); + delay(dly_t); + + IIC_SCL_L(scl); + delay(dly_t); +} + +void soft_iic_stop(soft_iic_dev iic) +{ + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SDA_L(sda); + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t * 2); + + IIC_SDA_H(sda); + delay(dly_t); +} + +static u8 soft_iic_check_ack(soft_iic_dev iic) +{ + u8 ack; + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SDA_DIR(sda, 1); + IIC_SCL_L(scl); + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t); + + if (IIC_SDA_READ(sda) == 0) { + ack = 1; + } else { + ack = 0; + } + delay(dly_t); + + IIC_SCL_L(scl); + delay(dly_t); + IIC_SDA_DIR(sda, 0); + IIC_SDA_L(sda); + + return ack; +} + +static void soft_iic_rx_ack(soft_iic_dev iic) +{ + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SDA_L(sda); + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t * 2); + + IIC_SCL_L(scl); + delay(dly_t); +} + +static void soft_iic_rx_nack(soft_iic_dev iic) +{ + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SDA_H(sda); + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t * 2); + + IIC_SCL_L(scl); + delay(dly_t); +} + +u8 soft_iic_tx_byte(soft_iic_dev iic, u8 byte) +{ + u8 i, ret; + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SCL_L(scl); + for (i = 0; i < 8; i++) { //MSB FIRST + if ((byte << i) & 0x80) { + IIC_SDA_H(sda); + } else { + IIC_SDA_L(sda); + } + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t * 2); + + IIC_SCL_L(scl); + delay(dly_t); + } + return soft_iic_check_ack(iic); +} + +u8 soft_iic_rx_byte(soft_iic_dev iic, u8 ack) +{ + u8 byte = 0, i; + u32 scl, sda, dly_t; + + scl = iic_get_scl(iic); + sda = iic_get_sda(iic); + dly_t = iic_get_delay(iic); + + IIC_SDA_DIR(sda, 1); + + for (i = 0; i < 8; i++) { + delay(dly_t); + + IIC_SCL_H(scl); + delay(dly_t); + + byte = byte << 1; + if (IIC_SDA_READ(sda)) { + byte |= 1; + } + delay(dly_t); + + IIC_SCL_L(scl); + delay(dly_t); + } + + IIC_SDA_DIR(sda, 0); + if (ack) { + soft_iic_rx_ack(iic); + } else { + soft_iic_rx_nack(iic); + } + + return byte; +} + + +int soft_iic_read_buf(soft_iic_dev iic, void *buf, int len) +{ + int i = 0; + + if (!buf || !len) { + return -1; + } + for (i = 0; i < len - 1; i++) { + ((u8 *)buf)[i] = soft_iic_rx_byte(iic, 1); + } + ((u8 *)buf)[len - 1] = soft_iic_rx_byte(iic, 0); + return len; +} + +int soft_iic_write_buf(soft_iic_dev iic, const void *buf, int len) +{ + int i; + u8 ack; + + if (!buf || !len) { + return -1; + } + for (i = 0; i < len; i++) { + ack = soft_iic_tx_byte(iic, ((u8 *)buf)[i]); + if (ack == 0) { + break; + } + } + return i; +} + diff --git a/2.code/2.p11_code/cpu/br28/liba/algo_gsensor.a b/2.code/2.p11_code/cpu/br28/liba/algo_gsensor.a new file mode 100644 index 0000000..42f1e8a Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/algo_gsensor.a differ diff --git a/2.code/2.p11_code/cpu/br28/liba/bank_switch.a b/2.code/2.p11_code/cpu/br28/liba/bank_switch.a new file mode 100644 index 0000000..cfaf7e1 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/bank_switch.a differ diff --git a/2.code/2.p11_code/cpu/br28/liba/cbuf.a b/2.code/2.p11_code/cpu/br28/liba/cbuf.a new file mode 100644 index 0000000..70f432b Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/cbuf.a differ diff --git a/2.code/2.p11_code/cpu/br28/liba/cpu.a b/2.code/2.p11_code/cpu/br28/liba/cpu.a new file mode 100644 index 0000000..c3b54a6 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/cpu.a differ diff --git a/2.code/2.p11_code/cpu/br28/liba/lbuf.a b/2.code/2.p11_code/cpu/br28/liba/lbuf.a new file mode 100644 index 0000000..6890ae3 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/lbuf.a differ diff --git a/2.code/2.p11_code/cpu/br28/liba/printf.a b/2.code/2.p11_code/cpu/br28/liba/printf.a new file mode 100644 index 0000000..53aca8a Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/printf.a differ diff --git a/2.code/2.p11_code/cpu/br28/liba/vad_algo.a b/2.code/2.p11_code/cpu/br28/liba/vad_algo.a new file mode 100644 index 0000000..afcba24 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/liba/vad_algo.a differ diff --git a/2.code/2.p11_code/cpu/br28/p11.ld b/2.code/2.p11_code/cpu/br28/p11.ld new file mode 100644 index 0000000..e4e0609 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/p11.ld @@ -0,0 +1,223 @@ + + +idle = ABSOLUTE(0x8000); +standby = ABSOLUTE(0x800a); +sleep = ABSOLUTE(0x801a); +deep_sleep = ABSOLUTE(0x802a); +ISR_BASE = 0x0; + +P11_CODE_BEGIN = 0x80; + +P11_RAM_LIMIT_H = 0x8000; +P11_RAM_LIMIT_L = 0x80; +P11_RAM_SIZE = P11_RAM_LIMIT_H - P11_RAM_LIMIT_L; +P11_RAM_END = P11_RAM_LIMIT_H; + +P11_POWEROFF_RAM_SIZE = 0x14 + 0xc; +P11_POWEROFF_RAM_BEGIN = P11_RAM_END - P11_POWEROFF_RAM_SIZE; + +P2M_MESSAGE_SIZE = 0x40; +M2P_MESSAGE_SIZE = 0x60; +P11_MESSAGE_SIZE = M2P_MESSAGE_SIZE + P2M_MESSAGE_SIZE; +P11_MESSAGE_BEGIN = P11_POWEROFF_RAM_BEGIN - P11_MESSAGE_SIZE; + + + + +P11_VAD_RAM_SIZE = 0; + +P11_VAD_RAM_BEGIN = P11_MESSAGE_BEGIN - P11_VAD_RAM_SIZE - 0x20; + +P11_RAM_CODE_BEGIN = P11_CODE_BEGIN; +P11_RAM_CODE_END = P11_VAD_RAM_BEGIN; +P11_RAM_CODE_SIZE = P11_RAM_CODE_END - P11_RAM_CODE_BEGIN; + +MEMORY +{ + p11_ram(rwx) : ORIGIN = P11_RAM_CODE_BEGIN, LENGTH = P11_RAM_CODE_SIZE + p11_poweroff_ram(rw) : ORIGIN = P11_POWEROFF_RAM_BEGIN, LENGTH = P11_POWEROFF_RAM_SIZE + p11_message_ram(rw) : ORIGIN = P11_MESSAGE_BEGIN, LENGTH = P11_MESSAGE_SIZE + p11_vad_ram(rw) : ORIGIN = P11_VAD_RAM_BEGIN, LENGTH = P11_VAD_RAM_SIZE +} + +ENTRY(_start) + +SECTIONS +{ + . = ORIGIN(p11_ram); + .text ALIGN(32): + { + *startup.o(.text) + + *(.ram0.data.bss) + *(.ram0.data) + *(.ram0.text.const) + *(.ram0.text) + + *(.*.text) + *(.*.const) + + + . = ALIGN(4); + gsensor_dev_begin = .; + KEEP(*(.gsensor_dev)) + gsensor_dev_end = .; + + . = ALIGN(4); + hrsensor_dev_begin = .; + KEEP(*(.hrsensor_dev)) + hrsensor_dev_end = .; + + *(.rodata*) + . = ALIGN(4); + PROVIDE(low_power_target_begin = .); + *(.lp_target.2.ops) + *(.lp_target.1.ops) + *(.lp_target.0.ops) + PROVIDE(low_power_target_end = .); + + + . = ALIGN(4); + loop_detect_handler_begin = .; + KEEP(*(.loop_detect_region)) + loop_detect_handler_end = .; + + . = ALIGN(4); + *(.*.data) + . = ALIGN(4); + *(.data*) + . = ALIGN(4); + } > p11_ram + + .data ALIGN(32): + { + + } > p11_ram + + .bss ALIGN(4): + { + *(.bss) + *(.*.bss) + *(COMMON) + } > p11_ram + + .stack_bss ALIGN(32): + { + *(.stack_magic0) + PROVIDE(_stack_begin = .); + PROVIDE(_sstack_begin = .); + *(.sstack) + PROVIDE(_sstack_end = .); + + PROVIDE(_ustack_begin = .); + *(.ustack) + PROVIDE(_ustack_end = .); + + PROVIDE(_stack_end = .); + *(.stack_magic1) + } > p11_ram + + PROVIDE(overlay_demo_begin = .); + OVERLAY : AT(0x200000) SUBALIGN(4) + { + .overlay_bank_demo_init + { + LONG(0xffffffff); + *(.demo.code.bank.0) + . = ALIGN(4); + } + .overlay_bank_demo_normal0 + { + LONG(0xffffffff); + *(.demo.code.bank.1) + } + + .overlay_bank_demo_normal1 + { + LONG(0xffffffff); + *(.demo.code.bank.2) + } + } > p11_ram + PROVIDE(overlay_demo_end = .); + + + PROVIDE(overlay_sensor_begin = .); + OVERLAY : AT(0x210000) SUBALIGN(4) + { + + .overlay_bank_sensor_init + { + LONG(0xffffffff); + *(.sensor.code.bank.0) + . = ALIGN(4); + } + .overlay_bank_sensor_normal0 + { + LONG(0xffffffff); + *(.sensor.code.bank.1) + } + .overlay_bank_sensor_normal1 + { + LONG(0xffffffff); + *(.sensor.code.bank.2) + } + + } > p11_ram + PROVIDE(overlay_sensor_end = .); + + PROVIDE(overlay_sys_begin = .); + OVERLAY : AT(0x220000) SUBALIGN(4) + { + + .overlay_bank_sys_init + { + LONG(0xffffffff); + *(.sys.code.bank.0) + . = ALIGN(4); + } + .overlay_bank_sys_normal0 + { + LONG(0xffffffff); + *(.sys.code.bank.1) + } + } > p11_ram + PROVIDE(overlay_sys_end = .); + + PROVIDE(p11_heap_begin = .); + p11_heap_end = P11_RAM_CODE_END; + + + . = ORIGIN(p11_message_ram); + .p11_message ALIGN(32): + { + *(.p2m_data) + *(.m2p_data) + } > p11_message_ram + + . = ORIGIN(p11_vad_ram); + .p11_vad ALIGN(4): + { + *(.m2p_dvad_config) + . = ALIGN(4); + *(.m2p_avad_config) + . = ALIGN(4); + *(.p2m_cbuf_data) + } > p11_vad_ram +} + +text_begin = ADDR(.text); +text_size = SIZEOF(.text); +text_end = text_begin + text_size; + +bss_begin = ADDR(.bss); +bss_size = SIZEOF(.bss); + +data_addr = ADDR(.data); +data_begin = text_begin + text_size; +data_size = SIZEOF(.data); + +p11_message_data_addr = ADDR(.p11_message); +p11_message_data_size = SIZEOF(.p11_message); + +p11_heap_size = p11_heap_end - p11_heap_begin; +ASSERT(p11_heap_size >= 200, "p11 heap space too small !") diff --git a/2.code/2.p11_code/cpu/br28/p11_ld.c b/2.code/2.p11_code/cpu/br28/p11_ld.c new file mode 100644 index 0000000..bedabaa --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/p11_ld.c @@ -0,0 +1,260 @@ +// *INDENT-OFF* +#include "app_config.h" + +#include "p11_rom_stubs.ld" + +/* ================= BR28 P11 Memory ======================== + + _______________ ____0x80FF +| | +| ROM0 | +|_______________|__ 0x8000(32K) +| | +| p2m_message | +|_______________| +| | +| m2p_message | +|_______________| +| | +| vad_cbuf_ram | +| m2p_avad_cfg |---> share with MSYS for VAD +| m2p_dvad_cfg | +|_______________| +| | +| p11_heap_ram |---> share with MSYS for User +|_______________| +| | +| stack | +|_______________| +| | +| bss | +|_______________| +| | +| data | +|_______________| +| | +| code | +|_______________|_0x80 CODE +| | +| isr vector | +|_______________|_ 0 RAM_LIMIT_L + + =========================================================== */ + +ISR_BASE = 0x0; + +P11_CODE_BEGIN = 0x80; + +P11_RAM_LIMIT_H = 0x8000; +P11_RAM_LIMIT_L = 0x80; +P11_RAM_SIZE = P11_RAM_LIMIT_H - P11_RAM_LIMIT_L; +P11_RAM_END = P11_RAM_LIMIT_H; + +P11_POWEROFF_RAM_SIZE = 0x14 + 0xc; +P11_POWEROFF_RAM_BEGIN = P11_RAM_END - P11_POWEROFF_RAM_SIZE; + +P2M_MESSAGE_SIZE = CONFIG_P2M_MESSAGE_SIZE; +M2P_MESSAGE_SIZE = CONFIG_M2P_MESSAGE_SIZE; +P11_MESSAGE_SIZE = M2P_MESSAGE_SIZE + P2M_MESSAGE_SIZE; +P11_MESSAGE_BEGIN = P11_POWEROFF_RAM_BEGIN - P11_MESSAGE_SIZE; + +#if CONFIG_VAD_ENABLE +P11_VAD_RAM_SIZE = CONFIG_P11_CBUF_SIZE + CONFIG_VAD_CONFIG_SIZE; +#else /* #if CONFIG_VAD_ENABLE */ +P11_VAD_RAM_SIZE = 0; +#endif /* #if CONFIG_VAD_ENABLE */ +P11_VAD_RAM_BEGIN = P11_MESSAGE_BEGIN - P11_VAD_RAM_SIZE - 0x20; + +P11_RAM_CODE_BEGIN = P11_CODE_BEGIN; +P11_RAM_CODE_END = P11_VAD_RAM_BEGIN; +P11_RAM_CODE_SIZE = P11_RAM_CODE_END - P11_RAM_CODE_BEGIN; + +MEMORY +{ + p11_ram(rwx) : ORIGIN = P11_RAM_CODE_BEGIN, LENGTH = P11_RAM_CODE_SIZE + p11_poweroff_ram(rw) : ORIGIN = P11_POWEROFF_RAM_BEGIN, LENGTH = P11_POWEROFF_RAM_SIZE + p11_message_ram(rw) : ORIGIN = P11_MESSAGE_BEGIN, LENGTH = P11_MESSAGE_SIZE + p11_vad_ram(rw) : ORIGIN = P11_VAD_RAM_BEGIN, LENGTH = P11_VAD_RAM_SIZE +} + +ENTRY(_start) + +SECTIONS +{ + . = ORIGIN(p11_ram); + .text ALIGN(32): + { + *startup.o(.text) + + *(.ram0.data.bss) + *(.ram0.data) + *(.ram0.text.const) + *(.ram0.text) + + *(.*.text) + *(.*.const) + + + . = ALIGN(4); + gsensor_dev_begin = .; + KEEP(*(.gsensor_dev)) + gsensor_dev_end = .; + + . = ALIGN(4); + hrsensor_dev_begin = .; + KEEP(*(.hrsensor_dev)) + hrsensor_dev_end = .; + + *(.rodata*) + . = ALIGN(4); + PROVIDE(low_power_target_begin = .); + *(.lp_target.2.ops) + *(.lp_target.1.ops) + *(.lp_target.0.ops) + PROVIDE(low_power_target_end = .); + + + . = ALIGN(4); + loop_detect_handler_begin = .; + KEEP(*(.loop_detect_region)) + loop_detect_handler_end = .; + + . = ALIGN(4); + *(.*.data) + . = ALIGN(4); + *(.data*) + . = ALIGN(4); + } > p11_ram + + .data ALIGN(32): + { + /* *(.data*) */ + } > p11_ram + + .bss ALIGN(4): + { + *(.bss) + *(.*.bss) + *(COMMON) + } > p11_ram + + .stack_bss ALIGN(32): + { + *(.stack_magic0) + PROVIDE(_stack_begin = .); + PROVIDE(_sstack_begin = .); + *(.sstack) + PROVIDE(_sstack_end = .); + + PROVIDE(_ustack_begin = .); + *(.ustack) + PROVIDE(_ustack_end = .); + + PROVIDE(_stack_end = .); + *(.stack_magic1) + } > p11_ram + + PROVIDE(overlay_demo_begin = .); + OVERLAY : AT(0x200000) SUBALIGN(4) + { + .overlay_bank_demo_init + { + LONG(0xffffffff); + *(.demo.code.bank.0) + . = ALIGN(4); + } + .overlay_bank_demo_normal0 + { + LONG(0xffffffff); + *(.demo.code.bank.1) + } + + .overlay_bank_demo_normal1 + { + LONG(0xffffffff); + *(.demo.code.bank.2) + } + } > p11_ram + PROVIDE(overlay_demo_end = .); + + + PROVIDE(overlay_sensor_begin = .); + OVERLAY : AT(0x210000) SUBALIGN(4) + { + /* TODO: */ + .overlay_bank_sensor_init + { + LONG(0xffffffff); + *(.sensor.code.bank.0) + . = ALIGN(4); + } + .overlay_bank_sensor_normal0 + { + LONG(0xffffffff); + *(.sensor.code.bank.1) + } + .overlay_bank_sensor_normal1 + { + LONG(0xffffffff); + *(.sensor.code.bank.2) + } + + } > p11_ram + PROVIDE(overlay_sensor_end = .); + + PROVIDE(overlay_sys_begin = .); + OVERLAY : AT(0x220000) SUBALIGN(4) + { + /* TODO: */ + .overlay_bank_sys_init + { + LONG(0xffffffff); + *(.sys.code.bank.0) + . = ALIGN(4); + } + .overlay_bank_sys_normal0 + { + LONG(0xffffffff); + *(.sys.code.bank.1) + } + } > p11_ram + PROVIDE(overlay_sys_end = .); + + PROVIDE(p11_heap_begin = .); + p11_heap_end = P11_RAM_CODE_END; + + + . = ORIGIN(p11_message_ram); + .p11_message ALIGN(32): + { + *(.p2m_data) + *(.m2p_data) + } > p11_message_ram + + . = ORIGIN(p11_vad_ram); + .p11_vad ALIGN(4): + { + *(.m2p_dvad_config) + . = ALIGN(4); + *(.m2p_avad_config) + . = ALIGN(4); + *(.p2m_cbuf_data) + } > p11_vad_ram +} + +text_begin = ADDR(.text); +text_size = SIZEOF(.text); +text_end = text_begin + text_size; + +bss_begin = ADDR(.bss); +bss_size = SIZEOF(.bss); + +data_addr = ADDR(.data); +data_begin = text_begin + text_size; +data_size = SIZEOF(.data); + +p11_message_data_addr = ADDR(.p11_message); +p11_message_data_size = SIZEOF(.p11_message); + +p11_heap_size = p11_heap_end - p11_heap_begin; +ASSERT(p11_heap_size >= CONFIG_P11_HEAP_RAM_SIZE_MIN, "p11 heap space too small !") diff --git a/2.code/2.p11_code/cpu/br28/p11_rom_stubs.ld b/2.code/2.p11_code/cpu/br28/p11_rom_stubs.ld new file mode 100644 index 0000000..6f761b1 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/p11_rom_stubs.ld @@ -0,0 +1,5 @@ +idle = ABSOLUTE(0x8000); +standby = ABSOLUTE(0x800a); +sleep = ABSOLUTE(0x801a); +deep_sleep = ABSOLUTE(0x802a); + diff --git a/2.code/2.p11_code/cpu/br28/post_build/BankLink.exe b/2.code/2.p11_code/cpu/br28/post_build/BankLink.exe new file mode 100644 index 0000000..79aa622 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/BankLink.exe differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_demo_init.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_init.bin new file mode 100644 index 0000000..7bde864 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_init.bin @@ -0,0 +1 @@ +ÿÿÿÿ \ No newline at end of file diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal0.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal0.bin new file mode 100644 index 0000000..7bde864 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal0.bin @@ -0,0 +1 @@ +ÿÿÿÿ \ No newline at end of file diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal1.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal1.bin new file mode 100644 index 0000000..7bde864 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal1.bin @@ -0,0 +1 @@ +ÿÿÿÿ \ No newline at end of file diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal2.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_demo_normal2.bin new file mode 100644 index 0000000..e69de29 diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_init.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_init.bin new file mode 100644 index 0000000..7bde864 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_init.bin @@ -0,0 +1 @@ +ÿÿÿÿ \ No newline at end of file diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_normal0.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_normal0.bin new file mode 100644 index 0000000..7bde864 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_normal0.bin @@ -0,0 +1 @@ +ÿÿÿÿ \ No newline at end of file diff --git a/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_normal1.bin b/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_normal1.bin new file mode 100644 index 0000000..7bde864 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/bank_sensor_normal1.bin @@ -0,0 +1 @@ +ÿÿÿÿ \ No newline at end of file diff --git a/2.code/2.p11_code/cpu/br28/post_build/download.bat b/2.code/2.p11_code/cpu/br28/post_build/download.bat new file mode 100644 index 0000000..2c9c12e --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/download.bat @@ -0,0 +1,71 @@ +rem @echo off + +@echo ***************************************************************** +@echo SDK BR28 P11 +@echo ***************************************************************** +@echo %date% + +cd %~dp0 + +set OBJDUMP=C:\JL\pi32\bin\llvm-objdump.exe +set OBJSIZEDUMP=C:\JL\pi32\bin\llvm-objsizedump.exe +set OBJCOPY=C:\JL\pi32\bin\llvm-objcopy.exe +set BANKLINK=.\BankLink.exe +set ELFFILE=p11.elf + +REM %OBJDUMP% -D -address-mask=0x1ffffff -print-imm-hex -print-dbg %ELFFILE% > p11.lst + +%OBJCOPY% -O binary -j .text %ELFFILE% text.bin +%OBJCOPY% -O binary -j .overlay_bank_demo_init %ELFFILE% bank_demo_init.bin +%OBJCOPY% -O binary -j .overlay_bank_demo_normal0 %ELFFILE% bank_demo_normal0.bin +%OBJCOPY% -O binary -j .overlay_bank_demo_normal1 %ELFFILE% bank_demo_normal1.bin +%OBJCOPY% -O binary -j .overlay_bank_demo_normal2 %ELFFILE% bank_demo_normal2.bin + +%OBJCOPY% -O binary -j .overlay_bank_sensor_init %ELFFILE% bank_sensor_init.bin +%OBJCOPY% -O binary -j .overlay_bank_sensor_normal0 %ELFFILE% bank_sensor_normal0.bin +%OBJCOPY% -O binary -j .overlay_bank_sensor_normal1 %ELFFILE% bank_sensor_normal1.bin + + + +%OBJDUMP% -section-headers -address-mask=0x1ffffff %ELFFILE% +%OBJDUMP% -t %ELFFILE% > symbol_tbl.txt + +%OBJSIZEDUMP% -dump-stack-size -enable-dbg-info %ELFFILE% > dump_stack_size.txt +%OBJSIZEDUMP% -dump-function-call -enable-dbg-info %ELFFILE% > dump_func_call.txt + +set bank_files=0x80 text.bin + +for %%a in (bank_demo_init.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_demo_init.bin) + +for %%a in (bank_demo_normal0.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_demo_normal0.bin) + +for %%a in (bank_demo_normal1.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_demo_normal1.bin) + +for %%a in (bank_sensor_init.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_sensor_init.bin) + +for %%a in (bank_sensor_normal0.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_sensor_normal0.bin) + +for %%a in (bank_sensor_normal1.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_sensor_normal1.bin) + +for %%a in (bank_sys_init.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_sys_init.bin) + +for %%a in (bank_sys_normal0.bin) do if %%~za gtr 0 ( +set bank_files=%bank_files% 0xAA55AA55 bank_sys_normal0.bin) + +echo %bank_files% + +%BANKLINK% %bank_files% p11_bank_code.bin + +if exist "..\..\..\..\sdk\cpu\br28\tools\" ( + copy .\p11_bank_code.bin ..\..\..\..\sdk\cpu\br28\tools\p11_code.bin +) + +::pause + diff --git a/2.code/2.p11_code/cpu/br28/post_build/dump_func_call.txt b/2.code/2.p11_code/cpu/br28/post_build/dump_func_call.txt new file mode 100644 index 0000000..9e1eea7 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/dump_func_call.txt @@ -0,0 +1,311 @@ +text_begin: +_user_mode: + timer_pool +exception_irq_handler: + exception_analyze +m2p_pvdd_level_sleep_t: +delay_50us: +pvdd_bk: +delay: +call_deep_sleep: + m2p_message + m2p_pvdd_level_sleep_t + m2p_pvdd_level_sleep_t +timer2_dly_lrc: +pvdd_protect: + pvdd_bk + m2p_pvdd_level_sleep_t +pvdd_protect_release: + m2p_pvdd_level_sleep_t + pvdd_bk +ram0_enter_sleep: +ram0_exit_sleep: +deepsleep_r: + ram0_enter_sleep + pvdd_protect_release + pvdd_protect + ram0_exit_sleep +gsensor_dev_begin: +gSensor.24: +usr_jiffies: +lrc_feq: +lrc_feq.186: +soft_iic_start: + delay + delay + delay +soft_iic_tx_byte: + delay + delay + delay + delay + delay + delay +soft_iic_stop: + delay + delay +_gravity_sensor_get_ndata: + soft_iic_start + soft_iic_tx_byte + soft_iic_stop +mir3da_register_read: +mir3da_is_online: + mir3da_register_read +mir3da_register_mask_write: +mdelay: +gravity_sensor_command: + soft_iic_start + soft_iic_tx_byte +mir3da_register_write: +mir3da_init: + mir3da_is_online + mir3da_register_mask_write + mdelay + mir3da_register_read + mir3da_register_write + mir3da_register_write + mir3da_register_write + mir3da_register_write + mir3da_register_write + mir3da_register_write + mir3da_register_mask_write + mir3da_register_write +mir3da_ctl: +stk832x_register_write: +stk832x_software_reset: + stk832x_register_write +stk832x_register_read: +stk832x_check_chip_id: + stk832x_software_reset + stk832x_register_read +stk832x_init: + stk832x_check_chip_id + stk832x_software_reset + stk832x_register_write + stk832x_register_write + stk832x_register_write + stk832x_register_write + stk832x_register_write + stk832x_register_write + stk832x_register_write +stk832x_ctl: +local_irq_disable: + filter +local_irq_enable: + filter +HWI_Install: + local_irq_disable + local_irq_enable +debug_init: + exception_irq_handler +usr_timer_init: + filter + lptmr3_int +bit_set_ie: + local_irq_disable +power_init: + p11_heap_begin + p2m_message + tmr0_int + HWI_Install + m2p_int + HWI_Install + soft_int_test_isr.207 + HWI_Install + p33_wkup_int + HWI_Install + bit_set_ie +iovdd2_bypass_iovdd: +irq_disable_core: + filter +irq_enable_core: + filter +__get_min_precesion: + filter + usr_jiffies +lptmr3_run: + lrc_feq + filter +usr_timer_del: + local_irq_disable + filter +charge_disable: + irq_disable_core + filter +p11_power_hw_manage: + local_irq_disable + irq_disable_core + filter + irq_enable_core + local_irq_disable + local_irq_disable + timer_pool + local_irq_enable + usr_timer_del + local_irq_enable + lvcmp_filter + usr_jiffies + __get_min_precesion + lptmr3_run + local_irq_enable + usr_jiffies + usr_jiffies + irq_disable_core + local_irq_disable + charge_disable + usr_timer_del + local_irq_enable + call_deep_sleep + irq_enable_core +main: + local_irq_disable + debug_init + usr_timer_init + power_init + iovdd2_bypass_iovdd + local_irq_enable + mdelay + p11_power_hw_manage +exception_analyze: +lptmr3_int: + local_irq_disable + filter + usr_jiffies + local_irq_disable + local_irq_enable + __get_min_precesion + lptmr3_run + local_irq_enable +ram_pdown_poff_exit: + delay + m2p_message + delay + delay + delay +analog_pdown_exit0: + m2p_message + timer2_dly_lrc + filter + timer2_dly_lrc + timer2_dly_lrc + timer2_dly_lrc +analog_pdown_exit1: + filter + m2p_message + timer2_dly_lrc +power_off_exit: + filter + m2p_message + timer2_dly_lrc +__power_recover: + local_irq_disable + filter +tmr0_int: + __power_recover +p33_wkup_int: + filter +ram_pdown_poff_enter: + m2p_message + delay + delay +analog_pdown_poff_enter: + m2p_message + filter + timer2_dly_lrc + timer2_dly_lrc +user_m2p11_irq: + m2p_message +m2p_int: + filter + m2p_message + local_irq_disable + delay + ram_pdown_poff_enter + local_irq_enable + local_irq_disable + delay + ram_pdown_poff_enter + analog_pdown_poff_enter + local_irq_enable + local_irq_disable + delay + ram_pdown_poff_enter + analog_pdown_poff_enter + local_irq_enable + local_irq_disable + bit_set_ie + delay + local_irq_enable + user_m2p11_irq +lvcmp_filter: + irq_disable_core + filter +soft_int_test_isr.207: + irq_disable_core + wkup_buf + memset + irq_enable_core + p2m_message + __power_recover +sqrt: +__ieee754_sqrt: + __muldf3 + __adddf3 + __subdf3 + __divdf3 +abs: +memcmp: +memmove: +memset: +strlen: +__adddf3: + normalize + normalize + __lshrdi3 + __ashldi3 + rep_clz + __ashldi3 + __lshrdi3 + __ashldi3 +normalize: + rep_clz + __ashldi3 +rep_clz: +__ashldi3: +__divdf3: + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __muldi3 + normalize + normalize +normalize: + __ashldi3 +__lshrdi3: +__muldf3: + __muldi3 + __muldi3 + __muldi3 + __muldi3 + __ashldi3 + __lshrdi3 + __ashldi3 + __lshrdi3 + normalize + normalize +normalize: + __ashldi3 +__muldi3: +__subdf3: diff --git a/2.code/2.p11_code/cpu/br28/post_build/dump_stack_size.txt b/2.code/2.p11_code/cpu/br28/post_build/dump_stack_size.txt new file mode 100644 index 0000000..09a7483 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/dump_stack_size.txt @@ -0,0 +1,86 @@ +text_begin: 0 +_user_mode: 0 +exception_irq_handler: 100 +m2p_pvdd_level_sleep_t: 0 +delay_50us: 0 +pvdd_bk: 0 +delay: 0 +call_deep_sleep: 0 +timer2_dly_lrc: 4 +pvdd_protect: 0 +pvdd_protect_release: 8 +ram0_enter_sleep: 0 +ram0_exit_sleep: 0 +deepsleep_r: 4 +gsensor_dev_begin: 0 +gSensor.24: 0 +usr_jiffies: 0 +lrc_feq: 0 +lrc_feq.186: 0 +soft_iic_start: 12 +soft_iic_tx_byte: 12 +soft_iic_stop: 16 +_gravity_sensor_get_ndata: 12 +mir3da_register_read: 0 +mir3da_is_online: 12 +mir3da_register_mask_write: 0 +mdelay: 0 +gravity_sensor_command: 4 +mir3da_register_write: 0 +mir3da_init: 12 +mir3da_ctl: 112 +stk832x_register_write: 0 +stk832x_software_reset: 12 +stk832x_register_read: 0 +stk832x_check_chip_id: 12 +stk832x_init: 124 +stk832x_ctl: 120 +local_irq_disable: 0 +local_irq_enable: 0 +HWI_Install: 16 +debug_init: 0 +usr_timer_init: 0 +bit_set_ie: 12 +power_init: 12 +iovdd2_bypass_iovdd: 0 +irq_disable_core: 0 +irq_enable_core: 0 +__get_min_precesion: 4 +lptmr3_run: 4 +usr_timer_del: 4 +charge_disable: 8 +p11_power_hw_manage: 28 +main: 0 +exception_analyze: 0 +lptmr3_int: 52 +ram_pdown_poff_exit: 16 +analog_pdown_exit0: 20 +analog_pdown_exit1: 4 +power_off_exit: 8 +__power_recover: 32 +tmr0_int: 36 +p33_wkup_int: 68 +ram_pdown_poff_enter: 16 +analog_pdown_poff_enter: 32 +user_m2p11_irq: 0 +m2p_int: 72 +lvcmp_filter: 8 +soft_int_test_isr.207: 68 +sqrt: 0 +__ieee754_sqrt: 24 +abs: 0 +memcmp: 4 +memmove: 16 +memset: 8 +strlen: 0 +__adddf3: 56 +normalize: 16 +rep_clz: 0 +__ashldi3: 0 +__divdf3: 76 +normalize: 8 +__lshrdi3: 0 +__muldf3: 68 +normalize: 8 +__muldi3: 12 +__subdf3: 0 diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf b/2.code/2.p11_code/cpu/br28/post_build/p11.elf new file mode 100644 index 0000000..94047e9 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11.elf differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.0.preopt.bc b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.0.preopt.bc new file mode 100644 index 0000000..157141f Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.0.preopt.bc differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.2.internalize.bc b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.2.internalize.bc new file mode 100644 index 0000000..a85d83d Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.2.internalize.bc differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.4.opt.bc b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.4.opt.bc new file mode 100644 index 0000000..11a285c Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.4.opt.bc differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.5.precodegen.bc b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.5.precodegen.bc new file mode 100644 index 0000000..11a285c Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.0.5.precodegen.bc differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.o b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.o new file mode 100644 index 0000000..420c8e1 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.o differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.objs.txt b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.objs.txt new file mode 100644 index 0000000..5efa014 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.objs.txt @@ -0,0 +1 @@ + objs/apps/common/device/bmp280/bmp280.c.o objs/apps/common/device/gSensor/SC7A20.c.o objs/apps/common/device/gSensor/gSensor_algo.c.o objs/apps/common/device/gSensor/gSensor_manage.c.o objs/apps/common/device/gSensor/mir3da.c.o objs/apps/common/device/gSensor/msa310.c.o objs/apps/common/device/gSensor/msa310_function.c.o objs/apps/common/device/gSensor/msa31x.c.o objs/apps/common/device/gSensor/stk832x.c.o objs/apps/common/device/hr_sensor/hrSensor_manage.c.o objs/apps/common/device/hr_sensor/hrs3603.c.o objs/apps/common/device/hr_sensor/hx3602/hrs3602.c.o objs/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c.o objs/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c.o objs/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c.o objs/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c.o objs/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c.o objs/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c.o objs/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c.o objs/apps/common/sport/sensor_api.c.o objs/apps/debug.c.o objs/apps/lib_config.c.o objs/apps/main.c.o objs/apps/msg.c.o objs/apps/timer.c.o objs/cpu/br28/common.c.o objs/cpu/br28/iic.c.o objs/cpu/br28/iic_soft.c.o objs/cpu/br28/spi.c.o objs/cpu/br28/test.c.o objs/cpu/br28/uart.c.o objs/cpu/br28/vad_api.c.o objs/cpu/br28/vad_develop.c.o diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.elf.resolution.txt b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.resolution.txt new file mode 100644 index 0000000..3c602e6 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/p11.elf.resolution.txt @@ -0,0 +1,578 @@ +objs/apps/common/device/bmp280/bmp280.c.o +objs/apps/common/device/gSensor/SC7A20.c.o +objs/apps/common/device/gSensor/gSensor_algo.c.o +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,algo_event_response,pl +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,user_p11_post_to_main_system,l +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,gsensor_algo_run,pl +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,algo_gsensor_run,l +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,gsensor_algo_init,pl +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,algo_gsensor_init,l +-r=objs/apps/common/device/gSensor/gSensor_algo.c.o,gsensor_algo_uninit,pl +objs/apps/common/device/gSensor/gSensor_manage.c.o +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gravity_sensor_write,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,soft_iic_start,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,soft_iic_tx_byte,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,printf,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,delay,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,soft_iic_write_buf,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,soft_iic_stop,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gravity_sensor_command,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,_gravity_sensor_get_ndata,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,soft_iic_rx_byte,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gSensor_int_io_detect,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gpio_read,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gSensor_read_data,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,memcpy,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,get_gSensor_data,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,read_gsensor_buf_check_len,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_set_soft_irq_size,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,read_gsensor_nbuf,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,cbuf_read,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_data_irq_handle,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_algo_run,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,hr_sensor_input_accel_data,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,cbuf_write,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,cbuf_clear,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,user_p11_post_to_main_system,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,cbuf_get_data_len,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,write_gsensor_data_handle,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,sensorhub_irq_add, +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,user_main_post_to_p11_system,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_io_ctl,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gravity_sensor_init,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,soft_iic_init,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,memcmp,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,strlen,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,cbuf_init,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_disable,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_algo_uninit,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_enable,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_algo_init,l +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gSensor_hdl,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,__gSensor_info,pl +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_dev_begin, +-r=objs/apps/common/device/gSensor/gSensor_manage.c.o,gsensor_dev_end, +objs/apps/common/device/gSensor/mir3da.c.o +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_init,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,printf,l +-r=objs/apps/common/device/gSensor/mir3da.c.o,mdelay,l +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_set_enable,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_read_data,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_open_full_fifo_int,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_open_fifo_watermark_int,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_close_fifo_int,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_read_full_fifo,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_read_fifo,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,mir3da_ctl,pl +-r=objs/apps/common/device/gSensor/mir3da.c.o,memcpy,l +-r=objs/apps/common/device/gSensor/mir3da.c.o,gravity_sensor_command,l +-r=objs/apps/common/device/gSensor/mir3da.c.o,_gravity_sensor_get_ndata,l +-r=objs/apps/common/device/gSensor/mir3da.c.o,sensor_model,pl +objs/apps/common/device/gSensor/msa310.c.o +objs/apps/common/device/gSensor/msa310_function.c.o +objs/apps/common/device/gSensor/msa31x.c.o +objs/apps/common/device/gSensor/stk832x.c.o +-r=objs/apps/common/device/gSensor/stk832x.c.o,printf,l +-r=objs/apps/common/device/gSensor/stk832x.c.o,_gravity_sensor_get_ndata,l +-r=objs/apps/common/device/gSensor/stk832x.c.o,mdelay,l +-r=objs/apps/common/device/gSensor/stk832x.c.o,gravity_sensor_command,l +-r=objs/apps/common/device/gSensor/stk832x.c.o,memcpy,l +objs/apps/common/device/hr_sensor/hrSensor_manage.c.o +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hrsensor_write_nbyte,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,soft_iic_start,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,delay,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,soft_iic_tx_byte,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,printf,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,soft_iic_stop,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hrsensor_read_nbyte,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,soft_iic_rx_byte,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hr_sensor_io_ctl,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hr_sensor_input_accel_data,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hr_sensor_init,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,soft_iic_init,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,memcmp,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,strlen,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hr_sensor_req_irq,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,sensorhub_irq_add, +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,user_main_post_to_p11_system,l +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hrSensor_hdl,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,__hrsensor_info,pl +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hrsensor_dev_begin, +-r=objs/apps/common/device/hr_sensor/hrSensor_manage.c.o,hrsensor_dev_end, +objs/apps/common/device/hr_sensor/hrs3603.c.o +objs/apps/common/device/hr_sensor/hx3602/hrs3602.c.o +objs/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c.o +objs/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c.o +objs/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c.o +objs/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c.o +objs/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c.o +objs/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c.o +objs/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c.o +objs/apps/common/sport/sensor_api.c.o +objs/apps/debug.c.o +-r=objs/apps/debug.c.o,putchar,pl +-r=objs/apps/debug.c.o,putbyte,pl +-r=objs/apps/debug.c.o,puts,pl +-r=objs/apps/debug.c.o,put_u32hex,pl +-r=objs/apps/debug.c.o,put_buf,pl +-r=objs/apps/debug.c.o,printf,pl +objs/apps/lib_config.c.o +-r=objs/apps/lib_config.c.o,LIB_CONFIG_VAD_ENABLE,pl +-r=objs/apps/lib_config.c.o,LIB_CONFIG_LPCTMU_ENABLE,pl +-r=objs/apps/lib_config.c.o,LIB_CONFIG_EXCEPTION_RESET_ENABLE,pl +-r=objs/apps/lib_config.c.o,CONFIG_DVAD_DEVELOP_ENABLE,pl +objs/apps/main.c.o +-r=objs/apps/main.c.o,user_main_init,pl +-r=objs/apps/main.c.o,user_run_loop,pl +-r=objs/apps/main.c.o,main,plx +-r=objs/apps/main.c.o,local_irq_disable,l +-r=objs/apps/main.c.o,printf,l +-r=objs/apps/main.c.o,debug_init,l +-r=objs/apps/main.c.o,usr_timer_init,l +-r=objs/apps/main.c.o,power_init,l +-r=objs/apps/main.c.o,iovdd2_bypass_iovdd,l +-r=objs/apps/main.c.o,local_irq_enable,l +-r=objs/apps/main.c.o,mdelay,l +-r=objs/apps/main.c.o,p11_power_hw_manage,l +-r=objs/apps/main.c.o,overlay_demo_begin, +-r=objs/apps/main.c.o,overlay_sensor_begin, +-r=objs/apps/main.c.o,bank_info_table,pl +objs/apps/msg.c.o +-r=objs/apps/msg.c.o,task_clear_all_message,pl +-r=objs/apps/msg.c.o,cbuf_clear,l +-r=objs/apps/msg.c.o,task_message_init,pl +-r=objs/apps/msg.c.o,cbuf_init,l +-r=objs/apps/msg.c.o,task_post_msg,pl +-r=objs/apps/msg.c.o,local_irq_disable,l +-r=objs/apps/msg.c.o,local_irq_enable,l +-r=objs/apps/msg.c.o,cbuf_write,l +-r=objs/apps/msg.c.o,task_get_msg,pl +-r=objs/apps/msg.c.o,cbuf_read,l +-r=objs/apps/msg.c.o,puts,l +-r=objs/apps/msg.c.o,mdebug_io_1,pl +-r=objs/apps/msg.c.o,mdebug_io_0,pl +-r=objs/apps/msg.c.o,user_p11_post_to_main_system,pl +-r=objs/apps/msg.c.o,printf,l +-r=objs/apps/msg.c.o,memcpy,l +-r=objs/apps/msg.c.o,__power_recover,l +-r=objs/apps/msg.c.o,user_p11_p2m_post_init,pl +-r=objs/apps/msg.c.o,user_main_post_to_p11_system,pl +-r=objs/apps/msg.c.o,user_m2p11_irq,pl +-r=objs/apps/msg.c.o,p2m_message,l +-r=objs/apps/msg.c.o,m2p_message,l +objs/apps/timer.c.o +-r=objs/apps/timer.c.o,get_cur_sys_tick,pl +-r=objs/apps/timer.c.o,timer_tick_init,pl +-r=objs/apps/timer.c.o,usr_timer_add,l +-r=objs/apps/timer.c.o,usr_lp_timer_init,pl +-r=objs/apps/timer.c.o,printf,l +-r=objs/apps/timer.c.o,HWI_Install,l +-r=objs/apps/timer.c.o,user_lptime_init,pl +-r=objs/apps/timer.c.o,cur_time_tick,pl +-r=objs/apps/timer.c.o,usr_usr_lp_timer_int_table,pl +-r=objs/apps/timer.c.o,usr_lp_timer_sfr_table,pl +-r=objs/apps/timer.c.o,get_lp_time_cnt,pl +-r=objs/apps/timer.c.o,loop_detect_handler_begin, +-r=objs/apps/timer.c.o,loop_detect_handler_end, +objs/cpu/br28/common.c.o +-r=objs/cpu/br28/common.c.o,udelay,pl +-r=objs/cpu/br28/common.c.o,mdelay,pl +-r=objs/cpu/br28/common.c.o,delay_measurement,pl +-r=objs/cpu/br28/common.c.o,gpio_set_output_value,l +-r=objs/cpu/br28/common.c.o,gpio_set_direction,l +-r=objs/cpu/br28/common.c.o,debug_io_1,pl +-r=objs/cpu/br28/common.c.o,debug_io_0,pl +-r=objs/cpu/br28/common.c.o,debug_io,pl +objs/cpu/br28/iic.c.o +-r=objs/cpu/br28/iic.c.o,hw_iic_init,pl +-r=objs/cpu/br28/iic.c.o,gpio_set_die,l +-r=objs/cpu/br28/iic.c.o,gpio_set_output_value,l +-r=objs/cpu/br28/iic.c.o,gpio_set_fun_input_port,l +-r=objs/cpu/br28/iic.c.o,gpio_set_fun_output_port,l +-r=objs/cpu/br28/iic.c.o,gpio_set_pull_up,l +-r=objs/cpu/br28/iic.c.o,gpio_set_pull_down,l +-r=objs/cpu/br28/iic.c.o,hw_iic_close,pl +-r=objs/cpu/br28/iic.c.o,hw_iic_start,pl +-r=objs/cpu/br28/iic.c.o,hw_iic_stop,pl +-r=objs/cpu/br28/iic.c.o,hw_iic_master_tx_byte,pl +-r=objs/cpu/br28/iic.c.o,local_irq_disable,l +-r=objs/cpu/br28/iic.c.o,delay,l +-r=objs/cpu/br28/iic.c.o,local_irq_enable,l +-r=objs/cpu/br28/iic.c.o,hw_iic_master_rx_byte,pl +-r=objs/cpu/br28/iic.c.o,putchar,l +-r=objs/cpu/br28/iic.c.o,hw_iic_master_read_buf,pl +-r=objs/cpu/br28/iic.c.o,hw_iic_master_write_buf,pl +-r=objs/cpu/br28/iic.c.o,iic_master_eeprom_test,pl +-r=objs/cpu/br28/iic.c.o,printf,l +-r=objs/cpu/br28/iic.c.o,iic_slave_test,pl +objs/cpu/br28/iic_soft.c.o +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_init,pl +-r=objs/cpu/br28/iic_soft.c.o,gpio_set_direction,l +-r=objs/cpu/br28/iic_soft.c.o,gpio_set_pull_down,l +-r=objs/cpu/br28/iic_soft.c.o,gpio_set_die,l +-r=objs/cpu/br28/iic_soft.c.o,gpio_set_output_value,l +-r=objs/cpu/br28/iic_soft.c.o,gpio_set_pull_up,l +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_uninit,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_suspend,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_resume,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_start,pl +-r=objs/cpu/br28/iic_soft.c.o,delay,l +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_stop,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_tx_byte,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_rx_byte,pl +-r=objs/cpu/br28/iic_soft.c.o,gpio_read,l +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_read_buf,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_write_buf,pl +-r=objs/cpu/br28/iic_soft.c.o,soft_iic_cfg,pl +objs/cpu/br28/spi.c.o +-r=objs/cpu/br28/spi.c.o,spi_cs_set_active,pl +-r=objs/cpu/br28/spi.c.o,gpio_set_output_value,l +-r=objs/cpu/br28/spi.c.o,spi_cs_set_idle,pl +-r=objs/cpu/br28/spi.c.o,spi_master_tx_byte,pl +-r=objs/cpu/br28/spi.c.o,spi_master_dma_tx,pl +-r=objs/cpu/br28/spi.c.o,printf,l +-r=objs/cpu/br28/spi.c.o,spi_master_rx_byte,pl +-r=objs/cpu/br28/spi.c.o,spi_master_dma_rx,pl +-r=objs/cpu/br28/spi.c.o,spi_master_init,pl +-r=objs/cpu/br28/spi.c.o,gpio_set_direction,l +-r=objs/cpu/br28/spi.c.o,gpio_set_fun_output_port,l +-r=objs/cpu/br28/spi.c.o,gpio_set_pull_down,l +-r=objs/cpu/br28/spi.c.o,gpio_set_pull_up,l +-r=objs/cpu/br28/spi.c.o,gpio_set_die,l +-r=objs/cpu/br28/spi.c.o,gpio_set_fun_input_port,l +-r=objs/cpu/br28/spi.c.o,spi_close,pl +-r=objs/cpu/br28/spi.c.o,spi_master_test_code,pl +-r=objs/cpu/br28/spi.c.o,put_buf,l +-r=objs/cpu/br28/spi.c.o,memset,l +-r=objs/cpu/br28/spi.c.o,delay,l +objs/cpu/br28/test.c.o +-r=objs/cpu/br28/test.c.o,soft_int_test,pl +-r=objs/cpu/br28/test.c.o,HWI_Install,l +-r=objs/cpu/br28/test.c.o,delay,l +-r=objs/cpu/br28/test.c.o,printf,l +-r=objs/cpu/br28/test.c.o,bit_set_swi,l +-r=objs/cpu/br28/test.c.o,bit_clr_swi,l +objs/cpu/br28/uart.c.o +-r=objs/cpu/br28/uart.c.o,debug_uart_init,pl +-r=objs/cpu/br28/uart.c.o,gpio_set_output_value,l +-r=objs/cpu/br28/uart.c.o,gpio_set_direction,l +-r=objs/cpu/br28/uart.c.o,gpio_set_fun_output_port,l +-r=objs/cpu/br28/uart.c.o,putchar,l +-r=objs/cpu/br28/uart.c.o,local_irq_disable,l +-r=objs/cpu/br28/uart.c.o,local_irq_enable,l +-r=objs/cpu/br28/uart.c.o,putbyte,l +objs/cpu/br28/vad_api.c.o +objs/cpu/br28/vad_develop.c.o +-r=objs/cpu/br28/vad_develop.c.o,dvad_open,pl +-r=objs/cpu/br28/vad_develop.c.o,jl_dvad_open,l +-r=objs/cpu/br28/vad_develop.c.o,dvad_get_mic_gain,pl +-r=objs/cpu/br28/vad_develop.c.o,jl_dvad_get_mic_gain,l +-r=objs/cpu/br28/vad_develop.c.o,dvad_detect,pl +-r=objs/cpu/br28/vad_develop.c.o,jl_dvad_detect,l +-r=objs/cpu/br28/vad_develop.c.o,dvad_close,pl +-r=objs/cpu/br28/vad_develop.c.o,jl_dvad_close,l +-r=objs/cpu/br28/vad_develop.c.o,CONFIG_DVAD_DEVELOP_ENABLE,l +cpu/br28/liba/cpu.a.llvm.3228.hwi.c +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,HWI_Install,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,reg_set_ip,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,bit_set_ie,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,bit_clr_ie,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,bit_set_swi,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,bit_clr_swi,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,local_irq_disable,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,local_irq_enable,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,irq_disable_core,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,irq_enable_core,pl +-r=cpu/br28/liba/cpu.a.llvm.3228.hwi.c,ISR_BASE, +cpu/br28/liba/cpu.a.llvm.20464.debug.c +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,exception_analyze,plx +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,puts,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,printf,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,put_u32hex,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,putchar,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,debug_init,pl +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,exception_irq_handler,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,debug_exception_test,pl +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,LIB_CONFIG_EXCEPTION_RESET_ENABLE,l +-r=cpu/br28/liba/cpu.a.llvm.20464.debug.c,_stack_end, +cpu/br28/liba/cpu.a.llvm.34308.gpio.c +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_direction,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_output_value,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_pull_up,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_pull_down,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_die,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_dieh,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_read,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_fun_output_port,pl +-r=cpu/br28/liba/cpu.a.llvm.34308.gpio.c,gpio_set_fun_input_port,pl +cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,usr_timer_add,pl +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,usr_timer_del,pl +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,local_irq_disable,l +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,local_irq_enable,l +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,usr_timer_schedule,pl +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,lptmr3_run,pl +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,lptmr3_stop,pl +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,usr_timer_init,pl +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.146528.usr_timer.c,get_lrc_hz,l +cpu/br28/liba/cpu.a.llvm.163672.power_driver.c +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,tmr0_wake_callback,pl +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,power_init,pl +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,lp_ipc_init,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,charge_init,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,power_wakeup_init,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,puts,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_power_hw_manage,pl +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,local_irq_disable,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,filter_check,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_low_power_target_query,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_low_power_target_enter,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_lowpower_down,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_low_power_target_exit,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,local_irq_enable,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,__power_recover,l +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_heap_begin, +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p11_heap_size, +-r=cpu/br28/liba/cpu.a.llvm.163672.power_driver.c,p2m_message,l +cpu/br28/liba/cpu.a.llvm.174768.power_manage.c +-r=cpu/br28/liba/cpu.a.llvm.174768.power_manage.c,p11_low_power_target_query,pl +-r=cpu/br28/liba/cpu.a.llvm.174768.power_manage.c,p11_low_power_target_enter,pl +-r=cpu/br28/liba/cpu.a.llvm.174768.power_manage.c,p11_low_power_target_exit,pl +-r=cpu/br28/liba/cpu.a.llvm.174768.power_manage.c,low_power_target_begin, +-r=cpu/br28/liba/cpu.a.llvm.174768.power_manage.c,low_power_target_end, +cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c +-r=cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c,power_wakeup_init,pl +-r=cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c,bit_set_ie,l +-r=cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c,charge_handler,l +-r=cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c,bit_set_swi,l +-r=cpu/br28/liba/cpu.a.llvm.179648.power_wakeup.c,wkup_buf,l +cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,user_m2p11_irq,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,get_lrc_hz,pl +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,lp_ipc_handle_sync_cmd,pl +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,lp_ipc_init,pl +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,bit_clr_ie,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,bit_set_ie,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,lowpower_prepare,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,charge_enable_flt,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,charge_disable,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,wdt_clear,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,puts,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,__light_power_down_enter,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,__power_down_enter,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,__power_off_enter,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,__soft_power_off_enter,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,lp_ctmu_init,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,p11_vad_m2p_handle, +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,soft_int_enable,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,p2m_message,pl +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,m2p_message,pl +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,m2p_cmd,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,LIB_CONFIG_LPCTMU_ENABLE,l +-r=cpu/br28/liba/cpu.a.llvm.187036.lp_ipc.c,LIB_CONFIG_VAD_ENABLE,l +cpu/br28/liba/cpu.a.llvm.201436.charge.c +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_disable,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,printf,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,irq_disable_core,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,irq_enable_core,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_enable,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_enable_flt,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,filter_check,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,usr_timer_add,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,usr_timer_del,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_soff,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,local_irq_disable,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,local_irq_enable,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_handler,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,soft_int_enable,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,soft_int_disable,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,p33_wkup_takeover,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_init,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,bit_clr_swi,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,lpctmu_softoff_scan,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,pluse_counter_enable,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,puts,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,__power_recover,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,filter_enable,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,filter,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,charge_en,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,timer_id,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,p3_awkup_flt1_bk,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,wkup_buf,pl +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,LIB_CONFIG_LPCTMU_ENABLE,l +-r=cpu/br28/liba/cpu.a.llvm.201436.charge.c,p2m_message,l +cpu/br28/liba/cpu.a.llvm.222448.power_analog.c +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,lowpower_prepare,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,lowpower_prepare_exit,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,hw_dcdc13_on,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,timer2_dly_lrc,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,hw_ldo13_on,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,__light_power_down_enter,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,local_irq_disable,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,delay,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,local_irq_enable,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,__power_down_enter,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,__power_off_enter,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,__soft_power_off_enter,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,bit_set_ie,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,pluse_counter_enable,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,lpctmu_softoff_enter,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,wait_dvdd_power_up,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,power_off_exit,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,__power_recover,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,puts,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,pluse_counter_disable,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,lpctmu_softoff_exit,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,p11_lowpower_down,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,irq_disable_core,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,putchar,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,idle, +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,standby, +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,sleep, +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,call_deep_sleep,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,irq_enable_core,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,putbyte,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,charge_soff,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,p33_wkup_msys,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,m2p_message,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,m2p_cmd,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,lp_sta,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,p2m_clk_backups,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,LIB_CONFIG_LPCTMU_ENABLE,l +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,pmu_det_backup,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,dvdd_lel,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,rvdd_lel,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,pvdd_lel,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,wdt_backup,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,wk_bak,pl +-r=cpu/br28/liba/cpu.a.llvm.222448.power_analog.c,wvio_sel_bak,pl +cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,delay,pl +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,timer2_dly_lrc,pl +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,sleep, +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,pvdd_protect_release_prepare,pl +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,pvdd_protect,plx +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,pvdd_protect_release,plx +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,ram0_enter_sleep,plx +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,ram0_exit_sleep,plx +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,call_deep_sleep,pl +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,deepsleep_r,l +-r=cpu/br28/liba/cpu.a.llvm.255764.pvdd_protect.c,m2p_message,l +cpu/br28/liba/cpu.a.llvm.265988.p33.c +-r=cpu/br28/liba/cpu.a.llvm.265988.p33.c,iovdd2_bypass_iovdd,pl +cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,IirFilter_init,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,IirFilter_update,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,p11_lctm_int,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,ctmu_res_algorithm_analyze,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,__power_recover,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lp_timer3_int,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,putbyte,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lp_timer3_init,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,printf,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,HWI_Install,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctmu_softoff_enter,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,puts,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctmu_softoff_scan,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,sleep, +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,delay,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctmu_softoff_exit,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctmu_alog_reset,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lp_ctmu_init,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,pluse_counter_enable,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,pluse_counter_disable,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctmu_test,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,ctmu_res_algorithm_init,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,gpio_set_direction,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,gpio_set_die,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,gpio_set_dieh,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,gpio_set_pull_up,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,gpio_set_pull_down,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctm_int_flag,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctm_softoff_flag,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,lpctm_charge_mode,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,eartch_cnt,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,eartch_iir,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,eartch_last_state,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,m2p_message,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,p2m_message,l +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,key_state,pl +-r=cpu/br28/liba/cpu.a.llvm.100940.lp_ctmu.c,th_iir,pl +cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,TouchAlgo_Init,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,TouchAlgo_Update,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,TouchAlgo_Reset,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,TouchAlgo_GetKey,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,ctmu_res_algorithm_init,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,ctmu_res_algorithm_analyze,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,lpctmu_alog_reset,pl +-r=cpu/br28/liba/cpu.a.llvm.129768.lp_ctmu_alog_v2.c,m2p_message,l +cpu/br28/liba/cpu.a.llvm.144064.wdt.c +-r=cpu/br28/liba/cpu.a.llvm.144064.wdt.c,wdt_clear,pl +cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,jl_dvad_open,pl +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,dvad_Init,l +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,jl_dvad_get_mic_gain,pl +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,jl_dvad_detect,pl +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,dvad_Run,l +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,jl_dvad_close,pl +-r=cpu/br28/liba/vad_algo.a.llvm.17838.dvad_api.c,CONFIG_DVAD_DEVELOP_ENABLE,l +cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,htk_fixlog2,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,init_thresh,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,frame_pow,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,find_thresh_dvad,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,simple_dvad,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,dvad_Run,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,dvad_Init,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,get_dvad_buf,pl +-r=cpu/br28/liba/vad_algo.a.llvm.382.dvad_algo.c,logtable,pl +cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_read,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,local_irq_disable,l +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,local_irq_enable,l +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_prewrite,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_updata_prewrite,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_discard_prewrite,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_write,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_is_write_able,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_write_alloc,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_write_updata,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_read_alloc,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_read_updata,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_init,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_clear,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_rewrite,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_get_writeptr,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_get_data_size,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_get_readptr,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_read_goback,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_get_data_len,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_read_alloc_len,pl +-r=cpu/br28/liba/cbuf.a.llvm.548.circular_buf.c,cbuf_read_alloc_len_updata,pl +cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,Is_double_click,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,algo_gsensor_init,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,printf,l +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,algo_gsensor_run,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,algo_gsensor_set_wrist,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,algo_gsensor_set_debug,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,algo_gsensor_get_ver,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,python_init,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,python_run,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,sqrt,l +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,abs,l +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,amp_x,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,amp_y,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,amp_z,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,amp_total,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,still_cnt,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,peak_error_fifo,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,point_cnt,pl +-r=cpu/br28/liba/algo_gsensor.a.llvm.502.p11_algo_gsensor.c,bright_screen_time,pl diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11.map b/2.code/2.p11_code/cpu/br28/post_build/p11.map new file mode 100644 index 0000000..3b97be2 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/p11.map @@ -0,0 +1,479 @@ +Archive member included to satisfy reference by file (symbol) + +cpu/br28/liba/cpu.a(hwi.o) objs/apps/timer.c.o (symbol from plugin) (HWI_Install) +cpu/br28/liba/cpu.a(debug.o) objs/apps/main.c.o (symbol from plugin) (debug_init) +cpu/br28/liba/cpu.a(gpio.o) objs/cpu/br28/common.c.o (symbol from plugin) (gpio_set_direction) +cpu/br28/liba/cpu.a(usr_timer.o) + objs/apps/timer.c.o (symbol from plugin) (usr_timer_add) +cpu/br28/liba/cpu.a(power_driver.o) + objs/apps/main.c.o (symbol from plugin) (power_init) +cpu/br28/liba/cpu.a(power_manage.o) + power_driver.o (symbol from plugin) (p11_low_power_target_query) +cpu/br28/liba/cpu.a(power_wakeup.o) + power_driver.o (symbol from plugin) (power_wakeup_init) +cpu/br28/liba/cpu.a(lp_ipc.o) + usr_timer.o (symbol from plugin) (get_lrc_hz) +cpu/br28/liba/cpu.a(charge.o) + lp_ipc.o (symbol from plugin) (charge_disable) +cpu/br28/liba/cpu.a(power_analog.o) + lp_ipc.o (symbol from plugin) (lowpower_prepare) +cpu/br28/liba/cpu.a(pvdd_protect.o) + objs/apps/common/device/gSensor/gSensor_manage.c.o (symbol from plugin) (delay) +cpu/br28/liba/cpu.a(p33.o) objs/apps/main.c.o (symbol from plugin) (iovdd2_bypass_iovdd) +cpu/br28/liba/cpu.a(startup.o) + (_start) +cpu/br28/liba/cpu.a(deepsleep.o) + pvdd_protect.o (symbol from plugin) (deepsleep_r) +cpu/br28/liba/cpu.a(lp_ctmu.o) + power_analog.o (symbol from plugin) (lpctmu_softoff_enter) +cpu/br28/liba/cpu.a(lp_ctmu_alog_v2.o) + lp_ctmu.o (symbol from plugin) (ctmu_res_algorithm_init) +cpu/br28/liba/cpu.a(wdt.o) lp_ipc.o (symbol from plugin) (wdt_clear) +cpu/br28/liba/vad_algo.a(dvad_api.o) + objs/cpu/br28/vad_develop.c.o (symbol from plugin) (jl_dvad_open) +cpu/br28/liba/vad_algo.a(dvad_algo.o) + dvad_api.o (symbol from plugin) (dvad_Run) +cpu/br28/liba/cbuf.a(circular_buf.o) + objs/apps/common/device/gSensor/gSensor_manage.c.o (symbol from plugin) (cbuf_read) +cpu/br28/liba/algo_gsensor.a(p11_algo_gsensor.c.o) + objs/apps/common/device/gSensor/gSensor_algo.c.o (symbol from plugin) (algo_gsensor_init) +C:/JL/pi32/q32s-lib/libm.a(lib_a-w_sqrt.o) + p11_algo_gsensor.c.o (symbol from plugin) (sqrt) +C:/JL/pi32/q32s-lib/libm.a(lib_a-e_sqrt.o) + C:/JL/pi32/q32s-lib/libm.a(lib_a-w_sqrt.o) (__ieee754_sqrt) +C:/JL/pi32/q32s-lib/libc.a(lib_a-abs.o) + p11_algo_gsensor.c.o (symbol from plugin) (abs) +C:/JL/pi32/q32s-lib/libc.a(lib_a-memcmp.o) + objs/apps/common/device/gSensor/gSensor_manage.c.o (symbol from plugin) (memcmp) +C:/JL/pi32/q32s-lib/libc.a(lib_a-memcpy.o) + objs/apps/common/device/gSensor/gSensor_manage.c.o (symbol from plugin) (memcpy) +C:/JL/pi32/q32s-lib/libc.a(lib_a-memset.o) + objs/cpu/br28/spi.c.o (symbol from plugin) (memset) +C:/JL/pi32/q32s-lib/libc.a(lib_a-strlen.o) + objs/apps/common/device/gSensor/gSensor_manage.c.o (symbol from plugin) (strlen) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(adddf3.o) + C:/JL/pi32/q32s-lib/libm.a(lib_a-e_sqrt.o) (__adddf3) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(ashldi3.o) + C:/JL/pi32/q32s-lib/libcompiler-rt.a(adddf3.o) (__ashldi3) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(divdf3.o) + C:/JL/pi32/q32s-lib/libm.a(lib_a-e_sqrt.o) (__divdf3) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(lshrdi3.o) + C:/JL/pi32/q32s-lib/libcompiler-rt.a(adddf3.o) (__lshrdi3) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(muldf3.o) + C:/JL/pi32/q32s-lib/libm.a(lib_a-e_sqrt.o) (__muldf3) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(muldi3.o) + C:/JL/pi32/q32s-lib/libcompiler-rt.a(divdf3.o) (__muldi3) +C:/JL/pi32/q32s-lib/libcompiler-rt.a(subdf3.o) + C:/JL/pi32/q32s-lib/libm.a(lib_a-e_sqrt.o) (__subdf3) + +Allocating common symbols +Common symbol size file + +amp_x 0x0 p11_algo_gsensor.c.o (symbol from plugin) +sensor_model 0x0 objs/apps/common/device/gSensor/mir3da.c.o (symbol from plugin) +dvdd_lel 0x0 power_analog.o (symbol from plugin) +m2p_cmd 0x0 power_analog.o (symbol from plugin) +p2m_clk_backups 0x0 power_analog.o (symbol from plugin) +lp_sta 0x0 power_analog.o (symbol from plugin) +still_cnt 0x0 p11_algo_gsensor.c.o (symbol from plugin) +p33_wkup_msys 0x0 power_analog.o (symbol from plugin) +wdt_backup 0x0 power_analog.o (symbol from plugin) +amp_y 0x0 p11_algo_gsensor.c.o (symbol from plugin) +pvdd_lel 0x0 power_analog.o (symbol from plugin) +th_iir 0x0 lp_ctmu.o (symbol from plugin) +pmu_det_backup 0x0 power_analog.o (symbol from plugin) +wk_bak 0x0 power_analog.o (symbol from plugin) +wvio_sel_bak 0x0 power_analog.o (symbol from plugin) +amp_z 0x0 p11_algo_gsensor.c.o (symbol from plugin) +rvdd_lel 0x0 power_analog.o (symbol from plugin) +wkup_buf 0x0 charge.o (symbol from plugin) +amp_total 0x0 p11_algo_gsensor.c.o (symbol from plugin) +key_state 0x0 lp_ctmu.o (symbol from plugin) +get_lp_time_cnt 0x0 objs/apps/timer.c.o (symbol from plugin) + +Discarded input sections + + .text 0x00000000 0x0 objs/apps/common/device/bmp280/bmp280.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/SC7A20.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/gSensor_algo.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/gSensor_manage.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/mir3da.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/msa310.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/msa310_function.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/msa31x.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/gSensor/stk832x.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/hrSensor_manage.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/hrs3603.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/hx3602/hrs3602.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/common/sport/sensor_api.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/debug.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/lib_config.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/main.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/msg.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/apps/timer.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/common.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/iic.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/iic_soft.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/spi.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/test.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/uart.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/vad_api.c.o (symbol from plugin) + .text 0x00000000 0x0 objs/cpu/br28/vad_develop.c.o (symbol from plugin) + .text 0x00000000 0x0 hwi.o (symbol from plugin) + .text 0x00000000 0x0 debug.o (symbol from plugin) + .text 0x00000000 0x0 gpio.o (symbol from plugin) + .text 0x00000000 0x0 usr_timer.o (symbol from plugin) + .text 0x00000000 0x0 power_driver.o (symbol from plugin) + .text 0x00000000 0x0 power_manage.o (symbol from plugin) + .text 0x00000000 0x0 power_wakeup.o (symbol from plugin) + .text 0x00000000 0x0 lp_ipc.o (symbol from plugin) + .text 0x00000000 0x0 charge.o (symbol from plugin) + .text 0x00000000 0x0 power_analog.o (symbol from plugin) + .text 0x00000000 0x0 pvdd_protect.o (symbol from plugin) + .text 0x00000000 0x0 p33.o (symbol from plugin) + .text 0x00000000 0x0 lp_ctmu.o (symbol from plugin) + .text 0x00000000 0x0 lp_ctmu_alog_v2.o (symbol from plugin) + .text 0x00000000 0x0 wdt.o (symbol from plugin) + .text 0x00000000 0x0 dvad_api.o (symbol from plugin) + .text 0x00000000 0x0 dvad_algo.o (symbol from plugin) + .text 0x00000000 0x0 circular_buf.o (symbol from plugin) + .text 0x00000000 0x0 p11_algo_gsensor.c.o (symbol from plugin) + +Memory Configuration + +Name Origin Length Attributes +p11_ram 0x00000080 0x00007ea0 xrw +p11_poweroff_ram 0x00007fe0 0x00000020 rw +p11_message_ram 0x00007f40 0x000000a0 rw +p11_vad_ram 0x00007f20 0x00000000 rw +*default* 0x00000000 0xffffffff + +Linker script and memory map + +LOAD objs/apps/common/device/bmp280/bmp280.c.o +LOAD cpu/br28/post_build/p11.elf.o +LOAD objs/apps/common/device/gSensor/SC7A20.c.o +LOAD objs/apps/common/device/gSensor/gSensor_algo.c.o +LOAD objs/apps/common/device/gSensor/gSensor_manage.c.o +LOAD objs/apps/common/device/gSensor/mir3da.c.o +LOAD objs/apps/common/device/gSensor/msa310.c.o +LOAD objs/apps/common/device/gSensor/msa310_function.c.o +LOAD objs/apps/common/device/gSensor/msa31x.c.o +LOAD objs/apps/common/device/gSensor/stk832x.c.o +LOAD objs/apps/common/device/hr_sensor/hrSensor_manage.c.o +LOAD objs/apps/common/device/hr_sensor/hrs3603.c.o +LOAD objs/apps/common/device/hr_sensor/hx3602/hrs3602.c.o +LOAD objs/apps/common/device/hr_sensor/hx3602/hrs3602_hrs_driv.c.o +LOAD objs/apps/common/device/hr_sensor/hx3602/hx3602_factory_test.c.o +LOAD objs/apps/common/device/hr_sensor/vc11s/module_heart_vc_int_10.c.o +LOAD objs/apps/common/device/hr_sensor/vc11s/vcHr11DEBUG.c.o +LOAD objs/apps/common/device/hr_sensor/vc11s/vcHr11Hci.c.o +LOAD objs/apps/common/device/hr_sensor/vchr02/module_heart_vc_int.c.o +LOAD objs/apps/common/device/hr_sensor/vchr02/vcHr02Hci.c.o +LOAD objs/apps/common/sport/sensor_api.c.o +LOAD objs/apps/debug.c.o +LOAD objs/apps/lib_config.c.o +LOAD objs/apps/main.c.o +LOAD objs/apps/msg.c.o +LOAD objs/apps/timer.c.o +LOAD objs/cpu/br28/common.c.o +LOAD objs/cpu/br28/iic.c.o +LOAD objs/cpu/br28/iic_soft.c.o +LOAD objs/cpu/br28/spi.c.o +LOAD objs/cpu/br28/test.c.o +LOAD objs/cpu/br28/uart.c.o +LOAD objs/cpu/br28/vad_api.c.o +LOAD objs/cpu/br28/vad_develop.c.o +START GROUP +LOAD cpu/br28/liba/cpu.a +LOAD cpu/br28/liba/printf.a +LOAD cpu/br28/liba/vad_algo.a +LOAD cpu/br28/liba/cbuf.a +LOAD cpu/br28/liba/lbuf.a +LOAD cpu/br28/liba/lbuf.a +LOAD cpu/br28/liba/bank_switch.a +LOAD cpu/br28/liba/algo_gsensor.a +END GROUP + 0x00008000 idle = 0x8000 + 0x0000800a standby = 0x800a + 0x0000801a sleep = 0x801a + 0x0000802a deep_sleep = 0x802a + 0x00000000 ISR_BASE = 0x0 + 0x00000080 P11_CODE_BEGIN = 0x80 + 0x00008000 P11_RAM_LIMIT_H = 0x8000 + 0x00000080 P11_RAM_LIMIT_L = 0x80 + 0x00007f80 P11_RAM_SIZE = (P11_RAM_LIMIT_H - P11_RAM_LIMIT_L) + 0x00008000 P11_RAM_END = P11_RAM_LIMIT_H + 0x00000020 P11_POWEROFF_RAM_SIZE = 0x20 + 0x00007fe0 P11_POWEROFF_RAM_BEGIN = (P11_RAM_END - P11_POWEROFF_RAM_SIZE) + 0x00000040 P2M_MESSAGE_SIZE = 0x40 + 0x00000060 M2P_MESSAGE_SIZE = 0x60 + 0x000000a0 P11_MESSAGE_SIZE = (M2P_MESSAGE_SIZE + P2M_MESSAGE_SIZE) + 0x00007f40 P11_MESSAGE_BEGIN = (P11_POWEROFF_RAM_BEGIN - P11_MESSAGE_SIZE) + 0x00000000 P11_VAD_RAM_SIZE = 0x0 + 0x00007f20 P11_VAD_RAM_BEGIN = ((P11_MESSAGE_BEGIN - P11_VAD_RAM_SIZE) - 0x20) + 0x00000080 P11_RAM_CODE_BEGIN = P11_CODE_BEGIN + 0x00007f20 P11_RAM_CODE_END = P11_VAD_RAM_BEGIN + 0x00007ea0 P11_RAM_CODE_SIZE = (P11_RAM_CODE_END - P11_RAM_CODE_BEGIN) + 0x00000080 . = ORIGIN (p11_ram) + +.text 0x00000080 0x22b4 + *startup.o(.text) + .text 0x00000080 0x58 cpu/br28/liba/cpu.a(startup.o) + 0x00000080 _start + 0x000000c6 exception_irq_handler + *(.ram0.data.bss) + .ram0.data.bss + 0x000000d8 0x20 cpu/br28/liba/cpu.a(deepsleep.o) + 0x000000f8 deepsleep_stack + *(.ram0.data) + .ram0.data 0x000000f8 0x3 cpu/br28/post_build/p11.elf.o + *(.ram0.text.const) + *(.ram0.text) + *fill* 0x000000fb 0x1 + .ram0.text 0x000000fc 0xe8 cpu/br28/post_build/p11.elf.o + 0x00000156 pvdd_protect + 0x00000174 pvdd_protect_release + 0x000001ae ram0_enter_sleep + 0x000001c6 ram0_exit_sleep + .ram0.text 0x000001e4 0x30 cpu/br28/liba/cpu.a(deepsleep.o) + 0x000001e4 deepsleep_r + *(.*.text) + *(.*.const) + 0x00000214 . = ALIGN (0x4) + 0x00000214 gsensor_dev_begin = . + *(.gsensor_dev) + .gsensor_dev 0x00000214 0x40 cpu/br28/post_build/p11.elf.o + 0x00000254 gsensor_dev_end = . + 0x00000254 . = ALIGN (0x4) + 0x00000254 hrsensor_dev_begin = . + *(.hrsensor_dev) + 0x00000254 hrsensor_dev_end = . + *(.rodata*) + 0x00000254 . = ALIGN (0x4) + 0x00000254 PROVIDE (low_power_target_begin, .) + *(.lp_target.2.ops) + *(.lp_target.1.ops) + *(.lp_target.0.ops) + 0x00000254 PROVIDE (low_power_target_end, .) + 0x00000254 . = ALIGN (0x4) + 0x00000254 loop_detect_handler_begin = . + *(.loop_detect_region) + 0x00000254 loop_detect_handler_end = . + 0x00000254 . = ALIGN (0x4) + *(.*.data) + 0x00000254 . = ALIGN (0x4) + *(.data*) + .data 0x00000254 0xc cpu/br28/post_build/p11.elf.o + 0x00000260 . = ALIGN (0x4) + .text 0x00000260 0x1472 cpu/br28/post_build/p11.elf.o + 0x00000908 main + 0x00000928 exception_analyze + .text 0x000016d2 0x0 cpu/br28/liba/cpu.a(deepsleep.o) + .text 0x000016d2 0x4 C:/JL/pi32/q32s-lib/libm.a(lib_a-w_sqrt.o) + 0x000016d2 sqrt + .text 0x000016d6 0x14c C:/JL/pi32/q32s-lib/libm.a(lib_a-e_sqrt.o) + 0x000016d6 __ieee754_sqrt + .text 0x00001822 0x8 C:/JL/pi32/q32s-lib/libc.a(lib_a-abs.o) + 0x00001822 abs + .text 0x0000182a 0x3c C:/JL/pi32/q32s-lib/libc.a(lib_a-memcmp.o) + 0x0000182a memcmp + .text 0x00001866 0x106 C:/JL/pi32/q32s-lib/libc.a(lib_a-memcpy.o) + 0x00001866 memcpy + 0x00001866 memmove + .text 0x0000196c 0x56 C:/JL/pi32/q32s-lib/libc.a(lib_a-memset.o) + 0x0000196c memset + .text 0x000019c2 0xe C:/JL/pi32/q32s-lib/libc.a(lib_a-strlen.o) + 0x000019c2 strlen + .text 0x000019d0 0x30e C:/JL/pi32/q32s-lib/libcompiler-rt.a(adddf3.o) + 0x000019d0 __adddf3 + .text 0x00001cde 0x26 C:/JL/pi32/q32s-lib/libcompiler-rt.a(ashldi3.o) + 0x00001cde __ashldi3 + .text 0x00001d04 0x32e C:/JL/pi32/q32s-lib/libcompiler-rt.a(divdf3.o) + 0x00001d04 __divdf3 + .text 0x00002032 0x28 C:/JL/pi32/q32s-lib/libcompiler-rt.a(lshrdi3.o) + 0x00002032 __lshrdi3 + .text 0x0000205a 0x29c C:/JL/pi32/q32s-lib/libcompiler-rt.a(muldf3.o) + 0x0000205a __muldf3 + .text 0x000022f6 0x36 C:/JL/pi32/q32s-lib/libcompiler-rt.a(muldi3.o) + 0x000022f6 __muldi3 + .text 0x0000232c 0x8 C:/JL/pi32/q32s-lib/libcompiler-rt.a(subdf3.o) + 0x0000232c __subdf3 + +.data 0x00002340 0x0 + +.bss 0x00002340 0x158 + *(.bss) + .bss 0x00002340 0x158 cpu/br28/post_build/p11.elf.o + *(.*.bss) + *(COMMON) + +.stack_bss 0x000024a0 0x600 + *(.stack_magic0) + [!provide] PROVIDE (_stack_begin, .) + [!provide] PROVIDE (_sstack_begin, .) + *(.sstack) + .sstack 0x000024a0 0x600 cpu/br28/liba/cpu.a(startup.o) + 0x00002aa0 _stack + [!provide] PROVIDE (_sstack_end, .) + [!provide] PROVIDE (_ustack_begin, .) + *(.ustack) + [!provide] PROVIDE (_ustack_end, .) + 0x00002aa0 PROVIDE (_stack_end, .) + *(.stack_magic1) + 0x00002aa0 PROVIDE (overlay_demo_begin, .) + +.overlay_bank_demo_init + 0x00002aa0 0x4 load address 0x00200000 + 0x00002aa0 0x4 LONG 0xffffffff + *(.demo.code.bank.0) + 0x00002aa4 . = ALIGN (0x4) + [!provide] PROVIDE (__load_start_overlay_bank_demo_init, LOADADDR (.overlay_bank_demo_init)) + [!provide] PROVIDE (__load_stop_overlay_bank_demo_init, (LOADADDR (.overlay_bank_demo_init) + SIZEOF (.overlay_bank_demo_init))) + +.overlay_bank_demo_normal0 + 0x00002aa0 0x4 load address 0x00200004 + 0x00002aa0 0x4 LONG 0xffffffff + *(.demo.code.bank.1) + [!provide] PROVIDE (__load_start_overlay_bank_demo_normal0, LOADADDR (.overlay_bank_demo_normal0)) + [!provide] PROVIDE (__load_stop_overlay_bank_demo_normal0, (LOADADDR (.overlay_bank_demo_normal0) + SIZEOF (.overlay_bank_demo_normal0))) + +.overlay_bank_demo_normal1 + 0x00002aa0 0x4 load address 0x00200008 + 0x00002aa0 0x4 LONG 0xffffffff + *(.demo.code.bank.2) + [!provide] PROVIDE (__load_start_overlay_bank_demo_normal1, LOADADDR (.overlay_bank_demo_normal1)) + [!provide] PROVIDE (__load_stop_overlay_bank_demo_normal1, (LOADADDR (.overlay_bank_demo_normal1) + SIZEOF (.overlay_bank_demo_normal1))) + [!provide] PROVIDE (overlay_demo_end, .) + 0x00002aa4 PROVIDE (overlay_sensor_begin, .) + +.overlay_bank_sensor_init + 0x00002aa4 0x4 load address 0x00210000 + 0x00002aa4 0x4 LONG 0xffffffff + *(.sensor.code.bank.0) + 0x00002aa8 . = ALIGN (0x4) + [!provide] PROVIDE (__load_start_overlay_bank_sensor_init, LOADADDR (.overlay_bank_sensor_init)) + [!provide] PROVIDE (__load_stop_overlay_bank_sensor_init, (LOADADDR (.overlay_bank_sensor_init) + SIZEOF (.overlay_bank_sensor_init))) + +.overlay_bank_sensor_normal0 + 0x00002aa4 0x4 load address 0x00210004 + 0x00002aa4 0x4 LONG 0xffffffff + *(.sensor.code.bank.1) + [!provide] PROVIDE (__load_start_overlay_bank_sensor_normal0, LOADADDR (.overlay_bank_sensor_normal0)) + [!provide] PROVIDE (__load_stop_overlay_bank_sensor_normal0, (LOADADDR (.overlay_bank_sensor_normal0) + SIZEOF (.overlay_bank_sensor_normal0))) + +.overlay_bank_sensor_normal1 + 0x00002aa4 0x4 load address 0x00210008 + 0x00002aa4 0x4 LONG 0xffffffff + *(.sensor.code.bank.2) + [!provide] PROVIDE (__load_start_overlay_bank_sensor_normal1, LOADADDR (.overlay_bank_sensor_normal1)) + [!provide] PROVIDE (__load_stop_overlay_bank_sensor_normal1, (LOADADDR (.overlay_bank_sensor_normal1) + SIZEOF (.overlay_bank_sensor_normal1))) + [!provide] PROVIDE (overlay_sensor_end, .) + [!provide] PROVIDE (overlay_sys_begin, .) + +.overlay_bank_sys_init + 0x00002aa8 0x4 load address 0x00220000 + 0x00002aa8 0x4 LONG 0xffffffff + *(.sys.code.bank.0) + 0x00002aac . = ALIGN (0x4) + [!provide] PROVIDE (__load_start_overlay_bank_sys_init, LOADADDR (.overlay_bank_sys_init)) + [!provide] PROVIDE (__load_stop_overlay_bank_sys_init, (LOADADDR (.overlay_bank_sys_init) + SIZEOF (.overlay_bank_sys_init))) + +.overlay_bank_sys_normal0 + 0x00002aa8 0x4 load address 0x00220004 + 0x00002aa8 0x4 LONG 0xffffffff + *(.sys.code.bank.1) + [!provide] PROVIDE (__load_start_overlay_bank_sys_normal0, LOADADDR (.overlay_bank_sys_normal0)) + [!provide] PROVIDE (__load_stop_overlay_bank_sys_normal0, (LOADADDR (.overlay_bank_sys_normal0) + SIZEOF (.overlay_bank_sys_normal0))) + [!provide] PROVIDE (overlay_sys_end, .) + 0x00002aac PROVIDE (p11_heap_begin, .) + 0x00007f20 p11_heap_end = P11_RAM_CODE_END + 0x00007f40 . = ORIGIN (p11_message_ram) + +.p11_message 0x00007f40 0xa0 + *(.p2m_data) + .p2m_data 0x00007f40 0x40 cpu/br28/post_build/p11.elf.o + 0x00007f40 p2m_message + *(.m2p_data) + .m2p_data 0x00007f80 0x60 cpu/br28/post_build/p11.elf.o + 0x00007f80 m2p_message + 0x00007f20 . = ORIGIN (p11_vad_ram) + +.p11_vad 0x00007f20 0x0 + *(.m2p_dvad_config) + 0x00007f20 . = ALIGN (0x4) + *(.m2p_avad_config) + 0x00007f20 . = ALIGN (0x4) + *(.p2m_cbuf_data) + 0x00000080 text_begin = ADDR (.text) + 0x000022b4 text_size = SIZEOF (.text) + 0x00002334 text_end = (text_begin + text_size) + 0x00002340 bss_begin = ADDR (.bss) + 0x00000158 bss_size = SIZEOF (.bss) + 0x00002340 data_addr = ADDR (.data) + 0x00002334 data_begin = (text_begin + text_size) + 0x00000000 data_size = SIZEOF (.data) + 0x00007f40 p11_message_data_addr = ADDR (.p11_message) + 0x000000a0 p11_message_data_size = SIZEOF (.p11_message) + 0x00005474 p11_heap_size = (p11_heap_end - p11_heap_begin) + 0x00000001 ASSERT ((p11_heap_size >= 0xc8), p11 heap space too small !) +LOAD C:/JL/pi32/q32s-lib/libm.a +LOAD C:/JL/pi32/q32s-lib/libc.a +LOAD C:/JL/pi32/q32s-lib/libm.a +LOAD C:/JL/pi32/q32s-lib/libcompiler-rt.a +OUTPUT(cpu/br28/post_build/p11.elf elf32-q32s) + +.debug_str 0x00000000 0x3f8b + .debug_str 0x00000000 0x3f8b cpu/br28/post_build/p11.elf.o + 0x416c (size before relaxing) + +.debug_loc 0x00000000 0x71e + .debug_loc 0x00000000 0x71e cpu/br28/post_build/p11.elf.o + +.debug_abbrev 0x00000000 0x7d8 + .debug_abbrev 0x00000000 0x788 cpu/br28/post_build/p11.elf.o + .debug_abbrev 0x00000788 0x28 cpu/br28/liba/cpu.a(startup.o) + .debug_abbrev 0x000007b0 0x28 cpu/br28/liba/cpu.a(deepsleep.o) + +.debug_info 0x00000000 0x6839 + .debug_info 0x00000000 0x6617 cpu/br28/post_build/p11.elf.o + .debug_info 0x00006617 0x128 cpu/br28/liba/cpu.a(startup.o) + .debug_info 0x0000673f 0xfa cpu/br28/liba/cpu.a(deepsleep.o) + +.debug_ranges 0x00000000 0x1e0 + .debug_ranges 0x00000000 0x1e0 cpu/br28/post_build/p11.elf.o + +.debug_macinfo 0x00000000 0x1 + .debug_macinfo + 0x00000000 0x1 cpu/br28/post_build/p11.elf.o + +.debug_pubnames + 0x00000000 0x126a + .debug_pubnames + 0x00000000 0x126a cpu/br28/post_build/p11.elf.o + +.debug_pubtypes + 0x00000000 0xa06 + .debug_pubtypes + 0x00000000 0xa06 cpu/br28/post_build/p11.elf.o + +.debug_frame 0x00000000 0x588 + .debug_frame 0x00000000 0x588 cpu/br28/post_build/p11.elf.o + +.debug_line 0x00000000 0x2e9b + .debug_line 0x00000000 0x2d5f cpu/br28/post_build/p11.elf.o + .debug_line 0x00002d5f 0xa2 cpu/br28/liba/cpu.a(startup.o) + .debug_line 0x00002e01 0x9a cpu/br28/liba/cpu.a(deepsleep.o) + +.debug_aranges 0x00000000 0x40 + .debug_aranges + 0x00000000 0x20 cpu/br28/liba/cpu.a(startup.o) + .debug_aranges + 0x00000020 0x20 cpu/br28/liba/cpu.a(deepsleep.o) diff --git a/2.code/2.p11_code/cpu/br28/post_build/p11_bank_code.bin b/2.code/2.p11_code/cpu/br28/post_build/p11_bank_code.bin new file mode 100644 index 0000000..d83588b Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/p11_bank_code.bin differ diff --git a/2.code/2.p11_code/cpu/br28/post_build/symbol_tbl.txt b/2.code/2.p11_code/cpu/br28/post_build/symbol_tbl.txt new file mode 100644 index 0000000..0debbbd --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/post_build/symbol_tbl.txt @@ -0,0 +1,1825 @@ + +p11.elf: file format ELF32-q32s + +SYMBOL TABLE: +00000000 *UND* 00000000 +00000080 l d .text 00000000 .text +00002340 l d .bss 00000000 .bss +000024a0 l d .stack_bss 00000000 .stack_bss +00002aa0 l d .overlay_bank_demo_init 00000000 .overlay_bank_demo_init +00002aa0 l d .overlay_bank_demo_normal0 00000000 .overlay_bank_demo_normal0 +00002aa0 l d .overlay_bank_demo_normal1 00000000 .overlay_bank_demo_normal1 +00002aa4 l d .overlay_bank_sensor_init 00000000 .overlay_bank_sensor_init +00002aa4 l d .overlay_bank_sensor_normal0 00000000 .overlay_bank_sensor_normal0 +00002aa4 l d .overlay_bank_sensor_normal1 00000000 .overlay_bank_sensor_normal1 +00002aa8 l d .overlay_bank_sys_init 00000000 .overlay_bank_sys_init +00002aa8 l d .overlay_bank_sys_normal0 00000000 .overlay_bank_sys_normal0 +00007f40 l d .p11_message 00000000 .p11_message +00007f20 l d .p11_vad 00000000 .p11_vad +00000000 l d .debug_str 00000000 .debug_str +00000000 l d .debug_loc 00000000 .debug_loc +00000000 l d .debug_abbrev 00000000 .debug_abbrev +00000000 l d .debug_info 00000000 .debug_info +00000000 l d .debug_ranges 00000000 .debug_ranges +00000000 l d .debug_macinfo 00000000 .debug_macinfo +00000000 l d .debug_pubnames 00000000 .debug_pubnames +00000000 l d .debug_pubtypes 00000000 .debug_pubtypes +00000000 l d .debug_frame 00000000 .debug_frame +00000000 l d .debug_line 00000000 .debug_line +00000000 l d .debug_aranges 00000000 .debug_aranges +00000000 l df *ABS* 00000000 startup.o +00002d5f .debug_line 00000000 .Lline_table_start0 +000000d8 .text 00000000 .Lsec_end0 +00002aa0 .stack_bss 00000000 .Ltmp0 +00000080 .text 00000000 .Ltmp1 +000000a4 .text 00000000 .Ltmp10 +00000080 .text 00000000 .Ltmp2 +000000c6 .text 00000000 .Ltmp20 +00006617 .debug_info 00000000 .Ltmp27 +00000788 .debug_abbrev 00000000 .Ltmp28 +000000a4 .text 00000000 _user_mode +00000000 l df *ABS* 00000000 deepsleep.o +00002e01 .debug_line 00000000 .Lline_table_start0 +00000214 .text 00000000 .Lsec_end0 +000000f8 .text 00000000 .Ltmp0 +000001e4 .text 00000000 .Ltmp1 +0000673f .debug_info 00000000 .Ltmp14 +000007b0 .debug_abbrev 00000000 .Ltmp15 +000001e4 .text 00000000 .Ltmp2 +00000000 l df *ABS* 00000000 +00001a70 .debug_str 00000000 +000000fc .text 00000000 +000000fc .text 00000000 +000000fc .text 00000000 +00000106 .text 00000000 +000062a1 .debug_info 00000000 +00000260 .text 00000000 +00000260 .text 00000000 +00000260 .text 00000000 +00006267 .debug_info 00000000 +0000027c .text 00000000 +0000027c .text 00000000 +00000296 .text 00000000 +00006104 .debug_info 00000000 +000002b0 .text 00000000 +000002b0 .text 00000000 +0000602f .debug_info 00000000 +000002c6 .text 00000000 +000002c6 .text 00000000 +000002c6 .text 00000000 +000002de .text 00000000 +00005fce .debug_info 00000000 +000002de .text 00000000 +000002de .text 00000000 +000002de .text 00000000 +00005eab .debug_info 00000000 +000002e2 .text 00000000 +000002e2 .text 00000000 +000002e6 .text 00000000 +00005ac0 .debug_info 00000000 +000002f6 .text 00000000 +000002f6 .text 00000000 +000002fa .text 00000000 +00005a7b .debug_info 00000000 +000002fa .text 00000000 +000002fa .text 00000000 +000002fa .text 00000000 +00000300 .text 00000000 +000001a0 .debug_ranges 00000000 +0000030c .text 00000000 +0000030c .text 00000000 +00000310 .text 00000000 +00000316 .text 00000000 +0000031a .text 00000000 +000001b8 .debug_ranges 00000000 +0000031a .text 00000000 +0000031a .text 00000000 +00005863 .debug_info 00000000 +0000031e .text 00000000 +0000031e .text 00000000 +0000032a .text 00000000 +00000180 .debug_ranges 00000000 +00000346 .text 00000000 +00000346 .text 00000000 +0000034c .text 00000000 +000051ed .debug_info 00000000 +00000168 .debug_ranges 00000000 +0000035a .text 00000000 +0000035c .text 00000000 +00000360 .text 00000000 +00000362 .text 00000000 +00000364 .text 00000000 +00000366 .text 00000000 +0000036a .text 00000000 +0000036c .text 00000000 +00000372 .text 00000000 +0000037a .text 00000000 +00000380 .text 00000000 +000048f0 .debug_info 00000000 +00000380 .text 00000000 +00000380 .text 00000000 +00000380 .text 00000000 +0000440a .debug_info 00000000 +00000384 .text 00000000 +00000384 .text 00000000 +00004210 .debug_info 00000000 +0000038e .text 00000000 +0000038e .text 00000000 +0000410b .debug_info 00000000 +00000392 .text 00000000 +00000392 .text 00000000 +00000130 .debug_ranges 00000000 +0000039e .text 00000000 +0000039e .text 00000000 +000003ae .text 00000000 +00000118 .debug_ranges 00000000 +000003bc .text 00000000 +000003bc .text 00000000 +00000100 .debug_ranges 00000000 +000000e8 .debug_ranges 00000000 +000003d0 .text 00000000 +000003da .text 00000000 +000000d0 .debug_ranges 00000000 +000003f6 .text 00000000 +000003f6 .text 00000000 +000003f6 .text 00000000 +000003f8 .text 00000000 +000000b8 .debug_ranges 00000000 +000003fe .text 00000000 +00000400 .text 00000000 +00000404 .text 00000000 +0000040e .text 00000000 +00000412 .text 00000000 +00000418 .text 00000000 +0000041c .text 00000000 +00000420 .text 00000000 +00000422 .text 00000000 +0000042a .text 00000000 +0000042e .text 00000000 +0000043a .text 00000000 +00000148 .debug_ranges 00000000 +0000043e .text 00000000 +0000043e .text 00000000 +00000440 .text 00000000 +00000444 .text 00000000 +0000044c .text 00000000 +00000454 .text 00000000 +00000458 .text 00000000 +0000045a .text 00000000 +00000464 .text 00000000 +00000468 .text 00000000 +0000046e .text 00000000 +00000472 .text 00000000 +00000476 .text 00000000 +00000478 .text 00000000 +00003a8d .debug_info 00000000 +00000486 .text 00000000 +00000486 .text 00000000 +0000048a .text 00000000 +00000496 .text 00000000 +000004a2 .text 00000000 +000004ac .text 00000000 +000004b0 .text 00000000 +000004b2 .text 00000000 +000004c0 .text 00000000 +000004c6 .text 00000000 +000004c8 .text 00000000 +00000080 .debug_ranges 00000000 +000004c8 .text 00000000 +000004c8 .text 00000000 +000004c8 .text 00000000 +000004e0 .text 00000000 +00000098 .debug_ranges 00000000 +000004e0 .text 00000000 +000004e0 .text 00000000 +000004e0 .text 00000000 +000004e0 .text 00000000 +000004ea .text 00000000 +0000334c .debug_info 00000000 +0000050c .text 00000000 +00000512 .text 00000000 +000031a1 .debug_info 00000000 +00000512 .text 00000000 +00000512 .text 00000000 +00000516 .text 00000000 +0000051a .text 00000000 +0000051e .text 00000000 +00000526 .text 00000000 +00000068 .debug_ranges 00000000 +00000526 .text 00000000 +00000526 .text 00000000 +00000526 .text 00000000 +00000548 .text 00000000 +00002b31 .debug_info 00000000 +00000576 .text 00000000 +00000030 .debug_ranges 00000000 +00000586 .text 00000000 +00000048 .debug_ranges 00000000 +000005a2 .text 00000000 +00002230 .debug_info 00000000 +000005ea .text 00000000 +000020d7 .debug_info 00000000 +000005ea .text 00000000 +000005ea .text 00000000 +000005ea .text 00000000 +0000209e .debug_info 00000000 +000005f4 .text 00000000 +000005f4 .text 00000000 +000005f6 .text 00000000 +000005fa .text 00000000 +000005fc .text 00000000 +00002013 .debug_info 00000000 +0000060c .text 00000000 +0000060c .text 00000000 +00000610 .text 00000000 +00000612 .text 00000000 +00000626 .text 00000000 +00001e1e .debug_info 00000000 +00000626 .text 00000000 +00000626 .text 00000000 +00000628 .text 00000000 +00001d71 .debug_info 00000000 +00000642 .text 00000000 +0000064c .text 00000000 +00000652 .text 00000000 +00000658 .text 00000000 +0000065a .text 00000000 +0000065c .text 00000000 +00000662 .text 00000000 +00000664 .text 00000000 +00000666 .text 00000000 +00001c53 .debug_info 00000000 +00000666 .text 00000000 +00000666 .text 00000000 +00001ace .debug_info 00000000 +0000066e .text 00000000 +00000672 .text 00000000 +0000067e .text 00000000 +00000682 .text 00000000 +0000068a .text 00000000 +000006a0 .text 00000000 +000006a2 .text 00000000 +000014e1 .debug_info 00000000 +000006a2 .text 00000000 +000006a2 .text 00000000 +000006a6 .text 00000000 +000006b2 .text 00000000 +000006b6 .text 00000000 +000006bc .text 00000000 +000006c4 .text 00000000 +000006c8 .text 00000000 +000006cc .text 00000000 +000006cc .text 00000000 +00000e54 .debug_info 00000000 +000006cc .text 00000000 +000006cc .text 00000000 +000006cc .text 00000000 +000006f4 .text 00000000 +00000e04 .debug_info 00000000 +00000106 .text 00000000 +00000106 .text 00000000 +00000106 .text 00000000 +00000b1f .debug_info 00000000 +000008d2 .debug_info 00000000 +00000124 .text 00000000 +00000018 .debug_ranges 00000000 +000006f4 .text 00000000 +000006f4 .text 00000000 +000006f8 .text 00000000 +0000070e .text 00000000 +00000710 .text 00000000 +00000712 .text 00000000 +00000554 .debug_info 00000000 +0000071a .text 00000000 +00000720 .text 00000000 +00000726 .text 00000000 +0000072a .text 00000000 +0000073a .text 00000000 +00000740 .text 00000000 +00000742 .text 00000000 +00000000 .debug_ranges 00000000 +0000074a .text 00000000 +00000774 .text 00000000 +00000778 .text 00000000 +00000780 .text 00000000 +00000784 .text 00000000 +00000788 .text 00000000 +0000078e .text 00000000 +00000796 .text 00000000 +00000798 .text 00000000 +000007a2 .text 00000000 +000007a6 .text 00000000 +000007ac .text 00000000 +000007ae .text 00000000 +000007b2 .text 00000000 +000007be .text 00000000 +000007c2 .text 00000000 +000007c6 .text 00000000 +000007ca .text 00000000 +000007cc .text 00000000 +000007ce .text 00000000 +000007d2 .text 00000000 +000007dc .text 00000000 +000007e0 .text 00000000 +000007f0 .text 00000000 +000007f4 .text 00000000 +00000802 .text 00000000 +00000808 .text 00000000 +0000080a .text 00000000 +00000810 .text 00000000 +00000816 .text 00000000 +0000081a .text 00000000 +0000081e .text 00000000 +00000824 .text 00000000 +00000834 .text 00000000 +00000838 .text 00000000 +0000083a .text 00000000 +0000083e .text 00000000 +00000840 .text 00000000 +0000084a .text 00000000 +0000084e .text 00000000 +00000850 .text 00000000 +0000085c .text 00000000 +00000884 .text 00000000 +000008c2 .text 00000000 +000008f2 .text 00000000 +000008f6 .text 00000000 +00000904 .text 00000000 +00000908 .text 00000000 +00000908 .text 00000000 +00000908 .text 00000000 +00000908 .text 00000000 +00000924 .text 00000000 +00000928 .text 00000000 +00000928 .text 00000000 +0000092a .text 00000000 +0000092a .text 00000000 +0000092a .text 00000000 +0000093c .text 00000000 +00000962 .text 00000000 +00000976 .text 00000000 +0000097e .text 00000000 +0000098a .text 00000000 +00000990 .text 00000000 +00000992 .text 00000000 +00000996 .text 00000000 +0000099a .text 00000000 +0000099e .text 00000000 +000009a2 .text 00000000 +000009a6 .text 00000000 +000009c8 .text 00000000 +000009ca .text 00000000 +000009cc .text 00000000 +000009ce .text 00000000 +000009d6 .text 00000000 +000009dc .text 00000000 +000009e2 .text 00000000 +000009ec .text 00000000 +00000244 .debug_info 00000000 +000009ec .text 00000000 +000009ec .text 00000000 +000009ec .text 00000000 +00000b66 .text 00000000 +0000003c .debug_info 00000000 +00000124 .text 00000000 +00000124 .text 00000000 +00000146 .text 00000000 +00000156 .text 00000000 +000006fc .debug_loc 00000000 +00000b66 .text 00000000 +00000b66 .text 00000000 +000006e9 .debug_loc 00000000 +00000bfa .text 00000000 +00000bfa .text 00000000 +000006d6 .debug_loc 00000000 +00000c48 .text 00000000 +00000c48 .text 00000000 +00000c60 .text 00000000 +00000c80 .text 00000000 +000006c3 .debug_loc 00000000 +00000cc2 .text 00000000 +00000cc2 .text 00000000 +000006b0 .debug_loc 00000000 +0000069d .debug_loc 00000000 +00000d10 .text 00000000 +00000d32 .text 00000000 +00000d5e .text 00000000 +00000dbe .text 00000000 +00000e34 .text 00000000 +00000e34 .text 00000000 +00000e34 .text 00000000 +00000e66 .text 00000000 +00000e66 .text 00000000 +00000e66 .text 00000000 +00000e66 .text 00000000 +00000e72 .text 00000000 +00000f88 .text 00000000 +0000068a .debug_loc 00000000 +00000f9c .text 00000000 +00000f9c .text 00000000 +00000668 .debug_loc 00000000 +0000107c .text 00000000 +0000107c .text 00000000 +000010fa .text 00000000 +000011a8 .text 00000000 +000011f4 .text 00000000 +00000655 .debug_loc 00000000 +000011f4 .text 00000000 +000011f4 .text 00000000 +000011f4 .text 00000000 +00001204 .text 00000000 +00001204 .text 00000000 +00001204 .text 00000000 +00001248 .text 00000000 +00001258 .text 00000000 +000012a2 .text 00000000 +00001308 .text 00000000 +00001318 .text 00000000 +0000139c .text 00000000 +000013ac .text 00000000 +00001438 .text 00000000 +0000148e .text 00000000 +00001528 .text 00000000 +00001530 .text 00000000 +00000642 .debug_loc 00000000 +0000062f .debug_loc 00000000 +00001546 .text 00000000 +0000154a .text 00000000 +00001560 .text 00000000 +0000156c .text 00000000 +000015aa .text 00000000 +000015da .text 00000000 +000015da .text 00000000 +000015e0 .text 00000000 +00001626 .text 00000000 +00001626 .text 00000000 +00001630 .text 00000000 +00001634 .text 00000000 +00001644 .text 00000000 +00001656 .text 00000000 +0000166c .text 00000000 +00001678 .text 00000000 +0000168a .text 00000000 +00001698 .text 00000000 +000016d2 .text 00000000 +00000156 .text 00000000 +00000156 .text 00000000 +0000061c .debug_loc 00000000 +00000174 .text 00000000 +00000174 .text 00000000 +00000182 .text 00000000 +0000018a .text 00000000 +0000019c .text 00000000 +000001ac .text 00000000 +000001ae .text 00000000 +000001ae .text 00000000 +000001b8 .text 00000000 +000001be .text 00000000 +000001c6 .text 00000000 +000001c6 .text 00000000 +000001d2 .text 00000000 +000001da .text 00000000 +000001e4 .text 00000000 +000005fe .debug_loc 00000000 +000005eb .debug_loc 00000000 +00000000 .debug_str 00000000 +00000015 .debug_str 00000000 +00000038 .debug_str 00000000 +00000070 .debug_str 00000000 +00000094 .debug_str 00000000 +000000be .debug_str 00000000 +000000cd .debug_str 00000000 +000000db .debug_str 00000000 +000000de .debug_str 00000000 +000000f0 .debug_str 00000000 +00000104 .debug_str 00000000 +00000117 .debug_str 00000000 +0000012f .debug_str 00000000 +00000149 .debug_str 00000000 +00000156 .debug_str 00000000 +00000164 .debug_str 00000000 +00000174 .debug_str 00000000 +00000186 .debug_str 00000000 +00000193 .debug_str 00000000 +000001a0 .debug_str 00000000 +000001b1 .debug_str 00000000 +000001be .debug_str 00000000 +000001ce .debug_str 00000000 +000001e2 .debug_str 00000000 +000001f8 .debug_str 00000000 +00000210 .debug_str 00000000 +00000226 .debug_str 00000000 +0000023b .debug_str 00000000 +00000252 .debug_str 00000000 +00000268 .debug_str 00000000 +0000027b .debug_str 00000000 +0000028d .debug_str 00000000 +000002a4 .debug_str 00000000 +000002bc .debug_str 00000000 +000002d2 .debug_str 00000000 +000002e5 .debug_str 00000000 +000002f8 .debug_str 00000000 +00000313 .debug_str 00000000 +00000331 .debug_str 00000000 +00000344 .debug_str 00000000 +00000351 .debug_str 00000000 +0000035f .debug_str 00000000 +0000221d .debug_str 00000000 +0000036a .debug_str 00000000 +00000376 .debug_str 00000000 +00000382 .debug_str 00000000 +0000038e .debug_str 00000000 +0000039b .debug_str 00000000 +000003a6 .debug_str 00000000 +000003b2 .debug_str 00000000 +000003be .debug_str 00000000 +000003ca .debug_str 00000000 +000003d7 .debug_str 00000000 +000003e4 .debug_str 00000000 +000003f0 .debug_str 00000000 +0000352d .debug_str 00000000 +000005c3 .debug_str 00000000 +00003533 .debug_str 00000000 +00003539 .debug_str 00000000 +00000403 .debug_str 00000000 +0000040e .debug_str 00000000 +0000043a .debug_str 00000000 +00000446 .debug_str 00000000 +0000044b .debug_str 00000000 +00000454 .debug_str 00000000 +00000468 .debug_str 00000000 +000000d6 .debug_str 00000000 +0000047d .debug_str 00000000 +00002226 .debug_str 00000000 +00000490 .debug_str 00000000 +000004a3 .debug_str 00000000 +000004b2 .debug_str 00000000 +000004ba .debug_str 00000000 +000004c4 .debug_str 00000000 +000004cd .debug_str 00000000 +000004d7 .debug_str 00000000 +000004e1 .debug_str 00000000 +000004f1 .debug_str 00000000 +000004ff .debug_str 00000000 +00000537 .debug_str 00000000 +0000050b .debug_str 00000000 +0000050f .debug_str 00000000 +0000051c .debug_str 00000000 +0000052b .debug_str 00000000 +0000052f .debug_str 00000000 +00000545 .debug_str 00000000 +00000551 .debug_str 00000000 +00000557 .debug_str 00000000 +0000055b .debug_str 00000000 +00000564 .debug_str 00000000 +0000056e .debug_str 00000000 +00000576 .debug_str 00000000 +0000057e .debug_str 00000000 +00000587 .debug_str 00000000 +00000591 .debug_str 00000000 +0000059a .debug_str 00000000 +000005a4 .debug_str 00000000 +000005ad .debug_str 00000000 +000005ba .debug_str 00000000 +000005c9 .debug_str 00000000 +000005cd .debug_str 00000000 +000005dd .debug_str 00000000 +000005ef .debug_str 00000000 +00000602 .debug_str 00000000 +00000612 .debug_str 00000000 +00000624 .debug_str 00000000 +00000633 .debug_str 00000000 +00000641 .debug_str 00000000 +00000665 .debug_str 00000000 +0000066d .debug_str 00000000 +0000067a .debug_str 00000000 +00000685 .debug_str 00000000 +00000690 .debug_str 00000000 +00000699 .debug_str 00000000 +0000069d .debug_str 00000000 +000006a9 .debug_str 00000000 +000006cd .debug_str 00000000 +000006fa .debug_str 00000000 +0000071e .debug_str 00000000 +00003c75 .debug_str 00000000 +00000743 .debug_str 00000000 +00000772 .debug_str 00000000 +0000077f .debug_str 00000000 +00000796 .debug_str 00000000 +000007ae .debug_str 00000000 +000007c4 .debug_str 00000000 +000007d5 .debug_str 00000000 +000007e9 .debug_str 00000000 +000007f9 .debug_str 00000000 +00000808 .debug_str 00000000 +00000816 .debug_str 00000000 +00000826 .debug_str 00000000 +0000083d .debug_str 00000000 +00000864 .debug_str 00000000 +00000892 .debug_str 00000000 +000008c9 .debug_str 00000000 +00000903 .debug_str 00000000 +0000093f .debug_str 00000000 +00000970 .debug_str 00000000 +0000099f .debug_str 00000000 +000009d9 .debug_str 00000000 +00000a09 .debug_str 00000000 +00000a28 .debug_str 00000000 +00000a35 .debug_str 00000000 +00000a47 .debug_str 00000000 +00000a5d .debug_str 00000000 +00000a76 .debug_str 00000000 +00000a98 .debug_str 00000000 +00000ab3 .debug_str 00000000 +00000abf .debug_str 00000000 +00000517 .debug_str 00000000 +00000acf .debug_str 00000000 +00000ada .debug_str 00000000 +00000ae3 .debug_str 00000000 +00000aed .debug_str 00000000 +00000aff .debug_str 00000000 +00000b06 .debug_str 00000000 +00000b13 .debug_str 00000000 +00000b23 .debug_str 00000000 +00000b31 .debug_str 00000000 +00000b47 .debug_str 00000000 +00000b5a .debug_str 00000000 +00000b5f .debug_str 00000000 +00000b64 .debug_str 00000000 +00000b69 .debug_str 00000000 +00000b6e .debug_str 00000000 +00000b73 .debug_str 00000000 +00000b78 .debug_str 00000000 +00000b7d .debug_str 00000000 +00000b82 .debug_str 00000000 +00000b87 .debug_str 00000000 +00000b8c .debug_str 00000000 +00000b91 .debug_str 00000000 +00000b96 .debug_str 00000000 +00000b9b .debug_str 00000000 +00000ba0 .debug_str 00000000 +00000ba5 .debug_str 00000000 +00000baa .debug_str 00000000 +00000baf .debug_str 00000000 +00000bb4 .debug_str 00000000 +00000bb9 .debug_str 00000000 +00000bbe .debug_str 00000000 +00000bc3 .debug_str 00000000 +00000bc7 .debug_str 00000000 +00000bcc .debug_str 00000000 +00000bd1 .debug_str 00000000 +00000bd6 .debug_str 00000000 +00000bdb .debug_str 00000000 +00000be0 .debug_str 00000000 +00000be5 .debug_str 00000000 +00000be9 .debug_str 00000000 +00000bf9 .debug_str 00000000 +00000bed .debug_str 00000000 +00000bf2 .debug_str 00000000 +00000bf8 .debug_str 00000000 +00000bfc .debug_str 00000000 +00000c00 .debug_str 00000000 +00000c04 .debug_str 00000000 +00000c08 .debug_str 00000000 +00000c0c .debug_str 00000000 +00000c16 .debug_str 00000000 +00000c20 .debug_str 00000000 +00000c28 .debug_str 00000000 +00000c32 .debug_str 00000000 +00000c3b .debug_str 00000000 +00000c44 .debug_str 00000000 +00000c4d .debug_str 00000000 +00000c56 .debug_str 00000000 +00000c5f .debug_str 00000000 +00000c66 .debug_str 00000000 +00000c6d .debug_str 00000000 +00000c74 .debug_str 00000000 +00000c7b .debug_str 00000000 +00000c82 .debug_str 00000000 +00000c89 .debug_str 00000000 +00000c90 .debug_str 00000000 +00000c97 .debug_str 00000000 +00000c9e .debug_str 00000000 +00000ca5 .debug_str 00000000 +00000cac .debug_str 00000000 +00000cb3 .debug_str 00000000 +00000cba .debug_str 00000000 +00000cc1 .debug_str 00000000 +00000cc8 .debug_str 00000000 +00000ccf .debug_str 00000000 +00000cd6 .debug_str 00000000 +00000cdd .debug_str 00000000 +00000ce4 .debug_str 00000000 +00000ceb .debug_str 00000000 +00000cf2 .debug_str 00000000 +00000cf9 .debug_str 00000000 +00000d00 .debug_str 00000000 +00000d07 .debug_str 00000000 +00000d0e .debug_str 00000000 +00000d15 .debug_str 00000000 +00000d1c .debug_str 00000000 +00000d23 .debug_str 00000000 +00000d2a .debug_str 00000000 +00000d31 .debug_str 00000000 +00000d38 .debug_str 00000000 +00000d3f .debug_str 00000000 +00000d45 .debug_str 00000000 +00000d4b .debug_str 00000000 +00000d51 .debug_str 00000000 +00000d57 .debug_str 00000000 +00000d5d .debug_str 00000000 +00000d63 .debug_str 00000000 +00000d69 .debug_str 00000000 +00000d6f .debug_str 00000000 +00000d78 .debug_str 00000000 +00000d81 .debug_str 00000000 +00000d88 .debug_str 00000000 +00000d90 .debug_str 00000000 +00000d9a .debug_str 00000000 +00000da4 .debug_str 00000000 +00000dac .debug_str 00000000 +00000db4 .debug_str 00000000 +00000dbc .debug_str 00000000 +00000dc4 .debug_str 00000000 +00000dcc .debug_str 00000000 +00000dd5 .debug_str 00000000 +00000dde .debug_str 00000000 +00000de7 .debug_str 00000000 +00000df0 .debug_str 00000000 +00000df7 .debug_str 00000000 +00000e01 .debug_str 00000000 +00000e09 .debug_str 00000000 +00000e11 .debug_str 00000000 +00000e1b .debug_str 00000000 +00000e25 .debug_str 00000000 +00000e2f .debug_str 00000000 +00000e39 .debug_str 00000000 +00000e4d .debug_str 00000000 +00000e58 .debug_str 00000000 +00000e61 .debug_str 00000000 +00000e6a .debug_str 00000000 +00000e73 .debug_str 00000000 +00000e88 .debug_str 00000000 +00000e9e .debug_str 00000000 +00000eb4 .debug_str 00000000 +00000ec9 .debug_str 00000000 +00000edd .debug_str 00000000 +00000ef7 .debug_str 00000000 +00000f0e .debug_str 00000000 +00000f25 .debug_str 00000000 +00000f3c .debug_str 00000000 +00000f51 .debug_str 00000000 +00000f6b .debug_str 00000000 +00000f85 .debug_str 00000000 +00000f99 .debug_str 00000000 +00000fad .debug_str 00000000 +00000fc8 .debug_str 00000000 +00000fe1 .debug_str 00000000 +00000ffb .debug_str 00000000 +00001019 .debug_str 00000000 +00001034 .debug_str 00000000 +0000104f .debug_str 00000000 +0000106a .debug_str 00000000 +00001085 .debug_str 00000000 +000010a0 .debug_str 00000000 +000010bb .debug_str 00000000 +000010d6 .debug_str 00000000 +000010f1 .debug_str 00000000 +0000110c .debug_str 00000000 +00001127 .debug_str 00000000 +0000114b .debug_str 00000000 +0000116f .debug_str 00000000 +00001194 .debug_str 00000000 +000011b9 .debug_str 00000000 +000011de .debug_str 00000000 +00001203 .debug_str 00000000 +0000121b .debug_str 00000000 +00001233 .debug_str 00000000 +00001248 .debug_str 00000000 +00001256 .debug_str 00000000 +00001268 .debug_str 00000000 +0000127a .debug_str 00000000 +0000128c .debug_str 00000000 +0000129b .debug_str 00000000 +000012aa .debug_str 00000000 +000012b9 .debug_str 00000000 +000012c8 .debug_str 00000000 +000012d5 .debug_str 00000000 +000012e2 .debug_str 00000000 +000012f0 .debug_str 00000000 +000012fd .debug_str 00000000 +0000130b .debug_str 00000000 +00001319 .debug_str 00000000 +00001328 .debug_str 00000000 +00001337 .debug_str 00000000 +0000134c .debug_str 00000000 +0000135a .debug_str 00000000 +00001369 .debug_str 00000000 +00001378 .debug_str 00000000 +00001388 .debug_str 00000000 +00001394 .debug_str 00000000 +000013a5 .debug_str 00000000 +000013b6 .debug_str 00000000 +000013c8 .debug_str 00000000 +000013da .debug_str 00000000 +000013e9 .debug_str 00000000 +000013f6 .debug_str 00000000 +00001405 .debug_str 00000000 +00001419 .debug_str 00000000 +00001433 .debug_str 00000000 +00001447 .debug_str 00000000 +00001455 .debug_str 00000000 +00001465 .debug_str 00000000 +00001474 .debug_str 00000000 +00001482 .debug_str 00000000 +0000148f .debug_str 00000000 +0000149c .debug_str 00000000 +000014b6 .debug_str 00000000 +000014c3 .debug_str 00000000 +000014d0 .debug_str 00000000 +000014dd .debug_str 00000000 +000014f6 .debug_str 00000000 +0000150b .debug_str 00000000 +00001520 .debug_str 00000000 +0000152e .debug_str 00000000 +0000153c .debug_str 00000000 +0000154f .debug_str 00000000 +00001561 .debug_str 00000000 +00001571 .debug_str 00000000 +00001587 .debug_str 00000000 +0000159a .debug_str 00000000 +000015ad .debug_str 00000000 +000015ca .debug_str 00000000 +000015e7 .debug_str 00000000 +00001604 .debug_str 00000000 +00001621 .debug_str 00000000 +00001646 .debug_str 00000000 +0000166b .debug_str 00000000 +00001692 .debug_str 00000000 +000016b9 .debug_str 00000000 +000016d0 .debug_str 00000000 +000016e7 .debug_str 00000000 +000016ff .debug_str 00000000 +00001717 .debug_str 00000000 +0000173c .debug_str 00000000 +00001761 .debug_str 00000000 +0000177c .debug_str 00000000 +00001797 .debug_str 00000000 +000017b2 .debug_str 00000000 +000017cd .debug_str 00000000 +000017e8 .debug_str 00000000 +00001803 .debug_str 00000000 +0000181e .debug_str 00000000 +00001839 .debug_str 00000000 +00001854 .debug_str 00000000 +0000186f .debug_str 00000000 +0000188a .debug_str 00000000 +000018a5 .debug_str 00000000 +000018c0 .debug_str 00000000 +000018db .debug_str 00000000 +000018f6 .debug_str 00000000 +00001911 .debug_str 00000000 +0000192c .debug_str 00000000 +00001947 .debug_str 00000000 +00001962 .debug_str 00000000 +0000197d .debug_str 00000000 +00001998 .debug_str 00000000 +000019b3 .debug_str 00000000 +000019ce .debug_str 00000000 +000019e9 .debug_str 00000000 +00001a04 .debug_str 00000000 +00001a1f .debug_str 00000000 +00001a3a .debug_str 00000000 +00001a55 .debug_str 00000000 +00000000 .debug_frame 00000000 +00001a8b .debug_str 00000000 +00001a9b .debug_str 00000000 +00001ab0 .debug_str 00000000 +00001abe .debug_str 00000000 +00001ad0 .debug_str 00000000 +00001ae2 .debug_str 00000000 +00001af4 .debug_str 00000000 +00001b03 .debug_str 00000000 +00001b12 .debug_str 00000000 +00001b21 .debug_str 00000000 +00001b30 .debug_str 00000000 +00001b39 .debug_str 00000000 +00001b42 .debug_str 00000000 +00001b4b .debug_str 00000000 +00001b52 .debug_str 00000000 +00001b58 .debug_str 00000000 +00001b5e .debug_str 00000000 +00001b65 .debug_str 00000000 +00001b6c .debug_str 00000000 +00001b74 .debug_str 00000000 +00001b7b .debug_str 00000000 +00001b81 .debug_str 00000000 +00001b92 .debug_str 00000000 +00001b9f .debug_str 00000000 +00001bad .debug_str 00000000 +00001bc8 .debug_str 00000000 +00001bdf .debug_str 00000000 +00001bef .debug_str 00000000 +00001c0a .debug_str 00000000 +00001c22 .debug_str 00000000 +00001c39 .debug_str 00000000 +00001c51 .debug_str 00000000 +00001c6a .debug_str 00000000 +00001c83 .debug_str 00000000 +00001c9c .debug_str 00000000 +00001b3d .debug_str 00000000 +00001ce5 .debug_str 00000000 +00001cee .debug_str 00000000 +00001390 .debug_str 00000000 +00001cb3 .debug_str 00000000 +00001ee9 .debug_str 00000000 +00001cb7 .debug_str 00000000 +000003e8 .debug_str 00000000 +00001cc9 .debug_str 00000000 +00001cd1 .debug_str 00000000 +00000e7f .debug_str 00000000 +00001cd9 .debug_str 00000000 +00000392 .debug_str 00000000 +00001ce1 .debug_str 00000000 +00001cea .debug_str 00000000 +00001cf3 .debug_str 00000000 +00001cfc .debug_str 00000000 +00001d0e .debug_str 00000000 +00001d20 .debug_str 00000000 +00001d2f .debug_str 00000000 +00001d3b .debug_str 00000000 +00001d47 .debug_str 00000000 +00001d53 .debug_str 00000000 +00001d60 .debug_str 00000000 +00001d6b .debug_str 00000000 +00001d77 .debug_str 00000000 +00001d83 .debug_str 00000000 +00001d90 .debug_str 00000000 +00001d9a .debug_str 00000000 +00001d9f .debug_str 00000000 +00001da3 .debug_str 00000000 +00001db3 .debug_str 00000000 +00001dc7 .debug_str 00000000 +00001dd4 .debug_str 00000000 +00001dd8 .debug_str 00000000 +000004be .debug_str 00000000 +00001ddc .debug_str 00000000 +00001de2 .debug_str 00000000 +00001df2 .debug_str 00000000 +00001e01 .debug_str 00000000 +00001e17 .debug_str 00000000 +00001e2c .debug_str 00000000 +00001e40 .debug_str 00000000 +00000bf4 .debug_str 00000000 +00001e53 .debug_str 00000000 +00001e57 .debug_str 00000000 +00001e67 .debug_str 00000000 +00001e77 .debug_str 00000000 +00001e7f .debug_str 00000000 +00001e87 .debug_str 00000000 +00003c13 .debug_str 00000000 +00001e97 .debug_str 00000000 +00001ea7 .debug_str 00000000 +00001eb8 .debug_str 00000000 +00001ec7 .debug_str 00000000 +00001ed8 .debug_str 00000000 +00001ee7 .debug_str 00000000 +00001eed .debug_str 00000000 +00001efe .debug_str 00000000 +00001f11 .debug_str 00000000 +00001f28 .debug_str 00000000 +00001f42 .debug_str 00000000 +00001f8b .debug_str 00000000 +00001fc5 .debug_str 00000000 +00001fd2 .debug_str 00000000 +00001fe4 .debug_str 00000000 +0000202f .debug_str 00000000 +0000203c .debug_str 00000000 +00002049 .debug_str 00000000 +00002055 .debug_str 00000000 +0000209f .debug_str 00000000 +000020ab .debug_str 00000000 +000020b7 .debug_str 00000000 +000020c3 .debug_str 00000000 +000020cf .debug_str 00000000 +000020db .debug_str 00000000 +000020e7 .debug_str 00000000 +000020f3 .debug_str 00000000 +000020ff .debug_str 00000000 +0000210b .debug_str 00000000 +00002117 .debug_str 00000000 +00002124 .debug_str 00000000 +00002131 .debug_str 00000000 +00002142 .debug_str 00000000 +000004b6 .debug_str 00000000 +00002191 .debug_str 00000000 +00002197 .debug_str 00000000 +0000219d .debug_str 00000000 +000021a1 .debug_str 00000000 +00003d24 .debug_str 00000000 +00003d13 .debug_str 00000000 +000021aa .debug_str 00000000 +000021d3 .debug_str 00000000 +000021b5 .debug_str 00000000 +000021ba .debug_str 00000000 +000021bf .debug_str 00000000 +000004e7 .debug_str 00000000 +000021c9 .debug_str 00000000 +000021d8 .debug_str 00000000 +000039a7 .debug_str 00000000 +000021e3 .debug_str 00000000 +000021e8 .debug_str 00000000 +00002208 .debug_str 00000000 +000037ef .debug_str 00000000 +00003998 .debug_str 00000000 +000021ed .debug_str 00000000 +00002201 .debug_str 00000000 +000021f5 .debug_str 00000000 +00003978 .debug_str 00000000 +000021fa .debug_str 00000000 +00002204 .debug_str 00000000 +00002210 .debug_str 00000000 +00002218 .debug_str 00000000 +0000222a .debug_str 00000000 +00002282 .debug_str 00000000 +00002296 .debug_str 00000000 +000022ad .debug_str 00000000 +000022c2 .debug_str 00000000 +000022dc .debug_str 00000000 +000022ec .debug_str 00000000 +000022f1 .debug_str 00000000 +000022f6 .debug_str 00000000 +000022fa .debug_str 00000000 +0000230e .debug_str 00000000 +00002366 .debug_str 00000000 +000023be .debug_str 00000000 +00002410 .debug_str 00000000 +0000241c .debug_str 00000000 +00002428 .debug_str 00000000 +00002435 .debug_str 00000000 +00002442 .debug_str 00000000 +00002450 .debug_str 00000000 +0000245e .debug_str 00000000 +0000246b .debug_str 00000000 +0000247a .debug_str 00000000 +00002489 .debug_str 00000000 +00002497 .debug_str 00000000 +000024a6 .debug_str 00000000 +000024b4 .debug_str 00000000 +00002506 .debug_str 00000000 +00003e45 .debug_str 00000000 +00002514 .debug_str 00000000 +0000251e .debug_str 00000000 +00002527 .debug_str 00000000 +00002538 .debug_str 00000000 +00002544 .debug_str 00000000 +00002541 .debug_str 00000000 +0000254d .debug_str 00000000 +00002557 .debug_str 00000000 +00002561 .debug_str 00000000 +0000256d .debug_str 00000000 +00002579 .debug_str 00000000 +0000257a .debug_str 00000000 +00002583 .debug_str 00000000 +000025e3 .debug_str 00000000 +00001de0 .debug_str 00000000 +000025ea .debug_str 00000000 +000025f5 .debug_str 00000000 +000025fa .debug_str 00000000 +00002604 .debug_str 00000000 +00002610 .debug_str 00000000 +000035f0 .debug_str 00000000 +00002617 .debug_str 00000000 +00002621 .debug_str 00000000 +00002630 .debug_str 00000000 +00002640 .debug_str 00000000 +00002649 .debug_str 00000000 +00002652 .debug_str 00000000 +0000265b .debug_str 00000000 +00002666 .debug_str 00000000 +0000266d .debug_str 00000000 +0000267a .debug_str 00000000 +00002688 .debug_str 00000000 +00002690 .debug_str 00000000 +000026a2 .debug_str 00000000 +000026b4 .debug_str 00000000 +000026c6 .debug_str 00000000 +000026d8 .debug_str 00000000 +000026ea .debug_str 00000000 +000026fc .debug_str 00000000 +0000270e .debug_str 00000000 +00002720 .debug_str 00000000 +00002732 .debug_str 00000000 +00002744 .debug_str 00000000 +00002756 .debug_str 00000000 +00002768 .debug_str 00000000 +0000277a .debug_str 00000000 +0000278c .debug_str 00000000 +0000279e .debug_str 00000000 +000027b0 .debug_str 00000000 +000027c5 .debug_str 00000000 +000027d8 .debug_str 00000000 +000027ea .debug_str 00000000 +000027fc .debug_str 00000000 +0000280e .debug_str 00000000 +00002820 .debug_str 00000000 +00002832 .debug_str 00000000 +00002844 .debug_str 00000000 +00002856 .debug_str 00000000 +00002868 .debug_str 00000000 +0000287a .debug_str 00000000 +0000288c .debug_str 00000000 +0000289e .debug_str 00000000 +000028b0 .debug_str 00000000 +000028c2 .debug_str 00000000 +000028d4 .debug_str 00000000 +000028e6 .debug_str 00000000 +000028f8 .debug_str 00000000 +0000290c .debug_str 00000000 +00002920 .debug_str 00000000 +00002934 .debug_str 00000000 +00002948 .debug_str 00000000 +0000295c .debug_str 00000000 +00002970 .debug_str 00000000 +00002984 .debug_str 00000000 +00002998 .debug_str 00000000 +000029ac .debug_str 00000000 +000029c0 .debug_str 00000000 +000029d4 .debug_str 00000000 +000029e8 .debug_str 00000000 +000029fc .debug_str 00000000 +00002a10 .debug_str 00000000 +00002a24 .debug_str 00000000 +00002a38 .debug_str 00000000 +00002a3c .debug_str 00000000 +00002a42 .debug_str 00000000 +00002a52 .debug_str 00000000 +00002ab2 .debug_str 00000000 +00002ac9 .debug_str 00000000 +00002ad4 .debug_str 00000000 +00002adc .debug_str 00000000 +00002b34 .debug_str 00000000 +00002b81 .debug_str 00000000 +00002b90 .debug_str 00000000 +00002ba3 .debug_str 00000000 +00002bb5 .debug_str 00000000 +00002bc0 .debug_str 00000000 +00002bcb .debug_str 00000000 +00002bdd .debug_str 00000000 +0000309b .debug_str 00000000 +00002be4 .debug_str 00000000 +00002bf4 .debug_str 00000000 +00002c1e .debug_str 00000000 +00002bd2 .debug_str 00000000 +00002bfe .debug_str 00000000 +00002c08 .debug_str 00000000 +00002c18 .debug_str 00000000 +00002c28 .debug_str 00000000 +00002c33 .debug_str 00000000 +00002c47 .debug_str 00000000 +00002c5e .debug_str 00000000 +00002c7b .debug_str 00000000 +00002c97 .debug_str 00000000 +00002cb3 .debug_str 00000000 +00002cce .debug_str 00000000 +00002ce9 .debug_str 00000000 +00002d00 .debug_str 00000000 +00002d1d .debug_str 00000000 +00002d39 .debug_str 00000000 +00002d55 .debug_str 00000000 +00002d70 .debug_str 00000000 +00002d8b .debug_str 00000000 +00002da2 .debug_str 00000000 +00002dbf .debug_str 00000000 +00002ddb .debug_str 00000000 +00002df7 .debug_str 00000000 +00002e12 .debug_str 00000000 +00002e2d .debug_str 00000000 +00002e44 .debug_str 00000000 +00002e61 .debug_str 00000000 +00002e7d .debug_str 00000000 +00002e99 .debug_str 00000000 +00002eb4 .debug_str 00000000 +00002ecf .debug_str 00000000 +00002ee6 .debug_str 00000000 +00002f03 .debug_str 00000000 +00002f1f .debug_str 00000000 +00002f3b .debug_str 00000000 +00002f56 .debug_str 00000000 +00002f71 .debug_str 00000000 +00002f8a .debug_str 00000000 +00002fa4 .debug_str 00000000 +00002fb3 .debug_str 00000000 +00002fcd .debug_str 00000000 +00002fe5 .debug_str 00000000 +00001cf7 .debug_str 00000000 +00002ff8 .debug_str 00000000 +00002ffd .debug_str 00000000 +0000104b .debug_str 00000000 +00003002 .debug_str 00000000 +00003014 .debug_str 00000000 +00003069 .debug_str 00000000 +00003618 .debug_str 00000000 +0000306f .debug_str 00000000 +00003073 .debug_str 00000000 +0000307c .debug_str 00000000 +00003085 .debug_str 00000000 +00003093 .debug_str 00000000 +000030a1 .debug_str 00000000 +000030b4 .debug_str 00000000 +000030c2 .debug_str 00000000 +000030d3 .debug_str 00000000 +000030df .debug_str 00000000 +000030ee .debug_str 00000000 +000030fb .debug_str 00000000 +00003106 .debug_str 00000000 +0000310e .debug_str 00000000 +00003112 .debug_str 00000000 +0000311b .debug_str 00000000 +00003127 .debug_str 00000000 +00003170 .debug_str 00000000 +000031b7 .debug_str 00000000 +000031f3 .debug_str 00000000 +00001dd0 .debug_str 00000000 +00003200 .debug_str 00000000 +0000320d .debug_str 00000000 +0000321b .debug_str 00000000 +00003225 .debug_str 00000000 +00003233 .debug_str 00000000 +00003240 .debug_str 00000000 +0000324c .debug_str 00000000 +00003256 .debug_str 00000000 +00003260 .debug_str 00000000 +0000326c .debug_str 00000000 +00003276 .debug_str 00000000 +00003283 .debug_str 00000000 +00003297 .debug_str 00000000 +000032df .debug_str 00000000 +000032e8 .debug_str 00000000 +000032f5 .debug_str 00000000 +000032fe .debug_str 00000000 +00003307 .debug_str 00000000 +0000330f .debug_str 00000000 +0000331c .debug_str 00000000 +00003326 .debug_str 00000000 +00003334 .debug_str 00000000 +0000333a .debug_str 00000000 +00003346 .debug_str 00000000 +00003351 .debug_str 00000000 +00003359 .debug_str 00000000 +00003363 .debug_str 00000000 +00003372 .debug_str 00000000 +00003381 .debug_str 00000000 +00003389 .debug_str 00000000 +00003391 .debug_str 00000000 +0000339a .debug_str 00000000 +000033a6 .debug_str 00000000 +000033b3 .debug_str 00000000 +000033c3 .debug_str 00000000 +000033d6 .debug_str 00000000 +000033e6 .debug_str 00000000 +000033f4 .debug_str 00000000 +0000343b .debug_str 00000000 +00003473 .debug_str 00000000 +0000348c .debug_str 00000000 +000034b4 .debug_str 00000000 +000034be .debug_str 00000000 +000034c8 .debug_str 00000000 +000034ce .debug_str 00000000 +000034d8 .debug_str 00000000 +000034e8 .debug_str 00000000 +000034f2 .debug_str 00000000 +00003505 .debug_str 00000000 +0000350e .debug_str 00000000 +00003517 .debug_str 00000000 +00003521 .debug_str 00000000 +000036dc .debug_str 00000000 +000000c7 .debug_str 00000000 +00003529 .debug_str 00000000 +0000352f .debug_str 00000000 +00003535 .debug_str 00000000 +0000353b .debug_str 00000000 +000031ee .debug_str 00000000 +00003545 .debug_str 00000000 +000036ae .debug_str 00000000 +0000354b .debug_str 00000000 +00003554 .debug_str 00000000 +0000355a .debug_str 00000000 +00003560 .debug_str 00000000 +00003568 .debug_str 00000000 +00003813 .debug_str 00000000 +00003570 .debug_str 00000000 +00003575 .debug_str 00000000 +0000357e .debug_str 00000000 +00003589 .debug_str 00000000 +00003596 .debug_str 00000000 +0000359e .debug_str 00000000 +00003cc1 .debug_str 00000000 +000035a6 .debug_str 00000000 +000035b0 .debug_str 00000000 +000035b4 .debug_str 00000000 +000035b8 .debug_str 00000000 +000035c4 .debug_str 00000000 +000035ca .debug_str 00000000 +000035d0 .debug_str 00000000 +000035d5 .debug_str 00000000 +000035da .debug_str 00000000 +000035e4 .debug_str 00000000 +000035ea .debug_str 00000000 +000035f6 .debug_str 00000000 +00003604 .debug_str 00000000 +00003610 .debug_str 00000000 +0000361e .debug_str 00000000 +00003625 .debug_str 00000000 +0000362c .debug_str 00000000 +00003633 .debug_str 00000000 +0000363e .debug_str 00000000 +00003651 .debug_str 00000000 +0000365e .debug_str 00000000 +0000364d .debug_str 00000000 +00003664 .debug_str 00000000 +000013c5 .debug_str 00000000 +0000366b .debug_str 00000000 +00003670 .debug_str 00000000 +00000409 .debug_str 00000000 +00003683 .debug_str 00000000 +000000cf .debug_str 00000000 +00003695 .debug_str 00000000 +00003cb2 .debug_str 00000000 +00003698 .debug_str 00000000 +0000369c .debug_str 00000000 +000036a2 .debug_str 00000000 +000036b3 .debug_str 00000000 +00003f34 .debug_str 00000000 +000036bc .debug_str 00000000 +000036cc .debug_str 00000000 +000036e1 .debug_str 00000000 +000036f3 .debug_str 00000000 +000036f9 .debug_str 00000000 +0000370a .debug_str 00000000 +0000370f .debug_str 00000000 +00003713 .debug_str 00000000 +00003723 .debug_str 00000000 +00003732 .debug_str 00000000 +00003737 .debug_str 00000000 +00000694 .debug_str 00000000 +00003749 .debug_str 00000000 +0000374e .debug_str 00000000 +0000375a .debug_str 00000000 +00003766 .debug_str 00000000 +00003778 .debug_str 00000000 +00003783 .debug_str 00000000 +00003791 .debug_str 00000000 +00003799 .debug_str 00000000 +000037b6 .debug_str 00000000 +000037c3 .debug_str 00000000 +000037cd .debug_str 00000000 +000037d2 .debug_str 00000000 +000037e2 .debug_str 00000000 +00003281 .debug_str 00000000 +000037eb .debug_str 00000000 +000037f4 .debug_str 00000000 +000037d4 .debug_str 00000000 +000037f8 .debug_str 00000000 +00003808 .debug_str 00000000 +0000260e .debug_str 00000000 +00003818 .debug_str 00000000 +00003829 .debug_str 00000000 +00003837 .debug_str 00000000 +0000383c .debug_str 00000000 +00003847 .debug_str 00000000 +00003853 .debug_str 00000000 +000025ef .debug_str 00000000 +0000386e .debug_str 00000000 +00003a8b .debug_str 00000000 +000038fc .debug_str 00000000 +00003a55 .debug_str 00000000 +00003928 .debug_str 00000000 +0000387e .debug_str 00000000 +0000388f .debug_str 00000000 +00003899 .debug_str 00000000 +000038b5 .debug_str 00000000 +000038bf .debug_str 00000000 +000038da .debug_str 00000000 +000038ec .debug_str 00000000 +0000390c .debug_str 00000000 +00003918 .debug_str 00000000 +00003937 .debug_str 00000000 +00003951 .debug_str 00000000 +0000395e .debug_str 00000000 +00003971 .debug_str 00000000 +00002615 .debug_str 00000000 +00003982 .debug_str 00000000 +0000398c .debug_str 00000000 +0000397c .debug_str 00000000 +0000399c .debug_str 00000000 +000039ad .debug_str 00000000 +000039b8 .debug_str 00000000 +000039cb .debug_str 00000000 +000039de .debug_str 00000000 +000039ef .debug_str 00000000 +00003a00 .debug_str 00000000 +00003a0f .debug_str 00000000 +00003a1b .debug_str 00000000 +00003b58 .debug_str 00000000 +000032fc .debug_str 00000000 +00003a2b .debug_str 00000000 +00003a44 .debug_str 00000000 +00003a5a .debug_str 00000000 +00003a6c .debug_str 00000000 +00003a7f .debug_str 00000000 +00003a91 .debug_str 00000000 +00003aa8 .debug_str 00000000 +00003aba .debug_str 00000000 +00003aca .debug_str 00000000 +00003adb .debug_str 00000000 +00003adf .debug_str 00000000 +00003aea .debug_str 00000000 +00003af3 .debug_str 00000000 +00003afc .debug_str 00000000 +00003b05 .debug_str 00000000 +00003b16 .debug_str 00000000 +00003b28 .debug_str 00000000 +00003b32 .debug_str 00000000 +00003b3e .debug_str 00000000 +00003355 .debug_str 00000000 +00003b4f .debug_str 00000000 +00003b5e .debug_str 00000000 +00003b6f .debug_str 00000000 +00003b7d .debug_str 00000000 +00003b97 .debug_str 00000000 +00003bac .debug_str 00000000 +00003bbd .debug_str 00000000 +00003bd8 .debug_str 00000000 +00003bdf .debug_str 00000000 +00003bf6 .debug_str 00000000 +00003c0c .debug_str 00000000 +00003c18 .debug_str 00000000 +00003c23 .debug_str 00000000 +00003c3a .debug_str 00000000 +00003c51 .debug_str 00000000 +00003c67 .debug_str 00000000 +00003c7d .debug_str 00000000 +00003c8a .debug_str 00000000 +00003c96 .debug_str 00000000 +00003ca8 .debug_str 00000000 +00003cb9 .debug_str 00000000 +00003cc5 .debug_str 00000000 +00003cd0 .debug_str 00000000 +00003cdf .debug_str 00000000 +00003cea .debug_str 00000000 +00003cf5 .debug_str 00000000 +00003d09 .debug_str 00000000 +00003d1d .debug_str 00000000 +0000398e .debug_str 00000000 +00003d28 .debug_str 00000000 +00003d37 .debug_str 00000000 +00003d47 .debug_str 00000000 +00003d5b .debug_str 00000000 +00003d60 .debug_str 00000000 +00003d72 .debug_str 00000000 +00003d7d .debug_str 00000000 +00003d91 .debug_str 00000000 +00003da0 .debug_str 00000000 +00003db3 .debug_str 00000000 +00003dc6 .debug_str 00000000 +00003dd5 .debug_str 00000000 +00003de5 .debug_str 00000000 +00003dee .debug_str 00000000 +00003dfb .debug_str 00000000 +00003e10 .debug_str 00000000 +00003e28 .debug_str 00000000 +00003e37 .debug_str 00000000 +00003e3f .debug_str 00000000 +00003e4c .debug_str 00000000 +00003e5e .debug_str 00000000 +00003e6b .debug_str 00000000 +00003e80 .debug_str 00000000 +00003e91 .debug_str 00000000 +00003b6a .debug_str 00000000 +00003ea1 .debug_str 00000000 +00003ea5 .debug_str 00000000 +00003eae .debug_str 00000000 +00003ebf .debug_str 00000000 +000005a9 .debug_str 00000000 +00000583 .debug_str 00000000 +00003ec9 .debug_str 00000000 +00003ece .debug_str 00000000 +00003ed7 .debug_str 00000000 +00003eda .debug_str 00000000 +00003eeb .debug_str 00000000 +00003ef5 .debug_str 00000000 +00003e5a .debug_str 00000000 +00003ef9 .debug_str 00000000 +00003f02 .debug_str 00000000 +00003f0a .debug_str 00000000 +00003f14 .debug_str 00000000 +00003f1d .debug_str 00000000 +00003f21 .debug_str 00000000 +00003f53 .debug_str 00000000 +00003f31 .debug_str 00000000 +00003f36 .debug_str 00000000 +00003f3b .debug_str 00000000 +00003f40 .debug_str 00000000 +00003f45 .debug_str 00000000 +00003f49 .debug_str 00000000 +00003f4e .debug_str 00000000 +00003f52 .debug_str 00000000 +00003f56 .debug_str 00000000 +00003f5e .debug_str 00000000 +00003f66 .debug_str 00000000 +000035ab .debug_str 00000000 +00002575 .debug_str 00000000 +00003f6f .debug_str 00000000 +00003f77 .debug_str 00000000 +00003f83 .debug_str 00000000 +00000000 .debug_loc 00000000 +00000013 .debug_loc 00000000 +00000026 .debug_loc 00000000 +00000048 .debug_loc 00000000 +0000007c .debug_loc 00000000 +0000009a .debug_loc 00000000 +000000ae .debug_loc 00000000 +000000e2 .debug_loc 00000000 +00000100 .debug_loc 00000000 +00000114 .debug_loc 00000000 +00000127 .debug_loc 00000000 +0000013a .debug_loc 00000000 +0000014d .debug_loc 00000000 +00000160 .debug_loc 00000000 +00000173 .debug_loc 00000000 +00000186 .debug_loc 00000000 +00000199 .debug_loc 00000000 +000001ac .debug_loc 00000000 +000001bf .debug_loc 00000000 +000001d2 .debug_loc 00000000 +000001f0 .debug_loc 00000000 +00000203 .debug_loc 00000000 +00000216 .debug_loc 00000000 +00000229 .debug_loc 00000000 +0000023c .debug_loc 00000000 +0000024f .debug_loc 00000000 +00000262 .debug_loc 00000000 +00000275 .debug_loc 00000000 +00000288 .debug_loc 00000000 +000002c7 .debug_loc 00000000 +000002da .debug_loc 00000000 +000002ed .debug_loc 00000000 +00000300 .debug_loc 00000000 +00000313 .debug_loc 00000000 +00000331 .debug_loc 00000000 +00000344 .debug_loc 00000000 +00000362 .debug_loc 00000000 +00000382 .debug_loc 00000000 +00000395 .debug_loc 00000000 +000003b3 .debug_loc 00000000 +000003d1 .debug_loc 00000000 +000003fa .debug_loc 00000000 +00000418 .debug_loc 00000000 +0000042b .debug_loc 00000000 +0000043e .debug_loc 00000000 +00000451 .debug_loc 00000000 +00000464 .debug_loc 00000000 +00000477 .debug_loc 00000000 +0000048a .debug_loc 00000000 +0000049d .debug_loc 00000000 +000004b0 .debug_loc 00000000 +000004c3 .debug_loc 00000000 +000004e3 .debug_loc 00000000 +00000501 .debug_loc 00000000 +00000514 .debug_loc 00000000 +00000527 .debug_loc 00000000 +0000053a .debug_loc 00000000 +0000054d .debug_loc 00000000 +00000560 .debug_loc 00000000 +00000573 .debug_loc 00000000 +00000586 .debug_loc 00000000 +000005a4 .debug_loc 00000000 +000005b7 .debug_loc 00000000 +0000035a .text 00000000 .GJTIE12_0_0_ +000003d0 .text 00000000 .GJTIE18_0_0_ +00000cf0 .text 00000000 .GJTIE43_0_0_ +00001546 .text 00000000 .GJTIE49_0_0_ +00000352 .text 00000000 .GJTIS12_0_0_ +000003c8 .text 00000000 .GJTIS18_0_0_ +00000cea .text 00000000 .GJTIS43_0_0_ +0000153e .text 00000000 .GJTIS49_0_0_ +00000258 l .text 00000008 .L_MergedGlobals +00002460 l .bss 00000038 .L_MergedGlobals.302 +00000000 .debug_line 00000000 .Lline_table_start0 +0000001d .debug_line 00000000 .Lline_table_start1 +00000518 .debug_line 00000000 .Lline_table_start10 +00000535 .debug_line 00000000 .Lline_table_start11 +00000552 .debug_line 00000000 .Lline_table_start12 +0000056f .debug_line 00000000 .Lline_table_start13 +0000058c .debug_line 00000000 .Lline_table_start14 +000005a9 .debug_line 00000000 .Lline_table_start15 +000005c6 .debug_line 00000000 .Lline_table_start16 +000005e3 .debug_line 00000000 .Lline_table_start17 +00000600 .debug_line 00000000 .Lline_table_start18 +0000061d .debug_line 00000000 .Lline_table_start19 +0000003a .debug_line 00000000 .Lline_table_start2 +0000063a .debug_line 00000000 .Lline_table_start20 +00000657 .debug_line 00000000 .Lline_table_start21 +00000689 .debug_line 00000000 .Lline_table_start22 +00000735 .debug_line 00000000 .Lline_table_start23 +000007d1 .debug_line 00000000 .Lline_table_start24 +00000822 .debug_line 00000000 .Lline_table_start25 +000008b3 .debug_line 00000000 .Lline_table_start26 +0000090f .debug_line 00000000 .Lline_table_start27 +000009a5 .debug_line 00000000 .Lline_table_start28 +000009f8 .debug_line 00000000 .Lline_table_start29 +00000102 .debug_line 00000000 .Lline_table_start3 +00000a28 .debug_line 00000000 .Lline_table_start30 +00000a89 .debug_line 00000000 .Lline_table_start31 +00000aa6 .debug_line 00000000 .Lline_table_start32 +00000ac3 .debug_line 00000000 .Lline_table_start33 +00000d35 .debug_line 00000000 .Lline_table_start34 +00000e1d .debug_line 00000000 .Lline_table_start35 +00000ee8 .debug_line 00000000 .Lline_table_start36 +0000122c .debug_line 00000000 .Lline_table_start37 +000016fc .debug_line 00000000 .Lline_table_start38 +000017c9 .debug_line 00000000 .Lline_table_start39 +000001e5 .debug_line 00000000 .Lline_table_start4 +00001a37 .debug_line 00000000 .Lline_table_start40 +00001e45 .debug_line 00000000 .Lline_table_start41 +00002112 .debug_line 00000000 .Lline_table_start42 +000026be .debug_line 00000000 .Lline_table_start43 +00002877 .debug_line 00000000 .Lline_table_start44 +00002901 .debug_line 00000000 .Lline_table_start45 +000029c1 .debug_line 00000000 .Lline_table_start46 +00002a83 .debug_line 00000000 .Lline_table_start47 +00002b3f .debug_line 00000000 .Lline_table_start48 +00002bf4 .debug_line 00000000 .Lline_table_start49 +00000312 .debug_line 00000000 .Lline_table_start5 +00002caa .debug_line 00000000 .Lline_table_start50 +00002d14 .debug_line 00000000 .Lline_table_start51 +0000032f .debug_line 00000000 .Lline_table_start6 +0000034c .debug_line 00000000 .Lline_table_start7 +00000369 .debug_line 00000000 .Lline_table_start8 +00000483 .debug_line 00000000 .Lline_table_start9 +00000486 l F .text 00000042 HWI_Install +00000626 l F .text 00000040 __get_min_precesion +00000cc2 l F .text 00000172 __power_recover +000002c6 l F .text 00000018 _gravity_sensor_get_ndata +00000b66 l F .text 00000094 analog_pdown_exit0 +00000bfa l F .text 0000004e analog_pdown_exit1 +0000107c l F .text 00000178 analog_pdown_poff_enter +00000512 l F .text 00000014 bit_set_ie +00000106 l F .text 0000001e call_deep_sleep +000006cc l F .text 00000028 charge_disable +0000247c l .bss 00000004 charge_en +000004c8 l F .text 00000018 debug_init +000000fc l F .text 0000000a delay +000000f9 l .text 00000001 delay_50us +00002463 l .bss 00000001 dvdd_lel +00002460 l .bss 00000001 filter +00002478 l .bss 00000004 filter_enable +00000214 l .text 00000020 gSensor +00000234 l .text 00000020 gSensor.24 +00002466 l .bss 00000002 global_id +0000030c l F .text 0000000e gravity_sensor_command +00002474 l .bss 00000004 hdl.5 +000005ea l F .text 0000000a iovdd2_bypass_iovdd +000005f4 l F .text 00000018 irq_disable_core +0000060c l F .text 0000001a irq_enable_core +00002470 l .bss 00000004 irq_lock_cnt +0000246c l .bss 00000004 irq_lock_core_cnt +000003f6 l F .text 00000048 local_irq_disable +0000043e l F .text 00000048 local_irq_enable +00002484 l .bss 00000004 lp_sta +0000092a l F .text 000000c2 lptmr3_int +00000666 l F .text 0000003c lptmr3_run +00000258 l .text 00000004 lrc_feq +0000025c l .text 00000004 lrc_feq.186 +000015da l F .text 0000004c lvcmp_filter +00002480 l .bss 00000004 m2p_cmd +00001204 l F .text 000003d6 m2p_int +000000f8 l .text 00000001 m2p_pvdd_level_sleep_t +000002fa l F .text 00000012 mdelay +00000346 l F .text 0000003a mir3da_ctl +0000031e l F .text 00000028 mir3da_init +000002e2 l F .text 00000014 mir3da_is_online +000002f6 l F .text 00000004 mir3da_register_mask_write +000002de l F .text 00000004 mir3da_register_read +0000031a l F .text 00000004 mir3da_register_write +000006f4 l F .text 00000214 p11_power_hw_manage +00002462 l .bss 00000001 p2m_clk_backups +00000e66 l F .text 00000136 p33_wkup_int +00002461 l .bss 00000001 p33_wkup_msys +00002464 l .bss 00000001 pmu_det_backup +00000526 l F .text 000000c4 power_init +00000c48 l F .text 0000007a power_off_exit +000000fa l .text 00000001 pvdd_bk +00000f9c l F .text 000000e0 ram_pdown_poff_enter +000009ec l F .text 0000017a ram_pdown_poff_exit +00000260 l F .text 0000001c soft_iic_start +000002b0 l F .text 00000016 soft_iic_stop +0000027c l F .text 00000034 soft_iic_tx_byte +00001626 l F .text 000000ac soft_int_test_isr.207 +00000392 l F .text 0000000c stk832x_check_chip_id +000003bc l F .text 0000003a stk832x_ctl +0000039e l F .text 0000001e stk832x_init +0000038e l F .text 00000004 stk832x_register_read +00000380 l F .text 00000004 stk832x_register_write +00000384 l F .text 0000000a stk832x_software_reset +00000124 l F .text 00000032 timer2_dly_lrc +00002468 l .bss 00000002 timer_id +00002340 l .bss 00000118 timer_pool +00000e34 l F .text 00000032 tmr0_int +000011f4 l F .text 00000010 user_m2p11_irq +00000254 l .text 00000004 usr_jiffies +000006a2 l F .text 0000002a usr_timer_del +00002490 l .bss 00000008 usr_timer_head +000004e0 l F .text 00000032 usr_timer_init +00002465 l .bss 00000001 wdt_backup +00002488 l .bss 00000006 wkup_buf +00000000 l df *ABS* 00000000 ../../../../src/newlib/newlib/libm/math/w_sqrt.c +00000000 l df *ABS* 00000000 ../../../../src/newlib/newlib/libm/math/e_sqrt.c +00000000 l df *ABS* 00000000 ../../../../src/newlib/newlib/libc/stdlib/abs.c +00000000 l df *ABS* 00000000 ../../../../src/newlib/newlib/libc/string/memcmp.c +00000000 l df *ABS* 00000000 ../../../../src/newlib/newlib/libc/string/strlen.c +00000000 l df *ABS* 00000000 adddf3.bc +00001ca6 l F .text 00000028 normalize +00001cce l F .text 00000010 rep_clz +00000000 l df *ABS* 00000000 ashldi3.bc +00000000 l df *ABS* 00000000 divdf3.bc +00002006 l F .text 0000002c normalize +00000000 l df *ABS* 00000000 lshrdi3.bc +00000000 l df *ABS* 00000000 muldf3.bc +000022ca l F .text 0000002c normalize +00000000 l df *ABS* 00000000 muldi3.bc +00000000 l df *ABS* 00000000 subdf3.bc +00000254 .text 00000000 loop_detect_handler_begin +00007f20 *ABS* 00000000 p11_heap_end +00001cde g F .text 00000026 __ashldi3 +000016d2 g F .text 00000004 sqrt +00007f20 *ABS* 00000000 P11_RAM_CODE_END +00001866 g F .text 00000106 memmove +00000080 .text 00000000 text_begin +00007f40 g .p11_message 00000040 p2m_message +00008000 *ABS* 00000000 P11_RAM_LIMIT_H +00001866 g F .text 00000106 memcpy +00000000 *ABS* 00000000 data_size +00000040 *ABS* 00000000 P2M_MESSAGE_SIZE +00002334 *ABS* 00000000 text_end +0000801a *ABS* 00000000 sleep +00000254 .text 00000000 loop_detect_handler_end +000001c6 g F .text 0000001e ram0_exit_sleep +0000800a *ABS* 00000000 standby +00000060 *ABS* 00000000 M2P_MESSAGE_SIZE +000019d0 g F .text 000002d6 __adddf3 +00000928 g F .text 00000002 exception_analyze +00007f40 .p11_message 00000000 p11_message_data_addr +000001ae g F .text 00000018 ram0_enter_sleep +00007f80 g .p11_message 00000060 m2p_message +00000254 .text 00000000 hrsensor_dev_end +00002032 g F .text 00000028 __lshrdi3 +00002334 *ABS* 00000000 data_begin +00008000 *ABS* 00000000 P11_RAM_END +000000c6 g F .text 00000000 exception_irq_handler +00008000 *ABS* 00000000 idle +00000080 g F .text 00000000 _start +00007fe0 *ABS* 00000000 P11_POWEROFF_RAM_BEGIN +00000080 *ABS* 00000000 P11_RAM_CODE_BEGIN +00000158 *ABS* 00000000 bss_size +00000156 g F .text 0000001e pvdd_protect +0000182a g F .text 0000003c memcmp +00002aa4 .overlay_bank_demo_normal1 00000000 overlay_sensor_begin +00002340 .p11_vad 00000000 data_addr +00001d04 g F .text 00000302 __divdf3 +0000205a g F .text 00000270 __muldf3 +000000a0 *ABS* 00000000 p11_message_data_size +00000214 .text 00000000 gsensor_dev_begin +0000196c g F .text 00000056 memset +00000908 g F .text 00000020 main +00000000 *ABS* 00000000 ISR_BASE +00000020 *ABS* 00000000 P11_POWEROFF_RAM_SIZE +00005474 *ABS* 00000000 p11_heap_size +00002aa0 .stack_bss 00000000 _stack_end +000022b4 *ABS* 00000000 text_size +00007f20 *ABS* 00000000 P11_VAD_RAM_BEGIN +00000000 *ABS* 00000000 P11_VAD_RAM_SIZE +00000254 .text 00000000 low_power_target_end +00007f40 *ABS* 00000000 P11_MESSAGE_BEGIN +00000254 .text 00000000 hrsensor_dev_begin +000000a0 *ABS* 00000000 P11_MESSAGE_SIZE +00002aac .overlay_bank_sys_normal0 00000000 p11_heap_begin +000016d6 g F .text 0000014c __ieee754_sqrt +00000080 *ABS* 00000000 P11_CODE_BEGIN +000000f8 .text 00000000 deepsleep_stack +00000174 g F .text 0000003a pvdd_protect_release +000001e4 g F .text 00000000 deepsleep_r +00007ea0 *ABS* 00000000 P11_RAM_CODE_SIZE +00002340 .bss 00000000 bss_begin +00007f80 *ABS* 00000000 P11_RAM_SIZE +000022f6 g F .text 00000036 __muldi3 +000019c2 g F .text 0000000e strlen +00002aa0 .stack_bss 00000000 _stack +00001822 g F .text 00000008 abs +00000080 *ABS* 00000000 P11_RAM_LIMIT_L +00000254 .text 00000000 low_power_target_begin +00000254 .text 00000000 gsensor_dev_end +0000232c g F .text 00000008 __subdf3 +00002aa0 .stack_bss 00000000 overlay_demo_begin +0000802a *ABS* 00000000 deep_sleep diff --git a/2.code/2.p11_code/cpu/br28/post_build/text.bin b/2.code/2.p11_code/cpu/br28/post_build/text.bin new file mode 100644 index 0000000..0b900e0 Binary files /dev/null and b/2.code/2.p11_code/cpu/br28/post_build/text.bin differ diff --git a/2.code/2.p11_code/cpu/br28/spi.c b/2.code/2.p11_code/cpu/br28/spi.c new file mode 100644 index 0000000..380e75d --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/spi.c @@ -0,0 +1,413 @@ +#ifdef SUPPORT_MS_EXTENSIONS +#pragma bss_seg(".spi.bss") +#pragma data_seg(".spi.data") +#pragma const_seg(".spi.const") +#pragma code_seg(".spi.text") +#pragma str_literal_override(".spi.text") +#endif /* #ifdef SUPPORT_MS_EXTENSIONS */ + +#include "includes.h" +#include "spi_hw.h" +#include "gpio.h" + +//================================================================// +// 注意: SPI 只做主机, 不做从机 +//================================================================// + +#define SPI_CS_IO IO_PORTB_05 +#define SPI_CLK_IO IO_PORTB_06 +#define SPI_DI_IO IO_PORTB_07 +#define SPI_DO_IO IO_PORTB_08 + +#define SPI_MASTER_CLOCK_FREQ 200000 +#define SYS_CLOCK_FREQ 16000000UL + +static u32 spi_get_clk_freq(void) +{ + return 1600000; +} + +___interrupt +static void spi_isr(void) +{ + printf("%s\n", __func__); + + if (SPI_PENDING_IS()) { + printf("spi pending\n"); + SPI_PENDING_CLEAR(); + } +} + + +void spi_cs_set_active(void) +{ + gpio_set_output_value(SPI_CS_IO, 0); +} + +void spi_cs_set_idle(void) +{ + gpio_set_output_value(SPI_CS_IO, 1); +} + + +void spi_master_tx_byte(u8 data) +{ + SPI_DIR_TRAMSMIT(); + SPI_BUF_WRITE(data); + + while (!(SPI_PENDING_IS())); + SPI_PENDING_CLEAR(); +} + +u32 spi_master_dma_tx(u8 *buf, u32 len) +{ + SPI_DIR_TRAMSMIT(); + + if (((u32)buf % 4) != 0) { + printf("spi buf: 0x%x not align 4\n", buf); + return 0; + } + SPI_DMA_ADDR_CONFIG(buf); + SPI_START_DMA_CNT(len); + + while (!(SPI_PENDING_IS())); + SPI_PENDING_CLEAR(); + + return len; +} + +u8 spi_master_rx_byte(void) +{ + u8 data = 0; + + SPI_DIR_RECEIVE(); + SPI_BUF_WRITE(0xFF); + + while (!(SPI_PENDING_IS())); + SPI_PENDING_CLEAR(); + + data = SPI_BUF_READ(); + + return data; +} + +u32 spi_master_dma_rx(u8 *buf, u32 len) +{ + SPI_DIR_RECEIVE(); + + if (((u32)buf % 4) != 0) { + printf("spi buf: 0x%x not align 4\n", buf); + return 0; + } + SPI_DMA_ADDR_CONFIG(buf); + SPI_START_DMA_CNT(len); + + while (!(SPI_PENDING_IS())); + SPI_PENDING_CLEAR(); + + return len; +} + +void spi_master_init(void) +{ + u32 baud = 0; + + SPI_CON_CLEAR(); + SPI_PENDING_CLEAR(); + + baud = spi_get_clk_freq() / SPI_MASTER_CLOCK_FREQ - 1; + + SPI_BAUD_CONFIG(baud); + + SPI_CS_IDLE_LOGIC(1); + + SPI_CLK_IDLE_LOGIC(1); + + SPI_UPDETE_AT_FALL_EDGE(); + SPI_SIMPLE_AT_RISE_EDGE(); + + SPI_BI_DIR(0); + SPI_CS_ENABLE(1); //always set 1 + + SPI_MASTER_MODE(); + + /* SPI_INT_ENABLE(1); */ + + //gpio: + //CS: + gpio_set_direction(SPI_CS_IO, 0); + gpio_set_output_value(SPI_CS_IO, 1); + + //CLK: + gpio_set_direction(SPI_CLK_IO, 0); + gpio_set_output_value(SPI_CLK_IO, 1); + //gpio_set_fun_input_port(SPI_CLK_IO, ); + gpio_set_fun_output_port(SPI_CLK_IO, P11_FO_SPI_CLK, 1, 1); + + //DO: + gpio_set_direction(SPI_DO_IO, 0); + gpio_set_output_value(SPI_DO_IO, 1); + //gpio_set_fun_input_port(SPI_DO_IO, ); + gpio_set_fun_output_port(SPI_DO_IO, P11_FO_SPI_DO, 1, 1); + + //DI: + gpio_set_direction(SPI_DI_IO, 1); + gpio_set_pull_down(SPI_DI_IO, 0); + gpio_set_pull_up(SPI_DI_IO, 1); + gpio_set_die(SPI_DI_IO, 1); + //gpio_set_fun_output_port(, P11_FO_, 1, 1); + gpio_set_fun_input_port(SPI_DI_IO, PFI_SPI_DI); + + SPI_MODULE_ENABLE(1); + + printf("P11_SPI->CON = 0x%x\n", P11_SPI->CON); + //printf("P11_SPI->BAUD = 0x%x\n", P11_SPI->BAUD); + printf("P11_SPI->BAUD = 0x%x\n", baud); + printf("P11_SPI->CNT = 0x%x\n", P11_SPI->CNT); + printf("P11_SPI->ADR = 0x%x\n", P11_SPI->ADR); +} + +void spi_close(void) +{ + SPI_MODULE_ENABLE(0); +} + +//=========================================// +// SPI test code // +//=========================================// +/*************************************************/ +/* + COMMAND LIST - WinBond FLASH WX25X10 +*/ +/*************************************************/ +#define WINBOND_WRITE_ENABLE 0x06 +#define WINBOND_WRITE_DISABLE 0x04 +#define WINBOND_READ_SR1 0x05 +#define WINBOND_READ_SR2 0x35 +#define WINBOND_WRITE_SR 0x01 +#define WINBOND_READ_DATA 0x03 +#define WINBOND_FAST_READ 0x0B +#define WINBOND_FAST_READ_DUAL 0x3B +#define WINBOND_FAST_READ_QUAD 0x6B +#define WINBOND_PAGE_PROGRAM 0x02 +#define WINBOND_PAGE_PROGRAM_QUAD 0x32 +#define WINBOND_SECTOR_ERASE 0x20 +#define WINBOND_BLOCK_ERASE 0xD8 +#define WINBOND_CHIP_ERASE 0xC7 +#define WINBOND_POWER_DOWN 0xB9 +#define WINBOND_RELEASE 0xAB +#define WINBOND_MANUFACTURE 0x90 +#define WINBOND_JEDEC_ID 0x9F + +enum NORFLASH_ERASE_CMD { + NORFLASH_ERASE_SECTOR, + NORFLASH_ERASE_BLOCK, + NORFLASH_ERASE_CHIP, +}; + +static void norflash_power_reset(void) +{ + printf("nor_power_reset\n"); + + spi_cs_set_active(); + spi_master_tx_byte(0x66); + spi_cs_set_idle(); + + spi_cs_set_active(); + spi_master_tx_byte(0x99); + spi_cs_set_idle(); + + delay(1000); +} + + +static void norflash_wait_ok(u32 otms) +{ + while (otms--) { + spi_cs_set_active(); + spi_master_tx_byte(WINBOND_READ_SR1); + u32 reg = spi_master_rx_byte(); + spi_cs_set_idle(); + + if ((reg & BIT(0)) == 0) { + break; + } + delay(10000); + } + + if (otms == 0) { + printf("flash time out\n"); + } +} + + +static void norflash_power_release(void) +{ + spi_cs_set_active(); + + spi_master_tx_byte(WINBOND_RELEASE); + + //3dummy Bytes + spi_master_tx_byte(0xff); + spi_master_tx_byte(0xff); + spi_master_tx_byte(0xff); + //device id + spi_master_rx_byte(); + + spi_cs_set_idle(); +} + + +static u32 norflash_read_id(void) +{ + u8 i; + u32 id = 0; + + spi_cs_set_active(); + + spi_master_tx_byte(WINBOND_JEDEC_ID); + + + for (i = 0; i < 3; i++) { + id <<= 8; + id |= spi_master_rx_byte(); + } + + spi_cs_set_idle(); + + printf("flash id 0x%x\n", id); + + return id; +} + + +static void norflash_send_addr(u32 addr) +{ + spi_master_tx_byte(addr >> 16); + spi_master_tx_byte(addr >> 8); + spi_master_tx_byte(addr); +} + +static void norflash_write_enable(void) +{ + spi_cs_set_active(); + spi_master_tx_byte(WINBOND_WRITE_ENABLE); + spi_cs_set_idle(); +} + +static int norflash_write(u8 *buf, u32 offset, u32 len) +{ + u32 _len = len; + + if (len == 0) { + return 0; + } + + norflash_write_enable(); + + spi_cs_set_active(); + + spi_master_tx_byte(WINBOND_PAGE_PROGRAM); + + norflash_send_addr(offset); + + spi_master_dma_tx(buf, len); + /* while (len--) { */ + /* spi_master_tx_byte(*buf++); */ + /* } */ + + spi_cs_set_idle(); + + norflash_wait_ok(1000); + + return 0; +} + + +static int norflash_read(u8 *buf, u32 offset, u32 len) +{ + spi_cs_set_active(); + + spi_master_tx_byte(WINBOND_FAST_READ); + + norflash_send_addr(offset); + + spi_master_rx_byte(); //DUMMY_BYTE + + spi_master_dma_rx(buf, len); + + spi_cs_set_idle(); + + return len; +} + + +static void norflash_erase(u32 cmd, u32 addr) +{ + switch (cmd) { + case NORFLASH_ERASE_SECTOR: + cmd = WINBOND_SECTOR_ERASE; + break; + + case NORFLASH_ERASE_BLOCK: + cmd = WINBOND_BLOCK_ERASE; + break; + + case NORFLASH_ERASE_CHIP: + cmd = WINBOND_CHIP_ERASE; + break; + default: + cmd = WINBOND_SECTOR_ERASE; + break; + } + + norflash_write_enable(); + + spi_cs_set_active(); + spi_master_tx_byte(cmd); + norflash_send_addr(addr); + spi_cs_set_idle(); + + norflash_wait_ok(100); +} + +void spi_master_test_code(void) +{ + int buf[256 / sizeof(int)]; + u8 *_buf = (u8 *)buf; + + spi_master_init(); + + norflash_power_release(); + norflash_wait_ok(150); + norflash_power_reset(); + + norflash_read_id(); + + printf("1.norflash_read: \n"); + norflash_read((u8 *)buf, 0, sizeof(buf)); + put_buf(_buf, sizeof(buf)); + + printf("2.norflash_erase: \n"); + norflash_erase(NORFLASH_ERASE_SECTOR, 0); + + printf("3.norflash_read: \n"); + norflash_read((u8 *)buf, 0, sizeof(buf)); + put_buf(_buf, sizeof(buf)); + + for (u32 i = 0; i < sizeof(buf); i++) { + _buf[i] = i; + } + + printf("4.norflash_write: \n"); + norflash_write((u8 *)buf, 0, sizeof(buf)); + + memset(buf, sizeof(buf), 0); + printf("5.norflash_read: \n"); + norflash_read((u8 *)buf, 0, sizeof(buf)); + put_buf(_buf, sizeof(buf)); + + spi_close(); +} + + diff --git a/2.code/2.p11_code/cpu/br28/test.c b/2.code/2.p11_code/cpu/br28/test.c new file mode 100644 index 0000000..815b3a8 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/test.c @@ -0,0 +1,30 @@ +#include "includes.h" + +//====================================// +// FOR TEST CODE // +//====================================// + +// test code: +#define SOFT_INT_INDEX 0 + +___interrupt +static void soft_int_test_isr(void) +{ + static u32 isr_cnt = 0; + + bit_clr_swi(SOFT_INT_INDEX); + printf("%s: %d\n", __func__, isr_cnt++); +} + +void soft_int_test(void) +{ + static u32 set_cnt = 0; + INTALL_HWI(IRQ_SOFT0_IDX, soft_int_test_isr, IRQ_SOFT0_IP); + + while (1) { + delay(1000000); + printf("\n%s: %d\n", __func__, set_cnt++); + bit_set_swi(SOFT_INT_INDEX); + } +} + diff --git a/2.code/2.p11_code/cpu/br28/uart.c b/2.code/2.p11_code/cpu/br28/uart.c new file mode 100644 index 0000000..dd312be --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/uart.c @@ -0,0 +1,157 @@ +#ifdef SUPPORT_MS_EXTENSIONS +#pragma bss_seg(".uart.bss") +#pragma data_seg(".uart.data") +#pragma const_seg(".uart.const") +#pragma code_seg(".uart.text") +#pragma str_literal_override(".uart.text") +#endif /* #ifdef SUPPORT_MS_EXTENSIONS */ + +#include "includes.h" +#include "uart.h" +#include "gpio.h" + +//uart时钟选择: +#define UART_CLK_SEL UART_CLK_RC16M //由主系统gpcnt模块算出rc16m频率,rc16m频率跟pvdd有关,注意配置被覆盖。 +/* #define UART_CLK_SEL UART_CLK_STD_12M //低功耗不能使用该时钟源 */ + +//uart波特率选择: +#define UART_TARGET_BAUD 115200L +//#define UART_TARGET_BAUD 1000000L + +//调试串口选择: P11_UART0/P11_UART1 +#define DEBUG_UART_SELECT P11_UART1 + +//输入选择. 只有UART0有输入功能 +#define DEBUG_UART_RX_ENABLE 0 +#if DEBUG_UART_RX_ENABLE +#define DEBUG_UART_RX_IO IO_PORTB_05 +#define DEBUG_UART_RX_OVERTIME 100 //ms +#endif /* #if DEBUG_UART_RX_ENABLE */ + +static u8 init = 0; + +___interrupt +static void uart0_isr(void) +{ + u8 rx = 0; + + if (UART_RX_PENDING_IS(P11_UART0)) { + rx = UART_BUF_READ(P11_UART0); + UART_RX_PENDING_CLEAR(P11_UART0); + printf("RX pending, rx: 0x%x\n", rx); + } + + if (UART_OT_PENDING_IS(P11_UART0)) { + rx = UART_BUF_READ(P11_UART0); + UART_OT_PENDING_CLEAR(P11_UART0); + printf("OT pending, rx: 0x%x\n", rx); + } +} + +static u32 uart_src_clk_get(void) +{ + u32 freq = 0; + + if (UART_CLK_SEL == UART_CLK_STD_12M) { + SFR(P11_CLOCK->CLK_CON1, 15, 2, 1); //MSYS_BT24M --> P11_BT24M + SFR(P11_CLOCK->CLK_CON1, 17, 3, 1); //STD12M sel P11_BT24M input + SFR(P11_CLOCK->CLK_CON1, 20, 2, 0); // div0 + SFR(P11_CLOCK->CLK_CON1, 22, 2, 1); // div1 + freq = 12000000; + } else if (UART_CLK_SEL == UART_CLK_RC16M) { + freq = 16000000;//(u32)((u32)m2p_message[M2P_RCH_FEQ_H] << 8 | m2p_message[M2P_RCH_FEQ_L]) * 1000; + } else if (UART_CLK_SEL == UART_CLK_SYS_CLK) { + freq = 16000000; + } + + P11_UART_CLK_SEL(UART_CLK_SEL); + + return freq; +} + +void debug_uart_init(u8 tx_port) +{ + u16 baud = (uart_src_clk_get() / UART_TARGET_BAUD) / 4 - 1; + + UART_CON0_CLEAR(DEBUG_UART_SELECT); + UART_CON1_CLEAR(DEBUG_UART_SELECT); + + UART_BAUD_SET(DEBUG_UART_SELECT, baud); + + //tx io inita + gpio_set_output_value(tx_port, 1); + gpio_set_direction(tx_port, 0); + + if (DEBUG_UART_SELECT == P11_UART1) { + gpio_set_fun_output_port(tx_port, P11_FO_UART1_TX, 1, 1); + } else if (DEBUG_UART_SELECT == P11_UART0) { + gpio_set_fun_output_port(tx_port, P11_FO_UART0_TX, 1, 1); + } + +#if DEBUG_UART_RX_ENABLE + u32 ot_value = 0; + if (DEBUG_UART_SELECT == P11_UART0) { + //rx io init: + gpio_set_direction(DEBUG_UART_RX_IO, 1); + gpio_set_pull_up(DEBUG_UART_RX_IO, 1); + gpio_set_pull_down(DEBUG_UART_RX_IO, 0); + gpio_set_die(DEBUG_UART_RX_IO, 1); + //iomc: + gpio_set_fun_input_port(DEBUG_UART_RX_IO, PFI_UART0_RX); + + //rx config: + UART_OT_PENDING_CLEAR(P11_UART0); + UART_RX_PENDING_CLEAR(P11_UART0); + ot_value = (uart_src_clk_get() * DEBUG_UART_RX_OVERTIME) / 1000; + UART_OTCNT_SET(P11_UART0, ot_value); + UART_OT_INT_ENABLE(P11_UART0); + UART_RX_INT_ENABLE(P11_UART0); + UART_RX_ENABLE(P11_UART0); + P11_CLOCK->WKUP_EN |= BIT(IRQ_UART0_IDX); + INTALL_HWI(IRQ_UART0_IDX, uart0_isr, IRQ_UART0_IP); + } +#endif /* #if DEBUG_UART_RX_ENABLE */ + + UART_TX_ENABLE(DEBUG_UART_SELECT); + + init = 1; +} + +__WEAK__ +void putchar(char a) +{ + if (init == 0) { + return; + } + + if (a == '\r') { + return; + } + + local_irq_disable(); + if (a == '\n') { + UART_BUF_WRITE(DEBUG_UART_SELECT, '\r'); + + __asm__ volatile("csync"); + while (!UART_TX_PENDING_IS(DEBUG_UART_SELECT)); + + UART_TX_PENDING_CLEAR(DEBUG_UART_SELECT); + + } + + UART_BUF_WRITE(DEBUG_UART_SELECT, a); + + __asm__ volatile("csync"); + while (!UART_TX_PENDING_IS(DEBUG_UART_SELECT)); + + UART_TX_PENDING_CLEAR(DEBUG_UART_SELECT); + + local_irq_enable(); +} + +__WEAK__ +void putbyte(char a) +{ + putchar(a); +} + diff --git a/2.code/2.p11_code/cpu/br28/vad_api.c b/2.code/2.p11_code/cpu/br28/vad_api.c new file mode 100644 index 0000000..18ab0b1 --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/vad_api.c @@ -0,0 +1,227 @@ +#ifdef SUPPORT_MS_EXTENSIONS +#pragma bss_seg(".vad_api.bss") +#pragma data_seg(".vad_api.data") +#pragma const_seg(".vad_api.const") +#pragma code_seg(".vad_api.text") +#pragma str_literal_override(".vad_api.text") +#endif /* #ifdef SUPPORT_MS_EXTENSIONS */ + + +#include "includes.h" +#include "gp_timer_api.h" +#include "app_config.h" +#include "gpio.h" +#include "vad_hw.h" + +#if CONFIG_VAD_ENABLE + +#define P11_VAD_POST_TO_MSYS() (P11_SYSTEM->P2M_INT_SET |= BIT(P2M_VAD_INDEX)) +#define P11_VAD_P2M_ENABLE() (P11_SYSTEM->P2M_INT_IE |= BIT(P2M_VAD_INDEX)) +#define P11_VAD_P2M_DISABLE() (P11_SYSTEM->P2M_INT_IE &= ~BIT(P2M_VAD_INDEX)) + +enum P11_VAD_CMD_TABLE { + P11_VAD_CMD_START = 0xAA, + P11_VAD_CMD_FRAME, + P11_VAD_CMD_STOP, +}; + +enum M2P_VAD_CMD_TABLE { + M2P_VAD_CMD_INIT = 0x55, + M2P_VAD_CMD_FRAME, + M2P_VAD_CMD_CLOSE, + M2P_VAD_CMD_TEST, +}; + +enum VAD_STATUS_TABLE { + VAD_STATUS_CLOSE = 0, + VAD_STATUS_IDLE, + VAD_STATUS_ACTIVE, +}; + +static struct vad_handle { + u8 status; +}; + +static struct vad_handle vad_hdl = {0}; +#define __this (&vad_hdl) + +static void p11_vad_post_to_main_system(enum P11_VAD_CMD_TABLE cmd) +{ + p2m_message[P2M_MESSAGE_VAD_CMD] = cmd; + + P11_VAD_POST_TO_MSYS(); +} + +void p11_vad_wakeup(void) +{ + __power_recover(); + + __this->status = VAD_STATUS_ACTIVE; +} + +void p11_dvad_start(void) +{ + printf("%s\n", __func__); + + __power_recover(); + + __this->status = VAD_STATUS_ACTIVE; + + p11_vad_post_to_main_system(P11_VAD_CMD_START); +} + + +void p11_vad_update_frame(u8 *buf, u32 len) +{ + static u8 cnt = 0; + + p11_vad_post_to_main_system(P11_VAD_CMD_FRAME); +} + +void p11_dvad_pause(void) +{ + p11_vad_post_to_main_system(P11_VAD_CMD_STOP); +} + +void p11_dvad_stop(void) +{ + printf("%s\n", __func__); + __this->status = VAD_STATUS_IDLE; + p11_vad_post_to_main_system(P11_VAD_CMD_STOP); +} + +/* static struct avad_config avad_cfg; */ +/* static struct dvad_config dvad_cfg; */ + +__NO_INIT__ static int __avad_cfg[CONFIG_P2M_AVAD_CONFIG_SIZE / sizeof(int)] SEC_USED(.m2p_avad_config); +__NO_INIT__ static int __dvad_cfg[CONFIG_P2M_DVAD_CONFIG_SIZE / sizeof(int)] SEC_USED(.m2p_dvad_config); + +static void p11_vad_init(void) +{ + printf("%s\n", __func__); + P11_VAD_P2M_ENABLE(); + + //TODO: init VAD HARDWARE + /************************avad config set********************/ + struct avad_config *avad_cfg = (struct avad_config *)__avad_cfg; + struct dvad_config *dvad_cfg = (struct dvad_config *)__dvad_cfg; + /* + avad_cfg->avad_quantile_p = 3; //0.8 + avad_cfg->avad_gain_db = 10; + avad_cfg->avad_compare_v = 3; + + dvad_cfg->dvad_gain_id = 10; + dvad_cfg->d2a_th_db = 20; + dvad_cfg->d_frame_con = 100; + dvad_cfg->d2a_frame_con = 100; + dvad_cfg->d_stride1 = 3;//<<7 + dvad_cfg->d_stride2 = 5;//<<7 + dvad_cfg->d_low_con_th = 6; + dvad_cfg->d_high_con_th = 3; + */ + + /* printf("avad_cfg @ 0x%x, dvad_cfg @ 0x%x\n", avad_cfg, dvad_cfg); + printf("avad_cfg->avad_th = %d\n", avad_cfg->avad_th); + printf("avad_cfg->quantile_p = %d\n", avad_cfg->quantile_p); + printf("avad_cfg->step = %d\n", avad_cfg->step); + printf("avad_cfg->avad_stride = %d\n", avad_cfg->avad_stride); + printf("avad_cfg->tmp_thl = %d\n", avad_cfg->tmp_thl); + printf("avad_cfg->sig_l = %d\n", avad_cfg->sig_l); + printf("avad_cfg->sig_h = %d\n", avad_cfg->sig_h); + printf("avad_cfg->avad_threshold = %d\n", avad_cfg->avad_threshold); + printf("avad_cfg->num_th = %d\n", avad_cfg->num_th); + printf("avad_cfg->high_num = %d\n", avad_cfg->high_num); + printf("avad_cfg->s_high_con_th = %d\n", avad_cfg->s_high_con_th); + + printf("dvad_cfg->d_low_con_th = %d\n", dvad_cfg->d_low_con_th); + printf("dvad_cfg->d_high_con_th = %d\n", dvad_cfg->d_high_con_th); + printf("dvad_cfg->d_stride1 = %d\n", dvad_cfg->d_stride1); + printf("dvad_cfg->d_stride2 = %d\n", dvad_cfg->d_stride2); + printf("dvad_cfg->st_1 = %d\n", dvad_cfg->st_1); + printf("dvad_cfg->st_2 = %d\n", dvad_cfg->st_2); + printf("dvad_cfg->si_num_th = %d\n", dvad_cfg->si_num_th); + printf("dvad_cfg->sf_con_th = %d\n", dvad_cfg->sf_con_th);*/ + + vad_init(avad_cfg, dvad_cfg); + + __this->status = VAD_STATUS_IDLE; +} + +static void p11_vad_close(void) +{ + __this->status = VAD_STATUS_CLOSE; + + vad_close(); + return; +} + +void p11_vad_test(); +void p11_vad_m2p_handle(void) +{ + u8 cmd = m2p_message[M2P_MESSAGE_VAD_CMD]; + + //printf("%s, cmd = 0x%x\n", __func__, cmd); + switch (cmd) { + case M2P_VAD_CMD_INIT: + p11_vad_init(); + break; + case M2P_VAD_CMD_FRAME: + vad_hw_updata_read_ptr(m2p_message[M2P_MESSAGE_VAD_CBUF_RPTR]); + break; + case M2P_VAD_CMD_CLOSE: + p11_vad_close(); + break; + case M2P_VAD_CMD_TEST: + p11_vad_test(); + break; + default: + break; + } + + return; +} + +//===========================================================================// +// P11_VAD POWER MANAGE // +//===========================================================================// +static enum LOW_POWER_LEVEL vad_level_query(void) +{ + enum LOW_POWER_LEVEL level = LOW_POWER_MODE_DEEP_SLEEP; + + switch (__this->status) { + case VAD_STATUS_CLOSE: + level = LOW_POWER_MODE_DEEP_SLEEP; + break; + case VAD_STATUS_IDLE: + level = LOW_POWER_MODE_SLEEP; + break; + case VAD_STATUS_ACTIVE: + level = LOW_POWER_MODE_IDLE; + break; + default: + level = LOW_POWER_MODE_DEEP_SLEEP; + break; + } + + return level; +} + +static void p11_vad_low_power_enter(enum LOW_POWER_LEVEL level) +{ + return; +} + +static void p11_vad_low_power_exit(enum LOW_POWER_LEVEL level) +{ + return; +} + +REGISTER_LOWPOWER_TARGET(vad_lp_target, 0) = { + .name = "vad", + .level = vad_level_query, + .enter = p11_vad_low_power_enter, + .exit = p11_vad_low_power_exit, +}; + + +#endif /* #if CONFIG_VAD_ENABLE */ diff --git a/2.code/2.p11_code/cpu/br28/vad_develop.c b/2.code/2.p11_code/cpu/br28/vad_develop.c new file mode 100644 index 0000000..e1c3a7c --- /dev/null +++ b/2.code/2.p11_code/cpu/br28/vad_develop.c @@ -0,0 +1,78 @@ +/***************************************************************** +>file name : vad_develop.c +>create time : Thu 28 Apr 2022 07:11:24 PM CST +*****************************************************************/ +#include "includes.h" +/******************************************************* + * DVAD算法模块开发说明 + * 1、默认使用杰理api,命名为jl_dvad_xxx + * 2、第三方算法开发,需将对应接口替换为自身算法模块 + * + *******************************************************/ +extern const int CONFIG_DVAD_DEVELOP_ENABLE; + +extern void *jl_dvad_open(void *cfg); +extern int jl_dvad_get_mic_gain(void *handle); +extern int jl_dvad_detect(void *handle, short *data, int samples); +extern void jl_dvad_close(void *handle); + +void *dvad_open(void *cfg) +{ + if (CONFIG_DVAD_DEVELOP_ENABLE == 0) { + return jl_dvad_open(cfg); + } + + /*其他算法开发*/ + if (CONFIG_DVAD_DEVELOP_ENABLE == 1) { + return NULL; + } + + return NULL; +} + +int dvad_get_mic_gain(void *handle) +{ + if (CONFIG_DVAD_DEVELOP_ENABLE == 0) { + return jl_dvad_get_mic_gain(handle); + } + + if (CONFIG_DVAD_DEVELOP_ENABLE == 1) { + return 0; + } + + return 0; +} + +/* + * 参数说明 : handle - 算法私有数据 + * data - PCM采样数据 + * samples - 音频采样点数 + * 返回值 : 0 - 保持原有状态不变 + * 1 - DVAD检测中 + * 2 - DVAD检测到语音 + * 3 - DVAD进入待机 + * + */ +int dvad_detect(void *handle, short *data, int samples) +{ + if (CONFIG_DVAD_DEVELOP_ENABLE == 0) { + return jl_dvad_detect(handle, data, samples); + } + + if (CONFIG_DVAD_DEVELOP_ENABLE == 1) { + return 0; + } + + return 0; +} + +void dvad_close(void *handle) +{ + if (CONFIG_DVAD_DEVELOP_ENABLE == 0) { + return jl_dvad_close(handle); + } + + if (CONFIG_DVAD_DEVELOP_ENABLE == 1) { + + } +} diff --git a/2.code/2.p11_code/include/cpu/br28/common.h b/2.code/2.p11_code/include/cpu/br28/common.h new file mode 100644 index 0000000..e9c6fe1 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/common.h @@ -0,0 +1,24 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +void delay(u32 cnt); +void udelay(u32 us); +void mdelay(u32 ms); +void debug_io_1(void); +void debug_io_0(void); +void debug_io(void); + + +#define ASSERT(a,...) \ + do { \ + if(!(a)){ \ + printf("file:%s, line:%d", __FILE__, __LINE__); \ + printf("ASSERT-FAILD: "#a" "__VA_ARGS__); \ + while(1); \ + } \ + }while(0); + + + + +#endif /* #ifndef _COMMON_H_ */ diff --git a/2.code/2.p11_code/include/cpu/br28/debug.h b/2.code/2.p11_code/include/cpu/br28/debug.h new file mode 100644 index 0000000..593f20c --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/debug.h @@ -0,0 +1,8 @@ +#ifndef _DUBUG_H_ +#define _DUBUG_H_ + +void exception_analyze(u32 *p_sp); +void debug_init(void); +void debug_test(); + +#endif /* #ifndef _DUBUG_H_ */ diff --git a/2.code/2.p11_code/include/cpu/br28/gp_timer_api.h b/2.code/2.p11_code/include/cpu/br28/gp_timer_api.h new file mode 100644 index 0000000..fa41779 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/gp_timer_api.h @@ -0,0 +1,21 @@ +#ifndef __GP_TIMER_API_H__ +#define __GP_TIMER_API_H__ + + +void gp_timer_init(P11_GPTMR_TypeDef *gp_timer, u32 us); + +void gp_timer_close(P11_GPTMR_TypeDef *gp_timer); + +void gp_timer_register_irq(P11_GPTMR_TypeDef *gp_timer, void (*handle)(void)); + +void gp_timer_unregister_irq(P11_GPTMR_TypeDef *gp_timer); + +void gp_timer_output_pwm(P11_GPTMR_TypeDef *gp_timer, u32 gpio, u32 freq, u32 duty); + +enum GP_TIMER_CAPTURE_EDGE_TABLE { + GP_TIMER_CAPTURE_EDGE_UP = 0, + GP_TIMER_CAPTURE_EDGE_DOWN, +}; +void gp_timer_capture(P11_GPTMR_TypeDef *gp_timer, u32 gpio, enum GP_TIMER_CAPTURE_EDGE_TABLE edge, u8 irflt_enable); + +#endif /* #ifndef __GP_TIMER_API_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/gpio.h b/2.code/2.p11_code/include/cpu/br28/gpio.h new file mode 100644 index 0000000..8cf9e90 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/gpio.h @@ -0,0 +1,118 @@ +/********************************************************************************************* + * Filename : gpio.h + + * Description : 本文件存放p11 gpio的接口函数和宏定义 + + * Author : MoZhiYe + + * Email : mozhiye@zh-jieli.com + + * Last modifiled : 2021-05-17 09:00 + + * Copyright:(c)JIELI 2021-2029 @ , All Rights Reserved. +*********************************************************************************************/ + +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#define IO_GROUP_NUM 16 + +//PB0 ~ PB13 +#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_PORTB_09 (IO_GROUP_NUM * 1 + 9) +#define IO_PORTB_10 (IO_GROUP_NUM * 1 + 10) +#define IO_PORTB_11 (IO_GROUP_NUM * 1 + 11) +// #define IO_PORTB_12 (IO_GROUP_NUM * 1 + 12) +// #define IO_PORTB_13 (IO_GROUP_NUM * 1 + 13) +// #define IO_PORTB_14 (IO_GROUP_NUM * 1 + 14) +// #define IO_PORTB_15 (IO_GROUP_NUM * 1 + 15) + +#define IO_MAX_NUM IO_PORTB_11 + +#ifndef EINVAL +#define EINVAL 22 /* Invalid argument */ +#endif /* #ifndef EINVAL */ + +#ifndef EFAULT +#define EFAULT 14 /* Bad address */ +#endif /* #ifndef EFAULT */ + +//===================================================// +// BR28 DEBUG IO +//===================================================// +#define DEBUG_GPIO IO_PORTB_03 + +#define DEBUG_IO_1() //{P11_PORT->PB_OUT |= BIT(DEBUG_GPIO-IO_PORTB_00), P11_PORT->PB_SEL |= BIT(DEBUG_GPIO-IO_PORTB_00), P11_PORT->PB_DIR &= ~BIT(DEBUG_GPIO-IO_PORTB_00);} +#define DEBUG_IO_0() //{P11_PORT->PB_OUT &= ~BIT(DEBUG_GPIO-IO_PORTB_00), P11_PORT->PB_SEL |= BIT(DEBUG_GPIO-IO_PORTB_00), P11_PORT->PB_DIR &= ~BIT(DEBUG_GPIO-IO_PORTB_00);} + +#define DEBUG_IO_TEST_1() //{P11_PORT->PB_OUT |= BIT(DEBUG_GPIO-IO_PORTB_00), P11_PORT->PB_SEL |= BIT(DEBUG_GPIO-IO_PORTB_00),\ +P11_PORT->PB_DIR &= ~BIT(DEBUG_GPIO - IO_PORTB_00); +// } + +#define DEBUG_IO_TEST_0() //{P11_PORT->PB_OUT &= ~BIT(DEBUG_GPIO-IO_PORTB_00), P11_PORT->PB_SEL |= BIT(DEBUG_GPIO-IO_PORTB_00),\ +P11_PORT->PB_DIR &= ~BIT(DEBUG_GPIO - IO_PORTB_00); +// } +//===================================================// +// BR28 P11 Crossbar API +//===================================================// + +enum OCH_SIGNAL_TABLE { + OCH_SIGNAL_RC250K = 1, + OCH_SIGNAL_RC16M, + OCH_SIGNAL_BT_OSC, + OCH_SIGNAL_LRC_OSC, + OCH_SIGNAL_RTC_OSC, + OCH_SIGNAL_SYS_CLK, + OCH_SIGNAL_UART1_TX, + OCH_SIGNAL_SLEEP_R, + OCH_SIGNAL_LCTMU_TEST, +}; + +enum PORT_ICHX_SEL { + ICHX_GP_ICH0, + ICHX_GP_ICH1, + ICHX_GP_ICH2, + ICHX_P33_PORT_IN, + ICHX_GPTMR0_PWM, + ICHX_GPTMR1_PWM, +}; + +enum PFI_TABLE { + PFI_GP_ICH0 = ((u32)(&(P11_IMAP->P11_FI_GP_ICH0))), + PFI_GP_ICH1 = ((u32)(&(P11_IMAP->P11_FI_GP_ICH1))), + PFI_GP_ICH2 = ((u32)(&(P11_IMAP->P11_FI_GP_ICH2))), + PFI_UART0_RX = ((u32)(&(P11_IMAP->P11_FI_UART0_RX))), + PFI_SPI_DI = ((u32)(&(P11_IMAP->P11_FI_SPI_DI))), + PFI_IIC_SCL = ((u32)(&(P11_IMAP->P11_FI_IIC_SCL))), + PFI_IIC_SDA = ((u32)(&(P11_IMAP->P11_FI_IIC_SDA))), + PFI_DMIC_DAT = ((u32)(&(P11_IMAP->P11_FI_DMIC_DAT))), +}; + +int gpio_set_direction(u32 gpio, u32 dir); + +int gpio_set_output_value(u32 gpio, u32 value); + +int gpio_set_pull_up(u32 gpio, u32 value); + +int gpio_set_pull_down(u32 gpio, int value); + +int gpio_set_die(u32 gpio, int value); + +int gpio_set_dieh(u32 gpio, int value); + +int gpio_read(u32 gpio); + +int gpio_set_fun_output_port(u32 gpio, u32 fun_index, u8 dir_ctl, u8 data_ctl); + +int gpio_set_fun_input_port(u32 gpio, enum PFI_TABLE pfun); + + +#endif /* #ifndef __GPIO_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/hwi.h b/2.code/2.p11_code/include/cpu/br28/hwi.h new file mode 100644 index 0000000..8493e45 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/hwi.h @@ -0,0 +1,78 @@ +#ifndef __ASS_Q32S_HWI__ +#define __ASS_Q32S_HWI__ + +//*********************************************************************************// +// Module name : hwi.h // +// Description : q32DSP interrupt head file // +// By Designer : zequan_liu // +// Dat changed : // +//*********************************************************************************// + + +#define IRQ_EXCEPTION_IDX 0 +#define IRQ_SOFT0_IDX 1 +#define IRQ_M2P_IDX 2 +#define IRQ_P33_IDX 3 +#define IRQ_WDT_IDX 4 +#define IRQ_SPI_IDX 5 +#define IRQ_UART0_IDX 6 +#define IRQ_UART1_IDX 7 +#define IRQ_IIC_IDX 8 +#define IRQ_LP_TMR0_IDX 9 +#define IRQ_LP_TMR1_IDX 10 +#define IRQ_LP_TMR2_IDX 11 +#define IRQ_LP_TMR3_IDX 12 +#define IRQ_GP_TMR0_IDX 13 +#define IRQ_GP_TMR1_IDX 14 +#define IRQ_LP_CTM_IDX 15 +#define IRQ_LP_VAD_IDX 16 + +//---------------------------------------------// +// interrupt install +//---------------------------------------------// + +void reg_set_ip(unsigned char index, unsigned char dat); +void bit_set_ie(unsigned char index); +void bit_clr_ie(unsigned char index); +void bit_set_swi(unsigned char index); +void bit_clr_swi(unsigned char index); + +#define INTALL_HWI(a,b,c) HWI_Install(a, (unsigned int)b, c) +void HWI_Install(unsigned char index, unsigned int isr, unsigned char priority); + +//---------------------------------------------// +// core_num +//---------------------------------------------// + +static inline int core_num(void) +{ + u32 num; + asm volatile("%0 = cnum" : "=r"(num) :); + return num; +} + +//---------------------------------------------// +// interrupt enable +//---------------------------------------------// + +#define ENABLE_INT enable_int +#define enable_int() local_irq_enable() + +#define DISABLE_INT disable_int +#define disable_int() local_irq_disable() + +#define ___interrupt __attribute__((interrupt(""))) + + +void local_irq_disable(); +void local_irq_enable(); + +void irq_disable_core(); +void irq_enable_core(); + +//*********************************************************************************// +// // +// end of this module // +// // +//*********************************************************************************// +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/iic_api.h b/2.code/2.p11_code/include/cpu/br28/iic_api.h new file mode 100644 index 0000000..a5d4a18 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/iic_api.h @@ -0,0 +1,22 @@ +#ifndef __IIC_API_H__ +#define __IIC_API_H__ + +//=========================================================================// +// IIC MASTER API // +//=========================================================================// +int hw_iic_init(void); +void hw_iic_close(void); +void hw_iic_start(void); +void hw_iic_stop(void); +u8 hw_iic_master_tx_byte(u8 data); +u8 hw_iic_master_rx_byte(u8 ack); +int hw_iic_master_read_buf(void *buf, int len); +int hw_iic_master_write_buf(const void *buf, int len); + +//=========================================================================// +// IIC SLAVE API // +//=========================================================================// +// void iic_slave_init(void); + + +#endif /* #ifndef __IIC_API_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/iic_hw.h b/2.code/2.p11_code/include/cpu/br28/iic_hw.h new file mode 100644 index 0000000..5250dae --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/iic_hw.h @@ -0,0 +1,41 @@ +#ifndef __IIC_HW_H__ +#define __IIC_HW_H__ + +//======================================================// +// IIC HW DEFINE // +//======================================================// +//------------------- P11_IIC->CON0 +#define IIC_CON0_CLEAR() (P11_IIC->CON0 = 0) +#define IIC_BYTE_PENDING_IS() (P11_IIC->CON0 & BIT(15)) +#define IIC_BYTE_PENDING_CLEAR() (P11_IIC->CON0 |= BIT(14)) +#define IIC_END_PENDING_IS() (P11_IIC->CON0 & BIT(13)) +#define IIC_END_PENDING_CLEAR() (P11_IIC->CON0 |= BIT(12)) +#define IIC_END_PENDING_INT_ENABLE(v) SFR(P11_IIC->CON0, 10, 1, v) +#define IIC_IO_FILTER_INPUT_ENABLE(v) SFR(P11_IIC->CON0, 9, 1, v) +#define IIC_INT_ENABLE(v) SFR(P11_IIC->CON0, 8, 1, v) +#define IIC_TRANSMIT_ACK_IS() (P11_IIC->CON0 & BIT(7)) +#define IIC_RECEIVE_ACK_SET(v) SFR(P11_IIC->CON0, 6, 1, v) +#define IIC_MASTER_RESTART_SET(v) SFR(P11_IIC->CON0, 5, 1, v) +#define IIC_MASTER_END_SET(v) SFR(P11_IIC->CON0, 4, 1, v) +#define IIC_DIR_TRANSMIT() (P11_IIC->CON0 &= ~BIT(3)) +#define IIC_DIR_RECEIVE() (P11_IIC->CON0 |= BIT(3)) +#define IIC_CONFIG_DONE() (P11_IIC->CON0 |= BIT(2)) +#define IIC_MASTER_MODE() (P11_IIC->CON0 &= ~BIT(1)) +#define IIC_SLAVE_MODE() (P11_IIC->CON0 |= BIT(1)) +#define IIC_MODULE_ENABLE(v) SFR(P11_IIC->CON0, 0, 1, v) + +//------------------- P11_IIC->CON1 +#define IIC_CON1_CLEAR() (P11_IIC->CON1 = 0) +#define IIC_START_PENDING_IS() (P11_IIC->CON1 & BIT(15)) +#define IIC_START_PENDING_CLEAR() (P11_IIC->CON1 |= BIT(14)) +#define IIC_SLAVE_IGNORE_BUS_MODE(v) SFR(P11_IIC->CON1, 13, 1, v) + +//------------------- P11_IIC->BAUD +#define IIC_MASTER_BAUD_CONFIG(v) (P11_IIC->BAUD = v) +#define IIC_SLAVE_ADDR_CONFIG(v) SFR(P11_IIC->BAUD, 1, 7, v) + +//------------------- P11_IIC->BUF +#define IIC_READ_BUF() (P11_IIC->BUF) +#define IIC_WRITE_BUF(v) (P11_IIC->BUF = v) + +#endif /* #ifndef __IIC_HW_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/iic_soft.h b/2.code/2.p11_code/include/cpu/br28/iic_soft.h new file mode 100644 index 0000000..5f8bf05 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/iic_soft.h @@ -0,0 +1,27 @@ +#ifndef __IIC_SOFT_H__ +#define __IIC_SOFT_H__ + +#include "typedef.h" +typedef const int soft_iic_dev; + +struct soft_iic_config { + int scl; + int sda; + u32 delay; + u8 io_pu; +}; + +extern const struct soft_iic_config soft_iic_cfg[]; + +int soft_iic_init(soft_iic_dev iic); +void soft_iic_uninit(soft_iic_dev iic); +void soft_iic_suspend(soft_iic_dev iic); +void soft_iic_resume(soft_iic_dev iic); +void soft_iic_start(soft_iic_dev iic); +void soft_iic_stop(soft_iic_dev iic); +u8 soft_iic_tx_byte(soft_iic_dev iic, u8 byte); +u8 soft_iic_rx_byte(soft_iic_dev iic, u8 ack); +int soft_iic_read_buf(soft_iic_dev iic, void *buf, int len); +int soft_iic_write_buf(soft_iic_dev iic, const void *buf, int len); + +#endif /* #ifndef __IIC_SOFT_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/includes.h b/2.code/2.p11_code/include/cpu/br28/includes.h new file mode 100644 index 0000000..fdbbaf0 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/includes.h @@ -0,0 +1,28 @@ +//*********************************************************************************// +// Module name : include.h // +// Description : all head file include // +// By Designer : ZeQuan_liu // +// Dat changed : // +//*********************************************************************************// + +#ifndef __INCLUDES__ +#define __INCLUDES__ + +#include "typedef.h" +#include "hwi.h" +#include "printf.h" +#include "string.h" +#include "common.h" +#include "interrupt_hw.h" +#include "power_interface.h" +// #include "power_manage.h" + +//#include "assert.h" + +#endif + +//*********************************************************************************// +// // +// end of this module // +// // +//*********************************************************************************// diff --git a/2.code/2.p11_code/include/cpu/br28/interrupt_hw.h b/2.code/2.p11_code/include/cpu/br28/interrupt_hw.h new file mode 100644 index 0000000..885792a --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/interrupt_hw.h @@ -0,0 +1,39 @@ +#ifndef __INTERRUPT_HW__ +#define __INTERRUPT_HW__ + + +/* +wkup:优先级3 + | + \|/ +ctmu:优先级2 + | + \|/ +pmu:优先级1 + | + \|/ +other:优先级0 +*/ + +#define IRQ_EXCEPTION_IP 0 +#define IRQ_M2P_IP 1 +#define IRQ_P33_IP 3 +#define IRQ_SOFT0_IP 0 +#define IRQ_WDT_IP 0 +#define IRQ_SPI_IP 0 +#define IRQ_UART0_IP 0 +#define IRQ_UART1_IP 0 +#define IRQ_IIC_IP 0 +#define IRQ_LP_TMR0_IP 1 +#define IRQ_LP_TMR1_IP 0 +#define IRQ_LP_TMR2_IP 0 +#define IRQ_LP_TMR3_IP 0 +#define IRQ_GP_TMR0_IP 0 +#define IRQ_GP_TMR1_IP 0 +#define IRQ_LP_CTM_IP 2 +#define IRQ_LP_VAD_IP 0 + + + + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/lp_timer_api.h b/2.code/2.p11_code/include/cpu/br28/lp_timer_api.h new file mode 100644 index 0000000..7636b63 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/lp_timer_api.h @@ -0,0 +1,9 @@ +#ifndef __LP_TIMER_API_H__ +#define __LP_TIMER_API_H__ + + +void lp_timer_init(P11_LPTMR_TypeDef *lp_timer, u32 us); + +void lp_timer_register_irq(P11_LPTMR_TypeDef *lp_timer, void (*handle)(void)); + +#endif /* #ifndef __LP_TIMER_API_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/power/lp_ipc.h b/2.code/2.p11_code/include/cpu/br28/power/lp_ipc.h new file mode 100644 index 0000000..c76b42e --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/lp_ipc.h @@ -0,0 +1,9 @@ +#ifndef __LP_IPC_H__ +#define __LP_IPC_H__ + +u32 get_lrc_hz(); + +void lp_ipc_init(); + + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/power/p11.h b/2.code/2.p11_code/include/cpu/br28/power/p11.h new file mode 100644 index 0000000..33b11a2 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p11.h @@ -0,0 +1,23 @@ +/********************************************************************************************* + * Filename : p11.h + + * Description : + + * Author : Bingquan + + * Email : caibingquan@zh-jieli.com + + * Last modifiled : 2019-12-09 10:21 + + * Copyright:(c)JIELI 2011-2019 @ , All Rights Reserved. +*********************************************************************************************/ +#ifndef __P11_H__ +#define __P11_H__ + +#include "p11_csfr.h" +#include "p11_sfr.h" +#include "p11_app.h" + +#endif /* #ifndef __P11_H__ */ + + diff --git a/2.code/2.p11_code/include/cpu/br28/power/p11_app.h b/2.code/2.p11_code/include/cpu/br28/power/p11_app.h new file mode 100644 index 0000000..50e072c --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p11_app.h @@ -0,0 +1,410 @@ +#ifndef __P11_APP_H__ +#define __P11_APP_H__ + +//-----special operation---------- +//P11_CLOCK->PWR_CON +#define RESET_FLAG() (P11_CLOCK->PWR_CON & BIT(7)) + +#define RESET_FLAG_CLR() P11_CLOCK->PWR_CON |= BIT(6); \ + NOP() + +#define INIT_FLAG_SET() P11_CLOCK->PWR_CON |= BIT(5); \ + NOP() + +//-----special operation---------- +#define SET_RECOVER_FLAG() P11_CLOCK->PWR_CON |= BIT(5); \ + NOP() + +#define INIT_FLAG_GET() (P11_CLOCK->PWR_CON &= ~BIT(5)) + +#define INIT_FLAG_CLR() P11_CLOCK->PWR_CON &= ~BIT(5); \ + NOP() + +#define SOFT_RESET_SET() P11_CLOCK->PWR_CON |= BIT(4); \ + NOP() + +#define SSMODE_NO_DLY() P11_CLOCK->PWR_CON |= BIT(3); \ + NOP() + +#define SSMODE_DLY() P11_CLOCK->PWR_CON &= ~BIT(3); \ + NOP() + +//========================== P11_SYSTEM->P2M_CLK_CON0 +#define P2M_RC_250K BIT(0) +#define P2M_RC_16M BIT(1) +#define P2M_BT_OSC BIT(2) +#define P2M_LRC BIT(3) +#define P2M_CLK_SET(x) P11_SYSTEM->P2M_CLK_CON0 = ((P11_SYSTEM->P2M_CLK_CON0 & ~0x1f) | (x) & 0x1f) + +#define P2M_CLK_GET(x) (P11_SYSTEM->P2M_CLK_CON0 & 0x1f) + +#define LED_CLK_SEL(x) P11_SYSTEM->P2M_CLK_CON0 = ((P11_SYSTEM->P2M_CLK_CON0 & ~0xe0) | (x) << 5) +enum { + LED_CLK_SEL_NONE = 0, + LED_CLK_SEL_RC_250K, + LED_CLK_SEL_RC_16M, + LED_CLK_SEL_BT_OSC, + LED_CLK_SEL_LRC, +}; + +#define GET_LED_CLK_SEL(x) (P11_SYSTEM->P2M_CLK_CON0 & 0xe0) + +//========================== P11_SYSTEM->P11_SYS_CON0 +#define MSYS_STATE_SET(x) P11_SYSTEM->P11_SYS_CON0 = ((P11_SYSTEM->P11_SYS_CON0 & ~0x0f) | (x) & 0xf) +enum { + MSYS_STATE_NORMAL = 0, + MSYS_STATE_PWR_DOWN, + MSYS_STATE_PWR_OFF, + MSYS_STATE_SOFT_PWR_OFF, + MSYS_STATE_LIGHT_PWR_DOWN, +}; + +#define MSYS_STATE_GET() (P11_SYSTEM->P11_SYS_CON0 & 0xf) +#define P11_KEY_CLR() P11_SYSTEM->P11_SYS_CON0 |= BIT(4) +#define P33_WKUP_MSYS_ENABLE() P11_SYSTEM->P11_SYS_CON0 |= BIT(5) +#define P33_WKUP_MSYS_DISABLE() P11_SYSTEM->P11_SYS_CON0 &= ~BIT(5) +#define GET_P33_WKUP_MSYS() (P11_SYSTEM->P11_SYS_CON0 & BIT(5) ? 1:0) +#define SET_P33_WKUP_MSYS(en) SFR(P11_SYSTEM->P11_SYS_CON0, 5, 1, en) +#define P33_WKUP_IE_SET() P11_SYSTEM->P11_SYS_CON0 |= BIT(6) +#define P33_WKUP_IE_CLR() P11_SYSTEM->P11_SYS_CON0 &= ~BIT(6) +#define P33_WKUP_PND() (P11_SYSTEM->P11_SYS_CON0 & BIT(7)) + +//========================== P11_SYSTEM->P11_SYS_CON1 +#define P11_ISOLATE_ENABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(0) +#define P11_ISOLATE_DISABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(0) +#define P11_RX_DISABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(1) +#define P11_RX_ENABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(1) +#define P11_TX_DISABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(2) +#define P11_TX_ENABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(2) +#define P2M_RESET_ENABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(3) +#define P2M_RESET_DISABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(3) +#define M2P_RESET_MASK_ENABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(4) +#define M2P_RESET_MASK_DISABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(4) +#define MSYS_DPOR_EN_ENABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(5) +#define MSYS_DPOR_EN_DISABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(5) +#define MSYS_DPOR_ISO_ENABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(6) +#define MSYS_DPOR_ISO_DISABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(6) +#define MSYS_IO_LATCH_ENABLE() P11_SYSTEM->P11_SYS_CON1 |= BIT(7) +#define MSYS_IO_LATCH_DISABLE() P11_SYSTEM->P11_SYS_CON1 &= ~BIT(7) + +#define MSYS_VDD_POR() (P11_SYSTEM->P11_SYS_CON1 & BIT(8)) +#define MSYS_RESET() (P11_SYSTEM->P11_SYS_CON1 & BIT(9)) + + +//========================== P11_WDT->CON +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, +}; + +#define WDT_PND() (P11_WDT->CON & BIT(7)) +#define WDT_CLR_PND() P11_WDT->CON |= BIT(6) +#define WDT_MODE_RESET() P11_WDT->CON &= ~BIT(5) +#define WDT_MODE_INT() P11_WDT->CON |= BIT(5) +#define WDT_ENABLE() P11_WDT->CON |= BIT(4) +#define WDT_DISABLE() P11_WDT->CON &= ~BIT(4) +#define WDT_TIMEOUT(x) P11_WDT->CON &= ~0xf; P11_WDT->CON |= x & 0xf + +#define WDT_EXCEPTION_EN() P11_WDT->CON |= BIT(8) +#define WDT_EXCEPTION_DIS() P11_WDT->CON &= ~BIT(8) + +/* + *------------------- P11_CLOCK->CLK_CON + */ + + +enum UART_CLK_TABLE { + UART_CLK_DIABLE = 0, + UART_CLK_STD_12M, + UART_CLK_RC16M, + UART_CLK_SYS_CLK, +}; +#define P11_UART_CLK_SEL(x) SFR(P11_CLOCK->CLK_CON2, 2, 2, x) + +//=============================================================// +// VAD lowpower时钟选项 // +//=============================================================// +enum VAD_LP_CLOCK_SOURCE { + VAD_LP_CLK_BTOSC, + VAD_LP_CLK_RC16M, + VAD_LP_CLK_LRC, +}; +//=============================================================// +// M2P中断消息列表 // +//=============================================================// + +/* + * Must Sync to MSYS code + */ + +enum { + M2P_LP_INDEX = 0, + M2P_PF_INDEX, + M2P_LLP_INDEX, + M2P_P33_INDEX, + M2P_SF_INDEX, + M2P_CTMU_INDEX, + M2P_CCMD_INDEX, //common cmd + M2P_VAD_INDEX, + M2P_USER_INDEX, + M2P_WDT_INDEX, +}; + +//=============================================================// +// P2M中断消息列表 // +//=============================================================// +enum { + P2M_LP_INDEX = 0, + P2M_PF_INDEX, + P2M_LLP_INDEX, + P2M_WK_INDEX, + P2M_WDT_INDEX, + P2M_LP_INDEX2, + P2M_CTMU_INDEX, + P2M_CTMU_POWUP, + P2M_REPLY_CCMD_INDEX, //reply common cmd + P2M_VAD_INDEX, + P2M_USER_INDEX, + P2M_BANK_INDEX, + P2M_LPTMR_INDEX, +}; + +//=============================================================// +// P2M通信消息列表 // +//=============================================================// +enum { + P2M_MESSAGE_WKUP_SRC = 0, + P2M_MESSAGE_WKUP_PND0, + P2M_MESSAGE_WKUP_PND1, + P2M_REPLY_COMMON_CMD, + P2M_MESSAGE_VAD_CMD, + P2M_MESSAGE_VAD_CBUF_WPTR, + P2M_MESSAGE_BANK_ADR_L, + P2M_MESSAGE_BANK_ADR_H, + P2M_MESSAGE_BANK_INDEX, + P2M_MESSAGE_BANK_ACK, + P2M_P11_HEAP_BEGIN_ADDR_L = 10, + P2M_P11_HEAP_BEGIN_ADDR_H, + P2M_P11_HEAP_SIZE_L, + P2M_P11_HEAP_SIZE_H, + + + P2M_MESSAGE_CTMU_KEY_EVENT = 16, + P2M_MESSAGE_CTMU_KEY_CNT, + P2M_MESSAGE_CTMU_WKUP_MSG, + P2M_MESSAGE_CTMU_EARTCH_EVENT, + + P2M_MESSAGE_CTMU_CH0_L_RES, + P2M_MESSAGE_CTMU_CH0_H_RES, + P2M_MESSAGE_CTMU_CH1_L_RES, + P2M_MESSAGE_CTMU_CH1_H_RES, + P2M_MESSAGE_CTMU_CH2_L_RES, + P2M_MESSAGE_CTMU_CH2_H_RES, + P2M_MESSAGE_CTMU_CH3_L_RES, + P2M_MESSAGE_CTMU_CH3_H_RES, + P2M_MESSAGE_CTMU_CH4_L_RES, + P2M_MESSAGE_CTMU_CH4_H_RES, + + P2M_MESSAGE_CTMU_EARTCH_L_IIR_VALUE, + P2M_MESSAGE_CTMU_EARTCH_H_IIR_VALUE, + P2M_MESSAGE_CTMU_EARTCH_L_TRIM_VALUE, + P2M_MESSAGE_CTMU_EARTCH_H_TRIM_VALUE, + P2M_MESSAGE_CTMU_EARTCH_L_DIFF_VALUE, + P2M_MESSAGE_CTMU_EARTCH_H_DIFF_VALUE, + + P2M_MESSAGE_AWKUP_P_PND, + P2M_MESSAGE_AWKUP_N_PND, + P2M_MESSAGE_WKUP_RTC, + + //继续从这个添加 + + + + // + P2M_USER_PEND = 56,//传感器使用或者开放客户使用 + P2M_USER_MSG_TYPE = 57, + P2M_USER_MSG_LEN0 = 58, + P2M_USER_MSG_LEN1 = 59, + P2M_USER_ADDR0 = 60, + P2M_USER_ADDR1 = 61, + P2M_USER_ADDR2 = 62, + P2M_USER_ADDR3 = 63, +}; + +//=============================================================// +// M2P通信消息列表 // +//=============================================================// +enum { + /*===========power=============*/ + M2P_LRC_PRD = 0, + M2P_MESSAGE_WVDD, + M2P_LRC_TMR_50us, + M2P_LRC_TMR_200us, + M2P_LRC_TMR_600us, + M2P_VDDIO_KEEP, + M2P_LRC_KEEP, + M2P_COMMON_CMD, + M2P_MESSAGE_VAD_CMD, + M2P_MESSAGE_VAD_CBUF_RPTR, + M2P_VDDIO_KEEP_TYPE = 10, + M2P_RCH_FEQ_H, + M2P_MEM_CONTROL, + M2P_BTOSC_KEEP, + M2P_CTMU_KEEP, + M2P_RTC_KEEP, + M2P_WDT_SYNC, + M2P_PVDD_LEVEL_SLEEP_TRIM, + + M2P_LRC_FEQ2 = 18, + M2P_LRC_FEQ1, + M2P_LRC_FEQ0, + + M2P_LIGHT_PDOWN_DVDD_VOL, + + M2P_MESSAGE_CTMU_CMD = 24, + M2P_MESSAGE_CTMU_MSG, + M2P_CTMU_PRD0, + M2P_CTMU_PRD1, + M2P_CTMU_CH_ENABLE, + M2P_CTMU_CH_DEBUG, + M2P_CTMU_CH_CFG, + M2P_CTMU_CH_WAKEUP_EN, + M2P_CTMU_EARTCH_CH, + M2P_CTMU_TIME_BASE, + + M2P_MESSAGE_CTMU_LONG_TIME_L, + M2P_MESSAGE_CTMU_LONG_TIME_H, + M2P_MESSAGE_CTMU_HOLD_TIME_L, + M2P_MESSAGE_CTMU_HOLD_TIME_H, + M2P_MESSAGE_CTMU_SOFTOFF_LONG_TIME_L, + M2P_MESSAGE_CTMU_SOFTOFF_LONG_TIME_H, + M2P_CTMU_LONG_PRESS_RESET_TIME_VALUE_L, //长按复位 + M2P_CTMU_LONG_PRESS_RESET_TIME_VALUE_H, + + M2P_CTMU_INEAR_VALUE_L, + M2P_CTMU_INEAR_VALUE_H, + M2P_CTMU_OUTEAR_VALUE_L, + M2P_CTMU_OUTEAR_VALUE_H, + M2P_MESSAGE_CTMU_EARTCH_TRIM_VALUE_L, + M2P_MESSAGE_CTMU_EARTCH_TRIM_VALUE_H, + + M2P_MESSAGE_CTMU_CH0_CFG0L = 48, + M2P_MESSAGE_CTMU_CH0_CFG0H, + M2P_MESSAGE_CTMU_CH0_CFG1L, + M2P_MESSAGE_CTMU_CH0_CFG1H, + M2P_MESSAGE_CTMU_CH0_CFG2L, + M2P_MESSAGE_CTMU_CH0_CFG2H, + + M2P_MESSAGE_CTMU_CH1_CFG0L = 56, + M2P_MESSAGE_CTMU_CH1_CFG0H, + M2P_MESSAGE_CTMU_CH1_CFG1L, + M2P_MESSAGE_CTMU_CH1_CFG1H, + M2P_MESSAGE_CTMU_CH1_CFG2L, + M2P_MESSAGE_CTMU_CH1_CFG2H, + + M2P_MESSAGE_CTMU_CH2_CFG0L = 64, + M2P_MESSAGE_CTMU_CH2_CFG0H, + M2P_MESSAGE_CTMU_CH2_CFG1L, + M2P_MESSAGE_CTMU_CH2_CFG1H, + M2P_MESSAGE_CTMU_CH2_CFG2L, + M2P_MESSAGE_CTMU_CH2_CFG2H, + + M2P_MESSAGE_CTMU_CH3_CFG0L = 72, + M2P_MESSAGE_CTMU_CH3_CFG0H, + M2P_MESSAGE_CTMU_CH3_CFG1L, + M2P_MESSAGE_CTMU_CH3_CFG1H, + M2P_MESSAGE_CTMU_CH3_CFG2L, + M2P_MESSAGE_CTMU_CH3_CFG2H, + + M2P_MESSAGE_CTMU_CH4_CFG0L = 80, + M2P_MESSAGE_CTMU_CH4_CFG0H, + M2P_MESSAGE_CTMU_CH4_CFG1L, + M2P_MESSAGE_CTMU_CH4_CFG1H, + M2P_MESSAGE_CTMU_CH4_CFG2L, + M2P_MESSAGE_CTMU_CH4_CFG2H, + M2P_RVD2PVDD_EN, + M2P_PVDD_EXTERN_DCDC, + + M2P_USER_PEND = 88, + M2P_USER_MSG_TYPE = 89, + M2P_USER_MSG_LEN0 = 90, + M2P_USER_MSG_LEN1 = 91, + M2P_USER_ADDR0 = 92, + M2P_USER_ADDR1 = 93, + M2P_USER_ADDR2 = 94, + M2P_USER_ADDR3 = 95, +}; + +enum { + CLOSE_P33_INTERRUPT = 1, + OPEN_P33_INTERRUPT, + LOWPOWER_PREPARE, + CHARGE_ENABLE, + CHARGE_DISABLE, + UPDATE_LRC_FEQ, + + M2P_WDT_CLEAR = 8, + + P2M_RESERVED_CMD = 0xFF, +}; + +enum { + VDDIO_KEEP_TYPE_TRIM = 0,//vddio keep使用trim值:默认 + VDDIO_KEEP_TYPE_PG, //vddio keep使用 mvvdio:功耗代价100ua +}; + +#define IS_TMR0_SRC_CLK_BTOSC() ((P11_LPTMR0->CON2 & 0xf) == 0x2) + +#define P11_WKUP_SYS() P11_SYSTEM->P2M_INT_SET = m2p_cmd; m2p_cmd = 0 +#define P11_WKUP_SYS_POST() P11_SYSTEM->P2M_INT_SET = BIT(P2M_LP_INDEX2) + +#define RC_250k_EN(a) \ + if (a) { \ + P11_CLOCK->CLK_CON1 |= BIT(10); \ + } else { \ + P11_CLOCK->CLK_CON1 &= ~BIT(10); \ + } + +//simple version +// +#define ENTER_CRITICAL() disable_int() + +#define EXIT_CRITICAL() enable_int() + +#define PDOWN 0 +#define POFF 1 +#define PDOWN_VAD 2 + +extern void __power_recover(void); +extern void __power_recover(void); +extern void p11_reset_main_system(); +extern void lp_timer1_enable(void); +extern void lp_timer1_disable(void); + +extern void idle(); +extern void standby(); +extern void sleep(); +extern void deep_sleep(); + +#define CALL_DEEP_SLEEP() deep_sleep() +#define CALL_SLEEP() sleep() +#define CALL_STANDBY() standby() +#define CALL_IDLE() idle() + +#endif /* #ifndef __P11_APP_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/power/p11_csfr.h b/2.code/2.p11_code/include/cpu/br28/power/p11_csfr.h new file mode 100644 index 0000000..4091423 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p11_csfr.h @@ -0,0 +1,178 @@ +//*********************************************************************************// +// Module name : csfr.h // +// Description : q32small core sfr define // +// By Designer : zequan_liu // +// Dat changed : // +//*********************************************************************************// + +#ifndef __P11_Q32S_CSFR__ +#define __P11_Q32S_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 CPU_CORE_NUM 1 + +//---------------------------------------------// +// q32small define +//---------------------------------------------// + +#ifdef PMU_SYSTEM +#define p11_q32s_sfr_base 0x00a000 +#define p11_q32s_sfr_offset 0x000000 // multi_core used +#else +#define p11_q32s_sfr_base 0xf2a000 +#define p11_q32s_sfr_offset 0x000000 // multi_core used +#endif + +#define p11_q32s_cpu_base (p11_q32s_sfr_base + 0x00) +#define p11_q32s_mpu_base (p11_q32s_sfr_base + 0x80) + +#define p11_q32s(n) ((JL_TypeDef_p11_q32s *)(p11_q32s_sfr_base + p11_q32s_sfr_offset*n)) +#define p11_q32s_mpu(n) ((JL_TypeDef_p11_q32s_MPU *)(p11_q32s_mpu_base + p11_q32s_sfr_offset*n)) + +//---------------------------------------------// +// q32small 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; + /* */ __RO __u32 REV_30_26[0x30 - 0x26 - 1]; + + /* 30 */ __RW __u32 PMU_CON; + /* */ __RO __u32 REV_3b_30[0x3b - 0x30 - 1]; + /* 3b */ __RW __u8 TTMR_CON; + /* 3c */ __RW __u32 TTMR_CNT; + /* 3d */ __RW __u32 TTMR_PRD; + /* 3e */ __RW __u32 BANK_CON; + /* 3f */ __RW __u32 BANK_NUM; + + /* 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 REV_70_6c[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 */ __RW __u32 WP0_PC; + + /* */ __RO __u32 REV_80_79[0x80 - 0x79 - 1]; + /* 80 */ __RW __u32 EMU_CON; + /* 81 */ __RW __u32 EMU_MSG; + /* 82 */ __RO __u32 EMU_SSP_H; + /* 83 */ __RO __u32 EMU_SSP_L; + /* 84 */ __RO __u32 EMU_USP_H; + /* 85 */ __RO __u32 EMU_USP_L; +} JL_TypeDef_p11_q32s; + +#undef __RW +#undef __RO +#undef __WO + +#undef __u8 +#undef __u16 +#undef __u32 + +#endif + +//*********************************************************************************// +// // +// end of this module // +// // +//*********************************************************************************// diff --git a/2.code/2.p11_code/include/cpu/br28/power/p11_io_imap.h b/2.code/2.p11_code/include/cpu/br28/power/p11_io_imap.h new file mode 100644 index 0000000..b8ff636 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p11_io_imap.h @@ -0,0 +1,38 @@ + + +//===============================================================================// +// +// input IO define +// +//===============================================================================// +#define P11_PB0_IN 1 +#define P11_PB1_IN 2 +#define P11_PB2_IN 3 +#define P11_PB3_IN 4 +#define P11_PB4_IN 5 +#define P11_PB5_IN 6 +#define P11_PB6_IN 7 +#define P11_PB7_IN 8 +#define P11_PB8_IN 9 +#define P11_PB9_IN 10 +#define P11_PB10_IN 11 +#define P11_PB11_IN 12 + +//===============================================================================// +// +// function input select sfr +// +//===============================================================================// +typedef struct { + __RW __u8 P11_FI_GP_ICH0; + __RW __u8 P11_FI_GP_ICH1; + __RW __u8 P11_FI_GP_ICH2; + __RW __u8 P11_FI_UART0_RX; + __RW __u8 P11_FI_SPI_DI; + __RW __u8 P11_FI_IIC_SCL; + __RW __u8 P11_FI_IIC_SDA; + __RW __u8 P11_FI_DMIC_DAT; +} P11_IMAP_TypeDef; + +#define P11_IMAP_BASE (p11_sfr_base + map_adr(0x16, 0x00)) +#define P11_IMAP ((P11_IMAP_TypeDef *)P11_IMAP_BASE) diff --git a/2.code/2.p11_code/include/cpu/br28/power/p11_io_omap.h b/2.code/2.p11_code/include/cpu/br28/power/p11_io_omap.h new file mode 100644 index 0000000..38021fb --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p11_io_omap.h @@ -0,0 +1,40 @@ + + +//===============================================================================// +// +// output function define +// +//===============================================================================// +#define P11_FO_GP_OCH0 ((0 << 2)|BIT(1)) +#define P11_FO_GP_OCH1 ((1 << 2)|BIT(1)) +#define P11_FO_GP_OCH2 ((2 << 2)|BIT(1)) +#define P11_FO_UART0_TX ((3 << 2)|BIT(1)|BIT(0)) +#define P11_FO_UART1_TX ((4 << 2)|BIT(1)|BIT(0)) +#define P11_FO_SPI_CLK ((5 << 2)|BIT(1)|BIT(0)) +#define P11_FO_SPI_DO ((6 << 2)|BIT(1)|BIT(0)) +#define P11_FO_IIC_SCL ((7 << 2)|BIT(1)|BIT(0)) +#define P11_FO_IIC_SDA ((8 << 2)|BIT(1)|BIT(0)) +#define P11_FO_DMIC_CLK ((9 << 2)|BIT(1)|BIT(0)) + +//===============================================================================// +// +// IO output select sfr +// +//===============================================================================// +typedef struct { + __RW __u8 P11_PB0_OUT; + __RW __u8 P11_PB1_OUT; + __RW __u8 P11_PB2_OUT; + __RW __u8 P11_PB3_OUT; + __RW __u8 P11_PB4_OUT; + __RW __u8 P11_PB5_OUT; + __RW __u8 P11_PB6_OUT; + __RW __u8 P11_PB7_OUT; + __RW __u8 P11_PB8_OUT; + __RW __u8 P11_PB9_OUT; + __RW __u8 P11_PB10_OUT; + __RW __u8 P11_PB11_OUT; +} P11_OMAP_TypeDef; + +#define P11_OMAP_BASE (p11_sfr_base + map_adr(0x15, 0x00)) +#define P11_OMAP ((P11_OMAP_TypeDef *)P11_OMAP_BASE) diff --git a/2.code/2.p11_code/include/cpu/br28/power/p11_sfr.h b/2.code/2.p11_code/include/cpu/br28/power/p11_sfr.h new file mode 100644 index 0000000..38dd9ff --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p11_sfr.h @@ -0,0 +1,245 @@ + +#ifndef __P11__ +#define __P11__ + +//===============================================================================// +// +// sfr define +// +//===============================================================================// + +#ifdef PMU_SYSTEM +#define p11_base 0x000000 +#define p11_ram_base p11_base +#define p11_sfr_base 0x00a000 +#else +#define p11_base 0xf20000 +#define p11_ram_base p11_base +#define p11_sfr_base 0xf2a000 +#endif + +#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 __s8(x) char(x); char(reserved_1_##x); char(reserved_2_##x); char(reserved_3_##x) +#define __s16(x) short(x); short(reserved_1_##x) +#define __s32(x) int(x) + +#define map_adr(grp, adr) ((64 * grp + adr) * 4) // grp(0x0-0xff), adr(0x0-0x3f) +#define P11_ACCESS(x) (*(volatile u32 *)(p11_base + x)) +#define P11_RAM(x) (*(volatile u32 *)(p11_ram_base + x)) + +//===============================================================================// +// +// sfr address define +// +//===============================================================================// + +//............. 0x0000 - 0x03ff............ for cpu + +// #include ../core/csfr.h + +//............. 0x0400 - 0x04ff............ for clock +typedef struct { + __RW __u32 PWR_CON; + __RW __u32 RST_SRC; + __RW __u32 WKUP_EN; + __RW __u32 WKUP_SRC; + __RW __u32 SYS_DIV; + __RW __u32 CLK_CON0; + __RW __u32 CLK_CON1; + __RW __u32 CLK_CON2; + __RW __u32 CLK_CON3; +} P11_CLOCK_TypeDef; + +#define P11_CLOCK_BASE (p11_sfr_base + map_adr(0x04, 0x00)) +#define P11_CLOCK ((P11_CLOCK_TypeDef *)P11_CLOCK_BASE) + +//............. 0x0500 - 0x05ff............ for memory control +typedef struct { + __RW __u32 MPC0; + __RW __u32 MPC1; + __RW __u32 MSC; +} P11_MEM_CTL_TypeDef; + +#define P11_MEM_CTL_BASE (p11_sfr_base + map_adr(0x05, 0x00)) +#define P11_MEM_CTL ((P11_MEM_CTL_TypeDef *)P11_MEM_CTL_BASE) + +//............. 0x0600 - 0x06ff............ for system +typedef struct { + __RW __u32 P2M_INT_IE; + __RW __u32 P2M_INT_SET; + __RW __u32 P2M_INT_CLR; + __RO __u32 P2M_INT_PND; + __RW __u32 P2M_CLK_CON0; + __RW __u32 M2P_INT_IE; + __RW __u32 M2P_INT_SET; + __RW __u32 M2P_INT_CLR; + __RO __u32 M2P_INT_PND; + __RW __u32 P11_SYS_CON0; + __RW __u32 P11_SYS_CON1; + __RW __u32 MEM_PWR_CON; +} P11_SYSTEM_TypeDef; + +#define P11_SYSTEM_BASE (p11_sfr_base + map_adr(0x06, 0x00)) +#define P11_SYSTEM ((P11_SYSTEM_TypeDef *)P11_SYSTEM_BASE) + +//............. 0x0800 - 0x08ff............ for watch dog +typedef struct { + __RW __u32 CON; + __RW __u32 KEY; + __RW __u32 DUMMY; +} P11_WDT_TypeDef; + +#define P11_WDT_BASE (p11_sfr_base + map_adr(0x08, 0x00)) +#define P11_WDT ((P11_WDT_TypeDef *)P11_WDT_BASE) + +//............. 0x0900 - 0x0cff............ for lp timer +typedef struct { + __RW __u32 CON0; + __RW __u32 CON1; + __RW __u32 CON2; + __RW __u32 PRD; + __RW __u32 RSC; + __RO __u32 CNT; +} P11_LPTMR_TypeDef; + +#define P11_LPTMR0_BASE (p11_sfr_base + map_adr(0x09, 0x00)) +#define P11_LPTMR1_BASE (p11_sfr_base + map_adr(0x0a, 0x00)) +#define P11_LPTMR2_BASE (p11_sfr_base + map_adr(0x0b, 0x00)) +#define P11_LPTMR3_BASE (p11_sfr_base + map_adr(0x0c, 0x00)) + +#define P11_LPTMR0 ((P11_LPTMR_TypeDef *)P11_LPTMR0_BASE) +#define P11_LPTMR1 ((P11_LPTMR_TypeDef *)P11_LPTMR1_BASE) +#define P11_LPTMR2 ((P11_LPTMR_TypeDef *)P11_LPTMR2_BASE) +#define P11_LPTMR3 ((P11_LPTMR_TypeDef *)P11_LPTMR3_BASE) + +//............. 0x0d00 - 0x0dff............ for irflt +typedef struct { + __RW __u32 CON; +} P11_IRFLT_TypeDef; + +#define P11_IRFLT_BASE (p11_sfr_base + map_adr(0x0d, 0x00)) +#define P11_IRFLT ((P11_IRFLT_TypeDef *)P11_IRFLT_BASE) + +//............. 0x0e00 - 0x0eff............ for spi +typedef struct { + __RW __u32 CON; + __WO __u32 BAUD; + __RW __u32 BUF; + __WO __u32 ADR; + __WO __u32 CNT; +} P11_SPI_TypeDef; + +#define P11_SPI_BASE (p11_sfr_base + map_adr(0x0e, 0x00)) +#define P11_SPI ((P11_SPI_TypeDef *)P11_SPI_BASE) + +//............. 0x0f00 - 0x10ff............ for uart +typedef struct { + __RW __u16 CON0; + //__RW __u16 CON1; + __WO __u16 BAUD; + __RW __u8 BUF; + __RW __u32 OTCNT; + //__RW __u32 TXADR; + //__WO __u16 TXCNT; + //__RW __u32 RXSADR; + //__RW __u32 RXEADR; + //__RW __u32 RXCNT; + //__RO __u16 HRXCNT; + __RW __u16 CON2; +} P11_UART_TypeDef; + +#define P11_UART0_BASE (p11_sfr_base + map_adr(0x0f, 0x00)) +#define P11_UART1_BASE (p11_sfr_base + map_adr(0x10, 0x00)) + +#define P11_UART0 ((P11_UART_TypeDef *)P11_UART0_BASE) +#define P11_UART1 ((P11_UART_TypeDef *)P11_UART1_BASE) + +//............. 0x1100 - 0x11ff............ for iic +typedef struct { + __RW __u32 CON0; + __RW __u32 CON1; + __RW __u32 BAUD; + __RW __u32 BUF; +} P11_IIC_TypeDef; + +#define P11_IIC_BASE (p11_sfr_base + map_adr(0x11, 0x00)) +#define P11_IIC ((P11_IIC_TypeDef *)P11_IIC_BASE) + +//............. 0x1200 - 0x12ff............ for port +typedef struct { + __RW __u32 OCH_CON0 ; + __RW __u32 ICH_CON0 ; + __RW __u32 P33_PORT ; + __RW __u32 PB_SEL ; + __RW __u32 PB_PU ; + __RW __u32 PB_PD ; + __RW __u32 PB_DIR ; + __RW __u32 PB_DIE ; + __RW __u32 PB_DIEH ; + __RW __u32 PB_OUT ; + __RO __u32 PB_IN ; +} P11_PORT_TypeDef; + +#define P11_PORT_BASE (p11_sfr_base + map_adr(0x12, 0x00)) +#define P11_PORT ((P11_PORT_TypeDef *)P11_PORT_BASE) + +//............. 0x1300 - 0x13ff............ for lp ctmu +typedef struct { + __RW __u32 CON0; + __RW __u32 CON1; + __RW __u32 CON2; + __RW __u32 CON3; + __RW __u32 ANA0; + __RW __u32 ANA1; + __RW __u32 RES; +} P11_LPCTM_TypeDef; + +#define P11_LPCTM_BASE (p11_sfr_base + map_adr(0x13, 0x00)) +#define P11_LPCTM ((P11_LPCTM_TypeDef *)P11_LPCTM_BASE) + +//............. 0x1400 - 0x14ff............ for lpvad +typedef struct { + __RW __u32 VAD_CON; + __RW __u32 VAD_ACON0; + __RW __u32 VAD_ACON1; + __RW __u32 AVAD_CON; + __RW __u32 AVAD_DATA; + __RW __u32 DVAD_CON0; + __RW __u32 DVAD_CON1; + __RW __u32 DMA_BADR; + __RW __u32 DMA_LEN; + __RW __u32 DMA_HPTR; + __RW __u32 DMA_SPTR; + __RW __u32 DMA_SPN; + __RW __u32 DMA_SHN; +} P11_LPVAD_TypeDef; + +#define P11_LPVAD_BASE (p11_sfr_base + map_adr(0x14, 0x00)) +#define P11_LPVAD ((P11_LPVAD_TypeDef *)P11_LPVAD_BASE) + +//............. 0x1500 - 0x16ff............ for crossbar +#include "p11_io_omap.h" +#include "p11_io_imap.h" + +//............. 0x1700 - 0x18ff............ for gp timer +typedef struct { + __RW __u32 CON; + __RW __u32 CNT; + __RW __u32 PRD; + __RW __u32 PWM; +} P11_GPTMR_TypeDef; + +#define P11_GPTMR0_BASE (p11_sfr_base + map_adr(0x17, 0x00)) +#define P11_GPTMR1_BASE (p11_sfr_base + map_adr(0x18, 0x00)) + +#define P11_GPTMR0 ((P11_GPTMR_TypeDef *)P11_GPTMR0_BASE) +#define P11_GPTMR1 ((P11_GPTMR_TypeDef *)P11_GPTMR1_BASE) + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/power/p33.h b/2.code/2.p11_code/include/cpu/br28/power/p33.h new file mode 100644 index 0000000..6388632 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p33.h @@ -0,0 +1,22 @@ +/********************************************************************************************* + * Filename : p33.h + + * Description : + + * Author : Bingquan + + * Email : caibingquan@zh-jieli.com + + * Last modifiled : 2019-12-09 10:42 + + * Copyright:(c)JIELI 2011-2019 @ , All Rights Reserved. + *********************************************************************************************/ + +#ifndef __P33_H__ +#define __P33_H__ + +#include "p33_sfr.h" + +#include "p33_app.h" + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/power/p33_api.h b/2.code/2.p11_code/include/cpu/br28/power/p33_api.h new file mode 100644 index 0000000..bd49a5d --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p33_api.h @@ -0,0 +1,6 @@ +#ifndef __P33_API_H__ +#define __P33_API_H__ + +void iovdd2_bypass_iovdd(u8 enable); + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/power/p33_app.h b/2.code/2.p11_code/include/cpu/br28/power/p33_app.h new file mode 100644 index 0000000..d183713 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p33_app.h @@ -0,0 +1,686 @@ +#ifndef __P33_APP_H__ +#define __P33_APP_H__ +/********************************************************************************************* + * Filename : p11_app.h + + * Description : 本文用于基于p33.h功能的封装 + + * Author : MoZhiYe + + * Email : mozhiye@zh-jieli.com + + * Last modifiled : 2021-04-17 09:00 + + * Copyright:(c)JIELI 2021-2029 @ , All Rights Reserved. +*********************************************************************************************/ +#include "p11_app.h" +#include "p33.h" + +//=============================================================// +// P33 SFR操作 // +//=============================================================// +// void p33_xor_1byte(u16 addr, u8 data0); +#define p33_xor_1byte(addr, data0) (*((volatile u8 *)&addr + 0x300*4) = data0) +//#define p33_xor_1byte(addr, data0) addr ^= (data0) + +// void p33_or_1byte(u16 addr, u8 data0); +#define p33_or_1byte(addr, data0) (*((volatile u8 *)&addr + 0x200*4) = data0) +//#define p33_or_1byte(addr, data0) addr |= (data0) + +// void p33_and_1byte(u16 addr, u8 data0); +#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 + +#define p33_rx_1byte(addr) addr + +#define P33_CON_SET(sfr, start, len, data) (sfr = (sfr & ~((~(0xff << len))) << (start))) | (((data) & (~(0xff << (len)))) << (start))) + +#define P33_CON_GET(sfr) sfr + +//-----special operation---------- +#define P33_WKUP_ENABLE() \ + P3_VLD_KEEP |= BIT(2) + +#define P33_WKUP_DISABLE() \ + 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)) + +/*******************************************************************/ + +#define DVDDLS_PU \ + P3_LS_IO_DLY = 0x4; \ + P3_LS_IO_ROM = 0x4; \ + P3_LS_ADC = 0x4; \ + P3_LS_AUDIO = 0x4; \ + P3_LS_RF = 0x4; \ + P3_LS_PLL = 0x4; \ + P3_LS_IO_DLY = 0x6; \ + P3_LS_IO_ROM = 0x6; \ + P3_LS_ADC = 0x6; \ + P3_LS_AUDIO = 0x6; \ + P3_LS_RF = 0x6; \ + P3_LS_PLL = 0x6; \ + +#define DVDDLS_EN \ + P3_LS_IO_DLY = 0x6; \ + P3_LS_IO_ROM = 0x6; \ + P3_LS_ADC = 0x6; \ + P3_LS_AUDIO = 0x6; \ + P3_LS_RF = 0x6; \ + P3_LS_PLL = 0x6; \ + +#define DVDDLS_OFF \ + P3_LS_IO_DLY = 0x7; \ + P3_LS_IO_ROM = 0x7; \ + P3_LS_ADC = 0x7; \ + P3_LS_AUDIO = 0x7; \ + P3_LS_RF = 0x7; \ + P3_LS_PLL = 0x7; \ + P3_LS_IO_DLY = 0x3; \ + P3_LS_IO_ROM = 0x3; \ + P3_LS_ADC = 0x3; \ + P3_LS_AUDIO = 0x3; \ + P3_LS_RF = 0x3; \ + P3_LS_PLL = 0x3; \ + +#define PVDDLS_EN(a) \ + if (a) { \ + P3_LS_P11 = 0x0; \ + } else { \ + P3_LS_P11 = 0x2; \ + } + +#define PVDDOK_SOFF P3_LS_P11 = 0x1; + +/* + *-------------------P3_ANA_CON0 + */ + +#define GET_DCVD_STA() (P3_ANA_CON0 & (BIT(2) | BIT(3))) + +#define VDD13TO12_SYS_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(0)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(0)); \ +} + +#define VDD13TO12_RVD_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(1)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(1)); \ +} + +#define DCVD_TO_DIG_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, (BIT(1) | BIT(0))); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~(BIT(1) | BIT(0))); \ +} + +#define DCVDD_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(2)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(2)); \ +} + +#define DCDC13_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(3)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(3)); \ +} + +#define IS_DCDC13_EN() ((P3_ANA_CON0 & BIT(3)) ? 1: 0 ) + +#define MVIO_PVDD_MVBG_ONLY() P3_ANA_CON0 = BIT(4) | BIT(5) | BIT(6) | BIT(7) +#define PVDD_MVBG_ONLY() P3_ANA_CON0 = BIT(4) | BIT(7) +#define PVDD_ONLY() P3_ANA_CON0 = BIT(4) + +#define PVDD_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(4)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(4)); \ +} + +#define PW_GATE_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(5) | BIT(6)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~(BIT(5) | BIT(6))); \ +} + +#define MVIO_VBAT_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(5)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(5)); \ +} + +#define MVIO_VPWR_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(6)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(6)); \ +} + +#define MBG_EN_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON0, BIT(7)); \ + } else { \ + p33_and_1byte(P3_ANA_CON0, ~BIT(7)); \ +} + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON1 + */ +#define RVDD_BYPASS_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON1, BIT(0)); \ + } else { \ + p33_and_1byte(P3_ANA_CON1, ~BIT(0)); \ +} + +#define WVDD_SHORT_RVDD(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON1, BIT(1)); \ + } else { \ + p33_and_1byte(P3_ANA_CON1, ~BIT(1)); \ +} + +#define WVDD_SHORT_DVDD(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON1, BIT(2)); \ + } else { \ + p33_and_1byte(P3_ANA_CON1, ~BIT(2)); \ +} + +#define WLDO06_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON1, BIT(3)); \ + } else { \ + p33_and_1byte(P3_ANA_CON1, ~BIT(3)); \ + } + +#define PVD_SHORT_PB3(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON1, BIT(7)); \ + } else { \ + p33_and_1byte(P3_ANA_CON1, ~BIT(7)); \ + } + +#define WVDD_PDOWN_ENTER P3_ANA_CON1 = (P3_ANA_CON1 & (~0x1f)) | 0x1e + +#define WVDD_POFF_ENTER P3_ANA_CON1 = (P3_ANA_CON1 & (~0x1f)) | 0x1a + +#define WVDD_PDOWN_POFF_EXIT P3_ANA_CON1 = (P3_ANA_CON1 & (~0x1f)) | 0x4 + +#define WVDD_LIGHT_PDOWN_ENTER P3_ANA_CON1 = (P3_ANA_CON1 & (~0x1f)) | 0x1c + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON2 + */ +#define IS_VCM_DET_EN() ((P3_ANA_CON2 & BIT(3)) ? 1: 0 ) + +#define VCM_DET_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON2, BIT(3)); \ + } else { \ + p33_and_1byte(P3_ANA_CON2, ~BIT(3)); \ + } + +#define IOVD_DRI_FULL(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON2, (BIT(4) | BIT(5))); \ + } else { \ + p33_and_1byte(P3_ANA_CON2, ~(BIT(4) | BIT(5))); \ + } + +#define DCVD_DRI_FULL(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON2, BIT(6)); \ + } else { \ + p33_and_1byte(P3_ANA_CON2, ~BIT(6)); \ + } + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON3 + */ + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON4 + */ +#define PMU_DET_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON4, BIT(0)); \ + } else { \ + p33_and_1byte(P3_ANA_CON4, ~BIT(0)); \ + } + +#define PMU_DET_BG_BUF_DISABLE() (P3_ANA_CON4 &= ~(BIT(5)|BIT(6)|BIT(7))) + +#define GET_P3_ANA_CON4() P3_ANA_CON4 + +#define SET_P3_ANA_CON4(val) P3_ANA_CON4 = val + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON5 + */ +#define GET_MVIO_SEL() (P3_ANA_CON5 & 0x7) +#define GET_WVIO_SEL() ((P3_ANA_CON5 >> 3) & 0x7) + +#define MVIO_SEL(cur) P3_ANA_CON5 = (P3_ANA_CON5 & (~0x7)) | cur +#define WVIO_SEL(cur) P3_ANA_CON5 = (P3_ANA_CON5 & (~(0x7 << 3))) | (cur << 3) +#define VDDIO_HD_SEL(cur) P3_ANA_CON5 = (P3_ANA_CON5 & (~(0x3 << 6)) | (cur << 6) + +/* + *-------------------P3_IOV2_CON + */ +#define IOV2_CFG(set) P3_IOV2_CON = (P3_IOV2_CON & ~0x7) | (set & 0x7) + +#define GET_IOV2_EN (P3_IOV2_CON & BIT(0)) +#define GET_IOV2_BYPASS (P3_IOV2_CON & BIT(1)) + +#define IOV2_LDO_EN P3_IOV2_CON = (P3_IOV2_CON & ~BIT(1)) | BIT(0) + +#define IOV2_EN(a) \ + if (a) { \ + p33_or_1byte(P3_IOV2_CON, BIT(0)); \ + } else { \ + p33_and_1byte(P3_IOV2_CON, ~BIT(0)); \ + } + + +#define IOV2_BYPASS(a) \ + if (a) { \ + p33_or_1byte(P3_IOV2_CON, BIT(1)); \ + } else { \ + p33_and_1byte(P3_IOV2_CON, ~BIT(1)); \ + } + +#define VIO2_DRI_FULL(a) \ + if (a) { \ + p33_or_1byte(P3_IOV2_CON, BIT(2)); \ + } else { \ + p33_and_1byte(P3_IOV2_CON, ~BIT(2)); \ + } + +/*******************************************************************/ + +/* + *-------------------P3_RVD_CON + */ +#define RVDD_CMP_EN(en) \ + if(en){ \ + p33_or_1byte(P3_RVD_CON, BIT(4));\ + }else{ \ + p33_and_1byte(P3_RVD_CON, BIT(4));\ + } + +#define PVDD_DCDC_LEV_SEL(sel) p33_tx_1byte(P3_RVD_CON, p33_rx_1byte(P3_RVD_CON) & (~0x0f) | sel) + +#define GET_PVDD_DCDC_LEV_SEL() (p33_rx_1byte(P3_RVD_CON) & 0xf) + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON6 + */ +#define DCVD_SEL(sel) P3_ANA_CON6 = (P3_ANA_CON6 & (~0xf)) | sel + +#define GET_DCVD_SEL() (P33_CON_GET(P3_ANA_CON6) & 0xf) + +enum { + DCVDD_VOL_SEL_100V = 0, + 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, + DCVDD_VOL_SEL_140V, +}; + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON7 + */ + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON8 + */ + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON9 + */ + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON10 + */ + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON10 + */ + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON11 + */ +#define DVDD_VOL_SEL(sel) P3_ANA_CON11 = (P3_ANA_CON11 & (~0xf)) | sel + +enum { + SYSVDD_VOL_SEL_081V = 0, + SYSVDD_VOL_SEL_084V, + SYSVDD_VOL_SEL_087V, + SYSVDD_VOL_SEL_090V, + SYSVDD_VOL_SEL_093V, + SYSVDD_VOL_SEL_096V, + SYSVDD_VOL_SEL_099V, + SYSVDD_VOL_SEL_102V, + SYSVDD_VOL_SEL_105V, + SYSVDD_VOL_SEL_108V, + SYSVDD_VOL_SEL_111V, + SYSVDD_VOL_SEL_114V, + SYSVDD_VOL_SEL_117V, + SYSVDD_VOL_SEL_120V, + SYSVDD_VOL_SEL_123V, + SYSVDD_VOL_SEL_126V, +}; + +#define GET_DVDD_VOL_SEL() (P3_ANA_CON11 & 0xf) + +#define SET_P3_ANA_CON11(val) (P3_ANA_CON11 = val) + +#define GET_P3_ANA_CON11() P3_ANA_CON11 +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON12 + */ +#define RVDD_VOL_SEL(sel) P3_ANA_CON12 = (P3_ANA_CON12 & (~0xf)) | sel + +#define GET_RVDD_VOL_SEL() (P3_ANA_CON12 & 0xf) + +#define SET_P3_ANA_CON12(val) (P3_ANA_CON12 = val) + +#define GET_P3_ANA_CON12() P3_ANA_CON12 + +enum { + RVDD_VOL_SEL_081V = 0, + RVDD_VOL_SEL_084V, + RVDD_VOL_SEL_087V, + RVDD_VOL_SEL_090V, + RVDD_VOL_SEL_093V, + RVDD_VOL_SEL_096V, + RVDD_VOL_SEL_099V, + RVDD_VOL_SEL_102V, + RVDD_VOL_SEL_105V, + RVDD_VOL_SEL_108V, + RVDD_VOL_SEL_111V, + RVDD_VOL_SEL_114V, + RVDD_VOL_SEL_117V, + RVDD_VOL_SEL_120V, + RVDD_VOL_SEL_123V, + RVDD_VOL_SEL_126V, +}; + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON13 + */ +#define WVDD_VOL_SEL(vol) P3_ANA_CON13 = (P3_ANA_CON13 & (~0xf)) | vol + +#define WVDDIO_SEL_AUTO_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON13, BIT(5)); \ + } else { \ + p33_and_1byte(P3_ANA_CON13, ~BIT(5)); \ + } + +#define WVDDIO_FBRES_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON13, BIT(7)); \ + } else { \ + p33_and_1byte(P3_ANA_CON13, ~BIT(7)); \ + } + +/*******************************************************************/ + +/* + *-------------------P3_ANA_CON14 + */ +#define PVD_HD_SEL(val) P3_ANA_CON14 = (P3_ANA_CON14 & (~0x7)) | val + +#define GET_PVD_HD_SEL() (p33_rx_1byte(P3_ANA_CON14) & 0x7) + +#define PVDD_DEUDSHT_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON14, BIT(3)); \ + } else { \ + p33_and_1byte(P3_ANA_CON14, ~BIT(3)); \ + } + +#define RVD2PVD_SHORT_EN(a) \ + if (a) { \ + p33_or_1byte(P3_ANA_CON14, BIT(4)); \ + } else { \ + p33_and_1byte(P3_ANA_CON14, ~BIT(4)); \ + } + +#define PVDD_DRV_SEL(val) \ + if (val) { \ + P3_ANA_CON14 = val & 0xf; \ + } else { \ + P3_ANA_CON14 = 0xf0; \ + } + + +/*******************************************************************/ + +/* + *-------------------P3_VLVD_CON + */ +#define GET_P33_VLVD_EN (P3_VLVD_CON & BIT(0)) + +#define P33_VLVD_EN(a) \ + if (a) { \ + p33_or_1byte(P3_VLVD_CON, BIT(0)); \ + } else { \ + p33_and_1byte(P3_VLVD_CON, ~BIT(0)); \ + } + +/*******************************************************************/ + +/* + *-------------------P3_LRC_CON0 + */ +#define LRC_EN(a) \ + if (a) { \ + p33_or_1byte(P3_LRC_CON0, BIT(0)); \ + } else { \ + p33_and_1byte(P3_LRC_CON0, ~BIT(0)); \ + } + +/*******************************************************************/ + +/* + *-------------------P3_PVDD0_AUTO + */ +#define SET_P3_PVDD0_AUTO(val) p33_tx_1byte(P3_PVDD0_AUTO, val) + +enum { + PVDD_VOL_SEL_050V = 0, + PVDD_VOL_SEL_055V, + PVDD_VOL_SEL_060V, + PVDD_VOL_SEL_065V, + PVDD_VOL_SEL_070V, + PVDD_VOL_SEL_075V, + PVDD_VOL_SEL_080V, + PVDD_VOL_SEL_085V, + PVDD_VOL_SEL_090V, + PVDD_VOL_SEL_095V, + PVDD_VOL_SEL_100V, + PVDD_VOL_SEL_105V, + PVDD_VOL_SEL_110V, + PVDD_VOL_SEL_115V, + PVDD_VOL_SEL_120V, + PVDD_VOL_SEL_125V, +}; + +#define PVDD_VOL_SEL_MAX PVDD_VOL_SEL_125V + +/*******************************************************************/ + +/* + *-------------------P3_PVDD1_AUTO + */ +#define PVDD_LEVEL_NOW(val) p33_tx_1byte(P3_PVDD1_AUTO, p33_rx_1byte(P3_PVDD1_AUTO) & (~0x0f) | val) + +#define PVDD_LEVEL_HIGH_NOW(sel) p33_tx_1byte(P3_PVDD1_AUTO, ((sel<<4)|sel)) + +#define PVDD_LEVEL_HIGH(sel) p33_tx_1byte(P3_PVDD1_AUTO, p33_rx_1byte(P3_PVDD1_AUTO) & (~0xf0) | val) + +#define GET_PVDD_LEVEL_NOW() (p33_rx_1byte(P3_PVDD1_AUTO) & 0x0f) + +/*******************************************************************/ + +/* + *-------------------P3_PVDD2_AUTO + */ +#define PVDD_DRI_SEL(a) \ + if (a) { \ + p33_or_1byte(P3_PVDD2_AUTO, BIT(0)); \ + } else { \ + p33_and_1byte(P3_PVDD2_AUTO, ~BIT(0)); \ + } + + + +/*******************************************************************/ + +/* + *-------------------P3_ANA_KEEP + */ +#define SET_P3_ANA_KEEP(val) p33_tx_1byte(P3_ANA_KEEP, val) + +/*******************************************************************/ + +/* + *-------------------P3_ANA_KEEP1 + */ +#define SET_P3_ANA_KEEP1(val) p33_tx_1byte(P3_ANA_KEEP1, val) + +/*******************************************************************/ + +/* + * *-------------------P3_CLK_CON0 + * */ + +#define RC_250K_EN(a) \ + if (a) { \ + p33_or_1byte(P3_CLK_CON0, BIT(0)); \ + } else { \ + p33_and_1byte(P3_CLK_CON0, ~BIT(0)); \ + } + +/*******************************************************************/ + +/* + * *-------------------P3_RST_CON0 + * */ + +#define DPOR_MASK(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(0)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, ~BIT(0)); \ + } + + +#define VLVD_RST_EN(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(2)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, ~BIT(2)); \ + } + + +#define VLVD_WKUP_EN(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(3)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, ~BIT(3)); \ + } + +#define PPOR_MASK(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(4)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, ~BIT(4)); \ + } + +#define P11_TO_P33_RST_MASK(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(5)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, ~BIT(5)); \ + } + +#define VDDOK_EN(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(6)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, ~BIT(6)); \ + } + +#define PVDDOK_EN(a) \ + if (a) { \ + p33_or_1byte(P3_RST_CON0, BIT(7)); \ + } else { \ + p33_and_1byte(P3_RST_CON0, (u8)(~BIT(7))); \ + } + + +#endif /* #ifndef __P33_APP_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/power/p33_sfr.h b/2.code/2.p11_code/include/cpu/br28/power/p33_sfr.h new file mode 100644 index 0000000..94c79de --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/p33_sfr.h @@ -0,0 +1,250 @@ +#ifndef __P33_SFR_H__ +#define __P33_SFR_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_IOV2_CON P33_ACCESS(0x00) + +//............. 0x0010 - 0x001f............ for analog others +#define P3_OSL_CON P33_ACCESS(0x10) +#define P3_VLVD_CON P33_ACCESS(0x11) +#define P3_RST_SRC 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_ANA_KEEP P33_ACCESS(0x16) +#define P3_VLD_KEEP P33_ACCESS(0x17) +#define P3_CLK_CON0 P33_ACCESS(0x18) +#define P3_ANA_READ P33_ACCESS(0x19) +#define P3_CHG_CON0 P33_ACCESS(0x1a) +#define P3_CHG_CON1 P33_ACCESS(0x1b) +#define P3_CHG_CON2 P33_ACCESS(0x1c) +#define P3_CHG_CON3 P33_ACCESS(0x1d) + +//............. 0x0020 - 0x002f............ for PWM LED +//#define P3_PWM_CON0 P33_ACCESS(0x20) +//#define P3_PWM_CON1 P33_ACCESS(0x21) +//#define P3_PWM_CON2 P33_ACCESS(0x22) +//#define P3_PWM_CON3 P33_ACCESS(0x23) +//#define P3_PWM_BRI_PRDL P33_ACCESS(0x24) +//#define P3_PWM_BRI_PRDH P33_ACCESS(0x25) +//#define P3_PWM_BRI_DUTY0L P33_ACCESS(0x26) +//#define P3_PWM_BRI_DUTY0H P33_ACCESS(0x27) +//#define P3_PWM_BRI_DUTY1L P33_ACCESS(0x28) +//#define P3_PWM_BRI_DUTY1H P33_ACCESS(0x29) +//#define P3_PWM_PRD_DIVL P33_ACCESS(0x2a) +//#define P3_PWM_DUTY0 P33_ACCESS(0x2b) +//#define P3_PWM_DUTY1 P33_ACCESS(0x2c) +//#define P3_PWM_DUTY2 P33_ACCESS(0x2d) +//#define P3_PWM_DUTY3 P33_ACCESS(0x2e) +//#define P3_PWM_CNT_RD P33_ACCESS(0x2f) + +//............. 0x0030 - 0x003f............ for PMU manager +#define P3_PMU_CON0 P33_ACCESS(0x30) + +#define P3_SFLAG0 P33_ACCESS(0x38) +#define P3_SFLAG1 P33_ACCESS(0x39) +#define P3_SFLAG2 P33_ACCESS(0x3a) +#define P3_SFLAG3 P33_ACCESS(0x3b) +//#define P3_SFLAG4 P33_ACCESS(0x3c) +//#define P3_SFLAG5 P33_ACCESS(0x3d) +//#define P3_SFLAG6 P33_ACCESS(0x3e) +//#define P3_SFLAG7 P33_ACCESS(0x3f) + +//............. 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_VLVD_FLT P33_ACCESS(0x46) +#define P3_PINR_CON1 P33_ACCESS(0x47) +#define P3_PINR_CON 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_PVDD2_AUTO P33_ACCESS(0x4e) + +//............. 0x0050 - 0x005f............ for port wake up +#define P3_WKUP_EN0 P33_ACCESS(0x50) +#define P3_WKUP_EN1 P33_ACCESS(0x51) +#define P3_WKUP_EDGE0 P33_ACCESS(0x52) +#define P3_WKUP_EDGE1 P33_ACCESS(0x53) +#define P3_WKUP_LEVEL0 P33_ACCESS(0x54) +#define P3_WKUP_LEVEL1 P33_ACCESS(0x55) +#define P3_WKUP_PND0 P33_ACCESS(0x56) +#define P3_WKUP_PND1 P33_ACCESS(0x57) +#define P3_WKUP_CPND0 P33_ACCESS(0x58) +#define P3_WKUP_CPND1 P33_ACCESS(0x59) + +//............. 0x0060 - 0x006f............ for +#define P3_AWKUP_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_INSEL P33_ACCESS(0x64) +#define P3_AWKUP_P_PND P33_ACCESS(0x65) +#define P3_AWKUP_N_PND P33_ACCESS(0x66) +#define P3_AWKUP_P_CPND P33_ACCESS(0x67) +#define P3_AWKUP_N_CPND P33_ACCESS(0x68) + +//............. 0x0070 - 0x007f............ for power gate +//#define P3_PGDR_CON0 P33_ACCESS(0x70) +//#define P3_PGDR_CON1 P33_ACCESS(0x71) +//#define P3_PGSD_CON P33_ACCESS(0x72) +//#define P3_PGFS_CON P33_ACCESS(0x73) + +//............. 0x0080 - 0x008f............ for +#define P3_AWKUP_FLT0 P33_ACCESS(0x80) +#define P3_AWKUP_FLT1 P33_ACCESS(0x81) +#define P3_AWKUP_FLT2 P33_ACCESS(0x82) + +#define P3_APORT_SEL0 P33_ACCESS(0x88) +#define P3_APORT_SEL1 P33_ACCESS(0x89) +#define P3_APORT_SEL2 P33_ACCESS(0x8a) + +//............. 0x0090 - 0x009f............ for analog control +#define P3_ANA_CON0 P33_ACCESS(0x90) +#define P3_ANA_CON1 P33_ACCESS(0x91) +#define P3_ANA_CON2 P33_ACCESS(0x92) +#define P3_ANA_CON3 P33_ACCESS(0x93) +#define P3_ANA_CON4 P33_ACCESS(0x94) +#define P3_ANA_CON5 P33_ACCESS(0x95) +#define P3_ANA_CON6 P33_ACCESS(0x96) +#define P3_ANA_CON7 P33_ACCESS(0x97) +#define P3_ANA_CON8 P33_ACCESS(0x98) +#define P3_ANA_CON9 P33_ACCESS(0x99) +#define P3_ANA_CON10 P33_ACCESS(0x9a) +#define P3_ANA_CON11 P33_ACCESS(0x9b) +#define P3_ANA_CON12 P33_ACCESS(0x9c) +#define P3_ANA_CON13 P33_ACCESS(0x9d) +#define P3_ANA_CON14 P33_ACCESS(0x9e) +#define P3_ANA_CON15 P33_ACCESS(0x9f) + +//............. 0x00a0 - 0x00af............ +#define P3_PR_PWR P33_ACCESS(0xa0) +#define P3_L5V_CON0 P33_ACCESS(0xa1) +#define P3_L5V_CON1 P33_ACCESS(0xa2) + +#define P3_LS_P11 P33_ACCESS(0xa4) + +#define P3_RVD_CON P33_ACCESS(0xa7) +#define P3_WKUP_SRC P33_ACCESS(0xa8) + +#define P3_PMU_DBG_CON P33_ACCESS(0xaa) +#define P3_ANA_KEEP1 P33_ACCESS(0xab) + +//............. 0x00b0 - 0x00bf............ for EFUSE +#define P3_EFUSE_CON0 P33_ACCESS(0xb0) +#define P3_EFUSE_CON1 P33_ACCESS(0xb1) +#define P3_EFUSE_RDAT P33_ACCESS(0xb2) + +#define P3_FUNC_EN P33_ACCESS(0xb8) + +//............. 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) +#define P3_PORT_SEL8 P33_ACCESS(0xc8) +#define P3_PORT_SEL9 P33_ACCESS(0xc9) +#define P3_PORT_SEL10 P33_ACCESS(0xca) +#define P3_PORT_SEL11 P33_ACCESS(0xcb) +#define P3_PORT_SEL12 P33_ACCESS(0xcc) +#define P3_PORT_SEL13 P33_ACCESS(0xcd) +#define P3_PORT_SEL14 P33_ACCESS(0xce) +#define P3_PORT_SEL15 P33_ACCESS(0xcf) + +//............. 0x00d0 - 0x00df............ +#define P3_LS_IO_DLY 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_ADC P33_ACCESS(0xd2) +#define P3_LS_AUDIO P33_ACCESS(0xd3) +#define P3_LS_RF P33_ACCESS(0xd4) +#define P3_LS_PLL P33_ACCESS(0xd5) + + +//===============================================================================// +// +// p33 rtcvdd +// +//===============================================================================// +//#define RTC_SFR_BEGIN 0x1000 + + + +//............. 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 PORT control +#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_FLEN RTC_ACCESS((0x94)) +#define R3_PORT_FLT RTC_ACCESS((0x95)) + +#define R3_PR_IN RTC_ACCESS((0x98)) +#define R3_PR_OUT RTC_ACCESS((0x99)) +#define R3_PR_DIR RTC_ACCESS((0x9a)) +#define R3_PR_DIE RTC_ACCESS((0x9b)) +#define R3_PR_PU RTC_ACCESS((0x9c)) +#define R3_PR_PD RTC_ACCESS((0x9d)) +#define R3_PR_HD RTC_ACCESS((0x9e)) + +//............. 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)) + + + + + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/power/power_api.h b/2.code/2.p11_code/include/cpu/br28/power/power_api.h new file mode 100644 index 0000000..5f87363 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/power_api.h @@ -0,0 +1,51 @@ +#ifndef __POWER_API_H__ +#define __POWER_API_H__ + +#include "gpio.h" + +enum LOW_POWER_LEVEL { + LOW_POWER_MODE_IDLE = 0, + LOW_POWER_MODE_STANDBY, + LOW_POWER_MODE_SLEEP, + LOW_POWER_MODE_DEEP_SLEEP, +}; + +//typedef u8(*idle_handler_t)(void); +typedef void(*low_power_enter)(enum LOW_POWER_LEVEL level); +typedef void(*low_power_exit)(enum LOW_POWER_LEVEL level); +typedef enum LOW_POWER_LEVEL(*level_handler_t)(void); + +struct low_power_target { + char *name; + level_handler_t level; + low_power_enter enter; + low_power_exit exit; + //idle_handler_t is_idle; +}; + +extern const struct low_power_target low_power_target_begin[]; +extern const struct low_power_target low_power_target_end[]; + +#define list_for_each_low_power_target(p) \ + for (p = low_power_target_begin; p < low_power_target_end; p++) + +//priv: 2 > 1 > 0 +#define REGISTER_LOWPOWER_TARGET(target, priv) \ + static const struct low_power_target target SEC_USED(.lp_target.priv.ops) + +enum LOW_POWER_LEVEL p11_low_power_target_query(void); + +void p11_low_power_target_enter(enum LOW_POWER_LEVEL level); + +void p11_low_power_target_exit(enum LOW_POWER_LEVEL level); + +extern volatile u8 p2m_message[]; +extern volatile u8 m2p_message[]; + +void power_init(void); + +void __power_recover(void); + +void p11_power_hw_manage(void); + +#endif /* #ifndef __POWER_HW_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/power/power_wakeup.h b/2.code/2.p11_code/include/cpu/br28/power/power_wakeup.h new file mode 100644 index 0000000..dfecda6 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power/power_wakeup.h @@ -0,0 +1,7 @@ +#ifndef __POWER_WAKEUP_H__ +#define __POWER_WAKEUP_H__ + +void power_wakeup_init(); + + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/power_interface.h b/2.code/2.p11_code/include/cpu/br28/power_interface.h new file mode 100644 index 0000000..918b71b --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/power_interface.h @@ -0,0 +1,16 @@ +#ifndef __POWER_INTERFACE_H__ +#define __POWER_INTERFACE_H__ + +#include "power/p33.h" + +#include "power/p33_api.h" + +#include "power/p11.h" + +#include "power/lp_ipc.h" + +#include "power/power_api.h" + +#include "power/power_wakeup.h" + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/ram_share.h b/2.code/2.p11_code/include/cpu/br28/ram_share.h new file mode 100644 index 0000000..79e35e9 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/ram_share.h @@ -0,0 +1,50 @@ +#ifndef __RAM_SHARE_H__ +#define __RAM_SHARE_H__ +/********************************************************************************************* + * Filename : ram_share.h + + * Description : 本文用于配置与主系统共享的ram大小 + + * Author : MoZhiYe + + * Email : mozhiye@zh-jieli.com + + * Last modifiled : 2021-10-21 17:00 + + * Copyright:(c)JIELI 2021-2029 @ , All Rights Reserved. +*********************************************************************************************/ + +//==========================================================// +// P2M & M2P MESSAGE_SIZE // +//==========================================================// +#define CONFIG_P2M_MESSAGE_SIZE 0x40 +#define CONFIG_M2P_MESSAGE_SIZE 0x60 + +//==========================================================// +// P11_VAD_CBUF_SIZE // +//==========================================================// +#define VAD_POINT_PER_FRAME (160) +#define VAD_FRAME_SIZE (VAD_POINT_PER_FRAME * 2) +#define VAD_CBUF_FRAME_CNT (6) +#define VAD_CBUF_TAG_SIZE (0) +#define VAD_CBUF_FRAME_SIZE (VAD_FRAME_SIZE + VAD_CBUF_TAG_SIZE) +#define CONFIG_P11_CBUF_SIZE (VAD_CBUF_FRAME_SIZE * VAD_CBUF_FRAME_CNT) + +//==========================================================// +// P11_VAD_CONFIG_SIZE // +//==========================================================// +#define CONFIG_P2M_AVAD_CONFIG_SIZE (20 * 4) //sizeof(int) +#define CONFIG_P2M_DVAD_CONFIG_SIZE (20 * 4) //sizeof(int) +#define CONFIG_VAD_CONFIG_SIZE (CONFIG_P2M_AVAD_CONFIG_SIZE + CONFIG_P2M_DVAD_CONFIG_SIZE) + +//==========================================================// +// P11 RAM SHARE WITH MAIN SYSTEM // +//NOTE: // +//1)该区域用于与主系统共享buf, 上电不进行初始化; // +//2)该宏用于配置最小值, 实际分配大小为 >= 配置值; // +//3)如果编译结果 < 配置值, 将会报错; // +//==========================================================// +#define CONFIG_P11_HEAP_RAM_SIZE_MIN 200 + + +#endif /* #ifndef __RAM_SHARE_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/spi_hw.h b/2.code/2.p11_code/include/cpu/br28/spi_hw.h new file mode 100644 index 0000000..23bb125 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/spi_hw.h @@ -0,0 +1,40 @@ +#ifndef __SPI_HW_H__ +#define __SPI_HW_H__ + +//======================================================// +// SPI HW DEFINE // +//======================================================// +//------------------- P11_SPI->CON +#define SPI_CON_CLEAR() (P11_SPI->CON = 0) +#define SPI_PENDING_IS() (P11_SPI->CON & BIT(15)) +#define SPI_PENDING_CLEAR() (P11_SPI->CON |= BIT(14)) +#define SPI_INT_ENABLE(v) SFR(P11_SPI->CON, 13, 1, v) +#define SPI_DIR_TRAMSMIT() (P11_SPI->CON &= ~BIT(12)) +#define SPI_DIR_RECEIVE() (P11_SPI->CON |= BIT(12)) +#define SPI_CS_IDLE_LOGIC(v) SFR(P11_SPI->CON, 7, 1, v) +#define SPI_CLK_IDLE_LOGIC(v) SFR(P11_SPI->CON, 6, 1, v) +#define SPI_UPDETE_AT_RISE_EDGE() (P11_SPI->CON &= ~BIT(5)) +#define SPI_UPDETE_AT_FALL_EDGE() (P11_SPI->CON |= BIT(5)) +#define SPI_SIMPLE_AT_RISE_EDGE() (P11_SPI->CON &= ~BIT(4)) +#define SPI_SIMPLE_AT_FALL_EDGE() (P11_SPI->CON |= BIT(4)) +#define SPI_BI_DIR(v) SFR(P11_SPI->CON, 3, 1, v) //双向/单向 +#define SPI_CS_ENABLE(v) SFR(P11_SPI->CON, 2, 1, v) //always set 1 +#define SPI_MASTER_MODE() (P11_SPI->CON &= ~BIT(1)) +#define SPI_SLAVE_MODE() (P11_SPI->CON |= BIT(1)) +#define SPI_MODULE_ENABLE(v) SFR(P11_SPI->CON, 0, 1, v) + +//------------------- P11_SPI->BAUD +#define SPI_BAUD_CONFIG(v) (P11_SPI->BAUD = v) + +//------------------- P11_SPI->BUF +#define SPI_BUF_READ() (P11_SPI->BUF) +#define SPI_BUF_WRITE(v) (P11_SPI->BUF = v) + +//------------------- P11_SPI->ADR +#define SPI_DMA_ADDR_CONFIG(v) (P11_SPI->ADR = (u32)v) +#define SPI_DMA_ADDR_GET(v) (P11_SPI->ADR) + +//------------------- P11_SPI->CNT +#define SPI_START_DMA_CNT(v) (P11_SPI->CNT = v) + +#endif /* #ifndef __SPI_HW_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/typedef.h b/2.code/2.p11_code/include/cpu/br28/typedef.h new file mode 100644 index 0000000..e51154e --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/typedef.h @@ -0,0 +1,89 @@ +//*********************************************************************************// +// Module name : typedef.h // +// Description : typedef head file // +// By Designer : zequan_liu // +// Dat changed : // +//*********************************************************************************// + +#ifndef __typedef_h__ +#define __typedef_h__ + +//------------------------------------------------------// +// typedef +//------------------------------------------------------// + +//typedef bool _bit, bit; +typedef float _f32, f32; +typedef double _d64, d64; + +typedef signed char _s08, s08, _s8, s8; +typedef signed short _s16, s16; +typedef signed int _s32, s32; +typedef signed long long _s64, s64; + +typedef unsigned char _u08, u08, _u8, u8, bool, BOOL; +typedef unsigned short _u16, u16; +typedef unsigned int _u32, u32; +typedef unsigned long long _u64, u64; + + +#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) + +//------------------------------------------------------// +// condition +//------------------------------------------------------// + +#define SIMEND asm ("trigger") + +#define FALSE 0 +#define TRUE 1 +#define false 0 +#define true 1 +#define NULL 0 + +#define AT(x) __attribute__ ((section(#x))) +#define SEC_USED(x) __attribute__((section(#x),used)) +#define __INLINE__ __attribute__ ((always_inline)) +#define __NOINLINE__ __attribute__ ((noinline)) +#define __WEAK__ __attribute__((weak)) +#define __NO_INIT__ +#define ___interrupt __attribute__((interrupt(""))) + +//------------------------------------------------------// +// common define +//------------------------------------------------------// + +#define hi(adr) ( (adr) >> 16 ) +#define lo(adr) ( (adr) & 0xffff ) + +#define LDR_W(ptr) *( (volatile _u32*)(ptr) ) +#define LDR_H(ptr) *( (volatile _u16*)(ptr) ) +#define LDR_B(ptr) *( (volatile _u08*)(ptr) ) + +#define STR_W(ptr,vld) *( (volatile _u32*)(ptr) ) = (_u32)(vld); +#define STR_H(ptr,vld) *( (volatile _u16*)(ptr) ) = (_u16)(vld); +#define STR_B(ptr,vld) *( (volatile _u08*)(ptr) ) = (_u08)(vld); + +#define BIT(n) ( 1<b) ? a : b ) + +#define SFR(sfr, start, len, dat) (sfr = sfr & ~((~(0xffffffff << len)) << start) | ((dat & (~(0xffffffff << len))) << start)) + +#define NOP() asm volatile ("nop") + +#endif + +//*********************************************************************************// +// // +// end of this module // +// // +//*********************************************************************************// diff --git a/2.code/2.p11_code/include/cpu/br28/uart.h b/2.code/2.p11_code/include/cpu/br28/uart.h new file mode 100644 index 0000000..4b19c02 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/uart.h @@ -0,0 +1,61 @@ +#ifndef __UART_H__ +#define __UART_H__ + +//======================================================// +// UART HW DEFINE // +//======================================================// +//------------------- P11_UARTx->BAUD +#define UART_BAUD_SET(x,v) (x->BAUD = v) + +//------------------- P11_UARTx->CLK_CON0 +#define UART_CON0_CLEAR(x) (x->CON0 = 0) +#define UART_TX_PENDING_IS(x) (x->CON0 & BIT(15)) +#define UART_RX_PENDING_IS(x) (x->CON0 & BIT(14)) +#define UART_TX_PENDING_CLEAR(x) (x->CON0 |= BIT(13)) +#define UART_RX_PENDING_CLEAR(x) (x->CON0 |= BIT(12)) +#define UART_OT_PENDING_IS(x) (x->CON0 & BIT(11)) +#define UART_OT_PENDING_CLEAR(x) (x->CON0 |= BIT(10)) +#define UART_OT_INT_ENABLE(x) (x->CON0 |= BIT(5)) +#define UART_OT_INT_DISABLE(x) (x->CON0 &= ~BIT(5)) + +enum UART_CLK_DIV_TABLE { + UART_CLK_DIV_4, + UART_CLK_DIV_3, +}; +/* +波特率计算: + UART_BAUD_SET = Fuart_clk / ((BAUD + 1) * UART_DIV_SEL) + */ +#define UART_DIV_SEL(x,v) SFR(x->CON0, 4, 1, v) + +#define UART_RX_INT_ENABLE(x) (x->CON0 |= BIT(3)) +#define UART_RX_INT_DISABLE(x) (x->CON0 &= ~BIT(3)) +#define UART_TX_INT_ENABLE(x) (x->CON0 |= BIT(2)) +#define UART_TX_INT_DISABLE(x) (x->CON0 &= ~BIT(2)) +#define UART_RX_ENABLE(x) (x->CON0 |= BIT(1)) +#define UART_RX_DISABLE(x) (x->CON0 &= ~BIT(1)) +#define UART_TX_ENABLE(x) (x->CON0 |= BIT(0)) +#define UART_TX_DISABLE(x) (x->CON0 &= ~BIT(0)) + +//------------------- P11_UARTx->CLK_CON2 +#define UART_CON1_CLEAR(x) (x->CON2 = 0) +#define UART_9BIT_ENABLE(x) (x->CON2 |= BIT(0)) +#define UART_9BIT_DISABLE(x) (x->CON2 &= ~BIT(0)) +#define UART_9BIT_TX_DATA(x,v) SFR(x->CON2, 1, 1 v) +#define UART_9BIT_RX_DATA(x) (x->CON2 & BIT(2)) + +//------------------- P11_UARTx->BUF +#define UART_BUF_WRITE(x,v) (x->BUF = v) +#define UART_BUF_READ(x) (x->BUF) + +//------------------- P11_UARTx->OTCNT +/* +OT超时计算: + Tot = Tuart_clk * UART_OTCNT_SET + */ +#define UART_OTCNT_SET(x,v) (x->OTCNT = v) + +void debug_uart_init(u8 tx_port); + +#endif + diff --git a/2.code/2.p11_code/include/cpu/br28/usr_timer.h b/2.code/2.p11_code/include/cpu/br28/usr_timer.h new file mode 100644 index 0000000..fa19279 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/usr_timer.h @@ -0,0 +1,10 @@ +#ifndef __USR_TIMER_H__ +#define __USR_TIMER_H__ + +void usr_timer_init(); + +u16 usr_timer_add(void *priv, void (*func)(void *priv), u32 msec, u8 priority); + +void usr_timer_del(u16 t); + +#endif diff --git a/2.code/2.p11_code/include/cpu/br28/vad_algo.h b/2.code/2.p11_code/include/cpu/br28/vad_algo.h new file mode 100644 index 0000000..c2f9b04 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/vad_algo.h @@ -0,0 +1,64 @@ +#ifndef __VAD_ALGO_H__ +#define __VAD_ALGO_H__ + +struct avad_config { + int avad_quantile_p; + int avad_th; + int avad_gain_db; + int avad_compare_v; +}; + +struct dvad_config { + int d_low_con_th; + int d_high_con_th; + int d2a_th_db; + int d2a_frame_con; + int dvad_gain_id; + int d_frame_con; + int d_stride1; + int d_stride2; +}; + + +#define hist_num 98 +#define dvad_frames_updata 128 +#define CONT_DD_ADFRMSIZE 25 +#define CONT_DD_ADFRMSIZE1 30 +#define co_1 16 +#define co_2 16 + +typedef int int32; +typedef short int16; +typedef signed char int8; +typedef unsigned int uint32; +typedef unsigned short uint16; +typedef unsigned char uint8; +typedef long long s64; +typedef unsigned long long u64; + +/**************dingdian%%%%%%%%%%%%%%%*/ + +typedef struct htk_fe_d { + unsigned short pow_hist[hist_num]; + unsigned char sum_cnt; + char speech_leave; + char sil_leave; + + uint8 d_voice_state; + char speech_fifo[CONT_DD_ADFRMSIZE1]; + char speech_cnt; + char vad_cnt; + int frame_cnt; + int energy_10frame; + uint8 speech_indexw1; + int sp_2_sl; + int sp_2_s2; +} htk_fe_dvad; + + +void dvad_Init(short init_noise); +void avad_Init(struct avad_config *cfg); +//int simple_avad(int cnts_l, int cnts_h, int frame_len, struct avad_config *cfg); +int dvad_Run(short *inbuf, int inlen, struct dvad_config *cfg); + +#endif /* #ifndef __VAD_ALGO_H__ */ diff --git a/2.code/2.p11_code/include/cpu/br28/vad_hw.h b/2.code/2.p11_code/include/cpu/br28/vad_hw.h new file mode 100644 index 0000000..0893572 --- /dev/null +++ b/2.code/2.p11_code/include/cpu/br28/vad_hw.h @@ -0,0 +1,12 @@ +#ifndef __VAD_HW_H__ +#define __VAD_HW_H__ + +#include "vad_algo.h" + +void vad_init(struct avad_config *a_cfg, struct dvad_config *d_cfg); + +void vad_hw_updata_read_ptr(u32 frames); + +void vad_close(void); + +#endif /* #ifndef __VAD_HW_H__ */ diff --git a/2.code/2.p11_code/include/device/SC7A20.h b/2.code/2.p11_code/include/device/SC7A20.h new file mode 100644 index 0000000..c05934c --- /dev/null +++ b/2.code/2.p11_code/include/device/SC7A20.h @@ -0,0 +1,34 @@ + +#ifndef _SL_SC7A20H_DRV_H_ +#define _SL_SC7A20H_DRV_H_ + +#if TCFG_SC7A20_EN + +/********客户需要进行的IIC接口封包函数****************/ +static unsigned char SL_SC7A20H_I2c_Spi_Write(unsigned char sl_spi_iic, unsigned char reg, unsigned char data); +static unsigned char SL_SC7A20H_I2c_Spi_Read(unsigned char sl_spi_iic, unsigned char reg, unsigned char len, unsigned char *buf); +/**SL_SC7A20H_I2c_Spi_Write 函数中, sl_spi_iic:0=spi 1=i2c Reg:寄存器地址 data:寄存器的配置值******************/ +/**SL_SC7A20H_I2c_Spi_Write 函数 是一个单次写的函数******************************************/ +/***SL_SC7A20H_I2c_Spi_Read 函数中, sl_spi_iic:0=spi 1=i2c Reg 同上,len:读取数据长度,buf:存储数据首地址(指针)**/ +/***SL_SC7A20H_I2c_Spi_Read 函数 是可以进行单次读或多次连续读取的函数************************/ + +/*************驱动初始化函数**************/ +static signed char SL_SC7A20H_Driver_Init(unsigned char Sl_spi_iic_init, unsigned char Sl_pull_up_mode); +/***输入参数:1,Sl_spi_iic_init:0-1***2,PULL_UP_MODE:0x00 0x08 0x04 0x0c********/ +/****Sl_spi_iic_init=0:SPI MODE, Sl_pull_up_mode config failed****************/ +/****Sl_spi_iic_init=1:IIC MODE***********************************************/ +/****Sl_pull_up_mode=0x00: SDO I2C pull up***********************************/ +/****Sl_pull_up_mode=0x08: I2C pull up and SDO open drain*******************/ +/****Sl_pull_up_mode=0x04: SDO pull up and I2C open drain*******************/ +/****Sl_pull_up_mode=0x0C: SDO I2C open drain********************************/ + +/*************返回数据情况如下**************/ +/**return : 0x28 表示CHIP ID 正常***********/ +/**return : 0 表示CHIP ID 异常***********/ +/**return :-1; SPI 通信问题***************/ +/**return :-2; IIC 通信问题***************/ + +#endif + +#endif // TCFG_SC7A20_EN + diff --git a/2.code/2.p11_code/include/device/bmp280.h b/2.code/2.p11_code/include/device/bmp280.h new file mode 100644 index 0000000..ef7fc10 --- /dev/null +++ b/2.code/2.p11_code/include/device/bmp280.h @@ -0,0 +1,166 @@ +#ifndef _BMP280_H_ +#define _BMP280_H_ + +#include "typedef.h" +#include "app_config.h" +// #include "asm/iic_soft.h" + + +#if TCFG_BMP280_DEV_ENABLE + +struct _bmp280_dev_platform_data { + u8 comms; //0:IIC; 1:SPI + u8 iic_hdl; + u8 iic_delay; //这个延时并非影响iic的时钟频率,而是2Byte数据之间的延时 +}; + + + +#define BMP280_I2C_ADDR 0x76 // The BMP280 I2C address +#define BMP280_I2C_ALT_ADDR 0x77 // The BMP280 I2C alternate address +#define BMP280_DEVICE_ID 0x58 // The BMP280 device ID +#define BMP280_RESET_VALUE 0xB6 // The BMP280 reset code + +#define BMP280_CHIPID_REG 0xD0 /*Chip ID Register */ +#define BMP280_RESET_REG 0xE0 /*Softreset Register */ +#define BMP280_STATUS_REG 0xF3 /*Status Register */ +#define BMP280_CTRLMEAS_REG 0xF4 /*Ctrl Measure Register */ +#define BMP280_CONFIG_REG 0xF5 /*Configuration Register */ +#define BMP280_PRESSURE_MSB_REG 0xF7 /*Pressure MSB Register */ +#define BMP280_PRESSURE_LSB_REG 0xF8 /*Pressure LSB Register */ +#define BMP280_PRESSURE_XLSB_REG 0xF9 /*Pressure XLSB Register */ +#define BMP280_TEMPERATURE_MSB_REG 0xFA /*Temperature MSB Reg */ +#define BMP280_TEMPERATURE_LSB_REG 0xFB /*Temperature LSB Reg */ +#define BMP280_TEMPERATURE_XLSB_REG 0xFC /*Temperature XLSB Reg */ +//状态寄存器转换标志 +#define BMP280_MEASURING 0x01 +#define BMP280_IM_UPDATE 0x08 + +/*calibration parameters */ +#define BMP280_DIG_T1_LSB_REG 0x88 +#define BMP280_DIG_T1_MSB_REG 0x89 +#define BMP280_DIG_T2_LSB_REG 0x8A +#define BMP280_DIG_T2_MSB_REG 0x8B +#define BMP280_DIG_T3_LSB_REG 0x8C +#define BMP280_DIG_T3_MSB_REG 0x8D +#define BMP280_DIG_P1_LSB_REG 0x8E +#define BMP280_DIG_P1_MSB_REG 0x8F +#define BMP280_DIG_P2_LSB_REG 0x90 +#define BMP280_DIG_P2_MSB_REG 0x91 +#define BMP280_DIG_P3_LSB_REG 0x92 +#define BMP280_DIG_P3_MSB_REG 0x93 +#define BMP280_DIG_P4_LSB_REG 0x94 +#define BMP280_DIG_P4_MSB_REG 0x95 +#define BMP280_DIG_P5_LSB_REG 0x96 +#define BMP280_DIG_P5_MSB_REG 0x97 +#define BMP280_DIG_P6_LSB_REG 0x98 +#define BMP280_DIG_P6_MSB_REG 0x99 +#define BMP280_DIG_P7_LSB_REG 0x9A +#define BMP280_DIG_P7_MSB_REG 0x9B +#define BMP280_DIG_P8_LSB_REG 0x9C +#define BMP280_DIG_P8_MSB_REG 0x9D +#define BMP280_DIG_P9_LSB_REG 0x9E +#define BMP280_DIG_P9_MSB_REG 0x9F +/******************ctrl_meas reg************************/ +//BMP工作模式 bit:1,0 +typedef enum { + BMP280_SLEEP_MODE = 0x0, + BMP280_FORCED_MODE = 0x1, //可以说0x2 + BMP280_NORMAL_MODE = 0x3 +} BMP280_WORK_MODE; +//BMP压力过采样因子 bit:4,3,2 +typedef enum { + BMP280_P_MODE_SKIP = 0x0, /*skipped*/ + BMP280_P_MODE_1, /*x1*/ + BMP280_P_MODE_2, /*x2*/ + BMP280_P_MODE_3, /*x4*/ + BMP280_P_MODE_4, /*x8*/ + BMP280_P_MODE_5 /*x16*/ +} BMP280_P_OVERSAMPLING; +//BMP温度过采样因子 bit:7,6,5 +typedef enum { + BMP280_T_MODE_SKIP = 0x0, /*skipped*/ + BMP280_T_MODE_1, /*x1*/ + BMP280_T_MODE_2, /*x2*/ + BMP280_T_MODE_3, /*x4*/ + BMP280_T_MODE_4, /*x8*/ + BMP280_T_MODE_5 /*x16*/ +} BMP280_T_OVERSAMPLING; + +/******************config reg************************/ +//bit0:spi3w_en: 1:enable spi 3-wire +//IIR滤波器时间常数 bit:4,3,2 +typedef enum { + BMP280_FILTER_OFF = 0x0, /*filter off*/ + BMP280_FILTER_MODE_1, /*0.223*ODR*/ /*x2*/ + BMP280_FILTER_MODE_2, /*0.092*ODR*/ /*x4*/ + BMP280_FILTER_MODE_3, /*0.042*ODR*/ /*x8*/ + BMP280_FILTER_MODE_4 /*0.021*ODR*/ /*x16*/ +} BMP280_FILTER_COEFFICIENT; +//保持时间 bit:7,6,5 +typedef enum { + BMP280_T_SB1 = 0x0, /*0.5ms*/ + BMP280_T_SB2, /*62.5ms*/ + BMP280_T_SB3, /*125ms*/ + BMP280_T_SB4, /*250ms*/ + BMP280_T_SB5, /*500ms*/ + BMP280_T_SB6, /*1000ms*/ + BMP280_T_SB7, /*2000ms*/ + BMP280_T_SB8, /*4000ms*/ +} BMP280_T_SB; + + +typedef struct { + /* T1~P9 为补偿系数 */ + u16 t1; + s16 t2; + s16 t3; + u16 p1; + s16 p2; + s16 p3; + s16 p4; + s16 p5; + s16 p6; + s16 p7; + s16 p8; + s16 p9; +} bmp280_params; + + +typedef struct { + BMP280_T_OVERSAMPLING t_osample; + BMP280_P_OVERSAMPLING p_osample; + BMP280_WORK_MODE workmode; +} bmp_oversample_mode; + +typedef struct { + BMP280_T_SB t_sb; + BMP280_FILTER_COEFFICIENT filter_coefficient; + u8 spi_en; +} bmp_config; + + +#define USE_FIXED_POINT_COMPENSATE 1//数据补偿算法选择:1:使用定点补偿 0:使用浮点补偿 +#if USE_FIXED_POINT_COMPENSATE //使用定点补偿 +typedef u32 bmp_pressure_data; +typedef s32 bmp_temperature_data; +#else //使用浮点补偿 +typedef double bmp_pressure_data; +typedef double bmp_temperature_data; +#endif + + + +bool bmp280_init(void *priv); +bool bmp280_check_id(void); +bool bmp280_set_temoversamp(bmp_oversample_mode *oversample_mode); +bool bmp280_set_standby_filter(bmp_config *bmp_config); +void bmp280_set_work_mode(BMP280_WORK_MODE workmode); +bool bmp280_reset(); //return 1:ok; 0:fail +void bmp280_get_temperature_and_pressure(bmp_temperature_data *temperature, bmp_pressure_data *pressure); +void bmp280_forced_mode_get_temperature_and_pressure(bmp_temperature_data *temperature, bmp_pressure_data *pressure); +float bmp280_get_altitude(bmp_temperature_data temperature, bmp_pressure_data pressure); + +// void bmp280_init_read_test(); +#endif +#endif diff --git a/2.code/2.p11_code/include/device/gSensor_algo.h b/2.code/2.p11_code/include/device/gSensor_algo.h new file mode 100644 index 0000000..083e30f --- /dev/null +++ b/2.code/2.p11_code/include/device/gSensor_algo.h @@ -0,0 +1,6 @@ +#pragma once + +void gsensor_algo_init(void); +void gsensor_algo_uninit(void); + +void gsensor_algo_run(void *accel, short point); \ No newline at end of file diff --git a/2.code/2.p11_code/include/device/gSensor_manage.h b/2.code/2.p11_code/include/device/gSensor_manage.h new file mode 100644 index 0000000..acb210a --- /dev/null +++ b/2.code/2.p11_code/include/device/gSensor_manage.h @@ -0,0 +1,105 @@ +#ifndef _GSENSOR_MANAGE_H +#define _GSENSOR_MANAGE_H +// #include "timer.h" +#include "app_config.h" +#include "includes.h" +#include "iic_api.h" +#include "typedef.h" +#include "circular_buf.h" +// #include "iic_soft.h" +// #include "cpu.h" +// #include "printf.h" +// #include "event.h" + +// #if TCFG_GSENSOR_ENABLE + +#define dev_log(fmt,...) //printf("[dev] " fmt "\n",##__VA_ARGS__) + +#define ACCEL_OF_GRAVITY 10 +#define ACCEL_DATA_GAIN 10 + +enum { + GSENSOR_DISABLE = 0, + GSENSOR_RESET_INT, + GSENSOR_RESUME_INT, + GSENSOR_INT_DET, + READ_GSENSOR_DATA, + GET_ACCEL_DATA, + SEARCH_SENSOR, +}; + +typedef struct { + short x; + short y; + short z; +} axis_info_t; + +typedef struct { + u8 logo[20]; + u8(*gravity_sensor_init)(void); + char (*gravity_sensor_check)(void); + int (*gravity_sensor_ctl)(u8 cmd, void *arg); +} G_SENSOR_INTERFACE; + + +struct gsensor_platform_data { + u8 iic; + char gSensor_name[20]; + u32 gSensor_int_io; +}; + +typedef struct { + u8 iic_hdl; + u8 iic_delay; //这个延时并非影响iic的时钟频率,而是2Byte数据之间的延时 + u8 ctl_flag; + int init_flag; + int check_cnt; + int check_timer_hdl; +} G_SENSOR_INFO; + + +int gravity_sensor_init(void *_data, cbuffer_t *cbuffer); +int gsensor_io_ctl(u8 cmd, void *arg); +int gsensor_enable(void); +int gsensor_disable(void); +void write_gsensor_data_handle(void); + +u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command); +int _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, int data_len); +int read_gsensor_buf_check_len(); +int gsensor_set_soft_irq_size(u16 size); +void gsensor_data_irq_handle(void); +int get_gSensor_data(short *buf); +int gSensor_read_data(u8 *buf, u8 buflen); +int read_gsensor_buf(short *buf); +int read_gsensor_nbuf(u8 *buf, short datalen); +extern G_SENSOR_INTERFACE gsensor_dev_begin[]; +extern G_SENSOR_INTERFACE gsensor_dev_end[]; + +#define REGISTER_GRAVITY_SENSOR(gSensor) \ + static G_SENSOR_INTERFACE gSensor SEC_USED(.gsensor_dev) + + +#define list_for_each_gsensor(c) \ + for (c=gsensor_dev_begin; c +// #include "iic_soft.h" +// #include "includes.h" +// #include "timer.h" + +struct _hx3603_dev_platform_data { + u8 iic_hdl; + u8 iic_delay; //这个延时并非影响iic的时钟频率,而是2Byte数据之间的延时 +}; +#define HX3603_ADDR 0x44 +#define HX3603_RADDR 0x89 +#define HX3603_WADDR 0x88 + + + + + + + +#define TIMER_READ_MODE + +typedef struct { + int32_t phase[3]; +} hrs3603_data_t; + +typedef enum { + MSG_ALG_NOT_OPEN = 0x01, + MSG_NO_TOUCH = 0x02, + MSG_PPG_LEN_TOO_SHORT = 0x03, + MSG_HR_READY = 0x04, + MSG_ALG_TIMEOUT = 0x05, + MSG_SETTLE = 0x06 +} hrs3603_msg_code_t; + +typedef enum { + MSG_BP_ALG_NOT_OPEN = 0x01, + MSG_BP_NO_TOUCH = 0x02, + MSG_BP_PPG_LEN_TOO_SHORT = 0x03, + MSG_BP_READY = 0x04, + MSG_BP_ALG_TIMEOUT = 0x05, + MSG_BP_SETTLE = 0x06 +} hrs3603_bp_msg_code_t; + +//add ericy 20180426 +typedef enum { + MSG_SPO2_ALG_NOT_OPEN = 0x01, + MSG_SPO2_NO_TOUCH = 0x02, + MSG_SPO2_PPG_LEN_TOO_SHORT = 0x03, + MSG_SPO2_READY = 0x04, + MSG_SPO2_ALG_TIMEOUT = 0x05, + MSG_SPO2_SETTLE = 0x06 +} hrs3603_spo2_msg_code_t; + +typedef struct { + hrs3603_spo2_msg_code_t spo2_alg_status; + uint32_t data_cnt; + uint16_t spo2_result; + uint8_t hr_result; + +} hrs3603_spo2_results_t; + +typedef struct { + uint8_t red_offset_idac; + uint8_t ir_offset_idac; + uint16_t spo2_start_cnt; + +} hrs3603_spo2_agcpara_t; + +typedef enum { + MSG_BFR_ALG_NOT_OPEN = 0x01, + MSG_BFR_NO_TOUCH = 0x02, + MSG_BFR_PPG_LEN_TOO_SHORT = 0x03, + MSG_BFR_READY = 0x04, + MSG_BFR_ALG_TIMEOUT = 0x05, + MSG_BFR_SETTLE = 0x06 +} hrs3603_bfr_msg_code_t; + +//add ericy 20180428 +typedef enum { + DEFAULT_MOTION = 0, + STATIC_MOTION = 1, + WALKING_MOTION = 2, + RUNING_MOTION = 3, + CYCLING_MOTION = 4, + SWINMING_MOTION = 5, + TENNIS_MOTION = 6, + HRM_MONITOR_MODE = 7 +} MOIION_STATUS; + +typedef struct { + + hrs3603_bfr_msg_code_t bfr_alg_status; + uint32_t data_cnt; + uint16_t bfr_result; + +} hrs3603_bfr_results_t; + +//add ericy 20180428 + +typedef struct { + hrs3603_msg_code_t alg_status; + uint32_t data_cnt; + uint8_t hr_result; + uint8_t hr_result_qual; // ericy add20170111 + u8 object_flg; +} hrs3603_results_t; + + +typedef struct { + hrs3603_bp_msg_code_t bp_alg_status; + uint8_t sbp; + uint8_t dbp; + uint32_t data_cnt; + uint8_t hr_result; //20170614 ericy + u8 object_flg; +} hrs3603_bp_results_t; + + + +typedef struct { + uint8_t reg_value_id; + uint8_t reg_value_osc; + uint8_t reg_value_ldo; + uint8_t reg_value_led; +} hx3603_efuse_value; + + + +#ifdef HRS_BLE_APP +typedef struct { + int8_t vector_flag; + uint8_t hr_result; + uint8_t alg_status; + uint32_t data_cnt; + uint16_t hrm_raw_data; + uint16_t als_raw_data; + uint16_t gsensor_x; + uint16_t gsensor_y; + uint16_t gsensor_z; +} rawdata_vector_t ; +#endif + +//extern volatile oled_display_t oled_dis; +void Hrs3603_hr_alg_config(void); +void Hrs3603_spo2_alg_config(void); +bool Hrs3603_chip_check_id(); + +void Hrs3603_chip_disable(void); +void hrs3603_disable(); +void hrs3603_hr_enable(void); +void hrs3603_spo2_enable(void); + +bool Hrs3603_write_reg(u8 addr, u8 data); +u8 Hrs3603_read_reg(u8 addr); +bool Hrs3603_read_hrs(u32 *hrm_data, u32 *als_data); +bool Hrs3603_read_ps1(u32 *infrared_data); +u8 Hrs3603_read_red_phase(u32 *red_raw_data, u32 *als_inred_data); +u8 Hrs3603_read_ir_phase(u32 *ir_raw_data, u32 *als_inir_data); +void Hrs3603_Int_handle(void); +int read_hrs3603_result(void *arg, u16 len); +void Hrs3603_spo2_Int_handle(void); +int read_hrs3603_spo2_result(void *arg, u16 len); +int Hrs3603_io_ctl(u8 cmd, void *arg); +#endif +#endif // HRS3603_H_INCLUDED + diff --git a/2.code/2.p11_code/include/device/mir3da.h b/2.code/2.p11_code/include/device/mir3da.h new file mode 100644 index 0000000..033e92e --- /dev/null +++ b/2.code/2.p11_code/include/device/mir3da.h @@ -0,0 +1,71 @@ + +/******************** (C) COPYRIGHT 2018 MiraMEMS ***************************** +* File Name : mir3da.h +* Author : ycwang@miramems.com +* Version : V1.0 +* Date : 05/18/2018 +* Description : Demo for configuring mir3da +*******************************************************************************/ +#ifndef __MIR3DA_h +#define __MIR3DA_h +#ifdef TCFG_MIR3DA_EN && TCFG_MIR3DA_EN + +/******************************************************************************* +Macro definitions - Register define for Gsensor asic +********************************************************************************/ +#define NSA_REG_SPI_I2C 0x00 +#define NSA_REG_WHO_AM_I 0x01 +#define NSA_REG_ACC_X_LSB 0x02 +#define NSA_REG_ACC_X_MSB 0x03 +#define NSA_REG_ACC_Y_LSB 0x04 +#define NSA_REG_ACC_Y_MSB 0x05 +#define NSA_REG_ACC_Z_LSB 0x06 +#define NSA_REG_ACC_Z_MSB 0x07 +#define NSA_REG_MOTION_FLAG 0x09 +#define NSA_REG_STEPS_MSB 0x0D +#define NSA_REG_STEPS_LSB 0x0E +#define NSA_REG_G_RANGE 0x0F +#define NSA_REG_ODR_AXIS_DISABLE 0x10 +#define NSA_REG_POWERMODE_BW 0x11 +#define NSA_REG_SWAP_POLARITY 0x12 +#define NSA_REG_FIFO_CTRL 0x14 +#define NAS_REG_INT_SET0 0x15 +#define NSA_REG_INTERRUPT_SETTINGS1 0x16 +#define NSA_REG_INTERRUPT_SETTINGS2 0x17 +#define NSA_REG_INTERRUPT_MAPPING1 0x19 +#define NSA_REG_INTERRUPT_MAPPING2 0x1a +#define NSA_REG_INTERRUPT_MAPPING3 0x1b +#define NSA_REG_INT_PIN_CONFIG 0x20 +#define NSA_REG_INT_LATCH 0x21 +#define NSA_REG_ACTIVE_DURATION 0x27 +#define NSA_REG_ACTIVE_THRESHOLD 0x28 +#define NSA_REG_TAP_DURATION 0x2A +#define NSA_REG_TAP_THRESHOLD 0x2B +#define NSA_REG_STEP_CONFIG1 0x2F +#define NSA_REG_STEP_CONFIG2 0x30 +#define NSA_REG_STEP_CONFIG3 0x31 +#define NSA_REG_STEP_CONFIG4 0x32 +#define NSA_REG_STEP_FILTER 0x33 +#define NSA_REG_SM_THRESHOLD 0x34 +#define NSA_REG_CUSTOM_OFFSET_X 0x38 +#define NSA_REG_CUSTOM_OFFSET_Y 0x39 +#define NSA_REG_CUSTOM_OFFSET_Z 0x3a +#define NSA_REG_ENGINEERING_MODE 0x7f +#define NSA_REG_SENSITIVITY_TRIM_X 0x80 +#define NSA_REG_SENSITIVITY_TRIM_Y 0x81 +#define NSA_REG_SENSITIVITY_TRIM_Z 0x82 +#define NSA_REG_COARSE_OFFSET_TRIM_X 0x83 +#define NSA_REG_COARSE_OFFSET_TRIM_Y 0x84 +#define NSA_REG_COARSE_OFFSET_TRIM_Z 0x85 +#define NSA_REG_FINE_OFFSET_TRIM_X 0x86 +#define NSA_REG_FINE_OFFSET_TRIM_Y 0x87 +#define NSA_REG_FINE_OFFSET_TRIM_Z 0x88 +#define NSA_REG_SENS_COMP 0x8c +#define NSA_REG_MEMS_OPTION 0x8f +#define NSA_REG_CHIP_INFO 0xc0 +#define NSA_REG_CHIP_INFO_SECOND 0xc1 +#define NSA_REG_MEMS_OPTION_SECOND 0xc7 +#define NSA_REG_SENS_COARSE_TRIM 0xd1 +#define NAS_REG_OSC_TRIM 0x8e +#endif +#endif diff --git a/2.code/2.p11_code/include/device/msa310.h b/2.code/2.p11_code/include/device/msa310.h new file mode 100644 index 0000000..92fa930 --- /dev/null +++ b/2.code/2.p11_code/include/device/msa310.h @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019 Silan MEMS. All Rights Reserved. +*/ +#ifndef _MSA310_H_ +#define _MSA310_H_ + + +#if TCFG_MSA310_EN +#include "stdint.h" +//msa310 max fre:400Khz(iic) +#define MSA_REG_SOFT_RESET 0x00 +#define MSA_REG_WHO_AM_I 0x01 +#define MSA_REG_ACC_X_LSB 0x02 +#define MSA_REG_ACC_X_MSB 0x03 +#define MSA_REG_ACC_Y_LSB 0x04 +#define MSA_REG_ACC_Y_MSB 0x05 +#define MSA_REG_ACC_Z_LSB 0x06 +#define MSA_REG_ACC_Z_MSB 0x07 + +#define MSA_REG_MOTION_FLAG 0x09 +#define MSA_REG_DATA_INT_FLAG 0x0a +#define MSA_REG_FIFO_SAMPLE_CNT 0x0d +#define MSA_REG_G_RANGE 0x0f +#define MSA_REG_ODR_AXIS_DISABLE 0x10 +#define MSA_REG_POWERMODE_BW 0x11 +#define MSA_REG_SWAP_POLARITY 0x12 +#define MSA_REG_FIFO_CTRL 0x14 +#define MSA_REG_FIFO_CTRL1 0x15 +#define MSA_REG_INTERRUPT_SETTINGS1 0x16 +#define MSA_REG_INTERRUPT_SETTINGS2 0x17 +#define MSA_REG_INTERRUPT_MAPPING1 0x19 +#define MSA_REG_INTERRUPT_MAPPING2 0x1a +#define MSA_REG_INT_PIN_CONFIG 0x20 +#define MSA_REG_INT_LATCH 0x21 +#define MSA_REG_ACTIVE_DURATION 0x27 +#define MSA_REG_ACTIVE_THRESHOLD 0x28 + +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; + +int32_t msa_read_data(int16_t *x, int16_t *y, int16_t *z); +int32_t msa_register_read_continuously(uint8_t addr, uint8_t count, uint8_t *data); +//int32_t i2c_write_byte_data( uint8_t addr, uint8_t data); +bool msa_WriteBytes(uint8_t RegAddr, uint8_t Data); +bool msa_ReadBytes(uint8_t *Data, uint8_t RegAddr); +// int32_t msa_read_fifo(int16_t *xBuf, int16_t *yBuf, int16_t *zBuf, int len); +int32_t msa_read_fifo(axis_info_t *raw_accel); +uint8_t msa_ReadBytes_ACKEND(uint8_t *Data, uint8_t RegAddr); +uint8_t msa310_init(void); + +#endif +#endif // MSA310_H + diff --git a/2.code/2.p11_code/include/device/msa310_function.h b/2.code/2.p11_code/include/device/msa310_function.h new file mode 100644 index 0000000..465eea7 --- /dev/null +++ b/2.code/2.p11_code/include/device/msa310_function.h @@ -0,0 +1,113 @@ +/** + ****************************************************************************** + * @file msa_app_fixpoint.h + * @author memsensing algorithm team + * @version V1.1.0 + * @date 18- 7 -2017 + * @brief This file contains definitions for msa_app_fixpoint.c firmware + ****************************************************************************** +**/ + +#ifndef _MSA_APP_FIXPOINT_H +#define _MSA_APP_FIXPOINT_H + +#if (TCFG_MSA310_EN) + +#define ABS(x) ( (x)>0?(x):-(x) ) +#define MSA_AWAKE 0 +#define MSA_RESTLESS 1 +#define MSA_ASLEEP 2 +#define MSA_ONTABLE 3 + +typedef struct { + int thisDirectionUp; + int lastDirectionUp; + int thisDirectionUpCnt; + int lastDirectionUpCnt; + long long timeCnt; + long long timeNow; + long long lastPeakTime; + long long thisPeakTime; + long long lastStepTime; + long long thisStepTime; + int timeInterval; + short int valueNew; + short int valueOld; + short int valuePeak; + short int valueValley; + short int valueThreshold; + short int valueThresholdInitial; + short int ThresholdCnt; + short int Threshold[4]; + int step_cnt; + int step_sum; + short int stepMode; + short int stepModeCnt; + long long stepModeTimeCnt; + short int staticModeCnt; + +} Step_Typedef, *pStep_Typedef; + +extern Step_Typedef Step_Structure; + +typedef struct { + unsigned char autoBrightFlag; + unsigned int enableCnt; + unsigned int enableCntLimit; + unsigned int disableCnt; + unsigned int disableCntLimit; + unsigned int accSquareSum[2]; + unsigned int accSquareMaxLimit; + unsigned int accSquareMinLimit; + unsigned char isLevelRotationCnt; + unsigned char isLevelCnt; + unsigned char notLevelCnt; + unsigned char isLevelCntLimit; + unsigned char levelRotationEnableCnt; + unsigned char levelRotationEnableCntLimit; + unsigned char levelDisableCnt; + unsigned char levelDisableCntLimit; + unsigned char autoBrightFromLevelFlag; + unsigned char lastStatus; + unsigned char backlightOffCnt; + unsigned char backlightOffCntSum; + unsigned char lightOnTimeCnt; + unsigned char lightOffTimeCnt; + int yzAngel; + int xzAngel; + int xzAngelLimitMin; + int xzAngelLimitMax; + int yzAngelLimitMin; + int yzAngelLimitMax; +} Bright_Typedef, *pBright_Typedef; + +extern Bright_Typedef Bright_Structure; + +typedef struct { + unsigned char Sleep_End_Flag; + unsigned int accSquareSum[20]; + short int Acc[3][20]; + int SumX; + int SumY; + int SumZ; + int SumX_Last; + int SumY_Last; + int SumZ_Last; + unsigned char Data_Cnt; + unsigned char A[5]; + unsigned short int Minute_Cnt; +} Sleep_Typedef, *pSleep_Typedef; + +extern Sleep_Typedef Sleep_Structure; + +void msa_param_init(void); +unsigned int msa_step(short int x, short int y, short int z); +unsigned char msa_light(short int x, short int y, short int z); +int msa_sleep(short int x, short int y, short int z); +void msa_step_clear(void); + +#endif /*TCFG_MSA310_EN*/ +#endif /*_MSA_APP_FIXPOINT_H*/ + +/************************ (C) COPYRIGHT MEMSENSING *****END OF FILE****/ + diff --git a/2.code/2.p11_code/include/device/msa31x.h b/2.code/2.p11_code/include/device/msa31x.h new file mode 100644 index 0000000..2492f97 --- /dev/null +++ b/2.code/2.p11_code/include/device/msa31x.h @@ -0,0 +1,48 @@ +#ifndef __MSA31X_H__ +#define __MSA31X_H__ + +#include "stdint.h" + +#define MSA_REG_SPI_I2C 0x00 +#define MSA_REG_WHO_AM_I 0x01 +#define MSA_REG_ACC_X_LSB 0x02 +#define MSA_REG_ACC_X_MSB 0x03 +#define MSA_REG_ACC_Y_LSB 0x04 +#define MSA_REG_ACC_Y_MSB 0x05 +#define MSA_REG_ACC_Z_LSB 0x06 +#define MSA_REG_ACC_Z_MSB 0x07 + +#define MSA_REG_MOTION_FLAG 0x09 +#define MSA_REG_G_RANGE 0x0f +#define MSA_REG_ODR_AXIS_DISABLE 0x10 +#define MSA_REG_POWERMODE_BW 0x11 +#define MSA_REG_SWAP_POLARITY 0x12 +#define MSA_REG_FIFO_CTRL 0x14 +#define MSA_REG_INTERRUPT_SETTINGS1 0x16 +#define MSA_REG_INTERRUPT_SETTINGS2 0x17 +#define MSA_REG_INTERRUPT_MAPPING1 0x19 +#define MSA_REG_INTERRUPT_MAPPING2 0x1a +#define MSA_REG_INTERRUPT_MAPPING3 0x1b +#define MSA_REG_INT_PIN_CONFIG 0x20 +#define MSA_REG_INT_LATCH 0x21 +#define MSA_REG_ACTIVE_DURATION 0x27 +#define MSA_REG_ACTIVE_THRESHOLD 0x28 +#define MSA_REG_TAP_DURATION 0x2A +#define MSA_REG_TAP_THRESHOLD 0x2B +#define MSA_REG_CUSTOM_OFFSET_X 0x38 +#define MSA_REG_CUSTOM_OFFSET_Y 0x39 +#define MSA_REG_CUSTOM_OFFSET_Z 0x3a +#define MSA_REG_ENGINEERING_MODE 0x7f +#define MSA_REG_SENSITIVITY_TRIM_X 0x80 +#define MSA_REG_SENSITIVITY_TRIM_Y 0x81 +#define MSA_REG_SENSITIVITY_TRIM_Z 0x82 +#define MSA_REG_COARSE_OFFSET_TRIM_X 0x83 +#define MSA_REG_COARSE_OFFSET_TRIM_Y 0x84 +#define MSA_REG_COARSE_OFFSET_TRIM_Z 0x85 +#define MSA_REG_FINE_OFFSET_TRIM_X 0x86 +#define MSA_REG_FINE_OFFSET_TRIM_Y 0x87 +#define MSA_REG_FINE_OFFSET_TRIM_Z 0x88 +#define MSA_REG_SENS_COMP 0x8c +#define MSA_REG_SENS_COARSE_TRIM 0xd1 + +#endif diff --git a/2.code/2.p11_code/include/device/p11_algo_api.h b/2.code/2.p11_code/include/device/p11_algo_api.h new file mode 100644 index 0000000..7488b03 --- /dev/null +++ b/2.code/2.p11_code/include/device/p11_algo_api.h @@ -0,0 +1,87 @@ +#pragma once + +#define algo_log(fmt,...) printf("[algo] " fmt "\n",##__VA_ARGS__) + +typedef union { + struct { + short wrist_up: 1; //抬腕动作 + short wrist_down: 1; //落腕动作 + short double_click: 1; //双击屏幕 + short hitting: 1; //击球动作 + short on_desk: 1; //放置桌面 + }; + short all; +} algo_type; + +typedef struct { + short x; //gsensor x轴数据 + short y; //gsensor y轴数据 + short z; //gsensor z轴数据 +} accel_data; + +typedef struct { + short lsb_g; //gsensor参数 1g对应的数值 + short sps; //gsensor参数 每秒采样次数 +} accel_config; + + +typedef enum { + ALGO_NOTHING, //没有相关动作 + ALGO_WRIST_UP, //抬腕动作 + ALGO_WRIST_DOWN, //落腕动作 + ALGO_DOUBLE_CLICK, //双击屏幕 + ALGO_HITTING, //击球动作 + ALGO_ON_DESK, //放置桌面 +} algo_out; + + +/* --------------------------------------------------------------------------*/ +/** + * @brief g sensor算法初始化 + * + * @param [in] select 选择需要开启的算法 + * @param [in] lsb_g gsensor参数 1g对应的数值 + * @param [in] sps gsensor参数 每秒采样次数 + * + */ +void algo_gsensor_init(algo_type open, accel_config accel); + +/* --------------------------------------------------------------------------*/ +/** + * @brief g sensor算法运行函数 + * + * @param [in] data 参考结构体algo_data + * @param [in] point gsensor 数据点数 + * + */ +algo_out algo_gsensor_run(accel_data *data, short point); + + +/* --------------------------------------------------------------------------*/ +/** + * @brief 设置抬腕算法亮屏的阈值,阈值越小越灵敏 + * + * @param [in] threshold 允许范围 0~100 ,建议范围 5~40,默认值 5 + * + */ +void algo_gsensor_set_wrist(short threshold); + + +/* --------------------------------------------------------------------------*/ +/** + * @brief 设置算法log打印开关 + * + * @param [in] enable 1-开启打印 0-关闭打印 + * + */ +void algo_gsensor_set_debug(char enable); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 获取算法亮屏版本 + * + * @param [out] 版本号:100~255 + * + */ +unsigned char algo_gsensor_get_ver(void); + diff --git a/2.code/2.p11_code/include/device/stk832x.h b/2.code/2.p11_code/include/device/stk832x.h new file mode 100644 index 0000000..c0b96ec --- /dev/null +++ b/2.code/2.p11_code/include/device/stk832x.h @@ -0,0 +1,21 @@ +#pragma once +#ifdef TCFG_STK832X_EN && TCFG_STK832X_EN +#define STK832x_REG_RANGESEL 0x0F +#define STK832x_RANGE_2G 0x03 +#define STK832x_RANGE_4G 0x05 +#define STK832x_RANGE_8G 0x08 + +#define STK_REG_POWMODE 0x11 +#define STK_SUSPEND_MODE 0x80 + +#define STK832x_SET_ODR_25HZ +#define STK832x_SET_ODR_50HZ +#define STK832x_SET_ODR_100HZ + +#define STK_REG_CHIPID 0x00 +#define STK8327_CHIPID_VAL 0x26 /* STK8327 CHIP ID = 0x26 */ +#define STK8329_CHIPID_VAL 0x25 /* STK8329&STK8325 CHIP ID = 0x25 */ +#define STK832x_CHIPID_VAL 0x23 /* STK8321 or STK8323 CHIP ID = 0x23 */ +#define FIFO_FRAME_MAX_CNT 32 + +#endif diff --git a/2.code/2.p11_code/include/generic/bank_switch.h b/2.code/2.p11_code/include/generic/bank_switch.h new file mode 100644 index 0000000..d1487fe --- /dev/null +++ b/2.code/2.p11_code/include/generic/bank_switch.h @@ -0,0 +1,62 @@ +/********************************************************************************************* + * Filename : bank_switch.h + + * Description : 本文件存放P11切Bank流程接口(API)和数据结构声明 + + * Author : MoZhiYe + + * Email : mozhiye@zh-jieli.com + + * Last modifiled : 2021-11-22 10:00 + + * Copyright:(c)JIELI 2021-2029 @ , All Rights Reserved. +*********************************************************************************************/ +#ifndef __BANK_SWITCH__ +#define __BANK_SWITCH__ + +//====================================================// +// BANK模块管理 // +//====================================================// +//demo +#define BANK_DEMO_TAG "demo" +#define BANK_CODE_DEMO_INIT_BANK_0 0 +#define BANK_CODE_DEMO_NORMAL_BANK_1 1 +#define BANK_CODE_DEMO_NORMAL_BANK_2 2 +#define BANK_CODE_DEMO_BANK_MAX 3 + + +#define BANK_SENSOR_TAG "sensor" +#define BANK_CODE_SENSOR_INIT_BANK_0 0 +#define BANK_CODE_SENSOR_NORMAL_BANK_1 1 +#define BANK_CODE_SENSOR_NORMAL_BANK_2 2 +#define BANK_CODE_SENSOR_BANK_MAX 3 + + +#define BANK_SYS_TAG "sys" +#define BANK_CODE_SYS_INIT_BANK_0 0 +#define BANK_CODE_SYS_NORMAL_BANK_1 1 + +extern int overlay_demo_begin[]; +extern int overlay_sensor_begin[]; + +//others + + +#define _BANK_CODE_SEG(name, index) __attribute__((section("."name".code.bank."#index))) +#define __BANK_CODE_SEG_DEFINE(name, index) _BANK_CODE_SEG(name, index) + +#define REGISTER_CODE_SEG(index) \ + _BANK_CODE_SEG(BANK_NAME,index) + + + + +struct bank_info { + char *name; + u8 total_bank; + u32 run_addr; +}; + +void bank_code_switch(char *name, u8 bank_index); + +#endif /* #ifndef __BANK_SWITCH__ */ diff --git a/2.code/2.p11_code/include/generic/circular_buf.h b/2.code/2.p11_code/include/generic/circular_buf.h new file mode 100644 index 0000000..efeef3f --- /dev/null +++ b/2.code/2.p11_code/include/generic/circular_buf.h @@ -0,0 +1,279 @@ +#ifndef CIRCULAR_BUF_INTERFACE_H +#define CIRCULAR_BUF_INTERFACE_H + +#include "typedef.h" +// #include "system/spinlock.h" + + + + + +/* --------------------------------------------------------------------------*/ +/** + * @brief cbuffer结构体 + */ +/* ----------------------------------------------------------------------------*/ +typedef struct _cbuffer { + u8 *begin; + u8 *end; + u8 *read_ptr; + u8 *write_ptr; + u8 *tmp_ptr ; + u32 tmp_len; + u32 data_len; + u32 total_len; + // spinlock_t lock; +} cbuffer_t; + + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief cbuffer初始化 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] buf 缓存空间 + * @param [in] size 缓存总大小 + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:cb_memcpy管理 + * @brief 把cbuffer_t结构体管理的内存空间的数据拷贝到buf数组 + + * @param [in] cbuffer cbuffer 句柄 + * @param [out] buf 指向用于存储读取内容的目标数组 + * @param [in] len 要读取的字节长度 + * + * @return 成功读取的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:cb_memcpy管理 + * @brief 把buf数组数据拷贝cbuffer_t结构体管理的内存空间 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] buf 指向用于存储写入内容的目标数组 + * @param [in] len 要写入的字节长度 + * + * @return 成功写入的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief 判断是否可写入len字节长度的数据 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] len len字节长度的数据 + * + * @return 返回可以写入的len字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:外部内存管理 + * @brief 预分配待写入数据的空间,要和cbuf_write_updata()配套使用,更新cbuf管理handle数据。 + * + * @param [in] cbuffer cbuffer句柄 + * @param [in] len 回传可以最多写入len字节长度的数据 + * + * @return 当前写指针的地址 + */ +/* ----------------------------------------------------------------------------*/ +void *cbuf_write_alloc(cbuffer_t *cbuffer, u32 *len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:外部内存管理 + * @brief 更新cbuf管理handle的写指针位置和数据长度 + * + * @param [in] cbuffer cbuffer句柄 + * @param [in] len 在非cbuffer_t结构体包含的内存空间中写入的数据的实际字节长度 + * + * @return 当前写指针的地址 + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_write_updata(cbuffer_t *cbuffer, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:外部内存管理 + * @brief 预分配待读取数据的空间,需要和cbuf_read_updata()配套使用,更新cbuf管理handle数据 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] len 回传可以最多读取len字节长度的数据 + * + * @return 当前读指针的地址 + */ +/* ----------------------------------------------------------------------------*/ +void *cbuf_read_alloc(cbuffer_t *cbuffer, u32 *len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:外部内存管理 + * @brief 更新cbuf管理handle的读指针位置和数据长度 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] len 在非cbuffer_t结构体包含的内存空间中读取的数据的实际字节长度 + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_read_updata(cbuffer_t *cbuffer, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:外部内存管理 + * @brief 清空cbuffer空间 + * + * @param [in] cbuffer cbuffer 句柄 + + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_clear(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:cb_memcpy管理。 + * @brief 指定位置进行数据重写 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] begin 指向需要重写内容的开始地址 + * @param [out] buf 指向用于存储重写内容的目标数组 + * @param [in] len 待重写内容的长度 + * + * @return 成功重写的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_rewrite(cbuffer_t *cbuffer, void *begin, void *buf, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:cb_memcpy管理 + * @brief 更新指向上一次操作的指针为当前指针,并刷新数据长度 + * + * @param [in] cbuffer cbuffer 句柄 + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_discard_prewrite(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:cb_memcpy管理 + * @brief 操作指针回退到上一次的操作位置,并刷新数据长度 + * + * @param [in] cbuffer cbuffer 句柄 + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_updata_prewrite(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:cb_memcpy管理 + * @brief 回退写入内容,从上一次的操作的指针处进行覆盖填充 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [out] buf 指向用于覆盖写入内容的目标数组 + * @param [in] len 填充数据的字节长度 + * + * @return 成功填充数据的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_prewrite(cbuffer_t *cbuffer, void *buf, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief 获取指向写指针的地址 + * + * @param [in] cbuffer cbuffer 句柄 + * + * @return 写指针的地址 + */ +/* ----------------------------------------------------------------------------*/ +void *cbuf_get_writeptr(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief 获取cbuffer存储的数据的字节长度 + * + * @param [in] cbuffer cbuffer句柄 + * + * @return 获取cbuffer存储的数据的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_get_data_size(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief 获取指向读指针的地址 + * + * @param [in] cbuffer cbuffer句柄 + * + * @return 读指针的地址 + */ +/* ----------------------------------------------------------------------------*/ +void *cbuf_get_readptr(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief 读指针向后回退 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] len 要回退的字节长度 + * + * @return 成功回退的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_read_goback(cbuffer_t *cbuffer, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:全局 + * @brief 获取存储数据的字节长度 + * + * @param [in] cbuffer cbuffer 句柄 + * + * @return 存储数据的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_get_data_len(cbuffer_t *cbuffer); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:memcpy管理+cbuf_read_alloc系列管理函数 + * @brief 预分配待读取数据的空间,并把读取到的数据存入buf数组 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [out] buf 存储读取的数据的目标buf数组 + * @param [in] len 要读取的数据的字节长度 + * + * @return + */ +/* ----------------------------------------------------------------------------*/ +u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len); + +/* --------------------------------------------------------------------------*/ +/** + * @brief 适用范围:memcpy管理+cbuf_read_alloc系列管理函数 + * @brief 更新cbuf管理handle的读指针位置和数据长度 + * + * @param [in] cbuffer cbuffer 句柄 + * @param [in] len 要更新的数据的字节长度 + */ +/* ----------------------------------------------------------------------------*/ +void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len); + +#endif + diff --git a/2.code/2.p11_code/include/generic/printf.h b/2.code/2.p11_code/include/generic/printf.h new file mode 100644 index 0000000..2ce06c5 --- /dev/null +++ b/2.code/2.p11_code/include/generic/printf.h @@ -0,0 +1,22 @@ +#ifndef _PRINTF_H_ +#define _PRINTF_H_ +#define line_inf printf("%s %s %d \r\n" ,__FILE__, __func__ , __LINE__) ; +#include +#include "typedef.h" +//#define NOFLOAT + +extern void putchar(char a); +extern void putbyte(char a); +extern int puts(const char *out); +void put_u32hex(unsigned int dat); +void put_buf(const u8 *buf, int len); +int printf(const char *format, ...); +//int assert_printf(const char *format, ...); +// int sprintf(char *out, const char *format, ...); +// int vprintf(const char *fmt, __builtin_va_list va); +// int vsnprintf(char *, unsigned long, const char *, __builtin_va_list); +// int snprintf(char *buf, unsigned long size, const char *fmt, ...); +// int print(char **out, char *end, const char *format, va_list args); +//int snprintf(char *, unsigned long, const char *, ...); + +#endif diff --git a/2.code/2.p11_code/include/generic/sensor_gp_timer.h b/2.code/2.p11_code/include/generic/sensor_gp_timer.h new file mode 100644 index 0000000..388efe7 --- /dev/null +++ b/2.code/2.p11_code/include/generic/sensor_gp_timer.h @@ -0,0 +1,13 @@ +#ifndef _SENSOR_GP_TIMER_H_ +#define _SENSOR_GP_TIMER_H_ + +int timer0_capture_init(u32 gSensor_int_io);//默认下降沿触发 +void port_edge_wkup_set_callback(void (*call_back)(void)); +void sensor_timer_cap_start();// +void sensor_timer_cap_close();//关闭定时器捕获 +int timer1_init();//给hx3603 定时40ms +void timer1_isr_set_callback(void (*call_back)(void)); +void timer1_start(); +void timer1_close();//关闭定时器 + +#endif /* #ifndef _SENSOR_GP_TIMER_H_ */ diff --git a/2.code/2.p11_code/tools/make_prompt.bat b/2.code/2.p11_code/tools/make_prompt.bat new file mode 100644 index 0000000..1b1953e --- /dev/null +++ b/2.code/2.p11_code/tools/make_prompt.bat @@ -0,0 +1,5 @@ +SET SCRIPT_PATH=%~dp0% +set PATH=%SCRIPT_PATH%\utils;%PATH% +cd .. +cmd + diff --git a/2.code/2.p11_code/tools/utils/[.exe b/2.code/2.p11_code/tools/utils/[.exe new file mode 100644 index 0000000..c71fba5 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/[.exe differ diff --git a/2.code/2.p11_code/tools/utils/do_merge_libs.bat b/2.code/2.p11_code/tools/utils/do_merge_libs.bat new file mode 100644 index 0000000..091500e --- /dev/null +++ b/2.code/2.p11_code/tools/utils/do_merge_libs.bat @@ -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% + diff --git a/2.code/2.p11_code/tools/utils/find.exe b/2.code/2.p11_code/tools/utils/find.exe new file mode 100644 index 0000000..85192fb Binary files /dev/null and b/2.code/2.p11_code/tools/utils/find.exe differ diff --git a/2.code/2.p11_code/tools/utils/fixbat.exe b/2.code/2.p11_code/tools/utils/fixbat.exe new file mode 100644 index 0000000..e6280d2 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/fixbat.exe differ diff --git a/2.code/2.p11_code/tools/utils/libiconv2.dll b/2.code/2.p11_code/tools/utils/libiconv2.dll new file mode 100644 index 0000000..747073f Binary files /dev/null and b/2.code/2.p11_code/tools/utils/libiconv2.dll differ diff --git a/2.code/2.p11_code/tools/utils/libintl3.dll b/2.code/2.p11_code/tools/utils/libintl3.dll new file mode 100644 index 0000000..ec11e6b Binary files /dev/null and b/2.code/2.p11_code/tools/utils/libintl3.dll differ diff --git a/2.code/2.p11_code/tools/utils/ls.exe b/2.code/2.p11_code/tools/utils/ls.exe new file mode 100644 index 0000000..96ff2e5 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/ls.exe differ diff --git a/2.code/2.p11_code/tools/utils/make.exe b/2.code/2.p11_code/tools/utils/make.exe new file mode 100644 index 0000000..17bfc2e Binary files /dev/null and b/2.code/2.p11_code/tools/utils/make.exe differ diff --git a/2.code/2.p11_code/tools/utils/merge-archives.exe b/2.code/2.p11_code/tools/utils/merge-archives.exe new file mode 100644 index 0000000..07e1a2b Binary files /dev/null and b/2.code/2.p11_code/tools/utils/merge-archives.exe differ diff --git a/2.code/2.p11_code/tools/utils/mkdir_win.exe b/2.code/2.p11_code/tools/utils/mkdir_win.exe new file mode 100644 index 0000000..f96d181 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/mkdir_win.exe differ diff --git a/2.code/2.p11_code/tools/utils/override-seg.exe b/2.code/2.p11_code/tools/utils/override-seg.exe new file mode 100644 index 0000000..3e759e2 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/override-seg.exe differ diff --git a/2.code/2.p11_code/tools/utils/rm.exe b/2.code/2.p11_code/tools/utils/rm.exe new file mode 100644 index 0000000..8e79306 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/rm.exe differ diff --git a/2.code/2.p11_code/tools/utils/true.exe b/2.code/2.p11_code/tools/utils/true.exe new file mode 100644 index 0000000..cb41f82 Binary files /dev/null and b/2.code/2.p11_code/tools/utils/true.exe differ diff --git a/2.code/2.p11_code/tools/utils/uname.exe b/2.code/2.p11_code/tools/utils/uname.exe new file mode 100644 index 0000000..3e2f4cf Binary files /dev/null and b/2.code/2.p11_code/tools/utils/uname.exe differ