8202_usb_card_if.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:46k
- /**************************************************************************
- * *
- * Copyright (c) 2002 by Sunplus Technology Co., Ltd. *
- * *
- * This software is copyrighted by and is the property of Sunplus *
- * Technology Co., Ltd. All rights are reserved by Sunplus Technology *
- * Co., Ltd. This software may only be used in accordance with the *
- * corresponding license agreement. Any unauthorized use, duplication, *
- * distribution, or disclosure of this software is expressly forbidden. *
- * *
- * This Copyright notice MUST not be removed or modified without prior *
- * written consent of Sunplus Technology Co., Ltd. *
- * *
- * Sunplus Technology Co., Ltd. reserves the right to modify this *
- * software without notice. *
- * *
- * Sunplus Technology Co., Ltd. *
- * 19, Innovation First Road, Science-Based Industrial Park, *
- * Hsin-Chu, Taiwan, R.O.C. *
- **************************************************************************/
- /*--------------------------------------------------------------------------
- | File Name : 8202_usb_card_if.c
- |
- | Description : 8202 Usb and Card Interface
- |
- | Version : 0.1
- |
- |
- | Rev Date Author(s) Status & Comments
- |---------------------------------------------------------------------------------
- | 0.1 2004/9/18 wthsin Creating
- |--------------------------------------------------------------------------------*/
- #include "user_init.h"
- #include "global.h"
- #include "emuio.h"
- #include "gpio.h"
- #include "func.h"
- #include "cpu.h"//wanghaoying 20030812
- #include "macro.h"
- #include "memmap.h"
- #include "memmap0.h"
- #include "fsNav.h"//liweihua 2004-3-30 14:34
- #include "cderr.h"
- #include "cardfs.h"
- #include "osd.h"
- #include "scsi.h"
- #include "usb.h"
- #ifdef HOST_UHCI
- #include "uhci.h"
- #else
- #include "host_811.h"
- #endif
- #if defined(SPHE8202_CARD_STORAGE)
- #include "card_main.h"
- #include "sd.h"
- #include "cf.h"
- #include "ms.h"
- #endif
- #ifdef SUPPORT_MIDI ///xlluo add 04-1-21
- #include "fsmidi.h"
- #include "fsMidiUI.h"
- #endif
- #ifdef SPHE8202_ALL_TYPE_CARD_WRITE
- extern BYTE card_browse_sign;//dingzhy 4-11-18 9:40
- #endif
- #ifdef FILE_MODE_WRITE //sunzhh add for file mode 2005-1-14
- extern BYTE file_mode_flag;
- #endif
- #if defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)
- extern UINT8 MediaIsEmpty;
- extern void show_card_reading_osd(BYTE type);
- extern void ircmd_stop(void);
- extern void SwitchMedia(BYTE direction);
- #endif
- #if defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)
- //0x01: USB ,0x02: CF ,0x04: SD_MMC ,0x08: MS ,0x10: SMC
- const UINT8 storage_parity_type[]= { 0x00, 0x01, 0x02, 0x01, 0x04, 0x01, 0x02, 0x01,
- 0x08, 0x01, 0x02, 0x01, 0x04, 0x01, 0x02, 0x01,
- 0x10, 0x01, 0x02, 0x01, 0x04, 0x01, 0x02, 0x01,
- 0x08, 0x01, 0x02, 0x01, 0x04, 0x01, 0x02, 0x01,};
- #endif
- #ifndef DVDRELEASE
- #define USB_CARD_IF_DBG 1
- #endif
- #define D printf("INFO: __%d__(%s:%s)n",__LINE__,__FILE__,__FUNCTION__);
- #ifndef USB_CARD_IF_DBG
- #undef printf
- #undef print_block
- #define printf(f, a...) do {} while (0)
- #define print_block(x,y) do {} while (0)
- #endif
- #if defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)
- #ifdef SPHE8202_CARD_STORAGE
- UINT8 CardEna=0;
- #ifdef IR_SWITCH_CD_USB_CF_OTHER //dingzhy for bus switch 04-10-22
- EXTERN BYTE detect_result_last;
- EXTERN BYTE now_valid_type;
- #endif
- #ifdef CARD_SETUP_TYPE_5
- UINT8 PMP_CF_Card_Insert=0;
- UINT8 PMP_CF_Card_Play=0;
- #ifdef SUPPORT_MULTI_PARTITION
- extern void Refresh_Partition_Menu(void);
- #ifdef FAT_FILE_MODE
- extern UINT16 fat_play_mode;
- extern void Refresh_FAT_Mode_GUI(void);
- #endif//#ifdef FAT_FILE_MODE
- #endif//#ifdef SUPPORT_MULTI_PARTITION
- #endif //#ifdef CARD_SETUP_TYPE_5
- /**************************************************************************
- * *
- * Function Name: Card_power_reset *
- * *
- * Purposes: *
- * USE GPIO to reset card power *
- * Descriptions: *
- * USE GPIO to reset card power *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- void Card_power_reset()
- {
- GPIO_O_SET(CARD_POWER_RESET,1); //Power Off
- delay_srv_10ms(30);
- GPIO_O_SET(CARD_POWER_RESET,0); //Power On
- #if defined(CARD_SETUP_TYPE_1)||defined(CARD_SETUP_TYPE_2)
- regs0->fm_gpio_len = 12 // Set FMGPIO_B[41:0] turn on
- | (0xf << 4); // Set FMGPIO_B[41:0] enable
- #elif defined(CARD_SETUP_TYPE_3)||defined(CARD_SETUP_TYPE_5)
- regs0->fm_gpio_len = 11 // Set FMGPIO_B[26:0] turn on
- | (0xf << 4); // Set FMGPIO_B[26:0] enable
- #elif defined(CARD_SETUP_TYPE_4)
- regs0->fm_gpio_len = 3 // Set FMGPIO_B[5:0] turn on
- | (0x1 << 4); // Set FMGPIO_B[5:0] enable
- #endif
- delay_srv_10ms(30);
- }
- /**************************************************************************
- * *
- * Function Name: Card_power_off *
- * *
- * Purposes: *
- * turn off card power, let card invalid *
- * Descriptions: *
- * turn off card power, let card invalid *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- void Card_power_off()
- {
- GPIO_O_SET(CARD_POWER_RESET,1); //Power Off
- regs0->fm_gpio_len = 0;
- }
- /**************************************************************************
- * *
- * Function Name: Card_gpio_init *
- * *
- * Purposes: *
- * initialize card GPIO, Set card GPIO valid *
- * Descriptions: *
- * initialize card GPIO, Set card GPIO valid *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- void Card_gpio_init()
- {
- #ifdef CARD_SETUP_TYPE_1
- regs0->sft_cfg3 &= ~(0x1 << 5); //set GPIO 50 ca8202 pin193
- regs0->sft_cfg1 &= ~(0x1 << 2); //set GPIO 17 ca8202 pin77
- GPIO_M_SET(CARD_SENSE1_PIN, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- #elif defined(CARD_SETUP_TYPE_2)
- regs0->sft_cfg1 &= ~(0x1 << 3); //set GPIO 16 ca8202 pin76
- GPIO_M_SET(CARD_SENSE1_PIN, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- #elif defined(CARD_SETUP_TYPE_3)
- regs0->sft_cfg3 &= ~(0x1 << 5); //set AUD4 disable, wthsin 2004/6/14 04:23pm
- regs0->sft_cfg0 &= ~(0x1 << 7); //set CS1 disable
- regs0->sft_cfg1 &= ~(0x1 << 5); //set A12 disable
- #ifdef PORTABLE_DVD
- regs0->sft_cfg0 &= ~(0x1 << 5); //set GPIO 38 ca8202 pin161
- #elif defined(IDE_CF_SW)
- regs0->sft_cfg0 &= ~(0x1 << 5); //set GPIO 38 ca8202 pin161
- #elif defined(COSMIC_CARD_READER) //FanGang added 2005-1-10 17:32
- regs0->sft_cfg0 &= ~(0x1 << 4); //set GPIO 39 ca8202 pin162
- #else
- regs0->sft_cfg0 &= ~(0x1 << 6); //set GPIO 29 ca8202 pin145
- #endif
- regs0->sft_cfg1 &= ~(0x1 << 3); //set GPIO 16 ca8202 pin76
- GPIO_M_SET(CARD_SENSE1_PIN, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- #ifdef HDMI_SMC_CLE
- GPIO_M_SET(CARD_SMC_CLE_PIN, 1); // benson 2004/11/17 01:40PM set gpio 36
- GPIO_E_SET(CARD_SMC_CLE_PIN, 1); // benson 2004/11/17 01:40PM set gpio 36
- #endif
- #elif defined(CARD_SETUP_TYPE_4)
- #if defined(MP_BOARD_256_PIN_NON_SHARE)//kenny 2004/7/14
- regs0->sft_cfg1 &= ~(0x1 << 3); //set GPIO 16 ca8202 pin76
- GPIO_M_SET(CARD_SENSE1_PIN, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- #elif defined(MP_BOARD_216_PIN_NON_SHARE)
- regs0->sft_cfg1 &= ~(0x1 << 3); //set GPIO 16 ca8202 ns-216 pin66
- #ifdef USE_SERVO_DFCT_GPIO //if define USE_SERVO_DFCT_GPIO, then we set pin55 to be GPIO
- regs0->sft_cfg4 &= ~(0x1 << 6); //set GPIO 8 ca8202 ns-216 pin55 (servo DFCT pin)
-
- #endif
- GPIO_M_SET(CARD_SENSE1_PIN, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- #else
- regs0->sft_cfg1 &= ~(0x1 << 3); //set GPIO 16 ca8202 pin76
- GPIO_M_SET(CARD_SENSE1_PIN, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- #endif
- #elif defined(CARD_SETUP_TYPE_5)
- regs0->sft_cfg0 &= ~(0x1 << 7); //set CS1 disable
- regs0->sft_cfg1 &= ~(0x1 << 5); //set A12 disable
- #ifdef PMP_PCB_VER_B
- regs0->sft_cfg1 &= ~(0x1 << 3); //set GPIO 16 ca8202 pin76
- #else //PMP_PCB_VER_C
- regs0->sft_cfg0 &= ~(0x1 << 4); //set GPIO 39 ca8202 pin162
- #endif
- regs0->sft_cfg1 &= ~(0x1 << 1); //set GPIO 18 ca8202 pin78
- GPIO_M_SET(CF_INS_SENSE, 1);
- GPIO_M_SET(CARD_POWER_RESET,1);
- GPIO_E_SET(CF_INS_SENSE, 0);
- #endif
- #ifndef CARD_SETUP_TYPE_5
- GPIO_E_SET(CARD_SENSE1_PIN, 0);
- GPIO_E_SET(CARD_SENSE2_PIN, 0);
- #endif
- #if !defined(CARD_SETUP_TYPE_4)&&!defined(CARD_SETUP_TYPE_5)
- GPIO_E_SET(CARD_SENSE3_PIN, 0);
- #endif
- GPIO_E_SET(CARD_POWER_RESET,1);
- CardEna=TRUE;
-
- GPIO_O_SET(CARD_POWER_RESET,1); //Power Off
-
- }
- /**************************************************************************
- * *
- * Function Name: CardStorageIsPlugIn *
- * *
- * Purposes: *
- * Check card Storage plug in or not *
- * Descriptions: *
- * Check card Storage plug in or not *
- * Arguments: *
- * NONE *
- * Returns: *
- * 0: FALSE *
- * 1: TRUE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- int CardStorageIsPlugIn(void)
- {
- UINT8 card_result=0;
- switch(storage_type)
- {
- #if defined(COMPACT_FLASH)
- case CF_CARD_DEVICE:
- #if defined(CARD_SETUP_TYPE_5)
- if((PMP_CF_Card_Play==1)&&(PMP_CF_Card_Insert==0))
- ircmd_return(); //card_result=1;
- else
- card_result=0;
- #else
- if(GPIO_I_GET(CARD_SENSE2_PIN)) card_result=1;
- #endif
- break;
- #endif
- #if defined(SD_MMC_CARD)
- case SD_CARD_DEVICE:
- #ifdef CARD_SETUP_TYPE_4
- if(GPIO_I_GET(CARD_SENSE1_PIN)) card_result=1;
- #else
- if(GPIO_I_GET(CARD_SENSE3_PIN)) card_result=1;
- #endif
- break;
- #endif
- #if defined(MEMORY_STICK)
- case MS_CARD_DEVICE:
- #ifdef CARD_SETUP_TYPE_4
- if(GPIO_I_GET(CARD_SENSE2_PIN)) card_result=1;
- #else
- if(GPIO_I_GET(CARD_SENSE1_PIN)) card_result=1;
- #endif
- break;
- #endif
- #if defined(SMART_MEDIA)
- case SMC_CARD_DEVICE:
- if(GPIO_I_GET(CARD_SENSE1_PIN)) card_result=1;
- break;
- #endif
- default:
- break;
- }
-
- if(card_result) return FALSE;
- else return TRUE;
- }
- /**************************************************************************
- * *
- * Function Name: Detect_Card_Storage *
- * *
- * Purposes: *
- * Detect which card exist *
- * Descriptions: *
- * Use card GPIO to Detect which card exist *
- * Arguments: *
- * NONE *
- * Returns: *
- * 0x02: CF ,0x04: SD_MMC ,0x08: MS ,0x10: SMC *
- * 0x06: SD+CF ,0x0a: CF+MS ,0x12: CF+SMC *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- BYTE Detect_Card_Storage()
- {
- UINT8 card_sense=0;
- BYTE card_storage_type=0;
- detect_type &= USB_DEVICE;//liweihua 2004-6-7
- #ifdef CARD_SETUP_TYPE_4
- card_sense=GPIO_I_GET(CARD_SENSE1_PIN)<<1;
- card_sense|=GPIO_I_GET(CARD_SENSE2_PIN);
-
- //printf("card_sense =%x!n",card_sense);
- switch(card_sense)
- {
- case 2:
- card_storage_type|=MS_CARD_DEVICE;
- break;
- case 1:
- card_storage_type|=SD_CARD_DEVICE;
- break;
- default:
- card_storage_type=0;
- break;
- }
- #elif defined(CARD_SETUP_TYPE_5)
- card_storage_type|=CF_CARD_DEVICE;
- //liweihua mod 2004-12-1
- int check_result=PMP_CF_Card_IsPlugIn();
- #ifdef SUPPORT_MULTI_PARTITION//liweihua 2004-12-10
- if((check_result>1) || (check_result<0))
- {
- #if defined(FAT_FILE_MODE) && (!defined(PMP_UI))//liweihua 2005-1-5
- if(fat_play_mode == 1)
- Refresh_FAT_Mode_GUI();
- else if((fat_play_mode == 2)&&(pFsJpeg->gifsState == FS_STATE_HDD))
- #else
- if(pFsJpeg->gifsState == FS_STATE_HDD)
- #endif
- Refresh_Partition_Menu();
- }
- else
- #endif
- if(check_result==1)
- PMP_CF_Card_Insert=1;
- else
- PMP_CF_Card_Insert=0;
- #else //CARD_SETUP_TYPE_1 ,CARD_SETUP_TYPE_2,CARD_SETUP_TYPE_3
- card_sense=GPIO_I_GET(CARD_SENSE1_PIN)<<2;
- card_sense|=GPIO_I_GET(CARD_SENSE2_PIN)<<1;
- card_sense|=GPIO_I_GET(CARD_SENSE3_PIN);
- //printf("card_sense =%x!n",card_sense);
- switch(card_sense)
- {
- case 7:
- card_storage_type=0;
- break;
- case 6:
- card_storage_type|=SD_CARD_DEVICE;
- break;
- case 5:
- card_storage_type|=CF_CARD_DEVICE;
- break;
- case 4:
- card_storage_type|=CF_CARD_DEVICE;
- card_storage_type|=SD_CARD_DEVICE;
- break;
- case 3:
- card_storage_type|=MS_CARD_DEVICE;
- break;
- case 2:
- card_storage_type|=SMC_CARD_DEVICE;
- break;
- case 1:
- card_storage_type|=CF_CARD_DEVICE;
- card_storage_type|=MS_CARD_DEVICE;
- break;
- case 0:
- card_storage_type|=CF_CARD_DEVICE;
- card_storage_type|=SMC_CARD_DEVICE;
- break;
- default:
- card_storage_type=0;
- break;
- }
- #endif
- detect_type |=card_storage_type;//liweihua 2004-6-7
- return card_storage_type;
- }
- #endif //#ifdef SPHE8202_CARD_STORAGE
- //-----------------------------------------------------------
- #ifdef SUPPORT_USB
- extern UINT8 UsbTestUnitReady(BYTE dev_lun);
- extern BYTE IsUSBCardReader(void);
- extern UINT8 USBEna;
- extern UINT8 CBWLUN;
- extern UINT8 SLAVE_ENUMERATED;
- extern UINT8 USB_ADDR;
- extern UINT8 MaxLUN;
- extern void USBCardReaderDetect(void);
- /**************************************************************************
- * *
- * Function Name: UsbIsPlugIn *
- * *
- * Purposes: *
- * Detect if the U disk is pluged *
- * Descriptions: *
- * use UHCI command Detect if the U disk is pluged *
- * Arguments: *
- * NONE *
- * Returns: *
- * TRUE or FALSE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- int UsbIsPlugIn(void)
- {
- int detect_result = 0;
- #ifdef HOST_UHCI
- detect_result = uhci_slaveDetect();
- #else //#define HOST_SL811HS
- detect_result = slave_detect();
- #endif
- if((detect_result == 0) && (card_plug_state == USER_DO_PLUG_IN))
- return TRUE;
- else if((detect_result == 0) && (card_plug_state == USER_DO_PLUG_OUT))
- return FALSE;
- else
- return FALSE;
- }
- /**************************************************************************
- * *
- * Function Name: uhci_slaveDetect *
- * *
- * Purposes: *
- * detect whether the U-Device is plugged in or not *
- * Descriptions: *
- * This function detect whether the U-Device is plugged in or not. *
- * Arguments: *
- * NONE *
- * Returns: *
- * 0: nothing 1: plug in 2: detached *
- * See also: NONE *
- * *
- **************************************************************************/
- /**************************************************************************************************
- * *
- * Description: This function detect whether the U-Device is plugged in or not. *
- * *
- * Author : wthsin *
- * Date : 2004/1/14 08:31pm *
- * *
- * Update : liweihua 2004-6-7
- **************************************************************************************************/
- BYTE usb_plug_out_flag; //for USB plug out when copying lijd 2004-11-19 16:15
- UINT32 uhci_slaveDetect(void)
- {
- int result;
-
- //-------------------------------------------------------------------------
- // Wait for USB enumeration
- //-------------------------------------------------------------------------
- if(!SLAVE_ENUMERATED)
- { // wait for an USB device to be inserted
- if(uhci_PlugInOutDetect())
- {
- printf("slave is plug in!!!n");
- usb_plug_out_flag=0;
- uhci_reset(); //wthsin 2003/12/30 04:43
- USB_ADDR=uDisk_ADDR;
- result=EnumUsbDev(USB_ADDR);
- if(no_disk_cnt == 1)//liweihua 20040324
- system_state=SYSTEM_OPEN; //wthsin, 2004/3/16 07:36pm
- if(result)
- { // enumerate USB device, assign USB address = #1
- SLAVE_ENUMERATED = TRUE; // Set slave USB device enumerated flag
- #ifdef SUPPORT_SLOT_IN_LOADER
- card_plug_state = USER_DO_PLUG_IN;
- #else
- if(play_state != VCD_STATE_OPEN)//liweihua add 2004-3-11
- card_plug_state = USER_DO_PLUG_IN;
- else
- card_plug_state = 0;
- #endif
- detect_type |= USB_DEVICE; //wthsin ,2004/3/1 03:16pm
- MaxLUN = 0; //Maoyong 2004.05.19
- return 1;
- }
- }
- }
- //-------------------------------------------------------------------------
- // USB enumerated, proceed accordingly
- //-------------------------------------------------------------------------
- else
- {
- if(!uhci_PlugInOutDetect()) // test for slave device detach
- {
- printf("slave is detached!!!n");
- usb_plug_out_flag=1;
- #ifdef MP3_ONLY_STOP_TO_GUI
- if( (play_state==VCD_STATE_MP3_FILELIST) && (media_type==MEDIA_CARD) )
- {
- ShowTitle();
- SwitchMedia(CARD2CD); //wsf 2004-9-16 16:43
- }
- #endif
-
- SLAVE_ENUMERATED = FALSE; // return to un-enumeration
- if((media_type == MEDIA_CARD)&&(storage_type == USB_DEVICE)) //liweihua mod 2004-3-30
- {
- if(Mp3ReadFinish)
- Mp3ReadFinish = 0;
- if((play_state == VCD_STATE_PAUSE)||(GetCurrentFileType() == CDROM_WMA))//liweihua mod 2004-4-19
- ircmd_stop();
- AVD_SetMediaInterrupt(); //wthsin , 2004/4/19 02:47pm
- }
- if(play_state != VCD_STATE_OPEN) //liweihua add 2004-2-1
- {
- if((media_type == MEDIA_CARD)&&(storage_type == USB_DEVICE))
- play_state = VCD_STATE_STOP;
-
- card_plug_state = USER_DO_PLUG_OUT;
- }
- detect_type &= (~USB_DEVICE);
- storage_type &= (~USB_DEVICE);
- return 2; // exit now.
- }
- }
- //-------------------------------------------------------------------------
- //USB Card reader special process
- //-------------------------------------------------------------------------
- USBCardReaderDetect();
-
- return 0;
- }
- #endif//end SUPPORT_USB
- /**************************************************************************
- * *
- * Function Name: CardTestReady *
- * *
- * Purposes: *
- * detect and initialize card/usb, then set card to browse *
- * Descriptions: *
- * detect and initialize card/usb, then set card to browse *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- void CardTestReady(void)
- {
- UINT8 media_exit=0;
-
- #ifdef IR_SWITCH_CD_USB_CF_OTHER
- storage_type = detect_result_last;
- now_valid_type = storage_type; //for bug:read cf,insert usb,will read cf again.
- #ifdef HIGH_CORTROL_CF
- GPIO_O_SET(SWITCH_GPIO,0);//dingzhy for switch bus 4-10-22 10:43
- #else
- GPIO_O_SET(SWITCH_GPIO,1);
- #endif
- #endif
- if(storage_type!=0)
- {
- #ifdef SPHE8202_CARD_STORAGE //Maoyong 2004-8-12 do card power reset.
- if(storage_type != USB_DEVICE)
- Card_power_reset();
- #endif
- switch(storage_type)
- {
- #ifdef SPHE8202_CARD_STORAGE
- #if defined(COMPACT_FLASH)
- case CF_CARD_DEVICE:
- #ifdef IR_SWITCH_CD_USB_CF_OTHER //dingzhy 4-10-22 10:41
- #ifdef HIGH_CORTROL_CF
- GPIO_O_SET(SWITCH_GPIO,1);//dingzhy use vfd data for test switch bus 4-10-22 10:43
- #else
- GPIO_O_SET(SWITCH_GPIO,0);
- #endif
- #endif
- #ifdef CARD_SETUP_TYPE_2
- regs0->fm_gpio_mode = 8;
- #elif defined(CARD_SETUP_TYPE_3)||defined(CARD_SETUP_TYPE_5)
- regs0->gpio_mode_B=2;
- regs0->fm_gpio_mode = 3;
- #endif
-
- #ifdef IDE_CF_SW
- IdeSetSequence(HD);//kenny 2004/8/29
- #endif
- cfIdeDetect();
- media_exit=1;
- break;
- #endif
- #if defined(SD_MMC_CARD)
- case SD_CARD_DEVICE:
- #ifdef CARD_SETUP_TYPE_2
- regs0->fm_gpio_mode = 3;
- #elif defined(CARD_SETUP_TYPE_3)||defined(CARD_SETUP_TYPE_4)
- regs0->gpio_mode_B=0;
- regs0->fm_gpio_mode = 3;
- #endif //CARD_SETUP_TYPE_2
- if(sdDetect()) //wthsin, 2004/6/24 07:40pm
- {
- psprintf(RegionValStr[REGION1], "SD Err");
- PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
- }
- else
- media_exit=1;
- break;
- #endif
- #if defined(MEMORY_STICK)
- case MS_CARD_DEVICE:
- #ifdef CARD_SETUP_TYPE_2
- regs0->fm_gpio_mode = 4;
- #elif defined(CARD_SETUP_TYPE_3)||defined(CARD_SETUP_TYPE_4)
- regs0->gpio_mode_B=0;
- regs0->fm_gpio_mode = 4;
- #endif //CARD_SETUP_TYPE_2
- msDetect();
- media_exit=1;
- break;
- #endif
- #if defined(SMART_MEDIA)
- case SMC_CARD_DEVICE:
- #ifdef CARD_SETUP_TYPE_2
- regs0->fm_gpio_mode = 8;
- #elif defined(CARD_SETUP_TYPE_3)
- regs0->fm_gpio_mode = 3;
- regs0->gpio_mode_B=1;
- #endif //CARD_SETUP_TYPE_2
- if(smcDetect())
- {
- psprintf(RegionValStr[REGION1], "SMC Err");
- PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
- }
- else
- media_exit=1;
- break;
- #endif
- #endif//#ifdef SPHE8202_CARD_STORAGE
- #ifdef SUPPORT_USB//liweihua 2004-6-7
- case USB_DEVICE:
- #if defined(IR_SWITCH_CD_USB_CF_OTHER)||defined(SPHE8202_USB_Write)||defined(FILE_MODE_WRITE) //dingzhy add it
- UsbTestReady(); //for bug:power on without usb,then insert usb,but can't play usb; dingzhy 04-10-22
- #endif
- media_exit=1;
- break;
- #endif//#ifdef SUPPORT_USB
- default:
- return;
- }
- }
- //#endif
- if(media_exit)
- {
- #ifdef SPHE8202_ALL_TYPE_CARD_WRITE
- if(card_browse_sign)
- #endif
- #ifdef FILE_MODE_WRITE //sunzhh add for file mode 2005-1-14
- if(!file_mode_flag)
- #endif
- CardSetBrowse();
- }
- }
- /**************************************************************************
- * *
- * Function Name: CARDIsPlugIn *
- * *
- * Purposes: *
- * Detect if the USB or CARD is pluged *
- * Descriptions: *
- * Detect if the USB or CARD is pluged *
- * Arguments: *
- * NONE *
- * Returns: *
- * 0: FALSE *
- * 1: TRUE *
- * See also: NONE *
- * *
- **************************************************************************/
- int CARDIsPlugIn(void)
- {//liweihua update 2004-6-8
- int detect_result = 0;
- if(storage_type!=0)
- {
- #ifdef SUPPORT_USB
- if(storage_type == USB_DEVICE)
- detect_result=UsbIsPlugIn();
- #endif
- #if defined(SUPPORT_USB)&&defined(SPHE8202_CARD_STORAGE)
- else
- #endif
- #ifdef SPHE8202_CARD_STORAGE
- detect_result=CardStorageIsPlugIn();
- #endif
- }
- return detect_result;
- }
- /**************************************************************************
- * *
- * Function Name: polling_storage *
- * *
- * Purposes: *
- * polling to detect usb/card plus in or plug out *
- * Descriptions: *
- * polling to detect usb/card plus in or plug out *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- extern int check_support_usb(void); //wthsin, 2004/5/27 01:34pm
- void polling_storage()
- {//liweihua update 2004-6-8
- BYTE detect_result = 0;
- #ifdef SPHE8202_CARD_STORAGE
- if(CardEna == TRUE) //only after card init then polling.
- Detect_Card_Storage();
- #endif
- #if defined(SUPPORT_USB)
- if(USBEna == TRUE) //only after USB init then polling.
- {
- #ifdef SPHE1000
- #ifdef HOST_UHCI
- uhci_slaveDetect();
- #else //#define HOST_SL811HS
- slave_detect();
- #endif
- #else
- #ifdef HOST_UHCI
- if(check_support_usb()==0) return;
- uhci_slaveDetect();
- #else //#define HOST_SL811HS
- slave_detect();
- #endif
- #endif
- }
- #endif
-
- detect_result=storage_parity_type[detect_type];
-
- #ifdef SWITCH_CD_CARD_USB//liweihua 2004-6-9
- extern BYTE select_media_type;
- if(detect_type&select_media_type)
- detect_result = select_media_type;
- else
- select_media_type = 0;
- #endif
-
- #ifdef IR_SWITCH_CD_USB_CF_OTHER //dingzhy for bus switch 04-10-22
- if((detect_type)&&(now_valid_type))
- {
- detect_result = storage_parity_type[now_valid_type];
- }
- else
- now_valid_type = 0;
-
- detect_result_last = detect_result;
- //dingzhy for debug switch function
- //psprintf(RegionValStr[REGION2], "D %x L %x V %x",detect_type,detect_result_last,now_valid_type);
- //PrintOsdMsg(STR_OS_SPACE, REGION2, 1, 1);
- #endif
-
- if((detect_result==0)&&(storage_type==0))
- {
- //printf("-------- Do nothing! ------n");
- return;
- }
- else if((detect_result!=0)&&((storage_type)==0))
- {
- printf("-------- Card/USB Insert! ------n");
- printf("media_type = %d",media_type);
- #ifndef SWITCH_CD_CARD_USB//liweihua 2004-6-9
- if(no_disk_cnt == 1) //liweihua 20040324
- #endif
- system_state=SYSTEM_OPEN;
- if(play_state != VCD_STATE_OPEN) //liweihua add 2004-3-11
- card_plug_state = USER_DO_PLUG_IN;
- storage_type = detect_result;
- if(media_type != MEDIA_CD)//nono 2004-9-24 20:17
- {
- t_disp = 0; //wthsin, 2004/7/6 11:39pm
- remain= 0;
- }
- if(media_type == MEDIA_CARD)
- SwitchMedia(CD2CARD);
- #ifdef SUPPORT_CARDREADER_TEST
- else if ((Is_MIDI_STATE())&&(gIsMidiSelMenu))
- {
- printf("polling_storage MidiCard_GetCardFile n");
- MidiCard_GetCardFile();
- }
- #endif
- }
- //else if((storage_type!=0)&&(storage_type!=detect_result))
- else if( (storage_type!=0)&& ((storage_type & detect_type) == 0) )
- {
- printf("-------- Card/USB Remove! ------n");
- MediaIsEmpty = MEDIA_NOT_EMPTY;//dingzhy 05-1-11 20:26
- #ifdef IR_SWITCH_CD_USB_CF_OTHER //dingzhy for tonic 4-10-22 13:19
- now_valid_type = 0; //for bug:move media,always show no media
- #endif
- #ifdef MP3_ONLY_STOP_TO_GUI
- if( (play_state==VCD_STATE_MP3_FILELIST) && (media_type==MEDIA_CARD) )
- {
- ShowTitle();
- SwitchMedia(CARD2CD); //wsf 2004-9-16 16:43
- }
- #endif
-
- if(media_type == MEDIA_CARD)
- {
- SwitchMedia(CARD2CD); //Maoyong 2004-8-11 22:52 marked above and add this.
- }
- #ifdef SUPPORT_CARDREADER_TEST
- if ((Is_MIDI_STATE())&&(gIsMidiSelMenu))
- {
- MidiCardReadInit();
- }
- #endif
- if(play_state != VCD_STATE_OPEN)
- card_plug_state = USER_DO_PLUG_OUT;
- #ifdef SPHE8202_CARD_STORAGE
- if(storage_type!=USB_DEVICE) //wthsin, 2004/6/28 10:09am
- Card_power_off(); //Power Off
- #endif//SPHE8202_CARD_STORAGE
- detect_result = 0;
- storage_type = 0;
- t_disp = 0; //wthsin, 2004/7/6 11:39pm
- remain= 0;
- }
- }
- /**************************************************************************
- * *
- * Function Name: CardSetBrowse *
- * *
- * Purposes: *
- * set system to play card media *
- * Descriptions: *
- * set system to play card media *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- //commone function to make system play card media now. Maoyong 2004.05.17
- void CardSetBrowse(void)
- {
- full_scrn = 0; //Maoyong 2004-8-11 23:02 for clear setup menu, must place before ClearOsdMsg
- ClearOsdMsg(0);
- t_disp = 0;
- #ifdef SUPPORT_MULTI_PARTITION//liweihua 2004-10-25 8:56
- browser = HddCardBrowse;
- #else
- browser = read_iso9660;
- #endif
- cd_type_loaded=CDROM;
- cd_type=CDROM;
- play_state=VCD_STATE_CLOSE;
- Mp3ReadFinish = 0;//liweihua 2004-5-13
- memset(pFsJpeg, 0, sizeof(FSJPEGDATA));//liweihua add 2004-5-8 9:11
- system_state=SYSTEM_BROWSE;
- sys_cmd=CMD_FUNC|CMD_FUNC_CLOSE;
- media_type = MEDIA_CARD;
-
- //customized osd information for card reading
- //Maoyong 2004.05.25 build funtions in ircmd.card.c, need to make osd display until
- //read all card files for some cards has too many files and take long times
- show_card_reading_osd(SHOW_MEDIA);
- }
- /**************************************************************************
- * *
- * Function Name: PMP_CF_Card_IsPlugIn *
- * *
- * Purposes: *
- * Detect if the PMP'CF is pluged *
- * Descriptions: *
- * Detect if the PMP'CF is pluged *
- * Arguments: *
- * NONE *
- * Returns: *
- * 0: nothing 2: CF plug in -2: CF plug out *
- * See also: NONE *
- * *
- **************************************************************************/
- #ifdef CARD_SETUP_TYPE_5
- UINT8 sense_check_result=0;//liweihua add 2004-11-30
- int PMP_CF_Card_IsPlugIn()
- {
- UINT8 cf_card_result=0;
- UINT8 check_result;
-
- check_result = sense_check_result;
- sense_check_result = GPIO_I_GET(CF_INS_SENSE);
-
- if(check_result != sense_check_result)
- {
- if(!sense_check_result)
- {
- printf("CF plug in!n");
- return 2;
- }
- else
- {
- printf("CF plug out!n");
- return -2;
- }
- }
- if(!sense_check_result) cf_card_result=1;
- //printf("cf_card_result =%x!n",cf_card_result);
- return cf_card_result;
- }
- #endif// CARD_SETUP_TYPE_5
- #endif //#if defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)
- /**************************************************************************
- * *
- * Function Name: pc_usb_access_mode *
- * *
- * Purposes: *
- * Set system to PC USB MODE *
- * Descriptions: *
- * when connect computer with usb, Set system to PC USB MODE *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- #ifdef PMP_DVD
- void pc_usb_access_mode()
- {
- delay_1ms(50); //Continous 50ms Detect "USB INSERT"
- if(!GPIO_I_GET(PC_USB_CONNECT_PIN)) return;
- watchdog_onoff(0); // disable watchdog
- psprintf(RegionValStr[REGION1], "PC USB MODE");
- PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
- #ifdef PMP_PCB_VER_C
- regs0->fm_gpio_mode = 9; //8202 IDE PIN => Hi-Z
- UINT16 temp;
- temp=regs0->gpio_mode_B;
- regs0->gpio_mode_B=0;
- #endif //#ifdef PMP_PCB_VER_C
- GPIO_O_SET(IDE_BUS_SWITCH_CONTROL_PIN,0);
- #ifdef PMP_PCB_VER_C
- GPIO_O_SET(USB_DEVICE_CHIP_POWER_PIN,0);
- delay_1ms(300);
- #endif //#ifdef PMP_PCB_VER_C
- GPIO_O_SET(USB_DEVICE_CHIP_POWER_PIN,1);
- GPIO_O_SET(CARD_POWER_RESET,0);
-
- while(GPIO_I_GET(PC_USB_CONNECT_PIN));
-
- GPIO_O_SET(IDE_BUS_SWITCH_CONTROL_PIN,1);
- #ifdef PMP_PCB_VER_B
- GPIO_O_SET(USB_DEVICE_CHIP_POWER_PIN,0);
- #else //PMP_PCB_VER_C
- regs0->gpio_mode_B=temp;
- #endif //#ifdef PMP_PCB_VER_B
- watchdog_onoff(1); // enable watchdog
- watchdog_renew(0xffff);//reset watchdog
- ClearOsdMsg(1);
- system_state= SYSTEM_OPEN;
- ircmd_stop();
- ircmd_return();
- }
- /**************************************************************************
- * *
- * Function Name: PMP_PC_Usb_PlugInOut *
- * *
- * Purposes: *
- * detect if usb connect to computer *
- * Descriptions: *
- * detect if usb connect to computer *
- * Arguments: *
- * NONE *
- * Returns: NONE *
- * *
- * See also: NONE *
- * *
- **************************************************************************/
- UINT8 pc_usb_vcc_flag=0;
- void PMP_PC_Usb_PlugInOut()
- {
- if(pc_usb_vcc_flag==0)
- {
- if(GPIO_I_GET(PC_USB_CONNECT_PIN))
- {
- #ifdef PMP_UI//liweihua 2005-1-17
- pmpkey_return();
- #endif
- pc_usb_access_mode();
- pc_usb_vcc_flag=1;
- }
- }
- else //(pc_usb_vcc_flag==0)
- {
- if(!GPIO_I_GET(PC_USB_CONNECT_PIN))
- {
- pc_usb_vcc_flag=0;
- }
- }
- }
- #endif //#ifdef PMP_DVD