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.

800 lines
16 KiB

4 months ago
#ifndef __UFCS_PE_DEFINE_H__
#define __UFCS_PE_DEFINE_H__
#include "stdint.h"
#define ufcs_VER 1
#define CTRL_MSG 0
#define DATA_MSG 1
#define VDM_MSG 2
#define UNKNOWN_MSG 7
#define DEV_SRC 1
#define DEV_SNK 2
#define DEV_CBL 3
#define UFCS_MAX_TX_SIZE 64
#define UFCS_MAX_RX_SIZE 64
#define nRetryCounter 3 // max retry
#define nMsgNumberCount 16 // max count
//#define UFCS_TIMER_COUNT 11 // max
//#define tFrameReceiveMax 600
#define tACKReceive 9//13//10
#define tSenderRespone 50 //20 30
#define tReceiverResponse 40 //20 30
#define tPowerSupply 550 //280 550
#define tCableInfoResponse 1200 //1100 1200
#define tRestartTrans 1050 //1000 1100
//#define tVerify 950 //900 1000
#define tCableTrans 1000
#define tDet4Recive 8
#define tACKTransmit 1000
#define tRetry 500
#define tWaitPing 120//120
#define tUFCSSrcRecover 1100//600
#define tPwrTransWait 25//50
#define tWatchDog 1000
#define tMsgTransDelay 3
#define tHardResetSentTimeout 10//4
#define tPCTimeout 1000
#define tFrameReceive 600//us
//len
#define L_Request 8
#define L_Sink_Information 8
#define L_Cable_Information 8
#define L_Device_Information 8
#define L_Error_Information 4
#define L_Config_Watchdog 2
#define L_Refuse 4
#define L_Verify_Request 17
#define L_Verify_Response 48
#define L_Test_Request 2
#define OUT_CAP_LEN 7
#define UFCS_BDRATE_115200 0
#define UFCS_BDRATE_57600 1
#define UFCS_BDRATE_38400 2
#define UFCS_BDRATE_19200 3
//PE source status
typedef enum
{
UFCS_PE_SRC_Startup = 0, //init
UFCS_PE_SRC_Ready,
UFCS_PE_SRC_Negotiate_Capability,
UFCS_PE_SRC_Init_Start_Cable_Detect,
UFCS_PE_SRC_Get_Cable_Info,
UFCS_PE_SRC_Send_Cable_Info,//5
UFCS_PE_SRC_Wait_End_Cable_Detect,
UFCS_PE_SRC_Send_End_Cable_Detect,
UFCS_PE_SRC_Test,
UFCS_PE_SRC_Send_Accept,
UFCS_PE_SRC_Send_Refuse,//10
UFCS_PE_SRC_Send_Output_Capabilities, //send cap
UFCS_PE_SRC_send_Supply_psrdy,
UFCS_PE_SRC_Send_Source_Information,
UFCS_PE_SRC_Send_Device_Information,
UFCS_PE_SRC_Send_Error_Information,//15
UFCS_PE_SRC_Send_Verify_Response,
UFCS_PE_SRC_Transition_to_default,
UFCS_PE_SRC_Send_Soft_Reset,
UFCS_PE_SRC_Get_Device_Info,
UFCS_PE_SRC_Send_Cable_HardReset,//20
UFCS_PE_SRC_Send_Power_Change,
UFCS_PE_SRC_Give_Vdm_Info,
UFCS_PE_SRC_Reserved,
UFCS_PE_SRC_request_information,
UFCS_PE_SRC_MAX,
} ufcs_pe_status_e;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
uint8_t msg_type: 3;
uint8_t version_1: 5;
uint8_t version_2: 1;
uint8_t msg_id: 4; //0-15 loop
uint8_t device_addr: 3;
} bit;
} ufcs_msg_header_u;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
uint8_t vdm_h: 8;
uint8_t vdm_l: 8;
} bit;
} ufcs_msg_vdm_id_u;
/***********huwei VDM message type start*************/
#define HUAWEI_UFCS_VDM_ID 0x0001
#define SOURCE_ID_LEN 4
#define SCP_B_POWER_LEN 10
typedef enum
{
UNKNOWN_HW_CTR_MSG = 0x00,
GET_SOURCE_ID,
GET_SCP_B_POWER,
} e_control_huawei_cmd;
typedef enum
{
UNKNOWN_HW_DATA_MSG = 0x00,
SOURCE_ID,
SCP_B_POWER,
} e_data_huawei_cmd;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
uint8_t vmd_cmd_l_8: 8;
uint8_t vmd_cmd_h_5: 5;
uint8_t vmd_cmd_type: 3;
} bit;
} u_ufcs_hw_vdm_info;
typedef union ufcs_hw_scp_b_power_info_u
{
uint32_t data32[2];
uint8_t byte[8];
struct
{
uint8_t output_index: 3;
uint8_t power_type: 4;
uint8_t scp_b_20v_power_h_8: 8;
uint8_t scp_b_20v_power_l_8: 8;
uint8_t scp_b_15v_power_h_8: 8;
uint8_t scp_b_15v_power_l_8: 8;
uint8_t scp_b_10v_power_h_8: 8;
uint8_t scp_b_10v_power_l_8: 8;
uint8_t scp_b_5v_power_h_8: 8;
uint8_t scp_b_5v_power_l_8: 8;
} bits;
} ufcs_hw_scp_b_power_info_u;
/***********huwei VDM message type end*************/
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
uint8_t refuse_cmd : 8;
uint8_t msg_type: 3;
uint8_t msg_id: 4;
uint8_t resived: 1;
} bit;
} ufcs_msg_refuse_header_u;
typedef struct
{
//uint8_t HardResetCounter;
int8_t MessageIDCounter;
uint8_t RetryCounter;
} ufcs_counters_s;
typedef enum
{
UFCS_ACKReceiveTimer = 0,
UFCS_SenderResponseTimer, //msg not ack like cap
UFCS_RestartTransTimer,
UFCS_CableInfoTimer,
UFCS_HDSK_DET4_Timer,
UFCS_WaitPingTimer,
UFCS_SrcRecoverTimer,
UFCS_PwrTransWaitTimer,
UFCS_WatchdogTimer,
UFCS_MsgTransDelayTimer,
UFCS_HardResetSendTimer,
UFCS_PC_Timer,
UFCS_TIMER_COUNT,
} ufcs_timer_e;
typedef struct ufcs_sent_pkt_s
{
uint8_t length;
uint8_t *ufcs_sent_buf; //[UFCS_MAX_TX_SIZE];
} ufcs_sent_pkt_s;
typedef struct ufcs_recived_pkt_s
{
// uint16_t length;
uint8_t *ufcs_recived_buf; //[UFCS_MAX_TX_SIZE];
} ufcs_recived_pkt_s;
typedef union
{
uint32_t word[2];
uint8_t byte[8];
struct
{
uint8_t V_min_step: 1;
uint8_t I_min_step: 3;
uint8_t out_mode_id: 4;
uint8_t maxV_h: 8;
uint8_t maxV_l: 8;
uint8_t minV_h: 8;
uint8_t minV_l: 8;
uint8_t maxI_h: 8;
uint8_t maxI_l: 8;
uint8_t minI: 8;
} bits;
} u_out_capabilities;
typedef struct
{
uint8_t reserved4: 4;
uint8_t outcap_mode_id: 4; //high bit
uint8_t reserved1;
uint8_t reserved2;
uint8_t reserved3;
uint8_t req_OutV_h;
uint8_t req_OutV_l;
uint8_t req_OutI_h;
uint8_t req_OutI_l; //low bit
} s_data_request;
typedef union
{
uint32_t data32;
uint8_t byte[4];
struct
{
//10mV or 10 mA
uint8_t refuse_msg_id: 4;
uint8_t reserved2: 4;
uint8_t refuse_msg_type: 3;
uint8_t reserved1: 5;
uint8_t refuse_cmd: 8;
uint8_t refuse_reason: 8;
} bits;
} u_refuse;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
uint8_t message_type: 3;
uint8_t target_addr: 3;
uint8_t volt_test_mode: 1;
uint8_t test_mode_enable: 1;
uint8_t message_id;
} bits;
} u_test_req;
typedef union
{
uint32_t data32[2];
uint8_t byte[8];
struct
{
uint8_t resrved2;
uint8_t reserved1;
uint8_t innerTemp;
uint8_t usbTemp;
uint8_t nowV_h;
uint8_t nowV_l;
uint8_t nowI_h;
uint8_t nowI_l;
} bits;
} u_pwr_information;
//typedef struct{
// //10mV or 10 mA
// uint8_t nowI_l:8;
// uint8_t nowI_h:8;
// uint8_t nowV_l:8;
// uint8_t nowV_h:8;
// uint8_t usbTemp:8;
// uint8_t innerTemp:8;
// uint8_t reserved1:8;
// uint8_t reserved2:8;
//}s_data_snk_info;
typedef union
{
uint32_t word[2];
uint8_t byte[8];
struct
{
uint8_t maxI: 8; //0~7
uint8_t maxV: 8; //8~15
uint16_t cable_R: 10; //16~31
uint16_t emarker_VID: 16; //32~47
uint16_t cable_VID: 16; //48~63
} bits;
} u_cable_info;
//for device information modify by wangxi
typedef union
{
uint32_t word[2];
uint8_t byte[8];
struct
{
uint16_t dev_SW_Ver: 16; //0~15
uint16_t dev_HW_Ver: 16; //16~31
uint16_t dev_IC_VID: 16; //32~47
uint16_t dev_VID: 16; //48~63
} bits;
} u_device_info;
typedef union
{
uint32_t word;
uint8_t byte[4];
struct
{
uint8_t OVP: 1;
uint8_t UVP: 1;
uint8_t OCP: 1;
uint8_t SCP: 1;
uint8_t USB_OTP: 1;
uint8_t IN_OTP: 1;
uint8_t CCOVP: 1;
uint8_t DN_OVP: 1;
uint8_t DP_OVP: 1;
uint8_t IN_OVP: 1;
uint8_t IN_UVP: 1;
uint8_t DrainI_Over: 1;
uint8_t IN_Power_Down: 1;
uint8_t CRC_Close_Out: 1;
uint8_t WTD_Over: 1;
uint32_t reserved: 17;
} bits;
} error_info_u;
typedef struct
{
uint8_t psw_id;
uint8_t rand_data[16];
} s_verift_request;
typedef struct
{
uint8_t rand_data[16];
uint8_t encrypted_data[32]; // 32byt
} s_verift_response;
typedef struct
{
uint8_t byte[2];
struct
{
uint8_t msg_id: 8;
uint8_t msg_type: 3;
uint8_t dev_address: 3;
uint8_t Vaccuracy_test_mode: 1;
uint8_t reserved: 1;
} bits;
} u_test_request;
typedef struct
{
uint8_t vendor_id[2]; //2byte
} s_vendor_id;
typedef struct
{
u_out_capabilities out_capabilities[OUT_CAP_LEN];
} ufcs_data_obj_s;
#pragma anon_unions
typedef union
{
uint16_t word;
struct
{
uint16_t en: 1;
uint16_t value: 15;
};
} ufcs_timer_u;
//typedef union
//{
// uint8_t byte[8];
// struct{
// uint16_t min_current; //arm 16 may batter
// uint16_t max_current;
// uint16_t min_volatage;
// uint16_t max_volatage;
// }s_power_fps_info;
//
//}u_ufcs_app_power_info;
typedef union
{
uint8_t byte[10];
uint16_t data16[5];
struct
{
uint16_t max_current;
uint16_t max_vol;
uint16_t Cable_impedance;
uint16_t vdm_id_code1;
uint16_t vdm_id_code2;
};
} emakr_info_s;
typedef union
{
uint8_t byte[17];
struct
{
uint8_t key_index;
uint8_t key_buf[16];
};
} very_request_info_s;
typedef union ufcs_power_change_capabilities_u
{
uint8_t byte[3];
struct
{
uint8_t resverd0: 4;
uint8_t index: 4;
uint8_t max_output_cur_H;
uint8_t max_output_cur_L;
} bits;
} ufcs_power_change_capabilities_u;
typedef unsigned char (*ufcs_Sha256Handle_t)(unsigned long *sha256Array, unsigned char keyChoose);
typedef union
{
uint32_t data32[2];
uint8_t byte[8];
struct
{
uint8_t vdmid_h;
uint8_t vdmid_l;
uint8_t chipid_h;
uint8_t chipid_l;
uint8_t hard_ware_h;
uint8_t hard_ware_l;
uint8_t soft_ware_h;
uint8_t soft_ware_l;
} bits;
} device_information_u;
typedef union
{
uint8_t byte;
struct
{
uint8_t main_ver: 2;
uint8_t mid_ver: 2;
uint8_t min_ver: 2;
uint8_t resverd: 2;
};
} ufcs_version_info_u;
typedef struct
{
uint8_t rcv_cmd;
uint8_t snt_cmd;
uint8_t ufcs_report_temp;
uint8_t refuse_rsn;
int8_t rcv_msg_id;
uint8_t out_cap_cnt;
uint8_t hdsk_cnt;
uint8_t vdm_data_len;
uint8_t accept_rsn;
uint8_t info_process;
ufcs_msg_vdm_id_u ufcs_msg_vdm_id;
uint8_t hdsk_dec_cnt_times;
ufcs_version_info_u ufcs_versions;
uint8_t hdsk_dec_cnt;
uint8_t rcv_uart_div;
uint8_t send_uart_div;
uint8_t ufcs_nRetryCounter;
uint8_t ufcs_msg_delay_cnt;
uint8_t ufcs_request_index;
uint16_t ufcs_adc_vol;
uint16_t ufcs_adc_cur;
uint16_t soft_ware_verision;
ufcs_msg_refuse_header_u ufcs_refuse_msg_header;
ufcs_power_change_capabilities_u power_change_cap[OUT_CAP_LEN];
//sram 8 byte
uint16_t ufcs_request_vol;
uint16_t ufcs_request_cur;
uint16_t ufcs_watchdog_time;
uint16_t source_id;
//sram 20 byte
uint16_t timeout[UFCS_TIMER_COUNT];
u_ufcs_hw_vdm_info hw_vdm_info;
ufcs_timer_u ufcs_timers[UFCS_TIMER_COUNT];
ufcs_counters_s ufcs_counters;
//sram 56 byte
ufcs_data_obj_s ufcs_data_obj;
//sram 8 byte
emakr_info_s emark_data;
//sram 4 byte
error_info_u error_info;
device_information_u device_information;
//sram 20 byte
ufcs_msg_header_u ufcs_msg_header;
very_request_info_s very_request_info;
ufcs_recived_pkt_s ufcs_recived_pkt;
//sram 12 byte resived 2 byte
ufcs_sent_pkt_s ufcs_sent_pkt;
//sram 4 byte
ufcs_Sha256Handle_t ufcs_Sha256Handle;
void (*dpdn_short_set)(uint8_t en);
uint8_t (*ufcs_bc12_is_ok)(uint8_t port);
// ufcs_hw_scp_b_power_info_u ufcs_hw_scp_b_power_info;
} ufcs_assist_s;
typedef enum
{
ufcs_Ctrl_Ping = 0x00,
ufcs_Ctrl_ACK,
ufcs_Ctrl_NCK,
ufcs_Ctrl_Accept,
ufcs_Ctrl_Soft_Reset,
ufcs_Ctrl_Power_Ready, //0x05
ufcs_Ctrl_Get_Output_Capabilities,
ufcs_Ctrl_Get_Source_Info,
ufcs_Ctrl_Get_Sink_Info,
ufcs_Ctrl_Get_Cable_Info,
ufcs_Ctrl_Get_Device_Info,
ufcs_Ctrl_Get_Error_Info,
ufcs_Ctrl_Detect_Cable_Info,
ufcs_Ctrl_Start_Cable_Detect,
ufcs_Ctrl_End_Cable_Detect,
ufcs_Ctrl_Exit_UFCS_Mode,
ufcs_Ctrl_Power_Swap
} control_cmd_e;
typedef enum
{
Not_Recognized = 0x01,
Not_Support_Cmd = 0x02,
Dev_Busy = 0x03,
Pwr_Out_Range = 0x04,
Others = 0x05,
} refuse_rsn_e;
typedef enum
{
Pwr_Meet_Range = 0x01,
Conf_Watch_Dog = 0x02,
Chg_Cbl_Det = 0x03,
Stop_Tx = 0x04,
Verify_Req = 0x05,
} accept_rsn_e;
typedef enum
{
Verify = 0x01,
} info_process_e;
typedef enum
{
Data_Output_Capabilities = 0x01,
ufcs_Data_Request,
Data_Source_Information,
Data_Sink_Information,
Data_Cable_Information,
Data_Device_Information,
Data_Error_Information,
Data_Config_Watchdog,
Data_Refuse,
Data_Verify_Request,
Data_Verify_Response,
Data_Power_change,
Data_Test_Request = 0xFF
} data_cmd_e;
//typedef enum{
// UnAttached,
// AttachWait,
// Attached,
// Error_Recovery
//}e_connect_state;
//typedef enum{
// Control_Msg_Rcv,
// Data_Msg_Rcv,
// VD_Msg_Rcv,
// Hardrst_Msg_Rcv
//}e_pe_event;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
//byte0
uint8_t pe_hardreset_recived_from_prl: 1;
uint8_t pe_softreset_recived_from_prl: 1;
uint8_t pe_packet_recived_from_prl: 1;
uint8_t pe_packet_sent_succ_from_prl: 1;
uint8_t pe_packet_sent_fail_from_prl: 1;
uint8_t hdsk_succ: 1;
uint8_t pe_send_hard_reset_from_prl: 1;
uint8_t pe_send_hard_succ_from_prl: 1;
uint8_t pe_packet_sent_discard_from_prl: 1;
uint8_t dn_over_voltage_flag: 1;
uint8_t dpdn_ov_send_hard_rst_flag: 1;
uint8_t reserved: 5;
} bits;
} ufcs_pe_event_flags_u;
typedef enum
{
ufcs_entry_status,
ufcs_exit_status,
} ufcs_pe_process_status_e;
//2 * 4 = 8
typedef struct
{
ufcs_pe_status_e pe_status;
ufcs_pe_process_status_e pe_process_status;
} ufcs_pe_status_s;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
uint8_t ACKReceive_timeout: 1;
uint8_t SenderResponse_timeout: 1;
uint8_t RestartTrans_timeout: 1;
uint8_t CableInfoResponse_timeout: 1;
uint8_t hdsk_det4_timeout: 1;
uint8_t waitping_timeout: 1;
uint8_t SrcRecover_timeout: 1;
uint8_t PowerTransWait_timeout: 1;
uint8_t Watchdog_timeout: 1;
uint8_t MsgTransDelay_timeout: 1;
uint8_t HardReset_timeout: 1;
uint8_t PC_timeout: 1;
uint8_t reserved: 4;
} bits;
} ufcs_timer_flags_u;
typedef union
{
uint16_t word;
uint8_t byte[2];
struct
{
//byte0
uint8_t Cable_Discovered_flag: 1;
uint8_t prl_relay_anck_success: 1;
uint8_t test_mode: 1;
uint8_t pwr_change_send_flag: 1;
uint8_t ufcs_Power_neg_completed: 1;
uint8_t hdsk_nego_succ: 1;
uint8_t snk_req_met: 2;
//byte1
uint8_t ufcs_reset: 2;
uint8_t resived : 6;
} bits;
} ufcs_process_flags_u; //need to change
typedef union
{
uint8_t byte;
struct
{
//byte0
uint8_t prl_rx_check_msg_id_flag: 1;
uint8_t prl_tx_check_msg_id_flag: 1;
uint8_t prl_tx_sucess_msg_id_add_flag: 1;
uint8_t pe_request_informatin_flag: 1;
uint8_t resived : 4;
} bits;
} ufcs_system_app_flags_u; //need to change
#endif