Debian Codegraph @

drivers/dahdi/voicebus/GpakApi.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2005, Adaptive Digital Technologies, Inc.
3 *
4 * File Name: GpakApi.c
5 *
6 * Description:
7 * This file contains user API functions to communicate with DSPs executing
8 * G.PAK software. The file is integrated into the host processor connected
9 * to C55X G.PAK DSPs via a Host Port Interface.
10 *
11 * Version: 1.0
12 *
13 * Revision History:
14 * 06/15/05 - Initial release.
15 * 11/15/2006 - 24 TDM-TDM Channels EC release
16 *
17 * This program has been released under the terms of the GPL version 2 by
18 * permission of Adaptive Digital Technologies, Inc.
19 *
20 */
21
22 /*
23 * See http://www.asterisk.org for more information about
24 * the Asterisk project. Please do not directly contact
25 * any of the maintainers of this project for assistance;
26 * the project provides a web site, mailing lists and IRC
27 * channels for your use.
28 *
29 * This program is free software, distributed under the terms of
30 * the GNU General Public License Version 2 as published by the
31 * Free Software Foundation. See the LICENSE file included with
32 * this program for more details.
33 */
34
35 #include "GpakHpi.h"
36 #include "GpakCust.h"
37 #include "GpakApi.h"
38 #include "gpakenum.h"
39
40 /* DSP to Host interface block offsets. */
41 #define REPLY_MSG_PNTR_OFFSET 0 /* I/F blk offset to Reply Msg Pointer */
42 #define CMD_MSG_PNTR_OFFSET 2 /* I/F blk offset to Command Msg Pointer */
43 #define EVENT_MSG_PNTR_OFFSET 4 /* I/F blk offset to Event Msg Pointer */
44 #define PKT_BUFR_MEM_OFFSET 6 /* I/F blk offset to Packet Buffer memory */
45 #define DSP_STATUS_OFFSET 8 /* I/F blk offset to DSP Status */
46 #define VERSION_ID_OFFSET 9 /* I/F blk offset to G.PAK Version Id */
47 #define MAX_CMD_MSG_LEN_OFFSET 10 /* I/F blk offset to Max Cmd Msg Length */
48 #define CMD_MSG_LEN_OFFSET 11 /* I/F blk offset to Command Msg Length */
49 #define REPLY_MSG_LEN_OFFSET 12 /* I/F blk offset to Reply Msg Length */
50 #define NUM_CHANNELS_OFFSET 13 /* I/F blk offset to Num Built Channels */
51 #define NUM_PKT_CHANNELS_OFFSET 14 /* I/F blk offset to Num Pkt Channels */
52 #define NUM_CONFERENCES_OFFSET 15 /* I/F blk offset to Num Conferences */
53 //#define CPU_USAGE_OFFSET_1MS 16 /* I/F blk offset to CPU Usage statistics */
54 #define CPU_USAGE_OFFSET 18 /* I/F blk offset to CPU Usage statistics */
55 //#define CPU_USAGE_OFFSET_10MS 20 /* I/F blk offset to CPU Usage statistics */
56 #define FRAMING_STATS_OFFSET 22 /* I/F blk offset to Framing statistics */
57
58 //#define GPAK_RELEASE_Rate rate10ms
59 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
60 // Macro to reconstruct a 32-bit value from two 16-bit values.
61 // Parameter p32: 32-bit-wide destination
62 // Parameter p16: 16-bit-wide source array of length 2 words
63 #define RECONSTRUCT_LONGWORD(p32, p16) p32 = (DSP_ADDRESS)p16[0]<<16; \
64 p32 |= (unsigned long)p16[1]
65 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
66
67 /* DSP Status value definitions. */
68 #define DSP_INIT_STATUS 0x5555 /* DSP Initialized status value */
69 #define HOST_INIT_STATUS 0xAAAA /* Host Initialized status value */
70
71 /* Circular packet buffer information structure offsets. */
72 #define CB_BUFR_BASE 0 /* pointer to base of circular buffer */
73 #define CB_BUFR_SIZE 2 /* size of buffer (words) */
74 #define CB_BUFR_PUT_INDEX 3 /* offset in buffer for next write */
75 #define CB_BUFR_TAKE_INDEX 4 /* offset in buffer for next read */
76 #define CIRC_BUFFER_INFO_STRUCT_SIZE 6
77
78 /* Miscellaneous definitions. */
79 #define MSG_BUFFER_SIZE 100 /* size (words) of Host msg buffer */
80 #define WORD_BUFFER_SIZE 84 /* size of DSP Word buffer (words) */
81
82 #ifdef __TMS320C55XX__ // debug sections if not on host
83 #pragma DATA_SECTION(pDspIfBlk,"GPAKAPIDEBUG_SECT")
84 #pragma DATA_SECTION(MaxCmdMsgLen,"GPAKAPIDEBUG_SECT")
85 #pragma DATA_SECTION(MaxChannels,"GPAKAPIDEBUG_SECT")
86 #pragma DATA_SECTION(DlByteBufr,"GPAKAPIDEBUG_SECT")
87 #pragma DATA_SECTION(DlWordBufr,"GPAKAPIDEBUG_SECT")
88 #pragma DATA_SECTION(pEventFifoAddress,"GPAKAPIDEBUG_SECT")
89 #endif
90
91 /* Host variables related to Host to DSP interface. */
92 static DSP_ADDRESS pDspIfBlk[MAX_DSP_CORES]; /* DSP address of I/F block */
93 static DSP_WORD MaxCmdMsgLen[MAX_DSP_CORES]; /* max Cmd msg length (octets) */
94 static unsigned short int MaxChannels[MAX_DSP_CORES]; /* max num channels */
95
96 //static unsigned short int MaxPktChannels[MAX_DSP_CORES]; /* max num pkt channels */
97 //static unsigned short int MaxConfs[MAX_DSP_CORES]; /* max num conferences */
98 //static DSP_ADDRESS pPktInBufr[MAX_DSP_CORES][MAX_PKT_CHANNELS]; /* Pkt In buffer */
99 //static DSP_ADDRESS pPktOutBufr[MAX_DSP_CORES][MAX_PKT_CHANNELS]; /* Pkt Out buffer */
100 static DSP_ADDRESS pEventFifoAddress[MAX_DSP_CORES]; /* event fifo */
101
102 static unsigned char DlByteBufr[DOWNLOAD_BLOCK_SIZE * 2]; /* Dowload byte buf */
103 static DSP_WORD DlWordBufr[DOWNLOAD_BLOCK_SIZE]; /* Dowload word buffer */
104
105 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106 * CheckDspReset - Check if the DSP was reset.
107 *
108 * FUNCTION
109 * This function determines if the DSP was reset and is ready. If reset
110 * occurred, it reads interface parameters and calculates DSP addresses.
111 *
112 * RETURNS
113 * -1 = DSP is not ready.
114 * 0 = Reset did not occur.
115 * 1 = Reset occurred.
116 *
117 */
118 static int __CheckDspReset(
119 int DspId /* DSP Identifier (0 to MaxDSPCores-1) */
120 )
121 {
122 DSP_ADDRESS IfBlockPntr; /* Interface Block pointer */
123 DSP_WORD DspStatus; /* DSP Status */
124 DSP_WORD DspChannels; /* number of DSP channels */
125 DSP_WORD Temp[2];
126
127 /* Read the pointer to the Interface Block. */
128 gpakReadDspMemory(DspId, DSP_IFBLK_ADDRESS, 2, Temp);
129 RECONSTRUCT_LONGWORD(IfBlockPntr, Temp);
130
131 /* If the pointer is zero, return with an indication the DSP is not
132 ready. */
133 if (IfBlockPntr == 0)
134 return (-1);
135
136 /* Read the DSP's Status. */
137 gpakReadDspMemory(DspId, IfBlockPntr + DSP_STATUS_OFFSET, 1, &DspStatus);
138
139 /* If status indicates the DSP was reset, read the DSP's interface
140 parameters and calculate DSP addresses. */
141 if (DspStatus == DSP_INIT_STATUS ||
142 ((DspStatus == HOST_INIT_STATUS) && (pDspIfBlk[DspId] == 0)))
143 {
144 /* Save the address of the DSP's Interface Block. */
145 pDspIfBlk[DspId] = IfBlockPntr;
146
147 /* Read the DSP's interface parameters. */
148 gpakReadDspMemory(DspId, IfBlockPntr + MAX_CMD_MSG_LEN_OFFSET, 1,
149 &(MaxCmdMsgLen[DspId]));
150
151 /* read the number of configured DSP channels */
152 gpakReadDspMemory(DspId, IfBlockPntr + NUM_CHANNELS_OFFSET, 1,
153 &DspChannels);
154 if (DspChannels > MAX_CHANNELS)
155 MaxChannels[DspId] = MAX_CHANNELS;
156 else
157 MaxChannels[DspId] = (unsigned short int) DspChannels;
158
159 /* read the pointer to the event fifo info struct */
160 gpakReadDspMemory(DspId, IfBlockPntr + EVENT_MSG_PNTR_OFFSET, 2, Temp);
161 RECONSTRUCT_LONGWORD(pEventFifoAddress[DspId], Temp);
162
163 /* Set the DSP Status to indicate the host recognized the reset. */
164 DspStatus = HOST_INIT_STATUS;
165 gpakWriteDspMemory(DspId, IfBlockPntr + DSP_STATUS_OFFSET, 1,
166 &DspStatus);
167
168 /* Return with an indication that a reset occurred. */
169 return (1);
170 }
171
172 /* If status doesn't indicate the host recognized a reset, return with an
173 indication the DSP is not ready. */
174 if ((DspStatus != HOST_INIT_STATUS) || (pDspIfBlk[DspId] == 0))
175 return (-1);
176
177 /* Return with an indication that a reset did not occur. */
178 return (0);
179 }
180
181 static int CheckDspReset(
182 int DspId /* DSP Identifier (0 to MaxDSPCores-1) */
183 )
184 {
185 int ret;
186 int retries = 20;
187 while (--retries) {
188 ret = __CheckDspReset(DspId);
189 if (-1 != ret)
190 return ret;
191 msleep(5);
192 }
193 return ret;
194 }
195
196 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
197 * WriteDspCmdMessage - Write a Host Command/Request message to DSP.
198 *
199 * FUNCTION
200 * This function writes a Host Command/Request message into DSP memory and
201 * informs the DSP of the presence of the message.
202 *
203 * RETURNS
204 * -1 = Unable to write message (msg len or DSP Id invalid or DSP not ready)
205 * 0 = Temporarily unable to write message (previous Cmd Msg busy)
206 * 1 = Message written successfully
207 *
208 */
209 static int WriteDspCmdMessage(
210 int DspId, /* DSP Identifier (0 to MaxDSPCores-1) */
211 DSP_WORD *pMessage, /* pointer to Command message */
212 DSP_WORD MsgLength /* length of message (octets) */
213 )
214 {
215 DSP_WORD CmdMsgLength; /* current Cmd message length */
216 DSP_WORD Temp[2];
217 DSP_ADDRESS BufferPointer; /* message buffer pointer */
218
219 /* Check if the DSP was reset and is ready. */
220 if (CheckDspReset(DspId) == -1)
221 return (-1);
222
223 /* Make sure the message length is valid. */
224 if ((MsgLength < 1) || (MsgLength > MaxCmdMsgLen[DspId]))
225 return (-1);
226
227 /* Make sure a previous Command message is not in use by the DSP. */
228 gpakReadDspMemory(DspId, pDspIfBlk[DspId] + CMD_MSG_LEN_OFFSET, 1,
229 &CmdMsgLength);
230 if (CmdMsgLength != 0)
231 return (0);
232
233 /* Purge any previous Reply message that wasn't read. */
234 gpakWriteDspMemory(DspId, pDspIfBlk[DspId] + REPLY_MSG_LEN_OFFSET, 1,
235 &CmdMsgLength);
236
237 /* Copy the Command message into DSP memory. */
238 gpakReadDspMemory(DspId, pDspIfBlk[DspId] + CMD_MSG_PNTR_OFFSET, 2, Temp);
239 RECONSTRUCT_LONGWORD(BufferPointer, Temp);
240 gpakWriteDspMemory(DspId, BufferPointer, (MsgLength + 1) / 2, pMessage);
241
242 /* Store the message length in DSP's Command message length (flags DSP that
243 a Command message is ready). */
244 CmdMsgLength = MsgLength;
245 gpakWriteDspMemory(DspId, pDspIfBlk[DspId] + CMD_MSG_LEN_OFFSET, 1,
246 &CmdMsgLength);
247
248 /* Return with an indication the message was written. */
249 return (1);
250 }
251
252
253 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
254 * ReadDspReplyMessage - Read a DSP Reply message from DSP.
255 *
256 * FUNCTION
257 * This function reads a DSP Reply message from DSP memory.
258 *
259 * RETURNS
260 * -1 = Unable to write message (msg len or DSP Id invalid or DSP not ready)
261 * 0 = No message available (DSP Reply message empty)
262 * 1 = Message read successfully (message and length stored in variables)
263 *
264 */
265 static int ReadDspReplyMessage(
266 int DspId, /* DSP Identifier (0 to MaxDSPCores-1) */
267 DSP_WORD *pMessage, /* pointer to Reply message buffer */
268 DSP_WORD *pMsgLength /* pointer to msg length var (octets) */
269 )
270 {
271 DSP_WORD MsgLength; /* message length */
272 DSP_ADDRESS BufferPointer; /* message buffer pointer */
273 DSP_WORD Temp[2];
274
275 /* Check if the DSP was reset and is ready. */
276 if (CheckDspReset(DspId) == -1)
277 return (-1);
278
279 /* Check if a Reply message is ready. */
280 gpakReadDspMemory(DspId, pDspIfBlk[DspId] + REPLY_MSG_LEN_OFFSET, 1,
281 &MsgLength);
282 if (MsgLength == 0)
283 return (0);
284
285 /* Make sure the message length is valid. */
286 if (MsgLength > *pMsgLength)
287 return (-1);
288
289 /* Copy the Reply message from DSP memory. */
290 gpakReadDspMemory(DspId, pDspIfBlk[DspId] + REPLY_MSG_PNTR_OFFSET, 2, Temp);
291 RECONSTRUCT_LONGWORD(BufferPointer, Temp);
292 gpakReadDspMemory(DspId, BufferPointer, (MsgLength + 1) / 2, pMessage);
293
294 /* Store the message length in the message length variable. */
295 *pMsgLength = MsgLength;
296
297 /* Indicate a Reply message is not ready. */
298 MsgLength = 0;
299 gpakWriteDspMemory(DspId, pDspIfBlk[DspId] + REPLY_MSG_LEN_OFFSET, 1,
300 &MsgLength);
301
302 /* Return with an indication the message was read. */
303 return (1);
304 }
305
306 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307 * ReadCircBuffer - Read from a DSP circular buffer.
308 *
309 * FUNCTION
310 * This function reads a block of words from a DSP circular buffer. The Take
311 * address is incremented by the number of words read adjusting for buffer
312 * wrap.
313 *
314 * RETURNS
315 * nothing
316 *
317 */
318 static void ReadCircBuffer(
319 int DspId, /* DSP Identifier (0 to MaxDSPCores-1) */
320 DSP_ADDRESS BufrBaseAddress, /* address of base of circular buffer */
321 DSP_ADDRESS BufrLastAddress, /* address of last word in buffer */
322 DSP_ADDRESS *TakeAddress, /* pointer to address in buffer for read */
323 DSP_WORD *pWordBuffer, /* pointer to buffer for words read */
324 DSP_WORD NumWords /* number of words to read */
325 )
326 {
327 DSP_WORD WordsTillEnd; /* number of words until end of buffer */
328
329 /* Determine the number of words from the start address until the end of the
330 buffer. */
331 WordsTillEnd = BufrLastAddress - *TakeAddress + 1;
332
333 /* If a buffer wrap will occur, read the first part at the end of the
334 buffer followed by the second part at the beginning of the buffer. */
335 if (NumWords > WordsTillEnd)
336 {
337 gpakReadDspMemory(DspId, *TakeAddress, WordsTillEnd, pWordBuffer);
338 gpakReadDspMemory(DspId, BufrBaseAddress, NumWords - WordsTillEnd,
339 &(pWordBuffer[WordsTillEnd]));
340 *TakeAddress = BufrBaseAddress + NumWords - WordsTillEnd;
341 }
342
343 /* If a buffer wrap will not occur, read all words starting at the current
344 take address in the buffer. */
345 else
346 {
347 gpakReadDspMemory(DspId, *TakeAddress, NumWords, pWordBuffer);
348 if (NumWords == WordsTillEnd)
349 *TakeAddress = BufrBaseAddress;
350 else
351 *TakeAddress = *TakeAddress + NumWords;
352 }
353 return;
354 }
355
356
357 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
358 * VerifyReply - Verify the reply message is correct for the command sent.
359 *
360 * FUNCTION
361 * This function verifies correct reply message content for the command that
362 * was just sent.
363 *
364 * RETURNS
365 * 0 = Incorrect
366 * 1 = Correct
367 *
368 */
369 static int VerifyReply(
370 DSP_WORD *pMsgBufr, /* pointer to Reply message buffer */
371 int CheckType, /* reply check type */
372 DSP_WORD CheckValue /* reply check value */
373 )
374 {
375
376 /* Verify Channel or Conference Id. */
377 if (CheckType == 1)
378 {
379 if (((pMsgBufr[1] >> 8) & 0xFF) != CheckValue)
380 return (0);
381 }
382
383 /* Verify Test Mode Id. */
384 else if (CheckType == 2)
385 {
386 if (pMsgBufr[1] != CheckValue)
387 return (0);
388 }
389
390 /* Return with an indication of correct reply. */
391 return (1);
392 }
393
394
395 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
396 * TransactCmd - Send a command to the DSP and receive it's reply.
397 *
398 * FUNCTION
399 * This function sends the specified command to the DSP and receives the DSP's
400 * reply.
401 *
402 * RETURNS
403 * Length of reply message (0 = Failure)
404 *
405 */
406 static unsigned int TransactCmd(
407 int DspId, /* DSP Identifier (0 to MaxDSPCores-1) */
408 DSP_WORD *pMsgBufr, /* pointer to Cmd/Reply message buffer */
409 DSP_WORD CmdLength, /* length of command message (octets) */
410 DSP_WORD ReplyType, /* required type of reply message */
411 DSP_WORD ReplyLength, /* required length of reply message (octets) */
412 int ReplyCheckType, /* reply check type */
413 DSP_WORD ReplyCheckValue /* reply check value */
414 )
415 {
416 int FuncStatus; /* function status */
417 int LoopCount; /* wait loop counter */
418 DSP_WORD RcvReplyLength; /* received Reply message length */
419 DSP_WORD RcvReplyType; /* received Reply message type code */
420 DSP_WORD RetValue; /* return value */
421
422 /* Default the return value to indicate a failure. */
423 RetValue = 0;
424
425 /* Lock access to the DSP. */
426 gpakLockAccess(DspId);
427
428 /* Attempt to write the command message to the DSP. */
429 LoopCount = 0;
430 while ((FuncStatus = WriteDspCmdMessage(DspId, pMsgBufr, CmdLength)) != 1)
431 {
432 if (FuncStatus == -1)
433 break;
434 if (++LoopCount > MAX_WAIT_LOOPS)
435 break;
436 gpakHostDelay();
437 }
438
439 /* Attempt to read the reply message from the DSP if the command message was
440 sent successfully. */
441 if (FuncStatus == 1)
442 {
443 for (LoopCount = 0; LoopCount < MAX_WAIT_LOOPS; LoopCount++)
444 {
445 RcvReplyLength = MSG_BUFFER_SIZE * 2;
446 FuncStatus = ReadDspReplyMessage(DspId, pMsgBufr, &RcvReplyLength);
447 if (FuncStatus == 1)
448 {
449 RcvReplyType = (pMsgBufr[0] >> 8) & 0xFF;
450 if ((RcvReplyLength >= ReplyLength) &&
451 (RcvReplyType == ReplyType) &&
452 VerifyReply(pMsgBufr, ReplyCheckType, ReplyCheckValue))
453 {
454 RetValue = RcvReplyLength;
455 break;
456 }
457 else if (RcvReplyType == MSG_NULL_REPLY)
458 break;
459 }
460 else if (FuncStatus == -1)
461 break;
462 gpakHostDelay();
463 }
464 }
465
466 /* Unlock access to the DSP. */
467 gpakUnlockAccess(DspId);
468
469 /* Return the length of the reply message (0 = failure). */
470 return (RetValue);
471 }
472
473 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
474 * gpakConfigurePorts - Configure a DSP's serial ports.
475 *
476 * FUNCTION
477 * This function configures a DSP's serial ports.
478 *
479 * RETURNS
480 * Status code indicating success or a specific error.
481 *
482 */
483 gpakConfigPortStatus_t gpakConfigurePorts(
484 unsigned short int DspId, /* DSP Id (0 to MaxDSPCores-1) */
485 const GpakPortConfig_t *pPortConfig, /* pointer to Port Config info */
486 GPAK_PortConfigStat_t *pStatus /* pointer to Port Config Status */
487 )
488 {
489 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
490
491 /* Make sure the DSP Id is valid. */
492 if (DspId >= MAX_DSP_CORES)
493 return (CpsInvalidDsp);
494
495 /* Build the Configure Serial Ports message. */
496 MsgBuffer[0] = MSG_CONFIGURE_PORTS << 8;
497 MsgBuffer[1] = (DSP_WORD)
498 ((pPortConfig->SlotsSelect1 << 12) |
499 ((pPortConfig->FirstBlockNum1 << 8) & 0x0F00) |
500 ((pPortConfig->SecBlockNum1 << 4) & 0x00F0));
501 MsgBuffer[2] = (DSP_WORD) pPortConfig->FirstSlotMask1;
502 MsgBuffer[3] = (DSP_WORD) pPortConfig->SecSlotMask1;
503 MsgBuffer[4] = (DSP_WORD)
504 ((pPortConfig->SlotsSelect2 << 12) |
505 ((pPortConfig->FirstBlockNum2 << 8) & 0x0F00) |
506 ((pPortConfig->SecBlockNum2 << 4) & 0x00F0));
507 MsgBuffer[5] = (DSP_WORD) pPortConfig->FirstSlotMask2;
508 MsgBuffer[6] = (DSP_WORD) pPortConfig->SecSlotMask2;
509 MsgBuffer[7] = (DSP_WORD)
510 ((pPortConfig->SlotsSelect3 << 12) |
511 ((pPortConfig->FirstBlockNum3 << 8) & 0x0F00) |
512 ((pPortConfig->SecBlockNum3 << 4) & 0x00F0));
513 MsgBuffer[8] = (DSP_WORD) pPortConfig->FirstSlotMask3;
514 MsgBuffer[9] = (DSP_WORD) pPortConfig->SecSlotMask3;
515
516 MsgBuffer[10] = (DSP_WORD)
517 (((pPortConfig->DxDelay1 << 11) & 0x0800) |
518 ((pPortConfig->RxDataDelay1 << 9) & 0x0600) |
519 ((pPortConfig->TxDataDelay1 << 7) & 0x0180) |
520 ((pPortConfig->RxClockPolarity1 << 6) & 0x0040) |
521 ((pPortConfig->TxClockPolarity1 << 5) & 0x0020) |
522 ((pPortConfig->RxFrameSyncPolarity1 << 4) & 0x0010) |
523 ((pPortConfig->TxFrameSyncPolarity1 << 3) & 0x0008) |
524 ((pPortConfig->CompandingMode1 << 1) & 0x0006) |
525 (pPortConfig->SerialWordSize1 & 0x0001));
526
527 MsgBuffer[11] = (DSP_WORD)
528 (((pPortConfig->DxDelay2 << 11) & 0x0800) |
529 ((pPortConfig->RxDataDelay2 << 9) & 0x0600) |
530 ((pPortConfig->TxDataDelay2 << 7) & 0x0180) |
531 ((pPortConfig->RxClockPolarity2 << 6) & 0x0040) |
532 ((pPortConfig->TxClockPolarity2 << 5) & 0x0020) |
533 ((pPortConfig->RxFrameSyncPolarity2 << 4) & 0x0010) |
534 ((pPortConfig->TxFrameSyncPolarity2 << 3) & 0x0008) |
535 ((pPortConfig->CompandingMode2 << 1) & 0x0006) |
536 (pPortConfig->SerialWordSize2 & 0x0001));
537
538 MsgBuffer[12] = (DSP_WORD)
539 (((pPortConfig->DxDelay3 << 11) & 0x0800) |
540 ((pPortConfig->RxDataDelay3 << 9) & 0x0600) |
541 ((pPortConfig->TxDataDelay3 << 7) & 0x0180) |
542 ((pPortConfig->RxClockPolarity3 << 6) & 0x0040) |
543 ((pPortConfig->TxClockPolarity3 << 5) & 0x0020) |
544 ((pPortConfig->RxFrameSyncPolarity3 << 4) & 0x0010) |
545 ((pPortConfig->TxFrameSyncPolarity3 << 3) & 0x0008) |
546 ((pPortConfig->CompandingMode3 << 1) & 0x0006) |
547 (pPortConfig->SerialWordSize3 & 0x0001));
548
549 MsgBuffer[13] = (DSP_WORD) pPortConfig->ThirdSlotMask1;
550 MsgBuffer[14] = (DSP_WORD) pPortConfig->FouthSlotMask1;
551 MsgBuffer[15] = (DSP_WORD) pPortConfig->FifthSlotMask1;
552 MsgBuffer[16] = (DSP_WORD) pPortConfig->SixthSlotMask1;
553 MsgBuffer[17] = (DSP_WORD) pPortConfig->SevenSlotMask1;
554 MsgBuffer[18] = (DSP_WORD) pPortConfig->EightSlotMask1;
555
556 MsgBuffer[19] = (DSP_WORD) pPortConfig->ThirdSlotMask2;;
557 MsgBuffer[20] = (DSP_WORD) pPortConfig->FouthSlotMask2;
558 MsgBuffer[21] = (DSP_WORD) pPortConfig->FifthSlotMask2;;
559 MsgBuffer[22] = (DSP_WORD) pPortConfig->SixthSlotMask2;
560 MsgBuffer[23] = (DSP_WORD) pPortConfig->SevenSlotMask2;;
561 MsgBuffer[24] = (DSP_WORD) pPortConfig->EightSlotMask2;
562
563 MsgBuffer[25] = (DSP_WORD) pPortConfig->ThirdSlotMask3;;
564 MsgBuffer[26] = (DSP_WORD) pPortConfig->FouthSlotMask3;
565 MsgBuffer[27] = (DSP_WORD) pPortConfig->FifthSlotMask3;;
566 MsgBuffer[28] = (DSP_WORD) pPortConfig->SixthSlotMask3;
567 MsgBuffer[29] = (DSP_WORD) pPortConfig->SevenSlotMask3;;
568 MsgBuffer[30] = (DSP_WORD) pPortConfig->EightSlotMask3;
569
570
571 /* Attempt to send the Configure Serial Ports message to the DSP and receive
572 it's reply. */
573 if (!TransactCmd(DspId, MsgBuffer, 62, MSG_CONFIG_PORTS_REPLY, 4, 0, 0))
574 return (CpsDspCommFailure);
575
576 /* Return with an indication of success or failure based on the return
577 status in the reply message. */
578 *pStatus = (GPAK_PortConfigStat_t) (MsgBuffer[1] & 0xFF);
579 if (*pStatus == Pc_Success)
580 return (CpsSuccess);
581 else
582 return (CpsParmError);
583 }
584 EXPORT_SYMBOL(gpakConfigurePorts);
585
586
587 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
588 * gpakConfigureChannel - Configure a DSP's Channel.
589 *
590 * FUNCTION
591 * This function configures a DSP's Channel.
592 *
593 * RETURNS
594 * Status code indicating success or a specific error.
595 *
596 */
597 gpakConfigChanStatus_t gpakConfigureChannel(
598 unsigned short int DspId, /* DSP Id (0 to MaxDSPCores-1) */
599 unsigned short int ChannelId, /* Channel Id (0 to MaxChannels-1) */
600 GpakChanType ChannelType, /* Channel Type */
601 GpakChannelConfig_t *pChanConfig, /* pointer to Channel Config info */
602 GPAK_ChannelConfigStat_t *pStatus /* pointer to Channel Config Status */
603 )
604 {
605 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
606 DSP_WORD MsgLength; /* message length */
607
608 /* Make sure the DSP Id is valid. */
609 if (DspId >= MAX_DSP_CORES)
610 return (CcsInvalidDsp);
611
612 /* Make sure the Channel Id is valid. */
613 if (ChannelId >= MaxChannels[DspId])
614 return (CcsInvalidChannel);
615
616 /* Build the Configure Channel message based on the Channel Type. */
617 switch (ChannelType)
618 {
619
620 /* PCM to Packet channel type. */
621 case tdmToTdm:
622
623 MsgBuffer[2] = (DSP_WORD)
624 ((pChanConfig->PcmInPortA << 8) |
625 (pChanConfig->PcmInSlotA & 0xFF));
626 MsgBuffer[3] = (DSP_WORD)
627 ((pChanConfig->PcmOutPortA << 8) |
628 (pChanConfig->PcmOutSlotA & 0xFF));
629
630 MsgBuffer[4] = (DSP_WORD)
631 ((pChanConfig->PcmInPortB << 8) |
632 (pChanConfig->PcmInSlotB & 0xFF));
633 MsgBuffer[5] = (DSP_WORD)
634 ((pChanConfig->PcmOutPortB << 8) |
635 (pChanConfig->PcmOutSlotB & 0xFF));
636
637 MsgBuffer[6] = (DSP_WORD)
638 (
639 ((pChanConfig->FaxCngDetB <<11) & 0x0800) |
640 ((pChanConfig->FaxCngDetA <<10) & 0x0400) |
641 ((pChanConfig->MuteToneB << 9) & 0x0200) |
642 ((pChanConfig->MuteToneA << 8) & 0x0100) |
643 ((pChanConfig->FrameRate << 6) & 0x00C0) |
644 ((pChanConfig->ToneTypesB << 5) & 0x0020) |
645 ((pChanConfig->ToneTypesA << 4) & 0x0010) |
646 ((pChanConfig->SoftwareCompand & 3) << 2) |
647 (pChanConfig->EcanEnableB << 1) |
648 (pChanConfig->EcanEnableA & 1)
649 );
650
651 MsgBuffer[7] = (DSP_WORD)
652 pChanConfig->EcanParametersA.EcanTapLength;
653 MsgBuffer[8] = (DSP_WORD)
654 pChanConfig->EcanParametersA.EcanNlpType;
655 MsgBuffer[9] = (DSP_WORD)
656 pChanConfig->EcanParametersA.EcanAdaptEnable;
657 MsgBuffer[10] = (DSP_WORD)
658 pChanConfig->EcanParametersA.EcanG165DetEnable;
659 MsgBuffer[11] = (DSP_WORD)
660 pChanConfig->EcanParametersA.EcanDblTalkThresh;
661 MsgBuffer[12] = (DSP_WORD)
662 pChanConfig->EcanParametersA.EcanNlpThreshold;
663 MsgBuffer[13] = (DSP_WORD)
664 pChanConfig->EcanParametersA.EcanNlpConv;
665 MsgBuffer[14] = (DSP_WORD)
666 pChanConfig->EcanParametersA.EcanNlpUnConv;
667 MsgBuffer[15] = (DSP_WORD)
668 pChanConfig->EcanParametersA.EcanNlpMaxSuppress;
669
670 MsgBuffer[16] = (DSP_WORD)
671 pChanConfig->EcanParametersA.EcanCngThreshold;
672 MsgBuffer[17] = (DSP_WORD)
673 pChanConfig->EcanParametersA.EcanAdaptLimit;
674 MsgBuffer[18] = (DSP_WORD)
675 pChanConfig->EcanParametersA.EcanCrossCorrLimit;
676 MsgBuffer[19] = (DSP_WORD)
677 pChanConfig->EcanParametersA.EcanNumFirSegments;
678 MsgBuffer[20] = (DSP_WORD)
679 pChanConfig->EcanParametersA.EcanFirSegmentLen;
680
681 MsgBuffer[21] = (DSP_WORD)
682 pChanConfig->EcanParametersB.EcanTapLength;
683 MsgBuffer[22] = (DSP_WORD)
684 pChanConfig->EcanParametersB.EcanNlpType;
685 MsgBuffer[23] = (DSP_WORD)
686 pChanConfig->EcanParametersB.EcanAdaptEnable;
687 MsgBuffer[24] = (DSP_WORD)
688 pChanConfig->EcanParametersB.EcanG165DetEnable;
689 MsgBuffer[25] = (DSP_WORD)
690 pChanConfig->EcanParametersB.EcanDblTalkThresh;
691 MsgBuffer[26] = (DSP_WORD)
692 pChanConfig->EcanParametersB.EcanNlpThreshold;
693 MsgBuffer[27] = (DSP_WORD)
694 pChanConfig->EcanParametersB.EcanNlpConv;
695 MsgBuffer[28] = (DSP_WORD)
696 pChanConfig->EcanParametersB.EcanNlpUnConv;
697 MsgBuffer[29] = (DSP_WORD)
698 pChanConfig->EcanParametersB.EcanNlpMaxSuppress;
699 MsgBuffer[30] = (DSP_WORD)
700 pChanConfig->EcanParametersB.EcanCngThreshold;
701 MsgBuffer[31] = (DSP_WORD)
702 pChanConfig->EcanParametersB.EcanAdaptLimit;
703 MsgBuffer[32] = (DSP_WORD)
704 pChanConfig->EcanParametersB.EcanCrossCorrLimit;
705 MsgBuffer[33] = (DSP_WORD)
706 pChanConfig->EcanParametersB.EcanNumFirSegments;
707 MsgBuffer[34] = (DSP_WORD)
708 pChanConfig->EcanParametersB.EcanFirSegmentLen;
709
710 MsgBuffer[35] = (DSP_WORD)
711 (
712 ((pChanConfig->EcanParametersB.EcanReconvergenceCheckEnable <<5) & 0x20) |
713 ((pChanConfig->EcanParametersA.EcanReconvergenceCheckEnable <<4) & 0x10) |
714 ((pChanConfig->EcanParametersB.EcanTandemOperationEnable <<3) & 0x8) |
715 ((pChanConfig->EcanParametersA.EcanTandemOperationEnable <<2) & 0x4) |
716 ((pChanConfig->EcanParametersB.EcanMixedFourWireMode << 1) & 0x2) |
717 (pChanConfig->EcanParametersA.EcanMixedFourWireMode & 1)
718 );
719 MsgBuffer[36] = (DSP_WORD)
720 pChanConfig->EcanParametersA.EcanMaxDoubleTalkThres;
721
722 MsgBuffer[37] = (DSP_WORD)
723 pChanConfig->EcanParametersB.EcanMaxDoubleTalkThres;
724
725 MsgBuffer[38] = (DSP_WORD)
726 pChanConfig->EcanParametersA.EcanSaturationLevel;
727 MsgBuffer[39] = (DSP_WORD)
728 pChanConfig->EcanParametersB.EcanSaturationLevel;
729 MsgBuffer[40] = (DSP_WORD)
730 pChanConfig->EcanParametersA.EcanNLPSaturationThreshold;
731 MsgBuffer[41] = (DSP_WORD)
732 pChanConfig->EcanParametersB.EcanNLPSaturationThreshold;
733 MsgLength = 84; /* byte number == 42*2 */
734 break;
735
736 /* PCM to Packet channel type. */
737 case tdmToTdmDebug:
738
739 MsgBuffer[2] = (DSP_WORD)
740 ((pChanConfig->PcmInPortA << 8) |
741 (pChanConfig->PcmInSlotA & 0xFF));
742 MsgBuffer[3] = (DSP_WORD)
743 ((pChanConfig->PcmOutPortA << 8) |
744 (pChanConfig->PcmOutSlotA & 0xFF));
745
746 MsgBuffer[4] = (DSP_WORD)
747 ((pChanConfig->PcmInPortB << 8) |
748 (pChanConfig->PcmInSlotB & 0xFF));
749 MsgBuffer[5] = (DSP_WORD)
750 ((pChanConfig->PcmOutPortB << 8) |
751 (pChanConfig->PcmOutSlotB & 0xFF));
752
753 MsgBuffer[6] = (DSP_WORD)
754 (
755 ((pChanConfig->FaxCngDetB << 11) & 0x0800) |
756 ((pChanConfig->FaxCngDetA << 10) & 0x0400) |
757 ((pChanConfig->MuteToneB << 9) & 0x0200) |
758 ((pChanConfig->MuteToneA << 8) & 0x0100) |
759 ((pChanConfig->FrameRate << 6) & 0x00C0) |
760 ((pChanConfig->ToneTypesB << 5) & 0x0020) |
761 ((pChanConfig->ToneTypesA << 4) & 0x0010) |
762 ((pChanConfig->SoftwareCompand & 3) << 2) |
763 (pChanConfig->EcanEnableB << 1) |
764 (pChanConfig->EcanEnableA & 1)
765 );
766
767 MsgBuffer[7] = (DSP_WORD)
768 pChanConfig->EcanParametersA.EcanTapLength;
769 MsgBuffer[8] = (DSP_WORD)
770 pChanConfig->EcanParametersA.EcanNlpType;
771 MsgBuffer[9] = (DSP_WORD)
772 pChanConfig->EcanParametersA.EcanAdaptEnable;
773 MsgBuffer[10] = (DSP_WORD)
774 pChanConfig->EcanParametersA.EcanG165DetEnable;
775 MsgBuffer[11] = (DSP_WORD)
776 pChanConfig->EcanParametersA.EcanDblTalkThresh;
777 MsgBuffer[12] = (DSP_WORD)
778 pChanConfig->EcanParametersA.EcanNlpThreshold;
779 MsgBuffer[13] = (DSP_WORD)
780 pChanConfig->EcanParametersA.EcanNlpConv;
781 MsgBuffer[14] = (DSP_WORD)
782 pChanConfig->EcanParametersA.EcanNlpUnConv;
783 MsgBuffer[15] = (DSP_WORD)
784 pChanConfig->EcanParametersA.EcanNlpMaxSuppress;
785
786 MsgBuffer[16] = (DSP_WORD)
787 pChanConfig->EcanParametersA.EcanCngThreshold;
788 MsgBuffer[17] = (DSP_WORD)
789 pChanConfig->EcanParametersA.EcanAdaptLimit;
790 MsgBuffer[18] = (DSP_WORD)
791 pChanConfig->EcanParametersA.EcanCrossCorrLimit;
792 MsgBuffer[19] = (DSP_WORD)
793 pChanConfig->EcanParametersA.EcanNumFirSegments;
794 MsgBuffer[20] = (DSP_WORD)
795 pChanConfig->EcanParametersA.EcanFirSegmentLen;
796
797 MsgBuffer[21] = (DSP_WORD)
798 pChanConfig->EcanParametersB.EcanTapLength;
799 MsgBuffer[22] = (DSP_WORD)
800 pChanConfig->EcanParametersB.EcanNlpType;
801 MsgBuffer[23] = (DSP_WORD)
802 pChanConfig->EcanParametersB.EcanAdaptEnable;
803 MsgBuffer[24] = (DSP_WORD)
804 pChanConfig->EcanParametersB.EcanG165DetEnable;
805 MsgBuffer[25] = (DSP_WORD)
806 pChanConfig->EcanParametersB.EcanDblTalkThresh;
807 MsgBuffer[26] = (DSP_WORD)
808 pChanConfig->EcanParametersB.EcanNlpThreshold;
809 MsgBuffer[27] = (DSP_WORD)
810 pChanConfig->EcanParametersB.EcanNlpConv;
811 MsgBuffer[28] = (DSP_WORD)
812 pChanConfig->EcanParametersB.EcanNlpUnConv;
813 MsgBuffer[29] = (DSP_WORD)
814 pChanConfig->EcanParametersB.EcanNlpMaxSuppress;
815 MsgBuffer[30] = (DSP_WORD)
816 pChanConfig->EcanParametersB.EcanCngThreshold;
817 MsgBuffer[31] = (DSP_WORD)
818 pChanConfig->EcanParametersB.EcanAdaptLimit;
819 MsgBuffer[32] = (DSP_WORD)
820 pChanConfig->EcanParametersB.EcanCrossCorrLimit;
821 MsgBuffer[33] = (DSP_WORD)
822 pChanConfig->EcanParametersB.EcanNumFirSegments;
823 MsgBuffer[34] = (DSP_WORD)
824 pChanConfig->EcanParametersB.EcanFirSegmentLen;
825
826 MsgBuffer[35] = (DSP_WORD)
827 (
828 ((pChanConfig->EcanParametersB.EcanReconvergenceCheckEnable << 5) & 0x20) |
829 ((pChanConfig->EcanParametersA.EcanReconvergenceCheckEnable << 4) & 0x10) |
830 ((pChanConfig->EcanParametersB.EcanTandemOperationEnable << 3) & 0x8) |
831 ((pChanConfig->EcanParametersA.EcanTandemOperationEnable << 2) & 0x4) |
832 ((pChanConfig->EcanParametersB.EcanMixedFourWireMode << 1) & 0x2) |
833 (pChanConfig->EcanParametersA.EcanMixedFourWireMode & 1)
834 );
835 MsgBuffer[36] = (DSP_WORD)
836 pChanConfig->EcanParametersA.EcanMaxDoubleTalkThres;
837
838 MsgBuffer[37] = (DSP_WORD)
839 pChanConfig->EcanParametersB.EcanMaxDoubleTalkThres;
840
841 MsgBuffer[38] = (DSP_WORD)
842 pChanConfig->EcanParametersA.EcanSaturationLevel;
843 MsgBuffer[39] = (DSP_WORD)
844 pChanConfig->EcanParametersB.EcanSaturationLevel;
845 MsgBuffer[40] = (DSP_WORD)
846 pChanConfig->EcanParametersA.EcanNLPSaturationThreshold;
847 MsgBuffer[41] = (DSP_WORD)
848 pChanConfig->EcanParametersB.EcanNLPSaturationThreshold;
849 MsgBuffer[42] = (DSP_WORD)
850 pChanConfig->ChannelId_tobe_Debug;
851
852 MsgLength = 86; /* byte number == 43*2 */
853 break;
854
855 /* Unknown (invalid) channel type. */
856 default:
857 *pStatus = Cc_InvalidChannelType;
858 return (CcsParmError);
859 }
860
861 MsgBuffer[0] = MSG_CONFIGURE_CHANNEL << 8;
862 MsgBuffer[1] = (DSP_WORD) ((ChannelId << 8) | (ChannelType & 0xFF));
863
864 /* Attempt to send the Configure Channel message to the DSP and receive it's
865 reply. */
866 if (!TransactCmd(DspId, MsgBuffer, MsgLength, MSG_CONFIG_CHAN_REPLY, 4, 1,
867 (DSP_WORD) ChannelId))
868 return (CcsDspCommFailure);
869
870 /* Return with an indication of success or failure based on the return
871 status in the reply message. */
872 *pStatus = (GPAK_ChannelConfigStat_t) (MsgBuffer[1] & 0xFF);
873 if (*pStatus == Cc_Success)
874 return (CcsSuccess);
875 else
876 return (CcsParmError);
877 }
878 EXPORT_SYMBOL(gpakConfigureChannel);
879
880 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
881 * gpakTearDownChannel - Tear Down a DSP's Channel.
882 *
883 * FUNCTION
884 * This function tears down a DSP's Channel.
885 *
886 * RETURNS
887 * Status code indicating success or a specific error.
888 *
889 */
890 gpakTearDownStatus_t gpakTearDownChannel(
891 unsigned short int DspId, /* DSP Id (0 to MaxDSPCores-1) */
892 unsigned short int ChannelId, /* Channel Id (0 to MaxChannels-1) */
893 GPAK_TearDownChanStat_t *pStatus /* pointer to Tear Down Status */
894 )
895 {
896 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
897
898 /* Make sure the DSP Id is valid. */
899 if (DspId >= MAX_DSP_CORES)
900 return (TdsInvalidDsp);
901
902 /* Make sure the Channel Id is valid. */
903 if (ChannelId >= MaxChannels[DspId])
904 return (TdsInvalidChannel);
905
906 /* Build the Tear Down Channel message. */
907 MsgBuffer[0] = MSG_TEAR_DOWN_CHANNEL << 8;
908 MsgBuffer[1] = (DSP_WORD) (ChannelId << 8);
909
910 /* Attempt to send the Tear Down Channel message to the DSP and receive it's
911 reply. */
912 if (!TransactCmd(DspId, MsgBuffer, 3, MSG_TEAR_DOWN_REPLY, 4, 1,
913 (DSP_WORD) ChannelId))
914 return (TdsDspCommFailure);
915
916 /* Return with an indication of success or failure based on the return
917 status in the reply message. */
918 *pStatus = (GPAK_TearDownChanStat_t) (MsgBuffer[1] & 0xFF);
919 if (*pStatus == Td_Success)
920 return (TdsSuccess);
921 else
922 return (TdsError);
923 }
924
925 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
926 * gpakAlgControl - Control an Algorithm.
927 *
928 * FUNCTION
929 * This function controls an Algorithm
930 *
931 * RETURNS
932 * Status code indicating success or a specific error.
933 *
934 */
935 gpakAlgControlStat_t gpakAlgControl(
936 unsigned short int DspId, // DSP identifier
937 unsigned short int ChannelId, // channel identifier
938 GpakAlgCtrl_t ControlCode, // algorithm control code
939 GPAK_AlgControlStat_t *pStatus // pointer to return status
940 )
941 {
942 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
943
944 /* Make sure the DSP Id is valid. */
945 if (DspId >= MAX_DSP_CORES)
946 return (AcInvalidDsp);
947
948 /* Make sure the Channel Id is valid. */
949 if (ChannelId >= MaxChannels[DspId])
950 return (AcInvalidChannel);
951
952 MsgBuffer[0] = MSG_ALG_CONTROL << 8;
953 MsgBuffer[1] = (DSP_WORD) ((ChannelId << 8) | (ControlCode & 0xFF));
954
955 /* Attempt to send the Tear Down Channel message to the DSP and receive it's
956 reply. */
957 //need_reply_len;
958 if (!TransactCmd(DspId, MsgBuffer, 4, MSG_ALG_CONTROL_REPLY, 4, 1,
959 (DSP_WORD) ChannelId))
960 return (AcDspCommFailure);
961
962 /* Return with an indication of success or failure based on the return
963 status in the reply message. */
964 *pStatus = (GPAK_AlgControlStat_t) (MsgBuffer[1] & 0xFF);
965 if (*pStatus == Ac_Success)
966 return (AcSuccess);
967 else
968 return (AcParmError);
969
970 }
971 EXPORT_SYMBOL(gpakAlgControl);
972
973 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
974 * gpakReadEventFIFOMessage - read from the event fifo
975 *
976 * FUNCTION
977 * This function reads a single event from the event fifo if one is available
978 *
979 * RETURNS
980 * Status code indicating success or a specific error.
981 *
982 * Notes: This function should be called in a loop until the return status
983 * indicates that the fifo is empty.
984 *
985 * If the event code equals "EventLoopbackTeardownComplete", then the
986 * contents of *pChannelId hold the coderBlockId that was assigned to
987 * the loopback coder that was torn down.
988 */
989 gpakReadEventFIFOMessageStat_t gpakReadEventFIFOMessage(
990 unsigned short int DspId, // DSP identifier
991 unsigned short int *pChannelId, // pointer to channel identifier
992 GpakAsyncEventCode_t *pEventCode, // pointer to Event Code
993 GpakAsyncEventData_t *pEventData // pointer to Event Data Struct
994 )
995 {
996 DSP_WORD WordBuffer[WORD_BUFFER_SIZE]; /* DSP words buffer */
997 GpakAsyncEventCode_t EventCode; /* DSP's event code */
998 DSP_WORD EventDataLength; /* Length of event to read */
999 DSP_WORD ChannelId; /* DSP's channel Id */
1000 DSP_ADDRESS EventInfoAddress; /* address of EventFIFO info structure */
1001 DSP_ADDRESS BufrBaseAddress; /* base address of EventFIFO buffer */
1002 DSP_ADDRESS BufrLastAddress; /* last address of EventFIFO buffer */
1003 DSP_ADDRESS TakeAddress; /* current take address in fifo buffer */
1004 DSP_WORD BufrSize; /* size (in words) of event FIFO buffer */
1005 DSP_WORD PutIndex; /* event fifo put index */
1006 DSP_WORD TakeIndex; /* event fifo take index */
1007 DSP_WORD WordsReady; /* number words ready for read out of event fifo */
1008 DSP_WORD EventError; /* flag indicating error with event fifo msg */
1009
1010 /* Make sure the DSP Id is valid. */
1011 if (DspId >= MAX_DSP_CORES)
1012 return (RefInvalidDsp);
1013
1014 /* Lock access to the DSP. */
1015 gpakLockAccess(DspId);
1016
1017 /* Check if the DSP was reset and is ready. */
1018 if (CheckDspReset(DspId) == -1)
1019 {
1020 gpakUnlockAccess(DspId);
1021 return (RefDspCommFailure);
1022 }
1023
1024 /* Check if an event message is ready in the DSP. */
1025 EventInfoAddress = pEventFifoAddress[DspId];
1026 gpakReadDspMemory(DspId, EventInfoAddress, CIRC_BUFFER_INFO_STRUCT_SIZE,
1027 WordBuffer);
1028 RECONSTRUCT_LONGWORD(BufrBaseAddress, ((DSP_WORD *)&WordBuffer[CB_BUFR_BASE]));
1029 BufrSize = WordBuffer[CB_BUFR_SIZE];
1030 PutIndex = WordBuffer[CB_BUFR_PUT_INDEX];
1031 TakeIndex = WordBuffer[CB_BUFR_TAKE_INDEX];
1032 if (PutIndex >= TakeIndex)
1033 WordsReady = PutIndex - TakeIndex;
1034 else
1035 WordsReady = PutIndex + BufrSize - TakeIndex;
1036
1037 if (WordsReady < 2)
1038 {
1039 gpakUnlockAccess(DspId);
1040 return (RefNoEventAvail);
1041 }
1042
1043 /* Read the event header from the DSP's Event FIFO. */
1044 TakeAddress = BufrBaseAddress + TakeIndex;
1045 BufrLastAddress = BufrBaseAddress + BufrSize - 1;
1046 ReadCircBuffer(DspId, BufrBaseAddress, BufrLastAddress, &TakeAddress,
1047 WordBuffer, 2);
1048 TakeIndex += 2;
1049 if (TakeIndex >= BufrSize)
1050 TakeIndex -= BufrSize;
1051
1052 ChannelId = (WordBuffer[0] >> 8) & 0xFF;
1053 EventCode = (GpakAsyncEventCode_t)(WordBuffer[0] & 0xFF);
1054 EventDataLength = WordBuffer[1];
1055 EventError = 0;
1056
1057 switch (EventCode)
1058 {
1059 case EventToneDetect:
1060 if (EventDataLength > WORD_BUFFER_SIZE)
1061 {
1062 gpakUnlockAccess(DspId);
1063 return (RefInvalidEvent);
1064 }
1065 ReadCircBuffer(DspId, BufrBaseAddress, BufrLastAddress, &TakeAddress,
1066 WordBuffer, EventDataLength);
1067 pEventData->toneEvent.ToneCode = (GpakToneCodes_t)
1068 (WordBuffer[0] & 0xFF);
1069 pEventData->toneEvent.ToneDuration = WordBuffer[1];
1070 pEventData->toneEvent.Direction = WordBuffer[2];
1071 pEventData->toneEvent.DebugToneStatus = WordBuffer[3];
1072 TakeIndex += EventDataLength;
1073 if (TakeIndex >= BufrSize)
1074 TakeIndex -= BufrSize;
1075 if (EventDataLength != 4)
1076 EventError = 1;
1077 break;
1078
1079 default:
1080 EventError = 1;
1081 break;
1082 };
1083
1084 /* Update the Take index in the DSP's Packet Out buffer information. */
1085 gpakWriteDspMemory(DspId, EventInfoAddress + CB_BUFR_TAKE_INDEX, 1,
1086 &TakeIndex);
1087
1088 /* Unlock access to the DSP. */
1089 gpakUnlockAccess(DspId);
1090
1091 if (EventError)
1092 return(RefInvalidEvent);
1093
1094 *pChannelId = ChannelId;
1095 *pEventCode = EventCode;
1096 return(RefEventAvail);
1097
1098 }
1099
1100
1101 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1102 * gpakPingDsp - ping the DSP to see if it's alive
1103 *
1104 * FUNCTION
1105 * This function checks if the DSP is still communicating with the host
1106 * and returns the DSP SW version
1107 *
1108 * RETURNS
1109 * Status code indicating success or a specific error.
1110 */
1111 gpakPingDspStat_t gpakPingDsp(
1112 unsigned short int DspId, // DSP identifier
1113 unsigned short int *pDspSwVersion // DSP software version
1114 )
1115 {
1116 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1117 DSP_WORD DspStatus; /* DSP's reply status */
1118
1119 /* Make sure the DSP Id is valid. */
1120 if (DspId >= MAX_DSP_CORES)
1121 return (PngInvalidDsp);
1122
1123 /* send value of 1, DSP increments it */
1124 MsgBuffer[0] = (MSG_PING << 8);
1125
1126 /* Attempt to send the ping message to the DSP and receive it's
1127 reply. */
1128 if (!TransactCmd(DspId, MsgBuffer, 1, MSG_PING_REPLY, 6, 0, 0))
1129 return (PngDspCommFailure);
1130
1131 /* Return with an indication of success or failure based on the return
1132 status in the reply message. */
1133 DspStatus = (MsgBuffer[1] & 0xFF);
1134 if (DspStatus == 0)
1135 {
1136 *pDspSwVersion = MsgBuffer[2];
1137 return (PngSuccess);
1138 }
1139 else
1140 return (PngDspCommFailure);
1141 }
1142 EXPORT_SYMBOL(gpakPingDsp);
1143
1144 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1145 * gpakSerialTxFixedValue - transmit a fixed value on a timeslot
1146 *
1147 * FUNCTION
1148 * This function controls transmission of a fixed value out onto a serial
1149 * port's timeslot.
1150 *
1151 * RETURNS
1152 * Status code indicating success or a specific error.
1153 */
1154 gpakSerialTxFixedValueStat_t gpakSerialTxFixedValue(
1155 unsigned short int DspId, // DSP identifier
1156 unsigned short int ChannelId, // channel identifier
1157 GpakSerialPort_t PcmOutPort, // PCM Output Serial Port Id
1158 unsigned short int PcmOutSlot, // PCM Output Time Slot
1159 unsigned short int Value, // 16-bit value
1160 GpakActivation State // activation state
1161 )
1162 {
1163 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1164 DSP_WORD DspStatus; /* DSP's reply status */
1165
1166 /* Make sure the DSP Id is valid. */
1167 if (DspId >= MAX_DSP_CORES)
1168 return (TfvInvalidDsp);
1169
1170 /* Make sure the Channel Id is valid. */
1171 if (ChannelId >= MaxChannels[DspId])
1172 return (TfvInvalidChannel);
1173
1174
1175 /* Build the message. */
1176 MsgBuffer[0] = MSG_SERIAL_TXVAL << 8;
1177 MsgBuffer[1] = (DSP_WORD) ((ChannelId << 8) | (State & 0xFF));
1178 MsgBuffer[2] = (DSP_WORD) ((PcmOutPort << 8) | (PcmOutSlot & 0xFF));
1179 MsgBuffer[3] = (DSP_WORD) Value;
1180
1181 /* Attempt to send the message to the DSP and receive it's
1182 reply. */
1183 //need_reply_len;
1184 if (!TransactCmd(DspId, MsgBuffer, 8, MSG_SERIAL_TXVAL_REPLY, 4,
1185 1, ChannelId))
1186 return (TfvDspCommFailure);
1187
1188 /* Return with an indication of success or failure based on the return
1189 status in the reply message. */
1190 DspStatus = (MsgBuffer[1] & 0xFF);
1191 if (DspStatus == 0)
1192 return (TfvSuccess);
1193 else
1194 return (TfvDspCommFailure);
1195 }
1196
1197 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1198 * gpakControlTdmLoopBack - control a serial port's loopback state
1199 *
1200 * FUNCTION
1201 * This function enables/disables the tdm input to output looback mode on a
1202 * serial port
1203 *
1204 * RETURNS
1205 * Status code indicating success or a specific error.
1206 */
1207
1208 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
1209 gpakControlTdmLoopBackStat_t gpakControlTdmLoopBack(
1210 unsigned short int DspId, // DSP identifier
1211 GpakSerialPort_t SerialPort, // Serial Port Id
1212 GpakActivation LoopBackState // Loopback State
1213 )
1214 {
1215 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1216 DSP_WORD DspStatus; /* DSP's reply status */
1217
1218 /* Make sure the DSP Id is valid. */
1219 if (DspId >= MAX_DSP_CORES)
1220 return (ClbInvalidDsp);
1221
1222 /* Build the message. */
1223 MsgBuffer[0] = MSG_TDM_LOOPBACK << 8;
1224 MsgBuffer[1] = (DSP_WORD) ((SerialPort << 8) | (LoopBackState & 0xFF));
1225
1226 /* Attempt to send the message to the DSP and receive it's
1227 reply. */
1228 //need_reply_len;
1229 if (!TransactCmd(DspId, MsgBuffer, 4, MSG_TDM_LOOPBACK_REPLY, 4, 0, 0))
1230 return (ClbDspCommFailure);
1231
1232 /* Return with an indication of success or failure based on the return
1233 status in the reply message. */
1234 DspStatus = (MsgBuffer[1] & 0xFF);
1235 if (DspStatus == 0)
1236 return (ClbSuccess);
1237 else
1238 return (ClbDspCommFailure);
1239 }
1240
1241 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1242 * gpakReadCpuUsage - Read CPU usage statistics from a DSP.
1243 *
1244 * FUNCTION
1245 * This function reads the CPU usage statistics from a DSP's memory. The
1246 * average CPU usage in units of .1 percent are obtained for each of the frame
1247 * rates.
1248 *
1249 * RETURNS
1250 * Status code indicating success or a specific error.
1251 *
1252 */
1253 gpakReadCpuUsageStat_t gpakReadCpuUsage(
1254 unsigned short int DspId, // Dsp Identifier
1255 unsigned short int *pPeakUsage, // pointer to peak usage variable
1256 unsigned short int *pPrev1SecPeakUsage // peak usage over previous 1 second
1257 )
1258 {
1259 DSP_WORD ReadBuffer[2]; /* DSP read buffer */
1260
1261 /* Make sure the DSP Id is valid. */
1262 if (DspId >= MAX_DSP_CORES)
1263 return (RcuInvalidDsp);
1264
1265 /* Lock access to the DSP. */
1266 gpakLockAccess(DspId);
1267
1268 /* Check if the DSP was reset and is ready. */
1269 if (CheckDspReset(DspId) == -1)
1270 return (RcuDspCommFailure);
1271
1272 /* Read the CPU Usage statistics from the DSP. */
1273 gpakReadDspMemory(DspId, pDspIfBlk[DspId] + CPU_USAGE_OFFSET, 2,
1274 ReadBuffer);
1275
1276 /* Unlock access to the DSP. */
1277 gpakUnlockAccess(DspId);
1278
1279 /* Store the usage statistics in the specified variables. */
1280 *pPrev1SecPeakUsage = ReadBuffer[0];
1281 *pPeakUsage = ReadBuffer[1];
1282
1283 /* Return with an indication the usage staistics were read successfully. */
1284 return (RcuSuccess);
1285 }
1286
1287 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1288 * gpakResetCpuUsageStats - reset the cpu usage statistics
1289 *
1290 * FUNCTION
1291 * This function resets the cpu utilization statistics
1292 *
1293 * RETURNS
1294 * Status code indicating success or a specific error.
1295 */
1296 gpakResetCpuUsageStat_t gpakResetCpuUsageStats(
1297 unsigned short int DspId // DSP identifier
1298 )
1299 {
1300 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1301 DSP_WORD DspStatus; /* DSP's reply status */
1302
1303 /* Make sure the DSP Id is valid. */
1304 if (DspId >= MAX_DSP_CORES)
1305 return (RstcInvalidDsp);
1306
1307 MsgBuffer[0] = (MSG_RESET_USAGE_STATS << 8);
1308
1309 /* Attempt to send the message to the DSP and receive it's reply. */
1310 //need_reply_len;
1311 if (!TransactCmd(DspId, MsgBuffer, 2, MSG_RESET_USAGE_STATS_REPLY, 4, 0, 0))
1312 return (RstcDspCommFailure);
1313
1314 /* Return with an indication of success or failure based on the return
1315 status in the reply message. */
1316 DspStatus = (MsgBuffer[1] & 0xFF);
1317 if (DspStatus == 0)
1318 return (RstcSuccess);
1319 else
1320 return (RstcDspCommFailure);
1321 }
1322
1323 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1324 * gpakReadFramingStats
1325 *
1326 * FUNCTION
1327 * This function reads a DSP's framing interrupt statistics
1328 *
1329 * RETURNS
1330 * Status code indicating success or a specific error.
1331 */
1332 gpakReadFramingStatsStatus_t gpakReadFramingStats(
1333 unsigned short int DspId, // DSP identifier
1334 unsigned short int *pFramingError1Count, // port 1 Framing error count
1335 unsigned short int *pFramingError2Count, // port 2 Framing error count
1336 unsigned short int *pFramingError3Count, // port 3 Framing error count
1337 unsigned short int *pDmaStopErrorCount, // DMA-stoppage error count
1338 unsigned short int *pDmaSlipStatsBuffer // DMA slips count
1339 )
1340 {
1341 DSP_WORD ReadBuffer[10]; /* DSP read buffer */
1342
1343 /* Make sure the DSP Id is valid. */
1344 if (DspId >= MAX_DSP_CORES)
1345 return (RfsInvalidDsp);
1346
1347 /* Lock access to the DSP. */
1348 gpakLockAccess(DspId);
1349
1350 /* Check if the DSP was reset and is ready. */
1351 if (CheckDspReset(DspId) == -1)
1352 return (RfsDspCommFailure);
1353
1354 /* Read the framing interrupt statistics from the DSP. */
1355 gpakReadDspMemory(DspId, pDspIfBlk[DspId] + FRAMING_STATS_OFFSET, 10,
1356 ReadBuffer);
1357
1358 /* Unlock access to the DSP. */
1359 gpakUnlockAccess(DspId);
1360
1361 /* Store the framing statistics in the specified variables. */
1362 *pFramingError1Count = ReadBuffer[0];
1363 *pFramingError2Count = ReadBuffer[1];
1364 *pFramingError3Count = ReadBuffer[2];
1365 *pDmaStopErrorCount = ReadBuffer[3];
1366
1367 if (pDmaSlipStatsBuffer != NULL) {
1368 /* If users want to get the DMA slips count */
1369 pDmaSlipStatsBuffer[0] = ReadBuffer[4];
1370 pDmaSlipStatsBuffer[1] = ReadBuffer[5];
1371 pDmaSlipStatsBuffer[2] = ReadBuffer[6];
1372 pDmaSlipStatsBuffer[3] = ReadBuffer[7];
1373 pDmaSlipStatsBuffer[4] = ReadBuffer[8];
1374 pDmaSlipStatsBuffer[5] = ReadBuffer[9];
1375 }
1376 /* Return with an indication the statistics were read successfully. */
1377 return (RfsSuccess);
1378 }
1379
1380 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1381 * gpakResetFramingStats - reset a DSP's framing interrupt statistics
1382 *
1383 * FUNCTION
1384 * This function resets a DSP's framing interrupt statistics
1385 *
1386 * RETURNS
1387 * Status code indicating success or a specific error.
1388 */
1389 gpakResetFramingStatsStatus_t gpakResetFramingStats(
1390 unsigned short int DspId // DSP identifier
1391 )
1392 {
1393 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1394 DSP_WORD DspStatus; /* DSP's reply status */
1395
1396 /* Make sure the DSP Id is valid. */
1397 if (DspId >= MAX_DSP_CORES)
1398 return (RstfInvalidDsp);
1399
1400 MsgBuffer[0] = (MSG_RESET_FRAME_STATS << 8);
1401
1402 /* Attempt to send the message to the DSP and receive it's reply. */
1403 //need_reply_len;
1404 if (!TransactCmd(DspId, MsgBuffer, 2, MSG_RESET_FRAME_STATS_REPLY, 4, 0, 0))
1405 return (RstfDspCommFailure);
1406
1407 /* Return with an indication of success or failure based on the return
1408 status in the reply message. */
1409 DspStatus = (MsgBuffer[1] & 0xFF);
1410 if (DspStatus == 0)
1411 return (RstfSuccess);
1412 else
1413 return (RstfDspCommFailure);
1414 }
1415
1416 /*
1417 * gpakDownloadDsp - Download a DSP's Program and initialized Data memory.
1418 *
1419 * FUNCTION
1420 * This function reads a DSP's Program and Data memory image from the
1421 * specified file and writes the image to the DSP's memory.
1422 *
1423 * RETURNS
1424 * Status code indicating success or a specific error.
1425 *
1426 */
1427 gpakDownloadStatus_t gpakDownloadDsp(
1428 unsigned short DspId, /* DSP Identifier (0 to MaxDSPCores-1) */
1429 GPAK_FILE_ID FileId /* G.PAK Download File Identifier */
1430 )
1431 {
1432 gpakDownloadStatus_t RetStatus; /* function return status */
1433 int NumRead; /* number of file bytes read */
1434 DSP_ADDRESS Address; /* DSP address */
1435 unsigned int WordCount; /* number of words in record */
1436 unsigned int NumWords; /* number of words to read/write */
1437 unsigned int i; /* loop index / counter */
1438 unsigned int j; /* loop index */
1439
1440 /* Make sure the DSP Id is valid. */
1441 if (DspId >= MAX_DSP_CORES)
1442 return (GdlInvalidDsp);
1443
1444 /* Lock access to the DSP. */
1445 gpakLockAccess(DspId);
1446
1447 RetStatus = GdlSuccess;
1448 while (RetStatus == GdlSuccess)
1449 {
1450
1451 /* Read a record header from the file. */
1452 NumRead = gpakReadFile(FileId, DlByteBufr, 6);
1453 if (NumRead == -1)
1454 {
1455 RetStatus = GdlFileReadError;
1456 break;
1457 }
1458 if (NumRead != 6)
1459 {
1460 RetStatus = GdlInvalidFile;
1461 break;
1462 }
1463 Address = (((DSP_ADDRESS) DlByteBufr[1]) << 16) |
1464 (((DSP_ADDRESS) DlByteBufr[2]) << 8) |
1465 ((DSP_ADDRESS) DlByteBufr[3]);
1466 WordCount = (((unsigned int) DlByteBufr[4]) << 8) |
1467 ((unsigned int) DlByteBufr[5]);
1468
1469 /* Check for the End Of File record. */
1470 if (DlByteBufr[0] == 0xFF)
1471 break;
1472
1473 /* Verify the record is for a valid memory type. */
1474 if ((DlByteBufr[0] != 0x00) && (DlByteBufr[0] != 0x01))
1475 {
1476 RetStatus = GdlInvalidFile;
1477 break;
1478 }
1479
1480 /* Read a block of words at a time from the file and write to the
1481 DSP's memory .*/
1482 while (WordCount != 0)
1483 {
1484 if (WordCount < DOWNLOAD_BLOCK_SIZE)
1485 NumWords = WordCount;
1486 else
1487 NumWords = DOWNLOAD_BLOCK_SIZE;
1488 WordCount -= NumWords;
1489 NumRead = gpakReadFile(FileId, DlByteBufr, NumWords * 2);
1490 if (NumRead == -1)
1491 {
1492 RetStatus = GdlFileReadError;
1493 break;
1494 }
1495 if (NumRead != (NumWords * 2))
1496 {
1497 RetStatus = GdlInvalidFile;
1498 break;
1499 }
1500 for (i = 0, j = 0; i < NumWords; i++, j += 2)
1501 DlWordBufr[i] = (((DSP_WORD) DlByteBufr[j]) << 8) |
1502 ((DSP_WORD) DlByteBufr[j + 1]);
1503 gpakWriteDspMemory(DspId, Address, NumWords, DlWordBufr);
1504 Address += ((DSP_ADDRESS) NumWords);
1505 }
1506 }
1507
1508 /* Unlock access to the DSP. */
1509 gpakUnlockAccess(DspId);
1510
1511 /* Return with an indication of success or failure. */
1512 return (RetStatus);
1513 }
1514
1515 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1516 * gpakReadCpuUsage - Read CPU usage statistics from a DSP.
1517 *
1518 * FUNCTION
1519 * This function reads the memory map register section of DSP memory.
1520 *
1521 * RETURNS
1522 * Status code indicating success or a specific error.
1523 *
1524 */
1525 gpakReadDSPMemoryStat_t gpakReadDSPMemoryMap(
1526 unsigned short int DspId, // Dsp Identifier
1527 unsigned short int *pDest, // Buffer on host to hold DSP memory map
1528 DSP_ADDRESS BufrBaseAddress, // DSP memory users want to read out
1529 unsigned short int MemoryLength_Word16 // Length of memory section read out, unit is 16-bit word
1530 )
1531 {
1532 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1533 DSP_WORD DspStatus; /* DSP reply's status */
1534 int i; /* loop index / counter */
1535
1536
1537 /* Make sure the DSP Id is valid. */
1538 if (DspId >= MAX_DSP_CORES)
1539 return (RmmInvalidDsp);
1540
1541 /* Verify the message buffer is large enough */
1542 if (MSG_BUFFER_SIZE < MemoryLength_Word16 )
1543 return (RmmSizeTooBig);
1544
1545 MsgBuffer[0] = MSG_READ_DSP_MEMORY << 8;
1546 MsgBuffer[1] = (DSP_WORD) ((BufrBaseAddress >> 16) & 0xFFFF);
1547 MsgBuffer[2] = (DSP_WORD) (BufrBaseAddress & 0xFFFF);
1548 MsgBuffer[3] = (DSP_WORD) MemoryLength_Word16;
1549
1550 /* Attempt to send the Read memory section message to the DSP and receive it's
1551 reply. */
1552 //need_reply_len;
1553 if (!TransactCmd(DspId, MsgBuffer, 8, MSG_READ_DSP_MEMORY_REPLY,
1554 (MemoryLength_Word16+2)*2, 0, 0) )
1555 return (RmmInvalidAddress);
1556
1557 /* Return with an indication of success or failure based on the return
1558 status in the reply message. */
1559 DspStatus = (MsgBuffer[1] & 0xFF);
1560 if (DspStatus != 0)
1561 return (RmmFailure);
1562
1563 for (i = 0; i < MemoryLength_Word16; i++)
1564 pDest[i] = (short int) MsgBuffer[2 + i];
1565
1566
1567 return (RmmSuccess);
1568 }
1569
1570 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1571 * gpakAccessGPIO - change Direction/read/write the GPIO on DSP
1572 *
1573 * FUNCTION
1574 * This function read/write GPIO and change the GPIO direction
1575 *
1576 *
1577 * RETURNS
1578 * Status code indicating success or a specific error.
1579 */
1580 gpakAccessGPIOStat_t gpakAccessGPIO(
1581 unsigned short int DspId, // DSP identifier
1582 GpakGPIOCotrol_t gpakControlGPIO,// select oeration, changeDIR/write/read
1583 unsigned short int *pGPIOValue // DSP software version
1584 )
1585 {
1586 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1587 DSP_WORD DspStatus; /* DSP's reply status */
1588
1589 /* Make sure the DSP Id is valid. */
1590 if (DspId >= MAX_DSP_CORES)
1591 return (GPIOInvalidDsp);
1592
1593 /* send value of 1, DSP increments it */
1594 MsgBuffer[0] = (MSG_ACCESSGPIO << 8);
1595 MsgBuffer[1] = (DSP_WORD) ((gpakControlGPIO << 8) | (*pGPIOValue & 0xFF) );
1596 /* Attempt to send the ping message to the DSP and receive it's
1597 reply. */
1598 if (!TransactCmd(DspId, MsgBuffer, 4, MSG_ACCESSGPIO_REPLY, 6, 0, 0))
1599 return (GPIODspCommFailure);
1600
1601 /* Return with an indication of success or failure based on the return
1602 status in the reply message. */
1603 DspStatus = (MsgBuffer[1] & 0xFF);
1604 if (DspStatus == 0)
1605 {
1606 *pGPIOValue = MsgBuffer[2];
1607 return (GPIOSuccess);
1608 }
1609 else
1610 return (GPIODspCommFailure);
1611 }
1612
1613 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1614 * gpakWriteSystemParms - Write a DSP's System Parameters.
1615 *
1616 * FUNCTION
1617 * This function writes a DSP's System Parameters information.
1618 *
1619 * Note:
1620 * Or-together the desired bit-mask #defines that are listed below. Only
1621 * those algorithm parameters whose bit-mask is selected in the UpdateBits
1622 * function parameter will be updated.
1623 *
1624 * RETURNS
1625 * Status code indicating success or a specific error.
1626 *
1627 */
1628
1629 gpakWriteSysParmsStatus_t gpakWriteSystemParms(
1630 unsigned short int DspId, // DSP identifier
1631 GpakSystemParms_t *pSysParms, /* pointer to System Parms info var */
1632 unsigned short int UpdateBits, /* input: flags indicating which parms to update */
1633 GPAK_SysParmsStat_t *pStatus /* pointer to Write System Parms Status */
1634 )
1635 {
1636 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1637 DSP_WORD DspStatus; /* DSP's reply status */
1638
1639 memset(MsgBuffer, 0, sizeof(MsgBuffer));
1640
1641 /* Make sure the DSP Id is valid. */
1642 if (DspId >= MAX_DSP_CORES)
1643 return (WspInvalidDsp);
1644
1645 /* Build the Write System Parameters message. */
1646 MsgBuffer[0] = MSG_WRITE_SYS_PARMS << 8;
1647
1648 if (UpdateBits & DTMF_UPDATE_MASK)
1649 {
1650 MsgBuffer[1] |= DTMF_UPDATE_MASK;
1651 MsgBuffer[8] = (DSP_WORD) pSysParms->MinSigLevel;
1652 MsgBuffer[9] = (DSP_WORD) (pSysParms->FreqDeviation & 0xff);
1653 if (pSysParms->SNRFlag)
1654 MsgBuffer[9] |= (1<<8);
1655 }
1656
1657 MsgBuffer[10] = (DSP_WORD) 0;
1658 if (UpdateBits & DTMF_TWIST_UPDATE_MASK)
1659 {
1660 MsgBuffer[1] |= DTMF_TWIST_UPDATE_MASK;
1661 MsgBuffer[10] |= (DSP_WORD) (pSysParms->DtmfFwdTwist & 0x000f);
1662 MsgBuffer[10] |= (DSP_WORD) ((pSysParms->DtmfRevTwist << 4) & 0x00f0);
1663 }
1664
1665
1666 if (UpdateBits & DTMF_VALID_MASK)
1667 {
1668 MsgBuffer[1] |= DTMF_VALID_MASK;
1669 MsgBuffer[11] = (DSP_WORD) (pSysParms->DtmfValidityMask & 0x00ff);
1670 }
1671
1672 /* Attempt to send the ping message to the DSP and receive it's
1673 reply. */
1674 if (!TransactCmd(DspId, MsgBuffer, 24, MSG_WRITE_SYS_PARMS_REPLY, 6, 0, 0))
1675 return (WspDspCommFailure);
1676
1677 /* Return with an indication of success or failure based on the return
1678 status in the reply message. */
1679 *pStatus = (GPAK_SysParmsStat_t) (MsgBuffer[2] );
1680
1681 DspStatus = (MsgBuffer[1] & 0xFF);
1682 if (DspStatus == 0)
1683 return (WspSuccess);
1684 else
1685 return (WspDspCommFailure);
1686 }
1687
1688 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1689 * gpakReadSystemParms - Read a DSP's System Parameters.
1690 *
1691 * FUNCTION
1692 * This function reads a DSP's System Parameters information.
1693 *
1694 * RETURNS
1695 * Status code indicating success or a specific error.
1696 *
1697 */
1698 gpakReadSysParmsStatus_t gpakReadSystemParms(
1699 unsigned short int DspId, // DSP identifier
1700 GpakSystemParms_t *pSysParms /* pointer to System Parms info var */
1701 )
1702 {
1703
1704 DSP_WORD MsgBuffer[MSG_BUFFER_SIZE]; /* message buffer */
1705
1706 /* Make sure the DSP Id is valid. */
1707 if (DspId >= MAX_DSP_CORES)
1708 return (RspInvalidDsp);
1709
1710 /* Build the Read System Parameters message. */
1711 MsgBuffer[0] = MSG_READ_SYS_PARMS << 8;
1712
1713 /* Attempt to send the ping message to the DSP and receive it's
1714 reply. */
1715 if (!TransactCmd(DspId, MsgBuffer, 2, MSG_READ_SYS_PARMS_REPLY, 22, 0, 0))
1716 return (RspDspCommFailure);
1717
1718 /* Extract the System Parameters information from the message. */
1719 pSysParms->DtmfValidityMask = (short int)(MsgBuffer[7]) ;
1720
1721 pSysParms->MinSigLevel = (short int)MsgBuffer[8];
1722 pSysParms->SNRFlag = (short int)((MsgBuffer[9]>>8) & 0x1);
1723 pSysParms->FreqDeviation = (short int)(MsgBuffer[9] & 0xff);
1724 pSysParms->DtmfFwdTwist = (short int)MsgBuffer[10] & 0x000f;
1725 pSysParms->DtmfRevTwist = (short int)(MsgBuffer[10] >> 4) & 0x000f;
1726
1727 /* Return with an indication that System Parameters info was obtained. */
1728 return (RspSuccess);
1729 }