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

« back to all changes in this revision

Viewing changes to kernel/oct612x/octdeviceapi/oct6100api/oct6100_api/oct6100_interrupts.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_interrupts.c
 
4
 
 
5
    Copyright (c) 2001-2007 Octasic Inc.
 
6
    
 
7
Description: 
 
8
 
 
9
        This file contains the API's interrupt service routine and all of its
 
10
        sub-functions.
 
11
 
 
12
This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API  is 
 
13
free software; you can redistribute it and/or modify it under the terms of 
 
14
the GNU General Public License as published by the Free Software Foundation; 
 
15
either version 2 of the License, or (at your option) any later version.
 
16
 
 
17
The OCT6100 GPL API is distributed in the hope that it will be useful, but 
 
18
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 
19
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 
20
for more details. 
 
21
 
 
22
You should have received a copy of the GNU General Public License 
 
23
along with the OCT6100 GPL API; if not, write to the Free Software 
 
24
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
25
 
 
26
$Octasic_Release: OCT612xAPI-01.00-PR49 $
 
27
 
 
28
$Octasic_Revision: 81 $
 
29
 
 
30
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
31
 
 
32
 
 
33
/*****************************  INCLUDE FILES  *******************************/
 
34
 
 
35
#include "octdef.h"
 
36
 
 
37
#include "oct6100api/oct6100_defines.h"
 
38
#include "oct6100api/oct6100_errors.h"
 
39
#include "oct6100api/oct6100_apiud.h"
 
40
 
 
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
 
 
49
#include "oct6100api/oct6100_interrupts_pub.h"
 
50
#include "oct6100api/oct6100_chip_open_pub.h"
 
51
#include "oct6100api/oct6100_events_pub.h"
 
52
#include "oct6100api/oct6100_channel_pub.h"
 
53
#include "oct6100api/oct6100_interrupts_pub.h"
 
54
 
 
55
#include "oct6100_chip_open_priv.h"
 
56
#include "oct6100_miscellaneous_priv.h"
 
57
#include "oct6100_events_priv.h"
 
58
#include "oct6100_interrupts_priv.h"
 
59
 
 
60
/****************************  PUBLIC FUNCTIONS  *****************************/
 
61
 
 
62
 
 
63
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
64
 
 
65
Function:               Oct6100InterruptConfigure
 
66
 
 
67
Description:    Configure the operation of all possible interrupt sources.
 
68
 
 
69
-------------------------------------------------------------------------------
 
70
|       Argument                |       Description
 
71
-------------------------------------------------------------------------------
 
72
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
73
                                                the present state of the chip and all its resources.
 
74
 
 
75
f_pIntrptConfig                 Pointer to interrupt configuration structure.
 
76
 
 
77
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
78
#if !SKIP_Oct6100InterruptConfigureDef
 
79
UINT32 Oct6100InterruptConfigureDef(
 
80
                                tPOCT6100_INTERRUPT_CONFIGURE           f_pIntrptConfig )
 
81
{
 
82
        f_pIntrptConfig->ulFatalGeneralConfig = cOCT6100_INTERRUPT_NO_TIMEOUT;
 
83
        f_pIntrptConfig->ulFatalMemoryConfig = cOCT6100_INTERRUPT_NO_TIMEOUT;
 
84
 
 
85
        f_pIntrptConfig->ulErrorMemoryConfig = cOCT6100_INTERRUPT_NO_TIMEOUT;
 
86
        f_pIntrptConfig->ulErrorOverflowToneEventsConfig = cOCT6100_INTERRUPT_NO_TIMEOUT;
 
87
        f_pIntrptConfig->ulErrorH100Config = cOCT6100_INTERRUPT_NO_TIMEOUT;
 
88
 
 
89
        f_pIntrptConfig->ulFatalMemoryTimeout = 100;
 
90
 
 
91
        f_pIntrptConfig->ulErrorMemoryTimeout = 100;
 
92
        f_pIntrptConfig->ulErrorOverflowToneEventsTimeout = 100;
 
93
        f_pIntrptConfig->ulErrorH100Timeout = 100;
 
94
 
 
95
        return cOCT6100_ERR_OK;
 
96
}
 
97
#endif
 
98
 
 
99
 
 
100
#if !SKIP_Oct6100InterruptConfigure
 
101
UINT32 Oct6100InterruptConfigure(
 
102
                                tPOCT6100_INSTANCE_API                          f_pApiInstance,
 
103
                                tPOCT6100_INTERRUPT_CONFIGURE           f_pIntrptConfig )
 
104
{
 
105
        tOCT6100_SEIZE_SERIALIZE_OBJECT         SeizeSerObj;
 
106
        tOCT6100_RELEASE_SERIALIZE_OBJECT       ReleaseSerObj;
 
107
        UINT32  ulResult;
 
108
        UINT32  ulFncRes;
 
109
 
 
110
        /* Set the process context of the serialize structure.*/
 
111
        SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
 
112
        ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
 
113
 
 
114
        /* Create serialization object for ISR. */
 
115
        SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
 
116
        SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
 
117
        ulResult = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
 
118
        if ( ulResult != cOCT6100_ERR_OK )
 
119
                return ulResult;
 
120
 
 
121
        /* Call serialized sub-function. */
 
122
        ulFncRes = Oct6100InterruptConfigureSer( f_pApiInstance, f_pIntrptConfig, TRUE );
 
123
        /* Release serialization object. */
 
124
        ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
 
125
        ulResult = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
 
126
        if ( ulResult != cOCT6100_ERR_OK )
 
127
                return ulResult;
 
128
 
 
129
        /* Check if an error occured in sub-function. */
 
130
        if ( ulFncRes != cOCT6100_ERR_OK )
 
131
                return ulFncRes;
 
132
 
 
133
        return cOCT6100_ERR_OK;
 
134
}
 
135
#endif
 
136
 
 
137
 
 
138
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
139
 
 
140
Function:               Oct6100InterruptServiceRoutine
 
141
 
 
142
Description:    The API's interrupt service routine.  This function clears all
 
143
                                register ROLs which have generated an interrupt and report the
 
144
                                events in the user supplied structure.  Also, the tone event
 
145
                                and/or playout event buffer will be emptied if valid events 
 
146
                                are present.
 
147
 
 
148
-------------------------------------------------------------------------------
 
149
|       Argument                |       Description
 
150
-------------------------------------------------------------------------------
 
151
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
152
                                                the present state of the chip and all its resources.
 
153
 
 
154
f_pIntFlags                             Pointer to structure containing event flags returned
 
155
                                                to user.
 
156
 
 
157
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
158
#if !SKIP_Oct6100InterruptServiceRoutineDef
 
159
UINT32 Oct6100InterruptServiceRoutineDef(
 
160
                                tPOCT6100_INTERRUPT_FLAGS                       f_pIntFlags )
 
161
{
 
162
        f_pIntFlags->fFatalGeneral = FALSE;
 
163
        f_pIntFlags->ulFatalGeneralFlags = 0x0;
 
164
        f_pIntFlags->fFatalReadTimeout = FALSE;
 
165
        
 
166
        f_pIntFlags->fErrorRefreshTooLate = FALSE;
 
167
        f_pIntFlags->fErrorPllJitter = FALSE;
 
168
        
 
169
        f_pIntFlags->fErrorOverflowToneEvents = FALSE;
 
170
 
 
171
        f_pIntFlags->fErrorH100OutOfSync = FALSE;
 
172
        f_pIntFlags->fErrorH100ClkA = FALSE;
 
173
        f_pIntFlags->fErrorH100ClkB = FALSE;
 
174
        f_pIntFlags->fErrorH100FrameA = FALSE;
 
175
 
 
176
        f_pIntFlags->fToneEventsPending = FALSE;
 
177
        f_pIntFlags->fBufferPlayoutEventsPending = FALSE;
 
178
 
 
179
        f_pIntFlags->fApiSynch = FALSE;
 
180
 
 
181
 
 
182
 
 
183
        return cOCT6100_ERR_OK;
 
184
}
 
185
#endif
 
186
 
 
187
 
 
188
#if !SKIP_Oct6100InterruptServiceRoutine
 
189
UINT32 Oct6100InterruptServiceRoutine(
 
190
                                tPOCT6100_INSTANCE_API                          f_pApiInstance,
 
191
                                tPOCT6100_INTERRUPT_FLAGS                       f_pIntFlags )
 
192
{
 
193
        tOCT6100_SEIZE_SERIALIZE_OBJECT         SeizeSerObj;
 
194
        tOCT6100_RELEASE_SERIALIZE_OBJECT       ReleaseSerObj;
 
195
        UINT32  ulResult;
 
196
        UINT32  ulFncRes;
 
197
 
 
198
        /* Set the process context of the serialize structure. */
 
199
        SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
 
200
        ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
 
201
 
 
202
        /* Seize the serialization object for the ISR. */
 
203
        SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
 
204
        SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
 
205
        ulResult = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
 
206
        if ( ulResult == cOCT6100_ERR_OK )
 
207
        {       
 
208
                /* Call the serialized sub-function. */
 
209
                ulFncRes = Oct6100InterruptServiceRoutineSer( f_pApiInstance, f_pIntFlags );
 
210
        }
 
211
        else
 
212
        {
 
213
                return ulResult;
 
214
        }
 
215
 
 
216
        /* Release the serialization object. */
 
217
        ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
 
218
        ulResult = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
 
219
        if ( ulResult != cOCT6100_ERR_OK )
 
220
                return ulResult;
 
221
 
 
222
        /* Check for an error in the sub-function. */
 
223
        if ( ulFncRes != cOCT6100_ERR_OK )
 
224
                return ulFncRes;
 
225
 
 
226
        return cOCT6100_ERR_OK;
 
227
}
 
228
#endif
 
229
 
 
230
 
 
231
/****************************  PRIVATE FUNCTIONS  ****************************/
 
232
 
 
233
 
 
234
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
235
 
 
236
Function:               Oct6100ApiIsrSwInit
 
237
 
 
238
Description:    Initializes portions of API instance associated to the API's 
 
239
                                interrupt service routine.
 
240
 
 
241
-------------------------------------------------------------------------------
 
242
|       Argument                |       Description
 
243
-------------------------------------------------------------------------------
 
244
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
245
                                                the present state of the chip and all its resources.
 
246
 
 
247
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
248
#if !SKIP_Oct6100ApiIsrSwInit
 
249
UINT32 Oct6100ApiIsrSwInit(
 
250
                                IN OUT  tPOCT6100_INSTANCE_API  f_pApiInstance )
 
251
{
 
252
        tPOCT6100_SHARED_INFO   pSharedInfo;
 
253
 
 
254
        /* Get local pointer to shared portion of instance. */
 
255
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
256
 
 
257
        /* Set the state of each interrupt group to disabled.  The state will */
 
258
        /* be updated to the true configuration once the configure interrupts function is called. */
 
259
        pSharedInfo->IntrptManage.byFatalGeneralState = cOCT6100_INTRPT_DISABLED;
 
260
        pSharedInfo->IntrptManage.byFatalMemoryState = cOCT6100_INTRPT_DISABLED;
 
261
        pSharedInfo->IntrptManage.byErrorMemoryState = cOCT6100_INTRPT_DISABLED;
 
262
        pSharedInfo->IntrptManage.byErrorH100State = cOCT6100_INTRPT_DISABLED;
 
263
        pSharedInfo->IntrptManage.byErrorOverflowToneEventsState = cOCT6100_INTRPT_DISABLED;
 
264
 
 
265
        /* Indicate that the mclk interrupt is not active at the moment. */
 
266
        pSharedInfo->IntrptManage.fMclkIntrptActive = FALSE;
 
267
 
 
268
        /* Indicate that no buffer playout events are pending for the moment. */
 
269
        pSharedInfo->IntrptManage.fBufferPlayoutEventsPending = FALSE;
 
270
 
 
271
        /* Indicate that no tone events are pending for the moment. */
 
272
        pSharedInfo->IntrptManage.fToneEventsPending = FALSE;
 
273
 
 
274
        /* The ISR has never been called. */
 
275
        pSharedInfo->IntrptManage.fIsrCalled = FALSE;
 
276
 
 
277
        return cOCT6100_ERR_OK;
 
278
}
 
279
#endif
 
280
 
 
281
 
 
282
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
283
 
 
284
Function:               Oct6100ApiIsrHwInit
 
285
 
 
286
Description:    Initializes the chip's interrupt registers.
 
287
 
 
288
-------------------------------------------------------------------------------
 
289
|       Argument                |       Description
 
290
-------------------------------------------------------------------------------
 
291
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
292
                                                the present state of the chip and all its resources.
 
293
 
 
294
f_pIntrptConfig                 Pointer to structure defining how the interrupts
 
295
                                                should be configured.
 
296
 
 
297
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
298
#if !SKIP_Oct6100ApiIsrHwInit
 
