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

📄 ct_flash.c

📁 DVB软件,基于CT216软件的开发源程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************

        (C)Copyright Cheertek Inc. 2005,
           K200, all right reserved.

        Product : Cheertek CT216 Flash High Level control functions.
        Date    : 2005.04.08
        Author  : Cheertek (K200 Jack)
        Purpose : do CT216 Flash IO control
        		  (0x0000-0000 ~ 0x1FFF-FFFF)

****************************************************************************/
/*************************************************************************
*
* FILE NAME                                            VERSION
*
*      CTHflash.c                                    CTH/Flash/0.0.2
*
* COMPONENT
*
*      CTH - CTK High Level Driver
*
* DESCRIPTION
*
*      This file contains the Flash Driver specific functions.
*
* DATA STRUCTURES
*
*      CT_FLASH_CfiQuery     :   This structure holds min CFI query information as
*						 defined in the JEDEC standard.
*
* DEPENDENCIES
*
*      none
*
*************************************************************************/
#include <stdio.h>
#include <string.h>

#include "ct_type.h"			/* for type define. */
#include "ct_flash.h"

#ifndef BOOT_DRIVER
    #include "ct_os.h"

	#define CT_FLASH_VERSION	"1.00a"
    #define FLASH_INT_OFF

    CTOS_SEMAPHORE	_CT_Flash_Sem;
#endif
/*******************************************************************************************/
#if 1
#define FLASH_MSG(p)
#else
#define FLASH_MSG(p)			printf p
#endif


#if 1
#define FLASH_DBG(p)
#else
#define FLASH_DBG(p) 		printf p
#endif

/*******************************************************************************************/ 

/*!
* manufacturer ID
*/
#define	ATMEL		0x1F	/*!< The manufacturer id for ATMEL 		*/
#define WINBOND		0xEF	/*!< The manufacturer id for WINBOND 	*/
#define AMIC		0x37	/*!< The manufacturer id for AMIC    	*/
#define MXICPART   	0xC2	/*!< The manufacturer id for MX      	*/
#define EON			0x1C	/*!< The manufacturer id for EON     	*/
#define SST			0xBF 	/*!< The manufacturer id for SST     	*/
#define PMC			0x7F 	/*!< The manufacturer id for PMC     	*/
#define ESI			0x4A    /*!< The manufacturer id for ESI     	*/
#define SPANSION	0x01    /*!< The manufacturer id for SPANSION	*/
#define ST			0x20    /*!< The manufacturer id for ST	*/
#define ESMT		0x8C    /*!< The manufacturer id for ESMT	*/

#if defined(CT956)
#define CMD_REG     *((volatile unsigned long *)0x80002a24)
#define OP_REG      *((volatile unsigned long *)0x80002a28)
#define READ_TYPE   *((volatile unsigned long *)0x80002a2c)
#define WR_REG      *((volatile unsigned long *)0x80002a30)
#define RD_REG      *((volatile unsigned long *)0x80002a34)
#define SCK_CTRL    *((volatile unsigned long *)0x80002a38)
#elif (defined(CT216S)|| defined(CT216T) || defined(CT216H)) 
#define CMD_REG     *((volatile unsigned long *)0x80002a04)
#define OP_REG      *((volatile unsigned long *)0x80002a08)
#define READ_TYPE   *((volatile unsigned long *)0x80002a0c)
#define WR_REG      *((volatile unsigned long *)0x80002a10)
#define RD_REG      *((volatile unsigned long *)0x80002a14)
#define SCK_CTRL    *((volatile unsigned long *)0x80002a18)
#else // CT216U
#define CMD_REG     *((volatile unsigned long *)0x80002a20)
#define OP_REG      *((volatile unsigned long *)0x80002a24)
#define READ_TYPE   *((volatile unsigned long *)0x80002a28)
#define WR_REG      *((volatile unsigned long *)0x80002a2c)
#define RD_REG      *((volatile unsigned long *)0x80002a30)
#define SCK_CTRL    *((volatile unsigned long *)0x80002a34)
#endif

#define CMD                    0x00
#define CMD_AD0                0x20
#define CMD_AD0_AD1            0x40
#define CMD_AD0_AD1_AD2        0x60
#define CMD_AD0_AD1_AD2_ADn    0x80

#define OPL_D1                 0x00
#define OPL_D1_D2              0x01
#define OPL_D1_D2_D3           0x02
#define OPL_D1_D2_D3_D4        0x03
#define OPL_D1_D2_D3_D4_Dn     0x04

#define IO_R 0x00
#define IO_W 0x08

#define Format_Write_Enable           CMD+                IO_W+OPL_D1				//0x00000008
#define Format_Write_Disable          CMD+                IO_W+OPL_D1				//0x00000008
#define Format_Read_Status            CMD+			        IO_R+OPL_D1				//0x00000000
#define Format_Write_Status           CMD+                IO_W+OPL_D1_D2			//0x00000009
#define Format_Read_Data              CMD_AD0_AD1_AD2_ADn+IO_R+OPL_D1_D2_D3_D4		//0x00000083
#define Format_Fast_Read              CMD_AD0_AD1_AD2_ADn+IO_R+OPL_D1_D2_D3_D4		//0x00000083 
#define Format_Page_Program           CMD+                IO_W+OPL_D1_D2_D3_D4_Dn	//0x0000000c
#define Format_Sector_Erase           CMD+                IO_W+OPL_D1_D2_D3_D4		//0x0000000b
#define Format_Bulk_Erase             CMD+                IO_W+OPL_D1				//0x00000008
#define Format_Power_Down             CMD+                IO_W+OPL_D1				//0x00000008
#define Format_Release_Power_Down     CMD+                IO_W+OPL_D1				//0x00000008
#define Format_Device_ID              CMD_AD0+            IO_R+OPL_D1_D2_D3_D4		//0x00000023
#define Format_Device_ID1             CMD_AD0+            IO_R+OPL_D1				//0x00000020

