From: caisking Date: Thu, 23 Apr 2026 07:50:15 +0000 (+0800) Subject: 优化开机限制 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f1f6c57c1e1973a944467090d9e02744273165ea;p=mirrors%2FFD230.git 优化开机限制 --- diff --git a/code/sdk/application/brandy/brandy_standard/board_init.c b/code/sdk/application/brandy/brandy_standard/board_init.c index ad961efe8..adb55a93c 100644 --- a/code/sdk/application/brandy/brandy_standard/board_init.c +++ b/code/sdk/application/brandy/brandy_standard/board_init.c @@ -118,7 +118,20 @@ static void gpio_func_init(void) static button_press_state_t g_pwrkey_press_state = RELEASED; static startup_reason_t startup_reason = STARTUP_OTHER; -#define PRESS_COUNT_LIMIT 5 +#define PWRKEY_CHECK_INTERVAL_MS 200 +#define PWRKEY_HOLD_TIME_MS 2000 +#define PRESS_COUNT_LIMIT (PWRKEY_HOLD_TIME_MS / PWRKEY_CHECK_INTERVAL_MS) +static uint64_t g_boot_stage_last_ms = 0; + +static void boot_log_stage(const char *stage_name) +{ + uint64_t now_ms = uapi_ulp_systick_get_ms(); + uint64_t delta_ms = now_ms - g_boot_stage_last_ms; + PRINT("【开机流程】%s,当前时间=%llu ms,阶段耗时=%llu ms"NEWLINE, + stage_name, (unsigned long long)now_ms, (unsigned long long)delta_ms); + g_boot_stage_last_ms = now_ms; +} + static button_press_state_t porting_button_get_state(void) { if ((readl(ANA_STS) & 0x3) == 0) @@ -141,6 +154,7 @@ static button_press_state_t porting_function_button_get_state(void) static void _poweroff(void) { + PRINT("【开机流程】执行关机流程:清中断、配置低功耗寄存器"NEWLINE); /* clr ulp int and event */ writel(0x5702C1E4, 0x3F); writel(0x5702C1EC, 0x3F); @@ -176,39 +190,55 @@ static void _poweroff(void) void check_pwrkey_3s(void) { - //3�밴������ - bool button_pressed = false; + // 开机按键长按校验 + button_press_state_t button_pressed = RELEASED; int pressed_count = 0; uapi_ulp_wkup_type_record(); startup_reason = uapi_get_startup_reason(); + button_pressed = porting_button_get_state(); int cpu_reset_case = get_cpu_utils_reset_cause(); - PRINT("bootup reasion %d (0-systick 1-pwrkey 2-vbus 3-other) cpu_resetcase 0x%04X"NEWLINE,startup_reason,cpu_reset_case); + PRINT("【开机按键】开始校验:目标长按=%d ms,采样间隔=%d ms,采样次数=%d"NEWLINE, + PWRKEY_HOLD_TIME_MS, PWRKEY_CHECK_INTERVAL_MS, PRESS_COUNT_LIMIT); + PRINT("bootup reasion %d (0-systick 1-pwrkey 2-vbus 3-other) cpu_resetcase 0x%04X realtime_pwrkey=%d hold_ms=%d limit=%d"NEWLINE, + startup_reason, cpu_reset_case, button_pressed, PWRKEY_HOLD_TIME_MS, PRESS_COUNT_LIMIT); if (cpu_reset_case == REBOOT_CAUSE_APPLICATION_SYSRESETREQ ) { + PRINT("【开机按键】检测到软件复位,不执行长按校验,直接继续启动"NEWLINE); PRINT("CPU reset Case is REBOOT , no need check PowerKey"NEWLINE); return ; } - if(startup_reason == 1) g_pwrkey_press_state = PRESSED; - else g_pwrkey_press_state = RELEASED; - if (g_pwrkey_press_state == PRESSED) + if (startup_reason == STARTUP_VBUS_EN) { - while(g_pwrkey_press_state == PRESSED){//���������ż��3�� - g_pwrkey_press_state = porting_button_get_state(); - PRINT("bootup timeout %d g_pwrkey_press_state %d"NEWLINE,pressed_count,g_pwrkey_press_state); - pressed_count ++ ; - if (pressed_count>=PRESS_COUNT_LIMIT) - { - break; - } - uapi_tcxo_delay_ms(200); + PRINT("【开机按键】检测到充电/VBUS启动,跳过长按校验,直接继续启动"NEWLINE); + return; + } + + g_pwrkey_press_state = button_pressed; + PRINT("bootup startup gated pwrkey_state=%d"NEWLINE, g_pwrkey_press_state); + + while (pressed_count < PRESS_COUNT_LIMIT) + { + g_pwrkey_press_state = porting_button_get_state(); + PRINT("bootup hold check %d/%d g_pwrkey_press_state %d"NEWLINE, + pressed_count + 1, PRESS_COUNT_LIMIT, g_pwrkey_press_state); + if (g_pwrkey_press_state != PRESSED) + { + PRINT("【开机按键】长按不足,触发关机。已连续按住=%d ms"NEWLINE, + pressed_count * PWRKEY_CHECK_INTERVAL_MS); + PRINT("not pressed %d ms continuously, poweroff!"NEWLINE, + pressed_count * PWRKEY_CHECK_INTERVAL_MS); + _poweroff(); + return; } - if(pressed_count < PRESS_COUNT_LIMIT ) + pressed_count++; + if (pressed_count < PRESS_COUNT_LIMIT) { - PRINT("not pressed 3 seconds , poweroff!"NEWLINE); - _poweroff(); + uapi_tcxo_delay_ms(PWRKEY_CHECK_INTERVAL_MS); } - PRINT("bootup continue pressed %d pressed count %d"NEWLINE,g_pwrkey_press_state==PRESSED?1:0,pressed_count); } + + PRINT("【开机按键】长按校验通过,允许继续启动"NEWLINE); + PRINT("bootup continue after hold check pressed_count %d"NEWLINE, pressed_count); } // static void check_power_on_voltage(void) @@ -275,7 +305,11 @@ void check_pwrkey_3s(void) bool need_enter_safemode(void) { - if (PRESSED == porting_button_get_state() && PRESSED == porting_function_button_get_state()) + button_press_state_t pwrkey_state = porting_button_get_state(); + button_press_state_t function_key_state = porting_function_button_get_state(); + PRINT("【开机流程】安全模式检测:电源键=%d 功能键=%d (0=按下 1=松开)"NEWLINE, + pwrkey_state, function_key_state); + if (PRESSED == pwrkey_state && PRESSED == function_key_state) { return true; }else{ @@ -284,41 +318,64 @@ bool need_enter_safemode(void) } void board_init(uint32_t flash_id, uint32_t flash_unique_id) { + g_boot_stage_last_ms = uapi_ulp_systick_get_ms(); + PRINT("【开机流程】board_init开始,flash_id=0x%x, flash_uid=0x%x, t0=%llu ms"NEWLINE, + flash_id, flash_unique_id, (unsigned long long)g_boot_stage_last_ms); + /* flash init */ + PRINT("【开机流程】开始初始化Flash"NEWLINE); flash_funcreg_adapt(0); flash_save_manufacturer(0, flash_id); uapi_flash_init(0); uapi_flash_config_cmd_at_xip_mode(0, (uint8_t)flash_unique_id); uapi_flash_switch_to_cache_mode(0); PRINT("Flash id is %x, init success"NEWLINE, flash_id); + boot_log_stage("Flash初始化完成"); + PRINT("【开机流程】开始初始化PIO配置"NEWLINE); pio_func_init(); + boot_log_stage("PIO初始化完成"); + + PRINT("【开机流程】开始初始化GPIO配置"NEWLINE); gpio_func_init(); + boot_log_stage("GPIO初始化完成"); + + PRINT("【开机流程】开始执行电源键长按开机校验"NEWLINE); check_pwrkey_3s(); + boot_log_stage("电源键长按校验完成"); // check_power_on_voltage(); - if (need_enter_safemode() == true) - { - PRINT("entering SafeMode\r\n"); - // #ifdef CUSTOM_UTILS - // uapi_dev_runtime_set_safemode_flag(1); - // #endif - }else{ - PRINT("entering NormalMode\r\n"); - } + // if (need_enter_safemode() == true) + // { + // PRINT("【开机流程】判定结果:进入安全模式"NEWLINE); + // PRINT("entering SafeMode\r\n"); + // // #ifdef CUSTOM_UTILS + // // uapi_dev_runtime_set_safemode_flag(1); + // // #endif + // }else{ + // PRINT("【开机流程】判定结果:进入正常模式"NEWLINE); + // PRINT("entering NormalMode\r\n"); + // } + // boot_log_stage("模式判定完成"); #ifdef QSPI_DISPLAY lcd_bus_register_api(&g_display_api_qspi, BUS_DISPLAY_QSPI); g_display_init_select = DISPLAY_CLASS_QSPI; + PRINT("【开机流程】显示总线选择:QSPI"NEWLINE); #else lcd_bus_register_api(&g_display_api_mipi, BUS_DISPLAY_MIPI); g_display_init_select = DISPLAY_CLASS_MIPI; + PRINT("【开机流程】显示总线选择:MIPI"NEWLINE); #endif + boot_log_stage("显示总线注册完成"); #ifdef BRANDY_PRODUCT_EVB g_board_init_select = BOARD_CLASS_E0B2; + PRINT("【开机流程】板级型号选择:BOARD_CLASS_E0B2"NEWLINE); #else g_board_init_select = BOARD_CLASS_E0B4; + PRINT("【开机流程】板级型号选择:BOARD_CLASS_E0B4"NEWLINE); #endif + boot_log_stage("board_init结束"); } \ No newline at end of file