299
UINT32 Oct6100ApiIsrHwInit(
 
300
                        IN OUT  tPOCT6100_INSTANCE_API                          f_pApiInstance,
 
301
                        IN              tPOCT6100_INTERRUPT_CONFIGURE           f_pIntrptConfig )
 
302
{
 
303
        tOCT6100_WRITE_PARAMS   WriteParams;
 
304
        UINT32  ulResult;
 
305
 
 
306
        /* Set some parameters of write struct. */
 
307
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
308
 
 
309
        WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
 
310
 
 
311
        /*==================================================================================*/
 
312
        /* Enable all the interrupts */
 
313
        
 
314
        WriteParams.ulWriteAddress = 0x104;
 
315
        WriteParams.usWriteData = 0x0001;
 
316
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
317
        if ( ulResult != cOCT6100_ERR_OK )
 
318
                return ulResult;
 
319
 
 
320
        WriteParams.ulWriteAddress = 0x204;
 
321
        WriteParams.usWriteData = 0x1C05;
 
322
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
323
        if ( ulResult != cOCT6100_ERR_OK )
 
324
                return ulResult;
 
325
 
 
326
        WriteParams.ulWriteAddress = 0x304;
 
327
        WriteParams.usWriteData = 0xFFFF;
 
328
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
329
        if ( ulResult != cOCT6100_ERR_OK )
 
330
                return ulResult;
 
331
 
 
332
        WriteParams.ulWriteAddress = 0x504;
 
333
        WriteParams.usWriteData = 0x0002;
 
334
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
335
        if ( ulResult != cOCT6100_ERR_OK )
 
336
                return ulResult;
 
337
 
 
338
        WriteParams.ulWriteAddress = 0x704;
 
339
        WriteParams.usWriteData = 0x0007;
 
340
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
341
        if ( ulResult != cOCT6100_ERR_OK )
 
342
                return ulResult;
 
343
        
 
344
        /*==================================================================================*/
 
345
 
 
346
        /* Calculate the number of mclk cycles in 1 ms. */
 
347
        f_pApiInstance->pSharedInfo->IntrptManage.ulNumMclkCyclesIn1Ms = f_pApiInstance->pSharedInfo->MiscVars.ulMclkFreq / 1000;
 
348
 
 
349
        /* Configure the interrupt registers as requested by the user. */
 
350
        ulResult = Oct6100InterruptConfigureSer( f_pApiInstance, f_pIntrptConfig, TRUE );
 
351
        if ( ulResult != cOCT6100_ERR_OK )
 
352
                return ulResult;
 
353
 
 
354
        return cOCT6100_ERR_OK;
 
355
}
 
356
#endif
 
357
 
 
358
 
 
359
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
360
 
 
361
Function:               Oct6100InterruptConfigureSer
 
362
 
 
363
Description:    Configure the operation of interrupt groups.
 
364
 
 
365
-------------------------------------------------------------------------------
 
366
|       Argument                |       Description
 
367
-------------------------------------------------------------------------------
 
368
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
369
                                                the present state of the chip and all its resources.
 
370
 
 
371
f_pIntrptConfig                 Pointer to interrupt configuration structure.
 
372
f_fCheckParams                  Check parameter enable flag.
 
373
 
 
374
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
375
#if !SKIP_Oct6100InterruptConfigureSer
 
376
UINT32 Oct6100InterruptConfigureSer(
 
377
                        IN OUT  tPOCT6100_INSTANCE_API                          f_pApiInstance,
 
378
                        IN              tPOCT6100_INTERRUPT_CONFIGURE           f_pIntrptConfig,
 
379
                        IN              BOOL                                                            f_fCheckParams )
 
380
{
 
381
        tPOCT6100_API_INTRPT_CONFIG     pIntrptConfig;
 
382
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
383
        UINT32  ulResult;
 
384
 
 
385
        /* Check for errors. */
 
386
        if ( f_fCheckParams == TRUE )
 
387
        {
 
388
                if ( f_pIntrptConfig->ulFatalGeneralConfig != cOCT6100_INTERRUPT_DISABLE &&
 
389
                         f_pIntrptConfig->ulFatalGeneralConfig != cOCT6100_INTERRUPT_NO_TIMEOUT )
 
390
                        return cOCT6100_ERR_INTRPTS_FATAL_GENERAL_CONFIG;
 
391
                if ( f_pIntrptConfig->ulFatalMemoryConfig != cOCT6100_INTERRUPT_DISABLE &&
 
392
                         f_pIntrptConfig->ulFatalMemoryConfig != cOCT6100_INTERRUPT_TIMEOUT &&
 
393
                         f_pIntrptConfig->ulFatalMemoryConfig != cOCT6100_INTERRUPT_NO_TIMEOUT )
 
394
                        return cOCT6100_ERR_INTRPTS_FATAL_MEMORY_CONFIG;
 
395
                if ( f_pIntrptConfig->ulErrorMemoryConfig != cOCT6100_INTERRUPT_DISABLE &&
 
396
                         f_pIntrptConfig->ulErrorMemoryConfig != cOCT6100_INTERRUPT_TIMEOUT &&
 
397
                         f_pIntrptConfig->ulErrorMemoryConfig != cOCT6100_INTERRUPT_NO_TIMEOUT )
 
398
                        return cOCT6100_ERR_INTRPTS_DATA_ERR_MEMORY_CONFIG;
 
399
                if ( f_pIntrptConfig->ulErrorOverflowToneEventsConfig != cOCT6100_INTERRUPT_DISABLE &&
 
400
                         f_pIntrptConfig->ulErrorOverflowToneEventsConfig != cOCT6100_INTERRUPT_TIMEOUT &&
 
401
                         f_pIntrptConfig->ulErrorOverflowToneEventsConfig != cOCT6100_INTERRUPT_NO_TIMEOUT )
 
402
                        return cOCT6100_ERR_INTRPTS_OVERFLOW_TONE_EVENTS_CONFIG;
 
403
                if ( f_pIntrptConfig->ulErrorH100Config != cOCT6100_INTERRUPT_DISABLE &&
 
404
                         f_pIntrptConfig->ulErrorH100Config != cOCT6100_INTERRUPT_TIMEOUT &&
 
405
                         f_pIntrptConfig->ulErrorH100Config != cOCT6100_INTERRUPT_NO_TIMEOUT )
 
406
                        return cOCT6100_ERR_INTRPTS_H100_ERROR_CONFIG;
 
407
 
 
408
                if ( f_pIntrptConfig->ulFatalMemoryTimeout < 10 ||
 
409
                         f_pIntrptConfig->ulFatalMemoryTimeout > 10000 )
 
410
                        return cOCT6100_ERR_INTRPTS_FATAL_MEMORY_TIMEOUT;
 
411
                if ( f_pIntrptConfig->ulErrorMemoryTimeout < 10 ||
 
412
                         f_pIntrptConfig->ulErrorMemoryTimeout > 10000 )
 
413
                        return cOCT6100_ERR_INTRPTS_DATA_ERR_MEMORY_TIMEOUT;
 
414
                if ( f_pIntrptConfig->ulErrorOverflowToneEventsTimeout < 10 ||
 
415
                         f_pIntrptConfig->ulErrorOverflowToneEventsTimeout > 10000 )
 
416
                        return cOCT6100_ERR_INTRPTS_OVERFLOW_TONE_EVENTS_TIMEOUT;
 
417
                if ( f_pIntrptConfig->ulErrorH100Timeout < 10 ||
 
418
                         f_pIntrptConfig->ulErrorH100Timeout > 10000 )
 
419
                        return cOCT6100_ERR_INTRPTS_H100_ERROR_TIMEOUT;
 
420
        }
 
421
 
 
422
        /* Copy the configuration to the API instance. */
 
423
        pIntrptConfig = &f_pApiInstance->pSharedInfo->IntrptConfig;
 
424
        pIntrptManage = &f_pApiInstance->pSharedInfo->IntrptManage;
 
425
 
 
426
        pIntrptConfig->byFatalGeneralConfig = (UINT8)( f_pIntrptConfig->ulFatalGeneralConfig & 0xFF );
 
427
        pIntrptConfig->byFatalMemoryConfig = (UINT8)( f_pIntrptConfig->ulFatalMemoryConfig & 0xFF );
 
428
        pIntrptConfig->byErrorMemoryConfig = (UINT8)( f_pIntrptConfig->ulErrorMemoryConfig & 0xFF );
 
429
        pIntrptConfig->byErrorOverflowToneEventsConfig = (UINT8)( f_pIntrptConfig->ulErrorOverflowToneEventsConfig & 0xFF );
 
430
        pIntrptConfig->byErrorH100Config = (UINT8)( f_pIntrptConfig->ulErrorH100Config & 0xFF );
 
431
 
 
432
        f_pIntrptConfig->ulFatalMemoryTimeout = ((f_pIntrptConfig->ulFatalMemoryTimeout + 9) / 10) * 10;
 
433
        pIntrptConfig->ulFatalMemoryTimeoutMclk = f_pIntrptConfig->ulFatalMemoryTimeout * pIntrptManage->ulNumMclkCyclesIn1Ms;
 
434
 
 
435
        f_pIntrptConfig->ulErrorMemoryTimeout = ((f_pIntrptConfig->ulErrorMemoryTimeout + 9) / 10) * 10;
 
436
        pIntrptConfig->ulErrorMemoryTimeoutMclk = f_pIntrptConfig->ulErrorMemoryTimeout * pIntrptManage->ulNumMclkCyclesIn1Ms;
 
437
 
 
438
        f_pIntrptConfig->ulErrorOverflowToneEventsTimeout = ((f_pIntrptConfig->ulErrorOverflowToneEventsTimeout + 9) / 10) * 10;
 
439
        pIntrptConfig->ulErrorOverflowToneEventsTimeoutMclk = f_pIntrptConfig->ulErrorOverflowToneEventsTimeout * pIntrptManage->ulNumMclkCyclesIn1Ms;
 
440
 
 
441
        f_pIntrptConfig->ulErrorH100Timeout = ((f_pIntrptConfig->ulErrorH100Timeout + 9) / 10) * 10;
 
442
        pIntrptConfig->ulErrorH100TimeoutMclk = f_pIntrptConfig->ulErrorH100Timeout * pIntrptManage->ulNumMclkCyclesIn1Ms;
 
443
 
 
444
 
 
445
        /*Clear all interrupts that were already enabled*/
 
446
        ulResult = Oct6100ApiClearEnabledInterrupts( f_pApiInstance );
 
447
        if ( ulResult != cOCT6100_ERR_OK )
 
448
                return ulResult;
 
449
 
 
450
        /* Before writing the new configuration to the chip's registers, make sure that any */
 
451
        /* interrupts which are either disabled or have no timeout period are not on the */
 
452
        /* disabled interrupt list. */
 
453
 
 
454
        /*==================================================================================*/
 
455
        if ( pIntrptConfig->byFatalGeneralConfig == cOCT6100_INTERRUPT_DISABLE )
 
456
                pIntrptManage->byFatalGeneralState = cOCT6100_INTRPT_DISABLED;
 
457
        else /* pIntrptConfig->byFatalGeneralConfig == cOCT6100_INTERRUPT_NO_TIMEOUT */
 
458
                pIntrptManage->byFatalGeneralState = cOCT6100_INTRPT_ACTIVE;
 
459
 
 
460
        /*==================================================================================*/
 
461
        if ( pIntrptConfig->byFatalMemoryConfig == cOCT6100_INTERRUPT_DISABLE )
 
462
                pIntrptManage->byFatalMemoryState = cOCT6100_INTRPT_DISABLED;
 
463
        else if ( pIntrptConfig->byFatalMemoryConfig == cOCT6100_INTERRUPT_NO_TIMEOUT )
 
464
                pIntrptManage->byFatalMemoryState = cOCT6100_INTRPT_ACTIVE;
 
465
        else /* ( pIntrptConfig->byFatalMemoryConfig == cOCT6100_INTERRUPT_TIMEOUT ) */
 
466
        {
 
467
                if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_DISABLED )
 
468
                        pIntrptManage->byFatalMemoryState = cOCT6100_INTRPT_ACTIVE;
 
469
        }
 
470
 
 
471
        /*==================================================================================*/
 
472
        if ( pIntrptConfig->byErrorMemoryConfig == cOCT6100_INTERRUPT_DISABLE )
 
473
                pIntrptManage->byErrorMemoryState = cOCT6100_INTRPT_DISABLED;
 
474
        else if ( pIntrptConfig->byErrorMemoryConfig == cOCT6100_INTERRUPT_NO_TIMEOUT )
 
475
                pIntrptManage->byErrorMemoryState = cOCT6100_INTRPT_ACTIVE;
 
476
        else /* (pIntrptConfig->byErrorMemoryConfig == cOCT6100_INTERRUPT_TIMEOUT ) */
 
477
        {
 
478
                if ( pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_DISABLED )
 
479
                        pIntrptManage->byErrorMemoryState = cOCT6100_INTRPT_ACTIVE;
 
480
        }
 
481
 
 
482
        /*==================================================================================*/
 