#define AAI_Word_Program		CMD_AD0_AD1_AD2 + IO_R + OPL_D1_D2		//0x69
#define AAI_Word_Program_Con		CMD_AD0_AD1_AD2	+ IO_W + OPL_D1_D2_D3		//0x6A

//Flash state
#define SRWD_STATE      0x00000080
#define BP_STATE        0x0000001c
#define AAI_STATE	0x00000040
#define WEL_STATE       0x00000002
#define WIP_STATE       0x00000001

//System state
#define WaitCMD_STATE   0x00001000
#define IOW_STATE       0x00000800
#define IOR_STATE       0x00000400
#define IDLE_STATE      0x00000200
#define FORCE_STOP      0x00000010

// SPFLASH size
#define FLASH_SIZE_64M      0x40
#define FLASH_SIZE_32M      0x20
#define FLASH_SIZE_16M      0x10
#define FLASH_SIZE_8M       0x08
#define FLASH_SIZE_4M       0x04

//BOOT area
#define BOOT_BOTTOM     0X01
#define BOOT_TOP        0X02
#define BOOT_NO         0X03    //NO 4k sector
#define BOOT_ALL        0X04   //all 4K sector

/*!
* A list of flash device ID's - add others as needed
*/
//flash TYPE

//MXICPART
#define  ID_MX25L4005      0xC212
#define  ID_MX25L8005      0xC213
#define  ID_MX25L1605      0xC214
#define  ID_MX25L3205      0xC215

//SST
#define  ID_SST25LF080A    0xBF80
#define  ID_SST25LF040A    0xBF44
#define  ID_SST25VF016B    0xBF41	//unsupport

//EON
#define  ID_EN25B40B       0x1C32
#define  ID_EN25B40T       0x1C42
#define  ID_EN25B80        0x1C33
#define  ID_EN25B80T       0x1C43
#define  ID_EN25P40        0x1C12   //yhtang_060327
#define  ID_EN25B16B       0x1C34
#define  ID_EN25F80        0x1C13//Eon_F80
#define  ID_EN25B32B       0x1C35
#define  ID_EN25B64B       0x1C36
#define  ID_EN25F16        0x1C14 

//WINBOND
#define  ID_W25D40B        0xEF32  // same W25B40B
#define  ID_W25D40T        0xEF42  // same W25B40T
#define  ID_W25X16         0xEF14
#define  ID_W25X32         0xEF15
#define  ID_W25X64         0xEF16
#define  ID_W25X80         0xEF13
#define  ID_W25X40         0xEF12
        
//ATMEL
#define ID_AT26DF081A		0x1F45
#define ID_AT26F004			0x1F04    
#define ID_AT26DF161		0x1F00

//AMIC
#define ID_A25L16P			0x3715
#define ID_A25L80P			0x3714
#define ID_A25L40P			0x3713

//ESI
#define ID_ES25P16			0x4A20

//SPANSION
#define ID_FL004A			0x0112
#define ID_FL008A			0x0113
#define ID_FL016A			0x0114
#define ID_FL032A			0x0115
#define ID_FL064A			0x0116

//ST
#define ID_M25P80			0x2014
#define ID_M25P16			0x2015
#define ID_M25P32			0x2016
#define ID_M25P64			0x2017

//ESMT
#define ID_EFL008A			0x8c13
#define ID_EFL016A			0x8c14
//PMC
#define ID_PM25LV010			0x9D7C
#define ID_PM25LV020			0x9D7D
#define ID_PM25LV040			0x9D7E
//end flash TYPE

#define WAIT_TIME  50		//50m sec
#define HLCHANG(I) (I << 24) | ((I & 0xff00) << 8) | ((I & 0xff0000) >> 8)

//Porting from 909
typedef struct  SPF_INFO
{    
   u32 dwProm_config;
//   WORD  wFast_Normal_FQ;  
//   BYTE  bMODE;
//   BYTE  bPH;       

   u16  wID;

   u16  bSize;
   u16  bBoot;
   u16  bWriteEnable ;
   u16  bWriteDisable;
   u16  bRead_Status ;
   u16  bWrite_Status;
   u16  bPageProgram ;
   u16  bSectorErase ;

   u16  bBulkErase ;
   u16  bReadData ;
   u16  bFastRead;
   u16  bPowerDown;
   u16  bRePowerDown;
}  SPF_INFO;
SPF_INFO SPF_INFO1;

u16 SPFcommand(u32 dwCmd,u32 dwOP,u32 dwState, u32 dwWaitime);
u16 ReadStatus(u32 dwMusk,u32 dwCMPValue,u32 dwWaitime);
u16 SPF_ReadID(u16 bFlashSize);
u16 SPF_EraseChip(void);
void SPF_ReadData(u32 dwStrAdr,u8 *pbBuff,u32 dwCnt);
u16 SPF_EraseSector(u32 dwSector);
u16 SPF_WriteProgram(u32 dwDRAM_Str_Addr,u32 dwDRAM_End_Addr,u32 dwFLASH_Addr);
u16 SPF_AAIProgram(u32 dwDRAM_Str_Addr,u32 dwDRAM_End_Addr,u32 dwFLASH_Addr);
u16 _SPF_ReadID(u16 bFlashSize);

/* for Debug Used Define */
//#define DEBUGFP 1
#ifdef	DEBUGFP
#define	DEBUGF(fmt,args...)		printf(fmt ,##args)
#else
#define	DEBUGF(fmt,args...)
#endif





⌨️ 快捷键说明

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