GpakApi.c 63 KB

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