~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to oct612x/octdeviceapi/oct6100api/oct6100_api/oct6100_debug.c

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2
 
 
3
 
File: oct6100_debug.c
4
 
 
5
 
    Copyright (c) 2001-2006 Octasic Inc.
6
 
    
7
 
Description: 
8
 
 
9
 
        This file contains functions used to debug the OCT6100.
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-PR43 $
26
 
 
27
 
$Octasic_Revision: 63 $
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
 
#include "oct6100api/oct6100_apiud.h"
39
 
 
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"
49
 
 
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"
54
 
 
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"
61
 
 
62
 
 
63
 
/****************************  PUBLIC FUNCTIONS  ****************************/
64
 
 
65
 
 
66
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
67
 
 
68
 
Function:               Oct6100DebugSelectChannel
69
 
 
70
 
Description:    This function sets the current debug channel.
71
 
 
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.
77
 
 
78
 
f_pSelectDebugChan              Pointer to select debug channel structure.
79
 
 
80
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
81
 
#if !SKIP_Oct6100DebugSelectChannelDef
82
 
UINT32 Oct6100DebugSelectChannelDef(
83
 
                                tPOCT6100_DEBUG_SELECT_CHANNEL  f_pSelectDebugChan )
84
 
{
85
 
        f_pSelectDebugChan->ulChannelHndl = cOCT6100_INVALID_VALUE;
86
 
 
87
 
        return cOCT6100_ERR_OK;
88
 
}
89
 
#endif
90
 
 
91
 
#if !SKIP_Oct6100DebugSelectChannel
92
 
UINT32 Oct6100DebugSelectChannel(
93
 
                                tPOCT6100_INSTANCE_API                          f_pApiInstance,
94
 
                                tPOCT6100_DEBUG_SELECT_CHANNEL  f_pSelectDebugChan )
95
 
{
96
 
        tOCT6100_SEIZE_SERIALIZE_OBJECT         SeizeSerObj;
97
 
        tOCT6100_RELEASE_SERIALIZE_OBJECT       ReleaseSerObj;
98
 
        UINT32                                                          ulSerRes = cOCT6100_ERR_OK;
99
 
        UINT32                                                          ulFncRes = cOCT6100_ERR_OK;
100
 
 
101
 
        /* Set the process context of the serialize structure. */
102
 
        SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
103
 
        ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
104
 
 
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 )
110
 
        {
111
 
                /* Call the serialized function. */
112
 
                ulFncRes = Oct6100DebugSelectChannelSer( f_pApiInstance, f_pSelectDebugChan, TRUE );
113
 
        }
114
 
        else
115
 
        {
116
 
                return ulSerRes;
117
 
        }
118
 
 
119
 
        /* Release the seized semaphores. */
120
 
        ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
121
 
        ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
122
 
 
123
 
        /* If an error occured then return the error code. */
124
 
        if ( ulSerRes != cOCT6100_ERR_OK )
125
 
                return ulSerRes;
126
 
        if ( ulFncRes != cOCT6100_ERR_OK )
127
 
                return ulFncRes;
128
 
 
129
 
        return cOCT6100_ERR_OK;
130
 
}
131
 
#endif
132
 
 
133
 
 
134
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
135
 
 
136
 
Function:               Oct6100DebugGetData
137
 
 
138
 
Description:    This function retrieves the last recorded debug data.
139
 
 
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.
145
 
 
146
 
f_pGetData                              Pointer to debug get data structure.
147
 
 
148
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
149
 
#if !SKIP_Oct6100DebugGetDataDef
150
 
UINT32 Oct6100DebugGetDataDef(
151
 
                                tPOCT6100_DEBUG_GET_DATA                        f_pGetData )
152
 
{
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;
160
 
        
161
 
        return cOCT6100_ERR_OK;
162
 
}
163
 
#endif
164
 
 
165
 
#if !SKIP_Oct6100DebugGetData
166
 
UINT32 Oct6100DebugGetData(
167
 
                                tPOCT6100_INSTANCE_API                          f_pApiInstance,
168
 
                                tPOCT6100_DEBUG_GET_DATA                        f_pGetData )
169
 
{
170
 
        tOCT6100_SEIZE_SERIALIZE_OBJECT         SeizeSerObj;
171
 
        tOCT6100_RELEASE_SERIALIZE_OBJECT       ReleaseSerObj;
172
 
        UINT32                                                          ulSerRes = cOCT6100_ERR_OK;
173
 
        UINT32                                                          ulFncRes = cOCT6100_ERR_OK;
174
 
 
175
 
        /* Set the process context of the serialize structure. */
176
 
        SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
177
 
        ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
178
 
 
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 )
184
 
        {
185
 
                /* Call the serialized function. */
186
 
                ulFncRes = Oct6100DebugGetDataSer( f_pApiInstance, f_pGetData );
187
 
        }
188
 
        else
189
 
        {
190
 
                return ulSerRes;
191
 
        }
192
 
 
193
 
        /* Release the seized semaphores. */
194
 
        ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
195
 
        ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
196
 
 
197
 
        /* If an error occured then return the error code. */
198
 
        if ( ulSerRes != cOCT6100_ERR_OK )
199
 
                return ulSerRes;
200
 
        if ( ulFncRes != cOCT6100_ERR_OK )
201
 
                return ulFncRes;
202
 
 
203
 
        return cOCT6100_ERR_OK;
204
 
}
205
 
#endif
206
 
 
207
 
 
208
 
/****************************  PRIVATE FUNCTIONS  ****************************/
209
 
 
210
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
211
 
 
212
 
Function:               Oct6100DebugSelectChannelSer
213
 
 
214
 
Description:    This function sets the debug channel.
215
 
 
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.
221
 
 
222
 
f_pSelectDebugChan                      Pointer to a tOCT6100_DEBUG_SELECT_CHANNEL structure.
223
 
