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

« back to all changes in this revision

Viewing changes to oct612x/octdeviceapi/oct6100api/oct6100_api/oct6100_memory.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_memory.c
4
 
 
5
 
    Copyright (c) 2001-2006 Octasic Inc.
6
 
    
7
 
Description: 
8
 
 
9
 
        This file contains the functions used to manage the allocation of memory
10
 
        blocks in external memory.
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-PR43 $
27
 
 
28
 
$Octasic_Revision: 42 $
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
 
 
40
 
#include "apilib/octapi_llman.h"
41
 
 
42
 
#include "oct6100api/oct6100_apiud.h"
43
 
#include "oct6100api/oct6100_tlv_inst.h"
44
 
#include "oct6100api/oct6100_chip_open_inst.h"
45
 
#include "oct6100api/oct6100_chip_stats_inst.h"
46
 
#include "oct6100api/oct6100_interrupts_inst.h"
47
 
#include "oct6100api/oct6100_remote_debug_inst.h"
48
 
#include "oct6100api/oct6100_debug_inst.h"
49
 
#include "oct6100api/oct6100_playout_buf_inst.h"
50
 
#include "oct6100api/oct6100_api_inst.h"
51
 
 
52
 
#include "oct6100api/oct6100_interrupts_pub.h"
53
 
#include "oct6100api/oct6100_channel_pub.h"
54
 
#include "oct6100api/oct6100_chip_open_pub.h"
55
 
 
56
 
#include "oct6100_chip_open_priv.h"
57
 
#include "oct6100_memory_priv.h"
58
 
 
59
 
 
60
 
/****************************  PRIVATE FUNCTIONS  ****************************/
61
 
 
62
 
 
63
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
64
 
 
65
 
Function:               Oct6100ApiGetMemorySwSizes
66
 
 
67
 
Description:    Gets the sizes of all portions of the API instance pertinent
68
 
                                to the management of the memories.
69
 
 
70
 
-------------------------------------------------------------------------------
71
 
|       Argument                |       Description
72
 
-------------------------------------------------------------------------------
73
 
f_pOpenChip                             Pointer to chip configuration struct.
74
 
f_pInstSizes                    Pointer to struct containing instance sizes.
75
 
 
76
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
77
 
#if !SKIP_Oct6100ApiGetMemorySwSizes
78
 
UINT32 Oct6100ApiGetMemorySwSizes(
79
 
                                IN              tPOCT6100_CHIP_OPEN                             f_pOpenChip,
80
 
                                OUT             tPOCT6100_API_INSTANCE_SIZES    f_pInstSizes )
81
 
{
82
 
        UINT32  ulTempVar;
83
 
        UINT32  ulResult;
84
 
        UINT32  ulNumTsiChariots;
85
 
 
86
 
        /*=========================================================================*/
87
 
        /* Internal memory */
88
 
 
89
 
        /* Evaluate the number of available TSI memory after reserving the ones used by channels. */
90
 
        ulNumTsiChariots = cOCT6100_TOTAL_TSI_CONTROL_MEM_ENTRY - f_pOpenChip->ulMaxPhasingTssts - cOCT6100_TSI_MEM_FOR_TIMESTAMP;
91
 
 
92
 
        if ( f_pOpenChip->fEnableExtToneDetection == TRUE )
93
 
                ulNumTsiChariots--;
94
 
 
95
 
        /* Calculate memory needed for TSI memory allocation. */
96
 
        ulResult = OctapiLlmAllocGetSize( ulNumTsiChariots, &f_pInstSizes->ulTsiMemoryAlloc );
97
 
        if ( ulResult != cOCT6100_ERR_OK )
98
 
                return cOCT6100_ERR_FATAL_94;
99
 
        
100
 
        /* Calculate memory needed for conversion memory allocation. */
101
 
        ulResult = OctapiLlmAllocGetSize( cOCT6100_MAX_CONVERSION_MEMORY_BLOCKS, &f_pInstSizes->ulConversionMemoryAlloc );
102
 
        if ( ulResult != cOCT6100_ERR_OK )
103
 
                return cOCT6100_ERR_FATAL_B5;
104
 
 
105
 
        mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulTsiMemoryAlloc, ulTempVar );
106
 
        mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulConversionMemoryAlloc, ulTempVar );
107
 
 
108
 
        return cOCT6100_ERR_OK;
109
 
}
110
 
#endif
111
 
 
112
 
 
113
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
114
 
 
115
 
Function:               Oct6100ApiMemorySwInit
116
 
 
117
 
Description:    Initializes all elements of the instance structure associated
118
 
                                to memories.
119
 
 
120
 
-------------------------------------------------------------------------------
121
 
|       Argument                |       Description
122
 
-------------------------------------------------------------------------------
123
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
124
 
                                                the present state of the chip and all its resources.
125
 
 
126
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
127
 
