|
|
@ -6,6 +6,71 @@ |
|
|
|
#include "comp_protocol_manager.h" |
|
|
|
#include "comp_sample_volt_cur_report.h" |
|
|
|
#include "pd.h" |
|
|
|
#include "ufcs.h" |
|
|
|
#include "app_porta.h" |
|
|
|
|
|
|
|
#if UFCS_DERATE_SUPPORT |
|
|
|
void ufcs_power_change_patch(uint16_t src_cap_idx) |
|
|
|
{ |
|
|
|
const ufcs_power_change_capabilities_u *power_change; |
|
|
|
|
|
|
|
// 为了避免撞包问题, 按协议规定12ms内没收到包才发power_change
|
|
|
|
if(user_app.ufcs_need_send_power_change |
|
|
|
&& user_app.ufcs_rx_package_cnt == 0) |
|
|
|
{ |
|
|
|
log_info("ufcs_derate_idx:%d\n", src_cap_idx); |
|
|
|
user_app.ufcs_need_send_power_change = false; |
|
|
|
power_change = &DEF_POWER_CHANGE_PDO[src_cap_idx]; |
|
|
|
dpdm_mgr_ufcs_send_power_change(power_change); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// 参数1: 需要更新多少到多少W的src_cap 参数2: 是否需要重新发送src_cap
|
|
|
|
void updata_diff_protocol_cap(uint16_t src_cap_idx, bool send_src_cap) |
|
|
|
{ |
|
|
|
// 根据当前走的协议是什么,去更新对应的src_cap
|
|
|
|
if(dpdm_power_get_next_protocol() == PROTOCOL_UNKNOWN |
|
|
|
|| dpdm_power_get_next_protocol() == PROTOCOL_APPLE |
|
|
|
|| dpdm_power_get_next_protocol() == PROTOCOL_DCP |
|
|
|
|| dpdm_power_get_next_protocol() == PROTOCOL_QC_PRE |
|
|
|
) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
log_info("%d %d %d\n", |
|
|
|
user_app.current_src_cap_idx, |
|
|
|
src_cap_idx, |
|
|
|
dpdm_power_get_next_protocol()); |
|
|
|
|
|
|
|
user_app.current_src_cap_idx = src_cap_idx; |
|
|
|
|
|
|
|
switch(dpdm_power_get_next_protocol()) |
|
|
|
{ |
|
|
|
case PROTOCOL_PD_FIX: |
|
|
|
case PROTOCOL_PD_PPS: |
|
|
|
pd_dpm_update_source_cap(&g_pd_port, &g_pd_port.pd_curr_config->src_cap_info[src_cap_idx], src_cap_idx); |
|
|
|
|
|
|
|
if(send_src_cap) |
|
|
|
{ |
|
|
|
pd_restart_send_src_cap(&g_pd_port); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case PROTOCOL_SCP: |
|
|
|
break; |
|
|
|
|
|
|
|
#if UFCS_DERATE_SUPPORT |
|
|
|
|
|
|
|
case PROTOCOL_UFCS: |
|
|
|
// 为了避免撞包问题, 按协议规定12ms内没收到包才发power_change
|
|
|
|
user_app.ufcs_need_send_power_change = true; |
|
|
|
break; |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 端口状态机
|
|
|
|
void port_status_run(void) |
|
|
@ -15,8 +80,6 @@ void port_status_run(void) |
|
|
|
static e_port_status port_status = PORT_IS_NULL; |
|
|
|
static e_port_status last_port_status = PORT_IS_NULL; |
|
|
|
static e_port_process_status port_process_status = port_enter_status; |
|
|
|
uint16_t set_current = CURRENT_5A; |
|
|
|
|
|
|
|
|
|
|
|
typec_status = typec_is_attched(); |
|
|
|
usba_status = port_a1_is_attached(); |
|
|
@ -49,6 +112,20 @@ void port_status_run(void) |
|
|
|
if(port_process_status == port_enter_status) |
|
|
|
{ |
|
|
|
port_process_status = port_exit_status; |
|
|
|
#if NTC_ENABLE |
|
|
|
|
|
|
|
if(user_app.ntc_triggered_dera) |
|
|
|
{ |
|
|
|
user_app.current_src_cap_idx = SRC_CAP_7W; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
user_app.current_src_cap_idx = SRC_CAP_30W; |
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
user_app.current_src_cap_idx = SRC_CAP_30W; |
|
|
|
#endif |
|
|
|
|
|
|
|
// 什么都没接时, 也是用buck给A口供电来检查A口是否插入
|
|
|
|
buck_control(true); |
|
|
@ -65,13 +142,6 @@ void port_status_run(void) |
|
|
|
if(port_process_status == port_enter_status) |
|
|
|
{ |
|
|
|
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); |
|
|
@ -81,6 +151,26 @@ void port_status_run(void) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#if NTC_ENABLE |
|
|
|
|
|
|
|
if(user_app.ntc_triggered_dera && user_app.current_src_cap_idx != SRC_CAP_7W) |
|
|
|
{ |
|
|
|
updata_diff_protocol_cap(SRC_CAP_7W, true); |
|
|
|
} |
|
|
|
else if(!user_app.ntc_triggered_dera && user_app.current_src_cap_idx != SRC_CAP_30W) |
|
|
|
{ |
|
|
|
updata_diff_protocol_cap(SRC_CAP_30W, true); |
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if(user_app.current_src_cap_idx != SRC_CAP_30W) |
|
|
|
{ |
|
|
|
updata_diff_protocol_cap(SRC_CAP_30W, true); |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case SINGLE_USBA_INSER: |
|
|
@ -104,23 +194,14 @@ 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);
|
|
|
|
dpdm_power_a1_gate_enable(true); |
|
|
|
// drv_delay_ms(2);
|
|
|
|
buck_control(false); |
|
|
|
} |
|
|
|
else |
|
|
@ -143,22 +224,39 @@ void port_status_run(void) |
|
|
|
&& (get_adp_curr_sample_volt() < VOLTAGE_5P5V) |
|
|
|
&& !REG_ANALOG_GATEA->bf.en) |
|
|
|
{ |
|
|
|
// set_current = CURRENT_5A + user_app.usba_high_current_vol;
|
|
|
|
// if(set_current > CURRENT_6A)
|
|
|
|
// {
|
|
|
|
// set_current = CURRENT_6A;
|
|
|
|
// }
|
|
|
|
// comp_powerout_prl_set_cur(set_current);
|
|
|
|
|
|
|
|
comp_set_current(&g_powerout_info, CURRENT_5P5A); // 需要立刻设置
|
|
|
|
dpdm_power_a1_gate_enable(true); |
|
|
|
buck_control(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if NTC_ENABLE |
|
|
|
|
|
|
|
if(user_app.ntc_triggered_dera && user_app.current_src_cap_idx != SRC_CAP_7W) |
|
|
|
{ |
|
|
|
updata_diff_protocol_cap(SRC_CAP_7W, true); |
|
|
|
} |
|
|
|
else if(!user_app.ntc_triggered_dera && user_app.current_src_cap_idx != SRC_CAP_20W) |
|
|
|
{ |
|
|
|
updata_diff_protocol_cap(SRC_CAP_20W, true); |
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if(user_app.current_src_cap_idx != SRC_CAP_20W) |
|
|
|
{ |
|
|
|
updata_diff_protocol_cap(SRC_CAP_20W, true); |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
#if UFCS_DERATE_SUPPORT |
|
|
|
ufcs_power_change_patch(user_app.current_src_cap_idx); |
|
|
|
#endif |
|
|
|
|
|
|
|
last_port_status = port_status; |
|
|
|
} |
|
|
|
|
|
|
|