You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
3.9 KiB
165 lines
3.9 KiB
/*
|
|
* @Copyright (C),: 2020-2030, ConvenientPower Inc.
|
|
* @File:
|
|
* @Author: zxs
|
|
* @Date: 2023-01-04 15:44:56
|
|
* @LastEditTime: 2023-01-05 18:29:13
|
|
* @LastEditors: your name
|
|
* @Description: Used to specify the main functions accomplished by this program file
|
|
*/
|
|
/**
|
|
******************************************************************************
|
|
* @copyright Copyright (C), 2016-2022, ConvenientPower. Co., Ltd.
|
|
* @file main.c
|
|
* @version 1.0
|
|
* @author CPS SW Team
|
|
* @date 2022/09/28
|
|
* @brief Source file of MAIN module.
|
|
******************************************************************************
|
|
*/
|
|
#include "app_spec.h"
|
|
#include "periodic_work.h"
|
|
#include "comp_pd_manager.h"
|
|
#include "dpdm_run.h"
|
|
#include "app_porta.h"
|
|
#include "analog_define.h"
|
|
#include "ntc.h"
|
|
#include "comp_protocol_manager.h"
|
|
#include "comp_powerout.h"
|
|
|
|
user_app_s user_app;
|
|
|
|
void protocol_pd_work(void)
|
|
{
|
|
pd_mgr_pd_typec_prl_stack_run(0);
|
|
pd_mgr_prl_stack_run(0);
|
|
}
|
|
|
|
void log_output(void)
|
|
{
|
|
// log_info("run...\n");
|
|
log_info("buck:%d gateA:%d gateC:%d\n",
|
|
user_app.buck_state,
|
|
REG_ANALOG_GATEA->bf.en,
|
|
REG_ANALOG_GATEC->bf.en);
|
|
|
|
log_info("A:%d C:%d VIN:%d\n",
|
|
port_a1_is_attached(),
|
|
typec_is_attched(),
|
|
COMP_ADC_GET_VIN());
|
|
|
|
// log_info("RT4_DP:%d RT2_VBUS:%d\n",
|
|
// COMP_ADC_GET_RT4_VOL(),
|
|
// COMP_ADC_GET_RT2_VOL());
|
|
|
|
// log_info("RT2_CUR:0x%x\n", REG_ANALOG_PUCUR->bf.io2);
|
|
|
|
log_info("gp1:%d detached_from_hw:%d\n",
|
|
COMP_ADC_GET_GP1_VOL(),
|
|
drv_analog_get_usba_detach_sta());
|
|
|
|
log_info("a_cur:%d rt3:%d\n",
|
|
COMP_ADC_GET_LS_CUR(),
|
|
COMP_ADC_GET_RT3_VOL());
|
|
|
|
}
|
|
|
|
void comm_event(void)
|
|
{
|
|
// if(user_app.interrupt_event_1)
|
|
// {
|
|
// user_app.interrupt_event_1 = false;
|
|
// buck_control(true);
|
|
// dpdm_power_a1_gate_enable(false);
|
|
// }
|
|
|
|
// if(user_app.interrupt_event_2)
|
|
// {
|
|
// user_app.interrupt_event_2 = false;
|
|
// dpdm_power_a1_gate_enable(true);
|
|
// buck_control(false);
|
|
// }
|
|
|
|
uint16_t set_current = CURRENT_4A;
|
|
|
|
#if POWEROUT_SUPPORT
|
|
|
|
if(get_adp_pwr_init_ok())
|
|
{
|
|
comp_powerout_state_machine_run(&g_powerout_info);
|
|
}
|
|
|
|
#endif
|
|
|
|
// A + C 且 电压 <5.5V时 电流要固定为4A
|
|
if(typec_is_attched()
|
|
&& !drv_analog_get_usba_detach_sta()
|
|
&& g_powerout_info.set_vol <= VOLTAGE_5P5V
|
|
)
|
|
{
|
|
set_current = CURRENT_4A + COMP_ADC_GET_LS_CUR();
|
|
|
|
if(set_current > CURRENT_6A)
|
|
{
|
|
set_current = CURRENT_6A;
|
|
}
|
|
|
|
comp_powerout_prl_set_cur(set_current);
|
|
}
|
|
}
|
|
|
|
static const periodic_work_entry_s app_works[] =
|
|
{
|
|
PERIODIC_WORK_ENTRY(1, 0, protocol_pd_work),
|
|
PERIODIC_WORK_ENTRY(1, 0, dpdm_run),
|
|
// PERIODIC_WORK_ENTRY(1, 0, ntc_run),
|
|
PERIODIC_WORK_ENTRY(1, 0, comm_event),
|
|
PERIODIC_WORK_ENTRY(4, 3, app_port_a1_work),
|
|
PERIODIC_WORK_ENTRY(1024, 0, log_output),
|
|
};
|
|
|
|
static void app_periodic_work(void)
|
|
{
|
|
static uint32_t cnt;
|
|
static uint32_t last_time;
|
|
uint32_t time;
|
|
|
|
time = get_sys_time();
|
|
|
|
if(time - last_time == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
last_time = time;
|
|
++cnt;
|
|
run_periodic_work(app_works, ARRAY_LEN(app_works), cnt);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
if(!system_init())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
dpdm_init();
|
|
app_porta_detect_init();
|
|
REG_ANALOG_DPDN->bf.en_dcp = 1;
|
|
REG_ANALOG_DPDN->bf.en_dn = 1;
|
|
REG_ANALOG_DPDN->bf.en_dp = 1;
|
|
REG_ANALOG_DPDN->bf.meas_dn = 1;
|
|
REG_ANALOG_DPDN->bf.meas_dp = 1;
|
|
REG_ANALOG_DPDN->bf.qc_comp_dn_en = 1;
|
|
REG_ANALOG_DPDN->bf.qc_comp_dp_en = 1;
|
|
REG_ANALOG_DPDN->bf.dn_switch_on = 1;
|
|
REG_ANALOG_DPDN->bf.dp_switch_on = 1;
|
|
REG_ANALOG_DPDN->bf.sel = 0;
|
|
REG_ANALOG_DPDN->bf.en_dcp1 = 1;
|
|
|
|
while(1)
|
|
{
|
|
app_periodic_work();
|
|
drv_watchdog_feed();
|
|
}
|
|
}
|
|
|