#if !SKIP_Oct6100ApiMemorySwInit
128
 
UINT32 Oct6100ApiMemorySwInit(
129
 
                                IN OUT  tPOCT6100_INSTANCE_API          f_pApiInstance )
130
 
{
131
 
        tPOCT6100_SHARED_INFO   pSharedInfo;
132
 
        PVOID   pTsiMemAlloc;
133
 
        PVOID   pAllocPnt;
134
 
        UINT32  ulResult;
135
 
 
136
 
        /* Get local pointer(s). */
137
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
138
 
 
139
 
        /*=========================================================================*/
140
 
        /* Internal memory */
141
 
        
142
 
        /* Initialize the TSI memory allocation structure. */
143
 
        pSharedInfo->MemoryMap.ulNumTsiEntries = cOCT6100_TOTAL_TSI_CONTROL_MEM_ENTRY - pSharedInfo->ChipConfig.usMaxPhasingTssts - cOCT6100_TSI_MEM_FOR_TIMESTAMP;
144
 
 
145
 
        if ( pSharedInfo->ChipConfig.fEnableExtToneDetection == TRUE )
146
 
                pSharedInfo->MemoryMap.ulNumTsiEntries--;
147
 
 
148
 
        mOCT6100_GET_TSI_MEMORY_ALLOC_PNT( pSharedInfo, pTsiMemAlloc );
149
 
        
150
 
        ulResult = OctapiLlmAllocInit( &pTsiMemAlloc, pSharedInfo->MemoryMap.ulNumTsiEntries );
151
 
        if ( ulResult != cOCT6100_ERR_OK )
152
 
                return cOCT6100_ERR_FATAL_95;
153
 
 
154
 
        /* Initialize the conversion memory allocation structure. */
155
 
        mOCT6100_GET_CONVERSION_MEMORY_ALLOC_PNT( pSharedInfo, pAllocPnt );
156
 
        
157
 
        ulResult = OctapiLlmAllocInit( &pAllocPnt, cOCT6100_MAX_CONVERSION_MEMORY_BLOCKS );
158
 
        if ( ulResult != cOCT6100_ERR_OK )
159
 
                return cOCT6100_ERR_FATAL_B6;
160
 
 
161
 
        return cOCT6100_ERR_OK;
162
 
}
163
 
#endif
164
 
 
165
 
 
166
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
167
 
 
168
 
Function:               Oct6100ApiBufferPlayoutMemorySwInit
169
 
 
170
 
Description:    Initialize the buffer playout memory allocation working 
171
 
                                structures.
172
 
 
173
 
-------------------------------------------------------------------------------
174
 
|       Argument                |       Description
175
 
-------------------------------------------------------------------------------
176
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
177
 
                                                the present state of the chip and all its resources.
178
 
 
179
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
180
 
#if !SKIP_Oct6100ApiBufferPlayoutMemorySwInit
181
 
UINT32 Oct6100ApiBufferPlayoutMemorySwInit(
182
 
                                IN OUT  tPOCT6100_INSTANCE_API  f_pApiInstance )
183
 
{
184
 
        tPOCT6100_SHARED_INFO                                           pSharedInfo;
185
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pNode;
186
 
        UINT32                                                                          i;
187
 
 
188
 
        /* Get local pointer to shared portion of instance. */
189
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
190
 
 
191
 
        /* Only if buffer playout will be used. */
192
 
        if ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers > 0 )
193
 
        {
194
 
                mOCT6100_GET_BUFFER_MEMORY_NODE_LIST_PNT( pSharedInfo, pNode );
195
 
 
196
 
                /* First node contains all free memory at beginning. This node is not used, but represents the memory. */
197
 
                pNode->ulSize = ( pSharedInfo->MiscVars.ulTotalMemSize + cOCT6100_EXTERNAL_MEM_BASE_ADDRESS ) - pSharedInfo->MemoryMap.ulFreeMemBaseAddress;
198
 
                pNode->ulNext = 0; 
199
 
                pNode->ulPrevious = 0; 
200
 
                pNode->fAllocated = FALSE;
201
 
                pNode->ulStartAddress = pSharedInfo->MemoryMap.ulFreeMemBaseAddress;
202
 
 
203
 
                pNode++;
204
 
 
205
 
                /* Now create the first node of the free list, i.e. nodes that can be used later for modeling the memory. */
206
 
                pNode->ulSize = 0;
207
 
                /* Next free. */
208
 
                pNode->ulNext = 2;
209
 
                /* Last. */
210
 
                pNode->ulPrevious = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1;
211
 
                pNode->fAllocated = FALSE;
212
 
                pNode->ulStartAddress = 0;
213
 
 
214
 
                pNode++;
215
 
 
216
 
                /* Link all the unused nodes. */
217
 
                for( i = 2; i < (UINT32)( ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1 ); i ++ )
218
 
                {
219
 
                        pNode->ulNext = i + 1;
220
 
                        pNode->ulPrevious = i - 1;
221
 
                        pNode->ulStartAddress = 0;
222
 
                        pNode->ulSize = 0;
223
 
                        pNode->fAllocated = FALSE;
224
 
                        pNode++;
225
 
                }
226
 
 
227
 
                /* Last node of the unused list. */
228
 
                pNode->fAllocated = FALSE;
229
 
                pNode->ulPrevious = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 2;
230
 
                /* Free list head. */
231
 
                pNode->ulNext = 1; 
232
 
                pNode->ulSize = 0;
233
 
                pNode->ulStartAddress = 0;
234
 
 
235
 
                /* Set roving pointer to first node ( which can be used! ) */
236
 
                pSharedInfo->PlayoutInfo.ulRovingNode = 0;
237
 
 
238
 
                /* First unused node. */
239
 
                pSharedInfo->PlayoutInfo.ulFirstUnusedNode = 1;
240
 
 
241
 
                /* Last unused node. */
242
 
                pSharedInfo->PlayoutInfo.ulLastUnusedNode = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1;
243
 
 
244
 
                /* Number of unused nodes. */
245
 
                pSharedInfo->PlayoutInfo.ulUnusedNodeCnt = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1;
246
 
        }
