diff --git a/PD_CPS8841H_33W/code/app/inc/config.h b/PD_CPS8841H_33W/code/app/inc/config.h index a6445b9..fe6f698 100644 --- a/PD_CPS8841H_33W/code/app/inc/config.h +++ b/PD_CPS8841H_33W/code/app/inc/config.h @@ -44,6 +44,8 @@ #define FB_FUNC_ENABLE 0 #if !UART_DEUG +#define NTC_ENABLE 1 +#else #define NTC_ENABLE 0 #endif diff --git a/PD_CPS8841H_33W/code/app/src/app_porta.c b/PD_CPS8841H_33W/code/app/src/app_porta.c index c69859a..37f04d9 100644 --- a/PD_CPS8841H_33W/code/app/src/app_porta.c +++ b/PD_CPS8841H_33W/code/app/src/app_porta.c @@ -157,6 +157,11 @@ void usba_ocp_detect(void) void app_port_a1_work(void) { + if(g_protection_param.protection_flag) + { + return; + } + app_porta_detect_work(); usba_ocp_detect(); } diff --git a/PD_CPS8841H_33W/code/app/src/app_spec.c b/PD_CPS8841H_33W/code/app/src/app_spec.c index d08bcee..586ed75 100644 --- a/PD_CPS8841H_33W/code/app/src/app_spec.c +++ b/PD_CPS8841H_33W/code/app/src/app_spec.c @@ -45,9 +45,9 @@ const fw_footprint_s S_FW_FP __attribute__((section(".ARM.__at_0x100000C2"))) = 0xFF, 0x08, {0}, // FW len - {(0x00 & 0xff), (0x00 >> 8)}, - 0, - .cc_fw_update_key = CC_FW_UPDATE_DS_KEY, + {(0x00 & 0xff), (0x00 >> 8)}, // fw_magic + 0, // mtp_trim_flag + .cc_fw_update_key = CC_FW_UPDATE_DS_KEY, // cc_fw_update_key }; @@ -124,7 +124,7 @@ uint8_t system_init(void) #if VD_PEAK_DETECT comp_vd_power_on_detect_ac_volt(DELAY_650MS); #else - drv_delay_ms(DELAY_650MS); + // drv_delay_ms(DELAY_650MS); #endif diff --git a/PD_CPS8841H_33W/code/app/src/comm_event.c b/PD_CPS8841H_33W/code/app/src/comm_event.c index 05de7f3..e16cba3 100644 --- a/PD_CPS8841H_33W/code/app/src/comm_event.c +++ b/PD_CPS8841H_33W/code/app/src/comm_event.c @@ -129,6 +129,7 @@ void port_status_run(void) // 什么都没接时, 也是用buck给A口供电来检查A口是否插入 buck_control(true); + drv_delay_ms(5); dpdm_power_a1_gate_enable(false); } else @@ -144,6 +145,7 @@ void port_status_run(void) port_process_status = port_exit_status; // 单C口时, 常开buck, 关闭gateA, 等A口有拉电流才反过来 buck_control(true); + drv_delay_ms(5); dpdm_power_a1_gate_enable(false); } else @@ -180,6 +182,7 @@ void port_status_run(void) // 单A口 dpdm_power_a1_gate_enable(true); + drv_delay_ms(5); buck_control(false); } else @@ -200,13 +203,14 @@ void port_status_run(void) // 加大电流--->开gateA--->关buck comp_set_current(&g_powerout_info, CURRENT_5P5A); // 需要立刻设置 // 是否有可能电流环设置的没那么快, 一打开gateA就被拉挂了? 需要加个延迟等电流环设置完再开A? - // drv_delay_us(500); dpdm_power_a1_gate_enable(true); + drv_delay_ms(5); buck_control(false); } else { buck_control(true); + drv_delay_ms(5); dpdm_power_a1_gate_enable(false); } } @@ -218,6 +222,7 @@ void port_status_run(void) { // todo: 看看是否需要延迟个1ms等待buck完全开启再关gateA buck_control(true); + drv_delay_ms(5); dpdm_power_a1_gate_enable(false); } else if(g_powerout_info.set_vol < VOLTAGE_5P5V @@ -226,6 +231,7 @@ void port_status_run(void) { comp_set_current(&g_powerout_info, CURRENT_5P5A); // 需要立刻设置 dpdm_power_a1_gate_enable(true); + drv_delay_ms(5); buck_control(false); } } diff --git a/PD_CPS8841H_33W/code/app/src/dpdm_run.c b/PD_CPS8841H_33W/code/app/src/dpdm_run.c index 9de9b0f..512ed67 100644 --- a/PD_CPS8841H_33W/code/app/src/dpdm_run.c +++ b/PD_CPS8841H_33W/code/app/src/dpdm_run.c @@ -16,7 +16,7 @@ #include "ufcs_protocol.h" #include "ufcs.h" #include "comp_gpio.h" - +#include "comp_protection.h" static uint16_t dp_power_down_discern(scp_port_s *scp_port); @@ -127,10 +127,9 @@ void buck_init(void) { // RT4当dcdc使能引脚 buck是低电平使能 REG_CLKCTRL_PIN_MUL_SET->bf.gp2 = 3; - drv_gpio_pull_up_resistor_en(GP2, 1); drv_gpio_enable_out(GPIO_PIN2); - REG_ANALOG_GP->bf.aie |= (1 << GPIO_PIN2); - drv_gpio_write(GPIO_PIN2, true); // 初始先关闭 + REG_ANALOG_GP->bf.oden |= (1 << GPIO_PIN2); + drv_gpio_write(GPIO_PIN2, false); // 初始先打开. 低电平是打开 } @@ -168,6 +167,11 @@ void dpdm_time_run(void) void dpdm_run(void) { + if(g_protection_param.protection_flag) + { + return; + } + dpdm_t *p = (dpdm_t *)&g_dpdm; state_machine_run(&p->sm); } @@ -184,15 +188,11 @@ static void Dpdm_Src_Idle_Entry(void *data) const static sm_state_t *Dpdm_Src_Idle_Run(const sm_state_t *self, void *data) { - dpdm_t *p = (dpdm_t *)data; - p->dpdm_port = typec_is_attched() ? 0 : 1; - log_info("dpdm_port:%d\n", p->dpdm_port); - dpdm_power_set_port(p->dpdm_port); - hvdcp_prl_init(&p->bc_port, p->dpdm_port); #if NTC_ENABLE - // 若是触发了NTC, 则不走DPDN协议 + // 若是触发了NTC, 则不走DPDN协议, 一直停在IDLE状态机里, 等温度降下去复位 + // 或者等温度上去触发芯片复位 if(user_app.ntc_triggered_dera) { return &g_dpdm_state[DPDM_SRC_STATE_IDLE]; @@ -200,6 +200,11 @@ const static sm_state_t *Dpdm_Src_Idle_Run(const sm_state_t *self, void *data) else #endif { + dpdm_t *p = (dpdm_t *)data; + p->dpdm_port = typec_is_attched() ? 0 : 1; + log_info("dpdm_port:%d\n", p->dpdm_port); + dpdm_power_set_port(p->dpdm_port); + hvdcp_prl_init(&p->bc_port, p->dpdm_port); return &g_dpdm_state[DPDM_SRC_STATE_APPLE]; } diff --git a/PD_CPS8841H_33W/code/app/src/main.c b/PD_CPS8841H_33W/code/app/src/main.c index 78be839..14488b1 100644 --- a/PD_CPS8841H_33W/code/app/src/main.c +++ b/PD_CPS8841H_33W/code/app/src/main.c @@ -28,11 +28,17 @@ #include "comp_powerout.h" #include "customized.h" #include "comm_event.h" +#include "comp_protection.h" user_app_s user_app = {0}; void protocol_pd_work(void) { + if(g_protection_param.protection_flag) + { + return; + } + pd_mgr_pd_typec_prl_stack_run(0); pd_mgr_prl_stack_run(0); } @@ -84,6 +90,11 @@ void usba_high_current(void) void comm_event(void) { + if(g_protection_param.protection_flag) + { + return; + } + // uint16_t set_current = CURRENT_4A; usba_high_current(); diff --git a/PD_CPS8841H_33W/code/component/src/comp_powerout.c b/PD_CPS8841H_33W/code/component/src/comp_powerout.c index f122d2f..9b9d205 100644 --- a/PD_CPS8841H_33W/code/component/src/comp_powerout.c +++ b/PD_CPS8841H_33W/code/component/src/comp_powerout.c @@ -237,12 +237,12 @@ void comp_powerout_transmit_machine(comp_powerout_info_s *powerout_info) // A+C时, 如果C口电压需要升压,那就先打开BUCK, 然后关闭GATEA。 // 开启BUCK需要时间, 等BUCK开启完毕后再关gate, 不过A口断一会也没要求。 // 不要在中断里进行操作IO口, 8850的寄存器不是原子操作----> 或者把powerout状态机放中断外跑 - if(typec_is_attched()) + if(typec_is_attched() && REG_ANALOG_GATEA->bf.en) { if(powerout_info->set_vol > VOLTAGE_5V) { buck_control(true); - drv_delay_ms(1); + drv_delay_ms(5); dpdm_power_a1_gate_enable(false); } } @@ -366,7 +366,7 @@ void comp_powerout_ready_machine(comp_powerout_info_s *powerout_info) || dpdm_power_get_next_protocol() == PROTOCOL_DCP || dpdm_power_get_next_protocol() == PROTOCOL_QC_PRE) { - pwr_request.request_cur = CURRENT_3P3A; + pwr_request.request_cur = CURRENT_3P4A; } } @@ -380,7 +380,7 @@ void comp_powerout_ready_machine(comp_powerout_info_s *powerout_info) || dpdm_power_get_next_protocol() == PROTOCOL_DCP || dpdm_power_get_next_protocol() == PROTOCOL_QC_PRE) { - pwr_request.request_cur = CURRENT_3P3A; + pwr_request.request_cur = CURRENT_3P4A; } } } diff --git a/PD_CPS8841H_33W/code/component/src/comp_protection.c b/PD_CPS8841H_33W/code/component/src/comp_protection.c index 4422c46..4347416 100644 --- a/PD_CPS8841H_33W/code/component/src/comp_protection.c +++ b/PD_CPS8841H_33W/code/component/src/comp_protection.c @@ -377,20 +377,21 @@ static void comp_protection_type_check(protection_param_s *protection_param) break; case SYS_ERR_OTP: -// if(HAL_ADC_GET_RT_ADC_VALUE() > NTC_OTP_RECOVER_VPT) -// { -// protect_info->hiccup_time++; -// -// if(protect_info->hiccup_time == DELAY_1S) -// { -// goto pro_hard_reset; -// } - -// } -// else -// { -// protect_info->hiccup_time = 0; -// } + if(COMP_ADC_GET_RT_VOL() > NTC_OTP_RECOVER_VPT) + { + protection_param->hiccup_time++; + + if(protection_param->hiccup_time == DELAY_1S) + { + goto pro_hard_reset; + } + + } + else + { + protection_param->hiccup_time = 0; + } + break; // case SYS_ERR_OVP: @@ -437,6 +438,8 @@ pro_hard_reset: */ static void comp_protection_entry_action(protection_param_s *protection_param) { + + comp_powerout_close_nmos(); log_info("pro:%d\n", protection_param->curr_expcode); #if PD_SUPPORT pd_mgr_prl_deinit(ADP_PORT0); @@ -463,6 +466,8 @@ static void comp_protection_entry_action(protection_param_s *protection_param) */ static void comp_protection_exit(protection_param_s *protection_param) { + // RESET_ADP_CURR_PORT(); + #if TYPEC_SUPPORT typec_reset(pd_get_pd_port(ADP_PORT0)); #endif diff --git a/PD_CPS8841H_33W/code/platform/protocol/qc_protocol/src/qc_protocol.c b/PD_CPS8841H_33W/code/platform/protocol/qc_protocol/src/qc_protocol.c index 4d36f10..7138ef0 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/qc_protocol/src/qc_protocol.c +++ b/PD_CPS8841H_33W/code/platform/protocol/qc_protocol/src/qc_protocol.c @@ -33,6 +33,13 @@ void qc_voltage_request_work(qc_port_s *qc_port) qc_param_s *qc_param; qc_param = &qc_port->qc_prl_param; + // 进了PD协议则不响应QC协议,优先QC协议 + if(dpdm_power_get_next_protocol() == PROTOCOL_PD_FIX + || dpdm_power_get_next_protocol() == PROTOCOL_PD_PPS) + { + return; + } + if(dpdm_power_get_next_protocol() == PROTOCOL_QC && (qc_param->qc_assist.request_vol == VOLTAGE_5V) && (qc_param->qc_assist.request_vol != vset)) { @@ -58,7 +65,7 @@ void qc_voltage_request_work(qc_port_s *qc_port) if(qc_param->qc_assist.request_vol == 5000) { - iset = CURRENT_3P3A; + iset = CURRENT_3P4A; // A + C 且都在5V时, 在powerout里会把电流设为5.5A // 仅测试,单A口时,实际设置3.3A能出4A @@ -69,22 +76,35 @@ void qc_voltage_request_work(qc_port_s *qc_port) } else if(qc_param->qc_assist.request_vol == 9000) { - iset = CURRENT_2P3A; + iset = CURRENT_2P4A; } else if(qc_param->qc_assist.request_vol >= 12000) { qc_param->qc_assist.request_vol = 12000; - iset = CURRENT_1P8A; + iset = CURRENT_1P9A; } else if(qc_param->qc_assist.request_vol <= 5000) { qc_param->qc_assist.request_vol = 5000; - iset = CURRENT_3P3A; + iset = CURRENT_3P4A; } if(qc_param->qc_assist.contionous_mode_state) { - // iset = CURRENT_3P4A; + if(qc_param->qc_assist.request_vol < 9000) + { + iset = CURRENT_3P4A; + } + else if(qc_param->qc_assist.request_vol < 12000) + { + iset = CURRENT_2P4A; + } + else if(qc_param->qc_assist.request_vol >= 12000) + { + qc_param->qc_assist.request_vol = 12000; + iset = CURRENT_1P9A; + } + set_cable_comp_enable(false); } diff --git a/PD_CPS8841H_33W/code/platform/protocol/scp_protocol/src/scp_protocol.c b/PD_CPS8841H_33W/code/platform/protocol/scp_protocol/src/scp_protocol.c index ae0257b..99acaaf 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/scp_protocol/src/scp_protocol.c +++ b/PD_CPS8841H_33W/code/platform/protocol/scp_protocol/src/scp_protocol.c @@ -141,14 +141,6 @@ static void scp_voltage_request_work(scp_port_s *scp_port) #if SCP_SUPPORT - -static bool is_rdp_en(void) -{ - return REG_ANALOG_DPDN->bf.en_rdp; -} - - - /* * @brief scp_first_handshake_dp_protection * @param dpdn_port @@ -158,17 +150,16 @@ static bool is_rdp_en(void) */ static void scp_first_handshake_dp_protection(scp_param_s *scp_param) { - if(!is_rdp_en() && scp_param->scp_prl_passist.scp_ping_get_cnt) + if(scp_param->scp_prl_passist.scp_ping_get_cnt > 3) { - scp_dp_det_disable(scp_param); - SET_DP_PULL_DOWN(true); return; } switch(scp_param->scp_prl_passist.scp_ping_get_cnt) { case 1: - + scp_dp_det_disable(scp_param); + SET_DP_PULL_DOWN(true); scp_param->scp_prl_passist.scp_ping_get_cnt++; log_info("cnt:%d\n", scp_param->scp_prl_passist.scp_ping_get_cnt); break; @@ -191,8 +182,8 @@ static void scp_first_handshake_dp_protection(scp_param_s *scp_param) void scp_prl_report_info_update(scp_param_s *scp_param) { - scp_param->scp_app_passist.scp_adc_cur = COMP_ADC_GET_VIN(); - scp_param->scp_app_passist.scp_adc_vol = COMP_ADC_GET_LS_CUR(); + scp_param->scp_app_passist.scp_adc_cur = COMP_ADC_GET_LS_CUR(); + scp_param->scp_app_passist.scp_adc_vol = COMP_ADC_GET_VIN(); scp_param->scp_app_passist.temperature = 25; scp_param->scp_app_passist.derating_ratio = 0; } diff --git a/PD_CPS8841H_33W/code/platform/rom_inc/comp/comp_config.h b/PD_CPS8841H_33W/code/platform/rom_inc/comp/comp_config.h index 44631bc..3ef4af7 100644 --- a/PD_CPS8841H_33W/code/platform/rom_inc/comp/comp_config.h +++ b/PD_CPS8841H_33W/code/platform/rom_inc/comp/comp_config.h @@ -134,6 +134,7 @@ #define CURRENT_1P7A 1700 #define CURRENT_1P8A 1800 #define CURRENT_1P75A 1750 +#define CURRENT_1P9A 1900 #define CURRENT_2A 2000 #define CURRENT_2P2A 2200 diff --git a/PD_CPS8841H_33W/code/prl_portable/src/pd.c b/PD_CPS8841H_33W/code/prl_portable/src/pd.c index 3b4961f..f3d72c2 100644 --- a/PD_CPS8841H_33W/code/prl_portable/src/pd.c +++ b/PD_CPS8841H_33W/code/prl_portable/src/pd.c @@ -118,6 +118,11 @@ bool app_src_power_handler_patch(pd_param_s *pd_param) { offest = CURRENT_0P3A; + if(request_vol <= VOLTAGE_9V) + { + offest = CURRENT_0P4A; + } + set_cable_comp_enable(true); dpdm_power_set_next_protocol(PROTOCOL_PD_FIX); }