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

📄 cf_processor.c

📁 微机+CF卡+SD卡+USB的开发示例希望大家能用
💻 C
字号:
/******************************************************************************
* 		                                               
*  (c) copyright Freescale Semiconductor Hong Kong Ltd. 2004
*  ALL RIGHTS RESERVED
*                                                                       
*******************************************************************************  
** THIS  CODE IS ONLY INTENDED AS AN EXAMPLE FOR DEMONSTRATING THE FREESCALE **
** MICROCONTROLLERS.  IT  HAS ONLY BEEN GIVEN A MIMIMUM LEVEL OF TEST. IT IS **
** PROVIDED  'AS  SEEN'  WITH  NO  GUARANTEES  AND  NO  PROMISE  OF SUPPORT. **
*******************************************************************************  
*                                                                           
* FILE:         CF_Processor.c
*  
* DESCRIPTION:  CompactFlash processor
*
* UPDATED HISTORY:
*
* REV   YYYY.MM.DD  AUTHOR        DESCRIPTION OF CHANGE
* ---   ----------  ------        ---------------------	
* 0.0   2003.09.01  Derek Lau     Initial version
*
******************************************************************************/                                                                        
/* Freescale  is  not  obligated  to  provide  any  support, upgrades or new */
/* releases  of  the Software. Freescale may make changes to the Software at */
/* any time, without any obligation to notify or provide updated versions of */
/* the  Software  to you. Freescale expressly disclaims any warranty for the */
/* Software.  The  Software is provided as is, without warranty of any kind, */
/* either  express  or  implied,  including, without limitation, the implied */
/* warranties  of  merchantability,  fitness  for  a  particular purpose, or */
/* non-infringement.  You  assume  the entire risk arising out of the use or */
/* performance of the Software, or any systems you design using the software */
/* (if  any).  Nothing  may  be construed as a warranty or representation by */
/* Freescale  that  the  Software  or  any derivative work developed with or */
/* incorporating  the  Software  will  be  free  from  infringement  of  the */
/* intellectual property rights of third parties. In no event will Freescale */
/* be  liable,  whether in contract, tort, or otherwise, for any incidental, */
/* special,  indirect, consequential or punitive damages, including, but not */
/* limited  to,  damages  for  any loss of use, loss of time, inconvenience, */
/* commercial loss, or lost profits, savings, or revenues to the full extent */
/* such  may be disclaimed by law. The Software is not fault tolerant and is */
/* not  designed,  manufactured  or  intended by Freescale for incorporation */
/* into  products intended for use or resale in on-line control equipment in */
/* hazardous, dangerous to life or potentially life-threatening environments */
/* requiring  fail-safe  performance,  such  as  in the operation of nuclear */
/* facilities,  aircraft  navigation  or  communication systems, air traffic */
/* control,  direct  life  support machines or weapons systems, in which the */
/* failure  of  products  could  lead  directly to death, personal injury or */
/* severe  physical  or  environmental  damage  (High  Risk Activities). You */
/* specifically  represent and warrant that you will not use the Software or */
/* any  derivative  work of the Software for High Risk Activities.           */
/* Freescale  and the Freescale logos are registered trademarks of Freescale */
/* Semiconductor Inc.                                                        */ 
/*****************************************************************************/
#include	"FreescaleDef.h"				// Get my definitions (Constants & Macros)
#include	"uf32reg.h"				// Get the uf32 registers.
#include	"mk_extern.h"			// Get Mini-Kernel global prototypes
#include	"cf_includes.h"		// Get CF module configuration
#include	"cf_extern.h"			// Get ATA exported global prototypes
#include	"USBMS_extern.h"
#include	"utl_includes.h"

#pragma CODE_SEG	DEFAULT
// code is placed in the main code area.


// ==================================================================
//   CF_SCSIInqury() -
//
//     SCSI Inqury Command
//
//	Input -		= Buffer pointer, XferLen 
//				
//	Output - 	= Inquiry out Data wrote to buffer
//				= Temp data used for Identify Device
//
//	Function returns ATA error code
//
// ==================================================================
CFErrorCode CF_SCSIInquiry(muint16 *pBuffer,muint8 XferLen)
{
	CFErrorCode error;
	muint8	i;
	
	error =	CF_IdentifyDevice( (muint16 *) pBuffer, kCFDevInfoModelEnd);
	if (error)
		return (error);

	QC3DR = 0x0080;		// removeable or not
	QC3DR = 0x0002;							// SCSI 2 compatible
	QC3DR = (muint16) ((XferLen - 5) << kOneByte);		// addition length = 31
	QC3DR = 0x0000;							// reserved

	for (i=0; i<=13; i++)
	{
		QC3DR = (*(pBuffer+kCFDevInfoModelBeg+i)<<8)|(*(pBuffer+kCFDevInfoModelBeg+i)>>8);
	}	
	
	return (kCFPass);
}

// ==================================================================
//   CF_SCSIReadCapacity() -
//
//     SCSI Read Capacity / CF Read Native Max Address
//
//	Input -		= Buffer pointer
//				
//	Output - 	= Data wrote to buffer
//
//	Function returns ATA error code
//
// ==================================================================
CFErrorCode CF_SCSIReadCapacity(muint8 *pBuffer)
{
	*pBuffer++ = (muint8) (gCFMaxCapacity >> kThreeByte);
	*pBuffer++ = (muint8) (gCFMaxCapacity >> kTwoByte);
	*pBuffer++ = (muint8) (gCFMaxCapacity >> kOneByte);
	*pBuffer++ = (muint8) gCFMaxCapacity;
	*pBuffer++ = 0;							
	*pBuffer++ = 0;							
	*pBuffer++ = 0x02;						// 512 bytes per block
	*pBuffer++ = 0x00;

	return (kCFPass);	
}


// ==================================================================
//   CF_IdentifyDevice() -
//
//     CF Identify Device command / Identify Packet Device Command
//
//	Input -		= Buffer pointer, Transfer Length
//				
//	Output - 	= Device information at buffer	
//
//	Function returns CF error code
//
// ==================================================================
CFErrorCode CF_IdentifyDevice(muint16 *pBuffer, muint16 XferLen)
{
	CFErrorCode error;
	
	CF_Write8Mem(CF_M_COMMAND,KCFCmdIdentifyDevice);
	
	error = CF_BufferReadMem(pBuffer, XferLen);
	if (error)
		return(error);

	return (kCFPass);	
}




//
// The end of file CF_processor.c 
// *********************************************************************************

⌨️ 快捷键说明

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