247
 
        else
248
 
        {
249
 
                pSharedInfo->PlayoutInfo.ulUnusedNodeCnt = 0;
250
 
        }
251
 
 
252
 
        return cOCT6100_ERR_OK;
253
 
}
254
 
#endif
255
 
 
256
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
257
 
 
258
 
Function:               Oct6100ApiReserveBufferPlayoutMemoryNode
259
 
 
260
 
Description:    Get a free node from the unused buffer playout node list.
261
 
 
262
 
-------------------------------------------------------------------------------
263
 
|       Argument                |       Description
264
 
-------------------------------------------------------------------------------
265
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
266
 
                                                the present state of the chip and all its resources.
267
 
 
268
 
f_pulNewNode                    The index of the node.
269
 
 
270
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
271
 
#if !SKIP_Oct6100ApiReserveBufferPlayoutMemoryNode
272
 
UINT32 Oct6100ApiReserveBufferPlayoutMemoryNode( 
273
 
                                IN OUT  tPOCT6100_INSTANCE_API  f_pApiInstance,
274
 
                                OUT             PUINT32                                 f_pulNewNode )
275
 
{
276
 
        tPOCT6100_SHARED_INFO                                           pSharedInfo;
277
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pNode;
278
 
 
279
 
        /* Get local pointer to shared portion of instance. */
280
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
281
 
 
282
 
        /* Check if a free block is left. */
283
 
        if ( pSharedInfo->PlayoutInfo.ulUnusedNodeCnt == 0 )
284
 
        {
285
 
                /* This should not happen according to the allocated list from the beginning. */
286
 
                return cOCT6100_ERR_FATAL_CC;
287
 
        }
288
 
 
289
 
        /* The new node is the first in the unused list. */
290
 
        *f_pulNewNode = pSharedInfo->PlayoutInfo.ulFirstUnusedNode;
291
 
 
292
 
        /* Unlink this new node from the unused list. */
293
 
        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, *f_pulNewNode );
294
 
 
295
 
        pSharedInfo->PlayoutInfo.ulFirstUnusedNode = pNode->ulNext;
296
 
 
297
 
        pNode->ulPrevious = pSharedInfo->PlayoutInfo.ulLastUnusedNode;
298
 
 
299
 
        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, pSharedInfo->PlayoutInfo.ulLastUnusedNode );
300
 
 
301
 
        pNode->ulNext = pSharedInfo->PlayoutInfo.ulFirstUnusedNode;
302
 
 
303
 
        /* Update unused node count. */
304
 
        pSharedInfo->PlayoutInfo.ulUnusedNodeCnt--;
305
 
 
306
 
        return cOCT6100_ERR_OK;
307
 
}
308
 
#endif
309
 
 
310
 
 
311
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
312
 
 
313
 
Function:               Oct6100ApiReleaseBufferPlayoutMemoryNode
314
 
 
315
 
Description:    Release a node that is not used anymore.  Insert this node 
316
 
                                into the unused list.
317
 
 
318
 
-------------------------------------------------------------------------------
319
 
|       Argument                |       Description
320
 
-------------------------------------------------------------------------------
321
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
322
 
                                                the present state of the chip and all its resources.
323
 
 
324
 
f_ulOldNode                             The index of the node.
325
 
 
326
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
327
 
#if !SKIP_Oct6100ApiReleaseBufferPlayoutMemoryNode
328
 
UINT32 Oct6100ApiReleaseBufferPlayoutMemoryNode( 
329
 
                                        IN OUT  tPOCT6100_INSTANCE_API  f_pApiInstance,
330
 
                                        IN              UINT32                                  f_ulOldNode )