483
        if ( pIntrptConfig->byErrorOverflowToneEventsConfig == cOCT6100_INTERRUPT_DISABLE )
 
484
                pIntrptManage->byErrorOverflowToneEventsState = cOCT6100_INTRPT_DISABLED;
 
485
        else if ( pIntrptConfig->byErrorOverflowToneEventsConfig == cOCT6100_INTERRUPT_NO_TIMEOUT )
 
486
                pIntrptManage->byErrorOverflowToneEventsState = cOCT6100_INTRPT_ACTIVE;
 
487
        else /* (pIntrptConfig->byErrorOverflowToneEventsConfig == cOCT6100_INTERRUPT_TIMEOUT ) */
 
488
        {
 
489
                if ( pIntrptManage->byErrorOverflowToneEventsState == cOCT6100_INTRPT_DISABLED )
 
490
                        pIntrptManage->byErrorOverflowToneEventsState = cOCT6100_INTRPT_ACTIVE;
 
491
        }
 
492
 
 
493
        /*==================================================================================*/
 
494
        if ( pIntrptConfig->byErrorH100Config == cOCT6100_INTERRUPT_DISABLE )
 
495
                pIntrptManage->byErrorH100State = cOCT6100_INTRPT_DISABLED;
 
496
        else if ( pIntrptConfig->byErrorH100Config == cOCT6100_INTERRUPT_NO_TIMEOUT )
 
497
                pIntrptManage->byErrorH100State = cOCT6100_INTRPT_ACTIVE;
 
498
        else /* (pIntrptConfig->byErrorH100Config == cOCT6100_INTERRUPT_TIMEOUT ) */
 
499
        {
 
500
                if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_DISABLED )
 
501
                        pIntrptManage->byErrorH100State = cOCT6100_INTRPT_ACTIVE;
 
502
        }
 
503
 
 
504
 
 
505
        /* Write to the interrupt registers to update the state of each interrupt group. */
 
506
        ulResult = Oct6100ApiWriteIeRegs( f_pApiInstance );
 
507
        if ( ulResult != cOCT6100_ERR_OK )
 
508
                return ulResult;
 
509
 
 
510
        return cOCT6100_ERR_OK;
 
511
}
 
512
#endif
 
513
 
 
514
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
515
 
 
516
Function:               Oct6100ApiClearEnabledInterrupts
 
517
 
 
518
Description:    Disabled interruption are not reported but still available. This 
 
519
                                function will clear the interrupts that were disabled and wish
 
520
                                to enable now.
 
521
 
 
522
-------------------------------------------------------------------------------
 
523
|       Argument                |       Description
 
524
-------------------------------------------------------------------------------
 
525
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
526
                                                the present state of the chip and all its resources.
 
527
 
 
528
f_pIntrptConfig                 Pointer to interrupt configuration structure.
 
529
f_pIntrptManage                 Pointer to interrupt manager structure.
 
530
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
531
 
 
532
#if !SKIP_Oct6100ApiClearEnabledInterrupts
 
533
UINT32 Oct6100ApiClearEnabledInterrupts(
 
534
                        IN      tPOCT6100_INSTANCE_API                          f_pApiInstance ) 
 
535
{
 
536
        
 
537
        tPOCT6100_SHARED_INFO           pSharedInfo;
 
538
        tOCT6100_WRITE_PARAMS           WriteParams;
 
539
        tPOCT6100_API_INTRPT_CONFIG     pIntrptConfig;
 
540
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
541
        UINT32                                          ulResult;
 
542
 
 
543
        /* Get local pointer to shared portion of instance. */
 
544
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
545
 
 
546
        /* Set the process context and user chip ID parameters once and for all. */
 
547
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
548
 
 
549
        WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
550
 
 
551
        /* Copy the configuration to the API instance. */
 
552
        pIntrptConfig = &f_pApiInstance->pSharedInfo->IntrptConfig;
 
553
        pIntrptManage = &f_pApiInstance->pSharedInfo->IntrptManage;
 
554
 
 
555
        if ( pIntrptConfig->byFatalGeneralConfig != cOCT6100_INTERRUPT_DISABLE &&
 
556
                 pIntrptManage->byFatalGeneralState != cOCT6100_INTRPT_DISABLED )
 
557
        {
 
558
                WriteParams.ulWriteAddress = 0x102;
 
559
                WriteParams.usWriteData = cOCT6100_INTRPT_MASK_REG_102H;
 
560
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
561
                if ( ulResult != cOCT6100_ERR_OK )
 
562
                        return ulResult;        
 
563
 
 
564
                WriteParams.ulWriteAddress = 0x202;
 
565
                WriteParams.usWriteData = 0x1800;
 
566
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
567
                if ( ulResult != cOCT6100_ERR_OK )
 
568
                        return ulResult;
 
569
 
 
570
                WriteParams.ulWriteAddress = 0x502;
 
571
                WriteParams.usWriteData = cOCT6100_INTRPT_MASK_REG_502H;
 
572
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
573
                if ( ulResult != cOCT6100_ERR_OK )
 
574
                        return ulResult;
 
575
        }
 
576
 
 
577
        if ( pIntrptConfig->byErrorMemoryConfig != cOCT6100_INTERRUPT_DISABLE &&
 
578
                 pIntrptManage->byErrorMemoryState != cOCT6100_INTRPT_DISABLED )
 
579
        {
 
580
                WriteParams.ulWriteAddress = 0x202;
 
581
                WriteParams.usWriteData = cOCT6100_INTRPT_MASK_REG_202H;
 
582
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
583
                if ( ulResult != cOCT6100_ERR_OK )
 
584
                        return ulResult;
 
585
        }
 
586
        
 
587
        if ( pIntrptConfig->byErrorH100Config != cOCT6100_INTERRUPT_DISABLE &&
 
588
                 pIntrptManage->byErrorH100State != cOCT6100_INTRPT_DISABLED )
 
589
        {
 
590
                WriteParams.ulWriteAddress = 0x302;
 
591
                WriteParams.usWriteData = cOCT6100_INTRPT_MASK_REG_302H;
 
592
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
593
                if ( ulResult != cOCT6100_ERR_OK )
 
594
                        return ulResult;
 
595
        }
 
596
 
 
597
        if ( pIntrptConfig->byErrorOverflowToneEventsConfig != cOCT6100_INTERRUPT_DISABLE &&
 
598
                 pIntrptManage->byErrorOverflowToneEventsState != cOCT6100_INTRPT_DISABLED )
 
599
        {
 
600
                WriteParams.ulWriteAddress = 0x702;
 
601
                WriteParams.usWriteData = cOCT6100_INTRPT_MASK_REG_702H;
 
602
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
603
                if ( ulResult != cOCT6100_ERR_OK )
 
604
                        return ulResult;
 
605
        }
 
606
 
 
607
 
 
608
        return cOCT6100_ERR_OK;
 
609
 
 
610
}
 
611
#endif
 
612
 
 
613
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
614
 
 
615
Function:               Oct6100InterruptServiceRoutineSer
 
616
 
 
617
Description:    Serialized sub-function of API's interrupt service routine.
 
618
 
 
619
-------------------------------------------------------------------------------
 
620
|       Argument                |       Description
 
621
-------------------------------------------------------------------------------
 
622
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
623
                                                the present state of the chip and all its resources.
 
624
 
 
625
f_pIntFlags                             Pointer to structure containing event flags returned
 
626
                                                to user.
 
627
 
 
628
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
629
#if !SKIP_Oct6100InterruptServiceRoutineSer
 
630
UINT32 Oct6100InterruptServiceRoutineSer(
 
631
                        IN OUT  tPOCT6100_INSTANCE_API                          f_pApiInstance,
 
632
                        IN              tPOCT6100_INTERRUPT_FLAGS                       f_pIntFlags )
 
633
{
 
634
        tPOCT6100_SHARED_INFO   pSharedInfo;
 
635
        tOCT6100_READ_PARAMS    ReadParams;
 
636
        tOCT6100_WRITE_PARAMS   WriteParams;
 
637
        UINT32  ulRegister210h;
 
638
        UINT32  ulResult;
 
639
        UINT16  usReadData;
 
640
 
 
641
        /* Get local pointer(s). */
 
642
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
643
 
 
644
        /* Must update the statistics.  Set parameters in read and write structs. */
 
645
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
646
 
 
647
        WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
648
 
 
649
        ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
 
650
 
 
651
        ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
652
        ReadParams.pusReadData = &usReadData;
 
653
        
 
654
        /* Set all the flags to default values to make sure the variables are initialized. */
 
655
        f_pIntFlags->fFatalGeneral = FALSE;
 
656
        f_pIntFlags->ulFatalGeneralFlags = 0x0;
 
657
        f_pIntFlags->fFatalReadTimeout = FALSE;
 
658
        
 
659
        f_pIntFlags->fErrorRefreshTooLate = FALSE;
 
660
        f_pIntFlags->fErrorPllJitter = FALSE;
 
661
 
 
662
        f_pIntFlags->fErrorH100OutOfSync = FALSE;
 
663
        f_pIntFlags->fErrorH100ClkA = FALSE;
 
664
        f_pIntFlags->fErrorH100ClkB = FALSE;
 
665
        f_pIntFlags->fErrorH100FrameA = FALSE;
 
666
        f_pIntFlags->fApiSynch = FALSE;
 
667
        
 
668
        f_pIntFlags->fErrorOverflowToneEvents = FALSE;
 
669
 
 
670
        /* Start by reading registers 210h to determine if any modules have flagged an interrupt. */
 
671
        ReadParams.ulReadAddress = 0x210;
 
672
        mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
673
        if ( ulResult != cOCT6100_ERR_OK )
 
674
                return ulResult;
 
675
        ulRegister210h = usReadData;
 
676
 
 
677
        /* Update the extended mclk counter. */
 
678
        ulResult = Oct6100ApiReadChipMclkTime( f_pApiInstance );
 
679
        if ( ulResult != cOCT6100_ERR_OK )
 
680
                return ulResult;
 
681
 
 
682
        /* If the mclk interrupt is active then check which interrupt timeout periods have expired. */
 
683
        ReadParams.ulReadAddress = 0x302;
 
684
        mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
685
        if ( ulResult != cOCT6100_ERR_OK )
 
686
                return ulResult;
 
687
        if ( (usReadData & 0x1) != 0 && pSharedInfo->IntrptManage.fMclkIntrptActive == TRUE )
 
688
        {
 
689
                /* Update timeout periods. */
 
690
                ulResult = Oct6100ApiUpdateIntrptTimeouts( f_pApiInstance );
 
691
                if ( ulResult != cOCT6100_ERR_OK )
 
692
                        return ulResult;
 
693
 
 
694
                f_pIntFlags->fApiSynch = TRUE;
 
695
 
 
696
                /* Read registers 210h and 212h again to determine if any modules have flagged an interrupt. */
 
697
                ReadParams.ulReadAddress = 0x210;
 
698
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
699
                if ( ulResult != cOCT6100_ERR_OK )
 
700
                        return ulResult;
 
701
                ulRegister210h = usReadData;
 
702
        }
 
703
 
 
704
        /* Read the interrupt registers to determine what interrupt conditions have occured. */
 
705
        ulResult = Oct6100ApiReadIntrptRegs( f_pApiInstance, f_pIntFlags, ulRegister210h );
 
706
        if ( ulResult != cOCT6100_ERR_OK )
 
707
                return ulResult;
 
708
 
 
709
        /* Empty the tone buffer if any events are pending. */
 
710
        ulResult = Oct6100ApiTransferToneEvents( f_pApiInstance, FALSE );
 
711
        if ( ulResult != cOCT6100_ERR_OK )
 
712
                return ulResult;
 
713
 
 
714
        /* Set the tone events pending flag. */
 
715
        f_pIntFlags->fToneEventsPending = pSharedInfo->IntrptManage.fToneEventsPending;
 
716
 
 
717
        /* Check for buffer playout events and insert in the software queue -- if activated. */
 
718
        if ( pSharedInfo->ChipConfig.ulSoftBufPlayoutEventsBufSize != 0 )
 
719
        {
 
720
                ulResult = Oct6100BufferPlayoutTransferEvents( f_pApiInstance, FALSE );
 
721
                if ( ulResult != cOCT6100_ERR_OK )
 
722
                        return ulResult;
 
723
 
 
724
                /* Set the buffer playout events pending flag. */
 
725
                f_pIntFlags->fBufferPlayoutEventsPending = pSharedInfo->IntrptManage.fBufferPlayoutEventsPending;
 
726
        }
 
727
        else
 
728
        {
 
729
                f_pIntFlags->fBufferPlayoutEventsPending = FALSE;
 
730
        }
 
731
 
 
732
        /* Update the states of each interrupt group. */
 
733
        ulResult = Oct6100ApiUpdateIntrptStates( f_pApiInstance, f_pIntFlags );
 
734
        if ( ulResult != cOCT6100_ERR_OK )
 
735
                return ulResult;
 
736
 
 
737
        /* Check the state of the NLP timestamp if required.*/
 
738
        ulResult = Oct6100ApiCheckProcessorState( f_pApiInstance, f_pIntFlags );
 
739
        if ( ulResult != cOCT6100_ERR_OK )
 
740
                return ulResult;
 
741
 
 
742
        /* Write to the necessary IE registers. */
 
743
        ulResult = Oct6100ApiWriteIntrptRegs( f_pApiInstance );
 
744
        if ( ulResult != cOCT6100_ERR_OK )
 
745
                return ulResult;
 
746
 
 
747
        /* Schedule the next mclk interrupt, if one is needed. */
 
748
        ulResult = Oct6100ApiScheduleNextMclkIntrptSer( f_pApiInstance );
 
749
        if ( ulResult != cOCT6100_ERR_OK )
 
750
                return ulResult;
 
751
 
 
752
        /* Free the interrupt pin of the chip (i.e. remove minimum time requirement between interrupts). */
 
753
        WriteParams.ulWriteAddress = 0x214;
 
754
        WriteParams.usWriteData = 0x0000;
 
755
        if ( pSharedInfo->ChipConfig.byInterruptPolarity == cOCT6100_ACTIVE_HIGH_POLARITY )
 
756
                WriteParams.usWriteData |= 0x4000;
 
757
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
758
        if ( ulResult != cOCT6100_ERR_OK )
 
759
                return ulResult;
 
760
 
 
761
        /* Indicate that the interrupt ROLs have been treated. */
 
762
        WriteParams.ulWriteAddress = 0x212;
 
763
        WriteParams.usWriteData = 0x8000;
 
764
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
765
        if ( ulResult != cOCT6100_ERR_OK )
 
766
                return ulResult;
 
767
 
 
768
        return cOCT6100_ERR_OK;
 
769
}
 
