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

📄 smt_ctl.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************/
/*																				*/
/*	Copyright (C) SEIKO EPSON CORP. 2000										*/
/*																				*/
/*	File name : smt_ctl.c														*/
/*		This is smart media control driver										*/
/*																				*/
/*	Revision history															*/
/*		2000.03.16  H.Ogura	start												*/
/*		2002.01.08  A.Saito	Append Interrupt disable/enable						*/
/*							processing											*/
/*		2002.08.05  A.Saito	Append Block erase check to each					*/
/*							function											*/
/*							Append function smtEraseChk()						*/
/*		2003.03.26  A.Saito	Modify parameter of smtPageProgram()				*/
/*							Remove definition TIMING_CHG						*/
/*		2003.04.24  A.Saito	Modify Prolix data Read/Write						*/
/*		2003.06.05	A.Saito	Modify Comment										*/
/*							Remove prototype declaration of functions			*/
/*																				*/
/********************************************************************************/
/********************************************************************************/
/*		The tab size of this file is 4. 										*/
/********************************************************************************/

//#include	"drv.h"
#include	"smt.h"
#include	"smt_ctl.h"

/********************************************************/
/*	PROTOTYPE											*/
/********************************************************/
/********************************************************/
/*	GLOBAL												*/
/********************************************************/
unsigned long		smt_MdaSiz;				// Media Size
static unsigned long	smtPsrBak = 0;
struct	SMT_MEDIASIZE{
	unsigned char	bDevice[3];
	unsigned long	ulSize;
}stMdaSiz[8] =	{							// Media Size Table
	  { { 0x6E, 0xE8, 0xEC },   1 },
	  { { 0xEA, 0x00, 0x00 },   2 },
	  { { 0xE3, 0xE5, 0x00 },   4 },
	  { { 0xE6, 0x00, 0x00 },   8 },
	  { { 0x73, 0x00, 0x00 },  16 },
	  { { 0x75, 0x00, 0x00 },  32 },
	  { { 0x76, 0x00, 0x00 },  64 },
	  { { 0x79, 0x00, 0x00 }, 128 },
	};
static	unsigned char		smt_EraseFlg = 0;
extern	union SMT_PROLIX_BUFF	smtProlBuff;
/************************************************************************
 *  smtCardDetect
 *      Type     : char
 *      Ret val  : Result Code
 *                     0 ... Not media detect
 *                     1 ... Media detect
 *      Argument : None
 *      Function : Check card detect information
 ************************************************************************/
char	smtCardDetect(void)
  {
	return(!SMT_R_CD);			// Card detect signal
  }

/************************************************************************
 *  smtWriteProtect
 *      Type     : char
 *      Ret val  : Result Code
 *                     0 ... Not write protect
 *                     1 ... Write protect
 *      Argument : None
 *      Function : Check write protect seal information
 ************************************************************************/
char	smtWriteProtect(void)
  {
	return(!SMT_R_WPS);			// Write protect seal signal
  }

/************************************************************************
 *  smtMediaReset
 *      Type     : int
 *      Ret val  : Error Code
 *                     SMT_E_SUCCESS ( 0) ... Successful
 *                     SMT_E_FAILURE (-1) ... Failure
 *      Argument : None
 *      Function : Smart media reset function
 ************************************************************************/
int	smtMediaReset(void)
  {
	int iRetVal;

	/*  */
//	extern int ChangeDrive(long DrvNum);
//	ChangeDrive(DRV_SM);


	SMT_R_CLE = SMT_BYTE1;			// CLE is set up in high
	SMT_R_WP = SMT_BYTE0;			// WP is set up in low
	SMT_R_CE = SMT_BYTE0;			// CE is set up in low
	SMT_R_ALE = SMT_BYTE0;			// ALE is set up in low

	SMT_M_INTDISABLE;
	*SMT_R_DATAIO = SMT_C_MDRESET;					// Reset command

	SMT_R_CLE = SMT_BYTE0;			// CLE is set up in low
	SMT_R_CE = SMT_BYTE1;			// ALE is set up in high
	asm("nop");
	iRetVal = smtReadyCheck(SMT_M_MS2CNT(6));
	SMT_M_INTENABLE;					// Interrupt enable

	return(iRetVal);					// Ready check (6mS) routine is call
  }

/************************************************************************
 *  smtStatusRead
 *      Type     : int
 *      Ret val  : Error Code
 *                     SMT_E_SUCCESS ( 0) ... Successful
 *                     SMT_E_FAILURE (-1) ... Failure
 *      Argument : unsigned char *pStatus ... Status store buffer
 *      Function : Smart media status read
 ************************************************************************/
