1
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
5
Copyright (c) 2001-2006 Octasic Inc.
9
This file contains functions used to debug the OCT6100.
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.
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
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.
25
$Octasic_Release: OCT612xAPI-01.00-PR43 $
27
$Octasic_Revision: 63 $
29
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
32
/***************************** INCLUDE FILES *******************************/
36
#include "oct6100api/oct6100_defines.h"
37
#include "oct6100api/oct6100_errors.h"
38
#include "oct6100api/oct6100_apiud.h"
40
#include "oct6100api/oct6100_apiud.h"
41
#include "oct6100api/oct6100_tlv_inst.h"
42
#include "oct6100api/oct6100_chip_open_inst.h"
43
#include "oct6100api/oct6100_chip_stats_inst.h"
44
#include "oct6100api/oct6100_interrupts_inst.h"
45
#include "oct6100api/oct6100_remote_debug_inst.h"
46
#include "oct6100api/oct6100_debug_inst.h"
47
#include "oct6100api/oct6100_api_inst.h"
48
#include "oct6100api/oct6100_channel_inst.h"
50
#include "oct6100api/oct6100_interrupts_pub.h"
51
#include "oct6100api/oct6100_chip_open_pub.h"
52
#include "oct6100api/oct6100_channel_pub.h"
53
#include "oct6100api/oct6100_debug_pub.h"
55
#include "oct6100_chip_open_priv.h"
56
#include "oct6100_channel_priv.h"
57
#include "oct6100_miscellaneous_priv.h"
58
#include "oct6100_memory_priv.h"
59
#include "oct6100_debug_priv.h"
60
#include "oct6100_version.h"
63
/**************************** PUBLIC FUNCTIONS ****************************/
66
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
68
Function: Oct6100DebugSelectChannel
70
Description: This function sets the current debug channel.
72
-------------------------------------------------------------------------------
73
| Argument | Description
74
-------------------------------------------------------------------------------
75
f_pApiInstance Pointer to API instance. This memory is used to keep the
76
present state of the chip and all its resources.
78
f_pSelectDebugChan Pointer to select debug channel structure.
80
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
81
#if !SKIP_Oct6100DebugSelectChannelDef
82
UINT32 Oct6100DebugSelectChannelDef(
83
tPOCT6100_DEBUG_SELECT_CHANNEL f_pSelectDebugChan )
85
f_pSelectDebugChan->ulChannelHndl = cOCT6100_INVALID_VALUE;
87
return cOCT6100_ERR_OK;
91
#if !SKIP_Oct6100DebugSelectChannel
92
UINT32 Oct6100DebugSelectChannel(
93
tPOCT6100_INSTANCE_API f_pApiInstance,
94
tPOCT6100_DEBUG_SELECT_CHANNEL f_pSelectDebugChan )
96
tOCT6100_SEIZE_SERIALIZE_OBJECT SeizeSerObj;
97
tOCT6100_RELEASE_SERIALIZE_OBJECT ReleaseSerObj;
98
UINT32 ulSerRes = cOCT6100_ERR_OK;
99
UINT32 ulFncRes = cOCT6100_ERR_OK;
101
/* Set the process context of the serialize structure. */
102
SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
103
ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
105
/* Seize all list semaphores needed by this function. */
106
SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
107
SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
108
ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
109
if ( ulSerRes == cOCT6100_ERR_OK )
111
/* Call the serialized function. */
112
ulFncRes = Oct6100DebugSelectChannelSer( f_pApiInstance, f_pSelectDebugChan, TRUE );
119
/* Release the seized semaphores. */
120
ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
121
ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
123
/* If an error occured then return the error code. */
124
if ( ulSerRes != cOCT6100_ERR_OK )
126
if ( ulFncRes != cOCT6100_ERR_OK )
129
return cOCT6100_ERR_OK;
134
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
136
Function: Oct6100DebugGetData
138
Description: This function retrieves the last recorded debug data.
140
-------------------------------------------------------------------------------
141
| Argument | Description
142
-------------------------------------------------------------------------------
143
f_pApiInstance Pointer to API instance. This memory is used to keep the
144
present state of the chip and all its resources.
146
f_pGetData Pointer to debug get data structure.
148
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
149
#if !SKIP_Oct6100DebugGetDataDef
150
UINT32 Oct6100DebugGetDataDef(
151
tPOCT6100_DEBUG_GET_DATA f_pGetData )
153
f_pGetData->ulGetDataMode = cOCT6100_DEBUG_GET_DATA_MODE_120S_LITE;
154
f_pGetData->ulGetDataContent = cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE;
155
f_pGetData->ulRemainingNumBytes = cOCT6100_INVALID_VALUE;
156
f_pGetData->ulTotalNumBytes = cOCT6100_INVALID_VALUE;
157
f_pGetData->ulMaxBytes = cOCT6100_INVALID_VALUE;
158
f_pGetData->ulValidNumBytes = cOCT6100_INVALID_VALUE;
159
f_pGetData->pbyData = NULL;
161
return cOCT6100_ERR_OK;
165
#if !SKIP_Oct6100DebugGetData
166
UINT32 Oct6100DebugGetData(
167
tPOCT6100_INSTANCE_API f_pApiInstance,
168
tPOCT6100_DEBUG_GET_DATA f_pGetData )
170
tOCT6100_SEIZE_SERIALIZE_OBJECT SeizeSerObj;
171
tOCT6100_RELEASE_SERIALIZE_OBJECT ReleaseSerObj;
172
UINT32 ulSerRes = cOCT6100_ERR_OK;
173
UINT32 ulFncRes = cOCT6100_ERR_OK;
175
/* Set the process context of the serialize structure. */
176
SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
177
ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
179
/* Seize all list semaphores needed by this function. */
180
SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
181
SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
182
ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
183
if ( ulSerRes == cOCT6100_ERR_OK )
185
/* Call the serialized function. */
186
ulFncRes = Oct6100DebugGetDataSer( f_pApiInstance, f_pGetData );
193
/* Release the seized semaphores. */
194
ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
195
ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
197
/* If an error occured then return the error code. */
198
if ( ulSerRes != cOCT6100_ERR_OK )
200
if ( ulFncRes != cOCT6100_ERR_OK )
203
return cOCT6100_ERR_OK;
208
/**************************** PRIVATE FUNCTIONS ****************************/
210
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
212
Function: Oct6100DebugSelectChannelSer
214
Description: This function sets the debug channel.
216
-------------------------------------------------------------------------------
217
| Argument | Description
218
-------------------------------------------------------------------------------
219
f_pApiInstance Pointer to API instance. This memory is used to keep the
220
present state of the chip and all its resources.
222
f_pSelectDebugChan Pointer to a tOCT6100_DEBUG_SELECT_CHANNEL structure.
223
f_fCheckChannelRecording Check if channel recording is enabled or not.
225
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
226
#if !SKIP_Oct6100DebugSelectChannelSer
227
UINT32 Oct6100DebugSelectChannelSer(
228
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
229
IN tPOCT6100_DEBUG_SELECT_CHANNEL f_pSelectDebugChan,
230
IN BOOL f_fCheckChannelRecording )
232
tPOCT6100_SHARED_INFO pSharedInfo;
233
tPOCT6100_API_CHANNEL pChanEntry = NULL;
234
tPOCT6100_API_CHANNEL pTempChanEntry;
235
tOCT6100_CHANNEL_OPEN TempChanOpen;
236
UINT16 usChanIndex = 0;
237
UINT32 ulEntryOpenCnt;
239
tOCT6100_WRITE_BURST_PARAMS BurstParams;
240
UINT16 ausWriteData[ 2 ];
243
/* Get local pointer(s). */
244
pSharedInfo = f_pApiInstance->pSharedInfo;
246
BurstParams.pProcessContext = f_pApiInstance->pProcessContext;
248
BurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
249
BurstParams.pusWriteData = ausWriteData;
251
/* First release the resources reserved for the channel that was previously debugged. */
252
if ( pSharedInfo->DebugInfo.usCurrentDebugChanIndex != cOCT6100_INVALID_INDEX &&
253
pSharedInfo->ChipConfig.fEnableChannelRecording == TRUE )
255
/*=======================================================================*/
256
/* Get a pointer to the channel's list entry. */
258
mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pTempChanEntry, pSharedInfo->DebugInfo.usCurrentDebugChanIndex )
260
/* Release the extra TSI memory entry and reprogram the TSST control memory if required. */
261
if ( pTempChanEntry->usExtraSinTsiDependencyCnt == 1 )
263
/*=======================================================================*/
264
/* Clear memcpy operations. */
266
BurstParams.ulWriteAddress = cOCT6100_MIXER_CONTROL_MEM_BASE + ( pSharedInfo->MixerInfo.usRecordCopyEventIndex * cOCT6100_MIXER_CONTROL_MEM_ENTRY_SIZE );
267
BurstParams.ulWriteLength = 2;
269
ausWriteData[ 0 ] = cOCT6100_MIXER_CONTROL_MEM_NO_OP;
270
ausWriteData[ 1 ] = 0x0;
272
mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
273
if ( ulResult != cOCT6100_ERR_OK )
276
BurstParams.ulWriteAddress = cOCT6100_MIXER_CONTROL_MEM_BASE + ( pSharedInfo->MixerInfo.usRecordSinEventIndex * cOCT6100_MIXER_CONTROL_MEM_ENTRY_SIZE );
278
mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
279
if ( ulResult != cOCT6100_ERR_OK )
282
/*=======================================================================*/
284
ulResult = Oct6100ApiReleaseTsiMemEntry( f_pApiInstance, pTempChanEntry->usExtraSinTsiMemIndex );
285
if ( ulResult != cOCT6100_ERR_OK )
288
if ( pTempChanEntry->usSinTsstIndex != cOCT6100_INVALID_INDEX )
290
ulResult = Oct6100ApiWriteInputTsstControlMemory( f_pApiInstance,
291
pTempChanEntry->usSinTsstIndex,
292
pTempChanEntry->usSinSoutTsiMemIndex,
293
pTempChanEntry->TdmConfig.bySinPcmLaw );
296
if ( ulResult != cOCT6100_ERR_OK )
299
pTempChanEntry->usExtraSinTsiDependencyCnt--;
300
pTempChanEntry->usExtraSinTsiMemIndex = cOCT6100_INVALID_INDEX;
304
/* Set the new parameters. */
305
if ( f_pSelectDebugChan->ulChannelHndl != cOCT6100_INVALID_HANDLE )
307
/* Check the provided handle. */
308
if ( (f_pSelectDebugChan->ulChannelHndl & cOCT6100_HNDL_TAG_MASK) != cOCT6100_HNDL_TAG_CHANNEL )
309
return cOCT6100_ERR_DEBUG_CHANNEL_INVALID_HANDLE;
311
usChanIndex = (UINT16)( f_pSelectDebugChan->ulChannelHndl & cOCT6100_HNDL_INDEX_MASK );
312
if ( usChanIndex >= pSharedInfo->ChipConfig.usMaxChannels )
313
return cOCT6100_ERR_DEBUG_CHANNEL_INVALID_HANDLE;
315
if ( f_fCheckChannelRecording == TRUE )
317
if ( pSharedInfo->ChipConfig.fEnableChannelRecording == FALSE )
318
return cOCT6100_ERR_DEBUG_CHANNEL_RECORDING_DISABLED;
321
/*=======================================================================*/
322
/* Get a pointer to the channel's list entry. */
324
mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pChanEntry, usChanIndex );
326
/* Extract the entry open count from the provided handle. */
327
ulEntryOpenCnt = ( f_pSelectDebugChan->ulChannelHndl >> cOCT6100_ENTRY_OPEN_CNT_SHIFT) & cOCT6100_ENTRY_OPEN_CNT_MASK;
329
/* Check for errors. */
330
if ( pChanEntry->fReserved != TRUE )
331
return cOCT6100_ERR_CHANNEL_NOT_OPEN;
332
if ( ulEntryOpenCnt != pChanEntry->byEntryOpenCnt )
333
return cOCT6100_ERR_CHANNEL_INVALID_HANDLE;
335
/*=======================================================================*/
337
/* First program the mixer entry if the user wants to record. */
338
/* Check if the API needs to reserve an extra TSI memory to load the SIN signal. */
339
if ( pSharedInfo->ChipConfig.fEnableChannelRecording == TRUE )
341
if ( pChanEntry->usExtraSinTsiMemIndex == cOCT6100_INVALID_INDEX )
343
ulResult = Oct6100ApiReserveTsiMemEntry( f_pApiInstance, &pChanEntry->usExtraSinTsiMemIndex );
344
if ( ulResult != cOCT6100_ERR_OK )
347
if ( pChanEntry->usSinTsstIndex != cOCT6100_INVALID_INDEX )
349
ulResult = Oct6100ApiWriteInputTsstControlMemory( f_pApiInstance,
350
pChanEntry->usSinTsstIndex,
351
pChanEntry->usExtraSinTsiMemIndex,
352
pChanEntry->TdmConfig.bySinPcmLaw );
353
if ( ulResult != cOCT6100_ERR_OK )
359
/*=======================================================================*/
360
/* Program the Sout Copy event. */
361
BurstParams.ulWriteAddress = cOCT6100_MIXER_CONTROL_MEM_BASE + ( pSharedInfo->MixerInfo.usRecordCopyEventIndex * cOCT6100_MIXER_CONTROL_MEM_ENTRY_SIZE );
362
BurstParams.ulWriteLength = 2;
364
ausWriteData[ 0 ] = cOCT6100_MIXER_CONTROL_MEM_COPY;
365
ausWriteData[ 0 ] |= pChanEntry->usSinSoutTsiMemIndex;
366
ausWriteData[ 0 ] |= pChanEntry->TdmConfig.bySinPcmLaw << cOCT6100_MIXER_CONTROL_MEM_LAW_OFFSET;
367
ausWriteData[ 1 ] = (UINT16)( pSharedInfo->DebugInfo.usRecordRinRoutTsiMemIndex );
369
mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
370
if ( ulResult != cOCT6100_ERR_OK )
372
/*=======================================================================*/
374
/*=======================================================================*/
375
/* Program the Sin copy event. */
376
BurstParams.ulWriteAddress = cOCT6100_MIXER_CONTROL_MEM_BASE + ( pSharedInfo->MixerInfo.usRecordSinEventIndex * cOCT6100_MIXER_CONTROL_MEM_ENTRY_SIZE );
377
BurstParams.ulWriteLength = 2;
379
ausWriteData[ 0 ] = cOCT6100_MIXER_CONTROL_MEM_COPY;
380
ausWriteData[ 0 ] |= pChanEntry->usExtraSinTsiMemIndex;
381
ausWriteData[ 0 ] |= pChanEntry->TdmConfig.bySinPcmLaw << cOCT6100_MIXER_CONTROL_MEM_LAW_OFFSET;
382
ausWriteData[ 1 ] = pChanEntry->usSinSoutTsiMemIndex;
384
mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
385
if ( ulResult != cOCT6100_ERR_OK )
387
/*=======================================================================*/
389
pChanEntry->usExtraSinTsiDependencyCnt++;
394
/* Set the index to invalid to deactivate the recording. */
395
usChanIndex = cOCT6100_INVALID_INDEX;
398
/* Set law of newly selected hot channel. */
399
if ( ( pSharedInfo->ChipConfig.fEnableChannelRecording == TRUE )
400
&& ( f_pSelectDebugChan->ulChannelHndl != cOCT6100_INVALID_HANDLE )
401
&& ( pChanEntry != NULL ) )
403
/* Set the PCM law of the debug channel. */
404
/* Let's program the channel memory. */
405
Oct6100ChannelOpenDef( &TempChanOpen );
407
TempChanOpen.ulEchoOperationMode = cOCT6100_ECHO_OP_MODE_HT_RESET; /* Activate the channel. */
408
TempChanOpen.VqeConfig.fEnableNlp = FALSE;
409
TempChanOpen.VqeConfig.ulComfortNoiseMode = cOCT6100_COMFORT_NOISE_NORMAL;
410
TempChanOpen.VqeConfig.fSinDcOffsetRemoval = FALSE;
411
TempChanOpen.VqeConfig.fRinDcOffsetRemoval = FALSE;
412
TempChanOpen.VqeConfig.lDefaultErlDb = 0;
414
/* Use the law of the channel being recorded. */
415
TempChanOpen.TdmConfig.ulRinPcmLaw = pChanEntry->TdmConfig.byRinPcmLaw;
416
TempChanOpen.TdmConfig.ulSinPcmLaw = pChanEntry->TdmConfig.bySinPcmLaw;
417
TempChanOpen.TdmConfig.ulRoutPcmLaw = pChanEntry->TdmConfig.byRoutPcmLaw;
418
TempChanOpen.TdmConfig.ulSoutPcmLaw = pChanEntry->TdmConfig.bySoutPcmLaw;
420
ulResult = Oct6100ApiWriteDebugChanMemory( f_pApiInstance,
421
&TempChanOpen.TdmConfig,
422
&TempChanOpen.VqeConfig,
424
pSharedInfo->DebugInfo.usRecordChanIndex,
425
pSharedInfo->DebugInfo.usRecordMemIndex,
426
pSharedInfo->DebugInfo.usRecordRinRoutTsiMemIndex,
427
pSharedInfo->DebugInfo.usRecordSinSoutTsiMemIndex );
428
if ( ulResult != cOCT6100_ERR_OK )
432
ausWriteData[ 0 ] = 0x0;
433
ausWriteData[ 1 ] = (UINT16)(( usChanIndex >> 0) & 0xFFFF);
435
/* Write the channel number into the Matrix hot channel field.*/
436
BurstParams.ulWriteAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
437
BurstParams.pusWriteData = ausWriteData;
438
BurstParams.ulWriteLength = 2;
440
mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
441
if ( ulResult != cOCT6100_ERR_OK )
444
pSharedInfo->DebugInfo.usCurrentDebugChanIndex = usChanIndex;
446
/* Cancel data dump request, if there was one. */
447
pSharedInfo->DebugInfo.fDebugDataBeingDumped = FALSE;
448
pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes = cOCT6100_INVALID_VALUE;
450
/* Call from remote client. */
451
if ( f_fCheckChannelRecording == FALSE )
453
/* If the user has not activated recording, let the remote client know. */
454
if ( pSharedInfo->ChipConfig.fEnableChannelRecording == FALSE )
455
return cOCT6100_ERR_DEBUG_RC_CHANNEL_RECORDING_DISABLED;
458
return cOCT6100_ERR_OK;
463
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
465
Function: Oct6100DebugGetDataSer
467
Description: This function retrieves the latest recorded debug data.
469
-------------------------------------------------------------------------------
470
| Argument | Description
471
-------------------------------------------------------------------------------
472
f_pApiInstance Pointer to API instance. This memory is used to keep the
473
present state of the chip and all its resources.
475
f_pGetData Pointer to a tOCT6100_DEBUG_GET_DATA structure.
477
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
478
#if !SKIP_Oct6100DebugGetDataSer
479
UINT32 Oct6100DebugGetDataSer(
480
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
481
IN OUT tPOCT6100_DEBUG_GET_DATA f_pGetData )
484
tPOCT6100_SHARED_INFO pSharedInfo;
485
tPOCT6100_API_CHANNEL pChanEntry = NULL;
486
tOCT6100_READ_PARAMS ReadParams;
487
tOCT6100_WRITE_PARAMS WriteParams;
488
tOCT6100_READ_BURST_PARAMS ReadBurstParams;
489
tOCT6100_WRITE_BURST_PARAMS WriteBurstParams;
491
UINT16 ausWriteData[ 2 ];
493
UINT16 usDebugEventReadPtr;
496
UINT32 ulToneEventIndex;
497
UINT32 ulReadPointer;
498
UINT32 ulUserBufWriteIndex = 0;
500
UINT32 ulDebugEventIndex = 0;
501
UINT32 ulStreamIndex;
502
UINT32 ulPcmSampleIndex;
503
UINT32 ulNumAfEvents;
504
UINT32 ulNumReads = 0;
507
UINT32 ulFeatureBytesOffset;
508
UINT32 ulFeatureBitOffset;
509
UINT32 ulFeatureFieldLength;
510
UINT32 ulStreamIndexMin;
511
UINT32 ulStreamIndexMax;
514
BOOL fResetRemainingDataFlag = FALSE;
516
/* Get local pointer(s). */
517
pSharedInfo = f_pApiInstance->pSharedInfo;
519
ReadBurstParams.pProcessContext = f_pApiInstance->pProcessContext;
521
ReadBurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
523
ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
525
ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
527
WriteBurstParams.pProcessContext = f_pApiInstance->pProcessContext;
529
WriteBurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
531
WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
533
WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
535
/* Check all user parameters. */
537
/* Check if channel recording is enabled. */
538
if ( pSharedInfo->ChipConfig.fEnableChannelRecording == FALSE )
539
return cOCT6100_ERR_DEBUG_CHANNEL_RECORDING_DISABLED;
541
/* Check if a current debugging channel has been selected. */
542
/* If not, the user has not yet called Oct6100DebugSelectChannel. */
543
if ( pSharedInfo->DebugInfo.usCurrentDebugChanIndex == cOCT6100_INVALID_INDEX )
544
return cOCT6100_ERR_DEBUG_RECORD_NO_CHAN_SELECTED;
546
/* Check that the user supplied a valid max bytes value. */
547
if ( f_pGetData->ulMaxBytes == cOCT6100_INVALID_VALUE )
548
return cOCT6100_ERR_DEBUG_GET_DATA_MAX_BYTES;
550
/* Data buffer must be aligned on 1024 bytes. */
551
if ( ( f_pGetData->ulMaxBytes % 1024 ) != 0 )
552
return cOCT6100_ERR_DEBUG_GET_DATA_MAX_BYTES;
554
/* Check that the user provided the required memory to transfer the information. */
555
if ( f_pGetData->pbyData == NULL )
556
return cOCT6100_ERR_DEBUG_GET_DATA_PTR_INVALID;
558
/* Check dump type. */
559
if ( ( f_pGetData->ulGetDataMode != cOCT6100_DEBUG_GET_DATA_MODE_16S_LITE )
560
&& ( f_pGetData->ulGetDataMode != cOCT6100_DEBUG_GET_DATA_MODE_120S_LITE )
561
&& ( f_pGetData->ulGetDataMode != cOCT6100_DEBUG_GET_DATA_MODE_16S )
562
&& ( f_pGetData->ulGetDataMode != cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
563
return cOCT6100_ERR_DEBUG_GET_DATA_MODE;
565
/* Check dump content. */
566
if ( ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
567
&& ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_RIN_PCM )
568
&& ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_SIN_PCM )
569
&& ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_SOUT_PCM ) )
570
return cOCT6100_ERR_DEBUG_GET_DATA_CONTENT;
572
/* Check if can accomodate the 120 seconds dump. */
573
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S_LITE )
574
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
576
if ( pSharedInfo->DebugInfo.ulDebugEventSize != 0x100 )
577
return cOCT6100_ERR_NOT_SUPPORTED_DEBUG_DATA_MODE_120S;
580
mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pChanEntry, pSharedInfo->DebugInfo.usCurrentDebugChanIndex )
582
/* Lets go dump the requested data. */
584
usDebugEventReadPtr = 0;
586
/* Check if this is the first time this function is called since the hot channel was set. */
587
if ( pSharedInfo->DebugInfo.fDebugDataBeingDumped == FALSE )
589
/* Check that the channel is not in POWER_DOWN. When the channel is in POWER_DOWN, */
590
/* the debug events are not recorded correctly in external memory. */
591
if ( pChanEntry->byEchoOperationMode == cOCT6100_ECHO_OP_MODE_POWER_DOWN )
592
return cOCT6100_ERR_DEBUG_CHANNEL_IN_POWER_DOWN;
594
pSharedInfo->DebugInfo.fDebugDataBeingDumped = TRUE;
596
/* Flag the hot channel that it must stop recording. The data is being transfered. */
597
/* This also tells the remote client not to do anything right now. */
599
ReadBurstParams.ulReadAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
600
ReadBurstParams.ulReadLength = 2;
601
ReadBurstParams.pusReadData = pSharedInfo->DebugInfo.ausHotChannelData;
603
mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
604
if ( ulResult != cOCT6100_ERR_OK )
607
WriteBurstParams.pusWriteData = ausWriteData;
608
WriteBurstParams.ulWriteAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
609
WriteBurstParams.ulWriteLength = 2;
611
WriteBurstParams.pusWriteData[ 0 ] = 0xFFFF;
612
WriteBurstParams.pusWriteData[ 1 ] = 0xFFFF;
614
mOCT6100_DRIVER_WRITE_BURST_API( WriteBurstParams, ulResult );
615
if ( ulResult != cOCT6100_ERR_OK )
618
/* Get the maximum number of events this firmware supports from the TLVs. */
619
pSharedInfo->DebugInfo.usMatrixCBMask = (UINT16)( pSharedInfo->DebugInfo.ulDebugEventSize & 0xFFFF );
620
pSharedInfo->DebugInfo.usMatrixCBMask -= 1;
622
/* Find out the chip log write pointer. */
624
/* Now get the current write pointer for matrix events. */
625
ReadParams.pusReadData = &pSharedInfo->DebugInfo.usChipDebugEventWritePtr;
626
ReadParams.ulReadAddress = pSharedInfo->DebugInfo.ulMatrixWpBaseAddress + 2;
628
mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
629
if ( ulResult != cOCT6100_ERR_OK )
632
ReadParams.pusReadData = &usReadData;
634
/* This write pointer might have wrapped, but we don't know for sure. */
635
/* To be confident, the chip frame timestamp is read. */
636
ReadParams.ulReadAddress = pSharedInfo->DebugInfo.ulMatrixTimestampBaseAddress;
638
mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
639
if ( ulResult != cOCT6100_ERR_OK )
642
ulTimestamp = usReadData << 16;
644
ReadParams.ulReadAddress += 2;
646
mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
647
if ( ulResult != cOCT6100_ERR_OK )
650
ulTimestamp |= usReadData;
653
if ( ulTimestamp < (UINT32)( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) )
655
if ( pSharedInfo->DebugInfo.usChipDebugEventWritePtr >= 2 )
657
/* Must trash the first 2 events. The chip is not yet ready. */
658
pSharedInfo->DebugInfo.usNumEvents = (UINT16)( pSharedInfo->DebugInfo.usChipDebugEventWritePtr - 2 );
662
pSharedInfo->DebugInfo.usNumEvents = 0x0;
667
pSharedInfo->DebugInfo.usNumEvents = (UINT16)( pSharedInfo->DebugInfo.usMatrixCBMask + 1 );
669
/* Account for event being created right now while the chip is running. */
670
/* The event at the write pointer will be discarded. */
671
if ( pSharedInfo->DebugInfo.usNumEvents > 0 )
672
pSharedInfo->DebugInfo.usNumEvents--;
675
/* If the user only requested the last 16 seconds, cap the number of events. */
676
if ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S
677
|| f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S_LITE )
679
/* x events to get the last 16 seconds. */
680
if ( pSharedInfo->DebugInfo.usNumEvents > ( 16000 / ( pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize / 8 ) ) )
681
pSharedInfo->DebugInfo.usNumEvents = (UINT16)( ( 16000 / ( pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize / 8 ) ) & 0xFFFF );
684
/* In heavy mode, the AF log pointer is retrieved. */
685
if ( ( pSharedInfo->DebugInfo.usNumEvents >= 2 )
686
&& ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
687
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) ) )
689
/* The latest AF log write pointer is at the latest matrix event. */
690
ReadParams.ulReadAddress = pSharedInfo->DebugInfo.ulMatrixBaseAddress + ( ( pSharedInfo->DebugInfo.usChipDebugEventWritePtr & pSharedInfo->DebugInfo.usMatrixCBMask ) * 1024 );
692
/* To get the AF log write pointer, which is at offset pSharedInfo->ImageInfo.ulAfWritePtrByteOffset. */
693
ReadParams.ulReadAddress += pSharedInfo->DebugInfo.ulAfWritePtrByteOffset;
694
mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
695
if ( ulResult != cOCT6100_ERR_OK )
698
pSharedInfo->DebugInfo.usAfLogWritePtr = usReadData;
700
/* The AF event read pointer is the AF write pointer +4096 */
701
/* This will make sure we do not get mixed up and fetch events that have */
702
/* just been written, but we think are old. */
704
/* To get the exact AF log pointer, the API would have to wait 512 milliseconds to make */
705
/* sure logging had stopped. This is not required since missing a few last events is not */
706
/* important at this point (the user knows that valid data has already been recorded). */
707
pSharedInfo->DebugInfo.usLastAfLogReadPtr = (UINT16)( ( pSharedInfo->DebugInfo.usAfLogWritePtr + 4096 ) & 0xFFFF );
709
/* Note that if the chip has just been booted, some of the AF events might not be initialized. */
713
pSharedInfo->DebugInfo.usLastAfLogReadPtr = 0;
714
pSharedInfo->DebugInfo.usAfLogWritePtr = 0;
717
/* To be aligned correctly for the bursts. */
718
while ( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) ) != 0 )
719
pSharedInfo->DebugInfo.usLastAfLogReadPtr++;
721
/* Remember the data mode for later checks. Also, the user cannot change this "mode". */
722
pSharedInfo->DebugInfo.ulCurrentGetDataMode = f_pGetData->ulGetDataMode;
726
/* Check that the user did not change the current data mode. */
727
if ( pSharedInfo->DebugInfo.ulCurrentGetDataMode != f_pGetData->ulGetDataMode )
728
return cOCT6100_ERR_DEBUG_GET_DATA_MODE_CANNOT_CHANGE;
731
/* Check if this is the first pass here. */
732
if ( pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes == cOCT6100_INVALID_VALUE )
734
/* Calculate how many bytes of data will be returned with respect to the selected data content. */
736
/* Check what content type the user requested. */
737
if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
739
/* Remember first AF Event Read Pointer. */
740
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr ) & 0xFF );
741
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr >> 8 ) & 0xFF );
743
/* Remember the AF Event Write Pointer. */
744
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usAfLogWritePtr ) & 0xFF );
745
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usAfLogWritePtr >> 8 ) & 0xFF );
747
/* Remember law and hot channel */
748
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( pChanEntry->TdmConfig.bySinPcmLaw | ( ( pSharedInfo->DebugInfo.usCurrentDebugChanIndex >> 2 ) & 0xFE ) );
749
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( pChanEntry->TdmConfig.bySoutPcmLaw );
751
/* Insert light or heavy mode in array. */
752
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S_LITE )
753
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S_LITE ) )
755
f_pGetData->pbyData[ ulUserBufWriteIndex - 1 ] |= 0x80;
757
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( pChanEntry->TdmConfig.byRinPcmLaw | ( ( pSharedInfo->DebugInfo.usCurrentDebugChanIndex & 0x1F ) << 3 ) );
759
/* Remember usNumEvents */
760
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usNumEvents ) & 0xFF );
761
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usNumEvents >> 8 ) & 0xFF );
764
/* Last indexes set to '0'! */
765
pSharedInfo->DebugInfo.usLastDebugEventIndex = 0;
766
pSharedInfo->DebugInfo.ulLastPcmSampleIndex = 0;
768
/* No tone event has been retrieved. */
769
pSharedInfo->DebugInfo.usLastToneEventIndex = 0;
771
/* The version strings have not yet been copied. */
772
pSharedInfo->DebugInfo.fImageVersionCopied = FALSE;
773
pSharedInfo->DebugInfo.fApiVersionCopied = FALSE;
775
/* Estimate the total size of the buffer that will be returned. */
776
f_pGetData->ulTotalNumBytes = ulUserBufWriteIndex;
778
/* If the full content is requested, add all the debug data. */
779
if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
781
/* Add the matrix events. */
782
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
783
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
785
/* Heavy mode! Grab everything! */
786
f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize;
790
/* Lite mode! Only the most important stuff. */
791
f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize;
794
/* Add the PCM samples. */
795
f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize * 3;
797
/* If requested, add the AF log events. */
798
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
799
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
801
f_pGetData->ulTotalNumBytes += (UINT32)( ( pSharedInfo->DebugInfo.usAfLogWritePtr - pSharedInfo->DebugInfo.usLastAfLogReadPtr ) & 0xFFFF ) * 16;
804
/* Add the tone events strings. */
805
f_pGetData->ulTotalNumBytes += cOCT6100_TLV_MAX_TONE_NAME_SIZE * pSharedInfo->ImageInfo.byNumToneDetectors;
807
/* Add the image version string. */
808
f_pGetData->ulTotalNumBytes += 512;
810
/* Add the API version string. */
811
f_pGetData->ulTotalNumBytes += sizeof( cOCT6100_API_VERSION );
813
else /* if ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) */
815
/* Add one PCM stream. */
816
f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize;
819
/* Save this in the instance for further calls. */
820
pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes = f_pGetData->ulTotalNumBytes;
822
/* Calculate remaining bytes. All the bytes for now! */
823
f_pGetData->ulRemainingNumBytes = f_pGetData->ulTotalNumBytes;
825
/* Save this in the instance for the next calls. */
826
pSharedInfo->DebugInfo.ulDebugDataRemainingNumBytes = f_pGetData->ulRemainingNumBytes;
830
f_pGetData->ulTotalNumBytes = pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes;
833
/* Calculate the event read pointer. */
834
ulReadPointer = ( ( pSharedInfo->DebugInfo.usChipDebugEventWritePtr - pSharedInfo->DebugInfo.usNumEvents ) & pSharedInfo->DebugInfo.usMatrixCBMask ) * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize;
836
ulReadPointer += pSharedInfo->DebugInfo.ulDebugChanStatsByteSize * pSharedInfo->DebugInfo.usLastDebugEventIndex;
837
ulReadPointer %= ( ( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize );
839
if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
841
/* Copy the debug events in the user buffer. */
842
for( ulDebugEventIndex = pSharedInfo->DebugInfo.usLastDebugEventIndex; ulDebugEventIndex < pSharedInfo->DebugInfo.usNumEvents; ulDebugEventIndex ++ )
844
ReadBurstParams.ulReadAddress = pSharedInfo->DebugInfo.ulMatrixBaseAddress + ulReadPointer;
846
/* Check if we are in light or heavy mode. The burst size is not the same. */
847
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
848
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
850
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= pSharedInfo->DebugInfo.ulDebugChanStatsByteSize )
851
ulNumReads = pSharedInfo->DebugInfo.ulDebugChanStatsByteSize / 2;
857
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize )
858
ulNumReads = pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize / 2;
864
while ( ulNumReads != 0 )
866
if ( ulNumReads >= pSharedInfo->ChipConfig.usMaxRwAccesses )
867
ReadBurstParams.ulReadLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
869
ReadBurstParams.ulReadLength = ulNumReads;
871
/* Set pointer where to write data. */
872
ReadBurstParams.pusReadData = pSharedInfo->MiscVars.ausSuperArray;
874
mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
875
if ( ulResult != cOCT6100_ERR_OK )
878
/* Copy data byte per byte to avoid endianess problems. */
879
for ( ulCopyIndex = 0; ulCopyIndex < ReadBurstParams.ulReadLength; ulCopyIndex ++ )
881
f_pGetData->pbyData[ ulUserBufWriteIndex + ulTempIndex + ( 2 * ulCopyIndex ) ] = (UINT8)( ReadBurstParams.pusReadData[ ulCopyIndex ] & 0xFF );
882
f_pGetData->pbyData[ ulUserBufWriteIndex + ulTempIndex + ( 2 * ulCopyIndex ) + 1 ] = (UINT8)( ( ReadBurstParams.pusReadData[ ulCopyIndex ] >> 8 ) & 0xFF );
885
/* Update indexes, temp variables, addresses. */
886
ulNumReads -= ReadBurstParams.ulReadLength;
887
ulTempIndex += ReadBurstParams.ulReadLength * 2;
888
ReadBurstParams.ulReadAddress += ReadBurstParams.ulReadLength * 2;
891
/* Store register 0x202 in the event structure. */
892
f_pGetData->pbyData[ ulUserBufWriteIndex + 255 ] = (UINT8)( pSharedInfo->IntrptManage.usRegister202h & 0xFF );
893
f_pGetData->pbyData[ ulUserBufWriteIndex + 256 ] = (UINT8)( ( pSharedInfo->IntrptManage.usRegister202h >> 8 ) & 0xFF );
895
/* Increment index. */
896
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
897
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
899
ulUserBufWriteIndex += pSharedInfo->DebugInfo.ulDebugChanStatsByteSize;
903
ulUserBufWriteIndex += pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize;
906
/* Increment read pointer to get next event. */
907
ulReadPointer = ( ulReadPointer + pSharedInfo->DebugInfo.ulDebugChanStatsByteSize ) % ( ( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize );
909
/* Save in the instance that one of the events was dumped. */
910
pSharedInfo->DebugInfo.usLastDebugEventIndex ++;
914
/* Check if all debug events have been transfered. */
915
if ( ( ulDebugEventIndex == pSharedInfo->DebugInfo.usNumEvents )
916
|| ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) )
918
/* Fetch all streams per event. */
919
for ( ulPcmSampleIndex = pSharedInfo->DebugInfo.ulLastPcmSampleIndex; ulPcmSampleIndex < ( (UINT32)pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ); ulPcmSampleIndex ++ )
921
/* Check if enough room for this sample. */
922
if ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
924
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < 1 )
927
else /* if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) */
929
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < 3 )
933
/* Check if must retrieve data from external memory. */
934
if ( ( ulPcmSampleIndex % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE * 2 ) ) == 0x0 )
936
ulReadPointer = ( ( ( pSharedInfo->DebugInfo.usChipDebugEventWritePtr - pSharedInfo->DebugInfo.usNumEvents ) * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ) & ( pSharedInfo->DebugInfo.usMatrixCBMask * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ) );
937
ulReadPointer += ( ulPcmSampleIndex / pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ) * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize;
938
ulReadPointer &= ( pSharedInfo->DebugInfo.usMatrixCBMask * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize );
939
ulReadPointer += ulPcmSampleIndex % pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize;
941
/* Retrieve more data from external memory. */
942
switch ( f_pGetData->ulGetDataContent )
944
case cOCT6100_DEBUG_GET_DATA_CONTENT_RIN_PCM:
945
ulStreamIndexMin = 0;
946
ulStreamIndexMax = 1;
948
case cOCT6100_DEBUG_GET_DATA_CONTENT_SIN_PCM:
949
ulStreamIndexMin = 1;
950
ulStreamIndexMax = 2;
952
case cOCT6100_DEBUG_GET_DATA_CONTENT_SOUT_PCM:
953
ulStreamIndexMin = 2;
954
ulStreamIndexMax = 3;
956
case cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE:
958
ulStreamIndexMin = 0;
959
ulStreamIndexMax = 3;
963
for ( ulStreamIndex = ulStreamIndexMin; ulStreamIndex < ulStreamIndexMax; ulStreamIndex ++ )
965
ReadBurstParams.ulReadAddress = pSharedInfo->MemoryMap.ulChanMainMemBase;
966
/* To get right channel information. */
967
ReadBurstParams.ulReadAddress += ( ( pSharedInfo->DebugInfo.usRecordMemIndex + 2 ) * pSharedInfo->MemoryMap.ulChanMainMemSize ) + pSharedInfo->DebugInfo.ulAfEventCbByteSize;
968
/* To get correct stream. */
969
ReadBurstParams.ulReadAddress += ( ( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize * ulStreamIndex );
970
/* PCM sample pointer in that stream. */
971
ReadBurstParams.ulReadAddress += ulReadPointer;
973
/* As much as we can for the burst. */
975
ulNumReads = cOCT6100_INTERNAL_SUPER_ARRAY_SIZE;
976
while ( ulNumReads != 0 )
978
if ( ulNumReads >= pSharedInfo->ChipConfig.usMaxRwAccesses )
979
ReadBurstParams.ulReadLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
981
ReadBurstParams.ulReadLength = ulNumReads;
983
/* Set pointer where to write data. */
984
if ( ulStreamIndex == 0 )
985
ReadBurstParams.pusReadData = &pSharedInfo->MiscVars.ausSuperArray[ ulTempIndex ];
986
else if ( ulStreamIndex == 1 )
987
ReadBurstParams.pusReadData = &pSharedInfo->MiscVars.ausSuperArray1[ ulTempIndex ];
988
else /* if ( ulStreamIndex == 2 ) */
989
ReadBurstParams.pusReadData = &pSharedInfo->MiscVars.ausSuperArray2[ ulTempIndex ];
991
mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
992
if ( ulResult != cOCT6100_ERR_OK )
995
/* Update indexes, temp variables, addresses. */
996
ulNumReads -= ReadBurstParams.ulReadLength;
997
ulTempIndex += ReadBurstParams.ulReadLength;
998
ReadBurstParams.ulReadAddress += ReadBurstParams.ulReadLength * 2;
1003
/* We now have the stream data for all streams for 1 event. */
1004
/* Return what we can to the user. */
1005
if ( ( ulPcmSampleIndex % 2 ) == 0 )
1007
if ( ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1008
|| ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_RIN_PCM ) )
1009
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray[ ( ulPcmSampleIndex / 2 ) % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE ) ] >> 8 ) & 0xFF );
1011
if ( ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1012
|| ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_SIN_PCM ) )
1013
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray1[ ( ulPcmSampleIndex / 2 ) % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE ) ] >> 8 ) & 0xFF );
1015
if ( ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1016
|| ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_SOUT_PCM ) )
1017
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray2[ ( ulPcmSampleIndex / 2 ) % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE ) ] >> 8 ) & 0xFF );
1019
else /* if ( ulPcmSampleIndex % 2 == 1 ) */
1021
if ( ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1022
|| ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_RIN_PCM ) )
1023
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray[ ( ulPcmSampleIndex / 2 ) % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE ) ] >> 0 ) & 0xFF );
1025
if ( ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1026
|| ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_SIN_PCM ) )
1027
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray1[ ( ulPcmSampleIndex / 2 ) % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE ) ] >> 0 ) & 0xFF );
1029
if ( ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1030
|| ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_SOUT_PCM ) )
1031
f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray2[ ( ulPcmSampleIndex / 2 ) % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE ) ] >> 0 ) & 0xFF );
1034
pSharedInfo->DebugInfo.ulLastPcmSampleIndex++;
1037
/* Check if we are done dumping the PCM samples! */
1038
if ( pSharedInfo->DebugInfo.ulLastPcmSampleIndex == ( (UINT32)pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ) )
1040
if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1043
/* Go for the AF events. The AF events are only copied in heavy mode. */
1044
if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
1045
|| ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
1047
while ( pSharedInfo->DebugInfo.usLastAfLogReadPtr != pSharedInfo->DebugInfo.usAfLogWritePtr )
1049
/* Check if enough room for an event. */
1050
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < 16 )
1053
/* Check if must fill our buffer. */
1054
if ( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) ) == 0x0 )
1056
ulNumAfEvents = ( pSharedInfo->DebugInfo.usAfLogWritePtr - pSharedInfo->DebugInfo.usLastAfLogReadPtr ) & 0xFFFF;
1058
/* Check for the size of the available buffer. */
1059
if ( ulNumAfEvents > ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) )
1060
ulNumAfEvents = ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 );
1062
/* Start at channel main base address. */
1063
ReadBurstParams.ulReadAddress = pSharedInfo->MemoryMap.ulChanMainMemBase;
1064
/* To get right channel information. */
1065
ReadBurstParams.ulReadAddress += ( ( pSharedInfo->DebugInfo.usRecordMemIndex + 2 ) * pSharedInfo->MemoryMap.ulChanMainMemSize );
1066
/* To get the right AF log. */
1067
ReadBurstParams.ulReadAddress += ( pSharedInfo->DebugInfo.usLastAfLogReadPtr * 16 );
1070
ulNumReads = ulNumAfEvents * 8;
1072
while ( ulNumReads != 0 )
1074
if ( ulNumReads >= pSharedInfo->ChipConfig.usMaxRwAccesses )
1075
ReadBurstParams.ulReadLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
1077
ReadBurstParams.ulReadLength = ulNumReads;
1079
/* Set pointer where to write data. */
1080
ReadBurstParams.pusReadData = &pSharedInfo->MiscVars.ausSuperArray[ ulTempIndex ];
1082
mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
1083
if ( ulResult != cOCT6100_ERR_OK )
1086
/* Update indexes, temp variables, addresses. */
1087
ulNumReads -= ReadBurstParams.ulReadLength;
1088
ulTempIndex += ReadBurstParams.ulReadLength;
1089
ReadBurstParams.ulReadAddress += ReadBurstParams.ulReadLength * 2;
1093
/* Copy data byte per byte to avoid endianess problems. */
1094
for ( ulCopyIndex = 0; ulCopyIndex < 8; ulCopyIndex ++ )
1096
f_pGetData->pbyData[ ulUserBufWriteIndex + ( 2 * ulCopyIndex ) ] = (UINT8)( pSharedInfo->MiscVars.ausSuperArray[ ( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) ) * 8 ) + ulCopyIndex ] & 0xFF );
1097
f_pGetData->pbyData[ ulUserBufWriteIndex + ( 2 * ulCopyIndex ) + 1 ] = (UINT8)( ( pSharedInfo->MiscVars.ausSuperArray[ ( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) ) * 8 ) + ulCopyIndex ] >> 8 ) & 0xFF );
1100
ulUserBufWriteIndex += 16;
1102
/* Increment AF log read ptr. */
1103
pSharedInfo->DebugInfo.usLastAfLogReadPtr = (UINT16)(( pSharedInfo->DebugInfo.usLastAfLogReadPtr + 1 ) & 0xFFFF );
1107
/* Check if we are done with the AF events. */
1108
if ( pSharedInfo->DebugInfo.usLastAfLogReadPtr == pSharedInfo->DebugInfo.usAfLogWritePtr )
1110
/* Insert the tone event information. */
1111
for ( ulToneEventIndex = pSharedInfo->DebugInfo.usLastToneEventIndex; ulToneEventIndex < pSharedInfo->ImageInfo.byNumToneDetectors; ulToneEventIndex++ )
1113
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < cOCT6100_TLV_MAX_TONE_NAME_SIZE )
1116
Oct6100UserMemCopy( &f_pGetData->pbyData[ ulUserBufWriteIndex ], pSharedInfo->ImageInfo.aToneInfo[ ulToneEventIndex ].aszToneName, cOCT6100_TLV_MAX_TONE_NAME_SIZE );
1118
ulUserBufWriteIndex += cOCT6100_TLV_MAX_TONE_NAME_SIZE;
1120
pSharedInfo->DebugInfo.usLastToneEventIndex++;
1123
/* If all the tone information has been copied. */
1124
if ( ulToneEventIndex == pSharedInfo->ImageInfo.byNumToneDetectors )
1126
/* Copy the image version. */
1127
if ( pSharedInfo->DebugInfo.fImageVersionCopied == FALSE )
1129
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= 512 )
1131
Oct6100UserMemCopy( &f_pGetData->pbyData[ ulUserBufWriteIndex ], pSharedInfo->ImageInfo.szVersionNumber, 512 );
1133
/* Get PLL jitter count from external memory. */
1134
if ( pSharedInfo->DebugInfo.fPouchCounter == TRUE )
1136
ulFeatureBytesOffset = pSharedInfo->MemoryMap.PouchCounterFieldOfst.usDwordOffset * 4;
1137
ulFeatureBitOffset = pSharedInfo->MemoryMap.PouchCounterFieldOfst.byBitOffset;
1138
ulFeatureFieldLength = pSharedInfo->MemoryMap.PouchCounterFieldOfst.byFieldSize;
1140
ulResult = Oct6100ApiReadDword( f_pApiInstance,
1141
cOCT6100_POUCH_BASE + ulFeatureBytesOffset,
1144
/* Create the mask to retrieve the appropriate value. */
1145
mOCT6100_CREATE_FEATURE_MASK( ulFeatureFieldLength, ulFeatureBitOffset, &ulMask );
1148
ulTempData &= ulMask;
1149
/* Move to right position. */
1150
ulTempData = ulTempData >> ulFeatureBitOffset;
1152
f_pGetData->pbyData[ ulUserBufWriteIndex + 510 ] = (UINT8)( ( ulTempData >> 8 ) & 0xFF );
1153
f_pGetData->pbyData[ ulUserBufWriteIndex + 511 ] = (UINT8)( ( ulTempData >> 0 ) & 0xFF );
1156
/* Add "ISR is not called" bit. */
1157
if ( pSharedInfo->IntrptManage.fIsrCalled == FALSE )
1159
f_pGetData->pbyData[ ulUserBufWriteIndex + 510 ] |= 0x80;
1162
ulUserBufWriteIndex += 512;
1164
/* The version has been copied. */
1165
pSharedInfo->DebugInfo.fImageVersionCopied = TRUE;
1169
/* If the image version has been copied, proceed with the API version. */
1170
if ( pSharedInfo->DebugInfo.fImageVersionCopied == TRUE )
1172
if ( pSharedInfo->DebugInfo.fApiVersionCopied == FALSE )
1174
if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= sizeof(cOCT6100_API_VERSION) )
1176
Oct6100UserMemCopy( &f_pGetData->pbyData[ ulUserBufWriteIndex ], cOCT6100_API_VERSION, sizeof(cOCT6100_API_VERSION) );
1177
ulUserBufWriteIndex += sizeof(cOCT6100_API_VERSION);
1179
/* The API version has been copied. */
1180
pSharedInfo->DebugInfo.fApiVersionCopied = TRUE;
1186
/* Check if we are done! */
1187
if ( pSharedInfo->DebugInfo.fApiVersionCopied == TRUE )
1191
/* Reset data being dumpped flag. */
1192
pSharedInfo->DebugInfo.fDebugDataBeingDumped = FALSE;
1194
/* Reset data recording in the chip. */
1195
WriteBurstParams.ulWriteAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
1196
WriteBurstParams.ulWriteLength = 2;
1197
WriteBurstParams.pusWriteData = pSharedInfo->DebugInfo.ausHotChannelData;
1199
mOCT6100_DRIVER_WRITE_BURST_API( WriteBurstParams, ulResult );
1200
if ( ulResult != cOCT6100_ERR_OK )
1203
fResetRemainingDataFlag = TRUE;
1207
else /* if ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) */
1209
fResetRemainingDataFlag = TRUE;
1214
/* Return number of valid bytes in buffer to user. */
1215
f_pGetData->ulValidNumBytes = ulUserBufWriteIndex;
1217
/* Update remaining bytes. */
1218
pSharedInfo->DebugInfo.ulDebugDataRemainingNumBytes -= ulUserBufWriteIndex;
1220
/* Return remaining bytes. */
1221
f_pGetData->ulRemainingNumBytes = pSharedInfo->DebugInfo.ulDebugDataRemainingNumBytes;
1223
/* Return total number of bytes. */
1224
f_pGetData->ulTotalNumBytes = pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes;
1226
/* Check if we are done dump the requested content. */
1227
if ( fResetRemainingDataFlag == TRUE )
1228
pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes = cOCT6100_INVALID_VALUE;
1230
return cOCT6100_ERR_OK;