331
 
{
332
 
        tPOCT6100_SHARED_INFO                                           pSharedInfo;
333
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pNode;
334
 
 
335
 
        /* Get local pointer to shared portion of instance. */
336
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
337
 
 
338
 
        /* Get the last unused node.  Insert this old node at the end of the unused list. */
339
 
        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, pSharedInfo->PlayoutInfo.ulLastUnusedNode );
340
 
 
341
 
        /* Last node points to old node. */
342
 
        pNode->ulNext = f_ulOldNode;
343
 
 
344
 
        /* Update old node. */
345
 
        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, f_ulOldNode );
346
 
 
347
 
        pNode->ulPrevious = pSharedInfo->PlayoutInfo.ulLastUnusedNode;
348
 
        pNode->ulNext = pSharedInfo->PlayoutInfo.ulFirstUnusedNode;
349
 
        pSharedInfo->PlayoutInfo.ulLastUnusedNode = f_ulOldNode;
350
 
 
351
 
        /* Keep unused node count. */
352
 
        pSharedInfo->PlayoutInfo.ulUnusedNodeCnt++;
353
 
 
354
 
        return cOCT6100_ERR_OK;
355
 
}
356
 
#endif
357
 
 
358
 
 
359
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
360
 
 
361
 
Function:               Oct6100ApiReserveBufferPlayoutMemory
362
 
 
363
 
Description:    Try to allocate requested size.
364
 
                                Returns an error if malloc point could not be found.
365
 
 
366
 
-------------------------------------------------------------------------------
367
 
|       Argument                |       Description
368
 
-------------------------------------------------------------------------------
369
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
370
 
                                                the present state of the chip and all its resources.
371
 
 
372
 
f_ulSize                                Needed size.
373
 
f_pulMallocAddress              Alloc point.  This memory can now be used.
374
 
 
375
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
376
 
#if !SKIP_Oct6100ApiReserveBufferPlayoutMemory
377
 
UINT32 Oct6100ApiReserveBufferPlayoutMemory( 
378
 
                                        IN OUT  tPOCT6100_INSTANCE_API  f_pApiInstance,
379
 
                                        IN              UINT32                                  f_ulSize, 
380
 
                                        OUT             PUINT32                                 f_pulMallocAddress )
381
 
{
382
 
        tPOCT6100_SHARED_INFO                                           pSharedInfo;
383
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pCurrentNode;
384
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pTempNode;
385
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pNewNode;
386
 
        
387
 
        UINT32 ulCurrentBufferPlayoutMallocNode;
388
 
        UINT32 ulNewNode;
389
 
        BOOL fFoundMemory = FALSE;
390
 
        UINT32 ulResult;
391
 
 
392
 
        /* Get local pointer to shared portion of instance. */
393
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
394
 
        
395
 
        /* Requested size must be divisible by 64. */
396
 
        if ( f_ulSize % 64 )
397
 
        {
398
 
                f_ulSize = f_ulSize + ( 64 - ( f_ulSize % 64 ) );
399
 
        }
400
 
 
401
 
        /* Start with roving pointer. */
402
 
        ulCurrentBufferPlayoutMallocNode = pSharedInfo->PlayoutInfo.ulRovingNode;
403
 
 
404
 
        *f_pulMallocAddress = 0;
405
 
 
406
 
        /* Return an error if size requested is zero. */
407
 
        if ( f_ulSize == 0 )
408
 
        {
409
 
                return cOCT6100_ERR_BUFFER_PLAYOUT_MALLOC_ZERO;
410
 
        }
411
 
 
412
 
        do
413
 
        {
414
 
                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pCurrentNode, ulCurrentBufferPlayoutMallocNode );
415
 
 
416
 
                /* Look for a free node big enough to fulfill user requested size. */
417
 
                if ( ( pCurrentNode->fAllocated == FALSE ) && ( pCurrentNode->ulSize >= f_ulSize ) )
418
 
                {
419
 
                        /* Use this node! */
420
 
                        pCurrentNode->fAllocated = TRUE;
421
 
 
422
 
                        if ( pCurrentNode->ulNext != 0 )
423
 
                        {
424
 
                                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulNext );
425
 
 
426
 
                                if( ( pTempNode->fAllocated == TRUE ) && ( pCurrentNode->ulSize > f_ulSize ) )
427
 
                                {
428
 
                                        /* Fragmentation NOW! */
429
 
 
430
 
                                        /* Allocate new node that will contain free size. */
431
 
                                        ulResult = Oct6100ApiReserveBufferPlayoutMemoryNode( f_pApiInstance, &ulNewNode );
432
 
                                        if ( ulResult != cOCT6100_ERR_OK )
433
 
                                                return ulResult;
434
 
 
435
 
                                        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNewNode, ulNewNode );
436
 
 
437
 
                                        /* Can use this free node. */
438
 
                                        pNewNode->ulSize = pCurrentNode->ulSize - f_ulSize;
439
 
                                        pNewNode->ulStartAddress = pCurrentNode->ulStartAddress + f_ulSize;
440
 
 
441
 
                                        /* Link new node into the list. */
442
 
                                        pNewNode->ulNext = pCurrentNode->ulNext;
443
 
                                        pNewNode->ulPrevious = ulCurrentBufferPlayoutMallocNode;
444
 
                                        pNewNode->fAllocated = FALSE;
445
 
                                        pTempNode->ulPrevious = ulNewNode;
446
 
                                        pCurrentNode->ulNext = ulNewNode;
447
 
                                }
448
 
                        }
