Debian Codegraph @

drivers/dahdi/oct612x/octdeviceapi/oct6100api/oct6100_api/oct6100_remote_debug.c

raw symbols ◀ ▶ SCIP
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2
3 File: oct6100_remote_debug.c
4
5 Copyright (c) 2001-2007 Octasic Inc.
6
7 Description:
8
9 This file contains the routines used for remote debugging.
10
11 This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API is
12 free software; you can redistribute it and/or modify it under the terms of
13 the GNU General Public License as published by the Free Software Foundation;
14 either version 2 of the License, or (at your option) any later version.
15
16 The OCT6100 GPL API is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with the OCT6100 GPL API; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 $Octasic_Release: OCT612xAPI-01.00-PR49 $
26
27 $Octasic_Revision: 35 $
28
29 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
30
31
32 /***************************** INCLUDE FILES *******************************/
33
34 #include "octdef.h"
35
36 #include "oct6100api/oct6100_defines.h"
37 #include "oct6100api/oct6100_errors.h"
38
39 #include "apilib/octapi_bt0.h"
40 #include "apilib/octapi_largmath.h"
41
42 #include "oct6100api/oct6100_apiud.h"
43 #include "oct6100api/oct6100_tlv_inst.h"
44 #include "oct6100api/oct6100_chip_open_inst.h"
45 #include "oct6100api/oct6100_chip_stats_inst.h"
46 #include "oct6100api/oct6100_interrupts_inst.h"
47 #include "oct6100api/oct6100_channel_inst.h"
48 #include "oct6100api/oct6100_remote_debug_inst.h"
49 #include "oct6100api/oct6100_debug_inst.h"
50 #include "oct6100api/oct6100_api_inst.h"
51
52 #include "oct6100api/oct6100_interrupts_pub.h"
53 #include "oct6100api/oct6100_chip_open_pub.h"
54 #include "oct6100api/oct6100_debug_pub.h"
55 #include "oct6100api/oct6100_channel_pub.h"
56 #include "oct6100api/oct6100_remote_debug_pub.h"
57
58 #include "octrpc/rpc_protocol.h"
59 #include "octrpc/oct6100_rpc_protocol.h"
60
61 #include "oct6100_miscellaneous_priv.h"
62 #include "oct6100_chip_open_priv.h"
63 #include "oct6100_channel_priv.h"
64 #include "oct6100_debug_priv.h"
65 #include "oct6100_remote_debug_priv.h"
66
67 /**************************** PUBLIC FUNCTIONS *****************************/
68
69 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
70
71 Function: Oct6100RemoteDebug
72
73 Description: This function interprets the remote debugging packets received
74 by the user’s software. Commands contained in the packet are
75 executed by the API. In addition, a response packet is
76 constructed and returned by the function. It is the responsibility
77 of the user’s software to transmit the response packet back to
78 the source of the debugging packet.
79
80 -------------------------------------------------------------------------------
81 | Argument | Description
82 -------------------------------------------------------------------------------
83 f_pApiInstance Pointer to API instance. This memory is used to keep
84 the present state of the chip and all its resources.
85
86 f_pRemoteDebug Pointer to a remote debug structure.
87
88 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
89 #if !SKIP_Oct6100RemoteDebugDef
90 UINT32 Oct6100RemoteDebugDef(
91 tPOCT6100_REMOTE_DEBUG f_pRemoteDebug )
92 {
93 f_pRemoteDebug->pulReceivedPktPayload = NULL;
94 f_pRemoteDebug->ulReceivedPktLength = 0;
95 f_pRemoteDebug->pulResponsePktPayload = NULL;
96 f_pRemoteDebug->ulMaxResponsePktLength = 0;
97 f_pRemoteDebug->ulResponsePktLength = 0;
98
99 return cOCT6100_ERR_OK;
100 }
101 #endif
102
103 #if !SKIP_Oct6100RemoteDebug
104 UINT32 Oct6100RemoteDebug(
105 tPOCT6100_INSTANCE_API f_pApiInstance,
106 tPOCT6100_REMOTE_DEBUG f_pRemoteDebug )
107 {
108 tPOCTRPC_OGRDTP_HEADER pOgrdtpHeader;
109 tPOCTRPC_INTERFACE_HEADER pInterfaceHeader;
110 tPOCTRPC_COMMAND_HEADER pRspCmndHeader;
111 PUINT32 pulRcvPktPayload;
112 PUINT32 pulRspPktPayload;
113 UINT32 ulPktLengthDword;
114 UINT32 ulSessionIndex;
115 UINT32 ulChecksum;
116 UINT32 ulResult;
117
118 /* Check for errors. */
119 if ( f_pRemoteDebug->pulReceivedPktPayload == NULL )
120 return cOCT6100_ERR_REMOTEDEBUG_RECEIVED_PKT_PAYLOAD;
121 if ( f_pRemoteDebug->pulResponsePktPayload == NULL )
122 return cOCT6100_ERR_REMOTEDEBUG_RESPONSE_PKT_PAYLOAD;
123 if ( f_pRemoteDebug->ulReceivedPktLength < cOCTRPC_MIN_PACKET_BYTE_LENGTH )
124 return cOCT6100_ERR_REMOTEDEBUG_RECEIVED_PKT_LENGTH;
125 if ( f_pRemoteDebug->ulReceivedPktLength > cOCTRPC_MAX_PACKET_BYTE_LENGTH )
126 return cOCT6100_ERR_REMOTEDEBUG_RECEIVED_PKT_LENGTH;
127 if ( f_pRemoteDebug->ulMaxResponsePktLength < f_pRemoteDebug->ulReceivedPktLength )
128 return cOCT6100_ERR_REMOTEDEBUG_RESPONSE_PKT_LENGTH;
129 if ( (f_pRemoteDebug->ulReceivedPktLength % 4) != 0 )
130 return cOCT6100_ERR_REMOTEDEBUG_RECEIVED_PKT_LENGTH;
131 if ( f_pApiInstance->pSharedInfo->ChipConfig.usMaxRemoteDebugSessions == 0 )
132 return cOCT6100_ERR_REMOTEDEBUG_DISABLED;
133
134 /* Set response length as received length. */
135 f_pRemoteDebug->ulResponsePktLength = f_pRemoteDebug->ulReceivedPktLength;
136
137 /* Typecast the packet payload to local pointers. */
138 pOgrdtpHeader = ( tPOCTRPC_OGRDTP_HEADER )f_pRemoteDebug->pulReceivedPktPayload;
139 pInterfaceHeader = ( tPOCTRPC_INTERFACE_HEADER )(f_pRemoteDebug->pulReceivedPktPayload + (sizeof( tOCTRPC_OGRDTP_HEADER ) / 4));
140
141 /* Get local pointer to received and response packet payloads. */
142 pulRcvPktPayload = f_pRemoteDebug->pulReceivedPktPayload;
143 pulRspPktPayload = f_pRemoteDebug->pulResponsePktPayload;
144
145 /* Get the length of the packet in UINT32s. */
146 ulPktLengthDword = f_pRemoteDebug->ulReceivedPktLength / 4;
147
148 /* Check the endian detection field to determine if the payload must be */
149 /* swapped to account for different endian formats. */
150 ulResult = Oct6100ApiCheckEndianDetectField( pOgrdtpHeader, ulPktLengthDword );
151 if ( ulResult != cOCT6100_ERR_OK )
152 return ulResult;
153
154 /* Check the packet's length. */
155 if ( pOgrdtpHeader->ulPktByteSize != f_pRemoteDebug->ulReceivedPktLength )
156 return cOCT6100_ERR_REMOTEDEBUG_RECEIVED_PKT_LENGTH;
157
158 /* Perform the sum of each word in the packet and compare to checksum. */
159 Oct6100ApiCalculateChecksum( pulRcvPktPayload, ulPktLengthDword, &ulChecksum );
160 if ( ulChecksum != pOgrdtpHeader->ulChecksum )
161 return cOCT6100_ERR_REMOTEDEBUG_CHECKSUM;
162
163 /* Check if the packet's session number has a corresponding entry in the API table.
164 If not then close an entry which has timed out, and allocate the entry to the
165 new session number. */
166 ulResult = Oct6100ApiCheckSessionNum( f_pApiInstance, pOgrdtpHeader, &ulSessionIndex );
167 if ( ulResult == cOCT6100_ERR_REMOTEDEBUG_ALL_SESSIONS_OPEN )
168 {
169 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, FALSE, FALSE, FALSE, cOCT6100_INVALID_VALUE, cOCTRPC_RDBGERR_ALL_SESSIONS_OPEN, cOCT6100_INVALID_VALUE, ulChecksum );
170 return cOCT6100_ERR_OK;
171 }
172 else if ( ulResult == cOCT6100_ERR_REMOTEDEBUG_TRANSACTION_ANSWERED )
173 {
174 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, TRUE, FALSE, FALSE, FALSE, ulSessionIndex, cOCT6100_INVALID_VALUE, cOCT6100_INVALID_VALUE, ulChecksum );
175 return cOCT6100_ERR_OK;
176 }
177 else if ( ulResult != cOCT6100_ERR_OK )
178 {
179 return ulResult;
180 }
181
182 /* Check if an echo packet. If so then there's no need to check the rest of
183 the packet. Simply copy the packet back to the output buffer, enter the
184 protocol number supported by this API compilation, and recalculate the
185 checksum. If the packet is not an echo packet and the protocol version
186 does not correspond to this compiled version then return the supported
187 protocol version. */
188 if ( pOgrdtpHeader->ulRpcProtocolNum == cOCTRPC_ECHO_PROTOCOL )
189 {
190 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, TRUE, FALSE, FALSE, ulSessionIndex, cOCT6100_INVALID_VALUE, cOCT6100_INVALID_VALUE, ulChecksum );
191 return cOCT6100_ERR_OK;
192 }
193 else if ( pOgrdtpHeader->ulRpcProtocolNum != cOCTRPC_PROTOCOL_V1_1 )
194 {
195 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, TRUE, FALSE, FALSE, ulSessionIndex, cOCTRPC_RDBGERR_PROTOCOL_NUMBER, cOCT6100_INVALID_VALUE, ulChecksum );
196 return cOCT6100_ERR_OK;
197 }
198 else if ( f_pRemoteDebug->ulReceivedPktLength <= cOCTRPC_FIRST_COMMAND_BYTE_OFFSET )
199 {
200 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, FALSE, FALSE, FALSE, ulSessionIndex, cOCTRPC_RDBGERR_NO_COMMAND_HEADER, cOCT6100_INVALID_VALUE, ulChecksum );
201 return cOCT6100_ERR_OK;
202 }
203
204
205 /* Check the packet's RPC interface type and version. If either does not match then
206 return the packet with the supported interface type and version of this compilation. */
207 if ( pInterfaceHeader->ulInterfaceVersion != cOCTRPC_INTERFACE_VERSION )
208 {
209 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, FALSE, TRUE, TRUE, ulSessionIndex, cOCTRPC_RDBGERR_INTERFACE_VERSION, cOCT6100_INVALID_VALUE, ulChecksum );
210 return cOCT6100_ERR_OK;
211 }
212 if ( pInterfaceHeader->ulInterfaceType != cOCTRPC_OCT6100_INTERFACE )
213 {
214 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, FALSE, TRUE, TRUE, ulSessionIndex, cOCTRPC_RDBGERR_INTERFACE_TYPE, cOCT6100_INVALID_VALUE, ulChecksum );
215 return cOCT6100_ERR_OK;
216 }
217
218 /* Check each command header to make sure the indicated command and length agree. If
219 there is an error in the packet's commands then the response packet will be
220 constructed by the function. */
221 ulResult = Oct6100ApiCheckPktCommands( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulSessionIndex, ulPktLengthDword, ulChecksum );
222 if ( ulResult == cOCT6100_ERR_REMOTE_DEBUG_PARSING_ERROR )
223 return cOCT6100_ERR_OK;
224
225 /* The packet's fields are valid. Each command must now be extracted and executed. */
226 Oct6100ApiExecutePktCommands( f_pApiInstance, pulRcvPktPayload, ulPktLengthDword );
227
228 pRspCmndHeader = ( tPOCTRPC_COMMAND_HEADER )(( PUINT32 )pulRspPktPayload + ((sizeof( tOCTRPC_OGRDTP_HEADER ) + sizeof( tOCTRPC_INTERFACE_HEADER )) / 4));
229
230 /* Verify if the new method of using the protocol is the selected case. */
231 /* All commands have been executed. Calculate the packet's new checksum
232 and copy the packet to user provided buffer for response packet. */
233 Oct6100ApiCalculateChecksum( pulRcvPktPayload, ulPktLengthDword, &ulChecksum );
234
235 /* Send response packet. */
236 Oct6100ApiFormResponsePkt( f_pApiInstance, pulRcvPktPayload, pulRspPktPayload, ulPktLengthDword, FALSE, FALSE, FALSE, FALSE, ulSessionIndex, cOCTRPC_RDBGERR_OK, cOCT6100_INVALID_VALUE, ulChecksum );
237
238 return cOCT6100_ERR_OK;
239 }
240 #endif
241
242
243 /**************************** PRIVATE FUNCTIONS ****************************/
244
245
246 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
247
248 Function: Oct6100ApiGetRemoteDebugSwSizes
249
250 Description: Gets the sizes of all portions of the API instance pertinent
251 to the management of remote debugging.
252
253 -------------------------------------------------------------------------------
254 | Argument | Description
255 -------------------------------------------------------------------------------
256 f_pChipOpen Pointer to chip configuration struct.
257 f_pInstSizes Pointer to struct containing instance sizes.
258
259 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
260 #if !SKIP_Oct6100ApiGetRemoteDebugSwSizes
261 UINT32 Oct6100ApiGetRemoteDebugSwSizes(
262 IN tPOCT6100_CHIP_OPEN f_pChipOpen,
263 OUT tPOCT6100_API_INSTANCE_SIZES f_pInstSizes )
264 {
265 UINT32 ulTempVar;
266 UINT32 ulResult;
267
268 /* Memory needed for remote debugging sessions. */
269 if ( f_pChipOpen->ulMaxRemoteDebugSessions > 0 )
270 {
271 f_pInstSizes->ulRemoteDebugList = f_pChipOpen->ulMaxRemoteDebugSessions * sizeof( tOCT6100_API_REMOTE_DEBUG_SESSION );
272
273 ulResult = octapi_bt0_get_size( f_pChipOpen->ulMaxRemoteDebugSessions, 4, 4, &f_pInstSizes->ulRemoteDebugTree );
274 if ( ulResult != cOCT6100_ERR_OK )
275 return cOCT6100_ERR_FATAL_41;
276
277 f_pInstSizes->ulRemoteDebugPktCache = cOCTRPC_MAX_PACKET_BYTE_LENGTH * f_pChipOpen->ulMaxRemoteDebugSessions;
278 f_pInstSizes->ulRemoteDebugDataBuf = cOCTRPC_MAX_PACKET_BYTE_LENGTH * 4;
279 }
280 else
281 {
282 f_pInstSizes->ulRemoteDebugList = 0;
283 f_pInstSizes->ulRemoteDebugTree = 0;
284 f_pInstSizes->ulRemoteDebugPktCache = 0;
285 f_pInstSizes->ulRemoteDebugDataBuf = 0;
286 }
287
288 /* Round off the size. */
289 mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulRemoteDebugList, ulTempVar )
290 mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulRemoteDebugTree, ulTempVar )
291 mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulRemoteDebugPktCache, ulTempVar )
292 mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulRemoteDebugDataBuf, ulTempVar )
293
294 return cOCT6100_ERR_OK;
295 }
296 #endif
297
298
299 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
300
301 Function: Oct6100ApiRemoteDebuggingSwInit
302
303 Description: Initializes all portions of the API instance associated to
304 remote debugging.
305
306 -------------------------------------------------------------------------------
307 | Argument | Description
308 -------------------------------------------------------------------------------
309 f_pApiInstance Pointer to API instance. This memory is used to keep
310 the present state of the chip and all its resources.
311
312 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
313 #if !SKIP_Oct6100ApiRemoteDebuggingSwInit
314 UINT32 Oct6100ApiRemoteDebuggingSwInit(
315 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance )
316 {
317 tPOCT6100_SHARED_INFO pSharedInfo;
318 PVOID pSessionTree;
319 UINT32 ulResult;
320
321 /* Get local pointer(s). */
322 pSharedInfo = f_pApiInstance->pSharedInfo;
323
324 pSharedInfo->RemoteDebugInfo.ulNumSessionsOpen = 0;
325 pSharedInfo->RemoteDebugInfo.ulMaxSessionsOpen = pSharedInfo->ChipConfig.usMaxRemoteDebugSessions;
326 pSharedInfo->RemoteDebugInfo.ulSessionListHead = cOCT6100_INVALID_VALUE;
327 pSharedInfo->RemoteDebugInfo.ulSessionListTail = cOCT6100_INVALID_VALUE;
328
329 if ( pSharedInfo->ChipConfig.usMaxRemoteDebugSessions > 0 )
330 {
331 mOCT6100_GET_REMOTE_DEBUG_TREE_PNT( pSharedInfo, pSessionTree )
332
333 ulResult = octapi_bt0_init( ( ( PVOID* )&pSessionTree ), pSharedInfo->ChipConfig.usMaxRemoteDebugSessions, 4, 4 );
334 if ( ulResult != cOCT6100_ERR_OK )
335 return cOCT6100_ERR_FATAL_42;
336 }
337
338 return cOCT6100_ERR_OK;
339 }
340 #endif
341
342
343 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
344
345 Function: Oct6100ApiCheckEndianDetectField
346
347 Description: Checks the endian field of a packet and performs a swap of
348 the packet data if deemed necessary.
349
350 -------------------------------------------------------------------------------
351 | Argument | Description
352 -------------------------------------------------------------------------------
353 f_pApiInstance Pointer to API instance. This memory is used to keep
354 the present state of the chip and all its resources.
355
356 f_ulPktLengthDword Length of the packet in dwords.
357
358 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
359 #if !SKIP_Oct6100ApiCheckEndianDetectField
360 UINT32 Oct6100ApiCheckEndianDetectField(
361 IN OUT tPOCTRPC_OGRDTP_HEADER f_pOgrdtpHeader,
362 IN UINT32 f_ulPktLengthDword )
363 {
364 PUINT32 pulPktPayload;
365 UINT32 ulBytePositionW = cOCT6100_INVALID_VALUE;
366 UINT32 ulBytePositionX = cOCT6100_INVALID_VALUE;
367 UINT32 ulBytePositionY = cOCT6100_INVALID_VALUE;
368 UINT32 ulBytePositionZ = cOCT6100_INVALID_VALUE;
369 UINT32 ulTempVar;
370 UINT32 i;
371
372 /* Bytes in dword are labeled as Z Y X W. */
373
374 /* Only swap if necessary. */
375 if ( f_pOgrdtpHeader->ulEndianDetect != cOCTRPC_ENDIAN_DETECT )
376 {
377 /* Find the position of each byte. */
378 for ( i = 0; i < 4; i++ )
379 {
380 ulTempVar = (f_pOgrdtpHeader->ulEndianDetect >> (8 * i)) & 0xFF;
381 switch ( ulTempVar )
382 {
383 case cOCTRPC_ENDIAN_DETECT_BYTE_W:
384 ulBytePositionW = i * 8;
385 break;
386 case cOCTRPC_ENDIAN_DETECT_BYTE_X:
387 ulBytePositionX = i * 8;
388 break;
389 case cOCTRPC_ENDIAN_DETECT_BYTE_Y:
390 ulBytePositionY = i * 8;
391 break;
392 case cOCTRPC_ENDIAN_DETECT_BYTE_Z:
393 ulBytePositionZ = i * 8;
394 break;
395 default:
396 return cOCT6100_ERR_REMOTEDEBUG_INVALID_PACKET;
397 }
398 }
399
400 /* Make sure all bytes of the endian detect field were found. */
401 if ( ulBytePositionW == cOCT6100_INVALID_VALUE ||
402 ulBytePositionX == cOCT6100_INVALID_VALUE ||
403 ulBytePositionY == cOCT6100_INVALID_VALUE ||
404 ulBytePositionZ == cOCT6100_INVALID_VALUE )
405 return cOCT6100_ERR_REMOTEDEBUG_INVALID_PACKET;
406
407 /* Swap the bytes of each dword of the packet. */
408 pulPktPayload = ( PUINT32 )f_pOgrdtpHeader;
409 for ( i = 0; i < f_ulPktLengthDword; i++ )
410 {
411 ulTempVar = pulPktPayload[ i ];
412 pulPktPayload[ i ] = ((ulTempVar >> ulBytePositionZ) & 0xFF) << 24;
413 pulPktPayload[ i ] |= ((ulTempVar >> ulBytePositionY) & 0xFF) << 16;
414 pulPktPayload[ i ] |= ((ulTempVar >> ulBytePositionX) & 0xFF) << 8;
415 pulPktPayload[ i ] |= ((ulTempVar >> ulBytePositionW) & 0xFF) << 0;
416 }
417 }
418
419 return cOCT6100_ERR_OK;
420 }
421 #endif
422
423
424 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
425
426 Function: Oct6100ApiCalculateChecksum
427
428 Description: Calculates the checksum of the given packet payload.
429
430 -------------------------------------------------------------------------------
431 | Argument | Description
432 -------------------------------------------------------------------------------
433 f_pulPktPayload Pointer to the payload of the packet.
434 f_ulPktLengthDword Length of the packet in dwords.
435 f_pulChecksum Pointer to the checksum of the packet.
436
437 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
438 #if !SKIP_Oct6100ApiCalculateChecksum
439 VOID Oct6100ApiCalculateChecksum(
440 IN PUINT32 f_pulPktPayload,
441 IN UINT32 f_ulPktLengthDword,
442 OUT PUINT32 f_pulChecksum )
443 {
444 tPOCTRPC_OGRDTP_HEADER pOgrdtpHeader;
445 UINT32 i;
446
447 for ( i = 0, *f_pulChecksum = 0; i < f_ulPktLengthDword; i++ )
448 {
449 *f_pulChecksum += (f_pulPktPayload[ i ] >> 16) & 0xFFFF;
450 *f_pulChecksum += (f_pulPktPayload[ i ] >> 0) & 0xFFFF;
451 }
452
453 pOgrdtpHeader = ( tPOCTRPC_OGRDTP_HEADER )f_pulPktPayload;
454 *f_pulChecksum -= (pOgrdtpHeader->ulChecksum >> 16) & 0xFFFF;
455 *f_pulChecksum -= (pOgrdtpHeader->ulChecksum >> 0) & 0xFFFF;
456 }
457 #endif
458
459
460 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
461
462 Function: Oct6100ApiFormResponsePkt
463
464 Description: Modifies the values of the indicated receive packet, update
465 the checksum field, and copy the receive packet to the
466 response packet.
467
468 -------------------------------------------------------------------------------
469 | Argument | Description
470 -------------------------------------------------------------------------------
471 f_pApiInstance Pointer to API instance. This memory is used to keep
472 the present state of the chip and all its resources.
473
474 f_pulRcvPktPayload Pointer to the payload of the received packet.
475 f_pulRspPktPayload Pointer to the payload of the response packet.
476 f_ulPktLengthDword Length of the packet in dwords.
477 f_fRetryPktResponse Flag indicating if the received packet was a retry packet.
478 f_fReplaceProtocolNum Flag indicating if the protocol number must be replaced.
479 f_fReplaceInterfaceType Flag indicating if the interface type must be replaced.
480 f_fReplaceInterfaceVersion Flag indicating if the interface version must be replaced.
481 f_ulSessionIndex Index of the remote debug session within the API' session list.
482 f_ulParsingErrorValue Parsing error value.
483 f_ulPayloadDwordIndex Index in the packet where the payload starts.
484 f_ulChecksum Checksum of the packet.
485
486 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
487 #if !SKIP_Oct6100ApiFormResponsePkt
488 VOID Oct6100ApiFormResponsePkt(
489 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
490 IN PUINT32 f_pulRcvPktPayload,
491 OUT PUINT32 f_pulRspPktPayload,
492 IN UINT32 f_ulPktLengthDword,
493 IN BOOL f_fRetryPktResponse,
494 IN BOOL f_fReplaceProtocolNum,
495 IN BOOL f_fReplaceInterfaceType,
496 IN BOOL f_fReplaceInterfaceVersion,
497 IN UINT32 f_ulSessionIndex,
498 IN UINT32 f_ulParsingErrorValue,
499 IN UINT32 f_ulPayloadDwordIndex,
500 IN UINT32 f_ulChecksum )
501 {
502 tPOCT6100_SHARED_INFO pSharedInfo;
503 tPOCTRPC_OGRDTP_HEADER pOgrdtpHeader;
504 tPOCTRPC_INTERFACE_HEADER pInterfaceHeader;
505 PUINT32 pulPktCache;
506
507 /* Get local pointer(s). */
508 pSharedInfo = f_pApiInstance->pSharedInfo;
509
510 /* Typecast pointer to OGRDTP packet header. */
511 pOgrdtpHeader = ( tPOCTRPC_OGRDTP_HEADER )f_pulRcvPktPayload;
512
513 /* Check if a response to a retry packet. */
514 if ( f_fRetryPktResponse == TRUE )
515 {
516 mOCT6100_GET_REMOTE_DEBUG_SESSION_PKT_CACHE_PNT( pSharedInfo, pulPktCache, f_ulSessionIndex )
517
518 Oct6100UserMemCopy( f_pulRspPktPayload, pulPktCache, f_ulPktLengthDword * 4 );
519 return;
520 }
521
522 /* Replace all packet header fields which must be changed. */
523 if ( f_ulParsingErrorValue != cOCT6100_INVALID_VALUE )
524 {
525 f_ulChecksum -= (pOgrdtpHeader->ulParsingError >> 16) & 0xFFFF;
526 f_ulChecksum -= (pOgrdtpHeader->ulParsingError >> 0) & 0xFFFF;
527
528 pOgrdtpHeader->ulParsingError = f_ulParsingErrorValue;
529
530 f_ulChecksum += (pOgrdtpHeader->ulParsingError >> 16) & 0xFFFF;
531 f_ulChecksum += (pOgrdtpHeader->ulParsingError >> 0) & 0xFFFF;
532 }
533
534 if ( f_fReplaceProtocolNum == TRUE )
535 {
536 f_ulChecksum -= (pOgrdtpHeader->ulRpcProtocolNum >> 16) & 0xFFFF;
537 f_ulChecksum -= (pOgrdtpHeader->ulRpcProtocolNum >> 0) & 0xFFFF;
538
539 pOgrdtpHeader->ulRpcProtocolNum = cOCTRPC_PROTOCOL_V1_1;
540
541 f_ulChecksum += (pOgrdtpHeader->ulRpcProtocolNum >> 16) & 0xFFFF;
542 f_ulChecksum += (pOgrdtpHeader->ulRpcProtocolNum >> 0) & 0xFFFF;
543 }
544
545 if ( f_fReplaceInterfaceType == TRUE )
546 {
547 pInterfaceHeader = ( tPOCTRPC_INTERFACE_HEADER )(f_pulRcvPktPayload + (sizeof( tOCTRPC_OGRDTP_HEADER ) / 4));
548
549 f_ulChecksum -= (pInterfaceHeader->ulInterfaceType >> 16) & 0xFFFF;
550 f_ulChecksum -= (pInterfaceHeader->ulInterfaceType >> 0) & 0xFFFF;
551
552 pInterfaceHeader->ulInterfaceType = cOCTRPC_OCT6100_INTERFACE;
553
554 f_ulChecksum += (pInterfaceHeader->ulInterfaceType >> 16) & 0xFFFF;
555 f_ulChecksum += (pInterfaceHeader->ulInterfaceType >> 0) & 0xFFFF;
556 }
557
558 if ( f_fReplaceInterfaceVersion == TRUE )
559 {
560 pInterfaceHeader = ( tPOCTRPC_INTERFACE_HEADER )(f_pulRcvPktPayload + (sizeof( tOCTRPC_OGRDTP_HEADER ) / 4));
561
562 f_ulChecksum -= (pInterfaceHeader->ulInterfaceVersion >> 16) & 0xFFFF;
563 f_ulChecksum -= (pInterfaceHeader->ulInterfaceVersion >> 0) & 0xFFFF;
564
565 pInterfaceHeader->ulInterfaceVersion = cOCTRPC_INTERFACE_VERSION;
566
567 f_ulChecksum += (pInterfaceHeader->ulInterfaceVersion >> 16) & 0xFFFF;
568 f_ulChecksum += (pInterfaceHeader->ulInterfaceVersion >> 0) & 0xFFFF;
569 }
570
571 if ( f_ulPayloadDwordIndex != cOCT6100_INVALID_VALUE )
572 {
573 f_pulRcvPktPayload += f_ulPayloadDwordIndex;
574
575 f_ulChecksum -= (*f_pulRcvPktPayload >> 16) & 0xFFFF;
576 f_ulChecksum -= (*f_pulRcvPktPayload >> 0) & 0xFFFF;
577
578 *f_pulRcvPktPayload = cOCTRPC_UNKNOWN_COMMAND_NUM;
579
580 f_ulChecksum += (*f_pulRcvPktPayload >> 16) & 0xFFFF;
581 f_ulChecksum += (*f_pulRcvPktPayload >> 0) & 0xFFFF;
582
583 f_pulRcvPktPayload -= f_ulPayloadDwordIndex;
584 }
585
586 /* Replace checksum. */
587 pOgrdtpHeader->ulChecksum = f_ulChecksum;
588
589 /* Copy the modified receive packet payload to the response packet. */
590 Oct6100UserMemCopy( f_pulRspPktPayload, f_pulRcvPktPayload, f_ulPktLengthDword * 4 );
591
592 /* Copy the response packet to the session's packet cache. */
593 if ( f_ulSessionIndex != cOCT6100_INVALID_VALUE )
594 {
595 mOCT6100_GET_REMOTE_DEBUG_SESSION_PKT_CACHE_PNT( pSharedInfo, pulPktCache, f_ulSessionIndex )
596
597 Oct6100UserMemCopy( pulPktCache, f_pulRspPktPayload, f_ulPktLengthDword * 4 );
598 }
599 }
600 #endif
601
602
603 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
604
605 Function: Oct6100ApiCheckPktCommands
606
607 Description: Checks the commands contained in the packet for errors in size.
608 Also checks for unknown commands. If an error is encountered
609 then the function will construct the response packet.
610
611 -------------------------------------------------------------------------------
612 | Argument | Description
613 -------------------------------------------------------------------------------
614 f_pApiInstance Pointer to API instance. This memory is used to keep
615 the present state of the chip and all its resources.
616
617 f_pulRcvPktPayload Pointer to the payload of the received packet.
618 f_pulRspPktPayload Pointer to the payload of the response packet.
619 f_ulPktLengthDword Length of the packet in dwords.
620 f_ulSessionIndex Index of the remote debug session within the API' session list.
621 f_ulChecksum Checksum of the packet.
622
623 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
624 #if !SKIP_Oct6100ApiCheckPktCommands
625 UINT32 Oct6100ApiCheckPktCommands(
626 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
627 IN PUINT32 f_pulRcvPktPayload,
628 IN OUT PUINT32 f_pulRspPktPayload,
629 IN UINT32 f_ulSessionIndex,
630 IN UINT32 f_ulPktLengthDword,
631 IN UINT32 f_ulChecksum )
632 {
633 tPOCTRPC_COMMAND_HEADER pCmndHeader;
634 UINT32 ulNumDwordsLeft;
635 UINT32 ulNumDwordsNeeded = 0;
636 UINT32 ulRpcCmndSizeDword;
637 BOOL fCmndIdentified;
638 BOOL fCmndHeaderPresent;
639
640 pCmndHeader = ( tPOCTRPC_COMMAND_HEADER )(f_pulRcvPktPayload + ((sizeof( tOCTRPC_OGRDTP_HEADER ) + sizeof( tOCTRPC_INTERFACE_HEADER )) / 4));
641 ulNumDwordsLeft = f_ulPktLengthDword - ((sizeof( tOCTRPC_OGRDTP_HEADER ) + sizeof( tOCTRPC_INTERFACE_HEADER )) / 4);
642 ulRpcCmndSizeDword = sizeof( tOCTRPC_COMMAND_HEADER ) / 4;
643 fCmndIdentified = TRUE;
644
645 while ( ulNumDwordsLeft != 0 )
646 {
647 if ( ulNumDwordsLeft < ulRpcCmndSizeDword )
648 {
649 fCmndHeaderPresent = FALSE;
650 }
651 else
652 {
653 fCmndHeaderPresent = TRUE;
654
655 switch ( pCmndHeader->ulRpcCommandNum )
656 {
657 case cOCT6100_RPC_READ_WORD:
658 {
659 ulNumDwordsNeeded = sizeof( tOCT6100_RPC_READ_WORD ) / 4;
660 }
661 break;
662 case cOCT6100_RPC_READ_BURST:
663 {
664 tPOCT6100_RPC_READ_BURST pBurstHeader;
665
666 ulNumDwordsNeeded = (sizeof( tOCT6100_RPC_READ_BURST ) - sizeof( UINT32 )) / 4;
667 pBurstHeader = ( tPOCT6100_RPC_READ_BURST )(( PUINT32 )pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
668 ulNumDwordsNeeded += (pBurstHeader->ulBurstLength + 1) / 2;
669 }
670 break;
671 case cOCT6100_RPC_WRITE_WORD:
672 {
673 ulNumDwordsNeeded = sizeof( tOCT6100_RPC_WRITE_WORD ) / 4;
674 }
675 break;
676 case cOCT6100_RPC_WRITE_SMEAR:
677 {
678 ulNumDwordsNeeded = sizeof( tOCT6100_RPC_WRITE_SMEAR ) / 4;
679 }
680 break;
681 case cOCT6100_RPC_WRITE_INC:
682 {
683 ulNumDwordsNeeded = sizeof( tOCT6100_RPC_WRITE_INC ) / 4;
684 }
685 break;
686 case cOCT6100_RPC_READ_ARRAY:
687 {
688 tPOCT6100_RPC_READ_ARRAY pArrayHeader;
689
690 ulNumDwordsNeeded = (sizeof( tOCT6100_RPC_READ_ARRAY ) - sizeof( UINT32 )) / 4;
691 pArrayHeader = ( tPOCT6100_RPC_READ_ARRAY )(( PUINT32 )pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
692 ulNumDwordsNeeded += pArrayHeader->ulArrayLength;
693 ulNumDwordsNeeded += (pArrayHeader->ulArrayLength + 1) / 2;
694 }
695 break;
696 case cOCT6100_RPC_WRITE_BURST:
697 {
698 tPOCT6100_RPC_WRITE_BURST pBurstHeader;
699
700 ulNumDwordsNeeded = (sizeof( tOCT6100_RPC_WRITE_BURST ) - sizeof( UINT32 )) / 4;
701 pBurstHeader = ( tPOCT6100_RPC_WRITE_BURST )(( PUINT32 )pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
702 ulNumDwordsNeeded += (pBurstHeader->ulBurstLength + 1) / 2;
703 }
704 break;
705 case cOCT6100_RPC_SET_HOT_CHANNEL:
706 {
707 ulNumDwordsNeeded = sizeof( tOCT6100_RPC_SET_HOT_CHANNEL ) / 4;
708 }
709 break;
710 case cOCT6100_RPC_GET_DEBUG_CHAN_INDEX:
711 {
712 ulNumDwordsNeeded = sizeof( tOCT6100_RPC_GET_DEBUG_CHAN_INDEX ) / 4;
713 }
714 break;
715 case cOCT6100_RPC_API_DISCONNECT:
716 {
717 /* There is no parameter to the disconnect command. */
718 ulNumDwordsNeeded = 0;
719 }
720 break;
721 default:
722 fCmndIdentified = FALSE;
723 }
724
725 ulNumDwordsNeeded += sizeof( tOCTRPC_COMMAND_HEADER ) / 4;
726 }
727
728 if ( fCmndHeaderPresent != TRUE )
729 {
730 Oct6100ApiFormResponsePkt( f_pApiInstance, f_pulRcvPktPayload, f_pulRspPktPayload, f_ulPktLengthDword, FALSE, FALSE, FALSE, FALSE, f_ulSessionIndex, cOCTRPC_RDBGERR_INVALID_PACKET_LENGTH, cOCT6100_INVALID_VALUE, f_ulChecksum );
731 return cOCT6100_ERR_REMOTE_DEBUG_PARSING_ERROR;
732 }
733 if ( fCmndIdentified != TRUE )
734 {
735 Oct6100ApiFormResponsePkt( f_pApiInstance, f_pulRcvPktPayload, f_pulRspPktPayload, f_ulPktLengthDword, FALSE, FALSE, FALSE, FALSE, f_ulSessionIndex, cOCTRPC_RDBGERR_INVALID_COMMAND_NUMBER, f_ulPktLengthDword - ulNumDwordsLeft, f_ulChecksum );
736 return cOCT6100_ERR_REMOTE_DEBUG_PARSING_ERROR;
737 }
738
739 if ( ulNumDwordsNeeded != (pCmndHeader->ulCommandByteSize / 4) ||
740 ulNumDwordsNeeded > ulNumDwordsLeft )
741 {
742 Oct6100ApiFormResponsePkt( f_pApiInstance, f_pulRcvPktPayload, f_pulRspPktPayload, f_ulPktLengthDword, FALSE, FALSE, FALSE, FALSE, f_ulSessionIndex, cOCTRPC_RDBGERR_INVALID_COMMAND_LENGTH, cOCT6100_INVALID_VALUE, f_ulChecksum );
743 return cOCT6100_ERR_REMOTE_DEBUG_PARSING_ERROR;
744 }
745
746 pCmndHeader = ( tPOCTRPC_COMMAND_HEADER )(( PUINT32 )pCmndHeader + ulNumDwordsNeeded);
747 ulNumDwordsLeft -= ulNumDwordsNeeded;
748 }
749
750 return cOCT6100_ERR_OK;
751 }
752 #endif
753
754
755 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
756
757 Function: Oct6100ApiExecutePktCommands
758
759 Description: Executes the commands contained in the received packet. The
760 received packet payload buffer is modified but NOT copied to
761 the response packet buffer.
762
763 -------------------------------------------------------------------------------
764 | Argument | Description
765 -------------------------------------------------------------------------------
766 f_pApiInstance Pointer to API instance. This memory is used to keep
767 the present state of the chip and all its resources.
768
769 f_pulRcvPktPayload Pointer to the payload of the received packet.
770 f_ulPktLengthDword Length of the packet in dwords.
771
772 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
773 #if !SKIP_Oct6100ApiExecutePktCommands
774 VOID Oct6100ApiExecutePktCommands(
775 IN tPOCT6100_INSTANCE_API f_pApiInstance,
776 IN PUINT32 f_pulRcvPktPayload,
777 IN UINT32 f_ulPktLengthDword )
778 {
779 tPOCTRPC_COMMAND_HEADER pReqCmndHeader;
780 tPOCTRPC_OGRDTP_HEADER pReqPktHeader;
781 UINT32 ulNumDwordsLeft;
782 UINT32 ulRpcCmndSizeDword;
783
784 pReqPktHeader = ( tPOCTRPC_OGRDTP_HEADER )(f_pulRcvPktPayload);
785 pReqCmndHeader = ( tPOCTRPC_COMMAND_HEADER )(( PUINT32 )f_pulRcvPktPayload + ((sizeof( tOCTRPC_OGRDTP_HEADER ) + sizeof( tOCTRPC_INTERFACE_HEADER )) / 4));
786 ulNumDwordsLeft = f_ulPktLengthDword - ((sizeof( tOCTRPC_OGRDTP_HEADER ) + sizeof( tOCTRPC_INTERFACE_HEADER )) / 4);
787 ulRpcCmndSizeDword = sizeof( tOCTRPC_COMMAND_HEADER ) / 4;
788
789 while ( ulNumDwordsLeft != 0 )
790 {
791 /* Switch on command number. */
792 switch ( pReqCmndHeader->ulRpcCommandNum )
793 {
794 case cOCT6100_RPC_READ_WORD:
795 Oct6100ApiRpcReadWord( f_pApiInstance, pReqCmndHeader );
796 break;
797 case cOCT6100_RPC_READ_BURST:
798 Oct6100ApiRpcReadBurst( f_pApiInstance, pReqCmndHeader );
799 break;
800 case cOCT6100_RPC_READ_ARRAY:
801 Oct6100ApiRpcReadArray( f_pApiInstance, pReqCmndHeader );
802 break;
803 case cOCT6100_RPC_WRITE_WORD:
804 Oct6100ApiRpcWriteWord( f_pApiInstance, pReqCmndHeader );
805 break;
806 case cOCT6100_RPC_WRITE_SMEAR:
807 Oct6100ApiRpcWriteSmear( f_pApiInstance, pReqCmndHeader );
808 break;
809 case cOCT6100_RPC_WRITE_BURST:
810 Oct6100ApiRpcWriteBurst( f_pApiInstance, pReqCmndHeader );
811 break;
812 case cOCT6100_RPC_SET_HOT_CHANNEL:
813 Oct6100ApiRpcSetHotChannel( f_pApiInstance, pReqCmndHeader );
814 break;
815 case cOCT6100_RPC_GET_DEBUG_CHAN_INDEX:
816 Oct6100ApiRpcGetDebugChanIndex( f_pApiInstance, pReqCmndHeader );
817 break;
818 case cOCT6100_RPC_API_DISCONNECT:
819 Oct6100ApiRpcDisconnect( f_pApiInstance, pReqCmndHeader, pReqPktHeader->ulDebugSessionNum );
820 break;
821 default:
822 pReqCmndHeader->ulFunctionResult = cOCT6100_ERR_REMOTEDEBUG_INVALID_RPC_COMMAND_NUM;
823 break;
824 }
825
826 /* Insert the result of the operation in the command header. */
827 if ( pReqCmndHeader->ulFunctionResult != cOCT6100_ERR_OK )
828 break;
829
830 /* Decrement the number of DWORDs left in the packet. */
831 ulNumDwordsLeft -= pReqCmndHeader->ulCommandByteSize / 4;
832
833 /* Point to the next command in the packet. */
834 pReqCmndHeader = ( tPOCTRPC_COMMAND_HEADER )(( PUINT32 )pReqCmndHeader + (pReqCmndHeader->ulCommandByteSize / 4));
835 }
836 }
837 #endif
838
839
840 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
841
842 Function: Oct6100ApiCheckSessionNum
843
844 Description: Checks if there is a session list entry open for the session
845 number received. If not, a free one is reserved if one is
846 available. If none are free, one which has timed-out is
847 released. If none are timed out then an error is returned.
848
849 -------------------------------------------------------------------------------
850 | Argument | Description
851 -------------------------------------------------------------------------------
852 f_pApiInstance Pointer to API instance. This memory is used to keep
853 the present state of the chip and all its resources.
854
855 f_pOgrdtpHeader Pointer to the header of the packet.
856 f_pulSessionIndex Pointer to the remote debugging session within the
857 API's session list.
858
859 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
860 #if !SKIP_Oct6100ApiCheckSessionNum
861 UINT32 Oct6100ApiCheckSessionNum(
862 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
863 IN tPOCTRPC_OGRDTP_HEADER f_pOgrdtpHeader,
864 OUT PUINT32 f_pulSessionIndex )
865 {
866 tPOCT6100_SHARED_INFO pSharedInfo;
867 tPOCT6100_API_REMOTE_DEBUG_INFO pRemoteDebugInfo;
868 tPOCT6100_API_REMOTE_DEBUG_SESSION pSessionEntry;
869 tPOCT6100_API_REMOTE_DEBUG_SESSION pSessionLink;
870 tOCT6100_GET_TIME GetTime;
871 PVOID pSessionTree;
872 PUINT32 pulTreeData;
873 UINT32 ulNewSessionIndex;
874 UINT32 aulTimeDiff[ 2 ];
875 UINT32 ulResult;
876 UINT16 usNegative;
877
878 /* Get local pointer(s). */
879 pSharedInfo = f_pApiInstance->pSharedInfo;
880
881 /* Set the process context of GetTime. */
882 GetTime.pProcessContext = f_pApiInstance->pProcessContext;
883
884 /* Get the current system time. */
885 ulResult = Oct6100UserGetTime( &GetTime );
886 if ( ulResult != cOCT6100_ERR_OK )
887 return ulResult;
888
889 /* Get a local pointer to the remote debugging info. */
890 pRemoteDebugInfo = &pSharedInfo->RemoteDebugInfo;
891
892 /* Check if the session number has an associated session list entry. */
893 mOCT6100_GET_REMOTE_DEBUG_TREE_PNT( pSharedInfo, pSessionTree )
894
895 ulResult = octapi_bt0_query_node( pSessionTree, ( ( PVOID )(&f_pOgrdtpHeader->ulDebugSessionNum) ), ( ( PVOID* )&pulTreeData ) );
896 if ( ulResult == cOCT6100_ERR_OK )
897 {
898 /* Return session index. */
899 *f_pulSessionIndex = *pulTreeData;
900
901 /* A session list entry is associated, so update the entries last packet time,
902 transaction number and packet retry number, and position in the linked list. */
903 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, *pulTreeData, pSessionEntry )
904
905 pSessionEntry->aulLastPktTime[ 0 ] = GetTime.aulWallTimeUs[ 0 ];
906 pSessionEntry->aulLastPktTime[ 1 ] = GetTime.aulWallTimeUs[ 1 ];
907 pSessionEntry->ulPktRetryNum = f_pOgrdtpHeader->ulPktRetryNum;
908
909 /* Remove the node from its current place in the linked-list and add it to the end. */
910 if ( pRemoteDebugInfo->ulSessionListTail != *pulTreeData )
911 {
912 /* Obtain local pointer to the session list entry to be moved. */
913 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, *pulTreeData, pSessionEntry )
914
915 /* Update link of previous session in list. */
916 if ( pSessionEntry->ulBackwardLink != cOCT6100_INVALID_VALUE )
917 {
918 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulBackwardLink, pSessionLink )
919 pSessionLink->ulForwardLink = pSessionEntry->ulForwardLink;
920 }
921 else
922 {
923 pRemoteDebugInfo->ulSessionListHead = pSessionEntry->ulForwardLink;
924 }
925
926 /* Update link of next session in list. */
927 if ( pSessionEntry->ulForwardLink != cOCT6100_INVALID_VALUE )
928 {
929 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulForwardLink, pSessionLink )
930 pSessionLink->ulBackwardLink = pSessionEntry->ulBackwardLink;
931 }
932 else
933 {
934 pRemoteDebugInfo->ulSessionListTail = pSessionEntry->ulBackwardLink;
935 }
936
937 /* Place session at the end of the list. */
938 pSessionEntry->ulBackwardLink = pRemoteDebugInfo->ulSessionListTail;
939 pSessionEntry->ulForwardLink = cOCT6100_INVALID_VALUE;
940
941 pRemoteDebugInfo->ulSessionListTail = *pulTreeData;
942
943 if ( pRemoteDebugInfo->ulSessionListHead == cOCT6100_INVALID_VALUE )
944 {
945 pRemoteDebugInfo->ulSessionListHead = *pulTreeData;
946 }
947 else
948 {
949 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulBackwardLink, pSessionLink )
950 pSessionLink->ulForwardLink = *pulTreeData;
951 }
952 }
953
954 /* Check if packet should be interpreted based on transaction number. */
955 if ( f_pOgrdtpHeader->ulPktRetryNum != 0 &&
956 pSessionEntry->ulTransactionNum == f_pOgrdtpHeader->ulTransactionNum &&
957 pSessionEntry->ulPktByteSize == f_pOgrdtpHeader->ulPktByteSize )
958 return cOCT6100_ERR_REMOTEDEBUG_TRANSACTION_ANSWERED;
959
960 /* Update transaction number since packet will be interpreted. */
961 pSessionEntry->ulTransactionNum = f_pOgrdtpHeader->ulTransactionNum;
962 pSessionEntry->ulPktByteSize = f_pOgrdtpHeader->ulPktByteSize;
963
964 return cOCT6100_ERR_OK;
965 }
966 else if ( ulResult == OCTAPI_BT0_KEY_NOT_IN_TREE )
967 {
968 /* If there is a free entry in the session list then seize it. Else, try to
969 find an entry which has timed out. If there are none then return an error. */
970 if ( pRemoteDebugInfo->ulNumSessionsOpen < pRemoteDebugInfo->ulMaxSessionsOpen )
971 {
972 ulNewSessionIndex = pRemoteDebugInfo->ulNumSessionsOpen;
973 }
974 else /* ( pRemoteDebugInfo->ulNumSessionsOpen == pRemoteDebugInfo->ulMaxSessionsOpen ) */
975 {
976 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pRemoteDebugInfo->ulSessionListHead, pSessionEntry )
977
978 ulResult = octapi_lm_subtract( GetTime.aulWallTimeUs, 1, pSessionEntry->aulLastPktTime, 1, aulTimeDiff, 1, &usNegative );
979 if ( ulResult != cOCT6100_ERR_OK || usNegative != FALSE )
980 return cOCT6100_ERR_FATAL_43;
981
982 /* If there are no session list entries available then return the packet with
983 a parsing error. */
984 if ( aulTimeDiff[ 1 ] == 0 && aulTimeDiff[ 0 ] < (cOCTRPC_SESSION_TIMEOUT * 1000000) )
985 return cOCT6100_ERR_REMOTEDEBUG_ALL_SESSIONS_OPEN;
986
987 ulNewSessionIndex = pRemoteDebugInfo->ulSessionListHead;
988
989 /* Remove old session index. */
990 ulResult = octapi_bt0_remove_node( pSessionTree, ( ( PVOID )&pSessionEntry->ulSessionNum ) );
991 if ( ulResult != cOCT6100_ERR_OK )
992 return cOCT6100_ERR_FATAL_44;
993
994 if ( pSessionEntry->ulBackwardLink != cOCT6100_INVALID_VALUE )
995 {
996 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulBackwardLink, pSessionLink )
997 pSessionLink->ulForwardLink = pSessionEntry->ulForwardLink;
998 }
999 else
1000 {
1001 pRemoteDebugInfo->ulSessionListHead = pSessionEntry->ulForwardLink;
1002 }
1003
1004 if ( pSessionEntry->ulForwardLink != cOCT6100_INVALID_VALUE )
1005 {
1006 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulForwardLink, pSessionLink )
1007 pSessionLink->ulBackwardLink = pSessionEntry->ulBackwardLink;
1008 }
1009 else
1010 {
1011 pRemoteDebugInfo->ulSessionListTail = pSessionEntry->ulBackwardLink;
1012 }
1013
1014 /* Decrement number of open sessions. */
1015 pRemoteDebugInfo->ulNumSessionsOpen--;
1016 }
1017
1018 /* Add new session. */
1019 ulResult = octapi_bt0_add_node( pSessionTree, ( ( PVOID )&f_pOgrdtpHeader->ulDebugSessionNum ), ( ( PVOID* )&pulTreeData ) );
1020 if ( ulResult != cOCT6100_ERR_OK )
1021 return cOCT6100_ERR_FATAL_45;
1022 *pulTreeData = ulNewSessionIndex;
1023
1024 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, ulNewSessionIndex, pSessionEntry )
1025
1026 pSessionEntry->aulLastPktTime[ 0 ] = GetTime.aulWallTimeUs[ 0 ];
1027 pSessionEntry->aulLastPktTime[ 1 ] = GetTime.aulWallTimeUs[ 1 ];
1028 pSessionEntry->ulSessionNum = f_pOgrdtpHeader->ulDebugSessionNum;
1029 pSessionEntry->ulTransactionNum = f_pOgrdtpHeader->ulTransactionNum;
1030 pSessionEntry->ulPktRetryNum = f_pOgrdtpHeader->ulPktRetryNum;
1031
1032 pSessionEntry->ulBackwardLink = pRemoteDebugInfo->ulSessionListTail;
1033 pSessionEntry->ulForwardLink = cOCT6100_INVALID_VALUE;
1034
1035 pRemoteDebugInfo->ulSessionListTail = ulNewSessionIndex;
1036 if ( pRemoteDebugInfo->ulSessionListHead == cOCT6100_INVALID_VALUE )
1037 pRemoteDebugInfo->ulSessionListHead = ulNewSessionIndex;
1038
1039 if ( pSessionEntry->ulBackwardLink != cOCT6100_INVALID_VALUE )
1040 {
1041 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulBackwardLink, pSessionLink )
1042 pSessionLink->ulForwardLink = ulNewSessionIndex;
1043 }
1044
1045 *f_pulSessionIndex = ulNewSessionIndex;
1046
1047 /* Increment number of open sessions. */
1048 pRemoteDebugInfo->ulNumSessionsOpen++;
1049
1050 return cOCT6100_ERR_OK;
1051 }
1052 else
1053 {
1054 return cOCT6100_ERR_FATAL_46;
1055 }
1056 }
1057 #endif
1058
1059
1060 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1061
1062 Function: Oct6100ApiRpcReadWord
1063
1064 Description: Checks the provided portion of an OCTRPC packet and interprets
1065 it as an cOCT6100_RPC_READ_WORD command.
1066
1067 -------------------------------------------------------------------------------
1068 | Argument | Description
1069 -------------------------------------------------------------------------------
1070 f_pApiInstance Pointer to API instance. This memory is used to keep
1071 the present state of the chip and all its resources.
1072
1073 f_pCmndHeader Pointer to RPC command structure.
1074
1075 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1076 #if !SKIP_Oct6100ApiRpcReadWord
1077 VOID Oct6100ApiRpcReadWord(
1078 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1079 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1080 {
1081 tPOCT6100_RPC_READ_WORD pReadCommand;
1082 tOCT6100_READ_PARAMS ReadParams;
1083 UINT32 ulResult;
1084 UINT16 usReadData;
1085
1086 /* Get pointer to command arguments. */
1087 pReadCommand = ( tPOCT6100_RPC_READ_WORD )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1088
1089 /* Set some read structure parameters. */
1090 ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
1091
1092 ReadParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
1093
1094 /* Copy parameters from packet payload to local read structure. */
1095 ReadParams.ulReadAddress = pReadCommand->ulAddress;
1096
1097 /* Supply memory for read data. */
1098 ReadParams.pusReadData = &usReadData;
1099
1100 /* Perform read access. */
1101 mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
1102
1103 usReadData &= 0xFFFF;
1104
1105 /* Return read data and result. */
1106 pReadCommand->ulReadData = (usReadData << 16) | usReadData;
1107 f_pCmndHeader->ulFunctionResult = ulResult;
1108 }
1109 #endif
1110
1111
1112 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1113
1114 Function: Oct6100ApiRpcReadBurst
1115
1116 Description: Checks the provided portion of an OCTRPC packet and interprets
1117 it as an cOCT6100_RPC_READ_BURST command.
1118
1119 -------------------------------------------------------------------------------
1120 | Argument | Description
1121 -------------------------------------------------------------------------------
1122 f_pApiInstance Pointer to API instance. This memory is used to keep
1123 the present state of the chip and all its resources.
1124
1125 f_pCmndHeader Pointer to RPC command structure.
1126
1127 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1128 #if !SKIP_Oct6100ApiRpcReadBurst
1129 VOID Oct6100ApiRpcReadBurst(
1130 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1131 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1132 {
1133 tPOCT6100_RPC_READ_BURST pBurstCommand;
1134 tOCT6100_READ_BURST_PARAMS BurstParams;
1135 UINT32 ulResult = cOCT6100_ERR_OK;
1136 UINT32 ulTempVar;
1137 UINT32 i;
1138 PUINT16 pusReadData;
1139 UINT32 ulNumWordsToRead;
1140
1141 /* Get local pointer to remote debugging read data buffer. */
1142 mOCT6100_GET_REMOTE_DEBUG_DATA_BUF_PNT( f_pApiInstance->pSharedInfo, pusReadData )
1143
1144 /* Get pointer to command arguments. */
1145 pBurstCommand = ( tPOCT6100_RPC_READ_BURST )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1146
1147 /* Set some read structure parameters. */
1148 BurstParams.pProcessContext = f_pApiInstance->pProcessContext;
1149
1150 BurstParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
1151
1152 /* Copy parameters from packet payload to local read structure. */
1153 BurstParams.ulReadAddress = pBurstCommand->ulAddress;
1154
1155
1156 /* Supply memory for read data. */
1157 BurstParams.pusReadData = pusReadData;
1158
1159 ulNumWordsToRead = pBurstCommand->ulBurstLength;
1160 while( ulNumWordsToRead > 0)
1161 {
1162 if ( ulNumWordsToRead <= f_pApiInstance->pSharedInfo->ChipConfig.usMaxRwAccesses )
1163 BurstParams.ulReadLength = ulNumWordsToRead;
1164 else
1165 BurstParams.ulReadLength = f_pApiInstance->pSharedInfo->ChipConfig.usMaxRwAccesses;
1166
1167 /* Perform read access. */
1168 mOCT6100_DRIVER_READ_BURST_API( BurstParams, ulResult )
1169 if ( ulResult != cOCT6100_ERR_OK )
1170 {
1171 f_pCmndHeader->ulFunctionResult = ulResult;
1172 return;
1173 }
1174
1175 BurstParams.ulReadAddress += BurstParams.ulReadLength * 2;
1176 BurstParams.pusReadData += BurstParams.ulReadLength;
1177
1178 /* Update the number of dword to read. */
1179 ulNumWordsToRead -= BurstParams.ulReadLength;
1180 }
1181
1182 /* Return read data. */
1183 ulTempVar = (pBurstCommand->ulBurstLength + 1) / 2;
1184 for ( i = 0; i < ulTempVar; i++ )
1185 {
1186 pBurstCommand->aulReadData[ i ] = (*pusReadData & 0xFFFF) << 16;
1187 pusReadData++;
1188 pBurstCommand->aulReadData[ i ] |= (*pusReadData & 0xFFFF) << 0;
1189 pusReadData++;
1190 }
1191
1192 /* Return result. */
1193 f_pCmndHeader->ulFunctionResult = ulResult;
1194 }
1195 #endif
1196
1197
1198 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1199
1200 Function: Oct6100ApiRpcReadArray
1201
1202 Description: Checks the provided portion of an OCTRPC packet and interprets
1203 it as an cOCT6100_RPC_READ_ARRAY command.
1204
1205 -------------------------------------------------------------------------------
1206 | Argument | Description
1207 -------------------------------------------------------------------------------
1208 f_pApiInstance Pointer to API instance. This memory is used to keep
1209 the present state of the chip and all its resources.
1210
1211 f_pCmndHeader Pointer to RPC command structure.
1212
1213 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1214 #if !SKIP_Oct6100ApiRpcReadArray
1215 VOID Oct6100ApiRpcReadArray(
1216 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1217 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1218 {
1219 tPOCT6100_RPC_READ_ARRAY pArrayCommand;
1220 tOCT6100_READ_PARAMS ReadParams;
1221 UINT32 ulResult = cOCT6100_ERR_OK;
1222 UINT32 i;
1223 PUINT32 pulAddressArray;
1224 PUINT32 pulDataArray;
1225 UINT16 usReadData;
1226
1227
1228 /* Get pointer to command arguments. */
1229 pArrayCommand = ( tPOCT6100_RPC_READ_ARRAY )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1230
1231 /* Set some read structure parameters. */
1232 ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
1233
1234 ReadParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
1235
1236 /* Supply memory for read data. */
1237 ReadParams.pusReadData = &usReadData;
1238
1239 /* Get pointers to array of addresses and data. */
1240 pulAddressArray = pArrayCommand->aulArrayData;
1241 pulDataArray = pArrayCommand->aulArrayData + pArrayCommand->ulArrayLength;
1242
1243 for ( i = 0; i < pArrayCommand->ulArrayLength; i++ )
1244 {
1245 /* Copy parameters from packet payload to local read structure. */
1246 ReadParams.ulReadAddress = pulAddressArray[ i ];
1247
1248 /* Perform read access. */
1249 mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
1250 if ( ulResult != cOCT6100_ERR_OK )
1251 break;
1252
1253 /* Return read data. */
1254 if ( (i % 2) == 0 )
1255 pulDataArray[ i / 2 ] = (usReadData & 0xFFFF) << 16;
1256 else /* ( (i % 2) == 1 ) */
1257 pulDataArray[ i / 2 ] |= (usReadData & 0xFFFF) << 0;
1258 }
1259
1260 /* Return result. */
1261 f_pCmndHeader->ulFunctionResult = ulResult;
1262 }
1263 #endif
1264
1265
1266 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1267
1268 Function: Oct6100ApiRpcWriteWord
1269
1270 Description: Checks the provided portion of an OCTRPC packet and interprets
1271 it as an cOCT6100_RPC_WRITE_WORD command.
1272
1273 -------------------------------------------------------------------------------
1274 | Argument | Description
1275 -------------------------------------------------------------------------------
1276 f_pApiInstance Pointer to API instance. This memory is used to keep
1277 the present state of the chip and all its resources.
1278
1279 f_pCmndHeader Pointer to RPC command structure.
1280
1281 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1282 #if !SKIP_Oct6100ApiRpcWriteWord
1283 VOID Oct6100ApiRpcWriteWord(
1284 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1285 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1286 {
1287 tPOCT6100_RPC_WRITE_WORD pWriteCommand;
1288 tOCT6100_WRITE_PARAMS WriteParams;
1289 UINT32 ulResult;
1290
1291 /* Get pointer to command arguments. */
1292 pWriteCommand = ( tPOCT6100_RPC_WRITE_WORD )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1293
1294 /* Set some read structure parameters. */
1295 WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
1296
1297 WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
1298
1299 /* Copy parameters from packet payload to local read structure. */
1300 WriteParams.ulWriteAddress = pWriteCommand->ulAddress;
1301 WriteParams.usWriteData = (UINT16)pWriteCommand->ulWriteData;
1302
1303 /* Perform write access. */
1304 mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
1305
1306 /* Return result. */
1307 f_pCmndHeader->ulFunctionResult = ulResult;
1308 }
1309 #endif
1310
1311
1312 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1313
1314 Function: Oct6100ApiRpcWriteSmear
1315
1316 Description: Checks the provided portion of an OCTRPC packet and interprets
1317 it as an cOCT6100_RPC_WRITE_SMEAR command.
1318
1319 -------------------------------------------------------------------------------
1320 | Argument | Description
1321 -------------------------------------------------------------------------------
1322 f_pApiInstance Pointer to API instance. This memory is used to keep
1323 the present state of the chip and all its resources.
1324
1325 f_pCmndHeader Pointer to RPC command structure.
1326
1327 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1328 #if !SKIP_Oct6100ApiRpcWriteSmear
1329 VOID Oct6100ApiRpcWriteSmear(
1330 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1331 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1332 {
1333 tPOCT6100_RPC_WRITE_SMEAR pSmearCommand;
1334 tOCT6100_WRITE_SMEAR_PARAMS SmearParams;
1335 UINT32 ulResult;
1336
1337 /* Get pointer to command arguments. */
1338 pSmearCommand = ( tPOCT6100_RPC_WRITE_SMEAR )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1339
1340 /* Set the smear structure parameters. */
1341 SmearParams.pProcessContext = f_pApiInstance->pProcessContext;
1342
1343 SmearParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
1344
1345 /* Copy parameters from packet payload to local read structure. */
1346 SmearParams.ulWriteAddress = pSmearCommand->ulAddress;
1347 SmearParams.usWriteData = (UINT16)pSmearCommand->ulWriteData;
1348 SmearParams.ulWriteLength = pSmearCommand->ulSmearLength;
1349
1350 /* Perform write access. */
1351 mOCT6100_DRIVER_WRITE_SMEAR_API( SmearParams, ulResult )
1352
1353 /* Return result. */
1354 f_pCmndHeader->ulFunctionResult = ulResult;
1355 }
1356 #endif
1357
1358
1359 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1360
1361 Function: Oct6100ApiRpcWriteBurst
1362
1363 Description: Checks the provided portion of an OCTRPC packet and interprets
1364 it as an cOCT6100_RPC_WRITE_BURST command.
1365
1366 -------------------------------------------------------------------------------
1367 | Argument | Description
1368 -------------------------------------------------------------------------------
1369 f_pApiInstance Pointer to API instance. This memory is used to keep
1370 the present state of the chip and all its resources.
1371
1372 f_pCmndHeader Pointer to RPC command structure.
1373
1374 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1375 #if !SKIP_Oct6100ApiRpcWriteBurst
1376 VOID Oct6100ApiRpcWriteBurst(
1377 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1378 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1379 {
1380 tPOCT6100_RPC_WRITE_BURST pBurstCommand;
1381 tOCT6100_WRITE_BURST_PARAMS BurstParams;
1382 UINT32 ulResult;
1383 UINT32 ulTempVar;
1384 UINT32 i, j;
1385 PUINT16 pusWriteData;
1386
1387 /* Get local pointer to remote debugging write data buffer. */
1388 mOCT6100_GET_REMOTE_DEBUG_DATA_BUF_PNT( f_pApiInstance->pSharedInfo, pusWriteData )
1389
1390 /* Get pointer to command arguments. */
1391 pBurstCommand = ( tPOCT6100_RPC_WRITE_BURST )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1392
1393 ulTempVar = (pBurstCommand->ulBurstLength + 1) / 2;
1394 for ( i = 0, j = 0; i < ulTempVar; i++ )
1395 {
1396 pusWriteData[ j++ ] = (UINT16)((pBurstCommand->aulWriteData[ i ] >> 16) & 0xFFFF);
1397 pusWriteData[ j++ ] = (UINT16)((pBurstCommand->aulWriteData[ i ] >> 0) & 0xFFFF);
1398 }
1399
1400 /* Set some structure parameters. */
1401 BurstParams.pProcessContext = f_pApiInstance->pProcessContext;
1402
1403 BurstParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
1404
1405 /* Copy parameters from packet payload to local read structure. */
1406 BurstParams.ulWriteAddress = pBurstCommand->ulAddress;
1407 BurstParams.ulWriteLength = pBurstCommand->ulBurstLength;
1408 BurstParams.pusWriteData = pusWriteData;
1409
1410 /* Perform write access. */
1411 mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult )
1412
1413 /* Return result. */
1414 f_pCmndHeader->ulFunctionResult = ulResult;
1415 }
1416 #endif
1417
1418
1419 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1420
1421 Function: Oct6100ApiRpcSetHotChannel
1422
1423 Description: Checks the provided portion of an OCTRPC packet and interprets
1424 it as an cOCT6100_RPC_SET_HOT_CHANNEL command.
1425
1426 -------------------------------------------------------------------------------
1427 | Argument | Description
1428 -------------------------------------------------------------------------------
1429 f_pApiInstance Pointer to API instance. This memory is used to keep
1430 the present state of the chip and all its resources.
1431
1432 f_pCmndHeader Pointer to RPC command structure.
1433
1434 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1435 #if !SKIP_Oct6100ApiRpcSetHotChannel
1436 VOID Oct6100ApiRpcSetHotChannel(
1437 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1438 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1439 {
1440 tPOCT6100_RPC_SET_HOT_CHANNEL pHotChanCommand;
1441 tOCT6100_DEBUG_SELECT_CHANNEL DebugSelectChannel;
1442 tPOCT6100_API_CHANNEL pChanEntry;
1443 UINT32 ulResult;
1444
1445 pHotChanCommand = ( tPOCT6100_RPC_SET_HOT_CHANNEL )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1446
1447 /* Verify if the hot channel index is valid. */
1448 if ( pHotChanCommand->ulHotChannel >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxChannels )
1449 {
1450 f_pCmndHeader->ulFunctionResult = cOCT6100_ERR_REMOTEDEBUG_INVALID_HOT_CHAN_INDEX;
1451 return;
1452 }
1453
1454 mOCT6100_GET_CHANNEL_ENTRY_PNT( f_pApiInstance->pSharedInfo, pChanEntry, pHotChanCommand->ulHotChannel );
1455
1456 DebugSelectChannel.ulChannelHndl = cOCT6100_HNDL_TAG_CHANNEL | (pChanEntry->byEntryOpenCnt << cOCT6100_ENTRY_OPEN_CNT_SHIFT) | pHotChanCommand->ulHotChannel;
1457
1458 /* The PCM law parameter is now obsolete. */
1459 /* The instance knows the law of the channel being recorded! */
1460
1461 /* Call the function. */
1462 ulResult = Oct6100DebugSelectChannelSer( f_pApiInstance, &DebugSelectChannel, FALSE );
1463
1464 /* Return result. */
1465 f_pCmndHeader->ulFunctionResult = ulResult;
1466 }
1467 #endif
1468
1469
1470 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1471
1472 Function: Oct6100ApiRpcGetDebugChanIndex
1473
1474 Description: Checks the provided portion of an OCTRPC packet and interprets
1475 it as an cOCT6100_RPC_GET_DEBUG_CHAN_INDEX command.
1476
1477 -------------------------------------------------------------------------------
1478 | Argument | Description
1479 -------------------------------------------------------------------------------
1480 f_pApiInstance Pointer to API instance. This memory is used to keep
1481 the present state of the chip and all its resources.
1482
1483 f_pCmndHeader Pointer to RPC command structure.
1484
1485 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1486 #if !SKIP_Oct6100ApiRpcGetDebugChanIndex
1487 VOID Oct6100ApiRpcGetDebugChanIndex(
1488 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1489 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader )
1490 {
1491 tPOCT6100_RPC_GET_DEBUG_CHAN_INDEX pDebugChanCommand;
1492
1493 pDebugChanCommand = ( tPOCT6100_RPC_GET_DEBUG_CHAN_INDEX )(( PUINT32 )f_pCmndHeader + (sizeof( tOCTRPC_COMMAND_HEADER ) / 4));
1494
1495 /* Set the debug channel index of the structure. */
1496 pDebugChanCommand->ulDebugChanIndex = f_pApiInstance->pSharedInfo->DebugInfo.usRecordMemIndex;
1497
1498 /* Return result. */
1499 f_pCmndHeader->ulFunctionResult = cOCT6100_ERR_OK;
1500 }
1501 #endif
1502
1503
1504 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1505
1506 Function: Oct6100ApiRpcDisconnect
1507
1508 Description: Destroy the current session.
1509
1510 -------------------------------------------------------------------------------
1511 | Argument | Description
1512 -------------------------------------------------------------------------------
1513 f_pApiInstance Pointer to API instance. This memory is used to keep
1514 the present state of the chip and all its resources.
1515
1516 f_pCmndHeader Pointer to RPC command structure.
1517 f_ulSessionNumber Session number of the current remote debugging session.
1518
1519 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1520 #if !SKIP_Oct6100ApiRpcDisconnect
1521 VOID Oct6100ApiRpcDisconnect(
1522 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1523 IN OUT tPOCTRPC_COMMAND_HEADER f_pCmndHeader,
1524 IN UINT32 f_ulSessionNumber )
1525 {
1526 tPOCT6100_SHARED_INFO pSharedInfo;
1527 tPOCT6100_API_REMOTE_DEBUG_INFO pRemoteDebugInfo;
1528 tPOCT6100_API_REMOTE_DEBUG_SESSION pSessionEntry;
1529 tPOCT6100_API_REMOTE_DEBUG_SESSION pSessionTempEntry;
1530 PVOID pSessionTree;
1531 UINT32 ulResult;
1532 PUINT32 pulTreeData;
1533 UINT32 ulSessionIndex;
1534
1535 f_pCmndHeader->ulFunctionResult = cOCT6100_ERR_OK;
1536
1537 /* Get local pointer(s). */
1538 pSharedInfo = f_pApiInstance->pSharedInfo;
1539
1540 /* Get a local pointer to the remote debugging info. */
1541 pRemoteDebugInfo = &pSharedInfo->RemoteDebugInfo;
1542
1543 /* Check if the session number has an associated session list entry. */
1544 mOCT6100_GET_REMOTE_DEBUG_TREE_PNT( pSharedInfo, pSessionTree )
1545
1546 ulResult = octapi_bt0_query_node( pSessionTree, ( ( PVOID )(&f_ulSessionNumber) ), ( ( PVOID* )&pulTreeData ) );
1547 if ( ulResult != cOCT6100_ERR_OK )
1548 f_pCmndHeader->ulFunctionResult = cOCT6100_ERR_REMOTEDEBUG_INAVLID_SESSION_NUMBER;
1549
1550 /* Return session index. */
1551 ulSessionIndex= *pulTreeData;
1552
1553 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, ulSessionIndex, pSessionEntry );
1554
1555 /* Clear the entry of the session. */
1556 pSessionEntry->aulLastPktTime[ 0 ] = 0;
1557 pSessionEntry->aulLastPktTime[ 1 ] = 0;
1558 pSessionEntry->ulSessionNum = cOCT6100_INVALID_VALUE;
1559 pSessionEntry->ulTransactionNum = cOCT6100_INVALID_VALUE;
1560 pSessionEntry->ulPktRetryNum = cOCT6100_INVALID_VALUE;
1561
1562 /* Update the other entry before removing the node. */
1563 pSessionEntry->ulBackwardLink = pRemoteDebugInfo->ulSessionListTail;
1564 pSessionEntry->ulForwardLink = cOCT6100_INVALID_VALUE;
1565
1566 if ( pSessionEntry->ulBackwardLink != cOCT6100_INVALID_VALUE )
1567 {
1568 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulBackwardLink, pSessionTempEntry );
1569 pSessionTempEntry->ulForwardLink = pSessionEntry->ulForwardLink;
1570 }
1571 else /* pSessionEntry->ulBackwardLink == cOCT6100_INVALID_VALUE */
1572 {
1573 pRemoteDebugInfo->ulSessionListHead = pSessionEntry->ulForwardLink;
1574 }
1575
1576 if ( pSessionEntry->ulForwardLink != cOCT6100_INVALID_VALUE )
1577 {
1578 mOCT6100_GET_REMOTE_DEBUG_LIST_ENTRY_PNT( pSharedInfo, pSessionEntry->ulForwardLink, pSessionTempEntry );
1579 pSessionTempEntry->ulBackwardLink = pSessionEntry->ulBackwardLink;
1580 }
1581 else /* pSessionEntry->ulForwardLink == cOCT6100_INVALID_VALUE */
1582 {
1583 pRemoteDebugInfo->ulSessionListTail = pSessionEntry->ulBackwardLink;
1584 }
1585
1586 /* Invalidate the pointer. */
1587 pSessionEntry->ulBackwardLink = cOCT6100_INVALID_VALUE;
1588 pSessionEntry->ulForwardLink = cOCT6100_INVALID_VALUE;
1589
1590 /* Remove the session. */
1591 ulResult = octapi_bt0_remove_node( pSessionTree, ( ( PVOID )&f_ulSessionNumber ) );
1592 if ( ulResult != cOCT6100_ERR_OK )
1593 f_pCmndHeader->ulFunctionResult = cOCT6100_ERR_FATAL_47;
1594
1595 /* Increment number of open sessions. */
1596 pRemoteDebugInfo->ulNumSessionsOpen--;
1597 }
1598 #endif