From b71066d711678f8754f08a5358064c28132c3736 Mon Sep 17 00:00:00 2001 From: "Jipeng.tang" Date: Mon, 9 Jun 2025 11:23:45 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9Eufcs=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82=202.=20=E4=BF=AE=E6=94=B9QC=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E7=9A=84OCP=E7=82=B9=E3=80=82=203.=20=E5=85=88=E5=85=B3?= =?UTF-8?q?=E9=97=ADQC3.0=EF=BC=8C=E6=9C=89=E9=9C=80=E8=A6=81=E5=86=8D?= =?UTF-8?q?=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 18 +- PD_CPS8841H_33W/code/app/inc/config.h | 6 +- PD_CPS8841H_33W/code/app/inc/dpdm_run.h | 19 ++ PD_CPS8841H_33W/code/app/src/app_porta.c | 8 +- PD_CPS8841H_33W/code/app/src/comm_event.c | 14 +- PD_CPS8841H_33W/code/app/src/customized.c | 32 +-- PD_CPS8841H_33W/code/app/src/dpdm_run.c | 194 +++++++++++++--- PD_CPS8841H_33W/code/app/src/porta_detect.c | 15 +- .../code/component/inc/comp_dpdn_manager.h | 4 +- .../component/inc/comp_protocol_manager.h | 4 +- .../component/src/comp_otp_derate_policy.c | 28 +-- .../code/component/src/comp_pd_manager.c | 2 +- .../code/component/src/comp_protection.c | 6 +- .../pd_protocol/inc/pd_send_new_src_cap.h | 7 +- .../protocol/pd_protocol/src/pd_protocol.c | 8 +- .../pd_protocol/src/pd_send_new_src_cap.c | 17 +- .../protocol/qc_protocol/src/qc_protocol.c | 26 ++- .../ufcs_protocol/inc/ufcs_protocol.h | 11 +- .../ufcs_protocol/src/ufcs_protocol.c | 35 +-- .../code/platform/rom_inc/comp/comp_config.h | 2 +- PD_CPS8841H_33W/code/prl_portable/inc/pd.h | 2 +- PD_CPS8841H_33W/code/prl_portable/inc/ufcs.h | 15 +- PD_CPS8841H_33W/code/prl_portable/src/pd.c | 2 +- PD_CPS8841H_33W/code/prl_portable/src/ufcs.c | 211 ++++++++++++++---- PD_CPS8841H_33W/project/cps8841H.uvprojx | 10 + 25 files changed, 521 insertions(+), 175 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0c142f0..37ffe7b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,22 @@ "drv_analog.h": "c", "iterator": "c", "comp_protocol_manager.h": "c", - "comp_sample_volt_cur_report.h": "c" + "comp_sample_volt_cur_report.h": "c", + "bit": "c", + "compare": "c", + "condition_variable": "c", + "cstddef": "c", + "string": "c", + "optional": "c", + "limits": "c", + "memory": "c", + "mutex": "c", + "new": "c", + "functional": "c", + "__locale": "c", + "atomic": "c", + "ios": "c", + "locale": "c", + "type_traits": "c" } } \ No newline at end of file diff --git a/PD_CPS8841H_33W/code/app/inc/config.h b/PD_CPS8841H_33W/code/app/inc/config.h index a10f826..fca60a0 100644 --- a/PD_CPS8841H_33W/code/app/inc/config.h +++ b/PD_CPS8841H_33W/code/app/inc/config.h @@ -114,16 +114,16 @@ extern user_app_s user_app; #define QC_SUPPORT 1 #if QC_SUPPORT -#define QC3P0_SUPPORT 1 +#define QC3P0_SUPPORT 0 #endif/**QC_SUPPORT**/ #endif/**QC_SCP_SUPPORT**/ -#define UFCS_SUPPORT 0 +#define UFCS_SUPPORT 1 #if UFCS_SUPPORT -#define UFCS_DERATE_SUPPORT 0 +#define UFCS_DERATE_SUPPORT 1 #endif/**UFCS_SUPPORT**/ #define APPLE_MODE_SUPPORT 0 diff --git a/PD_CPS8841H_33W/code/app/inc/dpdm_run.h b/PD_CPS8841H_33W/code/app/inc/dpdm_run.h index 5ac35a0..c8e306d 100644 --- a/PD_CPS8841H_33W/code/app/inc/dpdm_run.h +++ b/PD_CPS8841H_33W/code/app/inc/dpdm_run.h @@ -1,6 +1,20 @@ #ifndef __DPDM_H_ #define __DPDM_H_ #include "scp_protocol.h" +#include "ufcs_protocol.h" + +typedef enum +{ + DPDM_SRC_STATE_IDLE = 0, + DPDM_SRC_STATE_APPLE, + DPDM_SRC_STATE_BC, + DPDM_SRC_STATE_QC_PRE, + DPDM_SRC_STATE_QC, + DPDM_SRC_STATE_SCP, + DPDM_SRC_STATE_UFCS, + DPDM_SRC_STATE_RST, + DPDM_SRC_STATE_NUM +} dpdm_src_state_e; void dpdm_init(void); void dpdm_time_run(void); @@ -8,4 +22,9 @@ void dpdm_run(void); scp_port_s *dpdm_get_scp_port(void); void dpdm_reset(void); +#if UFCS_SUPPORT +ufcs_port_s *dpdm_get_ufcs_port(void); +void ufcs_dpdn_ovp(void); +void dpdn_mgr_enable_dpdn_prl(uint8_t en); +#endif #endif // end of __DPDM_H_ diff --git a/PD_CPS8841H_33W/code/app/src/app_porta.c b/PD_CPS8841H_33W/code/app/src/app_porta.c index 936c07a..a0ef92e 100644 --- a/PD_CPS8841H_33W/code/app/src/app_porta.c +++ b/PD_CPS8841H_33W/code/app/src/app_porta.c @@ -87,8 +87,8 @@ static void app_porta_detect_work(void) if(attached) { // 需要判断当前C口走的是什么协议, 再去更新对应的能力. 更新typeC的src_cap - pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[1]); - pd_restart_send_src_cap(&g_pd_port, 1); + // pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[SRC_CAP_20W], SRC_CAP_20W); + // pd_restart_send_src_cap(&g_pd_port); usba_plugin_detect_deinit(); usba_plugout_detect_init(); @@ -97,8 +97,8 @@ static void app_porta_detect_work(void) else { // 更新typeC的src_cap - pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[0]); - pd_restart_send_src_cap(&g_pd_port, 0); + // pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[SRC_CAP_30W], SRC_CAP_30W); + // pd_restart_send_src_cap(&g_pd_port); usba_plugout_detect_deinit(); usba_plugin_detect_init(USBA_PLUGIN_DETECT_LEVEL_LOW); diff --git a/PD_CPS8841H_33W/code/app/src/comm_event.c b/PD_CPS8841H_33W/code/app/src/comm_event.c index 95123e4..b9824e1 100644 --- a/PD_CPS8841H_33W/code/app/src/comm_event.c +++ b/PD_CPS8841H_33W/code/app/src/comm_event.c @@ -5,6 +5,7 @@ #include "comp_powerout.h" #include "comp_protocol_manager.h" #include "comp_sample_volt_cur_report.h" +#include "pd.h" // 端口状态机 void port_status_run(void) @@ -65,6 +66,12 @@ void port_status_run(void) { port_process_status = port_exit_status; + if(g_pd_port.pd_new_src_pdo != SRC_CAP_30W) + { + pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[SRC_CAP_30W], SRC_CAP_30W); + pd_restart_send_src_cap(&g_pd_port); + } + // 单C口时, 常开buck, 关闭gateA, 等A口有拉电流才反过来 buck_control(true); dpdm_power_a1_gate_enable(false); @@ -97,13 +104,18 @@ void port_status_run(void) { port_process_status = port_exit_status; + if(g_pd_port.pd_new_src_pdo != SRC_CAP_20W) + { + pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[SRC_CAP_20W], SRC_CAP_20W); + pd_restart_send_src_cap(&g_pd_port); + } + if(g_powerout_info.set_vol < VOLTAGE_5P5V && (get_adp_curr_sample_volt() < VOLTAGE_5P5V)) { // 加大电流--->开gateA--->关buck // comp_powerout_prl_set_cur(CURRENT_5A); comp_set_current(&g_powerout_info, CURRENT_5P5A); // 需要立刻设置 - // 是否有可能电流环设置的没那么快, 一打开gateA就被拉挂了? 需要加个延迟等电流环设置完再开A? // drv_delay_us(500); // drv_delay_ms(5); diff --git a/PD_CPS8841H_33W/code/app/src/customized.c b/PD_CPS8841H_33W/code/app/src/customized.c index ffcf26d..e2f5b20 100644 --- a/PD_CPS8841H_33W/code/app/src/customized.c +++ b/PD_CPS8841H_33W/code/app/src/customized.c @@ -1027,29 +1027,29 @@ const ufcs_power_change_capabilities_u DERATE_POWER_CHANGE_PDO[] = #endif -const ufcs_config_init_s UFCS_INIT_CONFIG[][PORT_TYPE_DUAL_PORT] = -{ - { +// const ufcs_config_init_s UFCS_INIT_CONFIG[][PORT_TYPE_DUAL_PORT] = +// { +// { - { - .prl_supported = true, +// { +// .prl_supported = true, - .ufcs_out_mode_info = UFCS_OUT_MODE_INFO, +// .ufcs_out_mode_info = UFCS_OUT_MODE_INFO, - .device_information = DEVICE_INFO, +// .device_information = DEVICE_INFO, -#if UFCS_DERATE_SUPPORT - .def_power_change_pdo = &DEF_POWER_CHANGE_PDO[0], - .derate_power_change_pdo = &DERATE_POWER_CHANGE_PDO[0], -#endif - .prl_common_ops = &PRL_COMMON_OPS +// #if UFCS_DERATE_SUPPORT +// .def_power_change_pdo = &DEF_POWER_CHANGE_PDO[0], +// .derate_power_change_pdo = &DERATE_POWER_CHANGE_PDO[0], +// #endif +// .prl_common_ops = &PRL_COMMON_OPS - } - } +// } +// } -}; +// }; -#endif +// #endif #if PD_SUPPORT diff --git a/PD_CPS8841H_33W/code/app/src/dpdm_run.c b/PD_CPS8841H_33W/code/app/src/dpdm_run.c index 05a27a4..50c032a 100644 --- a/PD_CPS8841H_33W/code/app/src/dpdm_run.c +++ b/PD_CPS8841H_33W/code/app/src/dpdm_run.c @@ -13,19 +13,10 @@ #include "drv_gpio.h" #include "afc.h" #include "comp_cable_compensation.h" +#include "ufcs_protocol.h" +#include "ufcs.h" #include "comp_gpio.h" -typedef enum -{ - DPDM_SRC_STATE_IDLE = 0, - DPDM_SRC_STATE_APPLE, - DPDM_SRC_STATE_BC, - DPDM_SRC_STATE_QC_PRE, - DPDM_SRC_STATE_QC, - DPDM_SRC_STATE_SCP, - DPDM_SRC_STATE_RST, - DPDM_SRC_STATE_NUM -} dpdm_src_state_e; static uint16_t dp_power_down_discern(scp_port_s *scp_port); @@ -41,6 +32,9 @@ const static sm_state_t *Dpdm_Src_Qc_Run(const sm_state_t *self, void *data); const static sm_state_t *Dpdm_Src_Scp_Run(const sm_state_t *self, void *data); static void Dpdm_Src_Rst_Entry(void *data); const static sm_state_t *Dpdm_Src_Rst_Run(const sm_state_t *self, void *data); +#if UFCS_SUPPORT +const static sm_state_t *Dpdm_Src_Ufcs_Run(const sm_state_t *self, void *data); +#endif // clang-format off static const sm_state_t g_dpdm_state[DPDM_SRC_STATE_NUM] = @@ -51,6 +45,9 @@ static const sm_state_t g_dpdm_state[DPDM_SRC_STATE_NUM] = [DPDM_SRC_STATE_QC_PRE] = {Dpdm_Src_Qc_Pre_Entry, Dpdm_Src_Qc_Pre_Run}, [DPDM_SRC_STATE_QC] = {0, Dpdm_Src_Qc_Run}, [DPDM_SRC_STATE_SCP] = {0, Dpdm_Src_Scp_Run}, +#if UFCS_SUPPORT + [DPDM_SRC_STATE_UFCS] = {0, Dpdm_Src_Ufcs_Run}, +#endif [DPDM_SRC_STATE_RST] = {Dpdm_Src_Rst_Entry, Dpdm_Src_Rst_Run}, }; // clang-format on @@ -62,6 +59,9 @@ typedef struct dpdm_src_handshake hvdcp_port_s bc_port; qc_port_s qc_port; scp_port_s scp_port; +#if UFCS_SUPPORT + ufcs_port_s ufcs_port; +#endif uint32_t time_p; uint16_t timer; uint8_t dpdm_port; @@ -100,6 +100,12 @@ static void Dpdm_State_Switching(const sm_state_t *self, void *data) case DPDM_SRC_STATE_SCP: log_info("DPDM_SRC_STATE_SCP\n"); break; +#if UFCS_SUPPORT + + case DPDM_SRC_STATE_UFCS: + log_info("DPDM_SRC_STATE_UFCS\n"); + break; +#endif case DPDM_SRC_STATE_RST: log_info("DPDM_SRC_STATE_RST\n"); @@ -119,28 +125,6 @@ void gp1_sample_init(void) void buck_init(void) { - // REG_CLKCTRL_PIN_MUL_SET->bf.gp2 = 3; - // drv_gpio_enable_out(GPIO_PIN2); - // REG_ANALOG_GP->bf.aie |= (1 << GPIO_PIN2); - // drv_gpio_write(GPIO_PIN2, true); - // drv_gpio_pull_up_resistor_en(GP2, 1); - - // REG_CLKCTRL_PIN_MUL_SET->bf.gp1 = 3; - // drv_gpio_enable_out(GPIO_PIN1); - // drv_gpio_write(GPIO_PIN1, true); - // drv_gpio_pull_up_resistor_en(GP1, 1); - - /* vd 引脚用来当普通GPIO口 */ - // REG_CLKCTRL_PIN_MUL_SET->bf.vd = 3; - // drv_gpio_pull_up_resistor_en(VD, 1); - // drv_gpio_enable_out(GPIO_PIN0); - // drv_analog_vd_res_en(false); - - // /* FB引脚当普通IO口 */ - // REG_CLKCTRL_PIN_MUL_SET->bf.rt2 = 3; - // drv_gpio_pull_up_resistor_en(RT2, 1); - // drv_gpio_enable_out(GPIO_PIN3); - // RT4当dcdc使能引脚 buck是低电平使能 REG_CLKCTRL_PIN_MUL_SET->bf.gp2 = 3; drv_gpio_pull_up_resistor_en(GP2, 1); @@ -165,6 +149,9 @@ void dpdm_time_run(void) hvdcp_prl_timer(&p->bc_port); qc_prl_timer(&p->qc_port); scp_prl_timer(&p->scp_port); +#if UFCS_SUPPORT + ufcs_prl_timer(&p->ufcs_port); +#endif p->time_p++; if(p->timer) @@ -183,6 +170,10 @@ static void Dpdm_Src_Idle_Entry(void *data) { dpdm_t *p = (dpdm_t *)data; p->timer = 0; + +#if UFCS_SUPPORT + ufcs_port_init(&p->ufcs_port); +#endif } const static sm_state_t *Dpdm_Src_Idle_Run(const sm_state_t *self, void *data) @@ -210,6 +201,24 @@ const static sm_state_t *Dpdm_Src_Apple_Run(const sm_state_t *self, void *data) dpdm_src_state_e dpdm_state = DPDM_SRC_STATE_APPLE; apple_port_prl_stack_run(&p->applp_port); + +#if UFCS_SUPPORT + + // 没进ufcs状态机前, 收到hard_reset都不响应, 直接清零 + if(p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset) + { + p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset = 0; + } + + ufcs_port_prl_stack_run(&p->ufcs_port); + + if(dpdm_power_get_next_protocol() == PROTOCOL_UFCS) // 在ping成功时会置为ufcs协议,ufcs_handshake_ping_callback_patch + { + dpdm_state = DPDM_SRC_STATE_UFCS; + } + +#endif + if(dpdm_power_get_next_protocol() == PROTOCOL_DCP) { apple_port_enable_apple(&p->applp_port, false); @@ -231,6 +240,24 @@ const static sm_state_t *Dpdm_Src_Bc_Run(const sm_state_t *self, void *data) dpdm_src_state_e dpdm_state = DPDM_SRC_STATE_BC; hvdcp_prl_stack_run(&p->bc_port); +#if UFCS_SUPPORT + + // 没进ufcs状态机前, 收到hard_reset都不响应, 直接清零 + if(p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset) + { + p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset = 0; + } + + // 在下面这个函数里进行2828握手成功判断 + ufcs_port_prl_stack_run(&p->ufcs_port); + + if(dpdm_power_get_next_protocol() == PROTOCOL_UFCS) // 在ping成功时会置为ufcs协议,ufcs_handshake_ping_callback_patch + { + dpdm_state = DPDM_SRC_STATE_UFCS; + } + +#endif + if(dpdm_power_get_next_protocol() == PROTOCOL_QC_PRE) { dpdm_state = DPDM_SRC_STATE_QC_PRE; @@ -256,6 +283,23 @@ const static sm_state_t *Dpdm_Src_Qc_Pre_Run(const sm_state_t *self, void *data) qc_prl_stack_run(&p->qc_port); scp_prl_stack_run(&p->scp_port); +#if UFCS_SUPPORT + + // 没进ufcs状态机前, 收到hard_reset都不响应, 直接清零 + if(p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset) + { + p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset = 0; + } + + ufcs_port_prl_stack_run(&p->ufcs_port); + + if(dpdm_power_get_next_protocol() == PROTOCOL_UFCS) // 在ping成功时会置为ufcs协议,ufcs_handshake_ping_callback_patch + { + dpdm_state = DPDM_SRC_STATE_UFCS; + } + +#endif + if(dp_power_down_discern(&p->scp_port)) { dpdm_state = DPDM_SRC_STATE_RST; @@ -303,6 +347,25 @@ const static sm_state_t *Dpdm_Src_Scp_Run(const sm_state_t *self, void *data) return &g_dpdm_state[dpdm_state]; } +#if UFCS_SUPPORT +const static sm_state_t *Dpdm_Src_Ufcs_Run(const sm_state_t *self, void *data) +{ + dpdm_t *p = (dpdm_t *)data; + dpdm_src_state_e dpdm_state = DPDM_SRC_STATE_UFCS; + + // ufcs_reset + if(p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.ufcs_reset) + { + log_info("ufcs_reset\n"); + dpdm_state = DPDM_SRC_STATE_RST; + } + + ufcs_port_prl_stack_run(&p->ufcs_port); + + return &g_dpdm_state[dpdm_state]; +} +#endif + static void Dpdm_Src_Rst_Entry(void *data) { dpdm_t *p = (dpdm_t *)data; @@ -390,3 +453,68 @@ void DPDN_COMP_Handler(void) is_last_dp = is_dp; is_last_dm = is_dm; } + +#if UFCS_SUPPORT + +void ufcs_dpdn_ovp(void) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + p->ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_pe_event_flag.bits.dn_over_voltage_flag = true; +} + +void dpdn_mgr_enable_dpdn_prl(uint8_t en) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + ufcs_port_enable_ufcs(&p->ufcs_port, en); +} + +void dpdm_mgr_ufcs_rx_handler(uint8_t port_num) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + ufcs_port_rx_handler(&p->ufcs_port); +} + + +void dpdm_mgr_ufcs_tx_handler(uint8_t port_num) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + ufcs_port_tx_handler(&p->ufcs_port); +} + +ufcs_port_s *dpdm_get_ufcs_port(void) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + return &p->ufcs_port; +} + +void dpdn_mgr_ufcs_hdsk_pluse_handler(uint8_t port_num) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + ufcs_port_hdsk_pluse_handler(&p->ufcs_port); +} + + +void PWD_Handler(void) +{ + dpdm_t *p = (dpdm_t *)&g_dpdm; + dpdm_src_state_e current_protocol = (dpdm_src_state_e)((p->sm.current_state - g_dpdm_state)); + + if(drv_extint_pwd1_read() & REG_EXTINT_VAL_BIT) + { + drv_extint_pwd1_mask_set(REG_EXTINT_CLR_BIT); //clr + + if(current_protocol == DPDM_SRC_STATE_APPLE + || current_protocol == DPDM_SRC_STATE_BC + || current_protocol == DPDM_SRC_STATE_QC_PRE + || current_protocol == DPDM_SRC_STATE_UFCS) + { +#if UFCS_SUPPORT + dpdn_mgr_ufcs_hdsk_pluse_handler(ADP_PORT0); // 参数并没有用到 +#endif + } + + } +} + + +#endif diff --git a/PD_CPS8841H_33W/code/app/src/porta_detect.c b/PD_CPS8841H_33W/code/app/src/porta_detect.c index ce507df..76498d5 100644 --- a/PD_CPS8841H_33W/code/app/src/porta_detect.c +++ b/PD_CPS8841H_33W/code/app/src/porta_detect.c @@ -70,6 +70,17 @@ void usba_plugin_detect_init(uint8_t level) det_data->level = level; det_data->last_time = get_sys_time(); det_data->attached = 0; + + + // 配置小电流寄存器 + drv_analog_usba_detach_config( + USBA_DETACH_CFG(true, USBA_DETACH_REF_100UV, USBA_DETACH_CLK_10K, + USBA_DETACH_WIDTH_75MS)); + + // 配置完小电流寄存器后要等生效 + drv_delay_ms(100); + + // log_info("usba_plugin_detect_init\n"); } void usba_plugin_detect_deinit(void) @@ -145,10 +156,6 @@ bool usba_plugin_detect(void) void usba_plugout_detect_init(void) { usba_det_s *det_data = &g_usba_det_data; - - drv_analog_usba_detach_config( - USBA_DETACH_CFG(true, USBA_DETACH_REF_100UV, USBA_DETACH_CLK_10K, - USBA_DETACH_WIDTH_75MS)); det_data->attached = true; det_data->last_time = get_sys_time(); } diff --git a/PD_CPS8841H_33W/code/component/inc/comp_dpdn_manager.h b/PD_CPS8841H_33W/code/component/inc/comp_dpdn_manager.h index aeba5a4..d920146 100644 --- a/PD_CPS8841H_33W/code/component/inc/comp_dpdn_manager.h +++ b/PD_CPS8841H_33W/code/component/inc/comp_dpdn_manager.h @@ -15,7 +15,7 @@ apple_port_get_apple_supported() -void dpdn_mgr_enable_dpdn_prl(uint8_t port_num, uint8_t en); +// void dpdn_mgr_enable_dpdn_prl(uint8_t port_num, uint8_t en); void dpdn_mgr_prl_init(uint8_t port_num, uint8_t port_type); void dpdn_mgr_prl_deinit(uint8_t port_num, uint8_t port_type, uint8_t scp_reset_mode); void dpdn_mgr_prl_stack_run(uint8_t port_num); @@ -33,7 +33,7 @@ void dpdn_mgr_enable_hvdcp_prl(uint8_t port_num, uint8_t en); void dpdn_mgr_ufcs_hdsk_pluse_handler(uint8_t port_num); void dpdm_mgr_ufcs_rx_handler(uint8_t port_num); void dpdm_mgr_ufcs_tx_handler(uint8_t port_num); -void dpdm_mgr_ufcs_send_power_change(uint8_t port_num, const ufcs_power_change_capabilities_u *new_power_change); +//void dpdm_mgr_ufcs_send_power_change(uint8_t port_num, const ufcs_power_change_capabilities_u *new_power_change); const ufcs_config_init_s * dpdm_mgr_get_ufcs_cur_config(uint8_t port_num); void dpdm_mgr_scp_handler(uint8_t port_num); diff --git a/PD_CPS8841H_33W/code/component/inc/comp_protocol_manager.h b/PD_CPS8841H_33W/code/component/inc/comp_protocol_manager.h index e1b1851..feb5de6 100644 --- a/PD_CPS8841H_33W/code/component/inc/comp_protocol_manager.h +++ b/PD_CPS8841H_33W/code/component/inc/comp_protocol_manager.h @@ -27,7 +27,9 @@ static bool buck_state; #define PROTOCOL_SCP 7 #define PROTOCOL_FCP 8 #define PROTOCOL_AFC 9 - +#if UFCS_SUPPORT +#define PROTOCOL_UFCS 10 +#endif void dpdm_power_set(uint16_t vset, uint16_t iset); void dpdm_power_gate_enable(bool is_en); diff --git a/PD_CPS8841H_33W/code/component/src/comp_otp_derate_policy.c b/PD_CPS8841H_33W/code/component/src/comp_otp_derate_policy.c index 28a364f..04a37fa 100644 --- a/PD_CPS8841H_33W/code/component/src/comp_otp_derate_policy.c +++ b/PD_CPS8841H_33W/code/component/src/comp_otp_derate_policy.c @@ -27,13 +27,13 @@ void comp_otp_derate_policy_task(void) g_curr_derate = g_protection_param.otp_derate; -#if UFCS_DERATE_SUPPORT - const ufcs_config_init_s *ufcs_config; - const ufcs_power_change_capabilities_u *power_change; +// #if UFCS_DERATE_SUPPORT +// const ufcs_config_init_s *ufcs_config; +// const ufcs_power_change_capabilities_u *power_change; - ufcs_config = dpdm_mgr_get_ufcs_cur_config(ADP_PORT0); +// ufcs_config = dpdm_mgr_get_ufcs_cur_config(ADP_PORT0); -#endif +// #endif #if PD_DERATE_SUPPORT const pd_config_init_s *pd_config; @@ -47,9 +47,9 @@ void comp_otp_derate_policy_task(void) #if PD_DERATE_SUPPORT pd_new_src_pdo = pd_config->derate_src_cap_info; #endif -#if UFCS_DERATE_SUPPORT - power_change = ufcs_config->derate_power_change_pdo; -#endif +// #if UFCS_DERATE_SUPPORT +// power_change = ufcs_config->derate_power_change_pdo; +// #endif } else { @@ -57,9 +57,9 @@ void comp_otp_derate_policy_task(void) pd_new_src_pdo = NULL; #endif -#if UFCS_DERATE_SUPPORT - power_change = ufcs_config->def_power_change_pdo; -#endif +// #if UFCS_DERATE_SUPPORT +// power_change = ufcs_config->def_power_change_pdo; +// #endif } @@ -71,9 +71,9 @@ void comp_otp_derate_policy_task(void) g_scp_rega5_derating_ratio = SCP_DERATE_A5_NUM[g_curr_derate]; #endif -#if UFCS_DERATE_SUPPORT - dpdm_mgr_ufcs_send_power_change(ADP_PORT0, power_change); -#endif +// #if UFCS_DERATE_SUPPORT +// dpdm_mgr_ufcs_send_power_change(ADP_PORT0, power_change); +// #endif } diff --git a/PD_CPS8841H_33W/code/component/src/comp_pd_manager.c b/PD_CPS8841H_33W/code/component/src/comp_pd_manager.c index d6e6257..56214ed 100644 --- a/PD_CPS8841H_33W/code/component/src/comp_pd_manager.c +++ b/PD_CPS8841H_33W/code/component/src/comp_pd_manager.c @@ -18,7 +18,7 @@ const pd_pdo_info_s PD_DEFAULT_CAP_INFO[] = }, { - .pdo_cnt = 4, + .pdo_cnt = 2, .src_pdp = 20, .pdo0 = PD_SRC_FPS_PDO(VOLTAGE_5V, CURRENT_3A, PD_SRC_FPS_FLAGS), .pdo1 = PD_SRC_FPS_PDO(VOLTAGE_9V, CURRENT_2P22A, 0), diff --git a/PD_CPS8841H_33W/code/component/src/comp_protection.c b/PD_CPS8841H_33W/code/component/src/comp_protection.c index 93912c8..cd02a59 100644 --- a/PD_CPS8841H_33W/code/component/src/comp_protection.c +++ b/PD_CPS8841H_33W/code/component/src/comp_protection.c @@ -19,6 +19,7 @@ #include "comp_discharge.h" #include "comp_lps_protect.h" #include "comp_usba_port_detect.h" +#include "dpdm_run.h" protection_param_s g_protection_param = {0}; @@ -285,10 +286,11 @@ void comp_protection_monitor(protection_param_s *protection_param) if(index == PROT_DN_WET) { - if(get_adp_prl_mgr_cur_prl() == PROTOCOL_UFCS) + if(dpdm_power_get_next_protocol() == PROTOCOL_UFCS) { comp_powerout_close_nmos(); - ufcs_prl_dn_over_volt(true); + // ufcs_prl_dn_over_volt(true); + ufcs_dpdn_ovp(); break; } } diff --git a/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/inc/pd_send_new_src_cap.h b/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/inc/pd_send_new_src_cap.h index d73ce5c..3f1a4c3 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/inc/pd_send_new_src_cap.h +++ b/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/inc/pd_send_new_src_cap.h @@ -4,9 +4,10 @@ #include "pd_protocol.h" #include "config.h" - +#define SRC_CAP_30W 0 +#define SRC_CAP_20W 1 void pd_new_src_cap_update_work(pd_port_s *pd_port); -void pd_dpm_update_source_cap(pd_port_s *pd_port, const pd_pdo_info_s *pdo); -void pd_restart_send_src_cap(pd_port_s *pd_port, uint8_t idx); +void pd_dpm_update_source_cap(pd_port_s *pd_port, const pd_pdo_info_s *pdo, uint8_t src_cap_idx); +void pd_restart_send_src_cap(pd_port_s *pd_port); #endif diff --git a/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_protocol.c b/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_protocol.c index 9bdca14..8504da0 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_protocol.c +++ b/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_protocol.c @@ -22,14 +22,14 @@ static void pd_protocol_config_init(pd_port_s *pd_port) pd_param_s *pd_param = &pd_port->pd_prl_param; - uint8_t ac_high_sta; + // uint8_t ac_high_sta; - ac_high_sta = *config->prl_common_ops->ac_high_sta; + // ac_high_sta = *config->prl_common_ops->ac_high_sta; - pd_dpm_update_source_cap(pd_port, &config->src_cap_info[ac_high_sta]); + // pd_dpm_update_source_cap(pd_port, &config->src_cap_info[ac_high_sta], SRC_CAP_30W); - pd_dpm_update_source_cap(pd_port, config->src_cap_info); + pd_dpm_update_source_cap(pd_port, config->src_cap_info, SRC_CAP_30W); memcpy(&pd_param->pd_assist.pd_ppssdb, &config->pd_ppssdb, sizeof(config->pd_ppssdb)); diff --git a/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_send_new_src_cap.c b/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_send_new_src_cap.c index 8995734..ed94e80 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_send_new_src_cap.c +++ b/PD_CPS8841H_33W/code/platform/protocol/pd_protocol/src/pd_send_new_src_cap.c @@ -1,10 +1,13 @@ #include "pd_send_new_src_cap.h" -void pd_dpm_update_source_cap(pd_port_s *pd_port, const pd_pdo_info_s *pdo) +void pd_dpm_update_source_cap(pd_port_s *pd_port, const pd_pdo_info_s *pdo, uint8_t src_cap_idx) { pd_param_s *pd_param = &pd_port->pd_prl_param; + pd_port->pd_new_src_pdo = src_cap_idx; + log_info("updata src_cap:%d\n", src_cap_idx); + pd_param->pd_assist.src_cap_send.pdo_cnt = pdo->pdo_cnt; memcpy(&pd_param->pd_assist.src_cap_send.pd_pdos[0].byte, &pdo->pdo0, 28); //src ext @@ -14,14 +17,8 @@ void pd_dpm_update_source_cap(pd_port_s *pd_port, const pd_pdo_info_s *pdo) pd_port->pd_old_src_pdo = pdo; } -void pd_restart_send_src_cap(pd_port_s *pd_port, uint8_t idx) +void pd_restart_send_src_cap(pd_port_s *pd_port) { - if(idx == pd_port->pd_new_src_pdo) - { - return; - } - - pd_port->pd_new_src_pdo = idx; pd_port->pd_send_new_src_cap_enable = true; } @@ -48,7 +45,9 @@ void pd_new_src_cap_update_work(pd_port_s *pd_port) (pd_param->pd_pe_status.pe_status == PE_SRC_Startup) ) { - pd_dpm_update_source_cap(pd_port, &pd_port->pd_curr_config->src_cap_info[pd_port->pd_new_src_pdo]); + pd_dpm_update_source_cap(pd_port, + &pd_port->pd_curr_config->src_cap_info[pd_port->pd_new_src_pdo], + pd_port->pd_new_src_pdo); pd_port->pd_send_new_src_cap_enable = false; 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 fe19def..164ef9c 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 @@ -58,16 +58,12 @@ void qc_voltage_request_work(qc_port_s *qc_port) if(qc_param->qc_assist.request_vol == 5000) { - iset = CURRENT_2P3A; - - if(port_a1_is_attached() && typec_is_attched()) - { - iset = CURRENT_3P4A; - } + iset = CURRENT_3P3A; + // A + C 且都在5V时, 在powerout里会把电流设为5.5A } else if(qc_param->qc_assist.request_vol == 9000) { - iset = CURRENT_2P3A; + iset = CURRENT_3P3A; if(port_a1_is_attached() && typec_is_attched()) { @@ -75,13 +71,21 @@ void qc_voltage_request_work(qc_port_s *qc_port) } } - else if(qc_param->qc_assist.request_vol >= 12000) + else if(qc_param->qc_assist.request_vol == 12000) { - qc_param->qc_assist.request_vol = 12000; - iset = CURRENT_2P3A; - + iset = CURRENT_2P8A; + if(port_a1_is_attached() && typec_is_attched()) + { + iset = CURRENT_1P8A; + } + } + else if(qc_param->qc_assist.request_vol >= 20000) + { + qc_param->qc_assist.request_vol = 20000; + iset = CURRENT_1P8A; if(port_a1_is_attached() && typec_is_attched()) { + qc_param->qc_assist.request_vol = 12000; iset = CURRENT_1P8A; } } diff --git a/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/inc/ufcs_protocol.h b/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/inc/ufcs_protocol.h index bfd6f20..9de6e02 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/inc/ufcs_protocol.h +++ b/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/inc/ufcs_protocol.h @@ -14,6 +14,10 @@ #include "ufcs_app.h" #include "config.h" /******************UFCS*output_cap define*****************************/ + +#define UFCS_CAP_30W 0 +#define UFCS_CAP_20W 1 + typedef enum { UFCS_VOL_STEP_10MV = 0, @@ -109,12 +113,12 @@ typedef struct ufcs_config_init_s #if UFCS_DERATE_SUPPORT const ufcs_power_change_capabilities_u *def_power_change_pdo; - const ufcs_power_change_capabilities_u *derate_power_change_pdo; + // const ufcs_power_change_capabilities_u *derate_power_change_pdo; #endif void (*protection_exception_flag_set)(void); - const prl_common_ops_s *prl_common_ops; + // const prl_common_ops_s *prl_common_ops; } ufcs_config_init_s; @@ -136,6 +140,8 @@ typedef struct ufcs_port_s uint8_t port_num; + uint8_t current_cap_gear; // ǰλ + } ufcs_port_s; @@ -147,5 +153,6 @@ void ufcs_prl_rx_handler(ufcs_port_s *ufcs_port); void ufcs_prl_tx_handler(ufcs_port_s *ufcs_port); void ufcs_prl_enable_ufcs(ufcs_port_s *ufcs_port, uint8_t en); void ufcs_prl_timer(ufcs_port_s *ufcs_port); +void dcp_ufcs_run(ufcs_port_s *ufcs_port); #endif diff --git a/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/src/ufcs_protocol.c b/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/src/ufcs_protocol.c index 1588b40..d778d08 100644 --- a/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/src/ufcs_protocol.c +++ b/PD_CPS8841H_33W/code/platform/protocol/ufcs_protocol/src/ufcs_protocol.c @@ -11,7 +11,10 @@ #include "ufcs_protocol.h" - +#include "ufcs.h" +#include "comp_primary_side.h" +#include "comp_sample_volt_cur_report.h" +#include "comp_temp_report.h" /* * @brief drv_dpdn1_short_staus_get @@ -37,15 +40,16 @@ static void ufcs_protocol_config_init(ufcs_port_s *ufcs_port, const ufcs_config_ { ufcs_param_s *ufcs_param = &ufcs_port->ufcs_prl_param; - uint8_t ac_high_sta; + // uint8_t ac_high_sta; - ASSERT(config->prl_common_ops); + // ASSERT(config->prl_common_ops); + // ASSERT(config->prl_common_ops->ac_high_sta); + // ac_high_sta = *config->prl_common_ops->ac_high_sta; - ASSERT(config->prl_common_ops->ac_high_sta); + // ac_high_sta = g_edge_param.ac_high; - ac_high_sta = *config->prl_common_ops->ac_high_sta; - ufcs_dpm_update_out_mode(ufcs_param, &config->ufcs_out_mode_info[ac_high_sta]); + ufcs_dpm_update_out_mode(ufcs_param, &config->ufcs_out_mode_info[0]); memcpy(&ufcs_param->ufcs_assist.device_information.byte[0], &config->device_information->byte[0], 8); @@ -63,10 +67,12 @@ void ufcs_prl_init(ufcs_port_s *ufcs_port) { ufcs_param_s *ufcs_param = &ufcs_port->ufcs_prl_param; - if(!ufcs_port->ufcs_curr_config->prl_supported) - { - return; - } + // if(!ufcs_port->ufcs_curr_config->prl_supported) + // { + // return; + // } + + ufcs_port->ufcs_curr_config = UFCS_INIT_CONFIG; ufcs_protocol_default_init(ufcs_param); @@ -133,10 +139,13 @@ static void patch_ufcs_prl_rx_check_msgnumber(ufcs_param_s *ufcs_param) static void ufcs_prl_report_info_update(ufcs_param_s *ufcs_param, const ufcs_config_init_s *config) { ASSERT(config); - ufcs_param->ufcs_assist.ufcs_adc_vol = *config->prl_common_ops->adc_vol; - ufcs_param->ufcs_assist.ufcs_adc_cur = *config->prl_common_ops->adc_cur; - ufcs_param->ufcs_assist.ufcs_report_temp = *config->prl_common_ops->report_temp; + // ufcs_param->ufcs_assist.ufcs_adc_vol = *config->prl_common_ops->adc_vol; + // ufcs_param->ufcs_assist.ufcs_adc_cur = *config->prl_common_ops->adc_cur; + // ufcs_param->ufcs_assist.ufcs_report_temp = *config->prl_common_ops->report_temp; + ufcs_param->ufcs_assist.ufcs_adc_vol = get_adp_curr_sample_volt(); + ufcs_param->ufcs_assist.ufcs_adc_cur = get_adp_curr_sample_cur(); + ufcs_param->ufcs_assist.ufcs_report_temp = get_adp_curr_temp(); } 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 36e93af..6d3a1c3 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 @@ -17,7 +17,7 @@ -#define CFG_ASSERT +// #define CFG_ASSERT #define ASSERT_PRINT comp_uart2_sync_print diff --git a/PD_CPS8841H_33W/code/prl_portable/inc/pd.h b/PD_CPS8841H_33W/code/prl_portable/inc/pd.h index 0e5d419..db0d621 100644 --- a/PD_CPS8841H_33W/code/prl_portable/inc/pd.h +++ b/PD_CPS8841H_33W/code/prl_portable/inc/pd.h @@ -35,7 +35,7 @@ static inline void pd_port_typec_prl_handler(pd_port_s *pd_port) static inline void pd_port_restart_send_src_cap(pd_port_s *pd_port, const pd_pdo_info_s *new_src_pdo) { - pd_restart_send_src_cap(pd_port, 0); + pd_restart_send_src_cap(pd_port); } diff --git a/PD_CPS8841H_33W/code/prl_portable/inc/ufcs.h b/PD_CPS8841H_33W/code/prl_portable/inc/ufcs.h index a083dbe..32764fa 100644 --- a/PD_CPS8841H_33W/code/prl_portable/inc/ufcs.h +++ b/PD_CPS8841H_33W/code/prl_portable/inc/ufcs.h @@ -5,17 +5,17 @@ #include "config.h" -extern ufcs_port_s g_ufcs_port; +// extern ufcs_port_s g_ufcs_port; #define ufcs_prl_get_ufcs_supported()\ (g_ufcs_prl_supported) -#define ufcs_prl_dn_over_volt(x)\ - do{\ - g_ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_pe_event_flag.bits.dn_over_voltage_flag = x;\ - }while(0) +// #define ufcs_prl_dn_over_volt(x)\ +// do{\ +// g_ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_pe_event_flag.bits.dn_over_voltage_flag = x;\ +// }while(0) @@ -23,7 +23,7 @@ extern ufcs_port_s g_ufcs_port; void ufcs_port_init(ufcs_port_s *ufcs_port); void ufcs_port_deinit(ufcs_port_s *ufcs_port); void ufcs_port_trans_port_type_config(uint8_t port_num, uint8_t port_type); -ufcs_port_s *ufcs_get_ufcs_port(uint8_t port_num); +// ufcs_port_s *ufcs_get_ufcs_port(uint8_t port_num); const ufcs_config_init_s * ufcs_get_ufcs_cur_config(uint8_t port_num); void ufcs_port_dpdn_port_num_config(uint8_t dpdn_num); void ufcs_port_send_power_change(ufcs_port_s *ufcs_port, const ufcs_power_change_capabilities_u *new_power_change); @@ -69,7 +69,8 @@ static inline void ufcs_port_tx_handler(ufcs_port_s *ufcs_port) ufcs_prl_tx_handler(ufcs_port); } +void dpdm_mgr_ufcs_send_power_change(const ufcs_power_change_capabilities_u *new_power_change); - +extern const ufcs_config_init_s UFCS_INIT_CONFIG[PORT_TYPE_DUAL_PORT]; #endif diff --git a/PD_CPS8841H_33W/code/prl_portable/src/pd.c b/PD_CPS8841H_33W/code/prl_portable/src/pd.c index 1ce9e75..34180f7 100644 --- a/PD_CPS8841H_33W/code/prl_portable/src/pd.c +++ b/PD_CPS8841H_33W/code/prl_portable/src/pd.c @@ -118,7 +118,7 @@ bool app_src_power_handler_patch(pd_param_s *pd_param) { if(request_vol == VOLTAGE_20V) { - offest = CURRENT_0P45A; + offest = CURRENT_0P35A; } else { diff --git a/PD_CPS8841H_33W/code/prl_portable/src/ufcs.c b/PD_CPS8841H_33W/code/prl_portable/src/ufcs.c index 4386f86..a07ea8a 100644 --- a/PD_CPS8841H_33W/code/prl_portable/src/ufcs.c +++ b/PD_CPS8841H_33W/code/prl_portable/src/ufcs.c @@ -3,8 +3,10 @@ #include "comp_protocol_manager.h" #include "comp_powerout.h" #include "customized.h" +#include "comp_cable_compensation.h" +#include "dpdm_run.h" -ufcs_port_s g_ufcs_port; +// ufcs_port_s g_ufcs_port; static void ufcs_handshake_ping_callback_patch(ufcs_param_s *ufcs_param); @@ -54,6 +56,127 @@ static const ufcs_phy_callback_s mtp_ufcs_phy_callback_func = .send_ufcs_pkt = mtp_send_ufcs_pkt }; +#if UFCS_SUPPORT +/*********************UFCS************************************/ + +#define SCP_RS82 0x00 +#define SCP_RS83 0xc3 + + +const ufcs_out_mode_info_s UFCS_OUT_MODE_INFO[] = +{ + + // { + // .out_mode_cnt = 5, + + // .mode1_l = UFCS_SRC_PDO_L(CURRENT_0P3A, CURRENT_5A, VOLTAGE_3P4V, VOLTAGE_5P5V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 1), + // .mode1_h = UFCS_SRC_PDO_H(CURRENT_0P3A, CURRENT_5A, VOLTAGE_3P4V, VOLTAGE_5P5V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 1), + + // .mode2_l = UFCS_SRC_PDO_L(CURRENT_0P3A, CURRENT_6P6A, VOLTAGE_5P5V, VOLTAGE_10V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 2), + // .mode2_h = UFCS_SRC_PDO_H(CURRENT_0P3A, CURRENT_6P6A, VOLTAGE_5P5V, VOLTAGE_10V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 2), + + // .mode3_l = UFCS_SRC_PDO_L(CURRENT_0P3A, CURRENT_6A, VOLTAGE_10V, VOLTAGE_11V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 3), + // .mode3_h = UFCS_SRC_PDO_H(CURRENT_0P3A, CURRENT_6A, VOLTAGE_10V, VOLTAGE_11V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 3), + + // .mode4_l = UFCS_SRC_PDO_L(CURRENT_0P3A, CURRENT_3P25A, VOLTAGE_11V, VOLTAGE_20V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 4), + // .mode4_h = UFCS_SRC_PDO_H(CURRENT_0P3A, CURRENT_3P25A, VOLTAGE_11V, VOLTAGE_20V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 4), + + // .mode5_l = UFCS_SRC_PDO_L(CURRENT_0P3A, CURRENT_3P1A, VOLTAGE_20V, VOLTAGE_21V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 5), + // .mode5_h = UFCS_SRC_PDO_H(CURRENT_0P3A, CURRENT_3P1A, VOLTAGE_20V, VOLTAGE_21V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 5), + + // .mode6_l = 0, + // .mode6_h = 0, + + // .mode7_l = 0, + // .mode7_h = 0 + // } + + { + .out_mode_cnt = 1, + + .mode1_l = UFCS_SRC_PDO_L(CURRENT_0P3A, CURRENT_3A, VOLTAGE_3P4V, VOLTAGE_11V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 1), + .mode1_h = UFCS_SRC_PDO_H(CURRENT_0P3A, CURRENT_3A, VOLTAGE_3P4V, VOLTAGE_11V, UFCS_VOL_STEP_20MV, UFCS_CUR_STEP_50MA, 1), + + .mode2_l = 0, + .mode2_h = 0, + + .mode3_l = 0, + .mode3_h = 0, + + .mode4_l = 0, + .mode4_h = 0, + + .mode5_l = 0, + .mode5_h = 0, + + .mode6_l = 0, + .mode6_h = 0, + + .mode7_l = 0, + .mode7_h = 0 + } + +}; + + + + +const device_information_u DEVICE_INFO[] = +{ + { + .bits.vdmid_h = (HUAWEI_UFCS_VDM_ID >> 8), + .bits.vdmid_l = (HUAWEI_UFCS_VDM_ID & 0xff), + .bits.chipid_h = SCP_RS82, + .bits.chipid_l = SCP_RS83, + .bits.hard_ware_h = 0x00, + .bits.hard_ware_l = 0x00, + .bits.soft_ware_h = SOFT_WARE_VERISION_H, + .bits.soft_ware_l = SOFT_WARE_VERISION_L + } +}; + +#if UFCS_DERATE_SUPPORT + +const ufcs_power_change_capabilities_u DEF_POWER_CHANGE_PDO[] = +{ + // 30W + { + .bits.index = 1, + .bits.resverd0 = 0, + .bits.max_output_cur_L = UFCS_POWER_CHANGE_L(CURRENT_3A), + .bits.max_output_cur_H = UFCS_POWER_CHANGE_H(CURRENT_3A), + }, + + // 20W + { + .bits.index = 1, + .bits.resverd0 = 0, + .bits.max_output_cur_L = UFCS_POWER_CHANGE_L(CURRENT_2A), + .bits.max_output_cur_H = UFCS_POWER_CHANGE_H(CURRENT_2A), + }, +}; +#endif + + +const ufcs_config_init_s UFCS_INIT_CONFIG[PORT_TYPE_DUAL_PORT] = +{ + { + .prl_supported = true, + + .ufcs_out_mode_info = UFCS_OUT_MODE_INFO, + + .device_information = DEVICE_INFO, + +#if UFCS_DERATE_SUPPORT + .def_power_change_pdo = &DEF_POWER_CHANGE_PDO[0], +#endif + // .prl_common_ops = &PRL_COMMON_OPS + } + +}; + +#endif + extern uint8_t g_ufcs_curr_tx_len; @@ -107,13 +230,15 @@ static uint8_t ptach_ufcs_src_hw_scpb_power_packet(ufcs_param_s *ufcs_param) */ void ufcs_handshake_ping_callback_patch(ufcs_param_s *ufcs_param) { - if((get_adp_prl_mgr_cur_prl() == PROTOCOL_PD_FIX) || - (get_adp_prl_mgr_cur_prl() == PROTOCOL_PD_PPS)) + if((dpdm_power_get_next_protocol() == PROTOCOL_PD_FIX) || + (dpdm_power_get_next_protocol() == PROTOCOL_PD_PPS)) { - prl_mgr_set_curr_volt(VOLTAGE_5V); + // prl_mgr_set_curr_volt(VOLTAGE_5V); + comp_powerout_prl_set_volt(VOLTAGE_5V); } - prl_mgr_set_cur_prl(PROTOCOL_UFCS); + // prl_mgr_set_cur_prl(PROTOCOL_UFCS); + dpdm_power_set_next_protocol(PROTOCOL_UFCS); } @@ -134,8 +259,13 @@ static void app_src_power_set(ufcs_param_s *ufcs_param) iset = (ufcs_param->ufcs_flags.ufcs_process_flag.bits.test_mode == true) ? \ ((iset * 1126) >> 10) : iset; - prl_mgr_set_curr_volt(vset); - prl_mgr_set_curr_cur(iset); + // prl_mgr_set_curr_volt(vset); + // prl_mgr_set_curr_cur(iset); + + // ufcsر߲ + set_cable_comp_enable(false); + // dpdm_power_set_next_protocol(PROTOCOL_UFCS); // pingɹ + dpdm_power_set(vset, iset); } /* @@ -181,7 +311,9 @@ static void ufcs_src_volt_test_func(u_test_req *test_req) volt_test_mode = test_req->bits.volt_test_mode; - if(g_ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.test_mode == volt_test_mode) + ufcs_port_s *ufcs_port = dpdm_get_ufcs_port(); + + if(ufcs_port->ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.test_mode == volt_test_mode) { return; } @@ -192,10 +324,10 @@ static void ufcs_src_volt_test_func(u_test_req *test_req) ((iset * 1126) >> 10) : ((iset << 10) / 1126); - g_ufcs_port.ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.test_mode = volt_test_mode; - - prl_mgr_set_curr_cur(iset); + ufcs_port->ufcs_prl_param.ufcs_flags.ufcs_process_flag.bits.test_mode = volt_test_mode; + // prl_mgr_set_curr_cur(iset); + comp_powerout_prl_set_cur(iset); #endif } @@ -213,16 +345,15 @@ static uint8_t ufcs_src_power_change_msg_assemble(ufcs_param_s *ufcs_param) uint8_t power_change_len; uint8_t ufcs_cap_cnt; + ufcs_port_s *ufcs_port = dpdm_get_ufcs_port(); + ufcs_cap_cnt = ufcs_param->ufcs_assist.out_cap_cnt; power_change_len = ufcs_cap_cnt * 3; ufcs_param->ufcs_assist.ufcs_sent_pkt.ufcs_sent_buf[4] = power_change_len; - - memcpy(&ufcs_param->ufcs_assist.power_change_cap[0].byte, &g_ufcs_port.ufcs_new_power_change_cur->byte, power_change_len); - - + memcpy(&ufcs_param->ufcs_assist.power_change_cap[0].byte, &ufcs_port->ufcs_new_power_change_cur->byte, power_change_len); memcpy(&ufcs_param->ufcs_assist.ufcs_sent_pkt.ufcs_sent_buf[5], ufcs_param->ufcs_assist.power_change_cap[0].byte, power_change_len); power_change_len += 5; @@ -255,6 +386,14 @@ void ufcs_port_init(ufcs_port_s *ufcs_port) ufcs_port_prl_hook_register(ufcs_port); ufcs_prl_init(ufcs_port); ufcs_port->ufcs_prl_param.ufcs_phy_callback = &mtp_ufcs_phy_callback_func; + + dpdn_mgr_enable_dpdn_prl(true); +#if UFCS_DERATE_SUPPORT + ufcs_port->current_cap_gear = UFCS_CAP_30W; +#endif + + // ṹ + ufcs_protocol_reset(&ufcs_port->ufcs_prl_param); } @@ -266,28 +405,22 @@ void ufcs_port_deinit(ufcs_port_s *ufcs_port) void ufcs_port_dpdn_port_num_config(uint8_t dpdn_num) { - g_ufcs_port.dpdn_port = dpdn_num; -} - - -void ufcs_port_trans_port_type_config(uint8_t port_num, uint8_t port_type) -{ - ufcs_port_s *ufcs_port = ufcs_get_ufcs_port(port_num); - - ufcs_port->ufcs_curr_config = GET_ADP_INIT_CONFIG_ADR(port_num, port_type, UFCS); + ufcs_port_s *ufcs_port = dpdm_get_ufcs_port(); + ufcs_port->dpdn_port = dpdn_num; } -ufcs_port_s *ufcs_get_ufcs_port(uint8_t port_num) -{ - return &g_ufcs_port; -} +// ufcs_port_s *ufcs_get_ufcs_port(uint8_t port_num) +// { +// return &g_ufcs_port; +// } const ufcs_config_init_s * ufcs_get_ufcs_cur_config(uint8_t port_num) { const ufcs_config_init_s *config; + ufcs_port_s *ufcs_port = dpdm_get_ufcs_port(); - config = g_ufcs_port.ufcs_curr_config; + config = ufcs_port->ufcs_curr_config; return config; } @@ -296,18 +429,14 @@ const ufcs_config_init_s * ufcs_get_ufcs_cur_config(uint8_t port_num) void ufcs_port_send_power_change(ufcs_port_s *ufcs_port, const ufcs_power_change_capabilities_u *new_power_change) { - ufcs_port->ufcs_new_power_change_cur = new_power_change; - ufcs_port->ufcs_send_power_change_en = !ufcs_port->ufcs_send_power_change_en; -} - - - - - - - - - +} +void dpdm_mgr_ufcs_send_power_change(const ufcs_power_change_capabilities_u *new_power_change) +{ + ufcs_port_s *ufcs_port = dpdm_get_ufcs_port(); + // ufcs_port_send_power_change(ufcs_port, new_power_change); + ufcs_port->ufcs_new_power_change_cur = new_power_change; + ufcs_port->ufcs_send_power_change_en = !ufcs_port->ufcs_send_power_change_en; +} diff --git a/PD_CPS8841H_33W/project/cps8841H.uvprojx b/PD_CPS8841H_33W/project/cps8841H.uvprojx index b823ad5..74f5096 100644 --- a/PD_CPS8841H_33W/project/cps8841H.uvprojx +++ b/PD_CPS8841H_33W/project/cps8841H.uvprojx @@ -614,6 +614,11 @@ 1 ..\code\prl_portable\src\afc.c + + ufcs.c + 1 + ..\code\prl_portable\src\ufcs.c + @@ -664,6 +669,11 @@ 1 ..\code\platform\protocol\apple_mode\src\apple_mode.c + + ufcs_protocol.c + 1 + ..\code\platform\protocol\ufcs_protocol\src\ufcs_protocol.c +