1
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
5
Copyright (c) 2001-2007 Octasic Inc.
9
This file contains the functions used to manage the allocation of memory
10
blocks in external memory.
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.
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
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.
26
$Octasic_Release: OCT612xAPI-01.00-PR49 $
28
$Octasic_Revision: 42 $
30
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
33
/***************************** INCLUDE FILES *******************************/
37
#include "oct6100api/oct6100_defines.h"
38
#include "oct6100api/oct6100_errors.h"
40
#include "apilib/octapi_llman.h"
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"
52
#include "oct6100api/oct6100_interrupts_pub.h"
53
#include "oct6100api/oct6100_channel_pub.h"
54
#include "oct6100api/oct6100_chip_open_pub.h"
56
#include "oct6100_chip_open_priv.h"
57
#include "oct6100_memory_priv.h"
60
/**************************** PRIVATE FUNCTIONS ****************************/
63
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
65
Function: Oct6100ApiGetMemorySwSizes
67
Description: Gets the sizes of all portions of the API instance pertinent
68
to the management of the memories.
70
-------------------------------------------------------------------------------
71
| Argument | Description
72
-------------------------------------------------------------------------------
73
f_pOpenChip Pointer to chip configuration struct.
74
f_pInstSizes Pointer to struct containing instance sizes.
76
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
77
#if !SKIP_Oct6100ApiGetMemorySwSizes
78
UINT32 Oct6100ApiGetMemorySwSizes(
79
IN tPOCT6100_CHIP_OPEN f_pOpenChip,
80
OUT tPOCT6100_API_INSTANCE_SIZES f_pInstSizes )
84
UINT32 ulNumTsiChariots;
86
/*=========================================================================*/
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;
92
if ( f_pOpenChip->fEnableExtToneDetection == TRUE )
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;
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;
105
mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulTsiMemoryAlloc, ulTempVar );
106
mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulConversionMemoryAlloc, ulTempVar );
108
return cOCT6100_ERR_OK;
113
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
115
Function: Oct6100ApiMemorySwInit
117
Description: Initializes all elements of the instance structure associated
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.
126
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
127
#if !SKIP_Oct6100ApiMemorySwInit
128
UINT32 Oct6100ApiMemorySwInit(
129
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance )
131
tPOCT6100_SHARED_INFO pSharedInfo;
136
/* Get local pointer(s). */
137
pSharedInfo = f_pApiInstance->pSharedInfo;
139
/*=========================================================================*/
140
/* Internal memory */
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;
145
if ( pSharedInfo->ChipConfig.fEnableExtToneDetection == TRUE )
146
pSharedInfo->MemoryMap.ulNumTsiEntries--;
148
mOCT6100_GET_TSI_MEMORY_ALLOC_PNT( pSharedInfo, pTsiMemAlloc );
150
ulResult = OctapiLlmAllocInit( &pTsiMemAlloc, pSharedInfo->MemoryMap.ulNumTsiEntries );
151
if ( ulResult != cOCT6100_ERR_OK )
152
return cOCT6100_ERR_FATAL_95;
154
/* Initialize the conversion memory allocation structure. */
155
mOCT6100_GET_CONVERSION_MEMORY_ALLOC_PNT( pSharedInfo, pAllocPnt );
157
ulResult = OctapiLlmAllocInit( &pAllocPnt, cOCT6100_MAX_CONVERSION_MEMORY_BLOCKS );
158
if ( ulResult != cOCT6100_ERR_OK )
159
return cOCT6100_ERR_FATAL_B6;
161
return cOCT6100_ERR_OK;
166
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
168
Function: Oct6100ApiBufferPlayoutMemorySwInit
170
Description: Initialize the buffer playout memory allocation working
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.
179
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
180
#if !SKIP_Oct6100ApiBufferPlayoutMemorySwInit
181
UINT32 Oct6100ApiBufferPlayoutMemorySwInit(
182
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance )
184
tPOCT6100_SHARED_INFO pSharedInfo;
185
tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE pNode;
188
/* Get local pointer to shared portion of instance. */
189
pSharedInfo = f_pApiInstance->pSharedInfo;
191
/* Only if buffer playout will be used. */
192
if ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers > 0 )
194
mOCT6100_GET_BUFFER_MEMORY_NODE_LIST_PNT( pSharedInfo, pNode );
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;
199
pNode->ulPrevious = 0;
200
pNode->fAllocated = FALSE;
201
pNode->ulStartAddress = pSharedInfo->MemoryMap.ulFreeMemBaseAddress;
205
/* Now create the first node of the free list, i.e. nodes that can be used later for modeling the memory. */
210
pNode->ulPrevious = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1;
211
pNode->fAllocated = FALSE;
212
pNode->ulStartAddress = 0;
216
/* Link all the unused nodes. */
217
for( i = 2; i < (UINT32)( ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1 ); i ++ )
219
pNode->ulNext = i + 1;
220
pNode->ulPrevious = i - 1;
221
pNode->ulStartAddress = 0;
223
pNode->fAllocated = FALSE;
227
/* Last node of the unused list. */
228
pNode->fAllocated = FALSE;
229
pNode->ulPrevious = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 2;
230
/* Free list head. */
233
pNode->ulStartAddress = 0;
235
/* Set roving pointer to first node ( which can be used! ) */
236
pSharedInfo->PlayoutInfo.ulRovingNode = 0;
238
/* First unused node. */
239
pSharedInfo->PlayoutInfo.ulFirstUnusedNode = 1;
241
/* Last unused node. */
242
pSharedInfo->PlayoutInfo.ulLastUnusedNode = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1;
244
/* Number of unused nodes. */
245
pSharedInfo->PlayoutInfo.ulUnusedNodeCnt = ( pSharedInfo->ChipConfig.usMaxPlayoutBuffers * 2 ) - 1;
249
pSharedInfo->PlayoutInfo.ulUnusedNodeCnt = 0;
252
return cOCT6100_ERR_OK;
256
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
258
Function: Oct6100ApiReserveBufferPlayoutMemoryNode
260
Description: Get a free node from the unused buffer playout node list.
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.
268
f_pulNewNode The index of the node.
270
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
271
#if !SKIP_Oct6100ApiReserveBufferPlayoutMemoryNode
272
UINT32 Oct6100ApiReserveBufferPlayoutMemoryNode(
273
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
274
OUT PUINT32 f_pulNewNode )
276
tPOCT6100_SHARED_INFO pSharedInfo;
277
tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE pNode;
279
/* Get local pointer to shared portion of instance. */
280
pSharedInfo = f_pApiInstance->pSharedInfo;
282
/* Check if a free block is left. */
283
if ( pSharedInfo->PlayoutInfo.ulUnusedNodeCnt == 0 )
285
/* This should not happen according to the allocated list from the beginning. */
286
return cOCT6100_ERR_FATAL_CC;
289
/* The new node is the first in the unused list. */
290
*f_pulNewNode = pSharedInfo->PlayoutInfo.ulFirstUnusedNode;
292
/* Unlink this new node from the unused list. */
293
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, *f_pulNewNode );
295
pSharedInfo->PlayoutInfo.ulFirstUnusedNode = pNode->ulNext;
297
pNode->ulPrevious = pSharedInfo->PlayoutInfo.ulLastUnusedNode;
299
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, pSharedInfo->PlayoutInfo.ulLastUnusedNode );
301
pNode->ulNext = pSharedInfo->PlayoutInfo.ulFirstUnusedNode;
303
/* Update unused node count. */
304
pSharedInfo->PlayoutInfo.ulUnusedNodeCnt--;
306
return cOCT6100_ERR_OK;
311
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
313
Function: Oct6100ApiReleaseBufferPlayoutMemoryNode
315
Description: Release a node that is not used anymore. Insert this node
316
into the unused list.
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.
324
f_ulOldNode The index of the node.
326
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
327
#if !SKIP_Oct6100ApiReleaseBufferPlayoutMemoryNode
328
UINT32 Oct6100ApiReleaseBufferPlayoutMemoryNode(
329
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
330
IN UINT32 f_ulOldNode )
332
tPOCT6100_SHARED_INFO pSharedInfo;
333
tPOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE pNode;
335
/* Get local pointer to shared portion of instance. */
336
pSharedInfo = f_pApiInstance->pSharedInfo;
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 );
341
/* Last node points to old node. */
342
pNode->ulNext = f_ulOldNode;
344
/* Update old node. */
345
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNode, f_ulOldNode );
347
pNode->ulPrevious = pSharedInfo->PlayoutInfo.ulLastUnusedNode;
348
pNode->ulNext = pSharedInfo->PlayoutInfo.ulFirstUnusedNode;
349
pSharedInfo->PlayoutInfo.ulLastUnusedNode = f_ulOldNode;
351
/* Keep unused node count. */
352
pSharedInfo->PlayoutInfo.ulUnusedNodeCnt++;
354
return cOCT6100_ERR_OK;
359
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
361
Function: Oct6100ApiReserveBufferPlayoutMemory
363
Description: Try to allocate requested size.
364
Returns an error if malloc point could not be found.
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.
372
f_ulSize Needed size.
373
f_pulMallocAddress Alloc point. This memory can now be used.
375
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
376
#if !SKIP_Oct6100ApiReserveBufferPlayoutMemory
377
UINT32 Oct6100ApiReserveBufferPlayoutMemory(
378
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
380
OUT PUINT32 f_pulMallocAddress )
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;
387
UINT32 ulCurrentBufferPlayoutMallocNode;
389
BOOL fFoundMemory = FALSE;
392
/* Get local pointer to shared portion of instance. */
393
pSharedInfo = f_pApiInstance->pSharedInfo;
395
/* Requested size must be divisible by 64. */
398
f_ulSize = f_ulSize + ( 64 - ( f_ulSize % 64 ) );
401
/* Start with roving pointer. */
402
ulCurrentBufferPlayoutMallocNode = pSharedInfo->PlayoutInfo.ulRovingNode;
404
*f_pulMallocAddress = 0;
406
/* Return an error if size requested is zero. */
409
return cOCT6100_ERR_BUFFER_PLAYOUT_MALLOC_ZERO;
414
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pCurrentNode, ulCurrentBufferPlayoutMallocNode );
416
/* Look for a free node big enough to fulfill user requested size. */
417
if ( ( pCurrentNode->fAllocated == FALSE ) && ( pCurrentNode->ulSize >= f_ulSize ) )
420
pCurrentNode->fAllocated = TRUE;
422
if ( pCurrentNode->ulNext != 0 )
424
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulNext );
426
if( ( pTempNode->fAllocated == TRUE ) && ( pCurrentNode->ulSize > f_ulSize ) )
428
/* Fragmentation NOW! */
430
/* Allocate new node that will contain free size. */
431
ulResult = Oct6100ApiReserveBufferPlayoutMemoryNode( f_pApiInstance, &ulNewNode );
432
if ( ulResult != cOCT6100_ERR_OK )
435
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNewNode, ulNewNode );
437
/* Can use this free node. */
438
pNewNode->ulSize = pCurrentNode->ulSize - f_ulSize;
439
pNewNode->ulStartAddress = pCurrentNode->ulStartAddress + f_ulSize;
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;
449
else if ( pCurrentNode->ulSize > f_ulSize )
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 )
456
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pNewNode, ulNewNode );
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;
465
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, 0 );
467
/* Check for the head node that would have to be updated. */
468
if ( ( ulCurrentBufferPlayoutMallocNode == 0 ) && ( pTempNode->ulPrevious == 0 ) )
469
pTempNode->ulPrevious = ulNewNode;
475
pCurrentNode->ulSize = f_ulSize;
477
/* Update roving pointer. */
478
pSharedInfo->PlayoutInfo.ulRovingNode = ulCurrentBufferPlayoutMallocNode;
479
*f_pulMallocAddress = pCurrentNode->ulStartAddress;
485
ulCurrentBufferPlayoutMallocNode = pCurrentNode->ulNext;
487
} while ( pSharedInfo->PlayoutInfo.ulRovingNode != ulCurrentBufferPlayoutMallocNode );
489
if ( fFoundMemory == FALSE )
491
return cOCT6100_ERR_BUFFER_PLAYOUT_NO_MEMORY;
494
return cOCT6100_ERR_OK;
499
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
501
Function: Oct6100ApiReleaseBufferPlayoutMemory
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.
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.
513
f_ulMallocAddress Alloc point. The memory at address will be freed.
515
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
516
#if !SKIP_Oct6100ApiReleaseBufferPlayoutMemory
517
UINT32 Oct6100ApiReleaseBufferPlayoutMemory(
518
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
519
IN UINT32 f_ulMallocAddress )
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;
526
UINT32 ulResult = cOCT6100_ERR_BUFFER_PLAYOUT_MALLOC_POINT_NOT_FOUND;
527
UINT32 ulNodeToMerge;
528
UINT32 ulNodeToRemove;
529
UINT32 ulCurrentBufferPlayoutMallocNode;
531
/* Get local pointer to shared portion of instance. */
532
pSharedInfo = f_pApiInstance->pSharedInfo;
534
/* Start from the beginning and find the alloc node. */
535
ulCurrentBufferPlayoutMallocNode = 0;
539
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pCurrentNode, ulCurrentBufferPlayoutMallocNode );
541
if ( ( pCurrentNode->ulStartAddress == f_ulMallocAddress ) && ( pCurrentNode->fAllocated == TRUE ) )
543
/* We found the block! */
544
pCurrentNode->fAllocated = FALSE;
546
/* Check if the next node can be merged. */
547
if ( pCurrentNode->ulNext != 0 )
549
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulNext );
551
if ( pTempNode->fAllocated == FALSE )
553
/* Can merge this block to us. */
554
pCurrentNode->ulSize += pTempNode->ulSize;
555
pTempNode->ulSize = 0;
557
/* Unlink unused node. */
558
ulNodeToRemove = pCurrentNode->ulNext;
559
pCurrentNode->ulNext = pTempNode->ulNext;
561
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulNext );
563
pTempNode->ulPrevious = ulCurrentBufferPlayoutMallocNode;
565
ulResult = Oct6100ApiReleaseBufferPlayoutMemoryNode( f_pApiInstance, ulNodeToRemove );
566
if ( ulResult != cOCT6100_ERR_OK )
569
/* Move roving pointer if have to. */
570
if ( pSharedInfo->PlayoutInfo.ulRovingNode == ulNodeToRemove )
571
pSharedInfo->PlayoutInfo.ulRovingNode = ulCurrentBufferPlayoutMallocNode;
575
/* Check if previous node can merge. */
576
if ( ulCurrentBufferPlayoutMallocNode != 0 )
578
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pCurrentNode->ulPrevious );
580
if ( pTempNode->fAllocated == FALSE )
582
ulNodeToMerge = pCurrentNode->ulPrevious;
584
/* Can merge us to this node. */
585
pTempNode->ulSize += pCurrentNode->ulSize;
586
pCurrentNode->ulSize = 0;
588
/* Unlink unused node. */
589
ulNodeToRemove = ulCurrentBufferPlayoutMallocNode;
591
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pOldNode, ulNodeToRemove );
593
pTempNode->ulNext = pOldNode->ulNext;
595
mOCT6100_GET_BUFFER_MEMORY_NODE_ENTRY_PNT( pSharedInfo, pTempNode, pTempNode->ulNext );
597
pTempNode->ulPrevious = ulNodeToMerge;
599
pOldNode->fAllocated = FALSE;
600
pOldNode->ulSize = 0;
601
pOldNode->ulStartAddress = 0;
603
/* Move roving pointer if have to. */
604
if ( pSharedInfo->PlayoutInfo.ulRovingNode == ulNodeToRemove )
605
pSharedInfo->PlayoutInfo.ulRovingNode = ulNodeToMerge;
607
/* Release this unused node. */
608
ulResult = Oct6100ApiReleaseBufferPlayoutMemoryNode( f_pApiInstance, ulNodeToRemove );
609
if ( ulResult != cOCT6100_ERR_OK )
620
ulCurrentBufferPlayoutMallocNode = pCurrentNode->ulNext;
622
} while( ulCurrentBufferPlayoutMallocNode != 0 );
629
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
631
Function: Oct6100ApiReserveTsiMemEntry
633
Description: Reserves a TSI chariot memory entry.
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.
641
f_pusTsiMemIndex Resulting index reserved in the TSI chariot memory.
643
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
644
#if !SKIP_Oct6100ApiReserveTsiMemEntry
645
UINT32 Oct6100ApiReserveTsiMemEntry(
646
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
647
OUT PUINT16 f_pusTsiMemIndex )
649
tPOCT6100_SHARED_INFO pSharedInfo;
653
UINT32 ulNumTsiB4Timestamp;
655
/* Get local pointer to shared portion of instance. */
656
pSharedInfo = f_pApiInstance->pSharedInfo;
658
mOCT6100_GET_TSI_MEMORY_ALLOC_PNT( pSharedInfo, pTsiMemAlloc )
660
ulResult = OctapiLlmAllocAlloc( pTsiMemAlloc, &ulIndex );
661
if ( ulResult != cOCT6100_ERR_OK )
663
if ( ulResult == OCTAPI_LLM_NO_STRUCTURES_LEFT )
664
return cOCT6100_ERR_MEMORY_ALL_TSI_MEM_ENTRY_RESERVED;
666
return cOCT6100_ERR_FATAL_92;
670
if ( ulIndex >= cOCT6100_NUM_TSI_B4_PHASING )
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;
675
if ( ulIndex >= ulNumTsiB4Timestamp )
677
/* + 4 for the timestamp TSI entries.*/
678
*f_pusTsiMemIndex = (UINT16)( pSharedInfo->ChipConfig.usMaxPhasingTssts + ulIndex + cOCT6100_TSI_MEM_FOR_TIMESTAMP );
680
else /* ulIndex < ulNumTsiB4Timestamp */
682
*f_pusTsiMemIndex = (UINT16)( pSharedInfo->ChipConfig.usMaxPhasingTssts + ulIndex );
685
else /* ulIndex < ulNumTsiB4Timestamp */
687
*f_pusTsiMemIndex = (UINT16)( ulIndex );
690
return cOCT6100_ERR_OK;
695
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
697
Function: Oct6100ApiReleaseTsiMemEntry
699
Description: Releases a TSI chariot memory entry specified.
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.
707
f_usTsiMemIndex Index reserved in the TSI chariot memory.
709
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
710
#if !SKIP_Oct6100ApiReleaseTsiMemEntry
711
UINT32 Oct6100ApiReleaseTsiMemEntry(
712
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
713
IN UINT16 f_usTsiMemIndex )
715
tPOCT6100_SHARED_INFO pSharedInfo;
720
/* Get local pointer to shared portion of instance. */
721
pSharedInfo = f_pApiInstance->pSharedInfo;
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;
727
ulIndex = f_usTsiMemIndex;
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;
733
mOCT6100_GET_TSI_MEMORY_ALLOC_PNT( pSharedInfo, pTsiMemAlloc )
735
ulResult = OctapiLlmAllocDealloc( pTsiMemAlloc, ulIndex );
736
if ( ulResult != cOCT6100_ERR_OK )
738
return cOCT6100_ERR_FATAL_93;
741
return cOCT6100_ERR_OK;
746
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
748
Function: Oct6100ApiReserveConversionMemEntry
750
Description: Reserves one of the conversion memory entry
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
759
f_pusConversionMemIndex Resulting index reserved in the conversion memory.
761
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
762
#if !SKIP_Oct6100ApiReserveConversionMemEntry
763
UINT32 Oct6100ApiReserveConversionMemEntry(
764
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
765
OUT PUINT16 f_pusConversionMemIndex )
767
tPOCT6100_SHARED_INFO pSharedInfo;
768
PVOID pConversionMemAlloc;
769
UINT32 ulConversionMemIndex;
772
/* Get local pointer to shared portion of instance. */
773
pSharedInfo = f_pApiInstance->pSharedInfo;
775
mOCT6100_GET_CONVERSION_MEMORY_ALLOC_PNT( pSharedInfo, pConversionMemAlloc )
777
ulResult = OctapiLlmAllocAlloc( pConversionMemAlloc, &ulConversionMemIndex );
778
if ( ulResult != cOCT6100_ERR_OK )
780
if ( ulResult == OCTAPI_LLM_NO_STRUCTURES_LEFT )
781
return cOCT6100_ERR_MEMORY_ALL_CONVERSION_MEM_ENTRY_RESERVED;
783
return cOCT6100_ERR_FATAL_B8;
786
*f_pusConversionMemIndex = (UINT16)( ulConversionMemIndex & 0xFFFF );
788
return cOCT6100_ERR_OK;
793
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
795
Function: Oct6100ApiReleaseConversionMemEntry
797
Description: Releases the conversion chariot memory entry specified.
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
806
f_usConversionMemIndex Index reserved in the conversion chariot memory.
808
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
809
#if !SKIP_Oct6100ApiReleaseConversionMemEntry
810
UINT32 Oct6100ApiReleaseConversionMemEntry(
811
IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
812
IN UINT16 f_usConversionMemIndex )
814
tPOCT6100_SHARED_INFO pSharedInfo;
815
PVOID pConversionMemAlloc;
818
/* Get local pointer to shared portion of instance. */
819
pSharedInfo = f_pApiInstance->pSharedInfo;
821
mOCT6100_GET_CONVERSION_MEMORY_ALLOC_PNT( pSharedInfo, pConversionMemAlloc )
823
ulResult = OctapiLlmAllocDealloc( pConversionMemAlloc, f_usConversionMemIndex );
824
if ( ulResult != cOCT6100_ERR_OK )
826
return cOCT6100_ERR_FATAL_B7;
829
return cOCT6100_ERR_OK;