f_fCheckChannelRecording        Check if channel recording is enabled or not.
224
 
 
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 )
231
 
{
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;
238
 
 
239
 
        tOCT6100_WRITE_BURST_PARAMS             BurstParams;
240
 
        UINT16  ausWriteData[ 2 ];
241
 
        UINT32  ulResult;
242
 
        
243
 
        /* Get local pointer(s). */
244
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
245
 
 
246
 
        BurstParams.pProcessContext = f_pApiInstance->pProcessContext;
247
 
 
248
 
        BurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
249
 
        BurstParams.pusWriteData = ausWriteData;
250
 
 
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 )
254
 
        {
255
 
                /*=======================================================================*/
256
 
                /* Get a pointer to the channel's list entry. */
257
 
 
258
 
                mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pTempChanEntry, pSharedInfo->DebugInfo.usCurrentDebugChanIndex  )
259
 
 
260
 
                /* Release the extra TSI memory entry and reprogram the TSST control memory if required. */
261
 
                if ( pTempChanEntry->usExtraSinTsiDependencyCnt == 1 )
262
 
                {
263
 
                        /*=======================================================================*/
264
 
                        /* Clear memcpy operations. */
265
 
 
266
 
                        BurstParams.ulWriteAddress = cOCT6100_MIXER_CONTROL_MEM_BASE + ( pSharedInfo->MixerInfo.usRecordCopyEventIndex * cOCT6100_MIXER_CONTROL_MEM_ENTRY_SIZE );
267
 
                        BurstParams.ulWriteLength = 2;
268
 
 
269
 
                        ausWriteData[ 0 ] = cOCT6100_MIXER_CONTROL_MEM_NO_OP;
270
 
                        ausWriteData[ 1 ] = 0x0;
271
 
 
272
 
                        mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
273
 
                        if ( ulResult != cOCT6100_ERR_OK )
274
 
                                return ulResult;
275
 
 
276
 
                        BurstParams.ulWriteAddress = cOCT6100_MIXER_CONTROL_MEM_BASE + ( pSharedInfo->MixerInfo.usRecordSinEventIndex * cOCT6100_MIXER_CONTROL_MEM_ENTRY_SIZE );
277
 
 
278
 
                        mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
279
 
                        if ( ulResult != cOCT6100_ERR_OK )
280
 
                                return ulResult;
281
 
 
282
 
                        /*=======================================================================*/
283
 
 
284
 
                        ulResult = Oct6100ApiReleaseTsiMemEntry( f_pApiInstance, pTempChanEntry->usExtraSinTsiMemIndex );
285
 
                        if ( ulResult != cOCT6100_ERR_OK )
286
 
                                return ulResult;
287
 
 
288
 
                        if ( pTempChanEntry->usSinTsstIndex != cOCT6100_INVALID_INDEX )
289
 
                        {
290
 
                                ulResult = Oct6100ApiWriteInputTsstControlMemory( f_pApiInstance,
291
 
                                                                                                                                  pTempChanEntry->usSinTsstIndex,
292
 
                                                                                                                                  pTempChanEntry->usSinSoutTsiMemIndex,
293
 
                                                                                                                                  pTempChanEntry->TdmConfig.bySinPcmLaw );
294
 
                        }
295
 
 
296
 
                        if ( ulResult != cOCT6100_ERR_OK )
297
 
                                return ulResult;
298
 
 
299
 
                        pTempChanEntry->usExtraSinTsiDependencyCnt--;
300
 
                        pTempChanEntry->usExtraSinTsiMemIndex = cOCT6100_INVALID_INDEX;
301
 
                }
302
 
        }
303
 
 
304
 
        /* Set the new parameters. */
305
 
        if ( f_pSelectDebugChan->ulChannelHndl != cOCT6100_INVALID_HANDLE )
306
 
        {
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;
310
 
 
311
 
                usChanIndex = (UINT16)( f_pSelectDebugChan->ulChannelHndl & cOCT6100_HNDL_INDEX_MASK );
312
 
                if ( usChanIndex >= pSharedInfo->ChipConfig.usMaxChannels )
313
 
                        return cOCT6100_ERR_DEBUG_CHANNEL_INVALID_HANDLE;
314
 
 
315
 
                if ( f_fCheckChannelRecording == TRUE )
316
 
                {
317
 
                        if ( pSharedInfo->ChipConfig.fEnableChannelRecording == FALSE )
318
 
                                return cOCT6100_ERR_DEBUG_CHANNEL_RECORDING_DISABLED;
319
 
                }
320
 
 
321
 
                /*=======================================================================*/
322
 
                /* Get a pointer to the channel's list entry. */
323
 
 
324
 
                mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pChanEntry, usChanIndex );
325
 
 
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;
328
 
 
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;
334
 
                
335
 
                /*=======================================================================*/
336
 
 
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 )
340
 
                {
341
 
                        if ( pChanEntry->usExtraSinTsiMemIndex == cOCT6100_INVALID_INDEX )
342
 
                        {
343
 
                                ulResult = Oct6100ApiReserveTsiMemEntry( f_pApiInstance, &pChanEntry->usExtraSinTsiMemIndex );
344
 
                                if ( ulResult != cOCT6100_ERR_OK )
345
 
                                        return ulResult;
346
 
 
347
 
                                if ( pChanEntry->usSinTsstIndex != cOCT6100_INVALID_INDEX )
348
 
                                {
349
 
                                        ulResult = Oct6100ApiWriteInputTsstControlMemory( f_pApiInstance,
350
 
                                                                                                                                          pChanEntry->usSinTsstIndex,
351
 
                                                                                                                                          pChanEntry->usExtraSinTsiMemIndex,
352
 
                                                                                                                                          pChanEntry->TdmConfig.bySinPcmLaw );
353
 
                                        if ( ulResult != cOCT6100_ERR_OK )
354
 
                                                return ulResult;
355
 
                                }
356
 
                        }
357
 
                
358
 
                        
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;
363
 
 
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 );
368
 
 
369
 
                        mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
