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.
202 lines
3.9 KiB
202 lines
3.9 KiB
4 months ago
|
/**
|
||
|
******************************************************************************
|
||
|
* @copyright Copyright (C), 2016-2022, ConvenientPower. Co., Ltd.
|
||
|
* @file comp_protection.h
|
||
|
* @version 1.0
|
||
|
* @author qing.cheng
|
||
|
* @date 2023-10-08
|
||
|
* @brief Header file of COMP_PROTECTION_H module.
|
||
|
******************************************************************************
|
||
|
*/
|
||
|
#ifndef _COMP_PROTECTION_H_
|
||
|
#define _COMP_PROTECTION_H_
|
||
|
|
||
|
|
||
|
#include "core_comm.h"
|
||
|
#include "drv_comm.h"
|
||
|
|
||
|
#include "drv_comm.h"
|
||
|
#include "config.h"
|
||
|
#include "drv_dac.h"
|
||
|
#include "comp_adc.h"
|
||
|
|
||
|
#define VIN0_UVP_TH 20000/*mV*/
|
||
|
|
||
|
#define VIN_UVP_ENABLE 0x0001
|
||
|
#define DP_WET_ENABLE 0x0002
|
||
|
#define DN_WET_ENABLE 0x0004
|
||
|
#define DPDN_WET_ENABLE 0x0006
|
||
|
#define PORT_OTP_ENABLE 0x0008
|
||
|
#define OTP_DERATE_ENABLE 0x0010
|
||
|
#define VIN_OCP_ENABLE 0x0020
|
||
|
#define VIN_OVP_ENABLE 0x0040
|
||
|
|
||
|
|
||
|
|
||
|
#define UOVP_CONDFIG 0x3A//0x2E1703A
|
||
|
|
||
|
|
||
|
#define VIN_UVP_VPT 5000
|
||
|
#define DN_OVP_VPT 4000//2374
|
||
|
#define DP_OVP_VPT DN_OVP_VPT
|
||
|
|
||
|
#define NTC_OTP_VPT 393/*393mV---110C*/
|
||
|
#define NTC_OTP_RECOVER_VPT 1056/*1056mV---80C*/
|
||
|
|
||
|
|
||
|
#define NTC_OTP_DERATE 1954
|
||
|
#define NTC_OTP_RECOVER 2625
|
||
|
|
||
|
#define OCP_VPT 0
|
||
|
|
||
|
#define NTC_CUR_5UA 0x01
|
||
|
#define NTC_CUR_20UA 0x03
|
||
|
#define NTC_CUR_100UA 0x05
|
||
|
#define NTC_CUR_OPEN 0x07
|
||
|
|
||
|
#define PRO_UVP_VPT_COEFF(x)\
|
||
|
((x * 666) >> 10)
|
||
|
|
||
|
|
||
|
#define PRO_DETECT_TIMES 5
|
||
|
|
||
|
#define OMP_ADC_GET_RT_VOL() COMP_ADC_GET_RT1_VOL()
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
SYS_VIN_UVP = 1,
|
||
|
SYS_VIN_OVP,
|
||
|
} sys_vin_errcode_e;
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
PROT_UVP = 0,
|
||
|
PROT_DP_WET,
|
||
|
PROT_DN_WET,
|
||
|
PROT_OTP,
|
||
|
PROT_DERATE,
|
||
|
PROT_OCP,
|
||
|
PROT_OVP,
|
||
|
PRO_CNT
|
||
|
} protect_type_e;
|
||
|
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
SYS_ERR_UVP = 0,
|
||
|
SYS_ERR_DP_WET,
|
||
|
SYS_ERR_DN_WET,
|
||
|
SYS_ERR_OTP,
|
||
|
SYS_ERR_OTP_DERATE,
|
||
|
SYS_ERR_OCP,
|
||
|
SYS_ERR_OVP,
|
||
|
SYS_ERR_PSRDY_FAIL,
|
||
|
SYS_ERR_RESTART,
|
||
|
SYS_ERR_GATE_UVP,
|
||
|
SYS_ERR_V2_OCP,
|
||
|
SYS_ERR_VBUS_OCP,
|
||
|
SYS_ERR_CCx_OVP,
|
||
|
SYS_ERR_VCONN_OCP,
|
||
|
SYS_NO_ERR
|
||
|
} sys_errcode_e;
|
||
|
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
PRO_EXIT = 0,
|
||
|
PRO_ENTER,
|
||
|
PRO_HANDER
|
||
|
} protect_state_e;
|
||
|
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
PRO_MONITOR = 0,
|
||
|
PRO_HICCUP
|
||
|
} protect_flag_e;
|
||
|
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
uint16_t protection_enable;
|
||
|
uint16_t hiccup_time;
|
||
|
|
||
|
uint8_t curr_expcode;
|
||
|
uint8_t protection_flag;
|
||
|
|
||
|
protect_state_e protect_state;
|
||
|
|
||
|
uint8_t otp_derate;
|
||
|
uint8_t hard_rest_flag;
|
||
|
uint8_t pro_cnt[PRO_CNT];
|
||
|
uint8_t ufcs_dn_ovp_flag;
|
||
|
|
||
|
} protection_param_s;
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
uint8_t vin_expcode;
|
||
|
uint8_t vin_uvp_cnt;
|
||
|
uint8_t pro_state;
|
||
|
protection_param_s protection_param[TYPEC_PORT_MAX];
|
||
|
|
||
|
} comp_protection_info_s;
|
||
|
|
||
|
extern comp_protection_info_s g_protection_param;
|
||
|
|
||
|
|
||
|
/*
|
||
|
* @brief comp_protection_exception_flag_set
|
||
|
* @param expcode (error code)
|
||
|
* @note NULL
|
||
|
* @retval NULL
|
||
|
*/
|
||
|
void comp_protection_exception_flag_set(uint8_t port, uint8_t expcode);
|
||
|
|
||
|
/*
|
||
|
* @brief comp_protection_init
|
||
|
* @param NULL
|
||
|
* @note OVP/UVP /OTP
|
||
|
* @retval NULL
|
||
|
*/
|
||
|
void comp_protection_init(void);
|
||
|
|
||
|
/**
|
||
|
* @brief trigger detect
|
||
|
*
|
||
|
* @param curr_value
|
||
|
* @param trigger_thrsh
|
||
|
* @param less_trigger
|
||
|
* @param times
|
||
|
* @param debounce
|
||
|
* @return uint8_t
|
||
|
*/
|
||
|
uint8_t trigger_check(uint16_t curr_value, uint16_t trigger_thrsh, uint8_t less_trigger, uint8_t *times, uint8_t debounce);
|
||
|
|
||
|
|
||
|
/*
|
||
|
* @brief comp_protection_monitor
|
||
|
* @param protection_param
|
||
|
* @note Periodic detection protection function
|
||
|
* @retval null
|
||
|
*/
|
||
|
void comp_protection_monitor(uint8_t port, protection_param_s *protection_param);
|
||
|
|
||
|
/*
|
||
|
* @brief comp_protect_exit
|
||
|
* @param protection_param
|
||
|
* @note NULL
|
||
|
* @retval NULL
|
||
|
*/
|
||
|
void comp_protection_run(uint8_t port);
|
||
|
|
||
|
/*
|
||
|
* @brief comp_protection_vin_check
|
||
|
* @param comp_protection_info
|
||
|
* @note NULL
|
||
|
* @retval NULL
|
||
|
*/
|
||
|
void comp_protection_vin_check(comp_protection_info_s *comp_protection_info);
|
||
|
#endif
|
||
|
|