Debian Codegraph @

xpp/oct612x/octdeviceapi/oct6100api/oct6100_api/oct6100_adpcm_chan.c

raw
1 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2
3 File: oct6100_adpcm_chan.c
4
5 Copyright (c) 2001-2007 Octasic Inc.
6
7 Description:
8
9 This file contains functions used to open and close ADPCM channels.
10
11 This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API is
12 free software; you can redistribute it and/or modify it under the terms of
13 the GNU General Public License as published by the Free Software Foundation;
14 either version 2 of the License, or (at your option) any later version.
15
16 The OCT6100 GPL API is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with the OCT6100 GPL API; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 $Octasic_Release: OCT612xAPI-01.00-PR49 $
26
27 $Octasic_Revision: 16 $
28
29 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
30
31
32 /***************************** INCLUDE FILES *******************************/
33
34 #include "octdef.h"
35
36 #include "oct6100api/oct6100_defines.h"
37 #include "oct6100api/oct6100_errors.h"
38 #include "oct6100api/oct6100_apiud.h"
39
40 #include "apilib/octapi_llman.h"
41
42 #include "oct6100api/oct6100_tlv_inst.h"
43 #include "oct6100api/oct6100_chip_open_inst.h"
44 #include "oct6100api/oct6100_chip_stats_inst.h"
45 #include "oct6100api/oct6100_interrupts_inst.h"
46 #include "oct6100api/oct6100_channel_inst.h"
47 #include "oct6100api/oct6100_remote_debug_inst.h"
48 #include "oct6100api/oct6100_debug_inst.h"
49 #include "oct6100api/oct6100_api_inst.h"
50 #include "oct6100api/oct6100_adpcm_chan_inst.h"
51
52 #include "oct6100api/oct6100_interrupts_pub.h"
53 #include "oct6100api/oct6100_chip_open_pub.h"
54 #include "oct6100api/oct6100_channel_pub.h"
55 #include "oct6100api/oct6100_adpcm_chan_pub.h"
56
57 #include "oct6100_chip_open_priv.h"
58 #include "oct6100_miscellaneous_priv.h"
59 #include "oct6100_memory_priv.h"
60 #include "oct6100_tsst_priv.h"
61 #include "oct6100_channel_priv.h"
62 #include "oct6100_adpcm_chan_priv.h"
63
64 /**************************** PUBLIC FUNCTIONS ****************************/
65
66 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
67
68 Function: Oct6100AdpcmChanOpen
69
70 Description: This function opens an ADPCM channel between two TDM timeslots.
71 This channel will perform ADPCM compression or decompression
72 depending on the channel mode.
73
74 -------------------------------------------------------------------------------
75 | Argument | Description
76 -------------------------------------------------------------------------------
77 f_pApiInstance Pointer to API instance. This memory is used to keep the
78 present state of the chip and all its resources.
79
80 f_pAdpcmChanOpen Pointer to ADPCM channel open structure.
81
82 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
83 #if !SKIP_Oct6100AdpcmChanOpenDef
84 UINT32 Oct6100AdpcmChanOpenDef(
85 tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen )
86 {
87 f_pAdpcmChanOpen->pulChanHndl = NULL;
88
89 f_pAdpcmChanOpen->ulInputTimeslot = cOCT6100_INVALID_TIMESLOT;
90 f_pAdpcmChanOpen->ulInputStream = cOCT6100_INVALID_STREAM;
91 f_pAdpcmChanOpen->ulInputNumTssts = 1;
92 f_pAdpcmChanOpen->ulInputPcmLaw = cOCT6100_PCM_U_LAW;
93
94 f_pAdpcmChanOpen->ulOutputTimeslot = cOCT6100_INVALID_TIMESLOT;
95 f_pAdpcmChanOpen->ulOutputStream = cOCT6100_INVALID_STREAM;
96 f_pAdpcmChanOpen->ulOutputPcmLaw = cOCT6100_PCM_U_LAW;
97 f_pAdpcmChanOpen->ulOutputNumTssts = 1;
98
99 f_pAdpcmChanOpen->ulChanMode = cOCT6100_ADPCM_ENCODING;
100 f_pAdpcmChanOpen->ulEncodingRate = cOCT6100_G726_32KBPS;
101 f_pAdpcmChanOpen->ulDecodingRate = cOCT6100_G726_32KBPS;
102
103 f_pAdpcmChanOpen->ulAdpcmNibblePosition = cOCT6100_ADPCM_IN_LOW_BITS;
104
105 return cOCT6100_ERR_OK;
106 }
107 #endif
108
109 #if !SKIP_Oct6100AdpcmChanOpen
110 UINT32 Oct6100AdpcmChanOpen(
111 tPOCT6100_INSTANCE_API f_pApiInstance,
112 tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen )
113 {
114 tOCT6100_SEIZE_SERIALIZE_OBJECT SeizeSerObj;
115 tOCT6100_RELEASE_SERIALIZE_OBJECT ReleaseSerObj;
116 UINT32 ulSerRes = cOCT6100_ERR_OK;
117 UINT32 ulFncRes = cOCT6100_ERR_OK;
118
119 /* Set the process context of the serialize structure.*/
120 SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
121 ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
122
123 /* Seize all list semaphores needed by this function. */
124 SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
125 SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
126 ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
127 if ( ulSerRes == cOCT6100_ERR_OK )
128 {
129 /* Call the serialized function. */
130 ulFncRes = Oct6100AdpcmChanOpenSer( f_pApiInstance, f_pAdpcmChanOpen );
131 }
132 else
133 {
134 return ulSerRes;
135 }
136
137 /* Release the seized semaphores. */
138 ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
139 ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
140
141 /* If an error occured then return the error code. */
142 if ( ulSerRes != cOCT6100_ERR_OK )
143 return ulSerRes;
144 if ( ulFncRes != cOCT6100_ERR_OK )
145 return ulFncRes;
146
147 return cOCT6100_ERR_OK;
148 }
149 #endif
150
151 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
152
153 Function: Oct6100AdpcmChanClose
154
155 Description: This function closes an opened ADPCM channel.
156
157 -------------------------------------------------------------------------------
158 | Argument | Description
159 -------------------------------------------------------------------------------
160 f_pApiInstance Pointer to API instance. This memory is used to keep the
161 present state of the chip and all its resources.
162
163 f_pAdpcmChanClose Pointer to ADPCM channel close structure.
164
165 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
166 #if !SKIP_Oct6100AdpcmChanCloseDef
167 UINT32 Oct6100AdpcmChanCloseDef(
168 tPOCT6100_ADPCM_CHAN_CLOSE f_pAdpcmChanClose )
169 {
170 f_pAdpcmChanClose->ulChanHndl = cOCT6100_INVALID_HANDLE;
171
172 return cOCT6100_ERR_OK;
173 }
174 #endif
175
176 #if !SKIP_Oct6100AdpcmChanClose
177 UINT32 Oct6100AdpcmChanClose(
178 tPOCT6100_INSTANCE_API f_pApiInstance,
179 tPOCT6100_ADPCM_CHAN_CLOSE f_pAdpcmChanClose )
180 {
181 tOCT6100_SEIZE_SERIALIZE_OBJECT SeizeSerObj;
182 tOCT6100_RELEASE_SERIALIZE_OBJECT ReleaseSerObj;
183 UINT32 ulSerRes = cOCT6100_ERR_OK;
184 UINT32 ulFncRes = cOCT6100_ERR_OK;
185
186 /* Set the process context of the serialize structure.*/
187 SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
188 ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;
189
190 /* Seize all list semaphores needed by this function. */
191 SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
192 SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
193 ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
194 if ( ulSerRes == cOCT6100_ERR_OK )
195 {
196 /* Call the serialized function. */
197 ulFncRes = Oct6100AdpcmChanCloseSer( f_pApiInstance, f_pAdpcmChanClose );
198 }
199 else
200 {
201 return ulSerRes;
202 }
203
204 /* Release the seized semaphores. */
205 ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
206 ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );
207
208 /* If an error occured then return the error code. */
209 if ( ulSerRes != cOCT6100_ERR_OK )
210 return ulSerRes;
211 if ( ulFncRes != cOCT6100_ERR_OK )
212 return ulFncRes;
213
214 return cOCT6100_ERR_OK;
215 }
216 #endif
217
218
219 /**************************** PRIVATE FUNCTIONS ****************************/
220
221 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
222
223 Function: Oct6100ApiGetAdpcmChanSwSizes
224
225 Description: Gets the sizes of all portions of the API instance pertinent
226 to the management of the ADPCM memory.
227
228 -------------------------------------------------------------------------------
229 | Argument | Description
230 -------------------------------------------------------------------------------
231 f_pOpenChip Pointer to chip configuration struct.
232 f_pInstSizes Pointer to struct containing instance sizes.
233
234 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
235 #if !SKIP_Oct6100ApiGetAdpcmChanSwSizes
236 UINT32 Oct6100ApiGetAdpcmChanSwSizes(
237 IN tPOCT6100_CHIP_OPEN f_pOpenChip,
238 OUT tPOCT6100_API_INSTANCE_SIZES f_pInstSizes )
239 {
240 UINT32 ulTempVar;
241 UINT32 ulResult;
242
243 /* Determine the amount of memory required for the API ADPCM channel list.*/
244 f_pInstSizes->ulAdpcmChannelList = f_pOpenChip->ulMaxAdpcmChannels * sizeof( tOCT6100_API_ADPCM_CHAN );
245
246 if ( f_pOpenChip->ulMaxAdpcmChannels > 0 )
247 {
248 /* Calculate memory needed for ADPCM memory allocation */
249 ulResult = OctapiLlmAllocGetSize( f_pOpenChip->ulMaxAdpcmChannels, &f_pInstSizes->ulAdpcmChannelAlloc );
250 if ( ulResult != cOCT6100_ERR_OK )
251 return cOCT6100_ERR_FATAL_48;
252 }
253 else
254 {
255 f_pInstSizes->ulAdpcmChannelAlloc = 0;
256 }
257
258 mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulAdpcmChannelList, ulTempVar )
259 mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulAdpcmChannelAlloc, ulTempVar )
260
261 return cOCT6100_ERR_OK;
262 }
263 #endif
264
265
266 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
267
268 Function: Oct6100ApiAdpcmChanSwInit
269
270 Description: Initializes all elements of the instance structure associated
271 to the ADPCM memory.
272
273 -------------------------------------------------------------------------------
274 | Argument | Description
275 -------------------------------------------------------------------------------
276 f_pApiInstance Pointer to API instance. This memory is used to keep
277 the present state of the chip and all its resources.
278
279 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
280 #if !SKIP_Oct6100ApiAdpcmChanSwInit
281 UINT32 Oct6100ApiAdpcmChanSwInit(
282 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance )
283 {
284 tPOCT6100_API_ADPCM_CHAN pChannelsTsiList;
285 tPOCT6100_SHARED_INFO pSharedInfo;
286 UINT32 ulMaxAdpcmChannels;
287 PVOID pAdpcmChannelsAlloc;
288 UINT32 ulResult;
289
290 /* Get local pointer to shared portion of instance. */
291 pSharedInfo = f_pApiInstance->pSharedInfo;
292
293 /* Initialize the ADPCM channel API list.*/
294 ulMaxAdpcmChannels = pSharedInfo->ChipConfig.usMaxAdpcmChannels;
295
296 /* Set all entries in the ADPCM channel list to unused. */
297 mOCT6100_GET_ADPCM_CHAN_LIST_PNT( pSharedInfo, pChannelsTsiList )
298
299 /* Clear the memory */
300 Oct6100UserMemSet( pChannelsTsiList, 0x00, sizeof(tOCT6100_API_ADPCM_CHAN) * ulMaxAdpcmChannels );
301
302 /* Initialize the ADPCM channel allocation structures to "all free". */
303 if ( ulMaxAdpcmChannels > 0 )
304 {
305 mOCT6100_GET_ADPCM_CHAN_ALLOC_PNT( pSharedInfo, pAdpcmChannelsAlloc )
306
307 ulResult = OctapiLlmAllocInit( &pAdpcmChannelsAlloc, ulMaxAdpcmChannels );
308 if ( ulResult != cOCT6100_ERR_OK )
309 return cOCT6100_ERR_FATAL_BD;
310 }
311
312 return cOCT6100_ERR_OK;
313 }
314 #endif
315
316
317 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
318
319 Function: Oct6100AdpcmChanOpenSer
320
321 Description: Opens an ADPCM channel.
322
323 -------------------------------------------------------------------------------
324 | Argument | Description
325 -------------------------------------------------------------------------------
326 f_pApiInstance Pointer to API instance. This memory is used to keep the
327 present state of the chip and all its resources.
328
329 f_pAdpcmChanOpen Pointer to an ADPCM channel open structure
330
331 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
332 #if !SKIP_Oct6100AdpcmChanOpenSer
333 UINT32 Oct6100AdpcmChanOpenSer(
334 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
335 IN OUT tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen )
336 {
337 UINT16 usAdpcmChanIndex;
338 UINT16 usTsiMemIndex;
339 UINT16 usAdpcmMemIndex;
340 UINT16 usInputTsstIndex;
341 UINT16 usOutputTsstIndex;
342 UINT32 ulResult;
343
344 /* Check the user's configuration of the ADPCM channel open structure for errors. */
345 ulResult = Oct6100ApiCheckAdpcmChanParams( f_pApiInstance, f_pAdpcmChanOpen );
346 if ( ulResult != cOCT6100_ERR_OK )
347 return ulResult;
348
349 /* Reserve all resources needed by the ADPCM channel. */
350 ulResult = Oct6100ApiReserveAdpcmChanResources( f_pApiInstance, f_pAdpcmChanOpen, &usAdpcmChanIndex, &usAdpcmMemIndex, &usTsiMemIndex, &usInputTsstIndex, &usOutputTsstIndex );
351 if ( ulResult != cOCT6100_ERR_OK )
352 return ulResult;
353
354 /* Write all necessary structures to activate the ADPCM channel. */
355 ulResult = Oct6100ApiWriteAdpcmChanStructs( f_pApiInstance, f_pAdpcmChanOpen, usAdpcmMemIndex, usTsiMemIndex, usInputTsstIndex, usOutputTsstIndex );
356 if ( ulResult != cOCT6100_ERR_OK )
357 return ulResult;
358
359 /* Update the ADPCM channel entry in the API list. */
360 ulResult = Oct6100ApiUpdateAdpcmChanEntry( f_pApiInstance, f_pAdpcmChanOpen, usAdpcmChanIndex, usAdpcmMemIndex, usTsiMemIndex, usInputTsstIndex, usOutputTsstIndex );
361 if ( ulResult != cOCT6100_ERR_OK )
362 return ulResult;
363
364 return cOCT6100_ERR_OK;
365 }
366 #endif
367
368
369 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
370
371 Function: Oct6100ApiCheckAdpcmChanParams
372
373 Description: Checks the user's ADPCM channel open configuration for errors.
374
375 -------------------------------------------------------------------------------
376 | Argument | Description
377 -------------------------------------------------------------------------------
378 f_pApiInstance Pointer to API instance. This memory is used to keep the
379 present state of the chip and all its resources.
380
381 f_pAdpcmChanOpen Pointer to ADPCM channel open configuration structure.
382
383 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
384 #if !SKIP_Oct6100ApiCheckAdpcmChanParams
385 UINT32 Oct6100ApiCheckAdpcmChanParams(
386 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
387 IN tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen )
388 {
389 UINT32 ulResult;
390
391 /* Check for errors. */
392 if ( f_pApiInstance->pSharedInfo->ChipConfig.usMaxAdpcmChannels == 0 )
393 return cOCT6100_ERR_ADPCM_CHAN_DISABLED;
394
395 if ( f_pAdpcmChanOpen->pulChanHndl == NULL )
396 return cOCT6100_ERR_ADPCM_CHAN_INVALID_HANDLE;
397
398 /* Check the input TDM streams, timeslots component for errors. */
399 if ( f_pAdpcmChanOpen->ulInputNumTssts != 1 &&
400 f_pAdpcmChanOpen->ulInputNumTssts != 2 )
401 return cOCT6100_ERR_ADPCM_CHAN_INPUT_NUM_TSSTS;
402
403 ulResult = Oct6100ApiValidateTsst( f_pApiInstance,
404 f_pAdpcmChanOpen->ulInputNumTssts,
405 f_pAdpcmChanOpen->ulInputTimeslot,
406 f_pAdpcmChanOpen->ulInputStream,
407 cOCT6100_INPUT_TSST );
408 if ( ulResult != cOCT6100_ERR_OK )
409 {
410 if ( ulResult == cOCT6100_ERR_TSST_TIMESLOT )
411 {
412 return cOCT6100_ERR_ADPCM_CHAN_INPUT_TIMESLOT;
413 }
414 else if ( ulResult == cOCT6100_ERR_TSST_STREAM )
415 {
416 return cOCT6100_ERR_ADPCM_CHAN_INPUT_STREAM;
417 }
418 else
419 {
420 return ulResult;
421 }
422 }
423
424 if( f_pAdpcmChanOpen->ulInputPcmLaw != cOCT6100_PCM_U_LAW &&
425 f_pAdpcmChanOpen->ulInputPcmLaw != cOCT6100_PCM_A_LAW )
426 return cOCT6100_ERR_ADPCM_CHAN_INPUT_PCM_LAW;
427
428 /* Check the output TDM streams, timeslots component for errors. */
429 if ( f_pAdpcmChanOpen->ulOutputNumTssts != 1 &&
430 f_pAdpcmChanOpen->ulOutputNumTssts != 2 )
431 return cOCT6100_ERR_ADPCM_CHAN_OUTPUT_NUM_TSSTS;
432
433 ulResult = Oct6100ApiValidateTsst( f_pApiInstance,
434 f_pAdpcmChanOpen->ulOutputNumTssts,
435 f_pAdpcmChanOpen->ulOutputTimeslot,
436 f_pAdpcmChanOpen->ulOutputStream,
437 cOCT6100_OUTPUT_TSST );
438 if ( ulResult != cOCT6100_ERR_OK )
439 {
440 if ( ulResult == cOCT6100_ERR_TSST_TIMESLOT )
441 {
442 return cOCT6100_ERR_ADPCM_CHAN_OUTPUT_TIMESLOT;
443 }
444 else if ( ulResult == cOCT6100_ERR_TSST_STREAM )
445 {
446 return cOCT6100_ERR_ADPCM_CHAN_OUTPUT_STREAM;
447 }
448 else
449 {
450 return ulResult;
451 }
452 }
453 if( f_pAdpcmChanOpen->ulOutputPcmLaw != cOCT6100_PCM_U_LAW &&
454 f_pAdpcmChanOpen->ulOutputPcmLaw != cOCT6100_PCM_A_LAW )
455 return cOCT6100_ERR_ADPCM_CHAN_OUTPUT_PCM_LAW;
456
457 /* Now, check the channel mode. */
458 if ( f_pAdpcmChanOpen->ulChanMode != cOCT6100_ADPCM_ENCODING &&
459 f_pAdpcmChanOpen->ulChanMode != cOCT6100_ADPCM_DECODING )
460 return cOCT6100_ERR_ADPCM_CHAN_MODE;
461
462 if ( f_pAdpcmChanOpen->ulChanMode == cOCT6100_ADPCM_ENCODING )
463 {
464 /* Check the encoding rate. */
465 if ( ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G711_64KBPS ) &&
466 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G726_40KBPS ) &&
467 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G726_32KBPS ) &&
468 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G726_24KBPS ) &&
469 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G726_16KBPS ) &&
470 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_40KBPS_4_1 ) &&
471 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_40KBPS_3_2 ) &&
472 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_40KBPS_2_3 ) &&
473 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_32KBPS_4_0 ) &&
474 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_32KBPS_3_1 ) &&
475 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_32KBPS_2_2 ) &&
476 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_24KBPS_3_0 ) &&
477 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_24KBPS_2_1 ) &&
478 ( f_pAdpcmChanOpen->ulEncodingRate != cOCT6100_G727_16KBPS_2_0 ) )
479 return cOCT6100_ERR_ADPCM_CHAN_ENCODING_RATE;
480 }
481 else /* if ( f_pAdpcmChanOpen->ulChanMode != cOCT6100_ADPCM_DECODING ) */
482 {
483 /* Check the decoding rate. */
484 if ( f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G711_64KBPS &&
485 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G726_40KBPS &&
486 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G726_32KBPS &&
487 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G726_24KBPS &&
488 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G726_16KBPS &&
489 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G726_ENCODED &&
490 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G711_G726_ENCODED &&
491 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G727_2C_ENCODED &&
492 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G727_3C_ENCODED &&
493 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G727_4C_ENCODED &&
494 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G711_G727_2C_ENCODED &&
495 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G711_G727_3C_ENCODED &&
496 f_pAdpcmChanOpen->ulDecodingRate != cOCT6100_G711_G727_4C_ENCODED )
497 return cOCT6100_ERR_ADPCM_CHAN_DECODING_RATE;
498
499 /* Make sure that two timeslots are allocated if PCM-ECHO encoded is selected. */
500 if ( (f_pAdpcmChanOpen->ulDecodingRate == cOCT6100_G711_G726_ENCODED ||
501 f_pAdpcmChanOpen->ulDecodingRate == cOCT6100_G711_G727_2C_ENCODED ||
502 f_pAdpcmChanOpen->ulDecodingRate == cOCT6100_G711_G727_3C_ENCODED ||
503 f_pAdpcmChanOpen->ulDecodingRate == cOCT6100_G711_G727_4C_ENCODED ) &&
504 f_pAdpcmChanOpen->ulInputNumTssts != 2 )
505 return cOCT6100_ERR_ADPCM_CHAN_INCOMPATIBLE_NUM_TSSTS;
506 }
507
508 /* Check the nibble position. */
509 if ( f_pAdpcmChanOpen->ulAdpcmNibblePosition != cOCT6100_ADPCM_IN_LOW_BITS &&
510 f_pAdpcmChanOpen->ulAdpcmNibblePosition != cOCT6100_ADPCM_IN_HIGH_BITS )
511 return cOCT6100_ERR_ADPCM_CHAN_ADPCM_NIBBLE_POSITION;
512
513 return cOCT6100_ERR_OK;
514 }
515 #endif
516
517
518 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
519
520 Function: Oct6100ApiReserveAdpcmChanResources
521
522 Description: Reserves all resources needed for the new ADPCM channel.
523
524 -------------------------------------------------------------------------------
525 | Argument | Description
526 -------------------------------------------------------------------------------
527 f_pApiInstance Pointer to API instance. This memory is used to keep the
528 present state of the chip and all its resources.
529
530 f_pAdpcmChanOpen Pointer to ADPCM channel configuration structure.
531 f_pusAdpcmChanIndex Allocated entry in ADPCM channel list.
532 f_pusAdpcmMemIndex Allocated entry in the ADPCM control memory.
533 f_pusTsiMemIndex Allocated entry in the TSI chariot memory.
534 f_pusInputTsstIndex TSST memory index of the input samples.
535 f_pusOutputTsstIndex TSST memory index of the output samples.
536
537 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
538 #if !SKIP_Oct6100ApiReserveAdpcmChanResources
539 UINT32 Oct6100ApiReserveAdpcmChanResources(
540 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
541 IN tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen,
542 OUT PUINT16 f_pusAdpcmChanIndex,
543 OUT PUINT16 f_pusAdpcmMemIndex,
544 OUT PUINT16 f_pusTsiMemIndex,
545 OUT PUINT16 f_pusInputTsstIndex,
546 OUT PUINT16 f_pusOutputTsstIndex )
547 {
548 tPOCT6100_SHARED_INFO pSharedInfo;
549 UINT32 ulResult;
550 UINT32 ulTempVar;
551 BOOL fAdpcmChanEntry = FALSE;
552 BOOL fAdpcmMemEntry = FALSE;
553 BOOL fTsiMemEntry = FALSE;
554 BOOL fInputTsst = FALSE;
555
556 /* Obtain local pointer to shared portion of instance. */
557 pSharedInfo = f_pApiInstance->pSharedInfo;
558
559 /* Reserve an entry in the ADPCM channel list. */
560 ulResult = Oct6100ApiReserveAdpcmChanEntry( f_pApiInstance, f_pusAdpcmChanIndex );
561 if ( ulResult == cOCT6100_ERR_OK )
562 {
563 fAdpcmChanEntry = TRUE;
564
565 /* Find a TSI memory entry.*/
566 ulResult = Oct6100ApiReserveTsiMemEntry( f_pApiInstance, f_pusTsiMemIndex );
567 if ( ulResult == cOCT6100_ERR_OK )
568 {
569 fTsiMemEntry = TRUE;
570
571 /* Find a conversion memory entry. */
572 ulResult = Oct6100ApiReserveConversionMemEntry( f_pApiInstance, f_pusAdpcmMemIndex );
573 if ( ulResult == cOCT6100_ERR_OK )
574 {
575 fAdpcmMemEntry = TRUE;
576
577 /* Reserve the input TSST entry. */
578 ulResult = Oct6100ApiReserveTsst( f_pApiInstance,
579 f_pAdpcmChanOpen->ulInputTimeslot,
580 f_pAdpcmChanOpen->ulInputStream,
581 f_pAdpcmChanOpen->ulInputNumTssts,
582 cOCT6100_INPUT_TSST,
583 f_pusInputTsstIndex,
584 NULL );
585 if ( ulResult == cOCT6100_ERR_OK )
586 {
587 fInputTsst = TRUE;
588
589 /* Reserve the output TSST entry. */
590 ulResult = Oct6100ApiReserveTsst( f_pApiInstance,
591 f_pAdpcmChanOpen->ulOutputTimeslot,
592 f_pAdpcmChanOpen->ulOutputStream,
593 f_pAdpcmChanOpen->ulOutputNumTssts,
594 cOCT6100_OUTPUT_TSST,
595 f_pusOutputTsstIndex,
596 NULL );
597 }
598 }
599 }
600 else
601 {
602 /* Return an error other than a fatal error. */
603 ulResult = cOCT6100_ERR_ADPCM_CHAN_NO_MORE_TSI_AVAILABLE;
604 }
605 }
606
607 if ( ulResult != cOCT6100_ERR_OK )
608 {
609 if( fAdpcmChanEntry == TRUE )
610 {
611 ulTempVar = Oct6100ApiReleaseAdpcmChanEntry( f_pApiInstance, *f_pusAdpcmChanIndex );
612 if ( ulTempVar != cOCT6100_ERR_OK )
613 return ulTempVar;
614 }
615
616 if( fTsiMemEntry == TRUE )
617 {
618 ulTempVar = Oct6100ApiReleaseTsiMemEntry( f_pApiInstance, *f_pusTsiMemIndex );
619 if ( ulTempVar != cOCT6100_ERR_OK )
620 return ulTempVar;
621 }
622
623 if( fAdpcmMemEntry == TRUE )
624 {
625 ulTempVar = Oct6100ApiReleaseConversionMemEntry( f_pApiInstance, *f_pusAdpcmMemIndex );
626 if ( ulTempVar != cOCT6100_ERR_OK )
627 return ulTempVar;
628 }
629
630 if( fInputTsst == TRUE )
631 {
632 ulTempVar = Oct6100ApiReleaseTsst( f_pApiInstance,
633 f_pAdpcmChanOpen->ulInputTimeslot,
634 f_pAdpcmChanOpen->ulInputStream,
635 f_pAdpcmChanOpen->ulInputNumTssts,
636 cOCT6100_INPUT_TSST,
637 cOCT6100_INVALID_INDEX );
638 if ( ulTempVar != cOCT6100_ERR_OK )
639 return ulTempVar;
640 }
641
642 return ulResult;
643 }
644
645 return cOCT6100_ERR_OK;
646 }
647 #endif
648
649
650 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
651
652 Function: Oct6100ApiWriteAdpcmChanStructs
653
654 Description: Performs all the required structure writes to configure the
655 new ADPCM channel.
656
657 -------------------------------------------------------------------------------
658 | Argument | Description
659 -------------------------------------------------------------------------------
660 f_pApiInstance Pointer to API instance. This memory is used to keep the
661 present state of the chip and all its resources.
662
663 f_pAdpcmChanOpen Pointer to ADPCM channel configuration structure.
664 f_pusAdpcmChanIndex Allocated entry in ADPCM channel list.
665 f_pusAdpcmMemIndex Allocated entry in the ADPCM control memory.
666 f_pusTsiMemIndex Allocated entry in the TSI chariot memory.
667 f_pusInputTsstIndex TSST memory index of the input samples.
668 f_pusOutputTsstIndex TSST memory index of the output samples.
669
670 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
671 #if !SKIP_Oct6100ApiWriteAdpcmChanStructs
672 UINT32 Oct6100ApiWriteAdpcmChanStructs(
673 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
674 IN tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen,
675 IN UINT16 f_usAdpcmMemIndex,
676 IN UINT16 f_usTsiMemIndex,
677 IN UINT16 f_usInputTsstIndex,
678 IN UINT16 f_usOutputTsstIndex )
679 {
680 tPOCT6100_SHARED_INFO pSharedInfo;
681 tOCT6100_WRITE_PARAMS WriteParams;
682 UINT32 ulResult;
683 UINT32 ulCompType = 0;
684
685 /* Obtain local pointer to shared portion of instance. */
686 pSharedInfo = f_pApiInstance->pSharedInfo;
687
688 WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
689
690 WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
691
692 /*------------------------------------------------------------------------------*/
693 /* Configure the TSST control memory. */
694
695 /* Set the input TSST control entry. */
696 ulResult = Oct6100ApiWriteInputTsstControlMemory( f_pApiInstance,
697 f_usInputTsstIndex,
698 f_usTsiMemIndex,
699 f_pAdpcmChanOpen->ulInputPcmLaw );
700 if ( ulResult != cOCT6100_ERR_OK )
701 return ulResult;
702
703 /* Set the output TSST control entry. */
704 ulResult = Oct6100ApiWriteOutputTsstControlMemory( f_pApiInstance,
705 f_usOutputTsstIndex,
706 f_pAdpcmChanOpen->ulAdpcmNibblePosition,
707 f_pAdpcmChanOpen->ulOutputNumTssts,
708 f_usTsiMemIndex );
709 if ( ulResult != cOCT6100_ERR_OK )
710 return ulResult;
711
712 /*------------------------------------------------------------------------------*/
713
714
715 /*------------------------------------------------------------------------------*/
716 /* Configure the ADPCM memory. */
717
718 if ( f_pAdpcmChanOpen->ulChanMode == cOCT6100_ADPCM_ENCODING )
719 {
720 switch( f_pAdpcmChanOpen->ulEncodingRate )
721 {
722 case cOCT6100_G711_64KBPS:
723
724 if ( f_pAdpcmChanOpen->ulOutputPcmLaw == cOCT6100_PCM_U_LAW )
725 ulCompType = 0x4;
726 else /* if ( f_pAdpcmChanOpen->ulOutputPcmLaw != cOCT6100_PCM_U_LAW ) */
727 ulCompType = 0x5;
728 break;
729 case cOCT6100_G726_40KBPS: ulCompType = 0x3; break;
730 case cOCT6100_G726_32KBPS: ulCompType = 0x2; break;
731 case cOCT6100_G726_24KBPS: ulCompType = 0x1; break;
732 case cOCT6100_G726_16KBPS: ulCompType = 0x0; break;
733 case cOCT6100_G727_40KBPS_4_1: ulCompType = 0xD; break;
734 case cOCT6100_G727_40KBPS_3_2: ulCompType = 0xA; break;
735 case cOCT6100_G727_40KBPS_2_3: ulCompType = 0x6; break;
736 case cOCT6100_G727_32KBPS_4_0: ulCompType = 0xE; break;
737 case cOCT6100_G727_32KBPS_3_1: ulCompType = 0xB; break;
738 case cOCT6100_G727_32KBPS_2_2: ulCompType = 0x7; break;
739 case cOCT6100_G727_24KBPS_3_0: ulCompType = 0xC; break;
740 case cOCT6100_G727_24KBPS_2_1: ulCompType = 0x8; break;
741 case cOCT6100_G727_16KBPS_2_0: ulCompType = 0x9; break;
742 }
743
744 ulResult = Oct6100ApiWriteEncoderMemory( f_pApiInstance,
745 f_usAdpcmMemIndex,
746 ulCompType,
747 f_usTsiMemIndex,
748 FALSE,
749 f_pAdpcmChanOpen->ulAdpcmNibblePosition,
750 cOCT6100_INVALID_INDEX,
751 cOCT6100_INVALID_VALUE,
752 cOCT6100_INVALID_VALUE );
753 if ( ulResult != cOCT6100_ERR_OK )
754 return ulResult;
755 }
756 else /* if ( f_pAdpcmChanOpen->ulChanMode != cOCT6100_ADPCM_DECODING ) */
757 {
758 switch( f_pAdpcmChanOpen->ulDecodingRate )
759 {
760 case cOCT6100_G711_64KBPS: ulCompType = 0x8; break;
761 case cOCT6100_G726_40KBPS: ulCompType = 0x3; break;
762 case cOCT6100_G726_32KBPS: ulCompType = 0x2; break;
763 case cOCT6100_G726_24KBPS: ulCompType = 0x1; break;
764 case cOCT6100_G726_16KBPS: ulCompType = 0x0; break;
765 case cOCT6100_G727_2C_ENCODED: ulCompType = 0x4; break;
766 case cOCT6100_G727_3C_ENCODED: ulCompType = 0x5; break;
767 case cOCT6100_G727_4C_ENCODED: ulCompType = 0x6; break;
768 case cOCT6100_G726_ENCODED: ulCompType = 0x9; break;
769 case cOCT6100_G711_G726_ENCODED: ulCompType = 0xA; break;
770 case cOCT6100_G711_G727_2C_ENCODED: ulCompType = 0xC; break;
771 case cOCT6100_G711_G727_3C_ENCODED: ulCompType = 0xD; break;
772 case cOCT6100_G711_G727_4C_ENCODED: ulCompType = 0xE; break;
773 }
774
775 ulResult = Oct6100ApiWriteDecoderMemory( f_pApiInstance,
776 f_usAdpcmMemIndex,
777 ulCompType,
778 f_usTsiMemIndex,
779 f_pAdpcmChanOpen->ulOutputPcmLaw,
780 f_pAdpcmChanOpen->ulAdpcmNibblePosition );
781 if ( ulResult != cOCT6100_ERR_OK )
782 return ulResult;
783 }
784
785 /*------------------------------------------------------------------------------*/
786
787 return cOCT6100_ERR_OK;
788 }
789 #endif
790
791
792 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
793
794 Function: Oct6100ApiUpdateAdpcmChanEntry
795
796 Description: Updates the new ADPCM channel in the ADPCM channel list.
797
798 -------------------------------------------------------------------------------
799 | Argument | Description
800 -------------------------------------------------------------------------------
801 f_pApiInstance Pointer to API instance. This memory is used to keep
802 the present state of the chip and all its resources.
803
804 f_pAdpcmChanOpen Pointer to ADPCM channel open configuration structure.
805 f_usAdpcmChanIndex Allocated entry in the ADPCM channel list.
806 f_usAdpcmMemIndex Allocated entry in ADPCM memory.
807 f_usTsiMemIndex Allocated entry in TSI chariot memory.
808 f_usInputTsstIndex TSST control memory index of the input TSST.
809 f_usOutputTsstIndex TSST control memory index of the output TSST.
810
811 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
812 #if !SKIP_Oct6100ApiUpdateAdpcmChanEntry
813 UINT32 Oct6100ApiUpdateAdpcmChanEntry(
814 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
815 IN OUT tPOCT6100_ADPCM_CHAN_OPEN f_pAdpcmChanOpen,
816 IN UINT16 f_usAdpcmChanIndex,
817 IN UINT16 f_usAdpcmMemIndex,
818 IN UINT16 f_usTsiMemIndex,
819 IN UINT16 f_usInputTsstIndex,
820 IN UINT16 f_usOutputTsstIndex )
821 {
822 tPOCT6100_API_ADPCM_CHAN pAdpcmChanEntry;
823
824 /*------------------------------------------------------------------------------*/
825 /* Obtain a pointer to the new ADPCM channel's list entry. */
826
827 mOCT6100_GET_ADPCM_CHAN_ENTRY_PNT( f_pApiInstance->pSharedInfo, pAdpcmChanEntry, f_usAdpcmChanIndex )
828
829 /* Copy the buffer's configuration and allocated resources. */
830 pAdpcmChanEntry->usInputTimeslot = (UINT16)( f_pAdpcmChanOpen->ulInputTimeslot & 0xFFFF );
831 pAdpcmChanEntry->usInputStream = (UINT16)( f_pAdpcmChanOpen->ulInputStream & 0xFFFF );
832 pAdpcmChanEntry->byInputNumTssts = (UINT8)( f_pAdpcmChanOpen->ulInputNumTssts & 0xFF );
833 pAdpcmChanEntry->byInputPcmLaw = (UINT8)( f_pAdpcmChanOpen->ulInputPcmLaw & 0xFF );
834
835 pAdpcmChanEntry->usOutputTimeslot = (UINT16)( f_pAdpcmChanOpen->ulOutputTimeslot & 0xFFFF );
836 pAdpcmChanEntry->usOutputStream = (UINT16)( f_pAdpcmChanOpen->ulOutputStream & 0xFFFF );
837 pAdpcmChanEntry->byOutputNumTssts = (UINT8)( f_pAdpcmChanOpen->ulOutputNumTssts & 0xFF );
838 pAdpcmChanEntry->byOutputPcmLaw = (UINT8)( f_pAdpcmChanOpen->ulOutputPcmLaw & 0xFF );
839
840 /* Store hardware related information. */
841 pAdpcmChanEntry->usTsiMemIndex = f_usTsiMemIndex;
842 pAdpcmChanEntry->usAdpcmMemIndex = f_usAdpcmMemIndex;
843 pAdpcmChanEntry->usInputTsstIndex = f_usInputTsstIndex;
844 pAdpcmChanEntry->usOutputTsstIndex = f_usOutputTsstIndex;
845
846 /* Form handle returned to user. */
847 *f_pAdpcmChanOpen->pulChanHndl = cOCT6100_HNDL_TAG_ADPCM_CHANNEL | (pAdpcmChanEntry->byEntryOpenCnt << cOCT6100_ENTRY_OPEN_CNT_SHIFT) | f_usAdpcmChanIndex;
848
849 /* Finally, mark the ADPCM channel as opened. */
850 pAdpcmChanEntry->fReserved = TRUE;
851
852 /* Increment the number of ADPCM channel opened. */
853 f_pApiInstance->pSharedInfo->ChipStats.usNumberAdpcmChans++;
854
855 /*------------------------------------------------------------------------------*/
856
857 return cOCT6100_ERR_OK;
858 }
859 #endif
860
861
862 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
863
864 Function: Oct6100AdpcmChanCloseSer
865
866 Description: Closes an ADPCM channel.
867
868 -------------------------------------------------------------------------------
869 | Argument | Description
870 -------------------------------------------------------------------------------
871 f_pApiInstance Pointer to API instance. This memory is used to keep the
872 present state of the chip and all its resources.
873
874 f_pAdpcmChanClose Pointer to ADPCM channel close structure.
875
876 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
877 #if !SKIP_Oct6100AdpcmChanCloseSer
878 UINT32 Oct6100AdpcmChanCloseSer(
879 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
880 IN OUT tPOCT6100_ADPCM_CHAN_CLOSE f_pAdpcmChanClose )
881 {
882 UINT16 usAdpcmChanIndex;
883 UINT16 usTsiMemIndex;
884 UINT16 usAdpcmMemIndex;
885 UINT16 usInputTsstIndex;
886 UINT16 usOutputTsstIndex;
887 UINT32 ulResult;
888
889 /* Verify that all the parameters given match the state of the API. */
890 ulResult = Oct6100ApiAssertAdpcmChanParams( f_pApiInstance, f_pAdpcmChanClose, &usAdpcmChanIndex, &usAdpcmMemIndex, &usTsiMemIndex, &usInputTsstIndex, &usOutputTsstIndex );
891 if ( ulResult != cOCT6100_ERR_OK )
892 return ulResult;
893
894 /* Release all resources associated to the ADPCM channel. */
895 ulResult = Oct6100ApiInvalidateAdpcmChanStructs( f_pApiInstance, usAdpcmMemIndex, usInputTsstIndex, usOutputTsstIndex );
896 if ( ulResult != cOCT6100_ERR_OK )
897 return ulResult;
898
899 /* Release all resources associated to the ADPCM channel. */
900 ulResult = Oct6100ApiReleaseAdpcmChanResources( f_pApiInstance, usAdpcmChanIndex, usAdpcmMemIndex, usTsiMemIndex );
901 if ( ulResult != cOCT6100_ERR_OK )
902 return ulResult;
903
904 /* Invalidate the handle. */
905 f_pAdpcmChanClose->ulChanHndl = cOCT6100_INVALID_HANDLE;
906
907 return cOCT6100_ERR_OK;
908 }
909 #endif
910
911
912 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
913
914 Function: Oct6100ApiAssertAdpcmChanParams
915
916 Description: Validate the handle given by the user and verify the state of
917 the ADPCM channel about to be closed.
918 Also return all required information to deactivate the channel.
919
920 -------------------------------------------------------------------------------
921 | Argument | Description
922 -------------------------------------------------------------------------------
923 f_pApiInstance Pointer to API instance. This memory is used to keep the
924 present state of the chip and all its resources.
925 f_pAdpcmChanClose Pointer to ADPCM channel close structure.
926 f_pusAdpcmChanIndex Index of the ADPCM channel structure in the API list.
927 f_pusAdpcmMemIndex Index of the ADPCM memory structure in the API list.
928 f_pusTsiMemIndex Index of the TSI chariot memory used for this channel.
929 f_pusInputTsstIndex Index of the input entry in the TSST control memory.
930 f_pusOutputTsstIndex Index of the output entry in the TSST control memory.
931
932 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
933 #if !SKIP_Oct6100ApiAssertAdpcmChanParams
934 UINT32 Oct6100ApiAssertAdpcmChanParams(
935 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
936 IN tPOCT6100_ADPCM_CHAN_CLOSE f_pAdpcmChanClose,
937 OUT PUINT16 f_pusAdpcmChanIndex,
938 OUT PUINT16 f_pusAdpcmMemIndex,
939 OUT PUINT16 f_pusTsiMemIndex,
940 OUT PUINT16 f_pusInputTsstIndex,
941 OUT PUINT16 f_pusOutputTsstIndex )
942 {
943 tPOCT6100_SHARED_INFO pSharedInfo;
944 tPOCT6100_API_ADPCM_CHAN pAdpcmChanEntry;
945 UINT32 ulEntryOpenCnt;
946
947 /* Get local pointer(s). */
948 pSharedInfo = f_pApiInstance->pSharedInfo;
949
950 /* Check the provided handle. */
951 if ( (f_pAdpcmChanClose->ulChanHndl & cOCT6100_HNDL_TAG_MASK) != cOCT6100_HNDL_TAG_ADPCM_CHANNEL )
952 return cOCT6100_ERR_ADPCM_CHAN_INVALID_HANDLE;
953
954 *f_pusAdpcmChanIndex = (UINT16)( f_pAdpcmChanClose->ulChanHndl & cOCT6100_HNDL_INDEX_MASK );
955
956 if ( *f_pusAdpcmChanIndex >= pSharedInfo->ChipConfig.usMaxAdpcmChannels )
957 return cOCT6100_ERR_ADPCM_CHAN_INVALID_HANDLE;
958
959 /*------------------------------------------------------------------------------*/
960 /* Get a pointer to the channel's list entry. */
961
962 mOCT6100_GET_ADPCM_CHAN_ENTRY_PNT( pSharedInfo, pAdpcmChanEntry, *f_pusAdpcmChanIndex )
963
964 /* Extract the entry open count from the provided handle. */
965 ulEntryOpenCnt = (f_pAdpcmChanClose->ulChanHndl >> cOCT6100_ENTRY_OPEN_CNT_SHIFT) & cOCT6100_ENTRY_OPEN_CNT_MASK;
966
967 /* Check for errors. */
968 if ( pAdpcmChanEntry->fReserved != TRUE )
969 return cOCT6100_ERR_ADPCM_CHAN_NOT_OPEN;
970 if ( ulEntryOpenCnt != pAdpcmChanEntry->byEntryOpenCnt )
971 return cOCT6100_ERR_ADPCM_CHAN_INVALID_HANDLE;
972
973 /* Return info needed to close the channel and release all resources. */
974 *f_pusInputTsstIndex = pAdpcmChanEntry->usInputTsstIndex;
975 *f_pusOutputTsstIndex = pAdpcmChanEntry->usOutputTsstIndex;
976 *f_pusTsiMemIndex = pAdpcmChanEntry->usTsiMemIndex;
977 *f_pusAdpcmMemIndex = pAdpcmChanEntry->usAdpcmMemIndex;
978
979 /*------------------------------------------------------------------------------*/
980
981 return cOCT6100_ERR_OK;
982 }
983 #endif
984
985
986 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
987
988 Function: Oct6100ApiInvalidateAdpcmChanStructs
989
990 Description: Closes an ADPCM channel.
991
992 -------------------------------------------------------------------------------
993 | Argument | Description
994 -------------------------------------------------------------------------------
995 f_pApiInstance Pointer to API instance. This memory is used to keep the
996 present state of the chip and all its resources.
997
998 f_usAdpcmMemIndex Index of the ADPCM memory.
999 f_usInputTsstIndex Index of the input entry in the TSST control memory.
1000 f_usOutputTsstIndex Index of the output entry in the TSST control memory.
1001
1002 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1003 #if !SKIP_Oct6100ApiInvalidateAdpcmChanStructs
1004 UINT32 Oct6100ApiInvalidateAdpcmChanStructs(
1005 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1006 IN UINT16 f_usAdpcmMemIndex,
1007 IN UINT16 f_usInputTsstIndex,
1008 IN UINT16 f_usOutputTsstIndex )
1009 {
1010 tPOCT6100_SHARED_INFO pSharedInfo;
1011 tOCT6100_WRITE_PARAMS WriteParams;
1012 UINT32 ulResult;
1013
1014 /* Obtain local pointer to shared portion of instance. */
1015 pSharedInfo = f_pApiInstance->pSharedInfo;
1016
1017 WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
1018
1019 WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
1020
1021 /*------------------------------------------------------------------------------*/
1022 /* Deactivate the TSST control memory. */
1023
1024 /* Set the input TSST control entry to unused. */
1025 WriteParams.ulWriteAddress = cOCT6100_TSST_CONTROL_MEM_BASE + ( f_usInputTsstIndex * cOCT6100_TSST_CONTROL_MEM_ENTRY_SIZE );
1026
1027 WriteParams.usWriteData = 0x0000;
1028 mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
1029 if ( ulResult != cOCT6100_ERR_OK )
1030 return ulResult;
1031
1032 /* Set the output TSST control entry to unused. */
1033 WriteParams.ulWriteAddress = cOCT6100_TSST_CONTROL_MEM_BASE + ( f_usOutputTsstIndex * cOCT6100_TSST_CONTROL_MEM_ENTRY_SIZE );
1034
1035 WriteParams.usWriteData = 0x0000;
1036 mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
1037 if ( ulResult != cOCT6100_ERR_OK )
1038 return ulResult;
1039
1040 /*------------------------------------------------------------------------------*/
1041
1042
1043 /*------------------------------------------------------------------------------*/
1044 /* Clear the ADPCM memory. */
1045
1046 ulResult = Oct6100ApiClearConversionMemory( f_pApiInstance, f_usAdpcmMemIndex );
1047 if ( ulResult != cOCT6100_ERR_OK )
1048 return ulResult;
1049
1050 /*------------------------------------------------------------------------------*/
1051
1052 return cOCT6100_ERR_OK;
1053 }
1054 #endif
1055
1056
1057 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1058
1059 Function: Oct6100ApiReleaseAdpcmChanResources
1060
1061 Description: Release and clear the API entry associated to the ADPCM channel.
1062
1063 -------------------------------------------------------------------------------
1064 | Argument | Description
1065 -------------------------------------------------------------------------------
1066 f_pApiInstance Pointer to API instance. This memory is used to keep the
1067 present state of the chip and all its resources.
1068 f_ulAdpcmChanIndex Index of the ADPCM channel in the API list.
1069 f_usAdpcmMemIndex Index of the ADPCM memory used.
1070 f_usTsiMemIndex Index of the TSI memory used.
1071
1072 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1073 #if !SKIP_Oct6100ApiReleaseAdpcmChanResources
1074 UINT32 Oct6100ApiReleaseAdpcmChanResources(
1075 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1076 IN UINT16 f_usAdpcmChanIndex,
1077 IN UINT16 f_usAdpcmMemIndex,
1078 IN UINT16 f_usTsiMemIndex )
1079 {
1080 tPOCT6100_SHARED_INFO pSharedInfo;
1081 tPOCT6100_API_ADPCM_CHAN pAdpcmChanEntry;
1082 UINT32 ulResult;
1083
1084 /* Obtain local pointer to shared portion of instance. */
1085 pSharedInfo = f_pApiInstance->pSharedInfo;
1086
1087 mOCT6100_GET_ADPCM_CHAN_ENTRY_PNT( pSharedInfo, pAdpcmChanEntry, f_usAdpcmChanIndex );
1088
1089 /*------------------------------------------------------------------------------*/
1090 /* Release all resources associated with ADPCM channel. */
1091
1092 /* Release the entry in the ADPCM channel list. */
1093 ulResult = Oct6100ApiReleaseAdpcmChanEntry( f_pApiInstance, f_usAdpcmChanIndex );
1094 if ( ulResult == cOCT6100_ERR_OK )
1095 {
1096 ulResult = Oct6100ApiReleaseConversionMemEntry( f_pApiInstance, f_usAdpcmMemIndex );
1097 if ( ulResult == cOCT6100_ERR_OK )
1098 {
1099 ulResult = Oct6100ApiReleaseTsiMemEntry( f_pApiInstance, f_usTsiMemIndex );
1100 if ( ulResult == cOCT6100_ERR_OK )
1101 {
1102 /* Release the input TSST entry. */
1103 ulResult = Oct6100ApiReleaseTsst(
1104 f_pApiInstance,
1105 pAdpcmChanEntry->usInputTimeslot,
1106 pAdpcmChanEntry->usInputStream,
1107 pAdpcmChanEntry->byInputNumTssts,
1108 cOCT6100_INPUT_TSST,
1109 cOCT6100_INVALID_INDEX );
1110 if ( ulResult == cOCT6100_ERR_OK )
1111 {
1112 /* Release the output TSST entry. */
1113 ulResult = Oct6100ApiReleaseTsst(
1114 f_pApiInstance,
1115 pAdpcmChanEntry->usOutputTimeslot,
1116 pAdpcmChanEntry->usOutputStream,
1117 pAdpcmChanEntry->byOutputNumTssts,
1118 cOCT6100_OUTPUT_TSST,
1119 cOCT6100_INVALID_INDEX );
1120 }
1121 }
1122 }
1123 }
1124
1125 /* Check if an error occured while releasing the reserved resources. */
1126 if ( ulResult != cOCT6100_ERR_OK )
1127 {
1128 if ( ulResult >= cOCT6100_ERR_FATAL )
1129 return ulResult;
1130 else
1131 return cOCT6100_ERR_FATAL_4A;
1132 }
1133
1134 /*------------------------------------------------------------------------------*/
1135
1136
1137 /*------------------------------------------------------------------------------*/
1138 /* Update the ADPCM channel's list entry. */
1139
1140 /* Mark the channel as closed. */
1141 pAdpcmChanEntry->fReserved = FALSE;
1142 pAdpcmChanEntry->byEntryOpenCnt++;
1143
1144 /* Decrement the number of ADPCM channels opened. */
1145 f_pApiInstance->pSharedInfo->ChipStats.usNumberAdpcmChans--;
1146
1147 /*------------------------------------------------------------------------------*/
1148
1149 return cOCT6100_ERR_OK;
1150 }
1151 #endif
1152
1153
1154 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1155
1156 Function: Oct6100ApiReserveAdpcmChanEntry
1157
1158 Description: Reserves one of the ADPCM channel API entry.
1159
1160 -------------------------------------------------------------------------------
1161 | Argument | Description
1162 -------------------------------------------------------------------------------
1163 f_pApiInstance Pointer to API instance. This memory is used to keep
1164 the present state of the chip and all its resources.
1165
1166 f_pusAdpcmChanIndex Resulting index reserved in the ADPCM channel list.
1167
1168 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1169 #if !SKIP_Oct6100ApiReserveAdpcmChanEntry
1170 UINT32 Oct6100ApiReserveAdpcmChanEntry(
1171 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1172 OUT PUINT16 f_pusAdpcmChanIndex )
1173 {
1174 tPOCT6100_SHARED_INFO pSharedInfo;
1175 PVOID pAdpcmChanAlloc;
1176 UINT32 ulResult;
1177 UINT32 ulAdpcmChanIndex;
1178
1179 /* Get local pointer to shared portion of instance. */
1180 pSharedInfo = f_pApiInstance->pSharedInfo;
1181
1182 mOCT6100_GET_ADPCM_CHAN_ALLOC_PNT( pSharedInfo, pAdpcmChanAlloc )
1183
1184 ulResult = OctapiLlmAllocAlloc( pAdpcmChanAlloc, &ulAdpcmChanIndex );
1185 if ( ulResult != cOCT6100_ERR_OK )
1186 {
1187 if ( ulResult == OCTAPI_LLM_NO_STRUCTURES_LEFT )
1188 return cOCT6100_ERR_ADPCM_CHAN_ALL_ADPCM_CHAN_ARE_OPENED;
1189 else
1190 return cOCT6100_ERR_FATAL_BE;
1191 }
1192
1193 *f_pusAdpcmChanIndex = (UINT16)( ulAdpcmChanIndex & 0xFFFF );
1194
1195 return cOCT6100_ERR_OK;
1196 }
1197 #endif
1198
1199
1200 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1201
1202 Function: Oct6100ApiReleaseAdpcmChanEntry
1203
1204 Description: Releases the specified ADPCM channel API entry.
1205
1206 -------------------------------------------------------------------------------
1207 | Argument | Description
1208 -------------------------------------------------------------------------------
1209 f_pApiInstance Pointer to API instance. This memory is used to keep
1210 the present state of the chip and all its resources.
1211
1212 f_usAdpcmChanIndex Index reserved in the ADPCM channel list.
1213
1214 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1215 #if !SKIP_Oct6100ApiReleaseAdpcmChanEntry
1216 UINT32 Oct6100ApiReleaseAdpcmChanEntry(
1217 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
1218 IN UINT16 f_usAdpcmChanIndex )
1219 {
1220 tPOCT6100_SHARED_INFO pSharedInfo;
1221 PVOID pAdpcmChanAlloc;
1222 UINT32 ulResult;
1223
1224 /* Get local pointer to shared portion of instance. */
1225 pSharedInfo = f_pApiInstance->pSharedInfo;
1226
1227 mOCT6100_GET_ADPCM_CHAN_ALLOC_PNT( pSharedInfo, pAdpcmChanAlloc )
1228
1229 ulResult = OctapiLlmAllocDealloc( pAdpcmChanAlloc, f_usAdpcmChanIndex );
1230 if ( ulResult != cOCT6100_ERR_OK )
1231 {
1232 return cOCT6100_ERR_FATAL_BF;
1233 }
1234
1235 return cOCT6100_ERR_OK;
1236 }
1237 #endif