370
 
                        if ( ulResult != cOCT6100_ERR_OK )
371
 
                                return ulResult;
372
 
                        /*=======================================================================*/
373
 
 
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;
378
 
 
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;
383
 
 
384
 
                        mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
385
 
                        if ( ulResult != cOCT6100_ERR_OK )
386
 
                                return ulResult;
387
 
                        /*=======================================================================*/
388
 
 
389
 
                        pChanEntry->usExtraSinTsiDependencyCnt++;
390
 
                }
391
 
        }
392
 
        else
393
 
        {
394
 
                /* Set the index to invalid to deactivate the recording. */
395
 
                usChanIndex = cOCT6100_INVALID_INDEX;
396
 
        }
397
 
 
398
 
        /* Set law of newly selected hot channel. */
399
 
        if ( ( pSharedInfo->ChipConfig.fEnableChannelRecording == TRUE ) 
400
 
                && ( f_pSelectDebugChan->ulChannelHndl != cOCT6100_INVALID_HANDLE )
401
 
                && ( pChanEntry != NULL ) )
402
 
        {
403
 
                /* Set the PCM law of the debug channel. */
404
 
                /* Let's program the channel memory. */
405
 
                Oct6100ChannelOpenDef( &TempChanOpen );
406
 
                
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;
413
 
 
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;
419
 
 
420
 
                ulResult = Oct6100ApiWriteDebugChanMemory( f_pApiInstance,
421
 
                                                                                          &TempChanOpen.TdmConfig,
422
 
                                                                                          &TempChanOpen.VqeConfig,
423
 
                                                                                          &TempChanOpen,
424
 
                                                                                          pSharedInfo->DebugInfo.usRecordChanIndex,
425
 
                                                                                          pSharedInfo->DebugInfo.usRecordMemIndex,
426
 
                                                                                          pSharedInfo->DebugInfo.usRecordRinRoutTsiMemIndex,
427
 
                                                                                          pSharedInfo->DebugInfo.usRecordSinSoutTsiMemIndex );
428
 
                if ( ulResult != cOCT6100_ERR_OK )
429
 
                        return ulResult;
430
 
        }               
431
 
 
432
 
        ausWriteData[ 0 ] = 0x0;
433
 
        ausWriteData[ 1 ] = (UINT16)(( usChanIndex >>  0) & 0xFFFF);
434
 
 
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;
439
 
 
440
 
        mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult );
441
 
        if ( ulResult != cOCT6100_ERR_OK )
442
 
                return ulResult;
443
 
 
444
 
        pSharedInfo->DebugInfo.usCurrentDebugChanIndex = usChanIndex;
445
 
        
446
 
        /* Cancel data dump request, if there was one. */
447
 
        pSharedInfo->DebugInfo.fDebugDataBeingDumped = FALSE;
448
 
        pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes = cOCT6100_INVALID_VALUE;
449
 
 
450
 
        /* Call from remote client. */
451
 
        if ( f_fCheckChannelRecording == FALSE )
452
 
        {
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;
456
 
        }
457
 
                
458
 
        return cOCT6100_ERR_OK;
459
 
}
460
 
#endif
461
 
 
462
 
 
463
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
464
 
 
465
 
Function:               Oct6100DebugGetDataSer
466
 
 
467
 
Description:    This function retrieves the latest recorded debug data.
468
 
 
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.
474
 
 
475
 
f_pGetData                              Pointer to a tOCT6100_DEBUG_GET_DATA structure.
476
 
 
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 )
482
 
{
483
 
 
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;
490
 
 
491
 
        UINT16  ausWriteData[ 2 ];
492
 
        UINT16  usReadData;
493
 
        UINT16  usDebugEventReadPtr;
494
 
 
495
 
        UINT32  ulResult;
496
 
        UINT32  ulToneEventIndex;
497
 
        UINT32  ulReadPointer;
498
 
        UINT32  ulUserBufWriteIndex = 0;
499
 
        UINT32  ulTimestamp;
500
 
        UINT32  ulDebugEventIndex = 0;
501
 
        UINT32  ulStreamIndex;
502
 
        UINT32  ulPcmSampleIndex;
503
 
        UINT32  ulNumAfEvents;
504
 
        UINT32  ulNumReads = 0;
505
 
        UINT32  ulTempIndex;
506
 
        UINT32  ulCopyIndex;
507
 
        UINT32  ulFeatureBytesOffset;
508
 
        UINT32  ulFeatureBitOffset;
509
 
        UINT32  ulFeatureFieldLength;
510
 
        UINT32  ulStreamIndexMin;
511
 
        UINT32  ulStreamIndexMax;
512
 
        UINT32  ulTempData;
513
 
        UINT32  ulMask;
514
 
        BOOL    fResetRemainingDataFlag = FALSE;
515
 
        
516
 
        /* Get local pointer(s). */
517
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
518
 
 
519
 
        ReadBurstParams.pProcessContext = f_pApiInstance->pProcessContext;
520
 
 
521
 
        ReadBurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
522
 
 
523
 
        ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
524
 
 
525
 
        ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
526
 
 
527
 
        WriteBurstParams.pProcessContext = f_pApiInstance->pProcessContext;
528
 
 
529
 
        WriteBurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
530
 
 
531
 
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
532
 
 
533
 
        WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
534
 
 
535
 
        /* Check all user parameters. */
536
 
 
537
 
        /* Check if channel recording is enabled. */
538
 
        if ( pSharedInfo->ChipConfig.fEnableChannelRecording == FALSE )
539
 
                return cOCT6100_ERR_DEBUG_CHANNEL_RECORDING_DISABLED;
540
 
 
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;
545
 
 
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;
549
 
 
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;
553
 
 
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;
557
 
 
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;
564
 
 
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;
571
 
 
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 ) )
575
 
        {
576
 
                if ( pSharedInfo->DebugInfo.ulDebugEventSize != 0x100 )
577
 
                        return cOCT6100_ERR_NOT_SUPPORTED_DEBUG_DATA_MODE_120S;
578
 
        }