449
 
                        else if ( pCurrentNode->ulSize > f_ulSize )
450
 
                        {
451
 
                                /* Must allocate a new free node for the rest of the space. */
452
 
                                ulResult = Oct6100ApiReserveBufferPlayoutMemoryNode( f_pApiInstance, &ulNewNode );
453
 
                                if ( ulResult != cOCT6100_ERR_OK )
454
 
                                        return ulResult;
455
 
 
456
 
                                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNewNode, ulNewNode );
457
 
 
458
 
                                pNewNode->ulNext = pCurrentNode->ulNext;
459
 
                                pCurrentNode->ulNext = ulNewNode;
460
 
                                pNewNode->ulPrevious = ulCurrentBufferPlayoutMallocNode;
461
 
                                pNewNode->fAllocated = FALSE;
462
 
                                pNewNode->ulSize = pCurrentNode->ulSize - f_ulSize;
463
 
                                pNewNode->ulStartAddress = pCurrentNode->ulStartAddress + f_ulSize;
464
 
 
465
 
                                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, 0 );
466
 
 
467
 
                                /* Check for the head node that would have to be updated. */
468
 
                                if ( ( ulCurrentBufferPlayoutMallocNode == 0 ) && ( pTempNode->ulPrevious == 0 ) )
469
 
                                        pTempNode->ulPrevious = ulNewNode;
470
 
                        }
471
 
                        else
472
 
                        {
473
 
                                /* Perfect fit. */
474
 
                        }
475
 
                        pCurrentNode->ulSize = f_ulSize;
476
 
 
477
 
                        /* Update roving pointer. */
478
 
                        pSharedInfo->PlayoutInfo.ulRovingNode = ulCurrentBufferPlayoutMallocNode;
479
 
                        *f_pulMallocAddress = pCurrentNode->ulStartAddress;
480
 
                        fFoundMemory = TRUE;
481
 
                        break;
482
 
                }
483
 
 
484
 
                /* Next block! */
485
 
                ulCurrentBufferPlayoutMallocNode = pCurrentNode->ulNext;
486
 
 
487
 
        } while ( pSharedInfo->PlayoutInfo.ulRovingNode != ulCurrentBufferPlayoutMallocNode );
488
 
 
489
 
        if ( fFoundMemory == FALSE )
490
 
        {
491
 
                return cOCT6100_ERR_BUFFER_PLAYOUT_NO_MEMORY;
492
 
        }
493
 
 
494
 
        return cOCT6100_ERR_OK;
495
 
}
496
 
#endif
497
 
 
498
 
 
499
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
500
 
 
501
 
Function:               Oct6100ApiReleaseBufferPlayoutMemory
502
 
 
503
 
Description:    Free what was allocated at address.  Free is somewhat slower 
504
 
                                then Malloc.  O(n), must travel through the list looking for 
505
 
                                the malloc point.  Return an error if alloc point was not found.
506
 
 
507
 
-------------------------------------------------------------------------------
508
 
|       Argument                |       Description
509
 
-------------------------------------------------------------------------------
510
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
511
 
                                                the present state of the chip and all its resources.
512
 
 
513
 
f_ulMallocAddress               Alloc point.  The memory at address will be freed.
514
 
 
515
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
516
 
#if !SKIP_Oct6100ApiReleaseBufferPlayoutMemory
517
 
UINT32 Oct6100ApiReleaseBufferPlayoutMemory(
518
 
                                IN OUT  tPOCT6100_INSTANCE_API  f_pApiInstance,
519
 
                                IN              UINT32                                  f_ulMallocAddress )
520
 
