1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* fusb302 usb phy driver for type-c and PD
*
* Copyright (C) 2015, 2016 Fairchild Semiconductor Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Seee the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _PDPOLICY_H_
#define _PDPOLICY_H_
/////////////////////////////////////////////////////////////////////////////
// Required headers
/////////////////////////////////////////////////////////////////////////////
#include "platform.h"
#include "PD_Types.h"
// EXTERNS
extern FSC_BOOL USBPDTxFlag; // Flag to indicate that we need to send a message (set by device policy manager)
extern sopMainHeader_t PDTransmitHeader; // Definition of the PD packet to send
#ifdef FSC_HAVE_SNK
extern sopMainHeader_t CapsHeaderSink; // Definition of the sink capabilities of the device
extern doDataObject_t CapsSink[7]; // Power object definitions of the sink capabilities of the device
extern doDataObject_t SinkRequest; // Sink request message
extern FSC_U32 SinkRequestMaxVoltage; // Maximum voltage that the sink will request
extern FSC_U32 SinkRequestMaxPower; // Maximum power the sink will request (used to calculate current as well)
extern FSC_U32 SinkRequestOpPower; // Operating power the sink will request (used to calculate current as well)
extern FSC_BOOL SinkGotoMinCompatible; // Whether the sink will respond to the GotoMin command
extern FSC_BOOL SinkUSBSuspendOperation; // Whether the sink wants to continue operation during USB suspend
extern FSC_BOOL SinkUSBCommCapable; // Whether the sink is USB communications capable
#endif // FSC_HAVE_SNK
#ifdef FSC_HAVE_SRC
extern sopMainHeader_t CapsHeaderSource; // Definition of the source capabilities of the device
extern doDataObject_t CapsSource[7]; // Power object definitions of the source capabilities of the device
#endif // FSC_HAVE_SRC
extern sopMainHeader_t CapsHeaderReceived; // Last capabilities header received (source or sink)
extern doDataObject_t PDTransmitObjects[7]; // Data objects to send
extern doDataObject_t CapsReceived[7]; // Last power objects received (source or sink)
extern doDataObject_t USBPDContract; // Current USB PD contract (request object)
#ifdef FSC_DEBUG
extern FSC_BOOL SourceCapsUpdated; // Flag to indicate whether we have updated the source caps (for the GUI)
#endif // FSC_DEBUG
extern PolicyState_t PolicyState; // State variable for Policy Engine
extern FSC_U8 PolicySubIndex; // Sub index for policy states
extern FSC_BOOL PolicyIsSource; // Flag to indicate whether we are acting as a source or a sink
extern FSC_BOOL PolicyIsDFP; // Flag to indicate whether we are acting as a UFP or DFP
extern FSC_BOOL PolicyHasContract; // Flag to indicate whether there is a contract in place
extern FSC_U32 VbusTransitionTime; // Time to wait for VBUS switch to transition
extern sopMainHeader_t PolicyRxHeader; // Header object for USB PD messages received
extern sopMainHeader_t PolicyTxHeader; // Header object for USB PD messages to send
extern doDataObject_t PolicyRxDataObj[7]; // Buffer for data objects received
extern doDataObject_t PolicyTxDataObj[7]; // Buffer for data objects to send
volatile extern FSC_U32 NoResponseTimer; // Policy engine no response timer
#ifdef FSC_HAVE_VDM
volatile extern FSC_U32 VdmTimer;
extern FSC_BOOL VdmTimerStarted;
#endif // FSC_HAVE_VDM
/////////////////////////////////////////////////////////////////////////////
// LOCAL PROTOTYPES
/////////////////////////////////////////////////////////////////////////////
void PolicyTick(void);
void InitializePDPolicyVariables(void);
void USBPDEnable(FSC_BOOL DeviceUpdate, SourceOrSink TypeCDFP);
void USBPDDisable(FSC_BOOL DeviceUpdate);
void USBPDPolicyEngine(void);
void PolicyErrorRecovery(void);
#ifdef FSC_HAVE_SRC
void PolicySourceSendHardReset(void);
void PolicySourceSoftReset(void);
void PolicySourceSendSoftReset(void);
void PolicySourceStartup(void);
void PolicySourceDiscovery(void);
void PolicySourceSendCaps(void);
void PolicySourceDisabled(void);
void PolicySourceTransitionDefault(void);
void PolicySourceNegotiateCap(void);
void PolicySourceTransitionSupply(void);
void PolicySourceCapabilityResponse(void);
void PolicySourceReady(void);
void PolicySourceGiveSourceCap(void);
void PolicySourceGetSourceCap(void);
void PolicySourceGetSinkCap(void);
void PolicySourceSendPing(void);
void PolicySourceGotoMin(void);
void PolicySourceGiveSinkCap(void);
void PolicySourceSendDRSwap(void);
void PolicySourceEvaluateDRSwap(void);
void PolicySourceSendVCONNSwap(void);
void PolicySourceSendPRSwap(void);
void PolicySourceEvaluatePRSwap(void);
void PolicySourceWaitNewCapabilities(void);
void PolicySourceEvaluateVCONNSwap(void);
#endif // FSC_HAVE_SRC
#ifdef FSC_HAVE_SNK
void PolicySinkSendHardReset(void);
void PolicySinkSoftReset(void);
void PolicySinkSendSoftReset(void);
void PolicySinkTransitionDefault(void);
void PolicySinkStartup(void);
void PolicySinkDiscovery(void);
void PolicySinkWaitCaps(void);
void PolicySinkEvaluateCaps(void);
void PolicySinkSelectCapability(void);
void PolicySinkTransitionSink(void);
void PolicySinkReady(void);
void PolicySinkGiveSinkCap(void);
void PolicySinkGetSinkCap(void);
void PolicySinkGiveSourceCap(void);
void PolicySinkGetSourceCap(void);
void PolicySinkSendDRSwap(void);
void PolicySinkEvaluateDRSwap(void);
void PolicySinkEvaluateVCONNSwap(void);
void PolicySinkSendPRSwap(void);
void PolicySinkEvaluatePRSwap(void);
#endif
void PolicyInvalidState(void);
void policyBISTReceiveMode(void);
void policyBISTFrameReceived(void);
void policyBISTCarrierMode2(void);
void policyBISTTestData(void);
FSC_BOOL PolicySendHardReset(PolicyState_t nextState, FSC_U32 delay);
FSC_U8 PolicySendCommand(FSC_U8 Command, PolicyState_t nextState, FSC_U8 subIndex);
FSC_U8 PolicySendCommandNoReset(FSC_U8 Command, PolicyState_t nextState, FSC_U8 subIndex);
FSC_U8 PolicySendData(FSC_U8 MessageType, FSC_U8 NumDataObjects, doDataObject_t* DataObjects, PolicyState_t nextState, FSC_U8 subIndex, SopType sop);
FSC_U8 PolicySendDataNoReset(FSC_U8 MessageType, FSC_U8 NumDataObjects, doDataObject_t* DataObjects, PolicyState_t nextState, FSC_U8 subIndex);
void UpdateCapabilitiesRx(FSC_BOOL IsSourceCaps);
void processDMTBIST(void);
#ifdef FSC_HAVE_VDM
// shim functions for VDM code
void InitializeVdmManager(void);
void convertAndProcessVdmMessage(SopType sop);
void sendVdmMessage(SopType sop, FSC_U32 * arr, FSC_U32 length, PolicyState_t next_ps);
void doVdmCommand(void);
void doDiscoverIdentity(void);
void doDiscoverSvids(void);
void PolicyGiveVdm(void);
void PolicyVdm(void);
void autoVdmDiscovery(void);
#endif // FSC_HAVE_VDM
SopType TokenToSopType(FSC_U8 data);
#ifdef FSC_DEBUG
#ifdef FSC_HAVE_SRC
void WriteSourceCapabilities(FSC_U8* abytData);
void ReadSourceCapabilities(FSC_U8* abytData);
#endif // FSC_HAVE_SRC
#ifdef FSC_HAVE_SNK
void WriteSinkCapabilities(FSC_U8* abytData);
void ReadSinkCapabilities(FSC_U8* abytData);
void WriteSinkRequestSettings(FSC_U8* abytData);
void ReadSinkRequestSettings(FSC_U8* abytData);
#endif // FSC_HAVE_SNK
void EnableUSBPD(void);
void DisableUSBPD(void);
FSC_BOOL GetPDStateLog(FSC_U8 * data);
void ProcessReadPDStateLog(FSC_U8* MsgBuffer, FSC_U8* retBuffer);
void ProcessPDBufferRead(FSC_U8* MsgBuffer, FSC_U8* retBuffer);
#endif // FSC_DEBUG
void SetVbusTransitionTime(FSC_U32 time_ms);
#endif /* _PDPOLICY_H_ */
|