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

DVD

开发平台:

C/C++

  1. #include "user_init.h"
  2. #ifdef SUPPORT_CARD_STORAGE
  3. #include "global.h"
  4. #include "ata.h"
  5. #include "atapi_if.h"
  6. #include "emuio.h"
  7. #include "func.h"
  8. #include "memmap.h"
  9. #include "cderr.h"
  10. #include "cardfs.h"
  11. //#ifndef GBM_CARD_READER
  12. #if !defined(GBM_CARD_READER)&& !defined(HJ023_CARD_READER)&& !defined(QSI_PORTABLE_DVD)
  13. #define CARD_RESET_INVERSE
  14. #endif
  15. //extern void dac_turn_on();
  16. extern int  font_decompress(void);
  17. //2004AUDDRV extern void DSPReset();
  18. extern void flush_atapi(void);
  19. //#define CARDIF_DBG
  20. extern BYTE    idIDECard;
  21. BYTE    iThCardPlugged=0; //Jeff 20021231
  22. void SetCardCs1Cs2Enable(void)//kenny 200212/26 , enable 74HC367, let card's CS1,CS2 enable
  23. {
  24.     #ifdef CARD_HOT_PLUG
  25.         #ifdef CARD_RESET_INVERSE
  26.             regs0->gpio_oe[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16)); //input mode 
  27.             delay_srv_10ms(10);
  28.         #else
  29.             regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  30.             regs0->gpio_out[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16));//output LOW to GPIO17
  31.             delay_srv_10ms(10);
  32.         #endif
  33.     #endif
  34. }
  35. //kenny move polling card plug in or not from polling.c 2002/12/26
  36. void polling_card_plug(void)
  37. {
  38.     if (media_type == MEDIA_CARD) {
  39.         if (resumeMSF!=0) {
  40.             resumeMSF = 0;
  41.         }
  42.     }
  43.     if ( //(system_state!=SYSTEM_BROWSE) && //kenny mark it 2003/1/26
  44.         ( !(card_plug_state&CARD_HAD_PLUGGED_IN) ) &&
  45.         CARDIsPlugIn()
  46.        )//User do plug-in action 
  47.     {
  48.         card_plug_state |= USER_DO_PLUG_IN;//clear this flag in CardTestReady()
  49.     }
  50.     if( !CARDIsPlugIn() )
  51.     {
  52.         #ifdef CARD_HOT_PLUG
  53.             #ifdef CARD_RESET_INVERSE
  54.                 regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  55.                 regs0->gpio_out[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16));//output LOW to GPIO17
  56.             #else
  57.                 #ifndef QSI_PORTABLE_DVD
  58.                 regs0->gpio_oe[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16)); //input mode               
  59.                 #else
  60.                    regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  61.                 regs0->gpio_out[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16));//output HIGH               
  62.              #endif
  63.             #endif
  64.         #endif
  65.         if(card_plug_state&CARD_HAD_PLUGGED_IN)//kenny 2003/1/23
  66.         card_plug_state|=USER_DO_PLUG_OUT;
  67.         
  68.         card_plug_state&=~CARD_HAD_PLUGGED_IN;
  69.     } else {
  70.         card_plug_state&=~USER_DO_PLUG_OUT;
  71.         card_plug_state|=CARD_HAD_PLUGGED_IN;
  72.     }
  73.     
  74.     //printf("S1=%x M1=%d n",card_plug_state,media_type);
  75.     
  76. #ifdef IDE_DIAGNOSTIC
  77. //yw 030303
  78. void CardTestReady()
  79. {
  80. //==============================================
  81. //for QSI source switch //added by JS //20040726
  82. #ifdef SUPPORT_QSI_SOURCE_SWITCH
  83. if (source_type_now!= source_card) {
  84. return;
  85. #endif
  86. //==============================================
  87.   #ifdef __MAIN_MENU__ 
  88.   if(CARD_MASTER)
  89.    {
  90. //     if ( CardIsExist() ) {
  91.      if ( FSIsExist() ) {
  92.         #ifdef CARDIF_DBG
  93.         printf("STSTEM STATE=%d:Card Existn",system_state);
  94.         #endif
  95.         CardSetBrowse();    //Maoyong 2004.05.18
  96.         //dac_turn_on(); 
  97.         card_plug_state&=~USER_DO_PLUG_IN;//kenny 2002/11/12
  98.         card_plug_state|=CARD_HAD_PLUGGED_IN;//kenny 2002/11/12
  99.         //printf("2.card_plug_state=%xn",card_plug_state);
  100.         } else {
  101.         #ifdef CARDIF_DBG
  102.         printf("STSTEM STATE=%d:Card not Foundtn",system_state);
  103.         #endif
  104.         CardReset();
  105.         if (idIDECard != IDE_MASTER_ID) { //Jeff 20021206
  106.             media_type = MEDIA_CD;
  107.         }
  108.       }
  109.    }
  110.   else
  111.    {
  112. //      if(CardIsExist()){
  113.       if(FSIsExist()){
  114.           ClearOsdMsg(1);
  115.           //dac_turn_on();
  116.           card_plug_state &= ~USER_DO_PLUG_IN;
  117.           card_plug_state |= CARD_HAD_PLUGGED_IN;
  118.       } else
  119.       {
  120.         CardReset();
  121.         if(idIDECard != IDE_MASTER_ID){
  122.             //media_type = MEDIA_CD;
  123.         }
  124.       }
  125.    }  
  126.   #else
  127. //    if ( CardIsExist() ) {
  128.     if ( FSIsExist() ) {
  129.         #ifdef CARDIF_DBG
  130.         printf("STSTEM STATE=%d:Card Existn",system_state);
  131.         #endif
  132.         CardSetBrowse(); 
  133.         //dac_turn_on(); 
  134.         card_plug_state&=~USER_DO_PLUG_IN;//kenny 2002/11/12
  135.         card_plug_state|=CARD_HAD_PLUGGED_IN;//kenny 2002/11/12
  136.         //printf("2.card_plug_state=%xn",card_plug_state);
  137.     } else {
  138.         #ifdef CARDIF_DBG
  139.         printf("STSTEM STATE=%d:Card not Foundn",system_state);
  140.         #endif
  141.         CardReset();
  142.         if (idIDECard != IDE_MASTER_ID) { //Jeff 20021206
  143.             media_type = MEDIA_CD;
  144.         }
  145.     }
  146.   #endif
  147. }
  148. #else
  149. void CardTestReady()
  150. {
  151. //==============================================
  152. //for QSI source switch //added by JS //20040726
  153. #ifdef SUPPORT_QSI_SOURCE_SWITCH
  154. if (source_type_now!= source_card) {
  155. return;
  156. #endif
  157. //==============================================
  158.   #if defined(__MAIN_MENU__) && !defined(CARD_MASTER)
  159. //    if(CardIsExist()){
  160.     if(FSIsExist()){
  161.         ClearOsdMsg(1);
  162.         //dac_turn_on();
  163.         card_plug_state &= ~USER_DO_PLUG_IN;
  164.         card_plug_state |= CARD_HAD_PLUGGED_IN;
  165.     } else
  166.     {
  167.         CardReset();
  168.         if(idIDECard != IDE_MASTER_ID){
  169.             //media_type = MEDIA_CD;
  170.         }
  171.     }
  172.   #else
  173. //    if ( CardIsExist() ) {
  174.     if ( FSIsExist() ) {
  175.         #ifdef CARDIF_DBG
  176.         printf("STSTEM STATE=%d:Card Existn",system_state);
  177.         #endif
  178.         flush_atapi();
  179.         CardSetBrowse();
  180.         //dac_turn_on(); 
  181.         card_plug_state&=~USER_DO_PLUG_IN;//kenny 2002/11/12
  182.         card_plug_state|=CARD_HAD_PLUGGED_IN;//kenny 2002/11/12
  183.         //printf("2.card_plug_state=%xn",card_plug_state);
  184.         
  185.     } else {
  186.         #ifdef CARDIF_DBG
  187.         printf("STSTEM STATE=%d:Card not Foundtn",system_state);
  188.         #endif
  189.         CardReset();
  190.         if (idIDECard != IDE_MASTER_ID) { //Jeff 20021206
  191.             media_type = MEDIA_CD;
  192.         }
  193.     }
  194.   #endif
  195. }
  196. #endif
  197. /* yw 030306
  198. void CardTestReady()
  199. {
  200. #if defined(__MAIN_MENU__) && !defined(CARD_MASTER)
  201. //    if(CardIsExist()){
  202.     if(FSIsExist()){
  203.         ClearOsdMsg(1);
  204.         //dac_turn_on();
  205.         card_plug_state &= ~USER_DO_PLUG_IN;
  206.         card_plug_state |= CARD_HAD_PLUGGED_IN;
  207.     } else
  208.     {
  209.         CardReset();
  210.         if(idIDECard != IDE_MASTER_ID){
  211.             //media_type = MEDIA_CD;
  212.         }
  213.     }
  214. #else
  215. //    if ( CardIsExist() ) {
  216.     if ( FSIsExist() ) {
  217.         #ifdef CARDIF_DBG
  218.         printf("STSTEM STATE=%d:Card Existn",system_state);
  219.         #endif
  220.         ClearOsdMsg(1);
  221.         browser = read_iso9660;
  222.         cd_type_loaded=CDROM;
  223.         cd_type=CDROM;
  224.         play_state=VCD_STATE_CLOSE;
  225.         system_state=SYSTEM_BROWSE;
  226.         sys_cmd=CMD_FUNC|CMD_FUNC_CLOSE;
  227.         media_type = MEDIA_CARD; 
  228.         //dac_turn_on(); 
  229.         card_plug_state&=~USER_DO_PLUG_IN;//kenny 2002/11/12
  230.         card_plug_state|=CARD_HAD_PLUGGED_IN;//kenny 2002/11/12
  231.         //printf("2.card_plug_state=%xn",card_plug_state);
  232.     } else {
  233.         #ifdef CARDIF_DBG
  234.         printf("STSTEM STATE=%d:Card not Foundtn",system_state);
  235.         #endif
  236.         CardReset();
  237.         if (idIDECard != IDE_MASTER_ID) { //Jeff 20021206
  238.             media_type = MEDIA_CD;
  239.         }
  240.     }
  241. #endif
  242. }
  243. */  
  244.   
  245. int CARDIsPlugIn()
  246. {
  247. #ifdef CARD_HOT_PLUG
  248.     
  249.     BYTE    newCardPlugged=0;
  250. //==============================================
  251. //for QSI source switch //added by JS //20040726
  252. #ifdef SUPPORT_QSI_SOURCE_SWITCH
  253. if (source_type_now!= source_card) {
  254. return 0;
  255. #endif
  256. //==============================================
  257.         
  258.     if ( (regs0->gpio_in[CF_CARD_DETECT_PIN/16] >> (CF_CARD_DETECT_PIN%16)) & 0x01) {
  259.         newCardPlugged &= ~0x01;
  260.     } else {
  261.         newCardPlugged |= 0x01;
  262.     }
  263.     if ( (regs0->gpio_in[CD_CARD_DETECT_PIN/16] >> (CD_CARD_DETECT_PIN%16)) & 0x01) {
  264.         newCardPlugged &= ~0x02;
  265.     } else {
  266.         newCardPlugged |= 0x02;
  267.     }
  268.     if (newCardPlugged==0) {
  269.         iThCardPlugged = 0;    
  270.     } else if (newCardPlugged==3) {
  271.         iThCardPlugged = 0;
  272.     } else {
  273.         iThCardPlugged = newCardPlugged;
  274.     }
  275.     if (iThCardPlugged>0)
  276.         return 1;
  277.     else
  278.         return 0;
  279.     
  280. #else
  281.     return 1;
  282. #endif
  283. }
  284. #ifdef CARD_DISABLE_LOADER_SCHEME
  285. void CardDisable()
  286. {
  287.     //set CARD_RESET_PIN:gpio17 pin( open drain pin) High to reset 
  288.     #ifdef CARD_RESET_INVERSE
  289.         regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16));
  290.         regs0->gpio_out[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16));
  291.     #else
  292.         #ifndef QSI_PORTABLE_DVD
  293.            regs0->gpio_oe[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16)); //input mode
  294.         #else
  295.            regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  296.            regs0->gpio_out[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16));//output HIGH               
  297.         #endif        
  298.     #endif
  299.     delay_srv_10ms(5);//Time for GPIO17 to be High
  300. }  
  301. #endif
  302. void CardReset()
  303. {
  304. #ifdef CARD_HOT_PLUG
  305.     //set CARD_RESET_PIN:gpio17 pin( open drain pin) High to reset 
  306.     #ifdef CARD_RESET_INVERSE
  307.         regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode
  308.         regs0->gpio_out[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16));//output LOW to GPIO17
  309.     #else
  310.         #ifndef QSI_PORTABLE_DVD
  311.            regs0->gpio_oe[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16)); //input mode
  312.         #else
  313.            regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  314.            regs0->gpio_out[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16));//output HIGH               
  315.         #endif
  316.     #endif
  317.     
  318.     delay_srv_10ms(80);//Time for GPIO17 to be High
  319.     
  320.     
  321.     if(CARDIsPlugIn())
  322.     {
  323.         #ifdef CARD_RESET_INVERSE
  324.             regs0->gpio_oe[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16)); //input mode to pull high
  325.         #else
  326.             regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode 
  327.             regs0->gpio_out[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16));//output LOW to GPIO17
  328.         #endif
  329.     }
  330. /*    
  331.     else
  332.     {
  333.         #ifdef CARD_RESET_INVERSE
  334.             regs0->gpio_out[CARD_RESET_PIN/16] &= ~(0x1<<(CARD_RESET_PIN%16));//output LOW to GPIO17
  335.             regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  336.         #else
  337.             regs0->gpio_out[CARD_RESET_PIN/16] |=(0x1<<(CARD_RESET_PIN%16));//output High to GPIO17
  338.             regs0->gpio_oe[CARD_RESET_PIN/16] |= (0x1<<(CARD_RESET_PIN%16)); //output mode  
  339.         #endif
  340.     } 
  341. */    
  342.     
  343.     delay_srv_10ms(100);//don't cancel this delay, if it is cancel some card will read fail
  344.     
  345.     #ifdef CARDIF_DBG
  346.     printf("CardResetn");
  347.     #endif
  348.     
  349.     font_decompress();
  350.     osd_init();
  351.     AUDIF_Reset_DSP();//2004AUDDRV DSPReset();
  352.     
  353. #endif
  354. }
  355. #endif //SUPPORT_CARD_STORAGE