579
 
 
580
 
        mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pChanEntry, pSharedInfo->DebugInfo.usCurrentDebugChanIndex )
581
 
 
582
 
        /* Lets go dump the requested data. */
583
 
 
584
 
        usDebugEventReadPtr = 0;
585
 
 
586
 
        /* Check if this is the first time this function is called since the hot channel was set. */
587
 
        if ( pSharedInfo->DebugInfo.fDebugDataBeingDumped == FALSE )
588
 
        {
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;
593
 
                
594
 
                pSharedInfo->DebugInfo.fDebugDataBeingDumped = TRUE;
595
 
                
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. */
598
 
 
599
 
                ReadBurstParams.ulReadAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
600
 
                ReadBurstParams.ulReadLength = 2;
601
 
                ReadBurstParams.pusReadData = pSharedInfo->DebugInfo.ausHotChannelData;
602
 
 
603
 
                mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
604
 
                if ( ulResult != cOCT6100_ERR_OK )
605
 
                        return ulResult;
606
 
 
607
 
                WriteBurstParams.pusWriteData = ausWriteData;
608
 
                WriteBurstParams.ulWriteAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
609
 
                WriteBurstParams.ulWriteLength = 2;
610
 
 
611
 
                WriteBurstParams.pusWriteData[ 0 ] = 0xFFFF;
612
 
                WriteBurstParams.pusWriteData[ 1 ] = 0xFFFF;
613
 
 
614
 
                mOCT6100_DRIVER_WRITE_BURST_API( WriteBurstParams, ulResult );
615
 
                if ( ulResult != cOCT6100_ERR_OK )
616
 
                        return ulResult;
617
 
 
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;
621
 
 
622
 
                /* Find out the chip log write pointer. */
623
 
 
624
 
                /* Now get the current write pointer for matrix events. */
625
 
                ReadParams.pusReadData = &pSharedInfo->DebugInfo.usChipDebugEventWritePtr;
626
 
                ReadParams.ulReadAddress = pSharedInfo->DebugInfo.ulMatrixWpBaseAddress + 2;
627
 
 
628
 
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
629
 
                if ( ulResult != cOCT6100_ERR_OK )
630
 
                        return ulResult;
631
 
 
632
 
                ReadParams.pusReadData = &usReadData;
633
 
                
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;
637
 
 
638
 
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
639
 
                if ( ulResult != cOCT6100_ERR_OK )
640
 
                        return ulResult;
641
 
 
642
 
                ulTimestamp = usReadData << 16;
643
 
 
644
 
                ReadParams.ulReadAddress += 2;
645
 
 
646
 
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
647
 
                if ( ulResult != cOCT6100_ERR_OK )
648
 
                        return ulResult;
649
 
 
650
 
                ulTimestamp |= usReadData;
651
 
 
652
 
                ulTimestamp >>= 12;
653
 
                if ( ulTimestamp < (UINT32)( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) )
654
 
                {
655
 
                        if ( pSharedInfo->DebugInfo.usChipDebugEventWritePtr >= 2 )
656
 
                        {
657
 
                                /* Must trash the first 2 events.  The chip is not yet ready. */
658
 
                                pSharedInfo->DebugInfo.usNumEvents = (UINT16)( pSharedInfo->DebugInfo.usChipDebugEventWritePtr - 2 );
659
 
                        }
660
 
                        else
661
 
                        {
662
 
                                pSharedInfo->DebugInfo.usNumEvents = 0x0;
663
 
                        }
664
 
                }
665
 
                else
666
 
                {
667
 
                        pSharedInfo->DebugInfo.usNumEvents = (UINT16)( pSharedInfo->DebugInfo.usMatrixCBMask + 1 );
668
 
 
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--;
673
 
                }
674
 
 
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 )
678
 
                {
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 );
682
 
                }
683
 
 
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 ) ) )
688
 
                {
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 );
691
 
 
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 )
696
 
                                return ulResult;
697
 
 
698
 
                        pSharedInfo->DebugInfo.usAfLogWritePtr = usReadData;
699
 
 
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. */
703
 
 
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 );
708
 
 
709
 
                        /* Note that if the chip has just been booted, some of the AF events might not be initialized. */
710
 
                }
711
 
                else
712
 
                {
713
 
                        pSharedInfo->DebugInfo.usLastAfLogReadPtr = 0;
714
 
                        pSharedInfo->DebugInfo.usAfLogWritePtr = 0;
715
 
                }
716
 
 
717
 
                /* To be aligned correctly for the bursts. */
718
 
                while ( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) ) != 0 )
719
 
                        pSharedInfo->DebugInfo.usLastAfLogReadPtr++;
720
 
 
721
 
                /* Remember the data mode for later checks.  Also, the user cannot change this "mode". */
722
 
                pSharedInfo->DebugInfo.ulCurrentGetDataMode = f_pGetData->ulGetDataMode;
723
 
        }
724
 
        else
725
 
        {
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;
729
 
        }
730
 
 
731
 
        /* Check if this is the first pass here. */
732
 
        if ( pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes == cOCT6100_INVALID_VALUE )
733
 
        {
734
 
                /* Calculate how many bytes of data will be returned with respect to the selected data content. */
735
 
                
736
 
                /* Check what content type the user requested.  */
737
 
                if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
738
 
                {
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 );
742
 
 
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 );
746
 
 
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 );
750
 
 
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 ) )
754
 
                        {
755
 
                                f_pGetData->pbyData[ ulUserBufWriteIndex - 1 ] |= 0x80;
756
 
                        }