770
#endif
 
771
 
 
772
 
 
773
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
774
 
 
775
Function:               Oct6100ApiReadIntrptRegs
 
776
 
 
777
Description:    Reads the interrupt registers of all modules currently
 
778
                                indicating an interrupt condition.
 
779
 
 
780
-------------------------------------------------------------------------------
 
781
|       Argument                |       Description
 
782
-------------------------------------------------------------------------------
 
783
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
784
                                                the present state of the chip and all its resources.
 
785
 
 
786
f_pIntFlags                             Pointer to an interrupt flag structure.
 
787
f_ulRegister210h                Value of register 0x210.
 
788
 
 
789
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
790
#if !SKIP_Oct6100ApiReadIntrptRegs
 
791
UINT32 Oct6100ApiReadIntrptRegs(
 
792
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance,
 
793
                                OUT             tPOCT6100_INTERRUPT_FLAGS               f_pIntFlags,
 
794
                                IN              UINT32                                                  f_ulRegister210h )
 
795
{
 
796
        tPOCT6100_SHARED_INFO                   pSharedInfo;
 
797
        tPOCT6100_API_CHIP_ERROR_STATS  pErrorStats;
 
798
        tPOCT6100_API_INTRPT_MANAGE             pIntrptManage;
 
799
        tOCT6100_READ_PARAMS                    ReadParams;
 
800
        tOCT6100_WRITE_PARAMS                   WriteParams;
 
801
 
 
802
        UINT32  ulResult;
 
803
        UINT16  usReadData;
 
804
        UINT32  ulFeatureBytesOffset;
 
805
        UINT32  ulFeatureBitOffset;
 
806
        UINT32  ulFeatureFieldLength;
 
807
        UINT32  ulTempData;
 
808
        UINT32  ulCounterValue;
 
809
        UINT32  ulMask;
 
810
 
 
811
        /* Get local pointer(s). */
 
812
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
813
        pErrorStats = &pSharedInfo->ErrorStats;
 
814
        pIntrptManage = &pSharedInfo->IntrptManage;
 
815
 
 
816
        /* Set some parameters of read struct. */
 
817
        ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
 
818
 
 
819
        ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
820
        ReadParams.pusReadData = &usReadData;
 
821
 
 
822
        /* Set some parameters of write struct. */
 
823
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
824
 
 
825
        WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
826
 
 
827
 
 
828
 
 
829
        /* CPU registers. */
 
830
        if ( (f_ulRegister210h & 0x00001) != 0 )
 
831
        {
 
832
                /*=======================================================================*/
 
833
                /* Read registers of this module. */
 
834
                ReadParams.ulReadAddress = 0x102;
 
835
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
836
                if ( ulResult != cOCT6100_ERR_OK )
 
837
                        return ulResult;
 
838
 
 
839
                /* Check which interrupt(s) were set. */
 
840
                if ( (usReadData & 0x0001) != 0 )
 
841
                {
 
842
                        f_pIntFlags->fFatalReadTimeout = TRUE;
 
843
                        pErrorStats->ulInternalReadTimeoutCnt++;
 
844
                }
 
845
 
 
846
                pIntrptManage->usRegister102h = usReadData;
 
847
                /*=======================================================================*/
 
848
        }
 
849
        else
 
850
        {
 
851
                pIntrptManage->usRegister102h = 0x0;
 
852
        }
 
853
 
 
854
        /* MAIN registers. */
 
855
        if ( (f_ulRegister210h & 0x00002) != 0 )
 
856
        {
 
857
                /*=======================================================================*/
 
858
                /* Read registers of this module. */
 
859
                ReadParams.ulReadAddress = 0x202;
 
860
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
861
                if ( ulResult != cOCT6100_ERR_OK )
 
862
                        return ulResult;
 
863
 
 
864
                /* Save current value in instance. */
 
865
                pIntrptManage->usRegister202h = usReadData;
 
866
 
 
867
                /* Check which interrupts were set. */
 
868
                if ( (usReadData & 0x0001) != 0 )
 
869
                {
 
870
                        f_pIntFlags->fErrorRefreshTooLate = TRUE;
 
871
                        pErrorStats->ulSdramRefreshTooLateCnt++;
 
872
                }
 
873
                if ( (usReadData & 0x0800) != 0 )
 
874
                {
 
875
                        f_pIntFlags->ulFatalGeneralFlags |= cOCT6100_FATAL_GENERAL_ERROR_TYPE_1;
 
876
                        f_pIntFlags->fFatalGeneral = TRUE;
 
877
                        pErrorStats->fFatalChipError = TRUE;
 
878
                }
 
879
                if ( (usReadData & 0x1000) != 0 )
 
880
                {
 
881
                        f_pIntFlags->ulFatalGeneralFlags |= cOCT6100_FATAL_GENERAL_ERROR_TYPE_2;
 
882
                        f_pIntFlags->fFatalGeneral = TRUE;
 
883
                        pErrorStats->fFatalChipError = TRUE;
 
884
                }
 
885
                if ( (usReadData & 0x0400) != 0 )
 
886
                {
 
887
                        f_pIntFlags->fErrorPllJitter = TRUE;
 
888
                        pErrorStats->ulPllJitterErrorCnt++;
 
889
 
 
890
                        /* Update the PLL jitter error count here. */
 
891
                        if ( pSharedInfo->DebugInfo.fPouchCounter == TRUE )
 
892
                        {
 
893
                                ulFeatureBytesOffset = pSharedInfo->MemoryMap.PouchCounterFieldOfst.usDwordOffset * 4;
 
894
                                ulFeatureBitOffset       = pSharedInfo->MemoryMap.PouchCounterFieldOfst.byBitOffset;
 
895
                                ulFeatureFieldLength = pSharedInfo->MemoryMap.PouchCounterFieldOfst.byFieldSize;
 
896
 
 
897
                                ulResult = Oct6100ApiReadDword( f_pApiInstance,
 
898
                                                                                                cOCT6100_POUCH_BASE + ulFeatureBytesOffset,
 
899
                                                                                                &ulTempData );
 
900
                                
 
901
                                /* Read previous value set in the feature field. */
 
902
                                mOCT6100_CREATE_FEATURE_MASK( ulFeatureFieldLength, ulFeatureBitOffset, &ulMask );
 
903
 
 
904
                                /* Update counter. */
 
905
                                ulCounterValue = ulTempData & ulMask;
 
906
                                ulCounterValue = ulCounterValue >> ulFeatureBitOffset;
 
907
                                ulCounterValue ++;
 
908
                                /* Handle wrap around case. */
 
909
                                ulCounterValue &= ( 1 << ulFeatureFieldLength ) - 1;
 
910
 
 
911
                                /* Clear old counter value. */
 
912
                                ulTempData &= (~ulMask);
 
913
                                ulTempData |= ulCounterValue << ulFeatureBitOffset;
 
914
 
 
915
                                /* Write the DWORD where the field is located.*/
 
916
                                ulResult = Oct6100ApiWriteDword( f_pApiInstance,
 
917
                                                                                                 cOCT6100_POUCH_BASE + ulFeatureBytesOffset,
 
918
                                                                                                 ulTempData );
 
919
                                if ( ulResult != cOCT6100_ERR_OK )
 
920
                                        return ulResult;        
 
921
                        }
 
922
                }
 
923
 
 
924
                /*=======================================================================*/
 
925
        }
 
926
        else
 
927
        {
 
928
                pIntrptManage->usRegister202h = 0x0;
 
929
        }
 
930
 
 
931
        /* H.100 registers. */
 
932
        if ( (f_ulRegister210h & 0x00004) != 0 )
 
933
        {
 
934
                /*=======================================================================*/
 
935
                /* Read registers of this module. */
 
936
                ReadParams.ulReadAddress = 0x302;
 
937
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
938
                if ( ulResult != cOCT6100_ERR_OK )
 
939
                        return ulResult;
 
940
 
 
941
                /* Check which interrupts were set. */
 
942
                if ( (usReadData & 0x0100) != 0 )
 
943
                {
 
944
                        f_pIntFlags->fErrorH100OutOfSync = TRUE;
 
945
                        pErrorStats->ulH100OutOfSyncCnt++;
 
946
                }
 
947
                if ( (usReadData & 0x1000) != 0 )
 
948
                {
 
949
                        f_pIntFlags->fErrorH100FrameA = TRUE;
 
950
                        pErrorStats->ulH100FrameABadCnt++;
 
951
                }
 
952
                if ( (usReadData & 0x4000) != 0 )
 
953
                {
 
954
                        f_pIntFlags->fErrorH100ClkA = TRUE;
 
955
                        pErrorStats->ulH100ClkABadCnt++;
 
956
                }
 
957
                if ( (usReadData & 0x8000) != 0 )
 
958
                {
 
959
                        if ( f_pApiInstance->pSharedInfo->ChipConfig.fEnableFastH100Mode == TRUE )
 
960
                        {
 
961
                                f_pIntFlags->fErrorH100ClkB = TRUE;
 
962
                                pErrorStats->ulH100ClkBBadCnt++;
 
963
                        }
 
964
                }
 
965
 
 
966
                pIntrptManage->usRegister302h = usReadData;
 
967
                /*=======================================================================*/
 
968
        }
 
969
        else
 
970
        {
 
971
                pIntrptManage->usRegister302h = 0x0;
 
972
        }
 
973
 
 
974
        /* TDMIE registers. */
 
975
        if ( (f_ulRegister210h & 0x00010) != 0 )
 
976
        {
 
977
                /*=======================================================================*/
 
978
                /* Read register. */
 
979
                ReadParams.ulReadAddress = 0x502;
 
980
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
981
                if ( ulResult != cOCT6100_ERR_OK )
 
982
                        return ulResult;
 
983
 
 
984
                /* Check which interrupts were set. */
 
985
                if ( (usReadData & 0x0002) != 0 )
 
986
                {
 
987
                        f_pIntFlags->ulFatalGeneralFlags |= cOCT6100_FATAL_GENERAL_ERROR_TYPE_3;
 
988
                        f_pIntFlags->fFatalGeneral = TRUE;
 
989
                        pErrorStats->fFatalChipError = TRUE;
 
990
                }
 
991
 
 
992
                pIntrptManage->usRegister502h = usReadData;
 
993
                /*=======================================================================*/
 
994
        }
 
995
        else
 
996
        {
 
997
                pIntrptManage->usRegister502h = 0x0;
 
998
        }
 
999
 
 
1000
        /* PGSP registers. */
 
1001
        if ( (f_ulRegister210h & 0x00080) != 0 )
 
1002
        {
 
1003
                /*=======================================================================*/
 
1004
                /* Read register. */
 
1005
                ReadParams.ulReadAddress = 0x702;
 
1006
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1007
                if ( ulResult != cOCT6100_ERR_OK )
 
1008
                        return ulResult;
 
1009
 
 
1010
                /* Check which interrupts were set. */
 
1011
                if ( (usReadData & 0x0002) != 0 )
 
1012
                {
 
1013
                        f_pIntFlags->fErrorOverflowToneEvents = TRUE;
 
1014
                        pErrorStats->ulOverflowToneEventsCnt++;
 
1015
                }
 
1016
        
 
1017
                pIntrptManage->usRegister702h = usReadData;
 
1018
                /*=======================================================================*/
 
1019
        }
 
1020
        else
 
1021
        {
 
1022
                pIntrptManage->usRegister702h = 0x0;
 
1023
        }
 
1024
        
 
1025
 
 
1026
 
 
1027
        /* If this is the first time the ISR is called, clear the ISR is not called bit */
 
1028
        /* in external memory to signal the remote client that we are called. */
 
1029
        if ( pSharedInfo->IntrptManage.fIsrCalled == FALSE )
 
1030
        {
 
1031
                /* Remember that we are being called. */
 
1032
                pSharedInfo->IntrptManage.fIsrCalled = TRUE;
 
1033
 
 
1034
                if ( pSharedInfo->DebugInfo.fIsIsrCalledField == TRUE )
 
1035
                {
 
1036
                        ulFeatureBytesOffset = pSharedInfo->MemoryMap.IsIsrCalledFieldOfst.usDwordOffset * 4;
 
1037
                        ulFeatureBitOffset       = pSharedInfo->MemoryMap.IsIsrCalledFieldOfst.byBitOffset;
 
1038
                        ulFeatureFieldLength = pSharedInfo->MemoryMap.IsIsrCalledFieldOfst.byFieldSize;
 
1039
 
 
1040
                        ulResult = Oct6100ApiReadDword( f_pApiInstance,
 
1041
                                                                                        cOCT6100_POUCH_BASE + ulFeatureBytesOffset,
 
1042
                                                                                        &ulTempData );
 
1043
                        
 
1044
                        /* Read previous value set in the feature field. */
 
1045
                        mOCT6100_CREATE_FEATURE_MASK( ulFeatureFieldLength, ulFeatureBitOffset, &ulMask );
 
1046
 
 
1047
                        /* Clear the field. */
 
1048
                        ulTempData &= (~ulMask);
 
1049
 
 
1050
                        /* Write the DWORD where the field is located.*/
 
1051
                        ulResult = Oct6100ApiWriteDword( f_pApiInstance,
 
1052
                                                                                         cOCT6100_POUCH_BASE + ulFeatureBytesOffset,
 
1053
                                                                                         ulTempData );
 
1054
                        if ( ulResult != cOCT6100_ERR_OK )
 
1055
                                return ulResult;        
 
1056
                }
 
1057
        }
 
1058
 
 
1059
        return cOCT6100_ERR_OK;
 
1060
}
 