{
521
 
        tPOCT6100_SHARED_INFO                                           pSharedInfo;
522
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pCurrentNode;
523
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pTempNode;
524
 
        tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE        pOldNode;
525
 
 
526
 
        UINT32 ulResult = cOCT6100_ERR_BUFFER_PLAYOUT_MALLOC_POINT_NOT_FOUND;
527
 
        UINT32 ulNodeToMerge;
528
 
        UINT32 ulNodeToRemove;
529
 
        UINT32 ulCurrentBufferPlayoutMallocNode;
530
 
 
531
 
        /* Get local pointer to shared portion of instance. */
532
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
533
 
 
534
 
        /* Start from the beginning and find the alloc node. */
535
 
        ulCurrentBufferPlayoutMallocNode = 0;
536
 
        
537
 
        do
538
 
        {
539
 
                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pCurrentNode, ulCurrentBufferPlayoutMallocNode );
540
 
 
541
 
                if ( ( pCurrentNode->ulStartAddress == f_ulMallocAddress ) && ( pCurrentNode->fAllocated == TRUE ) )
542
 
                {
543
 
                        /* We found the block! */
544
 
                        pCurrentNode->fAllocated = FALSE;
545
 
 
546
 
                        /* Check if the next node can be merged. */
547
 
                        if ( pCurrentNode->ulNext != 0 )
548
 
                        {
549
 
                                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulNext );
550
 
 
551
 
                                if ( pTempNode->fAllocated == FALSE )
552
 
                                {
553
 
                                        /* Can merge this block to us. */
554
 
                                        pCurrentNode->ulSize += pTempNode->ulSize;
555
 
                                        pTempNode->ulSize = 0;
556
 
 
557
 
                                        /* Unlink unused node. */
558
 
                                        ulNodeToRemove = pCurrentNode->ulNext;
559
 
                                        pCurrentNode->ulNext = pTempNode->ulNext;
560
 
 
561
 
                                        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulNext );
562
 
 
563
 
                                        pTempNode->ulPrevious = ulCurrentBufferPlayoutMallocNode;
564
 
 
565
 
                                        ulResult = Oct6100ApiReleaseBufferPlayoutMemoryNode( f_pApiInstance, ulNodeToRemove );
566
 
                                        if ( ulResult != cOCT6100_ERR_OK )
567
 
                                                return ulResult;
568
 
                                        
569
 
                                        /* Move roving pointer if have to. */
570
 
                                        if ( pSharedInfo->PlayoutInfo.ulRovingNode == ulNodeToRemove )
571
 
                                                pSharedInfo->PlayoutInfo.ulRovingNode = ulCurrentBufferPlayoutMallocNode;
572
 
                                }
573
 
                        }
574
 
 
575
 
                        /* Check if previous node can merge. */
576
 
                        if ( ulCurrentBufferPlayoutMallocNode != 0 )
577
 
                        {
578
 
                                mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulPrevious );
579
 
 
580
 
                                if ( pTempNode->fAllocated == FALSE )
581
 
                                {
582
 
                                        ulNodeToMerge = pCurrentNode->ulPrevious;
583
 
 
584
 
                                        /* Can merge us to this node. */
585
 
                                        pTempNode->ulSize += pCurrentNode->ulSize;
586
 
                                        pCurrentNode->ulSize = 0;
587
 
 
588
 
                                        /* Unlink unused node. */
589
 
                                        ulNodeToRemove = ulCurrentBufferPlayoutMallocNode;
590
 
 
591
 
                                        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pOldNode, ulNodeToRemove );
592
 
 
593
 
                                        pTempNode->ulNext = pOldNode->ulNext;
594
 
 
595
 
                                        mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pTempNode->ulNext );
596
 
 
597
 
                                        pTempNode->ulPrevious = ulNodeToMerge;
598
 
 
599
 
                                        pOldNode->fAllocated = FALSE;
600
 
                                        pOldNode->ulSize = 0;
601
 
                                        pOldNode->ulStartAddress = 0; 
602
 
 
603
 
                                        /* Move roving pointer if have to. */
604
 
                                        if ( pSharedInfo->PlayoutInfo.ulRovingNode == ulNodeToRemove )
605
 
                                                pSharedInfo->PlayoutInfo.ulRovingNode = ulNodeToMerge;
606
 
 
607
 
                                        /* Release this unused node. */
608
 
                                        ulResult = Oct6100ApiReleaseBufferPlayoutMemoryNode( f_pApiInstance, ulNodeToRemove );
609
 
                                        if ( ulResult != cOCT6100_ERR_OK )
610
 
                                                return ulResult;
611
 
                                }
612
 
                        }
613
 
 
614
 
                        /* All's good! */
615
 
                        ulResult = 0;
616
 
                        break;
617
 
                }
618
 
 
619
 
                /* Next node. */
620
 
                ulCurrentBufferPlayoutMallocNode = pCurrentNode->ulNext;
621
 
                
622
 
        } while( ulCurrentBufferPlayoutMallocNode != 0 );
623
 
 
624
 
        return ulResult;
625
 
}
626
 
#endif
627
 
 
628
 
 
629
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
630
 
 
631
 
Function:               Oct6100ApiReserveTsiMemEntry
632
 
 
633
 
Description:    Reserves a TSI chariot memory entry.
634
 
 
635
 
-------------------------------------------------------------------------------
636
 
|       Argument                |       Description
637
 
-------------------------------------------------------------------------------
638
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
639
 
                                                the present state of the chip and all its resources.
