sysmain_receiver.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:12k
源码类别:

DVD

开发平台:

C/C++

  1. #if defined (SUPPORT_APOGEE_AMP)||defined(SUPPORT_TUNER_MV114)||defined(SUPPORT_TUNER_ALPS)||defined(SUPPORT_RECEIVER)
  2. #ifdef SUPPORT_COAXIAL_IN  //xyy 2004-4-29  for XQ
  3. BYTE bCoaxialIn;
  4. #endif
  5. /*
  6.  huziqin 2004-2-26
  7.  call by tuner application and power amp's
  8. */
  9. UINT16 check_sum(BYTE *data,BYTE len)
  10. {
  11.     UINT16 sum = 0;
  12.     //printf("len %dn",len);
  13.     while(len>0)
  14.         {
  15.         sum += *data;
  16.         len --;
  17.         data ++;
  18.     };
  19.     //printf("sum %xn",sum);
  20.     return sum;
  21. }
  22. /*======================================================
  23. switch audio and video by gpio
  24. video: lower 4 bits
  25. 0--DVD
  26. 1--Video 1 in
  27. 2--Video 2 in
  28. Audio: upper 4 bits
  29. 0--MIC
  30. 1--AUDIO 1 in
  31. 2--AUDIO 2 in
  32. 3--TUNER in
  33. =======================================================*/
  34. //extern void set_downmix_off();//UINT8 setup_sel[MAX_SETUP_PAGE + MAX_CUSTM_SETUP_PAGE][MAX_PAGE_ITEM];
  35. /*
  36. When use av input function, the sft_cfg(part of GPIO setting) setting is done in this function.
  37. */
  38. void set_av_in_sft_cfg(void)//xyy 2004-3-23
  39. {
  40.     #if defined(SUNPLUS_RECEIVER_DVD)
  41.     regs0->sft_cfg6 &= ~(0x1 << 5);
  42.     #elif defined(XINGQIU_DVD_RECEIVER)
  43.     //
  44.     #endif
  45. }
  46. void av_in_switch(BYTE mode)
  47. {
  48.         printf("av_in_switchn");
  49. #if 0        
  50.     set_av_in_sft_cfg();//xyy 2004-3-23
  51.     GPIO_M_SET(AUIN_SL0, 1);             //xulf modified at 2004-2-20
  52.     GPIO_M_SET(AUIN_SL1, 1);
  53.     GPIO_M_SET(VIDEO_SL0, 1);
  54.     GPIO_M_SET(VIDEO_SL1, 1);
  55.     GPIO_E_SET(AUIN_SL0, 1);
  56.     GPIO_E_SET(AUIN_SL1, 1);
  57.     GPIO_E_SET(VIDEO_SL0, 1);
  58.     GPIO_E_SET(VIDEO_SL1, 1);
  59.     //AudioSetEcho(0,0);
  60.     //echo_level = 0;
  61.     //setup_SetEcho();
  62.     //AudioSetMIC(1, 0); //Set MIC always on, 1:always on, (the second parameter:unsed now)
  63.     //AudioSetMIC(1,1); 
  64.     //AudioSetMICVol(8);
  65.     //AudioSetMICVol_2(8); 
  66.     //downmix off
  67.     //set_downmix_off();
  68.     //AudioSetOutputMode(6, 0); //Set Output mode(4:AC3 5.1 channel)
  69.     //run_save_sel_cmd(3, 0);
  70. //Audio ======================================  
  71.     if((mode>>4) == 0)
  72.     {
  73.         printf("mic inputn");
  74.         GPIO_O_SET(AUIN_SL1, 0);
  75.         GPIO_O_SET(AUIN_SL0, 0);
  76.     }
  77.     if((mode>>4) == 1)
  78.     {
  79.         printf("audio 1 inputn");
  80.         GPIO_O_SET(AUIN_SL1, 0);
  81.         GPIO_O_SET(AUIN_SL0, 1);
  82.     }
  83.     if((mode>>4) == 2)
  84.     {
  85.         printf("audio 2 inputn");
  86.         GPIO_O_SET(AUIN_SL1, 1);
  87.         GPIO_O_SET(AUIN_SL0, 0);
  88.     }
  89.     if((mode>>4) == 3)
  90.     {
  91.         printf("tuner inputn");
  92.         GPIO_O_SET(AUIN_SL1, 1);
  93.         GPIO_O_SET(AUIN_SL0, 1);
  94.     }
  95. //Video ======================================
  96.     if((mode&0x0f) == 0)
  97.     {
  98.         printf("out_0n");
  99.         GPIO_O_SET(VIDEO_SL1, 0);
  100.         GPIO_O_SET(VIDEO_SL0, 0);
  101.     }
  102.     if((mode&0x0f) == 1)
  103.     {
  104.         printf("out_1n");
  105.         GPIO_O_SET(VIDEO_SL1, 1);
  106.         GPIO_O_SET(VIDEO_SL0, 0);
  107.     }
  108.     if((mode&0x0f) == 2)
  109.     {
  110.         printf("out_2n");
  111.         GPIO_O_SET(VIDEO_SL1, 0);
  112.         GPIO_O_SET(VIDEO_SL0, 1);
  113.     }
  114. #endif    
  115. }
  116. #ifdef DOLBY_AMP_VOLUME_CTRL
  117. extern void init_subvol();
  118. #endif
  119. void receiver_startup()
  120. {
  121. next_rcvr_mode =RECEIVER_MODE_DVD;  // this is changeable
  122.  
  123.  // Simon 12-4-2003
  124.  // Calculate support bits
  125.  rcvr_support_bits = 0;
  126.  #ifdef SUPPORT_DVD_PLAYER
  127.     rcvr_support_bits += (1 << RECEIVER_MODE_DVD);
  128.  #endif
  129.  #ifdef SUPPORT_AV_IN
  130.     rcvr_support_bits += (1 << RECEIVER_MODE_AV1);
  131.  #endif
  132.  #ifdef SUPPORT_SECOND_AV_IN
  133.     rcvr_support_bits += (1 << RECEIVER_MODE_AV2);
  134.  #endif
  135.  #ifdef SUPPORT_SPDIF_IN
  136.     rcvr_support_bits += (1 << RECEIVER_MODE_SPDIF);
  137.  #endif
  138.  #ifdef SUPPORT_COAXIAL_IN  //xyy 2004-4-29 for XQ
  139.   rcvr_support_bits += (1 << RECEIVER_MODE_COAXIAL);
  140.  #endif
  141.  #ifdef SUPPORT_TUNER_MV114
  142.     rcvr_support_bits += (1 << RECEIVER_MODE_TUNER);
  143.  #endif
  144.  #ifdef SUPPORT_DUMMY_MODE
  145.     rcvr_support_bits += (1 << RECEIVER_MODE_DUMMY);
  146.  #endif
  147.  
  148.  if (next_rcvr_mode == RECEIVER_MODE_DVD)
  149.  {
  150.     // original code moved to dvd_startup()
  151.     // The code is right before ap_main()
  152.     dvd_startup();
  153.     switch_modes_now = 0;
  154.     servo_inited = 1;
  155.     av_in_switch(0);
  156.     //psprintf(RegionValStr[REGION2], "DVD");
  157.     //PrintOsdMsg(STR_OS_SPACE, REGION2, 0, 1);
  158.  } 
  159.  else   // Start in a non-DVD mode
  160.  {
  161.     // In the future, we will enter this first,
  162.     // as soon as I figure out how to manage the states and loader
  163.     // correctly.
  164.     // 12-16-2003 Update:  DVD works w/o starting in DVD
  165.  #if DISC_SYSTEM==DISC_SYSTEM_ATAPI
  166. servo_inited = 1;
  167.  #endif
  168.     switch_modes_now = 1;
  169.     system_state = SYSTEM_MODE_CHANGE;
  170.  }
  171. #ifdef DOLBY_AMP_VOLUME_CTRL
  172. init_subvol();
  173. #endif
  174. }
  175. void show_noise_channel(ch)
  176. {
  177. switch(ch)
  178. {
  179. case 0: 
  180. psprintf(RegionValStr[REGION2], "TEST FL");
  181. break;
  182. case 1:
  183. psprintf(RegionValStr[REGION2], "TEST CE");
  184. break;
  185. case 2:
  186. psprintf(RegionValStr[REGION2], "TEST FR");
  187. break;
  188. case 3:
  189. psprintf(RegionValStr[REGION2], "TEST SR");
  190. break;
  191. case 4:
  192. psprintf(RegionValStr[REGION2], "TEST SL");
  193. break;
  194. default:
  195. break;
  196. }
  197.     PrintOsdMsg(STR_OS_SPACE, REGION2, 0, 1);
  198. }
  199. void do_noise_sequencer(void)
  200. {
  201. BYTE ch = 0;
  202.     AUDIF_Reset_DSP();//2004AUDDRV DSPReset();
  203.     //init_audio_dsp_coding_mode();                
  204.     AUDIF_Init_DSPCodingMode();
  205.     AUDIF_Set_SampleRate(FS_44K);//2004AUDDRV audif_set_sample_rate(FS_44K);
  206.     AUDIF_Set_CodingMode(AUDIF_CODING_MODE_NOISE);//2004AUDDRV audif_set_coding_mode(AUDIF_CODING_MODE_NOISE);
  207.     GPIO_DEMUTE();
  208.     watchdog_onoff(0);
  209.     system_state = SYSTEM_DOING_NOISE;
  210.     while (system_state == SYSTEM_DOING_NOISE)
  211.     {
  212.         ch = get_dsp3_pcm_value(22);
  213.         show_noise_channel(ch);
  214.     
  215.      polling();
  216.     }
  217.                 
  218. }
  219. #ifdef TP6311_DRIVER_VFD
  220. extern UINT16  vfd_set_av1(UINT16 index);
  221. extern UINT16  vfd_set_av2(UINT16 index);
  222. extern UINT16  vfd_set_spdifin(UINT16 index);
  223. #endif
  224. extern void stop_loader(void);
  225. #include "hc4094.c"
  226. #include "hc165.c"
  227. #include "rom_bus_io.h"
  228. #define STOP_SERVO_IN_OTHER_MODE  //huziqin 2004-4-27
  229. #ifdef STOP_SERVO_IN_OTHER_MODE
  230. void wait_servo_stop(void)
  231. {
  232. //drv_init();
  233.     delay_srv_10ms(100);
  234.     //system_stop();
  235.     stop_loader();
  236.     delay_srv_10ms(5);
  237. }
  238. #endif
  239. void receiver_check_system_state()
  240. {
  241. int init_cnt=0;
  242.     switch(system_state)
  243.     {
  244.         case SYSTEM_MODE_CHANGE:
  245.           switch_modes_now = 0;
  246.           ClearOsdMsg(0);
  247.           current_rcvr_mode = next_rcvr_mode;
  248.  #ifdef SUPPORT_COAXIAL_IN  //xyy 2004-4-29  for XQ
  249.   if(current_rcvr_mode == RECEIVER_MODE_SPDIF)
  250.   {
  251.      bCoaxialIn = 0;
  252. GPIO_O_SET(OPT_COAX_SEL,0);
  253.    }
  254.    else if(current_rcvr_mode == RECEIVER_MODE_COAXIAL)
  255.    {
  256.    bCoaxialIn = 1;
  257. GPIO_O_SET(OPT_COAX_SEL,1);
  258.     }
  259.  #endif
  260.           
  261.           
  262.         switch (current_rcvr_mode)
  263.         {
  264.             case RECEIVER_MODE_DVD:
  265.             #ifdef HC4094
  266.                  hc4094_set_io(HC4094_DVD_MODE); // wzj 2004-7-13
  267.             #endif
  268.             #ifdef ROM_BUS_EXTENT_IO    
  269.                 audio_sel_gnd();
  270.             #endif //ROM_BUS_EXTENT_IO    
  271.                 if (!servo_inited)
  272.                 {
  273.                     drv_init();
  274.                     servo_inited = 1;
  275.                 }
  276.                 else 
  277.                 {
  278.                     close_tray(0);
  279.                 }
  280.                 dvd_startup();
  281.                 
  282.             break;          
  283.             case RECEIVER_MODE_AV1:
  284.                 AUDIF_Reset_DSP();//2004AUDDRV DSPReset();
  285.                 //init_audio_dsp_coding_mode();    
  286.                 AUDIF_Init_DSPCodingMode();            
  287.                 AUDIF_Set_SampleRate(FS_44K);//2004AUDDRV audif_set_sample_rate(FS_44K);
  288.                 AUDIF_Set_CodingMode(AUDIF_CODING_MODE_TUNER);//2004AUDDRV audif_set_coding_mode(AUDIF_CODING_MODE_TUNER);
  289.             #ifdef HC4094
  290.                 hc4094_set_io(HC4094_AV1_MODE);
  291.             #endif  
  292.             #ifdef ROM_BUS_EXTENT_IO
  293.                 audio_sel_aux();
  294.             #endif //ROM_BUS_EXTENT_IO    
  295.                 //av_in_switch(0x11);
  296.                 GPIO_DEMUTE();
  297.                 AUDIF_Set_Echo(0,0);//2004AUDDRV AudioSetEcho(0,0);  //huziqin 2004-2-26
  298. #ifdef TP6311_DRIVER_VFD
  299.                 vfd_set_av1(0);
  300. #endif
  301. #ifdef STOP_SERVO_IN_OTHER_MODE
  302.                 wait_servo_stop();
  303.                 psprintf(RegionValStr[REGION2], "AV1");
  304.                 PrintOsdMsg(STR_OS_SPACE, REGION2, 0, 1);
  305. #endif                
  306.                 
  307.                 system_state = SYSTEM_DOING_AV1;            
  308.              while (system_state == SYSTEM_DOING_AV1)
  309.                 {
  310.                  polling();
  311.                 }
  312.              break;
  313.             case RECEIVER_MODE_AV2:
  314.                 do_noise_sequencer();
  315.                 
  316.              break;
  317. #ifdef SUPPORT_SPDIF_IN
  318.             case RECEIVER_MODE_SPDIF:
  319. #ifdef SUPPORT_COAXIAL_IN  //xyy 2004-4-29 for XQ
  320.             case RECEIVER_MODE_COAXIAL:
  321. #endif
  322.                 
  323.                  
  324. #ifdef SUPPORT_COAXIAL_IN  //xyy 2004-4-29 for XQ
  325.                vfd_set_spdifin(bCoaxialIn);
  326. #else
  327.                //vfd_set_spdifin(0);
  328. #endif
  329.              GPIO_DEMUTE();
  330.                 //av_in_switch(0x02);         
  331.                 
  332.                 AUDIF_Reset_DSP();//2004AUDDRV DSPReset();
  333.                 //init_audio_dsp_coding_mode();
  334.                 AUDIF_Init_DSPCodingMode();
  335.                 AUDIF_Set_SampleRate(FS_44K);//2004AUDDRV audif_set_sample_rate(FS_44K);
  336.                 AUDIF_Set_CodingMode(AUDIF_CODING_MODE_SPDIFINCD);//2004AUDDRV audif_set_coding_mode(AUDIF_CODING_MODE_SPDIFINCD);
  337.             
  338.              
  339.                 spdif_in_init();
  340. #ifdef TP6311_DRIVER_VFD                
  341.                vfd_set_spdifin(0);
  342. #endif
  343.                 system_state = SYSTEM_DOING_SPDIF;
  344.             while (system_state == SYSTEM_DOING_SPDIF) 
  345.             {                
  346.                 delay_1ms(1);
  347.                 polling();
  348.                 if(!(full_scrn & SOUND))
  349.                     spdif_in_init();
  350.             }
  351.             
  352.             break;
  353. #endif  // SUPPORT_SPDIF_IN         
  354.             case RECEIVER_MODE_TUNER:
  355.             #ifdef HC4094
  356.                 hc4094_set_io(HC4094_TUNER_MODE);
  357.             #endif    
  358.                 GPIO_DEMUTE();
  359. #ifdef SUPPORT_TUNER_MV114  //xyy 2003-10-10 13:30
  360.                 ShowTitle();
  361.              AUDIF_Reset_DSP();//2004AUDDRV DSPReset();
  362.                 //init_audio_dsp_coding_mode();      
  363.                 AUDIF_Init_DSPCodingMode();          
  364.                 AUDIF_Set_SampleRate(FS_44K);//2004AUDDRV audif_set_sample_rate(FS_44K);
  365.                 AUDIF_Set_CodingMode(AUDIF_CODING_MODE_TUNER);//2004AUDDRV audif_set_coding_mode(AUDIF_CODING_MODE_TUNER);
  366.              system_state = SYSTEM_DOING_TUNER;
  367.             
  368.              watchdog_onoff(0);      //close watchdog for tuner auto search no reset hongfeng 2005-01-21
  369.              tuner_main();
  370. #endif
  371. #ifdef ROM_BUS_EXTENT_IO
  372.                 tuner_power_set(0);
  373. #endif //ROM_BUS_EXTENT_IO
  374.             break;
  375.           }
  376.         break;
  377.     // Simon: 1-7-2004
  378.     // This state occurs when we use eject
  379.     // To switch back to DVD mode
  380.     case SYSTEM_EJECT_CHANGE:
  381.         next_rcvr_mode = RECEIVER_MODE_DVD;
  382.         current_rcvr_mode = next_rcvr_mode;
  383.         switch_modes_now = 0;
  384.         ircmd_trayout();
  385.         system_state = SYSTEM_OPEN;
  386.         psprintf(RegionValStr[REGION2], "DVD");
  387.             PrintOsdMsg(STR_OS_SPACE, REGION2, 0, 1);
  388.         break;
  389.         }   
  390. }    
  391. #endif