757
 
                        f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( pChanEntry->TdmConfig.byRinPcmLaw | ( ( pSharedInfo->DebugInfo.usCurrentDebugChanIndex & 0x1F ) << 3 ) );
758
 
 
759
 
                        /* Remember usNumEvents */
760
 
                        f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usNumEvents ) & 0xFF );
761
 
                        f_pGetData->pbyData[ ulUserBufWriteIndex++ ] = (UINT8)( ( pSharedInfo->DebugInfo.usNumEvents >> 8 ) & 0xFF );
762
 
                }
763
 
                
764
 
                /* Last indexes set to '0'! */
765
 
                pSharedInfo->DebugInfo.usLastDebugEventIndex = 0;
766
 
                pSharedInfo->DebugInfo.ulLastPcmSampleIndex = 0;
767
 
 
768
 
                /* No tone event has been retrieved. */
769
 
                pSharedInfo->DebugInfo.usLastToneEventIndex = 0;
770
 
 
771
 
                /* The version strings have not yet been copied. */
772
 
                pSharedInfo->DebugInfo.fImageVersionCopied = FALSE;
773
 
                pSharedInfo->DebugInfo.fApiVersionCopied = FALSE;
774
 
 
775
 
                /* Estimate the total size of the buffer that will be returned. */
776
 
                f_pGetData->ulTotalNumBytes = ulUserBufWriteIndex;
777
 
 
778
 
                /* If the full content is requested, add all the debug data. */
779
 
                if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
780
 
                {
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 ) )
784
 
                        {
785
 
                                /* Heavy mode!  Grab everything! */
786
 
                                f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize;
787
 
                        }
788
 
                        else
789
 
                        {
790
 
                                /* Lite mode!  Only the most important stuff. */
791
 
                                f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize;
792
 
                        }
793
 
 
794
 
                        /* Add the PCM samples. */
795
 
                        f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize * 3;
796
 
 
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 ) )
800
 
                        {
801
 
                                f_pGetData->ulTotalNumBytes += (UINT32)( ( pSharedInfo->DebugInfo.usAfLogWritePtr - pSharedInfo->DebugInfo.usLastAfLogReadPtr ) & 0xFFFF ) * 16;
802
 
                        }
803
 
 
804
 
                        /* Add the tone events strings. */
805
 
                        f_pGetData->ulTotalNumBytes += cOCT6100_TLV_MAX_TONE_NAME_SIZE * pSharedInfo->ImageInfo.byNumToneDetectors;
806
 
 
807
 
                        /* Add the image version string. */
808
 
                        f_pGetData->ulTotalNumBytes += 512;
809
 
 
810
 
                        /* Add the API version string. */
811
 
                        f_pGetData->ulTotalNumBytes += sizeof( cOCT6100_API_VERSION );
812
 
                }
813
 
                else /* if ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) */
814
 
                {
815
 
                        /* Add one PCM stream. */
816
 
                        f_pGetData->ulTotalNumBytes += pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize;
817
 
                }
818
 
 
819
 
                /* Save this in the instance for further calls. */
820
 
                pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes = f_pGetData->ulTotalNumBytes;
821
 
 
822
 
                /* Calculate remaining bytes.  All the bytes for now! */
823
 
                f_pGetData->ulRemainingNumBytes = f_pGetData->ulTotalNumBytes;
824
 
 
825
 
                /* Save this in the instance for the next calls. */
826
 
                pSharedInfo->DebugInfo.ulDebugDataRemainingNumBytes = f_pGetData->ulRemainingNumBytes;
827
 
        }
828
 
        else
829
 
        {
830
 
                f_pGetData->ulTotalNumBytes = pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes;
831
 
        }
832
 
 
833
 
        /* Calculate the event read pointer. */
834
 
        ulReadPointer = ( ( pSharedInfo->DebugInfo.usChipDebugEventWritePtr - pSharedInfo->DebugInfo.usNumEvents ) & pSharedInfo->DebugInfo.usMatrixCBMask ) * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize;
835
 
 
836
 
        ulReadPointer += pSharedInfo->DebugInfo.ulDebugChanStatsByteSize * pSharedInfo->DebugInfo.usLastDebugEventIndex;
837
 
        ulReadPointer %= ( ( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize );
838
 
 
839
 
        if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
840
 
        {
841
 
                /* Copy the debug events in the user buffer. */
842
 
                for( ulDebugEventIndex = pSharedInfo->DebugInfo.usLastDebugEventIndex; ulDebugEventIndex < pSharedInfo->DebugInfo.usNumEvents; ulDebugEventIndex ++ )
843
 
                {
844
 
                        ReadBurstParams.ulReadAddress = pSharedInfo->DebugInfo.ulMatrixBaseAddress + ulReadPointer;
845
 
 
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 ) )
849
 
                        {
850
 
                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= pSharedInfo->DebugInfo.ulDebugChanStatsByteSize )
851
 
                                        ulNumReads = pSharedInfo->DebugInfo.ulDebugChanStatsByteSize / 2;
852
 
                                else
853
 
                                        break;
854
 
                        }
855
 
                        else
856
 
                        {
857
 
                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize )
858
 
                                        ulNumReads = pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize / 2;
859
 
                                else
860
 
                                        break;
861
 
                        }
862
 
 
863
 
                        ulTempIndex = 0;
864
 
                        while ( ulNumReads != 0 )
865
 
                        {
866
 
                                if ( ulNumReads >= pSharedInfo->ChipConfig.usMaxRwAccesses )
867
 
                                        ReadBurstParams.ulReadLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
868
 
                                else
869
 
                                        ReadBurstParams.ulReadLength = ulNumReads;
870
 
 
871
 
                                /* Set pointer where to write data. */
872
 
                                ReadBurstParams.pusReadData = pSharedInfo->MiscVars.ausSuperArray;
873
 
 
874
 
                                mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
875
 
                                if ( ulResult != cOCT6100_ERR_OK )
876
 
                                        return ulResult;
877
 
 
878
 
                                /* Copy data byte per byte to avoid endianess problems. */
879
 
                                for ( ulCopyIndex = 0; ulCopyIndex < ReadBurstParams.ulReadLength; ulCopyIndex ++ )
880
 
                                {
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 );
883
 
                                }
