cwcdma.asp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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
  28. // SCB (DMA from host) to any other SCB. This is useful for AC3 through SPDIF.
  29. // SRC (source rate converters) task always alters the samples in somehow,
  30. // however it's from 48khz -> 48khz.
  31. // The alterations are not audible, but AC3 wont work.
  32. //
  33. // ...
  34. // |
  35. // +---------------+
  36. // | AsynchFGTxSCB |
  37. // +---------------+
  38. // |
  39. // subListPtr
  40. // |
  41. // +--------------+
  42. // | DMAReader |
  43. // +--------------+
  44. // |
  45. // subListPtr
  46. // |
  47. // +-------------+
  48. // | PCMReader |
  49. // +-------------+
  50. // (DMA from host)
  51. //
  52. struct dmaSCB
  53. {
  54. long dma_reserved1[3];
  55. short dma_reserved2:dma_outBufPtr;
  56. short dma_unused1:dma_unused2;
  57. long dma_reserved3[4];
  58. short dma_subListPtr:dma_nextSCB;
  59. short dma_SPBptr:dma_entryPoint;
  60. long dma_strmRsConfig;
  61. long dma_strmBufPtr;
  62. long dma_reserved4;
  63. VolumeControl s2m_volume;
  64. };
  65. #export DMAReader
  66. void DMAReader()
  67. {
  68. execChild();
  69. r2 = r0->dma_subListPtr;
  70. r1 = r0->nextSCB;
  71. rsConfig01 = r2->strmRsConfig;
  72. // Load rsConfig for input buffer
  73. rsDMA01 = r2->basicReq.daw, , tb = Z(0 - rf);
  74. // Load rsDMA in case input buffer is a DMA buffer Test to see if there is any data to transfer
  75. if (tb) goto execSibling_2ind1 after {
  76. r5 = rf + (-1);
  77. r6 = r1->dma_entryPoint; // r6 = entry point of sibling task
  78. r1 = r1->dma_SPBptr, // r1 = pointer to sibling task's SPB
  79. , ind = r6; // Load entry point of sibling task
  80. }
  81. rsConfig23 = r0->dma_strmRsConfig;
  82. // Load rsConfig for output buffer (never a DMA buffer)
  83. r4 = r0->dma_outBufPtr;
  84. rsa0 = r2->strmBufPtr;
  85. // rsa0 = input buffer pointer
  86. for (i = r5; i >= 0; --i)
  87. after {
  88. rsa2 = r4;
  89. // rsa2 = output buffer pointer
  90. nop;
  91. nop;
  92. }
  93. //*****************************
  94. // TODO: cycles to this point *
  95. //*****************************
  96. {
  97. acc0 = (rsd0 = *rsa0++1);
  98. // get sample
  99. nop; // Those "nop"'s are really uggly, but there's
  100. nop; // something with DSP's pipelines which I don't
  101. nop; // understand, resulting this code to fail without
  102. // having those "nop"'s (Benny)
  103. rsa0?reqDMA = r2;
  104. // Trigger DMA transfer on input stream,
  105. // if needed to replenish input buffer
  106. nop;
  107. // Yet another magic "nop" to make stuff work
  108. ,,r98 = acc0 $+>> 0;
  109. // store sample in ALU
  110. nop;
  111. // latency on load register.
  112. // (this one is understandable)
  113. *rsa2++1 = r98;
  114. // store sample in output buffer
  115. nop; // The same story
  116. nop; // as above again ...
  117. nop;
  118. }
  119. // TODO: cycles per loop iteration
  120. r2->strmBufPtr = rsa0,, ;
  121. // Update the modified buffer pointers
  122. r4 = rsa2;
  123. // Load output pointer position into r4
  124. r2 = r0->nextSCB;
  125. // Sibling task
  126. goto execSibling_2ind1 // takes 6 cycles
  127. after {
  128. r98 = r2->thisSPB:entryPoint;
  129. // Load child routine entry and data address
  130. r1 = r9;
  131. // r9 is r2->thisSPB
  132. r0->dma_outBufPtr = r4,,
  133. // Store updated output buffer pointer
  134. ind = r8;
  135. // r8 is r2->entryPoint
  136. }
  137. }