1061
#endif
 
1062
 
 
1063
 
 
1064
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1065
 
 
1066
Function:               Oct6100ApiUpdateIntrptStates
 
1067
 
 
1068
Description:    Updates the state of all interrupt register groups.
 
1069
 
 
1070
-------------------------------------------------------------------------------
 
1071
|       Argument                |       Description
 
1072
-------------------------------------------------------------------------------
 
1073
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
1074
                                                the present state of the chip and all its resources.
 
1075
 
 
1076
f_pIntFlags                             Interrupt flags.
 
1077
 
 
1078
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1079
#if !SKIP_Oct6100ApiUpdateIntrptStates
 
1080
UINT32 Oct6100ApiUpdateIntrptStates(
 
1081
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance,
 
1082
                                IN              tPOCT6100_INTERRUPT_FLAGS               f_pIntFlags )
 
1083
{
 
1084
        tPOCT6100_API_INTRPT_CONFIG     pIntrptConfig;
 
1085
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
1086
 
 
1087
        pIntrptConfig = &f_pApiInstance->pSharedInfo->IntrptConfig;
 
1088
        pIntrptManage = &f_pApiInstance->pSharedInfo->IntrptManage;
 
1089
 
 
1090
        /*-----------------------------------------------------------------------*/
 
1091
        if ( ( f_pIntFlags->fFatalReadTimeout == TRUE) &&
 
1092
                 pIntrptConfig->byFatalMemoryConfig == cOCT6100_INTERRUPT_TIMEOUT &&
 
1093
                 pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1094
        {
 
1095
                pIntrptManage->byFatalMemoryState = cOCT6100_INTRPT_WILL_TIMEOUT;
 
1096
                pIntrptManage->ulFatalMemoryDisableMclkHigh = pIntrptManage->ulRegMclkTimeHigh;
 
1097
                pIntrptManage->ulFatalMemoryDisableMclkLow = pIntrptManage->ulRegMclkTimeLow;
 
1098
        }
 
1099
        /*-----------------------------------------------------------------------*/
 
1100
        if ( (f_pIntFlags->fErrorRefreshTooLate == TRUE || 
 
1101
                  f_pIntFlags->fErrorPllJitter == TRUE ) &&
 
1102
                 pIntrptConfig->byErrorMemoryConfig == cOCT6100_INTERRUPT_TIMEOUT &&
 
1103
                 pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1104
        {
 
1105
                pIntrptManage->byErrorMemoryState = cOCT6100_INTRPT_WILL_TIMEOUT;
 
1106
                pIntrptManage->ulErrorMemoryDisableMclkHigh = pIntrptManage->ulRegMclkTimeHigh;
 
1107
                pIntrptManage->ulErrorMemoryDisableMclkLow = pIntrptManage->ulRegMclkTimeLow;
 
1108
        }
 
1109
        /*-----------------------------------------------------------------------*/
 
1110
        if ( (f_pIntFlags->fErrorOverflowToneEvents == TRUE) &&
 
1111
                 pIntrptConfig->byErrorOverflowToneEventsConfig == cOCT6100_INTERRUPT_TIMEOUT &&
 
1112
                 pIntrptManage->byErrorOverflowToneEventsState == cOCT6100_INTRPT_ACTIVE )
 
1113
        {
 
1114
                pIntrptManage->byErrorOverflowToneEventsState = cOCT6100_INTRPT_WILL_TIMEOUT;
 
1115
                pIntrptManage->ulErrorOverflowToneEventsDisableMclkHigh = pIntrptManage->ulRegMclkTimeHigh;
 
1116
                pIntrptManage->ulErrorOverflowToneEventsDisableMclkLow = pIntrptManage->ulRegMclkTimeLow;
 
1117
        }
 
1118
        /*-----------------------------------------------------------------------*/
 
1119
        if ( (f_pIntFlags->fErrorH100OutOfSync == TRUE ||
 
1120
                  f_pIntFlags->fErrorH100ClkA == TRUE ||
 
1121
                  f_pIntFlags->fErrorH100ClkB == TRUE ||
 
1122
                  f_pIntFlags->fErrorH100FrameA == TRUE ) &&
 
1123
                 pIntrptConfig->byErrorH100Config == cOCT6100_INTERRUPT_TIMEOUT &&
 
1124
                 pIntrptManage->byErrorH100State == cOCT6100_INTRPT_ACTIVE )
 
1125
        {
 
1126
                pIntrptManage->byErrorH100State = cOCT6100_INTRPT_WILL_TIMEOUT;
 
1127
                pIntrptManage->ulErrorH100DisableMclkHigh = pIntrptManage->ulRegMclkTimeHigh;
 
1128
                pIntrptManage->ulErrorH100DisableMclkLow = pIntrptManage->ulRegMclkTimeLow;
 
1129
        }
 
1130
        /*-----------------------------------------------------------------------*/
 
1131
 
 
1132
        return cOCT6100_ERR_OK;
 
1133
}
 
1134
#endif
 
1135
 
 
1136
 
 
1137
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1138
 
 
1139
Function:               Oct6100ApiWriteIntrptRegs
 
1140
 
 
1141
Description:    Writes to interrupt registers to clear interrupt condition, and
 
1142
                                writes to an interrupt's IE register if interrupt is to time
 
1143
                                out.
 
1144
 
 
1145
-------------------------------------------------------------------------------
 
1146
|       Argument                |       Description
 
1147
-------------------------------------------------------------------------------
 
1148
f_pApiInstance          Pointer to API instance. This memory is used to keep
 
1149
                                        the present state of the chip and all its resources.
 
1150
 
 
1151
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1152
#if !SKIP_Oct6100ApiWriteIntrptRegs
 
1153
UINT32 Oct6100ApiWriteIntrptRegs(
 
1154
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance )
 
1155
{
 
1156
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
1157
        tOCT6100_WRITE_PARAMS           WriteParams;
 
1158
 
 
1159
        UINT32  ulResult;
 
1160
 
 
1161
        /* Get some local pointers. */
 
1162
        pIntrptManage = &f_pApiInstance->pSharedInfo->IntrptManage;
 
1163
 
 
1164
        /* Set some parameters of write struct. */
 
1165
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1166
 
 
1167
        WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
 
1168
 
 
1169
 
 
1170
 
 
1171
        /*===========================================================================*/
 
1172
        if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_WILL_TIMEOUT )
 
1173
        {
 
1174
                WriteParams.ulWriteAddress = 0x104;
 
1175
                WriteParams.usWriteData = 0x0000;
 
1176
 
 
1177
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1178
                if ( ulResult != cOCT6100_ERR_OK )
 
1179
                        return ulResult;
 
1180
        }
 
1181
        if ( (pIntrptManage->usRegister102h & cOCT6100_INTRPT_MASK_REG_102H) != 0 )
 
1182
        {
 
1183
                WriteParams.ulWriteAddress = 0x102;
 
1184
                WriteParams.usWriteData = pIntrptManage->usRegister102h;
 
1185
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1186
                if ( ulResult != cOCT6100_ERR_OK )
 
1187
                        return ulResult;
 
1188
        }
 
1189
        /*===========================================================================*/
 
1190
 
 
1191
        /*===========================================================================*/
 
1192
        if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_WILL_TIMEOUT ||
 
1193
                 pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_WILL_TIMEOUT )
 
1194
        {
 
1195
                WriteParams.ulWriteAddress = 0x204;
 
1196
                WriteParams.usWriteData = 0x0000;
 
1197
 
 
1198
                if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1199
                        WriteParams.usWriteData |= 0x1800;
 
1200
 
 
1201
                if ( pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1202
                        WriteParams.usWriteData |= 0x0401;
 
1203
 
 
1204
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1205
                if ( ulResult != cOCT6100_ERR_OK )
 
1206
                        return ulResult;
 
1207
        }
 
1208
        if ( (pIntrptManage->usRegister202h & cOCT6100_INTRPT_MASK_REG_202H) != 0 )
 
1209
        {
 
1210
                WriteParams.ulWriteAddress = 0x202;
 
1211
                WriteParams.usWriteData = pIntrptManage->usRegister202h;
 
1212
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1213
                if ( ulResult != cOCT6100_ERR_OK )
 
1214
                        return ulResult;
 
1215
        }
 
1216
        /*===========================================================================*/
 
1217
 
 
1218
        /*===========================================================================*/
 
1219
        if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_WILL_TIMEOUT )
 
1220
        {
 
1221
                WriteParams.ulWriteAddress = 0x304;
 
1222
                WriteParams.usWriteData = 0x0000;
 
1223
 
 
1224
                if ( pIntrptManage->fMclkIntrptActive == TRUE )
 
1225
                        WriteParams.usWriteData |= 0x0001;
 
1226
 
 
1227
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1228
                if ( ulResult != cOCT6100_ERR_OK )
 
1229
                        return ulResult;
 
1230
        }
 
1231
        if ( (pIntrptManage->usRegister302h & cOCT6100_INTRPT_MASK_REG_302H) != 0 )
 
1232
        {
 
1233
                WriteParams.ulWriteAddress = 0x302;
 
1234
                WriteParams.usWriteData = pIntrptManage->usRegister302h;
 
1235
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1236
                if ( ulResult != cOCT6100_ERR_OK )
 
1237
                        return ulResult;
 
1238
        }
 
1239
        /*===========================================================================*/
 
1240
 
 
1241
        /*===========================================================================*/
 
1242
        if ( (pIntrptManage->usRegister502h & cOCT6100_INTRPT_MASK_REG_502H) != 0 )
 
1243
        {
 
1244
                WriteParams.ulWriteAddress = 0x502;
 
1245
                WriteParams.usWriteData = pIntrptManage->usRegister502h;
 
1246
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1247
                if ( ulResult != cOCT6100_ERR_OK )
 
1248
                        return ulResult;
 
1249
        }
 
1250
        /*===========================================================================*/
 
1251
 
 
1252
        /*===========================================================================*/
 
1253
        if ( pIntrptManage->byErrorOverflowToneEventsState == cOCT6100_INTRPT_WILL_TIMEOUT )
 
1254
        {
 
1255
                WriteParams.ulWriteAddress = 0x704;
 
1256
                WriteParams.usWriteData = 0x0000;
 
1257
 
 
1258
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1259
                if ( ulResult != cOCT6100_ERR_OK )
 
1260
                        return ulResult;
 
1261
        }
 
1262
        if ( (pIntrptManage->usRegister702h & cOCT6100_INTRPT_MASK_REG_702H) != 0 )
 
1263
        {
 
1264
                WriteParams.ulWriteAddress = 0x702;
 
1265
                WriteParams.usWriteData = pIntrptManage->usRegister702h;
 
1266
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1267
                if ( ulResult != cOCT6100_ERR_OK )
 
1268
                        return ulResult;
 
1269
        }
 
1270
        /*===========================================================================*/
 
1271
 
 
1272
 
 
1273
 
 
1274
        return cOCT6100_ERR_OK;
 
1275
}
 