884
 
 
885
 
                                /* Update indexes, temp variables, addresses. */
886
 
                                ulNumReads -= ReadBurstParams.ulReadLength;
887
 
                                ulTempIndex += ReadBurstParams.ulReadLength * 2;
888
 
                                ReadBurstParams.ulReadAddress += ReadBurstParams.ulReadLength * 2;
889
 
                        }
890
 
 
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 );
894
 
 
895
 
                        /* Increment index. */
896
 
                        if ( ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_16S )
897
 
                                || ( f_pGetData->ulGetDataMode == cOCT6100_DEBUG_GET_DATA_MODE_120S ) )
898
 
                        {
899
 
                                ulUserBufWriteIndex += pSharedInfo->DebugInfo.ulDebugChanStatsByteSize;
900
 
                        }
901
 
                        else
902
 
                        {
903
 
                                ulUserBufWriteIndex += pSharedInfo->DebugInfo.ulDebugChanLiteStatsByteSize;
904
 
                        }
905
 
 
906
 
                        /* Increment read pointer to get next event. */
907
 
                        ulReadPointer = ( ulReadPointer + pSharedInfo->DebugInfo.ulDebugChanStatsByteSize ) % ( ( pSharedInfo->DebugInfo.usMatrixCBMask + 1 ) * pSharedInfo->DebugInfo.ulDebugChanStatsByteSize );
908
 
 
909
 
                        /* Save in the instance that one of the events was dumped. */
910
 
                        pSharedInfo->DebugInfo.usLastDebugEventIndex ++;
911
 
                }
912
 
        }
913
 
 
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 ) )
917
 
        {
918
 
                /* Fetch all streams per event. */
919
 
                for ( ulPcmSampleIndex = pSharedInfo->DebugInfo.ulLastPcmSampleIndex; ulPcmSampleIndex < ( (UINT32)pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ); ulPcmSampleIndex ++ )
920
 
                {
921
 
                        /* Check if enough room for this sample. */
922
 
                        if ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
923
 
                        {
924
 
                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < 1 )
925
 
                                        break;
926
 
                        }
927
 
                        else /* if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) */
928
 
                        {
929
 
                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < 3 )
930
 
                                        break;
931
 
                        }
932
 
                        
933
 
                        /* Check if must retrieve data from external memory. */
934
 
                        if ( ( ulPcmSampleIndex % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE * 2 ) ) == 0x0 )
935
 
                        {
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;
940
 
 
941
 
                                /* Retrieve more data from external memory. */
942
 
                                switch ( f_pGetData->ulGetDataContent )
943
 
                                {
944
 
                                case cOCT6100_DEBUG_GET_DATA_CONTENT_RIN_PCM:
945
 
                                        ulStreamIndexMin = 0;
946
 
                                        ulStreamIndexMax = 1;
947
 
                                        break;
948
 
                                case cOCT6100_DEBUG_GET_DATA_CONTENT_SIN_PCM:
949
 
                                        ulStreamIndexMin = 1;
950
 
                                        ulStreamIndexMax = 2;
951
 
                                        break;
952
 
                                case cOCT6100_DEBUG_GET_DATA_CONTENT_SOUT_PCM:
953
 
                                        ulStreamIndexMin = 2;
954
 
                                        ulStreamIndexMax = 3;
955
 
                                        break;
956
 
                                case cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE:
957
 
                                default:
958
 
                                        ulStreamIndexMin = 0;
959
 
                                        ulStreamIndexMax = 3;
960
 
                                        break;
961
 
                                }
962
 
 
963
 
                                for ( ulStreamIndex = ulStreamIndexMin; ulStreamIndex < ulStreamIndexMax; ulStreamIndex ++ )
964
 
                                {
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;
972
 
 
973
 
                                        /* As much as we can for the burst. */
974
 
                                        ulTempIndex = 0;
975
 
                                        ulNumReads = cOCT6100_INTERNAL_SUPER_ARRAY_SIZE;
976
 
                                        while ( ulNumReads != 0 )
977
 
                                        {
978
 
                                                if ( ulNumReads >= pSharedInfo->ChipConfig.usMaxRwAccesses )
979
 
                                                        ReadBurstParams.ulReadLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
980
 
                                                else
981
 
                                                        ReadBurstParams.ulReadLength = ulNumReads;
982
 
 
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 ];
990
 
 
991
 
                                                mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
992
 
                                                if ( ulResult != cOCT6100_ERR_OK )
993
 
                                                        return ulResult;
994
 
 
995
 
                                                /* Update indexes, temp variables, addresses. */
996
 
                                                ulNumReads -= ReadBurstParams.ulReadLength;
997
 
                                                ulTempIndex += ReadBurstParams.ulReadLength;
998
 
                                                ReadBurstParams.ulReadAddress += ReadBurstParams.ulReadLength * 2;
999
 
                                        }
1000
 
                                }
1001
 
                        }
1002
 
 
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 )
1006
 
                        {
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 );
1010
 
 
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 );
1014
 
                                
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 );
1018
 
                        }
1019
 
                        else /* if ( ulPcmSampleIndex % 2 == 1 ) */
1020
 
                        {
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 );
1024
 
 
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 );
1028
 
 
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 );
1032
 
                        }
1033
 
 
1034
 
                        pSharedInfo->DebugInfo.ulLastPcmSampleIndex++;
1035
 
                }
1036
 
 
1037
 
                /* Check if we are done dumping the PCM samples! */