640
 
 
641
 
f_pusTsiMemIndex                Resulting index reserved in the TSI chariot memory.
642
 
 
643
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
644
 
#if !SKIP_Oct6100ApiReserveTsiMemEntry
645
 
UINT32 Oct6100ApiReserveTsiMemEntry(
646
 
                                IN OUT  tPOCT6100_INSTANCE_API          f_pApiInstance,
647
 
                                OUT             PUINT16                                         f_pusTsiMemIndex )
648
 
{
649
 
        tPOCT6100_SHARED_INFO           pSharedInfo;
650
 
        PVOID   pTsiMemAlloc;
651
 
        UINT32  ulResult;
652
 
        UINT32  ulIndex;
653
 
        UINT32  ulNumTsiB4Timestamp;
654
 
 
655
 
        /* Get local pointer to shared portion of instance. */
656
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
657
 
 
658
 
        mOCT6100_GET_TSI_MEMORY_ALLOC_PNT( pSharedInfo, pTsiMemAlloc )
659
 
        
660
 
        ulResult = OctapiLlmAllocAlloc( pTsiMemAlloc, &ulIndex );
661
 
        if ( ulResult != cOCT6100_ERR_OK )
662
 
        {
663
 
                if ( ulResult == OCTAPI_LLM_NO_STRUCTURES_LEFT )
664
 
                        return cOCT6100_ERR_MEMORY_ALL_TSI_MEM_ENTRY_RESERVED;
665
 
                else
666
 
                        return cOCT6100_ERR_FATAL_92;
667
 
        }
668
 
 
669
 
 
670
 
        if ( ulIndex >= cOCT6100_NUM_TSI_B4_PHASING )
671
 
        {
672
 
                /* Evaluate the number of TSI memory before the timestamp TSI. */
673
 
                ulNumTsiB4Timestamp = cOCT6100_NUM_TSI_B4_PHASING + cOCT6100_MAX_TSI_B4_TIMESTAMP - pSharedInfo->ChipConfig.usMaxPhasingTssts;
674
 
                
675
 
                if ( ulIndex >= ulNumTsiB4Timestamp )
676
 
                {
677
 
                        /* + 4 for the timestamp TSI entries.*/
678
 
                        *f_pusTsiMemIndex = (UINT16)( pSharedInfo->ChipConfig.usMaxPhasingTssts + ulIndex + cOCT6100_TSI_MEM_FOR_TIMESTAMP );
679
 
                }
680
 
                else /* ulIndex < ulNumTsiB4Timestamp */
681
 
                {
682
 
                        *f_pusTsiMemIndex = (UINT16)( pSharedInfo->ChipConfig.usMaxPhasingTssts + ulIndex );
683
 
                }
684
 
        }
685
 
        else /* ulIndex < ulNumTsiB4Timestamp */
686
 
        {
687
 
                *f_pusTsiMemIndex = (UINT16)( ulIndex );
688
 
        }
689
 
 
690
 
        return cOCT6100_ERR_OK;
691
 
}
692
 
#endif
693
 
 
694
 
 
695
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
696
 
 
697
 
Function:               Oct6100ApiReleaseTsiMemEntry
698
 
 
699
 
Description:    Releases a TSI chariot memory entry specified.
700
 
 
701
 
-------------------------------------------------------------------------------
702
 
|       Argument                |       Description
703
 
-------------------------------------------------------------------------------
704
 
f_pApiInstance                  Pointer to API instance. This memory is used to keep
705
 
                                                the present state of the chip and all its resources.
706
 
 
707
 
f_usTsiMemIndex                 Index reserved in the TSI chariot memory.
708
 
 
709
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
710
 
#if !SKIP_Oct6100ApiReleaseTsiMemEntry
711
 
UINT32 Oct6100ApiReleaseTsiMemEntry(
712
 
                                IN OUT  tPOCT6100_INSTANCE_API          f_pApiInstance,
713
 
                                IN              UINT16                                          f_usTsiMemIndex )
714
 
{
715
 
        tPOCT6100_SHARED_INFO           pSharedInfo;
716
 
        PVOID   pTsiMemAlloc;
717
 
        UINT32  ulResult;
718
 
        UINT32  ulIndex;
719
 
 
720
 
        /* Get local pointer to shared portion of instance. */
721
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
722
 
 
723
 
        /* Check if the entry programmed is greater then the timestamp entries. */
724
 
        if ( f_usTsiMemIndex > cOCT6100_TSST_CONTROL_TIMESTAMP_BASE_ENTRY )
725
 
                ulIndex = f_usTsiMemIndex - cOCT6100_TSI_MEM_FOR_TIMESTAMP;
726
 
        else
727
 
                ulIndex = f_usTsiMemIndex;
728
 
 
729
 
        /* Check if the entry programmed is greater then the phasing TSST entries. */
730
 
        if ( ulIndex > cOCT6100_TSST_CONTROL_PHASING_TSST_BASE_ENTRY )
731
 
                ulIndex -= pSharedInfo->ChipConfig.usMaxPhasingTssts;
732
 
 
733
 
        mOCT6100_GET_TSI_MEMORY_ALLOC_PNT( pSharedInfo, pTsiMemAlloc )
734
 
        
735
 
        ulResult = OctapiLlmAllocDealloc( pTsiMemAlloc, ulIndex );
736
 
        if ( ulResult != cOCT6100_ERR_OK )
737
 
        {
738
 
                return cOCT6100_ERR_FATAL_93;
739
 
        }
740
 
 
741
 
        return cOCT6100_ERR_OK;
742
 
}
743
 
