29 #ifndef __CLCM_TRANSPORTPROTOCOL_H__
30 #define __CLCM_TRANSPORTPROTOCOL_H__
45 #if !defined(_CLTP_CLIENTMODE) && !defined(_CLTP_SERVERMODE)
46 #error '_CLTP_CLIENTMODE' or '_CLTP_SERVERMODE' must be defined!!
69 #define CLTP_FRAMESTART_01 (0xFE) // marker byte 1
70 #define CLTP_FRAMESTART_02 (0xA1) // Marker byte 2 with version 1
71 #define CLTP_FRAMESTART_SIZE (2)
72 #define CLTP_FRAMESTART_POS (0)
89 #define CLTP_CMD_DIR_MASK (0x8000)
90 #define CLTP_CMD_DIR_TOCLIENT (0x0000)
91 #define CLTP_CMD_DIR_TOSERVER (0x8000)
93 #define CLTP_CMD_OPCODE_MASK (0xF800)
94 #define CLTP_CMD_OPCODE_POS (11)
95 #define CLTP_CMD_PAYLOADSIZE_MASK (0x07FF)
100 #define CLTP_CMD_SETINITPARAMSACK ((0 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOCLIENT) // TPSS must send this command to confirm that it has well received init parameters from TPCS it contains 1 byte with error code
101 #define CLTP_CMD_KEEPALIVE ((1 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOCLIENT) // If TPCS is configured to accept Keep Alive, TPSS sends periodically this command
102 #define CLTP_CMD_RESETCLIENTSTATE ((2 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOCLIENT) // The server asks the client to reset its state
103 #define CLTP_CMD_CLIENTCLCMD ((3 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOCLIENT) // Command sent to CHAILink Client (Notification or Asynchronous return)
106 #define CLTP_CMD_SETINITPARAMS ((0 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOSERVER) //
107 #define CLTP_CMD_ACKKEEPALIVE ((1 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOSERVER) // Command sent when TPCS received _CLTP_CMD_KEEPALIVE from TPSS
108 #define CLTP_CMD_RESETSERVERSTATE ((2 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOSERVER) // The Client asks the server to reset its state
109 #define CLTP_CMD_SERVERCLCMD ((3 << CLTP_CMD_OPCODE_POS) | CLTP_CMD_DIR_TOSERVER) // Payload is for CHAILink Server
111 #define CLTP_CMD_SIZE (2)
112 #define CLTP_CMD_POS (CLTP_FRAMESTART_POS + CLTP_FRAMESTART_SIZE)
117 #define CLTP_INITPARAMS_KEEPALIVE_MASK 0x01
118 #define CLTP_INITPARAMS_PASSTHRU_MASK 0x02
123 #define CLTP_HEADERSIZE (CLTP_FRAMESTART_SIZE + CLTP_CMD_SIZE)
128 #define CLTP_CRC_SIZE (1)
135 #if defined(_CLTP_SERVERMODE) || defined(ENABLE_ETHERNET_PASSTHRU)
136 #define CLTPRT_PAYLOADMAXSIZE CLMSG_MESSAGEMAXSIZE
138 #define CLTPRT_PAYLOADMAXSIZE CLMSG_MESSAGESIZE
141 #define CLTPRT_FRAMEMAXSIZE (CLTPRT_PAYLOADMAXSIZE + CLTP_HEADERSIZE + CLTP_CRC_SIZE)
142 #define CLTPRT_FRAMEMINSIZE (CLMSG_MESSAGEMINSIZE + CLTP_HEADERSIZE + CLTP_CRC_SIZE)
150 CLTPCS_None = 0x0000,
151 CLTPCS_KeepAliveActive = 0x0001,
152 CLTPCS_TransportConnected = 0x0002,
153 CLTPCS_Connected = 0x0004
159 CLTPSS_None = 0x0000,
160 CLTPSS_KeepAliveActive = 0x0001,
161 CLTPSS_KeepAliveSent = 0x0002,
162 CLTPSS_Connected = 0x0004,
163 CLTPSS_EthernetEnabled = 0x0008
173 CLTPPS_ReceivingHeader,
174 CLTPPS_ReceivingPayload,
213 #define CLTP_WAITINITPARAMSACK_TIMEOUTMS 2000
216 #define CLTP_CLSKEEPALIVE_DELAYBEFORESENDING 500
218 #define CLTP_CLSKEEPALIVE_DELAYBEFORERESET 2000
220 #define CLTP_CLCKEEPALIVE_DELAYBEFORERESET 2000
229 typedef void (*CLTP_ERRORCB)(
CLTP_ErrorCode reason,
void *
const pParam);
234 typedef void (*CLTP_FRAMRECEIVEDCB)( CPBYTE * pBuffer,
CPUINT16 wSize,
void *
const pParam);
240 typedef void (*CLTP_CONNECTIONSTATECHANGEDCB)( CPBOOLEAN fConnected,
CPUINT16 wData,
void *
const pParam);
243 typedef void (*CLTP_LOCK)(CPBOOLEAN fLock,
void *
const pParam);
247 CLTP_ERRORCB pfnErrorCB;
248 CLTP_FRAMRECEIVEDCB pfnReceiveCB;
249 CLTP_CONNECTIONSTATECHANGEDCB pfnConnectionStateChangedCB;
250 #if defined(_CLTP_SERVERMODE)
263 volatile CPBYTE* pbFillingCursor;
269 #if defined(_CLTP_CLIENTMODE)
278 #if defined(_CLTP_SERVERMODE)
279 typedef struct _CLTP_CLSVariables
283 } CLTP_CLSVariables, *PCLTP_CLSVariables;
289 CPBYTE *pIncomingFrame;
290 CPBYTE *pOutgoingFrame;
292 CLTP_Callbacks Callbacks;
294 CLTP_ParserData ParserData;
295 #if defined(_CLTP_CLIENTMODE)
296 CLTP_CLCVariables CLCVariables;
297 #elif defined(_CLTP_SERVERMODE)
298 CLTP_CLSVariables CLSVariables;
300 CPBYTE arbIncomingFrameT[CLTPRT_PAYLOADMAXSIZE + 3];
301 CPBYTE arbOutgoingFrameT[CLTPRT_PAYLOADMAXSIZE + 3];
313 CLTP_ErrorCode CLTP_Init(CLTP_Working *
const pWorking, CLTP_Callbacks
const *
const pCB,
CLT_Interface const *
const pTransportInterface);
317 void CLTP_DoProcess(CLTP_Working *
const pWorking);
321 void CLTP_ProcessTransport(CLTP_Working *
const pWorking);
327 CPBOOLEAN CLTP_IsReady(CLTP_Working *
const pWorking);
330 #define CLTP_GetOutgoingBuffer(pWorking) ((pWorking)->pOutgoingFrame + CLTP_HEADERSIZE)
339 CPBOOLEAN CLTP_WritePayload(CLTP_Working *
const pWorking, CPBYTE
const *
const pbPayload,
CPUINT16 const wPayloadSize,
CPUINT16 *
const pwWritten);
341 #if defined(_CLTP_CLIENTMODE)
346 void CLTP_SetKeepAlive(CLTP_Working *
const pWorking, CPBOOLEAN
const fActive);
352 void CLTP_ResetPeerState(CLTP_Working *
const pWorking);
359 CPBYTE CLTP_ComputeCRC( CPBYTE
const *
const pData,
CPUINT16 const wDataSize );
367 #endif // __CLCM_TRANSPORTPROTOCOL_H__
Definition: CLCm_TransportProtocol.h:187
Definition: CLCm_TransportProtocol.h:189
Definition: CLCm_TransportProtocol.h:190
Definition: CLCm_TransportProtocol.h:184
Definition: CLCm_TransportProtocol.h:191
Definition: CLCm_TransportProtocol.h:185
Definition: CLCm_TransportProtocol.h:186
Definition: CLCm_TransportProtocol.h:188
CLTP_ResetCode
Transport protocol: reset codes TPCS: Transport Protocol Client Side TPSS: Transport Protocol Server ...
Definition: CLCm_TransportProtocol.h:197
Happens when a peer (TPCS or TPCC) asks to its counterpart to reset its state.
Definition: CLCm_TransportProtocol.h:200
Definition: CLCm_TransportProtocol.h:183
Happens when TPCC try to connect (INITPARAMS) while TPCS state is already connected. TPCS MUST reset its state.
Definition: CLCm_TransportProtocol.h:201
Happens when a keep alive error occurred in the TPCS or TPCC.
Definition: CLCm_TransportProtocol.h:199
CLTP_ErrorCode
Transport protocol: error codes.
Definition: CLCm_TransportProtocol.h:182
Happens when the TPCS does not receive keep alive within CLTP_CLCKEEPALIVE_DELAYBEFORERESET.
Definition: CLCm_TransportProtocol.h:198
CHAI Link Transport Interface.
Definition: CLCm_Transport.h:82
Happens when a peer (TPCS or TPCC) sent a command not understood by its counterpart. There is a sync error between TPCC and TPCS : state must be reset.
Definition: CLCm_TransportProtocol.h:202