aboutsummaryrefslogtreecommitdiff
path: root/drivers/usb/fusb302/core/PDProtocol.h
blob: 99a54e89d0ddd141af556161c6770c0aa40fce8a (plain)
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
/*
 * 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 _PDPROTOCOL_H_
#define	_PDPROTOCOL_H_

/////////////////////////////////////////////////////////////////////////////
//                              Required headers
/////////////////////////////////////////////////////////////////////////////
#include "platform.h"
#include "PD_Types.h"

#ifdef FSC_DEBUG
#include "Log.h"
#endif // FSC_DEBUG

// EXTERNS
extern ProtocolState_t          ProtocolState;                                  // State variable for Protocol Layer
extern PDTxStatus_t             PDTxStatus;                                     // Status variable for current transmission
extern FSC_BOOL                 ProtocolMsgRx;                                  // Flag to indicate if we have received a packet
extern SopType                  ProtocolMsgRxSop;                               // SOP type of message received

#ifdef FSC_DEBUG
extern StateLog                 PDStateLog;
#endif // FSC_DEBUG

// Device FIFO Token Definitions
#define TXON                    0xA1
#define SOP1                    0x12  // TODO - SOPn and SYNCn_TOKEN appear to
#define SOP2                    0x13  //        be repeats???
#define SOP3                    0x1B
#define SYNC1_TOKEN             0x12
#define SYNC2_TOKEN             0x13
#define SYNC3_TOKEN             0x1B
#define RESET1                  0x15
#define RESET2                  0x16
#define PACKSYM                 0x80
#define JAM_CRC                 0xFF
#define EOP                     0x14
#define TXOFF                   0xFE

/////////////////////////////////////////////////////////////////////////////
//                            LOCAL PROTOTYPES
/////////////////////////////////////////////////////////////////////////////
void ProtocolTick(void);
void InitializePDProtocolVariables(void);
void UpdateCapabilitiesRx(FSC_BOOL IsSourceCaps);
void USBPDProtocol(void);
void ProtocolIdle(void);
void ProtocolResetWait(void);
void ProtocolRxWait(void);
void ProtocolGetRxPacket(void);
void ProtocolTransmitMessage(void);
void ProtocolSendingMessage(void);
void ProtocolWaitForPHYResponse(void);
void ProtocolVerifyGoodCRC(void);
void ProtocolSendGoodCRC(SopType sop);
void ProtocolLoadSOP(void);
void ProtocolLoadEOP(void);
void ProtocolSendHardReset(void);
void ProtocolFlushRxFIFO(void);
void ProtocolFlushTxFIFO(void);
void ResetProtocolLayer(FSC_BOOL ResetPDLogic);
void protocolBISTRxResetCounter(void);
void protocolBISTRxTestFrame(void);
void protocolBISTRxErrorCount(void);
void protocolBISTRxInformPolicy(void);

#ifdef FSC_DEBUG
FSC_BOOL StoreUSBPDToken(FSC_BOOL transmitter, USBPD_BufferTokens_t token);
FSC_BOOL StoreUSBPDMessage(sopMainHeader_t Header, doDataObject_t* DataObject, FSC_BOOL transmitter, FSC_U8 SOPType);
FSC_U8 GetNextUSBPDMessageSize(void);
FSC_U8 GetUSBPDBufferNumBytes(void);
FSC_BOOL ClaimBufferSpace(FSC_S32 intReqSize);
void GetUSBPDStatus(FSC_U8 abytData[]);
FSC_U8 GetUSBPDStatusOverview(void);
FSC_U8 ReadUSBPDBuffer(FSC_U8* pData, FSC_U8 bytesAvail);
void SendUSBPDMessage(FSC_U8* abytData);
void SendUSBPDHardReset(void);

void manualRetriesTakeTwo(void);
void setManualRetries(FSC_U8 mode);
FSC_U8 getManualRetries(void);

#endif // FSC_DEBUG

#endif	/* _PDPROTOCOL_H_ */