hweval_zoran.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:30k
源码类别:

DVD

开发平台:

Others

  1. /*******************************************************************************
  2. * Copyright(c) Philips Consumer Electronics B.V. 2001
  3. * The attached material and the information contained therein is proprietary
  4. * to Philips and is issued only under strict confidentiality arrangements.
  5. * It shall not be used, reproduced, copied in whole or in part, adapted,
  6. * modified, or disseminated without a written license of Philips.           
  7. * It must be returned to Philips upon its first request.
  8. *
  9. *  Project:        SA-MP ( Super Audio Media Player )
  10. *  File %name:     hweval.c %
  11. *  %version:       5 %
  12. *  %date_modified: Thu Jul 18 14:22:09 2002 %
  13. *  %derived_by:    potm %
  14. *  Creation date:  Mon Apr 08 10:37:53 2002
  15. *  First author:   klerxm
  16. *
  17. *  Advanced Systems and Applications Lab - Eindhoven
  18. *
  19. *  Continuus %full_filespec: hweval.c~5:csrc:1 %
  20. *
  21. *  Description:    Source file of Furore2 hardware evaluation routines
  22. *
  23. * Change history:
  24. *
  25. * Rev  Date       Who      Comments
  26. * ---- ---------- -------- -----------------------------------------------------
  27. *   1  2002-04-02 klerxm   Initial version
  28. *   2  2002-05-27 klerxm   Solved problem in SDRAM test
  29. *   3  2002-07-18 klerxm   Enable capturing after engine has jumped
  30. *   4  2002-07-18 klerxm   Updated function descriptions
  31. *   5  2003-03-25 potm     Corrected atomic register access
  32. *   6  2003-06-25 potm     Rewritten for easier hw debugging
  33. *
  34. *******************************************************************************/
  35. /*******************************************************************************
  36. *                                Include Files
  37. *******************************************************************************/
  38. #include "config.h"
  39. /* This file is for SACD only.*/
  40. #if D_SUPPORT_SACD
  41. #include <embedded.h>
  42. #include "includesysdefs.h"
  43. #include "kernelker_api.h"
  44. #include "Playcoresampsamp_apm.h"
  45. #include "Playcoresampsamp_gen.h"
  46. #include "Playcorenav_sacdglue_test.h"
  47. #include "Playcorenav_sacdglue_be.h"
  48. #include "decoderlow_leveldec_ll_reg.h"
  49. #define UInt16 UINT16
  50. #define UInt32 UINT32
  51. #define SACD_Read16(adr) (*((UINT16*)(MK_FP(0x1000,adr))))
  52. #define SACD_Write16(adr,val) (*((UINT16*)(MK_FP(0x1000,adr))) = (val))
  53. #ifdef tr_printf
  54. #undef tr_printf
  55. #define tr_printf(msg) (printf ## msg)
  56. #endif
  57. #ifdef SACD_HW_EVAL
  58. extern UINT8 secondtest;
  59. #endif
  60. /*******************************************************************************
  61. *                               Macro Definitions
  62. *******************************************************************************/
  63. /*******************************************************************************
  64. * The following defines can be used to set the type of Basic Engine Interface
  65. * connected to the Furore2. A complete engine interface type consists of a
  66. * logical OR of each of the bitfields described below. (Note: For IIS types
  67. * bits 3 to 9 don't care)
  68. *
  69. * 2-0 Engine interface type
  70. * ------xx xxxxx000  Normal IIS mode
  71. * ------xx xxxxx001  Stopped clock IIS mode
  72. * -------- -----010  FEC interface
  73. * -------- -----100  UDE synchronous mode
  74. * -------- -----101  UDE asynchronous mode handshake to stop data
  75. * -------- -----111  UDE asynchronous mode handshake per byte
  76. *
  77. * 5-3 Input sync selection (not applicable for IIS modes)
  78. * -------- --000---  If sync is '0' then active sync
  79. * -------- --001---  If sync is '1' then active sync
  80. * -------- --010---  Edge from '0' to '1' indicates first byte of a sector
  81. * -------- --011---  Edge from '1' to '0' indicates first byte of a sector
  82. * -------- --100---  No sync at input. Furore2 will generate her own sync signal
  83. *                    every 2064 bytes
  84. * 6 Input data request (not applicable for IIS modes)
  85. * -------- -1------  If REQ output is '1' then Furore2 requests new input data
  86. * -------- -0------  If REQ output is '0' then Furore2 requests new input data
  87. *
  88. * 7 Data send (not applicable for IIS modes)
  89. * -------- 1-------  If SENB input is '1' then engine will send new data
  90. * -------- 0-------  If SENB input is '0' then engine will send new data
  91. *
  92. * 8 Error indication (not applicable for IIS modes)
  93. * -------1 --------  If SERR input is '1' then error of that sector
  94. * -------0 --------  If SERR input is '0' then error of that sector
  95. *
  96. * 9 External input (not applicable for IIS modes)
  97. * ------1- --------  The host is master on the UDE bus. The external 'REQ' signal
  98. *                    from the Host interface is fed to the REQ output signal from
  99. *                    Furore2.
  100. * ------0- --------  Furore2 is master on the UDE bus and can request new data.
  101. *
  102. * 10-15 Not used (Don't care)
  103. * xxxxxx-- --------
  104. *
  105. *******************************************************************************/
  106. #define BE_IF_TYP_IIS_NORMAL        0x0000
  107. #define BE_IF_TYP_IIS_STOPPED_CLK   0x0001
  108. #define BE_IF_TYP_FEC               0x0002
  109. #define BE_IF_TYP_UDE_SYNCHR        0x0004
  110. #define BE_IF_TYP_UDE_ASYNC_HS2DATA 0x0005
  111. #define BE_IF_TYP_UDE_ASYNC_HS2BYTE 0x0007
  112. #define BE_IF_SYNC_0                0x0000
  113. #define BE_IF_SYNC_1                0x0008
  114. #define BE_IF_SYNC_POS_EDGE         0x0010
  115. #define BE_IF_SYNC_NEG_EDGE         0x0018
  116. #define BE_IF_SYNC_NO_SYNC          0x0020
  117. #define BE_IF_REQ_0                 0x0000
  118. #define BE_IF_REQ_1                 0x0040
  119. #define BE_IF_SENB_0                0x0000
  120. #define BE_IF_SENB_1                0x0080
  121. #define BE_IF_ERR_0                 0x0000
  122. #define BE_IF_ERR_1                 0x0100
  123. #define BE_IF_EXT_FUR2              0x0000
  124. #define BE_IF_EXT_HOST              0x0200
  125. /* Set the next define to one or more of the defines above */
  126. #define BE_IF_TYPE                  BE_IF_TYP_IIS_NORMAL
  127. #define SE_INT_FSD        0x0001
  128. #define SE_INT_SPL        0x0002
  129. #define SE_INT_ESD        0x0004
  130. #define SE_INT_TSD        0x0008
  131. #define SE_INT_LSD        0x0010
  132. #define SE_INT_FSC        0x0020
  133. #define SE_INT_LSC        0x0040
  134. #define SE_INT_EDC        0x0080
  135. #define SE_INT_SNC        0x0100
  136. #define SE_INT_FUL        0x0200
  137. #define SE_INT_NBH        0x0400
  138. #define SE_INT_DIS        0x0800
  139. #define ERROR_HOST_ID     0x00000001
  140. #define ERROR_PI_BUS      0x00000002
  141. #define ERROR_SDRAM       0x00000004
  142. #define ERROR_BUFFER      0x00000008
  143. #define BUFFERSIZE        (132*2048ul)
  144. /*******************************************************************************
  145. * The following defines can be used to set the Audio Input Clock Frequency
  146. * to either 256Fs or 384Fs
  147. *******************************************************************************/
  148. #define DCL_256FS                   0x0100
  149. #define DCL_384FS                   0x0000
  150. /* Set the next define to one of the defines above */
  151. #define DCL_AUDIO_IN                DCL_384FS
  152. #define FURORE_BASE                 0x500000ul //0x50000000ul
  153. /*******************************************************************************
  154. *                               Type definitions
  155. *******************************************************************************/
  156. typedef enum {
  157.   SE_IDLE,
  158.   SE_SEARCHING,
  159.   SE_FIRSTSYNC,
  160.   SE_INLOCK,
  161.   SE_FIRSTCAPTURED,
  162.   SE_LASTCAPTURED
  163. } SeStates;
  164. /*******************************************************************************
  165. *                              Function prototypes
  166. *******************************************************************************/
  167. /*******************************************************************************
  168. *                               Local functions
  169. *******************************************************************************/
  170. unsigned long captureSectorAtNum = 510ul;
  171. int NumToCapture = 9;
  172. //#error Please implement the delay function to provide a delay of about n second
  173. void delay(int n)
  174. {
  175.   usleep(1000000ul);
  176. }
  177. /*******************************************************************************
  178. *                               Data Definitions
  179. *******************************************************************************/
  180. /* Current status of the capturing process */
  181. static int seState;
  182. static unsigned short seErrors;
  183. static unsigned long bufferStart;
  184. #ifdef SACD_HW_EVAL
  185. /* SACD Master TOC of the Philips 'No SACD Mark' test disc */
  186. const unsigned char Mtoc[] = {
  187. #include "playcorenav_SACDsacd_mtoc.hex"
  188. };
  189. #endif
  190. /*******************************************************************************
  191. *                            Exported functions
  192. *******************************************************************************/
  193. /*******************************************************************************
  194. * Name       : Furore2Write
  195. * Purpose    : Write one hword to Furore2 memory/registers.
  196. * Input      : addr   Address to write to
  197. *              val    Hword to write
  198. * Output     : -
  199. * Returns    : -
  200. * Remarks    : SAD16-03
  201. *******************************************************************************/
  202. void Furore2Write( unsigned long addr, unsigned short val )
  203. {
  204.   SAMP(UInt16) furBase;
  205.   /* Save base-address (16 MSB address-bits) */
  206.   furBase = (SAMP(UInt16))((addr>>7)&0xFFFF);
  207. #if 1 //zoran
  208.   SACD_Write16(0x80, furBase);
  209.   SACD_Write16(addr&0x7E, val);
  210. #else
  211.   /* Activate H_A_sel and put base-address on data bus */
  212.   *(volatile SAMP(UInt16)*)(FURORE_BASE|0x80) = furBase;
  213.   /* Negate H_A_sel and write data */
  214.   *(volatile SAMP(UInt16)*)(FURORE_BASE+(addr&0x7E)) = val;
  215. #endif
  216.   /* Wait at least Twait (30 sys_clk cycles) */
  217. //#error insert required delay here
  218. #if 1 //ZORAN
  219.   {
  220.   int i;
  221.   for(i = 0; i < 8; i++);
  222.   }
  223.   //usleep(0UL); //1 us, sys_clk = 27~35MHZ
  224. #endif
  225. }
  226. /*******************************************************************************
  227. * Name       : Furore2Read
  228. * Purpose    : Read one hword from Furore2 memory/registers.
  229. * Input      : addr   Address to read from
  230. * Output     : -
  231. * Returns    : Hword to read
  232. * Remarks    : SAD16-03
  233. *******************************************************************************/
  234. unsigned short Furore2Read( unsigned long Addr )
  235. {
  236.   unsigned short dummy;
  237.   /* Activate H_A_sel and put base-address on data bus */
  238. //  *(volatile unsigned short*)(FURORE_BASE | 0x80) = (unsigned short)((Addr>>7)&0xFFFF);
  239. #if 1 //zoran
  240.   SACD_Write16(0x80, (unsigned short)((Addr>>7)&0xFFFF));
  241. #endif
  242.   /* Read once */
  243. //  dummy = *(volatile unsigned short*)(FURORE_BASE + (Addr&0x7E));
  244.   dummy = SACD_Read16(Addr&0x7E);
  245.   /* Wait at least Twait (30 sys_clk cycles) */
  246. //#error insert required delay here
  247. #if 1 //ZORAN
  248.   {
  249.   int i;
  250.   for(i = 0; i < 8; i++);
  251.   }
  252.   //usleep(0UL); //1 us, sys_clk = 27~35MHZ
  253. #endif
  254.   /* Read twice and return result */
  255. //  dummy = *(volatile unsigned short*)(FURORE_BASE | 0x80);
  256.   dummy = SACD_Read16(0x80);
  257.   return dummy;
  258. }
  259. #define FURORE_SEL_PCM 0x7FE18Aul
  260. #define EXTERNAL_PCM_INPUT 1
  261. #define INTERNAL_PCM_INPUT 0 //PCM is internally generated by decimation filter.
  262. #define FURORE_SEL_DSD_PCM0 0x7fe192ul
  263. #define FURORE_SEL_DSD_PCM1 0x7fe194ul
  264. #define FURORE_SEL_DSD_PCM2 0x7fe196ul
  265. void FuroreSetInternalInputPCMMode(void)
  266. {
  267.   Furore2Write(FURORE_SEL_PCM, INTERNAL_PCM_INPUT);
  268. }
  269. /*
  270. Desc: For medias other than SACD, set external PCM input mode.
  271. */
  272. void FuroreSetExternalInputPCMMode(void)
  273. {
  274.   DAC_SACD_SetMute(TRUE);
  275.   SACD_XMIT2_TIMING();
  276. #if 0 //todo: check later.
  277.   /* Prepare the Furore for capturing */
  278.   Furore2Write(0x7F9608, (0));                     /* VBR_BOT */
  279.   Furore2Write(0x7F960A, ((BUFFERSIZE) >> 8));     /* VBR_TOP */
  280.   Furore2Write(0x7F860E, 0x0000);                                 /* VBR_WRIL */
  281.   Furore2Write(0x7F860C, 0);                    /* VBR_WRIH */
  282.   Furore2Write(0x7F8612, 0x0000);                                 /* VBR_REAL */
  283.   Furore2Write(0x7F8610, 0);                    /* VBR_REAH */
  284.   Furore2Write(0x7F9200, 0x0001);                                 /* SE_RST */
  285.   Furore2Write(0x7F9236, BE_IF_TYPE );                            /* SE_BE_IF */
  286.   Furore2Write(0x7F920C, 0x0000);                                 /* SE_EMR */
  287.   Furore2Write(0x7F9204, 0x0BFF);                                 /* SE_IER */
  288. #if 0
  289.   Furore2Write(0x7F8216, (unsigned short)Begin);                  /* SE_CAPL */
  290.   Furore2Write(0x7F8214, (unsigned short)(Begin>>16)+3);          /* SE_CAPH */
  291.   Furore2Write(0x7F821A, (unsigned short)End);                    /* SE_LSTL */
  292.   Furore2Write(0x7F8218, (unsigned short)(End>>16)+3);            /* SE_LSTH */
  293. #endif
  294.   Furore2Write(0x7FE108, DCL_AUDIO_IN );                          /* LLD_DCL */
  295.   Furore2Write(0x7FE10C, 0x0100);                                 /* FAD_MOD */
  296.   Furore2Write(0x7FE1B2, 0xCC00);                                 /* FAD_IN_SEL */
  297.   Furore2Write(0x7FE18C, 0x0000);                                 /* SEL_DSD_DEB */
  298.   Furore2Write(0x7FE192, 0x9999);                                 /* SW_MAT0 */
  299.   Furore2Write(0x7FE194, 0x7B99);                                 /* SW_MAT1 */
  300.   Furore2Write(0x7FE196, 0xFE7B);                                 /* SW_MAT2 */
  301.   Furore2Write(0x7FE700, 0x0000);                                 /* DEL_ENA */
  302.   /* Clear interrupts */
  303.   Furore2Read(0x7F9206);                                          /* SE_ISR */
  304. #endif
  305.   Furore2Write(0x7FE18Cul, 0x0000);                                 /* SEL_DSD_DEB */
  306.   Furore2Write(FURORE_SEL_PCM, EXTERNAL_PCM_INPUT);
  307.   Furore2Write(FURORE_SEL_DSD_PCM0, PCM_LE_RI | (PCM_CE_LF << 8));
  308.   Furore2Write(FURORE_SEL_DSD_PCM1, PCM_LS_RS | (PCM_DCLK << 8) | (PCM_WCLK << 12));
  309.   DAC_SACD_SetMute(FALSE);
  310. }
  311. //The following functions are for testing hardware environment only.
  312. #ifdef SACD_HW_EVAL
  313. /*******************************************************************************
  314. * Name       : Furore2Init
  315. * Purpose    : Initialises Furore2 chip and programs all registers necessary
  316. *              to capture the requested number of sectors. Also programs
  317. *              postprocessing to output mutes on all channels.
  318. * Input      : Begin        Physical sector number where to start capturing.
  319. *              End          Physical sector number where to stop capturing.
  320. * Output     : -
  321. * Returns    : Result of initialisation is a bitmask consisting of:
  322. *               ERROR_HOST_ID     0x00000001
  323. *               ERROR_PI_BUS      0x00000002
  324. *               ERROR_SDRAM       0x00000004
  325. *               ERROR_BUFFER      0x00000008
  326. * Remarks    : -
  327. *******************************************************************************/
  328. int Furore2Init( unsigned long Begin, unsigned long End )
  329. {
  330.   int Error = 0;
  331.   unsigned long i;
  332.   unsigned short d,HostId;
  333.   unsigned long errorAddress = 0xFFFFFFFFul;
  334.   int validBuffer = 0;
  335.   static int secondaryTestDoneOnce = 0;
  336.   tr_printf(("Initialising Furore... "));
  337.   /* Reset host interface */
  338.   Furore2Write(0x7FE000ul, 0x0707);
  339.   /* Set wait to 6 */
  340.   Furore2Write(0x7FED00ul, 0x0c0c);
  341.   /* Check for Furore 2 cut 2 ID */
  342.   HostId = Furore2Read(0x7FED02ul);
  343.   if( HostId==0xC2F2 )
  344.   {
  345.     /* Swap reads/writes */
  346.     Furore2Write(0x7FE008ul, 0x0606);
  347.   }
  348.   else if( HostId!=0xF2C2 )
  349.   {
  350.     Error |= ERROR_HOST_ID;
  351.   }
  352.   /* Check host ID */
  353.   if( Furore2Read(0x7FE006ul) != 0x5510 )
  354.   {
  355.     Error |= ERROR_HOST_ID;
  356.   }
  357. #if 0
  358.   /* Perform PI bus test */
  359.   for( i=0; i<130 && !(Error & ERROR_PI_BUS); i++ )
  360.   {
  361.     Furore2Write(0x7F9204ul, 1<<(i%13));
  362.     if ( (Furore2Read(0x7F9204ul)&0x1FFF) != (1<<(i%13)) ) Error |= ERROR_PI_BUS;
  363.   }
  364.   /* Perform SDRAM test */
  365.   for ( i=0,d=0; i<0x7F8000ul; i+=16 )
  366.   {
  367.     Furore2Write(i, d);
  368.     if (d==0xFFFF ) d=0; else d++;
  369.   }
  370.   bufferStart = 0;
  371.   for ( i=0,d=0; i<0x7F8000ul; i+=16 )
  372.   {
  373.     if ( Furore2Read(i) != d)
  374.     {
  375.       if(!(Error & ERROR_SDRAM))
  376.       {
  377.         errorAddress = i;
  378.         Error |= ERROR_SDRAM;
  379.       }
  380.       if(!validBuffer)
  381.       {
  382.         if((i - bufferStart) >= BUFFERSIZE)
  383.         {
  384.           validBuffer = 1;
  385.         }
  386.         else
  387.         {
  388.           bufferStart = i + 16;
  389.         }
  390.       }
  391.     }
  392.     if ( d==0xFFFF ) d=0; else d++;
  393.   }
  394.   if((i - bufferStart) >= BUFFERSIZE)
  395.   {
  396.     validBuffer = 1;
  397.   }
  398.   if(!validBuffer)
  399.   {
  400.     Error |= ERROR_BUFFER;
  401.   }
  402.   if(Error & ERROR_SDRAM)
  403.   {
  404.     tr_printf(("FAILEDnSDRAM test failed, "));
  405.     if(Error & ERROR_BUFFER)
  406.     {
  407.       tr_printf(("unable to allocate buffer in SDRAMn"));
  408.     }
  409.     else
  410.     {
  411.       tr_printf(("buffer allocated in SDRAMn"));
  412.     }
  413.   }
  414.   if(!secondaryTestDoneOnce)
  415.   {
  416.     if(!(Error & ERROR_SDRAM))
  417.     {
  418.       for ( i=0; i<0x7F8000ul; i+=2 )
  419.       {
  420.         Furore2Write(i, 0xFFFF);
  421.       }
  422.       for(i = bufferStart; i < bufferStart + BUFFERSIZE; i++)
  423.       {
  424.         if(Furore2Read(i) != 0xFFFF)
  425.         {
  426.           tr_printf(("FAILEDnSecondary SDRAM test failed for selected buffer space at 0x%08lXn", i));
  427.           Error |= ERROR_SDRAM;
  428.           Error |= ERROR_BUFFER;
  429.           break;
  430.         }
  431.       }
  432.       secondaryTestDoneOnce = 1;
  433.     }
  434.     if(!(Error & ERROR_SDRAM))
  435.     {
  436.       for(i = 0; i < 0x7F8000ul; i+=2 )
  437.       {
  438.         if(Furore2Read(i) != 0xFFFF)
  439.         {
  440.           tr_printf(("FAILEDnSecondary SDRAM test failed at 0x%08lXn", i));
  441.           Error |= ERROR_SDRAM;
  442.           break;
  443.         }
  444.       }
  445.     }
  446.   }
  447. #else
  448.     validBuffer = 1;
  449. #endif
  450.   /* Prepare the Furore for capturing */
  451.   Furore2Write(0x7F9608ul, (bufferStart >> 8));                     /* VBR_BOT */
  452.   Furore2Write(0x7F960Aul, ((bufferStart + BUFFERSIZE) >> 8));     /* VBR_TOP */
  453.   Furore2Write(0x7F860Eul, 0x0000);                                 /* VBR_WRIL */
  454.   Furore2Write(0x7F860Cul, (bufferStart >> 16));                    /* VBR_WRIH */
  455.   Furore2Write(0x7F8612ul, 0x0000);                                 /* VBR_REAL */
  456.   Furore2Write(0x7F8610ul, (bufferStart >> 16));                    /* VBR_REAH */
  457.   Furore2Write(0x7F9200ul, 0x0001);                                 /* SE_RST */
  458.   Furore2Write(0x7F9236ul, BE_IF_TYPE );                            /* SE_BE_IF */
  459.   Furore2Write(0x7F920Cul, 0x0000);                                 /* SE_EMR */
  460.   Furore2Write(0x7F9204ul, 0x0BFF);                                 /* SE_IER */
  461.   Furore2Write(0x7F8216ul, (unsigned short)Begin);                  /* SE_CAPL */
  462.   Furore2Write(0x7F8214ul, (unsigned short)(Begin>>16)+3);          /* SE_CAPH */
  463.   Furore2Write(0x7F8218ul, (unsigned short)(End>>16)+3);            /* SE_LSTH */
  464.   Furore2Write(0x7F821Aul, (unsigned short)End);                    /* SE_LSTL */
  465.   Furore2Write(0x7FE108ul, DCL_AUDIO_IN );                          /* LLD_DCL */
  466.   Furore2Write(0x7FE10Cul, 0x0100);                                 /* FAD_MOD */
  467.   Furore2Write(0x7FE1B2ul, 0xCC00);                                 /* FAD_IN_SEL */
  468.   Furore2Write(0x7FE18Cul, 0x0000);                                 /* SEL_DSD_DEB */
  469.   Furore2Write(0x7FE192ul, 0x9999);                                 /* SW_MAT0 */
  470.   Furore2Write(0x7FE194ul, 0x7B99);                                 /* SW_MAT1 */
  471.   Furore2Write(0x7FE196ul, 0xFE7B);                                 /* SW_MAT2 */
  472.   Furore2Write(0x7FE700ul, 0x0000);                                 /* DEL_ENA */
  473.   /* Clear interrupts */
  474.   Furore2Read(0x7F9206ul);                                          /* SE_ISR */
  475.   seState = SE_IDLE;
  476.   seErrors = 0;
  477.   if (!Error)
  478.   {
  479.     tr_printf(("OK.n"));
  480.   }
  481.   else
  482.   {
  483.     tr_printf(("error code %un", Error));
  484.     if(Error & ERROR_SDRAM)
  485.     {
  486.       tr_printf(("Example of not working SDRAM address: 0x%08lXn", errorAddress));
  487.     }
  488.   }
  489.   return Error;
  490. }
  491. /*******************************************************************************
  492. * Name       : Furore2EnableCapturing
  493. * Purpose    : Programs the Furore2 sectorprocessor to start capturing.
  494. * Input      : -
  495. * Output     : -
  496. * Returns    : -
  497. * Remarks    : -
  498. *******************************************************************************/
  499. void Furore2EnableCapturing()
  500. {
  501.   Furore2Write(0x7F920A, 0x0001);                                 /* SE_ENA */
  502.   seState = SE_SEARCHING;
  503.   /* If no timed syncs are detected, it is considered an error.
  504.      The flag will be cleared if and when timed syncs are detected */
  505.   seErrors |= SE_INT_TSD;
  506. }
  507. /*******************************************************************************
  508. * Name       : Furore2GetStatus
  509. * Purpose    : Returns the current state of the capturing process along with
  510. *              possible errors that have a occurred so far.
  511. *              When capturing is started, the furore will go through the states
  512. *              until either a blocking error occurs or the capturing is finished.
  513. * Input      : -
  514. * Output     : *pErrors             An unsigned short (bit pattern) indicating
  515. *                                     which errors occurred since last Furore2
  516. *                                     initialisation
  517. *               0x0004  SE_INT_ESD  early syncs detected
  518. *               0x0008  SE_INT_TSD  NO timed syncs were detected!!
  519. *               0x0010  SE_INT_LSD  late syncs detected
  520. *               0x0080  SE_INT_EDC  erroneous sector
  521. *               0x0100  SE_INT_SNC  sector number continuity error
  522. *               0x0200  SE_INT_FUL  buffer full
  523. *               0x0800  SE_INT_DIS  sector processor disabled
  524. *
  525. *              *pISR                The value of the interrupt status register
  526. *                                     at the moment this function was called
  527. *
  528. * Returns    :  0 SE_IDLE           Capturing hasn't been started yet
  529. *               1 SE_SEARCHING      Capturing was started, but no sync was
  530. *                                     detected
  531. *               2 SE_FIRSTSYNC      First sync was detected, but the sector
  532. *                                     processor isn't in lock yet
  533. *               3 SE_INLOCK         The sector processor is in lock, but the
  534. *                                     first sector wasn't captured yet
  535. *               4 SE_FIRSTCAPTURED  First sector was captured, last sector wasn't
  536. *               5 SE_LASTCAPTURED   Last sector was captured, capturing complete
  537. *
  538. *
  539. * Remarks    : -
  540. *******************************************************************************/
  541. unsigned short Furore2GetStatus(unsigned short *pErrors, unsigned short *pISR)
  542. {
  543.   unsigned short isr = Furore2Read(0x7F9206);
  544.   *pISR = isr;
  545.   if( (seState == SE_SEARCHING) &&
  546.       (isr & SE_INT_FSD) )
  547.   {
  548.     isr &= ~SE_INT_FSD;
  549.     seState = SE_FIRSTSYNC;
  550.   }
  551.   if( (seState == SE_FIRSTSYNC) &&
  552.       (isr & SE_INT_SPL) )
  553.   {
  554.     isr &= ~SE_INT_SPL;
  555.     seState = SE_INLOCK;
  556.   }
  557.   if( (seState == SE_INLOCK) &&
  558.       (isr & SE_INT_FSC) )
  559.   {
  560.     isr &= ~SE_INT_FSC;
  561.     seState = SE_FIRSTCAPTURED;
  562.   }
  563.   if( (seState == SE_FIRSTCAPTURED) &&
  564.       (isr & SE_INT_LSC) )
  565.   {
  566.     isr &= ~SE_INT_LSC;
  567.     seState = SE_LASTCAPTURED;
  568.   }
  569.   seErrors |= isr & (SE_INT_DIS|SE_INT_ESD|SE_INT_LSD|SE_INT_EDC|SE_INT_SNC|SE_INT_FUL);
  570.   /* Clear the TSD flag if there have been timed syncs */
  571.   seErrors &= ~(isr & SE_INT_TSD);
  572.   if(pErrors)
  573.   {
  574.     *pErrors = seErrors;
  575.   }
  576.   return seState;
  577. }
  578. void SACD_Isr(void)
  579. {
  580.   int Error;
  581.   int i, j;
  582.   /*unsigned short isr = 0, oldisr = 0, enabled = 1;*/
  583.   unsigned short curh, curl;
  584.   unsigned short errorBits, f2status, temp;
  585.   unsigned short enabled, isr;
  586.     enabled = Furore2Read(0x7F920A);
  587.     f2status = Furore2GetStatus(&errorBits, &isr);
  588.     if(1) //todo: was errorBits)
  589.     {
  590. #if 0 //todo enable later.
  591.     tr_printf((" EN:0x%04X  E:0x%04X isr:", enabled, errorBits));
  592.     temp = isr;
  593.     for(j = 0; j < 16; j++)
  594.     {
  595.       tr_printf(("%s", (temp & 0x8000) ? "1" : "0"));
  596.       temp <<= 1;
  597.     }
  598. #endif
  599.     curh = Furore2Read(0x7F921C);
  600.     curl = Furore2Read(0x7F921E);
  601. #if 1 //remove later.
  602.     tr_printf(("%04Xn", curl));
  603. #else
  604.     tr_printf((" SN:0x%04X%04Xn", curh, curl));
  605. #endif
  606.     }
  607. }
  608. #ifdef SACD_HW_EVAL
  609. /*******************************************************************************
  610. * Name       : Furore2Verify
  611. * Purpose    : Compares the data that was read against the contents of
  612. *              the SACD Master TOC of the Philips 'No SACD Mark' test disc.
  613. * Input      : -
  614. * Output     : -
  615. * Returns    : 0            Verification successful.
  616. *              >0           Number of mismatching bytes.
  617. *              -1           Signature of TOC is invalid (no bytes matched).
  618. * Remarks    : To use this function, sectors 510-519 of the disc should have
  619. *              been read in the buffer using the functions Furore2Init() and
  620. *              Furore2GetStatus().
  621. *******************************************************************************/
  622. int Furore2Verify()
  623. {
  624.   unsigned long i;
  625.   int Swap=0, Count=0;
  626.   unsigned short Signature=Furore2Read(bufferStart);
  627.   if( Signature==0x5341 ) Swap=0;
  628.   else if( Signature==0x4153 ) Swap=1;
  629.   else Count=-1;
  630.   if( Count==0 )
  631.   {
  632.     for(i=0;i<sizeof(Mtoc)&&i<BUFFERSIZE;i+=2)
  633.     {
  634.       if( Furore2Read(bufferStart+i)!=((Mtoc[Swap?i+1:i]<<8)|Mtoc[Swap?i:i+1]) ) Count+=2;
  635.     }
  636.   }
  637.   return Count;
  638. }
  639. /*******************************************************************************
  640. * The following function is an example of how the test routines above
  641. * can be used. The following actions will be performed:
  642. * 1. Furore2 will be initialised and sector processor will be programmed to
  643. *    capture the SACD Master TOC of the disc (logical sectors 510 to 519).
  644. * 2. The Furore2 sectorprocessor will be started after the engine has jumped to
  645. *    the wanted position.
  646. * 3. In a loop the status of the capturing process will be retrieved until
  647. *    capturing stops.
  648. * 4. The captured data is verified against the SACD Master TOC of the Philips
  649. *    'No SACD Mark' test disc.
  650. *******************************************************************************/
  651. int CaptureMasterToc(void)
  652. {
  653.   int Error;
  654.   int i, j;
  655.   /*unsigned short isr = 0, oldisr = 0, enabled = 1;*/
  656.   unsigned short curh, curl;
  657.   unsigned short errorBits, f2status, temp;
  658.   unsigned short enabled, isr;
  659. //  PE_SACD_AbortPlayback(1);
  660.   Error = SAMP(BE_ReadToc)();
  661.   if (Error) tr_printf(("ReadToc failedn")); else tr_printf(("ReadToc okn"));
  662.   /* Initialise Furore2 and program sector processor to capture the SACD Master TOC */
  663.   if (Error == 0)
  664.   {
  665.     Error = Furore2Init( captureSectorAtNum, captureSectorAtNum + NumToCapture);
  666.     if (Error)
  667.     {
  668.       if(!(Error & (ERROR_HOST_ID|ERROR_PI_BUS|ERROR_BUFFER)))
  669.       {
  670.         tr_printf(("Only SDRAM test failed. Continuing with buffer in working part of SDRAM.n"));
  671.       }
  672.       else
  673.       {
  674.         return Error;
  675.       }
  676.     }
  677.   }
  678.   /* Seek to the wanted postition and enable capturing */
  679.   Error = SAMP(BE_Seek)( captureSectorAtNum - 4 + 0x30000ul); //sacd todo: was - 510
  680.   if (Error == 0)
  681.   {
  682.     Furore2EnableCapturing();
  683.   }
  684.   if (Error)
  685.   {
  686.     tr_printf(("Seek failedn"));
  687.     return Error;
  688.   }
  689.   else
  690.   {
  691.     tr_printf(("Seek okn"));
  692.   }
  693.   i = 0;
  694.   do
  695.   {
  696.     /* Wait for about a second */
  697.     delay(1);
  698.     enabled = Furore2Read(0x7F920A);
  699.     f2status = Furore2GetStatus(&errorBits, &isr);
  700.     tr_printf((" SE_ENA:0x%04X  errorBits:0x%04X isr:", enabled, errorBits));
  701.     temp = isr;
  702.     for(j = 0; j < 16; j++)
  703.     {
  704.       tr_printf(("%s", (temp & 0x8000) ? "1" : "0"));
  705.       temp <<= 1;
  706.     }
  707.     curh = Furore2Read(0x7F921C);
  708.     curl = Furore2Read(0x7F921E);
  709.     tr_printf((" SE_CUR:0x%04X%04Xn", curh, curl));
  710.     i++;
  711.   }
  712.   while(enabled && (i < 20));
  713. //  PE_SACD_AbortPlayback(1);
  714.   if(f2status == SE_LASTCAPTURED)
  715.   {
  716.     tr_printf(("Capturing ok. (errorBits = 0x%04X)n", errorBits));
  717.     /* Verify captured data */
  718.     Error = Furore2Verify();
  719.     if (Error) tr_printf(("Verification failed at byte %dn", Error)); else tr_printf(("Verification okn"));
  720.   }
  721.   else
  722.   {
  723.     tr_printf(("Capturing failed.nStatus was "));
  724.     switch(f2status)
  725.     {
  726.     case SE_IDLE:
  727.       tr_printf(("IDLE"));
  728.       break;
  729.     case SE_SEARCHING:
  730.       tr_printf(("SEARCHING"));
  731.       break;
  732.     case SE_FIRSTSYNC:
  733.       tr_printf(("FIRSTSYNC"));
  734.       break;
  735.     case SE_INLOCK:
  736.       tr_printf(("INLOCK"));
  737.       break;
  738.     case SE_FIRSTCAPTURED:
  739.       tr_printf(("FIRSTCAPTURED"));
  740.       break;
  741.     case SE_LASTCAPTURED:
  742.       tr_printf(("LASTCAPTURED"));
  743.       break;
  744.     default:
  745.       tr_printf(("UNKNOWN"));
  746.       break;
  747.     }
  748.     tr_printf((" at the end of the loop (errorbits = 0x%04X)n", errorBits));
  749.   }
  750.   return Error;
  751. }
  752. void ShowCurrentSector()
  753. {
  754.   unsigned short curh, curl;
  755.   curh = Furore2Read(0x7F921C);
  756.   curl = Furore2Read(0x7F921E);
  757.   tr_printf(("SE_CUR:0x%04X%04Xn", curh, curl));
  758. }
  759. void PspKeyDetection()
  760. {
  761.   int Error, i, j;
  762.   unsigned short isr, oldisr = 0;
  763.   tr_printf(("Starting PSP detection...n"));
  764.   Furore2Write(0x7F9204, 0x1FFF);
  765.   Furore2Write(0x7F920A, 0x1000);
  766.   Furore2Write(0x7F9222, 0x029F);
  767.   Error = SAMP(BE_Seek)( 0x2F000 );
  768.   if(Error)
  769.   {
  770.     tr_printf(("Seek failed.n"));
  771.   }
  772.   else
  773.   {
  774.     tr_printf(("Seek ok.n"));
  775.     for(i = 0; i < 10 && !(oldisr & 0x1000); i++)
  776.     {
  777.       oldisr = isr = Furore2Read(0x7F9206);
  778.       tr_printf((" SE_ISR:0x%04X (", isr));
  779.       for(j = 0; j < 16; j++)
  780.       {
  781.         tr_printf(("%s", (isr & 0x8000) ? "1" : "0"));
  782.         isr <<= 1;
  783.       }
  784.       tr_printf((") pll_lock:%un", (Furore2Read(0x7f9222) >> 10) & 1));
  785.       /* Wait for about 1 second */
  786.       delay(1);
  787.     }
  788.     if(oldisr & 0x1000)
  789.     {
  790.       tr_printf(("PSP key detection successful.n"));
  791.     }
  792.     else
  793.     {
  794.       tr_printf(("PSP key not detected yet.n"));
  795.       Error = SAMP(BE_Seek)( 0x80000 );
  796.       /* Wait for about 3 seconds */
  797.       delay(3);
  798.       if(Error)
  799.       {
  800.         tr_printf(("Uh oh.n"));
  801.       }
  802.       oldisr = isr = Furore2Read(0x7F9206);
  803.       tr_printf((" SE_ISR:0x%04X (", isr));
  804.       for(j = 0; j < 16; j++)
  805.       {
  806.         tr_printf(("%s", (isr & 0x8000) ? "1" : "0"));
  807.         isr <<= 1;
  808.       }
  809.       tr_printf((")n"));
  810.       if(oldisr & 0x1000)
  811.       {
  812.         tr_printf(("Success.n"));
  813.       }
  814.       else
  815.       {
  816.         tr_printf(("Failure.n"));
  817.       }
  818.     }
  819.   }
  820. }
  821. #endif
  822. #endif
  823. #endif // D_SUPPORT_SACD