#endif
744
 
 
745
 
 
746
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
747
 
 
748
 
Function:               Oct6100ApiReserveConversionMemEntry
749
 
 
750
 
Description:    Reserves one of the conversion memory entry 
751
 
 
752
 
-------------------------------------------------------------------------------
753
 
|       Argument                |       Description
754
 
-------------------------------------------------------------------------------
755
 
f_pApiInstance                  Pointer to API instance. This memory is used to 
756
 
                                                keep the present state of the chip and all its 
757
 
                                                resources.
758
 
 
759
 
f_pusConversionMemIndex Resulting index reserved in the conversion memory.
760
 
 
761
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
762
 
#if !SKIP_Oct6100ApiReserveConversionMemEntry
763
 
UINT32 Oct6100ApiReserveConversionMemEntry(
764
 
                                IN OUT  tPOCT6100_INSTANCE_API          f_pApiInstance,
765
 
                                OUT             PUINT16                                         f_pusConversionMemIndex )
766
 
{
767
 
        tPOCT6100_SHARED_INFO           pSharedInfo;
768
 
        PVOID   pConversionMemAlloc;
769
 
        UINT32  ulConversionMemIndex;
770
 
        UINT32  ulResult;
771
 
 
772
 
        /* Get local pointer to shared portion of instance. */
773
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
774
 
 
775
 
        mOCT6100_GET_CONVERSION_MEMORY_ALLOC_PNT( pSharedInfo, pConversionMemAlloc )
776
 
        
777
 
        ulResult = OctapiLlmAllocAlloc( pConversionMemAlloc, &ulConversionMemIndex );
778
 
        if ( ulResult != cOCT6100_ERR_OK )
779
 
        {
780
 
                if ( ulResult == OCTAPI_LLM_NO_STRUCTURES_LEFT )
781
 
                        return cOCT6100_ERR_MEMORY_ALL_CONVERSION_MEM_ENTRY_RESERVED;
782
 
                else
783
 
                        return cOCT6100_ERR_FATAL_B8;
784
 
        }
785
 
 
786
 
        *f_pusConversionMemIndex = (UINT16)( ulConversionMemIndex & 0xFFFF );
787
 
 
788
 
        return cOCT6100_ERR_OK;
789
 
}
790
 
#endif
791
 
 
792
 
 
793
 
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
794
 
 
795
 
Function:               Oct6100ApiReleaseConversionMemEntry
796
 
 
797
 
Description:    Releases the conversion chariot memory entry specified.
798
 
 
799
 
-------------------------------------------------------------------------------
800
 
|       Argument                |       Description
801
 
-------------------------------------------------------------------------------
802
 
f_pApiInstance                  Pointer to API instance. This memory is used to 
803
 
                                                keep the present state of the chip and all its 
804
 
                                                resources.
805
 
 
806
 
f_usConversionMemIndex  Index reserved in the conversion chariot memory.
807
 
 
808
 
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
809
 
#if !SKIP_Oct6100ApiReleaseConversionMemEntry
810
 
UINT32 Oct6100ApiReleaseConversionMemEntry(
811
 
                                IN OUT  tPOCT6100_INSTANCE_API          f_pApiInstance,
812
 
                                IN              UINT16                                          f_usConversionMemIndex )
813
 
{
814
 
        tPOCT6100_SHARED_INFO           pSharedInfo;
815
 
        PVOID                                           pConversionMemAlloc;
816
 
        UINT32                                          ulResult;
817
 
 
818
 
        /* Get local pointer to shared portion of instance. */
819
 
        pSharedInfo = f_pApiInstance->pSharedInfo;
820
 
 
821
 
        mOCT6100_GET_CONVERSION_MEMORY_ALLOC_PNT( pSharedInfo, pConversionMemAlloc )
822
 
        
823
 
        ulResult = OctapiLlmAllocDealloc( pConversionMemAlloc, f_usConversionMemIndex );
824
 
        if ( ulResult != cOCT6100_ERR_OK )
825
 
        {
826
 
                return cOCT6100_ERR_FATAL_B7;
827
 
        }
828
 
 
829
 
        return cOCT6100_ERR_OK;
830
 
}
831
 
#endif