1276
#endif
 
1277
 
 
1278
 
 
1279
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1280
 
 
1281
Function:               Oct6100ApiWriteIeRegs
 
1282
 
 
1283
Description:    Writes the IE field of each interrupt register.
 
1284
 
 
1285
-------------------------------------------------------------------------------
 
1286
|       Argument                |       Description
 
1287
-------------------------------------------------------------------------------
 
1288
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
1289
                                                the present state of the chip and all its resources.
 
1290
 
 
1291
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1292
#if !SKIP_Oct6100ApiWriteIeRegs
 
1293
UINT32 Oct6100ApiWriteIeRegs(
 
1294
                                tPOCT6100_INSTANCE_API                  f_pApiInstance )
 
1295
{
 
1296
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
1297
        tOCT6100_WRITE_PARAMS           WriteParams;
 
1298
        tOCT6100_READ_PARAMS            ReadParams;
 
1299
        UINT32  ulResult;
 
1300
 
 
1301
        /* Get some local pointers. */
 
1302
        pIntrptManage = &f_pApiInstance->pSharedInfo->IntrptManage;
 
1303
 
 
1304
        /* Set some parameters of write struct. */
 
1305
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1306
 
 
1307
        WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
 
1308
 
 
1309
 
 
1310
        /* Set some parameters of read struct. */
 
1311
        ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1312
 
 
1313
        ReadParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
 
1314
        
 
1315
        /*==================================================================================*/
 
1316
        WriteParams.ulWriteAddress = 0x104;
 
1317
        WriteParams.usWriteData = 0x0000;
 
1318
 
 
1319
        if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1320
                WriteParams.usWriteData |= 0x0001;
 
1321
 
 
1322
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1323
        if ( ulResult != cOCT6100_ERR_OK )
 
1324
                return ulResult;
 
1325
        /*==================================================================================*/
 
1326
 
 
1327
        /*==================================================================================*/
 
1328
        WriteParams.ulWriteAddress = 0x204;
 
1329
        WriteParams.usWriteData = 0x0000;
 
1330
 
 
1331
        if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1332
                WriteParams.usWriteData |= 0x1800;
 
1333
        if ( pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1334
                WriteParams.usWriteData |= 0x0401;
 
1335
 
 
1336
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1337
        if ( ulResult != cOCT6100_ERR_OK )
 
1338
                return ulResult;
 
1339
        /*==================================================================================*/
 
1340
 
 
1341
        /*==================================================================================*/
 
1342
        WriteParams.ulWriteAddress = 0x304;
 
1343
        WriteParams.usWriteData = 0x0000;
 
1344
 
 
1345
        if ( pIntrptManage->fMclkIntrptActive == TRUE )
 
1346
                WriteParams.usWriteData |= 0x0001;
 
1347
        if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_ACTIVE )
 
1348
        {
 
1349
                if ( f_pApiInstance->pSharedInfo->ChipConfig.fEnableFastH100Mode == TRUE )
 
1350
                        WriteParams.usWriteData |= 0xD100;
 
1351
                else
 
1352
                        WriteParams.usWriteData |= 0x5100;
 
1353
        }
 
1354
 
 
1355
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1356
        if ( ulResult != cOCT6100_ERR_OK )
 
1357
                return ulResult;
 
1358
        /*==================================================================================*/
 
1359
 
 
1360
        /*==================================================================================*/
 
1361
        WriteParams.ulWriteAddress = 0x504;
 
1362
        WriteParams.usWriteData = 0x0000;
 
1363
 
 
1364
        if ( pIntrptManage->byFatalGeneralState == cOCT6100_INTRPT_ACTIVE )
 
1365
                WriteParams.usWriteData |= 0x0002;
 
1366
 
 
1367
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1368
        if ( ulResult != cOCT6100_ERR_OK )
 
1369
                return ulResult;
 
1370
        /*==================================================================================*/
 
1371
 
 
1372
        /*==================================================================================*/
 
1373
        WriteParams.ulWriteAddress = 0x704;
 
1374
        WriteParams.usWriteData = 0x0000;
 
1375
 
 
1376
        if ( pIntrptManage->byErrorOverflowToneEventsState == cOCT6100_INTRPT_ACTIVE )
 
1377
                WriteParams.usWriteData |= 0x0002;
 
1378
 
 
1379
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1380
        if ( ulResult != cOCT6100_ERR_OK )
 
1381
                return ulResult;
 
1382
        /*==================================================================================*/
 
1383
 
 
1384
 
 
1385
        /*==================================================================================*/
 
1386
        /* Enable the GLOBAL IEs for the interrupt pin. */
 
1387
        WriteParams.ulWriteAddress = 0x218;
 
1388
        WriteParams.usWriteData = 0x00D7;
 
1389
 
 
1390
        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1391
        if ( ulResult != cOCT6100_ERR_OK )
 
1392
                return ulResult;
 
1393
        /*==================================================================================*/
 
1394
        
 
1395
        return cOCT6100_ERR_OK;
 
1396
}
 
1397
#endif
 
1398
 
 
1399
 
 
1400
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1401
 
 
1402
Function:               Oct6100ApiReadChipMclkTime
 
1403
 
 
1404
Description:    Reads the chip's mclk cycle count to construct a chip time.
 
1405
                                The time is used to manage interrupts.
 
1406
 
 
1407
-------------------------------------------------------------------------------
 
1408
|       Argument                |       Description
 
1409
-------------------------------------------------------------------------------
 
1410
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
1411
                                                the present state of the chip and all its resources.
 
1412
 
 
1413
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1414
#if !SKIP_Oct6100ApiReadChipMclkTime
 
1415
UINT32 Oct6100ApiReadChipMclkTime(
 
1416
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance )
 
1417
{
 
1418
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
1419
        tPOCT6100_SHARED_INFO           pSharedInfo;
 
1420
        tOCT6100_READ_PARAMS            ReadParams;
 
1421
        UINT32  ulCheckData;
 
1422
        UINT32  ulResult;
 
1423
        UINT32  i;
 
1424
        UINT16  usReadData;
 
1425
 
 
1426
        /* Get local pointer(s). */
 
1427
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
1428
        pIntrptManage = &pSharedInfo->IntrptManage;
 
1429
 
 
1430
        /* Assign memory for read data. */
 
1431
        ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1432
 
 
1433
        ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
1434
        ReadParams.pusReadData = &usReadData;
 
1435
 
 
1436
        /* Perform reads. */
 
1437
        for ( i = 0; i < 100; i++ )
 
1438
        {
 
1439
                ReadParams.ulReadAddress = 0x306;
 
1440
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1441
                if ( ulResult != cOCT6100_ERR_OK )
 
1442
                        return ulResult;
 
1443
                pIntrptManage->ulRegMclkTimeHigh = usReadData & 0xFF;
 
1444
                ulCheckData = usReadData;
 
1445
 
 
1446
                ReadParams.ulReadAddress = 0x308;
 
1447
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1448
                if ( ulResult != cOCT6100_ERR_OK )
 
1449
                        return ulResult;
 
1450
                pIntrptManage->ulRegMclkTimeLow = (usReadData & 0xFFFF) << 16;
 
1451
 
 
1452
                ReadParams.ulReadAddress = 0x306;
 
1453
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1454
                if ( ulResult != cOCT6100_ERR_OK )
 
1455
                        return ulResult;
 
1456
                if ( ulCheckData == usReadData )
 
1457
                        break;
 
1458
        }
 
1459
 
 
1460
        if ( i == 100 )
 
1461
                return cOCT6100_ERR_FATAL_2F;
 
1462
 
 
1463
        return cOCT6100_ERR_OK;
 
1464
}
 
1465
#endif
 
1466
 
 
1467
 
 
1468
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1469
 
 
1470
Function:               Oct6100ApiUpdateIntrptTimeouts
 
1471
 
 
1472
Description:    Checks which interrupt groups have finished their timeout
 
1473
                                period.
 
1474
 
 
1475
-------------------------------------------------------------------------------
 
1476
|       Argument                |       Description
 
1477
-------------------------------------------------------------------------------
 
1478
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
1479
                                                the present state of the chip and all its resources.
 
1480
 
 
1481
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1482
#if !SKIP_Oct6100ApiUpdateIntrptTimeouts
 
1483
UINT32 Oct6100ApiUpdateIntrptTimeouts(
 
1484
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance )
 
1485
{
 
1486
        tPOCT6100_API_INTRPT_MANAGE pIntrptManage;
 
1487
        tOCT6100_WRITE_PARAMS           WriteParams;
 
1488
        UINT32  ulRegMclkTimePlus5MsHigh;
 
1489
        UINT32  ulRegMclkTimePlus5MsLow;
 
1490
        UINT32  ulResult;
 
1491
        BOOL    fFatalMemoryChange = FALSE;
 
1492
        BOOL    fDataErrMemoryChange = FALSE;
 
1493
        BOOL    fErrorOverflowToneEventsChange = FALSE;
 
1494
        BOOL    fH100ErrorChange = FALSE;
 
1495
 
 
1496
        /* Get local pointer to interrupt management structure. */
 
1497
        pIntrptManage = &f_pApiInstance->pSharedInfo->IntrptManage;
 
1498
 
 
1499
        /* Calculate mclk time + 5 ms. */
 
1500
        ulRegMclkTimePlus5MsLow = pIntrptManage->ulRegMclkTimeLow + (5 * pIntrptManage->ulNumMclkCyclesIn1Ms);
 
1501
        if ( ulRegMclkTimePlus5MsLow < pIntrptManage->ulRegMclkTimeLow )
 
1502
                ulRegMclkTimePlus5MsHigh = pIntrptManage->ulRegMclkTimeHigh + 1;
 
1503
        else /* ( ulRegMclkTimePlus5MsLow >= pIntrptManage->ulRegMclkTimeLow ) */
 
1504
                ulRegMclkTimePlus5MsHigh = pIntrptManage->ulRegMclkTimeHigh;
 
1505
 
 
1506
        /* Check which interrupts are timed out and need to be reenabled now. */
 
1507
        if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_IN_TIMEOUT )
 
1508
        {
 
1509
                mOCT6100_CHECK_INTRPT_TIMEOUT( ulRegMclkTimePlus5MsHigh, ulRegMclkTimePlus5MsLow, pIntrptManage->ulFatalMemoryDisableMclkHigh, pIntrptManage->ulFatalMemoryDisableMclkLow, pIntrptManage->ulFatalMemoryEnableMclkHigh, pIntrptManage->ulFatalMemoryEnableMclkLow, pIntrptManage->byFatalMemoryState, fFatalMemoryChange )
 
1510
        }
 
1511
        if ( pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_IN_TIMEOUT )
 
1512
        {
 
1513
                mOCT6100_CHECK_INTRPT_TIMEOUT( ulRegMclkTimePlus5MsHigh, ulRegMclkTimePlus5MsLow, pIntrptManage->ulErrorMemoryDisableMclkHigh, pIntrptManage->ulErrorMemoryDisableMclkLow, pIntrptManage->ulErrorMemoryEnableMclkHigh, pIntrptManage->ulErrorMemoryEnableMclkLow, pIntrptManage->byErrorMemoryState, fDataErrMemoryChange )
 
1514
        }
 
1515
        if ( pIntrptManage->byErrorOverflowToneEventsState == cOCT6100_INTRPT_IN_TIMEOUT )
 
1516
        {
 
1517
                mOCT6100_CHECK_INTRPT_TIMEOUT( ulRegMclkTimePlus5MsHigh, ulRegMclkTimePlus5MsLow, pIntrptManage->ulErrorOverflowToneEventsDisableMclkHigh, pIntrptManage->ulErrorOverflowToneEventsDisableMclkLow, pIntrptManage->ulErrorOverflowToneEventsEnableMclkHigh, pIntrptManage->ulErrorOverflowToneEventsEnableMclkLow, pIntrptManage->byErrorOverflowToneEventsState, fErrorOverflowToneEventsChange )
 
1518
        }
 
1519
        if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_IN_TIMEOUT )
 
1520
        {
 
1521
                mOCT6100_CHECK_INTRPT_TIMEOUT( ulRegMclkTimePlus5MsHigh, ulRegMclkTimePlus5MsLow, pIntrptManage->ulErrorH100DisableMclkHigh, pIntrptManage->ulErrorH100DisableMclkLow, pIntrptManage->ulErrorH100EnableMclkHigh, pIntrptManage->ulErrorH100EnableMclkLow, pIntrptManage->byErrorH100State, fH100ErrorChange )
 
1522
        }
 
1523
 
 
1524
        /* Set some parameters of write struct. */
 
