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.
304 lines
9.9 KiB
304 lines
9.9 KiB
4 months ago
|
#ifndef __PD_APP_H__
|
||
|
#define __PD_APP_H__
|
||
|
|
||
|
#include "task_pd_sys_app_define.h"
|
||
|
#include "task_typec_define.h"
|
||
|
#include "task_pd_prl_define.h"
|
||
|
#include "task_pd_pe_define.h"
|
||
|
#include "pd_chunk_define.h"
|
||
|
#define PD_EXT_PKT_MAX_SIZE 60/*PD DMA is 60 byte*/
|
||
|
#define PD_EXT_PKT_RX_MAX_SIZE 32/*PD DMA is 60 byte*/
|
||
|
|
||
|
#define PD_CHUNK_RX_MAX_SIZE 264
|
||
|
|
||
|
#define PD_SRC_CAP_MAX_NUM 7
|
||
|
#define PD_EPR_SRC_CAP_MAX_NUM 6
|
||
|
|
||
|
#define PD_MSG_HDR_L_OFFSET 0
|
||
|
#define PD_MSG_HDR_H_OFFSET 1
|
||
|
#define PD_MSG_PAYLOAD_OFFSET 2
|
||
|
#define PD_MSG_EXT_HDR_L_OFFSET 2
|
||
|
#define PD_MSG_EXT_HDR_H_OFFSET 3
|
||
|
#define PD_MSG_EXT_PAYLOAD_OFFSET 4
|
||
|
#define PD_VDM_HDR_OFFSET 2
|
||
|
#define PD_VDM_VDO_OFFSET 6
|
||
|
|
||
|
#define PD_OBJ_MAX_NUM 7
|
||
|
#define PD_VDO_MAX_NUM 6
|
||
|
|
||
|
#define PD_HDR_SIZE 2
|
||
|
#define PD_PAYLOAD_MAX_SIZE 28
|
||
|
#define PD_EXT_HDR_SIZE 2
|
||
|
#define PD_EXT_PAYLOAD_MAX_SIZE (PD_PAYLOAD_MAX_SIZE - PD_EXT_HDR_SIZE)
|
||
|
#define PD_VDM_HDR_SIZE 4
|
||
|
|
||
|
#define PD_BIST_CARRIER_MODE 0x05
|
||
|
#define PD_BIST_TEST_DATA 0x08
|
||
|
|
||
|
|
||
|
#define PD_SVID 0xFF00
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
SVDM_CMD_TYPE_REQ = 0,
|
||
|
SVDM_CMD_TYPE_ACK = 1,
|
||
|
SVDM_CMD_TYPE_NAK = 2,
|
||
|
SVDM_CMD_TYPE_BUSY = 3,
|
||
|
} svdm_cmd_type_e;
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
PWR_REQ_REJCT = 0,
|
||
|
PWR_REQ_HARD_RST = 1,
|
||
|
PWR_REQ_ACCEPT = 2,
|
||
|
} pwr_req_resp_e;
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
VDM_UNKNOWN = 0,
|
||
|
VDM_IDENTITY_REQ_SUCESS = 1,
|
||
|
VDM_SVID_REQ_SUCESS = 2,
|
||
|
VDM_DIS_MODE_REQ_SUCESS = 3,
|
||
|
VDM_DIS_ENTRY_MODE_REQ_SUCESS = 4,
|
||
|
VDM_NAK = 5,
|
||
|
} APPLE_VDM_STATE;
|
||
|
|
||
|
struct pd_param_s;
|
||
|
typedef struct pd_param_s pd_param_s;
|
||
|
typedef struct
|
||
|
{
|
||
|
uint16_t tNoResponse;
|
||
|
|
||
|
uint16_t tSrcRecover;
|
||
|
uint16_t tPPSTimeout;
|
||
|
|
||
|
uint16_t tTypeCSendSourceCap;
|
||
|
uint8_t tSenderResponse;
|
||
|
uint8_t tHardResetComplete;
|
||
|
|
||
|
uint8_t tBISTContMode;
|
||
|
uint8_t tChunkingNotSupported;
|
||
|
uint8_t tSourcePowerSupplyReady;
|
||
|
uint8_t tVDMSenderResponse;
|
||
|
uint8_t tDiscoverIdentity;
|
||
|
uint8_t tSinkTx;
|
||
|
uint8_t tPSHardReset;
|
||
|
uint8_t tVCONNSourceTimeout;
|
||
|
uint8_t tWaitSendSrcCap;
|
||
|
uint8_t tCCDebounce;
|
||
|
} pd_time_maccor_s;
|
||
|
|
||
|
|
||
|
typedef uint16_t (*hal_adc_get_vbus_t)(void);
|
||
|
typedef uint16_t (*hal_adc_get_current_t)(void);
|
||
|
typedef void (*hal_power_state_set_t)(uint8_t state);
|
||
|
typedef void (*pd_power_shut_down_t)(void);
|
||
|
typedef uint32_t (*pd_hw_get_soft_ver_t)(void);
|
||
|
|
||
|
typedef struct hw_system_info_s
|
||
|
{
|
||
|
uint8_t power_mode;
|
||
|
uint16_t adc_vbus_vol;
|
||
|
uint16_t adc_current;
|
||
|
uint16_t soft_ver;
|
||
|
|
||
|
} hw_system_info_s;
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
|
||
|
pd_sop_type_e sent_pkt_sop_type;
|
||
|
pd_sop_type_e rcv_pkt_sop_type;
|
||
|
int8_t rcv_msg_id[3];
|
||
|
uint8_t pd_spec_rev;
|
||
|
uint8_t get_manu_info_type;
|
||
|
uint8_t pd_bist_mode;
|
||
|
uint8_t pd_power_role; //0:SNK, 1:SRC
|
||
|
uint8_t pd_data_role; //0:UFP, 1:DFP
|
||
|
uint8_t ccdis_delay;
|
||
|
uint8_t tccdis_timer;
|
||
|
uint8_t vconn_src;
|
||
|
typec_attrs_s typec_attrs;
|
||
|
pd_counters_s pd_counters;
|
||
|
alert_flags_u alert_flags;
|
||
|
u_task_pd_app_power_info recv_req_pdo;
|
||
|
pd_rdos_raw_u recv_rdo;
|
||
|
pd_sent_pkt_s pd_sent_pkt;
|
||
|
pd_rcv_pkt_s pd_rcv_pkt;
|
||
|
uint16_t vdm_req_svid;
|
||
|
uint16_t vdm_svid;
|
||
|
pd_timer_s pd_timers[PD_TIMER_COUNT];
|
||
|
|
||
|
pd_msg_header_s pd_msg_header;
|
||
|
pd_ext_msg_header_s pd_ext_msg_header;
|
||
|
|
||
|
pd_svdm_header_u rcv_svdm_header;
|
||
|
pd_svdm_header_u snt_svdm_header;
|
||
|
pd_ID_Header_u rcv_svdm_id_header;
|
||
|
pd_Cert_Stat_u rcv_svdm_cert_stat;
|
||
|
pd_Product_u rcv_svdm_product;
|
||
|
pd_usvdm_header_u rcv_usvdm_header;
|
||
|
packet_attr_u pkt_attr;
|
||
|
pd_Product_Type_u rcv_svdm_product_type;
|
||
|
|
||
|
usvdm_frame_u usvdm_frame;
|
||
|
// src_cap_s src_cap;
|
||
|
src_cap_s snk_cap;
|
||
|
// pd_pdos_s snk_cap_pdo;//remove no use
|
||
|
src_send_cap_s src_cap_send;
|
||
|
|
||
|
|
||
|
pd_MIDB_u pd_midb;
|
||
|
pd_ppssdb_u pd_ppssdb;
|
||
|
pd_sdb_u pd_sdb;
|
||
|
pd_scedb_u pd_scedb;
|
||
|
pd_skedb_u pd_skedb;
|
||
|
pd_ado_u pd_alart_pdo;
|
||
|
//#ifdef APPLE_UVMD_SUPPORT
|
||
|
uint8_t apple_uvdm_state;
|
||
|
pd_apple_uvmd_u pd_apple_uvmd;/*add apple----20byte*/
|
||
|
//#endif
|
||
|
// pd_GMIDB_u pd_get_manu_info; //remove no use
|
||
|
|
||
|
hw_system_info_s hw_system_info;
|
||
|
//hw
|
||
|
pd_hw_uvdm_header_u hw_uvdm_header;
|
||
|
PD_RMDO_u pd_revision_info;
|
||
|
// uint16_t timeout[PD_TIMER_COUNT];
|
||
|
const uint16_t *timeout;
|
||
|
//#ifdef CFG_PD_LONG_PKT
|
||
|
|
||
|
// uint8_t recv_ext_msg[PD_EXT_PKT_RX_MAX_SIZE];/*recv packet buf*/ /*TODO reduce recv_ext_msg buf size to 36 */
|
||
|
uint8_t ext_msg[PD_EXT_PKT_MAX_SIZE];/*send packet buf*/
|
||
|
//#endif
|
||
|
#ifdef CFG_PD_CHUNKED_EXT_MSG
|
||
|
uint8_t expected_chunk;
|
||
|
uint16_t received_size;
|
||
|
#endif
|
||
|
|
||
|
#ifdef CFG_PD_SRC_EPR
|
||
|
uint8_t eprmd_enter_failed_data;
|
||
|
src_send_cap_s epr_source_cap;
|
||
|
#endif
|
||
|
pd_sido_u sido;
|
||
|
uint8_t apple_vdm_state;
|
||
|
uint8_t apple_charge_status;
|
||
|
uint8_t enter_mode_vdo_index;
|
||
|
uint8_t applemode_uvdm_loss_cnt;
|
||
|
|
||
|
uint8_t EPR_Mode_Entry_Ack_cnt;
|
||
|
uint8_t EPR_Mode_Entry_Ack_max;
|
||
|
} pd_assist_s;
|
||
|
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
typec_status_s pd_typec_status;
|
||
|
pd_prl_status_s pd_prl_status;
|
||
|
pd_pe_status_s pd_pe_status;
|
||
|
} s_pd_status;
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
volatile typec_flags_u pd_typec_flags;
|
||
|
volatile pd_prl_flags_u pd_prl_flag;
|
||
|
volatile pd_prl_chunk_u pd_prl_chunk_flag;
|
||
|
volatile pd_pe_event_flags_u pd_pe_event_flag;
|
||
|
volatile pd_process_flags_u pd_process_flag;
|
||
|
volatile u_task_pd_app_flags sys_app_pd_flag;/*Can be optimized*/
|
||
|
volatile pd_timer_flags_u pd_timer_flags;
|
||
|
} pd_flags_s;
|
||
|
|
||
|
|
||
|
|
||
|
typedef struct pd_callback_s
|
||
|
{
|
||
|
|
||
|
void (*pd_phy_open_vconn)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_phy_close_vconn)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_phy_set_SinkTxOk)(uint8_t port);
|
||
|
void (*pd_phy_set_SinkTxNG)(uint8_t port);
|
||
|
void (*pd_phy_init_pd)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_phy_set_data_role)(uint8_t port, bool role);
|
||
|
void (*pd_phy_close_SOP12)(uint8_t port, bool en);
|
||
|
void (*pd_prl_analyze_header)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_prl_analyze_msg)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_prl_ext_msg_header)(uint8_t port, pd_param_s* pd_param); //not uset
|
||
|
void (*pd_prl_req_cap_msg)(uint8_t port, pd_assist_s* pd_assist);
|
||
|
void (*send_pd_pkt)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*enter_bist_carrier_mode)(uint8_t port);
|
||
|
bool (*request_handler)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_get_manufacturer_info_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_manufacturer_info_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_src_status_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_src_alart_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
|
||
|
uint8_t (*pd_pwr_snk_req_evaluate)(uint8_t port, pd_param_s* pd_param);
|
||
|
|
||
|
|
||
|
bool (*pe_reset_handler_ext)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_svdm_req_msg_assemble_ext)(pd_param_s* pd_param, uint8_t obj_pos, uint8_t cmd_typ, uint8_t cmd, uint16_t svid);
|
||
|
void (*pd_pe_reset_ext)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_src_cap_ext_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
|
||
|
void (*pd_ctrl_msg_assemble_ext)(pd_ctrl_msg_type_e ctrl_msg_type, pd_param_s* pd_param);
|
||
|
void (*PE_SRC_Ready_packet_deal)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_vswap_check)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_VDM_Request_deal)(uint8_t port, pd_param_s* pd_param, svdm_cmd_e request_type, uint16_t svid);
|
||
|
|
||
|
} pd_callback_s;
|
||
|
|
||
|
typedef struct pd_callback2_s
|
||
|
{
|
||
|
void (*pd_phy_open_vbus)(uint8_t port);
|
||
|
void (*pd_phy_close_vbus)(uint8_t port);
|
||
|
bool (*pd_phy_get_cc_status)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_phy_typec_disconnect_check)(uint8_t port, pd_param_s* pd_param);
|
||
|
//pe
|
||
|
void (*pd_resp_svdm_msg_assemble)(uint8_t port, vdm_cmd_type_e cmd_type, pd_param_s* pd_param);
|
||
|
void (*pd_resp_hw_uvdm)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_prl_req_cap_msg)(uint8_t port, pd_assist_s* pd_assist);
|
||
|
void (*pd_src_cap_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
bool (*app_src_power_handler)(uint8_t port, pd_param_s* pd_param);
|
||
|
bool (*app_src_power_check)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_VDM_Attention_Request)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_OTHER_UVDM_call)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_RESVERD0_Info_call)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_APPLE_UVDM_call)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_DFP_VDM_Mode_Exit_Request_call)(uint8_t port, pd_param_s* pd_param);
|
||
|
bool (*pd_epr_cable_check)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_epr_src_cap_msg_assemble)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_prl_epr_req_msg)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*RCH_Processing_Extended_Message_callback)(uint8_t port, pd_param_s *pd_param);
|
||
|
void (*TCH_Construct_Chunked_Message_callback)(uint8_t port, pd_param_s *pd_param);
|
||
|
void (*TCH_Sending_Chunked_Message_callback)(uint8_t port, pd_param_s *pd_param);
|
||
|
void (*TCH_Wait_Chunk_Request_callback)(uint8_t port, pd_param_s *pd_param);
|
||
|
void (*PE_SRC_Evaluate_EPR_Mode_Entry_callback)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_SRC_EPR_Mode_Entry_Ack_callback)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_SRC_EPR_Mode_Discover_Cable_callback)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*PE_DFP_VCS_CBL_Send_Cable_Reset_callback)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pe_src_cable_check_callback)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_hard_reset_update_time)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_typec_status_real_time_check)(uint8_t port, pd_param_s* pd_param);
|
||
|
void (*pd_pe_soft_reset_recev_error_packet)(uint8_t port, pd_param_s* pd_param);
|
||
|
} pd_callback2_s;
|
||
|
|
||
|
struct pd_param_s
|
||
|
{
|
||
|
|
||
|
pd_flags_s pd_flags;
|
||
|
typec_status_s typec_status;
|
||
|
pd_prl_status_s pd_prl_status;
|
||
|
#ifdef CFG_PD_CHUNKED_EXT_MSG
|
||
|
pd_chunk_state_s chunk_state;
|
||
|
#endif
|
||
|
pd_pe_status_s pd_pe_status;
|
||
|
pd_assist_s pd_assist;
|
||
|
const pd_callback_s *pd_callback;
|
||
|
const pd_callback2_s *pd_callback2;
|
||
|
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif
|