enctrace.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. --
  16. -- Description : Internal traces
  17. --
  18. ------------------------------------------------------------------------------*/
  19. /*------------------------------------------------------------------------------
  20. 1. Include headers
  21. ------------------------------------------------------------------------------*/
  22. #include <stdio.h>
  23. #include "enctrace.h"
  24. /*------------------------------------------------------------------------------
  25. 2. External compiler flags
  26. --------------------------------------------------------------------------------
  27. --------------------------------------------------------------------------------
  28. 3. Module defines
  29. ------------------------------------------------------------------------------*/
  30. static FILE *fileAsic = NULL;
  31. static FILE *filePreProcess = NULL;
  32. static FILE *fRegs = NULL;
  33. static FILE *fRecon = NULL;
  34. static FILE *fTrace = NULL;
  35. /*------------------------------------------------------------------------------
  36. 4. Local function prototypes
  37. ------------------------------------------------------------------------------*/
  38. void EncTraceCloseAll(void)
  39. {
  40. if(fileAsic != NULL)
  41. fclose(fileAsic);
  42. if(filePreProcess != NULL)
  43. fclose(filePreProcess);
  44. if(fRegs != NULL)
  45. fclose(fRegs);
  46. if(fRecon != NULL)
  47. fclose(fRecon);
  48. if(fTrace != NULL)
  49. fclose(fTrace);
  50. }
  51. /*------------------------------------------------------------------------------
  52. EncTraceAsic
  53. ------------------------------------------------------------------------------*/
  54. void EncTraceAsicParameters(asicData_s * asic)
  55. {
  56. if(fileAsic == NULL)
  57. fileAsic = fopen("sw_asic.trc", "w");
  58. if(fileAsic == NULL)
  59. {
  60. fprintf(stderr, "Unable to open trace file: asic.trc\n");
  61. return;
  62. }
  63. fprintf(fileAsic, "ASIC parameters:\n");
  64. fprintf(fileAsic, "Input lum bus: 0x%08x\n",
  65. (u32) asic->regs.inputLumBase);
  66. fprintf(fileAsic, "Input cb bus: 0x%08x\n",
  67. (u32) asic->regs.inputCbBase);
  68. fprintf(fileAsic, "Input cr bus: 0x%08x\n\n",
  69. (u32) asic->regs.inputCrBase);
  70. /*fprintf(fileAsic, "Internal image base W: 0x%08x\n", (u32)asic->internalImageBase.virtualAddress); */
  71. fprintf(fileAsic, "Encoding type: %6d\n", asic->regs.codingType);
  72. /*
  73. * fprintf(fileAsic, "Input endian mode: %6d\n",
  74. * asic->regs.inputEndianMode);
  75. * fprintf(fileAsic, "Input endian width: %6d\n",
  76. * asic->regs.inputEndianWidth);
  77. * fprintf(fileAsic, "Output endian width: %6d\n",
  78. * asic->regs.outputEndianWidth);
  79. */
  80. fprintf(fileAsic, "Mbs in row: %6d\n", asic->regs.mbsInRow);
  81. fprintf(fileAsic, "Mbs in col: %6d\n", asic->regs.mbsInCol);
  82. fprintf(fileAsic, "Input lum width: %6d\n", asic->regs.pixelsOnRow);
  83. fprintf(fileAsic, "Frame type: %6d\n",
  84. asic->regs.frameCodingType);
  85. fprintf(fileAsic, "QP: %6d\n", asic->regs.qp);
  86. fprintf(fileAsic, "Round control: %6d\n",
  87. asic->regs.roundingCtrl);
  88. /* fprintf(fileAsic, "MV SAD penalty: %6d\n", asic->regs.mvSadPenalty);
  89. fprintf(fileAsic, "Intra SAD penalty: %6d\n", asic->regs.intraSadPenalty);
  90. fprintf(fileAsic, "4MV SAD penalty: %6d\n", asic->regs.fourMvSadPenalty);
  91. */
  92. fprintf(fileAsic, "Burst size: %6d\n", ENC8290_BURST_LENGTH);
  93. }
  94. /*------------------------------------------------------------------------------
  95. EncTracePreProcess
  96. ------------------------------------------------------------------------------*/
  97. void EncTracePreProcess(preProcess_s * preProcess)
  98. {
  99. if(filePreProcess == NULL)
  100. filePreProcess = fopen("sw_preprocess.trc", "w");
  101. if(filePreProcess == NULL)
  102. {
  103. fprintf(stderr, "Unable to open trace file: preprocess.trc\n");
  104. return;
  105. }
  106. fprintf(filePreProcess, "Input width: %d\n", preProcess->lumWidthSrc);
  107. fprintf(filePreProcess, "Input height: %d\n", preProcess->lumHeightSrc);
  108. fprintf(filePreProcess, "Hor offset src: %d\n", preProcess->horOffsetSrc);
  109. fprintf(filePreProcess, "Ver offset src: %d\n", preProcess->verOffsetSrc);
  110. }
  111. /*------------------------------------------------------------------------------
  112. EncTraceRegs
  113. ------------------------------------------------------------------------------*/
  114. void EncTraceRegs(const void *ewl, u32 readWriteFlag, u32 mbNum)
  115. {
  116. u32 i;
  117. char RW = 'W';
  118. static i32 frame = 0;
  119. if(fRegs == NULL)
  120. fRegs = fopen("sw_reg.trc", "w");
  121. if(fRegs == NULL)
  122. fRegs = stderr;
  123. fprintf(fRegs, "pic=%d\n", frame);
  124. fprintf(fRegs, "mb=%d\n", mbNum);
  125. /* After frame is finished, registers are read */
  126. if (readWriteFlag)
  127. {
  128. RW = 'R';
  129. frame++;
  130. }
  131. /* Dump registers in same denali format as the system model */
  132. for(i = 0; i <= 0x17C; i += 4)
  133. if ((i != 0xA0) && (i != 0x38))
  134. fprintf(fRegs, "%c %08x/%08x\n", RW, i, EWLReadReg(ewl, i));
  135. /* Regs with enable bits last, force encoder enable high for frame start */
  136. fprintf(fRegs, "%c %08x/%08x\n", RW, 0xA0, EWLReadReg(ewl, 0xA0));
  137. fprintf(fRegs, "%c %08x/%08x\n", RW, 0x38,
  138. EWLReadReg(ewl, 0x38) | (readWriteFlag==0));
  139. fprintf(fRegs, "\n");
  140. /*fclose(fRegs);
  141. * fRegs = NULL; */
  142. }
  143. u32 SwapEndian(u32 tmp)
  144. {
  145. u32 swapped;
  146. swapped = tmp >> 24;
  147. swapped |= (tmp >> 8) & (0xFF00);
  148. swapped |= (tmp << 8) & (0xFF0000);
  149. swapped |= tmp << 24;
  150. return swapped;
  151. }
  152. /*------------------------------------------------------------------------------
  153. EncDumpRecon
  154. ------------------------------------------------------------------------------*/
  155. void EncDumpRecon(asicData_s * asic)
  156. {
  157. if(fRecon == NULL)
  158. fRecon = fopen("sw_recon_internal.yuv", "wb");
  159. if(fRecon)
  160. {
  161. u32 index;
  162. u32 size = asic->regs.mbsInCol * asic->regs.mbsInRow * 16 * 16;
  163. if(asic->regs.internalImageLumBaseW ==
  164. asic->internalImageLuma[0].busAddress)
  165. index = 0;
  166. else
  167. index = 1;
  168. {
  169. u32 *pTmp = asic->internalImageLuma[index].virtualAddress;
  170. fwrite(pTmp, 1, size, fRecon);
  171. }
  172. {
  173. u32 *pTmp = asic->internalImageChroma[index].virtualAddress;
  174. fwrite(pTmp, 1, size / 2, fRecon);
  175. }
  176. }
  177. }