From 2200a04f0597b9913115e9f1e519d3e2489635d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=90=AA?= Date: Tue, 28 Jul 2026 16:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=AD=E7=94=B5=E8=BD=AE?= =?UTF-8?q?=E6=8D=A2=E4=BF=9D=E5=AD=98=E5=8F=8A=E8=93=9D=E7=89=99=E5=B9=BF?= =?UTF-8?q?=E6=92=AD=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/ble/ble_peripheral/app/src/Rf433.c | 3 ++- .../ble/ble_peripheral/app/src/fmc_spi.c | 18 ++++++++++++++---- .../example/ble/ble_peripheral/app/src/uart.c | 5 +---- .../ble/ble_peripheral/mdk/Linker/cpu_xip.scat | 7 ++++--- .../ble_peripheral/mdk/ble_peripheral.uvprojx | 2 +- .../mdk/output_tool/xinchip_bootloader2.bat | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/project/example/ble/ble_peripheral/app/src/Rf433.c b/project/example/ble/ble_peripheral/app/src/Rf433.c index ed1e550..c86a4b5 100644 --- a/project/example/ble/ble_peripheral/app/src/Rf433.c +++ b/project/example/ble/ble_peripheral/app/src/Rf433.c @@ -7,6 +7,7 @@ #include "light_transition.h" #include "pwm.h" #include "rf433_decoder.h" +#include "timeslice.h" union rf433_flag rf_flag = {0}; unsigned char high_level_time; unsigned char low_level_time; @@ -415,7 +416,6 @@ void _433_fun(){ return; } - sss=1;//记忆标志位 switch(res_data){ //椭圆 case ON://单击 @@ -496,6 +496,7 @@ void _433_fun(){ } break; } + set_TaskComps_timer(2U, 1000U); } diff --git a/project/example/ble/ble_peripheral/app/src/fmc_spi.c b/project/example/ble/ble_peripheral/app/src/fmc_spi.c index 7a42090..f9bafe5 100644 --- a/project/example/ble/ble_peripheral/app/src/fmc_spi.c +++ b/project/example/ble/ble_peripheral/app/src/fmc_spi.c @@ -33,6 +33,7 @@ #include "PWM.h" #include "RF433.h" #include "xc60xx.h" +#include "timeslice.h" /*------------------------------------------------------------------------------------ Macros @@ -77,6 +78,8 @@ unsigned char get_checksum(unsigned char *ptrdata, unsigned char length) #define FLASH_POWER_MODE_INDEX 28U #define FLASH_POWER_CYCLE_INDEX 29U #define FLASH_POWER_MODE_MARK 0xA7U +#define USER_STATE_SAVE_DELAY_MS 1000U +#define POWER_CYCLE_BOOT_SAVE_DELAY_MS 100U uint8_t power_restore_policy = POWER_RESTORE_CYCLE_STATIC; static uint8_t power_cycle_next_color; @@ -240,10 +243,13 @@ void power_restore_policy_set(uint8_t policy) { if(policy > POWER_RESTORE_CYCLE_STATIC) return; - power_restore_policy = policy; - if(policy == POWER_RESTORE_CYCLE_STATIC) + /* Re-sending the active policy must not restart the color sequence. */ + if(policy == POWER_RESTORE_CYCLE_STATIC && + power_restore_policy != POWER_RESTORE_CYCLE_STATIC) power_cycle_next_color = 0U; - sss = 1U; + + power_restore_policy = policy; + set_TaskComps_timer(2U, USER_STATE_SAVE_DELAY_MS); } void power_restore_apply_on_boot(void) @@ -280,5 +286,9 @@ void power_restore_apply_on_boot(void) } power_cycle_next_color = (uint8_t)((color + 1U) % 3U); - sss = 1U; + + /* Persist the next color after startup while input power is stable. + * This sequence does not depend on a shutdown-time flash write. + */ + set_TaskComps_timer(2U, POWER_CYCLE_BOOT_SAVE_DELAY_MS); } diff --git a/project/example/ble/ble_peripheral/app/src/uart.c b/project/example/ble/ble_peripheral/app/src/uart.c index bd3fda0..a85d310 100644 --- a/project/example/ble/ble_peripheral/app/src/uart.c +++ b/project/example/ble/ble_peripheral/app/src/uart.c @@ -84,7 +84,6 @@ void uart_receive_cb(uint8_t *buff, uint16_t len) void scan_uar_data(uint8_t *frame){ } -extern uint8_t sss; uint8_t rx_date; void scan_uart(uint8_t *arr) { @@ -106,8 +105,6 @@ void scan_uart(uint8_t *arr) checksum += user_rx_buf[i]; } user_rx_buf[5] = checksum; // 校验位 - sss=1; - // printf("sss=%d\r\n",sss); switch (user_rx_buf[4]) { @@ -178,7 +175,7 @@ void scan_uart(uint8_t *arr) break; } - //set_TaskComps_timer(2,1000); + set_TaskComps_timer(2U, 1000U); } diff --git a/project/example/ble/ble_peripheral/mdk/Linker/cpu_xip.scat b/project/example/ble/ble_peripheral/mdk/Linker/cpu_xip.scat index 64a5363..b815bc8 100644 --- a/project/example/ble/ble_peripheral/mdk/Linker/cpu_xip.scat +++ b/project/example/ble/ble_peripheral/mdk/Linker/cpu_xip.scat @@ -1,6 +1,6 @@ -LOAD 0x1100E000 +LOAD 0x11011000 { - EXE 0x1100E000 + EXE 0x11011000 { startup_xinc.o (RESET, +FIRST) * (+RO) @@ -20,7 +20,8 @@ LOAD 0x1100E000 *(ram_em) } ScatterAssert((0x530077b0)+ImageLength(RW2) < 0x53008000) - ScatterAssert(ImageLength(EXE) <= 0x10000) + /* User settings start at flash offset 0x1E000. */ + ScatterAssert(ImageLength(EXE) <= 0xD000) } diff --git a/project/example/ble/ble_peripheral/mdk/ble_peripheral.uvprojx b/project/example/ble/ble_peripheral/mdk/ble_peripheral.uvprojx index 011f4f2..40e2371 100644 --- a/project/example/ble/ble_peripheral/mdk/ble_peripheral.uvprojx +++ b/project/example/ble/ble_peripheral/mdk/ble_peripheral.uvprojx @@ -338,7 +338,7 @@ 0 --gnu --diag_suppress=66 --feedback fb.txt - APP_SCAN_FUNCTION=0 CFG_MIN_STACK CONFIG_BT_WAKEUP_VIA_GPIO=0 CONFIG_HFCLK_IS_OSC32M_PLL_32M=1 SCATTER_LOAD_RAM_EM=1 SDK_VERSION="2b8e78c6" RC_32K=1 XC60XX CFG_BLE CFG_EMB CFG_STATIC HCI_TEST_NO_IP=0 CFG_ACT=20 CFG_CON=1 CFG_RAL=1 CFG_HOST CFG_APP CFG_APP_PRF CFG_RF_EXTRC CFG_AES_RPA CFG_PERIPHERAL USE_XIP=1 DEBUG_ENABLE ROM_ENV_ENABLE=0 CODE_USE_XIP CFG_PRF_BASS USE_ROM_FLASH=1 CFG_ADV_LOW_POWER CFG_CONN_OPTIMIZE_0x3E + WDT_ON=1 APP_SCAN_FUNCTION=0 CFG_MIN_STACK CONFIG_BT_WAKEUP_VIA_GPIO=0 CONFIG_HFCLK_IS_OSC32M_PLL_32M=1 SCATTER_LOAD_RAM_EM=1 SDK_VERSION="2b8e78c6" RC_32K=1 XC60XX CFG_BLE CFG_EMB CFG_STATIC HCI_TEST_NO_IP=0 CFG_ACT=20 CFG_CON=1 CFG_RAL=1 CFG_HOST CFG_APP CFG_APP_PRF CFG_RF_EXTRC CFG_AES_RPA CFG_PERIPHERAL USE_XIP=1 DEBUG_ENABLE ROM_ENV_ENABLE=0 CODE_USE_XIP CFG_PRF_BASS USE_ROM_FLASH=1 CFG_ADV_LOW_POWER CFG_CONN_OPTIMIZE_0x3E ..\..\..\..\..\component\ble\Include;..\app\api;..\..\..\..\..\component\ble\modules\aes\api;..\..\..\..\..\component\ble\modules\aes\src;..\..\..\..\..\component\ble\modules\common\api;..\..\..\..\..\component\ble\modules\common\src;..\..\..\..\..\component\ble\modules\ecc_p256\api;..\..\..\..\..\component\ble\modules\ecc_p256\src;..\..\..\..\..\component\ble\modules\h4tl\api;..\..\..\..\..\component\ble\modules\h4tl\src;..\..\..\..\..\component\ble\modules\ke\api;..\..\..\..\..\component\ble\modules\ke\src;..\..\..\..\..\component\ble\modules\nvds\api;..\..\..\..\..\component\ble\modules\nvds\src;..\..\..\..\..\component\ble\modules\rf\api;..\..\..\..\..\component\ble\modules\rf\src;..\..\..\..\..\component\ble\modules\rwip\api;..\..\..\..\..\component\ble\modules\rwip\src;..\..\..\..\..\component\ble\ip\ahi\api;..\..\..\..\..\component\ble\ip\ahi\src;..\..\..\..\..\component\ble\ip\ble\gaf\api;..\..\..\..\..\component\ble\ip\ble\gaf\inc;..\..\..\..\..\component\ble\ip\ble\gaf\src;..\..\..\..\..\component\ble\ip\ble\gaf\src\acc;..\..\..\..\..\component\ble\ip\ble\gaf\src\al;..\..\..\..\..\component\ble\ip\ble\gaf\src\arc;..\..\..\..\..\component\ble\ip\ble\gaf\src\bap\bc;..\..\..\..\..\component\ble\ip\ble\gaf\src\bap\capa;..\..\..\..\..\component\ble\ip\ble\gaf\src\bap\codec;..\..\..\..\..\component\ble\ip\ble\gaf\src\bap\uc;..\..\..\..\..\component\ble\ip\ble\gaf\src\iap;..\..\..\..\..\component\ble\ip\ble\hl\api;..\..\..\..\..\component\ble\ip\ble\hl\inc;..\..\..\..\..\component\ble\ip\ble\hl\src;..\..\..\..\..\component\ble\ip\ble\hl\src\gap;..\..\..\..\..\component\ble\ip\ble\hl\src\gap\gapc;..\..\..\..\..\component\ble\ip\ble\hl\src\gap\gapm;..\..\..\..\..\component\ble\ip\ble\hl\src\gatt;..\..\..\..\..\component\ble\ip\ble\hl\src\inc;..\..\..\..\..\component\ble\ip\ble\hl\src\l2cap;..\..\..\..\..\component\ble\ip\ble\ll\api;..\..\..\..\..\component\ble\ip\ble\ll\src;..\..\..\..\..\component\ble\ip\ble\ll\src\co;..\..\..\..\..\component\ble\ip\ble\ll\src\llc;..\..\..\..\..\component\ble\ip\ble\ll\src\lld;..\..\..\..\..\component\ble\ip\ble\ll\src\lli;..\..\..\..\..\component\ble\ip\ble\ll\src\llm;..\..\..\..\..\component\ble\ip\ble\profiles\bas\bass\api;..\..\..\..\..\component\ble\ip\ble\profiles\bas\bass\src;..\..\..\..\..\component\ble\ip\em\api;..\..\..\..\..\component\ble\ip\em\src;..\..\..\..\..\component\ble\ip\hci\api;..\..\..\..\..\component\ble\ip\hci\src;..\..\..\..\..\component\ble\ip\sch\api;..\..\..\..\..\component\ble\ip\sch\src;..\..\..\..\..\component\ble\plf\refip\src\build\ble-full\reg\fw;..\app\api;..\app\src;..\..\..\..\..\component\ble\plf\refip\src\arch;..\..\..\..\..\component\ble\plf\refip\src\arch\compiler\gnuarm;..\..\..\..\..\component\ble\plf\refip\src\arch\ll\gnuarm;..\..\..\..\..\component\ble\plf\refip\src\driver\reg;..\..\..\..\..\component\ble\plf\refip\src\arch\boot\rvds;..\..\..\..\..\component\ble\plf\refip\src\driver\syscntl;..\..\..\..\..\component\ble\plf\refip\src\driver\emi;..\..\..\..\..\component\ble\plf\refip\src\driver\intc;..\..\..\..\..\component\ble\plf\refip\src\driver\uart;..\..\..\..\..\component\ble\plf\refip\src\driver\flash;..\..\..\..\..\component\ble\plf\refip\src\driver\led;..\..\..\..\..\component\ble\modules\dbg\api;..\..\..\..\..\component\ble\plf\refip\src\driver\uart;..\..\..\..\..\component\xc6xx_drivers\Drivers\CMSIS;..\..\..\..\..\component\xc6xx_drivers\Drivers\CMSIS\Device;..\..\..\..\..\component\xc6xx_drivers\Drivers\Startup;..\..\..\..\..\component\xc6xx_drivers\Drivers\Startup\xc60xx;..\..\..\..\..\component\xc6xx_drivers\Drivers\Periph_HAL_Driver;..\..\..\..\..\component\xc6xx_drivers\Drivers\Periph_HAL_Driver\Bitfields;..\..\..\..\..\component\xc6xx_drivers\Drivers\Periph_HAL_Driver\Ringbuffer;..\..\..\..\..\component\xc6xx_drivers\Drivers\test_case\PWR;..\..\..\..\..\component\xc6xx_drivers\Drivers\test_case\TIMER;..\..\..\..\..\component\ble\ip\ble\api;..\..\..\..\..\component\ble\ip\ble\ll_rom_port;..\..\..\..\..\component\xc6xx_drivers\Drivers\xc_driver;..\..\..\..\..\component\xc6xx_drivers\Drivers\CMSIS\Device\xc_m0_register;..\..\..\..\..\component\ble\modules\flash;..\..\..\..\..\component\xc6xx_drivers\Drivers\xc_driver;..\..\..\driver\adc_mic_pga\app\api;..\app\src\project_config;..\app\src\elk_leds diff --git a/project/example/ble/ble_peripheral/mdk/output_tool/xinchip_bootloader2.bat b/project/example/ble/ble_peripheral/mdk/output_tool/xinchip_bootloader2.bat index 4d93ede..a127f01 100644 --- a/project/example/ble/ble_peripheral/mdk/output_tool/xinchip_bootloader2.bat +++ b/project/example/ble/ble_peripheral/mdk/output_tool/xinchip_bootloader2.bat @@ -1,6 +1,6 @@ .\output_tool\xinchip_bootloader2_tool.exe .\output_tool\boot2 ^ .\output_tool\host 0x11002000 0 ^ -app.bin 0x1100E000 1 ^ +app.bin 0x11011000 1 ^ .\output_bin\ble_peripheral.bin 1 copy .\output_bin\ble_peripheral.bin .\