1038
 
                if ( pSharedInfo->DebugInfo.ulLastPcmSampleIndex == ( (UINT32)pSharedInfo->DebugInfo.usNumEvents * pSharedInfo->DebugInfo.ulRecordedPcmEventByteSize ) )
1039
 
                {
1040
 
                        if ( f_pGetData->ulGetDataContent == cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE )
1041
 
                        {
1042
 
 
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 ) )
1046
 
                                {
1047
 
                                        while ( pSharedInfo->DebugInfo.usLastAfLogReadPtr != pSharedInfo->DebugInfo.usAfLogWritePtr )
1048
 
                                        {
1049
 
                                                /* Check if enough room for an event. */
1050
 
                                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < 16 )
1051
 
                                                        break;
1052
 
 
1053
 
                                                /* Check if must fill our buffer. */
1054
 
                                                if ( ( pSharedInfo->DebugInfo.usLastAfLogReadPtr % ( cOCT6100_INTERNAL_SUPER_ARRAY_SIZE / 8 ) ) == 0x0 )
1055
 
                                                {
1056
 
                                                        ulNumAfEvents = ( pSharedInfo->DebugInfo.usAfLogWritePtr - pSharedInfo->DebugInfo.usLastAfLogReadPtr ) & 0xFFFF;
1057
 
 
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 );
1061
 
 
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 );
1068
 
 
1069
 
                                                        ulTempIndex = 0;
1070
 
                                                        ulNumReads = ulNumAfEvents * 8;
1071
 
 
1072
 
                                                        while ( ulNumReads != 0 )
1073
 
                                                        {
1074
 
                                                                if ( ulNumReads >= pSharedInfo->ChipConfig.usMaxRwAccesses )
1075
 
                                                                        ReadBurstParams.ulReadLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
1076
 
                                                                else
1077
 
                                                                        ReadBurstParams.ulReadLength = ulNumReads;
1078
 
 
1079
 
                                                                /* Set pointer where to write data. */
1080
 
                                                                ReadBurstParams.pusReadData = &pSharedInfo->MiscVars.ausSuperArray[ ulTempIndex ];
1081
 
 
1082
 
                                                                mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult );
1083
 
                                                                if ( ulResult != cOCT6100_ERR_OK )
1084
 
                                                                        return ulResult;
1085
 
 
1086
 
                                                                /* Update indexes, temp variables, addresses. */
1087
 
                                                                ulNumReads -= ReadBurstParams.ulReadLength;
1088
 
                                                                ulTempIndex += ReadBurstParams.ulReadLength;
1089
 
                                                                ReadBurstParams.ulReadAddress += ReadBurstParams.ulReadLength * 2;
1090
 
                                                        }
1091
 
                                                }
1092
 
 
1093
 
                                                /* Copy data byte per byte to avoid endianess problems. */
1094
 
                                                for ( ulCopyIndex = 0; ulCopyIndex < 8; ulCopyIndex ++ )
1095
 
                                                {
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 );
1098
 
                                                }
1099
 
 
1100
 
                                                ulUserBufWriteIndex += 16;
1101
 
 
1102
 
                                                /* Increment AF log read ptr. */
1103
 
                                                pSharedInfo->DebugInfo.usLastAfLogReadPtr = (UINT16)(( pSharedInfo->DebugInfo.usLastAfLogReadPtr + 1 ) & 0xFFFF );
1104
 
                                        }
1105
 
                                }
1106
 
 
1107
 
                                /* Check if we are done with the AF events. */
1108
 
                                if ( pSharedInfo->DebugInfo.usLastAfLogReadPtr == pSharedInfo->DebugInfo.usAfLogWritePtr )
1109
 
                                {
1110
 
                                        /* Insert the tone event information. */
1111
 
                                        for ( ulToneEventIndex = pSharedInfo->DebugInfo.usLastToneEventIndex; ulToneEventIndex < pSharedInfo->ImageInfo.byNumToneDetectors; ulToneEventIndex++ )
1112
 
                                        {
1113
 
                                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) < cOCT6100_TLV_MAX_TONE_NAME_SIZE )
1114
 
                                                        break;
1115
 
 
1116
 
                                                Oct6100UserMemCopy( &f_pGetData->pbyData[ ulUserBufWriteIndex ], pSharedInfo->ImageInfo.aToneInfo[ ulToneEventIndex ].aszToneName, cOCT6100_TLV_MAX_TONE_NAME_SIZE );
1117
 
 
1118
 
                                                ulUserBufWriteIndex += cOCT6100_TLV_MAX_TONE_NAME_SIZE;
1119
 
 
1120
 
                                                pSharedInfo->DebugInfo.usLastToneEventIndex++;
1121
 
                                        }
1122
 
 
1123
 
                                        /* If all the tone information has been copied. */
1124
 
                                        if ( ulToneEventIndex == pSharedInfo->ImageInfo.byNumToneDetectors )