int	smtStatusRead(unsigned char *pStatus)
  {
	int	iRetVal;								// Return Value

	iRetVal = SMT_E_SUCCESS;					// Initialize return value
	smtErrInf.iSmtErr = SMT_E_SUCCESS;			// Initialize error structure

	if(SMT_R_RB == SMT_BYTE1)
	  {
		SMT_R_CLE = SMT_BYTE1;	// CLE is set up in high
		SMT_R_CE = SMT_BYTE0;	// CE is set up in low

		*SMT_R_DATAIO = SMT_C_STSREAD;			// Status read command

		SMT_R_CLE = SMT_BYTE0;	// CLE is set up in low

		SMT_M_INTDISABLE;						// Interrupt disable
		*pStatus = *SMT_R_DATAIO;				// Read status information
		SMT_M_INTENABLE;						// Interrupt enable

		SMT_R_CE = SMT_BYTE1;	// CE is set up in high
	  }
	else
	  {
		smtErrInf.iSmtErr = SMT_E_STSBUSY;		// ERROR : Status busy error !!
		iRetVal = SMT_E_FAILURE;
	  }

	return(iRetVal);
  }

/************************************************************************
 *  smtIdRead
 *      Type     : void
 *      Ret val  : None
 *      Argument : unsigned char *pbMaker  ... Maker code store buffer
 *                 unsigned char *pbDevice ... Device code store buffer
 *      Function : Smart media ID read command sequence
 ************************************************************************/
int	smtIdRead(unsigned char *pbMaker, unsigned char *pbDevice)
  {
	long	lLoop1, lLoop2;

	if(smt_EraseFlg)
	  {
		smtEraseChk();
	  }

	SMT_R_CLE = SMT_BYTE1;			// CLE is set up in high
	SMT_R_CE = SMT_BYTE0;			// CE is set up in low


	*SMT_R_DATAIO = SMT_C_MIDREAD;					// ID read command

	SMT_R_CLE = SMT_BYTE0;			// CLE is set up in low
	SMT_R_ALE = SMT_BYTE1;			// ALE is set up in high

	*SMT_R_DATAIO = SMT_C_DMYADDR;					// Dummy address

	SMT_R_ALE = SMT_BYTE0;			// ALE is set up in low

	asm("nop");										// Waited for 200nS

	SMT_M_INTDISABLE;								// Interrupt disable
	*pbMaker = *SMT_R_DATAIO;						// Read maker code
	*pbDevice = *SMT_R_DATAIO;						// Read device code
	SMT_M_INTENABLE;								// Interrupt enable

	SMT_R_CE = SMT_BYTE1;			// CE is set up in HIGH

	for(lLoop1 = 0; lLoop1 < 8; lLoop1++)
	  {
		for(lLoop2 = 0; (lLoop2 < 3)&&(stMdaSiz[lLoop1].bDevice[lLoop2] != 0x00); lLoop2++)
		  {
			if(stMdaSiz[lLoop1].bDevice[lLoop2] == *pbDevice)
			  {
				smt_MdaSiz = stMdaSiz[lLoop1].ulSize;
				return;

			  }
		  }
	  }
  }

/************************************************************************
 *  smtBlockErase
 *      Type     : int
 *      Ret val  : Error Code
 *                     SMT_E_SUCCESS ( 0) ... Successful
 *                     SMT_E_FAILURE (-1) ... Failure
 *      Argument : unsigned long ulMediaSize ... Media size information
 *                 unsigned long ulBlock     ... Physical block address
 *      Function : Block erase command
 ************************************************************************/
int	smtBlockErase(unsigned long ulBlock)
  {
	int	iRetVal;									// Return value
	union SMT_STATUS	uStatus;					// Status code

	if(smt_EraseFlg)
	  {
		smtEraseChk();
	  }

	SMT_R_WP = SMT_BYTE1;				// WP is set up in high
	SMT_R_CLE = SMT_BYTE1;				// CLE is set up in high
	SMT_R_CE = SMT_BYTE0;				// CE is set up in low

	*SMT_R_DATAIO = SMT_C_ERASE_1;						// Block erase command (1st)

	SMT_R_CLE = SMT_BYTE0;				// CLE is set up in low
	SMT_R_ALE = SMT_BYTE1;				// ALE is set up in high

	*SMT_R_DATAIO = SMT_M_BYTE(ulBlock, SMT_BYTE0);		// Block address
	*SMT_R_DATAIO = SMT_M_BYTE(ulBlock, SMT_BYTE1);
	if(smt_MdaSiz > 32)
	  {
		*SMT_R_DATAIO = SMT_M_BYTE(ulBlock, SMT_BYTE2);
	  }

	SMT_R_CLE = SMT_BYTE1;				// CLE is set up in high
	SMT_R_ALE = SMT_BYTE0;				// ALE is set up in low

	SMT_M_INTDISABLE;									// Interrupt disable
	*SMT_R_DATAIO = SMT_C_ERASE_2;						// Block erase command (2st)
	SMT_M_INTENABLE;									// Interrupt enable


	smt_EraseFlg = 1;									// Block erasing flag set
	return(SMT_E_SUCCESS);
  }

