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

DVD

开发平台:

Others

  1. /*
  2. file: nav_sacd.c
  3. desc: Implements event handler for SACD.
  4. Created on: Nov 7, 2003
  5. */
  6. #include "config.h"
  7. #if D_SUPPORT_SACD
  8. #ifdef _DEBUG
  9. #undef IFTARCE
  10. #define IFTRACE if (gTraceCore)
  11. #include "DebugDbgMain.h"
  12. #endif
  13. #include "IncludeSysDefs.h"
  14. #include "Kernelker_api.h"
  15. #include "KernelEventDef.h"
  16. #include "PlaycoreCoremaincoregdef.h"
  17. #include "Playcoreplaymodeplaymode.h"
  18. #include "Playcorenav_sacdpe_sacd.h"
  19. #include "Playcorescpadscmgr.h"
  20. #include "PlaycorescpadScPadAlloc.h"
  21. #include "Playcorenav_sacdsacd_uart.h"
  22. #include "PlaycoreSAMPsamp_gen.h"
  23. #include "PlaycoreSAMPsamp_nav.h"
  24. #include "PlaycoreSAMPsamp_apm.h"
  25. #include "PlaycoreSAMPsamp_sdm.h"
  26. #include "Playcorenav_sacdhweval_zoran.h"
  27. #include "Playcorenav_sacdnav_sacd.h"
  28. extern BOOL g_in_full_stop;
  29. static SAMP(ErrCode) Constructor(void);
  30. static void Destructor(void);
  31. static void SampCallback(SAMP(BitSet32) Event, void * EventData);
  32. static void NavCallback(SAMP(BitSet32) Event, void * EventData);
  33. #ifndef SACD_AREA_INFO_INSDRAM
  34. static void SaveSACDAreaInfo(SAMP(SAMP_AreaInfoDef) *stereo,SAMP(SAMP_AreaInfoDef) *multi);
  35. #endif
  36. /////////////////////////////////////////////////////////////////////////////////////////////////
  37. // int SACD_Navigator(HDLR_OP Op, EVENT Event, void *Param) -
  38. // The main router for SACD-Navigation Events.
  39. //
  40. // Input:
  41. // Op - The type of operation being invoked
  42. // Event - The event to route
  43. // Param - An optional parameter for the event being routed
  44. //
  45. // Output:
  46. // Zero if the routing is successful.
  47. int SACD_Navigator(HDLR_OP Op, EVENT Event, void *Param)
  48. {
  49.    SAMP(ErrCode) err = SAMP(ERR_OK);
  50. switch (Op)
  51. {
  52. case HDLR_ENTER: Constructor();
  53. //<<ZKR ML:033104 Aviod pop sound  when loading  sacd
  54. #ifdef EXINO2  
  55. DAC_SACD_SetMute(FALSE);
  56. #endif
  57. //>>ZKR ML:033104
  58. break;
  59. case HDLR_EXIT: Destructor();
  60. break;
  61. case HDLR_EVENT:
  62. switch (Event)
  63. {
  64. case IE_CORE_PAUSE:
  65. err = SAMP(NAV_Pause)();
  66. break;
  67. case IE_CORE_STOP:
  68.                         //todo: check how to do full stop.
  69.                         SAMP(NAV_Stop)();
  70.                g_in_full_stop = TRUE; /* forces next PLAY to be mapped to RESTART */
  71. // PE_SACD_AbortPlayback(0); //todo check later.
  72. break;
  73. case IE_CORE_PLAY:
  74.                         if(gcs.pstate == PST_PAUSE || gcs.pstate== PST_SCAN)
  75.                         {
  76.                          //only valid when it's pause or trick mode state.
  77.                          err = SAMP(NAV_ResumePlay)();
  78.  break;
  79.                         }
  80.                         //fall through
  81. case IE_CORE_RESTART:
  82.                         if(PM_IsPlaybackProgram(PM_GetPlaybackMode()))
  83. err = SAMP(NAV_PlayTrack)(SACD_GLOBALS.ProgramList.tracks[0], SACD_GLOBALS.gbPlayPauseArea? 0:1);
  84.                         else
  85.                         err = SAMP(NAV_PlayTrack)(1, SACD_GLOBALS.gbPlayPauseArea? 0:1);
  86.                         break;
  87. case IE_CORE_NEXT_CHAPTER:
  88. err = SAMP(NAV_NextTrack)();
  89. break;
  90. case IE_CORE_PREVIOUS_CHAPTER:
  91. err = SAMP(NAV_PreviousTrack)();
  92. break;
  93. case IE_CORE_GOTO_ENTRY:
  94. case IE_CORE_MENU_NUMERICAL_SELECTION:
  95.                         if(PM_IsPlaybackProgram(PM_GetPlaybackMode()))
  96.                         err = SAMP(NAV_PlayTrack)(SACD_GLOBALS.ProgramList.tracks[(int)Param], SACD_GLOBALS.gbPlayPauseArea? 0:1);
  97.                         else
  98.                         err = SAMP(NAV_PlayTrack)((int)Param, SACD_GLOBALS.gbPlayPauseArea? 0:1);
  99. break;
  100. case IE_CORE_AB_REPEAT:
  101. if (0 == (int)Param) {
  102.                            err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_OFF));
  103.      PM_SetRepeatAB(0);
  104. break;
  105. }
  106. if (PM_GetRepeatAB() & PM_REPEAT_AB_B) {
  107.                            err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_OFF));
  108.      PM_SetRepeatAB(0);
  109. }
  110. else { //after set A or A-B, set repeat single, then A will never be setted for the dwStartAddress is still there.
  111. if ((0 == PM_GetRepeatAB()))// && ((g_pCDDANav->m_PositionA).iPlaylistItem < 0))      // so I remove this condition, if this is necessary, let me know please, tonnyg
  112. {
  113.                             err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_A));
  114.  PM_SetRepeatAB(PM_REPEAT_AB_A);
  115. }
  116. else {
  117.                               err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_AB));
  118. PM_SetRepeatAB(PM_REPEAT_AB_B);
  119. }
  120. }
  121. break;
  122. #if 0 //SAMP doesn't support bookmark.
  123. case IE_CORE_SET_BOOKMARK:
  124. #ifdef HW_POWER_ON_RESUME
  125. NVM_BMK_SET((int)Param);
  126. #endif
  127. SetMarker(eBookmark, (WORD)Param - 1);
  128. break;
  129. case IE_CORE_GOTO_BOOKMARK:
  130. OnGoToBookmark((WORD)Param - 1);
  131. break;
  132. #endif
  133. case IE_CORE_SCAN:
  134.                        if(0 == (int)Param) //normal speed play
  135.                        {
  136.                         err = SAMP(NAV_ResumePlay)();
  137.                        }
  138.                        else
  139.                        if(0 < (int)Param) //fast forward
  140.                        {
  141.                         err = SAMP(NAV_ForwardScan)((SAMP(UInt8)) Param);
  142.                        }
  143.                        else
  144.                        if(0 > (int)Param) //fast backward
  145.                        {
  146.                         int param = -((int)Param);
  147.                         err = SAMP(NAV_BackwardScan)((SAMP(UInt8)) param);
  148.                        }
  149. break;
  150. case IE_CORE_TICK_ONE_SEC:
  151. break;
  152. case IE_CORE_TICK_200:
  153. // OnTick();
  154. break;
  155. case IE_CORE_SEAMLESS_MODE_CHANGE:
  156.                         //non_shuffle to shuffle
  157.                         if(PM_IsPlaybackShuffle(PM_GetPlaybackMode()))
  158.                          err = SAMP(NAV_Shuffle)(TRUE);
  159.                         else
  160.                         {
  161.                          err = SAMP(NAV_Shuffle)(FALSE);
  162.                          if(PM_IsPlaybackProgram(PM_GetPlaybackMode()))
  163.                          {
  164.                           //non_program to program
  165.                           err = SAMP(NAV_SetPlaySequence)(SAMP(NAV_PLAY_SEQ_PROGRAM));
  166.                          }
  167.                          else
  168.                          {
  169.                          //non_normal to normal
  170.                          err = SAMP(NAV_SetPlaySequence)(SAMP(NAV_PLAY_SEQ_ALL));
  171.                          }
  172.                         }
  173.                         if(PM_IsRepeatAll())
  174.                          err = SAMP(NAV_Repeat)(SAMP(NAV_REPEAT_ALL));
  175.                         else
  176.                         if(PM_IsRepeatSingle())
  177.                          err = SAMP(NAV_Repeat)(SAMP(NAV_REPEAT_TRACK));
  178.                         else
  179.                          err = SAMP(NAV_Repeat)(SAMP(NAV_REPEAT_OFF));
  180. break;
  181. case IE_CORE_GOTO_TIME:
  182. case IE_CORE_GOTO_DISC_TIME:
  183.                         {
  184.                          SAMP(SACD_TimeCode) Timecode;
  185.                          if(IE_CORE_GOTO_TIME == Event)
  186.                           (ULONG)Param += Nav_SACD_Get_Track_Start_Time(SACD_GLOBALS.currentTrack);
  187.                          Timecode.min = (BYTE)(((ULONG)Param)/60);
  188.                          Timecode.sec = (BYTE)(((ULONG)Param)%60);
  189.                          Timecode.fr = 0;
  190.                          err = SAMP(NAV_PlayAtTimecode)(Timecode);
  191.                         }
  192. #ifdef EXINO2  // <<< SEC CH.KO033104  
  193. ie_send(IE_UI_REFRESH_TIME);           
  194. #endif
  195. break;
  196. case IE_CORE_CDNAV_INTRO:
  197.                         err = SAMP(NAV_IntroScan)(TRUE, (SAMP(UInt8)) SACD_INTRO_TIME);
  198. break;
  199.                   case IE_CORE_SACD_SET_ACTIVE_AREA:
  200.                         err = SAMP(NAV_AreaSwitch)((SAMP(SACD_Area)) Param);
  201.                         SACD_GLOBALS.activeArea = (SAMP(SACD_Area)) Param;
  202.                         break;
  203.                   case IE_CORE_SAMP_NAV_ACTIVATED:
  204.                         //Do APM settings.
  205.      err = SAMP(NAV_SetProgramList)(&(SACD_GLOBALS.ProgramList));
  206.                         err = SAMP(APM_SetInputMode)(SAMP(SACD_IN_DSD));
  207. #ifdef AUDIO_DAC_SUPPORT_DSD
  208.                         err = SAMP(APM_SetOutputMode)(SAMP(APM_OUT_DSD), SAMP(APM_OUT_DSD));
  209. #else
  210.                         err = SAMP(APM_SetOutputMode)(SAMP(APM_OUT_PCM), SAMP(APM_OUT_PCM));
  211. #endif
  212. #if 0 //check later.
  213.                         err = SAMP(APM_Set6chDownmix)((SAMP(APM_6ch_MixDef))(gps->SACD6ChDownmixMode));
  214.                         err = SAMP(APM_Set2chDownmix)((SAMP(APM_2ch_MixDef)) (gps->SACD2ChDownmixMode));
  215.                         err = SAMP(APM_SetSpeakers)((SAMP(APM_SpeakerDef)) (gps->SACDSpeakerMode));
  216.                         {
  217.                          SAMP(UInt16) Attenuation[8];
  218.                          Attenuation[0] = gps->SACDAttenuationLeft;
  219.                          Attenuation[1] = gps->SACDAttenuationRight;
  220.                          Attenuation[2] = gps->SACDAttenuationCenter;
  221.                          Attenuation[3] = gps->SACDAttenuationLfe;
  222.                          Attenuation[4] = gps->SACDAttenuationLs;
  223.                          Attenuation[5] = gps->SACDAttenuationRs;
  224.                          Attenuation[6] = gps->SACDAttenuation2CHLeft;
  225.                          Attenuation[7] = gps->SACDAttenuation2CHRight;
  226.                          err = SAMP(APM_SetAttenuation)(Attenuation);
  227.                         }
  228.                         {
  229.                          SAMP(UInt32) Delay[6];
  230.                          Delay[0] = gps->SACDDelayLeft;
  231.                          Delay[1] = gps->SACDDelayRight;
  232.                          Delay[2] = gps->SACDDelayCenter;
  233.                          Delay[3] = gps->SACDDelayLfe;
  234.                          Delay[4] = gps->SACDDelayLs;
  235.                          Delay[5] = gps->SACDDelayRs;
  236.                          err = SAMP(APM_SetDelay)(Delay);
  237.                         }
  238.                         err = SAMP(APM_SetFilterMode)((SAMP(APM_FilterModeDef)) (gps->SACDFilterMode));
  239.                         err = SAMP(APM_SetBassFilters)((SAMP(APM_BassFrequencyDef)) (gps->SACDBassFrequency), (SAMP(APM_BassSlopeDef)) (gps->SACDBassSlope));
  240. #else
  241.                         {
  242. DEC_LL_OCFG_SETTING ocfg;
  243.                          SAMP(APM_6ch_MixDef) sacd_ocfg;
  244. ocfg = SpeakersConfigTable[gps->SpeakersConfigIndex].mOCFG;
  245.                          switch(ocfg)
  246.                          {
  247. case DEC_LL_OCFG_2_1:
  248. case DEC_LL_OCFG_2_0_SURROUND_COMPATIBLE:
  249. case DEC_LL_OCFG_1_0:
  250. case DEC_LL_OCFG_2_0_NORMAL:
  251.                             sacd_ocfg = SAMP(APM_MIX_6CH_2_0);
  252.                                break;
  253. case DEC_LL_OCFG_2_2:
  254.                              sacd_ocfg = SAMP(APM_MIX_6CH_2_2);
  255.                                break;
  256. case DEC_LL_OCFG_3_2:
  257.                              sacd_ocfg = SAMP(APM_MIX_6CH_3_2);
  258.                                break;
  259. case DEC_LL_OCFG_3_0:
  260. case DEC_LL_OCFG_3_1:
  261.                              sacd_ocfg = SAMP(APM_MIX_6CH_3_0);
  262.                                break;
  263.                         }
  264.                          err = SAMP(APM_Set6chDownmix)(sacd_ocfg);
  265. }
  266.                         err = SAMP(APM_Set2chDownmix)(SAMP(APM_MIX_2CH_DOWNMIX));
  267.                         {
  268. SAMP(APM_SpeakerDef) speakerSetting;
  269. if(SPK_SIZE_SMALL == SpeakersConfigTable[gps->SpeakersConfigIndex].mFrontSpk)
  270.                            {
  271.                             speakerSetting = SAMP(APM_SSS1);
  272.                            }
  273.                            else //front speaker is large
  274.                            {
  275.                             if(SPK_SIZE_LARGE == SpeakersConfigTable[gps->SpeakersConfigIndex].mSurroundSpk)
  276.                             speakerSetting = SAMP(APM_LLL1);
  277. else
  278.                             speakerSetting = SAMP(APM_LSS0);
  279.                               //sacd todo: check when to set SAMP(APM_LSS0_noLFE).
  280.                            }
  281.                         err = SAMP(APM_SetSpeakers)(speakerSetting);
  282.                         }
  283.                         {
  284.                          SAMP(UInt16) Attenuation[8];
  285. memset(Attenuation, 0, 16);
  286.                          err = SAMP(APM_SetAttenuation)(Attenuation);
  287.                         }
  288.                         {
  289.                          SAMP(UInt32) Delay[6];
  290. memset(Delay, 0, 24);
  291.                          err = SAMP(APM_SetDelay)(Delay);
  292.                         }
  293.                         err = SAMP(APM_SetFilterMode)(SAMP(APM_FM_MAX_SNR));
  294. {
  295. SAMP(APM_BassFrequencyDef) bassFreq = SAMP(APM_BASS_FREQ_100);
  296.                            SAMP(APM_BassSlopeDef) bassSlope = SAMP(APM_BASS_SLOPE_18);
  297. #if defined(BM_CUTOFF_120HZ)
  298.                            bassFreq = SAMP(APM_BASS_FREQ_120);
  299. #elif defined(BM_CUTOFF_80HZ)
  300.                            bassFreq = SAMP(APM_BASS_FREQ_80);
  301. #endif
  302. #if defined(BM_SLOPE_24)
  303.                            bassSlope = SAMP(APM_BASS_SLOPE_24);
  304. #elif defined(BM_SLOPE_12)
  305.                            bassSlope = SAMP(APM_BASS_SLOPE_12);
  306. #endif
  307.                          err = SAMP(APM_SetBassFilters)(bassFreq, bassSlope);
  308. }
  309. #endif
  310.                         err = SAMP(APM_SetPcmUpsampling)(SACD_UPSAMPLING_RATE); //active only when output is PCM.
  311.                         err = SAMP(APM_SetPIO)(2176); //doesn't matter?
  312. //                        err = SAMP(NAV_PlayTrack)(1, SACD_GLOBALS.gbPlayPauseArea? 0:1); //todo: remove later.
  313. //todo: check later.                        DAC_SACD_SetMute(FALSE);
  314.                         break;
  315. default:
  316. dbg_printf(("SACD_Nav: Unexpected Event %xn",Event & 0xFF));
  317. break;
  318. }
  319. break;
  320. default:
  321. dbg_printf((" SACD_Nav: Unknown Operation requested %dn", Op));
  322. break;
  323. }
  324.    if(err != SAMP(ERR_OK))
  325.    {
  326. tr_printf((" SACD_Nav: error handling SACD nav event! %dn", Op));
  327.    }
  328. return 0;
  329. }
  330. //jerry todo: remove later.
  331. //int hold_samp = 1;
  332. /*
  333. Desc: initialize and start SAMP.
  334. rtn: Err_OK, succeed so it's a SACD disc.
  335.      otherwise not a SACD disc.
  336. */
  337. static SAMP(ErrCode) Constructor(void)
  338. {
  339.     void (*lFuroreISR)(void);
  340.     SAMP(ErrCode)  lErr = SAMP(ERR_OK);
  341.     //TODO: check if stack overflows with the 2 structs.
  342. //    SAMP(SAMP_AreaInfoDef) stereo;
  343. //    SAMP(SAMP_AreaInfoDef) multi;
  344.     SAMP(Bool) bDiscRecognized = FALSE;
  345.     //initialize SACD_GLOBALS
  346.     SACD_GLOBALS.samp_state = SAMP_NOT_ACTIVATED;
  347.     SACD_GLOBALS.nav_state = NAV_NOT_ACTIVATED;
  348.     SACD_GLOBALS.play_speed = 1;
  349.     SACD_GLOBALS.iCurrentTime = 0;
  350.     SACD_GLOBALS.iCurrentAbsTime = 0;
  351.     SACD_GLOBALS.gbPlayPauseArea = 1;
  352. //    SACD_GLOBALS.channels =
  353.     SACD_GLOBALS.currentTrack = 0;
  354.     SACD_GLOBALS.currentIndex = 0;
  355. #ifndef SACD_AREA_INFO_INSDRAM
  356.     SACD_GLOBALS.StereoAreaInfoPtr = sc_Malloc((sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
  357.     SACD_GLOBALS.MultiAreaInfoPtr = sc_Malloc((sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
  358.     if(NULL == SACD_GLOBALS.StereoAreaInfoPtr || NULL == SACD_GLOBALS.MultiAreaInfoPtr)
  359.     {
  360.      tr_printf(("Fatal! Constructor: can't allocate memory from scratch pad "));
  361.      return SAMP(ERR_FAILED);
  362.     }
  363. #endif
  364. #ifndef SACD_AREA_INFO_INSDRAM
  365.     //todo: ask Philips to save Area info In SC.
  366.     SACD_GLOBALS.pAreaStereo = malloc(sizeof(SAMP(SAMP_AreaInfoDef)));
  367.     SACD_GLOBALS.pAreaMulti = malloc(sizeof(SAMP(SAMP_AreaInfoDef)));
  368.     if(NULL == SACD_GLOBALS.pAreaStereo || NULL == SACD_GLOBALS.pAreaMulti)
  369.     {
  370. tr_printf((" SACD_Nav: Fatal! Heap size too small for SAMP_AreaInfoDefn"));
  371.     }
  372. #else
  373.     {
  374.      UINT32 temp = 0;
  375.      int i;
  376.      for(i = 0; i < 4; i++)
  377.      {
  378.       sc_SetBytes32(SDRAM_2CH_AREA_INFO_BASE, i*4, 4, (const BYTE *)(&temp));
  379.       sc_SetBytes32(SDRAM_MULTICH_AREA_INFO_BASE, i*4, 4, (const BYTE *)(&temp));
  380.      }
  381.     }
  382. #endif
  383. //todo: check later.    DAC_SACD_SetMute(TRUE);
  384. #if 0 //sacd todo: check later.
  385.     //install ISR.
  386.     SAMP(SDM_GetHandler)( &lFuroreISR );
  387.     lErr = SAMP(ISR_Install)( lFuroreISR );
  388. #endif
  389.     if(SAMP(ERR_OK) != lErr)
  390. tr_printf((" SACD_Nav: Fatal! Install ISR failedn"));
  391.     //BE_Init
  392.     lErr = SAMP(BE_Init)();
  393.     if(SAMP(ERR_OK) != lErr)
  394. tr_printf((" SACD_Nav: Fatal! BE_Init failedn"));
  395.     //DAC_Init
  396. //    lErr = SAMP(DAC_Init)();
  397.     if(SAMP(ERR_OK) != lErr)
  398. tr_printf((" SACD_Nav: Fatal! DAC_Init failedn"));
  399.     //SetEngine type as IIS
  400.     lErr = SAMP(SDM_SetEngineType)(SAMP(SDM_BE_I2S));
  401. #if 1 //sacd todo: check later.
  402.     //install ISR.
  403.     SAMP(SDM_GetHandler)( &lFuroreISR );
  404.     lErr = SAMP(ISR_Install)( lFuroreISR );
  405. #endif
  406.     //Set Burst length
  407.     lErr = SAMP(SDM_SetBurstLength)(SACD_BURST_LENGTH);
  408.     //Set Dac Pinning
  409. #ifdef AUDIO_DAC_SUPPORT_DSD
  410.     lErr = SAMP(SDM_SetDacPinning)(0,  0,
  411.                                    0,  0,
  412.                                    0,  0,
  413.                                    0,  0,
  414.                                    0,  0,
  415.                                    0,  0,
  416.                                    SAMP(SDM_DSD_CLOCK), 0, 0);
  417.     //set DSD clock polarity. Doesn't matter with PCM DAC.
  418.     lErr = SAMP(SDM_SetDsdClockPolarity)(1);    //TODO: check later.
  419.     //sacd todo: do external mute. 
  420. //    DAC_Set_DSD_Mode(1);
  421. #else
  422.     lErr = SAMP(SDM_SetDacPinning)(SAMP(SDM_PCM_LEFTFRONT_RIGHTFRONT),  SAMP(SDM_PIO),
  423.                                    SAMP(SDM_PCM_CENTER_LFE),  SAMP(SDM_PIO),
  424.                                    SAMP(SDM_PCM_LEFTSURR_RIGHTSURR), SAMP(SDM_PIO),
  425.                                    SAMP(SDM_PCM_DATACLOCK),  SAMP(SDM_PCM_WORDCLOCK),
  426.                                    SAMP(SDM_PCM_DATACLOCK),  SAMP(SDM_PCM_WORDCLOCK),
  427.                                    SAMP(SDM_PCM_LEFTFRONT_RIGHTFRONT), SAMP(SDM_PIO),
  428.                                    SAMP(SDM_PIO), SAMP(SDM_PIO), SAMP(SDM_PIO));
  429. #endif
  430.     {
  431. #ifdef MASTERCLOCK_256
  432.     SAMP(SDM_AudioClockDef) AudioClock = SAMP(SDM_AUD_CLK_256FS);
  433. #else
  434.     SAMP(SDM_AudioClockDef) AudioClock = SAMP(SDM_AUD_CLK_384FS);
  435. #endif
  436.     //set audio clk, e.g. 384fs. valid for DSD stream.
  437.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_DSD), AudioClock);
  438.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_44), AudioClock);
  439.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_88), AudioClock);
  440.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_176), AudioClock);
  441.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_48), AudioClock);
  442.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_96), AudioClock);
  443.     lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_192), AudioClock);
  444.     }
  445.     //system clock is 27M hz
  446.     lErr = SAMP(SDM_SetSystemClock)(SYS_CLK);
  447.     //samp init
  448.     lErr = SAMP(SAMP_Init)();
  449.     if(SAMP(ERR_OK) != lErr)
  450. tr_printf((" SACD_Nav: Fatal! SAMP_Init failedn"));
  451.     //SAMP Subscribe
  452.     lErr = SAMP(SAMP_Subscribe)( SampCallback
  453.                               , ( SAMP_ACTIVATED
  454.                                 | SAMP_NOT_ACTIVATED ) );
  455.     //NAV subscribe
  456.     lErr = SAMP(NAV_Subscribe)( NavCallback
  457.                               , ( NAV_ACTIVATED
  458.                                 | NAV_NOT_ACTIVATED
  459.                                 | NAV_STARTED
  460.                                 | NAV_PAUSED
  461.                                 | NAV_STOPPED
  462.                                 | NAV_FINISHED
  463.                                 | NAV_PROGRESS_INFO
  464.                                 | NAV_MODE_CHANGE
  465.                                 | NAV_WARNING
  466.                                 | NAV_ERROR
  467.                                 | NAV_CHANNELS_CONFIG) );
  468.     //SAMP activate
  469. #ifdef SACD_AREA_INFO_INSDRAM
  470.     lErr = SAMP(SAMP_Activate)(bDiscRecognized, NULL, NULL, (SAMP(Bool) *)&(SACD_GLOBALS.hybrid));
  471. #else
  472.     lErr = SAMP(SAMP_Activate)(bDiscRecognized, SACD_GLOBALS.pAreaStereo, SACD_GLOBALS.pAreaMulti, (SAMP(Bool) *)&(SACD_GLOBALS.hybrid));
  473. #endif
  474.     if(SAMP(ERR_OK) != lErr)
  475. tr_printf((" SACD_Nav: Fatal! SAMP_Activate failedn"));
  476.     return lErr;
  477. }
  478. /*
  479. desc: kill SAMP.
  480. */
  481. static void Destructor(void)
  482. {
  483.   SAMP(ErrCode)  lErr = SAMP(ERR_OK);
  484.   SAMP(NAV_StateDef) stateDef;
  485.   SAMP(NAV_GetState)(&stateDef);
  486.   //todo: check with Philips jerry cai
  487.   stateDef.PlayState = SAMP(NAV_PLAYING);
  488.   // First make sure it is deactivated!
  489.   switch (stateDef.PlayState)
  490.   {
  491.   case SAMP(NAV_PLAY_CALLED):
  492.   case SAMP(NAV_PLAYING):
  493.   case SAMP(NAV_PAUSE_CALLED):
  494. //todo: check with philips  case SAMP(NAV_PAUSED):
  495.       lErr |= SAMP(NAV_Stop)();
  496.     // fall through
  497.   case SAMP(NAV_STOP_CALLED):
  498.     // fall through
  499. //todo: check with philips.  case SAMP(NAV_STOPPED):
  500.   case SAMP(NAV_ACTIVATING):
  501.        lErr |= SAMP(NAV_Subscribe)( NavCallback, 0);
  502. //       lErr |= SAMP(SAMP_Subscribe)( SampCallback, 0 );
  503.        //sacd todo: check later.
  504.        lErr |= SAMP(SAMP_Deactivate)();
  505.     // fall through
  506.   case SAMP(NAV_DEACTIVATED):
  507.   case SAMP(NAV_NOT_ACTIVATED):
  508.     {
  509.       // Deactivated -> nothing to be done!
  510.     }
  511.     break;
  512.   default:
  513.     {
  514.      tr_printf(("Warning: Nav_SACD_Desctructor: Unknown nav state"));
  515.     }
  516.     break;
  517.   }
  518.   DAC_SACD_SetMute(TRUE);
  519.   //IIS is back to PCM mode. In this order noise is minimized during the transition.
  520.   SAMP(BE_Term)();
  521. // <<< SEC shKang042304 : when power off, spindle has to be stopped by coremain
  522. if (g_power_state == POWER_SEQUENCE_OFF_REQUESTED)
  523. {
  524. tr_printf(("n auto spindown because of power off !!! n "));
  525. PE_SACD_AbortPlayback(0);
  526. }
  527. // SEC shKang042304 >>>
  528.   
  529. #ifdef AUDIO_DAC_SUPPORT_DSD
  530. //  DAC_Set_DSD_Mode(0); //back to pcm mode.
  531. #else
  532.   lErr = SAMP(APM_SetInputMode)(SAMP(SACD_IN_PCM_44));
  533.   lErr = SAMP(APM_SetOutputMode)(SAMP(APM_OUT_BPS), SAMP(APM_OUT_BPS));
  534. #endif
  535.   lErr |= SAMP(SAMP_Term)();
  536.   SACD_ISR_Uninstall();
  537.   DAC_SACD_SetMute(FALSE);
  538.   //set Furore chip to bypass mode.
  539. //  FuroreSetExternalInputPCMMode();
  540. #ifndef SACD_AREA_INFO_INSDRAM
  541.   sc_Free(SACD_GLOBALS.StereoAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
  542.   sc_Free(SACD_GLOBALS.MultiAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
  543. #endif
  544.   if(SAMP(ERR_OK) != lErr){
  545.    tr_printf(("FATAL NAV_SACD: fail in destructor.n"));
  546.   }
  547. }
  548. /*
  549. Desc: call back function for SAMP events.
  550. */
  551. static void SampCallback(SAMP(BitSet32) Event, void * EventData)
  552. {
  553.   switch( Event )
  554.   {
  555.   case SAMP_ACTIVATED :
  556.     DAC_Set_DSD_Mode(1); //todo: check later.
  557.  g_disc_is_hybrid_sacd = SACD_GLOBALS.hybrid;
  558.     SACD_GLOBALS.samp_state = SAMP_ACTIVATED;
  559. #ifdef SACD_AREA_INFO_INSDRAM
  560.     //todo: update  SACD_GLOBALS.activeArea
  561.     if(Nav_SACD_Get_Num_Of_Tracks(SAMP(SACD_AREA_MULTICHANNEL)) > 0)
  562.      SACD_GLOBALS.activeArea = SAMP(SACD_AREA_MULTICHANNEL);
  563.     else
  564.      SACD_GLOBALS.activeArea = SAMP(SACD_AREA_STEREO);
  565. #else
  566.     SaveSACDAreaInfo(SACD_GLOBALS.pAreaStereo, SACD_GLOBALS.pAreaMulti);
  567.     if(SACD_GLOBALS.pAreaMulti->NumberOfTracks > 0)
  568.      SACD_GLOBALS.activeArea = SAMP(SACD_AREA_MULTICHANNEL);
  569.     else
  570.      SACD_GLOBALS.activeArea = SAMP(SACD_AREA_STEREO);
  571.     if(NULL != SACD_GLOBALS.pAreaStereo)
  572.     {
  573.      free(SACD_GLOBALS.pAreaStereo);
  574.      SACD_GLOBALS.pAreaStereo = NULL;
  575.     }
  576.     if(NULL != SACD_GLOBALS.pAreaMulti)
  577.     {
  578.      free(SACD_GLOBALS.pAreaMulti);
  579.      SACD_GLOBALS.pAreaMulti = NULL;
  580.     }
  581. #endif
  582.   break;
  583.   case SAMP_NOT_ACTIVATED:
  584.     SACD_GLOBALS.samp_state = SAMP_NOT_ACTIVATED;
  585.     ie_send(IE_CORE_SACD_IDENTIFICATION_FAILED);
  586.   break;
  587.   default:
  588.     tr_printf(( "Unknown SAMP event received" ));
  589.   break;
  590.   }
  591. }
  592. //extern int track_playing;//jerry todo: remove later.
  593. /*
  594. Desc: callback function for NAV events.
  595. */
  596. static void NavCallback(SAMP(BitSet32) Event, void * EventData)
  597. {
  598.   SAMP(ErrCode)  lErr = SAMP(ERR_OK);
  599.   SACD_GLOBALS.nav_state = Event;
  600.   switch( Event )
  601.   {
  602.   case NAV_ACTIVATED:
  603. #if 1 //jerry cai //todo: check later.
  604.  gcs.mstate = MST_DISC_READY; //UI will detect this state change then open SACD menu and issue restart.
  605. #endif
  606.  gcs.pstate= PST_STOP;
  607.  CLEAR_COP_MASK(0xFFFFFFFFL);
  608.  SET_COP_MASK(COP_RESTART|COP_PLAY|COP_TIME_PLAY|COP_SEAMLESS_MODE_CHANGE);//scan is not allowed by SAMP yet.
  609. //    DAC_SACD_SetMute(FALSE);
  610.     ie_send(IE_CORE_SAMP_NAV_ACTIVATED);
  611.     break;
  612.   case NAV_NOT_ACTIVATED:
  613.  gcs.pstate= PST_STOP;
  614.  CLEAR_COP_MASK(0xFFFFFFFFL);
  615.  SET_COP_MASK(COP_EJECT|COP_SETUP);
  616.     break;
  617.   case NAV_STARTED:
  618. //    track_playing = 1; //jerry todo: remove later.
  619. #if 0 //jerry cai //todo: check later.
  620.  gcs.mstate = MST_DISC_READY; //UI will detect this state change then open SACD menu and issue restart.
  621. #endif
  622.  CLEAR_COP_MASK(COP_PLAY);
  623.  SET_COP_MASK(COP_STOP|COP_PAUSE|COP_SCAN|COP_SCAN_BACKWARD|COP_NEXT_CHAPTER|
  624.                  COP_PREVIOUS_CHAPTER|COP_REVERSE_PLAY|COP_ABREPEAT);
  625.  gcs.pstate= PST_PLAY;
  626.     {
  627.      SACD_GLOBALS.play_speed = *((SAMP(Int16) *) EventData);
  628.      if(1 != SACD_GLOBALS.play_speed)
  629.      {
  630.    gcs.pstate= PST_SCAN;  //either forward or backward
  631.    SET_COP_MASK(COP_PLAY); //for SAMP, play command will resume normal speed playback.
  632.      }
  633.     }
  634.     break;
  635.   case NAV_PAUSED:
  636.  CLEAR_COP_MASK(COP_PAUSE);
  637.     SET_COP_MASK(COP_PLAY); //scan, next/prev is allowed in pause state.
  638.  gcs.pstate= PST_PAUSE;
  639.     break;
  640.   case NAV_STOPPED:
  641.   //Does it mean the whole play list has been finished?
  642.   case NAV_FINISHED:
  643.  CLEAR_COP_MASK(COP_STOP|COP_PAUSE|COP_SCAN|COP_SCAN_BACKWARD|COP_NEXT_CHAPTER|
  644.                  COP_PREVIOUS_CHAPTER|COP_REVERSE_PLAY|COP_ABREPEAT); //time play is allowed
  645.     SET_COP_MASK(COP_PLAY);
  646.  gcs.pstate= PST_STOP;
  647. // <<< SEC shKang042204 : after finishing the total track, has to be a full stop status.
  648. #ifdef EXINO2
  649. g_in_full_stop = TRUE;
  650. #endif // EXINO2
  651. // SEC shKang042204 >>>
  652.     break;
  653.   case NAV_PROGRESS_INFO:
  654.     {
  655.     SAMP(NAV_ProgressInfoDef) *info = (SAMP(NAV_ProgressInfoDef) *) EventData;
  656.     SACD_GLOBALS.iCurrentTime = info->rel_time.min*60 + info->rel_time.sec;
  657. #ifdef SACD_DO_NOT_DISPLAY_COUNT_DOWN_IN_PAUSE_AREA
  658.     if(0 == info->index)
  659.     SACD_GLOBALS.iCurrentTime = 0;
  660. #endif
  661.     SACD_GLOBALS.iCurrentAbsTime = info->abs_time.min*60 + info->abs_time.sec;
  662.     ie_send(IE_UI_TIME_UPDATE);
  663.     if(SACD_GLOBALS.currentTrack != info->track)
  664.      ie_send(IE_UI_TRACK_UPDATE);
  665.     SACD_GLOBALS.currentTrack = info->track;
  666.     SACD_GLOBALS.currentIndex = info->index;
  667.     }
  668.     break;
  669.   case NAV_MODE_CHANGE:
  670.     {
  671.     SAMP(NAV_ModeChangeDef) mode = *(SAMP(NAV_ModeChangeDef) *) EventData;
  672.     if(mode.reshuffled)
  673.     {
  674.      dbg_printf(("SAMP reshuffled"));
  675.     }
  676.     if(mode.repeat_ab_canceled)
  677.      PM_SetRepeatAB(0);
  678.     }
  679.     break;
  680.   case NAV_WARNING:
  681.     {
  682.     SAMP(NAV_WarningCodeDef) warningCode = *(SAMP(NAV_WarningCodeDef) *) EventData;
  683.     dbg_printf(("SAMP EventWarning: 0x%lx ", warningCode));
  684.     }
  685.     break;
  686.   case NAV_ERROR:
  687.     {
  688.     SAMP(NAV_ErrorCodeDef) errorCode = *(SAMP(NAV_ErrorCodeDef) *) EventData;
  689.     dbg_printf(("SAMP Eventerror: 0x%lx ", errorCode));
  690.     }
  691.     break;
  692.   case NAV_CHANNELS_CONFIG:
  693.     {
  694.     SACD_GLOBALS.channels = *((SAMP(SACD_ChannelsConfigDef) *)EventData);
  695.     }
  696.     break;
  697.   default:
  698.     dbg_printf(("SAMP Unkown Event"));
  699.   break;
  700.   }
  701. }
  702. /*TODO: ask Philips to put the info directly in Scratch pad*/
  703. #ifndef SACD_AREA_INFO_INSDRAM
  704. static void SaveSACDAreaInfo(SAMP(SAMP_AreaInfoDef) *stereo,SAMP(SAMP_AreaInfoDef) *multi)
  705. {
  706.   sc_Write(SACD_GLOBALS.StereoAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4, (const Sc_cont *)stereo);
  707.   sc_Write(SACD_GLOBALS.MultiAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4, (const Sc_cont *)multi);
  708. }
  709. #endif
  710. UINT16 Nav_SACD_Get_Track_Start_Time(UINT16 trackNo)
  711. {
  712. #ifdef SACD_AREA_INFO_INSDRAM
  713.   DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SDRAM_MULTICH_AREA_INFO_BASE :
  714.                                                                          SDRAM_2CH_AREA_INFO_BASE;
  715. #else
  716.   WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SACD_GLOBALS.MultiAreaInfoPtr :
  717.                                                                          SACD_GLOBALS.StereoAreaInfoPtr;
  718. #endif
  719.   WORD i_hAddress;
  720.   char buff[8];
  721.   UINT16 startTime;
  722.   BYTE offset;
  723.   if(trackNo == 0) // track starts from 1.
  724.    return 0;
  725.   trackNo --;
  726. #ifdef SACD_AREA_INFO_INSDRAM
  727.   sc_GetBytes32(areaStartAddr, TRACK_START_INFO_LOCATION(trackNo), 2, buff);
  728.   startTime = buff[0]*60 + buff[1];
  729. #else
  730.   offset = TRACK_START_INFO_LOCATION(trackNo)%4;
  731.   i_hAddress = areaStartAddr + TRACK_START_INFO_LOCATION(trackNo)/4;
  732.   sc_Read(i_hAddress, 2, (Sc_cont *)buff);
  733.   startTime = buff[offset]*60 + buff[offset + 1];
  734. #endif
  735.   return startTime;
  736. }
  737. /*
  738. Desc: Get the length of a track. The information is retrieved from scratch pad.
  739. */
  740. UINT16 Nav_SACD_Get_Track_Length(UINT16 trackNo)
  741. {
  742. #ifdef SACD_AREA_INFO_INSDRAM
  743.   DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SDRAM_MULTICH_AREA_INFO_BASE :
  744.                                                                          SDRAM_2CH_AREA_INFO_BASE;
  745. #else
  746.   WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SACD_GLOBALS.MultiAreaInfoPtr :
  747.                                                                          SACD_GLOBALS.StereoAreaInfoPtr;
  748. #endif
  749.   WORD i_hAddress;
  750.   char buff[8];
  751.   UINT16 time;
  752.   BYTE offset;
  753.   if(trackNo == 0) // track starts from 1.
  754.    return 0;
  755. #if 0
  756.   startTime = Nav_SACD_Get_Track_Start_Time(trackNo);
  757.   if(trackNo == Nav_SACD_Get_Num_Of_Tracks(SACD_ACTIVE_AREA))
  758.    endTime = Nav_SACD_Get_Total_Time(SACD_ACTIVE_AREA);
  759.   else
  760.    endTime = Nav_SACD_Get_Track_Start_Time(trackNo+1);
  761.   return endTime - startTime;
  762. #endif
  763.   trackNo --;
  764. #ifdef SACD_AREA_INFO_INSDRAM
  765.   sc_GetBytes32(areaStartAddr, 5 + Nav_SACD_Get_Num_Of_Tracks(SACD_ACTIVE_AREA)*3 + trackNo*3, 2, buff);
  766.   time = buff[0]*60 + buff[1];
  767. #else
  768.   offset = TRACK_LEN_INFO_LOCATION(trackNo)%4;
  769.   i_hAddress = areaStartAddr + TRACK_LEN_INFO_LOCATION(trackNo)/4;
  770.   sc_Read(i_hAddress, 2, (Sc_cont *)buff);
  771.   time = buff[offset]*60 + buff[offset + 1];
  772. #endif
  773.   return time;
  774. }
  775. /*
  776. Desc: get number of tracks in an area.
  777. */
  778. UINT16 Nav_SACD_Get_Num_Of_Tracks(SAMP(SACD_Area) area)
  779. {
  780.   char buff[4];
  781.   UINT16 res;
  782. #ifdef SACD_AREA_INFO_INSDRAM
  783.   DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SDRAM_MULTICH_AREA_INFO_BASE :
  784.                                                                          SDRAM_2CH_AREA_INFO_BASE;
  785. #else
  786.   WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SACD_GLOBALS.MultiAreaInfoPtr :
  787.                                                                          SACD_GLOBALS.StereoAreaInfoPtr;
  788. #endif
  789. #ifdef SACD_AREA_INFO_INSDRAM
  790.   sc_GetBytes32(areaStartAddr, 0, 4, buff);
  791. #else
  792.   sc_Read(areaStartAddr, 1, (Sc_cont *)buff);
  793. #endif
  794.   res = (UINT16)buff[0];
  795.   res &= 0xff; //todo: check with Philips.
  796.   return res;
  797. }
  798. UINT16 Nav_SACD_Get_Total_Time(SAMP(SACD_Area) area)
  799. {
  800.   char buff[2];
  801.   UINT16 res;
  802. #ifdef SACD_AREA_INFO_INSDRAM
  803.   DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SDRAM_MULTICH_AREA_INFO_BASE :
  804.                                                                          SDRAM_2CH_AREA_INFO_BASE;
  805. #else
  806.   WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SACD_GLOBALS.MultiAreaInfoPtr :
  807.                                                                          SACD_GLOBALS.StereoAreaInfoPtr;
  808. #endif
  809. #ifdef SACD_AREA_INFO_INSDRAM
  810.   sc_GetBytes32(areaStartAddr, 2, 2, buff);   //tod: was 4 check with Philips.
  811. #else
  812.   sc_GetBytes(areaStartAddr, 4, 2, buff);
  813. #endif
  814.   res = (UINT16)buff[0]*60 + buff[1];
  815.   return res;
  816. }
  817. #endif // D_SUPPORT_SACD