1525
        WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1526
 
 
1527
        WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
 
1528
        
 
1529
        /* Write to the IE registers which have changed. */
 
1530
 
 
1531
        /*==================================================================================*/
 
1532
        if ( fFatalMemoryChange == TRUE )
 
1533
        {
 
1534
                WriteParams.ulWriteAddress = 0x104;
 
1535
                WriteParams.usWriteData = 0x0000;
 
1536
 
 
1537
                if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1538
                        WriteParams.usWriteData |= 0x0001;
 
1539
 
 
1540
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1541
                if ( ulResult != cOCT6100_ERR_OK )
 
1542
                        return ulResult;
 
1543
 
 
1544
        }
 
1545
        /*==================================================================================*/
 
1546
 
 
1547
        /*==================================================================================*/
 
1548
        if ( fFatalMemoryChange == TRUE || 
 
1549
                 fDataErrMemoryChange == TRUE )
 
1550
        {
 
1551
                WriteParams.ulWriteAddress = 0x204;
 
1552
                WriteParams.usWriteData = 0x0000;
 
1553
 
 
1554
                if ( pIntrptManage->byFatalMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1555
                        WriteParams.usWriteData |= 0x1800;
 
1556
                if ( pIntrptManage->byErrorMemoryState == cOCT6100_INTRPT_ACTIVE )
 
1557
                        WriteParams.usWriteData |= 0x0401;
 
1558
 
 
1559
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1560
                if ( ulResult != cOCT6100_ERR_OK )
 
1561
                        return ulResult;
 
1562
 
 
1563
        }
 
1564
        /*==================================================================================*/
 
1565
 
 
1566
        /*==================================================================================*/
 
1567
        if ( pIntrptManage->fMclkIntrptActive == TRUE ||
 
1568
                 fH100ErrorChange == TRUE )
 
1569
        {
 
1570
                WriteParams.ulWriteAddress = 0x304;
 
1571
                WriteParams.usWriteData = 0x0000;
 
1572
 
 
1573
                if ( pIntrptManage->fMclkIntrptActive == TRUE )
 
1574
                        WriteParams.usWriteData |= 0x0001;
 
1575
                
 
1576
                if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_ACTIVE )
 
1577
                {
 
1578
                        if ( f_pApiInstance->pSharedInfo->ChipConfig.fEnableFastH100Mode == TRUE )
 
1579
                                WriteParams.usWriteData |= 0xD100;
 
1580
                        else
 
1581
                                WriteParams.usWriteData |= 0x5100;
 
1582
                }
 
1583
 
 
1584
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1585
                if ( ulResult != cOCT6100_ERR_OK )
 
1586
                        return ulResult;
 
1587
        
 
1588
        }
 
1589
        /*==================================================================================*/
 
1590
 
 
1591
 
 
1592
        /*==================================================================================*/
 
1593
        if ( fErrorOverflowToneEventsChange == TRUE )
 
1594
        {
 
1595
                WriteParams.ulWriteAddress = 0x704;
 
1596
                WriteParams.usWriteData = 0x0000;
 
1597
 
 
1598
                if ( pIntrptManage->byErrorOverflowToneEventsState == cOCT6100_INTRPT_ACTIVE )
 
1599
                        WriteParams.usWriteData |= 0x0002;
 
1600
 
 
1601
                mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1602
                if ( ulResult != cOCT6100_ERR_OK )
 
1603
                        return ulResult;
 
1604
        
 
1605
        }
 
1606
        /*==================================================================================*/
 
1607
 
 
1608
        return cOCT6100_ERR_OK;
 
1609
}
 
1610
#endif
 
1611
 
 
1612
 
 
1613
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1614
 
 
1615
Function:               Oct6100ApiScheduleNextMclkIntrptSer
 
1616
 
 
1617
Description:    Serialized sub-function of Oct6100ApiScheduleNextMclkIntrpt.
 
1618
 
 
1619
-------------------------------------------------------------------------------
 
1620
|       Argument                |       Description
 
1621
-------------------------------------------------------------------------------
 
1622
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
1623
                                                the present state of the chip and all its resources.
 
1624
 
 
1625
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1626
#if !SKIP_Oct6100ApiScheduleNextMclkIntrptSer
 
1627
UINT32 Oct6100ApiScheduleNextMclkIntrptSer(
 
1628
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance )
 
1629
{
 
1630
        tPOCT6100_SHARED_INFO                   pSharedInfo;
 
1631
        tPOCT6100_API_INTRPT_CONFIG     pIntrptConfig;
 
1632
        tPOCT6100_API_INTRPT_MANAGE     pIntrptManage;
 
1633
        tOCT6100_WRITE_PARAMS           WriteParams;
 
1634
        UINT32  ulTimeDiff;
 
1635
        UINT32  ulRegMclkTimeHigh;
 
1636
        UINT32  ulRegMclkTimeLow;
 
1637
        UINT32  ulResult;
 
1638
        BOOL    fConditionFlag = TRUE;
 
1639
        
 
1640
        /* Get local pointer(s). */
 
1641
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
1642
        
 
1643
        /* Obtain temporary pointers to reduce indirection, thus speeding up processing. */
 
1644
        pIntrptConfig = &pSharedInfo->IntrptConfig;
 
1645
        pIntrptManage = &pSharedInfo->IntrptManage;
 
1646
        ulRegMclkTimeHigh = pIntrptManage->ulRegMclkTimeHigh;
 
1647
        ulRegMclkTimeLow = pIntrptManage->ulRegMclkTimeLow;
 
1648
 
 
1649
        /* First, check if any interrupts have just been disabled.  If there are any, */
 
1650
        /* determine the time at which they should be reenabled. */
 
1651
        pIntrptManage->ulNextMclkIntrptTimeHigh = cOCT6100_INVALID_VALUE;
 
1652
        pIntrptManage->ulNextMclkIntrptTimeLow = cOCT6100_INVALID_VALUE;
 
1653
 
 
1654
        while ( fConditionFlag )
 
1655
        {
 
1656
                /* Indicate that no mclk interrupt is needed, yet. */
 
1657
                ulTimeDiff = cOCT6100_INVALID_VALUE;
 
1658
 
 
1659
                /* Check each interrupt category to see if an mclk interrupt is needed to */
 
1660
                /* reenable an interrupt at a later time. */
 
1661
                if ( pIntrptManage->byFatalMemoryState != cOCT6100_INTRPT_ACTIVE &&
 
1662
                         pIntrptManage->byFatalMemoryState != cOCT6100_INTRPT_DISABLED )
 
1663
                {
 
1664
                        mOCT6100_GET_INTRPT_ENABLE_TIME( ulRegMclkTimeHigh, ulRegMclkTimeLow, pIntrptManage->byFatalMemoryState, pIntrptManage->ulFatalMemoryEnableMclkHigh, pIntrptManage->ulFatalMemoryEnableMclkLow, pIntrptConfig->ulFatalMemoryTimeoutMclk, ulTimeDiff )
 
1665
                }
 
1666
                if ( pIntrptManage->byErrorMemoryState != cOCT6100_INTRPT_ACTIVE &&
 
1667
                         pIntrptManage->byErrorMemoryState != cOCT6100_INTRPT_DISABLED )
 
1668
                {
 
1669
                        mOCT6100_GET_INTRPT_ENABLE_TIME( ulRegMclkTimeHigh, ulRegMclkTimeLow, pIntrptManage->byErrorMemoryState, pIntrptManage->ulErrorMemoryEnableMclkHigh, pIntrptManage->ulErrorMemoryEnableMclkLow, pIntrptConfig->ulErrorMemoryTimeoutMclk, ulTimeDiff )
 
1670
                }
 
1671
                if ( pIntrptManage->byErrorOverflowToneEventsState != cOCT6100_INTRPT_ACTIVE &&
 
1672
                         pIntrptManage->byErrorOverflowToneEventsState != cOCT6100_INTRPT_DISABLED )
 
1673
                {        
 
1674
                        mOCT6100_GET_INTRPT_ENABLE_TIME( ulRegMclkTimeHigh, ulRegMclkTimeLow, pIntrptManage->byErrorOverflowToneEventsState, pIntrptManage->ulErrorOverflowToneEventsEnableMclkHigh, pIntrptManage->ulErrorOverflowToneEventsEnableMclkLow, pIntrptConfig->ulErrorOverflowToneEventsTimeoutMclk, ulTimeDiff )
 
1675
                }
 
1676
                if ( pIntrptManage->byErrorH100State != cOCT6100_INTRPT_ACTIVE &&
 
1677
                         pIntrptManage->byErrorH100State != cOCT6100_INTRPT_DISABLED )
 
1678
                {
 
1679
                        mOCT6100_GET_INTRPT_ENABLE_TIME( ulRegMclkTimeHigh, ulRegMclkTimeLow, pIntrptManage->byErrorH100State, pIntrptManage->ulErrorH100EnableMclkHigh, pIntrptManage->ulErrorH100EnableMclkLow, pIntrptConfig->ulErrorH100TimeoutMclk, ulTimeDiff )
 
1680
                }
 
1681
 
 
1682
                /* Set some parameters of write struct. */
 
1683
                WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1684
 
 
1685
                WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
 
1686
 
 
1687
                /* Schedule next mclk interrupt, if any is needed. */
 
1688
                if ( ulTimeDiff != cOCT6100_INVALID_VALUE )
 
1689
                {
 
1690
                        UINT32  ulMclkTimeTest;
 
1691
                        UINT32  ulAlarmTimeTest;
 
1692
                        UINT32  ulTimeDiffTest;
 
1693
                        BOOL    fAlarmTimePassed;
 
1694
 
 
1695
                        /* Indicate that an mclk interrupt is scheduled.*/
 
1696
                        pIntrptManage->fMclkIntrptActive = TRUE;
 
1697
 
 
1698
                        pIntrptManage->ulNextMclkIntrptTimeLow = ulRegMclkTimeLow + ulTimeDiff;
 
1699
                        if ( pIntrptManage->ulNextMclkIntrptTimeLow < ulRegMclkTimeLow )
 
1700
                                pIntrptManage->ulNextMclkIntrptTimeHigh = ulRegMclkTimeHigh + 1;
 
1701
                        else /* ( pIntrptManage->ulNextMclkIntrptTimeLow >= ulRegMclkTimeLow ) */
 
1702
                                pIntrptManage->ulNextMclkIntrptTimeHigh = ulRegMclkTimeHigh;
 
1703
                        
 
1704
                        WriteParams.ulWriteAddress = 0x30C;
 
1705
                        WriteParams.usWriteData  = (UINT16)( (pIntrptManage->ulNextMclkIntrptTimeLow >> 24) & 0xFF );
 
1706
                        WriteParams.usWriteData |= (UINT16)( (pIntrptManage->ulNextMclkIntrptTimeHigh & 0xFF) << 8 );
 
1707
                        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1708
                        if ( ulResult != cOCT6100_ERR_OK )
 
1709
                                return ulResult;
 
1710
                        
 
1711
                        WriteParams.ulWriteAddress = 0x30E;
 
1712
                        WriteParams.usWriteData = (UINT16)( (pIntrptManage->ulNextMclkIntrptTimeLow >> 8) & 0xFFFF );
 
1713
                        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1714
                        if ( ulResult != cOCT6100_ERR_OK )
 
1715
                                return ulResult;
 
1716
                        
 
1717
                        WriteParams.ulWriteAddress = 0x304;
 
1718
                        WriteParams.usWriteData = 0;
 
1719
                        
 
1720
                        if ( pIntrptManage->fMclkIntrptActive == TRUE )
 
1721
                                WriteParams.usWriteData = 0x0001;
 
1722
 
 
1723
                        if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_ACTIVE )
 
1724
                        {
 
1725
                                if ( f_pApiInstance->pSharedInfo->ChipConfig.fEnableFastH100Mode == TRUE )
 
1726
                                        WriteParams.usWriteData |= 0xD100;
 
1727
                                else
 
1728
                                        WriteParams.usWriteData |= 0x5100;
 
1729
                        }
 
1730
                        
 
1731
                        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1732
                        if ( ulResult != cOCT6100_ERR_OK )
 
1733
                                return ulResult;
 
1734
 
 
1735
                        /* Disable the ROL if previously set. */
 
1736
                        WriteParams.ulWriteAddress = 0x302;
 
1737
                        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1738
                        if ( ulResult != cOCT6100_ERR_OK )
 
1739
                                return ulResult;
 
1740
 
 
1741
                        /* Check if already passed the next interrupt time. */
 
1742
                        ulResult = Oct6100ApiReadChipMclkTime( f_pApiInstance );
 
1743
                        if ( ulResult != cOCT6100_ERR_OK )
 
1744
                                return ulResult;
 
1745
 
 
1746
                        ulMclkTimeTest  = (pIntrptManage->ulRegMclkTimeLow >> 16) & 0xFFFF;
 
1747
                        ulAlarmTimeTest = (pIntrptManage->ulNextMclkIntrptTimeLow >> 16) & 0xFFFF;
 
1748
 
 
1749
                        /* Update the local Mlck timer values.*/
 
1750
                        ulRegMclkTimeHigh       = pIntrptManage->ulRegMclkTimeHigh;
 
1751
                        ulRegMclkTimeLow        = pIntrptManage->ulRegMclkTimeLow;
 
1752
 
 
1753
                        fAlarmTimePassed = FALSE;
 
1754
 
 
1755
                        if ( ulMclkTimeTest > ulAlarmTimeTest )
 
1756
                        {
 
1757
                                ulTimeDiffTest = ulMclkTimeTest - ulAlarmTimeTest;
 
1758
                                if ( ulTimeDiffTest <= 0x8000 )
 
1759
                                        fAlarmTimePassed = TRUE;
 
1760
                        }
 
1761
                        else /* ( ulMclkTimeTest <= ulAlarmTimeTest ) */
 
1762
                        {
 
1763
                                ulTimeDiffTest = ulAlarmTimeTest - ulMclkTimeTest;
 
1764
                                if ( ulTimeDiffTest > 0x8000 )
 
1765
                                        fAlarmTimePassed = TRUE;
 
1766
                        }
 
1767
                        
 
1768
                        if ( fAlarmTimePassed == TRUE )
 
1769
                        {
 
1770
                                /* Passed the interrupt time.  Schedule next interrupt (if needed). */
 
1771
                                ulResult = Oct6100ApiUpdateIntrptTimeouts( f_pApiInstance );
 
1772
                                if ( ulResult != cOCT6100_ERR_OK )
 
1773
                                        return ulResult;
 
1774
 
 
1775
                                continue;
 
1776
                        }
 
1777
                        else
 
1778
                        {
 
1779
                                fConditionFlag = FALSE;
 
1780
                        }
 
1781
                }
 
1782
                else
 
1783
                {
 
1784
                        /* Indicate that no mclk interrupt is scheduled. */
 
1785
                        pIntrptManage->fMclkIntrptActive = FALSE;
 
1786
 
 
1787
                        /* Insure that the mclk interrupt is not enabled. */
 
1788
                        WriteParams.ulWriteAddress = 0x304;
 
1789
                        WriteParams.usWriteData = 0x0000;
 
1790
                        if ( pIntrptManage->byErrorH100State == cOCT6100_INTRPT_ACTIVE )
 
1791
                        {
 
1792
                                if ( f_pApiInstance->pSharedInfo->ChipConfig.fEnableFastH100Mode == TRUE )
 
1793
                                        WriteParams.usWriteData |= 0xD100;
 
1794
                                else
 
1795
                                        WriteParams.usWriteData |= 0x5100;
 
1796
                        }
 
1797
                        mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )
 
1798
                        if ( ulResult != cOCT6100_ERR_OK )
 
1799
                                return ulResult;
 
1800
 
 
1801
                        fConditionFlag = FALSE;
 
1802
                }
 