/************************************************************************
 *  smtPageRead
 *      Type     : int
 *      Ret val  : Error Code
 *                    SMT_E_SUCCESS ( 0) ... Successful
 *                    SMT_E_FAILURE (-1) ... Failure
 *      Argument : unsigned char bCommand ... Read command
 *                 unsigned long ulColumn ... Column address
 *                 unsigned long ulPage   ... Page address
 *                 char *pBuffer          ... Read data buffer
 *      Function : Page read command
 ************************************************************************/
int	smtPageRead(unsigned char bCommand, unsigned long ulColumn, unsigned long ulPage, char *pBuffer)
  {
	int	iRetVal;					// Return value
	int	iLoop;						// Loop Counter
	unsigned long	uTimeLoop;			// Time Loop Counter
	int	iLoopMax;					// Loop Max Counter

	if(smt_EraseFlg)
	  {
		smtEraseChk();
	  }

	if((bCommand != SMT_C_DREAD_1)					// Read command check
	&& (bCommand != SMT_C_DREAD_3))
	  {
		bCommand = SMT_C_DREAD_1;					// >>> DEFAULT = Read(1)
	  }

	//DMA setting
	*(volatile unsigned long*)0x48240 = 0x0;				// clear DmaReg
	*(volatile unsigned short*)0x48240 = SMT_S_DATA;		// transfer count
	*(volatile unsigned char*)0x48243 = 0x80;				// dual transfer mode	

	*(volatile unsigned long*)0x48244 = SMT_R_AREA15;	// source address
	*(volatile unsigned char*)0x48247 &=0x0f;			// byte transfer, address fixed

	*(volatile unsigned long*)0x48248 =(unsigned long) pBuffer;			// dest address
	*(volatile unsigned char*)0x4824b &=0x7f;			// successive transfer mode, dest inc
	*(volatile unsigned char*)0x4824b |=0x70;				

	SMT_R_CLE = SMT_BYTE1;			// CLE is set up in high
	SMT_R_CE = SMT_BYTE0;			// CE is set up in low

	*SMT_R_DATAIO = bCommand;						// Read command

	SMT_R_CLE = SMT_BYTE0;			// CLE is set up in low
	SMT_R_ALE = SMT_BYTE1;			// ALE is set up in high

	*SMT_R_DATAIO = SMT_M_BYTE(ulColumn, SMT_BYTE0);	// Column address
	*SMT_R_DATAIO = SMT_M_BYTE(ulPage, SMT_BYTE0);		// Page address (LOW)
	if(smt_MdaSiz <= 32)
	  {
		SMT_M_INTDISABLE;								// Interrupt disable
	  }
	*SMT_R_DATAIO = SMT_M_BYTE(ulPage, SMT_BYTE1);		//              (HIGH)
	if(smt_MdaSiz > 32)
	  {
		SMT_M_INTDISABLE;								// Interrupt disable
		*SMT_R_DATAIO = SMT_M_BYTE(ulPage, SMT_BYTE2);
	  }

	SMT_R_ALE = SMT_BYTE0;				// ALE is set up in low
	asm("nop");

	iRetVal = smtReadyCheck(SMT_M_US2CNT(100));		// Ready check (100uS) routine is call
	if(iRetVal == SMT_E_SUCCESS)
	  {
		SMT_M_INTENABLE;								// Interrupt enable

		if(bCommand == SMT_C_DREAD_1)					// Set read data count
		  {
			SMT_ECC_RST;
			SMT_ECC_EN;

			SMT_DMA_ENABLE;
			SMT_DMA_TRG;
			/*
			for(iLoop = 0; iLoop < SMT_S_DATA; iLoop++)
			  {
				*pBuffer++ = *SMT_R_DATAIO;				// Read data area
			  }
			  */
			for(uTimeLoop = 0; uTimeLoop<SMT_M_US2CNT(10); uTimeLoop++)
			{
				if(!SMT_DMA_FLAG)
					break;
			}
			SMT_ECC_DIS;
			// check ECC ready
			for(uTimeLoop = 0; uTimeLoop <SMT_M_MS2CNT(5); uTimeLoop++)
			{
				if(SMT_ECC_RDY)

⌨️ 快捷键说明

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