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.
629 lines
13 KiB
629 lines
13 KiB
#ifndef TASK_SCP_APP_H
|
|
#define TASK_SCP_APP_H
|
|
|
|
#include "task_scp_prl.h"
|
|
#include "comp_config.h"
|
|
|
|
|
|
#define REG_FUNC_ENTRY(addr, func) { (addr), (func) }
|
|
#define REG_ATTR(reg, attr) (attr)
|
|
|
|
|
|
#define AOUT_VOL(x) (((x) * 100))
|
|
#define AOUT_CUR(x) ((((x) * 100)))
|
|
|
|
#define COMMUN_VALUE(x) ((x * 500))
|
|
|
|
#define LIMIT_VALUE(x,y) ((((x) << 8) | (y)))
|
|
|
|
#define LINIT_H8BIT(x) (((x) >> 8))
|
|
#define LINIT_L8BIT(x) (((x) & 0xff))
|
|
|
|
#define BIAS_VALUE(x,y) ((((x) << 8) | (y)) & 0x7fff)
|
|
|
|
#define STEP_VOL(x) (((x) & 0x7f))
|
|
#define STEP_CUR(x) (((x) & 0x7f))
|
|
|
|
#define VSSET_VALUE(x) (((x) * 10) + 3000)
|
|
#define ISSET_VALUE(x) (((x) * 50))
|
|
|
|
//#define GET_ADC_VBUS() 1
|
|
//#define GET_ADC_CURRT() 1
|
|
|
|
//#define VOLTAGE_3P3V 3300
|
|
//#define VOLTAGE_3P4V 3400
|
|
//#define VOLTAGE_5V 5000
|
|
//#define VOLTAGE_5P5V 5500
|
|
//#define VOLTAGE_21V 21000
|
|
|
|
//#define CURRENT_0P2A 200
|
|
//#define CURRENT_0P3A 300
|
|
//#define CURRENT_3A 3000
|
|
//#define CURRENT_3P2A 3200
|
|
//#define CURRENT_4P2A 4200
|
|
|
|
//#define DELAY_200MS 200
|
|
|
|
|
|
struct scp_param_s;
|
|
typedef struct scp_param_s scp_param_s;
|
|
|
|
|
|
|
|
typedef union scp_app_timer_u
|
|
{
|
|
uint32_t data32;
|
|
uint8_t byte[4];
|
|
|
|
struct
|
|
{
|
|
uint8_t dp_en : 1;
|
|
|
|
uint8_t communication_en : 1;
|
|
|
|
uint8_t reserve: 6;
|
|
|
|
uint8_t dp_value : 8;
|
|
|
|
uint16_t communication_value : 16;
|
|
|
|
} bf;
|
|
|
|
} scp_app_timer_u;
|
|
|
|
// uint8_t scp_vol_update : 1;
|
|
// uint8_t scp_cur_update : 1;
|
|
|
|
typedef union scp_app_flag_u
|
|
{
|
|
uint8_t data16;
|
|
uint8_t byte[2];
|
|
|
|
struct
|
|
{
|
|
uint8_t dp_no_detect : 1;
|
|
uint8_t scp_reset : 2;
|
|
uint8_t scp_b_class : 1;
|
|
|
|
uint8_t scp_disable_otp : 1;
|
|
uint8_t scp_b_mode_voltage_reflection : 1;
|
|
uint8_t scp_a_mode_voltage_reflection : 1;
|
|
uint8_t vout_adc_update_dis : 1;
|
|
|
|
uint8_t iout_adc_update_dis : 1;
|
|
uint8_t reverd: 7;
|
|
|
|
} bf;
|
|
|
|
} scp_app_flag_u;
|
|
|
|
|
|
typedef struct scp_app_passist_s
|
|
{
|
|
scp_app_timer_u scp_app_timer;
|
|
scp_app_flag_u scp_app_flag;
|
|
uint8_t temperature;
|
|
uint8_t derating_ratio;
|
|
uint8_t scp_communication_value;
|
|
|
|
uint16_t a_vol;
|
|
uint16_t a_cur;
|
|
|
|
uint16_t b_vol;
|
|
uint16_t b_cur;
|
|
|
|
uint16_t vol;
|
|
uint16_t cur;
|
|
|
|
uint16_t limit_cur;
|
|
uint16_t limit_vol;
|
|
|
|
uint16_t limit_def_cur;
|
|
uint16_t limit_def_vol;
|
|
|
|
uint16_t vol_max;
|
|
uint16_t cur_max;
|
|
|
|
uint16_t vol_min;
|
|
uint16_t cur_min;
|
|
|
|
uint16_t scp_adc_vol;
|
|
uint16_t scp_adc_cur;
|
|
|
|
unsigned long sha_arry[8];
|
|
|
|
const uint8_t* reg_value;
|
|
const uint8_t* reg_attr;
|
|
|
|
} scp_app_passist_s;
|
|
|
|
|
|
typedef struct scp_app_callback_s
|
|
{
|
|
unsigned char (*Sha256Handle)(unsigned long *sha256Array, unsigned char keyChoose);
|
|
void (*open_noms)(uint8_t port);
|
|
void (*close_noms)(uint8_t port);
|
|
void (*scp_afc_identify)(uint8_t port, scp_param_s *scp_param);
|
|
void (*capabiloties_features)(uint8_t port, scp_prl_s *scp_prl_passist);
|
|
void (*Intercepting_hook_functions)(uint8_t port, scp_param_s *scp_param);
|
|
void (*scp_register_value_to_encryption_arry)(uint8_t port, scp_param_s *scp_param);
|
|
void (*scp_encryption_arry_to_scp_register_value)(uint8_t port, scp_param_s *scp_param);
|
|
void (*scp_exit_scp_mode)(uint8_t port, scp_param_s *scp_param);
|
|
void (*scp_disable_pd_func)(uint8_t port, uint8_t reg_val);
|
|
|
|
} scp_app_callback_s;
|
|
|
|
|
|
struct scp_param_s
|
|
{
|
|
scp_app_passist_s scp_app_passist;
|
|
scp_prl_s scp_prl_passist;
|
|
const scp_app_callback_s *callback;
|
|
};
|
|
|
|
typedef void(*app_fb_action)(scp_param_s *scp_param);
|
|
|
|
typedef struct reg_func_entry_s
|
|
{
|
|
uint8_t addr;
|
|
void (*func)(uint8_t port, scp_param_s *scp_param);
|
|
} reg_func_entry_s;
|
|
|
|
typedef struct reg_attr_s
|
|
{
|
|
uint8_t attr0 : 4;
|
|
uint8_t attr1 : 4;
|
|
} reg_attr_s;
|
|
|
|
|
|
/*
|
|
* @brief scp_register_attr_rom_list
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_register_attr_rom_list(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_register_value_init
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_register_value_init(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief scp_register_value_encry_to_reset---Exit the encrypted reset register
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_register_value_encry_to_reset(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_register_value_reset
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_register_value_reset(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_register_attr_init---Register property initialization
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_encry_register_attr_reset(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_app_normal--
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_app_normal_process(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief scp_dp_protection
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_dp_protection(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_ctrl_byte0---register 0xa0 function
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_ctrl_byte0_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
|
|
/*
|
|
* @brief scp_reg_output_control---register 0x2b function
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_output_control_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_ctrl_byte1---register 0xa1 function
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_ctrl_byte1_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_detection_communication_timeout
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_detection_communication_timeout(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief scp_reg_s_fun1---register 0xcf function disable
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_s_fun1_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief scp_reg_s_fun2---register 0xcf function disable
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_s_fun2_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_limit_set
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_limit_set(uint8_t port, uint8_t reg_addr, uint8_t vol_cur, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_limit_set----register 0xb0/b1 function
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_vset_boundary_l_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief scp_reg_limit_set----register 0xb2/0xb3 function
|
|
* @param scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_iset_boundary_l_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief pow_int
|
|
* @param x
|
|
* @param y
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
uint16_t pow_int(uint8_t x, uint8_t y);
|
|
|
|
|
|
/*
|
|
* @brief get_scp_bias_max
|
|
* @param addr
|
|
* @param *scp_prl_passist
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
uint16_t get_scp_bias_max(uint8_t port, uint8_t addr, scp_prl_s *scp_prl_passist);
|
|
|
|
/*
|
|
* @brief scp_reg_vset_offset----register 0xbd function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_vset_offset_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief step_base----Register magnification resolution
|
|
* @param *scp_param
|
|
* @param reg
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
uint16_t step_base(uint8_t port, scp_param_s *scp_param, uint8_t reg);
|
|
|
|
|
|
/*
|
|
* @brief step_base----register 0xcc function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void step_vset_offset_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_iset_offset----register 0xbf function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_iset_offset_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief step_iset_offset----register 0xcd function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void step_iset_offset_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_vset_l----register 0xb9 function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_vset_l_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_vsset----register 0xca function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_vsset_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_vsset----register 0xbb function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_iset_l_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reg_isset----register 0xcb function
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reg_isset_write(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
void fcp_sstat_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void fcp_adapter_status_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_discrete_capabiloties_features_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_status_byte0_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_status_byte1_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_status_byte2_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_vout_h_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_vout_l_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_iout_h_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_iout_l_read(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
|
|
|
|
/*
|
|
* @brief update_adc_value
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void update_adc_value(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_temperature_report
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_temperature_report(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief scp_derating_update
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_derating_update(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_update_cccv_status
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_update_cccv_status(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
|
|
|
|
/*
|
|
* @brief scp_app_encyption
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_app_encyption_process(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief set_register_attr
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void set_register_attr(uint8_t port, uint8_t address, uint8_t attr, scp_prl_s *scp_prl_passist);
|
|
|
|
/*
|
|
* @brief set_register_value
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void set_register_value(uint8_t port, uint8_t address, uint8_t value, scp_prl_s *scp_prl_passist);
|
|
|
|
/*
|
|
* @brief random_number
|
|
* @param NULL
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
uint8_t random_number(void);
|
|
|
|
/*
|
|
* @brief multiplex_register
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void multiplex_register(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_register_value_to_encryption_arry
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_register_value_to_encryption_arry(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_encryption_arry_to_scp_register_value
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_encryption_arry_to_scp_register_value(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief hw_sha256_calc
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void hw_sha256_calc(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief encry_exit
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void encry_exit(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_parity_crc_error_reset
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_parity_crc_error_reset(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_app_run
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_app_run(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_prl_app_reset
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_prl_app_reset(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_protocol_run
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_protocol_run(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_timer_func
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_timer_func(uint8_t port, scp_param_s *scp_param);
|
|
|
|
/*
|
|
* @brief scp_reset_default
|
|
* @param *scp_param
|
|
* @param mode
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_reset_default(uint8_t port, scp_param_s *scp_param, uint8_t mode);
|
|
/*
|
|
* @brief process_reg
|
|
* @param *scp_param
|
|
* @param *tb
|
|
* @param tb_size
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void process_reg(uint8_t port, scp_param_s *scp_param, const struct reg_func_entry_s*tb, uint8_t tb_size);
|
|
/*
|
|
* @brief scp_app_process_reg_rd
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_app_process_reg_rd(uint8_t port, scp_param_s *scp_param);
|
|
/*
|
|
* @brief scp_app_process_reg_wr
|
|
* @param *scp_param
|
|
* @note
|
|
* @retval NULL
|
|
*/
|
|
void scp_app_process_reg_wr(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void fcp_set_vi(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_set_volt(uint8_t port, scp_param_s *scp_param);
|
|
|
|
void scp_set_cur(uint8_t port, scp_param_s *scp_param);
|
|
|
|
|
|
/*
|
|
* @brief afc_packet_reply
|
|
* @param *scp_prl_passist
|
|
* @param *afc_support_power
|
|
* @param afc_cnt
|
|
* @note
|
|
* @retval request power meet(1:meet,not meet)
|
|
*/
|
|
bool afc_packet_reply(uint8_t port, scp_prl_s *scp_prl_passist, uint8_t *afc_support_power, uint8_t afc_cnt);
|
|
|
|
|
|
#endif
|
|
|