1803
        }
 
1804
 
 
1805
        return cOCT6100_ERR_OK;
 
1806
}
 
1807
#endif
 
1808
 
 
1809
 
 
1810
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1811
 
 
1812
Function:               Oct6100ApiCheckProcessorState
 
1813
 
 
1814
Description:    This function verifies if the NLP and AF processors are operating
 
1815
                                correctly.
 
1816
 
 
1817
-------------------------------------------------------------------------------
 
1818
|       Argument                |       Description
 
1819
-------------------------------------------------------------------------------
 
1820
f_pApiInstance                  Pointer to API instance. This memory is used to keep
 
1821
                                                the present state of the chip and all its resources.
 
1822
 
 
1823
f_pIntFlags                             Pointer to a tOCT6100_INTERRUPT_FLAGS structure.
 
1824
 
 
1825
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1826
#if !SKIP_Oct6100ApiCheckProcessorState
 
1827
UINT32  Oct6100ApiCheckProcessorState(
 
1828
                                IN OUT  tPOCT6100_INSTANCE_API                  f_pApiInstance,
 
1829
                                IN OUT  tPOCT6100_INTERRUPT_FLAGS               f_pIntFlags )
 
1830
{
 
1831
        tPOCT6100_SHARED_INFO                   pSharedInfo;
 
1832
        tOCT6100_READ_PARAMS                    ReadParams;
 
1833
        tOCT6100_READ_BURST_PARAMS              ReadBurstParams;
 
1834
 
 
1835
        UINT32          ulNlpTimestamp;
 
1836
        UINT32          ulAfTimestamp;
 
1837
        UINT32          ulTimestampDiff;
 
1838
 
 
1839
        UINT32          ulResult;
 
1840
        UINT32          i;
 
1841
 
 
1842
        UINT16          usReadData;
 
1843
        UINT16          ausReadData[ 2 ];
 
1844
 
 
1845
        UINT32          aulWaitTime[ 2 ];
 
1846
        
 
1847
        /* Get local pointer(s). */
 
1848
        pSharedInfo = f_pApiInstance->pSharedInfo;
 
1849
 
 
1850
        /* Set some parameters of write struct. */
 
1851
        ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1852
 
 
1853
        ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
1854
        ReadParams.pusReadData = &usReadData;
 
1855
 
 
1856
        /* Set some parameters of write struct. */
 
1857
        ReadBurstParams.pProcessContext = f_pApiInstance->pProcessContext;
 
1858
 
 
1859
        ReadBurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
 
1860
        ReadBurstParams.pusReadData = ausReadData;
 
1861
 
 
1862
        /*-----------------------------------------------------------------------*/
 
1863
        /* Check if chip is in reset. */
 
1864
 
 
1865
        /* Read the main control register. */
 
1866
        ReadParams.ulReadAddress = 0x100;
 
1867
 
 
1868
        mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1869
        if ( ulResult != cOCT6100_ERR_OK )
 
1870
                return ulResult;
 
1871
 
 
1872
        if ( usReadData == 0x0000 )
 
1873
        {
 
1874
                /* Chip was resetted. */
 
1875
                f_pIntFlags->ulFatalGeneralFlags |= cOCT6100_FATAL_GENERAL_ERROR_TYPE_4;
 
1876
                f_pIntFlags->fFatalGeneral = TRUE;
 
1877
                pSharedInfo->ErrorStats.fFatalChipError = TRUE;
 
1878
        }
 
1879
 
 
1880
        /*-----------------------------------------------------------------------*/
 
1881
 
 
1882
 
 
1883
        /*-----------------------------------------------------------------------*/
 
1884
        /* Reading the AF timestamp.*/
 
1885
 
 
1886
        for ( i = 0; i < cOCT6100_MAX_LOOP; i++ )
 
1887
        {
 
1888
                /* Read the timestamp.*/
 
1889
                ReadBurstParams.ulReadAddress   = 0x082E0008;
 
1890
                ReadBurstParams.ulReadLength    = 2;
 
1891
 
 
1892
                mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult )
 
1893
                if ( ulResult != cOCT6100_ERR_OK )
 
1894
                        return ulResult;
 
1895
 
 
1896
                /* Read the high part again to make sure it didn't wrap. */
 
1897
                ReadParams.ulReadAddress                = 0x082E0008;
 
1898
 
 
1899
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1900
                if ( ulResult != cOCT6100_ERR_OK )
 
1901
                        return ulResult;
 
1902
 
 
1903
                /* Check if the low part wrapped. */
 
1904
                if ( ausReadData[ 0 ] == usReadData )
 
1905
                        break;
 
1906
        }
 
1907
 
 
1908
        if ( i == cOCT6100_MAX_LOOP )
 
1909
                return cOCT6100_ERR_INTRPTS_AF_TIMESTAMP_READ_TIMEOUT;
 
1910
 
 
1911
        /* Save the AF timestamp. */
 
1912
        ulAfTimestamp = (ausReadData[ 0 ] << 16) | ausReadData[ 1 ];
 
1913
 
 
1914
        /*-----------------------------------------------------------------------*/
 
1915
 
 
1916
        
 
1917
        /*-----------------------------------------------------------------------*/
 
1918
        /* Reading the NLP timestamp. */
 
1919
 
 
1920
        for ( i = 0; i < cOCT6100_MAX_LOOP; i++ )
 
1921
        {
 
1922
                /* Read the timestamp. */
 
1923
                ReadBurstParams.ulReadAddress   = 0x08000008;
 
1924
                ReadBurstParams.ulReadLength    = 2;
 
1925
 
 
1926
                mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult )
 
1927
                if ( ulResult != cOCT6100_ERR_OK )
 
1928
                        return ulResult;
 
1929
 
 
1930
                /* Read the high part again to make sure it didn't wrap. */
 
1931
                ReadParams.ulReadAddress                = 0x08000008;
 
1932
 
 
1933
                mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
 
1934
                if ( ulResult != cOCT6100_ERR_OK )
 
1935
                        return ulResult;
 
1936
 
 
1937
                /* Check if the low part wrapped. */
 
1938
                if ( ausReadData[ 0 ] == usReadData )
 
1939
                        break;
 
1940
        }
 
1941
 
 
1942
        if ( i == cOCT6100_MAX_LOOP )
 
1943
                return cOCT6100_ERR_INTRPTS_NLP_TIMESTAMP_READ_TIMEOUT;
 
1944
 
 
1945
        /* Save the NLP timestamp. */
 
1946
        ulNlpTimestamp = (ausReadData[ 0 ] << 16) | ausReadData[ 1 ];
 
1947
 
 
1948
        /*-----------------------------------------------------------------------*/
 
1949
 
 
1950
 
 
1951
        /*-----------------------------------------------------------------------*/
 
1952
        /* Check the validity of the timestamp. */
 
1953
        
 
1954
        if ( ulAfTimestamp > ulNlpTimestamp )
 
1955
        {
 
1956
                /* The NLP timestamp wrapped. */
 
1957
                ulTimestampDiff  = 0xFFFFFFFF - ulAfTimestamp + 1;
 
1958
                ulTimestampDiff += ulNlpTimestamp;
 
1959
        }
 
1960
        else
 
1961
                ulTimestampDiff = ulNlpTimestamp - ulAfTimestamp;
 
1962
 
 
1963
        if ( ulTimestampDiff > 0x2000 )
 
1964
        {
 
1965
                f_pIntFlags->ulFatalGeneralFlags |= cOCT6100_FATAL_GENERAL_ERROR_TYPE_5;
 
1966
                f_pIntFlags->fFatalGeneral = TRUE;
 
1967
                pSharedInfo->ErrorStats.fFatalChipError = TRUE;
 
1968
        }
 
1969
 
 
1970
        /*Check if AF and NLP are both stuck*/
 
1971
        if ( f_pIntFlags->fErrorH100ClkA == FALSE &&
 
1972
                 f_pIntFlags->fErrorH100ClkB == FALSE &&
 
1973
                 f_pIntFlags->fErrorH100FrameA == FALSE &&
 
1974
                 f_pIntFlags->fErrorH100OutOfSync == FALSE )
 
1975
                
 
1976
        {
 
1977
                if ( ulAfTimestamp == 0 && ulNlpTimestamp == 0 )
 
1978
                {
 
1979
                        /*Give some time to the counters*/
 
1980
                        aulWaitTime[ 0 ] = 250;
 
1981
                        aulWaitTime[ 1 ] = 0;
 
1982
                        ulResult = Oct6100ApiWaitForTime( f_pApiInstance, aulWaitTime );
 
1983
                        if ( ulResult != cOCT6100_ERR_OK )
 
1984
                                return ulResult;
 
1985
 
 
1986
                        /*Let's read again the AF timestamp to be sure. Maybe they were at 0 at the same time*/
 
1987
                        ReadBurstParams.ulReadAddress   = 0x082E0008;
 
1988
                        ReadBurstParams.ulReadLength    = 2;
 
1989
 
 
1990
                        mOCT6100_DRIVER_READ_BURST_API( ReadBurstParams, ulResult )
 
1991
                        if ( ulResult != cOCT6100_ERR_OK )
 
1992
                        return ulResult;
 
1993
 
 
1994
                        ulAfTimestamp = (ausReadData[ 0 ] << 16) | ausReadData[ 1 ];
 
1995
        
 
1996
                        if ( ulAfTimestamp == 0 )
 
1997
                        {
 
1998
                                /*TDM Clocks are ok but NLP and AF timestamps are both at 0*/
 
1999
                                f_pIntFlags->ulFatalGeneralFlags |= cOCT6100_FATAL_GENERAL_ERROR_TYPE_9;
 
2000
                                f_pIntFlags->fFatalGeneral = TRUE;
 
2001
                                pSharedInfo->ErrorStats.fFatalChipError = TRUE;
 
2002
                        }
 
2003
                }
 
2004
                        
 
2005
        }
 
2006
 
 
2007
        /*-----------------------------------------------------------------------*/
 
2008
 
 
2009
        return cOCT6100_ERR_OK;
 
2010
}
 
2011
#endif