⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8202_usb_card_if.c

📁 Sunplus 8202S source code.
💻 C
📖 第 1 页 / 共 4 页
字号:
/**************************************************************************
 *                                                                        *
 *         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                                    *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -