cwcdma.asp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // Copyright(c) by Benny Sjostrand (benny@hostmobility.com)
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. //
  18. //
  19. // This code runs inside the DSP (cs4610, cs4612, cs4624, or cs4630),
  20. // to compile it you need a tool named SPASM 3.0 and DSP code owned by
  21. // Cirrus Logic(R). The SPASM program will generate a object file (cwcdma.osp),
  22. // the "ospparser" tool will genereate the cwcdma.h file it's included from
  23. // the cs46xx_lib.c file.
  24. //
  25. //
  26. // The purpose of this code is very simple: make it possible to tranfser
  27. // the samples 'as they are' with no alteration from a PCMreader SCB (DMA from host)
  28. // to any other SCB. This is useful for AC3 throug SPDIF. SRC (source rate converters)
  29. // task always alters the samples in some how, however it's from 48khz -> 48khz. The
  30. // alterations are not audible, but AC3 wont work.
  31. //
  32. // ...
  33. // |
  34. // +---------------+
  35. // | AsynchFGTxSCB |
  36. // +---------------+
  37. // |
  38. // subListPtr
  39. // |
  40. // +--------------+
  41. // | DMAReader |
  42. // +--------------+
  43. // |
  44. // subListPtr
  45. // |
  46. // +-------------+
  47. // | PCMReader |
  48. // +-------------+
  49. // (DMA from host)
  50. //
  51. struct dmaSCB
  52. {
  53. long dma_reserved1[3];
  54. short dma_reserved2:dma_outBufPtr;
  55. short dma_unused1:dma_unused2;
  56. long dma_reserved3[4];
  57. short dma_subListPtr:dma_nextSCB;
  58. short dma_SPBptr:dma_entryPoint;
  59. long dma_strmRsConfig;
  60. long dma_strmBufPtr;
  61. long dma_reserved4;
  62. VolumeControl s2m_volume;
  63. };
  64. #export DMAReader
  65. void DMAReader()
  66. {
  67. execChild();
  68. r2 = r0->dma_subListPtr;
  69. r1 = r0->nextSCB;
  70. rsConfig01 = r2->strmRsConfig;
  71. // Load rsConfig for input buffer
  72. rsDMA01 = r2->basicReq.daw, , tb = Z(0 - rf);
  73. // Load rsDMA in case input buffer is a DMA buffer Test to see if there is any data to transfer
  74. if (tb) goto execSibling_2ind1 after {
  75. r5 = rf + (-1);
  76. r6 = r1->dma_entryPoint; // r6 = entry point of sibling task
  77. r1 = r1->dma_SPBptr, // r1 = pointer to sibling task's SPB
  78. , ind = r6; // Load entry point of sibling task
  79. }
  80. rsConfig23 = r0->dma_strmRsConfig;
  81. // Load rsConfig for output buffer (never a DMA buffer)
  82. r4 = r0->dma_outBufPtr;
  83. rsa0 = r2->strmBufPtr;
  84. // rsa0 = input buffer pointer
  85. for (i = r5; i >= 0; --i)
  86. after {
  87. rsa2 = r4;
  88. // rsa2 = output buffer pointer
  89. nop;
  90. nop;
  91. }
  92. //*****************************
  93. // TODO: cycles to this point *
  94. //*****************************
  95. {
  96. acc0 = (rsd0 = *rsa0++1);
  97. // get sample
  98. nop; // Those "nop"'s are really uggly, but there's
  99. nop; // something with DSP's pipelines which I don't
  100. nop; // understand, resulting this code to fail without
  101. // having those "nop"'s (Benny)
  102. rsa0?reqDMA = r2;
  103. // Trigger DMA transfer on input stream,
  104. // if needed to replenish input buffer
  105. nop;
  106. // Yet another magic "nop" to make stuff work
  107. ,,r98 = acc0 $+>> 0;
  108. // store sample in ALU
  109. nop;
  110. // latency on load register.
  111. // (this one is understandable)
  112. *rsa2++1 = r98;
  113. // store sample in output buffer
  114. nop; // The same story
  115. nop; // as above again ...
  116. nop;
  117. }
  118. // TODO: cycles per loop iteration
  119. r2->strmBufPtr = rsa0,, ;
  120. // Update the modified buffer pointers
  121. r4 = rsa2;
  122. // Load output pointer position into r4
  123. r2 = r0->nextSCB;
  124. // Sibling task
  125. goto execSibling_2ind1 // takes 6 cycles
  126. after {
  127. r98 = r2->thisSPB:entryPoint;
  128. // Load child routine entry and data address
  129. r1 = r9;
  130. // r9 is r2->thisSPB
  131. r0->dma_outBufPtr = r4,,
  132. // Store updated output buffer pointer
  133. ind = r8;
  134. // r8 is r2->entryPoint
  135. }
  136. }