1125
 
                                        {
1126
 
                                                /* Copy the image version. */
1127
 
                                                if ( pSharedInfo->DebugInfo.fImageVersionCopied == FALSE )
1128
 
                                                {
1129
 
                                                        if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= 512 )
1130
 
                                                        {
1131
 
                                                                Oct6100UserMemCopy( &f_pGetData->pbyData[ ulUserBufWriteIndex ], pSharedInfo->ImageInfo.szVersionNumber, 512 );
1132
 
 
1133
 
                                                                /* Get PLL jitter count from external memory. */
1134
 
                                                                if ( pSharedInfo->DebugInfo.fPouchCounter == TRUE )
1135
 
                                                                {
1136
 
                                                                        ulFeatureBytesOffset = pSharedInfo->MemoryMap.PouchCounterFieldOfst.usDwordOffset * 4;
1137
 
                                                                        ulFeatureBitOffset       = pSharedInfo->MemoryMap.PouchCounterFieldOfst.byBitOffset;
1138
 
                                                                        ulFeatureFieldLength = pSharedInfo->MemoryMap.PouchCounterFieldOfst.byFieldSize;
1139
 
 
1140
 
                                                                        ulResult = Oct6100ApiReadDword( f_pApiInstance,
1141
 
                                                                                                                                        cOCT6100_POUCH_BASE + ulFeatureBytesOffset,
1142
 
                                                                                                                                        &ulTempData );
1143
 
                                                                        
1144
 
                                                                        /* Create the mask to retrieve the appropriate value. */
1145
 
                                                                        mOCT6100_CREATE_FEATURE_MASK( ulFeatureFieldLength, ulFeatureBitOffset, &ulMask );
1146
 
 
1147
 
                                                                        /* Mask data. */
1148
 
                                                                        ulTempData &= ulMask;
1149
 
                                                                        /* Move to right position. */
1150
 
                                                                        ulTempData = ulTempData >> ulFeatureBitOffset;
1151
 
 
1152
 
                                                                        f_pGetData->pbyData[ ulUserBufWriteIndex + 510 ] = (UINT8)( ( ulTempData >> 8 ) & 0xFF );
1153
 
                                                                        f_pGetData->pbyData[ ulUserBufWriteIndex + 511 ] = (UINT8)( ( ulTempData >> 0 ) & 0xFF );
1154
 
                                                                }
1155
 
 
1156
 
                                                                /* Add "ISR is not called" bit. */
1157
 
                                                                if ( pSharedInfo->IntrptManage.fIsrCalled == FALSE )
1158
 
                                                                {
1159
 
                                                                        f_pGetData->pbyData[ ulUserBufWriteIndex + 510 ] |= 0x80;
1160
 
                                                                }
1161
 
 
1162
 
                                                                ulUserBufWriteIndex += 512;
1163
 
 
1164
 
                                                                /* The version has been copied. */
1165
 
                                                                pSharedInfo->DebugInfo.fImageVersionCopied = TRUE;
1166
 
                                                        }
1167
 
                                                }
1168
 
 
1169
 
                                                /* If the image version has been copied, proceed with the API version. */
1170
 
                                                if ( pSharedInfo->DebugInfo.fImageVersionCopied == TRUE )
1171
 
                                                {
1172
 
                                                        if ( pSharedInfo->DebugInfo.fApiVersionCopied == FALSE )
1173
 
                                                        {
1174
 
                                                                if ( ( f_pGetData->ulMaxBytes - ulUserBufWriteIndex ) >= sizeof(cOCT6100_API_VERSION) )
1175
 
                                                                {
1176
 
                                                                        Oct6100UserMemCopy( &f_pGetData->pbyData[ ulUserBufWriteIndex ], cOCT6100_API_VERSION, sizeof(cOCT6100_API_VERSION) );
1177
 
                                                                        ulUserBufWriteIndex += sizeof(cOCT6100_API_VERSION);
1178
 
 
1179
 
                                                                        /* The API version has been copied. */
1180
 
                                                                        pSharedInfo->DebugInfo.fApiVersionCopied = TRUE;
1181
 
                                                                }
1182
 
                                                        }
1183
 
                                                }
1184
 
                                        }
1185
 
 
1186
 
                                        /* Check if we are done! */
1187
 
                                        if ( pSharedInfo->DebugInfo.fApiVersionCopied == TRUE )
1188
 
                                        {
1189
 
                                                /* Done dumping. */
1190
 
 
1191
 
                                                /* Reset data being dumpped flag. */
1192
 
                                                pSharedInfo->DebugInfo.fDebugDataBeingDumped = FALSE;
1193
 
 
1194
 
                                                /* Reset data recording in the chip. */
1195
 
                                                WriteBurstParams.ulWriteAddress = pSharedInfo->DebugInfo.ulHotChannelSelectBaseAddress;
1196
 
                                                WriteBurstParams.ulWriteLength = 2;
1197
 
                                                WriteBurstParams.pusWriteData = pSharedInfo->DebugInfo.ausHotChannelData;
1198
 
 
1199
 
                                                mOCT6100_DRIVER_WRITE_BURST_API( WriteBurstParams, ulResult );
1200
 
                                                if ( ulResult != cOCT6100_ERR_OK )
1201
 
                                                        return ulResult;
1202
 
 
1203
 
                                                fResetRemainingDataFlag = TRUE;
1204
 
                                        }
1205
 
                                }
1206
 
                        }
1207
 
                        else /* if ( f_pGetData->ulGetDataContent != cOCT6100_DEBUG_GET_DATA_CONTENT_COMPLETE ) */
1208
 
                        {
1209
 
                                fResetRemainingDataFlag = TRUE;
1210
 
                        }
1211
 
                }
1212
 
        }
1213
 
 
1214
 
        /* Return number of valid bytes in buffer to user. */
1215
 
        f_pGetData->ulValidNumBytes = ulUserBufWriteIndex;
1216
 
 
1217
 
        /* Update remaining bytes. */
1218
 
        pSharedInfo->DebugInfo.ulDebugDataRemainingNumBytes -= ulUserBufWriteIndex;
1219
 
 
1220
 
        /* Return remaining bytes. */
1221
 
        f_pGetData->ulRemainingNumBytes = pSharedInfo->DebugInfo.ulDebugDataRemainingNumBytes;
1222
 
 
1223
 
        /* Return total number of bytes. */
1224
 
        f_pGetData->ulTotalNumBytes = pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes;
1225
 
 
1226
 
        /* Check if we are done dump the requested content. */
1227
 
        if ( fResetRemainingDataFlag == TRUE )
1228
 
                pSharedInfo->DebugInfo.ulDebugDataTotalNumBytes = cOCT6100_INVALID_VALUE;
1229
 
 
1230
 
        return cOCT6100_ERR_OK;
1231
 
}
1232
 
#endif